Let's say we have two variables X and Y. X is 53 and Y is 52. What I want to do is compare them by adding 1 to the Y, so that it would be 53 - therefore X would be equal to Y + 1.
I am trying to do it by simply using equal operator and addition for Y variables, like so:
X == Y + 1
Even though this looks simple enough, I am getting false as the result. What am I missing?
?- X = 50+2, Y = 50+1, X =:= Y + 1.
as you can see, (=:=)/2 evaluates both sides, as do (>)/2, etc
If you are reasoning over integers, use your Prolog system's CLP(FD) constraints to compare and evaluate arithmetic integer expressions.
For example, in SICStus, SWI and YAP, after use_module(library(clpfd):
?- 53 #= 52 + 1.
true.
This works in all directions.
Other examples:
?- X #= 52 + 1.
X = 53.
?- 53 #= Y + 1.
Y = 52.
?- 53 #= 52 + 1.
true.
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