author  wenzelm 
Sat, 22 Oct 2016 20:09:30 +0200  
changeset 64349  26bc905be09d 
parent 62147  a1b666aaac1a 
child 67399  eab6ce8368fa 
permissions  rwrr 
1477  1 
(* Title: FOLP/IFOLP.thy 
2 
Author: Martin D Coen, Cambridge University Computer Laboratory 

1142  3 
Copyright 1992 University of Cambridge 
4 
*) 

5 

60770  6 
section \<open>Intuitionistic FirstOrder Logic with Proofs\<close> 
17480  7 

8 
theory IFOLP 

9 
imports Pure 

10 
begin 

0  11 

48891  12 
ML_file "~~/src/Tools/misc_legacy.ML" 
13 

39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is globalonly;
wenzelm
parents:
38800
diff
changeset

14 
setup Pure_Thy.old_appl_syntax_setup 
26956
1309a6a0a29f
setup PureThy.old_appl_syntax_setup  theory Pure provides regular application syntax by default;
wenzelm
parents:
26480
diff
changeset

15 

55380
4de48353034e
prefer vacuous definitional type classes over axiomatic ones;
wenzelm
parents:
52230
diff
changeset

16 
class "term" 
36452  17 
default_sort "term" 
0  18 

17480  19 
typedecl p 
20 
typedecl o 

0  21 

17480  22 
consts 
0  23 
(*** Judgements ***) 
1477  24 
Proof :: "[o,p]=>prop" 
0  25 
EqProof :: "[p,p,o]=>prop" ("(3_ /= _ :/ _)" [10,10,10] 5) 
17480  26 

0  27 
(*** Logical Connectives  Type Formers ***) 
41310  28 
eq :: "['a,'a] => o" (infixl "=" 50) 
17480  29 
True :: "o" 
30 
False :: "o" 

41310  31 
conj :: "[o,o] => o" (infixr "&" 35) 
32 
disj :: "[o,o] => o" (infixr "" 30) 

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

0  34 
(*Quantifiers*) 
1477  35 
All :: "('a => o) => o" (binder "ALL " 10) 
36 
Ex :: "('a => o) => o" (binder "EX " 10) 

0  37 
(*Rewriting gadgets*) 
1477  38 
NORM :: "o => o" 
39 
norm :: "'a => 'a" 

0  40 

648
e27c9ec2b48b
FOLP/IFOLP.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents:
283
diff
changeset

41 
(*** Proof Term Formers: precedence must exceed 50 ***) 
1477  42 
tt :: "p" 
43 
contr :: "p=>p" 

17480  44 
fst :: "p=>p" 
45 
snd :: "p=>p" 

1477  46 
pair :: "[p,p]=>p" ("(1<_,/_>)") 
47 
split :: "[p, [p,p]=>p] =>p" 

17480  48 
inl :: "p=>p" 
49 
inr :: "p=>p" 

60555
51a6997b1384
support 'when' statement, which corresponds to 'presume';
wenzelm
parents:
59529
diff
changeset

50 
"when" :: "[p, p=>p, p=>p]=>p" 
1477  51 
lambda :: "(p => p) => p" (binder "lam " 55) 
41310  52 
App :: "[p,p]=>p" (infixl "`" 60) 
648
e27c9ec2b48b
FOLP/IFOLP.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents:
283
diff
changeset

53 
alll :: "['a=>p]=>p" (binder "all " 55) 
41310  54 
app :: "[p,'a]=>p" (infixl "^" 55) 
1477  55 
exists :: "['a,p]=>p" ("(1[_,/_])") 
0  56 
xsplit :: "[p,['a,p]=>p]=>p" 
57 
ideq :: "'a=>p" 

58 
idpeel :: "[p,'a=>p]=>p" 

17480  59 
nrm :: p 
60 
NRM :: p 

0  61 

35113  62 
syntax "_Proof" :: "[p,o]=>prop" ("(_ /: _)" [51, 10] 5) 
63 

60770  64 
parse_translation \<open> 
38800  65 
let fun proof_tr [p, P] = Const (@{const_syntax Proof}, dummyT) $ P $ p 
52143  66 
in [(@{syntax_const "_Proof"}, K proof_tr)] end 
60770  67 
\<close> 
17480  68 

38800  69 
(*show_proofs = true displays the proof terms  they are ENORMOUS*) 
60770  70 
ML \<open>val show_proofs = Attrib.setup_config_bool @{binding show_proofs} (K false)\<close> 
38800  71 

60770  72 
print_translation \<open> 
38800  73 
let 
74 
fun proof_tr' ctxt [P, p] = 

75 
if Config.get ctxt show_proofs then Const (@{syntax_const "_Proof"}, dummyT) $ p $ P 

