-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch1.pl
55 lines (41 loc) · 1.11 KB
/
ch1.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
% Student exercise profile
:- set_prolog_flag(occurs_check, error). % disallow cyclic terms
:- set_prolog_stack(global, limit(8 000 000)). % limit term space (8Mb)
:- set_prolog_stack(local, limit(2 000 000)). % limit environment space
% Your program goes here
/** <examples> Your example queries go here, e.g.
?- member(X, [cat, mouse]).
*/
% binary facts
parent(pam, bob).
parent(tom, bob).
parent(tom, liz).
parent(bob, ann).
parent(bob, pat).
parent(pat, jim).
% unary facts
male(tom).
male(bob).
male(jim).
female(liz).
female(pat).
female(ann).
female(pam).
% clauses
offspring(Y, X) :- parent(X, Y).
% X is mother of Y IF X is parent of Y and X is a male
mother(X, Y) :- parent(X, Y), female(X).
% X is grandparent of Z IF X is parent of Y and Y is parent of Z
grandparent(X, Z) :-
parent(X, Y),
parent(Y, Z).
% X is sister of Y IF Z is parent of both and X is a female
sister(X, Y) :-
parent(Z, X),
parent(Z, Y),
female(X).
predecessor(X, Z) :-
parent(X, Z).
predecessor(X, Z) :-
parent(X, Y),
predecessor(Y, Z).