author | convert-repo |
Thu, 23 Jul 2009 14:03:20 +0000 | |
changeset 255 | 435bf30c29a5 |
parent 66 | 14b9286ed036 |
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)"; |
|
104 |
by (rtac (major RS (thms_def RS def_induct)) 1); |
|
105 |
by (rtac thms_bnd_mono 1); |
|
106 |
by (rewrite_tac rule_defs); |
|
107 |
by (fast_tac (set_cs addIs prems) 1); |
|
108 |
val conseq_induct = result(); |
|
109 |
||
110 |
(*The deduction theorem*) |
|
111 |
val [major] = goal PL.thy "insert(p,H) |- q ==> H |- p->q"; |
|
112 |
by (rtac (major RS conseq_induct) 1); |
|
113 |
by (fast_tac (set_cs addIs [conseq_I, conseq_H RS weaken_right]) 1); |
|
114 |
by (fast_tac (set_cs addIs [conseq_K RS weaken_right]) 1); |
|
115 |
by (fast_tac (set_cs addIs [conseq_S RS weaken_right]) 1); |
|
116 |
by (fast_tac (set_cs addIs [conseq_DN RS weaken_right]) 1); |
|
117 |
by (fast_tac (set_cs addIs [conseq_S RS conseq_MP RS conseq_MP]) 1); |
|
118 |
val deduction = result(); |
|
119 |
||
120 |
||
121 |
(*The cut rule*) |
|
122 |
val prems = goal PL.thy "[| H|-p; insert(p,H) |- q |] ==> H |- q"; |
|
123 |
by (rtac (deduction RS conseq_MP) 1); |
|
124 |
by (REPEAT (resolve_tac prems 1)); |
|
125 |
val cut = result(); |
|
126 |
||
127 |
val prems = goal PL.thy "H |- false ==> H |- p"; |
|
128 |
by (rtac (conseq_DN RS conseq_MP) 1); |
|
129 |
by (rtac weaken_right 1); |
|
130 |
by (resolve_tac prems 1); |
|
131 |
val conseq_falseE = result(); |
|
132 |
||
133 |
(* [| H |- p->false; H |- p; q: pl |] ==> H |- q *) |
|
134 |
val conseq_notE = standard (conseq_MP RS conseq_falseE); |
|
135 |
||
136 |
(** The function eval **) |
|
137 |
||
61 | 138 |
val pl_ss = set_ss addsimps [pl_rec_var,pl_rec_false,pl_rec_imp] @ PL0.simps; |
0 | 139 |
|
140 |
goalw PL.thy [eval_def] "tt[false] = False"; |
|
141 |
by (simp_tac pl_ss 1); |
|
142 |
val eval_false = result(); |
|
143 |
||
144 |
goalw PL.thy [eval_def] "tt[#v] = (v:tt)"; |
|
145 |
by (simp_tac pl_ss 1); |
|
146 |
val eval_var = result(); |
|
147 |
||
148 |
goalw PL.thy [eval_def] "tt[p->q] = (tt[p]-->tt[q])"; |
|
149 |
by (simp_tac pl_ss 1); |
|
150 |
val eval_imp = result(); |
|
151 |
||
152 |
val pl_ss = pl_ss addsimps [eval_false, eval_var, eval_imp]; |
|
153 |
||
154 |
(** The function hyps **) |
|
155 |
||
156 |
goalw PL.thy [hyps_def] "hyps(false,tt) = {}"; |
|
157 |
by (simp_tac pl_ss 1); |
|
158 |
val hyps_false = result(); |
|
159 |
||
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
0
diff
changeset
|
160 |
goalw PL.thy [hyps_def] "hyps(#v,tt) = {if(v:tt, #v, (#v)->false)}"; |
0 | 161 |
by (simp_tac pl_ss 1); |
162 |
val hyps_var = result(); |
|
163 |
||
164 |
goalw PL.thy [hyps_def] "hyps(p->q,tt) = hyps(p,tt) Un hyps(q,tt)"; |
|
165 |
by (simp_tac pl_ss 1); |
|
166 |
val hyps_imp = result(); |
|
167 |
||
168 |
val pl_ss = pl_ss addsimps [hyps_false, hyps_var, hyps_imp]; |
|
169 |
||
170 |
val ball_eq = prove_goalw Set.thy [Ball_def] "(!x:A.P(x)) = (!x.x:A --> P(x))" |
|
171 |
(fn _ => [rtac refl 1]); |
|
172 |
||
173 |
(*Soundness of the rules wrt truth-table semantics*) |
|
174 |
val [major] = goalw PL.thy [sat_def] "H |- p ==> H |= p"; |
|
175 |
by (rtac (major RS conseq_induct) 1); |
|
176 |
by (fast_tac (set_cs addSDs [eval_imp RS iffD1 RS mp]) 5); |
|
66 | 177 |
by (ALLGOALS (asm_simp_tac(pl_ss addsimps [ball_eq]))); |
178 |
by(fast_tac HOL_cs 1); |
|
0 | 179 |
val soundness = result(); |
180 |
||
181 |
(** Structural induction on pl |
|
182 |
||
183 |
val major::prems = goalw PL.thy pl_defs |
|
184 |
"[| q: pl; \ |
|
185 |
\ P(false); \ |
|
186 |
\ !!v. v:nat ==> P(#v); \ |
|
187 |
\ !!q1 q2. [| q1: pl; q2: pl; P(q1); P(q2) |] ==> P(q1->q2) \ |
|
188 |
\ |] ==> P(q)"; |
|
189 |
by (rtac (major RS sexp_induct) 1); |
|
190 |
by (etac nat_induct 1); |
|
191 |
by (REPEAT (ares_tac prems 1)); |
|
192 |
val pl_induct = result(); |
|
193 |
**) |
|
194 |
(*** Towards the completeness proof ***) |
|
195 |
||
196 |
val [premf] = goal PL.thy "H |- p->false ==> H |- p->q"; |
|
197 |
by (rtac deduction 1); |
|
198 |
by (rtac (premf RS weaken_left_insert RS conseq_notE) 1); |
|
199 |
by (rtac conseq_H 1); |
|
200 |
by (rtac insertI1 1); |
|
201 |
val false_imp = result(); |
|
202 |
||
203 |
val [premp,premq] = goal PL.thy |
|
204 |
"[| H |- p; H |- q->false |] ==> H |- (p->q)->false"; |
|
205 |
by (rtac deduction 1); |
|
206 |
by (rtac (premq RS weaken_left_insert RS conseq_MP) 1); |
|
207 |
by (rtac (conseq_H RS conseq_MP) 1); |
|
208 |
by (rtac insertI1 1); |
|
209 |
by (rtac (premp RS weaken_left_insert) 1); |
|
210 |
val imp_false = result(); |
|
211 |
||
212 |
(*This formulation is required for strong induction hypotheses*) |
|
213 |
goal PL.thy "hyps(p,tt) |- if(tt[p], p, p->false)"; |
|
214 |
by (rtac (expand_if RS iffD2) 1); |
|
56
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
215 |
by(PL0.induct_tac "p" 1); |
0 | 216 |
by (ALLGOALS (simp_tac (pl_ss addsimps [conseq_I, conseq_H]))); |
217 |
by (fast_tac (set_cs addIs [weaken_left_Un1, weaken_left_Un2, |
|
218 |
weaken_right, imp_false] |
|
219 |
addSEs [false_imp]) 1); |
|
220 |
val hyps_conseq_if = result(); |
|
221 |
||
222 |
(*Key lemma for completeness; yields a set of assumptions satisfying p*) |
|
223 |
val [sat] = goalw PL.thy [sat_def] "{} |= p ==> hyps(p,tt) |- p"; |
|
224 |
by (rtac (sat RS spec RS mp RS if_P RS subst) 1 THEN |
|
225 |
rtac hyps_conseq_if 2); |
|
226 |
by (fast_tac set_cs 1); |
|
227 |
val sat_conseq_p = result(); |
|
228 |
||
229 |
(*For proving certain theorems in our new propositional logic*) |
|
230 |
val conseq_cs = |
|
231 |
set_cs addSIs [deduction] addIs [conseq_H, conseq_H RS conseq_MP]; |
|
232 |
||
233 |
(*The excluded middle in the form of an elimination rule*) |
|
234 |
goal PL.thy "H |- (p->q) -> ((p->false)->q) -> q"; |
|
235 |
by (rtac (deduction RS deduction) 1); |
|
236 |
by (rtac (conseq_DN RS conseq_MP) 1); |
|
237 |
by (ALLGOALS (best_tac (conseq_cs addSIs prems))); |
|
238 |
val conseq_excluded_middle = result(); |
|
239 |
||
240 |
(*Hard to prove directly because it requires cuts*) |
|
241 |
val prems = goal PL.thy |
|
242 |
"[| insert(p,H) |- q; insert(p->false,H) |- q |] ==> H |- q"; |
|
243 |
by (rtac (conseq_excluded_middle RS conseq_MP RS conseq_MP) 1); |
|
244 |
by (REPEAT (resolve_tac (prems@[deduction]) 1)); |
|
245 |
val conseq_excluded_middle_rule = result(); |
|
246 |
||
247 |
(*** Completeness -- lemmas for reducing the set of assumptions ***) |
|
248 |
||
249 |
(*For the case hyps(p,t)-insert(#v,Y) |- p; |
|
250 |
we also have hyps(p,t)-{#v} <= hyps(p, t-{v}) *) |
|
56
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
251 |
goal PL.thy "hyps(p, t-{v}) <= insert((#v)->false, hyps(p,t)-{#v})"; |
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
252 |
by (PL0.induct_tac "p" 1); |
0 | 253 |
by (simp_tac pl_ss 1); |
254 |
by (simp_tac (pl_ss setloop (split_tac [expand_if])) 1); |
|
255 |
by (simp_tac pl_ss 1); |
|
256 |
by (fast_tac set_cs 1); |
|
56
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
257 |
val hyps_Diff = result(); |
0 | 258 |
|
259 |
(*For the case hyps(p,t)-insert(#v -> false,Y) |- p; |
|
48
21291189b51e
changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents:
0
diff
changeset
|
260 |
we also have hyps(p,t)-{(#v)->false} <= hyps(p, insert(v,t)) *) |
56
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
261 |
goal PL.thy "hyps(p, insert(v,t)) <= insert(#v, hyps(p,t)-{(#v)->false})"; |
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
262 |
by (PL0.induct_tac "p" 1); |
0 | 263 |
by (simp_tac pl_ss 1); |
66 | 264 |
by (simp_tac (pl_ss setloop (split_tac [expand_if])) 1); |
0 | 265 |
by (simp_tac pl_ss 1); |
266 |
by (fast_tac set_cs 1); |
|
56
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
267 |
val hyps_insert = result(); |
0 | 268 |
|
269 |
(** Two lemmas for use with weaken_left **) |
|
270 |
||
271 |
goal Set.thy "B-C <= insert(a, B-insert(a,C))"; |
|
272 |
by (fast_tac set_cs 1); |
|
273 |
val insert_Diff_same = result(); |
|
274 |
||
275 |
goal Set.thy "insert(a, B-{c}) - D <= insert(a, B-insert(c,D))"; |
|
276 |
by (fast_tac set_cs 1); |
|
277 |
val insert_Diff_subset2 = result(); |
|
278 |
||
279 |
(*The set hyps(p,t) is finite, and elements have the form #v or #v->false; |
|
280 |
could probably prove the stronger hyps(p,t) : Fin(hyps(p,{}) Un hyps(p,nat))*) |
|
56
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
281 |
goal PL.thy "hyps(p,t) : Fin(UN v:{x.True}. {#v, (#v)->false})"; |
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
282 |
by (PL0.induct_tac "p" 1); |
0 | 283 |
by (ALLGOALS (simp_tac (pl_ss setloop (split_tac [expand_if])) THEN' |
284 |
fast_tac (set_cs addSIs [Fin_0I, Fin_insertI, Fin_UnI]))); |
|
56
385d51d74f71
Used Datatype functor to define propositional logic terms.
nipkow
parents:
48
diff
changeset
|
285 |
val hyps_finite = result(); |
0 | 286 |
|
287 |
val Diff_weaken_left = subset_refl RSN (2, Diff_mono) RS weaken_left; |
|
288 |
||
289 |
(*Induction on the finite set of assumptions hyps(p,t0). |
|
290 |
We may repeatedly subtract assumptions until none are left!*) |
|
291 |
val [sat] = goal PL.thy |
|
292 |
"{} |= p ==> !t. hyps(p,t) - hyps(p,t0) |- p"; |
|
293 |
by (rtac (hyps_finite RS Fin_induct) 1); |
|
294 |
by (simp_tac (pl_ss addsimps [sat RS sat_conseq_p]) 1); |
|
295 |
by (safe_tac set_cs); |
|
296 |
(*Case hyps(p,t)-insert(#v,Y) |- p *) |
|
297 |
by (rtac conseq_excluded_middle_rule 1); |
|
298 |
by (rtac (insert_Diff_same RS weaken_left) 1); |
|
299 |
by (etac spec 1); |
|
300 |
by (rtac (insert_Diff_subset2 RS weaken_left) 1); |
|
301 |
by (rtac (hyps_Diff RS Diff_weaken_left) 1); |
|
302 |
by (etac spec 1); |
|
303 |
(*Case hyps(p,t)-insert(#v -> false,Y) |- p *) |
|
304 |
by (rtac conseq_excluded_middle_rule 1); |
|
305 |
by (rtac (insert_Diff_same RS weaken_left) 2); |
|
306 |
by (etac spec 2); |
|
307 |
by (rtac (insert_Diff_subset2 RS weaken_left) 1); |
|
308 |
by (rtac (hyps_insert RS Diff_weaken_left) 1); |
|
309 |
by (etac spec 1); |
|
310 |
val completeness_0_lemma = result(); |
|
311 |
||
312 |
(*The base case for completeness*) |
|
313 |
val [sat] = goal PL.thy "{} |= p ==> {} |- p"; |
|
314 |
by (rtac (Diff_cancel RS subst) 1); |
|
315 |
by (rtac (sat RS (completeness_0_lemma RS spec)) 1); |
|
316 |
val completeness_0 = result(); |
|
317 |
||
318 |
(*A semantic analogue of the Deduction Theorem*) |
|
319 |
val [sat] = goalw PL.thy [sat_def] "insert(p,H) |= q ==> H |= p->q"; |
|
320 |
by (simp_tac pl_ss 1); |
|
321 |
by (cfast_tac [sat] 1); |
|
322 |
val sat_imp = result(); |
|
323 |
||
324 |
val [finite] = goal PL.thy "H: Fin({p.True}) ==> !p. H |= p --> H |- p"; |
|
325 |
by (rtac (finite RS Fin_induct) 1); |
|
326 |
by (safe_tac (set_cs addSIs [completeness_0])); |
|
327 |
by (rtac (weaken_left_insert RS conseq_MP) 1); |
|
328 |
by (fast_tac (set_cs addSIs [sat_imp]) 1); |
|
329 |
by (fast_tac conseq_cs 1); |
|
330 |
val completeness_lemma = result(); |
|
331 |
||
332 |
val completeness = completeness_lemma RS spec RS mp; |
|
333 |
||
334 |
val [finite] = goal PL.thy "H: Fin({p.True}) ==> (H |- p) = (H |= p)"; |
|
335 |
by (fast_tac (set_cs addSEs [soundness, finite RS completeness]) 1); |
|
336 |
val conseq_iff = result(); |
|
337 |
||
338 |
writeln"Reached end of file."; |
|
339 |