1 (* Title: HOL/Induct/PropLog.thy
3 Copyright 1994 TU Muenchen & University of Cambridge
6 section {* Meta-theory of propositional logic *}
8 theory PropLog imports Main begin
11 Datatype definition of propositional logic formulae and inductive
12 definition of the propositional tautologies.
14 Inductive definition of propositional logic. Soundness and
15 completeness w.r.t.\ truth-tables.
17 Prove: If @{text "H |= p"} then @{text "G |= p"} where @{text "G \<in>
21 subsection {* The datatype of propositions *}
25 var 'a ("#_" [1000]) |
26 imp "'a pl" "'a pl" (infixr "->" 90)
29 subsection {* The proof system *}
31 inductive thms :: "['a pl set, 'a pl] => bool" (infixl "|-" 50)
34 H: "p\<in>H ==> H |- p"
36 | S: "H |- (p->q->r) -> (p->q) -> p->r"
37 | DN: "H |- ((p->false) -> false) -> p"
38 | MP: "[| H |- p->q; H |- p |] ==> H |- q"
41 subsection {* The semantics *}
43 subsubsection {* Semantics of propositional logic. *}
45 primrec eval :: "['a set, 'a pl] => bool" ("_[[_]]" [100,0] 100)
48 | "tt[[#v]] = (v \<in> tt)"
49 | eval_imp: "tt[[p->q]] = (tt[[p]] --> tt[[q]])"
52 A finite set of hypotheses from @{text t} and the @{text Var}s in
56 primrec hyps :: "['a pl, 'a set] => 'a pl set"
59 | "hyps (#v) tt = {if v \<in> tt then #v else #v->false}"
60 | "hyps (p->q) tt = hyps p tt Un hyps q tt"
63 subsubsection {* Logical consequence *}
66 For every valuation, if all elements of @{text H} are true then so
70 definition sat :: "['a pl set, 'a pl] => bool" (infixl "|=" 50)
71 where "H |= p = (\<forall>tt. (\<forall>q\<in>H. tt[[q]]) --> tt[[p]])"
74 subsection {* Proof theory of propositional logic *}
76 lemma thms_mono: "G<=H ==> thms(G) <= thms(H)"
77 apply (rule predicate1I)
78 apply (erule thms.induct)
79 apply (auto intro: thms.intros)
82 lemma thms_I: "H |- p->p"
83 -- {*Called @{text I} for Identity Combinator, not for Introduction. *}
84 by (best intro: thms.K thms.S thms.MP)
87 subsubsection {* Weakening, left and right *}
89 lemma weaken_left: "[| G \<subseteq> H; G|-p |] ==> H|-p"
90 -- {* Order of premises is convenient with @{text THEN} *}
91 by (erule thms_mono [THEN predicate1D])
93 lemma weaken_left_insert: "G |- p \<Longrightarrow> insert a G |- p"
94 by (rule weaken_left) (rule subset_insertI)
96 lemma weaken_left_Un1: "G |- p \<Longrightarrow> G \<union> B |- p"
97 by (rule weaken_left) (rule Un_upper1)
99 lemma weaken_left_Un2: "G |- p \<Longrightarrow> A \<union> G |- p"
100 by (rule weaken_left) (rule Un_upper2)
102 lemma weaken_right: "H |- q ==> H |- p->q"
103 by (fast intro: thms.K thms.MP)
106 subsubsection {* The deduction theorem *}
108 theorem deduction: "insert p H |- q ==> H |- p->q"
109 apply (induct set: thms)
110 apply (fast intro: thms_I thms.H thms.K thms.S thms.DN
111 thms.S [THEN thms.MP, THEN thms.MP] weaken_right)+
115 subsubsection {* The cut rule *}
117 lemma cut: "insert p H |- q \<Longrightarrow> H |- p \<Longrightarrow> H |- q"
118 by (rule thms.MP) (rule deduction)
120 lemma thms_falseE: "H |- false \<Longrightarrow> H |- q"
121 by (rule thms.MP, rule thms.DN) (rule weaken_right)
123 lemma thms_notE: "H |- p -> false \<Longrightarrow> H |- p \<Longrightarrow> H |- q"
124 by (rule thms_falseE) (rule thms.MP)
127 subsubsection {* Soundness of the rules wrt truth-table semantics *}
129 theorem soundness: "H |- p ==> H |= p"
130 by (induct set: thms) (auto simp: sat_def)
133 subsection {* Completeness *}
135 subsubsection {* Towards the completeness proof *}
137 lemma false_imp: "H |- p->false ==> H |- p->q"
138 apply (rule deduction)
139 apply (metis H insert_iff weaken_left_insert thms_notE)
143 "[| H |- p; H |- q->false |] ==> H |- (p->q)->false"
144 apply (rule deduction)
145 apply (metis H MP insert_iff weaken_left_insert)
148 lemma hyps_thms_if: "hyps p tt |- (if tt[[p]] then p else p->false)"
149 -- {* Typical example of strengthening the induction statement. *}
152 apply (simp_all add: thms_I thms.H)
153 apply (blast intro: weaken_left_Un1 weaken_left_Un2 weaken_right
157 lemma sat_thms_p: "{} |= p ==> hyps p tt |- p"
158 -- {* Key lemma for completeness; yields a set of assumptions
159 satisfying @{text p} *}
161 by (metis (full_types) empty_iff hyps_thms_if)
164 For proving certain theorems in our new propositional logic.
167 declare deduction [intro!]
168 declare thms.H [THEN thms.MP, intro]
171 The excluded middle in the form of an elimination rule.
174 lemma thms_excluded_middle: "H |- (p->q) -> ((p->false)->q) -> q"
175 apply (rule deduction [THEN deduction])
176 apply (rule thms.DN [THEN thms.MP], best intro: H)
179 lemma thms_excluded_middle_rule:
180 "[| insert p H |- q; insert (p->false) H |- q |] ==> H |- q"
181 -- {* Hard to prove directly because it requires cuts *}
182 by (rule thms_excluded_middle [THEN thms.MP, THEN thms.MP], auto)
185 subsection{* Completeness -- lemmas for reducing the set of assumptions*}
188 For the case @{prop "hyps p t - insert #v Y |- p"} we also have @{prop
189 "hyps p t - {#v} \<subseteq> hyps p (t-{v})"}.
192 lemma hyps_Diff: "hyps p (t-{v}) <= insert (#v->false) ((hyps p t)-{#v})"
196 For the case @{prop "hyps p t - insert (#v -> Fls) Y |- p"} we also have
197 @{prop "hyps p t-{#v->Fls} \<subseteq> hyps p (insert v t)"}.
200 lemma hyps_insert: "hyps p (insert v t) <= insert (#v) (hyps p t-{#v->false})"
203 text {* Two lemmas for use with @{text weaken_left} *}
205 lemma insert_Diff_same: "B-C <= insert a (B-insert a C)"
208 lemma insert_Diff_subset2: "insert a (B-{c}) - D <= insert a (B-insert c D)"
212 The set @{term "hyps p t"} is finite, and elements have the form
213 @{term "#v"} or @{term "#v->Fls"}.
216 lemma hyps_finite: "finite(hyps p t)"
219 lemma hyps_subset: "hyps p t <= (UN v. {#v, #v->false})"
222 lemma Diff_weaken_left: "A \<subseteq> C \<Longrightarrow> A - B |- p \<Longrightarrow> C - B |- p"
223 by (rule Diff_mono [OF _ subset_refl, THEN weaken_left])
226 subsubsection {* Completeness theorem *}
229 Induction on the finite set of assumptions @{term "hyps p t0"}. We
230 may repeatedly subtract assumptions until none are left!
233 lemma completeness_0_lemma:
234 "{} |= p ==> \<forall>t. hyps p t - hyps p t0 |- p"
235 apply (rule hyps_subset [THEN hyps_finite [THEN finite_subset_induct]])
236 apply (simp add: sat_thms_p, safe)
237 txt{*Case @{text"hyps p t-insert(#v,Y) |- p"} *}
238 apply (iprover intro: thms_excluded_middle_rule
239 insert_Diff_same [THEN weaken_left]
240 insert_Diff_subset2 [THEN weaken_left]
241 hyps_Diff [THEN Diff_weaken_left])
242 txt{*Case @{text"hyps p t-insert(#v -> false,Y) |- p"} *}
243 apply (iprover intro: thms_excluded_middle_rule
244 insert_Diff_same [THEN weaken_left]
245 insert_Diff_subset2 [THEN weaken_left]
246 hyps_insert [THEN Diff_weaken_left])
249 text{*The base case for completeness*}
250 lemma completeness_0: "{} |= p ==> {} |- p"
251 by (metis Diff_cancel completeness_0_lemma)
253 text{*A semantic analogue of the Deduction Theorem*}
254 lemma sat_imp: "insert p H |= q ==> H |= p->q"
255 by (auto simp: sat_def)
257 theorem completeness: "finite H ==> H |= p ==> H |- p"
258 apply (induct arbitrary: p rule: finite_induct)
259 apply (blast intro: completeness_0)
260 apply (iprover intro: sat_imp thms.H insertI1 weaken_left_insert [THEN thms.MP])
263 theorem syntax_iff_semantics: "finite H ==> (H |- p) = (H |= p)"
264 by (blast intro: soundness completeness)