16
17:-module(pdl_dGM,
18 [
19 eventualities/2,
20 simplify_X/2,
21 reduce_local/9
22 ]). 23
24:- dynamic
25 eventualities/2,
26 simplify_X/2,
27 reduce_local/9. 28
30
31eventualities([], []).
32
33eventualities([pr(State,FmlList)|Branch], Eventualities) :-
34 eventualities_fml(State,FmlList, Eventualities1), !,
35 eventualities(Branch, Eventualities2),
36 sort(Eventualities1, SortedEventualities1),
37 sort(Eventualities2, SortedEventualities2),
38 merge_set(SortedEventualities1, SortedEventualities2, Eventualities).
39eventualities([isCopyOf(_,_)|Branch], Eventualities) :-
40 eventualities(Branch, Eventualities).
41
42eventualities_fml(_,[], []).
43
44eventualities_fml(State, [Fml|FmlList], Eventualities) :-
45 eventualities_fml(State, Fml, Eventualities1), !,
46 eventualities_fml(State, FmlList, Eventualities2),
47 sort(Eventualities1, SortedEventualities1),
48 sort(Eventualities2, SortedEventualities2),
49 merge_set(SortedEventualities1, SortedEventualities2, Eventualities).
50
51eventualities_fml(State, x(X,Fml), [ev(State,x(X,Fml))|Eventualities]) :-
52 eventualities_fml(State, Fml, Eventualities).
53
97
98eventualities_fml(_,_,[]).
99
100
102
103simplify_X([], []).
104
105simplify_X([Fml|FmlList], [SimplifiedFml|SimplifiedFmlList]) :-
106 simplify_X_fml(Fml, SimplifiedFml), !,
107 simplify_X(FmlList, SimplifiedFmlList).
108
109simplify_X_fml(x(_,Fml), x(SimplifiedFml)) :-
110 simplify_X_fml(Fml, SimplifiedFml).
111
112simplify_X_fml(and(A,B), and(SimplifiedA,SimplifiedB)) :-
113 simplify_X_fml(A, SimplifiedA),
114 simplify_X_fml(B, SimplifiedB).
115
116simplify_X_fml(or(A,B), or(SimplifiedA,SimplifiedB)) :-
117 simplify_X_fml(A, SimplifiedA),
118 simplify_X_fml(B, SimplifiedB).
119
120simplify_X_fml(not(A), not(SimplifiedA)) :-
121 simplify_X_fml(A, SimplifiedA).
122
123simplify_X_fml(dia(R,A), dia(SimplifiedR,SimplifiedA)) :-
124 simplify_X_fml(R, SimplifiedR),
125 simplify_X_fml(A, SimplifiedA).
126
127simplify_X_fml(box(R,A), box(SimplifiedR,SimplifiedA)) :-
128 simplify_X_fml(R, SimplifiedR),
129 simplify_X_fml(A, SimplifiedA).
130
131simplify_X_fml(comp(R,S), comp(SimplifiedR,SimplifiedS)) :-
132 simplify_X_fml(R, SimplifiedR),
133 simplify_X_fml(S, SimplifiedS).
134
135simplify_X_fml(test(R), test(SimplifiedR)) :-
136 simplify_X_fml(R, SimplifiedR).
137
138simplify_X_fml(A,A).
139
150
151reduce_local([], _, Workedoff, Workedoff, [], [], [], DT, DT).
152
153reduce_local([true|Unexpanded], X, Workedoff, NewWorkedoff,
154 Universal, Existential, Eventualities, IDT, ODT) :- !,
155 extend_unexpanded([true], Workedoff, Unexpanded, NewUnexpanded, X, true),
156 reduce_local(NewUnexpanded, X, [true|Workedoff],
157 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
158
159reduce_local([or(A,B)|Unexpanded], X, Workedoff, NewWorkedoff,
160 Universal, Existential, Eventualities, IDT, ODT) :-
169 get_branch_point_counter(Count),
170 pdl_on_write('In reduce_local, LEFT branch of OR, reduce_local: '), pdl_on_write(Count), pdl_on_nl,
171 increment_branch_point_counter(1),
172 extend_unexpanded([A], Workedoff, Unexpanded, NewUnexpanded,
173 X, ['or-LEFT',or(A,B)]),
174 reduce_local(NewUnexpanded, X, [or(A,B)|Workedoff],
175 NewWorkedoff, Universal, Existential, Eventualities, [l|IDT], ODT).
176
177reduce_local([or(A,B)|Unexpanded], X, Workedoff, NewWorkedoff,
178 Universal, Existential, Eventualities, IDT, ODT) :-
183 get_branch_point_counter(Count),
184 pdl_on_write('In reduce_local, RIGHT branch of OR, reduce_local: '), pdl_on_write(Count), pdl_on_nl,
185 increment_branch_point_counter(-1),
186 extend_unexpanded([B], Workedoff, Unexpanded, NewUnexpanded,
187 X, ['or-RIGHT',or(A,B)]),
188 reduce_local(NewUnexpanded, X, [or(A,B)|Workedoff],
189 NewWorkedoff, Universal, Existential, Eventualities, [r|IDT], ODT).
190
193reduce_local([or(A,B)|Unexpanded], _X, Workedoff, _NewWorkedoff,
194 _Universal, _Existential, _Eventualities, _IDT, _ODT) :-
195 !,
197 append([or(A,B)|Unexpanded],Workedoff,Fmls),
198 store_inconsistent(Fmls),
199 fail.
200
201reduce_local([not(or(A,B))|Unexpanded], X, Workedoff, NewWorkedoff,
202 Universal, Existential, Eventualities, IDT, ODT) :- !,
203 complement(A, NotA),
204 complement(B, NotB),
205 extend_unexpanded([NotA,NotB], Workedoff, Unexpanded, NewUnexpanded,
206 X, ['and',not(or(A,B))]),
207 reduce_local(NewUnexpanded, X, [not(or(A,B))|Workedoff],
208 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
209
210reduce_local([dia(or(R,S),A)|Unexpanded], X, Workedoff, NewWorkedoff,
211 Universal, Existential, Eventualities, IDT, ODT) :- 212 get_branch_point_counter(Count),
213 pdl_on_write('In reduce_local, LEFT branch of DIA-OR, reduce_local: '), pdl_on_write(Count), pdl_on_nl,
214 increment_branch_point_counter(1),
215 extend_unexpanded([dia(R,A)], Workedoff, Unexpanded, NewUnexpanded,
216 X, ['dia-or-LEFT',dia(or(R,S),A)]),
217 reduce_local(NewUnexpanded, X, [dia(or(R,S),A)|Workedoff],
218 NewWorkedoff, Universal, Existential, Eventualities, [l|IDT], ODT).
219
220reduce_local([dia(or(R,S),A)|Unexpanded], X, Workedoff, NewWorkedoff,
221 Universal, Existential, Eventualities, IDT, ODT) :- !,
222 225 get_branch_point_counter(Count),
226 pdl_on_write('In reduce_local, RIGHT branch of DIA-OR, reduce_local: '), pdl_on_write(Count), pdl_on_nl,
227 increment_branch_point_counter(-1),
228 extend_unexpanded([dia(S,A)], Workedoff, Unexpanded, NewUnexpanded,
229 X, ['dia-or-RIGHT',dia(or(R,S),A)]),
230 reduce_local(NewUnexpanded, X, [dia(or(R,S))|Workedoff],
231 NewWorkedoff, Universal, Existential, Eventualities, [r|IDT], ODT).
232
233reduce_local([dia(comp(R,S),A)|Unexpanded], X, Workedoff, NewWorkedoff,
234 Universal, Existential, Eventualities, IDT, ODT) :- !,
235 extend_unexpanded([dia(R,dia(S,A))], Workedoff, Unexpanded, NewUnexpanded,
236 X, ['dia-comp',dia(comp(R,S),A)]),
237 reduce_local(NewUnexpanded, X, [dia(comp(R,S),A)|Workedoff],
238 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
239
240reduce_local([dia(star(R),A)|Unexpanded], X, Workedoff, NewWorkedoff,
241 Universal, Existential, Eventualities, IDT, ODT) :- !,
242 extend_unexpanded([x(X,dia(star(R),A))], Workedoff, Unexpanded, NewUnexpanded,
243 X, ['dia-star',dia(star(R),A)]),
244 reduce_local(NewUnexpanded, X, [dia(star(R),A)|Workedoff],
245 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
246
254reduce_local([x(Y,dia(star(R),A))|Unexpanded], X, Workedoff, NewWorkedoff,
255 Universal, Existential,
256 [fulfilled(X, x(Y,dia(star(R),A)))|Eventualities], IDT, ODT) :- 257 get_branch_point_counter(Count),
258 pdl_on_write('In reduce_local, LEFT branch of X, reduce_local: '), pdl_on_write(Count), pdl_on_nl,
259 increment_branch_point_counter(1),
260 extend_unexpanded([A], Workedoff, Unexpanded, NewUnexpanded,
261 X, ['X-LEFT',x(Y,dia(star(R),A))]),
262 reduce_local(NewUnexpanded, X, [x(Y,dia(star(R),A))|Workedoff],
263 NewWorkedoff, Universal, Existential, Eventualities, [l|IDT], ODT).
264
265reduce_local([x(Y,dia(star(R),A))|Unexpanded], X, Workedoff, NewWorkedoff,
266 Universal, Existential, Eventualities, IDT, ODT) :- !,
270 complement(A, NotA),
271 get_branch_point_counter(Count),
272 pdl_on_write('In reduce_local, RIGHT branch of X, reduce_local: '), pdl_on_write(Count), pdl_on_nl,
273 increment_branch_point_counter(-1),
274 extend_unexpanded([NotA,dia(R,x(Y,dia(star(R),A)))], Workedoff,
275 Unexpanded, NewUnexpanded,
276 X, ['X-RIGHT',x(Y,dia(star(R),A))]),
277 reduce_local(NewUnexpanded, X, [x(Y,dia(star(R),A))|Workedoff],
278 NewWorkedoff, Universal, Existential, Eventualities, [r|IDT], ODT).
279
280reduce_local([dia(test(A),B)|Unexpanded], X, Workedoff, NewWorkedoff,
281 Universal, Existential, Eventualities, IDT, ODT) :- !,
282 extend_unexpanded([A,B], Workedoff, Unexpanded, NewUnexpanded,
283 X, ['dia-test',dia(test(A),B)]),
284 reduce_local(NewUnexpanded, X, [dia(test(A),B)|Workedoff],
285 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
286
287reduce_local([dia(R,A)|Unexpanded], X, Workedoff, NewWorkedoff,
288 Universal, [dia(R,A)|Existential], Eventualities, IDT, ODT) :- !,
289 atom(R), 290 reduce_local(Unexpanded, X, [dia(R,A)|Workedoff],
291 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
292
293reduce_local([not(dia(or(R,S),A))|Unexpanded], X, Workedoff, NewWorkedoff,
294 Universal, Existential, Eventualities, IDT, ODT) :- !,
295 extend_unexpanded([not(dia(R,A)),not(dia(S,A))], Workedoff, Unexpanded, NewUnexpanded,
296 X, ['box-or',not(dia(or(R,S),A))]),
297 reduce_local(NewUnexpanded, X, [not(dia(or(R,S),A))|Workedoff],
298 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
299
300reduce_local([not(dia(comp(R,S),A))|Unexpanded], X, Workedoff, NewWorkedoff,
301 Universal, Existential, Eventualities, IDT, ODT) :- !,
302 extend_unexpanded([not(dia(R,dia(S,A)))], Workedoff, Unexpanded, NewUnexpanded,
303 X, ['box-comp',not(dia(comp(R,S),A))]),
304 reduce_local(NewUnexpanded, X, [not(dia(comp(R,S),A))|Workedoff],
305 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
306
307reduce_local([not(dia(star(R),A))|Unexpanded], X, Workedoff, NewWorkedoff,
308 Universal, Existential, Eventualities, IDT, ODT) :- !,
309 complement(A, NotA),
310 extend_unexpanded([NotA,not(dia(R,dia(star(R),A)))], Workedoff, Unexpanded, NewUnexpanded,
311 X, ['box-star',not(dia(star(R),A))]),
312 reduce_local(NewUnexpanded, X, [not(dia(star(R),A))|Workedoff],
313 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
314
315reduce_local([not(dia(test(A),B))|Unexpanded], X, Workedoff, NewWorkedoff,
316 Universal, Existential, Eventualities, IDT, ODT) :- 317 complement(A, NotA),
318 get_branch_point_counter(Count),
319 pdl_on_write('In reduce_local, LEFT branch of BOX-TEST, reduce_local: '), pdl_on_write(Count), pdl_on_nl,
320 increment_branch_point_counter(1),
321 extend_unexpanded([NotA], Workedoff, Unexpanded, NewUnexpanded,
322 X, ['box-test-LEFT',not(dia(test(A),B))]),
323 reduce_local(NewUnexpanded, X, [not(dia(test(A),B))|Workedoff],
324 NewWorkedoff, Universal, Existential, Eventualities, [l|IDT], ODT).
325
326reduce_local([not(dia(test(A),B))|Unexpanded], X, Workedoff, NewWorkedoff,
327 Universal, Existential, Eventualities, IDT, ODT) :- !,
329 complement(B, NotB),
330 get_branch_point_counter(Count),
331 pdl_on_write('In reduce_local, RIGHT branch of BOX-TEST, reduce_local: '), pdl_on_write(Count), pdl_on_nl,
332 increment_branch_point_counter(-1),
333 extend_unexpanded([NotB], Workedoff, Unexpanded, NewUnexpanded,
334 X, ['box-test-RIGHT',not(dia(test(A),B))]),
335 reduce_local(NewUnexpanded, X, [not(dia(test(A),B))|Workedoff],
336 NewWorkedoff, Universal, Existential, Eventualities, [r|IDT], ODT).
337
338reduce_local([not(dia(R,A))|Unexpanded], X, Workedoff, NewWorkedoff,
339 [not(dia(R,A))|Universal], Existential, Eventualities, IDT, ODT) :- !,
340 atom(R), 341 reduce_local(Unexpanded, X, [not(dia(R,A))|Workedoff],
342 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT).
343
344reduce_local([Literal|Unexpanded], X, Workedoff, NewWorkedoff,
345 Universal, Existential, Eventualities, IDT, ODT) :- !,
346 reduce_local(Unexpanded, X, [Literal|Workedoff],
347 NewWorkedoff, Universal, Existential, Eventualities, IDT, ODT)