View source with formatted comments or as raw
    1% A simple family database
    2
    3% An unrelated program. As full server this is solved. Using the dynamic
    4% calling we only consider  predicates  reachable   from  the  query and
    5% global constraints whose call-tree overlaps with the query.
    6
    7test1(X) :- not test2(X, Y).
    8test1(X).
    9test2(X, Y) :- (Y \= 1, not test3(X)).
   10test2(X, 1) :- not test3(X).
   11test3(X) :- not test1(X).
   12
   13% The family
   14
   15male(bob).
   16male(bo).
   17male(ben).
   18male(jeff).
   19male(ron).
   20male(tim).
   21male(ray).
   22
   23female(may).
   24female(joy).
   25female(jill).
   26female(kathy).
   27female(ali).
   28female(sam).
   29female(beth).
   30
   31father(bob,jill).
   32father(bob,bo).
   33%father(bob,kathy).
   34%father(bo,ron).
   35father(bo,ali).
   36father(ben,sam).
   37%father(jeff,beth).
   38%father(jeff,tim).
   39%father(jeff,ray).
   40
   41mother(may,jill).
   42mother(may,bo).
   43%mother(may,kathy).
   44%mother(joy,ron).
   45mother(joy,ali).
   46mother(jill,sam).
   47%mother(kathy,beth).
   48%mother(kathy,tim).
   49%mother(kathy,ray).
   50
   51
   52parent(X,Y) :- father(X,Y).
   53parent(X,Y) :- mother(X,Y).
   54
   55grandparent(X,Y):-parent(X,Z),parent(Z,Y).
   56
   57ancestor(X,Y) :- parent(X,Y).
   58ancestor(X,Y) :- parent(X,Z),ancestor(Z,Y).
   59
   60sibling(X,Y):-X\=Y,parent(Z,X),parent(Z,Y).
   61
   62sister(X,Y):-sibling(X,Y),female(X).
   63
   64brother(X,Y):-sibling(X,Y),male(X).
   65
   66cousin(X,Y):-parent(P1,X),parent(P2,Y),P1\=P2.%sibling(P1,P2).
   67
   68hardmath(X) :- X is A+(B*C-(D/E-F)*G)*H.
   69
   70
   71
   72?- ancestor(bob,sam).