clpfd - Can someone explain why this prolog query evaluates to false? -
i trying write predicate pythagorean(x,y,z,w)
can generate triples such x^2 + y^2 = z^2
, w >= x,y,z > 0
.
this wrote:
pyth(x,y,z,w) :- x > 0, y > 0, z > 0, s1 x*x + y*y, s2 z*z, s1 == s2, w @> z.
use clpfd!
:- use_module(library(clpfd)).
we define pytri/2
based on fd-constraints sum/3
, chain/2
, (#=)/2
, , (#<)/2
:
pytri(zs,perimeter) :- zs = [a,b,c], maplist(#<(1),zs), sum(zs,#=,perimeter), chain(zs,#<), a^2 + b^2 #= c^2.
let's find 17 pythagorean triples (16 primitive + 1 non-primitive) having perimeter ≤ 100:
?- pytri([x,y,z],perimeter), perimeter #=< 100, labeling([],[z,y,x]). perimeter = 12, x = 3, y = 4, z = 5 ; perimeter = 24, x = 6, y = 8, z = 10 ; perimeter = 30, x = 5, y = 12, z = 13 ; perimeter = 36, x = 9, y = 12, z = 15 ; perimeter = 40, x = 8, y = 15, z = 17 ; perimeter = 48, x = 12, y = 16, z = 20 ; perimeter = 60, x = 15, y = 20, z = 25 ; perimeter = 56, x = 7, y = 24, z = 25 ; perimeter = 60, x = 10, y = 24, z = 26 ; perimeter = 70, x = 20, y = 21, z = 29 ; perimeter = 72, x = 18, y = 24, z = 30 ; perimeter = 80, x = 16, y = 30, z = 34 ; perimeter = 84, x = 21, y = 28, z = 35 ; perimeter = 84, x = 12, y = 35, z = 37 ; perimeter = 90, x = 15, y = 36, z = 39 ; perimeter = 96, x = 24, y = 32, z = 40 ; perimeter = 90, x = 9, y = 40, z = 41 ; false. % terminates universally
Comments
Post a Comment