130
|
1 |
(* Title: HOL/ex/pl.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow & Lawrence C Paulson
|
|
4 |
Copyright 1994 TU Muenchen & University of Cambridge
|
|
5 |
|
|
6 |
Soundness and completeness of propositional logic w.r.t. truth-tables.
|
|
7 |
|
|
8 |
Prove: If H|=p then G|=p where G:Fin(H)
|
|
9 |
*)
|
|
10 |
|
|
11 |
open PropLog;
|
|
12 |
|
|
13 |
(** Monotonicity **)
|
|
14 |
goalw PropLog.thy thms.defs "!!G H. G<=H ==> thms(G) <= thms(H)";
|
|
15 |
by (rtac lfp_mono 1);
|
|
16 |
by (REPEAT (ares_tac basic_monos 1));
|
|
17 |
val thms_mono = result();
|
|
18 |
|
|
19 |
(*Rule is called I for Identity Combinator, not for Introduction*)
|
|
20 |
goal PropLog.thy "H |- p->p";
|
|
21 |
by(best_tac (HOL_cs addIs [thms.K,thms.S,thms.MP]) 1);
|
|
22 |
val thms_I = result();
|
|
23 |
|
|
24 |
(** Weakening, left and right **)
|
|
25 |
|
|
26 |
(* "[| G<=H; G |- p |] ==> H |- p"
|
|
27 |
This order of premises is convenient with RS
|
|
28 |
*)
|
|
29 |
val weaken_left = standard (thms_mono RS subsetD);
|
|
30 |
|
|
31 |
(* H |- p ==> insert(a,H) |- p *)
|
|
32 |
val weaken_left_insert = subset_insertI RS weaken_left;
|
|
33 |
|
|
34 |
val weaken_left_Un1 = Un_upper1 RS weaken_left;
|
|
35 |
val weaken_left_Un2 = Un_upper2 RS weaken_left;
|
|
36 |
|
|
37 |
goal PropLog.thy "!!H. H |- q ==> H |- p->q";
|
|
38 |
by(fast_tac (HOL_cs addIs [thms.K,thms.MP]) 1);
|
|
39 |
val weaken_right = result();
|
|
40 |
|
|
41 |
(*The deduction theorem*)
|
|
42 |
goal PropLog.thy "!!H. insert(p,H) |- q ==> H |- p->q";
|
|
43 |
by (etac thms.induct 1);
|
|
44 |
by (fast_tac (set_cs addIs [thms_I, thms.H RS weaken_right]) 1);
|
|
45 |
by (fast_tac (set_cs addIs [thms.K RS weaken_right]) 1);
|
|
46 |
by (fast_tac (set_cs addIs [thms.S RS weaken_right]) 1);
|
|
47 |
by (fast_tac (set_cs addIs [thms.DN RS weaken_right]) 1);
|
|
48 |
by (fast_tac (set_cs addIs [thms.S RS thms.MP RS thms.MP]) 1);
|
|
49 |
val deduction = result();
|
|
50 |
|
|
51 |
|
|
52 |
(* "[| insert(p,H) |- q; H |- p |] ==> H |- q"
|
|
53 |
The cut rule - not used
|
|
54 |
*)
|
|
55 |
val cut = deduction RS thms.MP;
|
|
56 |
|
|
57 |
(* H |- false ==> H |- p *)
|
|
58 |
val thms_falseE = weaken_right RS (thms.DN RS thms.MP);
|
|
59 |
|
|
60 |
(* [| H |- p->false; H |- p; q: pl |] ==> H |- q *)
|
|
61 |
val thms_notE = standard (thms.MP RS thms_falseE);
|
|
62 |
|
|
63 |
(** The function eval **)
|
|
64 |
|
|
65 |
val pl_ss = set_ss addsimps
|
|
66 |
(PropLog.pl.simps @ [eval2_false, eval2_var, eval2_imp]
|
|
67 |
@ [hyps_false, hyps_var, hyps_imp]);
|
|
68 |
|
|
69 |
goalw PropLog.thy [eval_def] "tt[false] = False";
|
|
70 |
by (simp_tac pl_ss 1);
|
|
71 |
val eval_false = result();
|
|
72 |
|
|
73 |
goalw PropLog.thy [eval_def] "tt[#v] = (v:tt)";
|
|
74 |
by (simp_tac pl_ss 1);
|
|
75 |
val eval_var = result();
|
|
76 |
|
|
77 |
goalw PropLog.thy [eval_def] "tt[p->q] = (tt[p]-->tt[q])";
|
|
78 |
by (simp_tac pl_ss 1);
|
|
79 |
val eval_imp = result();
|
|
80 |
|
|
81 |
val pl_ss = pl_ss addsimps [eval_false, eval_var, eval_imp];
|
|
82 |
|
|
83 |
(*Soundness of the rules wrt truth-table semantics*)
|
|
84 |
goalw PropLog.thy [sat_def] "!!H. H |- p ==> H |= p";
|
|
85 |
by (etac thms.induct 1);
|
|
86 |
by (fast_tac (set_cs addSDs [eval_imp RS iffD1 RS mp]) 5);
|
|
87 |
by (ALLGOALS (asm_simp_tac pl_ss));
|
|
88 |
val soundness = result();
|
|
89 |
|
|
90 |
(*** Towards the completeness proof ***)
|
|
91 |
|
|
92 |
goal PropLog.thy "!!H. H |- p->false ==> H |- p->q";
|
|
93 |
by (rtac deduction 1);
|
|
94 |
by (etac (weaken_left_insert RS thms_notE) 1);
|
|
95 |
by (rtac thms.H 1);
|
|
96 |
by (rtac insertI1 1);
|
|
97 |
val false_imp = result();
|
|
98 |
|
|
99 |
val [premp,premq] = goal PropLog.thy
|
|
100 |
"[| H |- p; H |- q->false |] ==> H |- (p->q)->false";
|
|
101 |
by (rtac deduction 1);
|
|
102 |
by (rtac (premq RS weaken_left_insert RS thms.MP) 1);
|
|
103 |
by (rtac (thms.H RS thms.MP) 1);
|
|
104 |
by (rtac insertI1 1);
|
|
105 |
by (rtac (premp RS weaken_left_insert) 1);
|
|
106 |
val imp_false = result();
|
|
107 |
|
|
108 |
(*This formulation is required for strong induction hypotheses*)
|
|
109 |
goal PropLog.thy "hyps(p,tt) |- if(tt[p], p, p->false)";
|
|
110 |
by (rtac (expand_if RS iffD2) 1);
|
|
111 |
by(PropLog.pl.induct_tac "p" 1);
|
|
112 |
by (ALLGOALS (simp_tac (pl_ss addsimps [thms_I, thms.H])));
|
|
113 |
by (fast_tac (set_cs addIs [weaken_left_Un1, weaken_left_Un2,
|
|
114 |
weaken_right, imp_false]
|
|
115 |
addSEs [false_imp]) 1);
|
|
116 |
val hyps_thms_if = result();
|
|
117 |
|
|
118 |
(*Key lemma for completeness; yields a set of assumptions satisfying p*)
|
|
119 |
val [sat] = goalw PropLog.thy [sat_def] "{} |= p ==> hyps(p,tt) |- p";
|
|
120 |
by (rtac (sat RS spec RS mp RS if_P RS subst) 1 THEN
|
|
121 |
rtac hyps_thms_if 2);
|
|
122 |
by (fast_tac set_cs 1);
|
|
123 |
val sat_thms_p = result();
|
|
124 |
|
|
125 |
(*For proving certain theorems in our new propositional logic*)
|
|
126 |
val thms_cs =
|
|
127 |
set_cs addSIs [deduction] addIs [thms.H, thms.H RS thms.MP];
|
|
128 |
|
|
129 |
(*The excluded middle in the form of an elimination rule*)
|
|
130 |
goal PropLog.thy "H |- (p->q) -> ((p->false)->q) -> q";
|
|
131 |
by (rtac (deduction RS deduction) 1);
|
|
132 |
by (rtac (thms.DN RS thms.MP) 1);
|
|
133 |
by (ALLGOALS (best_tac (thms_cs addSIs prems)));
|
|
134 |
val thms_excluded_middle = result();
|
|
135 |
|
|
136 |
(*Hard to prove directly because it requires cuts*)
|
|
137 |
val prems = goal PropLog.thy
|
|
138 |
"[| insert(p,H) |- q; insert(p->false,H) |- q |] ==> H |- q";
|
|
139 |
by (rtac (thms_excluded_middle RS thms.MP RS thms.MP) 1);
|
|
140 |
by (REPEAT (resolve_tac (prems@[deduction]) 1));
|
|
141 |
val thms_excluded_middle_rule = result();
|
|
142 |
|
|
143 |
(*** Completeness -- lemmas for reducing the set of assumptions ***)
|
|
144 |
|
|
145 |
(*For the case hyps(p,t)-insert(#v,Y) |- p;
|
|
146 |
we also have hyps(p,t)-{#v} <= hyps(p, t-{v}) *)
|
|
147 |
goal PropLog.thy "hyps(p, t-{v}) <= insert(#v->false, hyps(p,t)-{#v})";
|
|
148 |
by (PropLog.pl.induct_tac "p" 1);
|
|
149 |
by (simp_tac pl_ss 1);
|
|
150 |
by (simp_tac (pl_ss setloop (split_tac [expand_if])) 1);
|
|
151 |
by (simp_tac pl_ss 1);
|
|
152 |
by (fast_tac set_cs 1);
|
|
153 |
val hyps_Diff = result();
|
|
154 |
|
|
155 |
(*For the case hyps(p,t)-insert(#v -> false,Y) |- p;
|
|
156 |
we also have hyps(p,t)-{#v->false} <= hyps(p, insert(v,t)) *)
|
|
157 |
goal PropLog.thy "hyps(p, insert(v,t)) <= insert(#v, hyps(p,t)-{#v->false})";
|
|
158 |
by (PropLog.pl.induct_tac "p" 1);
|
|
159 |
by (simp_tac pl_ss 1);
|
|
160 |
by (simp_tac (pl_ss setloop (split_tac [expand_if])) 1);
|
|
161 |
by (simp_tac pl_ss 1);
|
|
162 |
by (fast_tac set_cs 1);
|
|
163 |
val hyps_insert = result();
|
|
164 |
|
|
165 |
(** Two lemmas for use with weaken_left **)
|
|
166 |
|
|
167 |
goal Set.thy "B-C <= insert(a, B-insert(a,C))";
|
|
168 |
by (fast_tac set_cs 1);
|
|
169 |
val insert_Diff_same = result();
|
|
170 |
|
|
171 |
goal Set.thy "insert(a, B-{c}) - D <= insert(a, B-insert(c,D))";
|
|
172 |
by (fast_tac set_cs 1);
|
|
173 |
val insert_Diff_subset2 = result();
|
|
174 |
|
|
175 |
(*The set hyps(p,t) is finite, and elements have the form #v or #v->false;
|
|
176 |
could probably prove the stronger hyps(p,t) : Fin(hyps(p,{}) Un hyps(p,nat))*)
|
|
177 |
goal PropLog.thy "hyps(p,t) : Fin(UN v:{x.True}. {#v, #v->false})";
|
|
178 |
by (PropLog.pl.induct_tac "p" 1);
|
|
179 |
by (ALLGOALS (simp_tac (pl_ss setloop (split_tac [expand_if])) THEN'
|
|
180 |
fast_tac (set_cs addSIs Fin.intrs@[Fin_UnI])));
|
|
181 |
val hyps_finite = result();
|
|
182 |
|
|
183 |
val Diff_weaken_left = subset_refl RSN (2, Diff_mono) RS weaken_left;
|
|
184 |
|
|
185 |
(*Induction on the finite set of assumptions hyps(p,t0).
|
|
186 |
We may repeatedly subtract assumptions until none are left!*)
|
|
187 |
val [sat] = goal PropLog.thy
|
|
188 |
"{} |= p ==> !t. hyps(p,t) - hyps(p,t0) |- p";
|
|
189 |
by (rtac (hyps_finite RS Fin_induct) 1);
|
|
190 |
by (simp_tac (pl_ss addsimps [sat RS sat_thms_p]) 1);
|
|
191 |
by (safe_tac set_cs);
|
|
192 |
(*Case hyps(p,t)-insert(#v,Y) |- p *)
|
|
193 |
by (rtac thms_excluded_middle_rule 1);
|
|
194 |
by (rtac (insert_Diff_same RS weaken_left) 1);
|
|
195 |
by (etac spec 1);
|
|
196 |
by (rtac (insert_Diff_subset2 RS weaken_left) 1);
|
|
197 |
by (rtac (hyps_Diff RS Diff_weaken_left) 1);
|
|
198 |
by (etac spec 1);
|
|
199 |
(*Case hyps(p,t)-insert(#v -> false,Y) |- p *)
|
|
200 |
by (rtac thms_excluded_middle_rule 1);
|
|
201 |
by (rtac (insert_Diff_same RS weaken_left) 2);
|
|
202 |
by (etac spec 2);
|
|
203 |
by (rtac (insert_Diff_subset2 RS weaken_left) 1);
|
|
204 |
by (rtac (hyps_insert RS Diff_weaken_left) 1);
|
|
205 |
by (etac spec 1);
|
|
206 |
val completeness_0_lemma = result();
|
|
207 |
|
|
208 |
(*The base case for completeness*)
|
|
209 |
val [sat] = goal PropLog.thy "{} |= p ==> {} |- p";
|
|
210 |
by (rtac (Diff_cancel RS subst) 1);
|
|
211 |
by (rtac (sat RS (completeness_0_lemma RS spec)) 1);
|
|
212 |
val completeness_0 = result();
|
|
213 |
|
|
214 |
(*A semantic analogue of the Deduction Theorem*)
|
|
215 |
val [sat] = goalw PropLog.thy [sat_def] "insert(p,H) |= q ==> H |= p->q";
|
|
216 |
by (simp_tac pl_ss 1);
|
|
217 |
by (cfast_tac [sat] 1);
|
|
218 |
val sat_imp = result();
|
|
219 |
|
|
220 |
val [finite] = goal PropLog.thy "H: Fin({p.True}) ==> !p. H |= p --> H |- p";
|
|
221 |
by (rtac (finite RS Fin_induct) 1);
|
|
222 |
by (safe_tac (set_cs addSIs [completeness_0]));
|
|
223 |
by (rtac (weaken_left_insert RS thms.MP) 1);
|
|
224 |
by (fast_tac (set_cs addSIs [sat_imp]) 1);
|
|
225 |
by (fast_tac thms_cs 1);
|
|
226 |
val completeness_lemma = result();
|
|
227 |
|
|
228 |
val completeness = completeness_lemma RS spec RS mp;
|
|
229 |
|
|
230 |
val [finite] = goal PropLog.thy "H: Fin({p.True}) ==> (H |- p) = (H |= p)";
|
|
231 |
by (fast_tac (set_cs addSEs [soundness, finite RS completeness]) 1);
|
|
232 |
val thms_iff = result();
|
|
233 |
|
|
234 |
writeln"Reached end of file.";
|