author  wenzelm 
Wed, 03 Nov 2010 21:53:56 +0100  
changeset 40335  3e4bb6e7c3ca 
parent 39159  0dec18004e75 
child 41959  b460124855b8 
permissions  rwrr 
17481  1 
(* Title: LK/LK0.thy 
7093  2 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 
3 
Copyright 1993 University of Cambridge 

4 

5 
There may be printing problems if a seqent is in expanded normal form 

35113  6 
(etaexpanded, betacontracted). 
7093  7 
*) 
8 

17481  9 
header {* Classical FirstOrder Sequent Calculus *} 
10 

11 
theory LK0 

12 
imports Sequents 

13 
begin 

7093  14 

17481  15 
classes "term" 
36452  16 
default_sort "term" 
7093  17 

18 
consts 

19 

21524  20 
Trueprop :: "two_seqi" 
7093  21 

17481  22 
True :: o 
23 
False :: o 

22894  24 
equal :: "['a,'a] => o" (infixl "=" 50) 
17481  25 
Not :: "o => o" ("~ _" [40] 40) 
22894  26 
conj :: "[o,o] => o" (infixr "&" 35) 
27 
disj :: "[o,o] => o" (infixr "" 30) 

28 
imp :: "[o,o] => o" (infixr ">" 25) 

29 
iff :: "[o,o] => o" (infixr "<>" 25) 

17481  30 
The :: "('a => o) => 'a" (binder "THE " 10) 
31 
All :: "('a => o) => o" (binder "ALL " 10) 

32 
Ex :: "('a => o) => o" (binder "EX " 10) 

7093  33 

34 
syntax 

35113  35 
"_Trueprop" :: "two_seqe" ("((_)/  (_))" [6,6] 5) 
17481  36 

