root(a).
child(b,a).
child(c,a).
child(d,b).
child(e,b).
child(f,c).
child(g,c).
predecessor(X,Y):-child(Y,X).
successor(X,Y):-child(X,Y).
parent(X,Y):-child(Y,X).
sibling(X,Y):-child(X,Z),child(Y,Z).
Output
1 ?- root(a).
true.
2 ?- child(b,a).
true.
3 ?- sibling(X,Y).
X = Y, Y = b ;
X = b,
Y = c ;
X = c,
Y = b ;
X = Y, Y = c ;
X = Y, Y = d ;
X = d,
Y = e ;
X = e,
Y = d ;
X = Y, Y = e ;
X = Y, Y = f ;
X = f,
Y = g ;
X = g,
Y = f ;
X = Y, Y = g.
4 ?- successor(X,Y).
X = b,
Y = a ;
X = c,
Y = a ;
X = d,
Y = b ;
X = e,
Y = b ;
X = f,
Y = c ;
X = g,
Y = c.
1 ?- perdecessor(X,Y).
Correct to: "predecessor(X,Y)"? yes
X = a,
Y = b ;
X = a,
Y = c ;
X = b,
Y = d ;
X = b,
Y = e ;
X = c,
Y = f ;
X = c,
Y = g.
2 ?- parent(X,Y).
X = a,
Y = b .
3 ?- parent(X,Y).
X = a,
Y = b ;
X = a,
Y = c ;
X = b,
Y = d ;
X = b,
Y = e ;
X = c,
Y = f ;
X = c,
Y = g.
0 comments:
Post a Comment