prolog: rule to check pythagorean triplet?
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 | ?-
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).
Is there a difference between (n - (~r % n) - 1) and (n - (abs(r) % n)) when r < 0?
How determine two pairs of numbers are equal
How to find out the sum of products of all combinations of first n natural numbers taken r at a time?n and r are both constants [duplicate]
calculate bounding sphere radius in normalized space
Two positive integers 'a' and 'b' have a sum of 's' and a bitwise XOR of 'x'. How many possible values are there for the ordered pair (a, b)?
How to get the true Euclidean remainder?
How to find position of point that is x unit distant from AB line segment and y unit distant from BC line segment?
Feature based alignment & Non linear least square
Finding the number of times a statement runs
How to calculate distance between several points simultaneously with Euclidean Distance
Division operation is giving me the wrong result
Netlogo Flocking Model Code Explanation
Proof big omega of 1^k+2^k+..+n^k
Quaternion - Angle computation using accelerometer and gyroscope
Implementing equality function with basic arithmetic operations
How can I find points at an equal distance between 2 objects?