- Everybody who has a child is happy.
- We need the predicates happy/1, parent/2, child/1.
- happy(X) :- parent(X, Y), child(Y).
- We need the predicates happy/1, parent/2, child/1.
- For all X, if X has a child who has a sister then X has two children.
- We need the predicates child/1, sisterOf/2 (symmetric predicate), hastwochildren/1.
- hastwochildren(X) :- parent(X,Y), sisterOf(Y,Z).
- As an alternative:
- hastwochildren(X) :- parent(X,Y), parent(X,Z), female(Z).
- We need the predicates child/1, sisterOf/2 (symmetric predicate), hastwochildren/1.
- Define the relation grandchild using the parent relation.
- We need the predicates grandchild/2, parent/2.
- grandchild(X,Y) :- parent(Z,X), parent(Y,Z).
- We need the predicates grandchild/2, parent/2.
- Define the relation aunt(X, Y)
- We need the predicates: aunt/2, parent/2, sisterOf/2.
- aunt(X,Y) :- parent(Z,Y), sisterOf(X,Z).
- We need the predicates: aunt/2, parent/2, sisterOf/2.
- Define the predecessor relation
- We need the predicates: predecessor/2, parent/2:
- predecessor(X,Y) :- parent(X,Y).
predecessor(X,Y) :- parent(Z,Y), predecessor(X,Y).
- predecessor(X,Y) :- parent(X,Y).
- As an alternative:
- predecessor(X,Y) :- parent(X,Y).
predecessor(X,Y) :- parent(X,Z), predecessor(Z,Y).
- We need the predicates: predecessor/2, parent/2:
Some remarks:
The predecessor relation is defined by two clauses. This set of clauses is called procedure.