I recently saw a program in Prolog using the predicate #=/2. I looked this up on the SWI prolog website where they defined it as
The arithmetic expression X equals Y. When reasoning over integers, replace is/2 by #=/2 to obtain more general relations.
What I don't understand about this is how #=/2 can be more 'general' since it is only for integers.
From the documentation entry page:
They implement pure relations between integer expressions and can be used in all directions
Just an example:
?- X+3 #= X*2.
X = 3.
Looks simple, but actually it's rather difficult to obtain such result within conventional arithmetic expression evaluation.
?- X+3 is X*2.
ERROR: is/2: Arguments are not sufficiently instantiated
From the is/2 page, you can see the signature
-Number is +Expr
where +Expr
means it must be ground.
Also, the left argument of is/2 actually should be atomic:
?- 3+3 is 3*2.
false.
despite we know the above statement should be true...
A note: the name CLP(FD) is a bit an 'understatement', as pointed out by @false, could be named CLP(Z), since finiteness of domain can often be relaxed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With