35113  37 
parse_translation {* [(@{syntax_const "_Trueprop"}, two_seq_tr @{const_syntax Trueprop})] *} 
38 
print_translation {* [(@{const_syntax Trueprop}, two_seq_tr' @{syntax_const "_Trueprop"})] *} 

7093  39 

22894  40 
abbreviation 
41 
not_equal (infixl "~=" 50) where 

42 
"x ~= y == ~ (x = y)" 

7093  43 

35355
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

44 
notation (xsymbols) 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

45 
Not ("\<not> _" [40] 40) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

46 
conj (infixr "\<and>" 35) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

47 
disj (infixr "\<or>" 30) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

48 
imp (infixr "\<longrightarrow>" 25) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

49 
iff (infixr "\<longleftrightarrow>" 25) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

50 
All (binder "\<forall>" 10) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

51 
Ex (binder "\<exists>" 10) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

52 
not_equal (infixl "\<noteq>" 50) 
7093  53 

35355
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

54 
notation (HTML output) 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

55 
Not ("\<not> _" [40] 40) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

56 
conj (infixr "\<and>" 35) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

57 
disj (infixr "\<or>" 30) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

58 
All (binder "\<forall>" 10) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

59 
Ex (binder "\<exists>" 10) and 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
wenzelm
parents:
35113
diff
changeset

60 
not_equal (infixl "\<noteq>" 50) 
7093  61 

17481  62 
axioms 
7093  63 

64 
(*Structural rules: contraction, thinning, exchange [Soren Heilmann] *) 

65 

17481  66 
contRS: "$H  $E, $S, $S, $F ==> $H  $E, $S, $F" 
67 
contLS: "$H, $S, $S, $G  $E ==> $H, $S, $G  $E" 

7093  68 

17481  69 
thinRS: "$H  $E, $F ==> $H  $E, $S, $F" 
70 
thinLS: "$H, $G  $E ==> $H, $S, $G  $E" 

7093  71 

17481  72 
exchRS: "$H  $E, $R, $S, $F ==> $H  $E, $S, $R, $F" 
73 
exchLS: "$H, $R, $S, $G  $E ==> $H, $S, $R, $G  $E" 

7093  74 

17481  75 
cut: "[ $H  $E, P; $H, P  $E ] ==> $H  $E" 
7093  76 

77 
(*Propositional rules*) 

78 

17481  79 
basic: "$H, P, $G  $E, P, $F" 
7093  80 

17481  81 
conjR: "[ $H $E, P, $F; $H $E, Q, $F ] ==> $H $E, P&Q, $F" 
82 
conjL: "$H, P, Q, $G  $E ==> $H, P & Q, $G  $E" 

7093  83 

17481  84 
disjR: "$H  $E, P, Q, $F ==> $H  $E, PQ, $F" 
85 
disjL: "[ $H, P, $G  $E; $H, Q, $G  $E ] ==> $H, PQ, $G  $E" 

7093  86 

17481  87 
impR: "$H, P  $E, Q, $F ==> $H  $E, P>Q, $F" 
88 
impL: "[ $H,$G  $E,P; $H, Q, $G  $E ] ==> $H, P>Q, $G  $E" 

7093  89 

17481  90 
notR: "$H, P  $E, $F ==> $H  $E, ~P, $F" 
91 
notL: "$H, $G  $E, P ==> $H, ~P, $G  $E" 

7093  92 

17481  93 
FalseL: "$H, False, $G  $E" 
7093  94 

17481  95 
True_def: "True == False>False" 
96 
iff_def: "P<>Q == (P>Q) & (Q>P)" 

7093  97 

98 
(*Quantifiers*) 

99 

17481  100 
allR: "(!!x.$H  $E, P(x), $F) ==> $H  $E, ALL x. P(x), $F" 
101 
allL: "$H, P(x), $G, ALL x. P(x)  $E ==> $H, ALL x. P(x), $G  $E" 

7093  102 

17481  103 
exR: "$H  $E, P(x), $F, EX x. P(x) ==> $H  $E, EX x. P(x), $F" 
104 
exL: "(!!x.$H, P(x), $G  $E) ==> $H, EX x. P(x), $G  $E" 

7093  105 

106 
(*Equality*) 

107 

17481  108 
refl: "$H  $E, a=a, $F" 
109 
subst: "$H(a), $G(a)  $E(a) ==> $H(b), a=b, $G(b)  $E(b)" 

7093  110 

111 
(* Reflection *) 

112 

17481  113 
eq_reflection: " x=y ==> (x==y)" 
114 
iff_reflection: " P<>Q ==> (P==Q)" 

7093  115 

116 
(*Descriptions*) 

117 

17481  118 
The: "[ $H  $E, P(a), $F; !!x.$H, P(x)  $E, x=a, $F ] ==> 
7093  119 
$H  $E, P(THE x. P(x)), $F" 
120 

35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
35113
diff
changeset

121 
definition If :: "[o, 'a, 'a] => 'a" ("(if (_)/ then (_)/ else (_))" 10) where 
7093  122 
"If(P,x,y) == THE z::'a. (P > z=x) & (~P > z=y)" 
123 

21426  124 

125 
(** Structural Rules on formulas **) 

126 

127 
(*contraction*) 

128 

129 
lemma contR: "$H  $E, P, P, $F ==> $H  $E, P, $F" 

130 
by (rule contRS) 

131 

132 
lemma contL: "$H, P, P, $G  $E ==> $H, P, $G  $E" 

133 
by (rule contLS) 

134 

135 
(*thinning*) 

136 

137 
lemma thinR: "$H  $E, $F ==> $H  $E, P, $F" 

138 
by (rule thinRS) 

139 

140 
lemma thinL: "$H, $G  $E ==> $H, P, $G  $E" 

141 
by (rule thinLS) 

142 

143 
(*exchange*) 

144 

145 
lemma exchR: "$H  $E, Q, P, $F ==> $H  $E, P, Q, $F" 

146 
by (rule exchRS) 

147 

148 
lemma exchL: "$H, Q, P, $G  $E ==> $H, P, Q, $G  $E" 

149 
by (rule exchLS) 

150 

151 
ML {* 

152 
(*Cut and thin, replacing the rightside formula*) 

27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27146
diff
changeset

153 
fun cutR_tac ctxt s i = 
27239  154 
res_inst_tac ctxt [(("P", 0), s) ] @{thm cut} i THEN rtac @{thm thinR} i 
21426  155 

156 
(*Cut and thin, replacing the leftside formula*) 

27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27146
diff
changeset

157 
fun cutL_tac ctxt s i = 
27239  158 
res_inst_tac ctxt [(("P", 0), s)] @{thm cut} i THEN rtac @{thm thinL} (i+1) 
21426  159 
*} 
160 

161 

162 
(** Ifandonlyif rules **) 

163 
lemma iffR: 

164 
"[ $H,P  $E,Q,$F; $H,Q  $E,P,$F ] ==> $H  $E, P <> Q, $F" 

165 
apply (unfold iff_def) 

166 
apply (assumption  rule conjR impR)+ 

167 
done 

168 

169 
lemma iffL: 

170 
"[ $H,$G  $E,P,Q; $H,Q,P,$G  $E ] ==> $H, P <> Q, $G  $E" 

171 
apply (unfold iff_def) 

172 
apply (assumption  rule conjL impL basic)+ 

173 
done 

174 

175 
lemma iff_refl: "$H  $E, (P <> P), $F" 

176 
apply (rule iffR basic)+ 

177 
done 

178 

179 
lemma TrueR: "$H  $E, True, $F" 

180 
apply (unfold True_def) 

181 
apply (rule impR) 

182 
apply (rule basic) 

183 
done 

184 

185 
(*Descriptions*) 

186 
lemma the_equality: 

187 
assumes p1: "$H  $E, P(a), $F" 

188 
and p2: "!!x. $H, P(x)  $E, x=a, $F" 

189 
shows "$H  $E, (THE x. P(x)) = a, $F" 

190 
apply (rule cut) 

191 
apply (rule_tac [2] p2) 

192 
apply (rule The, rule thinR, rule exchRS, rule p1) 

193 
apply (rule thinR, rule exchRS, rule p2) 

194 
done 

195 

196 

197 
(** Weakened quantifier rules. Incomplete, they let the search terminate.**) 

198 

199 
lemma allL_thin: "$H, P(x), $G  $E ==> $H, ALL x. P(x), $G  $E" 

200 
apply (rule allL) 

201 
apply (erule thinL) 

202 
done 

203 

204 
lemma exR_thin: "$H  $E, P(x), $F ==> $H  $E, EX x. P(x), $F" 

205 
apply (rule exR) 

206 
apply (erule thinR) 

207 
done 

208 

209 
(*The rules of LK*) 

210 

211 
ML {* 

212 
val prop_pack = empty_pack add_safes 

39159  213 
[@{thm basic}, @{thm refl}, @{thm TrueR}, @{thm FalseL}, 
214 
@{thm conjL}, @{thm conjR}, @{thm disjL}, @{thm disjR}, @{thm impL}, @{thm impR}, 

215 
@{thm notL}, @{thm notR}, @{thm iffL}, @{thm iffR}]; 

21426  216 

39159  217 
val LK_pack = prop_pack add_safes [@{thm allR}, @{thm exL}] 
218 
add_unsafes [@{thm allL_thin}, @{thm exR_thin}, @{thm the_equality}]; 

21426  219 

39159  220 
val LK_dup_pack = prop_pack add_safes [@{thm allR}, @{thm exL}] 
221 
add_unsafes [@{thm allL}, @{thm exR}, @{thm the_equality}]; 

21426  222 

223 

224 
fun lemma_tac th i = 

39159  225 
rtac (@{thm thinR} RS @{thm cut}) i THEN REPEAT (rtac @{thm thinL} i) THEN rtac th i; 
21426  226 
*} 
227 

228 
method_setup fast_prop = 

30549  229 
{* Scan.succeed (K (SIMPLE_METHOD' (fast_tac prop_pack))) *} 
21426  230 
"propositional reasoning" 
231 

232 
method_setup fast = 

30549  233 
{* Scan.succeed (K (SIMPLE_METHOD' (fast_tac LK_pack))) *} 
21426  234 
"classical reasoning" 
235 

236 
method_setup fast_dup = 

30549  237 
{* Scan.succeed (K (SIMPLE_METHOD' (fast_tac LK_dup_pack))) *} 
21426  238 
"classical reasoning" 
239 

240 
method_setup best = 

30549  241 
{* Scan.succeed (K (SIMPLE_METHOD' (best_tac LK_pack))) *} 
21426  242 
"classical reasoning" 
243 

244 
method_setup best_dup = 

30549  245 
{* Scan.succeed (K (SIMPLE_METHOD' (best_tac LK_dup_pack))) *} 
21426  246 
"classical reasoning" 
7093  247 

7118
ee384c7b7416
adding missing declarations for the <<...>> notation
paulson
parents:
7093
diff
changeset

248 

21426  249 
lemma mp_R: 
250 
assumes major: "$H  $E, $F, P > Q" 

251 
and minor: "$H  $E, $F, P" 

252 
shows "$H  $E, Q, $F" 

253 
apply (rule thinRS [THEN cut], rule major) 

254 
apply (tactic "step_tac LK_pack 1") 

255 
apply (rule thinR, rule minor) 

256 
done 

257 

258 
lemma mp_L: 

259 
assumes major: "$H, $G  $E, P > Q" 

260 
and minor: "$H, $G, Q  $E" 

261 
shows "$H, P, $G  $E" 

262 
apply (rule thinL [THEN cut], rule major) 

263 
apply (tactic "step_tac LK_pack 1") 

264 
apply (rule thinL, rule minor) 

265 
done 

266 

267 

268 
(** Two rules to generate left and right rules from implications **) 

269 

270 
lemma R_of_imp: 

271 
assumes major: " P > Q" 

272 
and minor: "$H  $E, $F, P" 

273 
shows "$H  $E, Q, $F" 

274 
apply (rule mp_R) 

275 
apply (rule_tac [2] minor) 

276 
apply (rule thinRS, rule major [THEN thinLS]) 

277 
done 

278 

279 
lemma L_of_imp: 

280 
assumes major: " P > Q" 

281 
and minor: "$H, $G, Q  $E" 

282 
shows "$H, P, $G  $E" 

283 
apply (rule mp_L) 

284 
apply (rule_tac [2] minor) 

285 
apply (rule thinRS, rule major [THEN thinLS]) 

286 
done 

287 

288 
(*Can be used to create implications in a subgoal*) 

289 
lemma backwards_impR: 

290 
assumes prem: "$H, $G  $E, $F, P > Q" 

291 
shows "$H, P, $G  $E, Q, $F" 

292 
apply (rule mp_L) 

293 
apply (rule_tac [2] basic) 

294 
apply (rule thinR, rule prem) 

295 
done 

296 

297 
lemma conjunct1: "P&Q ==> P" 

298 
apply (erule thinR [THEN cut]) 

299 
apply fast 

300 
done 

301 

302 
lemma conjunct2: "P&Q ==> Q" 

303 
apply (erule thinR [THEN cut]) 

304 
apply fast 

305 
done 

306 

307 
lemma spec: " (ALL x. P(x)) ==>  P(x)" 

308 
apply (erule thinR [THEN cut]) 

309 
apply fast 

310 
done 

311 

312 

313 
(** Equality **) 

314 

315 
lemma sym: " a=b > b=a" 

39159  316 
by (tactic {* safe_tac (LK_pack add_safes [@{thm subst}]) 1 *}) 
21426  317 

318 
lemma trans: " a=b > b=c > a=c" 

39159  319 
by (tactic {* safe_tac (LK_pack add_safes [@{thm subst}]) 1 *}) 
21426  320 

321 
(* Symmetry of equality in hypotheses *) 

322 
lemmas symL = sym [THEN L_of_imp, standard] 

323 

324 
(* Symmetry of equality in hypotheses *) 

325 
lemmas symR = sym [THEN R_of_imp, standard] 

326 

327 
lemma transR: "[ $H $E, $F, a=b; $H $E, $F, b=c ] ==> $H $E, a=c, $F" 

328 
by (rule trans [THEN R_of_imp, THEN mp_R]) 

329 

330 
(* Two theorms for rewriting only one instance of a definition: 

331 
the first for definitions of formulae and the second for terms *) 

332 

333 
lemma def_imp_iff: "(A == B) ==>  A <> B" 

334 
apply unfold 

335 
apply (rule iff_refl) 

336 
done 

337 

338 
lemma meta_eq_to_obj_eq: "(A == B) ==>  A = B" 

339 
apply unfold 

340 
apply (rule refl) 

341 
done 

342 

343 

344 
(** ifthenelse rules **) 

345 

346 
lemma if_True: " (if True then x else y) = x" 

347 
unfolding If_def by fast 

348 

349 
lemma if_False: " (if False then x else y) = y" 

350 
unfolding If_def by fast 

351 

352 
lemma if_P: " P ==>  (if P then x else y) = x" 

353 
apply (unfold If_def) 

354 
apply (erule thinR [THEN cut]) 

355 
apply fast 

356 
done 

357 

358 
lemma if_not_P: " ~P ==>  (if P then x else y) = y"; 

359 
apply (unfold If_def) 

360 
apply (erule thinR [THEN cut]) 

361 
apply fast 

362 
done 

363 

364 
end 