author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Tue, 03 Nov 2009 17:51:10 +0100 | |
changeset 271 | 1b57f99737fe |
parent 270 | c55883442514 |
child 273 | b82e765ca464 |
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") |
0 | 5 |
begin |
6 |
||
261
34fb63221536
changed Type.typ_match to Sign.typ_match
Christian Urban <urbanc@in.tum.de>
parents:
259
diff
changeset
|
7 |
ML {* Attrib.empty_binding *} |
34fb63221536
changed Type.typ_match to Sign.typ_match
Christian Urban <urbanc@in.tum.de>
parents:
259
diff
changeset
|
8 |
|
0 | 9 |
locale QUOT_TYPE = |
10 |
fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
|
11 |
and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b" |
|
12 |
and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)" |
|
13 |
assumes equiv: "EQUIV R" |
|
14 |
and rep_prop: "\<And>y. \<exists>x. Rep y = R x" |
|
15 |
and rep_inverse: "\<And>x. Abs (Rep x) = x" |
|
16 |
and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)" |
|
17 |
and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)" |
|
15 | 18 |
begin |
0 | 19 |
|
20 |
definition |
|
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
21 |
ABS::"'a \<Rightarrow> 'b" |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
22 |
where |
0 | 23 |
"ABS x \<equiv> Abs (R x)" |
24 |
||
25 |
definition |
|
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
26 |
REP::"'b \<Rightarrow> 'a" |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
27 |
where |
0 | 28 |
"REP a = Eps (Rep a)" |
29 |
||
15 | 30 |
lemma lem9: |
0 | 31 |
shows "R (Eps (R x)) = R x" |
32 |
proof - |
|
33 |
have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def) |
|
34 |
then have "R x (Eps (R x))" by (rule someI) |
|
15 | 35 |
then show "R (Eps (R x)) = R x" |
0 | 36 |
using equiv unfolding EQUIV_def by simp |
37 |
qed |
|
38 |
||
39 |
theorem thm10: |
|
24
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
40 |
shows "ABS (REP a) \<equiv> a" |
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
41 |
apply (rule eq_reflection) |
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
42 |
unfolding ABS_def REP_def |
0 | 43 |
proof - |
15 | 44 |
from rep_prop |
0 | 45 |
obtain x where eq: "Rep a = R x" by auto |
46 |
have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp |
|
47 |
also have "\<dots> = Abs (R x)" using lem9 by simp |
|
48 |
also have "\<dots> = Abs (Rep a)" using eq by simp |
|
49 |
also have "\<dots> = a" using rep_inverse by simp |
|
50 |
finally |
|
51 |
show "Abs (R (Eps (Rep a))) = a" by simp |
|
52 |
qed |
|
53 |
||
15 | 54 |
lemma REP_refl: |
0 | 55 |
shows "R (REP a) (REP a)" |
56 |
unfolding REP_def |
|
57 |
by (simp add: equiv[simplified EQUIV_def]) |
|
58 |
||
59 |
lemma lem7: |
|
22 | 60 |
shows "(R x = R y) = (Abs (R x) = Abs (R y))" |
0 | 61 |
apply(rule iffI) |
62 |
apply(simp) |
|
63 |
apply(drule rep_inject[THEN iffD2]) |
|
64 |
apply(simp add: abs_inverse) |
|
65 |
done |
|
15 | 66 |
|
0 | 67 |
theorem thm11: |
68 |
shows "R r r' = (ABS r = ABS r')" |
|
69 |
unfolding ABS_def |
|
70 |
by (simp only: equiv[simplified EQUIV_def] lem7) |
|
71 |
||
4 | 72 |
|
2 | 73 |
lemma REP_ABS_rsp: |
4 | 74 |
shows "R f (REP (ABS g)) = R f g" |
75 |
and "R (REP (ABS g)) f = R g f" |
|
23 | 76 |
by (simp_all add: thm10 thm11) |
4 | 77 |
|
0 | 78 |
lemma QUOTIENT: |
79 |
"QUOTIENT R ABS REP" |
|
80 |
apply(unfold QUOTIENT_def) |
|
81 |
apply(simp add: thm10) |
|
82 |
apply(simp add: REP_refl) |
|
83 |
apply(subst thm11[symmetric]) |
|
84 |
apply(simp add: equiv[simplified EQUIV_def]) |
|
85 |
done |
|
86 |
||
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
87 |
lemma R_trans: |
49 | 88 |
assumes ab: "R a b" |
89 |
and bc: "R b c" |
|
22 | 90 |
shows "R a c" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
91 |
proof - |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
92 |
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
|
93 |
moreover have ab: "R a b" by fact |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
94 |
moreover have bc: "R b c" by fact |
22 | 95 |
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
|
96 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
97 |
|
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
98 |
lemma R_sym: |
49 | 99 |
assumes ab: "R a b" |
22 | 100 |
shows "R b a" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
101 |
proof - |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
102 |
have re: "SYM R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
22 | 103 |
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
|
104 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
105 |
|
49 | 106 |
lemma R_trans2: |
107 |
assumes ac: "R a c" |
|
22 | 108 |
and bd: "R b d" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
109 |
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
|
110 |
using ac bd |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
111 |
by (blast intro: R_trans R_sym) |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
112 |
|
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
113 |
lemma REPS_same: |
25
9020ee23a020
The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
24
diff
changeset
|
114 |
shows "R (REP a) (REP b) \<equiv> (a = b)" |
38 | 115 |
proof - |
116 |
have "R (REP a) (REP b) = (a = b)" |
|
117 |
proof |
|
118 |
assume as: "R (REP a) (REP b)" |
|
119 |
from rep_prop |
|
120 |
obtain x y |
|
121 |
where eqs: "Rep a = R x" "Rep b = R y" by blast |
|
122 |
from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp |
|
123 |
then have "R x (Eps (R y))" using lem9 by simp |
|
124 |
then have "R (Eps (R y)) x" using R_sym by blast |
|
125 |
then have "R y x" using lem9 by simp |
|
126 |
then have "R x y" using R_sym by blast |
|
127 |
then have "ABS x = ABS y" using thm11 by simp |
|
128 |
then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp |
|
129 |
then show "a = b" using rep_inverse by simp |
|
130 |
next |
|
131 |
assume ab: "a = b" |
|
132 |
have "REFL R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
|
133 |
then show "R (REP a) (REP b)" unfolding REFL_def using ab by auto |
|
134 |
qed |
|
135 |
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
|
136 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
137 |
|
0 | 138 |
end |
139 |
||
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
|
140 |
|
0 | 141 |
section {* type definition for the quotient type *} |
142 |
||
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
|
143 |
(* 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
|
144 |
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
|
145 |
|
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
|
146 |
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
|
147 |
fun error_msg pre post msg = |
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
|
148 |
msg |> quote |
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
|
149 |
|> enclose (pre ^ " ") (" " ^ post) |
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
|
150 |
|> error |
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
|
151 |
*} |
0 | 152 |
|
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
153 |
declare [[map list = (map, LIST_REL)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
154 |
declare [[map * = (prod_fun, prod_rel)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
155 |
declare [[map "fun" = (fun_map, FUN_REL)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
156 |
|
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
157 |
ML {* maps_lookup @{theory} "List.list" *} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
158 |
ML {* maps_lookup @{theory} "*" *} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
159 |
ML {* maps_lookup @{theory} "fun" *} |
174
09048a951dca
moved the map_funs setup into QuotMain
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
160 |
|
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
|
161 |
|
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
|
162 |
(* definition of the quotient types *) |
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
|
163 |
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
|
164 |
|
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
|
165 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
166 |
text {* FIXME: auxiliary function *} |
193 | 167 |
ML {* |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
168 |
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
|
169 |
let |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
170 |
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
|
171 |
val ((_, [th']), _) = Variable.import true [th] ctxt; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
172 |
in th' end); |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
173 |
*} |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
174 |
|
0 | 175 |
section {* lifting of constants *} |
176 |
||
177 |
ML {* |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
178 |
fun lookup_snd _ [] _ = NONE |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
179 |
| lookup_snd eq ((value, key)::xs) key' = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
180 |
if eq (key', key) then SOME value |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
181 |
else lookup_snd eq xs key'; |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
182 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
183 |
fun lookup_qenv qenv qty = |
254
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
184 |
(case (AList.lookup (op =) qenv qty) of |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
185 |
SOME rty => SOME (qty, rty) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
186 |
| NONE => NONE) |
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
187 |
*} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
188 |
|
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
189 |
ML {* |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
190 |
(* calculates the aggregate abs and rep functions for a given type; |
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
191 |
repF is for constants' arguments; absF is for constants; |
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
192 |
function types need to be treated specially, since repF and absF |
163
3da18bf6886c
Split Finite Set example into separate file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
162
diff
changeset
|
193 |
change |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
194 |
*) |
46 | 195 |
datatype flag = absF | repF |
0 | 196 |
|
109
386671ef36bd
fixed the problem with function types; but only type_of works; cterm_of does not work
Christian Urban <urbanc@in.tum.de>
parents:
108
diff
changeset
|
197 |
fun negF absF = repF |
386671ef36bd
fixed the problem with function types; but only type_of works; cterm_of does not work
Christian Urban <urbanc@in.tum.de>
parents:
108
diff
changeset
|
198 |
| negF repF = absF |
386671ef36bd
fixed the problem with function types; but only type_of works; cterm_of does not work
Christian Urban <urbanc@in.tum.de>
parents:
108
diff
changeset
|
199 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
200 |
fun get_fun flag qenv lthy ty = |
0 | 201 |
let |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
202 |
|
0 | 203 |
fun get_fun_aux s fs_tys = |
204 |
let |
|
205 |
val (fs, tys) = split_list fs_tys |
|
15 | 206 |
val (otys, ntys) = split_list tys |
0 | 207 |
val oty = Type (s, otys) |
208 |
val nty = Type (s, ntys) |
|
209 |
val ftys = map (op -->) tys |
|
210 |
in |
|
130
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
129
diff
changeset
|
211 |
(case (maps_lookup (ProofContext.theory_of lthy) s) of |
110
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
212 |
SOME info => (list_comb (Const (#mapfun info, ftys ---> (oty --> nty)), fs), (oty, nty)) |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
213 |
| NONE => raise ERROR ("no map association for type " ^ s)) |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
214 |
end |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
215 |
|
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
216 |
fun get_fun_fun fs_tys = |
110
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
217 |
let |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
218 |
val (fs, tys) = split_list fs_tys |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
219 |
val ([oty1, oty2], [nty1, nty2]) = split_list tys |
128 | 220 |
val oty = nty1 --> oty2 |
221 |
val nty = oty1 --> nty2 |
|
110
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
222 |
val ftys = map (op -->) tys |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
223 |
in |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
224 |
(list_comb (Const (@{const_name "fun_map"}, ftys ---> oty --> nty), fs), (oty, nty)) |
0 | 225 |
end |
226 |
||
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
227 |
fun get_const flag (qty, rty) = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
228 |
let |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
229 |
val thy = ProofContext.theory_of lthy |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
230 |
val qty_name = Long_Name.base_name (fst (dest_Type qty)) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
231 |
in |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
232 |
case flag of |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
233 |
absF => (Const (Sign.full_bname thy ("ABS_" ^ qty_name), rty --> qty), (rty, qty)) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
234 |
| repF => (Const (Sign.full_bname thy ("REP_" ^ qty_name), qty --> rty), (qty, rty)) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
235 |
end |
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
236 |
|
70
f3cbda066c3a
consistent usage of rty (for the raw, unquotient type); tuned a bit the Isar
Christian Urban <urbanc@in.tum.de>
parents:
69
diff
changeset
|
237 |
fun mk_identity ty = Abs ("", ty, Bound 0) |
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
238 |
|
0 | 239 |
in |
254
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
240 |
if (AList.defined (op =) qenv ty) |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
241 |
then (get_const flag (the (lookup_qenv qenv ty))) |
0 | 242 |
else (case ty of |
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
243 |
TFree _ => (mk_identity ty, (ty, ty)) |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
244 |
| Type (_, []) => (mk_identity ty, (ty, ty)) |
109
386671ef36bd
fixed the problem with function types; but only type_of works; cterm_of does not work
Christian Urban <urbanc@in.tum.de>
parents:
108
diff
changeset
|
245 |
| Type ("fun" , [ty1, ty2]) => |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
246 |
get_fun_fun [get_fun (negF flag) qenv lthy ty1, get_fun flag qenv lthy ty2] |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
247 |
| Type (s, tys) => get_fun_aux s (map (get_fun flag qenv lthy) tys) |
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
248 |
| _ => raise ERROR ("no type variables") |
0 | 249 |
) |
250 |
end |
|
251 |
*} |
|
252 |
||
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
253 |
text {* produces the definition for a lifted constant *} |
86 | 254 |
|
2 | 255 |
ML {* |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
256 |
fun get_const_def nconst otrm qenv lthy = |
0 | 257 |
let |
258 |
val ty = fastype_of nconst |
|
259 |
val (arg_tys, res_ty) = strip_type ty |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
260 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
261 |
val rep_fns = map (fst o get_fun repF qenv lthy) arg_tys |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
262 |
val abs_fn = (fst o get_fun absF qenv lthy) res_ty |
0 | 263 |
|
180
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
264 |
fun mk_fun_map (t1,t2) = Const (@{const_name "fun_map"}, dummyT) $ t1 $ t2 |
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
265 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
266 |
val fns = Library.foldr mk_fun_map (rep_fns, abs_fn) |
180
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
267 |
|> Syntax.check_term lthy |
0 | 268 |
in |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
269 |
fns $ otrm |
0 | 270 |
end |
271 |
*} |
|
272 |
||
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
273 |
|
0 | 274 |
ML {* |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
275 |
fun exchange_ty qenv ty = |
254
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
276 |
case (lookup_snd (op =) qenv ty) of |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
277 |
SOME qty => qty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
278 |
| NONE => |
0 | 279 |
(case ty of |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
280 |
Type (s, tys) => Type (s, map (exchange_ty qenv) tys) |
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
281 |
| _ => ty |
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
282 |
) |
0 | 283 |
*} |
284 |
||
254
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
285 |
ML {* |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
286 |
fun ppair lthy (ty1, ty2) = |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
287 |
"(" ^ (Syntax.string_of_typ lthy ty1) ^ "," ^ (Syntax.string_of_typ lthy ty2) ^ ")" |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
288 |
*} |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
289 |
|
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
290 |
ML {* |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
291 |
fun print_env qenv lthy = |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
292 |
map (ppair lthy) qenv |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
293 |
|> commas |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
294 |
|> tracing |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
295 |
*} |
77ff9624cfd6
fixed the problem with types in map
Christian Urban <urbanc@in.tum.de>
parents:
252
diff
changeset
|
296 |
|
0 | 297 |
ML {* |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
298 |
fun make_const_def nconst_bname otrm mx qenv lthy = |
0 | 299 |
let |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
300 |
val otrm_ty = fastype_of otrm |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
301 |
val nconst_ty = exchange_ty qenv otrm_ty |
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
302 |
val nconst = Const (Binding.name_of nconst_bname, nconst_ty) |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
303 |
val def_trm = get_const_def nconst otrm qenv lthy |
0 | 304 |
in |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
77
diff
changeset
|
305 |
define (nconst_bname, mx, def_trm) lthy |
15 | 306 |
end |
0 | 307 |
*} |
308 |
||
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
309 |
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
|
310 |
(* difference of two types *) |
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
|
311 |
fun diff (T, S) Ds = |
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
|
312 |
case (T, S) of |
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
|
313 |
(TVar v, TVar u) => if v = u then Ds else (T, S)::Ds |
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
|
314 |
| (TFree x, TFree y) => if x = y then Ds else (T, S)::Ds |
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
|
315 |
| (Type (a, Ts), Type (b, Us)) => |
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
|
316 |
if a = b then diffs (Ts, Us) Ds else (T, S)::Ds |
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
|
317 |
| _ => (T, S)::Ds |
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
|
318 |
and diffs (T::Ts, U::Us) Ds = diffs (Ts, Us) (diff (T, U) Ds) |
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
|
319 |
| diffs ([], []) Ds = Ds |
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
|
320 |
| diffs _ _ = error "Unequal length of type arguments" |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
321 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
322 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
323 |
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
|
324 |
fun quotdef_cmd ((bind, qty, mx), (attr, prop)) lthy = |
263
a159ba20979e
slightly saner way of parsing the quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
261
diff
changeset
|
325 |
let |
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
|
326 |
val (_, rhs) = Logic.dest_equals prop |
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
|
327 |
val rty = fastype_of rhs |
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
|
328 |
val qenv = distinct (op=) (diff (qty, rty) []) |
263
a159ba20979e
slightly saner way of parsing the quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
261
diff
changeset
|
329 |
in |
a159ba20979e
slightly saner way of parsing the quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
261
diff
changeset
|
330 |
make_const_def bind rhs mx qenv lthy |
a159ba20979e
slightly saner way of parsing the quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
261
diff
changeset
|
331 |
end |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
332 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
333 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
334 |
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
|
335 |
val constdecl = |
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
|
336 |
OuterParse.binding -- |
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
|
337 |
(OuterParse.$$$ "::" |-- OuterParse.!!! |
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
|
338 |
(OuterParse.typ -- OuterParse.opt_mixfix' --| OuterParse.where_)) |
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
|
339 |
>> OuterParse.triple2; |
263
a159ba20979e
slightly saner way of parsing the quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
261
diff
changeset
|
340 |
*} |
a159ba20979e
slightly saner way of parsing the quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
261
diff
changeset
|
341 |
|
a159ba20979e
slightly saner way of parsing the quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
261
diff
changeset
|
342 |
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
|
343 |
val quotdef_parser = |
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
|
344 |
(constdecl -- (SpecParse.opt_thm_name ":" -- OuterParse.prop)) |
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
|
345 |
*} |
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
|
346 |
|
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
|
347 |
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
|
348 |
fun quotdef ((bind, qtystr, mx), (attr, propstr)) lthy = |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
349 |
let |
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
|
350 |
val qty = (Syntax.check_typ lthy o Syntax.parse_typ lthy) qtystr |
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
|
351 |
val prop = (Syntax.check_prop lthy o Syntax.parse_prop lthy) propstr |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
352 |
in |
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
|
353 |
quotdef_cmd ((bind, qty, mx), (attr, prop)) lthy |> snd |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
354 |
end |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
355 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
356 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
357 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
358 |
val _ = OuterSyntax.local_theory "quotient_def" "lifted definition of constants" |
263
a159ba20979e
slightly saner way of parsing the quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
261
diff
changeset
|
359 |
OuterKeyword.thy_decl (quotdef_parser >> quotdef) |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
360 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
361 |
|
139 | 362 |
section {* ATOMIZE *} |
363 |
||
364 |
text {* |
|
365 |
Unabs_def converts a definition given as |
|
366 |
||
367 |
c \<equiv> %x. %y. f x y |
|
368 |
||
369 |
to a theorem of the form |
|
370 |
||
371 |
c x y \<equiv> f x y |
|
372 |
||
373 |
This function is needed to rewrite the right-hand |
|
374 |
side to the left-hand side. |
|
375 |
*} |
|
376 |
||
377 |
ML {* |
|
378 |
fun unabs_def ctxt def = |
|
379 |
let |
|
380 |
val (lhs, rhs) = Thm.dest_equals (cprop_of def) |
|
381 |
val xs = strip_abs_vars (term_of rhs) |
|
382 |
val (_, ctxt') = Variable.add_fixes (map fst xs) ctxt |
|
383 |
||
384 |
val thy = ProofContext.theory_of ctxt' |
|
385 |
val cxs = map (cterm_of thy o Free) xs |
|
386 |
val new_lhs = Drule.list_comb (lhs, cxs) |
|
387 |
||
388 |
fun get_conv [] = Conv.rewr_conv def |
|
389 |
| get_conv (x::xs) = Conv.fun_conv (get_conv xs) |
|
390 |
in |
|
391 |
get_conv xs new_lhs |> |
|
392 |
singleton (ProofContext.export ctxt' ctxt) |
|
393 |
end |
|
394 |
*} |
|
395 |
||
396 |
lemma atomize_eqv[atomize]: |
|
397 |
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" |
|
398 |
proof |
|
399 |
assume "A \<equiv> B" |
|
400 |
then show "Trueprop A \<equiv> Trueprop B" by unfold |
|
401 |
next |
|
402 |
assume *: "Trueprop A \<equiv> Trueprop B" |
|
403 |
have "A = B" |
|
404 |
proof (cases A) |
|
405 |
case True |
|
406 |
have "A" by fact |
|
407 |
then show "A = B" using * by simp |
|
408 |
next |
|
409 |
case False |
|
410 |
have "\<not>A" by fact |
|
411 |
then show "A = B" using * by auto |
|
412 |
qed |
|
413 |
then show "A \<equiv> B" by (rule eq_reflection) |
|
414 |
qed |
|
415 |
||
416 |
ML {* |
|
417 |
fun atomize_thm thm = |
|
418 |
let |
|
221 | 419 |
val thm' = Thm.freezeT (forall_intr_vars thm) |
139 | 420 |
val thm'' = ObjectLogic.atomize (cprop_of thm') |
421 |
in |
|
221 | 422 |
@{thm Pure.equal_elim_rule1} OF [thm'', thm'] |
139 | 423 |
end |
424 |
*} |
|
425 |
||
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
426 |
ML {* atomize_thm @{thm list.induct} *} |
139 | 427 |
|
428 |
section {* REGULARIZE *} |
|
429 |
||
430 |
text {* tyRel takes a type and builds a relation that a quantifier over this |
|
431 |
type needs to respect. *} |
|
432 |
ML {* |
|
257
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
433 |
fun matches (ty1, ty2) = |
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
434 |
Type.raw_instance (ty1, Logic.varifyT ty2); |
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
435 |
|
139 | 436 |
fun tyRel ty rty rel lthy = |
257
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
437 |
if matches (rty, ty) |
139 | 438 |
then rel |
439 |
else (case ty of |
|
440 |
Type (s, tys) => |
|
441 |
let |
|
442 |
val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys; |
|
443 |
val ty_out = ty --> ty --> @{typ bool}; |
|
444 |
val tys_out = tys_rel ---> ty_out; |
|
445 |
in |
|
446 |
(case (maps_lookup (ProofContext.theory_of lthy) s) of |
|
447 |
SOME (info) => list_comb (Const (#relfun info, tys_out), map (fn ty => tyRel ty rty rel lthy) tys) |
|
448 |
| NONE => HOLogic.eq_const ty |
|
449 |
) |
|
450 |
end |
|
451 |
| _ => HOLogic.eq_const ty) |
|
452 |
*} |
|
453 |
||
454 |
definition |
|
455 |
Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" |
|
456 |
where |
|
457 |
"(x \<in> p) \<Longrightarrow> (Babs p m x = m x)" |
|
458 |
(* TODO: Consider defining it with an "if"; sth like: |
|
459 |
Babs p m = \<lambda>x. if x \<in> p then m x else undefined |
|
460 |
*) |
|
461 |
||
462 |
ML {* |
|
463 |
fun needs_lift (rty as Type (rty_s, _)) ty = |
|
464 |
case ty of |
|
465 |
Type (s, tys) => |
|
466 |
(s = rty_s) orelse (exists (needs_lift rty) tys) |
|
467 |
| _ => false |
|
468 |
||
469 |
*} |
|
470 |
||
471 |
ML {* |
|
472 |
fun mk_babs ty ty' = Const (@{const_name "Babs"}, [ty' --> @{typ bool}, ty] ---> ty) |
|
473 |
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool}) |
|
474 |
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool}) |
|
475 |
fun mk_resp ty = Const (@{const_name Respects}, [[ty, ty] ---> @{typ bool}, ty] ---> @{typ bool}) |
|
476 |
*} |
|
477 |
||
478 |
(* applies f to the subterm of an abstractions, otherwise to the given term *) |
|
479 |
ML {* |
|
480 |
fun apply_subt f trm = |
|
481 |
case trm of |
|
145 | 482 |
Abs (x, T, t) => |
483 |
let |
|
484 |
val (x', t') = Term.dest_abs (x, T, t) |
|
485 |
in |
|
486 |
Term.absfree (x', T, f t') |
|
487 |
end |
|
139 | 488 |
| _ => f trm |
489 |
*} |
|
490 |
||
491 |
(* FIXME: if there are more than one quotient, then you have to look up the relation *) |
|
492 |
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
|
493 |
fun my_reg lthy rel rty trm = |
139 | 494 |
case trm of |
495 |
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
|
496 |
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
|
497 |
let |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
498 |
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
|
499 |
in |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
500 |
(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
|
501 |
end |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
502 |
else |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
503 |
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
|
504 |
| 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
|
505 |
let |
139 | 506 |
val ty1 = domain_type ty |
507 |
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
|
508 |
val rrel = tyRel T rty rel lthy |
139 | 509 |
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
|
510 |
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
|
511 |
(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
|
512 |
else |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
513 |
Const (@{const_name "All"}, ty) $ apply_subt (my_reg lthy rel rty) t |
139 | 514 |
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
|
515 |
| 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
|
516 |
let |
139 | 517 |
val ty1 = domain_type ty |
518 |
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
|
519 |
val rrel = tyRel T rty rel lthy |
139 | 520 |
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
|
521 |
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
|
522 |
(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
|
523 |
else |
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
524 |
Const (@{const_name "Ex"}, ty) $ apply_subt (my_reg lthy rel rty) t |
139 | 525 |
end |
251 | 526 |
| Const (@{const_name "op ="}, ty) $ t => |
527 |
if needs_lift rty (fastype_of t) then |
|
528 |
(tyRel (fastype_of t) rty rel lthy) $ t |
|
529 |
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
|
530 |
| t1 $ t2 => (my_reg lthy rel rty t1) $ (my_reg lthy rel rty t2) |
139 | 531 |
| _ => trm |
532 |
*} |
|
533 |
||
141
0ffc37761e53
Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
140
diff
changeset
|
534 |
text {* Assumes that the given theorem is atomized *} |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
535 |
ML {* |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
536 |
fun build_regularize_goal thm rty rel lthy = |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
537 |
Logic.mk_implies |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
538 |
((prop_of thm), |
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
241
diff
changeset
|
539 |
(my_reg lthy rel rty (prop_of thm))) |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
540 |
*} |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
541 |
|
252
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
542 |
lemma universal_twice: "(\<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
|
543 |
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
|
544 |
|
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
545 |
lemma implication_twice: "(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
|
546 |
by auto |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
547 |
|
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
548 |
(*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
|
549 |
by auto*) |
251 | 550 |
|
187 | 551 |
ML {* |
251 | 552 |
fun regularize thm rty rel rel_eqv rel_refl lthy = |
187 | 553 |
let |
554 |
val g = build_regularize_goal thm rty rel lthy; |
|
555 |
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
|
556 |
(ObjectLogic.full_atomize_tac) THEN' |
251 | 557 |
REPEAT_ALL_NEW (FIRST' [ |
558 |
rtac rel_refl, |
|
559 |
atac, |
|
252
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
251
diff
changeset
|
560 |
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
|
561 |
(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
|
562 |
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
|
563 |
(*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
|
564 |
EqSubst.eqsubst_tac ctxt [0] |
187 | 565 |
[(@{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
|
566 |
(@{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
|
567 |
(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
|
568 |
(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
|
569 |
]); |
187 | 570 |
val cthm = Goal.prove lthy [] [] g (fn x => tac (#context x) 1); |
571 |
in |
|
572 |
cthm OF [thm] |
|
573 |
end |
|
574 |
*} |
|
575 |
||
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
576 |
section {* RepAbs injection *} |
139 | 577 |
|
161
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
578 |
(* 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
|
579 |
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
|
580 |
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
|
581 |
|
139 | 582 |
ML {* |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
583 |
fun old_exchange_ty rty qty ty = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
584 |
if ty = rty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
585 |
then qty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
586 |
else |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
587 |
(case ty of |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
588 |
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
|
589 |
| _ => ty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
590 |
) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
591 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
592 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
593 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
594 |
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
|
595 |
get_fun flag [(qty, rty)] lthy ty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
596 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
597 |
fun old_make_const_def nconst_bname otrm mx rty qty lthy = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
598 |
make_const_def nconst_bname otrm mx [(qty, rty)] lthy |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
599 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
600 |
|
235
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
601 |
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
|
602 |
ML {* |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
603 |
fun eqsubst_prop ctxt thms t = |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
604 |
let |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
605 |
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
|
606 |
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
|
607 |
NONE => error "eqsubst_prop" |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
608 |
| SOME th => cprem_of th 1 |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
609 |
in term_of a' end |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
610 |
*} |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
611 |
|
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
612 |
ML {* |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
613 |
fun repeat_eqsubst_prop ctxt thms t = |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
614 |
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
|
615 |
handle _ => t |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
616 |
*} |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
617 |
|
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
618 |
|
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
619 |
ML {* |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
620 |
fun eqsubst_thm ctxt thms thm = |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
621 |
let |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
622 |
val goalstate = Goal.init (Thm.cprop_of thm) |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
623 |
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
|
624 |
NONE => error "eqsubst_thm" |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
625 |
| SOME th => cprem_of th 1 |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
626 |
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
|
627 |
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
|
628 |
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
|
629 |
in |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
630 |
@{thm Pure.equal_elim_rule1} OF [rt,thm] |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
631 |
end |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
632 |
*} |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
633 |
|
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
634 |
ML {* |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
635 |
fun repeat_eqsubst_thm ctxt thms thm = |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
636 |
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
|
637 |
handle _ => thm |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
638 |
*} |
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
639 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
640 |
ML {* |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
641 |
fun build_repabs_term lthy thm constructors rty qty = |
139 | 642 |
let |
643 |
fun mk_rep tm = |
|
644 |
let |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
645 |
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
|
646 |
in fst (old_get_fun repF rty qty lthy ty) $ tm end |
139 | 647 |
|
648 |
fun mk_abs tm = |
|
649 |
let |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
650 |
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
|
651 |
fst (old_get_fun absF rty qty lthy ty) $ tm end |
139 | 652 |
|
653 |
fun is_constructor (Const (x, _)) = member (op =) constructors x |
|
654 |
| is_constructor _ = false; |
|
655 |
||
656 |
fun build_aux lthy tm = |
|
657 |
case tm of |
|
658 |
Abs (a as (_, vty, _)) => |
|
659 |
let |
|
660 |
val (vs, t) = Term.dest_abs a; |
|
661 |
val v = Free(vs, vty); |
|
662 |
val t' = lambda v (build_aux lthy t) |
|
663 |
in |
|
664 |
if (not (needs_lift rty (fastype_of tm))) then t' |
|
665 |
else mk_rep (mk_abs ( |
|
666 |
if not (needs_lift rty vty) then t' |
|
667 |
else |
|
668 |
let |
|
669 |
val v' = mk_rep (mk_abs v); |
|
670 |
val t1 = Envir.beta_norm (t' $ v') |
|
671 |
in |
|
672 |
lambda v t1 |
|
673 |
end |
|
674 |
)) |
|
675 |
end |
|
676 |
| x => |
|
677 |
let |
|
678 |
val (opp, tms0) = Term.strip_comb tm |
|
679 |
val tms = map (build_aux lthy) tms0 |
|
680 |
val ty = fastype_of tm |
|
681 |
in |
|
682 |
if (((fst (Term.dest_Const opp)) = @{const_name Respects}) handle _ => false) |
|
683 |
then (list_comb (opp, (hd tms0) :: (tl tms))) |
|
684 |
else if (is_constructor opp andalso needs_lift rty ty) then |
|
685 |
mk_rep (mk_abs (list_comb (opp,tms))) |
|
686 |
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
|
687 |
mk_rep(mk_abs(list_comb(opp,tms))) |
139 | 688 |
else if tms = [] then opp |
689 |
else list_comb(opp, tms) |
|
690 |
end |
|
691 |
in |
|
235
7affee8f90f5
Using subst for identity definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
223
diff
changeset
|
692 |
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
|
693 |
(build_aux lthy (Thm.prop_of thm)) |
139 | 694 |
end |
695 |
*} |
|
696 |
||
141
0ffc37761e53
Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
140
diff
changeset
|
697 |
text {* Assumes that it is given a regularized theorem *} |
139 | 698 |
ML {* |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
699 |
fun build_repabs_goal ctxt thm cons rty qty = |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
700 |
Logic.mk_equals ((Thm.prop_of thm), (build_repabs_term ctxt thm cons rty qty)) |
139 | 701 |
*} |
702 |
||
187 | 703 |
ML {* |
704 |
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} => |
|
705 |
let |
|
706 |
val pat = Drule.strip_imp_concl (cprop_of thm) |
|
707 |
val insts = Thm.match (pat, concl) |
|
708 |
in |
|
709 |
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
|
710 |
end |
187 | 711 |
handle _ => no_tac |
712 |
) |
|
713 |
*} |
|
714 |
||
715 |
||
716 |
||
717 |
ML {* |
|
718 |
fun quotient_tac quot_thm = |
|
719 |
REPEAT_ALL_NEW (FIRST' [ |
|
720 |
rtac @{thm FUN_QUOTIENT}, |
|
721 |
rtac quot_thm, |
|
722 |
rtac @{thm IDENTITY_QUOTIENT} |
|
723 |
]) |
|
724 |
*} |
|
725 |
||
726 |
ML {* |
|
727 |
fun LAMBDA_RES_TAC ctxt i st = |
|
728 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
729 |
(_ $ (_ $ (Abs(_,_,_))$(Abs(_,_,_)))) => |
|
730 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
731 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
732 |
| _ => fn _ => no_tac) i st |
|
733 |
*} |
|
734 |
||
735 |
ML {* |
|
736 |
fun WEAK_LAMBDA_RES_TAC ctxt i st = |
|
737 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
738 |
(_ $ (_ $ _$(Abs(_,_,_)))) => |
|
739 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
740 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
741 |
| (_ $ (_ $ (Abs(_,_,_))$_)) => |
|
742 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
743 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
744 |
| _ => fn _ => no_tac) i st |
|
745 |
*} |
|
746 |
||
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
747 |
ML {* |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
748 |
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
|
749 |
let |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
750 |
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
|
751 |
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
|
752 |
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
|
753 |
in |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
754 |
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
|
755 |
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
|
756 |
else no_tac |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
757 |
end |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
758 |
handle _ => no_tac) |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
759 |
*} |
187 | 760 |
|
761 |
ML {* |
|
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
762 |
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
|
763 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
764 |
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
|
765 |
in |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
766 |
((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
|
767 |
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
|
768 |
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
|
769 |
(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
|
770 |
end |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
771 |
handle _ => no_tac |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
772 |
) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
773 |
*} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
774 |
|
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
775 |
ML {* |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
776 |
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
|
777 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
778 |
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
|
779 |
in |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
780 |
((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
|
781 |
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
|
782 |
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
|
783 |
(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
|
784 |
end |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
785 |
handle _ => no_tac |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
786 |
) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
787 |
*} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
788 |
|
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
789 |
ML {* |
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
790 |
fun r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms = |
187 | 791 |
(FIRST' [ |
259 | 792 |
(* rtac @{thm FUN_QUOTIENT}, |
187 | 793 |
rtac quot_thm, |
259 | 794 |
rtac @{thm IDENTITY_QUOTIENT},*) |
187 | 795 |
rtac trans_thm, |
796 |
LAMBDA_RES_TAC ctxt, |
|
797 |
res_forall_rsp_tac ctxt, |
|
798 |
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
|
799 |
FIRST' (map rtac rsp_thms), |
187 | 800 |
(instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' (RANGE [quotient_tac quot_thm])), |
801 |
rtac refl, |
|
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
802 |
(* 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
|
803 |
(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
|
804 |
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
|
805 |
rtac @{thm ext}, |
187 | 806 |
rtac reflex_thm, |
807 |
atac, |
|
808 |
( |
|
809 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
810 |
THEN_ALL_NEW (fn _ => no_tac) |
|
811 |
), |
|
812 |
WEAK_LAMBDA_RES_TAC ctxt |
|
813 |
]) |
|
814 |
*} |
|
815 |
||
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
|
816 |
ML {* |
210
f88ea69331bf
Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
209
diff
changeset
|
817 |
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
|
818 |
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
|
819 |
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
|
820 |
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
|
821 |
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
|
822 |
(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
|
823 |
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
|
824 |
in |
210
f88ea69331bf
Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
209
diff
changeset
|
825 |
@{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
|
826 |
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
|
827 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
828 |
|
187 | 829 |
section {* Cleaning the goal *} |
830 |
||
236
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
831 |
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
|
832 |
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
|
833 |
done |
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
834 |
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
|
835 |
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
|
836 |
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
|
837 |
done |
23f9fead8bd6
Cleaning of 'map id' and 'prod_fun id id' in lower_defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
235
diff
changeset
|
838 |
|
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
|
839 |
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
|
840 |
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
|
841 |
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
|
842 |
let |
209
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
843 |
val e1 = @{thm fun_cong} OF [thm]; |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
844 |
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
|
845 |
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
|
846 |
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
|
847 |
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
|
848 |
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
|
849 |
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
|
850 |
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
|
851 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
852 |
|
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
853 |
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
|
854 |
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
|
855 |
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
|
856 |
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
|
857 |
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
|
858 |
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
|
859 |
in |
214 | 860 |
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
|
861 |
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
|
862 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
863 |
|
191
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
864 |
ML {* |
241
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
865 |
fun findabs_all rty tm = |
191
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
866 |
case tm of |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
867 |
Abs(_, T, b) => |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
868 |
let |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
869 |
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
|
870 |
val tys = findabs_all rty b' |
191
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
871 |
val ty = fastype_of tm |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
872 |
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
|
873 |
end |
241
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
874 |
| 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
|
875 |
| _ => []; |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
876 |
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
|
877 |
*} |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
878 |
|
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
879 |
|
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
880 |
ML {* |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
881 |
fun findaps_all rty tm = |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
882 |
case tm of |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
883 |
Abs(_, T, b) => |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
884 |
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
|
885 |
| (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
|
886 |
| 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
|
887 |
| _ => []; |
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
239
diff
changeset
|
888 |
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
|
889 |
*} |
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
|
890 |
|
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
891 |
ML {* |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
892 |
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
|
893 |
let |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
894 |
val (_, [lty, rty]) = dest_Type typ; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
895 |
val thy = ProofContext.theory_of lthy; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
896 |
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
|
897 |
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
|
898 |
val lpi = Drule.instantiate' inst [] thm; |
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
899 |
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
|
900 |
(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
|
901 |
(quotient_tac quot_thm); |
259 | 902 |
val gc = Drule.strip_imp_concl (cprop_of lpi); |
903 |
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
|
904 |
in |
253
e169a99c6ada
Automatic computation of application preservation and manually finished "alpha.induct". Slow...
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
252
diff
changeset
|
905 |
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
|
906 |
end |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
907 |
*} |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
908 |
|
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
909 |
ML {* |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
910 |
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
|
911 |
case tm of |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
912 |
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
|
913 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
914 |
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
|
915 |
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
|
916 |
((T :: tya), tye) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
917 |
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
|
918 |
| 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
|
919 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
920 |
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
|
921 |
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
|
922 |
(tya, (T :: tye)) |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
923 |
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
|
924 |
| Abs(_, T, b) => |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
925 |
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
|
926 |
| f $ a => |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
927 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
928 |
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
|
929 |
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
|
930 |
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
|
931 |
| _ => ([], []); |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
932 |
*} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
933 |
ML {* |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
934 |
fun findallex rty qty tm = |
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
935 |
let |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
936 |
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
|
937 |
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
|
938 |
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
|
939 |
in |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
940 |
(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
|
941 |
end |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
942 |
*} |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
943 |
|
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
944 |
ML {* |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
945 |
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
|
946 |
let |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
947 |
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
|
948 |
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
|
949 |
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
|
950 |
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
|
951 |
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
|
952 |
val tac = |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
953 |
(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
|
954 |
(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
|
955 |
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
|
956 |
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
|
957 |
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
|
958 |
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
|
959 |
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
|
960 |
in |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
961 |
t_eq |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
962 |
end |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
963 |
*} |
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
964 |
|
269 | 965 |
ML {* |
966 |
fun applic_prs lthy rty qty absrep ty = |
|
967 |
let |
|
968 |
fun absty ty = |
|
969 |
old_exchange_ty rty qty ty |
|
970 |
fun mk_rep tm = |
|
971 |
let |
|
972 |
val ty = old_exchange_ty rty qty (fastype_of tm) |
|
973 |
in fst (old_get_fun repF rty qty lthy ty) $ tm end; |
|
974 |
fun mk_abs tm = |
|
975 |
let |
|
976 |
val ty = old_exchange_ty rty qty (fastype_of tm) in |
|
977 |
fst (old_get_fun absF rty qty lthy ty) $ tm end; |
|
978 |
val (l, ltl) = Term.strip_type ty; |
|
979 |
val nl = map absty l; |
|
980 |
val vs = map (fn _ => "x") l; |
|
981 |
val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy; |
|
982 |
val args = map Free (vfs ~~ nl); |
|
983 |
val lhs = list_comb((Free (fname, nl ---> ltl)), args); |
|
984 |
val rargs = map mk_rep args; |
|
985 |
val f = Free (fname, nl ---> ltl); |
|
986 |
val rhs = mk_abs (list_comb((mk_rep f), rargs)); |
|
987 |
val eq = Logic.mk_equals (rhs, lhs); |
|
988 |
val ceq = cterm_of (ProofContext.theory_of lthy') eq; |
|
989 |
val sctxt = (Simplifier.context lthy' HOL_ss) addsimps (absrep :: @{thms fun_map.simps}); |
|
990 |
val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1) |
|
991 |
val t_id = MetaSimplifier.rewrite_rule @{thms id_def_sym} t; |
|
992 |
in |
|
993 |
singleton (ProofContext.export lthy' lthy) t_id |
|
994 |
end |
|
995 |
*} |
|
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
996 |
|
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
997 |
ML {* |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
998 |
fun lookup_quot_data lthy qty = |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
999 |
let |
257
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
1000 |
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
|
1001 |
val rty = Logic.unvarifyT (#rtyp quotdata) |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1002 |
val rel = #rel quotdata |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1003 |
val rel_eqv = #equiv_thm quotdata |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1004 |
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
|
1005 |
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
|
1006 |
in |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1007 |
(rty, rel, rel_refl, rel_eqv) |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1008 |
end |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1009 |
*} |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1010 |
|
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1011 |
ML {* |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1012 |
fun lookup_quot_thms lthy qty_name = |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1013 |
let |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1014 |
val thy = ProofContext.theory_of lthy; |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1015 |
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
|
1016 |
val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same") |
269 | 1017 |
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
|
1018 |
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
|
1019 |
in |
269 | 1020 |
(trans2, reps_same, absrep, quot) |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1021 |
end |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1022 |
*} |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1023 |
|
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1024 |
ML {* |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1025 |
fun lookup_quot_consts defs = |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1026 |
let |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1027 |
fun dest_term (a $ b) = (a, b); |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1028 |
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
|
1029 |
in |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1030 |
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
|
1031 |
end |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1032 |
*} |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1033 |
|
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1034 |
ML {* |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1035 |
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
|
1036 |
val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data lthy qty; |
269 | 1037 |
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
|
1038 |
val consts = lookup_quot_consts defs; |
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
1039 |
val t_a = atomize_thm t; |
251 | 1040 |
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
|
1041 |
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
|
1042 |
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
|
1043 |
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
|
1044 |
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
|
1045 |
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
|
1046 |
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
|
1047 |
val aps = findaps rty (prop_of t_a); |
269 | 1048 |
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
|
1049 |
val lam_prs_thms = map (make_simp_prs_thm lthy quot @{thm LAMBDA_PRS}) abs; |
259 | 1050 |
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
|
1051 |
val defs_sym = add_lower_defs lthy defs; |
259 | 1052 |
val defs_sym_eq = map (fn x => eq_reflection OF [x]) defs_sym; |
1053 |
val t_d0 = MetaSimplifier.rewrite_rule defs_sym_eq t_l; |
|
1054 |
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
|
1055 |
val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
1056 |
in |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
1057 |
ObjectLogic.rulify t_r |
187 | 1058 |
end |
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
1059 |
*} |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
1060 |
|
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1061 |
|
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
1062 |
end |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1063 |