math


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).

Related Links

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?

Categories

HOME
ffmpeg
common-lisp
unit-testing
clojure
performance-testing
android-sqlite
datetime
xquery
mocha
application-cache
ionic3
build.gradle
documentation
dbus
boxfuse
sparkpost
ellipse
deserialization
phpbb3
org-mode
drupal-commerce
jscodeshift
spring-restdocs
slime
ibm-datapower
azure-ad-graph-api
montecarlo
bitcode
digital-logic
scalability
angular-ngmodel
monads
parallax.js
coqide
kubernetes-go-client
gecko
zipline
ecmascript-4
json-rpc
runge-kutta
linechart
eve
internet-explorer-10
formatdatetime
arm7
manifoldjs
infiniband
curly-braces
plotrix
sqlite-net
vb4android
webpagetest
winobjc
training-data
js-of-ocaml
screen-capture
subroutine
relaxng
biojava
axlsx
mailx
base-conversion
iphone-5
zim-database
getuikit
bessel-functions
before-save
first-class-functions
bson
keymapping
dotliquid
sqlprofiler
blueprint
django-endless-pagination
nmea
execcommand
capitalize
sender
openid4java
polyglot
posterous
newsgroup
code-statistics
web-based
greensoftware
versant-vod

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App