src/ZF/ex/PropLog.ML
 author lcp Tue Aug 16 18:58:42 1994 +0200 (1994-08-16) changeset 532 851df239ac8b parent 515 abcc438e7c27 child 760 f0200e91b272 permissions -rw-r--r--
ZF/Makefile,ROOT.ML, ZF/ex/Integ.thy: updated for EquivClass
1 (*  Title: 	ZF/ex/prop-log.ML
2     ID:         \$Id\$
3     Author: 	Tobias Nipkow & Lawrence C Paulson
4     Copyright   1992  University of Cambridge
6 For ex/prop-log.thy.  Inductive definition of propositional logic.
7 Soundness and completeness w.r.t. truth-tables.
9 Prove: If H|=p then G|=p where G:Fin(H)
10 *)
12 open PropLog;
14 (*** prop_rec -- by Vset recursion ***)
16 (** conversion rules **)
18 goal PropLog.thy "prop_rec(Fls,b,c,d) = b";
19 by (rtac (prop_rec_def RS def_Vrec RS trans) 1);
20 by (rewrite_goals_tac prop.con_defs);
21 by (simp_tac rank_ss 1);
22 val prop_rec_Fls = result();
24 goal PropLog.thy "prop_rec(#v,b,c,d) = c(v)";
25 by (rtac (prop_rec_def RS def_Vrec RS trans) 1);
26 by (rewrite_goals_tac prop.con_defs);
27 by (simp_tac rank_ss 1);
28 val prop_rec_Var = result();
30 goal PropLog.thy "prop_rec(p=>q,b,c,d) = \
31 \      d(p, q, prop_rec(p,b,c,d), prop_rec(q,b,c,d))";
32 by (rtac (prop_rec_def RS def_Vrec RS trans) 1);
33 by (rewrite_goals_tac prop.con_defs);
34 by (simp_tac rank_ss 1);
35 val prop_rec_Imp = result();
37 val prop_rec_ss =
38     arith_ss addsimps [prop_rec_Fls, prop_rec_Var, prop_rec_Imp];
40 (*** Semantics of propositional logic ***)
42 (** The function is_true **)
44 goalw PropLog.thy [is_true_def] "is_true(Fls,t) <-> False";
45 by (simp_tac (prop_rec_ss addsimps [one_not_0 RS not_sym]) 1);
46 val is_true_Fls = result();
48 goalw PropLog.thy [is_true_def] "is_true(#v,t) <-> v:t";
49 by (simp_tac (prop_rec_ss addsimps [one_not_0 RS not_sym]
50 	      setloop (split_tac [expand_if])) 1);
51 val is_true_Var = result();
53 goalw PropLog.thy [is_true_def]
54     "is_true(p=>q,t) <-> (is_true(p,t)-->is_true(q,t))";
55 by (simp_tac (prop_rec_ss setloop (split_tac [expand_if])) 1);
56 val is_true_Imp = result();
58 (** The function hyps **)
60 goalw PropLog.thy [hyps_def] "hyps(Fls,t) = 0";
61 by (simp_tac prop_rec_ss 1);
62 val hyps_Fls = result();
64 goalw PropLog.thy [hyps_def] "hyps(#v,t) = {if(v:t, #v, #v=>Fls)}";
65 by (simp_tac prop_rec_ss 1);
66 val hyps_Var = result();
68 goalw PropLog.thy [hyps_def] "hyps(p=>q,t) = hyps(p,t) Un hyps(q,t)";
69 by (simp_tac prop_rec_ss 1);
70 val hyps_Imp = result();
72 val prop_ss = prop_rec_ss
75 	      hyps_Fls, hyps_Var, hyps_Imp];
77 (*** Proof theory of propositional logic ***)
79 goalw PropLog.thy thms.defs "!!G H. G<=H ==> thms(G) <= thms(H)";
80 by (rtac lfp_mono 1);
81 by (REPEAT (rtac thms.bnd_mono 1));
82 by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
83 val thms_mono = result();
85 val thms_in_pl = thms.dom_subset RS subsetD;
87 val ImpE = prop.mk_cases prop.con_defs "p=>q : prop";
89 (*Stronger Modus Ponens rule: no typechecking!*)
90 goal PropLog.thy "!!p q H. [| H |- p=>q;  H |- p |] ==> H |- q";
91 by (rtac thms.MP 1);
92 by (REPEAT (eresolve_tac [asm_rl, thms_in_pl, thms_in_pl RS ImpE] 1));
93 val thms_MP = result();
95 (*Rule is called I for Identity Combinator, not for Introduction*)
96 goal PropLog.thy "!!p H. p:prop ==> H |- p=>p";
97 by (rtac (thms.S RS thms_MP RS thms_MP) 1);
98 by (rtac thms.K 5);
99 by (rtac thms.K 4);
100 by (REPEAT (ares_tac prop.intrs 1));
101 val thms_I = result();
103 (** Weakening, left and right **)
105 (* [| G<=H;  G|-p |] ==> H|-p   Order of premises is convenient with RS*)
106 val weaken_left = standard (thms_mono RS subsetD);
108 (* H |- p ==> cons(a,H) |- p *)
109 val weaken_left_cons = subset_consI RS weaken_left;
111 val weaken_left_Un1  = Un_upper1 RS weaken_left;
112 val weaken_left_Un2  = Un_upper2 RS weaken_left;
114 goal PropLog.thy "!!H p q. [| H |- q;  p:prop |] ==> H |- p=>q";
115 by (rtac (thms.K RS thms_MP) 1);
116 by (REPEAT (ares_tac [thms_in_pl] 1));
117 val weaken_right = result();
119 (*The deduction theorem*)
120 goal PropLog.thy "!!p q H. [| cons(p,H) |- q;  p:prop |] ==>  H |- p=>q";
121 by (etac thms.induct 1);
122 by (fast_tac (ZF_cs addIs [thms_I, thms.H RS weaken_right]) 1);
123 by (fast_tac (ZF_cs addIs [thms.K RS weaken_right]) 1);
124 by (fast_tac (ZF_cs addIs [thms.S RS weaken_right]) 1);
125 by (fast_tac (ZF_cs addIs [thms.DN RS weaken_right]) 1);
126 by (fast_tac (ZF_cs addIs [thms.S RS thms_MP RS thms_MP]) 1);
127 val deduction = result();
130 (*The cut rule*)
131 goal PropLog.thy "!!H p q. [| H|-p;  cons(p,H) |- q |] ==>  H |- q";
132 by (rtac (deduction RS thms_MP) 1);
133 by (REPEAT (ares_tac [thms_in_pl] 1));
134 val cut = result();
136 goal PropLog.thy "!!H p. [| H |- Fls; p:prop |] ==> H |- p";
137 by (rtac (thms.DN RS thms_MP) 1);
138 by (rtac weaken_right 2);
139 by (REPEAT (ares_tac (prop.intrs@[consI1]) 1));
140 val thms_FlsE = result();
142 (* [| H |- p=>Fls;  H |- p;  q: prop |] ==> H |- q *)
143 val thms_notE = standard (thms_MP RS thms_FlsE);
145 (*Soundness of the rules wrt truth-table semantics*)
146 goalw PropLog.thy [logcon_def] "!!H. H |- p ==> H |= p";
147 by (etac thms.induct 1);
148 by (fast_tac (ZF_cs addSDs [is_true_Imp RS iffD1 RS mp]) 5);
149 by (ALLGOALS (asm_simp_tac prop_ss));
150 val soundness = result();
152 (*** Towards the completeness proof ***)
154 val [premf,premq] = goal PropLog.thy
155     "[| H |- p=>Fls; q: prop |] ==> H |- p=>q";
156 by (rtac (premf RS thms_in_pl RS ImpE) 1);
157 by (rtac deduction 1);
158 by (rtac (premf RS weaken_left_cons RS thms_notE) 1);
159 by (REPEAT (ares_tac [premq, consI1, thms.H] 1));
160 val Fls_Imp = result();
162 val [premp,premq] = goal PropLog.thy
163     "[| H |- p;  H |- q=>Fls |] ==> H |- (p=>q)=>Fls";
164 by (cut_facts_tac ([premp,premq] RL [thms_in_pl]) 1);
165 by (etac ImpE 1);
166 by (rtac deduction 1);
167 by (rtac (premq RS weaken_left_cons RS thms_MP) 1);
168 by (rtac (consI1 RS thms.H RS thms_MP) 1);
169 by (rtac (premp RS weaken_left_cons) 2);
170 by (REPEAT (ares_tac prop.intrs 1));
171 val Imp_Fls = result();
173 (*Typical example of strengthening the induction formula*)
174 val [major] = goal PropLog.thy
175     "p: prop ==> hyps(p,t) |- if(is_true(p,t), p, p=>Fls)";
176 by (rtac (expand_if RS iffD2) 1);
177 by (rtac (major RS prop.induct) 1);
178 by (ALLGOALS (asm_simp_tac (prop_ss addsimps [thms_I, thms.H])));
179 by (safe_tac (ZF_cs addSEs [Fls_Imp RS weaken_left_Un1,
180 			    Fls_Imp RS weaken_left_Un2]));
181 by (ALLGOALS (fast_tac (ZF_cs addIs [weaken_left_Un1, weaken_left_Un2,
182 				     weaken_right, Imp_Fls])));
183 val hyps_thms_if = result();
185 (*Key lemma for completeness; yields a set of assumptions satisfying p*)
186 val [premp,sat] = goalw PropLog.thy [logcon_def]
187     "[| p: prop;  0 |= p |] ==> hyps(p,t) |- p";
188 by (rtac (sat RS spec RS mp RS if_P RS subst) 1 THEN
189     rtac (premp RS hyps_thms_if) 2);
190 by (fast_tac ZF_cs 1);
191 val logcon_thms_p = result();
193 (*For proving certain theorems in our new propositional logic*)
194 val thms_cs =
195     ZF_cs addSIs (prop.intrs @ [deduction])
196           addIs [thms_in_pl, thms.H, thms.H RS thms_MP];
198 (*The excluded middle in the form of an elimination rule*)
199 val prems = goal PropLog.thy
200     "[| p: prop;  q: prop |] ==> H |- (p=>q) => ((p=>Fls)=>q) => q";
201 by (rtac (deduction RS deduction) 1);
202 by (rtac (thms.DN RS thms_MP) 1);
203 by (ALLGOALS (best_tac (thms_cs addSIs prems)));
204 val thms_excluded_middle = result();
206 (*Hard to prove directly because it requires cuts*)
207 val prems = goal PropLog.thy
208     "[| cons(p,H) |- q;  cons(p=>Fls,H) |- q;  p: prop |] ==> H |- q";
209 by (rtac (thms_excluded_middle RS thms_MP RS thms_MP) 1);
210 by (REPEAT (resolve_tac (prems@prop.intrs@[deduction,thms_in_pl]) 1));
211 val thms_excluded_middle_rule = result();
213 (*** Completeness -- lemmas for reducing the set of assumptions ***)
215 (*For the case hyps(p,t)-cons(#v,Y) |- p;
216   we also have hyps(p,t)-{#v} <= hyps(p, t-{v}) *)
217 val [major] = goal PropLog.thy
218     "p: prop ==> hyps(p, t-{v}) <= cons(#v=>Fls, hyps(p,t)-{#v})";
219 by (rtac (major RS prop.induct) 1);
220 by (simp_tac prop_ss 1);
221 by (asm_simp_tac (prop_ss setloop (split_tac [expand_if])) 1);
222 by (fast_tac (ZF_cs addSEs prop.free_SEs) 1);
223 by (asm_simp_tac prop_ss 1);
224 by (fast_tac ZF_cs 1);
225 val hyps_Diff = result();
227 (*For the case hyps(p,t)-cons(#v => Fls,Y) |- p;
228   we also have hyps(p,t)-{#v=>Fls} <= hyps(p, cons(v,t)) *)
229 val [major] = goal PropLog.thy
230     "p: prop ==> hyps(p, cons(v,t)) <= cons(#v, hyps(p,t)-{#v=>Fls})";
231 by (rtac (major RS prop.induct) 1);
232 by (simp_tac prop_ss 1);
233 by (asm_simp_tac (prop_ss setloop (split_tac [expand_if])) 1);
234 by (fast_tac (ZF_cs addSEs prop.free_SEs) 1);
235 by (asm_simp_tac prop_ss 1);
236 by (fast_tac ZF_cs 1);
237 val hyps_cons = result();
239 (** Two lemmas for use with weaken_left **)
241 goal ZF.thy "B-C <= cons(a, B-cons(a,C))";
242 by (fast_tac ZF_cs 1);
243 val cons_Diff_same = result();
245 goal ZF.thy "cons(a, B-{c}) - D <= cons(a, B-cons(c,D))";
246 by (fast_tac ZF_cs 1);
247 val cons_Diff_subset2 = result();
249 (*The set hyps(p,t) is finite, and elements have the form #v or #v=>Fls;
250  could probably prove the stronger hyps(p,t) : Fin(hyps(p,0) Un hyps(p,nat))*)
251 val [major] = goal PropLog.thy
252     "p: prop ==> hyps(p,t) : Fin(UN v:nat. {#v, #v=>Fls})";
253 by (rtac (major RS prop.induct) 1);
254 by (asm_simp_tac (prop_ss addsimps (Fin.intrs @ [UN_I, cons_iff])
255 		  setloop (split_tac [expand_if])) 2);
256 by (ALLGOALS (asm_simp_tac (prop_ss addsimps [Un_0, Fin.emptyI, Fin_UnI])));
257 val hyps_finite = result();
259 val Diff_weaken_left = subset_refl RSN (2, Diff_mono) RS weaken_left;
261 (*Induction on the finite set of assumptions hyps(p,t0).
262   We may repeatedly subtract assumptions until none are left!*)
263 val [premp,sat] = goal PropLog.thy
264     "[| p: prop;  0 |= p |] ==> ALL t. hyps(p,t) - hyps(p,t0) |- p";
265 by (rtac (premp RS hyps_finite RS Fin_induct) 1);
266 by (simp_tac (prop_ss addsimps [premp, sat, logcon_thms_p, Diff_0]) 1);
267 by (safe_tac ZF_cs);
268 (*Case hyps(p,t)-cons(#v,Y) |- p *)
269 by (rtac thms_excluded_middle_rule 1);
270 by (etac prop.Var_I 3);
271 by (rtac (cons_Diff_same RS weaken_left) 1);
272 by (etac spec 1);
273 by (rtac (cons_Diff_subset2 RS weaken_left) 1);
274 by (rtac (premp RS hyps_Diff RS Diff_weaken_left) 1);
275 by (etac spec 1);
276 (*Case hyps(p,t)-cons(#v => Fls,Y) |- p *)
277 by (rtac thms_excluded_middle_rule 1);
278 by (etac prop.Var_I 3);
279 by (rtac (cons_Diff_same RS weaken_left) 2);
280 by (etac spec 2);
281 by (rtac (cons_Diff_subset2 RS weaken_left) 1);
282 by (rtac (premp RS hyps_cons RS Diff_weaken_left) 1);
283 by (etac spec 1);
284 val completeness_0_lemma = result();
286 (*The base case for completeness*)
287 val [premp,sat] = goal PropLog.thy "[| p: prop;  0 |= p |] ==> 0 |- p";
288 by (rtac (Diff_cancel RS subst) 1);
289 by (rtac (sat RS (premp RS completeness_0_lemma RS spec)) 1);
290 val completeness_0 = result();
292 (*A semantic analogue of the Deduction Theorem*)
293 goalw PropLog.thy [logcon_def] "!!H p q. [| cons(p,H) |= q |] ==> H |= p=>q";
294 by (simp_tac prop_ss 1);
295 by (fast_tac ZF_cs 1);
296 val logcon_Imp = result();
298 goal PropLog.thy "!!H. H: Fin(prop) ==> ALL p:prop. H |= p --> H |- p";
299 by (etac Fin_induct 1);
300 by (safe_tac (ZF_cs addSIs [completeness_0]));
301 by (rtac (weaken_left_cons RS thms_MP) 1);
302 by (fast_tac (ZF_cs addSIs (logcon_Imp::prop.intrs)) 1);
303 by (fast_tac thms_cs 1);
304 val completeness_lemma = result();
306 val completeness = completeness_lemma RS bspec RS mp;
308 val [finite] = goal PropLog.thy "H: Fin(prop) ==> H |- p <-> H |= p & p:prop";
309 by (fast_tac (ZF_cs addSEs [soundness, finite RS completeness,
310 			    thms_in_pl]) 1);
311 val thms_iff = result();
313 writeln"Reached end of file.";