*** 1 ?- parent(john, X). X = mary ?- parent(X, john). X = paul ?- parent(parent, X), parent(X, Y), parent(Y,Z). no *** 2.a sum(A3,A2,A1,B3,B2,B1,S4,S3,S2,S1) :- halfadder(A1,B1,C1,S1), fulladder(A2,B2,C1,S2,C2), fulladder(A3,B3,C2,S3,S4). *** 2.b % first solution % calculates S=A-B (A in 4 bits, B in 3 bits, S in 3 bits) % doesn't work when the result takes 4 bits sub4(A4,A3,A2,A1,B3,B2,B1,S3,S2,S1) :- sum(B3,B2,B1,S3,S2,S1,A4,A3,A2,A1). % second solution % calculates S=A-B (A,B,S all in 3 bits) % doesn't work when the result takes 4 bits sub3(A3,A2,A1,B3,B2,B1,S3,S2,S1) :- sum(B3,B2,B1,S3,S2,S1,0,A3,A2,A1). *** 3 grandparent(X,Y):-parent(X,Z),parent(Z,Y). *** 4 T_P^0 = {} T_P^1 = T_P({}) = set of facts defining the truth tables of and, or, eor, not T_P^2 = T_P(T_P^1) = T_P^1 union the set of facts defining the truth tables of halfadder and fulladder T_P^3 = T_P(T_P^2) = T_P^2 union the set of facts defining the truth tables of sum T_P^4 = T_P(T_P^3) = T_P^3 union the set of facts defining the truth tables of sub3 and sub4 T_P^5 = T_P(T_P^4) = T_P^4 this is a fixpoint and thus is the least Herbrand model