triska / clpz

Constraint Logic Programming over Integers
https://www.metalevel.at/prolog/clpz
184 stars 15 forks source link

Stronger propagation for exponentiation #5

Open triska opened 8 years ago

triska commented 8 years ago

Enhance propagation in the following cases, if possible:

?-  X^Y #= 0.
X^Y#=0.

and:

?- X in 0..100, 2^I #= X.
X in 0..100,
2^I#=X.

Suggested by @JCumin. These cases must be checked carefully.

JCumin commented 7 years ago

Another case where stronger propagation should be possible (tested on SWI's CLP(FD), I'm assuming those cases hold for CLP(Z)):

?- X in 0..sup, Y in inf.. -1, X^I #= Y.
X in 0..sup,
X^I#=Y,
Y in inf.. -1

X is positive and Y is not, therefore it should fail.

This is particularely noticeable when there is only one unknown:

?- 2^I #= -4.
2^I#= -4.      % should fail without needing labeling

The same thing happens when X is negative:

?- (-2)^I #= -4.
-2^I#= -4

(Though it can be less obvious to fail when possible in the general case because of odd powers yielding negative numbers)

UWN commented 7 years ago

@JCumin : Still not using clpz?

JCumin commented 7 years ago

@UWN I only have a recreational use for Prolog, as such I don't feel like it is worth investing money into a SICStus license (whether it be paid by me or anyone else). Moreover, SICStus top-level did not really make a great impression on me.

UWN commented 7 years ago

@JCumin - so you did not even take the offer?? For the top level, I do agree - but at least it has better naming of variables.

JCumin commented 7 years ago

@UWN No I did not. I would feel bad having someone spend a significant amount of money for how little I use Prolog. Moreover my main project needs to be runnable on a free distribution, so I wouldn't work on porting it to SICStus anyway.