14
15:- include(ec_common). 16
64
66
67
78first_d(1000).
89
90abdemo_special(long,Gs,R):-abdemo_timed(Gs,R).
91abdemo_special(_,Gs,R):- abdemo(Gs,R).
92
93abdemo(Gs,[HA,BA]) :-
94 init_gensym(t), first_d(D),
95 abdemo_top(Gs,[[[],[]],[[],[]]],[[HA,HC],[BA,BC]],[],N,D),
96 write_plan_len(HA,BA).
97
98abdemo_timed(Gs,[HA,BA]) :-
99 ticks(Z1),
100 abdemo(Gs,[HA,BA]),
101 write_plan(HA,BA),
102 ticks(Z2), Z is (Z2-Z1)/60, write('Total time taken '), writenl(Z), nl.
103
104
105abdemo_top(Gs,R1,R3,N1,N3,D) :-
106 abdemo_id(Gs,R1,R2,N1,N2,D), !, abdemo_cont(R2,R3,N2,N3).
107
108
114
115abdemo_cont([[HA,TC],RB],[[HA,TC],RB],N,N) :- all_executable(HA), !.
116
117abdemo_cont([[HA,HC],[BA,BC]],R2,N1,N3) :-
118 write('Abstract plan: '), write(HA), writenl(BA), nl,
119 refine([[HA,HC],[BA,BC]],N1,Gs,R1,N2), action_count([[HA,HC],[BA,BC]],D),
120 abdemo_top(Gs,R1,R2,N2,N3,D).
121
122
124
125abdemo_id(Gs,R1,R2,N1,N2,D) :-
126 write(' DMS'), write(D), write(' '), abdemo(Gs,R1,R2,N1,N2,D).
127
128abdemo_id(Gs,R1,R2,N1,N2,D1) :- D2 is D1+1, abdemo_id(Gs,R1,R2,N1,N2,D2).
129
130
131all_executable([]).
132
133all_executable([happens(A,T1,T2)|R]) :- executable(A), all_executable(R).
134
135
136
137
139
140
149
150abdemo(Gs,[[HA,TC1],[BA,TC2]],R,N1,N2,D) :-
151 trace(on), write('Goals: '), writenl(Gs),
152 write('Happens: '), writenl(HA),
153 write('Befores: '), writenl(BA),
154 write('Nafs: '), writenl(N1), nl, nl, fail.
155
156abdemo([],R,R,N,N,D).
157
173
174abdemo([holds_at(F1,T)|Gs1],R1,R3,N1,N4,D) :-
175 F1 \= neg(F2), abresolve(initially(F1),R1,Gs2,R1,B),
176 append(Gs2,Gs1,Gs3), add_neg([clipped(0,F1,T)],N1,N2),
177 abdemo_naf([clipped(0,F1,T)],R1,R2,N2,N3,D),
178 abdemo(Gs3,R2,R3,N3,N4,D).
179
186
187abdemo([holds_at(F1,T3)|Gs1],R1,R6,N1,N5,D) :-
188 F1 \= neg(F2), abresolve(initiates(A,F1,T1),R1,Gs2,R1,B1),
189 abresolve(happens(A,T1,T2),R1,[],R2,B2),
190 check_depth(R2,D),
191 abresolve(before(T2,T3),R2,[],R3,B3),
192 append(Gs2,Gs1,Gs3), check_nafs(B2,N1,R3,R4,N1,N2,D),
193 add_neg([clipped(T1,F1,T3)],N2,N3),
194 abdemo_naf([clipped(T1,F1,T3)],R4,R5,N3,N4,D),
195 abdemo(Gs3,R5,R6,N4,N5,D).
196
207
208abdemo([holds_at(neg(F),T)|Gs1],R1,R3,N1,N4,D) :-
209 abresolve(initially(neg(F)),R1,Gs2,R1,B),
210 append(Gs2,Gs1,Gs3), add_neg([declipped(0,F,T)],N1,N2),
211 abdemo_naf([declipped(0,F,T)],R1,R2,N2,N3,D),
212 abdemo(Gs3,R2,R3,N3,N4,D).
213
214abdemo([holds_at(neg(F),T3)|Gs1],R1,R6,N1,N5,D) :-
215 abresolve(terminates(A,F,T1),R1,Gs2,R1,B1),
216 abresolve(happens(A,T1,T2),R1,[],R2,B2),
217 check_depth(R2,D),
218 abresolve(before(T2,T3),R2,[],R3,B3),
219 append(Gs2,Gs1,Gs3), check_nafs(B2,N1,R3,R4,N1,N2,D),
220 add_neg([declipped(T1,F,T3)],N2,N3),
221 abdemo_naf([declipped(T1,F,T3)],R4,R5,N3,N4,D),
222 abdemo(Gs3,R5,R6,N4,N5,D).
223
232
233abdemo([happens(A,T1,T2)|Gs],R1,R4,N1,N3,D) :-
234 !, abresolve(happens(A,T1,T2),R1,[],R2,B), check_depth(R2,D),
235 check_nafs(B,N1,R2,R3,N1,N2,D), abdemo(Gs,R3,R4,N2,N3,D).
236
237abdemo([happens(A,T)|Gs],R1,R4,N1,N3,D) :-
238 !, abresolve(happens(A,T),R1,[],R2,B), check_depth(R2,D),
239 check_nafs(B,N1,R2,R3,N1,N2,D), abdemo(Gs,R3,R4,N2,N3,D).
240
256
257abdemo([expand([happens(A,T1,T2)|Bs])|Gs1],R1,R8,N1,N8,D) :-
258 !, axiom(happens(A,T1,T2),Gs2),
259 add_sub_actions(Gs2,R1,R2,N1,N2,D,Hs),
260 solve_befores(Bs,R2,R3,N2,N3,D),
261 abdemo_holds_ats(Gs2,R3,R4,N3,N4,D),
262 solve_other_goals(Gs2,R4,R5,N4,N5,D),
263 check_clipping(Gs2,R5,R6,N5,N6,D),
264 check_sub_action_nafs(Hs,N1,R6,R7,N6,N7,D),
265 abdemo(Gs1,R7,R8,N7,N8,D).
266
272
273abdemo([not(G)|Gs],R1,R3,N1,N4,D) :-
274 !, abdemo_naf([G],R1,R2,N1,N2,D), add_neg([G],N2,N3),
275 abdemo(Gs,R2,R3,N3,N4,D).
276
277abdemo([G|Gs1],R1,R3,N1,N2,D) :-
278 abresolve(G,R1,Gs2,R2,B), append(Gs2,Gs1,Gs3),
279 abdemo(Gs3,R2,R3,N1,N2,D).
280
281
282check_depth(R,D) :- action_count(R,L), L =< D.
283
284
285action_count([[HA,TC],RB],L) :- length(HA,L).
286
287
288
289
291
292
294
295
296abdemo_holds_ats([],R,R,N,N,D).
297
298abdemo_holds_ats([holds_at(F,T)|Gs],R1,R3,N1,N3,D) :-
299 !, abdemo([holds_at(F,T)],R1,R2,N1,N2,D),
300 abdemo_holds_ats(Gs,R2,R3,N2,N3,D).
301
302abdemo_holds_ats([G|Gs],R1,R2,N1,N2,D) :-
303 abdemo_holds_ats(Gs,R1,R2,N1,N2,D).
304
305
306solve_other_goals([],R,R,N,N,D).
307
308solve_other_goals([G|Gs],R1,R3,N1,N3,D) :-
309 G \= holds_at(F,T), G \= happens(A,T1,T2),
310 G \= happens(A,T), G \= before(T1,T2),
311 G \= not(clipped(T1,F,T2)), G \= not(declipped(T1,F,T2)), !,
312 abdemo([G],R1,R2,N1,N2,D),
313 solve_other_goals(Gs,R2,R3,N2,N3,D).
314
315solve_other_goals([G|Gs],R1,R2,N1,N2,D) :-
316 solve_other_goals(Gs,R1,R2,N1,N2,D).
317
324
325add_sub_actions([],R,R,N,N,D,[]).
326
327add_sub_actions([happens(A,T1,T2)|Gs],R1,R3,N1,N3,D,Hs2) :-
328 !, abresolve(happens(A,T1,T2),R1,[],R2,B), check_depth(R2,D),
329 add_sub_actions(Gs,R2,R3,N2,N3,D,Hs1), cond_add(B,happens(A,T1,T2),Hs1,Hs2).
330
331add_sub_actions([happens(A,T)|Gs],R1,R3,N1,N3,D,Hs2) :-
332 !, abresolve(happens(A,T),R1,[],R2,B), check_depth(R2,D),
333 add_sub_actions(Gs,R2,R3,N2,N3,D,Hs1), cond_add(B,happens(A,T,T),Hs1,Hs2).
334
335add_sub_actions([before(T1,T2)|Gs],R1,R3,N1,N3,D,Hs) :-
336 !, abresolve(before(T1,T2),R1,[],R2,B),
337 add_sub_actions(Gs,R2,R3,N2,N3,D,Hs).
338
339add_sub_actions([G|Gs],R1,R2,N1,N2,D,Hs) :-
340 add_sub_actions(Gs,R1,R2,N1,N2,D,Hs).
341
342
343cond_add(false,H,Hs,Hs) :- !.
344
345cond_add(true,H,Hs,[H|Hs]).
346
347
348solve_befores([],R,R,N,N,D).
349
350solve_befores([before(T1,T2)|Gs],R1,R3,N1,N3,D) :-
351 !, abdemo([before(T1,T2)],R1,R2,N1,N2,D),
352 solve_befores(Gs,R2,R3,N2,N3,D).
353
354solve_befores([G|Gs],R1,R2,N1,N2,D) :-
355 solve_befores(Gs,R1,R2,N1,N2,D).
356
357
358check_sub_action_nafs([],N1,R,R,N2,N2,D) :- !.
359
360check_sub_action_nafs([happens(A,T1,T2)|Hs],N1,R1,R3,N2,N4,D) :-
361 check_nafs(A,T1,T2,N1,R1,R2,N2,N3,D),
362 check_sub_action_nafs(Hs,N1,R2,R3,N3,N4,D).
363
364
365check_clipping([],R,R,N,N,D) :- !.
366
367check_clipping([not(clipped(T1,F,T2))|Gs],R1,R3,N1,N3,D) :-
368 !, abdemo_naf([clipped(T1,F,T2)],R1,R2,N1,N2,D),
369 check_clipping(Gs,R2,R3,N2,N3,D).
370
371check_clipping([not(declipped(T1,F,T2))|Gs],R1,R3,N1,N3,D) :-
372 !, abdemo_naf([declipped(T1,F,T2)],R1,R2,N1,N2,D),
373 check_clipping(Gs,R2,R3,N2,N3,D).
374
375check_clipping([G|Gs],R1,R2,N1,N2,D) :-
376 check_clipping(Gs,R1,R2,N1,N2,D).
377
378
379
380
382
383
392
393abresolve(terms_or_rels(A,F,T),R,Gs,R,false) :- axiom(releases(A,F,T),Gs).
394
395abresolve(terms_or_rels(A,F,T),R,Gs,R,false) :- !, axiom(terminates(A,F,T),Gs).
396
397abresolve(inits_or_rels(A,F,T),R,Gs,R,false) :- axiom(releases(A,F,T),Gs).
398
399abresolve(inits_or_rels(A,F,T),R,Gs,R,false) :- !, axiom(initiates(A,F,T),Gs).
400
414
415abresolve(happens(A,T),R1,Gs,R2,B) :- !, abresolve(happens(A,T,T),R1,Gs,R2,B).
416
417abresolve(happens(A,T1,T2),[[HA,TC],RB],[],[[HA,TC],RB],false) :-
418 member(happens(A,T1,T2),HA).
419
420abresolve(happens(A,T,T),[[HA,TC],RB],[],[[[happens(A,T,T)|HA],TC],RB],B) :-
421 executable(A), !, B = true, skolemise(T).
422
423abresolve(happens(A,T1,T2),R1,[],R2,B) :-
424 !, B = true, skolemise(T1), skolemise(T2), add_happens(A,T1,T2,R1,R2).
425
430
431abresolve(before(X,Y),R,[],R,false) :-
432 skolemise(X), skolemise(Y), demo_before(X,Y,R), !.
433
434abresolve(before(X,Y),R1,[],R2,B) :-
435 !, B = false, skolemise(X), skolemise(Y), \+ demo_beq(Y,X,R1),
436 add_before(X,Y,R1,R2).
437
442
443abresolve(diff(X,Y),R,[],R,false) :- !, X \= Y.
444
445abresolve(is(X,Y),R,[],R,false) :- !, X is Y.
446
447abresolve(G,R,[],[G|R],false) :- ec_abducible(G).
448
449abresolve(G,R,Gs,R,false) :- axiom(G,Gs).
450
451
452
453
455
456
475
476
477abdemo_nafs([],R,R,N,N,D).
478
479abdemo_nafs([N|Ns],R1,R3,N1,N3,D) :-
480 abdemo_naf(N,R1,R2,N1,N2,D), abdemo_nafs(Ns,R2,R3,N2,N3,D).
481
482
506
507abdemo_naf([clipped(T1,F,T4)|Gs1],R1,R2,N1,N2,D) :-
508 !, findall(Gs3,
509 (abresolve(terms_or_rels(A,F,T2),R1,Gs2,R1,false),
510 abresolve(happens(A,T2,T3),R1,[],R1,false),
511 append([before(T1,T3),before(T2,T4)|Gs2],Gs1,Gs3)),Gss),
512 abdemo_nafs(Gss,R1,R2,N1,N2,D).
513
514abdemo_naf([declipped(T1,F,T4)|Gs1],R1,R2,N1,N2,D) :-
515 !, findall(Gs3,
516 (abresolve(inits_or_rels(A,F,T2),R1,Gs2,R1,false),
517 abresolve(happens(A,T2,T3),R1,[],R1,false),
518 append([before(T1,T3),before(T2,T4)|Gs2],Gs1,Gs3)),Gss),
519 abdemo_nafs(Gss,R1,R2,N1,N2,D).
520
533
535
536abdemo_naf([holds_at(F1,T)|Gs1],R1,R3,N1,N3,D) :-
537 opposite(F1,F2), copy_term(Gs1,Gs2),
538 abdemo([holds_at(F2,T)],R1,R2,N1,N2,D), !,
539 abdemo_naf_cont(R1,Gs2,R2,R3,N1,N3,D).
540
541abdemo_naf([holds_at(F,T)|Gs],R1,R2,N1,N2,D) :-
542 !, abdemo_naf(Gs,R1,R2,N1,N2,D).
543
553
554abdemo_naf([before(X,Y)|Gs],R,R,N,N,D) :- X == Y, !.
555
556abdemo_naf([before(X,Y)|Gs],R,R,N,N,D) :- demo_before(Y,X,R), !.
557
558abdemo_naf([before(X,Y)|Gs1],R1,R2,N1,N2,D) :-
559 !, append(Gs1,[postponed(before(X,Y))],Gs2),
560 abdemo_naf(Gs2,R1,R2,N1,N2,D).
561
568
569abdemo_naf([postponed(before(X,Y))|Gs],R1,R2,N,N,D) :-
570 \+ demo_beq(X,Y,R1), add_before(Y,X,R1,R2).
571
572abdemo_naf([postponed(before(X,Y))|Gs],R1,R2,N1,N2,D) :-
573 !, abdemo_naf(Gs,R1,R2,N1,N2,D).
574
579
581
582abdemo_naf([not(G)|Gs1],R1,R3,N1,N3,D) :-
583 copy_term(Gs1,Gs2), abdemo([G],R1,R2,N1,N2,D), !,
584 abdemo_naf_cont(R1,Gs2,R2,R3,N1,N3,D).
585
586abdemo_naf([not(G)|Gs],R1,R2,N1,N2,D) :- !, abdemo_naf(Gs,R1,R2,N1,N2,D).
587
588abdemo_naf([G|Gs1],R,R,N,N,D) :- \+ abresolve(G,R,Gs2,R,false), !.
589
590abdemo_naf([G1|Gs1],R1,R2,N1,N2,D) :-
591 findall(Gs2,(abresolve(G1,R1,Gs3,R1,false),append(Gs3,Gs1,Gs2)),Gss),
592 abdemo_nafs(Gss,R1,R2,N1,N2,D).
593
594
601
602abdemo_naf_cont(R1,Gs,R2,R2,N,N,D).
603
604abdemo_naf_cont(R1,Gs,R2,R3,N1,N2,D) :-
605 R1 \= R2, abdemo_naf(Gs,R1,R3,N1,N2,D).
606
607
619
620
621check_nafs(false,N1,R,R,N2,N2,D) :- !. 622
623check_nafs(true,N,[[[happens(A,T1,T2)|HA],TC],RB],R,N1,N2,D) :-
624 check_nafs(A,T1,T2,N,[[[happens(A,T1,T2)|HA],TC],RB],R,N1,N2,D).
625
626check_nafs(A,T1,T2,[],R,R,N,N,D).
627
628check_nafs(A,T1,T2,[N|Ns],R1,R3,N1,N3,D) :-
629 check_naf(A,T1,T2,N,R1,R2,N1,N2,D),
630 check_nafs(A,T1,T2,Ns,R2,R3,N2,N3,D).
631
632
633check_naf(A,T2,T3,[clipped(T1,F,T4)],R1,R2,N1,N2,D) :-
634 !, findall([before(T1,T3),before(T2,T4)|Gs],
635 (abresolve(terms_or_rels(A,F,T2),R1,Gs,R1,false)),Gss),
636 abdemo_nafs(Gss,R1,R2,N1,N2,D).
637
638check_naf(A,T2,T3,[declipped(T1,F,T4)],R1,R2,N1,N2,D) :-
639 !, findall([before(T1,T3),before(T2,T4)|Gs],
640 (abresolve(inits_or_rels(A,F,T2),R1,Gs,R1,false)),Gss),
641 abdemo_nafs(Gss,R1,R2,N1,N2,D).
642
643check_naf(A,T1,T2,N,R1,R2,N1,N2,D) :- abdemo_naf(N,R1,R2,N1,N2,D).
644
645
646
647
649
650
657
658demo_before(0,Y,R) :- !, Y \= 0.
659
660demo_before(X,Y,[RH,[BA,TC]]) :- member(before(X,Y),TC).
661
663
664demo_beq(X,Y,R) :- X == Y, !.
665
666demo_beq(X,Y,R) :- demo_before(X,Y,R), !.
667
668demo_beq(X,Y,[[HA,TC],RB]) :- member(beq(X,Y),TC).
669
670
677
678add_before(X,Y,[RH,[BA,TC]],[RH,[BA,TC]]) :- member(before(X,Y),TC), !.
679
680add_before(X,Y,[[HA,HC],[BA,BC1]],[[HA,HC],[[before(X,Y)|BA],BC2]]) :-
681 \+ demo_beq(Y,X,[[HA,HC],[BA,BC1]]), find_bef_connections(X,Y,BC1,C1,C2),
682 find_beq_connections(X,Y,HC,C3,C4), delete_abdemo(X,C3,C5), delete_abdemo(Y,C4,C6),
683 append(C5,C1,C7), append(C6,C2,C8),
684 cross_prod_bef(C7,C8,C9,BC1), append(C9,BC1,BC2).
685
693
694add_happens(A,T1,T2,[[HA,HC1],[BA,BC1]],[[[happens(A,T1,T2)|HA],HC2],[BA,BC2]]) :-
695 \+ demo_before(T2,T1,[[HA,HC1],[BA,BC1]]),
696 find_beq_connections(T1,T2,HC1,C1,C2), cross_prod_beq(C1,C2,C3,HC1),
697 append(C3,HC1,HC2), find_bef_connections(T1,T2,BC1,C4,C5),
698 cross_prod_bef(C4,C5,C6,BC1), delete_abdemo(before(T1,T2),C6,C7),
699 append(C7,BC1,BC2).
700
706
707find_bef_connections(X,Y,[],[X],[Y]).
708
709find_bef_connections(X,Y,[before(Z,X)|R],[Z|C1],C2) :-
710 !, find_bef_connections(X,Y,R,C1,C2).
711
712find_bef_connections(X,Y,[before(Y,Z)|R],C1,[Z|C2]) :-
713 !, find_bef_connections(X,Y,R,C1,C2).
714
715find_bef_connections(X,Y,[before(Z1,Z2)|R],C1,C2) :-
716 find_bef_connections(X,Y,R,C1,C2).
717
722
723find_beq_connections(X,Y,[],[X],[Y]).
724
725find_beq_connections(X,Y,[beq(Z,X)|R],[Z|C1],C2) :-
726 !, find_beq_connections(X,Y,R,C1,C2).
727
728find_beq_connections(X,Y,[beq(Y,Z)|R],C1,[Z|C2]) :-
729 !, find_beq_connections(X,Y,R,C1,C2).
730
731find_beq_connections(X,Y,[beq(Z1,Z2)|R],C1,C2) :-
732 find_beq_connections(X,Y,R,C1,C2).
733
734
735cross_prod_bef([],C,[],R).
736
737cross_prod_bef([X|C1],C2,R3,R) :-
738 cross_one_bef(X,C2,R1,R), cross_prod_bef(C1,C2,R2,R), append(R1,R2,R3).
739
740cross_one_bef(X,[],[],R).
741
742cross_one_bef(X,[Y|C],[before(X,Y)|R1],R) :-
743 \+ member(before(X,Y),R), !, cross_one_bef(X,C,R1,R).
744
745cross_one_bef(X,[Y|C],R1,R) :- cross_one_bef(X,C,R1,R).
746
747
748cross_prod_beq([],C,[],R).
749
750cross_prod_beq([X|C1],C2,R3,R) :-
751 cross_one_beq(X,C2,R1,R), cross_prod_beq(C1,C2,R2,R), append(R1,R2,R3).
752
753cross_one_beq(X,[],[],R).
754
755cross_one_beq(X,[Y|C],[beq(X,Y)|R1],R) :-
756 \+ member(beq(X,Y),R), !, cross_one_beq(X,C,R1,R).
757
758cross_one_beq(X,[Y|C],R1,R) :- cross_one_beq(X,C,R1,R).
759
760
761
762
764
765
794
795refine([[HA1,HC1],[BA1,BC1]],N1,Gs,[[HA2,HC2],[BA2,BC2]],N3) :-
796 split_happens(HA1,[BA1,BC1],happens(A,T1,T2),HA2),
797 split_beqs(HC1,T1,T2,T3,T4,HC3,HC2),
798 split_befores(BA1,T1,T2,T3,T4,BA3,BA2),
799 split_befores(BC1,T1,T2,T3,T4,BC3,BC2),
800 split_nafs(N1,T1,T2,T3,T4,N2,N3),
801 append([expand([happens(A,T3,T4)|BA3])],N2,Gs).
802
803
809
810split_happens([happens(A,T1,T2)],RB,happens(A,T1,T2),[]) :- !.
811
812split_happens([happens(A1,T1,T2)|RH1],RB,happens(A3,T5,T6),
813 [happens(A4,T7,T8)|RH2]) :-
814 split_happens(RH1,RB,happens(A2,T3,T4),RH2),
815 order(happens(A1,T1,T2),happens(A2,T3,T4),RB,
816 happens(A3,T5,T6),happens(A4,T7,T8)).
817
818
819order(happens(A1,T1,T2),happens(A2,T3,T4),RB,
820 happens(A1,T1,T2),happens(A2,T3,T4)) :-
821 \+ executable(A1), executable(A2), !.
822
823order(happens(A1,T1,T2),happens(A2,T3,T4),RB,
824 happens(A2,T3,T4),happens(A1,T1,T2)) :-
825 \+ executable(A2), executable(A1), !.
826
827order(happens(A1,T1,T2),happens(A2,T3,T4),RB,
828 happens(A1,T1,T2),happens(A2,T3,T4)) :-
829 demo_before(T1,T3,[[],RB]), !.
830
831order(happens(A1,T1,T2),happens(A2,T3,T4),RB,happens(A2,T3,T4),happens(A1,T1,T2)).
832
833
834split_befores([],T1,T2,T3,T4,[],[]).
835
836split_befores([before(T1,T2)|Bs1],T3,T4,T5,T6,Bs2,[before(T1,T2)|Bs3]) :-
837 no_match(T1,T2,T3,T4), !, split_befores(Bs1,T3,T4,T5,T6,Bs2,Bs3).
838
839split_befores([before(T1,T2)|Bs1],T3,T4,T5,T6,[before(T7,T8)|Bs2],Bs3) :-
840 substitute_time(T1,T3,T4,T5,T6,T7), substitute_time(T2,T3,T4,T5,T6,T8),
841 split_befores(Bs1,T3,T4,T5,T6,Bs2,Bs3).
842
843
844split_beqs([],T1,T2,T3,T4,[],[]).
845
846split_beqs([beq(T1,T2)|Bs1],T3,T4,T5,T6,Bs2,[beq(T1,T2)|Bs3]) :-
847 no_match(T1,T2,T3,T4), !, split_beqs(Bs1,T3,T4,T5,T6,Bs2,Bs3).
848
849split_beqs([beq(T1,T2)|Bs1],T3,T4,T5,T6,[beq(T7,T8)|Bs2],Bs3) :-
850 substitute_time(T1,T3,T4,T5,T6,T7), substitute_time(T2,T3,T4,T5,T6,T8),
851 split_beqs(Bs1,T3,T4,T5,T6,Bs2,Bs3).
852
853
854split_nafs([],T1,T2,T3,T4,[],[]).
855
856split_nafs([[clipped(T1,F,T2)]|Bs1],T3,T4,T5,T6,Bs2,[[clipped(T1,F,T2)]|Bs3]) :-
857 no_match(T1,T2,T3,T4), !, split_nafs(Bs1,T3,T4,T5,T6,Bs2,Bs3).
858
859split_nafs([[clipped(T1,F,T2)]|Bs1],T3,T4,T5,T6,
860 [not(clipped(T7,F,T8))|Bs2],Bs3) :-
861 !, substitute_time(T1,T3,T4,T5,T6,T7), substitute_time(T2,T3,T4,T5,T6,T8),
862 split_nafs(Bs1,T3,T4,T5,T6,Bs2,Bs3).
863
864split_nafs([[declipped(T1,F,T2)]|Bs1],T3,T4,T5,T6,Bs2,
865 [[declipped(T1,F,T2)]|Bs3]) :-
866 no_match(T1,T2,T3,T4), !, split_nafs(Bs1,T3,T4,T5,T6,Bs2,Bs3).
867
868split_nafs([[declipped(T1,F,T2)]|Bs1],T3,T4,T5,T6,
869 [not(declipped(T7,F,T8))|Bs2],Bs3) :-
870 !, substitute_time(T1,T3,T4,T5,T6,T7), substitute_time(T2,T3,T4,T5,T6,T8),
871 split_nafs(Bs1,T3,T4,T5,T6,Bs2,Bs3).
872
873split_nafs([N|Bs1],T3,T4,T5,T6,Bs2,[N|Bs3]) :-
874 substitute_time(T1,T3,T4,T5,T6,T7), substitute_time(T2,T3,T4,T5,T6,T8),
875 split_nafs(Bs1,T3,T4,T5,T6,Bs2,Bs3).
876
877
878substitute_time(T1,T1,T2,T3,T4,T3) :- !.
879
880substitute_time(T2,T1,T2,T3,T4,T4) :- !.
881
882substitute_time(T1,T2,T3,T4,T5,T1).
883
884
885no_match(T1,T2,T3,T4) :- T1 \= T3, T2 \= T3, T1 \= T4, T2 \= T4.
886
887
888
889
891
892
897
898add_neg(N,Ns,Ns) :- member(N,Ns), !.
899
900add_neg(N,Ns,[N|Ns]).
901
902
904
905append_negs([],[],[]).
906
907append_negs([N|Ns1],Ns2,Ns4) :- add_neg(N,Ns2,Ns3), append(Ns1,Ns3,Ns4).
908
909
910delete_abdemo(X,[],[]).
911
912delete_abdemo(X,[X|L],L) :- !.
913
914delete_abdemo(X,[Y|L1],[Y|L2]) :- delete_abdemo(X,L1,L2).
915
916
918
919skolemise(T) :- var(T), gensym(t,T), !.
920
921skolemise(T).
922
923
924opposite(neg(F),F) :- !.
925
926opposite(F,neg(F)).
927
928
929trace(off)