author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Wed, 04 Nov 2009 16:10:39 +0100 | |
changeset 284 | 78bc4d9d7975 |
parent 283 | 5470176d6730 |
child 285 | 8ebdef196fd5 |
permissions | -rw-r--r-- |
0 | 1 |
theory QuotMain |
6 | 2 |
imports QuotScript QuotList Prove |
264
d0581fbc096c
split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
263
diff
changeset
|
3 |
uses ("quotient_info.ML") |
d0581fbc096c
split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
263
diff
changeset
|
4 |
("quotient.ML") |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
5 |
("quotient_def.ML") |
0 | 6 |
begin |
7 |
||
8 |
locale QUOT_TYPE = |
|
9 |
fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
|
10 |
and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b" |
|
11 |
and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)" |
|
12 |
assumes equiv: "EQUIV R" |
|
13 |
and rep_prop: "\<And>y. \<exists>x. Rep y = R x" |
|
14 |
and rep_inverse: "\<And>x. Abs (Rep x) = x" |
|
15 |
and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)" |
|
16 |
and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)" |
|
15 | 17 |
begin |
0 | 18 |
|
19 |
definition |
|
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
20 |
ABS::"'a \<Rightarrow> 'b" |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
21 |
where |
0 | 22 |
"ABS x \<equiv> Abs (R x)" |
23 |
||
24 |
definition |
|
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
25 |
REP::"'b \<Rightarrow> 'a" |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
26 |
where |
0 | 27 |
"REP a = Eps (Rep a)" |
28 |
||
15 | 29 |
lemma lem9: |
0 | 30 |
shows "R (Eps (R x)) = R x" |
31 |
proof - |
|
32 |
have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def) |
|
33 |
then have "R x (Eps (R x))" by (rule someI) |
|
15 | 34 |
then show "R (Eps (R x)) = R x" |
0 | 35 |
using equiv unfolding EQUIV_def by simp |
36 |
qed |
|
37 |
||
38 |
theorem thm10: |
|
24
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
39 |
shows "ABS (REP a) \<equiv> a" |
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
40 |
apply (rule eq_reflection) |
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
41 |
unfolding ABS_def REP_def |
0 | 42 |
proof - |
15 | 43 |
from rep_prop |
0 | 44 |
obtain x where eq: "Rep a = R x" by auto |
45 |
have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp |
|
46 |
also have "\<dots> = Abs (R x)" using lem9 by simp |
|
47 |
also have "\<dots> = Abs (Rep a)" using eq by simp |
|
48 |
also have "\<dots> = a" using rep_inverse by simp |
|
49 |
finally |
|
50 |
show "Abs (R (Eps (Rep a))) = a" by simp |
|
51 |
qed |
|
52 |
||
15 | 53 |
lemma REP_refl: |
0 | 54 |
shows "R (REP a) (REP a)" |
55 |
unfolding REP_def |
|
56 |
by (simp add: equiv[simplified EQUIV_def]) |
|
57 |
||
58 |
lemma lem7: |
|
22 | 59 |
shows "(R x = R y) = (Abs (R x) = Abs (R y))" |
0 | 60 |
apply(rule iffI) |
61 |
apply(simp) |
|
62 |
apply(drule rep_inject[THEN iffD2]) |
|
63 |
apply(simp add: abs_inverse) |
|
64 |
done |
|
15 | 65 |
|
0 | 66 |
theorem thm11: |
67 |
shows "R r r' = (ABS r = ABS r')" |
|
68 |
unfolding ABS_def |
|
69 |
by (simp only: equiv[simplified EQUIV_def] lem7) |
|
70 |
||
4 | 71 |
|
2 | 72 |
lemma REP_ABS_rsp: |
4 | 73 |
shows "R f (REP (ABS g)) = R f g" |
74 |
and "R (REP (ABS g)) f = R g f" |
|
23 | 75 |
by (simp_all add: thm10 thm11) |
4 | 76 |
|
0 | 77 |
lemma QUOTIENT: |
78 |
"QUOTIENT R ABS REP" |
|
79 |
apply(unfold QUOTIENT_def) |
|
80 |
apply(simp add: thm10) |
|
81 |
apply(simp add: REP_refl) |
|
82 |
apply(subst thm11[symmetric]) |
|
83 |
apply(simp add: equiv[simplified EQUIV_def]) |
|
84 |
done |
|
85 |
||
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
86 |
lemma R_trans: |
49 | 87 |
assumes ab: "R a b" |
88 |
and bc: "R b c" |
|
22 | 89 |
shows "R a c" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
90 |
proof - |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
91 |
have tr: "TRANS R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
92 |
moreover have ab: "R a b" by fact |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
93 |
moreover have bc: "R b c" by fact |
22 | 94 |
ultimately show "R a c" unfolding TRANS_def by blast |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
95 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
96 |
|
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
97 |
lemma R_sym: |
49 | 98 |
assumes ab: "R a b" |
22 | 99 |
shows "R b a" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
100 |
proof - |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
101 |
have re: "SYM R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
22 | 102 |
then show "R b a" using ab unfolding SYM_def by blast |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
103 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
104 |
|
49 | 105 |
lemma R_trans2: |
106 |
assumes ac: "R a c" |
|
22 | 107 |
and bd: "R b d" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
108 |
shows "R a b = R c d" |
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
109 |
using ac bd |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
110 |
by (blast intro: R_trans R_sym) |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
111 |
|
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
112 |
lemma REPS_same: |
25
9020ee23a020
The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
24
diff
changeset
|
113 |
shows "R (REP a) (REP b) \<equiv> (a = b)" |
38 | 114 |
proof - |
115 |
have "R (REP a) (REP b) = (a = b)" |
|
116 |
proof |
|
117 |
assume as: "R (REP a) (REP b)" |
|
118 |
from rep_prop |
|
119 |
obtain x y |
|
120 |
where eqs: "Rep a = R x" "Rep b = R y" by blast |
|
121 |
from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp |
|
122 |
then have "R x (Eps (R y))" using lem9 by simp |
|
123 |
then have "R (Eps (R y)) x" using R_sym by blast |
|
124 |
then have "R y x" using lem9 by simp |
|
125 |
then have "R x y" using R_sym by blast |
|
126 |
then have "ABS x = ABS y" using thm11 by simp |
|
127 |
then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp |
|
128 |
then show "a = b" using rep_inverse by simp |
|
129 |
next |
|
130 |
assume ab: "a = b" |
|
131 |
have "REFL R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
|
132 |
then show "R (REP a) (REP b)" unfolding REFL_def using ab by auto |
|
133 |
qed |
|
134 |
then show "R (REP a) (REP b) \<equiv> (a = b)" by simp |
|
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
135 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
136 |
|
0 | 137 |
end |
138 |
||
127
b054cf6bd179
the command "quotient" can now define more than one quotient at the same time; quotients need to be separated by and
Christian Urban <urbanc@in.tum.de>
parents:
126
diff
changeset
|
139 |
|
0 | 140 |
section {* type definition for the quotient type *} |
141 |
||
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
142 |
(* the auxiliary data for the quotient types *) |
264
d0581fbc096c
split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
263
diff
changeset
|
143 |
use "quotient_info.ML" |
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
144 |
|
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
145 |
declare [[map list = (map, LIST_REL)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
146 |
declare [[map * = (prod_fun, prod_rel)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
147 |
declare [[map "fun" = (fun_map, FUN_REL)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
148 |
|
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
149 |
ML {* maps_lookup @{theory} "List.list" *} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
150 |
ML {* maps_lookup @{theory} "*" *} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
151 |
ML {* maps_lookup @{theory} "fun" *} |
174
09048a951dca
moved the map_funs setup into QuotMain
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
152 |
|
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
153 |
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
154 |
(* definition of the quotient types *) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
155 |
(* FIXME: should be called quotient_typ.ML *) |
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
156 |
use "quotient.ML" |
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
157 |
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
158 |
|
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
159 |
(* lifting of constants *) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
160 |
use "quotient_def.ML" |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
161 |
|
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
162 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
163 |
text {* FIXME: auxiliary function *} |
193 | 164 |
ML {* |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
165 |
val no_vars = Thm.rule_attribute (fn context => fn th => |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
166 |
let |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
167 |
val ctxt = Variable.set_body false (Context.proof_of context); |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
168 |
val ((_, [th']), _) = Variable.import true [th] ctxt; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
169 |
in th' end); |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
170 |
*} |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
171 |
|
139 | 172 |
section {* ATOMIZE *} |
173 |
||
174 |
text {* |
|
175 |
Unabs_def converts a definition given as |
|
176 |
||
177 |
c \<equiv> %x. %y. f x y |
|
178 |
||
179 |
to a theorem of the form |
|
180 |
||
181 |
c x y \<equiv> f x y |
|
182 |
||
183 |
This function is needed to rewrite the right-hand |
|
184 |
side to the left-hand side. |
|
185 |
*} |
|
186 |
||
187 |
ML {* |
|
188 |
fun unabs_def ctxt def = |
|
189 |
let |
|
190 |
val (lhs, rhs) = Thm.dest_equals (cprop_of def) |
|
191 |
val xs = strip_abs_vars (term_of rhs) |
|
192 |
val (_, ctxt') = Variable.add_fixes (map fst xs) ctxt |
|
193 |
||
194 |
val thy = ProofContext.theory_of ctxt' |
|
195 |
val cxs = map (cterm_of thy o Free) xs |
|
196 |
val new_lhs = Drule.list_comb (lhs, cxs) |
|
197 |
||
198 |
fun get_conv [] = Conv.rewr_conv def |
|
199 |
| get_conv (x::xs) = Conv.fun_conv (get_conv xs) |
|
200 |
in |
|
201 |
get_conv xs new_lhs |> |
|
202 |
singleton (ProofContext.export ctxt' ctxt) |
|
203 |
end |
|
204 |
*} |
|
205 |
||
206 |
lemma atomize_eqv[atomize]: |
|
207 |
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" |
|
208 |
proof |
|
209 |
assume "A \<equiv> B" |
|
210 |
then show "Trueprop A \<equiv> Trueprop B" by unfold |
|
211 |
next |
|
212 |
assume *: "Trueprop A \<equiv> Trueprop B" |
|
213 |
have "A = B" |
|
214 |
proof (cases A) |
|
215 |
case True |
|
216 |
have "A" by fact |
|
217 |
then show "A = B" using * by simp |
|
218 |
next |
|
219 |
case False |
|
220 |
have "\<not>A" by fact |
|
221 |
then show "A = B" using * by auto |
|
222 |
qed |
|
223 |
then show "A \<equiv> B" by (rule eq_reflection) |
|
224 |
qed |
|
225 |
||
226 |
ML {* |
|
227 |
fun atomize_thm thm = |
|
228 |
let |
|
221 | 229 |
val thm' = Thm.freezeT (forall_intr_vars thm) |
139 | 230 |
val thm'' = ObjectLogic.atomize (cprop_of thm') |
231 |
in |
|
221 | 232 |
@{thm Pure.equal_elim_rule1} OF [thm'', thm'] |
139 | 233 |
end |
234 |
*} |
|
235 |
||
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
236 |
ML {* atomize_thm @{thm list.induct} *} |
139 | 237 |
|
238 |
section {* REGULARIZE *} |
|
282
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
239 |
(* |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
240 |
|
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
241 |
Regularizing a theorem means: |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
242 |
- Quantifiers over a type that needs lifting are replaced by |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
243 |
bounded quantifiers, for example: |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
244 |
\<forall>x. P \<Longrightarrow> \<forall>x\<in>(Respects R). P |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
245 |
- Abstractions over a type that needs lifting are replaced |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
246 |
by bounded abstactions: |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
247 |
\<lambda>x. P \<Longrightarrow> Ball (Respects R) (\<lambda>x. P) |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
248 |
|
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
249 |
- Equalities over the type being lifted are replaced by |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
250 |
appropriate relations: |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
251 |
A = B \<Longrightarrow> A \<approx> B |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
252 |
Example with more complicated types of A, B: |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
253 |
A = B \<Longrightarrow> (op = \<Longrightarrow> op \<approx>) A B |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
254 |
|
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
255 |
Regularizing is done in 3 phases: |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
256 |
- First a regularized term is created |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
257 |
- Next we prove that the original theorem implies the new one |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
258 |
- Finally using MP we get the new theorem. |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
259 |
|
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
260 |
To prove that the old theorem implies the new one, we first |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
261 |
atomize it and then try: |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
262 |
- Reflexivity of the relation |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
263 |
- Assumption |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
264 |
- Elimnating quantifiers on both sides of toplevel implication |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
265 |
- Simplifying implications on both sides of toplevel implication |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
266 |
- Ball (Respects ?E) ?P = All ?P |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
267 |
- (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q |
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
268 |
|
e9212a4a44be
Description of regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
277
diff
changeset
|
269 |
*) |
139 | 270 |
|
271 |
text {* tyRel takes a type and builds a relation that a quantifier over this |
|
272 |
type needs to respect. *} |
|
273 |
ML {* |
|
257
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
274 |
fun matches (ty1, ty2) = |
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
275 |
Type.raw_instance (ty1, Logic.varifyT ty2); |
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
276 |
|
139 | 277 |
fun tyRel ty rty rel lthy = |
257
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
278 |
if matches (rty, ty) |
139 | 279 |
then rel |
280 |
else (case ty of |
|
281 |
Type (s, tys) => |
|
282 |
let |
|
283 |
val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys; |
|
284 |
val ty_out = ty --> ty --> @{typ bool}; |
|
285 |
val tys_out = tys_rel ---> ty_out; |
|
286 |
in |
|
287 |
(case (maps_lookup (ProofContext.theory_of lthy) s) of |
|
288 |
SOME (info) => list_comb (Const (#relfun info, tys_out), map (fn ty => tyRel ty rty rel lthy) tys) |
|
289 |
| NONE => HOLogic.eq_const ty |
|
290 |
) |
|
291 |
end |
|
292 |
| _ => HOLogic.eq_const ty) |
|
293 |
*} |
|
294 |
||
295 |
definition |
|
296 |
Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" |
|
297 |
where |
|
298 |
"(x \<in> p) \<Longrightarrow> (Babs p m x = m x)" |
|
299 |
(* TODO: Consider defining it with an "if"; sth like: |
|
300 |
Babs p m = \<lambda>x. if x \<in> p then m x else undefined |
|
301 |
*) |
|
302 |
||
303 |
ML {* |
|
304 |
fun needs_lift (rty as Type (rty_s, _)) ty = |
|
305 |
case ty of |
|
306 |
Type (s, tys) => |
|
307 |
(s = rty_s) orelse (exists (needs_lift rty) tys) |
|
308 |
| _ => false |
|
309 |
||
310 |
*} |
|
311 |
||
312 |
ML {* |
|
313 |
fun mk_babs ty ty' = Const (@{const_name "Babs"}, [ty' --> @{typ bool}, ty] ---> ty) |
|
314 |
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool}) |
|
315 |
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool}) |
|
316 |
fun mk_resp ty = Const (@{const_name Respects}, [[ty, ty] ---> @{typ bool}, ty] ---> @{typ bool}) |
|
317 |
*} |
|
318 |
||
319 |
(* applies f to the subterm of an abstractions, otherwise to the given term *) |
|
320 |
ML {* |
|
321 |
fun apply_subt f trm = |
|
322 |
case trm of |
|
145 | 323 |
Abs (x, T, t) => |
324 |
let |
|
325 |
val (x', t') = Term.dest_abs (x, T, t) |
|
326 |
in |
|
327 |
Term.absfree (x', T, f t') |
|
328 |
end |
|
139 | 329 |
| _ => f trm |
330 |
*} |
|
331 |
||
332 |
(* FIXME: if there are more than one quotient, then you have to look up the relation *) |
|
333 |
ML {* |
|
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
334 |
fun my_reg lthy rel rty trm = |
139 | 335 |
case trm of |
336 |
Abs (x, T, t) => |
|
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
337 |
if (needs_lift rty T) then |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
338 |
let |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
339 |
val rrel = tyRel T rty rel lthy |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
340 |
in |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
341 |
(mk_babs (fastype_of trm) T) $ (mk_resp T $ rrel) $ (apply_subt (my_reg lthy rel rty) trm) |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
342 |
end |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
343 |
else |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
344 |
Abs(x, T, (apply_subt (my_reg lthy rel rty) t)) |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
345 |
| Const (@{const_name "All"}, ty) $ (t as Abs (x, T, _)) => |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
346 |
let |
139 | 347 |
val ty1 = domain_type ty |
348 |
val ty2 = domain_type ty1 |
|
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
349 |
val rrel = tyRel T rty rel lthy |
139 | 350 |
in |
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
351 |
if (needs_lift rty T) then |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
352 |
(mk_ball ty1) $ (mk_resp ty2 $ rrel) $ (apply_subt (my_reg lthy rel rty) t) |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
353 |
else |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
354 |
Const (@{const_name "All"}, ty) $ apply_subt (my_reg lthy rel rty) t |
139 | 355 |
end |
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
356 |
| Const (@{const_name "Ex"}, ty) $ (t as Abs (x, T, _)) => |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
357 |
let |
139 | 358 |
val ty1 = domain_type ty |
359 |
val ty2 = domain_type ty1 |
|
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
360 |
val rrel = tyRel T rty rel lthy |
139 | 361 |
in |
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
362 |
if (needs_lift rty T) then |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
363 |
(mk_bex ty1) $ (mk_resp ty2 $ rrel) $ (apply_subt (my_reg lthy rel rty) t) |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
364 |
else |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
365 |
Const (@{const_name "Ex"}, ty) $ apply_subt (my_reg lthy rel rty) t |
139 | 366 |
end |
251 | 367 |
| Const (@{const_name "op ="}, ty) $ t => |
368 |
if needs_lift rty (fastype_of t) then |
|
369 |
(tyRel (fastype_of t) rty rel lthy) $ t |
|
370 |
else Const (@{const_name "op ="}, ty) $ (my_reg lthy rel rty t) |
|
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
371 |
| t1 $ t2 => (my_reg lthy rel rty t1) $ (my_reg lthy rel rty t2) |
139 | 372 |
| _ => trm |
373 |
*} |
|
374 |
||
283
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
375 |
ML {* |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
376 |
fun my_reg_inst lthy rel rty trm = |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
377 |
case rel of |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
378 |
Const (n, _) => Syntax.check_term lthy |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
379 |
(my_reg lthy (Const (n, dummyT)) rty trm) |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
380 |
*} |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
381 |
|
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
382 |
(*ML {* |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
383 |
(*val r = term_of @{cpat "R::?'a list \<Rightarrow> ?'a list \<Rightarrow>bool"};*) |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
384 |
val r = Free ("R", dummyT); |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
385 |
val t = (my_reg @{context} r @{typ "'a list"} @{term "\<forall>(x::'b list). P x"}); |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
386 |
val t2 = Syntax.check_term @{context} t; |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
387 |
Toplevel.program (fn () => cterm_of @{theory} t2) |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
388 |
*}*) |
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
389 |
|
141
0ffc37761e53
Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
140
diff
changeset
|
390 |
text {* Assumes that the given theorem is atomized *} |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
391 |
ML {* |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
392 |
fun build_regularize_goal thm rty rel lthy = |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
393 |
Logic.mk_implies |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
394 |
((prop_of thm), |
283
5470176d6730
Type instantiation in regularize
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
282
diff
changeset
|
395 |
(my_reg_inst lthy rel rty (prop_of thm))) |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
396 |
*} |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
397 |
|
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
398 |
lemma universal_twice: |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
399 |
"(\<And>x. (P x \<longrightarrow> Q x)) \<Longrightarrow> ((\<forall>x. P x) \<longrightarrow> (\<forall>x. Q x))" |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
400 |
by auto |
252
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
401 |
|
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
402 |
lemma implication_twice: |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
403 |
"(c \<longrightarrow> a) \<Longrightarrow> (a \<Longrightarrow> b \<longrightarrow> d) \<Longrightarrow> (a \<longrightarrow> b) \<longrightarrow> (c \<longrightarrow> d)" |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
404 |
by auto |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
405 |
|
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
406 |
(*lemma equality_twice: "a = c \<Longrightarrow> b = d \<Longrightarrow> (a = b \<longrightarrow> c = d)" |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
407 |
by auto*) |
251 | 408 |
|
187 | 409 |
ML {* |
251 | 410 |
fun regularize thm rty rel rel_eqv rel_refl lthy = |
187 | 411 |
let |
412 |
val g = build_regularize_goal thm rty rel lthy; |
|
413 |
fun tac ctxt = |
|
252
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
414 |
(ObjectLogic.full_atomize_tac) THEN' |
251 | 415 |
REPEAT_ALL_NEW (FIRST' [ |
416 |
rtac rel_refl, |
|
417 |
atac, |
|
252
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
418 |
rtac @{thm universal_twice}, |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
419 |
(rtac @{thm impI} THEN' atac), |
252
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
420 |
rtac @{thm implication_twice}, |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
421 |
(*rtac @{thm equality_twice},*) |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
422 |
EqSubst.eqsubst_tac ctxt [0] |
187 | 423 |
[(@{thm equiv_res_forall} OF [rel_eqv]), |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
424 |
(@{thm equiv_res_exists} OF [rel_eqv])], |
252
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
425 |
(rtac @{thm impI} THEN' (asm_full_simp_tac (Simplifier.context ctxt HOL_ss)) THEN' rtac rel_refl), |
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
426 |
(rtac @{thm RIGHT_RES_FORALL_REGULAR}) |
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
427 |
]); |
187 | 428 |
val cthm = Goal.prove lthy [] [] g (fn x => tac (#context x) 1); |
429 |
in |
|
430 |
cthm OF [thm] |
|
431 |
end |
|
432 |
*} |
|
433 |
||
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
434 |
section {* RepAbs injection *} |
139 | 435 |
|
161
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
436 |
(* Needed to have a meta-equality *) |
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
437 |
lemma id_def_sym: "(\<lambda>x. x) \<equiv> id" |
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
438 |
by (simp add: id_def) |
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
439 |
|
139 | 440 |
ML {* |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
441 |
fun old_exchange_ty rty qty ty = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
442 |
if ty = rty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
443 |
then qty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
444 |
else |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
445 |
(case ty of |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
446 |
Type (s, tys) => Type (s, map (old_exchange_ty rty qty) tys) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
447 |
| _ => ty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
448 |
) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
449 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
450 |
|
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
451 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
452 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
453 |
fun old_get_fun flag rty qty lthy ty = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
454 |
get_fun flag [(qty, rty)] lthy ty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
455 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
456 |
fun old_make_const_def nconst_bname otrm mx rty qty lthy = |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
457 |
make_def nconst_bname otrm qty mx Attrib.empty_binding [(qty, rty)] lthy |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
458 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
459 |
|
235
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
460 |
text {* Does the same as 'subst' in a given prop or theorem *} |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
461 |
ML {* |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
462 |
fun eqsubst_prop ctxt thms t = |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
463 |
let |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
464 |
val goalstate = Goal.init (cterm_of (ProofContext.theory_of ctxt) t) |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
465 |
val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
466 |
NONE => error "eqsubst_prop" |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
467 |
| SOME th => cprem_of th 1 |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
468 |
in term_of a' end |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
469 |
*} |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
470 |
|
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
471 |
ML {* |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
472 |
fun repeat_eqsubst_prop ctxt thms t = |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
473 |
repeat_eqsubst_prop ctxt thms (eqsubst_prop ctxt thms t) |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
474 |
handle _ => t |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
475 |
*} |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
476 |
|
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
477 |
|
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
478 |
ML {* |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
479 |
fun eqsubst_thm ctxt thms thm = |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
480 |
let |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
481 |
val goalstate = Goal.init (Thm.cprop_of thm) |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
482 |
val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
483 |
NONE => error "eqsubst_thm" |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
484 |
| SOME th => cprem_of th 1 |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
485 |
val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1 |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
486 |
val cgoal = cterm_of (ProofContext.theory_of ctxt) (Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a')) |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
487 |
val rt = Toplevel.program (fn () => Goal.prove_internal [] cgoal (fn _ => tac)); |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
488 |
in |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
489 |
@{thm Pure.equal_elim_rule1} OF [rt,thm] |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
490 |
end |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
491 |
*} |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
492 |
|
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
493 |
ML {* |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
494 |
fun repeat_eqsubst_thm ctxt thms thm = |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
495 |
repeat_eqsubst_thm ctxt thms (eqsubst_thm ctxt thms thm) |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
496 |
handle _ => thm |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
497 |
*} |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
498 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
499 |
ML {* |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
500 |
fun build_repabs_term lthy thm constructors rty qty = |
139 | 501 |
let |
502 |
fun mk_rep tm = |
|
503 |
let |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
504 |
val ty = old_exchange_ty rty qty (fastype_of tm) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
505 |
in fst (old_get_fun repF rty qty lthy ty) $ tm end |
139 | 506 |
|
507 |
fun mk_abs tm = |
|
508 |
let |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
509 |
val ty = old_exchange_ty rty qty (fastype_of tm) in |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
510 |
fst (old_get_fun absF rty qty lthy ty) $ tm end |
139 | 511 |
|
512 |
fun is_constructor (Const (x, _)) = member (op =) constructors x |
|
513 |
| is_constructor _ = false; |
|
514 |
||
515 |
fun build_aux lthy tm = |
|
516 |
case tm of |
|
517 |
Abs (a as (_, vty, _)) => |
|
518 |
let |
|
519 |
val (vs, t) = Term.dest_abs a; |
|
520 |
val v = Free(vs, vty); |
|
521 |
val t' = lambda v (build_aux lthy t) |
|
522 |
in |
|
523 |
if (not (needs_lift rty (fastype_of tm))) then t' |
|
524 |
else mk_rep (mk_abs ( |
|
525 |
if not (needs_lift rty vty) then t' |
|
526 |
else |
|
527 |
let |
|
528 |
val v' = mk_rep (mk_abs v); |
|
529 |
val t1 = Envir.beta_norm (t' $ v') |
|
530 |
in |
|
531 |
lambda v t1 |
|
532 |
end |
|
533 |
)) |
|
534 |
end |
|
535 |
| x => |
|
536 |
let |
|
537 |
val (opp, tms0) = Term.strip_comb tm |
|
538 |
val tms = map (build_aux lthy) tms0 |
|
539 |
val ty = fastype_of tm |
|
540 |
in |
|
541 |
if (((fst (Term.dest_Const opp)) = @{const_name Respects}) handle _ => false) |
|
542 |
then (list_comb (opp, (hd tms0) :: (tl tms))) |
|
543 |
else if (is_constructor opp andalso needs_lift rty ty) then |
|
544 |
mk_rep (mk_abs (list_comb (opp,tms))) |
|
545 |
else if ((Term.is_Free opp) andalso (length tms > 0) andalso (needs_lift rty ty)) then |
|
149
7cf1d7adfc5f
Removed some debugging messages
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
148
diff
changeset
|
546 |
mk_rep(mk_abs(list_comb(opp,tms))) |
139 | 547 |
else if tms = [] then opp |
548 |
else list_comb(opp, tms) |
|
549 |
end |
|
550 |
in |
|
235
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
551 |
repeat_eqsubst_prop lthy @{thms id_def_sym} |
161
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
552 |
(build_aux lthy (Thm.prop_of thm)) |
139 | 553 |
end |
554 |
*} |
|
555 |
||
141
0ffc37761e53
Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
140
diff
changeset
|
556 |
text {* Assumes that it is given a regularized theorem *} |
139 | 557 |
ML {* |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
558 |
fun build_repabs_goal ctxt thm cons rty qty = |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
559 |
Logic.mk_equals ((Thm.prop_of thm), (build_repabs_term ctxt thm cons rty qty)) |
139 | 560 |
*} |
561 |
||
187 | 562 |
ML {* |
563 |
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} => |
|
564 |
let |
|
565 |
val pat = Drule.strip_imp_concl (cprop_of thm) |
|
566 |
val insts = Thm.match (pat, concl) |
|
567 |
in |
|
568 |
rtac (Drule.instantiate insts thm) 1 |
|
152
53277fbb2dba
Simplified the proof with some tactic... Still hangs sometimes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
151
diff
changeset
|
569 |
end |
187 | 570 |
handle _ => no_tac |
571 |
) |
|
572 |
*} |
|
573 |
||
574 |
||
575 |
||
576 |
ML {* |
|
577 |
fun quotient_tac quot_thm = |
|
578 |
REPEAT_ALL_NEW (FIRST' [ |
|
579 |
rtac @{thm FUN_QUOTIENT}, |
|
580 |
rtac quot_thm, |
|
581 |
rtac @{thm IDENTITY_QUOTIENT} |
|
582 |
]) |
|
583 |
*} |
|
584 |
||
585 |
ML {* |
|
586 |
fun LAMBDA_RES_TAC ctxt i st = |
|
587 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
588 |
(_ $ (_ $ (Abs(_,_,_))$(Abs(_,_,_)))) => |
|
589 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
590 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
591 |
| _ => fn _ => no_tac) i st |
|
592 |
*} |
|
593 |
||
594 |
ML {* |
|
595 |
fun WEAK_LAMBDA_RES_TAC ctxt i st = |
|
596 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
597 |
(_ $ (_ $ _$(Abs(_,_,_)))) => |
|
598 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
599 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
600 |
| (_ $ (_ $ (Abs(_,_,_))$_)) => |
|
601 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
602 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
603 |
| _ => fn _ => no_tac) i st |
|
604 |
*} |
|
605 |
||
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
606 |
ML {* |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
607 |
fun APPLY_RSP_TAC rty = Subgoal.FOCUS (fn {concl, ...} => |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
608 |
let |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
609 |
val (_ $ (R $ (f $ _) $ (_ $ _))) = term_of concl; |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
610 |
val pat = Drule.strip_imp_concl (cprop_of @{thm APPLY_RSP}); |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
611 |
val insts = Thm.match (pat, concl) |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
612 |
in |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
613 |
if needs_lift rty (type_of f) then |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
614 |
rtac (Drule.instantiate insts @{thm APPLY_RSP}) 1 |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
615 |
else no_tac |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
616 |
end |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
617 |
handle _ => no_tac) |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
618 |
*} |
187 | 619 |
|
620 |
ML {* |
|
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
621 |
val res_forall_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} => |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
622 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
623 |
val _ $ (_ $ (Const (@{const_name Ball}, _) $ _) $ (Const (@{const_name Ball}, _) $ _)) = term_of concl |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
624 |
in |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
625 |
((simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
626 |
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
627 |
THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN' |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
628 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))) 1 |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
629 |
end |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
630 |
handle _ => no_tac |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
631 |
) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
632 |
*} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
633 |
|
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
634 |
ML {* |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
635 |
val res_exists_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} => |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
636 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
637 |
val _ $ (_ $ (Const (@{const_name Bex}, _) $ _) $ (Const (@{const_name Bex}, _) $ _)) = term_of concl |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
638 |
in |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
639 |
((simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
640 |
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
641 |
THEN' instantiate_tac @{thm RES_EXISTS_RSP} ctxt THEN' |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
642 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))) 1 |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
643 |
end |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
644 |
handle _ => no_tac |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
645 |
) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
646 |
*} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
647 |
|
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
648 |
ML {* |
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
649 |
fun r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms = |
187 | 650 |
(FIRST' [ |
259 | 651 |
(* rtac @{thm FUN_QUOTIENT}, |
187 | 652 |
rtac quot_thm, |
259 | 653 |
rtac @{thm IDENTITY_QUOTIENT},*) |
187 | 654 |
rtac trans_thm, |
655 |
LAMBDA_RES_TAC ctxt, |
|
656 |
res_forall_rsp_tac ctxt, |
|
657 |
res_exists_rsp_tac ctxt, |
|
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
658 |
FIRST' (map rtac rsp_thms), |
187 | 659 |
(instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' (RANGE [quotient_tac quot_thm])), |
660 |
rtac refl, |
|
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
661 |
(* rtac @{thm arg_cong2[of _ _ _ _ "op ="]},*) |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
662 |
(APPLY_RSP_TAC rty ctxt THEN' (RANGE [quotient_tac quot_thm, quotient_tac quot_thm])), |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
663 |
Cong_Tac.cong_tac @{thm cong}, |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
664 |
rtac @{thm ext}, |
187 | 665 |
rtac reflex_thm, |
666 |
atac, |
|
667 |
( |
|
668 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
669 |
THEN_ALL_NEW (fn _ => no_tac) |
|
670 |
), |
|
671 |
WEAK_LAMBDA_RES_TAC ctxt |
|
672 |
]) |
|
673 |
*} |
|
674 |
||
190
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
675 |
ML {* |
210
f88ea69331bf
Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
209
diff
changeset
|
676 |
fun repabs lthy thm constructors rty qty quot_thm reflex_thm trans_thm rsp_thms = |
190
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
677 |
let |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
678 |
val rt = build_repabs_term lthy thm constructors rty qty; |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
679 |
val rg = Logic.mk_equals ((Thm.prop_of thm), rt); |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
680 |
fun tac ctxt = (ObjectLogic.full_atomize_tac) THEN' |
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
681 |
(REPEAT_ALL_NEW (r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms)); |
190
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
682 |
val cthm = Goal.prove lthy [] [] rg (fn x => tac (#context x) 1); |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
683 |
in |
210
f88ea69331bf
Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
209
diff
changeset
|
684 |
@{thm Pure.equal_elim_rule1} OF [cthm, thm] |
190
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
685 |
end |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
686 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
687 |
|
187 | 688 |
section {* Cleaning the goal *} |
689 |
||
236
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
690 |
lemma prod_fun_id: "prod_fun id id = id" |
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
691 |
apply (simp add: prod_fun_def) |
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
692 |
done |
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
693 |
lemma map_id: "map id x = x" |
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
694 |
apply (induct x) |
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
695 |
apply (simp_all add: map.simps) |
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
696 |
done |
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
697 |
|
190
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
698 |
text {* expects atomized definition *} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
699 |
ML {* |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
700 |
fun add_lower_defs_aux ctxt thm = |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
701 |
let |
209
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
702 |
val e1 = @{thm fun_cong} OF [thm]; |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
703 |
val f = eqsubst_thm ctxt @{thms fun_map.simps} e1; |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
704 |
val g = MetaSimplifier.rewrite_rule @{thms id_def_sym} f; |
236
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
705 |
val h = repeat_eqsubst_thm ctxt @{thms FUN_MAP_I id_apply prod_fun_id map_id} g |
190
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
706 |
in |
236
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
707 |
thm :: (add_lower_defs_aux ctxt h) |
190
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
708 |
end |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
709 |
handle _ => [thm] |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
710 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
711 |
|
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
712 |
ML {* |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
713 |
fun add_lower_defs ctxt defs = |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
714 |
let |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
715 |
val defs_pre_sym = map symmetric defs |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
716 |
val defs_atom = map atomize_thm defs_pre_sym |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
717 |
val defs_all = flat (map (add_lower_defs_aux ctxt) defs_atom) |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
718 |
in |
214 | 719 |
map Thm.varifyT defs_all |
190
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
720 |
end |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
721 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
722 |
|
191
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
723 |
ML {* |
241
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
724 |
fun findabs_all rty tm = |
191
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
725 |
case tm of |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
726 |
Abs(_, T, b) => |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
727 |
let |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
728 |
val b' = subst_bound ((Free ("x", T)), b); |
241
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
729 |
val tys = findabs_all rty b' |
191
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
730 |
val ty = fastype_of tm |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
731 |
in if needs_lift rty ty then (ty :: tys) else tys |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
732 |
end |
241
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
733 |
| f $ a => (findabs_all rty f) @ (findabs_all rty a) |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
734 |
| _ => []; |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
735 |
fun findabs rty tm = distinct (op =) (findabs_all rty tm) |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
736 |
*} |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
737 |
|
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
738 |
|
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
739 |
ML {* |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
740 |
fun findaps_all rty tm = |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
741 |
case tm of |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
742 |
Abs(_, T, b) => |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
743 |
findaps_all rty (subst_bound ((Free ("x", T)), b)) |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
744 |
| (f $ a) => (findaps_all rty f @ findaps_all rty a) |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
745 |
| Free (_, (T as (Type ("fun", (_ :: _))))) => (if needs_lift rty T then [T] else []) |
241
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
746 |
| _ => []; |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
747 |
fun findaps rty tm = distinct (op =) (findaps_all rty tm) |
191
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
748 |
*} |
190
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
749 |
|
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
750 |
ML {* |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
751 |
fun make_simp_prs_thm lthy quot_thm thm typ = |
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
752 |
let |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
753 |
val (_, [lty, rty]) = dest_Type typ; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
754 |
val thy = ProofContext.theory_of lthy; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
755 |
val (lcty, rcty) = (ctyp_of thy lty, ctyp_of thy rty) |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
756 |
val inst = [SOME lcty, NONE, SOME rcty]; |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
757 |
val lpi = Drule.instantiate' inst [] thm; |
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
758 |
val tac = |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
759 |
(compose_tac (false, lpi, 2)) THEN_ALL_NEW |
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
760 |
(quotient_tac quot_thm); |
259 | 761 |
val gc = Drule.strip_imp_concl (cprop_of lpi); |
762 |
val t = Goal.prove_internal [] gc (fn _ => tac 1) |
|
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
763 |
in |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
764 |
MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] t |
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
765 |
end |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
766 |
*} |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
767 |
|
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
768 |
ML {* |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
769 |
fun findallex_all rty qty tm = |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
770 |
case tm of |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
771 |
Const (@{const_name All}, T) $ (s as (Abs(_, _, b))) => |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
772 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
773 |
val (tya, tye) = findallex_all rty qty s |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
774 |
in if needs_lift rty T then |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
775 |
((T :: tya), tye) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
776 |
else (tya, tye) end |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
777 |
| Const (@{const_name Ex}, T) $ (s as (Abs(_, _, b))) => |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
778 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
779 |
val (tya, tye) = findallex_all rty qty s |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
780 |
in if needs_lift rty T then |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
781 |
(tya, (T :: tye)) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
782 |
else (tya, tye) end |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
783 |
| Abs(_, T, b) => |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
784 |
findallex_all rty qty (subst_bound ((Free ("x", T)), b)) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
785 |
| f $ a => |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
786 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
787 |
val (a1, e1) = findallex_all rty qty f; |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
788 |
val (a2, e2) = findallex_all rty qty a; |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
789 |
in (a1 @ a2, e1 @ e2) end |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
790 |
| _ => ([], []); |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
791 |
*} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
792 |
ML {* |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
793 |
fun findallex rty qty tm = |
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
794 |
let |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
795 |
val (a, e) = findallex_all rty qty tm; |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
796 |
val (ad, ed) = (map domain_type a, map domain_type e); |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
797 |
val (au, eu) = (distinct (op =) ad, distinct (op =) ed) |
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
798 |
in |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
799 |
(map (old_exchange_ty rty qty) au, map (old_exchange_ty rty qty) eu) |
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
800 |
end |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
801 |
*} |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
802 |
|
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
803 |
ML {* |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
804 |
fun make_allex_prs_thm lthy quot_thm thm typ = |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
805 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
806 |
val (_, [lty, rty]) = dest_Type typ; |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
807 |
val thy = ProofContext.theory_of lthy; |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
808 |
val (lcty, rcty) = (ctyp_of thy lty, ctyp_of thy rty) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
809 |
val inst = [NONE, SOME lcty]; |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
810 |
val lpi = Drule.instantiate' inst [] thm; |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
811 |
val tac = |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
812 |
(compose_tac (false, lpi, 1)) THEN_ALL_NEW |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
813 |
(quotient_tac quot_thm); |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
814 |
val gc = Drule.strip_imp_concl (cprop_of lpi); |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
815 |
val t = Goal.prove_internal [] gc (fn _ => tac 1) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
816 |
val t_noid = MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] t; |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
817 |
val t_sym = @{thm "HOL.sym"} OF [t_noid]; |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
818 |
val t_eq = @{thm "eq_reflection"} OF [t_sym] |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
819 |
in |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
820 |
t_eq |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
821 |
end |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
822 |
*} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
823 |
|
269 | 824 |
ML {* |
825 |
fun applic_prs lthy rty qty absrep ty = |
|
826 |
let |
|
827 |
fun absty ty = |
|
828 |
old_exchange_ty rty qty ty |
|
829 |
fun mk_rep tm = |
|
830 |
let |
|
831 |
val ty = old_exchange_ty rty qty (fastype_of tm) |
|
832 |
in fst (old_get_fun repF rty qty lthy ty) $ tm end; |
|
833 |
fun mk_abs tm = |
|
834 |
let |
|
835 |
val ty = old_exchange_ty rty qty (fastype_of tm) in |
|
836 |
fst (old_get_fun absF rty qty lthy ty) $ tm end; |
|
837 |
val (l, ltl) = Term.strip_type ty; |
|
838 |
val nl = map absty l; |
|
839 |
val vs = map (fn _ => "x") l; |
|
840 |
val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy; |
|
841 |
val args = map Free (vfs ~~ nl); |
|
842 |
val lhs = list_comb((Free (fname, nl ---> ltl)), args); |
|
843 |
val rargs = map mk_rep args; |
|
844 |
val f = Free (fname, nl ---> ltl); |
|
845 |
val rhs = mk_abs (list_comb((mk_rep f), rargs)); |
|
846 |
val eq = Logic.mk_equals (rhs, lhs); |
|
847 |
val ceq = cterm_of (ProofContext.theory_of lthy') eq; |
|
848 |
val sctxt = (Simplifier.context lthy' HOL_ss) addsimps (absrep :: @{thms fun_map.simps}); |
|
849 |
val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1) |
|
850 |
val t_id = MetaSimplifier.rewrite_rule @{thms id_def_sym} t; |
|
851 |
in |
|
852 |
singleton (ProofContext.export lthy' lthy) t_id |
|
853 |
end |
|
854 |
*} |
|
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
855 |
|
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
856 |
ML {* |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
857 |
fun lookup_quot_data lthy qty = |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
858 |
let |
257
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
859 |
val SOME quotdata = find_first (fn x => matches ((#qtyp x), qty)) (quotdata_lookup lthy) |
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
860 |
val rty = Logic.unvarifyT (#rtyp quotdata) |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
861 |
val rel = #rel quotdata |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
862 |
val rel_eqv = #equiv_thm quotdata |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
863 |
val rel_refl_pre = @{thm EQUIV_REFL} OF [rel_eqv] |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
864 |
val rel_refl = @{thm spec} OF [MetaSimplifier.rewrite_rule [@{thm REFL_def}] rel_refl_pre] |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
865 |
in |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
866 |
(rty, rel, rel_refl, rel_eqv) |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
867 |
end |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
868 |
*} |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
869 |
|
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
870 |
ML {* |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
871 |
fun lookup_quot_thms lthy qty_name = |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
872 |
let |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
873 |
val thy = ProofContext.theory_of lthy; |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
874 |
val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2") |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
875 |
val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same") |
269 | 876 |
val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10") |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
877 |
val quot = PureThy.get_thm thy ("QUOTIENT_" ^ qty_name) |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
878 |
in |
269 | 879 |
(trans2, reps_same, absrep, quot) |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
880 |
end |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
881 |
*} |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
882 |
|
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
883 |
ML {* |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
884 |
fun lookup_quot_consts defs = |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
885 |
let |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
886 |
fun dest_term (a $ b) = (a, b); |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
887 |
val def_terms = map (snd o Logic.dest_equals o concl_of) defs; |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
888 |
in |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
889 |
map (fst o dest_Const o snd o dest_term) def_terms |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
890 |
end |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
891 |
*} |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
892 |
|
275
34ad627ac5d5
fixed definition of PLUS
Christian Urban <urbanc@in.tum.de>
parents:
274
diff
changeset
|
893 |
|
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
894 |
ML {* |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
895 |
fun lift_thm lthy qty qty_name rsp_thms defs t = let |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
896 |
val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data lthy qty; |
269 | 897 |
val (trans2, reps_same, absrep, quot) = lookup_quot_thms lthy qty_name; |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
898 |
val consts = lookup_quot_consts defs; |
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
899 |
val t_a = atomize_thm t; |
251 | 900 |
val t_r = regularize t_a rty rel rel_eqv rel_refl lthy; |
210
f88ea69331bf
Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
209
diff
changeset
|
901 |
val t_t = repabs lthy t_r consts rty qty quot rel_refl trans2 rsp_thms; |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
902 |
val (alls, exs) = findallex rty qty (prop_of t_a); |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
903 |
val allthms = map (make_allex_prs_thm lthy quot @{thm FORALL_PRS}) alls |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
904 |
val exthms = map (make_allex_prs_thm lthy quot @{thm EXISTS_PRS}) exs |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
905 |
val t_a = MetaSimplifier.rewrite_rule (allthms @ exthms) t_t |
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
906 |
val abs = findabs rty (prop_of t_a); |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
907 |
val aps = findaps rty (prop_of t_a); |
269 | 908 |
val app_prs_thms = map (applic_prs lthy rty qty absrep) aps; |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
909 |
val lam_prs_thms = map (make_simp_prs_thm lthy quot @{thm LAMBDA_PRS}) abs; |
259 | 910 |
val t_l = repeat_eqsubst_thm lthy (lam_prs_thms @ app_prs_thms) t_a; |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
911 |
val defs_sym = add_lower_defs lthy defs; |
259 | 912 |
val defs_sym_eq = map (fn x => eq_reflection OF [x]) defs_sym; |
913 |
val t_d0 = MetaSimplifier.rewrite_rule defs_sym_eq t_l; |
|
914 |
val t_d = repeat_eqsubst_thm lthy defs_sym t_d0; |
|
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
915 |
val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
916 |
in |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
917 |
ObjectLogic.rulify t_r |
187 | 918 |
end |
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
919 |
*} |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
920 |
|
273
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
921 |
ML {* |
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
922 |
fun lift_thm_note qty qty_name rsp_thms defs thm name lthy = |
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
923 |
let |
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
924 |
val lifted_thm = lift_thm lthy qty qty_name rsp_thms defs thm; |
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
925 |
val (_, lthy2) = note (name, lifted_thm) lthy; |
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
926 |
in |
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
927 |
lthy2 |
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
928 |
end; |
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
929 |
*} |
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
930 |
|
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
931 |
|
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
932 |
end |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
933 |