76 
else P 

77 
in [(@{const_syntax Proof}, proof_tr')] end 

60770  78 
\<close> 
17480  79 

0  80 

81 
(**** Propositional logic ****) 

82 

83 
(*Equality*) 

84 
(* Like Intensional Equality in MLTT  but proofs distinct from terms *) 

85 

51306  86 
axiomatization where 
87 
ieqI: "ideq(a) : a=a" and 

17480  88 
ieqE: "[ p : a=b; !!x. f(x) : P(x,x) ] ==> idpeel(p,f) : P(a,b)" 
0  89 

90 
(* Truth and Falsity *) 

91 

51306  92 
axiomatization where 
93 
TrueI: "tt : True" and 

17480  94 
FalseE: "a:False ==> contr(a):P" 
0  95 

96 
(* Conjunction *) 

97 

51306  98 
axiomatization where 
99 
conjI: "[ a:P; b:Q ] ==> <a,b> : P&Q" and 

100 
conjunct1: "p:P&Q ==> fst(p):P" and 

17480  101 
conjunct2: "p:P&Q ==> snd(p):Q" 
0  102 

103 
(* Disjunction *) 

104 

51306  105 
axiomatization where 
106 
disjI1: "a:P ==> inl(a):PQ" and 

107 
disjI2: "b:Q ==> inr(b):PQ" and 

17480  108 
disjE: "[ a:PQ; !!x. x:P ==> f(x):R; !!x. x:Q ==> g(x):R 
109 
] ==> when(a,f,g):R" 

0  110 

111 
(* Implication *) 

112 

51306  113 
axiomatization where 
114 
impI: "\<And>P Q f. (!!x. x:P ==> f(x):Q) ==> lam x. f(x):P>Q" and 

115 
mp: "\<And>P Q f. [ f:P>Q; a:P ] ==> f`a:Q" 

0  116 

117 
(*Quantifiers*) 

118 

51306  119 
axiomatization where 
120 
allI: "\<And>P. (!!x. f(x) : P(x)) ==> all x. f(x) : ALL x. P(x)" and 

121 
spec: "\<And>P f. (f:ALL x. P(x)) ==> f^x : P(x)" 

0  122 

51306  123 
axiomatization where 
124 
exI: "p : P(x) ==> [x,p] : EX x. P(x)" and 

17480  125 
exE: "[ p: EX x. P(x); !!x u. u:P(x) ==> f(x,u) : R ] ==> xsplit(p,f):R" 
0  126 

127 
(**** Equality between proofs ****) 

128 

51306  129 
axiomatization where 
130 
prefl: "a : P ==> a = a : P" and 

131 
psym: "a = b : P ==> b = a : P" and 

17480  132 
ptrans: "[ a = b : P; b = c : P ] ==> a = c : P" 
0  133 

51306  134 
axiomatization where 
17480  135 
idpeelB: "[ !!x. f(x) : P(x,x) ] ==> idpeel(ideq(a),f) = f(a) : P(a,a)" 
0  136 

51306  137 
axiomatization where 
138 
fstB: "a:P ==> fst(<a,b>) = a : P" and 

139 
sndB: "b:Q ==> snd(<a,b>) = b : Q" and 

17480  140 
pairEC: "p:P&Q ==> p = <fst(p),snd(p)> : P&Q" 
0  141 

51306  142 
axiomatization where 
143 
whenBinl: "[ a:P; !!x. x:P ==> f(x) : Q ] ==> when(inl(a),f,g) = f(a) : Q" and 

144 
whenBinr: "[ b:P; !!x. x:P ==> g(x) : Q ] ==> when(inr(b),f,g) = g(b) : Q" and 

17480  145 
plusEC: "a:PQ ==> when(a,%x. inl(x),%y. inr(y)) = a : PQ" 
0  146 

51306  147 
axiomatization where 
148 
applyB: "[ a:P; !!x. x:P ==> b(x) : Q ] ==> (lam x. b(x)) ` a = b(a) : Q" and 

17480  149 
funEC: "f:P ==> f = lam x. f`x : P" 
0  150 

51306  151 
axiomatization where 
17480  152 
specB: "[ !!x. f(x) : P(x) ] ==> (all x. f(x)) ^ a = f(a) : P(a)" 
0  153 

154 

155 
(**** Definitions ****) 

156 

62147  157 
definition Not :: "o => o" ("~ _" [40] 40) 
158 
where not_def: "~P == P>False" 

159 

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

161 
where "P<>Q == (P>Q) & (Q>P)" 

0  162 

163 
(*Unique existence*) 

62147  164 
definition Ex1 :: "('a => o) => o" (binder "EX! " 10) 
165 
where ex1_def: "EX! x. P(x) == EX x. P(x) & (ALL y. P(y) > y=x)" 

0  166 

167 
(*Rewriting  special constants to flag normalized terms and formulae*) 

51306  168 
axiomatization where 
169 
norm_eq: "nrm : norm(x) = x" and 

17480  170 
NORM_iff: "NRM : NORM(P) <> P" 
171 

26322  172 
(*** Sequentstyle elimination rules for & > and ALL ***) 
173 

61337  174 
schematic_goal conjE: 
26322  175 
assumes "p:P&Q" 
176 
and "!!x y.[ x:P; y:Q ] ==> f(x,y):R" 

177 
shows "?a:R" 

178 
apply (rule assms(2)) 

179 
apply (rule conjunct1 [OF assms(1)]) 

180 
apply (rule conjunct2 [OF assms(1)]) 

181 
done 

182 

61337  183 
schematic_goal impE: 
26322  184 
assumes "p:P>Q" 
185 
and "q:P" 

186 
and "!!x. x:Q ==> r(x):R" 

187 
shows "?p:R" 

188 
apply (rule assms mp)+ 

189 
done 

190 

61337  191 
schematic_goal allE: 
26322  192 
assumes "p:ALL x. P(x)" 
193 
and "!!y. y:P(x) ==> q(y):R" 

194 
shows "?p:R" 

195 
apply (rule assms spec)+ 

196 
done 

197 

198 
(*Duplicates the quantifier; for use with eresolve_tac*) 

61337  199 
schematic_goal all_dupE: 
26322  200 
assumes "p:ALL x. P(x)" 
201 
and "!!y z.[ y:P(x); z:ALL x. P(x) ] ==> q(y,z):R" 

202 
shows "?p:R" 

203 
apply (rule assms spec)+ 

204 
done 

205 

206 

207 
(*** Negation rules, which translate between ~P and P>False ***) 

208 

61337  209 
schematic_goal notI: 
26322  210 
assumes "!!x. x:P ==> q(x):False" 
211 
shows "?p:~P" 

212 
unfolding not_def 

213 
apply (assumption  rule assms impI)+ 

214 
done 

215 

61337  216 
schematic_goal notE: "p:~P \<Longrightarrow> q:P \<Longrightarrow> ?p:R" 
26322  217 
unfolding not_def 
218 
apply (drule (1) mp) 

219 
apply (erule FalseE) 

220 
done 

221 

222 
(*This is useful with the special implication rules for each kind of P. *) 

61337  223 
schematic_goal not_to_imp: 
26322  224 
assumes "p:~P" 
225 
and "!!x. x:(P>False) ==> q(x):Q" 

226 
shows "?p:Q" 

227 
apply (assumption  rule assms impI notE)+ 

228 
done 

229 

230 
(* For substitution int an assumption P, reduce Q to P>Q, substitute into 

27150  231 
this implication, then apply impI to move P back into the assumptions.*) 
61337  232 
schematic_goal rev_mp: "[ p:P; q:P > Q ] ==> ?p:Q" 
26322  233 
apply (assumption  rule mp)+ 
234 
done 

235 

236 

237 
(*Contrapositive of an inference rule*) 

61337  238 
schematic_goal contrapos: 
26322  239 
assumes major: "p:~Q" 
240 
and minor: "!!y. y:P==>q(y):Q" 

241 
shows "?a:~P" 

242 
apply (rule major [THEN notE, THEN notI]) 

243 
apply (erule minor) 

244 
done 

245 

246 
(** Unique assumption tactic. 

247 
Ignores proof objects. 

248 
Fails unless one assumption is equal and exactly one is unifiable 

249 
**) 

250 

60770  251 
ML \<open> 
26322  252 
local 
253 
fun discard_proof (Const (@{const_name Proof}, _) $ P $ _) = P; 

254 
in 

58963
26bf09b95dda
proper context for assume_tac (atac remains as fallback without context);
wenzelm
parents:
58889
diff
changeset

255 
fun uniq_assume_tac ctxt = 
26322  256 
SUBGOAL 
257 
(fn (prem,i) => 

258 
let val hyps = map discard_proof (Logic.strip_assums_hyp prem) 

259 
and concl = discard_proof (Logic.strip_assums_concl prem) 

260 
in 

261 
if exists (fn hyp => hyp aconv concl) hyps 

29269
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents:
27152
diff
changeset

262 
then case distinct (op =) (filter (fn hyp => Term.could_unify (hyp, concl)) hyps) of 
58963
26bf09b95dda
proper context for assume_tac (atac remains as fallback without context);
wenzelm
parents:
58889
diff
changeset

263 
[_] => assume_tac ctxt i 
26322  264 
 _ => no_tac 
265 
else no_tac 

266 
end); 

267 
end; 

60770  268 
\<close> 
26322  269 

270 

271 
(*** Modus Ponens Tactics ***) 

272 

273 
(*Finds P>Q and P in the assumptions, replaces implication by Q *) 

60770  274 
ML \<open> 
58963
26bf09b95dda
proper context for assume_tac (atac remains as fallback without context);
wenzelm
parents:
58889
diff
changeset

275 
fun mp_tac ctxt i = 
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset

276 
eresolve_tac ctxt [@{thm notE}, make_elim @{thm mp}] i THEN assume_tac ctxt i 
60770  277 
\<close> 
59529  278 
method_setup mp = \<open>Scan.succeed (SIMPLE_METHOD' o mp_tac)\<close> 
26322  279 

280 
(*Like mp_tac but instantiates no variables*) 

60770  281 
ML \<open> 
58963
26bf09b95dda
proper context for assume_tac (atac remains as fallback without context);
wenzelm
parents:
58889
diff
changeset

282 
fun int_uniq_mp_tac ctxt i = 
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset

283 
eresolve_tac ctxt [@{thm notE}, @{thm impE}] i THEN uniq_assume_tac ctxt i 
60770  284 
\<close> 
26322  285 

286 

287 
(*** Ifandonlyif ***) 

288 

61337  289 
schematic_goal iffI: 
26322  290 
assumes "!!x. x:P ==> q(x):Q" 
291 
and "!!x. x:Q ==> r(x):P" 

292 
shows "?p:P<>Q" 

293 
unfolding iff_def 

294 
apply (assumption  rule assms conjI impI)+ 

295 
done 

296 

297 

61337  298 
schematic_goal iffE: 
26322  299 
assumes "p:P <> Q" 
300 
and "!!x y.[ x:P>Q; y:Q>P ] ==> q(x,y):R" 

301 
shows "?p:R" 

302 
apply (rule conjE) 

303 
apply (rule assms(1) [unfolded iff_def]) 

304 
apply (rule assms(2)) 

305 
apply assumption+ 

306 
done 

307 

308 
(* Destruct rules for <> similar to Modus Ponens *) 

309 

61337  310 
schematic_goal iffD1: "[ p:P <> Q; q:P ] ==> ?p:Q" 
26322  311 
unfolding iff_def 
312 
apply (rule conjunct1 [THEN mp], assumption+) 

313 
done 

314 

61337  315 
schematic_goal iffD2: "[ p:P <> Q; q:Q ] ==> ?p:P" 
26322  316 
unfolding iff_def 
317 
apply (rule conjunct2 [THEN mp], assumption+) 

318 
done 

319 

61337  320 
schematic_goal iff_refl: "?p:P <> P" 
26322  321 
apply (rule iffI) 
322 
apply assumption+ 

323 
done 

324 

61337  325 
schematic_goal iff_sym: "p:Q <> P ==> ?p:P <> Q" 
26322  326 
apply (erule iffE) 
327 
apply (rule iffI) 

328 
apply (erule (1) mp)+ 

329 
done 

330 

61337  331 
schematic_goal iff_trans: "[ p:P <> Q; q:Q<> R ] ==> ?p:P <> R" 
26322  332 
apply (rule iffI) 
333 
apply (assumption  erule iffE  erule (1) impE)+ 

334 
done 

335 

336 
(*** Unique existence. NOTE THAT the following 2 quantifications 

337 
EX!x such that [EX!y such that P(x,y)] (sequential) 

338 
EX!x,y such that P(x,y) (simultaneous) 

339 
do NOT mean the same thing. The parser treats EX!x y.P(x,y) as sequential. 

340 
***) 

341 

61337  342 
schematic_goal ex1I: 
26322  343 
assumes "p:P(a)" 
344 
and "!!x u. u:P(x) ==> f(u) : x=a" 

345 
shows "?p:EX! x. P(x)" 

346 
unfolding ex1_def 

347 
apply (assumption  rule assms exI conjI allI impI)+ 

348 
done 

349 

61337  350 
schematic_goal ex1E: 
26322  351 
assumes "p:EX! x. P(x)" 
352 
and "!!x u v. [ u:P(x); v:ALL y. P(y) > y=x ] ==> f(x,u,v):R" 

353 
shows "?a : R" 

354 
apply (insert assms(1) [unfolded ex1_def]) 

355 
apply (erule exE conjE  assumption  rule assms(1))+ 

29305  356 
apply (erule assms(2), assumption) 
26322  357 
done 
358 

359 

360 
(*** <> congruence rules for simplification ***) 

361 

362 
(*Use iffE on a premise. For conj_cong, imp_cong, all_cong, ex_cong*) 

60770  363 
ML \<open> 
59529  364 
fun iff_tac ctxt prems i = 
365 
resolve_tac ctxt (prems RL [@{thm iffE}]) i THEN 

366 
REPEAT1 (eresolve_tac ctxt [asm_rl, @{thm mp}] i) 

60770  367 
\<close> 
26322  368 

59529  369 
method_setup iff = 
370 
\<open>Attrib.thms >> (fn prems => fn ctxt => SIMPLE_METHOD' (iff_tac ctxt prems))\<close> 

371 

61337  372 
schematic_goal conj_cong: 
26322  373 
assumes "p:P <> P'" 
374 
and "!!x. x:P' ==> q(x):Q <> Q'" 

375 
shows "?p:(P&Q) <> (P'&Q')" 

376 
apply (insert assms(1)) 

59529  377 
apply (assumption  rule iffI conjI  erule iffE conjE mp  iff assms)+ 
26322  378 
done 
379 

61337  380 
schematic_goal disj_cong: 
26322  381 
"[ p:P <> P'; q:Q <> Q' ] ==> ?p:(PQ) <> (P'Q')" 
59529  382 
apply (erule iffE disjE disjI1 disjI2  assumption  rule iffI  mp)+ 
26322  383 
done 
384 

61337  385 
schematic_goal imp_cong: 
26322  386 
assumes "p:P <> P'" 
387 
and "!!x. x:P' ==> q(x):Q <> Q'" 

388 
shows "?p:(P>Q) <> (P'>Q')" 

389 
apply (insert assms(1)) 

59529  390 
apply (assumption  rule iffI impI  erule iffE  mp  iff assms)+ 
26322  391 
done 
392 

61337  393 
schematic_goal iff_cong: 
26322  394 
"[ p:P <> P'; q:Q <> Q' ] ==> ?p:(P<>Q) <> (P'<>Q')" 
59529  395 
apply (erule iffE  assumption  rule iffI  mp)+ 
26322  396 
done 
397 

61337  398 
schematic_goal not_cong: 
26322  399 
"p:P <> P' ==> ?p:~P <> ~P'" 
59529  400 
apply (assumption  rule iffI notI  mp  erule iffE notE)+ 
26322  401 
done 
402 

61337  403 
schematic_goal all_cong: 
26322  404 
assumes "!!x. f(x):P(x) <> Q(x)" 
405 
shows "?p:(ALL x. P(x)) <> (ALL x. Q(x))" 

59529  406 
apply (assumption  rule iffI allI  mp  erule allE  iff assms)+ 
26322  407 
done 
408 

61337  409 
schematic_goal ex_cong: 
26322  410 
assumes "!!x. f(x):P(x) <> Q(x)" 
411 
shows "?p:(EX x. P(x)) <> (EX x. Q(x))" 

59529  412 
apply (erule exE  assumption  rule iffI exI  mp  iff assms)+ 
26322  413 
done 
414 

415 
(*NOT PROVED 

56199  416 
ML_Thms.bind_thm ("ex1_cong", prove_goal (the_context ()) 
26322  417 
"(!!x.f(x):P(x) <> Q(x)) ==> ?p:(EX! x.P(x)) <> (EX! x.Q(x))" 
418 
(fn prems => 

419 
[ (REPEAT (eresolve_tac [ex1E, spec RS mp] 1 ORELSE ares_tac [iffI,ex1I] 1 

420 
ORELSE mp_tac 1 

421 
ORELSE iff_tac prems 1)) ])) 

422 
*) 

423 

424 
(*** Equality rules ***) 

425 

426 
lemmas refl = ieqI 

427 

61337  428 
schematic_goal subst: 
26322  429 
assumes prem1: "p:a=b" 
430 
and prem2: "q:P(a)" 

431 
shows "?p : P(b)" 

432 
apply (rule prem2 [THEN rev_mp]) 

433 
apply (rule prem1 [THEN ieqE]) 

434 
apply (rule impI) 

435 
apply assumption 

436 
done 

437 

61337  438 
schematic_goal sym: "q:a=b ==> ?c:b=a" 
26322  439 
apply (erule subst) 
440 
apply (rule refl) 

441 
done 

442 

61337  443 
schematic_goal trans: "[ p:a=b; q:b=c ] ==> ?d:a=c" 
26322  444 
apply (erule (1) subst) 
445 
done 

446 

447 
(** ~ b=a ==> ~ a=b **) 

61337  448 
schematic_goal not_sym: "p:~ b=a ==> ?q:~ a=b" 
26322  449 
apply (erule contrapos) 
450 
apply (erule sym) 

451 
done 

452 

61337  453 
schematic_goal ssubst: "p:b=a \<Longrightarrow> q:P(a) \<Longrightarrow> ?p:P(b)" 
45594  454 
apply (drule sym) 
455 
apply (erule subst) 

456 
apply assumption 

457 
done 

26322  458 

459 
(*A special case of ex1E that would otherwise need quantifier expansion*) 

61337  460 
schematic_goal ex1_equalsE: "[ p:EX! x. P(x); q:P(a); r:P(b) ] ==> ?d:a=b" 
26322  461 
apply (erule ex1E) 
462 
apply (rule trans) 

463 
apply (rule_tac [2] sym) 

464 
apply (assumption  erule spec [THEN mp])+ 

465 
done 

466 

467 
(** Polymorphic congruence rules **) 

468 

61337  469 
schematic_goal subst_context: "[ p:a=b ] ==> ?d:t(a)=t(b)" 
26322  470 
apply (erule ssubst) 
471 
apply (rule refl) 

472 
done 

473 

61337  474 
schematic_goal subst_context2: "[ p:a=b; q:c=d ] ==> ?p:t(a,c)=t(b,d)" 
26322  475 
apply (erule ssubst)+ 
476 
apply (rule refl) 

477 
done 

478 

61337  479 
schematic_goal subst_context3: "[ p:a=b; q:c=d; r:e=f ] ==> ?p:t(a,c,e)=t(b,d,f)" 
26322  480 
apply (erule ssubst)+ 
481 
apply (rule refl) 

482 
done 

483 

484 
(*Useful with eresolve_tac for proving equalties from known equalities. 

485 
a = b 

486 
  

487 
c = d *) 

61337  488 
schematic_goal box_equals: "[ p:a=b; q:a=c; r:b=d ] ==> ?p:c=d" 
26322  489 
apply (rule trans) 
490 
apply (rule trans) 

491 
apply (rule sym) 

492 
apply assumption+ 

493 
done 

494 

495 
(*Dual of box_equals: for proving equalities backwards*) 

61337  496 
schematic_goal simp_equals: "[ p:a=c; q:b=d; r:c=d ] ==> ?p:a=b" 
26322  497 
apply (rule trans) 
498 
apply (rule trans) 

499 
apply (assumption  rule sym)+ 

500 
done 

501 

502 
(** Congruence rules for predicate letters **) 

503 

61337  504 
schematic_goal pred1_cong: "p:a=a' ==> ?p:P(a) <> P(a')" 
26322  505 
apply (rule iffI) 
60770  506 
apply (tactic \<open> 
507 
DEPTH_SOLVE (assume_tac @{context} 1 ORELSE eresolve_tac @{context} [@{thm subst}, @{thm ssubst}] 1)\<close>) 

26322  508 
done 
509 

61337  510 
schematic_goal pred2_cong: "[ p:a=a'; q:b=b' ] ==> ?p:P(a,b) <> P(a',b')" 
26322  511 
apply (rule iffI) 
60770  512 
apply (tactic \<open> 
513 
DEPTH_SOLVE (assume_tac @{context} 1 ORELSE eresolve_tac @{context} [@{thm subst}, @{thm ssubst}] 1)\<close>) 

26322  514 
done 
515 

61337  516 
schematic_goal pred3_cong: "[ p:a=a'; q:b=b'; r:c=c' ] ==> ?p:P(a,b,c) <> P(a',b',c')" 
26322  517 
apply (rule iffI) 
60770  518 
apply (tactic \<open> 
519 
DEPTH_SOLVE (assume_tac @{context} 1 ORELSE eresolve_tac @{context} [@{thm subst}, @{thm ssubst}] 1)\<close>) 

26322  520 
done 
521 

27152
192954a9a549
changed pred_congs: merely cover pred1_cong pred2_cong pred3_cong;
wenzelm
parents:
27150
diff
changeset

522 
lemmas pred_congs = pred1_cong pred2_cong pred3_cong 
26322  523 

524 
(*special case for the equality predicate!*) 

45602  525 
lemmas eq_cong = pred2_cong [where P = "op ="] 
26322  526 

527 

528 
(*** Simplifications of assumed implications. 

529 
Roy Dyckhoff has proved that conj_impE, disj_impE, and imp_impE 

530 
used with mp_tac (restricted to atomic formulae) is COMPLETE for 

531 
intuitionistic propositional logic. See 

532 
R. Dyckhoff, Contractionfree sequent calculi for intuitionistic logic 

533 
(preprint, University of St Andrews, 1991) ***) 

534 

61337  535 
schematic_goal conj_impE: 
26322  536 
assumes major: "p:(P&Q)>S" 
537 
and minor: "!!x. x:P>(Q>S) ==> q(x):R" 

538 
shows "?p:R" 

539 
apply (assumption  rule conjI impI major [THEN mp] minor)+ 

540 
done 

541 

61337  542 
schematic_goal disj_impE: 
26322  543 
assumes major: "p:(PQ)>S" 
544 
and minor: "!!x y.[ x:P>S; y:Q>S ] ==> q(x,y):R" 

545 
shows "?p:R" 

60770  546 
apply (tactic \<open>DEPTH_SOLVE (assume_tac @{context} 1 ORELSE 
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset

547 
resolve_tac @{context} [@{thm disjI1}, @{thm disjI2}, @{thm impI}, 
60770  548 
@{thm major} RS @{thm mp}, @{thm minor}] 1)\<close>) 
26322  549 
done 
550 

551 
(*Simplifies the implication. Classical version is stronger. 

552 
Still UNSAFE since Q must be provable  backtracking needed. *) 

61337  553 
schematic_goal imp_impE: 
26322  554 
assumes major: "p:(P>Q)>S" 
555 
and r1: "!!x y.[ x:P; y:Q>S ] ==> q(x,y):Q" 

556 
and r2: "!!x. x:S ==> r(x):R" 

557 
shows "?p:R" 

558 
apply (assumption  rule impI major [THEN mp] r1 r2)+ 

559 
done 

560 

561 
(*Simplifies the implication. Classical version is stronger. 

562 
Still UNSAFE since ~P must be provable  backtracking needed. *) 

61337  563 
schematic_goal not_impE: 
26322  564 
assumes major: "p:~P > S" 
565 
and r1: "!!y. y:P ==> q(y):False" 

566 
and r2: "!!y. y:S ==> r(y):R" 

567 
shows "?p:R" 

568 
apply (assumption  rule notI impI major [THEN mp] r1 r2)+ 

569 
done 

570 

571 
(*Simplifies the implication. UNSAFE. *) 

61337  572 
schematic_goal iff_impE: 
26322  573 
assumes major: "p:(P<>Q)>S" 
574 
and r1: "!!x y.[ x:P; y:Q>S ] ==> q(x,y):Q" 

575 
and r2: "!!x y.[ x:Q; y:P>S ] ==> r(x,y):P" 

576 
and r3: "!!x. x:S ==> s(x):R" 

577 
shows "?p:R" 

578 
apply (assumption  rule iffI impI major [THEN mp] r1 r2 r3)+ 

579 
done 

580 

581 
(*What if (ALL x.~~P(x)) > ~~(ALL x.P(x)) is an assumption? UNSAFE*) 

61337  582 
schematic_goal all_impE: 
26322  583 
assumes major: "p:(ALL x. P(x))>S" 
584 
and r1: "!!x. q:P(x)" 

585 
and r2: "!!y. y:S ==> r(y):R" 

586 
shows "?p:R" 

587 
apply (assumption  rule allI impI major [THEN mp] r1 r2)+ 

588 
done 

589 

590 
(*Unsafe: (EX x.P(x))>S is equivalent to ALL x.P(x)>S. *) 

61337  591 
schematic_goal ex_impE: 
26322  592 
assumes major: "p:(EX x. P(x))>S" 
593 
and r: "!!y. y:P(a)>S ==> q(y):R" 

594 
shows "?p:R" 

595 
apply (assumption  rule exI impI major [THEN mp] r)+ 

596 
done 

597 

598 

61337  599 
schematic_goal rev_cut_eq: 
26322  600 
assumes "p:a=b" 
601 
and "!!x. x:a=b ==> f(x):R" 

602 
shows "?p:R" 

603 
apply (rule assms)+ 

604 
done 

605 

606 
lemma thin_refl: "!!X. [p:x=x; PROP W] ==> PROP W" . 

607 

48891  608 
ML_file "hypsubst.ML" 
26322  609 

60770  610 
ML \<open> 
42799  611 
structure Hypsubst = Hypsubst 
612 
( 

26322  613 
(*Take apart an equality judgement; otherwise raise Match!*) 
614 
fun dest_eq (Const (@{const_name Proof}, _) $ 

41310  615 
(Const (@{const_name eq}, _) $ t $ u) $ _) = (t, u); 
26322  616 

617 
val imp_intr = @{thm impI} 

618 

619 
(*etac rev_cut_eq moves an equality to be the last premise. *) 

620 
val rev_cut_eq = @{thm rev_cut_eq} 

621 

622 
val rev_mp = @{thm rev_mp} 

623 
val subst = @{thm subst} 

624 
val sym = @{thm sym} 

625 
val thin_refl = @{thm thin_refl} 

42799  626 
); 
26322  627 
open Hypsubst; 
60770  628 
\<close> 
26322  629 

48891  630 
ML_file "intprover.ML" 
26322  631 

632 

633 
(*** Rewrite rules ***) 

634 

61337  635 
schematic_goal conj_rews: 
26322  636 
"?p1 : P & True <> P" 
637 
"?p2 : True & P <> P" 

638 
"?p3 : P & False <> False" 

639 
"?p4 : False & P <> False" 

640 
"?p5 : P & P <> P" 

641 
"?p6 : P & ~P <> False" 

642 
"?p7 : ~P & P <> False" 

643 
"?p8 : (P & Q) & R <> P & (Q & R)" 

60770  644 
apply (tactic \<open>fn st => IntPr.fast_tac @{context} 1 st\<close>)+ 
26322  645 
done 
646 

61337  647 
schematic_goal disj_rews: 
26322  648 
"?p1 : P  True <> True" 
649 
"?p2 : True  P <> True" 

650 
"?p3 : P  False <> P" 

651 
"?p4 : False  P <> P" 

652 
"?p5 : P  P <> P" 

653 
"?p6 : (P  Q)  R <> P  (Q  R)" 

60770  654 
apply (tactic \<open>IntPr.fast_tac @{context} 1\<close>)+ 
26322  655 
done 
656 

61337  657 
schematic_goal not_rews: 
26322  658 
"?p1 : ~ False <> True" 
659 
"?p2 : ~ True <> False" 

60770  660 
apply (tactic \<open>IntPr.fast_tac @{context} 1\<close>)+ 
26322  661 
done 
662 

61337  663 
schematic_goal imp_rews: 
26322  664 
"?p1 : (P > False) <> ~P" 
665 
"?p2 : (P > True) <> True" 

666 
"?p3 : (False > P) <> True" 

667 
"?p4 : (True > P) <> P" 

668 
"?p5 : (P > P) <> True" 

669 
"?p6 : (P > ~P) <> ~P" 

60770  670 
apply (tactic \<open>IntPr.fast_tac @{context} 1\<close>)+ 
26322  671 
done 
672 

61337  673 
schematic_goal iff_rews: 
26322  674 
"?p1 : (True <> P) <> P" 
675 
"?p2 : (P <> True) <> P" 

676 
"?p3 : (P <> P) <> True" 

677 
"?p4 : (False <> P) <> ~P" 

678 
"?p5 : (P <> False) <> ~P" 

60770  679 
apply (tactic \<open>IntPr.fast_tac @{context} 1\<close>)+ 
26322  680 
done 
681 

61337  682 
schematic_goal quant_rews: 
26322  683 
"?p1 : (ALL x. P) <> P" 
684 
"?p2 : (EX x. P) <> P" 

60770  685 
apply (tactic \<open>IntPr.fast_tac @{context} 1\<close>)+ 
26322  686 
done 
687 

688 
(*These are NOT supplied by default!*) 

61337  689 
schematic_goal distrib_rews1: 
26322  690 
"?p1 : ~(PQ) <> ~P & ~Q" 
691 
"?p2 : P & (Q  R) <> P&Q  P&R" 

692 
"?p3 : (Q  R) & P <> Q&P  R&P" 

693 
"?p4 : (P  Q > R) <> (P > R) & (Q > R)" 

60770  694 
apply (tactic \<open>IntPr.fast_tac @{context} 1\<close>)+ 
26322  695 
done 
696 

61337  697 
schematic_goal distrib_rews2: 
26322  698 
"?p1 : ~(EX x. NORM(P(x))) <> (ALL x. ~NORM(P(x)))" 
699 
"?p2 : ((EX x. NORM(P(x))) > Q) <> (ALL x. NORM(P(x)) > Q)" 

700 
"?p3 : (EX x. NORM(P(x))) & NORM(Q) <> (EX x. NORM(P(x)) & NORM(Q))" 

701 
"?p4 : NORM(Q) & (EX x. NORM(P(x))) <> (EX x. NORM(Q) & NORM(P(x)))" 

60770  702 
apply (tactic \<open>IntPr.fast_tac @{context} 1\<close>)+ 
26322  703 
done 
704 

705 
lemmas distrib_rews = distrib_rews1 distrib_rews2 

706 

61337  707 
schematic_goal P_Imp_P_iff_T: "p:P ==> ?p:(P <> True)" 
60770  708 
apply (tactic \<open>IntPr.fast_tac @{context} 1\<close>) 
26322  709 
done 
710 

61337  711 
schematic_goal not_P_imp_P_iff_F: "p:~P ==> ?p:(P <> False)" 
60770  712 
apply (tactic \<open>IntPr.fast_tac @{context} 1\<close>) 
26322  713 
done 
0  714 

715 
end 