0
|
1 |
(* Title: HOL/ex/prop-log.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow & Lawrence C Paulson
|
|
4 |
Copyright 1993 TU Muenchen & University of Cambridge
|
|
5 |
|
|
6 |
For ex/prop-log.thy. Inductive definition of propositional logic.
|
|
7 |
Soundness and completeness w.r.t. truth-tables.
|
|
8 |
|
|
9 |
Prove: If H|=p then G|=p where G:Fin(H)
|
|
10 |
*)
|
|
11 |
|
|
12 |
open PL;
|
|
13 |
|
|
14 |
val rule_defs = [axK_def, axS_def, axDN_def, ruleMP_def];
|
|
15 |
|
|
16 |
|
|
17 |
(** Monotonicity and unfolding of the function **)
|
|
18 |
|
|
19 |
goalw PL.thy rule_defs "mono(%X. H Un axK Un axS Un axDN Un ruleMP(X))";
|
|
20 |
by (rtac monoI 1);
|
|
21 |
by(fast_tac set_cs 1);
|
|
22 |
val thms_bnd_mono = result();
|
|
23 |
|
|
24 |
goalw PL.thy [thms_def] "!!G H. G<=H ==> thms(G) <= thms(H)";
|
|
25 |
by (REPEAT (ares_tac [subset_refl, Un_mono, lfp_mono] 1));
|
|
26 |
val thms_mono = result();
|
|
27 |
|
|
28 |
(** Introduction rules for the consequence relation **)
|
|
29 |
|
|
30 |
(* thms(H) = H Int Un axK Un axS Un ruleMP(thms(H)) *)
|
|
31 |
val thms_unfold = thms_bnd_mono RS (thms_def RS def_lfp_Tarski);
|
|
32 |
|
|
33 |
(*Proof by hypothesis*)
|
|
34 |
val prems = goalw PL.thy [conseq_def] "p:H ==> H |- p";
|
|
35 |
by (rtac (thms_unfold RS ssubst) 1);
|
|
36 |
by (fast_tac (set_cs addSIs prems) 1);
|
|
37 |
val conseq_H = result();
|
|
38 |
|
|
39 |
(*Proof by axiom K*)
|
|
40 |
goalw PL.thy [conseq_def] "H |- p->q->p";
|
|
41 |
by (rtac (thms_unfold RS ssubst) 1);
|
|
42 |
by (rewtac axK_def);
|
|
43 |
by (fast_tac set_cs 1);
|
|
44 |
val conseq_K = result();
|
|
45 |
|
|
46 |
(*Proof by axiom S*)
|
|
47 |
goalw PL.thy [conseq_def] "H |- (p->q->r) -> (p->q) -> p -> r";
|
|
48 |
by (rtac (thms_unfold RS ssubst) 1);
|
|
49 |
by (rewtac axS_def);
|
|
50 |
by (fast_tac set_cs 1);
|
|
51 |
val conseq_S = result();
|
|
52 |
|
|
53 |
(*Proof by axiom DN (double negation) *)
|
|
54 |
goalw PL.thy [conseq_def] "H |- ((p->false) -> false) -> p";
|
|
55 |
by (rtac (thms_unfold RS ssubst) 1);
|
|
56 |
by (rewtac axDN_def);
|
|
57 |
by (fast_tac set_cs 1);
|
|
58 |
val conseq_DN = result();
|
|
59 |
|
|
60 |
(*Proof by rule MP (Modus Ponens) *)
|
|
61 |
val [prempq,premp] = goalw PL.thy [conseq_def]
|
|
62 |
"[| H |- p->q; H |- p |] ==> H |- q";
|
|
63 |
by (rtac (thms_unfold RS ssubst) 1);
|
|
64 |
by (rewtac ruleMP_def);
|
|
65 |
by (fast_tac (set_cs addSIs [premp,prempq]) 1);
|
|
66 |
val conseq_MP = result();
|
|
67 |
|
|
68 |
(*Rule is called I for Identity Combinator, not for Introduction*)
|
|
69 |
goal PL.thy "H |- p->p";
|
|
70 |
by (rtac (conseq_S RS conseq_MP RS conseq_MP) 1);
|
|
71 |
by (rtac conseq_K 2);
|
|
72 |
by (rtac conseq_K 1);
|
|
73 |
val conseq_I = result();
|
|
74 |
|
|
75 |
(** Weakening, left and right **)
|
|
76 |
|
|
77 |
(*This order of premises is convenient with RS*)
|
|
78 |
val prems = goalw PL.thy [conseq_def] "[| G<=H; G |- p |] ==> H |- p";
|
|
79 |
by (rtac (thms_mono RS subsetD) 1);
|
|
80 |
by (REPEAT (resolve_tac prems 1));
|
|
81 |
val weaken_left = result();
|
|
82 |
|
|
83 |
(* H |- p ==> insert(a,H) |- p *)
|
|
84 |
val weaken_left_insert = subset_insertI RS weaken_left;
|
|
85 |
|
|
86 |
val weaken_left_Un1 = Un_upper1 RS weaken_left;
|
|
87 |
val weaken_left_Un2 = Un_upper2 RS weaken_left;
|
|
88 |
|
|
89 |
val prems = goal PL.thy "H |- q ==> H |- p->q";
|
|
90 |
by (rtac (conseq_K RS conseq_MP) 1);
|
|
91 |
by (REPEAT (resolve_tac prems 1));
|
|
92 |
val weaken_right = result();
|
|
93 |
|
|
94 |
(** Rule induction for H|-p **)
|
|
95 |
|
|
96 |
(*Careful unfolding/folding to avoid a big expansion*)
|
|
97 |
val major::prems = goalw PL.thy [conseq_def]
|
|
98 |
"[| H |- a; \
|
|
99 |
\ !!x. x:H ==> P(x); \
|
|
100 |
\ !!x y. P(x->y->x); \
|
|
101 |
\ !!x y z. P((x->y->z)->(x->y)->x->z); \
|
|
102 |
\ !!x. P(((x->false)->false)->x); \
|
|
103 |
\ !!x y. [| H |- x->y; H |- x; P(x->y); P(x) |] ==> P(y) \
|
|
104 |
\ |] ==> P(a)";
|
|
105 |
by (rtac (major RS (thms_def RS def_induct)) 1);
|
|
106 |
by (rtac thms_bnd_mono 1);
|
|
107 |
by (rewrite_tac rule_defs);
|
|
108 |
by (fast_tac (set_cs addIs prems) 1);
|
|
109 |
val conseq_induct = result();
|
|
110 |
|
|
111 |
(*The deduction theorem*)
|
|
112 |
val [major] = goal PL.thy "insert(p,H) |- q ==> H |- p->q";
|
|
113 |
by (rtac (major RS conseq_induct) 1);
|
|
114 |
by (fast_tac (set_cs addIs [conseq_I, conseq_H RS weaken_right]) 1);
|
|
115 |
by (fast_tac (set_cs addIs [conseq_K RS weaken_right]) 1);
|
|
116 |
by (fast_tac (set_cs addIs [conseq_S RS weaken_right]) 1);
|
|
117 |
by (fast_tac (set_cs addIs [conseq_DN RS weaken_right]) 1);
|
|
118 |
by (fast_tac (set_cs addIs [conseq_S RS conseq_MP RS conseq_MP]) 1);
|
|
119 |
val deduction = result();
|
|
120 |
|
|
121 |
|
|
122 |
(*The cut rule*)
|
|
123 |
val prems = goal PL.thy "[| H|-p; insert(p,H) |- q |] ==> H |- q";
|
|
124 |
by (rtac (deduction RS conseq_MP) 1);
|
|
125 |
by (REPEAT (resolve_tac prems 1));
|
|
126 |
val cut = result();
|
|
127 |
|
|
128 |
val prems = goal PL.thy "H |- false ==> H |- p";
|
|
129 |
by (rtac (conseq_DN RS conseq_MP) 1);
|
|
130 |
by (rtac weaken_right 1);
|
|
131 |
by (resolve_tac prems 1);
|
|
132 |
val conseq_falseE = result();
|
|
133 |
|
|
134 |
(* [| H |- p->false; H |- p; q: pl |] ==> H |- q *)
|
|
135 |
val conseq_notE = standard (conseq_MP RS conseq_falseE);
|
|
136 |
|
|
137 |
(** The function eval **)
|
|
138 |
|
|
139 |
val pl_ss = set_ss addsimps [pl_rec_var,pl_rec_false,pl_rec_imp];
|
|
140 |
|
|
141 |
goalw PL.thy [eval_def] "tt[false] = False";
|
|
142 |
by (simp_tac pl_ss 1);
|
|
143 |
val eval_false = result();
|
|
144 |
|
|
145 |
goalw PL.thy [eval_def] "tt[#v] = (v:tt)";
|
|
146 |
by (simp_tac pl_ss 1);
|
|
147 |
val eval_var = result();
|
|
148 |
|
|
149 |
goalw PL.thy [eval_def] "tt[p->q] = (tt[p]-->tt[q])";
|
|
150 |
by (simp_tac pl_ss 1);
|
|
151 |
val eval_imp = result();
|
|
152 |
|
|
153 |
val pl_ss = pl_ss addsimps [eval_false, eval_var, eval_imp];
|
|
154 |
|
|
155 |
(** The function hyps **)
|
|
156 |
|
|
157 |
goalw PL.thy [hyps_def] "hyps(false,tt) = {}";
|
|
158 |
by (simp_tac pl_ss 1);
|
|
159 |
val hyps_false = result();
|
|
160 |
|
|
161 |
goalw PL.thy [hyps_def] "hyps(#v,tt) = {if(v:tt, #v, #v->false)}";
|
|
162 |
by (simp_tac pl_ss 1);
|
|
163 |
val hyps_var = result();
|
|
164 |
|
|
165 |
goalw PL.thy [hyps_def] "hyps(p->q,tt) = hyps(p,tt) Un hyps(q,tt)";
|
|
166 |
by (simp_tac pl_ss 1);
|
|
167 |
val hyps_imp = result();
|
|
168 |
|
|
169 |
val pl_ss = pl_ss addsimps [hyps_false, hyps_var, hyps_imp];
|
|
170 |
|
|
171 |
val ball_eq = prove_goalw Set.thy [Ball_def] "(!x:A.P(x)) = (!x.x:A --> P(x))"
|
|
172 |
(fn _ => [rtac refl 1]);
|
|
173 |
|
|
174 |
(*Soundness of the rules wrt truth-table semantics*)
|
|
175 |
val [major] = goalw PL.thy [sat_def] "H |- p ==> H |= p";
|
|
176 |
by (rtac (major RS conseq_induct) 1);
|
|
177 |
by (fast_tac (set_cs addSDs [eval_imp RS iffD1 RS mp]) 5);
|
|
178 |
by (ALLGOALS (asm_simp_tac(pl_ss addsimps
|
|
179 |
[ball_eq,not_def RS fun_cong RS sym])));
|
|
180 |
val soundness = result();
|
|
181 |
|
|
182 |
(** Structural induction on pl
|
|
183 |
|
|
184 |
val major::prems = goalw PL.thy pl_defs
|
|
185 |
"[| q: pl; \
|
|
186 |
\ P(false); \
|
|
187 |
\ !!v. v:nat ==> P(#v); \
|
|
188 |
\ !!q1 q2. [| q1: pl; q2: pl; P(q1); P(q2) |] ==> P(q1->q2) \
|
|
189 |
\ |] ==> P(q)";
|
|
190 |
by (rtac (major RS sexp_induct) 1);
|
|
191 |
by (etac nat_induct 1);
|
|
192 |
by (REPEAT (ares_tac prems 1));
|
|
193 |
val pl_induct = result();
|
|
194 |
**)
|
|
195 |
(*** Towards the completeness proof ***)
|
|
196 |
|
|
197 |
val [premf] = goal PL.thy "H |- p->false ==> H |- p->q";
|
|
198 |
by (rtac deduction 1);
|
|
199 |
by (rtac (premf RS weaken_left_insert RS conseq_notE) 1);
|
|
200 |
by (rtac conseq_H 1);
|
|
201 |
by (rtac insertI1 1);
|
|
202 |
val false_imp = result();
|
|
203 |
|
|
204 |
val [premp,premq] = goal PL.thy
|
|
205 |
"[| H |- p; H |- q->false |] ==> H |- (p->q)->false";
|
|
206 |
by (rtac deduction 1);
|
|
207 |
by (rtac (premq RS weaken_left_insert RS conseq_MP) 1);
|
|
208 |
by (rtac (conseq_H RS conseq_MP) 1);
|
|
209 |
by (rtac insertI1 1);
|
|
210 |
by (rtac (premp RS weaken_left_insert) 1);
|
|
211 |
val imp_false = result();
|
|
212 |
|
|
213 |
(*This formulation is required for strong induction hypotheses*)
|
|
214 |
goal PL.thy "hyps(p,tt) |- if(tt[p], p, p->false)";
|
|
215 |
by (rtac (expand_if RS iffD2) 1);
|
|
216 |
by(res_inst_tac[("x","p")]spec 1);
|
|
217 |
by (rtac pl_ind 1);
|
|
218 |
by (ALLGOALS (simp_tac (pl_ss addsimps [conseq_I, conseq_H])));
|
|
219 |
by (fast_tac (set_cs addIs [weaken_left_Un1, weaken_left_Un2,
|
|
220 |
weaken_right, imp_false]
|
|
221 |
addSEs [false_imp]) 1);
|
|
222 |
val hyps_conseq_if = result();
|
|
223 |
|
|
224 |
(*Key lemma for completeness; yields a set of assumptions satisfying p*)
|
|
225 |
val [sat] = goalw PL.thy [sat_def] "{} |= p ==> hyps(p,tt) |- p";
|
|
226 |
by (rtac (sat RS spec RS mp RS if_P RS subst) 1 THEN
|
|
227 |
rtac hyps_conseq_if 2);
|
|
228 |
by (fast_tac set_cs 1);
|
|
229 |
val sat_conseq_p = result();
|
|
230 |
|
|
231 |
(*For proving certain theorems in our new propositional logic*)
|
|
232 |
val conseq_cs =
|
|
233 |
set_cs addSIs [deduction] addIs [conseq_H, conseq_H RS conseq_MP];
|
|
234 |
|
|
235 |
(*The excluded middle in the form of an elimination rule*)
|
|
236 |
goal PL.thy "H |- (p->q) -> ((p->false)->q) -> q";
|
|
237 |
by (rtac (deduction RS deduction) 1);
|
|
238 |
by (rtac (conseq_DN RS conseq_MP) 1);
|
|
239 |
by (ALLGOALS (best_tac (conseq_cs addSIs prems)));
|
|
240 |
val conseq_excluded_middle = result();
|
|
241 |
|
|
242 |
(*Hard to prove directly because it requires cuts*)
|
|
243 |
val prems = goal PL.thy
|
|
244 |
"[| insert(p,H) |- q; insert(p->false,H) |- q |] ==> H |- q";
|
|
245 |
by (rtac (conseq_excluded_middle RS conseq_MP RS conseq_MP) 1);
|
|
246 |
by (REPEAT (resolve_tac (prems@[deduction]) 1));
|
|
247 |
val conseq_excluded_middle_rule = result();
|
|
248 |
|
|
249 |
(*** Completeness -- lemmas for reducing the set of assumptions ***)
|
|
250 |
|
|
251 |
(*For the case hyps(p,t)-insert(#v,Y) |- p;
|
|
252 |
we also have hyps(p,t)-{#v} <= hyps(p, t-{v}) *)
|
|
253 |
goal PL.thy "!p.hyps(p, t-{v}) <= insert(#v->false, hyps(p,t)-{#v})";
|
|
254 |
by (rtac pl_ind 1);
|
|
255 |
by (simp_tac pl_ss 1);
|
|
256 |
by (simp_tac (pl_ss setloop (split_tac [expand_if])) 1);
|
|
257 |
by (fast_tac (set_cs addSEs [sym RS var_neq_imp] addSDs [var_inject]) 1);
|
|
258 |
by (simp_tac pl_ss 1);
|
|
259 |
by (fast_tac set_cs 1);
|
|
260 |
val hyps_Diff = result() RS spec;
|
|
261 |
|
|
262 |
(*For the case hyps(p,t)-insert(#v -> false,Y) |- p;
|
|
263 |
we also have hyps(p,t)-{#v->false} <= hyps(p, insert(v,t)) *)
|
|
264 |
goal PL.thy "!p.hyps(p, insert(v,t)) <= insert(#v, hyps(p,t)-{#v->false})";
|
|
265 |
by (rtac pl_ind 1);
|
|
266 |
by (simp_tac pl_ss 1);
|
|
267 |
by (simp_tac (pl_ss setloop (split_tac [expand_if])) 1);
|
|
268 |
by (fast_tac (set_cs addSEs [var_neq_imp, imp_inject] addSDs [var_inject]) 1);
|
|
269 |
by (simp_tac pl_ss 1);
|
|
270 |
by (fast_tac set_cs 1);
|
|
271 |
val hyps_insert = result() RS spec;
|
|
272 |
|
|
273 |
(** Two lemmas for use with weaken_left **)
|
|
274 |
|
|
275 |
goal Set.thy "B-C <= insert(a, B-insert(a,C))";
|
|
276 |
by (fast_tac set_cs 1);
|
|
277 |
val insert_Diff_same = result();
|
|
278 |
|
|
279 |
goal Set.thy "insert(a, B-{c}) - D <= insert(a, B-insert(c,D))";
|
|
280 |
by (fast_tac set_cs 1);
|
|
281 |
val insert_Diff_subset2 = result();
|
|
282 |
|
|
283 |
(*The set hyps(p,t) is finite, and elements have the form #v or #v->false;
|
|
284 |
could probably prove the stronger hyps(p,t) : Fin(hyps(p,{}) Un hyps(p,nat))*)
|
|
285 |
goal PL.thy "!p.hyps(p,t) : Fin(UN v:{x.True}. {#v, #v->false})";
|
|
286 |
by (rtac pl_ind 1);
|
|
287 |
by (ALLGOALS (simp_tac (pl_ss setloop (split_tac [expand_if])) THEN'
|
|
288 |
fast_tac (set_cs addSIs [Fin_0I, Fin_insertI, Fin_UnI])));
|
|
289 |
val hyps_finite = result() RS spec;
|
|
290 |
|
|
291 |
val Diff_weaken_left = subset_refl RSN (2, Diff_mono) RS weaken_left;
|
|
292 |
|
|
293 |
(*Induction on the finite set of assumptions hyps(p,t0).
|
|
294 |
We may repeatedly subtract assumptions until none are left!*)
|
|
295 |
val [sat] = goal PL.thy
|
|
296 |
"{} |= p ==> !t. hyps(p,t) - hyps(p,t0) |- p";
|
|
297 |
by (rtac (hyps_finite RS Fin_induct) 1);
|
|
298 |
by (simp_tac (pl_ss addsimps [sat RS sat_conseq_p]) 1);
|
|
299 |
by (safe_tac set_cs);
|
|
300 |
(*Case hyps(p,t)-insert(#v,Y) |- p *)
|
|
301 |
by (rtac conseq_excluded_middle_rule 1);
|
|
302 |
by (rtac (insert_Diff_same RS weaken_left) 1);
|
|
303 |
by (etac spec 1);
|
|
304 |
by (rtac (insert_Diff_subset2 RS weaken_left) 1);
|
|
305 |
by (rtac (hyps_Diff RS Diff_weaken_left) 1);
|
|
306 |
by (etac spec 1);
|
|
307 |
(*Case hyps(p,t)-insert(#v -> false,Y) |- p *)
|
|
308 |
by (rtac conseq_excluded_middle_rule 1);
|
|
309 |
by (rtac (insert_Diff_same RS weaken_left) 2);
|
|
310 |
by (etac spec 2);
|
|
311 |
by (rtac (insert_Diff_subset2 RS weaken_left) 1);
|
|
312 |
by (rtac (hyps_insert RS Diff_weaken_left) 1);
|
|
313 |
by (etac spec 1);
|
|
314 |
val completeness_0_lemma = result();
|
|
315 |
|
|
316 |
(*The base case for completeness*)
|
|
317 |
val [sat] = goal PL.thy "{} |= p ==> {} |- p";
|
|
318 |
by (rtac (Diff_cancel RS subst) 1);
|
|
319 |
by (rtac (sat RS (completeness_0_lemma RS spec)) 1);
|
|
320 |
val completeness_0 = result();
|
|
321 |
|
|
322 |
(*A semantic analogue of the Deduction Theorem*)
|
|
323 |
val [sat] = goalw PL.thy [sat_def] "insert(p,H) |= q ==> H |= p->q";
|
|
324 |
by (simp_tac pl_ss 1);
|
|
325 |
by (cfast_tac [sat] 1);
|
|
326 |
val sat_imp = result();
|
|
327 |
|
|
328 |
val [finite] = goal PL.thy "H: Fin({p.True}) ==> !p. H |= p --> H |- p";
|
|
329 |
by (rtac (finite RS Fin_induct) 1);
|
|
330 |
by (safe_tac (set_cs addSIs [completeness_0]));
|
|
331 |
by (rtac (weaken_left_insert RS conseq_MP) 1);
|
|
332 |
by (fast_tac (set_cs addSIs [sat_imp]) 1);
|
|
333 |
by (fast_tac conseq_cs 1);
|
|
334 |
val completeness_lemma = result();
|
|
335 |
|
|
336 |
val completeness = completeness_lemma RS spec RS mp;
|
|
337 |
|
|
338 |
val [finite] = goal PL.thy "H: Fin({p.True}) ==> (H |- p) = (H |= p)";
|
|
339 |
by (fast_tac (set_cs addSEs [soundness, finite RS completeness]) 1);
|
|
340 |
val conseq_iff = result();
|
|
341 |
|
|
342 |
writeln"Reached end of file.";
|
|
343 |
|
|
344 |
|