author | wenzelm |
Wed, 23 Jul 2014 14:50:20 +0200 | |
changeset 57616 | 50ab1db5c0fd |
parent 56199 | 8e8d28ed7529 |
child 58889 | 5b7a9633cfa8 |
permissions | -rw-r--r-- |
1477 | 1 |
(* Title: FOLP/IFOLP.thy |
2 |
Author: Martin D Coen, Cambridge University Computer Laboratory |
|
1142 | 3 |
Copyright 1992 University of Cambridge |
4 |
*) |
|
5 |
||
17480 | 6 |
header {* Intuitionistic First-Order Logic with Proofs *} |
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 global-only;
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" |
|
2714 | 31 |
Not :: "o => o" ("~ _" [40] 40) |
41310 | 32 |
conj :: "[o,o] => o" (infixr "&" 35) |
33 |
disj :: "[o,o] => o" (infixr "|" 30) |
|
34 |
imp :: "[o,o] => o" (infixr "-->" 25) |
|
35 |
iff :: "[o,o] => o" (infixr "<->" 25) |
|
0 | 36 |
(*Quantifiers*) |
1477 | 37 |
All :: "('a => o) => o" (binder "ALL " 10) |
38 |
Ex :: "('a => o) => o" (binder "EX " 10) |
|
39 |
Ex1 :: "('a => o) => o" (binder "EX! " 10) |
|
0 | 40 |
(*Rewriting gadgets*) |
1477 | 41 |
NORM :: "o => o" |
42 |
norm :: "'a => 'a" |
|
0 | 43 |
|
648
e27c9ec2b48b
FOLP/IFOLP.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents:
283
diff
changeset
|
44 |
(*** Proof Term Formers: precedence must exceed 50 ***) |
1477 | 45 |
tt :: "p" |
46 |
contr :: "p=>p" |
|
17480 | 47 |
fst :: "p=>p" |
48 |
snd :: "p=>p" |
|
1477 | 49 |
pair :: "[p,p]=>p" ("(1<_,/_>)") |
50 |
split :: "[p, [p,p]=>p] =>p" |
|
17480 | 51 |
inl :: "p=>p" |
52 |
inr :: "p=>p" |
|
1477 | 53 |
when :: "[p, p=>p, p=>p]=>p" |
54 |
lambda :: "(p => p) => p" (binder "lam " 55) |
|
41310 | 55 |
App :: "[p,p]=>p" (infixl "`" 60) |
648
e27c9ec2b48b
FOLP/IFOLP.thy: tightening precedences to eliminate syntactic ambiguities.
lcp
parents:
283
diff
changeset
|
56 |
alll :: "['a=>p]=>p" (binder "all " 55) |
41310 | 57 |
app :: "[p,'a]=>p" (infixl "^" 55) |
1477 | 58 |
exists :: "['a,p]=>p" ("(1[_,/_])") |
0 | 59 |
xsplit :: "[p,['a,p]=>p]=>p" |
60 |
ideq :: "'a=>p" |
|
61 |
idpeel :: "[p,'a=>p]=>p" |
|
17480 | 62 |
nrm :: p |
63 |
NRM :: p |
|
0 | 64 |
|
35113 | 65 |
syntax "_Proof" :: "[p,o]=>prop" ("(_ /: _)" [51, 10] 5) |
66 |
||
38800 | 67 |
parse_translation {* |
68 |
let fun proof_tr [p, P] = Const (@{const_syntax Proof}, dummyT) $ P $ p |
|
52143 | 69 |
in [(@{syntax_const "_Proof"}, K proof_tr)] end |
17480 | 70 |
*} |
71 |
||
38800 | 72 |
(*show_proofs = true displays the proof terms -- they are ENORMOUS*) |
42616
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
wenzelm
parents:
41310
diff
changeset
|
73 |
ML {* val show_proofs = Attrib.setup_config_bool @{binding show_proofs} (K false) *} |
38800 | 74 |
|
52143 | 75 |
print_translation {* |
38800 | 76 |
let |
77 |
fun proof_tr' ctxt [P, p] = |
|
78 |
if Config.get ctxt show_proofs then Const (@{syntax_const "_Proof"}, dummyT) $ p $ P |
|
79 |
else P |
|
80 |
in [(@{const_syntax Proof}, proof_tr')] end |
|
81 |
*} |
|
17480 | 82 |
|
0 | 83 |
|
84 |
(**** Propositional logic ****) |
|
85 |
||
86 |
(*Equality*) |
|
87 |
(* Like Intensional Equality in MLTT - but proofs distinct from terms *) |
|
88 |
||
51306 | 89 |
axiomatization where |
90 |
ieqI: "ideq(a) : a=a" and |
|
17480 | 91 |
ieqE: "[| p : a=b; !!x. f(x) : P(x,x) |] ==> idpeel(p,f) : P(a,b)" |
0 | 92 |
|
93 |
(* Truth and Falsity *) |
|
94 |
||
51306 | 95 |
axiomatization where |
96 |
TrueI: "tt : True" and |
|
17480 | 97 |
FalseE: "a:False ==> contr(a):P" |
0 | 98 |
|
99 |
(* Conjunction *) |
|
100 |
||
51306 | 101 |
axiomatization where |
102 |
conjI: "[| a:P; b:Q |] ==> <a,b> : P&Q" and |
|
103 |
conjunct1: "p:P&Q ==> fst(p):P" and |
|
17480 | 104 |
conjunct2: "p:P&Q ==> snd(p):Q" |
0 | 105 |
|
106 |
(* Disjunction *) |
|
107 |
||
51306 | 108 |
axiomatization where |
109 |
disjI1: "a:P ==> inl(a):P|Q" and |
|
110 |
disjI2: "b:Q ==> inr(b):P|Q" and |
|
17480 | 111 |
disjE: "[| a:P|Q; !!x. x:P ==> f(x):R; !!x. x:Q ==> g(x):R |
112 |
|] ==> when(a,f,g):R" |
|
0 | 113 |
|
114 |
(* Implication *) |
|
115 |
||
51306 | 116 |
axiomatization where |
117 |
impI: "\<And>P Q f. (!!x. x:P ==> f(x):Q) ==> lam x. f(x):P-->Q" and |
|
118 |
mp: "\<And>P Q f. [| f:P-->Q; a:P |] ==> f`a:Q" |
|
0 | 119 |
|
120 |
(*Quantifiers*) |
|
121 |
||
51306 | 122 |
axiomatization where |
123 |
allI: "\<And>P. (!!x. f(x) : P(x)) ==> all x. f(x) : ALL x. P(x)" and |
|
124 |
spec: "\<And>P f. (f:ALL x. P(x)) ==> f^x : P(x)" |
|
0 | 125 |
|
51306 | 126 |
axiomatization where |
127 |
exI: "p : P(x) ==> [x,p] : EX x. P(x)" and |
|
17480 | 128 |
exE: "[| p: EX x. P(x); !!x u. u:P(x) ==> f(x,u) : R |] ==> xsplit(p,f):R" |
0 | 129 |
|
130 |
(**** Equality between proofs ****) |
|
131 |
||
51306 | 132 |
axiomatization where |
133 |
prefl: "a : P ==> a = a : P" and |
|
134 |
psym: "a = b : P ==> b = a : P" and |
|
17480 | 135 |
ptrans: "[| a = b : P; b = c : P |] ==> a = c : P" |
0 | 136 |
|
51306 | 137 |
axiomatization where |
17480 | 138 |
idpeelB: "[| !!x. f(x) : P(x,x) |] ==> idpeel(ideq(a),f) = f(a) : P(a,a)" |
0 | 139 |
|
51306 | 140 |
axiomatization where |
141 |
fstB: "a:P ==> fst(<a,b>) = a : P" and |
|
142 |
sndB: "b:Q ==> snd(<a,b>) = b : Q" and |
|
17480 | 143 |
pairEC: "p:P&Q ==> p = <fst(p),snd(p)> : P&Q" |
0 | 144 |
|
51306 | 145 |
axiomatization where |
146 |
whenBinl: "[| a:P; !!x. x:P ==> f(x) : Q |] ==> when(inl(a),f,g) = f(a) : Q" and |
|
147 |
whenBinr: "[| b:P; !!x. x:P ==> g(x) : Q |] ==> when(inr(b),f,g) = g(b) : Q" and |
|
17480 | 148 |
plusEC: "a:P|Q ==> when(a,%x. inl(x),%y. inr(y)) = a : P|Q" |
0 | 149 |
|
51306 | 150 |
axiomatization where |
151 |
applyB: "[| a:P; !!x. x:P ==> b(x) : Q |] ==> (lam x. b(x)) ` a = b(a) : Q" and |
|
17480 | 152 |
funEC: "f:P ==> f = lam x. f`x : P" |
0 | 153 |
|
51306 | 154 |
axiomatization where |
17480 | 155 |
specB: "[| !!x. f(x) : P(x) |] ==> (all x. f(x)) ^ a = f(a) : P(a)" |
0 | 156 |
|
157 |
||
158 |
(**** Definitions ****) |
|
159 |
||
51306 | 160 |
defs |
17480 | 161 |
not_def: "~P == P-->False" |
162 |
iff_def: "P<->Q == (P-->Q) & (Q-->P)" |
|
0 | 163 |
|
164 |
(*Unique existence*) |
|
17480 | 165 |
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 |
(*** Sequent-style elimination rules for & --> and ALL ***) |
173 |
||
36319 | 174 |
schematic_lemma 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 |
||
36319 | 183 |
schematic_lemma 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 |
||
36319 | 191 |
schematic_lemma 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*) |
|
36319 | 199 |
schematic_lemma 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 |
||
36319 | 209 |
schematic_lemma 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 |
||
36319 | 216 |
schematic_lemma 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. *) |
|
36319 | 223 |
schematic_lemma 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.*) |
36319 | 232 |
schematic_lemma 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*) |
|
36319 | 238 |
schematic_lemma 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 |
||
251 |
ML {* |
|
252 |
local |
|
253 |
fun discard_proof (Const (@{const_name Proof}, _) $ P $ _) = P; |
|
254 |
in |
|
255 |
val uniq_assume_tac = |
|
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 |
26322 | 263 |
[_] => assume_tac i |
264 |
| _ => no_tac |
|
265 |
else no_tac |
|
266 |
end); |
|
267 |
end; |
|
268 |
*} |
|
269 |
||
270 |
||
271 |
(*** Modus Ponens Tactics ***) |
|
272 |
||
273 |
(*Finds P-->Q and P in the assumptions, replaces implication by Q *) |
|
274 |
ML {* |
|
275 |
fun mp_tac i = eresolve_tac [@{thm notE}, make_elim @{thm mp}] i THEN assume_tac i |
|
276 |
*} |
|
277 |
||
278 |
(*Like mp_tac but instantiates no variables*) |
|
279 |
ML {* |
|
280 |
fun int_uniq_mp_tac i = eresolve_tac [@{thm notE}, @{thm impE}] i THEN uniq_assume_tac i |
|
281 |
*} |
|
282 |
||
283 |
||
284 |
(*** If-and-only-if ***) |
|
285 |
||
36319 | 286 |
schematic_lemma iffI: |
26322 | 287 |
assumes "!!x. x:P ==> q(x):Q" |
288 |
and "!!x. x:Q ==> r(x):P" |
|
289 |
shows "?p:P<->Q" |
|
290 |
unfolding iff_def |
|
291 |
apply (assumption | rule assms conjI impI)+ |
|
292 |
done |
|
293 |
||
294 |
||
36319 | 295 |
schematic_lemma iffE: |
26322 | 296 |
assumes "p:P <-> Q" |
297 |
and "!!x y.[| x:P-->Q; y:Q-->P |] ==> q(x,y):R" |
|
298 |
shows "?p:R" |
|
299 |
apply (rule conjE) |
|
300 |
apply (rule assms(1) [unfolded iff_def]) |
|
301 |
apply (rule assms(2)) |
|
302 |
apply assumption+ |
|
303 |
done |
|
304 |
||
305 |
(* Destruct rules for <-> similar to Modus Ponens *) |
|
306 |
||
36319 | 307 |
schematic_lemma iffD1: "[| p:P <-> Q; q:P |] ==> ?p:Q" |
26322 | 308 |
unfolding iff_def |
309 |
apply (rule conjunct1 [THEN mp], assumption+) |
|
310 |
done |
|
311 |
||
36319 | 312 |
schematic_lemma iffD2: "[| p:P <-> Q; q:Q |] ==> ?p:P" |
26322 | 313 |
unfolding iff_def |
314 |
apply (rule conjunct2 [THEN mp], assumption+) |
|
315 |
done |
|
316 |
||
36319 | 317 |
schematic_lemma iff_refl: "?p:P <-> P" |
26322 | 318 |
apply (rule iffI) |
319 |
apply assumption+ |
|
320 |
done |
|
321 |
||
36319 | 322 |
schematic_lemma iff_sym: "p:Q <-> P ==> ?p:P <-> Q" |
26322 | 323 |
apply (erule iffE) |
324 |
apply (rule iffI) |
|
325 |
apply (erule (1) mp)+ |
|
326 |
done |
|
327 |
||
36319 | 328 |
schematic_lemma iff_trans: "[| p:P <-> Q; q:Q<-> R |] ==> ?p:P <-> R" |
26322 | 329 |
apply (rule iffI) |
330 |
apply (assumption | erule iffE | erule (1) impE)+ |
|
331 |
done |
|
332 |
||
333 |
(*** Unique existence. NOTE THAT the following 2 quantifications |
|
334 |
EX!x such that [EX!y such that P(x,y)] (sequential) |
|
335 |
EX!x,y such that P(x,y) (simultaneous) |
|
336 |
do NOT mean the same thing. The parser treats EX!x y.P(x,y) as sequential. |
|
337 |
***) |
|
338 |
||
36319 | 339 |
schematic_lemma ex1I: |
26322 | 340 |
assumes "p:P(a)" |
341 |
and "!!x u. u:P(x) ==> f(u) : x=a" |
|
342 |
shows "?p:EX! x. P(x)" |
|
343 |
unfolding ex1_def |
|
344 |
apply (assumption | rule assms exI conjI allI impI)+ |
|
345 |
done |
|
346 |
||
36319 | 347 |
schematic_lemma ex1E: |
26322 | 348 |
assumes "p:EX! x. P(x)" |
349 |
and "!!x u v. [| u:P(x); v:ALL y. P(y) --> y=x |] ==> f(x,u,v):R" |
|
350 |
shows "?a : R" |
|
351 |
apply (insert assms(1) [unfolded ex1_def]) |
|
352 |
apply (erule exE conjE | assumption | rule assms(1))+ |
|
29305 | 353 |
apply (erule assms(2), assumption) |
26322 | 354 |
done |
355 |
||
356 |
||
357 |
(*** <-> congruence rules for simplification ***) |
|
358 |
||
359 |
(*Use iffE on a premise. For conj_cong, imp_cong, all_cong, ex_cong*) |
|
360 |
ML {* |
|
361 |
fun iff_tac prems i = |
|
362 |
resolve_tac (prems RL [@{thm iffE}]) i THEN |
|
363 |
REPEAT1 (eresolve_tac [asm_rl, @{thm mp}] i) |
|
364 |
*} |
|
365 |
||
36319 | 366 |
schematic_lemma conj_cong: |
26322 | 367 |
assumes "p:P <-> P'" |
368 |
and "!!x. x:P' ==> q(x):Q <-> Q'" |
|
369 |
shows "?p:(P&Q) <-> (P'&Q')" |
|
370 |
apply (insert assms(1)) |
|
371 |
apply (assumption | rule iffI conjI | |
|
372 |
erule iffE conjE mp | tactic {* iff_tac @{thms assms} 1 *})+ |
|
373 |
done |
|
374 |
||
36319 | 375 |
schematic_lemma disj_cong: |
26322 | 376 |
"[| p:P <-> P'; q:Q <-> Q' |] ==> ?p:(P|Q) <-> (P'|Q')" |
377 |
apply (erule iffE disjE disjI1 disjI2 | assumption | rule iffI | tactic {* mp_tac 1 *})+ |
|
378 |
done |
|
379 |
||
36319 | 380 |
schematic_lemma imp_cong: |
26322 | 381 |
assumes "p:P <-> P'" |
382 |
and "!!x. x:P' ==> q(x):Q <-> Q'" |
|
383 |
shows "?p:(P-->Q) <-> (P'-->Q')" |
|
384 |
apply (insert assms(1)) |
|
385 |
apply (assumption | rule iffI impI | erule iffE | tactic {* mp_tac 1 *} | |
|
386 |
tactic {* iff_tac @{thms assms} 1 *})+ |
|
387 |
done |
|
388 |
||
36319 | 389 |
schematic_lemma iff_cong: |
26322 | 390 |
"[| p:P <-> P'; q:Q <-> Q' |] ==> ?p:(P<->Q) <-> (P'<->Q')" |
391 |
apply (erule iffE | assumption | rule iffI | tactic {* mp_tac 1 *})+ |
|
392 |
done |
|
393 |
||
36319 | 394 |
schematic_lemma not_cong: |
26322 | 395 |
"p:P <-> P' ==> ?p:~P <-> ~P'" |
396 |
apply (assumption | rule iffI notI | tactic {* mp_tac 1 *} | erule iffE notE)+ |
|
397 |
done |
|
398 |
||
36319 | 399 |
schematic_lemma all_cong: |
26322 | 400 |
assumes "!!x. f(x):P(x) <-> Q(x)" |
401 |
shows "?p:(ALL x. P(x)) <-> (ALL x. Q(x))" |
|
402 |
apply (assumption | rule iffI allI | tactic {* mp_tac 1 *} | erule allE | |
|
403 |
tactic {* iff_tac @{thms assms} 1 *})+ |
|
404 |
done |
|
405 |
||
36319 | 406 |
schematic_lemma ex_cong: |
26322 | 407 |
assumes "!!x. f(x):P(x) <-> Q(x)" |
408 |
shows "?p:(EX x. P(x)) <-> (EX x. Q(x))" |
|
409 |
apply (erule exE | assumption | rule iffI exI | tactic {* mp_tac 1 *} | |
|
410 |
tactic {* iff_tac @{thms assms} 1 *})+ |
|
411 |
done |
|
412 |
||
413 |
(*NOT PROVED |
|
56199 | 414 |
ML_Thms.bind_thm ("ex1_cong", prove_goal (the_context ()) |
26322 | 415 |
"(!!x.f(x):P(x) <-> Q(x)) ==> ?p:(EX! x.P(x)) <-> (EX! x.Q(x))" |
416 |
(fn prems => |
|
417 |
[ (REPEAT (eresolve_tac [ex1E, spec RS mp] 1 ORELSE ares_tac [iffI,ex1I] 1 |
|
418 |
ORELSE mp_tac 1 |
|
419 |
ORELSE iff_tac prems 1)) ])) |
|
420 |
*) |
|
421 |
||
422 |
(*** Equality rules ***) |
|
423 |
||
424 |
lemmas refl = ieqI |
|
425 |
||
36319 | 426 |
schematic_lemma subst: |
26322 | 427 |
assumes prem1: "p:a=b" |
428 |
and prem2: "q:P(a)" |
|
429 |
shows "?p : P(b)" |
|
430 |
apply (rule prem2 [THEN rev_mp]) |
|
431 |
apply (rule prem1 [THEN ieqE]) |
|
432 |
apply (rule impI) |
|
433 |
apply assumption |
|
434 |
done |
|
435 |
||
36319 | 436 |
schematic_lemma sym: "q:a=b ==> ?c:b=a" |
26322 | 437 |
apply (erule subst) |
438 |
apply (rule refl) |
|
439 |
done |
|
440 |
||
36319 | 441 |
schematic_lemma trans: "[| p:a=b; q:b=c |] ==> ?d:a=c" |
26322 | 442 |
apply (erule (1) subst) |
443 |
done |
|
444 |
||
445 |
(** ~ b=a ==> ~ a=b **) |
|
36319 | 446 |
schematic_lemma not_sym: "p:~ b=a ==> ?q:~ a=b" |
26322 | 447 |
apply (erule contrapos) |
448 |
apply (erule sym) |
|
449 |
done |
|
450 |
||
45594 | 451 |
schematic_lemma ssubst: "p:b=a \<Longrightarrow> q:P(a) \<Longrightarrow> ?p:P(b)" |
452 |
apply (drule sym) |
|
453 |
apply (erule subst) |
|
454 |
apply assumption |
|
455 |
done |
|
26322 | 456 |
|
457 |
(*A special case of ex1E that would otherwise need quantifier expansion*) |
|
36319 | 458 |
schematic_lemma ex1_equalsE: "[| p:EX! x. P(x); q:P(a); r:P(b) |] ==> ?d:a=b" |
26322 | 459 |
apply (erule ex1E) |
460 |
apply (rule trans) |
|
461 |
apply (rule_tac [2] sym) |
|
462 |
apply (assumption | erule spec [THEN mp])+ |
|
463 |
done |
|
464 |
||
465 |
(** Polymorphic congruence rules **) |
|
466 |
||
36319 | 467 |
schematic_lemma subst_context: "[| p:a=b |] ==> ?d:t(a)=t(b)" |
26322 | 468 |
apply (erule ssubst) |
469 |
apply (rule refl) |
|
470 |
done |
|
471 |
||
36319 | 472 |
schematic_lemma subst_context2: "[| p:a=b; q:c=d |] ==> ?p:t(a,c)=t(b,d)" |
26322 | 473 |
apply (erule ssubst)+ |
474 |
apply (rule refl) |
|
475 |
done |
|
476 |
||
36319 | 477 |
schematic_lemma subst_context3: "[| p:a=b; q:c=d; r:e=f |] ==> ?p:t(a,c,e)=t(b,d,f)" |
26322 | 478 |
apply (erule ssubst)+ |
479 |
apply (rule refl) |
|
480 |
done |
|
481 |
||
482 |
(*Useful with eresolve_tac for proving equalties from known equalities. |
|
483 |
a = b |
|
484 |
| | |
|
485 |
c = d *) |
|
36319 | 486 |
schematic_lemma box_equals: "[| p:a=b; q:a=c; r:b=d |] ==> ?p:c=d" |
26322 | 487 |
apply (rule trans) |
488 |
apply (rule trans) |
|
489 |
apply (rule sym) |
|
490 |
apply assumption+ |
|
491 |
done |
|
492 |
||
493 |
(*Dual of box_equals: for proving equalities backwards*) |
|
36319 | 494 |
schematic_lemma simp_equals: "[| p:a=c; q:b=d; r:c=d |] ==> ?p:a=b" |
26322 | 495 |
apply (rule trans) |
496 |
apply (rule trans) |
|
497 |
apply (assumption | rule sym)+ |
|
498 |
done |
|
499 |
||
500 |
(** Congruence rules for predicate letters **) |
|
501 |
||
36319 | 502 |
schematic_lemma pred1_cong: "p:a=a' ==> ?p:P(a) <-> P(a')" |
26322 | 503 |
apply (rule iffI) |
504 |
apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE eresolve_tac [@{thm subst}, @{thm ssubst}] 1) *}) |
|
505 |
done |
|
506 |
||
36319 | 507 |
schematic_lemma pred2_cong: "[| p:a=a'; q:b=b' |] ==> ?p:P(a,b) <-> P(a',b')" |
26322 | 508 |
apply (rule iffI) |
509 |
apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE eresolve_tac [@{thm subst}, @{thm ssubst}] 1) *}) |
|
510 |
done |
|
511 |
||
36319 | 512 |
schematic_lemma pred3_cong: "[| p:a=a'; q:b=b'; r:c=c' |] ==> ?p:P(a,b,c) <-> P(a',b',c')" |
26322 | 513 |
apply (rule iffI) |
514 |
apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE eresolve_tac [@{thm subst}, @{thm ssubst}] 1) *}) |
|
515 |
done |
|
516 |
||
27152
192954a9a549
changed pred_congs: merely cover pred1_cong pred2_cong pred3_cong;
wenzelm
parents:
27150
diff
changeset
|
517 |
lemmas pred_congs = pred1_cong pred2_cong pred3_cong |
26322 | 518 |
|
519 |
(*special case for the equality predicate!*) |
|
45602 | 520 |
lemmas eq_cong = pred2_cong [where P = "op ="] |
26322 | 521 |
|
522 |
||
523 |
(*** Simplifications of assumed implications. |
|
524 |
Roy Dyckhoff has proved that conj_impE, disj_impE, and imp_impE |
|
525 |
used with mp_tac (restricted to atomic formulae) is COMPLETE for |
|
526 |
intuitionistic propositional logic. See |
|
527 |
R. Dyckhoff, Contraction-free sequent calculi for intuitionistic logic |
|
528 |
(preprint, University of St Andrews, 1991) ***) |
|
529 |
||
36319 | 530 |
schematic_lemma conj_impE: |
26322 | 531 |
assumes major: "p:(P&Q)-->S" |
532 |
and minor: "!!x. x:P-->(Q-->S) ==> q(x):R" |
|
533 |
shows "?p:R" |
|
534 |
apply (assumption | rule conjI impI major [THEN mp] minor)+ |
|
535 |
done |
|
536 |
||
36319 | 537 |
schematic_lemma disj_impE: |
26322 | 538 |
assumes major: "p:(P|Q)-->S" |
539 |
and minor: "!!x y.[| x:P-->S; y:Q-->S |] ==> q(x,y):R" |
|
540 |
shows "?p:R" |
|
541 |
apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE |
|
542 |
resolve_tac [@{thm disjI1}, @{thm disjI2}, @{thm impI}, |
|
543 |
@{thm major} RS @{thm mp}, @{thm minor}] 1) *}) |
|
544 |
done |
|
545 |
||
546 |
(*Simplifies the implication. Classical version is stronger. |
|
547 |
Still UNSAFE since Q must be provable -- backtracking needed. *) |
|
36319 | 548 |
schematic_lemma imp_impE: |
26322 | 549 |
assumes major: "p:(P-->Q)-->S" |
550 |
and r1: "!!x y.[| x:P; y:Q-->S |] ==> q(x,y):Q" |
|
551 |
and r2: "!!x. x:S ==> r(x):R" |
|
552 |
shows "?p:R" |
|
553 |
apply (assumption | rule impI major [THEN mp] r1 r2)+ |
|
554 |
done |
|
555 |
||
556 |
(*Simplifies the implication. Classical version is stronger. |
|
557 |
Still UNSAFE since ~P must be provable -- backtracking needed. *) |
|
36319 | 558 |
schematic_lemma not_impE: |
26322 | 559 |
assumes major: "p:~P --> S" |
560 |
and r1: "!!y. y:P ==> q(y):False" |
|
561 |
and r2: "!!y. y:S ==> r(y):R" |
|
562 |
shows "?p:R" |
|
563 |
apply (assumption | rule notI impI major [THEN mp] r1 r2)+ |
|
564 |
done |
|
565 |
||
566 |
(*Simplifies the implication. UNSAFE. *) |
|
36319 | 567 |
schematic_lemma iff_impE: |
26322 | 568 |
assumes major: "p:(P<->Q)-->S" |
569 |
and r1: "!!x y.[| x:P; y:Q-->S |] ==> q(x,y):Q" |
|
570 |
and r2: "!!x y.[| x:Q; y:P-->S |] ==> r(x,y):P" |
|
571 |
and r3: "!!x. x:S ==> s(x):R" |
|
572 |
shows "?p:R" |
|
573 |
apply (assumption | rule iffI impI major [THEN mp] r1 r2 r3)+ |
|
574 |
done |
|
575 |
||
576 |
(*What if (ALL x.~~P(x)) --> ~~(ALL x.P(x)) is an assumption? UNSAFE*) |
|
36319 | 577 |
schematic_lemma all_impE: |
26322 | 578 |
assumes major: "p:(ALL x. P(x))-->S" |
579 |
and r1: "!!x. q:P(x)" |
|
580 |
and r2: "!!y. y:S ==> r(y):R" |
|
581 |
shows "?p:R" |
|
582 |
apply (assumption | rule allI impI major [THEN mp] r1 r2)+ |
|
583 |
done |
|
584 |
||
585 |
(*Unsafe: (EX x.P(x))-->S is equivalent to ALL x.P(x)-->S. *) |
|
36319 | 586 |
schematic_lemma ex_impE: |
26322 | 587 |
assumes major: "p:(EX x. P(x))-->S" |
588 |
and r: "!!y. y:P(a)-->S ==> q(y):R" |
|
589 |
shows "?p:R" |
|
590 |
apply (assumption | rule exI impI major [THEN mp] r)+ |
|
591 |
done |
|
592 |
||
593 |
||
36319 | 594 |
schematic_lemma rev_cut_eq: |
26322 | 595 |
assumes "p:a=b" |
596 |
and "!!x. x:a=b ==> f(x):R" |
|
597 |
shows "?p:R" |
|
598 |
apply (rule assms)+ |
|
599 |
done |
|
600 |
||
601 |
lemma thin_refl: "!!X. [|p:x=x; PROP W|] ==> PROP W" . |
|
602 |
||
48891 | 603 |
ML_file "hypsubst.ML" |
26322 | 604 |
|
605 |
ML {* |
|
42799 | 606 |
structure Hypsubst = Hypsubst |
607 |
( |
|
26322 | 608 |
(*Take apart an equality judgement; otherwise raise Match!*) |
609 |
fun dest_eq (Const (@{const_name Proof}, _) $ |
|
41310 | 610 |
(Const (@{const_name eq}, _) $ t $ u) $ _) = (t, u); |
26322 | 611 |
|
612 |
val imp_intr = @{thm impI} |
|
613 |
||
614 |
(*etac rev_cut_eq moves an equality to be the last premise. *) |
|
615 |
val rev_cut_eq = @{thm rev_cut_eq} |
|
616 |
||
617 |
val rev_mp = @{thm rev_mp} |
|
618 |
val subst = @{thm subst} |
|
619 |
val sym = @{thm sym} |
|
620 |
val thin_refl = @{thm thin_refl} |
|
42799 | 621 |
); |
26322 | 622 |
open Hypsubst; |
623 |
*} |
|
624 |
||
48891 | 625 |
ML_file "intprover.ML" |
26322 | 626 |
|
627 |
||
628 |
(*** Rewrite rules ***) |
|
629 |
||
36319 | 630 |
schematic_lemma conj_rews: |
26322 | 631 |
"?p1 : P & True <-> P" |
632 |
"?p2 : True & P <-> P" |
|
633 |
"?p3 : P & False <-> False" |
|
634 |
"?p4 : False & P <-> False" |
|
635 |
"?p5 : P & P <-> P" |
|
636 |
"?p6 : P & ~P <-> False" |
|
637 |
"?p7 : ~P & P <-> False" |
|
638 |
"?p8 : (P & Q) & R <-> P & (Q & R)" |
|
639 |
apply (tactic {* fn st => IntPr.fast_tac 1 st *})+ |
|
640 |
done |
|
641 |
||
36319 | 642 |
schematic_lemma disj_rews: |
26322 | 643 |
"?p1 : P | True <-> True" |
644 |
"?p2 : True | P <-> True" |
|
645 |
"?p3 : P | False <-> P" |
|
646 |
"?p4 : False | P <-> P" |
|
647 |
"?p5 : P | P <-> P" |
|
648 |
"?p6 : (P | Q) | R <-> P | (Q | R)" |
|
649 |
apply (tactic {* IntPr.fast_tac 1 *})+ |
|
650 |
done |
|
651 |
||
36319 | 652 |
schematic_lemma not_rews: |
26322 | 653 |
"?p1 : ~ False <-> True" |
654 |
"?p2 : ~ True <-> False" |
|
655 |
apply (tactic {* IntPr.fast_tac 1 *})+ |
|
656 |
done |
|
657 |
||
36319 | 658 |
schematic_lemma imp_rews: |
26322 | 659 |
"?p1 : (P --> False) <-> ~P" |
660 |
"?p2 : (P --> True) <-> True" |
|
661 |
"?p3 : (False --> P) <-> True" |
|
662 |
"?p4 : (True --> P) <-> P" |
|
663 |
"?p5 : (P --> P) <-> True" |
|
664 |
"?p6 : (P --> ~P) <-> ~P" |
|
665 |
apply (tactic {* IntPr.fast_tac 1 *})+ |
|
666 |
done |
|
667 |
||
36319 | 668 |
schematic_lemma iff_rews: |
26322 | 669 |
"?p1 : (True <-> P) <-> P" |
670 |
"?p2 : (P <-> True) <-> P" |
|
671 |
"?p3 : (P <-> P) <-> True" |
|
672 |
"?p4 : (False <-> P) <-> ~P" |
|
673 |
"?p5 : (P <-> False) <-> ~P" |
|
674 |
apply (tactic {* IntPr.fast_tac 1 *})+ |
|
675 |
done |
|
676 |
||
36319 | 677 |
schematic_lemma quant_rews: |
26322 | 678 |
"?p1 : (ALL x. P) <-> P" |
679 |
"?p2 : (EX x. P) <-> P" |
|
680 |
apply (tactic {* IntPr.fast_tac 1 *})+ |
|
681 |
done |
|
682 |
||
683 |
(*These are NOT supplied by default!*) |
|
36319 | 684 |
schematic_lemma distrib_rews1: |
26322 | 685 |
"?p1 : ~(P|Q) <-> ~P & ~Q" |
686 |
"?p2 : P & (Q | R) <-> P&Q | P&R" |
|
687 |
"?p3 : (Q | R) & P <-> Q&P | R&P" |
|
688 |
"?p4 : (P | Q --> R) <-> (P --> R) & (Q --> R)" |
|
689 |
apply (tactic {* IntPr.fast_tac 1 *})+ |
|
690 |
done |
|
691 |
||
36319 | 692 |
schematic_lemma distrib_rews2: |
26322 | 693 |
"?p1 : ~(EX x. NORM(P(x))) <-> (ALL x. ~NORM(P(x)))" |
694 |
"?p2 : ((EX x. NORM(P(x))) --> Q) <-> (ALL x. NORM(P(x)) --> Q)" |
|
695 |
"?p3 : (EX x. NORM(P(x))) & NORM(Q) <-> (EX x. NORM(P(x)) & NORM(Q))" |
|
696 |
"?p4 : NORM(Q) & (EX x. NORM(P(x))) <-> (EX x. NORM(Q) & NORM(P(x)))" |
|
697 |
apply (tactic {* IntPr.fast_tac 1 *})+ |
|
698 |
done |
|
699 |
||
700 |
lemmas distrib_rews = distrib_rews1 distrib_rews2 |
|
701 |
||
36319 | 702 |
schematic_lemma P_Imp_P_iff_T: "p:P ==> ?p:(P <-> True)" |
26322 | 703 |
apply (tactic {* IntPr.fast_tac 1 *}) |
704 |
done |
|
705 |
||
36319 | 706 |
schematic_lemma not_P_imp_P_iff_F: "p:~P ==> ?p:(P <-> False)" |
26322 | 707 |
apply (tactic {* IntPr.fast_tac 1 *}) |
708 |
done |
|
0 | 709 |
|
710 |
end |