-
Notifications
You must be signed in to change notification settings - Fork 0
/
alp_exp.pl
157 lines (104 loc) · 4.2 KB
/
alp_exp.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* ************************** EX1 ********************************* */
/* This is a simple example with NAF through abduction. */
/* Try this example with the following goals (G1 and G2): */
/* G1: demo([flies(tweety)],[],FinalExp). */
/* G2: demo([flies(sam)],[],FinalExp). */
/* Note here that only the second goal (G2) succeeds. */
/* **************************************************************** */
:- dynamic(flies/1).
:- dynamic(abnormal/1).
:- dynamic(bird/1).
:- dynamic(penguin/1).
:- dynamic(eagle/1).
flies(X) :- bird(X), not(abnormal(X)).
abnormal(X) :- penguin(X).
bird(X) :- penguin(X).
bird(X) :- eagle(X).
penguin(tweety).
eagle(sam).
/* Abducibles */
/* We don't define any abducibles */
abducible_predicate(none).
/* ************************** EX2 ********************************* */
/* This is an example with NAF through abduction. */
/* Try this example with the following goals (G1 and G2): */
/* G1: demo([flies(sam)],[],FinalExp). */
/* G2: demo([not(flies(sam))],[],FinalExp). */
/* **************************************************************** */
:- dynamic(flies/1).
:- dynamic(abnormal/1).
:- dynamic(light/1).
:- dynamic(heavy/1).
:- dynamic(bird/1).
:- dynamic(penguin/1).
:- dynamic(eagle/1).
flies(X) :- bird(X), not(abnormal(X)).
abnormal(X) :- penguin(X).
abnormal(X) :- not(light(X)).
light(X) :- not(heavy(X)).
heavy(X) :- not(light(X)).
bird(X) :- penguin(X).
bird(X) :- eagle(X).
penguin(tweety).
eagle(sam).
/* Abducibles */
/* We don't define any abducibles */
abducible_predicate(none).
/* ************************** EX3 ********************************* */
/* This is an example with NAF through abduction and */
/* other abducibles (no integrity constraints). */
/* We assume here that our knowledge about birds is incomplete */
/* and so we define a new abducible "bird_ab(X)" which states */
/* that X is a bird. Also "slim" is an abducible predicate. */
/* Try this example with the following goals (G1, G2 and G3): */
/* G1: demo([flies(tweety)],[],FinalExp). */
/* G2: demo([flies(sam)],[],FinalExp). */
/* G3: demo([flies(john)],[],FinalExp). */
/* Note that now only the first goal (G1) fails. */
/* Note also that the second goal (G2) now has two explanations. */
/* **************************************************************** */
:- dynamic(flies/1).
:- dynamic(abnormal/1).
:- dynamic(heavy/1).
:- dynamic(light/1).
:- dynamic(bird/1).
:- dynamic(penguin/1).
:- dynamic(eagle/1).
flies(X) :- bird(X), not(abnormal(X)).
abnormal(X) :- penguin(X).
abnormal(X) :- heavy(X).
heavy(X) :- not(light(X)).
light(X) :- slim(X).
bird(X) :- penguin(X).
bird(X) :- eagle(X).
bird(X) :- bird_ab(X).
penguin(tweety).
eagle(sam).
/* Abducibles */
abducible_predicate(bird_ab).
abducible_predicate(slim).
/* ************************** EX4 ********************************* */
/* This is an example with abducibles and integrity constraints. */
/* Try this example with the following goals (G1 and G2): */
/* G1: demo([car_doesnt_start(mycar)],[],FinalExp). */
/* G2: demo([car_doesnt_start(yourcar)],[],FinalExp). */
/* Note that there are two alternative explanations for G2. */
/* **************************************************************** */
:- dynamic(ic/0).
:- dynamic(car_doesnt_start/1).
:- dynamic(lights_go_on/1).
:- dynamic(fuel_indicator_empty/1).
car_doesnt_start(X) :- battery_flat(X).
car_doesnt_start(X) :- has_no_fuel(X).
lights_go_on(mycar).
fuel_indicator_empty(mycar).
/* Integrity Constraints */
ic :- battery_flat(X), lights_go_on(X).
ic :- has_no_fuel(X), not(fuel_indicator_empty(X)), not(broken_indicator(X)).
/* This second constraint is equivalent to : */
/* fuel_indicator_empty(X):- has_no_fuel(X), not(broken_indicator(X)). */
/* written as a denial. */
/* Abducibles */
abducible_predicate(battery_flat).
abducible_predicate(has_no_fuel).
abducible_predicate(broken_indicator).