author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Wed, 28 Oct 2009 16:05:59 +0100 | |
changeset 221 | f219011a5e3c |
parent 219 | 329111e1c4ba |
child 223 | 9d7d9236d9f9 |
permissions | -rw-r--r-- |
0 | 1 |
theory QuotMain |
6 | 2 |
imports QuotScript QuotList Prove |
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
70
diff
changeset
|
3 |
uses ("quotient.ML") |
0 | 4 |
begin |
5 |
||
6 |
locale QUOT_TYPE = |
|
7 |
fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
|
8 |
and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b" |
|
9 |
and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)" |
|
10 |
assumes equiv: "EQUIV R" |
|
11 |
and rep_prop: "\<And>y. \<exists>x. Rep y = R x" |
|
12 |
and rep_inverse: "\<And>x. Abs (Rep x) = x" |
|
13 |
and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)" |
|
14 |
and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)" |
|
15 | 15 |
begin |
0 | 16 |
|
17 |
definition |
|
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
18 |
ABS::"'a \<Rightarrow> 'b" |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
19 |
where |
0 | 20 |
"ABS x \<equiv> Abs (R x)" |
21 |
||
22 |
definition |
|
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
23 |
REP::"'b \<Rightarrow> 'a" |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
24 |
where |
0 | 25 |
"REP a = Eps (Rep a)" |
26 |
||
15 | 27 |
lemma lem9: |
0 | 28 |
shows "R (Eps (R x)) = R x" |
29 |
proof - |
|
30 |
have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def) |
|
31 |
then have "R x (Eps (R x))" by (rule someI) |
|
15 | 32 |
then show "R (Eps (R x)) = R x" |
0 | 33 |
using equiv unfolding EQUIV_def by simp |
34 |
qed |
|
35 |
||
36 |
theorem thm10: |
|
24
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
37 |
shows "ABS (REP a) \<equiv> a" |
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
38 |
apply (rule eq_reflection) |
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
39 |
unfolding ABS_def REP_def |
0 | 40 |
proof - |
15 | 41 |
from rep_prop |
0 | 42 |
obtain x where eq: "Rep a = R x" by auto |
43 |
have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp |
|
44 |
also have "\<dots> = Abs (R x)" using lem9 by simp |
|
45 |
also have "\<dots> = Abs (Rep a)" using eq by simp |
|
46 |
also have "\<dots> = a" using rep_inverse by simp |
|
47 |
finally |
|
48 |
show "Abs (R (Eps (Rep a))) = a" by simp |
|
49 |
qed |
|
50 |
||
15 | 51 |
lemma REP_refl: |
0 | 52 |
shows "R (REP a) (REP a)" |
53 |
unfolding REP_def |
|
54 |
by (simp add: equiv[simplified EQUIV_def]) |
|
55 |
||
56 |
lemma lem7: |
|
22 | 57 |
shows "(R x = R y) = (Abs (R x) = Abs (R y))" |
0 | 58 |
apply(rule iffI) |
59 |
apply(simp) |
|
60 |
apply(drule rep_inject[THEN iffD2]) |
|
61 |
apply(simp add: abs_inverse) |
|
62 |
done |
|
15 | 63 |
|
0 | 64 |
theorem thm11: |
65 |
shows "R r r' = (ABS r = ABS r')" |
|
66 |
unfolding ABS_def |
|
67 |
by (simp only: equiv[simplified EQUIV_def] lem7) |
|
68 |
||
4 | 69 |
|
2 | 70 |
lemma REP_ABS_rsp: |
4 | 71 |
shows "R f (REP (ABS g)) = R f g" |
72 |
and "R (REP (ABS g)) f = R g f" |
|
23 | 73 |
by (simp_all add: thm10 thm11) |
4 | 74 |
|
0 | 75 |
lemma QUOTIENT: |
76 |
"QUOTIENT R ABS REP" |
|
77 |
apply(unfold QUOTIENT_def) |
|
78 |
apply(simp add: thm10) |
|
79 |
apply(simp add: REP_refl) |
|
80 |
apply(subst thm11[symmetric]) |
|
81 |
apply(simp add: equiv[simplified EQUIV_def]) |
|
82 |
done |
|
83 |
||
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
84 |
lemma R_trans: |
49 | 85 |
assumes ab: "R a b" |
86 |
and bc: "R b c" |
|
22 | 87 |
shows "R a c" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
88 |
proof - |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
89 |
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
|
90 |
moreover have ab: "R a b" by fact |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
91 |
moreover have bc: "R b c" by fact |
22 | 92 |
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
|
93 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
94 |
|
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
95 |
lemma R_sym: |
49 | 96 |
assumes ab: "R a b" |
22 | 97 |
shows "R b a" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
98 |
proof - |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
99 |
have re: "SYM R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
22 | 100 |
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
|
101 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
102 |
|
49 | 103 |
lemma R_trans2: |
104 |
assumes ac: "R a c" |
|
22 | 105 |
and bd: "R b d" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
106 |
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
|
107 |
using ac bd |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
108 |
by (blast intro: R_trans R_sym) |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
109 |
|
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
110 |
lemma REPS_same: |
25
9020ee23a020
The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
24
diff
changeset
|
111 |
shows "R (REP a) (REP b) \<equiv> (a = b)" |
38 | 112 |
proof - |
113 |
have "R (REP a) (REP b) = (a = b)" |
|
114 |
proof |
|
115 |
assume as: "R (REP a) (REP b)" |
|
116 |
from rep_prop |
|
117 |
obtain x y |
|
118 |
where eqs: "Rep a = R x" "Rep b = R y" by blast |
|
119 |
from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp |
|
120 |
then have "R x (Eps (R y))" using lem9 by simp |
|
121 |
then have "R (Eps (R y)) x" using R_sym by blast |
|
122 |
then have "R y x" using lem9 by simp |
|
123 |
then have "R x y" using R_sym by blast |
|
124 |
then have "ABS x = ABS y" using thm11 by simp |
|
125 |
then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp |
|
126 |
then show "a = b" using rep_inverse by simp |
|
127 |
next |
|
128 |
assume ab: "a = b" |
|
129 |
have "REFL R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
|
130 |
then show "R (REP a) (REP b)" unfolding REFL_def using ab by auto |
|
131 |
qed |
|
132 |
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
|
133 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
134 |
|
0 | 135 |
end |
136 |
||
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
|
137 |
|
0 | 138 |
section {* type definition for the quotient type *} |
139 |
||
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
70
diff
changeset
|
140 |
use "quotient.ML" |
0 | 141 |
|
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
142 |
declare [[map list = (map, LIST_REL)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
143 |
declare [[map * = (prod_fun, prod_rel)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
144 |
declare [[map "fun" = (fun_map, FUN_REL)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
145 |
|
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
146 |
ML {* maps_lookup @{theory} "List.list" *} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
147 |
ML {* maps_lookup @{theory} "*" *} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
148 |
ML {* maps_lookup @{theory} "fun" *} |
174
09048a951dca
moved the map_funs setup into QuotMain
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
149 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
150 |
text {* FIXME: auxiliary function *} |
193 | 151 |
ML {* |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
152 |
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
|
153 |
let |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
154 |
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
|
155 |
val ((_, [th']), _) = Variable.import true [th] ctxt; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
156 |
in th' end); |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
157 |
*} |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
158 |
|
0 | 159 |
section {* lifting of constants *} |
160 |
||
161 |
ML {* |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
162 |
(* whether ty1 is an instance of ty2 *) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
163 |
fun matches (ty1, ty2) = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
164 |
Type.raw_instance (ty1, Logic.varifyT ty2) |
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
165 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
166 |
fun lookup_snd _ [] _ = NONE |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
167 |
| lookup_snd eq ((value, key)::xs) key' = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
168 |
if eq (key', key) then SOME value |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
169 |
else lookup_snd eq xs key'; |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
170 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
171 |
fun lookup_qenv qenv qty = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
172 |
(case (AList.lookup matches qenv qty) of |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
173 |
SOME rty => SOME (qty, rty) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
174 |
| NONE => NONE) |
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
175 |
*} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
176 |
|
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
177 |
ML {* |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
178 |
(* 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
|
179 |
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
|
180 |
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
|
181 |
change |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
182 |
*) |
46 | 183 |
datatype flag = absF | repF |
0 | 184 |
|
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
|
185 |
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
|
186 |
| 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
|
187 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
188 |
fun get_fun flag qenv lthy ty = |
0 | 189 |
let |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
190 |
|
0 | 191 |
fun get_fun_aux s fs_tys = |
192 |
let |
|
193 |
val (fs, tys) = split_list fs_tys |
|
15 | 194 |
val (otys, ntys) = split_list tys |
0 | 195 |
val oty = Type (s, otys) |
196 |
val nty = Type (s, ntys) |
|
197 |
val ftys = map (op -->) tys |
|
198 |
in |
|
130
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
129
diff
changeset
|
199 |
(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
|
200 |
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
|
201 |
| 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
|
202 |
end |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
203 |
|
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
204 |
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
|
205 |
let |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
206 |
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
|
207 |
val ([oty1, oty2], [nty1, nty2]) = split_list tys |
128 | 208 |
val oty = nty1 --> oty2 |
209 |
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
|
210 |
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
|
211 |
in |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
212 |
(list_comb (Const (@{const_name "fun_map"}, ftys ---> oty --> nty), fs), (oty, nty)) |
0 | 213 |
end |
214 |
||
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
215 |
fun get_const flag (qty, rty) = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
216 |
let |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
217 |
val thy = ProofContext.theory_of lthy |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
218 |
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
|
219 |
in |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
220 |
case flag of |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
221 |
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
|
222 |
| 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
|
223 |
end |
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
224 |
|
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
|
225 |
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
|
226 |
|
0 | 227 |
in |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
228 |
if (AList.defined matches qenv ty) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
229 |
then (get_const flag (the (lookup_qenv qenv ty))) |
0 | 230 |
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
|
231 |
TFree _ => (mk_identity ty, (ty, ty)) |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
232 |
| 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
|
233 |
| Type ("fun" , [ty1, ty2]) => |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
234 |
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
|
235 |
| 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
|
236 |
| _ => raise ERROR ("no type variables") |
0 | 237 |
) |
238 |
end |
|
239 |
*} |
|
240 |
||
180
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
241 |
|
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
242 |
text {* produces the definition for a lifted constant *} |
86 | 243 |
|
2 | 244 |
ML {* |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
245 |
fun get_const_def nconst otrm qenv lthy = |
0 | 246 |
let |
247 |
val ty = fastype_of nconst |
|
248 |
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
|
249 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
250 |
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
|
251 |
val abs_fn = (fst o get_fun absF qenv lthy) res_ty |
0 | 252 |
|
180
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
253 |
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
|
254 |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
255 |
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
|
256 |
|> Syntax.check_term lthy |
0 | 257 |
in |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
258 |
fns $ otrm |
0 | 259 |
end |
260 |
*} |
|
261 |
||
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
262 |
ML {* lookup_snd *} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
263 |
|
0 | 264 |
ML {* |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
265 |
fun exchange_ty qenv ty = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
266 |
case (lookup_snd matches qenv ty) of |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
267 |
SOME qty => qty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
268 |
| NONE => |
0 | 269 |
(case ty of |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
270 |
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
|
271 |
| _ => ty |
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
272 |
) |
0 | 273 |
*} |
274 |
||
275 |
ML {* |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
276 |
fun make_const_def nconst_bname otrm mx qenv lthy = |
0 | 277 |
let |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
278 |
val otrm_ty = fastype_of otrm |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
279 |
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
|
280 |
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
|
281 |
val def_trm = get_const_def nconst otrm qenv lthy |
0 | 282 |
in |
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
77
diff
changeset
|
283 |
define (nconst_bname, mx, def_trm) lthy |
15 | 284 |
end |
0 | 285 |
*} |
286 |
||
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
287 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
288 |
fun build_qenv lthy qtys = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
289 |
let |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
290 |
val qenv = map (fn {qtyp, rtyp, ...} => (qtyp, rtyp)) (quotdata_lookup lthy) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
291 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
292 |
fun find_assoc qty = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
293 |
case (AList.lookup matches qenv qty) of |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
294 |
SOME rty => (qty, rty) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
295 |
| NONE => error (implode |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
296 |
["Quotient type ", |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
297 |
quote (Syntax.string_of_typ lthy qty), |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
298 |
" does not exists"]) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
299 |
in |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
300 |
map find_assoc qtys |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
301 |
end |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
302 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
303 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
304 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
305 |
(* taken from isar_syn.ML *) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
306 |
val constdecl = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
307 |
OuterParse.binding -- |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
308 |
(OuterParse.where_ >> K (NONE, NoSyn) || |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
309 |
OuterParse.$$$ "::" |-- OuterParse.!!! ((OuterParse.typ >> SOME) -- |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
310 |
OuterParse.opt_mixfix' --| OuterParse.where_) || |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
311 |
Scan.ahead (OuterParse.$$$ "(") |-- |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
312 |
OuterParse.!!! (OuterParse.mixfix' --| OuterParse.where_ >> pair NONE)) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
313 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
314 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
315 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
316 |
val qd_parser = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
317 |
(Args.parens (OuterParse.$$$ "for" |-- (Scan.repeat OuterParse.typ))) -- |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
318 |
(constdecl -- (SpecParse.opt_thm_name ":" -- OuterParse.prop)) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
319 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
320 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
321 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
322 |
fun pair lthy (ty1, ty2) = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
323 |
"(" ^ (Syntax.string_of_typ lthy ty1) ^ "," ^ (Syntax.string_of_typ lthy ty2) ^ ")" |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
324 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
325 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
326 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
327 |
fun parse_qd_spec (qtystrs, ((bind, (typstr__, mx)), (attr__, propstr))) lthy = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
328 |
let |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
329 |
val qtys = map (Syntax.check_typ lthy o Syntax.parse_typ lthy) qtystrs |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
330 |
val qenv = build_qenv lthy qtys |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
331 |
val prop = Syntax.parse_prop lthy propstr |> Syntax.check_prop lthy |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
332 |
val (lhs, rhs) = Logic.dest_equals prop |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
333 |
in |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
334 |
make_const_def bind rhs mx qenv lthy |> snd |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
335 |
end |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
336 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
337 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
338 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
339 |
val _ = OuterSyntax.local_theory "quotient_def" "lifted definition of constants" |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
340 |
OuterKeyword.thy_decl (qd_parser >> parse_qd_spec) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
341 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
342 |
|
139 | 343 |
section {* ATOMIZE *} |
344 |
||
345 |
text {* |
|
346 |
Unabs_def converts a definition given as |
|
347 |
||
348 |
c \<equiv> %x. %y. f x y |
|
349 |
||
350 |
to a theorem of the form |
|
351 |
||
352 |
c x y \<equiv> f x y |
|
353 |
||
354 |
This function is needed to rewrite the right-hand |
|
355 |
side to the left-hand side. |
|
356 |
*} |
|
357 |
||
358 |
ML {* |
|
359 |
fun unabs_def ctxt def = |
|
360 |
let |
|
361 |
val (lhs, rhs) = Thm.dest_equals (cprop_of def) |
|
362 |
val xs = strip_abs_vars (term_of rhs) |
|
363 |
val (_, ctxt') = Variable.add_fixes (map fst xs) ctxt |
|
364 |
||
365 |
val thy = ProofContext.theory_of ctxt' |
|
366 |
val cxs = map (cterm_of thy o Free) xs |
|
367 |
val new_lhs = Drule.list_comb (lhs, cxs) |
|
368 |
||
369 |
fun get_conv [] = Conv.rewr_conv def |
|
370 |
| get_conv (x::xs) = Conv.fun_conv (get_conv xs) |
|
371 |
in |
|
372 |
get_conv xs new_lhs |> |
|
373 |
singleton (ProofContext.export ctxt' ctxt) |
|
374 |
end |
|
375 |
*} |
|
376 |
||
377 |
lemma atomize_eqv[atomize]: |
|
378 |
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" |
|
379 |
proof |
|
380 |
assume "A \<equiv> B" |
|
381 |
then show "Trueprop A \<equiv> Trueprop B" by unfold |
|
382 |
next |
|
383 |
assume *: "Trueprop A \<equiv> Trueprop B" |
|
384 |
have "A = B" |
|
385 |
proof (cases A) |
|
386 |
case True |
|
387 |
have "A" by fact |
|
388 |
then show "A = B" using * by simp |
|
389 |
next |
|
390 |
case False |
|
391 |
have "\<not>A" by fact |
|
392 |
then show "A = B" using * by auto |
|
393 |
qed |
|
394 |
then show "A \<equiv> B" by (rule eq_reflection) |
|
395 |
qed |
|
396 |
||
397 |
ML {* |
|
398 |
fun atomize_thm thm = |
|
399 |
let |
|
221 | 400 |
val thm' = Thm.freezeT (forall_intr_vars thm) |
139 | 401 |
val thm'' = ObjectLogic.atomize (cprop_of thm') |
402 |
in |
|
221 | 403 |
@{thm Pure.equal_elim_rule1} OF [thm'', thm'] |
139 | 404 |
end |
405 |
*} |
|
406 |
||
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
407 |
ML {* atomize_thm @{thm list.induct} *} |
139 | 408 |
|
409 |
section {* REGULARIZE *} |
|
410 |
||
411 |
text {* tyRel takes a type and builds a relation that a quantifier over this |
|
412 |
type needs to respect. *} |
|
413 |
ML {* |
|
414 |
fun tyRel ty rty rel lthy = |
|
415 |
if ty = rty |
|
416 |
then rel |
|
417 |
else (case ty of |
|
418 |
Type (s, tys) => |
|
419 |
let |
|
420 |
val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys; |
|
421 |
val ty_out = ty --> ty --> @{typ bool}; |
|
422 |
val tys_out = tys_rel ---> ty_out; |
|
423 |
in |
|
424 |
(case (maps_lookup (ProofContext.theory_of lthy) s) of |
|
425 |
SOME (info) => list_comb (Const (#relfun info, tys_out), map (fn ty => tyRel ty rty rel lthy) tys) |
|
426 |
| NONE => HOLogic.eq_const ty |
|
427 |
) |
|
428 |
end |
|
429 |
| _ => HOLogic.eq_const ty) |
|
430 |
*} |
|
431 |
||
432 |
definition |
|
433 |
Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" |
|
434 |
where |
|
435 |
"(x \<in> p) \<Longrightarrow> (Babs p m x = m x)" |
|
436 |
(* TODO: Consider defining it with an "if"; sth like: |
|
437 |
Babs p m = \<lambda>x. if x \<in> p then m x else undefined |
|
438 |
*) |
|
439 |
||
440 |
ML {* |
|
441 |
fun needs_lift (rty as Type (rty_s, _)) ty = |
|
442 |
case ty of |
|
443 |
Type (s, tys) => |
|
444 |
(s = rty_s) orelse (exists (needs_lift rty) tys) |
|
445 |
| _ => false |
|
446 |
||
447 |
*} |
|
448 |
||
449 |
ML {* |
|
450 |
(* trm \<Rightarrow> new_trm *) |
|
451 |
fun regularise trm rty rel lthy = |
|
452 |
case trm of |
|
453 |
Abs (x, T, t) => |
|
454 |
if (needs_lift rty T) then let |
|
455 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
456 |
val v = Free (x', T); |
|
457 |
val t' = subst_bound (v, t); |
|
458 |
val rec_term = regularise t' rty rel lthy2; |
|
459 |
val lam_term = Term.lambda_name (x, v) rec_term; |
|
460 |
val sub_res_term = tyRel T rty rel lthy; |
|
461 |
val respects = Const (@{const_name Respects}, (fastype_of sub_res_term) --> T --> @{typ bool}); |
|
462 |
val res_term = respects $ sub_res_term; |
|
463 |
val ty = fastype_of trm; |
|
464 |
val rabs = Const (@{const_name Babs}, (fastype_of res_term) --> ty --> ty); |
|
465 |
val rabs_term = (rabs $ res_term) $ lam_term; |
|
466 |
in |
|
467 |
rabs_term |
|
468 |
end else let |
|
469 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
470 |
val v = Free (x', T); |
|
471 |
val t' = subst_bound (v, t); |
|
472 |
val rec_term = regularise t' rty rel lthy2; |
|
473 |
in |
|
474 |
Term.lambda_name (x, v) rec_term |
|
475 |
end |
|
476 |
| ((Const (@{const_name "All"}, at)) $ (Abs (x, T, t))) => |
|
477 |
if (needs_lift rty T) then let |
|
478 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
479 |
val v = Free (x', T); |
|
480 |
val t' = subst_bound (v, t); |
|
481 |
val rec_term = regularise t' rty rel lthy2; |
|
482 |
val lam_term = Term.lambda_name (x, v) rec_term; |
|
483 |
val sub_res_term = tyRel T rty rel lthy; |
|
484 |
val respects = Const (@{const_name Respects}, (fastype_of sub_res_term) --> T --> @{typ bool}); |
|
485 |
val res_term = respects $ sub_res_term; |
|
486 |
val ty = fastype_of lam_term; |
|
487 |
val rall = Const (@{const_name Ball}, (fastype_of res_term) --> ty --> @{typ bool}); |
|
488 |
val rall_term = (rall $ res_term) $ lam_term; |
|
489 |
in |
|
490 |
rall_term |
|
491 |
end else let |
|
492 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
493 |
val v = Free (x', T); |
|
494 |
val t' = subst_bound (v, t); |
|
495 |
val rec_term = regularise t' rty rel lthy2; |
|
496 |
val lam_term = Term.lambda_name (x, v) rec_term |
|
497 |
in |
|
498 |
Const(@{const_name "All"}, at) $ lam_term |
|
499 |
end |
|
500 |
| ((Const (@{const_name "All"}, at)) $ P) => |
|
501 |
let |
|
502 |
val (_, [al, _]) = dest_Type (fastype_of P); |
|
503 |
val ([x], lthy2) = Variable.variant_fixes [""] lthy; |
|
504 |
val v = (Free (x, al)); |
|
505 |
val abs = Term.lambda_name (x, v) (P $ v); |
|
506 |
in regularise ((Const (@{const_name "All"}, at)) $ abs) rty rel lthy2 end |
|
507 |
| ((Const (@{const_name "Ex"}, at)) $ (Abs (x, T, t))) => |
|
508 |
if (needs_lift rty T) then let |
|
509 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
510 |
val v = Free (x', T); |
|
511 |
val t' = subst_bound (v, t); |
|
512 |
val rec_term = regularise t' rty rel lthy2; |
|
513 |
val lam_term = Term.lambda_name (x, v) rec_term; |
|
514 |
val sub_res_term = tyRel T rty rel lthy; |
|
515 |
val respects = Const (@{const_name Respects}, (fastype_of sub_res_term) --> T --> @{typ bool}); |
|
516 |
val res_term = respects $ sub_res_term; |
|
517 |
val ty = fastype_of lam_term; |
|
518 |
val rall = Const (@{const_name Bex}, (fastype_of res_term) --> ty --> @{typ bool}); |
|
519 |
val rall_term = (rall $ res_term) $ lam_term; |
|
520 |
in |
|
521 |
rall_term |
|
522 |
end else let |
|
523 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
524 |
val v = Free (x', T); |
|
525 |
val t' = subst_bound (v, t); |
|
526 |
val rec_term = regularise t' rty rel lthy2; |
|
527 |
val lam_term = Term.lambda_name (x, v) rec_term |
|
528 |
in |
|
529 |
Const(@{const_name "Ex"}, at) $ lam_term |
|
530 |
end |
|
531 |
| ((Const (@{const_name "Ex"}, at)) $ P) => |
|
532 |
let |
|
533 |
val (_, [al, _]) = dest_Type (fastype_of P); |
|
534 |
val ([x], lthy2) = Variable.variant_fixes [""] lthy; |
|
535 |
val v = (Free (x, al)); |
|
536 |
val abs = Term.lambda_name (x, v) (P $ v); |
|
537 |
in regularise ((Const (@{const_name "Ex"}, at)) $ abs) rty rel lthy2 end |
|
538 |
| a $ b => (regularise a rty rel lthy) $ (regularise b rty rel lthy) |
|
539 |
| _ => trm |
|
540 |
||
541 |
*} |
|
542 |
||
543 |
(* my version of regularise *) |
|
544 |
(****************************) |
|
545 |
||
546 |
(* some helper functions *) |
|
547 |
||
548 |
||
549 |
ML {* |
|
550 |
fun mk_babs ty ty' = Const (@{const_name "Babs"}, [ty' --> @{typ bool}, ty] ---> ty) |
|
551 |
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool}) |
|
552 |
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool}) |
|
553 |
fun mk_resp ty = Const (@{const_name Respects}, [[ty, ty] ---> @{typ bool}, ty] ---> @{typ bool}) |
|
554 |
*} |
|
555 |
||
556 |
(* applies f to the subterm of an abstractions, otherwise to the given term *) |
|
557 |
ML {* |
|
558 |
fun apply_subt f trm = |
|
559 |
case trm of |
|
145 | 560 |
Abs (x, T, t) => |
561 |
let |
|
562 |
val (x', t') = Term.dest_abs (x, T, t) |
|
563 |
in |
|
564 |
Term.absfree (x', T, f t') |
|
565 |
end |
|
139 | 566 |
| _ => f trm |
567 |
*} |
|
568 |
||
569 |
||
570 |
(* FIXME: assumes always the typ is qty! *) |
|
571 |
(* FIXME: if there are more than one quotient, then you have to look up the relation *) |
|
572 |
ML {* |
|
573 |
fun my_reg rel trm = |
|
574 |
case trm of |
|
575 |
Abs (x, T, t) => |
|
576 |
let |
|
577 |
val ty1 = fastype_of trm |
|
578 |
in |
|
146 | 579 |
(mk_babs ty1 T) $ (mk_resp T $ rel) $ (apply_subt (my_reg rel) trm) |
139 | 580 |
end |
581 |
| Const (@{const_name "All"}, ty) $ t => |
|
582 |
let |
|
583 |
val ty1 = domain_type ty |
|
584 |
val ty2 = domain_type ty1 |
|
585 |
in |
|
586 |
(mk_ball ty1) $ (mk_resp ty2 $ rel) $ (apply_subt (my_reg rel) t) |
|
587 |
end |
|
588 |
| Const (@{const_name "Ex"}, ty) $ t => |
|
589 |
let |
|
590 |
val ty1 = domain_type ty |
|
591 |
val ty2 = domain_type ty1 |
|
592 |
in |
|
593 |
(mk_bex ty1) $ (mk_resp ty2 $ rel) $ (apply_subt (my_reg rel) t) |
|
594 |
end |
|
595 |
| t1 $ t2 => (my_reg rel t1) $ (my_reg rel t2) |
|
596 |
| _ => trm |
|
597 |
*} |
|
598 |
||
599 |
||
600 |
(*fun prove_reg trm \<Rightarrow> thm (we might need some facts to do this) |
|
601 |
trm == new_trm |
|
602 |
*) |
|
603 |
||
141
0ffc37761e53
Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
140
diff
changeset
|
604 |
text {* Assumes that the given theorem is atomized *} |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
605 |
ML {* |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
606 |
fun build_regularize_goal thm rty rel lthy = |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
607 |
Logic.mk_implies |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
608 |
((prop_of thm), |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
609 |
(regularise (prop_of thm) rty rel lthy)) |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
610 |
*} |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
611 |
|
187 | 612 |
ML {* |
613 |
fun regularize thm rty rel rel_eqv lthy = |
|
614 |
let |
|
615 |
val g = build_regularize_goal thm rty rel lthy; |
|
616 |
fun tac ctxt = |
|
617 |
(asm_full_simp_tac ((Simplifier.context ctxt HOL_ss) addsimps |
|
618 |
[(@{thm equiv_res_forall} OF [rel_eqv]), |
|
619 |
(@{thm equiv_res_exists} OF [rel_eqv])])) THEN_ALL_NEW |
|
620 |
(((rtac @{thm RIGHT_RES_FORALL_REGULAR}) THEN' (RANGE [fn _ => all_tac, atac]) THEN' |
|
621 |
(MetisTools.metis_tac ctxt [])) ORELSE' (MetisTools.metis_tac ctxt [])); |
|
622 |
val cthm = Goal.prove lthy [] [] g (fn x => tac (#context x) 1); |
|
623 |
in |
|
624 |
cthm OF [thm] |
|
625 |
end |
|
626 |
*} |
|
627 |
||
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
628 |
section {* RepAbs injection *} |
139 | 629 |
|
161
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
630 |
(* 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
|
631 |
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
|
632 |
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
|
633 |
|
139 | 634 |
ML {* |
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
635 |
fun old_exchange_ty rty qty ty = |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
636 |
if ty = rty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
637 |
then qty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
638 |
else |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
639 |
(case ty of |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
640 |
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
|
641 |
| _ => ty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
642 |
) |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
643 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
644 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
645 |
ML {* |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
646 |
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
|
647 |
get_fun flag [(qty, rty)] lthy ty |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
648 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
649 |
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
|
650 |
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
|
651 |
*} |
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
652 |
|
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
653 |
ML {* |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
654 |
fun build_repabs_term lthy thm constructors rty qty = |
139 | 655 |
let |
656 |
fun mk_rep tm = |
|
657 |
let |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
658 |
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
|
659 |
in fst (old_get_fun repF rty qty lthy ty) $ tm end |
139 | 660 |
|
661 |
fun mk_abs tm = |
|
662 |
let |
|
218
df05cd030d2f
added infrastructure for defining lifted constants
Christian Urban <urbanc@in.tum.de>
parents:
214
diff
changeset
|
663 |
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
|
664 |
fst (old_get_fun absF rty qty lthy ty) $ tm end |
139 | 665 |
|
666 |
fun is_constructor (Const (x, _)) = member (op =) constructors x |
|
667 |
| is_constructor _ = false; |
|
668 |
||
669 |
fun build_aux lthy tm = |
|
670 |
case tm of |
|
671 |
Abs (a as (_, vty, _)) => |
|
672 |
let |
|
673 |
val (vs, t) = Term.dest_abs a; |
|
674 |
val v = Free(vs, vty); |
|
675 |
val t' = lambda v (build_aux lthy t) |
|
676 |
in |
|
677 |
if (not (needs_lift rty (fastype_of tm))) then t' |
|
678 |
else mk_rep (mk_abs ( |
|
679 |
if not (needs_lift rty vty) then t' |
|
680 |
else |
|
681 |
let |
|
682 |
val v' = mk_rep (mk_abs v); |
|
683 |
val t1 = Envir.beta_norm (t' $ v') |
|
684 |
in |
|
685 |
lambda v t1 |
|
686 |
end |
|
687 |
)) |
|
688 |
end |
|
689 |
| x => |
|
690 |
let |
|
691 |
val (opp, tms0) = Term.strip_comb tm |
|
692 |
val tms = map (build_aux lthy) tms0 |
|
693 |
val ty = fastype_of tm |
|
694 |
in |
|
695 |
if (((fst (Term.dest_Const opp)) = @{const_name Respects}) handle _ => false) |
|
696 |
then (list_comb (opp, (hd tms0) :: (tl tms))) |
|
697 |
else if (is_constructor opp andalso needs_lift rty ty) then |
|
698 |
mk_rep (mk_abs (list_comb (opp,tms))) |
|
699 |
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
|
700 |
mk_rep(mk_abs(list_comb(opp,tms))) |
139 | 701 |
else if tms = [] then opp |
702 |
else list_comb(opp, tms) |
|
703 |
end |
|
704 |
in |
|
161
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
705 |
MetaSimplifier.rewrite_term @{theory} @{thms id_def_sym} [] |
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
706 |
(build_aux lthy (Thm.prop_of thm)) |
139 | 707 |
end |
708 |
*} |
|
709 |
||
141
0ffc37761e53
Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
140
diff
changeset
|
710 |
text {* Assumes that it is given a regularized theorem *} |
139 | 711 |
ML {* |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
712 |
fun build_repabs_goal ctxt thm cons rty qty = |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
713 |
Logic.mk_equals ((Thm.prop_of thm), (build_repabs_term ctxt thm cons rty qty)) |
139 | 714 |
*} |
715 |
||
187 | 716 |
ML {* |
717 |
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} => |
|
718 |
let |
|
719 |
val pat = Drule.strip_imp_concl (cprop_of thm) |
|
720 |
val insts = Thm.match (pat, concl) |
|
721 |
in |
|
722 |
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
|
723 |
end |
187 | 724 |
handle _ => no_tac |
725 |
) |
|
726 |
*} |
|
727 |
||
728 |
ML {* |
|
729 |
fun res_forall_rsp_tac ctxt = |
|
730 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
731 |
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI} |
|
732 |
THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN' |
|
733 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
734 |
*} |
|
735 |
||
736 |
ML {* |
|
737 |
fun res_exists_rsp_tac ctxt = |
|
738 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
739 |
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI} |
|
740 |
THEN' instantiate_tac @{thm RES_EXISTS_RSP} ctxt THEN' |
|
741 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
742 |
*} |
|
743 |
||
744 |
||
745 |
ML {* |
|
746 |
fun quotient_tac quot_thm = |
|
747 |
REPEAT_ALL_NEW (FIRST' [ |
|
748 |
rtac @{thm FUN_QUOTIENT}, |
|
749 |
rtac quot_thm, |
|
750 |
rtac @{thm IDENTITY_QUOTIENT} |
|
751 |
]) |
|
752 |
*} |
|
753 |
||
754 |
ML {* |
|
755 |
fun LAMBDA_RES_TAC ctxt i st = |
|
756 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
757 |
(_ $ (_ $ (Abs(_,_,_))$(Abs(_,_,_)))) => |
|
758 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
759 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
760 |
| _ => fn _ => no_tac) i st |
|
761 |
*} |
|
762 |
||
763 |
ML {* |
|
764 |
fun WEAK_LAMBDA_RES_TAC ctxt i st = |
|
765 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
766 |
(_ $ (_ $ _$(Abs(_,_,_)))) => |
|
767 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
768 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
769 |
| (_ $ (_ $ (Abs(_,_,_))$_)) => |
|
770 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
771 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
772 |
| _ => fn _ => no_tac) i st |
|
773 |
*} |
|
774 |
||
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
775 |
ML {* |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
776 |
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
|
777 |
let |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
778 |
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
|
779 |
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
|
780 |
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
|
781 |
in |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
782 |
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
|
783 |
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
|
784 |
else no_tac |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
785 |
end |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
786 |
handle _ => no_tac) |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
787 |
*} |
187 | 788 |
|
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' [ |
792 |
rtac @{thm FUN_QUOTIENT}, |
|
793 |
rtac quot_thm, |
|
794 |
rtac @{thm IDENTITY_QUOTIENT}, |
|
795 |
rtac trans_thm, |
|
796 |
LAMBDA_RES_TAC ctxt, |
|
797 |
res_forall_rsp_tac ctxt, |
|
798 |
res_exists_rsp_tac ctxt, |
|
799 |
( |
|
800 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps rsp_thms)) |
|
801 |
THEN_ALL_NEW (fn _ => no_tac) |
|
802 |
), |
|
803 |
(instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' (RANGE [quotient_tac quot_thm])), |
|
804 |
rtac refl, |
|
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
805 |
(* 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
|
806 |
(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
|
807 |
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
|
808 |
rtac @{thm ext}, |
187 | 809 |
rtac reflex_thm, |
810 |
atac, |
|
811 |
( |
|
812 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
813 |
THEN_ALL_NEW (fn _ => no_tac) |
|
814 |
), |
|
815 |
WEAK_LAMBDA_RES_TAC ctxt |
|
816 |
]) |
|
817 |
*} |
|
818 |
||
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
|
819 |
ML {* |
210
f88ea69331bf
Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
209
diff
changeset
|
820 |
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
|
821 |
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
|
822 |
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
|
823 |
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
|
824 |
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
|
825 |
(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
|
826 |
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
|
827 |
in |
210
f88ea69331bf
Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
209
diff
changeset
|
828 |
@{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
|
829 |
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
|
830 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
831 |
|
187 | 832 |
section {* Cleaning the goal *} |
833 |
||
834 |
text {* Does the same as 'subst' in a given theorem *} |
|
835 |
ML {* |
|
836 |
fun eqsubst_thm ctxt thms thm = |
|
837 |
let |
|
838 |
val goalstate = Goal.init (Thm.cprop_of thm) |
|
839 |
val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of |
|
840 |
NONE => error "eqsubst_thm" |
|
841 |
| SOME th => cprem_of th 1 |
|
842 |
val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1 |
|
843 |
val cgoal = cterm_of (ProofContext.theory_of ctxt) (Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a')) |
|
844 |
val rt = Toplevel.program (fn () => Goal.prove_internal [] cgoal (fn _ => tac)); |
|
845 |
in |
|
209
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
846 |
@{thm Pure.equal_elim_rule1} OF [rt,thm] |
187 | 847 |
end |
848 |
*} |
|
849 |
||
209
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
850 |
ML {* |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
851 |
fun repeat_eqsubst_thm ctxt thms thm = |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
852 |
repeat_eqsubst_thm ctxt thms (eqsubst_thm ctxt thms thm) |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
853 |
handle _ => thm |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
854 |
*} |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
855 |
|
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
|
856 |
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
|
857 |
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
|
858 |
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
|
859 |
let |
209
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
860 |
val e1 = @{thm fun_cong} OF [thm]; |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
861 |
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
|
862 |
val g = MetaSimplifier.rewrite_rule @{thms id_def_sym} f; |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
863 |
val h = repeat_eqsubst_thm ctxt @{thms FUN_MAP_I} g; |
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
864 |
val i = MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] 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
|
865 |
in |
209
1e8e1b736586
map_append lifted automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
207
diff
changeset
|
866 |
thm :: (add_lower_defs_aux ctxt i) |
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
|
867 |
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
|
868 |
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
|
869 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
870 |
|
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
871 |
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
|
872 |
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
|
873 |
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
|
874 |
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
|
875 |
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
|
876 |
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
|
877 |
in |
214 | 878 |
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
|
879 |
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
|
880 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
881 |
|
191
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
882 |
text {* the proper way to do it *} |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
883 |
ML {* |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
884 |
fun findabs rty tm = |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
885 |
case tm of |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
886 |
Abs(_, T, b) => |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
887 |
let |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
888 |
val b' = subst_bound ((Free ("x", T)), b); |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
889 |
val tys = findabs rty b' |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
890 |
val ty = fastype_of tm |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
891 |
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
|
892 |
end |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
893 |
| f $ a => (findabs rty f) @ (findabs rty a) |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
894 |
| _ => [] |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
895 |
*} |
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
|
896 |
|
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
897 |
ML {* |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
898 |
fun make_simp_lam_prs_thm lthy quot_thm typ = |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
899 |
let |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
900 |
val (_, [lty, rty]) = dest_Type typ; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
901 |
val thy = ProofContext.theory_of lthy; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
902 |
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
|
903 |
val inst = [SOME lcty, NONE, SOME rcty]; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
904 |
val lpi = Drule.instantiate' inst [] @{thm LAMBDA_PRS}; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
905 |
val tac = |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
906 |
(compose_tac (false, @{thm LAMBDA_PRS}, 2)) THEN_ALL_NEW |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
907 |
(quotient_tac quot_thm); |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
908 |
val t = Goal.prove lthy [] [] (concl_of lpi) (fn _ => tac 1); |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
909 |
val ts = @{thm HOL.sym} OF [t] |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
910 |
in |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
911 |
MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] ts |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
912 |
end |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
913 |
*} |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
914 |
|
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
915 |
ML {* |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
916 |
fun simp_allex_prs lthy quot thm = |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
917 |
let |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
918 |
val rwf = @{thm FORALL_PRS} OF [quot]; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
919 |
val rwfs = @{thm "HOL.sym"} OF [rwf]; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
920 |
val rwe = @{thm EXISTS_PRS} OF [quot]; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
921 |
val rwes = @{thm "HOL.sym"} OF [rwe] |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
922 |
in |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
923 |
(simp_allex_prs lthy quot (eqsubst_thm lthy [rwfs, rwes] thm)) |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
924 |
end |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
925 |
handle _ => thm |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
926 |
*} |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
927 |
|
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
928 |
ML {* |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
929 |
fun lift_thm lthy consts rty qty rel rel_eqv rel_refl quot rsp_thms trans2 reps_same t_defs t = let |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
930 |
val t_a = atomize_thm t; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
931 |
val t_r = regularize t_a rty rel rel_eqv lthy; |
210
f88ea69331bf
Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
209
diff
changeset
|
932 |
val t_t = repabs lthy t_r consts rty qty quot rel_refl trans2 rsp_thms; |
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
933 |
val abs = findabs rty (prop_of t_a); |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
934 |
val simp_lam_prs_thms = map (make_simp_lam_prs_thm lthy quot) abs; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
935 |
fun simp_lam_prs lthy thm = |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
936 |
simp_lam_prs lthy (eqsubst_thm lthy simp_lam_prs_thms thm) |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
937 |
handle _ => thm |
210
f88ea69331bf
Simplfied interface to repabs_injection.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
209
diff
changeset
|
938 |
val t_l = simp_lam_prs lthy t_t; |
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
939 |
val t_a = simp_allex_prs lthy quot t_l; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
940 |
val t_defs_sym = add_lower_defs lthy t_defs; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
941 |
val t_d = MetaSimplifier.rewrite_rule t_defs_sym t_a; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
942 |
val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
943 |
in |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
944 |
ObjectLogic.rulify t_r |
187 | 945 |
end |
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
946 |
*} |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
947 |
|
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
948 |
end |