-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.ml
177 lines (147 loc) · 8.21 KB
/
example.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
(* ========================================================================= *)
(* Some examples illustrating how the theorem-proving code can be used. *)
(* *)
(* Copyright (c) 2003-2007, John Harrison. (See "LICENSE.txt" for details.) *)
(* ========================================================================= *)
include Atp_batch;;
(*include Format;;*)
print_string "Starting examples\n";;
(* ------------------------------------------------------------------------- *)
(* Printer for formulas, to give feedback when not using toplevel. *)
(* ------------------------------------------------------------------------- *)
let print_formula fm = print_qformula print_atom fm; print_newline();;
(* ------------------------------------------------------------------------- *)
(* Prove Dijkstra's "Golden Rule" via naive tautology algorithm. *)
(* ------------------------------------------------------------------------- *)
let gold = <<p /\ q <=> ((p <=> q) <=> p \/ q)>> in
if tautology gold then print_formula gold else failwith "Not a tautology";;
(* ------------------------------------------------------------------------- *)
(* Solve some instances of Urquhart problems using Stalmarck's algorithm. *)
(* ------------------------------------------------------------------------- *)
let urquhart n =
let pvs = map (fun n -> Atom(P("p_"^(string_of_int n)))) (1 -- n) in
end_itlist (fun p q -> Iff(p,q)) (pvs @ pvs);;
do_list (time stalmarck ** urquhart) [1;2;4;8;16];;
(* ------------------------------------------------------------------------- *)
(* Print a propositional formula asserting that 11 is a prime number. *)
(* ------------------------------------------------------------------------- *)
let prf = prime 11 in
print_qformula print_propvar prf; print_newline();;
(* ------------------------------------------------------------------------- *)
(* Prove Agatha formula using simple tableaux after initial splitting. *)
(* ------------------------------------------------------------------------- *)
let p55 =
<<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)>> in
if can (time splittab) p55 then print_formula p55
else failwith "Proof failed";;
(* ------------------------------------------------------------------------- *)
(* Prove the Los formula using positive resolution. *)
(* ------------------------------------------------------------------------- *)
let los =
<<(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))>> in
if can (time presolution) los then print_formula los
else failwith "Proof failed";;
(* ------------------------------------------------------------------------- *)
(* Prove Wishnu Prasetya's formula by just adding equality axioms. *)
(* ------------------------------------------------------------------------- *)
let wishnu =
<<(exists x. x = f(g(x)) /\ forall x'. x' = f(g(x')) ==> x = x') <=>
(exists y. y = g(f(y)) /\ forall y'. y' = g(f(y')) ==> y = y')>> in
if can meson (equalitize wishnu) then print_formula wishnu
else failwith "Formula was not proved";;
(* ------------------------------------------------------------------------- *)
(* Prove a formula from EWD1266a using paramodulation. *)
(* ------------------------------------------------------------------------- *)
let ewd =
<<(forall x. f(x) ==> g(x)) /\
(exists x. f(x)) /\
(forall x y. g(x) /\ g(y) ==> x = y)
==> forall y. g(y) ==> f(y)>> in
if can (time paramodulation) ewd then print_formula ewd
else failwith "Proof failed";;
(* ------------------------------------------------------------------------- *)
(* Perform Knuth-Bendix completion on the group axioms. *)
(* ------------------------------------------------------------------------- *)
let eqs =
complete_and_simplify
["1"; "*"; "i"]
[<<1 * x = x>>; <<i(x) * x = 1>>; <<(x * y) * z = x * y * z>>] in
do_list print_formula eqs;;
(* ------------------------------------------------------------------------- *)
(* Produce all valid syllogisms (permitting empty relations). *)
(* ------------------------------------------------------------------------- *)
let all_valid_syllogisms =
map anglicize_syllogism (filter aedecide all_possible_syllogisms) in
do_list (fun syl -> print_string syl; print_newline()) all_valid_syllogisms;;
(* ------------------------------------------------------------------------- *)
(* Check a resultant (from Maple) by complex quantifier elimination. *)
(* ------------------------------------------------------------------------- *)
let result =
time complex_qelim
<<forall a b c d e f.
(exists x. a * x^2 + b * x + c = 0 /\ d * x^2 + e * x + f = 0) \/
(a = 0) /\ (d = 0) <=>
d^2*c^2-2*d*c*a*f+a^2*f^2-e*d*b*c-e*b*a*f+a*e^2*c+f*d*b^2 = 0>> in
print_formula result;;
(* ------------------------------------------------------------------------- *)
(* Perform real quantifier elimination on false and true quadratic criteria. *)
(* ------------------------------------------------------------------------- *)
let quad_f =
time real_qelim
<<forall a b c. (exists x. a * x^2 + b * x + c = 0) <=>
b^2 >= 4 * a * c>> in
print_formula quad_f;;
let quad_t =
time real_qelim
<<forall a b c. (exists x. a * x^2 + b * x + c = 0) <=>
a = 0 /\ (~(b = 0) \/ c = 0) \/
~(a = 0) /\ b^2 >= 4 * a * c>> in
print_formula quad_t;;
(* ------------------------------------------------------------------------- *)
(* Prove a key lemma for Loeb's theorem by Mizar-like interactive proof and *)
(* turn it into a strict LCF proof afterwards. *)
(* ------------------------------------------------------------------------- *)
let lob = prove
<<(forall p. |--(p) ==> |--(Pr(p))) /\
(forall p q. |--(imp(Pr(imp(p,q)),imp(Pr(p),Pr(q))))) /\
(forall p. |--(imp(Pr(p),Pr(Pr(p)))))
==> (forall p q. |--(imp(p,q)) /\ |--(p) ==> |--(q)) /\
(forall p q. |--(imp(q,imp(p,q)))) /\
(forall p q r. |--(imp(imp(p,imp(q,r)),imp(imp(p,q),imp(p,r)))))
==> |--(imp(G,imp(Pr(G),S))) /\ |--(imp(imp(Pr(G),S),G))
==> |--(imp(Pr(S),S)) ==> |--(S)>>
[assume["lob1",<<forall p. |--(p) ==> |--(Pr(p))>>;
"lob2",<<forall p q. |--(imp(Pr(imp(p,q)),imp(Pr(p),Pr(q))))>>;
"lob3",<<forall p. |--(imp(Pr(p),Pr(Pr(p))))>>];
assume["logic",<<(forall p q. |--(imp(p,q)) /\ |--(p) ==> |--(q)) /\
(forall p q. |--(imp(q,imp(p,q)))) /\
(forall p q r. |--(imp(imp(p,imp(q,r)),
imp(imp(p,q),imp(p,r)))))>>];
assume ["fix1",<<|--(imp(G,imp(Pr(G),S)))>>;
"fix2",<<|--(imp(imp(Pr(G),S),G))>>];
assume["consistency",<<|--(imp(Pr(S),S))>>];
have <<|--(Pr(imp(G,imp(Pr(G),S))))>> by ["lob1"; "fix1"];
so have <<|--(imp(Pr(G),Pr(imp(Pr(G),S))))>> by ["lob2"; "logic"];
so have <<|--(imp(Pr(G),imp(Pr(Pr(G)),Pr(S))))>> by ["lob2"; "logic"];
so have <<|--(imp(Pr(G),Pr(S)))>> by ["lob3"; "logic"];
so note("L",<<|--(imp(Pr(G),S))>>) by ["consistency"; "logic"];
so have <<|--(G)>> by ["fix2"; "logic"];
so have <<|--(Pr(G))>> by ["lob1"; "logic"];
so conclude <<|--(S)>> by ["L"; "logic"];
qed] in
print_thm lob; print_newline();;