12560
|
1 |
(* Title: ZF/Induct/PropLog.thy
|
12088
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow & Lawrence C Paulson
|
|
4 |
Copyright 1993 University of Cambridge
|
|
5 |
|
|
6 |
Datatype definition of propositional logic formulae and inductive definition
|
|
7 |
of the propositional tautologies.
|
12560
|
8 |
|
|
9 |
Inductive definition of propositional logic.
|
|
10 |
Soundness and completeness w.r.t. truth-tables.
|
|
11 |
|
|
12 |
Prove: If H|=p then G|=p where G \<in> Fin(H)
|
12088
|
13 |
*)
|
|
14 |
|
12560
|
15 |
theory PropLog = Main:
|
12088
|
16 |
|
|
17 |
(** The datatype of propositions; note mixfix syntax **)
|
|
18 |
consts
|
12560
|
19 |
propn :: "i"
|
12088
|
20 |
|
|
21 |
datatype
|
12560
|
22 |
"propn" = Fls
|
|
23 |
| Var ("n \<in> nat") ("#_" [100] 100)
|
|
24 |
| "=>" ("p \<in> propn", "q \<in> propn") (infixr 90)
|
12088
|
25 |
|
|
26 |
(** The proof system **)
|
|
27 |
consts
|
12560
|
28 |
thms :: "i => i"
|
12088
|
29 |
|
|
30 |
syntax
|
12560
|
31 |
"|-" :: "[i,i] => o" (infixl 50)
|
12088
|
32 |
|
|
33 |
translations
|
12560
|
34 |
"H |- p" == "p \<in> thms(H)"
|
12088
|
35 |
|
|
36 |
inductive
|
12560
|
37 |
domains "thms(H)" <= "propn"
|
|
38 |
intros
|
|
39 |
H: "[| p \<in> H; p \<in> propn |] ==> H |- p"
|
|
40 |
K: "[| p \<in> propn; q \<in> propn |] ==> H |- p=>q=>p"
|
|
41 |
S: "[| p \<in> propn; q \<in> propn; r \<in> propn |]
|
|
42 |
==> H |- (p=>q=>r) => (p=>q) => p=>r"
|
|
43 |
DN: "p \<in> propn ==> H |- ((p=>Fls) => Fls) => p"
|
|
44 |
MP: "[| H |- p=>q; H |- p; p \<in> propn; q \<in> propn |] ==> H |- q"
|
|
45 |
type_intros "propn.intros"
|
12088
|
46 |
|
|
47 |
|
|
48 |
(** The semantics **)
|
|
49 |
consts
|
12560
|
50 |
"|=" :: "[i,i] => o" (infixl 50)
|
|
51 |
hyps :: "[i,i] => i"
|
|
52 |
is_true_fun :: "[i,i] => i"
|
12088
|
53 |
|
|
54 |
constdefs (*this definitionis necessary since predicates can't be recursive*)
|
12560
|
55 |
is_true :: "[i,i] => o"
|
12088
|
56 |
"is_true(p,t) == is_true_fun(p,t)=1"
|
|
57 |
|
|
58 |
defs
|
|
59 |
(*Logical consequence: for every valuation, if all elements of H are true
|
|
60 |
then so is p*)
|
12560
|
61 |
logcon_def: "H |= p == \<forall>t. (\<forall>q \<in> H. is_true(q,t)) --> is_true(p,t)"
|
12088
|
62 |
|
|
63 |
primrec (** A finite set of hypotheses from t and the Vars in p **)
|
|
64 |
"hyps(Fls, t) = 0"
|
12560
|
65 |
"hyps(Var(v), t) = (if v \<in> t then {#v} else {#v=>Fls})"
|
12088
|
66 |
"hyps(p=>q, t) = hyps(p,t) Un hyps(q,t)"
|
|
67 |
|
|
68 |
primrec (** Semantics of propositional logic **)
|
|
69 |
"is_true_fun(Fls, t) = 0"
|
12560
|
70 |
"is_true_fun(Var(v), t) = (if v \<in> t then 1 else 0)"
|
12088
|
71 |
"is_true_fun(p=>q, t) = (if is_true_fun(p,t)=1 then is_true_fun(q,t)
|
|
72 |
else 1)"
|
|
73 |
|
12560
|
74 |
declare propn.intros [simp]
|
|
75 |
|
|
76 |
(*** Semantics of propositional logic ***)
|
|
77 |
|
|
78 |
(** The function is_true **)
|
|
79 |
|
|
80 |
lemma is_true_Fls [simp]: "is_true(Fls,t) <-> False"
|
|
81 |
by (simp add: is_true_def)
|
|
82 |
|
|
83 |
lemma is_true_Var [simp]: "is_true(#v,t) <-> v \<in> t"
|
|
84 |
by (simp add: is_true_def)
|
|
85 |
|
|
86 |
lemma is_true_Imp [simp]: "is_true(p=>q,t) <-> (is_true(p,t)-->is_true(q,t))"
|
|
87 |
by (simp add: is_true_def)
|
|
88 |
|
|
89 |
|
|
90 |
(*** Proof theory of propositional logic ***)
|
|
91 |
|
|
92 |
lemma thms_mono: "G \<subseteq> H ==> thms(G) \<subseteq> thms(H)"
|
|
93 |
apply (unfold thms.defs )
|
|
94 |
apply (rule lfp_mono)
|
|
95 |
apply (rule thms.bnd_mono)+
|
|
96 |
apply (assumption | rule univ_mono basic_monos)+
|
|
97 |
done
|
|
98 |
|
|
99 |
lemmas thms_in_pl = thms.dom_subset [THEN subsetD]
|
|
100 |
|
|
101 |
inductive_cases ImpE: "p=>q \<in> propn"
|
|
102 |
|
|
103 |
(*Stronger Modus Ponens rule: no typechecking!*)
|
|
104 |
lemma thms_MP: "[| H |- p=>q; H |- p |] ==> H |- q"
|
|
105 |
apply (rule thms.MP)
|
|
106 |
apply (erule asm_rl thms_in_pl thms_in_pl [THEN ImpE])+
|
|
107 |
done
|
|
108 |
|
|
109 |
(*Rule is called I for Identity Combinator, not for Introduction*)
|
|
110 |
lemma thms_I: "p \<in> propn ==> H |- p=>p"
|
|
111 |
apply (rule thms.S [THEN thms_MP, THEN thms_MP])
|
|
112 |
apply (rule_tac [5] thms.K)
|
|
113 |
apply (rule_tac [4] thms.K)
|
|
114 |
apply (simp_all add: propn.intros )
|
|
115 |
done
|
|
116 |
|
|
117 |
(** Weakening, left and right **)
|
|
118 |
|
|
119 |
(* [| G \<subseteq> H; G|-p |] ==> H|-p Order of premises is convenient with RS*)
|
|
120 |
lemmas weaken_left = thms_mono [THEN subsetD, standard]
|
|
121 |
|
|
122 |
(* H |- p ==> cons(a,H) |- p *)
|
|
123 |
lemmas weaken_left_cons = subset_consI [THEN weaken_left]
|
|
124 |
|
|
125 |
lemmas weaken_left_Un1 = Un_upper1 [THEN weaken_left]
|
|
126 |
lemmas weaken_left_Un2 = Un_upper2 [THEN weaken_left]
|
|
127 |
|
|
128 |
lemma weaken_right: "[| H |- q; p \<in> propn |] ==> H |- p=>q"
|
|
129 |
by (simp_all add: thms.K [THEN thms_MP] thms_in_pl)
|
|
130 |
|
|
131 |
|
|
132 |
(*The deduction theorem*)
|
|
133 |
lemma deduction: "[| cons(p,H) |- q; p \<in> propn |] ==> H |- p=>q"
|
|
134 |
apply (erule thms.induct)
|
|
135 |
apply (blast intro: thms_I thms.H [THEN weaken_right])
|
|
136 |
apply (blast intro: thms.K [THEN weaken_right])
|
|
137 |
apply (blast intro: thms.S [THEN weaken_right])
|
|
138 |
apply (blast intro: thms.DN [THEN weaken_right])
|
|
139 |
apply (blast intro: thms.S [THEN thms_MP [THEN thms_MP]])
|
|
140 |
done
|
|
141 |
|
|
142 |
|
|
143 |
(*The cut rule*)
|
|
144 |
lemma cut: "[| H|-p; cons(p,H) |- q |] ==> H |- q"
|
|
145 |
apply (rule deduction [THEN thms_MP])
|
|
146 |
apply (simp_all add: thms_in_pl)
|
|
147 |
done
|
|
148 |
|
|
149 |
lemma thms_FlsE: "[| H |- Fls; p \<in> propn |] ==> H |- p"
|
|
150 |
apply (rule thms.DN [THEN thms_MP])
|
|
151 |
apply (rule_tac [2] weaken_right)
|
|
152 |
apply (simp_all add: propn.intros)
|
|
153 |
done
|
|
154 |
|
|
155 |
(* [| H |- p=>Fls; H |- p; q \<in> propn |] ==> H |- q *)
|
|
156 |
lemmas thms_notE = thms_MP [THEN thms_FlsE, standard]
|
|
157 |
|
|
158 |
(*Soundness of the rules wrt truth-table semantics*)
|
|
159 |
lemma soundness: "H |- p ==> H |= p"
|
|
160 |
apply (unfold logcon_def)
|
|
161 |
apply (erule thms.induct)
|
|
162 |
apply auto
|
|
163 |
done
|
|
164 |
|
|
165 |
(*** Towards the completeness proof ***)
|
|
166 |
|
|
167 |
lemma Fls_Imp: "[| H |- p=>Fls; q \<in> propn |] ==> H |- p=>q"
|
|
168 |
apply (frule thms_in_pl)
|
|
169 |
apply (rule deduction)
|
|
170 |
apply (rule weaken_left_cons [THEN thms_notE])
|
|
171 |
apply (blast intro: thms.H elim: ImpE)+
|
|
172 |
done
|
|
173 |
|
|
174 |
lemma Imp_Fls: "[| H |- p; H |- q=>Fls |] ==> H |- (p=>q)=>Fls"
|
|
175 |
apply (frule thms_in_pl)
|
|
176 |
apply (frule thms_in_pl [of concl: "q=>Fls"])
|
|
177 |
apply (rule deduction)
|
|
178 |
apply (erule weaken_left_cons [THEN thms_MP])
|
|
179 |
apply (rule consI1 [THEN thms.H, THEN thms_MP])
|
|
180 |
apply (blast intro: weaken_left_cons elim: ImpE)+
|
|
181 |
done
|
|
182 |
|
|
183 |
(*Typical example of strengthening the induction formula*)
|
|
184 |
lemma hyps_thms_if:
|
|
185 |
"p \<in> propn ==> hyps(p,t) |- (if is_true(p,t) then p else p=>Fls)"
|
|
186 |
apply (simp (no_asm))
|
|
187 |
apply (induct_tac "p")
|
|
188 |
apply (simp_all (no_asm_simp) add: thms_I thms.H)
|
|
189 |
apply (safe elim!: Fls_Imp [THEN weaken_left_Un1]
|
|
190 |
Fls_Imp [THEN weaken_left_Un2])
|
|
191 |
apply (blast intro: weaken_left_Un1 weaken_left_Un2 weaken_right Imp_Fls)+
|
|
192 |
done
|
|
193 |
|
|
194 |
(*Key lemma for completeness; yields a set of assumptions satisfying p*)
|
|
195 |
lemma logcon_thms_p: "[| p \<in> propn; 0 |= p |] ==> hyps(p,t) |- p"
|
|
196 |
apply (unfold logcon_def)
|
|
197 |
apply (drule hyps_thms_if)
|
|
198 |
apply simp
|
|
199 |
done
|
|
200 |
|
|
201 |
|
|
202 |
(*For proving certain theorems in our new propositional logic*)
|
|
203 |
lemmas propn_SIs = propn.intros deduction
|
|
204 |
lemmas propn_Is = thms_in_pl thms.H thms.H [THEN thms_MP]
|
|
205 |
|
|
206 |
|
|
207 |
(*The excluded middle in the form of an elimination rule*)
|
|
208 |
lemma thms_excluded_middle:
|
|
209 |
"[| p \<in> propn; q \<in> propn |] ==> H |- (p=>q) => ((p=>Fls)=>q) => q"
|
|
210 |
apply (rule deduction [THEN deduction])
|
|
211 |
apply (rule thms.DN [THEN thms_MP])
|
|
212 |
apply (best intro!: propn_SIs intro: propn_Is)+
|
|
213 |
done
|
|
214 |
|
|
215 |
(*Hard to prove directly because it requires cuts*)
|
|
216 |
lemma thms_excluded_middle_rule:
|
|
217 |
"[| cons(p,H) |- q; cons(p=>Fls,H) |- q; p \<in> propn |] ==> H |- q"
|
|
218 |
apply (rule thms_excluded_middle [THEN thms_MP, THEN thms_MP])
|
|
219 |
apply (blast intro!: propn_SIs intro: propn_Is)+
|
|
220 |
done
|
|
221 |
|
|
222 |
|
|
223 |
(*** Completeness -- lemmas for reducing the set of assumptions ***)
|
|
224 |
|
|
225 |
(*For the case hyps(p,t)-cons(#v,Y) |- p
|
|
226 |
we also have hyps(p,t)-{#v} \<subseteq> hyps(p, t-{v}) *)
|
|
227 |
lemma hyps_Diff:
|
|
228 |
"p \<in> propn ==> hyps(p, t-{v}) \<subseteq> cons(#v=>Fls, hyps(p,t)-{#v})"
|
|
229 |
by (induct_tac "p", auto)
|
|
230 |
|
|
231 |
(*For the case hyps(p,t)-cons(#v => Fls,Y) |- p
|
|
232 |
we also have hyps(p,t)-{#v=>Fls} \<subseteq> hyps(p, cons(v,t)) *)
|
|
233 |
lemma hyps_cons:
|
|
234 |
"p \<in> propn ==> hyps(p, cons(v,t)) \<subseteq> cons(#v, hyps(p,t)-{#v=>Fls})"
|
|
235 |
by (induct_tac "p", auto)
|
|
236 |
|
|
237 |
(** Two lemmas for use with weaken_left **)
|
|
238 |
|
|
239 |
lemma cons_Diff_same: "B-C \<subseteq> cons(a, B-cons(a,C))"
|
|
240 |
by blast
|
|
241 |
|
|
242 |
lemma cons_Diff_subset2: "cons(a, B-{c}) - D \<subseteq> cons(a, B-cons(c,D))"
|
|
243 |
by blast
|
|
244 |
|
|
245 |
(*The set hyps(p,t) is finite, and elements have the form #v or #v=>Fls
|
|
246 |
could probably prove the stronger hyps(p,t) \<in> Fin(hyps(p,0) Un hyps(p,nat))*)
|
|
247 |
lemma hyps_finite: "p \<in> propn ==> hyps(p,t) \<in> Fin(\<Union>v \<in> nat. {#v, #v=>Fls})"
|
|
248 |
by (induct_tac "p", auto)
|
|
249 |
|
|
250 |
lemmas Diff_weaken_left = Diff_mono [OF _ subset_refl, THEN weaken_left]
|
|
251 |
|
|
252 |
(*Induction on the finite set of assumptions hyps(p,t0).
|
|
253 |
We may repeatedly subtract assumptions until none are left!*)
|
|
254 |
lemma completeness_0_lemma [rule_format]:
|
|
255 |
"[| p \<in> propn; 0 |= p |] ==> \<forall>t. hyps(p,t) - hyps(p,t0) |- p"
|
|
256 |
apply (frule hyps_finite)
|
|
257 |
apply (erule Fin_induct)
|
|
258 |
apply (simp add: logcon_thms_p Diff_0)
|
|
259 |
(*inductive step*)
|
|
260 |
apply safe
|
|
261 |
(*Case hyps(p,t)-cons(#v,Y) |- p *)
|
|
262 |
apply (rule thms_excluded_middle_rule)
|
|
263 |
apply (erule_tac [3] propn.intros)
|
|
264 |
apply (blast intro: cons_Diff_same [THEN weaken_left])
|
|
265 |
apply (blast intro: cons_Diff_subset2 [THEN weaken_left]
|
|
266 |
hyps_Diff [THEN Diff_weaken_left])
|
|
267 |
(*Case hyps(p,t)-cons(#v => Fls,Y) |- p *)
|
|
268 |
apply (rule thms_excluded_middle_rule)
|
|
269 |
apply (erule_tac [3] propn.intros)
|
|
270 |
apply (blast intro: cons_Diff_subset2 [THEN weaken_left]
|
|
271 |
hyps_cons [THEN Diff_weaken_left])
|
|
272 |
apply (blast intro: cons_Diff_same [THEN weaken_left])
|
|
273 |
done
|
|
274 |
|
|
275 |
(*The base case for completeness*)
|
|
276 |
lemma completeness_0: "[| p \<in> propn; 0 |= p |] ==> 0 |- p"
|
|
277 |
apply (rule Diff_cancel [THEN subst])
|
|
278 |
apply (blast intro: completeness_0_lemma)
|
|
279 |
done
|
|
280 |
|
|
281 |
(*A semantic analogue of the Deduction Theorem*)
|
|
282 |
lemma logcon_Imp: "[| cons(p,H) |= q |] ==> H |= p=>q"
|
|
283 |
by (simp add: logcon_def)
|
|
284 |
|
|
285 |
lemma completeness [rule_format]:
|
|
286 |
"H \<in> Fin(propn) ==> \<forall>p \<in> propn. H |= p --> H |- p"
|
|
287 |
apply (erule Fin_induct)
|
|
288 |
apply (safe intro!: completeness_0)
|
|
289 |
apply (rule weaken_left_cons [THEN thms_MP])
|
|
290 |
apply (blast intro!: logcon_Imp propn.intros)
|
|
291 |
apply (blast intro: propn_Is)
|
|
292 |
done
|
|
293 |
|
|
294 |
lemma thms_iff: "H \<in> Fin(propn) ==> H |- p <-> H |= p & p \<in> propn"
|
|
295 |
by (blast intro: soundness completeness thms_in_pl)
|
|
296 |
|
12088
|
297 |
end
|