My prolog knowledge is old, but I believe the problem is that Prolog only evaluates the right side of an is
So try:
pythag(H,A,B) :- Z is H*H, Z is (A*A) + (B*B).
Frage
Prolog Keeps saying 'no' to me.... :(
I am very new to prolog, I have a basic question:
So I'm trying to produce a simple rule that checks if three numbers constitute the length of the sides of a right-angle triangle, like this:
addup(X,Y,Z) :- X is Y+Z. /* this works*/
pythag(H,A,B) :- (H*H) is (A*A) + (B*B). /*this doesn't work*/
For testing, the 'addup' rule DOES appear to work.... I believe there is an issue with the left-hand side of the 'IS' in my program, as the following test seems to indicate this:
In interactive mode I can as whether 2 is the sum of 1 and 1, and it says yes:
| ?- 2 is 1+1.
yes
But if I switch the left and right hand sides; it says no:
| ?- 1+1 is 2.
no
Can somebody provide a correct version of the pythag rule above ? Version Info follows:
GNU Prolog 1.3.0
By Daniel Diaz
Copyright (C) 1999-2007 Daniel Diaz
| ?-
Lösung
My prolog knowledge is old, but I believe the problem is that Prolog only evaluates the right side of an is
So try:
pythag(H,A,B) :- Z is H*H, Z is (A*A) + (B*B).