Last active
August 29, 2015 14:26
-
-
Save ee08b397/0b4965650dc5b3c643da to your computer and use it in GitHub Desktop.
execution order does matter for prolog, top-down; ancestor22 can cause infinite recursion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
a | |
/ \ | |
b d | |
| | |
c | |
| | |
e | |
*/ | |
parent(a, b). | |
parent(a, d). | |
parent(b, c). | |
parent(c, e). | |
ancestor11(X, X). | |
ancestor11(X, Y) :- parent(Z, Y), ancestor11(X, Z). | |
ancestor12(X, Y) :- parent(Z, Y), ancestor12(X, Z). | |
ancestor12(X, X). | |
ancestor21(X, X). | |
ancestor21(X, Y) :- ancestor21(X, Z), parent(Z, Y). | |
ancestor22(X, Y) :- ancestor22(X, Z), parent(Z, Y). | |
ancestor22(X, X). | |
ancestor31(X, Y) :- parent(X,Y). | |
ancestor31(X, Y) :- parent(X, Z), ancestor31(Z, Y). | |
ancestor32(X, Y) :- parent(X, Z), ancestor32(Z, Y). | |
ancestor32(X, Y) :- parent(X,Y). |
you're right, but the point here for 21 and 22 are demonstration of the order, and possible infinite recursion
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do you have ancestor(X,X)? That is not correct anyway