CLPFD-systems are not primarily targeted to handle quadratic equations efficiently, nevertheless, are there better ways to formulate problems like the following?
It seems the problem boils down to equations like the following. SWI with library(clpfd)
gave:
?- time( ((L+7)^2#=L^2+189, L in 0..10000000) ). % 252,169,718 inferences, 87208.554 CPU in 87445.038 seconds (100% CPU, 2892 Lips) ERROR: Out of local stack
But now the latest version in SWI gives
?- time( ((L+7)^2#=L^2+189, L in 0..10000000) ). % 3,805,545,940 inferences, 868.635 CPU in 870.311 seconds (100% CPU, 4381063 Lips) L = 10.
and in SICStus 4.3beta7 I get:
| ?- statistics(runtime,_). yes | ?- (L+7)*(L+7)#=L*L+189, L in 0..10000000. L = 10 ? ; no | ?- statistics(runtime,[_,T_ms]). T_ms = 2550 ? ; no
(L+7)*(L+7)#=L*L+189, L in 0..10000, label([L])
is much smaller than the time required when the ^2 operator is used... – Farina*
in place of ^2 leads to less consistency. Also, the cost is proportional to the size of the domain for L. – DaubeX^2
versusX*X
(in GNU, theX^2
was far better behaved. I think in general, for algebraic equations, one might need to apply some maths to prune the search tree a bit. Otherwise, the Prolog FD implementation(s) will struggle. – AmiceX * X
case without resulting in a segfault (gprolog V 1.4.2). – Amice