-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignmentTree.pl
137 lines (121 loc) · 2.23 KB
/
assignmentTree.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* Family Tree Program */
/* facts */
wife(george, mum).
wife(spencer, kydd).
wife(philip, elizabeth).
wife(charles, diana).
wife(mark, anne).
wife(andrew, sarah).
son(elizabeth, charles).
son(elizabeth, andrew).
son(elizabeth, edward).
son(philip, charles).
son(philip, andrew).
son(philip, edward).
son(diana, william).
son(diana, harry).
son(charles, william).
son(charles, harry).
son(mark, peter).
son(anne, peter).
daughter(elizabeth, anne).
daughter(philip, anne).
daughter(mark, zara).
daughter(anne, zara).
daughter(andrew, eugenie).
daughter(andrew, beatrice).
daughter(sarah, eugenie).
daughter(sarah, beatrice).
daughter(spencer, diana).
daughter(kydd, diana).
daughter(george, margaret).
daughter(mum, margaret).
daughter(mum, elizabeth).
daughter(george, elizabeth).
/* rules */
husband(H,X):-
wife(X,H).
spouse(S,X):-
wife(X,S);
husband(X,S).
child(P,X):-
son(P,X);
daughter(P,X).
parent(C,X):-
child(X,C).
grandchild(G, X):-
child(G,P),
child(P,X).
grandparent(G, X):-
parent(G, P),
parent(P, X).
greatGrandparent(Child, GGrandparent):-
grandparent(Child, Grandparent),
parent(Grandparent, GGrandparent).
brother(B, X):-
child(P, B),
son(P,X),
not(daughter(P,X)),
not(wife(P,_)),
not(B=X).
sister(S, X):-
child(P, S),
daughter(P,X),
not(son(P,X)),
not(husband(P,_)),
not(S=X).
sibling(Person, Sibling):-
brother(Person, Sibling);
sister(Person, Sibling).
sisterInLaw(Person, Sister):-
(
sibling(Person, Sibling),
wife(Sibling, Sister)
);
(
spouse(Person, Spouse),
sibling(Spouse, Sibling),
wife(Sibling, Sister)
);
(
spouse(Person, Spouse),
sister(Spouse, Sister)
).
brotherInLaw(Person, Brother):-
(
sibling(Person, Sibling),
husband(Sibling, Brother)
);
(
spouse(Person, Spouse),
sibling(Spouse, Sibling),
husband(Sibling, Brother)
);
(
spouse(Person, Spouse),
brother(Spouse, Brother)
).
uncle(Child, Uncle):-
parent(Child, Parent),
(
brother(Parent, Uncle);
(
sister(Parent, Sister),
husband(Sister, Uncle)
)
).
aunt(Child, Aunt):-
parent(Child, Parent),
(
sister(Parent, Aunt);
(
brother(Parent, Sister),
wife(Sister, Aunt)
)
).
firstCousin(Person, Cousin):-
grandparent(Person, Grandparent),
wife(Grandparent, _),
grandparent(Cousin, Grandparent),
not(sibling(Person,Cousin)),
not(Person=Cousin).