-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolution.ml
951 lines (739 loc) · 32 KB
/
resolution.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
(* ========================================================================= *)
(* Resolution. *)
(* *)
(* Copyright (c) 2003-2007, John Harrison. (See "LICENSE.txt" for details.) *)
(* ========================================================================= *)
(* ------------------------------------------------------------------------- *)
(* Barber's paradox is an example of why we need factoring. *)
(* ------------------------------------------------------------------------- *)
let barb = <<~(exists b. forall x. shaves(b,x) <=> ~shaves(x,x))>>;;
START_INTERACTIVE;;
simpcnf(skolemize(Not barb));;
END_INTERACTIVE;;
(* ------------------------------------------------------------------------- *)
(* MGU of a set of literals. *)
(* ------------------------------------------------------------------------- *)
let rec mgu l env =
match l with
a::b::rest -> mgu (b::rest) (unify_literals env (a,b))
| _ -> solve env;;
let unifiable p q = can (unify_literals undefined) (p,q);;
(* ------------------------------------------------------------------------- *)
(* Rename a clause. *)
(* ------------------------------------------------------------------------- *)
let rename pfx cls =
let fvs = fv(list_disj cls) in
let vvs = map (fun s -> Var(pfx^s)) fvs in
map (subst(fpf fvs vvs)) cls;;
(* ------------------------------------------------------------------------- *)
(* General resolution rule, incorporating factoring as in Robinson's paper. *)
(* ------------------------------------------------------------------------- *)
let resolvents cl1 cl2 p acc =
let ps2 = filter (unifiable(negate p)) cl2 in
if ps2 = [] then acc else
let ps1 = filter (fun q -> q <> p & unifiable p q) cl1 in
let pairs = allpairs (fun s1 s2 -> s1,s2)
(map (fun pl -> p::pl) (allsubsets ps1))
(allnonemptysubsets ps2) in
itlist (fun (s1,s2) sof ->
try image (subst (mgu (s1 @ map negate s2) undefined))
(union (subtract cl1 s1) (subtract cl2 s2)) :: sof
with Failure _ -> sof) pairs acc;;
let resolve_clauses cls1 cls2 =
let cls1' = rename "x" cls1 and cls2' = rename "y" cls2 in
itlist (resolvents cls1' cls2') cls1' [];;
(* ------------------------------------------------------------------------- *)
(* Basic "Argonne" loop. *)
(* ------------------------------------------------------------------------- *)
let rec resloop (used,unused) =
match unused with
[] -> failwith "No proof found"
| cl::ros ->
print_string(string_of_int(length used) ^ " used; "^
string_of_int(length unused) ^ " unused.");
print_newline();
let used' = insert cl used in
let news = itlist(@) (mapfilter (resolve_clauses cl) used') [] in
if mem [] news then true else resloop (used',ros@news);;
let pure_resolution fm = resloop([],simpcnf(specialize(pnf fm)));;
let resolution fm =
let fm1 = askolemize(Not(generalize fm)) in
map (pure_resolution ** list_conj) (simpdnf fm1);;
(* ------------------------------------------------------------------------- *)
(* Simple example that works well. *)
(* ------------------------------------------------------------------------- *)
START_INTERACTIVE;;
let davis_putnam_example = resolution
<<exists x. exists y. forall z.
(F(x,y) ==> (F(y,z) /\ F(z,z))) /\
((F(x,y) /\ G(x,y)) ==> (G(x,z) /\ G(z,z)))>>;;
END_INTERACTIVE;;
(* ------------------------------------------------------------------------- *)
(* Matching of terms and literals. *)
(* ------------------------------------------------------------------------- *)
let rec term_match env eqs =
match eqs with
[] -> env
| (Fn(f,fa),Fn(g,ga))::oth when f = g & length fa = length ga ->
term_match env (zip fa ga @ oth)
| (Var x,t)::oth ->
if not (defined env x) then term_match ((x |-> t) env) oth
else if apply env x = t then term_match env oth
else failwith "term_match"
| _ -> failwith "term_match";;
let rec match_literals env tmp =
match tmp with
Atom(R(p,a1)),Atom(R(q,a2)) | Not(Atom(R(p,a1))),Not(Atom(R(q,a2))) ->
term_match env [Fn(p,a1),Fn(q,a2)]
| _ -> failwith "match_literals";;
(* ------------------------------------------------------------------------- *)
(* Test for subsumption *)
(* ------------------------------------------------------------------------- *)
let subsumes_clause cls1 cls2 =
let rec subsume env cls =
match cls with
[] -> env
| l1::clt ->
tryfind (fun l2 -> subsume (match_literals env (l1,l2)) clt)
cls2 in
can (subsume undefined) cls1;;
(* ------------------------------------------------------------------------- *)
(* With deletion of tautologies and bi-subsumption with "unused". *)
(* ------------------------------------------------------------------------- *)
let rec replace cl lis =
match lis with
[] -> [cl]
| c::cls -> if subsumes_clause cl c then cl::cls
else c::(replace cl cls);;
let incorporate gcl cl unused =
if trivial cl or
exists (fun c -> subsumes_clause c cl) (gcl::unused)
then unused else replace cl unused;;
let rec resloop (used,unused) =
match unused with
[] -> failwith "No proof found"
| cl::ros ->
print_string(string_of_int(length used) ^ " used; "^
string_of_int(length unused) ^ " unused.");
print_newline();
let used' = insert cl used in
let news = itlist(@) (mapfilter (resolve_clauses cl) used') [] in
if mem [] news then true
else resloop(used',itlist (incorporate cl) news ros);;
let pure_resolution fm = resloop([],simpcnf(specialize(pnf fm)));;
let resolution fm =
let fm1 = askolemize(Not(generalize fm)) in
map (pure_resolution ** list_conj) (simpdnf fm1);;
(* ------------------------------------------------------------------------- *)
(* This is now a lot quicker. *)
(* ------------------------------------------------------------------------- *)
START_INTERACTIVE;;
let davis_putnam_example = resolution
<<exists x. exists y. forall z.
(F(x,y) ==> (F(y,z) /\ F(z,z))) /\
((F(x,y) /\ G(x,y)) ==> (G(x,z) /\ G(z,z)))>>;;
END_INTERACTIVE;;
(* ------------------------------------------------------------------------- *)
(* Positive (P1) resolution. *)
(* ------------------------------------------------------------------------- *)
let presolve_clauses cls1 cls2 =
if forall positive cls1 or forall positive cls2
then resolve_clauses cls1 cls2 else [];;
let rec presloop (used,unused) =
match unused with
[] -> failwith "No proof found"
| cl::ros ->
print_string(string_of_int(length used) ^ " used; "^
string_of_int(length unused) ^ " unused.");
print_newline();
let used' = insert cl used in
let news = itlist(@) (mapfilter (presolve_clauses cl) used') [] in
if mem [] news then true else
presloop(used',itlist (incorporate cl) news ros);;
let pure_presolution fm = presloop([],simpcnf(specialize(pnf fm)));;
let presolution fm =
let fm1 = askolemize(Not(generalize fm)) in
map (pure_presolution ** list_conj) (simpdnf fm1);;
(* ------------------------------------------------------------------------- *)
(* Example: the (in)famous Los problem. *)
(* ------------------------------------------------------------------------- *)
START_INTERACTIVE;;
let los = time presolution
<<(forall x y z. P(x,y) ==> P(y,z) ==> P(x,z)) /\
(forall x y z. Q(x,y) ==> Q(y,z) ==> Q(x,z)) /\
(forall x y. Q(x,y) ==> Q(y,x)) /\
(forall x y. P(x,y) \/ Q(x,y))
==> (forall x y. P(x,y)) \/ (forall x y. Q(x,y))>>;;
(* ------------------------------------------------------------------------- *)
(* Introduce a set-of-support restriction. *)
(* ------------------------------------------------------------------------- *)
let pure_resolution fm =
resloop(partition (exists positive) (simpcnf(specialize(pnf fm))));;
let resolution fm =
let fm1 = askolemize(Not(generalize fm)) in
map (pure_resolution ** list_conj) (simpdnf fm1);;
(* ------------------------------------------------------------------------- *)
(* The Pelletier examples again. *)
(* ------------------------------------------------------------------------- *)
(***********
let p1 = time presolution
<<p ==> q <=> ~q ==> ~p>>;;
let p2 = time presolution
<<~ ~p <=> p>>;;
let p3 = time presolution
<<~(p ==> q) ==> q ==> p>>;;
let p4 = time presolution
<<~p ==> q <=> ~q ==> p>>;;
let p5 = time presolution
<<(p \/ q ==> p \/ r) ==> p \/ (q ==> r)>>;;
let p6 = time presolution
<<p \/ ~p>>;;
let p7 = time presolution
<<p \/ ~ ~ ~p>>;;
let p8 = time presolution
<<((p ==> q) ==> p) ==> p>>;;
let p9 = time presolution
<<(p \/ q) /\ (~p \/ q) /\ (p \/ ~q) ==> ~(~q \/ ~q)>>;;
let p10 = time presolution
<<(q ==> r) /\ (r ==> p /\ q) /\ (p ==> q /\ r) ==> (p <=> q)>>;;
let p11 = time presolution
<<p <=> p>>;;
let p12 = time presolution
<<((p <=> q) <=> r) <=> (p <=> (q <=> r))>>;;
let p13 = time presolution
<<p \/ q /\ r <=> (p \/ q) /\ (p \/ r)>>;;
let p14 = time presolution
<<(p <=> q) <=> (q \/ ~p) /\ (~q \/ p)>>;;
let p15 = time presolution
<<p ==> q <=> ~p \/ q>>;;
let p16 = time presolution
<<(p ==> q) \/ (q ==> p)>>;;
let p17 = time presolution
<<p /\ (q ==> r) ==> s <=> (~p \/ q \/ s) /\ (~p \/ ~r \/ s)>>;;
(* ------------------------------------------------------------------------- *)
(* Monadic Predicate Logic. *)
(* ------------------------------------------------------------------------- *)
let p18 = time presolution
<<exists y. forall x. P(y) ==> P(x)>>;;
let p19 = time presolution
<<exists x. forall y z. (P(y) ==> Q(z)) ==> P(x) ==> Q(x)>>;;
let p20 = time presolution
<<(forall x y. exists z. forall w. P(x) /\ Q(y) ==> R(z) /\ U(w))
==> (exists x y. P(x) /\ Q(y)) ==> (exists z. R(z))>>;;
let p21 = time presolution
<<(exists x. P ==> Q(x)) /\ (exists x. Q(x) ==> P)
==> (exists x. P <=> Q(x))>>;;
let p22 = time presolution
<<(forall x. P <=> Q(x)) ==> (P <=> (forall x. Q(x)))>>;;
let p23 = time presolution
<<(forall x. P \/ Q(x)) <=> P \/ (forall x. Q(x))>>;;
let p24 = time presolution
<<~(exists x. U(x) /\ Q(x)) /\
(forall x. P(x) ==> Q(x) \/ R(x)) /\
~(exists x. P(x) ==> (exists x. Q(x))) /\
(forall x. Q(x) /\ R(x) ==> U(x)) ==>
(exists x. P(x) /\ R(x))>>;;
let p25 = time presolution
<<(exists x. P(x)) /\
(forall x. U(x) ==> ~G(x) /\ R(x)) /\
(forall x. P(x) ==> G(x) /\ U(x)) /\
((forall x. P(x) ==> Q(x)) \/ (exists x. Q(x) /\ P(x))) ==>
(exists x. Q(x) /\ P(x))>>;;
let p26 = time presolution
<<((exists x. P(x)) <=> (exists x. Q(x))) /\
(forall x y. P(x) /\ Q(y) ==> (R(x) <=> U(y))) ==>
((forall x. P(x) ==> R(x)) <=> (forall x. Q(x) ==> U(x)))>>;;
let p27 = time presolution
<<(exists x. P(x) /\ ~Q(x)) /\
(forall x. P(x) ==> R(x)) /\
(forall x. U(x) /\ V(x) ==> P(x)) /\
(exists x. R(x) /\ ~Q(x)) ==>
(forall x. U(x) ==> ~R(x)) ==>
(forall x. U(x) ==> ~V(x))>>;;
let p28 = time presolution
<<(forall x. P(x) ==> (forall x. Q(x))) /\
((forall x. Q(x) \/ R(x)) ==> (exists x. Q(x) /\ R(x))) /\
((exists x. R(x)) ==> (forall x. L(x) ==> M(x))) ==>
(forall x. P(x) /\ L(x) ==> M(x))>>;;
let p29 = time presolution
<<(exists x. P(x)) /\ (exists x. G(x)) ==>
((forall x. P(x) ==> H(x)) /\ (forall x. G(x) ==> J(x)) <=>
(forall x y. P(x) /\ G(y) ==> H(x) /\ J(y)))>>;;
let p30 = time presolution
<<(forall x. P(x) \/ G(x) ==> ~H(x)) /\
(forall x. (G(x) ==> ~U(x)) ==> P(x) /\ H(x)) ==>
(forall x. U(x))>>;;
let p31 = time presolution
<<~(exists x. P(x) /\ (G(x) \/ H(x))) /\ (exists x. Q(x) /\ P(x)) /\
(forall x. ~H(x) ==> J(x)) ==>
(exists x. Q(x) /\ J(x))>>;;
let p32 = time presolution
<<(forall x. P(x) /\ (G(x) \/ H(x)) ==> Q(x)) /\
(forall x. Q(x) /\ H(x) ==> J(x)) /\
(forall x. R(x) ==> H(x)) ==>
(forall x. P(x) /\ R(x) ==> J(x))>>;;
let p33 = time presolution
<<(forall x. P(a) /\ (P(x) ==> P(b)) ==> P(c)) <=>
(forall x. P(a) ==> P(x) \/ P(c)) /\ (P(a) ==> P(b) ==> P(c))>>;;
let p34 = time presolution
<<((exists x. forall y. P(x) <=> P(y)) <=>
((exists x. Q(x)) <=> (forall y. Q(y)))) <=>
((exists x. forall y. Q(x) <=> Q(y)) <=>
((exists x. P(x)) <=> (forall y. P(y))))>>;;
let p35 = time presolution
<<exists x y. P(x,y) ==> (forall x y. P(x,y))>>;;
(* ------------------------------------------------------------------------- *)
(* Full predicate logic (without Identity and Functions) *)
(* ------------------------------------------------------------------------- *)
let p36 = time presolution
<<(forall x. exists y. P(x,y)) /\
(forall x. exists y. G(x,y)) /\
(forall x y. P(x,y) \/ G(x,y)
==> (forall z. P(y,z) \/ G(y,z) ==> H(x,z)))
==> (forall x. exists y. H(x,y))>>;;
let p37 = time presolution
<<(forall z.
exists w. forall x. exists y. (P(x,z) ==> P(y,w)) /\ P(y,z) /\
(P(y,w) ==> (exists u. Q(u,w)))) /\
(forall x z. ~P(x,z) ==> (exists y. Q(y,z))) /\
((exists x y. Q(x,y)) ==> (forall x. R(x,x))) ==>
(forall x. exists y. R(x,y))>>;;
(*** This one seems too slow
let p38 = time presolution
<<(forall x.
P(a) /\ (P(x) ==> (exists y. P(y) /\ R(x,y))) ==>
(exists z w. P(z) /\ R(x,w) /\ R(w,z))) <=>
(forall x.
(~P(a) \/ P(x) \/ (exists z w. P(z) /\ R(x,w) /\ R(w,z))) /\
(~P(a) \/ ~(exists y. P(y) /\ R(x,y)) \/
(exists z w. P(z) /\ R(x,w) /\ R(w,z))))>>;;
***)
let p39 = time presolution
<<~(exists x. forall y. P(y,x) <=> ~P(y,y))>>;;
let p40 = time presolution
<<(exists y. forall x. P(x,y) <=> P(x,x))
==> ~(forall x. exists y. forall z. P(z,y) <=> ~P(z,x))>>;;
let p41 = time presolution
<<(forall z. exists y. forall x. P(x,y) <=> P(x,z) /\ ~P(x,x))
==> ~(exists z. forall x. P(x,z))>>;;
(*** Also very slow
let p42 = time presolution
<<~(exists y. forall x. P(x,y) <=> ~(exists z. P(x,z) /\ P(z,x)))>>;;
***)
(*** and this one too..
let p43 = time presolution
<<(forall x y. Q(x,y) <=> forall z. P(z,x) <=> P(z,y))
==> forall x y. Q(x,y) <=> Q(y,x)>>;;
***)
let p44 = time presolution
<<(forall x. P(x) ==> (exists y. G(y) /\ H(x,y)) /\
(exists y. G(y) /\ ~H(x,y))) /\
(exists x. J(x) /\ (forall y. G(y) ==> H(x,y))) ==>
(exists x. J(x) /\ ~P(x))>>;;
(*** and this...
let p45 = time presolution
<<(forall x.
P(x) /\ (forall y. G(y) /\ H(x,y) ==> J(x,y)) ==>
(forall y. G(y) /\ H(x,y) ==> R(y))) /\
~(exists y. L(y) /\ R(y)) /\
(exists x. P(x) /\ (forall y. H(x,y) ==>
L(y)) /\ (forall y. G(y) /\ H(x,y) ==> J(x,y))) ==>
(exists x. P(x) /\ ~(exists y. G(y) /\ H(x,y)))>>;;
***)
(*** and this
let p46 = time presolution
<<(forall x. P(x) /\ (forall y. P(y) /\ H(y,x) ==> G(y)) ==> G(x)) /\
((exists x. P(x) /\ ~G(x)) ==>
(exists x. P(x) /\ ~G(x) /\
(forall y. P(y) /\ ~G(y) ==> J(x,y)))) /\
(forall x y. P(x) /\ P(y) /\ H(x,y) ==> ~J(y,x)) ==>
(forall x. P(x) ==> G(x))>>;;
***)
(* ------------------------------------------------------------------------- *)
(* Example from Manthey and Bry, CADE-9. *)
(* ------------------------------------------------------------------------- *)
let p55 = time presolution
<<lives(agatha) /\ lives(butler) /\ lives(charles) /\
(killed(agatha,agatha) \/ killed(butler,agatha) \/
killed(charles,agatha)) /\
(forall x y. killed(x,y) ==> hates(x,y) /\ ~richer(x,y)) /\
(forall x. hates(agatha,x) ==> ~hates(charles,x)) /\
(hates(agatha,agatha) /\ hates(agatha,charles)) /\
(forall x. lives(x) /\ ~richer(x,agatha) ==> hates(butler,x)) /\
(forall x. hates(agatha,x) ==> hates(butler,x)) /\
(forall x. ~hates(x,agatha) \/ ~hates(x,butler) \/ ~hates(x,charles))
==> killed(agatha,agatha) /\
~killed(butler,agatha) /\
~killed(charles,agatha)>>;;
let p57 = time presolution
<<P(f((a),b),f(b,c)) /\
P(f(b,c),f(a,c)) /\
(forall (x) y z. P(x,y) /\ P(y,z) ==> P(x,z))
==> P(f(a,b),f(a,c))>>;;
(* ------------------------------------------------------------------------- *)
(* See info-hol, circa 1500. *)
(* ------------------------------------------------------------------------- *)
let p58 = time presolution
<<forall P Q R. forall x. exists v. exists w. forall y. forall z.
((P(x) /\ Q(y)) ==> ((P(v) \/ R(w)) /\ (R(z) ==> Q(v))))>>;;
let p59 = time presolution
<<(forall x. P(x) <=> ~P(f(x))) ==> (exists x. P(x) /\ ~P(f(x)))>>;;
let p60 = time presolution
<<forall x. P(x,f(x)) <=>
exists y. (forall z. P(z,y) ==> P(z,f(x))) /\ P(x,y)>>;;
(* ------------------------------------------------------------------------- *)
(* From Gilmore's classic paper. *)
(* ------------------------------------------------------------------------- *)
let gilmore_1 = time presolution
<<exists x. forall y z.
((F(y) ==> G(y)) <=> F(x)) /\
((F(y) ==> H(y)) <=> G(x)) /\
(((F(y) ==> G(y)) ==> H(y)) <=> H(x))
==> F(z) /\ G(z) /\ H(z)>>;;
(*** This is not valid, according to Gilmore
let gilmore_2 = time presolution
<<exists x y. forall z.
(F(x,z) <=> F(z,y)) /\ (F(z,y) <=> F(z,z)) /\ (F(x,y) <=> F(y,x))
==> (F(x,y) <=> F(x,z))>>;;
***)
let gilmore_3 = time presolution
<<exists x. forall y z.
((F(y,z) ==> (G(y) ==> H(x))) ==> F(x,x)) /\
((F(z,x) ==> G(x)) ==> H(z)) /\
F(x,y)
==> F(z,z)>>;;
let gilmore_4 = time presolution
<<exists x y. forall z.
(F(x,y) ==> F(y,z) /\ F(z,z)) /\
(F(x,y) /\ G(x,y) ==> G(x,z) /\ G(z,z))>>;;
let gilmore_5 = time presolution
<<(forall x. exists y. F(x,y) \/ F(y,x)) /\
(forall x y. F(y,x) ==> F(y,y))
==> exists z. F(z,z)>>;;
let gilmore_6 = time presolution
<<forall x. exists y.
(exists u. forall v. F(u,x) ==> G(v,u) /\ G(u,x))
==> (exists u. forall v. F(u,y) ==> G(v,u) /\ G(u,y)) \/
(forall u v. exists w. G(v,u) \/ H(w,y,u) ==> G(u,w))>>;;
let gilmore_7 = time presolution
<<(forall x. K(x) ==> exists y. L(y) /\ (F(x,y) ==> G(x,y))) /\
(exists z. K(z) /\ forall u. L(u) ==> F(z,u))
==> exists v w. K(v) /\ L(w) /\ G(v,w)>>;;
let gilmore_8 = time presolution
<<exists x. forall y z.
((F(y,z) ==> (G(y) ==> (forall u. exists v. H(u,v,x)))) ==> F(x,x)) /\
((F(z,x) ==> G(x)) ==> (forall u. exists v. H(u,v,z))) /\
F(x,y)
==> F(z,z)>>;;
(*** This one still isn't easy!
let gilmore_9 = time presolution
<<forall x. exists y. forall z.
((forall u. exists v. F(y,u,v) /\ G(y,u) /\ ~H(y,x))
==> (forall u. exists v. F(x,u,v) /\ G(z,u) /\ ~H(x,z))
==> (forall u. exists v. F(x,u,v) /\ G(y,u) /\ ~H(x,y))) /\
((forall u. exists v. F(x,u,v) /\ G(y,u) /\ ~H(x,y))
==> ~(forall u. exists v. F(x,u,v) /\ G(z,u) /\ ~H(x,z))
==> (forall u. exists v. F(y,u,v) /\ G(y,u) /\ ~H(y,x)) /\
(forall u. exists v. F(z,u,v) /\ G(y,u) /\ ~H(z,y)))>>;;
***)
(* ------------------------------------------------------------------------- *)
(* Example from Davis-Putnam papers where Gilmore procedure is poor. *)
(* ------------------------------------------------------------------------- *)
let davis_putnam_example = time presolution
<<exists x. exists y. forall z.
(F(x,y) ==> (F(y,z) /\ F(z,z))) /\
((F(x,y) /\ G(x,y)) ==> (G(x,z) /\ G(z,z)))>>;;
************)
END_INTERACTIVE;;
(* ------------------------------------------------------------------------- *)
(* Example *)
(* ------------------------------------------------------------------------- *)
START_INTERACTIVE;;
let gilmore_1 = resolution
<<exists x. forall y z.
((F(y) ==> G(y)) <=> F(x)) /\
((F(y) ==> H(y)) <=> G(x)) /\
(((F(y) ==> G(y)) ==> H(y)) <=> H(x))
==> F(z) /\ G(z) /\ H(z)>>;;
(* ------------------------------------------------------------------------- *)
(* Pelletiers yet again. *)
(* ------------------------------------------------------------------------- *)
(************
let p1 = time resolution
<<p ==> q <=> ~q ==> ~p>>;;
let p2 = time resolution
<<~ ~p <=> p>>;;
let p3 = time resolution
<<~(p ==> q) ==> q ==> p>>;;
let p4 = time resolution
<<~p ==> q <=> ~q ==> p>>;;
let p5 = time resolution
<<(p \/ q ==> p \/ r) ==> p \/ (q ==> r)>>;;
let p6 = time resolution
<<p \/ ~p>>;;
let p7 = time resolution
<<p \/ ~ ~ ~p>>;;
let p8 = time resolution
<<((p ==> q) ==> p) ==> p>>;;
let p9 = time resolution
<<(p \/ q) /\ (~p \/ q) /\ (p \/ ~q) ==> ~(~q \/ ~q)>>;;
let p10 = time resolution
<<(q ==> r) /\ (r ==> p /\ q) /\ (p ==> q /\ r) ==> (p <=> q)>>;;
let p11 = time resolution
<<p <=> p>>;;
let p12 = time resolution
<<((p <=> q) <=> r) <=> (p <=> (q <=> r))>>;;
let p13 = time resolution
<<p \/ q /\ r <=> (p \/ q) /\ (p \/ r)>>;;
let p14 = time resolution
<<(p <=> q) <=> (q \/ ~p) /\ (~q \/ p)>>;;
let p15 = time resolution
<<p ==> q <=> ~p \/ q>>;;
let p16 = time resolution
<<(p ==> q) \/ (q ==> p)>>;;
let p17 = time resolution
<<p /\ (q ==> r) ==> s <=> (~p \/ q \/ s) /\ (~p \/ ~r \/ s)>>;;
(* ------------------------------------------------------------------------- *)
(* Monadic Predicate Logic. *)
(* ------------------------------------------------------------------------- *)
let p18 = time resolution
<<exists y. forall x. P(y) ==> P(x)>>;;
let p19 = time resolution
<<exists x. forall y z. (P(y) ==> Q(z)) ==> P(x) ==> Q(x)>>;;
let p20 = time resolution
<<(forall x y. exists z. forall w. P(x) /\ Q(y) ==> R(z) /\ U(w)) ==>
(exists x y. P(x) /\ Q(y)) ==>
(exists z. R(z))>>;;
let p21 = time resolution
<<(exists x. P ==> Q(x)) /\ (exists x. Q(x) ==> P) ==> (exists x. P <=> Q(x))>>;;
let p22 = time resolution
<<(forall x. P <=> Q(x)) ==> (P <=> (forall x. Q(x)))>>;;
let p23 = time resolution
<<(forall x. P \/ Q(x)) <=> P \/ (forall x. Q(x))>>;;
let p24 = time resolution
<<~(exists x. U(x) /\ Q(x)) /\
(forall x. P(x) ==> Q(x) \/ R(x)) /\
~(exists x. P(x) ==> (exists x. Q(x))) /\
(forall x. Q(x) /\ R(x) ==> U(x)) ==>
(exists x. P(x) /\ R(x))>>;;
let p25 = time resolution
<<(exists x. P(x)) /\
(forall x. U(x) ==> ~G(x) /\ R(x)) /\
(forall x. P(x) ==> G(x) /\ U(x)) /\
((forall x. P(x) ==> Q(x)) \/ (exists x. Q(x) /\ P(x))) ==>
(exists x. Q(x) /\ P(x))>>;;
let p26 = time resolution
<<((exists x. P(x)) <=> (exists x. Q(x))) /\
(forall x y. P(x) /\ Q(y) ==> (R(x) <=> U(y))) ==>
((forall x. P(x) ==> R(x)) <=> (forall x. Q(x) ==> U(x)))>>;;
let p27 = time resolution
<<(exists x. P(x) /\ ~Q(x)) /\
(forall x. P(x) ==> R(x)) /\
(forall x. U(x) /\ V(x) ==> P(x)) /\
(exists x. R(x) /\ ~Q(x)) ==>
(forall x. U(x) ==> ~R(x)) ==>
(forall x. U(x) ==> ~V(x))>>;;
let p28 = time resolution
<<(forall x. P(x) ==> (forall x. Q(x))) /\
((forall x. Q(x) \/ R(x)) ==> (exists x. Q(x) /\ R(x))) /\
((exists x. R(x)) ==> (forall x. L(x) ==> M(x))) ==>
(forall x. P(x) /\ L(x) ==> M(x))>>;;
let p29 = time resolution
<<(exists x. P(x)) /\ (exists x. G(x)) ==>
((forall x. P(x) ==> H(x)) /\ (forall x. G(x) ==> J(x)) <=>
(forall x y. P(x) /\ G(y) ==> H(x) /\ J(y)))>>;;
let p30 = time resolution
<<(forall x. P(x) \/ G(x) ==> ~H(x)) /\ (forall x. (G(x) ==> ~U(x)) ==>
P(x) /\ H(x)) ==>
(forall x. U(x))>>;;
let p31 = time resolution
<<~(exists x. P(x) /\ (G(x) \/ H(x))) /\ (exists x. Q(x) /\ P(x)) /\
(forall x. ~H(x) ==> J(x)) ==>
(exists x. Q(x) /\ J(x))>>;;
let p32 = time resolution
<<(forall x. P(x) /\ (G(x) \/ H(x)) ==> Q(x)) /\
(forall x. Q(x) /\ H(x) ==> J(x)) /\
(forall x. R(x) ==> H(x)) ==>
(forall x. P(x) /\ R(x) ==> J(x))>>;;
let p33 = time resolution
<<(forall x. P(a) /\ (P(x) ==> P(b)) ==> P(c)) <=>
(forall x. P(a) ==> P(x) \/ P(c)) /\ (P(a) ==> P(b) ==> P(c))>>;;
let p34 = time resolution
<<((exists x. forall y. P(x) <=> P(y)) <=>
((exists x. Q(x)) <=> (forall y. Q(y)))) <=>
((exists x. forall y. Q(x) <=> Q(y)) <=>
((exists x. P(x)) <=> (forall y. P(y))))>>;;
let p35 = time resolution
<<exists x y. P(x,y) ==> (forall x y. P(x,y))>>;;
(* ------------------------------------------------------------------------- *)
(* Full predicate logic (without Identity and Functions) *)
(* ------------------------------------------------------------------------- *)
let p36 = time resolution
<<(forall x. exists y. P(x,y)) /\
(forall x. exists y. G(x,y)) /\
(forall x y. P(x,y) \/ G(x,y)
==> (forall z. P(y,z) \/ G(y,z) ==> H(x,z)))
==> (forall x. exists y. H(x,y))>>;;
let p37 = time resolution
<<(forall z.
exists w. forall x. exists y. (P(x,z) ==> P(y,w)) /\ P(y,z) /\
(P(y,w) ==> (exists u. Q(u,w)))) /\
(forall x z. ~P(x,z) ==> (exists y. Q(y,z))) /\
((exists x y. Q(x,y)) ==> (forall x. R(x,x))) ==>
(forall x. exists y. R(x,y))>>;;
(*** This one seems too slow
let p38 = time resolution
<<(forall x.
P(a) /\ (P(x) ==> (exists y. P(y) /\ R(x,y))) ==>
(exists z w. P(z) /\ R(x,w) /\ R(w,z))) <=>
(forall x.
(~P(a) \/ P(x) \/ (exists z w. P(z) /\ R(x,w) /\ R(w,z))) /\
(~P(a) \/ ~(exists y. P(y) /\ R(x,y)) \/
(exists z w. P(z) /\ R(x,w) /\ R(w,z))))>>;;
***)
let p39 = time resolution
<<~(exists x. forall y. P(y,x) <=> ~P(y,y))>>;;
let p40 = time resolution
<<(exists y. forall x. P(x,y) <=> P(x,x))
==> ~(forall x. exists y. forall z. P(z,y) <=> ~P(z,x))>>;;
let p41 = time resolution
<<(forall z. exists y. forall x. P(x,y) <=> P(x,z) /\ ~P(x,x))
==> ~(exists z. forall x. P(x,z))>>;;
(*** Also very slow
let p42 = time resolution
<<~(exists y. forall x. P(x,y) <=> ~(exists z. P(x,z) /\ P(z,x)))>>;;
***)
(*** and this one too..
let p43 = time resolution
<<(forall x y. Q(x,y) <=> forall z. P(z,x) <=> P(z,y))
==> forall x y. Q(x,y) <=> Q(y,x)>>;;
***)
let p44 = time resolution
<<(forall x. P(x) ==> (exists y. G(y) /\ H(x,y)) /\
(exists y. G(y) /\ ~H(x,y))) /\
(exists x. J(x) /\ (forall y. G(y) ==> H(x,y))) ==>
(exists x. J(x) /\ ~P(x))>>;;
(*** and this...
let p45 = time resolution
<<(forall x.
P(x) /\ (forall y. G(y) /\ H(x,y) ==> J(x,y)) ==>
(forall y. G(y) /\ H(x,y) ==> R(y))) /\
~(exists y. L(y) /\ R(y)) /\
(exists x. P(x) /\ (forall y. H(x,y) ==>
L(y)) /\ (forall y. G(y) /\ H(x,y) ==> J(x,y))) ==>
(exists x. P(x) /\ ~(exists y. G(y) /\ H(x,y)))>>;;
***)
(*** and this
let p46 = time resolution
<<(forall x. P(x) /\ (forall y. P(y) /\ H(y,x) ==> G(y)) ==> G(x)) /\
((exists x. P(x) /\ ~G(x)) ==>
(exists x. P(x) /\ ~G(x) /\
(forall y. P(y) /\ ~G(y) ==> J(x,y)))) /\
(forall x y. P(x) /\ P(y) /\ H(x,y) ==> ~J(y,x)) ==>
(forall x. P(x) ==> G(x))>>;;
***)
(* ------------------------------------------------------------------------- *)
(* Example from Manthey and Bry, CADE-9. *)
(* ------------------------------------------------------------------------- *)
let p55 = time resolution
<<lives(agatha) /\ lives(butler) /\ lives(charles) /\
(killed(agatha,agatha) \/ killed(butler,agatha) \/
killed(charles,agatha)) /\
(forall x y. killed(x,y) ==> hates(x,y) /\ ~richer(x,y)) /\
(forall x. hates(agatha,x) ==> ~hates(charles,x)) /\
(hates(agatha,agatha) /\ hates(agatha,charles)) /\
(forall x. lives(x) /\ ~richer(x,agatha) ==> hates(butler,x)) /\
(forall x. hates(agatha,x) ==> hates(butler,x)) /\
(forall x. ~hates(x,agatha) \/ ~hates(x,butler) \/ ~hates(x,charles))
==> killed(agatha,agatha) /\
~killed(butler,agatha) /\
~killed(charles,agatha)>>;;
let p57 = time resolution
<<P(f((a),b),f(b,c)) /\
P(f(b,c),f(a,c)) /\
(forall (x) y z. P(x,y) /\ P(y,z) ==> P(x,z))
==> P(f(a,b),f(a,c))>>;;
(* ------------------------------------------------------------------------- *)
(* See info-hol, circa 1500. *)
(* ------------------------------------------------------------------------- *)
let p58 = time resolution
<<forall P Q R. forall x. exists v. exists w. forall y. forall z.
((P(x) /\ Q(y)) ==> ((P(v) \/ R(w)) /\ (R(z) ==> Q(v))))>>;;
let p59 = time resolution
<<(forall x. P(x) <=> ~P(f(x))) ==> (exists x. P(x) /\ ~P(f(x)))>>;;
let p60 = time resolution
<<forall x. P(x,f(x)) <=>
exists y. (forall z. P(z,y) ==> P(z,f(x))) /\ P(x,y)>>;;
(* ------------------------------------------------------------------------- *)
(* From Gilmore's classic paper. *)
(* ------------------------------------------------------------------------- *)
let gilmore_1 = time resolution
<<exists x. forall y z.
((F(y) ==> G(y)) <=> F(x)) /\
((F(y) ==> H(y)) <=> G(x)) /\
(((F(y) ==> G(y)) ==> H(y)) <=> H(x))
==> F(z) /\ G(z) /\ H(z)>>;;
(*** This is not valid, according to Gilmore
let gilmore_2 = time resolution
<<exists x y. forall z.
(F(x,z) <=> F(z,y)) /\ (F(z,y) <=> F(z,z)) /\ (F(x,y) <=> F(y,x))
==> (F(x,y) <=> F(x,z))>>;;
***)
let gilmore_3 = time resolution
<<exists x. forall y z.
((F(y,z) ==> (G(y) ==> H(x))) ==> F(x,x)) /\
((F(z,x) ==> G(x)) ==> H(z)) /\
F(x,y)
==> F(z,z)>>;;
let gilmore_4 = time resolution
<<exists x y. forall z.
(F(x,y) ==> F(y,z) /\ F(z,z)) /\
(F(x,y) /\ G(x,y) ==> G(x,z) /\ G(z,z))>>;;
let gilmore_5 = time resolution
<<(forall x. exists y. F(x,y) \/ F(y,x)) /\
(forall x y. F(y,x) ==> F(y,y))
==> exists z. F(z,z)>>;;
let gilmore_6 = time resolution
<<forall x. exists y.
(exists u. forall v. F(u,x) ==> G(v,u) /\ G(u,x))
==> (exists u. forall v. F(u,y) ==> G(v,u) /\ G(u,y)) \/
(forall u v. exists w. G(v,u) \/ H(w,y,u) ==> G(u,w))>>;;
let gilmore_7 = time resolution
<<(forall x. K(x) ==> exists y. L(y) /\ (F(x,y) ==> G(x,y))) /\
(exists z. K(z) /\ forall u. L(u) ==> F(z,u))
==> exists v w. K(v) /\ L(w) /\ G(v,w)>>;;
let gilmore_8 = time resolution
<<exists x. forall y z.
((F(y,z) ==> (G(y) ==> (forall u. exists v. H(u,v,x)))) ==> F(x,x)) /\
((F(z,x) ==> G(x)) ==> (forall u. exists v. H(u,v,z))) /\
F(x,y)
==> F(z,z)>>;;
(*** This one still isn't easy!
let gilmore_9 = time resolution
<<forall x. exists y. forall z.
((forall u. exists v. F(y,u,v) /\ G(y,u) /\ ~H(y,x))
==> (forall u. exists v. F(x,u,v) /\ G(z,u) /\ ~H(x,z))
==> (forall u. exists v. F(x,u,v) /\ G(y,u) /\ ~H(x,y))) /\
((forall u. exists v. F(x,u,v) /\ G(y,u) /\ ~H(x,y))
==> ~(forall u. exists v. F(x,u,v) /\ G(z,u) /\ ~H(x,z))
==> (forall u. exists v. F(y,u,v) /\ G(y,u) /\ ~H(y,x)) /\
(forall u. exists v. F(z,u,v) /\ G(y,u) /\ ~H(z,y)))>>;;
***)
(* ------------------------------------------------------------------------- *)
(* Example from Davis-Putnam papers where Gilmore procedure is poor. *)
(* ------------------------------------------------------------------------- *)
let davis_putnam_example = time resolution
<<exists x. exists y. forall z.
(F(x,y) ==> (F(y,z) /\ F(z,z))) /\
((F(x,y) /\ G(x,y)) ==> (G(x,z) /\ G(z,z)))>>;;
(* ------------------------------------------------------------------------- *)
(* The (in)famous Los problem. *)
(* ------------------------------------------------------------------------- *)
let los = time resolution
<<(forall x y z. P(x,y) ==> P(y,z) ==> P(x,z)) /\
(forall x y z. Q(x,y) ==> Q(y,z) ==> Q(x,z)) /\
(forall x y. Q(x,y) ==> Q(y,x)) /\
(forall x y. P(x,y) \/ Q(x,y))
==> (forall x y. P(x,y)) \/ (forall x y. Q(x,y))>>;;
**************)
END_INTERACTIVE;;