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