I read a brief article about Prolog and Logic Programming. I\'m curious if Logic Programs can do algebra. Like would you be able to ask what the Variable of X is in the equa
How about this? Note that this will only work for X+Y=Z.
X+Y=Z
equation(X,Y,Z):- var(X),X is Z-Y. equation(X,Y,Z):- var(Y),Y is Z-X. equation(X,Y,Z):- var(Z),Z is X+Y.
You can ask:
equation(5,X,7). X = 2 . ?- equation(2,5,X). X = 7. ?- equation(X,5,7). X = 2