math - prolog: rule to check pythagorean triplet? -


prolog keeps saying 'no' me.... :(

i very new prolog, have basic question:

so i'm trying produce simple rule checks if 3 numbers constitute length of sides of right-angle triangle, this:

addup(x,y,z) :- x y+z. /* works*/ pythag(h,a,b) :- (h*h) (a*a) + (b*b). /*this doesn't work*/ 

for testing, 'addup' rule appear work.... believe there issue left-hand side of 'is' in program, following test seems indicate this:

in interactive mode can whether 2 sum of 1 , 1, , says yes:

| ?- 2 1+1.  yes 

but if switch left , right hand sides; says no:

| ?- 1+1 2.  no 

can provide correct version of pythag rule above ? version info follows:

gnu prolog 1.3.0 daniel diaz copyright (c) 1999-2007 daniel diaz | ?-  

my prolog knowledge old, believe problem prolog evaluates right side of is

so try:

pythag(h,a,b) :- z h*h, z (a*a) + (b*b). 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -