4
6
7:-op(140, fy, ~). 8:-op(160, xfy, and). 9:-op(160, xfy, or). 10:-op(180, xfy, =>). 11
13
14:-op(140, fy, sometimes). 15:-op(140, fy, always). 16:-op(140, fy, next). 17
19
20:-op(160, xfy, until). 21:-op(160, xfy, unless). 22
24
25:-op(140, fy, k). 26
32
33is_new(new(_)).
34
35is_snl_literal(unknown(_)).
36
37is_snl_literal(~ unknown(_)).
38
39is_modal(k L):-
40 is_literal(L).
41
42is_modal(~ k L):-
43 is_literal(L).
44
45is_modal_literal(L):-
46 is_modal(L).
47
48is_modal_literal(L):-
49 is_literal(L).
50
56
57is_literal([_]):- !,fail. 58 59is_literal([_|_]):-!,fail.
60
61is_literal(~ X):-
62 is_literal(X).
63
64is_literal(X):-
65 is_proposition(X).
66
67is_literal(X):-
68 is_constant(X).
69
70is_not_literal(~ X):- !,
71 is_not_proposition(X).
72
73is_not_literal(X):-
74 is_not_proposition(X).
75
76
82
83is_constant(true).
84is_constant(false).
85is_constant(start).
86
92
93is_proposition(Formula) :-
94 \+(is_not_proposition(Formula)).
95
102
103is_not_proposition([]).
104is_not_proposition(X) :- is_constant(X).
105is_not_proposition(_ and _).
106is_not_proposition(_ or _).
107is_not_proposition(~ _).
108is_not_proposition(sometimes _).
109is_not_proposition(always _).
110is_not_proposition(_ => _).
111is_not_proposition(next _).
112is_not_proposition(k _).
113is_not_proposition(_ until _).
114is_not_proposition(_ unless _).
115
120
121conjunctive(_ and _).
122conjunctive(~(_ or _)).
123conjunctive(~(_ => _)).
124
129
130disjunctive(~(_ and _)).
131disjunctive(_ or _).
132disjunctive(_ => _).
133
139
141
142:-dynamic predcount/1. 143
145
146:-dynamic rulecount/1. 147
148:-dynamic clear/0. 149
151
152predcount(1).
153rulecount(1).
154
155clear :-retract(predcount(_)),
156 assert(predcount(1)).
157
158
166
167newpredcount(N) :- predcount(N),
168 retract(predcount(N)),
169 M is N+1,
170 assert(predcount(M)).
171
172startrulecount(N) :- rulecount(N),
173 retract(rulecount(N)),
174 assert(rulecount(1)).
175startrulecount(1).
176
177newrulecount(N) :- rulecount(N),
178 retract(rulecount(N)),
179 M is N+1,
180 assert(rulecount(M)).
181
185
186new_temp_prop(V):- newpredcount(N),
187 term_to_atom(N,NN),
188 string_concat('tmpp',NN,NV),
189 atom_to_term(NV,V,_).
190
191new_dontknow_prop(X,X):- is_snl_literal(X).
192new_dontknow_prop(V,X):- V=.. [unknown|[X]].
193
194new_conj_prop(V,true):-V=[true].
195new_conj_prop(V,X):- V=.. [new|[X]].
196
200
202
206
208
209 my_writef(X,Y):-writef(X,Y).
210 my_write(X):-write(X).
211
215
216write_ruleset((Initial,Literal,Modal,Temporal)) :-
217 nl,write('Initial Clauses'),nl,
218 write('['), nl, write_ruleset1(Initial),!, write(']'), nl,
219 nl,write('Literal Clauses'),nl,
220 write('['), nl, write_ruleset1(Literal),!, write(']'), nl,
221 nl,write('Modal Clauses'),nl,
222 write('['), nl, write_ruleset1(Modal),!, write(']'), nl,
223 nl,write('Temporal Clauses'),nl,
224 write('['), nl, write_ruleset1(Temporal),!, write(']'), nl.
225
226write_ruleset(Ruleset) :-
227 write('['), nl, write_ruleset1(Ruleset),!, write(']'), nl.
228
229write_ruleset1([Rule | Rest]) :-
230 write(' '), write_form(Rule), nl, write_ruleset1(Rest).
231
232write_ruleset1([]).
233
237
238write_form(r(X,Y,false)) :-
239 write(X),
240 write(' '),
241 write(Y),
242 write(' '),
243 write(' false ').
244
245write_form(r(X,Y,P)) :-
246 write(X),
247 write(' '),
248 write(Y),
249 write(' '),
250 write_form(P).
251
252write_form(P => F) :-
253 write_form(P),
254 write(' => '),
255 write_form(F).
256
258write_form(~ X) :-
259 write('~'), !,
260 write_form(X).
261write_form(- X) :-
262 write('~'), !,
263 write_form(X).
264
265
266write_form(X and Y) :-
267 write('('),
268 !,
269 write_form(X),
270 write(' & '),
271 write_form(Y),
272 write(')').
273
274write_form(X or Y) :-
275 write('('),
276 !,
277 write_form(X),
278 write(' | '),
279 write_form(Y),
280 write(')').
281
282write_form(X until Y) :-
283 write('('),
284 !,
285 write_form(X),
286 write(' U '),
287 write_form(Y),
288 write(')').
289
290write_form(X unless Y) :-
291 write('('),
292 !,
293 write_form(X),
294 write(' W '),
295 write_form(Y),
296 write(')').
297
298write_form(next X) :- write('O'), !, write_form(X).
299write_form(sometimes X) :- write('<>'), !, write_form(X).
300write_form(always X) :- write('[]'), !, write_form(X).
301write_form(k X) :- write('k'), !, write_form(X).
302write_form(new(X)) :- write('new('),!,write_form(X),write(')').
303write_form(unknown(X)) :- write('unknown('),!,write_form(X),write(')').
304write_form(X) :- write(X).
305
306
317
318write_otter_rules(X,Y,Z):-
319 write_otter_rules(X),
320 write_otter_rules(Y),
321 write_otter_rules(Z).
322
323write_otter_rules(X,Y):-
324 write_otter_rules(X),
325 write_otter_rules(Y).
326
327write_otter_rules([]).
328
329write_otter_rules([r(_,_,Rule)|RRest]):-
330 write_otter_rule(Rule),
331 write_otter_rules(RRest).
332
333write_otter_rules([Rule|RRest]):-
334 write_otter_rule(Rule),
335 write_otter_rules(RRest).
336
347
348write_otter_rule(B):-
349 disjunction_of_literals(B),!,
350 write_otter_disjunct(B),
351 write('.'),nl.
352
353write_otter_rule(A => next B):-
354 write_otter_conjunct(A),
355 write(' | '),
356 write_otter_disjunct(B),
357 write('.'),nl.
358
367
368write_otter_conjunct(false):-
369 write('$F').
370
371write_otter_conjunct(tmp_p(X)):-
372 write('-slast_tmp_p_'),
373 write(X).
374
375write_otter_conjunct(~ A):-
376 write('-slast_neg_'),
377 write(A).
378
379write_otter_conjunct(new(X)):-
380 trace,
381 write('-slast_new_'),
382 write_otter_and_proposition(X).
383
384write_otter_conjunct(unknown(X)):-
385 write('-slast_nkn_'),
386 write_otter_proposition(X).
387
388write_otter_conjunct(A):-
389 is_literal(A),
390 write('-slast_'),
391 write(A).
392
393write_otter_conjunct(A and B):-
394 write_otter_conjunct(A),
395 write(' | '),
396 write_otter_conjunct(B).
397
398
408
409write_otter_disjunct(false):-
410 write('$F').
411
412write_otter_disjunct(~ A):-
413 write('-'),
414 write_otter_disjunct(A).
415
416write_otter_disjunct(tmp_p(X)):-
417 write('s_tmp_p_'),
418 write(X).
419
420write_otter_disjunct(new(X)):-
421 write('s_new_'),
422 write_otter_and_proposition(X).
423
424write_otter_disjunct(unknown(X)):-
425 write('s_nkn_'),
426 write_otter_proposition(X).
427
428write_otter_disjunct(A):-
429 is_literal(A),
430 write('s_'),
431 write(A).
432
433write_otter_disjunct(A or B):-
434 write_otter_disjunct(A),
435 write(' | '),
436 write_otter_disjunct(B).
437
442
443write_otter_proposition(~ X):-
444 write('neg_'),
445 write_otter_proposition(X).
446
447write_otter_proposition(new(X)):-
448 write('new_'),
449 write_otter_and_proposition(X).
450
451write_otter_proposition(unknown(X)):-
452 write('nkn_'),
453 write_otter_proposition(X).
454
455write_otter_proposition(X):-
456 is_literal(X),
457 write(X).
458
464
465write_otter_and_proposition(tmp_p(X) and B):-
466 write_otter_and_proposition(B and tmp_p(X)).
467
468write_otter_and_proposition(A and B):-
469 write_otter_and_proposition(A),
470 write('_'),
471 write_otter_and_proposition(B).
472
473write_otter_and_proposition(A):-
474 write_otter_proposition(A).
475
483
484write_list([]).
485
486write_list([[Rule,Path]|Rest]):-
487 write(' ['),
488 write_form(Rule),
489 write(', '),
490 write(Path),
491 write(' ]\n'),
492 write_list(Rest).
493
494
501
502number_rules([],_FromList,[]):-!.
503
504number_rules([Rule|Rest],FromList,[NewRule|NewRest]):-
505 number_rule(Rule,FromList,NewRule),
506 number_rules(Rest,FromList,NewRest).
507
508number_rule(r(N1,N2,Clause),_,r(N1,N2,Clause)).
509number_rule(Rule,FromList,r(N,FromList,Rule)):-
510 newrulecount(N).
511
522
523dis_implies(true => B, _C => B):-!.
524dis_implies(_A => B, true => B):-!.
525dis_implies(A => B, A => B):-!.
526
532
533dis_implies(_A => _B, _C):-fail,!.
534
535dis_implies(A, NegA => _C):-
536 is_literal(A),!,
537 snff_negate(A,NegA).
538
540
541dis_implies(A,B):-!,
542 list_strip_or(A,A1),
543 list_strip_or(B,B1),
544 subset(A1,B1).
545
547
548set_implies([],_):-!.
549
550set_implies(X,X):-!.
551
552set_implies(_,[[true]]):-!.
553
554set_implies(_,[true]):-!.
555
556set_implies([[false]],_):-!.
557
558set_implies([false],_):-!.
559
560set_implies([H|Tail],[H1]):-
561 is_literal(H1),
562 is_literal(H),!,
563 member(H1,[H|Tail]).
564
565set_implies([H1|Tail1],[H2|Tail2]):-
566 is_literal(H1),
567 is_literal(H2),!,
568 subset([H2|Tail2],[H1|Tail1]).
569
570set_implies([H1],[H|Tail]):-
571 is_modal_literal(H1),
572 is_modal_literal(H),!,
573 modal_member(H1,[H|Tail]).
574
575set_implies([H1|Tail1],[H2|Tail2]):-
576 is_modal_literal(H1),
577 is_modal_literal(H2),!,
578 modal_subset([H1|Tail1],[H2|Tail2]).
579
580set_implies([H1],[H2|Tail2]):-
581 is_literal(H1),!,
582 is_superset_of_member_of_list([H1],[H2|Tail2]).
583
584set_implies([H1|Tail1],[H2|Tail2]):-
585 is_literal(H1),!,
586 is_superset_of_member_of_list([H1|Tail1],[H2|Tail2]).
587
588set_implies([H1|Tail1],[H2|Tail2]):-
589 is_literal(H2),!,
590 set_implies(H1,[H2|Tail2]),
591 set_implies(Tail1,[H2|Tail2]).
592
593set_implies([H1|List1],List2):-
594 set_implies(H1,List2),
595 set_implies(List1,List2).
596
603
604strip(X or Y, AList):-
605 strip(X, XList),
606 strip(Y, YList),
607 append(XList, YList, AList), !. 608
609strip(X and Y, AList):-
610 strip(X, XList),
611 strip(Y, YList),
612 append(XList, YList, AList), !. 613
614strip(X, [X]).
615
617
618list_strip_or(X or Y,NewXY):-
619 list_strip_or(X,NewX),
620 list_strip_or(Y,NewY),
621 append(NewX,NewY,NewXY),!.
622
623list_strip_or(X,[NewX]):-
624 simplify_and(X,NewX).
625
632
633strip_or(X or Y, NewXY):-
634 strip_or(X, NewX),
635 strip_or(Y, NewY),
636 append(NewX, NewY, NewXY),!.
637
638strip_or(X and Y, [NewXY]):-
639 strip(X and Y, NewXY),!.
640
641strip_or(X,[[X]]) :- !.
642
649
650strip_and(X and Y, NewXY):-
651 strip_and(X, NewX),
652 strip_and(Y, NewY),
653 append(NewX, NewY, NewXY),!.
654
655strip_and(X or Y, [NewXY]):-
656 strip(X or Y, NewXY),!.
657
658strip_and(X,[[X]]) :- !.
659
661
662member_of_2nd_is_subset_of_1st([],List1,[_|Tail2]):-
663 member_of_2nd_is_subset_of_1st(List1,List1,Tail2),!.
664
665member_of_2nd_is_subset_of_1st([H1|_],_,[H2|_]):-
666 subset(H2,H1),!.
667
668member_of_2nd_is_subset_of_1st([_|Tail1],List1, [H2|Tail2]):-
669 member_of_2nd_is_subset_of_1st(Tail1,List1, [H2|Tail2]),!.
670
672
673modal_subset([],_):-!.
674
675modal_subset(X, X):-!.
676
677modal_subset([H |Tail], BList) :-
678 modal_member(H, BList),!,
679 modal_subset(Tail, BList).
680
685
686modal_member(X, [X | _]):- !.
687
688modal_member(X, [sometimes X|_]):- !.
689
690modal_member(X, [~ always ~ X|_]):- !.
691
692modal_member(X, [_ | Tail]) :- modal_member(X, Tail).
693
697
707
708simplify([],[]).
709simplify([Rule | Rest], NewRules) :-
710 simplify_rule(Rule, SRule),
711 simplify(Rest, NewRest),
712 append(SRule, NewRest, NewRules).
713
724
725simplify_rule(r(N1,N2,X => Y),[r(N1,N2,NewR)]):-
726 is_modal_rule(X => Y),
727 snff_negate(X, NegX),
728 simplify_rule(r(N1,N2,NegX or Y),[r(N1,N2,R)]),
729 change_form(R,[NewR]).
730
731simplify_rule(r(N1,N2,R), FinalSet) :-
732 simplify_true_false(R,U),
733 remove_true_rules(r(N1,N2,U),RuleSet), 734 735 expand_false_rules(RuleSet, FinalSet).
736
745
746simplify_true_false(P => next F, NewP => next NewF ) :-
747 simplify_and(P, NewishP),
748 simplify_and_dup(NewishP, NewP),
749 simplify_or(F,NewishF),
750 simplify_or_dup(NewishF, NewList),
751 disjoin(NewList,NewF).
752
753simplify_true_false(F, NewF) :-
754 disjunction_of_modal_literals(F),
755 simplify_or(F,NewishF),
756 simplify_or_dup(NewishF, NewerF),
757 simplify_or_modal(NewerF,NewList),
758 disjoin(NewList, NewF).
759
767
768simplify_and(A and true, NewA) :- simplify_and(A, NewA),!.
769
770simplify_and(true and A, NewA) :- simplify_and(A, NewA),!.
771
772simplify_and(_ and false, false):-!.
773
774simplify_and(false and _, false):-!.
775
776simplify_and(A and _, false) :- simplify_and(A, false),!.
777
778simplify_and(_ and B, false) :- simplify_and(B, false),!.
779
780simplify_and(A and B, NewB) :-
781 simplify_and(A, true),!,
782 simplify_and(B, NewB).
783
784simplify_and(A and B, NewA) :-
785 simplify_and(B, true),!,
786 simplify_and(A, NewA).
787
788simplify_and(A and B, NewA and NewB) :-
789 simplify_and(A, NewA),
790 simplify_and(B, NewB),!.
791
792simplify_and(~ ~ P, NewP):-
793 simplify_and(P, NewP).
794
795simplify_and(~ true,false).
796
797simplify_and(~ false,true).
798
799simplify_and(P, P).
800
801
809
810simplify_and_dup(A, false):- 811 strip(A, AList),
812 comp_lits_and(AList),!.
813
814simplify_and_dup(A, NewA):-
815 strip(A, AList),
816 remove_duplicate(AList, NewList),
817 conjoin(NewList, NewA).
818
825
826remove_duplicate(false,false):- !.
827
828remove_duplicate(List1,List2):-
829 list_to_set(List1,List2).
830
831
839
840simplify_or(A or false, NewA) :- simplify_or(A, NewA).
841
842simplify_or(false or A, NewA) :- simplify_or(A, NewA).
843
844simplify_or(_ or true, true).
845
846simplify_or(true or _, true).
847
848simplify_or(A or _, true) :- simplify_or(A, true).
849
850simplify_or(_ or B, true) :- simplify_or(B, true).
851
852simplify_or(A or B, NewB) :-
853 simplify_or(A, false),
854 simplify_or(B, NewB).
855
856simplify_or(A or B, NewA) :-
857 simplify_or(B, false),
858 simplify_or(A, NewA).
859
860simplify_or(A or B, NewA or NewB) :-
861 simplify_or(A, NewA),
862 simplify_or(B, NewB).
863
864simplify_or(~ ~ P, NewP):-
865 simplify_or(P,NewP).
866
867simplify_or(~ true,false).
868
869simplify_or(~ false,true).
870
871simplify_or(P, P).
872
880
881simplify_or_dup(A, [true]):- 882 strip(A, AList),
883 check_comp_lits(AList).
884
885simplify_or_dup(A, [true]):- 886 strip(A, AList),
887 check_modal_lits(AList).
888
889simplify_or_dup(A, NewList):-
890 strip(A, AList),
891 remove_duplicate(AList, NewList).
892
894
895check_comp_lits(AList):-
896 comp_lits_and(AList).
897
899
900check_modal_lits(AList):-
901 modal_lits_and(AList).
902
904
905simplify_or_modal([],[]):-!.
906
907simplify_or_modal([~ k ~ L|Rest],[~ k ~ L |Final]):-
908 remove_member(L,Rest, NewerRest), !, 909 remove_member(k L,NewerRest, NewestRest), 910 simplify_or_modal(NewestRest,Final).
911
912simplify_or_modal([k L|Rest],Final):-
913 member(L,Rest), !, 914 simplify_or_modal(Rest,Final).
915
916simplify_or_modal([k L|Rest],Final):-
917 member(~ k ~ L,Rest), !, 918 simplify_or_modal(Rest,Final).
919
920simplify_or_modal([k L|Rest],[k L|Final]):-
921 simplify_or_modal(Rest,Final).
922
923simplify_or_modal([L|Rest],Final):-
924 member(~ k ~ L,Rest), !, 925 remove_member(k L,Rest, NewerRest), 926 simplify_or_modal(NewerRest,Final).
927
928simplify_or_modal([L|Rest],[L|Final]):-
929 remove_member(k L,Rest, NewerRest), 930 simplify_or_modal(NewerRest,Final).
931
932simplify_or_modal([L|Rest],[L|Final]):-
933 simplify_or_modal(Rest,Final).
934
936
937comp_lits(X,Y):-
938 negate_modal_lit(X,Y).
939
945
946comp_lits_and([H|Tail]):-
947 negate_modal_lit(H, NegH),
948 member(NegH,Tail).
949
950comp_lits_and([_|Tail]):-
951 comp_lits_and(Tail).
952
954
955modal_lits_and([sometimes X|List]):- !,
956 negate_modal_lit(X,NegX),
957 member(NegX,List).
958
959modal_lits_and([always _|List]):- !,
960 modal_lits_and(List).
961
962modal_lits_and([X|List]):- !,
963 negate_modal_lit(X,NegX),
964 member(sometimes NegX,List).
965
966modal_lits_and([_|List]):- !,
967 modal_lits_and(List).
968
974
975comp_lits_or([H|Tail]):-
976 negate_all(H, NegH),
977 node_is_member_of(NegH,Tail).
978
979comp_lits_or([_|Tail]):-
980 comp_lits_or(Tail).
981
989
990negate_all([],[]).
991
992negate_all([H|Tail],[NegH|NewTail]):-
993 negate_modal_lit(H, NegH),
994 negate_all(Tail,NewTail).
995
1005
1006remove_true_rules( r(N1,N2,_ => true), r(N1,N2,[])).
1007remove_true_rules( r(N1,N2,_ => next true), r(N1,N2,[])).
1008remove_true_rules( r(N1,N2,true),r(N1,N2,[])).
1009remove_true_rules( R, [R] ).
1010
1026
1027expand_false_rules(r(_,_,[]),[]):-!.
1028
1029expand_false_rules([],[]):-!.
1030
1031expand_false_rules( [r(_,N2, P => next false)|Rest ], [r(NewR1,N2,NegP)|NewRules ] ) :-
1032 snff_negate(P, NegP),
1033 newrulecount(NewR1),
1034 expand_false_rules(Rest, NewRules).
1035
1036expand_false_rules( [ Other | Rest ], [ Other | NewRest ] ) :-
1037 expand_false_rules(Rest, NewRest).
1038
1045
1046disjoin([], false):-!.
1047disjoin(List, Form) :- disjoin2(List, Form).
1048
1050
1051disjoin2([F|[]], F):-!.
1052disjoin2([F | Rest], F or NewForm) :- disjoin2(Rest, NewForm).
1053
1061
1062conjoin([], true):-!.
1063conjoin(List, Form) :- conjoin2(List, Form).
1064
1066
1067conjoin2([F|[]],F):-!.
1068conjoin2([F | Rest], F and NewForm) :- conjoin2(Rest, NewForm).
1069
1078
1079is_superset_of_member_of_list(Node, [H|_]):-
1080 subset(H, Node).
1081
1082is_superset_of_member_of_list(Node, [_|List]):-
1083 is_superset_of_member_of_list(Node, List).
1084
1094
1095node_is_member_of(NewNode, [Node|_]):-
1096 same(NewNode, Node), !.
1097
1098node_is_member_of(NewNode, [_|OldNodes]):-
1099 node_is_member_of(NewNode, OldNodes).
1100
1108
1109same(X,X) :- !.
1110
1111same(X,Y):-
1112 subset(X,Y),!,
1113 subset(Y,X).
1114
1122
1123remove_duplicate_nodes([],[]):-!.
1124
1125remove_duplicate_nodes([Node|NodeList], NewNodes):-
1126 node_is_member_of(Node, NodeList), !,
1127 remove_duplicate_nodes(NodeList, NewNodes).
1128
1129remove_duplicate_nodes([Node|NodeList], [Node|NewNodes]):-
1130 remove_duplicate_nodes(NodeList, NewNodes).
1131
1133
1134remove_member(X,[X|Rest],NewList):-
1135 remove_member(X,Rest,NewList).
1136
1137remove_member(X,[Y|Rest],[Y|NewList]):-
1138 remove_member(X,Rest,NewList).
1139
1140remove_member(_,[],[]).
1141
1148
1149rewrite_and_or([H], NewH):-
1150 conjoin(H,NewH).
1151
1152rewrite_and_or([H|Tail], NewH or NewTail):-
1153 conjoin(H, NewH),
1154 rewrite_and_or(Tail, NewTail).
1155
1157
1158negate_modal_lit(~ k ~ X, k ~ X).
1159
1160negate_modal_lit(k ~ X, ~ k ~ X).
1161
1162negate_modal_lit(~ k X, k X).
1163
1164negate_modal_lit(k X, ~ k X).
1165
1166negate_modal_lit(~ X, X).
1167
1168negate_modal_lit(X, ~ X).
1169
1170
1173
1177
1178snff([],[]).
1179
1180snff(Final, Final) :-
1181 snff_in_form_list(Final).
1182
1183snff(Initial, Final) :-
1184 snff_anchor_to_start(Initial,Anchored),
1185 snff_rewrite_list(Anchored,Final).
1186
1190
1191snff_anchor_to_start([],[]):-!.
1192
1193snff_anchor_to_start([H|Tail], [H|NewRest]):-
1194 in_form(H),
1195 snff_anchor_to_start(Tail,NewRest).
1199snff_anchor_to_start([H|Tail], [start => V, V => (H)|NewRest]):-
1200 new_temp_prop(V),
1201 snff_anchor_to_start(Tail, NewRest).
1202
1206
1207snff_rewrite_list([],[]):-!.
1208snff_rewrite_list([Rule|Rest],[Rule|NewRest]):-
1209 in_form(Rule),
1210 snff_rewrite_list(Rest,NewRest).
1211
1212snff_rewrite_list([Rule|Rest],Other):-
1213 snff_rewrites(Rule,NewRule, NewInform),
1214 snff_rewrite_list(NewRule,NewerRule),
1215 append(NewInform,NewerRule,FinalRule),
1216 snff_rewrite_list(Rest,NewRest),
1217 append(FinalRule,NewRest,Other).
1218
1222
1223snff_rewrites(X => (A and B),[X => A, X => B],[]).
1224
1225snff_rewrites(X => ~(A and B),[X => ~ A or ~ B],[]).
1226
1227snff_rewrites(X => (A => B),[X => ~ A or B],[]).
1228
1229snff_rewrites(X => ~ (A => B),[X => A, X => ~ B],[]).
1230
1231snff_rewrites(X => ~ ~ A ,[X => A],[]).
1232
1233snff_rewrites(X => k A,[X => ~ V],[V => k A, ~ V => k A]):-
1234 is_literal(A),
1235 simplify_and(~ A,NewA),
1236 new_dontknow_prop(V,NewA).
1237
1238snff_rewrites(X => k A ,[V => A],[X => k V]):-
1239 is_not_literal(A),
1240 new_temp_prop(V).
1241
1242snff_rewrites(X => ~ k A ,[X => V],[V => ~ k A, ~ V => k A]):-
1243 is_literal(A),
1244 simplify_and(~ A, NewA),
1245 new_dontknow_prop(V,NewA).
1246
1247snff_rewrites(X => ~ k A ,[X => ~ k ~ V, V => ~ A],[]):-
1248 is_not_literal(A),
1249 new_temp_prop(V).
1250
1251snff_rewrites(X => A or B, Rest,[NegX or NewA or NewB]):-
1252 snff_negate(X,NegX),
1253 check_dnf(A, NewA, ARest),
1254 check_dnf(B, NewB, BRest),
1255 append(ARest,BRest,Rest).
1256
1257snff_rewrites(X => next A ,[V => A],[X => next V]):-
1259 new_temp_prop(V).
1260
1261snff_rewrites(X => ~ next A,[X => next ~ A],[]).
1262
1263snff_rewrites(X => (A until B),[X => V until B, V => A],[]):-
1264 is_not_literal(A),
1265 new_temp_prop(V).
1266
1267snff_rewrites(X => (A until B),[X => A until V, V => B],[]):-
1268 is_not_literal(B),
1269 new_temp_prop(V).
1270
1271snff_rewrites(X => (A until B),[],[~ X or B or A, ~ X or B or V, V => next (B or A), V => next (B or V), X => sometimes B]):-
1272 is_literal(A),
1273 is_literal(B),
1274 new_temp_prop(V).
1275
1276snff_rewrites(X => ~ (A until B),[X => ((~ B) unless (~ A and ~ B))],[]).
1277
1278snff_rewrites(X => (A unless B),[X => V unless B, V => A],[]):-
1279 is_not_literal(A),
1280 new_temp_prop(V).
1281
1282snff_rewrites(X => (A unless B) ,[X => A unless V, V => B],[]):-
1283 is_not_literal(B),
1284 new_temp_prop(V).
1285
1286snff_rewrites(X => (A unless B) ,[],[~ X or B or A, ~ X or B or V, V => next (B or A), V => next (B or V)]):-
1287 is_literal(A),
1288 is_literal(B),
1289 new_temp_prop(V).
1290
1291snff_rewrites(X => ~ (A unless B) ,[X => ((~ B) until (~ A and ~ B))],[]).
1292
1293snff_rewrites(X => (sometimes A) ,[V => A],[X => sometimes V]):-
1294 is_not_literal(A),
1295 new_temp_prop(V).
1296
1297snff_rewrites(X => (~ sometimes A) ,[X => always ~ A],[]).
1298
1299snff_rewrites(X => (always A) ,[X => always V , V => A],[]):-
1300 is_not_literal(A),
1301 new_temp_prop(V).
1302
1303snff_rewrites(X => (always A) ,[],[~ X or A, V => next A, ~ X or V, V => next V]):-
1304 is_literal(A),
1305 new_temp_prop(V).
1306
1307snff_rewrites(X => (~ always A) ,[X => sometimes ~ A ],[]).
1308
1309snff_rewrites(X => (Y),[],[~ X or Y]):-
1310 conjunction_of_literals(X),
1311 disjunction_of_modal_literals(Y).
1312
1316
1317snff_in_form_list([]):-!.
1318
1319snff_in_form_list([H|Tail]):-
1320 in_form(H),
1321 snff_in_form_list(Tail).
1322
1326
1327in_form(start => X):-
1328 disjunction_of_literals(X).
1329
1330in_form(X):-
1331 disjunction_of_literals(X).
1332
1333in_form(X => k A):-
1334 is_literal(X),
1335 is_literal(A).
1336
1337in_form(X => ~ k A):-
1338 is_literal(X),
1339 is_literal(A).
1340
1341in_form(X => sometimes Y):-
1342 conjunction_of_literals(X),
1343 is_literal(Y).
1344
1345in_form(X => next(Y)):-
1346 conjunction_of_literals(X),
1347 disjunction_of_literals(Y).
1348
1352
1353disjunction_of_literals(X):-
1354 strip_or(X,StrippedX),
1355 is_literal_list(StrippedX).
1356
1360
1361disjunction_of_modal_literals(X):-
1362 strip_or(X,StrippedX),
1363 is_modal_literal_list(StrippedX).
1364
1368
1369conjunction_of_literals(X):-
1370 strip_and(X,StrippedX),
1371 is_literal_list(StrippedX).
1372
1376
1377is_literal_list([[H]|Tail]):-
1378 is_literal(H),
1379 is_literal_list(Tail).
1380
1381is_literal_list([]).
1382
1386
1387is_modal_literal_list([]).
1388
1389is_modal_literal_list([[k H]|Tail]):-
1390 is_literal(H),
1391 is_modal_literal_list(Tail).
1392
1393is_modal_literal_list([[~ k H]|Tail]):-
1394 is_literal(H),
1395 is_modal_literal_list(Tail).
1396
1397is_modal_literal_list([[H]|Tail]):-
1398 is_literal(H),
1399 is_modal_literal_list(Tail).
1400
1404
1405check_dnf(A or B, NewA or NewB, Rest):-
1406 check_dnf(A, NewA, ARest),
1407 check_dnf(B, NewB, BRest),
1408 append(ARest,BRest,Rest).
1409
1410check_dnf(A => B, NewAll, Rest):-
1411 check_dnf(~ A or B, NewAll, Rest).
1412
1413check_dnf(A, A, []):-
1414 is_literal(A).
1415
1416check_dnf(k A, ~ V, [V => ~ k A, ~ V => k A]):-
1417 is_literal(A),
1418 snff_negate(A,NegA),
1419 new_dontknow_prop(V,NegA).
1420
1421check_dnf(~ k A, V, [V => ~ k A, ~ V => k A]):-
1422 is_literal(A),
1423 snff_negate(A,NegA),
1424 new_dontknow_prop(V,NegA).
1425
1426check_dnf(A, V, [V => A]):-
1427 new_temp_prop(V).
1432
1433snff_negate(~ X, X):- !.
1434
1435snff_negate(X and Y, NotX or NotY):-
1436 !,
1437 snff_negate(X, NotX),
1438 snff_negate(Y, NotY).
1439
1440snff_negate(X or Y, NotX and NotY):-
1441 !,
1442 snff_negate(X, NotX),
1443 snff_negate(Y, NotY).
1444
1445snff_negate(true, false).
1446
1447snff_negate(false, true).
1448
1449snff_negate(X, ~ X):-
1450 is_proposition(X).
1451
1452
1492
1499
1500
1508
1509mres(LiteralRules,ModalRules,Initial,NewLRules,NewMRules):-
1510 cyclemres(1,[],[],LiteralRules,ModalRules,Initial,NewLRules,NewMRules).
1511
1513
1528
1529mres(OldLiteral,OldModal,NewishLiteral,NewishModal,Initial,NewLiteral,NewModal):-
1530 cyclemres(1,OldLiteral,OldModal,NewishLiteral,NewishModal,Initial,NewLiteral,NewModal).
1531
1555
1556cyclemres(_,[],[],[],[],_,[],[]).
1558
1559cyclemres(_,LRules,MRules,[],[],_,LRules,MRules):-
1561 my_write('Have generated no new resolvents,current literal/modal clauses are :-\n'),
1562 write_ruleset(LRules), 1563 write_ruleset(MRules). 1564
1565cyclemres(_,_,_,NewLRules,_,[r(_,_,X)],[r(0,[],false)],_):-
1567 snff_negate(X,NegX),
1568 test_member(NegX,NewLRules),
1569 simplify(NewLRules,SNewLRules),
1570 self_subsumption(SNewLRules,SubNewLRules),
1571 flatten(SubNewLRules,FSubNewLRules),
1572 my_write('\nNew literal clauses include (~ start).\n'),
1573 write_ruleset(FSubNewLRules), 1574 write('\nHave generated false in initial clauses.\n').
1575
1576cyclemres(_,_OldLRules,OldMRules,NewLRules,_,_,[r(0,[],false)],OldMRules):-
1578 test_member(false,NewLRules),
1579 my_write('\nNew literal clauses include false.\n'),
1580 write_ruleset(NewLRules), 1581 write('\nHave generated false in literal clauses.\n').
1582
1583cyclemres(_,_OldLRules,_OldMRules,_,NewMRules,_,[r(0,[],false)],[r(0,[],false)]):-
1585 test_member(false,NewMRules),
1586 my_write('\nNewModal clauses include false.\n'),
1587 write_ruleset(NewMRules), 1588 write('\nHave generated false in modal clauses.\n').
1589
1591
1592cyclemres(Count,OldLRules,OldMRules,NewLRules,NewMRules,Initial,NewerLRules,NewerMRules):-
1595 writef('\nCycle Number%t.',[Count]),
1596 my_k_to_literal(NewMRules,KRules),
1597 append(KRules,NewLRules,AddedNewLRules),
1598 simplify(AddedNewLRules,SimplifiedLRules),
1599 simplify(NewMRules,SimplifiedMRules),
1600 garbage_collect,
1601 subsumption(OldLRules,SimplifiedLRules,SubOldLRules,SubNewLRules1),
1602 trim_stacks,
1603 subsumption(OldMRules,SubNewLRules1,SubOldMRules1,SubNewLRules2),
1604 trim_stacks,
1605 subsumption(SimplifiedMRules,SubNewLRules2,SubNewMRules1,SubNewLRules),
1606 trim_stacks,
1607 subsumption(SubOldMRules1,SubNewMRules1,SubOldMRules,SubNewMRules),
1608 trim_stacks,
1609 my_write('\nOld Literal Clauses\n'),
1610 write_ruleset(SubOldLRules),
1611 my_write('\nOld Modal Clauses\n'),
1612 write_ruleset(SubOldMRules),
1613 my_write('\nNew Literal Clauses\n'),
1614 write_ruleset(SubNewLRules),
1615 my_write('\nNew Modal Clauses\n'),
1616 write_ruleset(SubNewMRules),
1617 do_mres(SubOldLRules,SubOldMRules,SubNewLRules,SubNewMRules,ResLRules,ResMRules,NewOldLRules,NewOldMRules),
1618 NewCount is Count + 1,!,garbage_collect,
1619 cyclemres(NewCount,NewOldLRules,NewOldMRules,ResLRules,ResMRules,Initial,NewerLRules,NewerMRules).
1620
1624
1636
1637subsumption(Old_Rules,New_Rules,New_Old_Rules,FNew_New_Rules) :-
1638 self_subsumption(New_Rules,Newish_Rules),
1639 flatten(Newish_Rules,FNewish_Rules),!,
1640 subsumption2(Old_Rules,FNewish_Rules,New_Old_Rules,New_New_Rules),
1641 flatten(New_New_Rules,FNew_New_Rules),!.
1642
1650
1651self_subsumption([],[]):-!.
1652
1653self_subsumption([R|Rest],[NewR|NewRules]):-
1654 subsume_rule(Rest,R,Remain_Rest,NewR),!,
1655 self_subsumption(Remain_Rest,NewRules).
1656
1657
1666
1667subsumption2(Old_Rules,[],Old_Rules,[]):-!.
1668
1669subsumption2([],NewRules,[],NewRules):-!.
1670
1671subsumption2(Old_Rules,[R|Rest],New_Old_Rules,[NewR|New_Rules]):-
1672 subsume_rule(Old_Rules,R,Newish_Old_Rules,NewR),!,
1673 subsumption2(Newish_Old_Rules,Rest,New_Old_Rules,New_Rules).
1674
1692
1694
1695subsume_rule([],r(N1,N2,G),[],[r(N1,N2,G)]):-!.
1696subsume_rule([],R,[],[R]):-!.
1697
1698subsume_rule([r(N1,N2,F) | Rules],r(_,_,G),[r(N1,N2,F) | Rules],[]) :-
1699 dis_implies(F,G),!. 1700
1701subsume_rule([r(_,_,F) | Rules],r(N1,N2,G),New_Old_Rules,New_New_Rules) :-
1702 dis_implies(G ,F),!, 1703 subsume_rule(Rules,r(N1,N2,G),New_Old_Rules,New_New_Rules).
1704
1706
1707subsume_rule([ R | Rules],r(N1,N2,G),[ R | New_Rules],New_New_Rules) :-
1708 subsume_rule(Rules,r(N1,N2,G),New_Rules,New_New_Rules).
1709
1711
1712subsume_rule([ R1 | Rules],R2,[ R1 | New_Old_Rules],New_New_Rules) :-
1713 subsume_rule(Rules,R2,New_Old_Rules,New_New_Rules).
1714
1715
1719
1736
1737
1738do_mres(LNewOrig,MOrigRules,LNew,RNew,FinalL,FinalM,NewOrigL2,NewOrigM2):-
1740 do_mres(LNewOrig,MOrigRules,LNew,FinalL1,FinalM1,NewOrigL1,NewOrigM1),
1741 do_mres(NewOrigL1,NewOrigM1,RNew,FinalL2,FinalM2,NewOrigL2,NewOrigM2),
1742 append(FinalL1,FinalL2,FinalL),
1743 append(FinalM1,FinalM2,FinalM).
1744
1745do_mres(LNewOrig,MNewOrig,[],[],[],LNewOrig,MNewOrig).
1747
1748do_mres(LOrigRules,MOrigRules,[Rule|Rest],FinalL,FinalM,NewOrigL,NewOrigM) :-
1750 mresolve(Rule,LOrigRules,MOrigRules,RulesL1,RulesM1),
1751 add_to_set(LOrigRules,MOrigRules,Rule,Rest,RulesL1,RulesM1,FinalL,FinalM,NewOrigL,NewOrigM).
1752
1754
1755add_to_set(LOrigRules,MOrigRules,Rule,Rest,RulesL1,RulesM1,FinalL,FinalM,NewOrigL,NewOrigM) :-
1757 is_modal_rule(Rule),!,
1758 do_mres(LOrigRules,[Rule|MOrigRules],Rest,NewRulesL,NewRulesM,NewOrigL,NewOrigM),
1759 append(RulesL1,NewRulesL,FinalL),
1760 append(RulesM1,NewRulesM,FinalM).
1761
1762add_to_set(LOrigRules,MOrigRules,Rule,Rest,RulesL1,RulesM1,FinalL,FinalM,NewOrigL,NewOrigM) :-
1764 do_mres([Rule|LOrigRules],MOrigRules,Rest,NewRulesL,NewRulesM,NewOrigL,NewOrigM),
1765 append(RulesL1,NewRulesL,FinalL),
1766 append(RulesM1,NewRulesM,FinalM).
1767
1777
1779
1780mresolve(_,[],[],[],[]).
1782
1784
1785mresolve(r(N1,N2,F),[r(N3,_,G) | Rest],Other,LFinal,MFinal) :-
1787 basic_nt_resolve(F,G,Resolvent,[],[]),
1788 mresolve(r(N1,N2,F),Rest,Other,NewLRules,NewMRules),
1789 generate_new_resolvent([N1,N3],Resolvent,NewLRules,NewMRules,LFinal,MFinal).
1790
1791mresolve(Rule,[_ | Rest],Other,NewLRules,NewMRules) :-
1793 mresolve(Rule,Rest,Other,NewLRules,NewMRules).
1794
1795mresolve(r(N1,N2,F),[],[r(N3,_,G) | Rest],LFinal,MFinal) :-
1797 basic_nt_resolve(F,G,Resolvent,[],[]),
1798 mresolve(r(N1,N2,F),[],Rest,NewLRules,NewMRules),
1799 generate_new_resolvent([N1,N3],Resolvent,NewLRules,NewMRules,LFinal,MFinal).
1800
1801mresolve(Rule,[],[_ | Rest],NewLRules,NewMRules) :-
1803 mresolve(Rule,[],Rest,NewLRules,NewMRules).
1804
1811
1812generate_new_resolvent(_,[],LR,MR,LR,MR).
1813
1814generate_new_resolvent(FromList,[Resolvent],LRules,MRules,FinalLRules,FinalMRules):-
1815 is_modal_disjunct(Resolvent),!,
1816 simplify_rule(r(_,FromList,Resolvent),[r(_,FromList,SimpRule)]),
1817 change_form(SimpRule,RulesList),
1818 number_rules(RulesList,FromList,NumberedRules),
1819 simplify(NumberedRules,SimpRules),
1820 separate_rules(SimpRules,_ERules,_Initial,NewLRules,NewMRules,_Temporal),
1821 append(LRules,NewLRules,FinalLRules),
1822 append(MRules,NewMRules,FinalMRules).
1823
1824generate_new_resolvent(FromList,[Resolvent],LRules,MRules,[SimpRule | LRules],MRules):-
1825 newrulecount(N),
1826 simplify_rule(r(N,FromList,Resolvent),[SimpRule]).
1827
1836
1837basic_nt_resolve(A => B,Disj2,Resolvent,S1,S2):-
1838 snff_negate(A,NegA),!,
1839 basic_nt_resolve(NegA or B,Disj2,Resolvent,S1,S2).
1840
1841basic_nt_resolve(Disj1,A => B,Resolvent,S1,S2):-
1842 snff_negate(A,NegA),!,
1843 basic_nt_resolve(Disj1,NegA or B,Resolvent,S1,S2).
1844
1845basic_nt_resolve(A or B,Disj2,Resolvent,S1,S2) :-
1846 basic_nt_resolve(A,Disj2,Resolvent,[B|S1],S2).
1847
1848basic_nt_resolve(A or B,Disj2,Resolvent,S1,S2) :-
1849 basic_nt_resolve(B,Disj2,Resolvent,[A|S1],S2).
1850
1851basic_nt_resolve(_ or _, _,_,_,_) :- fail.
1852
1853basic_nt_resolve(A,Disj2,Resolvent,S1,S2) :-
1854 internal_nt_resolve(A,Disj2,Resolvent,S1,S2).
1855
1864
1865internal_nt_resolve(L,A or B, Resolvent,S1,S2) :-
1866 internal_nt_resolve(L,A,Resolvent,S1,[B|S2]).
1867
1868internal_nt_resolve(L,A or B,Resolvent,S1,S2) :-
1869 internal_nt_resolve(L,B,Resolvent,S1,[A|S2]).
1870
1871internal_nt_resolve(_,_ or _,_,_,_) :- fail.
1872
1873internal_nt_resolve(L,M,[Resolvent],S1,S2) :-
1874 resolveable(L,M,S1,S2,NewS1,NewS2),
1875 append(NewS1,NewS2,NewLst),
1876 disjoin(NewLst,Resolvent).
1877
1881
1882resolveable(L,M,S1,S2,S1,S2):-
1883 comp_lits(L,M).
1884
1888
1889resolveable(L,M,S1,S2,NewS1,NewS2):-
1890 sometime_rule(L,M,S1,S2,NewS1,NewS2).
1891
1892resolveable(L,M,S1,S2,NewS1,NewS2):-
1893 always_rule(L,M,S1,S2,NewS1,NewS2).
1894
1898
1899sometime_rule(k L,k M,S1,S2,S1,S2):-
1900 comp_lits(L,M).
1901
1905
1906sometime_rule(k L,M,S1,S2,S1,S2):-
1907 comp_lits(L,M).
1908
1909sometime_rule(L,k M,S1,S2,S1,S2):-
1910 comp_lits(L,M).
1911
1915
1916always_rule(~ k L,L,S1,S2,S1,NewS2):-
1917 change_resolvent(S2,NewS2).
1918
1919always_rule(L,~ k L,S1,S2,NewS1,S2):-
1920 change_resolvent(S1,NewS1).
1921
1922always_rule(~ k ~ L,M,S1,S2,S1,NewS2):-
1923 comp_lits(L,M),
1924 change_resolvent(S2,NewS2).
1925
1926always_rule(L,~ k ~ M,S1,S2,NewS1,S2):-
1927 comp_lits(L,M),
1928 change_resolvent(S1,NewS1).
1929
1933
1934change_resolvent([A or B|Rest], NewAll):-
1935 change_resolvent(A or B,NewAB),
1936 change_resolvent(Rest, NewRest),
1937 append(NewAB,NewRest, NewAll).
1938
1939change_resolvent(A or B, NewAB):-
1940 change_resolvent(A, NewA),
1941 change_resolvent(B, NewB),
1942 append(NewA, NewB, NewAB).
1943
1944change_resolvent([A|Rest],NewAll):-
1945 change_resolvent(A,NewA),
1946 change_resolvent(Rest,NewRest),
1947 append(NewA,NewRest,NewAll).
1948
1949change_resolvent([],[]).
1950
1951change_resolvent(X,[X]):-is_snl_literal(X).
1952
1953change_resolvent(~ k L,[~ k L]):-is_literal(L).
1954
1955change_resolvent(k L,[k L]):-is_literal(L).
1956
1957change_resolvent(k ~ L,[k ~ L]):-is_literal(L). 1958
1959change_resolvent(~ k ~ L,[~ k ~ L]):-is_literal(L).
1960
1961change_resolvent(~ L,[~ k L]):-is_literal(L).
1962
1963change_resolvent(L,[~ k ~ L]):-is_literal(L).
1964
1966
1967is_modal_rule(r(_,_,Y => X)):-
1968 is_modal_rule(Y => X).
1969
1970is_modal_rule(_Y => X):-
1971 is_modal_disjunct(X).
1972
1974
1975is_modal_disjunct(k _).
1976
1977is_modal_disjunct(~ k _).
1978
1979is_modal_disjunct(A or _):-
1980 is_modal_disjunct(A).
1981
1982is_modal_disjunct(_ or B):-
1983 is_modal_disjunct(B).
1984
1986
1987is_list_of_only_modals(A or B):-
1988 is_modal(A),
1989 is_list_of_only_modals(B).
1990
1991is_list_of_only_modals(A):-
1992 is_modal(A).
1993
1994is_list_of_only_literals(A or B):-
1995 is_literal(A),
1996 is_list_of_only_literals(B).
1997
1998is_list_of_only_literals(A):-
1999 is_literal(A).
2000
2004
2005change_form(true,[true]).
2006
2007change_form(Disjunction,[true => Disjunction]):-
2008 is_modal(Disjunction).
2009
2010change_form(~ k X or Disj1, [Disj2 => ~ k X]):-
2011 is_literal(Disj1),!,
2012 snff_negate(Disj1,Disj2).
2013
2014change_form(k X or Disj1, [Disj2 => k X]):-
2015 is_literal(Disj1),!,
2016 snff_negate(Disj1,Disj2).
2017
2018change_form(Disj1 or ~ k X, [Disj2 => ~ k X] ):-
2019 is_literal(Disj1),!,
2020 snff_negate(Disj1,Disj2).
2021
2022change_form(Disj1 or k X, [Disj2 => k X]):-
2023 is_literal(Disj1),!,
2024 snff_negate(Disj1,Disj2).
2025
2026change_form(Disjunction,[Disjunction]):-
2027 is_list_of_only_literals(Disjunction).
2028
2029change_form(Disjunction,List):-
2030 is_list_of_only_modals(Disjunction),
2031 snl_form(Disjunction,Literals,Modals),
2032 append([Literals],Modals,List).
2033
2034change_form(Disj1 or Disj2,Rest):-
2035 is_literal(Disj1),
2036 snff_rewrite_list([~ Disj1 => (Disj2)],Rest).
2037
2038change_form(Disj1 or Disj2,Rest):-
2039 is_not_literal(Disj1),!,
2040 change_order(Disj1 or Disj2, NewDisj),
2041 change_form(NewDisj,Rest).
2042
2044
2045change_order(A or B,NewOrder):-
2046 strip_or(A,NewA),
2047 strip_or(B,NewB),
2048 flatten(NewA,FlatA),
2049 flatten(NewB,FlatB),
2050 append(FlatB,FlatA,New),
2051 disjoin(New,NewOrder).
2052
2053
2064
2065snl(Formula,Formula,_,[],[]):-
2066 is_snl_literal(Formula).
2067
2068snl(NewLiteralA or NewLiteralB,A or B,N,Literals,Modals):-
2069 snl(NewLiteralA,A,N,Literals1,Modals1),
2070 snl(NewLiteralB,B,N,Literals2,Modals2),
2071 append(Literals1,Literals2,Literals),
2072 append(Modals1,Modals2,Modals).
2073
2074snl(NewLiteral,A and B,N,Literals,Modals):-
2075 snl_conjunction(NewLiteral,A and B,N,Literals,Modals).
2076
2077snl(NewLiteral,Formula,N,[],[Rule1,Rule2]):-
2078 is_literal(Formula),!,
2079 new_dontknow_prop(NewLiteral,Formula),
2080 snff_negate(Formula, NegF),
2081 snff_negate(NewLiteral, NegNewLiteral),
2082 number_rule(NewLiteral => ~ k NegF,N,Rule1),
2083 number_rule(NegNewLiteral => k NegF,N,Rule2).
2084
2089
2090
2091snl_form(k L,[NegNewProp],[NewProp => ~ k L, NegNewProp => k L]):-
2092 snff_negate(L,NegL),
2093 new_dontknow_prop(NewProp, NegL),
2094 snff_negate(NewProp,NegNewProp).
2095
2096snl_form(~ k L,[NewProp],[NewProp => ~ k L, NegNewProp => k L]):-
2097 snff_negate(L,NegL),
2098 new_dontknow_prop(NewProp, NegL),
2099 snff_negate(NewProp,NegNewProp).
2100
2101snl_form(A or B,Literals,Modals):-
2102 snl_form(A,Literals1,Modals1),
2103 snl_form(B,Literals2,Modals2),
2104 append(Literals1,Literals2,LiteralList),
2105 disjoin(LiteralList,Literals),
2106 append(Modals1,Modals2,Modals).
2107
2116snl_conjunction(SimpSNL,Conjunction,_,[],[]):-
2117 strip_and(Conjunction,List),
2118 flatten(List,FList),
2119 remove_news(FList,NewList),
2120 separate_snl_literals(NewList,NewishList,OldSNLList),
2121 subset(NewishList,[]),
2122 conjoin(OldSNLList,OldSNL),
2123 simplify_and(OldSNL,SimpSNL).
2127snl_conjunction(NewConj,Conjunction,N,[],[Rule1,Rule2]):-
2128 strip_and(Conjunction,List),
2129 flatten(List,FList),
2130 remove_news(FList,NewList),
2131 separate_snl_literals(NewList,NewishList,OldSNLList),
2132 test_conjunction(NewishList,Prop),
2133 conjoin(OldSNLList,OldSNL),
2134 new_dontknow_prop(NewSNL,Prop),
2135 simplify_and(OldSNL and NewSNL,NewConj),
2136 snff_negate(Prop,NegProp),
2137 snff_negate(NewSNL,NegNewSNL),
2138 number_rule(NewSNL => ~ k NegProp,N,Rule1),
2139 number_rule(NegNewSNL => k NegProp,N,Rule2).
2143snl_conjunction(NewConj,Conjunction,N,Literals,SimplifiedRules):-
2144 strip_and(Conjunction,List),
2145 flatten(List,FList),
2146 remove_news(FList,NewList),
2147 separate_snl_literals(NewList,NewishList,OldSNLList),
2148 conjoin(OldSNLList,OldSNL),
2149 conjoin(NewishList,Formula),
2150 simplify_and(Formula,SFormula),
2151 new_conj_prop(NewProp,SFormula),
2152 snff_negate(SFormula,NFormula),
2153 number_rule(NewProp or NFormula,N,Definition),
2154 simplify([Definition],Literals),
2155 new_dontknow_prop(NewSNL,NewProp),
2156 generate_new_modals(NewSNL,N,NewishList,NewModals),
2157 simplify_and(OldSNL and NewSNL,NewConj),
2158 snff_negate(NewProp,NegNewProp),
2159 snff_negate(NewSNL,NegNewSNL),
2160 number_rule(NewSNL => ~ k NegNewProp,N,Rule1),
2161 number_rule(NegNewSNL => k NegNewProp,N,Rule2),
2162 append([Rule1],[Rule2],Definitions),
2163 append(Definitions,NewModals,Rules),
2164 simplify(Rules,SimplifiedRules).
2165
2167
2168generate_new_modals(_,_,[],[]).
2169
2170generate_new_modals(NewSNL,N,[Head|Tail],[Definition|NewModals]):-
2171 snff_negate(NewSNL,NegNewSNL),
2172 snff_negate(Head,NegHead),
2173 number_rule(NegNewSNL => k NegHead,N,Definition),
2174 generate_new_modals(NewSNL,N,Tail,NewModals).
2175
2176test_conjunction([Head|Tail],Head):-
2177 subset(Tail,[]).
2178
2180
2181remove_news([],[]).
2182
2183remove_news([new(X)|List],[X|NewList]):-
2184 remove_news(List,NewList).
2185
2186remove_news([X|List],[X|NewList]):-
2187 remove_news(List,NewList).
2188
2190
2191separate_snl_literals(List,Literals,SNLLiterals):-
2192 sublist(is_snl_literal,List,SNLLiterals),
2193 subtract(List,SNLLiterals,Lit),
2194 sort(Lit,Literals).
2195
2197
2198my_k_to_literal([],[]):- !.
2199
2200my_k_to_literal([r(N,_M,X => k Y)|Rest],[Rule|NewRest]):-!,
2201 snff_negate(X,NegX),
2202 number_rule(NegX or Y,[N,mres5],Rule),
2203 my_k_to_literal(Rest,NewRest).
2204
2205my_k_to_literal([r(_,_,_ => ~ k _)|Rest],NewRest):-!,
2206 my_k_to_literal(Rest,NewRest).
2207
2220
2248
2250
2251tempres(Rules,[[ERule,PrevPath]|ERulePaths],NewERule,RelatedRules,RulesUsed,LoopPath):-
2252 temp_resolution(ERule,ERulePaths,Rules,PrevPath,NewERule,RelatedRules,RulesUsed,LoopPath).
2253
2254
2275
2276temp_resolution(ERule,ERulePaths,Rules,PrevPaths,NewERule,RelatedRules,RulesUsed,NewLoopPath):-
2277 my_writef('Attempting temporal resolution with %t.\n',[ERule]),
2278 resolve_eventuality(ERule, Rules, RelatedRules1,RulesUsed1,LoopPath),
2279 test_path(ERule,ERulePaths,Rules,PrevPaths,LoopPath,NewERule,RelatedRules1,RulesUsed1,RelatedRules,RulesUsed,NewLoopPath).
2280
2295
2296 2297 2298
2299test_path(_,[],_Rules,_,[],_NewERule,_,_,[],[],[]):- !.
2300
2301 2302 2303
2304test_path(_,[[ERule,PrevPath]|ERulePaths], Rules,_,[],NewERule,_,_,RelatedRules,RulesUsed,LoopPath):- !,
2305 temp_resolution(ERule,ERulePaths,Rules,PrevPath,NewERule,RelatedRules,RulesUsed,LoopPath).
2306
2307 2308 2309
2310test_path(_,[],_Rules,PrevPath1,LoopPath,_NewERule,_,_,[],[],[]):-
2311 same_node_in_list(PrevPath1,LoopPath),!.
2312
2313 2314 2315
2316test_path(_,[[ERule,PrevPath]|ERulePaths],Rules,PrevPath1,LoopPath,NewERule,_,_,RelatedRules,RulesUsed,NewLoopPath):-
2317 same_node_in_list(PrevPath1,LoopPath),!,
2318 temp_resolution(ERule,ERulePaths,Rules,PrevPath,NewERule,RelatedRules,RulesUsed,NewLoopPath).
2319
2320 2321 2322 2323
2324test_path(ERule,_, _, _, LoopPath,ERule,RelatedRules,RulesUsed,RelatedRules,RulesUsed,LoopPath).
2325
2326
2334
2335same_node_in_list([PrevLoop|_],LoopPath):-
2336 same_node(PrevLoop,LoopPath),!.
2337
2338same_node_in_list([_|PrevLoops],LoopPath):-
2339 same_node_in_list(PrevLoops,LoopPath).
2340
2360
2361 2362
2363resolve_eventuality(F,Others, RelatedRules,[], LoopList):-
2364 snff_negate(F, NewF), 2365 relatedrules(NewF, Others, RelatedRules, NewOthers),
2366 write_ruleset(RelatedRules),
2367 write_ruleset(NewOthers),
2368 add_initial(RelatedRules, OrigNodes), !,
2369 simplify_top_node(F,OrigNodes,SimplerOrig),
2370 build_graph(F,Others, SimplerOrig,SimplerOrig, LoopList).
2371
2383
2384relatedrules(Prop, [r(N1,N2,P => next Prop)|RuleList], [r(N1,N2, P => next Prop)|RelatedRules], RemainingRules):- !,
2385 relatedrules(Prop, RuleList, RelatedRules, RemainingRules).
2386
2387relatedrules(Prop, [r(N1,N2,Prop)|RuleList], [r(N1,N2, Prop)|RelatedRules], RemainingRules):-
2388 disjunction_of_literals(Prop),!,
2389 relatedrules(Prop, RuleList, RelatedRules, RemainingRules).
2390
2391relatedrules(Prop, [Rule|RuleList], RelatedRules, [Rule|RemainingRules]):-
2392 relatedrules(Prop, RuleList, RelatedRules, RemainingRules).
2393
2394relatedrules(_,[],[],[]).
2395
2405
2406add_initial([r(_,_, F => next _)|Rules], [StrippedF |Nodes]):-
2407 strip(F, StrippedF),
2408 add_initial(Rules, Nodes).
2409
2410add_initial([r(_,_, F)|Rules], [[true] |Nodes]):-
2411 disjunction_of_literals(F),
2412 add_initial(Rules, Nodes).
2413
2414add_initial([], []).
2415
2429
2430 2431
2432build_graph(_,_,_,[[true]],[[true]]):- !.
2433
2434build_graph(F,Rules, PrevNode, TopNode,FinalNode):-
2435 writef('\nThe New Node is %t.\n',[PrevNode]),
2436 build_node(F,Rules, PrevNode,TopNode,NewNode),!,
2437 test_newnode(F,Rules, PrevNode, TopNode,NewNode,FinalNode).
2438
2448
2449test_newnode(_,_,_,_,[],[]):- !. 2450
2451test_newnode(_,_,_,_,[[true]],[[true]]):-!. 2452
2453test_newnode(_,_, PrevNode, _,NewNode,NewNode):-
2454 same_node(PrevNode,NewNode),!. 2455
2456test_newnode(F,Rules, _, TopNode,NewNode,FinalNode):-
2457 build_graph(F,Rules, NewNode, TopNode,FinalNode).
2458 2459
2473
2474build_node(F,Rules, PrevNode, TopNode,FinalNode):-
2475 flatten(PrevNode,FlatPrev),
2476 get_relevant_rules(Rules,PrevNode,FlatPrev,TopNode, Useful,[],NewishNode),
2477 combine_useful_rules(Useful,PrevNode,FlatPrev,TopNode,NewishNode,NewThisNode),
2478 simplify_new_node(F,NewThisNode,FinalNode).
2479
2492
2493combine_useful_rules([],_,_,_, FinalNode,FinalNode):- !. 2494
2495combine_useful_rules(Rules, PrevNode,FlatPrev,TopNode,ThisNode,FinalNode):- !,
2496 split_into_sublists(Rules,FlatPrev,SplitRules),
2497 combine_for_disjuncts(PrevNode,SplitRules,PrevNode,TopNode,ThisNode,FinalNode).
2498
2512
2513get_relevant_rules([r(_,_, P => next Q)|Rest],PrevNode,FlatPrev,TopNode,Useful,ThisNode,FinalNode):-
2514 strip_or(Q,StrippedQ), 2515 set_implies(StrippedQ,PrevNode), 2516 strip_or(P,[StrippedP]),
2517 set_implies([StrippedP],TopNode),!,
2518 remove_subsumed(StrippedP,ThisNode,NewThisNode),
2519 get_relevant_rules(Rest,PrevNode,FlatPrev,TopNode,Useful,NewThisNode,FinalNode).
2520
2521get_relevant_rules([r(_,_,P => next Q)|Rest],PrevNode,FlatPrev,TopNode,Useful,ThisNode, FinalNode):-
2522 strip_or(Q,StrippedQ), 2523 set_implies(StrippedQ,PrevNode),!, 2524 strip_or(P,StrippedP),
2525 combine_lhs_with_initial(StrippedP,TopNode,NewDisjuncts),
2526 remove_subsumed_list(NewDisjuncts,ThisNode,NewThisNode),
2527 get_relevant_rules(Rest,PrevNode,FlatPrev,TopNode,Useful,NewThisNode,FinalNode).
2528
2529get_relevant_rules([r(N1,N2,P => next Q)|Rest],PrevNode,FlatPrev,TopNode,[r(N1,N2,P => next Q)|Useful],ThisNode,FinalNode):-
2530 strip(Q,StrippedQ),
2531 subset(StrippedQ,FlatPrev),!, 2532 get_relevant_rules(Rest,PrevNode,FlatPrev,TopNode,Useful,ThisNode,FinalNode).
2533
2534get_relevant_rules([r(_,_,Q)|Rest],PrevNode,FlatPrev,TopNode,Useful,ThisNode,FinalNode):-
2535 disjunction_of_literals(Q),
2536 strip_or(Q,StrippedQ), 2537 set_implies(StrippedQ,PrevNode),!, 2538 remove_subsumed_list(TopNode,ThisNode,NewThisNode),
2539 get_relevant_rules(Rest,PrevNode,FlatPrev,TopNode,Useful,NewThisNode,FinalNode).
2540
2541get_relevant_rules([r(N1,N2,Q)|Rest],PrevNode,FlatPrev,TopNode,[r(N1,N2,Q)|Useful],ThisNode,FinalNode):-
2542 disjunction_of_literals(Q),
2543 strip(Q,StrippedQ),
2544 subset(StrippedQ,FlatPrev),!, 2545 get_relevant_rules(Rest,PrevNode,FlatPrev,TopNode,Useful,ThisNode,FinalNode).
2546
2547get_relevant_rules([_|Rest],PrevNode,FlatPrev,TopNode,Useful,ThisNode,FinalNode):- !,
2548 get_relevant_rules(Rest,PrevNode,FlatPrev,TopNode,Useful,ThisNode,FinalNode).
2549 2550
2551get_relevant_rules([],_,_,_,[],FinalNode,FinalNode). 2552
2560 2561 2562
2563combine_lhs_with_initial([[Conj]],[H|Tail],[NewDisjunct|NewDisjuncts]):- !,
2564 simplify_a_disjunct([Conj|H],NewDisjunct),
2565 combine_lhs_with_initial([[Conj]],Tail,NewDisjuncts).
2566
2567combine_lhs_with_initial([Conj],[H|Tail],[NewDisjunct|NewDisjuncts]):-
2568 append(Conj,H,NewConj),
2569 simplify_a_disjunct(NewConj,NewDisjunct),
2570 combine_lhs_with_initial([Conj],Tail,NewDisjuncts).
2571
2572combine_lhs_with_initial(_,[],[]).
2573
2582
2583same_node([],[]):-!.
2584
2585same_node(List1,List2):-
2586 set_implies(List1,List2),
2587 set_implies(List2,List1).
2588
2601
2602combine_for_disjuncts([D1|Disjuncts],Rules,PrevNode,TopNode,ThisNode,FinalNode):-
2603 get_rules_for_disjunct(Rules,D1,NewRules),
2604 combine_rules(Rules,NewRules,D1,PrevNode,TopNode,ThisNode,NewerNode,NewerRules),
2605 combine_for_disjuncts(Disjuncts, NewerRules,PrevNode,TopNode,NewerNode,FinalNode).
2606
2607combine_for_disjuncts([], _Rules, _PrevNode, _TopNode, FinalNode,FinalNode).
2608
2618
2619get_rules_for_disjunct([[Lit]|Rest],[Lit|Disjuncts],[NewRest]):- !, 2620 get_rules_for_disjunct(Rest,Disjuncts,NewRest).
2621
2622get_rules_for_disjunct([[Lit,Rules]|Rest],[Lit|Disjuncts],[Rules|NewRest]):- !,
2623 get_rules_for_disjunct(Rest,Disjuncts,NewRest).
2624
2625get_rules_for_disjunct([[Lit,Rules]|Rest],Disjuncts,[Rules|NewRest]):-
2626 member(Lit,Disjuncts),!,
2627 get_rules_for_disjunct(Rest,Disjuncts,NewRest).
2628
2629get_rules_for_disjunct([[_,_]|Rest],Disjuncts,NewRest):-
2630 get_rules_for_disjunct(Rest,Disjuncts,NewRest).
2631
2632get_rules_for_disjunct(_,[],[]). 2633
2634get_rules_for_disjunct([],_,[]). 2635
2647
2648combine_rules(Rules,SplitRules, D1,PrevNode, TopNode,ThisNode,FinalNode,NewRules):-
2649 combine_sublists(SplitRules,Combined),
2650 get_relevant_combined(Combined,Rules,D1,PrevNode,TopNode,ThisNode,FinalNode,NewRules).
2651
2660
2661split_into_sublists(Rules,[C1|Conjuncts],[[C1,C1Rules]|RestRules]):-
2662 rules_that_give_a_conjunct(C1,Rules,C1Rules),
2663 split_into_sublists(Rules,Conjuncts,RestRules).
2664
2665split_into_sublists(_,[],[]).
2666
2675
2676rules_that_give_a_conjunct(C1,[r(N1,N2,P => next Q)|Rest],[r(N1,N2,P => next Q)|NewRest]):-
2677 strip(Q,StrippedQ),
2678 member(C1,StrippedQ),!,
2679 rules_that_give_a_conjunct(C1,Rest,NewRest).
2680
2681rules_that_give_a_conjunct(C1,[r(N1,N2,Q)|Rest],[r(N1,N2,Q)|NewRest]):-
2682 disjunction_of_literals(Q),
2683 strip(Q,StrippedQ),
2684 member(C1,StrippedQ),!,
2685 rules_that_give_a_conjunct(C1,Rest,NewRest).
2686
2687rules_that_give_a_conjunct(C1,[_|Rest],NewRest):-
2688 rules_that_give_a_conjunct(C1,Rest,NewRest).
2689
2690rules_that_give_a_conjunct(_,[],[]).
2691
2700
2701combine_sublists([_],[]):-!. 2702
2703combine_sublists([L1|[L2]],L12):- !, 2704 combine_two_sublists(L1,L2,L12).
2705
2706combine_sublists([L1|L2],NewL1L2):- !, 2707 combine_sublists(L2,NewL2),
2708 combine_two_sublists(L1,NewL2,NewL1L2).
2709
2710combine_sublists([],[]). 2718
2719combine_two_sublists([H1|Tail1],List2,NewList):-
2720 combine_element_with_all(H1,List2,H1List2),
2721 combine_two_sublists(Tail1,List2,Tail1List2),
2722 append(H1List2,Tail1List2,NewList).
2723
2724combine_two_sublists([],_,[]).
2725
2732
2733combine_element_with_all(H1,[H2|Tail2],FinalList):-
2734 combine_two_rules(H1,H2,H1H2),
2735 test_combine_rules(H1H2,H1,Tail2,FinalList).
2736
2737combine_element_with_all(_,[],[]).
2738
2740
2741test_combine_rules(r(_,_,false => next _),H1,Tail2,H1Tail2):- !,
2742 combine_element_with_all(H1,Tail2,H1Tail2).
2743
2744test_combine_rules(Rule,H1,Tail2,[Rule|H1Tail2]):-
2745 combine_element_with_all(H1,Tail2,H1Tail2).
2746
2758
2759get_relevant_combined(_,Rules,_,_,_,[[true]],[[true]],Rules):-!.
2760
2761get_relevant_combined([r(_,_,P => next Q)|Rest],Rules,D1,PrevNode,TopNode,ThisNode,FinalNode,NewRules):-
2762 strip_or(Q,StrippedQ), 2763 set_implies(StrippedQ,PrevNode), 2764 strip_or(P,[StrippedP]),
2765 set_implies([StrippedP],TopNode),!,
2766 remove_subsumed(StrippedP,ThisNode,NewerThisNode),
2767 get_relevant_combined(Rest,Rules,D1,PrevNode,TopNode,NewerThisNode,FinalNode,NewRules).
2768
2769
2770get_relevant_combined([r(_,_,P => next Q)|Rest],Rules,D1,PrevNode,TopNode,ThisNode,FinalNode,NewRules):-
2771 strip_or(Q,StrippedQ), 2772 set_implies(StrippedQ,PrevNode),!, 2773 strip_or(P,StrippedP),
2774 combine_lhs_with_initial(StrippedP,TopNode,NewDisjuncts),
2775 remove_subsumed_list(NewDisjuncts,ThisNode,NewerThisNode),
2776 get_relevant_combined(Rest,Rules,D1,PrevNode,TopNode,NewerThisNode,FinalNode,NewRules).
2777
2778get_relevant_combined([r(_,_,Q)|Rest],Rules,D1,PrevNode,TopNode,ThisNode,FinalNode,NewRules):-
2779 disjunction_of_literals(Q),
2780 strip_or(Q,StrippedQ), 2781 set_implies(StrippedQ,PrevNode),!, 2782 remove_subsumed_list(TopNode,ThisNode,NewerThisNode),
2783 get_relevant_combined(Rest,Rules,D1,PrevNode,TopNode,NewerThisNode,FinalNode,NewRules).
2784
2785get_relevant_combined([Rule|Rest],Rules,D1,PrevNode,TopNode,ThisNode,FinalNode,NewRules):- !,
2786 add_combined_to_rules(Rule,Rules,D1,PrevNode,NewerRules),
2787 get_relevant_combined(Rest,NewerRules,D1,PrevNode,TopNode,ThisNode,FinalNode,NewRules).
2788 2789
2790get_relevant_combined([],Rules,_,_,_,FinalNode,FinalNode,Rules). 2798
2799combine_two_rules(r(N1,_,P => next F), r(N3,_,Q => next G), r(N1,[N1,N3],NewLHS => next RHS)):-
2800 simplify_and(P and Q, NewerLHS),
2801 simplify_and_dup(NewerLHS, NewLHS),
2802 simplify_dnf(F and G, RHS).
2803
2804combine_two_rules(r(N1,_,F), r(N3,_,Q => next G), r(N1,[N1,N3],Q => next RHS)):-
2805 disjunction_of_literals(F),
2806 simplify_dnf(F and G, RHS).
2807
2808combine_two_rules(r(N1,_,P => next F), r(N3,_,G), r(N1,[N1,N3],P => next RHS)):-
2809 disjunction_of_literals(G),
2810 simplify_dnf(F and G, RHS).
2811
2812combine_two_rules(r(N1,_,F), r(N3,_,G), r(N1,[N1,N3],RHS)):-
2813 disjunction_of_literals(F),
2814 disjunction_of_literals(G),
2815 simplify_dnf(F and G, RHS).
2816
2829
2830simplify_dnf(X,Y):-
2831 cnf_to_dnf(X,NewX),
2832 simplifylist(NewX,SimplerX),
2833 simplify_in_dnf(SimplerX,SimplerDNF),
2834 simplify_dnf1(SimplerDNF,Y).
2835
2837
2838cnf_to_dnf(X,NewX):-
2839 strip_cnf(X,StrippedX),
2840 combine_sublists_in_dnf(StrippedX,NewX).
2841
2849
2850simplify_dnf1([],false):-!.
2851
2852simplify_dnf1([true],true):-!.
2853
2854simplify_dnf1(SimpleX,Y):-
2855 rewrite_and_or(SimpleX,Y).
2856
2864
2865simplify_a_disjunct(Dis,NewDis):-
2866 simplifylist([Dis],[NewDis]).
2867
2878
2879simplifylist([H|Tail],[[false]|NewTail]):-
2880 simplify_and_false(H),!,
2881 simplifylist(Tail,NewTail).
2882
2883simplifylist([H|Tail], [[false]|NewTail]):-
2884 comp_lits_and(H),!,
2885 simplifylist(Tail, NewTail).
2886
2887simplifylist([H|Tail], [NewerH|NewTail]):-
2888 remove_duplicate(H, NewH),!,
2889 simplify_and_true(NewH,NewerH),
2890 simplifylist(Tail, NewTail).
2891
2892simplifylist([],[]).
2893
2904
2905remove_true(List,[[true]]):-
2906 member([true],List),!.
2907
2908remove_true(List,[[true]]):-
2909 member([],List),!.
2910
2911remove_true(List,List):-!.
2912
2926
2927remove_false([[true]],[[true]]):-!.
2928
2929remove_false([false|Rest],NewRest):-
2930 !,remove_false(Rest,NewRest).
2931
2932remove_false([[false]|Rest],NewRest):-
2933 !,remove_false(Rest,NewRest).
2934
2935remove_false([Nodelist|Rest],[Nodelist|NewRest]):-
2936 !,remove_false(Rest,NewRest).
2937
2938remove_false([],[]).
2939
2949
2950simplify_and_false([false|_]):- !.
2951
2952simplify_and_false([_|Rest]):-
2953 simplify_and_false(Rest).
2954
2964
2965simplify_and_true([true|Rest],NewRest):- !,
2966 simplify_and_true(Rest,NewRest).
2967
2968simplify_and_true([H|Rest],[H|NewRest]):- !,
2969 simplify_and_true(Rest,NewRest).
2970
2971simplify_and_true([],[]).
2972
2981
2982simplify_top_node(_,[],[]):-!. 2983
2984simplify_top_node(_,[[true]],[[true]]):-!.
2985 2986
2987simplify_top_node(F,ListofDisjuncts,FinalDNF):-
2988 simplifylist(ListofDisjuncts,SimpleDisjuncts),
2989 simplify_in_dnf(SimpleDisjuncts,SimplerDNF),
2990 simplify_comp_lits_in_dnf(SimplerDNF,SimplifiedDNF1),
2991 simplify_in_dnf(SimplifiedDNF1,SimplifiedDNF),
2992 remove_bad_disjuncts(F,SimplifiedDNF,FinalDNF).
2993
3002
3003simplify_new_node(_,[],[]):-!. 3004
3005simplify_new_node(F,SimplerDNF,FinalDNF):-
3006 simplify_comp_lits_in_dnf(SimplerDNF,SimplifiedDNF1),
3007 simplify_in_dnf(SimplifiedDNF1,SimplifiedDNF),
3008 remove_bad_disjuncts(F,SimplifiedDNF,FinalDNF).
3009
3010
3019
3020remove_bad_disjuncts(_,[],[]).
3021
3022remove_bad_disjuncts(F,[H|Tail],NewTail):-
3023 member(F,H),!,
3024 remove_bad_disjuncts(F,Tail,NewTail).
3025
3026remove_bad_disjuncts(F,[H|Tail],[H|NewTail]):-
3027 remove_bad_disjuncts(F,Tail,NewTail).
3028
3041
3042simplify_in_dnf(List,NewList):-
3043 remove_true(List,NewerList),
3044 remove_false(NewerList,NoFalseList),
3045 order_node(NoFalseList,OrderedList),
3046 remove_sublists(OrderedList,NewList).
3047
3056order_node([[true]],[[true]]):-!. 3057
3058order_node([[false]],[[false]]):-!.
3059
3060order_node([],[[false]]):-!.
3061
3062order_node(Node,NewNode):-
3063 give_length_key_list(Node,KeyList),
3064 keysort(KeyList,Sorted),
3065 take_key(Sorted,NewNode).
3066
3073
3074give_length_key_list([H|Tail],[Key-H|NewTail]):-
3075 give_key_length(H,Key),
3076 give_length_key_list(Tail,NewTail).
3077
3078give_length_key_list([],[]).
3085give_key_length([_|Tail],NewKey):-
3086 give_key_length(Tail,Key),
3087 NewKey is Key + 1.
3088
3089give_key_length([],0).
3097
3098take_key([_-H|Tail],[H|NewTail]):-
3099 take_key(Tail,NewTail).
3100
3101take_key([],[]).
3102
3110
3111remove_sublists([H|Tail],[H|NewTail]):-
3112 remove_sublist(H,Tail,NewerTail),
3113 remove_sublists(NewerTail,NewTail).
3114
3115remove_sublists([],[]).
3116
3125
3126remove_sublist(H,[H1|Tail],NewTail):-
3127 subset(H,H1),!,
3128 remove_sublist(H,Tail,NewTail).
3129
3130remove_sublist(H,[H1|Tail],[H1|NewTail]):-
3131 remove_sublist(H,Tail,NewTail).
3132
3133remove_sublist(_,[],[]).
3134
3143
3144simplify_comp_lits_in_dnf(DNFList,NewList):-
3145 get_comp_list(DNFList,CompLits),
3146 add_extra_disjuncts(DNFList,CompLits,NewList).
3147
3155
3156get_comp_list(DNFList,CompLits):-
3157 flatten(DNFList,FlatList),
3158 find_comp_lits(FlatList,CompLits).
3159
3168
3169find_comp_lits([H|Tail],[H|NewTail]):-
3170 is_comp_lit(H,Tail),!,
3171 find_comp_lits(Tail,NewTail).
3172
3173find_comp_lits([_|Tail],NewTail):-
3174 find_comp_lits(Tail,NewTail).
3175
3176find_comp_lits([],[]).
3183
3184is_comp_lit(H,Tail):-
3185 snff_negate(H,NegH),
3186 member(NegH,Tail),!.
3187
3196
(List,[H|Tail],NewList):-
3198 solve_for_comp_lit(H, List, List, NewerList),
3199 add_extra_disjuncts(NewerList,Tail,NewList).
3200
3201add_extra_disjuncts(List,[],List).
3202
3215
3216solve_for_comp_lit(Comp,[D1|DRest],List,NewestRest):-
3217 member(Comp,D1),!,
3218 remove_member(Comp,D1,NewD1),
3219 snff_negate(Comp,NegComp),
3220 solve_for_second_comp(NegComp,DRest,List,NewD1,NewList),
3221 solve_for_comp_lit(Comp,DRest,NewList,NewestRest).
3222
3223solve_for_comp_lit(Comp,[D1|DRest],List,NewestRest):-
3224 snff_negate(Comp,NegComp),
3225 member(NegComp,D1),!,
3226 remove_member(NegComp,D1,NewD1),
3227 solve_for_second_comp(Comp,DRest,List,NewD1,NewList),
3228 solve_for_comp_lit(Comp,DRest,NewList,NewestRest).
3229
3230solve_for_comp_lit(Comp,[_|DRest],List,NewRest):-
3231 solve_for_comp_lit(Comp,DRest,List,NewRest).
3232
3233solve_for_comp_lit(_,[],List,List).
3234
3245
3246solve_for_second_comp(Comp,[[Comp]|_],_,[],[[true]]):- !.
3247 3248
3249solve_for_second_comp(Comp,[D1|DRest],All,OldConjuncts,NewestRest):-
3250 member(Comp,D1),!,
3251 remove_member(Comp,D1,NewD1),
3252 append(OldConjuncts,NewD1,NewerConjuncts),
3253 simplify_a_disjunct(NewerConjuncts,NewConjuncts),
3254 remove_subsumed(NewConjuncts,All,NewAll),
3255 solve_for_second_comp(Comp,DRest,NewAll,OldConjuncts,NewestRest).
3256
3257solve_for_second_comp(Comp,[_|DRest],All,OldConjuncts,NewRest):-
3258 solve_for_second_comp(Comp,DRest,All,OldConjuncts,NewRest).
3259
3260solve_for_second_comp(_,[],All,_,All).
3261
3263
3264remove_subsumed_list([H|Tail],All,FinalAll):-
3265 remove_subsumed(H,All,NewAll),
3266 remove_subsumed_list(Tail,NewAll,FinalAll).
3267
3268remove_subsumed_list([],FinalAll,FinalAll).
3269
3271
3272remove_subsumed([true],_,[[true]]):-!.
3273
3274remove_subsumed([false],All,All):-!.
3275
3276remove_subsumed(Dis,[H|Tail],[H|Tail]):-
3277 subset(H,Dis),!.
3278
3279remove_subsumed(Dis,[H|Tail],NewTail):-
3280 subset(Dis,H), !,
3281 remove_subsumed(Dis, Tail,NewTail).
3282
3283remove_subsumed(Dis,[H|Tail],[H|NewTail]):-
3284 remove_subsumed(Dis,Tail,NewTail).
3285
3286remove_subsumed(Dis,[],[Dis]).
3287
3294
3295strip_cnf(A and B,NewAB):- !,
3296 strip_cnf(A,NewA),
3297 strip_cnf(B,NewB),
3298 append(NewA,NewB,NewAB).
3299
3300strip_cnf(A or B,[NewAB]):- !,
3301 strip_or(A or B, NewAB).
3302
3303strip_cnf(A,[[[A]]]).
3304
3313
3314combine_sublists_in_dnf([_],[]):-!. 3315
3316combine_sublists_in_dnf([L1|[L2]],L12):- !, 3317 combine_two_sublists_in_dnf(L1,L2,L12).
3318
3319combine_sublists_in_dnf([L1|L2],NewL1L2):- !, 3320 combine_sublists_in_dnf(L2,NewL2),
3321 combine_two_sublists_in_dnf(L1,NewL2,NewL1L2).
3322
3323combine_sublists_in_dnf([],[]). 3324
3332
3333combine_two_sublists_in_dnf([H1|Tail1],List2,NewList):-
3334 combine_element_with_all_in_dnf(H1,List2,H1List2),
3335 combine_two_sublists_in_dnf(Tail1,List2,Tail1List2),
3336 append(H1List2,Tail1List2,NewList).
3337
3338combine_two_sublists_in_dnf([],_,[]).
3339
3346
3347combine_element_with_all_in_dnf(H1,[H2|Tail2],[H1H2|H1Tail2]):-
3348 append(H1,H2,H1H2),
3349 combine_element_with_all_in_dnf(H1,Tail2,H1Tail2).
3350
3351combine_element_with_all_in_dnf(_,[],[]).
3352
3354
3355add_combined_to_rules(r(_,_,false => next _),Rules,_,_,Rules):- !.
3356
3357add_combined_to_rules(r(_,_, _ => next false),Rules,_,_,Rules):- !.
3358
3359add_combined_to_rules(r(_,_, true => false),Rules,_,_,Rules):- !.
3360
3361add_combined_to_rules(r(N1,N2,P => next Q),Rules,_D1,PrevNode,NewRules):-
3362 strip_or(Q,StrippedQ),
3363 remove_ok_disjuncts(StrippedQ,PrevNode,NewStrippedQ),
3364 flatten(NewStrippedQ,FinalQ),
3365 add_combined_to_rule(r(N1,N2,P => next Q),FinalQ,Rules,NewRules).
3366
3367add_combined_to_rules(r(N1,N2,Q),Rules,_D1,PrevNode,NewRules):-
3368 disjunction_of_literals(Q),
3369 strip_or(Q,StrippedQ),
3370 remove_ok_disjuncts(StrippedQ,PrevNode,NewStrippedQ),
3371 flatten(NewStrippedQ,FinalQ),
3372 add_combined_to_rule(r(N1,N2,Q),FinalQ,Rules,NewRules).
3373
3374add_combined_to_rule(r(N1,N2,P => next Q),StrippedQ,[[Lit,LitRules]|Rest],[[Lit,NewLitRules]|NewRest]):-
3375 member(Lit,StrippedQ),!,
3376 add_combined_rule(r(N1,N2,P => next Q),LitRules,NewLitRules),
3377 add_combined_to_rule(r(N1,N2,P => next Q),StrippedQ,Rest,NewRest).
3378
3379add_combined_to_rule(r(N1,N2,Q),StrippedQ,[[Lit,LitRules]|Rest],[[Lit,NewLitRules]|NewRest]):-
3380 disjunction_of_literals(Q),
3381 member(Lit,StrippedQ),!,
3382 add_combined_rule(r(N1,N2,Q),LitRules,NewLitRules),
3383 add_combined_to_rule(r(N1,N2,Q),StrippedQ,Rest,NewRest).
3384
3385add_combined_to_rule(r(N1,N2,P => next Q),StrippedQ,[[Lit,LitRules]|Rest],[[Lit,LitRules]|NewRest]):- !,
3386 add_combined_to_rule(r(N1,N2,P => next Q),StrippedQ,Rest,NewRest).
3387
3388add_combined_to_rule(r(N1,N2,Q),StrippedQ,[[Lit,LitRules]|Rest],[[Lit,LitRules]|NewRest]):-
3389 disjunction_of_literals(Q),
3390 add_combined_to_rule(r(N1,N2,Q),StrippedQ,Rest,NewRest).
3391
3392add_combined_to_rule(r(_,_, _ => next _),_,[],[]).
3393
3394add_combined_to_rule(r(_,_,_),_,[],[]).
3395
3397
3398add_combined_rule(r(_,_,P1 => next Q1),[r(M1,M2,P2 => next Q2)|LitRest],[r(M1,M2,P2 => next Q2)|LitRest]):-
3399 strip_or(Q1,StrippedQ1),
3400 strip_or(Q2,StrippedQ2),
3401 same_node(StrippedQ1,StrippedQ2),
3402 strip(P1,StrippedP1),
3403 strip(P2,StrippedP2),
3404 set_implies(StrippedP1,StrippedP2),!.
3405
3406add_combined_rule(r(_,_,Q1),[r(M1,M2,P2 => next Q2)|LitRest],[r(M1,M2,P2 => next Q2)|LitRest]):-
3407 disjunction_of_literals(Q1),
3408 strip_or(Q1,StrippedQ1),
3409 strip_or(Q2,StrippedQ2),
3410 same_node(StrippedQ1,StrippedQ2),
3411 strip(P2,StrippedP2),
3412 set_implies([true],StrippedP2),!.
3413
3414add_combined_rule(r(_,_,_ => next Q1),[r(M1,M2,Q2)|LitRest],[r(M1,M2,Q2)|LitRest]):-
3415 disjunction_of_literals(Q2),
3416 strip_or(Q1,StrippedQ1),
3417 strip_or(Q2,StrippedQ2),
3418 same_node(StrippedQ1,StrippedQ2),!.
3419
3420add_combined_rule(r(_,_,Q1),[r(M1,M2,Q2)|LitRest],[r(M1,M2,Q2)|LitRest]):-
3421 disjunction_of_literals(Q1),
3422 disjunction_of_literals(Q2),
3423 strip_or(Q1,StrippedQ1),
3424 strip_or(Q2,StrippedQ2),
3425 same_node(StrippedQ1,StrippedQ2),!.
3426
3427add_combined_rule(r(N1,N2,P1 => next Q1),[r(_,_,P2 => next Q2)|LitRest],NewLitRest):-
3428 strip_or(Q1,StrippedQ1),
3429 strip_or(Q2,StrippedQ2),
3430 same_node(StrippedQ1,StrippedQ2),
3431 strip(P1,StrippedP1),
3432 strip(P2,StrippedP2),
3433 set_implies(StrippedP2,StrippedP1),!,
3434 add_combined_rule(r(N1,N2,P1 => next Q1),LitRest,NewLitRest).
3435
3436add_combined_rule(r(N1,N2,P1 => next Q1),[r(_,_,Q2)|LitRest], NewLitRest):-
3437 disjunction_of_literals(Q2),
3438 strip_or(Q1,StrippedQ1),
3439 strip_or(Q2,StrippedQ2),
3440 same_node(StrippedQ1,StrippedQ2),
3441 strip(P1,StrippedP1),
3442 set_implies([true],StrippedP1),!,
3443 add_combined_rule(r(N1,N2,P1 => next Q1),LitRest,NewLitRest).
3444
3445add_combined_rule(r(N1,N2,Q1),[r(_,_,_ => next Q2)|LitRest], NewLitRest):-
3446 disjunction_of_literals(Q1),
3447 strip_or(Q1,StrippedQ1),
3448 strip_or(Q2,StrippedQ2),
3449 same_node(StrippedQ1,StrippedQ2),
3450 add_combined_rule(r(N1,N2,Q1),LitRest,NewLitRest).
3451
3452add_combined_rule(r(N1,N2,P1 => next Q1),[r(M1,M2,P2 => next Q2)|LitRest],[r(M1,M2,P2 => next Q2)|NewLitRest]):-
3453 add_combined_rule(r(N1,N2,P1 => next Q1),LitRest,NewLitRest).
3454
3455add_combined_rule(r(N1,N2,P1 => next Q1),[r(M1,M2,Q2)|LitRest],[r(M1,M2, Q2)|NewLitRest]):-
3456 disjunction_of_literals(Q2),
3457 add_combined_rule(r(N1,N2,P1 => next Q1),LitRest,NewLitRest).
3458
3459add_combined_rule(r(N1,N2,Q1),[r(M1,M2,P2 => next Q2)|LitRest],[r(M1,M2, P2 => next Q2)|NewLitRest]):-
3460 disjunction_of_literals(Q1),
3461 add_combined_rule(r(N1,N2,Q1),LitRest,NewLitRest).
3462
3463add_combined_rule(r(N1,N2,Q1),[r(M1,M2,Q2)|LitRest],[r(M1,M2,Q2)|NewLitRest]):-
3464 disjunction_of_literals(Q1),
3465 disjunction_of_literals(Q2),
3466 add_combined_rule(r(N1,N2,true => next Q1),LitRest,NewLitRest).
3467
3468add_combined_rule(r(N1,N2,P1 => next Q1),[],[r(N1,N2,P1 => next Q1)]).
3469
3470add_combined_rule(r(N1,N2,Q1),[],[r(N1,N2,Q1)]):-
3471 disjunction_of_literals(Q1).
3472
3474
3475remove_ok_disjuncts([H|Rest],Node,NewRest):-
3476 set_implies(H,Node),!,
3477 remove_ok_disjuncts(Rest,Node,NewRest).
3478
3479remove_ok_disjuncts([H|Rest],Node,[H|NewRest]):-
3480 remove_ok_disjuncts(Rest,Node,NewRest).
3481
3482remove_ok_disjuncts([],_,[]).
3483
3484
3486
3487collect_statistics((CPUTime,Inferences,LocalUsed,GlobalUsed,TrailUsed)):-
3488 statistics(cputime,CPUTime),
3489 statistics(inferences,Inferences),
3490 statistics(localused,LocalUsed),
3491 statistics(globalused,GlobalUsed),
3492 statistics(trailused,TrailUsed).
3493
3494calculate_statistics((CPUTime1,Inferences1,LocalUsed1,GlobalUsed1,TrailUsed1),
3495 (CPUTime2,Inferences2,LocalUsed2,GlobalUsed2,TrailUsed2)):-
3496 write('\n\nStatistics\n\n'),
3497 CPUTime is CPUTime2 - CPUTime1,
3498 writef('CPUTime:%w\n',[CPUTime]),
3499 Inferences is Inferences2 - Inferences1,
3500 writef('Inferences:%w\n',[Inferences]),
3501 LocalUsed is LocalUsed2 - LocalUsed1,
3502 writef('Local Stack:%t\n',[LocalUsed]),
3503 GlobalUsed is GlobalUsed2 - GlobalUsed1,
3504 writef('Global Stack:%t\n',[GlobalUsed]),
3505 TrailUsed is TrailUsed2 - TrailUsed1,
3506 writef('Trail Stack:%t\n',[TrailUsed]).
3507
3509
3510otres(Rules):-
3511 clear,
3512 collect_statistics(X),
3513 otres_allres(Rules,_),
3514 collect_statistics(Y),
3515 calculate_statistics(X,Y),
3516 newrulecount(N),
3517 Counter is N - 1,
3518 writef('\nNumber of clauses generated: %t\n',[Counter]).
3519
3526
3527otres_allres(Rules,AllNewRules):-
3528 startrulecount(_),
3529 snff(Rules,SNFRules),
3530 check_initial(SNFRules,NewSNFRules),
3531 number_rules(NewSNFRules,[],NumberedSNF),
3532 separate_and_format_rules(NumberedSNF,ERules,ERulePaths,OtherRules),
3533 generate_snl(OtherRules,NOtherRules),
3534 simplify_lists(NOtherRules,(Initial,Literal,Modal,Temporal)),
3535 my_write('\nSet of clauses after translation to SNF :\n'),
3536 write_ruleset((Initial,Literal,Modal,Temporal)),
3537 mres(Literal,Modal,Initial,NewerLiteral,NewerModal),
3538 write('\notres_allres (1) ==> Usable rules are \n'),
3539 write_otter_rules(NewerLiteral),nl,
3540 write('\notres_allres (1) ==> Rules in the SoS are \n'),
3541 write_otter_rules(Temporal),nl,
3542 read(OtterRules),
3543 otres_test_otter_output(OtterRules,(Initial,NewerLiteral,NewerModal,Temporal),ERulePaths,ERules,AllNewRules).
3544
3546
3547otres_allres(OldRules,NewRules,ERulePaths,ERules,AllNewRules):-
3548 number_rules(NewRules,[],NumberedRules),
3549 simplify(NumberedRules,SimpleRules),
3550 split_temp_lit_rules(SimpleRules,NewLiteral,NewTemporal),
3551 my_write('otres_allres (2) ==> New literal rules are \n'),write_ruleset(NewLiteral),
3552 my_write('otres_allres (2) ==> New temporal rules are \n'),write_ruleset(NewTemporal),
3553 step_resolution(NewLiteral,NewTemporal,OldRules,ERules,ERulePaths,AllNewRules).
3554
3562
3563check_initial(Initial,Final):-
3564 new_temp_prop(V),
3565 change_initial(Initial,V,NewList),
3566 append([start => V],NewList,Final).
3567
3568change_initial([],_,[]):-!.
3569
3570change_initial([start => X|Rest],V,[~ V or X|NewRest]):-
3571 change_initial(Rest,V,NewRest).
3572
3573change_initial([H|Rest],V,[H|NewRest]):-
3574 change_initial(Rest,V,NewRest).
3575
3580
3581generate_snl((Initial,Literal,Modal,Temporal),(Initial,NewLiteral,NewModal,NewTemporal)):-
3582 my_write('\nGenerating SNL Clauses\n'),
3583 my_write('\nTemporal Clauses are \n'),
3584 write_ruleset(Temporal),
3585 generate_snl(Temporal,Literal,Modal,NewTemporal,NewLiteral,NewModal),
3586 my_write('\nNew Temporal Clauses are \n'),
3587 write_ruleset(NewTemporal).
3588
3589generate_snl([],Literal,Modal,[],Literal,Modal).
3590
3591generate_snl([r(N1,M,X => next Y)|List],OldLiteral,OldModal,
3592 [r(N1,M,X => next Y),r(N2,[N1],NewX => next NewY)|NewList],NewerLiteral,NewerModal):-
3593 newrulecount(N2),
3594 snl(NewX,X,[N1],NewLiterals1,NewModals1),
3595 snl(NewY,Y,[N1],NewLiterals2,NewModals2),
3596 append(NewLiterals1,NewLiterals2,NewLiteral),
3597 append(NewLiteral,OldLiteral,Literal),
3598 append(NewModals1,NewModals2,NewModal),
3599 append(NewModal,OldModal,Modal),
3600 generate_snl(List,Literal,Modal,NewList,NewerLiteral,NewerModal).
3601
3602generate_snl([X|List],OldLiteral,OldModal,[X|NewList],NewerLiteral,NewerModal):-
3603 generate_snl(List,OldLiteral,OldModal,NewList,NewerLiteral,NewerModal).
3604
3609
3610generate_otter_snl(OldRules,NewOldRules,NewishLiteral,OldModal,SNewModal):-
3611 generate_snl(OldRules,[],OldModal,NewOldRules,NewLiteral,NewModal),
3612 remove_duplicate_rules(NewLiteral,NewerLiteral),
3613 remove_already_existing(NewerLiteral,NewOldRules,NewishLiteral),
3614 get_new_modal_rules(OldModal,NewModal,NewerModal),
3615 remove_duplicate_rules(NewerModal,SNewModal).
3616
3618
3619remove_already_existing([],_,[]).
3620
3621remove_already_existing([r(_,_,Rule)|Tail],OldRules,ReallyNew):-
3622 test_member(Rule,OldRules),!,
3623 remove_already_existing(Tail,OldRules,ReallyNew).
3624
3625remove_already_existing([Head|Tail],OldRules,[Head|ReallyNew]):-
3626 remove_already_existing(Tail,OldRules,ReallyNew).
3627
3629
3630separate_and_format_rules(Rules,ERules,ERulePaths,(InitialRules,LiteralRules,ModalRules,TemporalRules)):-
3631 separate_rules(Rules,AllERules,InitialRules,LiteralRules,ModalRules,TemporalRules),
3632 remove_duplicate_erules(AllERules, ERules),
3633 my_write('\n\nThe list of eventuality rules is \n\n'),
3634 write_ruleset(ERules),
3635 process_eventualities(ERules, ERulePaths).
3636
3648
3649separate_rules([],[],[],[],[],[]):-!.
3650
3651separate_rules([r(N1,N2, F => sometimes G)|Rules],
3652 [r(N1,N2, F => sometimes G)|ERules],InitialRules,LiteralRules,ModalRules,TemporalRules) :- !,
3653 separate_rules(Rules,ERules,InitialRules, LiteralRules, ModalRules, TemporalRules).
3655
3656
3657separate_rules([r(N1,N2,P => next F)|Rules],
3658 ERules,InitialRules, LiteralRules, ModalRules,[r(N1,N2, P => next F)|TemporalRules]) :- !,
3659 separate_rules(Rules,ERules, InitialRules, LiteralRules, ModalRules, TemporalRules).
3661
3662separate_rules([r(N1,N2,start => F)|Rules],
3663 ERules,[r(N1,N2,F)|InitialRules],LiteralRules, ModalRules,TemporalRules) :- !,
3664 separate_rules(Rules,ERules,InitialRules, LiteralRules,ModalRules, TemporalRules).
3666
3667separate_rules([r(N1,N2,X => k A)|Rules],
3668 ERules,InitialRules,LiteralRules, [r(N1,N2, X => k A)|ModalRules],TemporalRules) :-!,
3669 separate_rules(Rules,ERules, InitialRules, LiteralRules, ModalRules, TemporalRules).
3671
3672separate_rules([r(N1,N2,X => ~ k A)|Rules],
3673 ERules,InitialRules, LiteralRules, [r(N1,N2, X => ~ k A)|ModalRules],TemporalRules) :-!,
3674 separate_rules(Rules,ERules, InitialRules, LiteralRules,ModalRules, TemporalRules).
3676
3677separate_rules([r(N1,N2,F)|Rules],
3678 ERules,InitialRules,[r(N1,N2,F)|LiteralRules], ModalRules,TemporalRules) :-
3679 disjunction_of_literals(F),!,
3680 separate_rules(Rules,ERules, InitialRules, LiteralRules,ModalRules, TemporalRules).
3682
3683separate_rules([_|Rules],ERules,InitialRules, LiteralRules, ModalRules,TemporalRules) :-
3684 separate_rules(Rules,ERules, InitialRules, LiteralRules, ModalRules,TemporalRules).
3686
3698
3699remove_duplicate_rules([],[]).
3700
3701remove_duplicate_rules([r(_,_,Rule)|Rest], NewRules):-
3702 test_member(Rule, Rest),!,
3703 remove_duplicate_rules(Rest, NewRules).
3704
3705remove_duplicate_rules([Rule|Rest], [Rule|NewRules]):-
3706 remove_duplicate_rules(Rest, NewRules).
3707
3709
3710remove_duplicate_erules([],[]).
3711
3712remove_duplicate_erules([Rule|Rest], NewRules):-
3713 erule_in_list(Rule, Rest),!,
3714 remove_duplicate_erules(Rest, NewRules).
3715
3716remove_duplicate_erules([Rule|Rest], [Rule|NewRules]):-
3717 remove_duplicate_erules(Rest, NewRules).
3718
3725
3726erule_in_list(r(_,_, P => sometimes F), [r(_,_,Q => sometimes F)|_]):-
3727 strip(P, StrippedP),
3728 strip(Q, StrippedQ),
3729 same(StrippedP, StrippedQ).
3730
3731erule_in_list(r(N1,N2, P => sometimes F), [_|Rest]):-
3732 erule_in_list(r(N1,N2, P => sometimes F), Rest).
3733
3740
3741process_eventualities(EList, ShortEList):-
3742 extract_eventualities(EList, NewEList),
3743 remove_duplicate(NewEList, NewerEList),
3744 eventualities_paths(NewerEList,ShortEList).
3745
3751
([],[]).
3753
3754extract_eventualities([r(_,_, _ => sometimes F)|Rest], [F|NewRest]):-
3755 extract_eventualities(Rest, NewRest).
3756
3765
3766eventualities_paths([],[]).
3767
3768eventualities_paths([H|Tail],[[H,[]]|NewTail]):-
3769 eventualities_paths(Tail,NewTail).
3770
3772
3773simplify_lists((Initial,Literal,Modal,Temporal),(SInitial,SLiteral,SModal,STemporal)):-
3774 simplify(Initial,SInitial),
3775 simplify(Literal,SLiteral),
3776 simplify(Modal,SModal),
3777 simplify(Temporal,STemporal).
3778
3780
3781step_resolution(NewerLiteral,NewerTemporal,(Initial,Literal,Modal,Temporal),ERules,ERulePaths,AllNewRules):-
3782 mres(Literal,Modal,NewerLiteral,[],Initial,NewLiteral,NewModal),
3783 do_step_resolution(NewerLiteral,NewerTemporal,(Initial,Literal,Modal,Temporal),ERules,ERulePaths,AllNewRules,NewLiteral,NewModal).
3784
3785do_step_resolution(_,_,_,_,_,_,[r(0,[],false)],_):-
3786 otres_test_new_rules(_,r(0,[],false),_,_,_,_).
3787
3788do_step_resolution(NewerLiteral,NewerTemporal,(Initial,Literal,_,Temporal),ERules,ERulePaths,AllNewRules,NewLiteral,NewModal):-
3790 my_write('step_resolution ==> New temporal rules are\n'),write_ruleset(NewerTemporal),
3791 get_new_literal_rules(Literal,NewLiteral,ExtraLiteral),
3792 my_write('step_resolution ==> New literal rules are\n'),write_ruleset(ExtraLiteral),
3793 write('\nstep_resolution ==> Usable rules are \n'),
3794 write_otter_rules(Literal,Temporal),nl,
3795 write('\nstep_resolution ==>Rules in the SoS are \n'),
3796 write_otter_rules(NewerTemporal,ExtraLiteral),nl,
3797 read(OtterRules),
3798 otres_test_otter_output(OtterRules,(Initial,NewerLiteral,NewModal,Temporal),ERulePaths,ERules,AllNewRules).
3799
3801
3802otres_test_otter_output([true => next false],(_,_,_,_),_,_,NewAllRules):-
3803 write('\nHave generated false (1).\n'),
3804 otres_test_new_rules(_,r(0,[],false),_,_,_,NewAllRules).
3805
3806otres_test_otter_output([false],(_,_,_,_),_,_,NewAllRules):-
3807 write('\nHave generated false (2).\n'),
3808 otres_test_new_rules(_,r(0,[],false),_,_,_,NewAllRules).
3809
3810otres_test_otter_output(OldOtterRules,([r(_,_,X)],Literal,_,Temporal),_,_,NewAllRules):-
3811 test_member(~ X,OldOtterRules),
3812 rewrite_rules(OldOtterRules,NewOldRules,NewOtterRules),
3813 give_rules_old_numbers(NewOldRules,Literal,Temporal,NewishOldRules),
3814 sort(NewishOldRules,SortedRules),
3815 my_write('\nOutput from otter ==> New literal rules are \n'),write_ruleset(NewOtterRules),
3816 my_write('\nOutput from otter ==> Remaining rules are\n'),write_ruleset(SortedRules),
3817 write('\nHave generated false (3).\n'),
3818 otres_test_new_rules(_,r(0,[],false),_,_,_,NewAllRules).
3819
3820otres_test_otter_output(OldOtterRules,(Initial,Literal,Modal,Temporal),ERulePaths, ERules,AllNewRules):-
3821 rewrite_rules(OldOtterRules,NewOldRules,NewOtterRules),
3822 give_rules_old_numbers(NewOldRules,Literal,Temporal,NewishOldRules),
3826 generate_otter_snl(NewishOldRules,SNLNewOldRules,NewLiteral,Modal,NewModal),
3827 append(NewOtterRules,NewLiteral,NewerOtterRules),
3828 my_write('\nOutput from otter ==> New literal rules (A => next false) are \n'),write_ruleset(NewerOtterRules),
3829 my_write('\nOutput from otter ==> Remaining rules (after snl) are\n'),write_ruleset(SNLNewOldRules),
3830 my_write('\nOutput from snl ==> New modal rules are\n'),write_ruleset(NewModal),
3831 run_tempres_or_otter(SNLNewOldRules,NewerOtterRules,NewModal,(Initial,Literal,Modal,Temporal),ERulePaths, ERules,AllNewRules).
3832
3834
3836
3837run_tempres_or_otter(NonTempRules,[],NewModal,(Initial,Literal,Modal,Temporal),ERulePaths, ERules,AllNewRules):-
3838 my_write('\nrun_tempres_or_otter ==> (1)\n'),
3839 split_temp_lit_rules(NonTempRules,NewLiteral,NewTemporal),
3843 get_new_literal_rules_after_temporal(Literal,NewLiteral,SmallNewLiteral),
3844 my_write('Literal - Old Literal clauses\n'),write_ruleset(Literal),
3845 my_write('NewLiteral - All Literal clauses coming from otter\n'),write_ruleset(NewLiteral),
3846 my_write('SmallNewLiteral - the really new clauses generated by otter\n'),write_ruleset(SmallNewLiteral),
3847 run_tempres_or_modal(SmallNewLiteral,NewLiteral,NewModal,NonTempRules,NewTemporal,(Initial,Literal,Modal,Temporal),ERulePaths, ERules,AllNewRules).
3848
3849run_tempres_or_otter(NonTempRules,[],_,(Initial,Literal,Modal,Temporal),ERulePaths, ERules,AllNewRules):-
3850 my_write('\nrun_tempres_or_otter ==> (2)\n'),
3851 write_ruleset(NonTempRules),
3852 my_write('Attempting Breadth-First Temporal Resolution \n'),
3853 full_tempres(NonTempRules,ERulePaths, ERules, MoreRules,NewERulePaths,_RulesUsed),
3854 otres_test_new_rules(NonTempRules,MoreRules,(Initial,Literal,Modal,Temporal),NewERulePaths,ERules,AllNewRules).
3855
3856run_tempres_or_otter(UsableRules,SoSRules,_,(Initial,Literal,Modal,Temporal),ERulePaths,ERules,AllNewRules):-
3857 my_write('\nrun_tempres_or_otter ==> (3)\n'),
3858 write('\nrun_tempres_or_otter ==> Usable rules are \n'),
3859 write_otter_rules(UsableRules),nl,
3860 write('\nrun_tempres_or_otter ==> Rules in the SoS are \n'),
3861 write_otter_rules(SoSRules),nl,
3862 read(OtterRules),
3863 otres_test_otter_output(OtterRules,(Initial,Literal,Modal,Temporal),ERulePaths, ERules,AllNewRules).
3864
3866
3867run_tempres_or_modal([],NewLiteral,_,AllTemporal,NewTemporal,(Initial,_Literal,Modal,_Temporal),ERulePaths, ERules,AllNewRules):-
3868 my_write('\nrun_tempres_or_modal ==> (1)\n'),
3869 my_write('Attempting Breadth-First Temporal Resolution \n'),
3870 full_tempres(AllTemporal,ERulePaths, ERules, MoreRules,NewERulePaths,_RulesUsed),
3871 otres_test_new_rules(AllTemporal,MoreRules,(Initial,NewLiteral,Modal,NewTemporal),NewERulePaths, ERules,AllNewRules).
3872
3873
3874run_tempres_or_modal(ExtraLiteral,NewLiteral,NewModal,_,NewTemporal,(Initial,Literal,Modal,_Temporal),
3875 ERulePaths, ERules,AllNewRules):-
3876 my_write('\nrun_tempres_or_modal ==> (2)\n'),
3877 mres(Literal,Modal,ExtraLiteral,NewModal,Initial,FinalLiteral,FinalModal),
3878 get_new_literal_rules(Literal,NewLiteral,ExtraLiteral1),
3885 run_tempres_or_temporal(ExtraLiteral1,FinalLiteral,(Initial,Literal,FinalModal,NewTemporal),ERulePaths, ERules,AllNewRules).
3886
3888
3889run_tempres_or_temporal(_,[r(_,_,false)],_,_,_,_):-
3890 otres_test_new_rules(_,r(_,_,false),_,_,_,_).
3891
3892run_tempres_or_temporal([],NewLiteral,(Initial,_Literal,Modal,Temporal),ERulePaths, ERules,AllNewRules):-
3893 my_write('\nrun_tempres_or_temporal ==> (1)\n'),
3894 my_write('Attempting Breadth-First Temporal Resolution \n'),
3895 append(Temporal,NewLiteral,AllTemporal),
3896 full_tempres(AllTemporal,ERulePaths, ERules,MoreRules,NewERulePaths,_RulesUsed),
3897 otres_test_new_rules(AllTemporal,MoreRules,(Initial,NewLiteral,Modal,Temporal),NewERulePaths, ERules,AllNewRules).
3898
3899run_tempres_or_temporal(ExtraLiteral,NewLiteral,(Initial,Literal,Modal,Temporal),ERulePaths, ERules,AllNewRules):-
3900 my_write('\nrun_tempres_or_temporal ==> (2)\n'),
3902 write('\nrun_tempres_or_temporal ==> Usable rules are \n'),
3903 write_otter_rules(Literal,Temporal),nl,
3904 write('\nrun_tempres_or_temporal ==> Rules in the SoS are \n'),
3905 write_otter_rules(ExtraLiteral),nl,
3906 read(OtterRules),
3907 otres_test_otter_output(OtterRules,(Initial,NewLiteral,Modal,Temporal),ERulePaths, ERules,AllNewRules).
3908
3910
3911otres_test_new_rules(_,r(N1,N2,false),_,_,_,r(N1,N2,false)):-
3912 write('Formula is unsatisfiable (1).\n').
3913
3914otres_test_new_rules(_,[],_,_,_,[]):-
3915 write('Formula is satisfiable (2).\n'). 3916
3917otres_test_new_rules(OldRules,NewRules,(Initial,_,Modal,_),ERulePaths, ERules,NewAllRules):-
3918 split_temp_lit_rules(OldRules,Literal,Temporal),
3919 otres_allres((Initial,Literal,Modal,Temporal),NewRules,ERulePaths,ERules,NewAllRules).
3920
3930
3931rewrite_rules([],[],[]).
3932
3933rewrite_rules([false|_],[false],[]):-!.
3934
3935rewrite_rules([P => next false|Rules],NewOldRules,[NewRule1|NewRules]):- !,
3936 snff_negate(P, NegP),
3937 number_rule(NegP,[],NewRule1),
3938 rewrite_rules(Rules,NewOldRules,NewRules).
3939
3940rewrite_rules([Rule|Rest],NewOldRules,NewRest):-
3941 number_rule(Rule,[],NRule),
3942 simplify_rule(NRule, SRule),
3943 test_add_rule(SRule,Rest,NewOldRules,NewRest).
3944
3946
3947test_add_rule([],Rest,NewOldRules,NewRest):- !,
3948 rewrite_rules(Rest,NewOldRules,NewRest).
3949
3950test_add_rule([Rule],Rest,[Rule|NewOldRules],NewRest):-
3951 rewrite_rules(Rest,NewOldRules,NewRest).
3952
3962
3963full_tempres(r(N1,N2,false), _, _, r(N1,N2,false), _,_).
3964
3965full_tempres(_,[],ERules,NewRules,[],_):-
3966 write('\nfull_tempres (1) ==> No previous loop paths.\n'),
3967 process_path([],_,_,[],_,ERules,NewRules, _).
3968
3969full_tempres(Rules,ERulePaths,ERules,NewRules,NewERulePaths,RulesUsed):-
3970 write('\nfull_tempres (2) ==> Previous loop paths.\n'),
3971 tempres(Rules,ERulePaths,NewERule,RelatedRules,RulesUsed,LoopPath),
3972 process_path(LoopPath,RelatedRules,RulesUsed,ERulePaths,NewERule,ERules,NewRules,NewERulePaths).
3973
3991
3992process_path([],_,_,_,_ERule,_, [], _):-
3993 my_write('No more loop paths.\n').
3994
3995process_path(LoopPath,RelatedRules,RulesUsed,ERulePaths,ERule,ERules, NewRules, RotatedERulePaths):-
3996 write('The eventuality (for possibly several rules) being considered is '),
3997 write_form(ERule),nl,
3998 write('New Loop detected is '),
3999 write(LoopPath),nl,
4000 write('Loops previously detected are \n'), write(' [\n'),
4001 write_list(ERulePaths),
4002 write(' ]\n'),
4003 add_new_path_to_found_previously(ERule,LoopPath,ERulePaths,NodePath,NewERulePaths),
4004 rotate_rule(ERule,NewERulePaths,RotatedERulePaths),
4005 new_rules(ERule,LoopPath,ERules,RulesUsed,RelatedRules,NodePath,NewRules),
4006 write_ruleset(NewRules).
4007
4019
4020rotate_rule(ERule,ERulePaths,NewList):-
4021 split_list(ERule,ERulePaths,FirstBit, LastBit),
4022 append(LastBit,FirstBit,NewList).
4023
4033
4034split_list(ERule,[[ERule,PrevPath]|Rest],[[ERule,PrevPath]], Rest).
4035
4036split_list(ERule,[[AnERule,PrevPath]|Rest],[[AnERule,PrevPath]|FirstBit], LastBit):-
4037 split_list(ERule,Rest,FirstBit,LastBit).
4038
4047
4048new_rules(ERule, CycleRules, ERules, RuleNoUsed_A,RelatedRules,NodePath,NewRules):-
4049 get_rel_rules(ERule, ERules, RelRules),
4050 generate_new_rules(RelRules, CycleRules, RuleNoUsed_A,RelatedRules,NodePath,NewRules).
4051
4060
4061add_new_path_to_found_previously(ERule,NewPath,[[ERule, OldPaths]|Rest],_NodePath,[[ERule,[NewPath|OldPaths]]|Rest]).
4062
4063add_new_path_to_found_previously(ERule,NewPath,[ERulePath|Rest],NodePath,[ERulePath|NewRest]):-
4064 add_new_path_to_found_previously(ERule,NewPath,Rest,NodePath,NewRest).
4065
4073
4074get_rel_rules(_, [], []).
4075
4076get_rel_rules(F, [r(N1,N2,P => sometimes F)|Rest], [r(N1,N2,P => sometimes F)|NewRest]):-
4077 get_rel_rules(F, Rest, NewRest).
4078
4079get_rel_rules(F, [_|Rest], NewRest):-
4080 get_rel_rules(F, Rest, NewRest).
4081
4092
4093generate_new_rules([],_,_,_,_,[]).
4094
4095generate_new_rules([RelRule|Rest],CycleRules, _RuleNoUsed,RelatedRules,NodePath,AllNewRules):-
4096 generate_new_rule(RelRule, CycleRules, AllRulesUsed_ANON ,SomeNewRules),
4097 generate_new_rules(Rest, CycleRules, AllRulesUsed_ANON ,RelatedRules, NodePath,OtherNewRules),
4098 append(SomeNewRules, OtherNewRules, AllNewRules).
4099
4107
4108generate_new_rule(r(N1,_, A => sometimes F), [[true]],_RuleNoUsed,[r(0,[N1],NegA or F)]):-
4109 snff_negate(A,NegA).
4110
4111generate_new_rule(r(N1,_,true => sometimes F), [[NegF]],_RuleNoUsed,[r(0,[N1],F)]):-
4112 disjunction_of_literals(F),
4113 snff_negate(F, NegF).
4114
4115generate_new_rule(r(_N1,_,P => sometimes F),DisjunctList,_RuleNoUsed,NewRules):-
4116 neg_cycle_list(DisjunctList,NewList),
4117 construct_new_rules(P,NewList,F,NewRules).
4118
4120
4121construct_new_rules(P, List, Eventuality,[V => next (V or Eventuality), NegP or V or Eventuality |Rest]):-
4122 snff_negate(P, NegP),
4123 new_temp_prop(V),
4124 build_rules(NegP,Eventuality,V,List,Rest).
4125
4127
4128build_rules(NegP,Eventuality,V,[H|Tail],[NegP or Eventuality or H, V => next (H or Eventuality)|Rest]):-
4129 build_rules(NegP,Eventuality,V,Tail,Rest).
4130
4131build_rules(_NegP,_Eventuality,_V,[],[]).
4132
4140
4141neg_cycle_list([[P]],[NegP]):-
4142 snff_negate(P,NegP).
4143
4144neg_cycle_list([List],[NegP]):-
4145 snff_negate_list(List,NegP).
4146
4147neg_cycle_list([List|Lists], [NegP| Rest]):-
4148 snff_negate_list(List,NegP),
4149 neg_cycle_list(Lists,Rest).
4150
4152
4153snff_negate_list([H],NegH):-
4154 snff_negate(H,NegH).
4155
4156snff_negate_list([H|Rest],NegH or NewRest):-
4157 snff_negate(H,NegH),
4158 snff_negate_list(Rest,NewRest).
4159
4161
4162split_temp_lit_rules([r(N,M,A => next B)|Rest],Literal,[r(N,M,A => next B)|Temporal]):-
4163 split_temp_lit_rules(Rest,Literal,Temporal).
4164
4165split_temp_lit_rules([r(N,M,B)|Rest],[r(N,M,B)|Literal],Temporal):-
4166 disjunction_of_literals(B),
4167 split_temp_lit_rules(Rest,Literal,Temporal).
4168
4169split_temp_lit_rules([A => next B|Rest],Literal,[A => next B|Temporal]):-
4170 split_temp_lit_rules(Rest,Literal,Temporal).
4171
4172split_temp_lit_rules([B|Rest],[B|Literal],Temporal):-
4173 disjunction_of_literals(B),
4174 split_temp_lit_rules(Rest,Literal,Temporal).
4175
4176split_temp_lit_rules([],[],[]).
4177
4179
4180get_new_modal_rules(Modal,[r(N,_,_)|NewModal],Other):-
4181 rule_member(N,Modal),!,
4182 get_new_modal_rules(Modal,NewModal,Other).
4183
4184get_new_modal_rules(Modal,[r(_,_,Rule)|NewModal],Other):-
4185 test_member(Rule,Modal),
4186 get_new_modal_rules(Modal,NewModal,Other).
4187
4188get_new_modal_rules(Modal,[r(N,M,Rule)|NewModal],[r(N,M,Rule)|Other]):-
4189 get_new_modal_rules(Modal,NewModal,Other).
4190
4191get_new_modal_rules(_,[],[]).
4192
4194
4195get_new_literal_rules(Literal,[r(N,_,_)|NewLiteral],Other):-
4196 rule_member(N,Literal),!,
4197 get_new_literal_rules(Literal,NewLiteral,Other).
4198
4199get_new_literal_rules(Literal,[r(N,M,Rule)|NewLiteral],[r(N,M,Rule)|Other]):-
4200 get_new_literal_rules(Literal,NewLiteral,Other).
4201
4202get_new_literal_rules(_,[],[]).
4203
4205
4206get_new_literal_rules_after_temporal(Literal,[r(_,_,Rule)|NewLiteral],Other):-
4207 rule_in_list(Rule,Literal),!,
4208 get_new_literal_rules_after_temporal(Literal,NewLiteral,Other).
4209
4210get_new_literal_rules_after_temporal(Literal,[r(N,M,Rule)|NewLiteral],[r(N,M,Rule)|Other]):-
4211 get_new_literal_rules_after_temporal(Literal,NewLiteral,Other).
4212
4213get_new_literal_rules_after_temporal(_,[],[]).
4214
4216
4217rule_in_list(Rule,[r(_,_,Rule)|_]):- !.
4218
4219rule_in_list(D,[r(_,_,E)|_]):-
4220 strip(D,SD),
4221 strip(E,SE),
4222 same(SD,SE),!.
4223
4224rule_in_list(D,[_|Rest]):-!,
4225 rule_in_list(D,Rest).
4226
4228
4229rule_member(N,[r(N,_,_)|_]):- !.
4230
4231rule_member(N,[_|Rest]):-
4232 rule_member(N,Rest).
4233
4234rule_member(_,[]):-!,fail.
4235
4237
4238test_member(X,[X|_]).
4239
4240test_member(X,[r(_,_,X)|_]).
4241
4242test_member(X,[_|Rest]):-
4243 test_member(X,Rest).
4244
4250
4251give_rules_old_numbers([],_,_,[]).
4252
4253give_rules_old_numbers([r(N1,N2,X => next Y)|Tail],Literal,Temporal,[NRule|NewishOldRules]):-
4254 find_same_rule(r(N1,N2,X => next Y),Temporal,NRule),
4255 give_rules_old_numbers(Tail,Literal,Temporal,NewishOldRules).
4256
4257give_rules_old_numbers([r(N1,N2,X)|Tail],Literal,Temporal,[NRule|NewishOldRules]):-
4258 find_same_rule(r(N1,N2,X),Literal,NRule),
4259 give_rules_old_numbers(Tail,Literal,Temporal,NewishOldRules).
4260
4261find_same_rule(r(N1,N2,Clause),List,r(N1,N2,Clause)):-
4262 \+ (member(r(_,_,Clause),List)).
4263
4264find_same_rule(r(N1,N2,Clause),List,r(N5,N6,Clause)):-
4265 sublist(same_rule(r(N1,N2,Clause)),List,SameList),
4266 sort(SameList,Sorted),
4267 nth1(1,Sorted,r(N3,N4,Clause)),
4268 test_number(N1,N2,N3,N4,N5,N6).
4269
4270same_rule(r(_,_,X),r(_,_,Y)):-
4271 strip_or(X,SX),
4272 strip_or(Y,SY),
4273 flatten(SX,FX),
4274 flatten(SY,FY),
4275 subset(FX,FY),
4276 subset(FY,FX).
4277
4278test_number(N1,N2,N3,_N4,N1,N2):- N1 < N3.
4279test_number(_N1,_N2,N3,N4,N3,N4).
4280
4282ex354:-otres([start => x,
4283 x => sometimes p,
4284 ~ x or ~ p,
4285 x => next y,
4286 ~ y or ~ p,
4287 ~ y or t,
4288 t => next ~ p,
4289 t => next t]).
4290
4291ex5211:-otres([start => x,
4292 x => k y,
4293 y => sometimes p,
4294 x => k ~ p,
4295 x => ~ k ~ z,
4296 z => next w,
4297 ~ w or ~ p,
4298 ~ w or t,
4299 t => next ~ p,
4300 t => next t]).
4301
4302ex5212:-otres([start => x,
4303 x => sometimes y,
4304 y => k p,
4305 x => k ~ p,
4306 x => next z,
4307 ~ z or w,
4308 ~ z or t,
4309 t => next w,
4310 t => next t,
4311 w => ~ k p]).
4312
4313ex621:-otres([start => x,
4314 x => k y,
4315 y => next p,
4316 x => next z,
4317 z => ~ k p]).
4318
4319ex7121:-otres([start => x,
4320 x => next y,
4321 y => k p,
4322 x => ~ k ~ z,
4323 z => next ~ p]).
4324
4325ex7122:-otres([start => x,
4326 x => next y,
4327 y => k p,
4328 x => ~ k ~ v,
4329 ~ v or t,
4330 ~ v or u,
4331 t => next (w or ~ p),
4332 u => next (~ w or ~ p)]).
4333
4334ex7123:-otres([start => x,
4335 ~ x or z or y,
4336 ~ x or z or w,
4337 w => next (z or y),
4338 w => next (z or w),
4339 x => sometimes z,
4340 z => k p2,
4341 y => k p1,
4342 x => ~ k ~ r,
4343 ~ r or t or s,
4344 ~ r or t or u,
4345 u => next (t or s),
4346 u => next (t or u),
4347 t => ~ k p1,
4348 t => ~ k p2,
4349 s => ~ k p2]).
4350
4351ex81:-otres([~(k always p => always k p)]).
4352ex82:-otres([~(always k p => k always p)]).
4353ex83:-otres([(k sometimes p and k ~ p) => k next sometimes p]).
4354
4355ex84:-otres([start => x,
4356 ~ x or y,
4357 ~ x or a,
4358 ~ x or b,
4359 a and b => next y,
4360 a => next a,
4361 b => next b,
4362 y => k p,
4363 x => ~ k ~ w,
4364 w => sometimes ~ p]).
4365
4366ex85:-otres([start => x,
4367 ~ x or y,
4368 ~ x or a,
4369 ~ x or b,
4370 a => next y,
4371 b => next y,
4372 a => next a,
4373 b => next b,
4374 y => k p,
4375 x => ~ k ~ w,
4376 w => sometimes ~ p]).
4377
4378
4379ex86:-otres([start => x,
4380 ~ x or y,
4381 ~ x or a,
4382 ~ x or b,
4383 a => next (c or y),
4384 b => next (~ c or y),
4385 a => next a,
4386 b => next b,
4387 y => k p,
4388 x => ~ k ~ w,
4389 w => sometimes ~ p]).
4390
4391ex87:-otres([start => y,
4392 ~ y or a,
4393 ~ y or b,
4394 ~ y or l,
4395 x => next l,
4396 a => next l,
4397 b => next (c or d),
4398 c => next a,
4399 d => next a,
4400 a => next x,
4401 x => next b,
4402 y => sometimes ~ l])