23 datatype 'a pl = |
23 datatype 'a pl = |
24 false | |
24 false | |
25 var 'a ("#_" [1000]) | |
25 var 'a ("#_" [1000]) | |
26 imp "'a pl" "'a pl" (infixr "->" 90) |
26 imp "'a pl" "'a pl" (infixr "->" 90) |
27 |
27 |
|
28 |
28 subsection {* The proof system *} |
29 subsection {* The proof system *} |
29 |
30 |
30 inductive |
31 inductive thms :: "['a pl set, 'a pl] => bool" (infixl "|-" 50) |
31 thms :: "['a pl set, 'a pl] => bool" (infixl "|-" 50) |
|
32 for H :: "'a pl set" |
32 for H :: "'a pl set" |
33 where |
33 where |
34 H [intro]: "p\<in>H ==> H |- p" |
34 H: "p\<in>H ==> H |- p" |
35 | K: "H |- p->q->p" |
35 | K: "H |- p->q->p" |
36 | S: "H |- (p->q->r) -> (p->q) -> p->r" |
36 | S: "H |- (p->q->r) -> (p->q) -> p->r" |
37 | DN: "H |- ((p->false) -> false) -> p" |
37 | DN: "H |- ((p->false) -> false) -> p" |
38 | MP: "[| H |- p->q; H |- p |] ==> H |- q" |
38 | MP: "[| H |- p->q; H |- p |] ==> H |- q" |
|
39 |
39 |
40 |
40 subsection {* The semantics *} |
41 subsection {* The semantics *} |
41 |
42 |
42 subsubsection {* Semantics of propositional logic. *} |
43 subsubsection {* Semantics of propositional logic. *} |
43 |
44 |
44 primrec eval :: "['a set, 'a pl] => bool" ("_[[_]]" [100,0] 100) where |
45 primrec eval :: "['a set, 'a pl] => bool" ("_[[_]]" [100,0] 100) |
45 "tt[[false]] = False" |
46 where |
46 | "tt[[#v]] = (v \<in> tt)" |
47 "tt[[false]] = False" |
47 | eval_imp: "tt[[p->q]] = (tt[[p]] --> tt[[q]])" |
48 | "tt[[#v]] = (v \<in> tt)" |
|
49 | eval_imp: "tt[[p->q]] = (tt[[p]] --> tt[[q]])" |
48 |
50 |
49 text {* |
51 text {* |
50 A finite set of hypotheses from @{text t} and the @{text Var}s in |
52 A finite set of hypotheses from @{text t} and the @{text Var}s in |
51 @{text p}. |
53 @{text p}. |
52 *} |
54 *} |
53 |
55 |
54 primrec hyps :: "['a pl, 'a set] => 'a pl set" where |
56 primrec hyps :: "['a pl, 'a set] => 'a pl set" |
|
57 where |
55 "hyps false tt = {}" |
58 "hyps false tt = {}" |
56 | "hyps (#v) tt = {if v \<in> tt then #v else #v->false}" |
59 | "hyps (#v) tt = {if v \<in> tt then #v else #v->false}" |
57 | "hyps (p->q) tt = hyps p tt Un hyps q tt" |
60 | "hyps (p->q) tt = hyps p tt Un hyps q tt" |
58 |
61 |
|
62 |
59 subsubsection {* Logical consequence *} |
63 subsubsection {* Logical consequence *} |
60 |
64 |
61 text {* |
65 text {* |
62 For every valuation, if all elements of @{text H} are true then so |
66 For every valuation, if all elements of @{text H} are true then so |
63 is @{text p}. |
67 is @{text p}. |
64 *} |
68 *} |
65 |
69 |
66 definition |
70 definition sat :: "['a pl set, 'a pl] => bool" (infixl "|=" 50) |
67 sat :: "['a pl set, 'a pl] => bool" (infixl "|=" 50) where |
71 where "H |= p = (\<forall>tt. (\<forall>q\<in>H. tt[[q]]) --> tt[[p]])" |
68 "H |= p = (\<forall>tt. (\<forall>q\<in>H. tt[[q]]) --> tt[[p]])" |
|
69 |
72 |
70 |
73 |
71 subsection {* Proof theory of propositional logic *} |
74 subsection {* Proof theory of propositional logic *} |
72 |
75 |
73 lemma thms_mono: "G<=H ==> thms(G) <= thms(H)" |
76 lemma thms_mono: "G<=H ==> thms(G) <= thms(H)" |
85 |
88 |
86 lemma weaken_left: "[| G \<subseteq> H; G|-p |] ==> H|-p" |
89 lemma weaken_left: "[| G \<subseteq> H; G|-p |] ==> H|-p" |
87 -- {* Order of premises is convenient with @{text THEN} *} |
90 -- {* Order of premises is convenient with @{text THEN} *} |
88 by (erule thms_mono [THEN predicate1D]) |
91 by (erule thms_mono [THEN predicate1D]) |
89 |
92 |
90 lemmas weaken_left_insert = subset_insertI [THEN weaken_left] |
93 lemma weaken_left_insert: "G |- p \<Longrightarrow> insert a G |- p" |
91 |
94 by (rule weaken_left) (rule subset_insertI) |
92 lemmas weaken_left_Un1 = Un_upper1 [THEN weaken_left] |
95 |
93 lemmas weaken_left_Un2 = Un_upper2 [THEN weaken_left] |
96 lemma weaken_left_Un1: "G |- p \<Longrightarrow> G \<union> B |- p" |
|
97 by (rule weaken_left) (rule Un_upper1) |
|
98 |
|
99 lemma weaken_left_Un2: "G |- p \<Longrightarrow> A \<union> G |- p" |
|
100 by (rule weaken_left) (rule Un_upper2) |
94 |
101 |
95 lemma weaken_right: "H |- q ==> H |- p->q" |
102 lemma weaken_right: "H |- q ==> H |- p->q" |
96 by (fast intro: thms.K thms.MP) |
103 by (fast intro: thms.K thms.MP) |
97 |
104 |
98 |
105 |
105 done |
112 done |
106 |
113 |
107 |
114 |
108 subsubsection {* The cut rule *} |
115 subsubsection {* The cut rule *} |
109 |
116 |
110 lemmas cut = deduction [THEN thms.MP] |
117 lemma cut: "insert p H |- q \<Longrightarrow> H |- p \<Longrightarrow> H |- q" |
111 |
118 by (rule thms.MP) (rule deduction) |
112 lemmas thms_falseE = weaken_right [THEN thms.DN [THEN thms.MP]] |
119 |
113 |
120 lemma thms_falseE: "H |- false \<Longrightarrow> H |- q" |
114 lemmas thms_notE = thms.MP [THEN thms_falseE] |
121 by (rule thms.MP, rule thms.DN) (rule weaken_right) |
|
122 |
|
123 lemma thms_notE: "H |- p -> false \<Longrightarrow> H |- p \<Longrightarrow> H |- q" |
|
124 by (rule thms_falseE) (rule thms.MP) |
115 |
125 |
116 |
126 |
117 subsubsection {* Soundness of the rules wrt truth-table semantics *} |
127 subsubsection {* Soundness of the rules wrt truth-table semantics *} |
118 |
128 |
119 theorem soundness: "H |- p ==> H |= p" |
129 theorem soundness: "H |- p ==> H |= p" |
120 apply (unfold sat_def) |
130 by (induct set: thms) (auto simp: sat_def) |
121 apply (induct set: thms) |
131 |
122 apply auto |
|
123 done |
|
124 |
132 |
125 subsection {* Completeness *} |
133 subsection {* Completeness *} |
126 |
134 |
127 subsubsection {* Towards the completeness proof *} |
135 subsubsection {* Towards the completeness proof *} |
128 |
136 |
165 The excluded middle in the form of an elimination rule. |
173 The excluded middle in the form of an elimination rule. |
166 *} |
174 *} |
167 |
175 |
168 lemma thms_excluded_middle: "H |- (p->q) -> ((p->false)->q) -> q" |
176 lemma thms_excluded_middle: "H |- (p->q) -> ((p->false)->q) -> q" |
169 apply (rule deduction [THEN deduction]) |
177 apply (rule deduction [THEN deduction]) |
170 apply (rule thms.DN [THEN thms.MP], best) |
178 apply (rule thms.DN [THEN thms.MP], best intro: H) |
171 done |
179 done |
172 |
180 |
173 lemma thms_excluded_middle_rule: |
181 lemma thms_excluded_middle_rule: |
174 "[| insert p H |- q; insert (p->false) H |- q |] ==> H |- q" |
182 "[| insert p H |- q; insert (p->false) H |- q |] ==> H |- q" |
175 -- {* Hard to prove directly because it requires cuts *} |
183 -- {* Hard to prove directly because it requires cuts *} |
211 by (induct p) auto |
219 by (induct p) auto |
212 |
220 |
213 lemma hyps_subset: "hyps p t <= (UN v. {#v, #v->false})" |
221 lemma hyps_subset: "hyps p t <= (UN v. {#v, #v->false})" |
214 by (induct p) auto |
222 by (induct p) auto |
215 |
223 |
216 lemmas Diff_weaken_left = Diff_mono [OF _ subset_refl, THEN weaken_left] |
224 lemma Diff_weaken_left: "A \<subseteq> C \<Longrightarrow> A - B |- p \<Longrightarrow> C - B |- p" |
|
225 by (rule Diff_mono [OF _ subset_refl, THEN weaken_left]) |
|
226 |
217 |
227 |
218 subsubsection {* Completeness theorem *} |
228 subsubsection {* Completeness theorem *} |
219 |
229 |
220 text {* |
230 text {* |
221 Induction on the finite set of assumptions @{term "hyps p t0"}. We |
231 Induction on the finite set of assumptions @{term "hyps p t0"}. We |
244 apply (erule completeness_0_lemma [THEN spec]) |
254 apply (erule completeness_0_lemma [THEN spec]) |
245 done |
255 done |
246 |
256 |
247 text{*A semantic analogue of the Deduction Theorem*} |
257 text{*A semantic analogue of the Deduction Theorem*} |
248 lemma sat_imp: "insert p H |= q ==> H |= p->q" |
258 lemma sat_imp: "insert p H |= q ==> H |= p->q" |
249 by (unfold sat_def, auto) |
259 by (auto simp: sat_def) |
250 |
260 |
251 theorem completeness: "finite H ==> H |= p ==> H |- p" |
261 theorem completeness: "finite H ==> H |= p ==> H |- p" |
252 apply (induct arbitrary: p rule: finite_induct) |
262 apply (induct arbitrary: p rule: finite_induct) |
253 apply (blast intro: completeness_0) |
263 apply (blast intro: completeness_0) |
254 apply (iprover intro: sat_imp thms.H insertI1 weaken_left_insert [THEN thms.MP]) |
264 apply (iprover intro: sat_imp thms.H insertI1 weaken_left_insert [THEN thms.MP]) |