1
Solutions to predicate Logic Tutorial 1
1.
a. term(logic,1)
b. C (term(C,1)compulsory(C))
c. C (term(C,2)compulsory(C))
d. C (term(C,2)Yprereq(Y,C) (Yprereq(Y,C) X(prereq(X,C)term(X,1))))
e. X,Y (term(X,2) prereq(Y,X) term(Y,1))
f. X (term(X,1) term(X,2) Y(lecturer(Y) teaches(Y,X)))
g. Y(lecturer(Y) X (term(X,1) term(X,2) teaches(Y,X)))
2.
Describing the gate types:
xorgate(g1)
This says g1 is an xor gate.
xorgate(g2)
andgate(g3)
andgate(g4)
orgate(g5)
Describing the inputs:
input1(g1,1)
input2(g1,0)
These say the first input of g1 is 1 and the second input of g1 is 0.
X (input1(g2,X) output(g1,X))
This says the output of g1 is the first input of g2.
input2(g2,1)
input1(g3,1)
X (input2(g3,X) output(g1,X))
This says the output of g1 is the second input of g3.
input1(g4,1)
input2(g4,0)
X (input1(g5,X) output(g3,X))
X (input2(g5,X) output(g4,X))
Describing outputs of gates:
X,G,I1,I2 (output(G,X) andgate(G) input1(G,I1) input2(G,I2) and_result(I1, I2, X))
This says if G is an andgate and its two inputs are I1 and I2, then the output of G is the result of and-
ing I1 and I2.
X,G,I1,I2 (output(G,X) orgate(G) input1(G,I1) input2(G,I2) or_result(I1, I2, X))
X,G,I1,I2 (output(G,X) xorgate(G) input1(G,I1) input2(G,I2) xor_result(I1, I2, X))
and_result(1,1,1)
X (and_result(0,X,0))
X (and_result(X,0,0))
or_result(0,0,0)
X (or_result(1,X,1))
X (or_result(X,1,1))
X (xor_result(X,X,0))
X,Y (xor_result(X,Y,1) X=Y)