author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Tue, 27 Oct 2009 15:00:15 +0100 | |
changeset 207 | 18d7d9dc75cb |
parent 206 | 1e227c9ee915 |
parent 205 | 2a803a1556d5 |
child 209 | 1e8e1b736586 |
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 |
||
203
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
200
diff
changeset
|
140 |
ML {* Proof.theorem_i NONE *} |
7384115df9fd
added equiv-thm to the quot_info
Christian Urban <urbanc@in.tum.de>
parents:
200
diff
changeset
|
141 |
|
71
35be65791f1d
exported parts of QuotMain into a separate ML-file
Christian Urban <urbanc@in.tum.de>
parents:
70
diff
changeset
|
142 |
use "quotient.ML" |
0 | 143 |
|
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
144 |
declare [[map list = (map, LIST_REL)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
145 |
declare [[map * = (prod_fun, prod_rel)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
146 |
declare [[map "fun" = (fun_map, FUN_REL)]] |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
147 |
|
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
148 |
ML {* maps_lookup @{theory} "List.list" *} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
149 |
ML {* maps_lookup @{theory} "*" *} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
150 |
ML {* maps_lookup @{theory} "fun" *} |
174
09048a951dca
moved the map_funs setup into QuotMain
Christian Urban <urbanc@in.tum.de>
parents:
170
diff
changeset
|
151 |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
152 |
ML {* |
193 | 153 |
val quot_def_parser = |
154 |
(OuterParse.$$$ "(" |-- OuterParse.$$$ "with" |-- |
|
205 | 155 |
((OuterParse.list1 OuterParse.typ) --| OuterParse.$$$ ")")) -- |
193 | 156 |
(OuterParse.binding -- |
157 |
Scan.option (OuterParse.$$$ "::" |-- OuterParse.typ) -- |
|
158 |
OuterParse.mixfix --| OuterParse.where_ -- SpecParse.spec) |
|
159 |
*} |
|
160 |
||
161 |
ML {* |
|
162 |
fun test (qrtys, (((bind, typstr), mx), (attr, prop))) lthy = lthy |
|
163 |
*} |
|
164 |
||
165 |
ML {* |
|
166 |
val _ = OuterSyntax.local_theory "quotient_def" "lifted definition" |
|
167 |
OuterKeyword.thy_decl (quot_def_parser >> test) |
|
168 |
*} |
|
169 |
||
170 |
(* FIXME: auxiliary function *) |
|
171 |
ML {* |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
172 |
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
|
173 |
let |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
174 |
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
|
175 |
val ((_, [th']), _) = Variable.import true [th] ctxt; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
176 |
in th' end); |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
177 |
*} |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
178 |
|
0 | 179 |
section {* lifting of constants *} |
180 |
||
181 |
ML {* |
|
185
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
182 |
|
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
183 |
*} |
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
184 |
|
929bc55efff7
added code for declaring map-functions
Christian Urban <urbanc@in.tum.de>
parents:
182
diff
changeset
|
185 |
ML {* |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
186 |
(* 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
|
187 |
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
|
188 |
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
|
189 |
change |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
190 |
*) |
46 | 191 |
datatype flag = absF | repF |
0 | 192 |
|
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
|
193 |
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
|
194 |
| 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
|
195 |
|
46 | 196 |
fun get_fun flag rty qty lthy ty = |
0 | 197 |
let |
198 |
val qty_name = Long_Name.base_name (fst (dest_Type qty)) |
|
15 | 199 |
|
0 | 200 |
fun get_fun_aux s fs_tys = |
201 |
let |
|
202 |
val (fs, tys) = split_list fs_tys |
|
15 | 203 |
val (otys, ntys) = split_list tys |
0 | 204 |
val oty = Type (s, otys) |
205 |
val nty = Type (s, ntys) |
|
206 |
val ftys = map (op -->) tys |
|
207 |
in |
|
130
8e8ba210f0f7
moved the map-info and fun-info section to quotient.ML
Christian Urban <urbanc@in.tum.de>
parents:
129
diff
changeset
|
208 |
(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
|
209 |
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
|
210 |
| 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
|
211 |
end |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
212 |
|
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
213 |
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
|
214 |
let |
f5f641c05794
A fix for one fun_map; doesn't work for more.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
109
diff
changeset
|
215 |
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
|
216 |
val ([oty1, oty2], [nty1, nty2]) = split_list tys |
128 | 217 |
val oty = nty1 --> oty2 |
218 |
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
|
219 |
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
|
220 |
in |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
221 |
(list_comb (Const (@{const_name "fun_map"}, ftys ---> oty --> nty), fs), (oty, nty)) |
0 | 222 |
end |
223 |
||
170 | 224 |
val thy = ProofContext.theory_of lthy |
225 |
||
226 |
fun get_const absF = (Const (Sign.full_bname thy ("ABS_" ^ qty_name), rty --> qty), (rty, qty)) |
|
227 |
| get_const repF = (Const (Sign.full_bname thy ("REP_" ^ qty_name), qty --> rty), (qty, rty)) |
|
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
228 |
|
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
|
229 |
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
|
230 |
|
0 | 231 |
in |
232 |
if ty = qty |
|
46 | 233 |
then (get_const flag) |
0 | 234 |
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
|
235 |
TFree _ => (mk_identity ty, (ty, ty)) |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
236 |
| 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
|
237 |
| Type ("fun" , [ty1, ty2]) => |
118
1c30d48bfc15
slightly simplified get_fun function
Christian Urban <urbanc@in.tum.de>
parents:
117
diff
changeset
|
238 |
get_fun_fun [get_fun (negF flag) rty qty lthy ty1, get_fun flag rty qty lthy ty2] |
46 | 239 |
| Type (s, tys) => get_fun_aux s (map (get_fun flag rty qty lthy) tys) |
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
240 |
| _ => raise ERROR ("no type variables") |
0 | 241 |
) |
242 |
end |
|
243 |
*} |
|
244 |
||
180
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
245 |
|
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
246 |
text {* produces the definition for a lifted constant *} |
86 | 247 |
|
2 | 248 |
ML {* |
0 | 249 |
fun get_const_def nconst oconst rty qty lthy = |
250 |
let |
|
251 |
val ty = fastype_of nconst |
|
252 |
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
|
253 |
|
0 | 254 |
val fresh_args = arg_tys |> map (pair "x") |
15 | 255 |
|> Variable.variant_frees lthy [nconst, oconst] |
0 | 256 |
|> map Free |
257 |
||
46 | 258 |
val rep_fns = map (fst o get_fun repF rty qty lthy) arg_tys |
259 |
val abs_fn = (fst o get_fun absF rty qty lthy) res_ty |
|
0 | 260 |
|
180
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
261 |
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
|
262 |
|
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
263 |
val fns = Library.foldr (mk_fun_map) (rep_fns, abs_fn) |
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
264 |
|> Syntax.check_term lthy |
0 | 265 |
in |
180
fcacca9588b4
changed the definitions of liftet constants to use fun_maps
Christian Urban <urbanc@in.tum.de>
parents:
174
diff
changeset
|
266 |
fns $ oconst |
0 | 267 |
end |
268 |
*} |
|
269 |
||
270 |
ML {* |
|
15 | 271 |
fun exchange_ty rty qty ty = |
49 | 272 |
if ty = rty |
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
273 |
then qty |
15 | 274 |
else |
0 | 275 |
(case ty of |
276 |
Type (s, tys) => Type (s, map (exchange_ty rty qty) tys) |
|
41
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
277 |
| _ => ty |
72d63aa8af68
added ctxt as explicit argument to build_goal; tuned
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
278 |
) |
0 | 279 |
*} |
280 |
||
281 |
ML {* |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
282 |
fun make_const_def nconst_bname oconst mx rty qty lthy = |
0 | 283 |
let |
284 |
val oconst_ty = fastype_of oconst |
|
285 |
val nconst_ty = exchange_ty rty qty oconst_ty |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
286 |
val nconst = Const (Binding.name_of nconst_bname, nconst_ty) |
0 | 287 |
val def_trm = get_const_def nconst oconst rty qty lthy |
288 |
in |
|
79
c0c41fefeb06
added quotient command (you need to update isar-keywords-prove.el)
Christian Urban <urbanc@in.tum.de>
parents:
77
diff
changeset
|
289 |
define (nconst_bname, mx, def_trm) lthy |
15 | 290 |
end |
0 | 291 |
*} |
292 |
||
139 | 293 |
section {* ATOMIZE *} |
294 |
||
295 |
text {* |
|
296 |
Unabs_def converts a definition given as |
|
297 |
||
298 |
c \<equiv> %x. %y. f x y |
|
299 |
||
300 |
to a theorem of the form |
|
301 |
||
302 |
c x y \<equiv> f x y |
|
303 |
||
304 |
This function is needed to rewrite the right-hand |
|
305 |
side to the left-hand side. |
|
306 |
*} |
|
307 |
||
308 |
ML {* |
|
309 |
fun unabs_def ctxt def = |
|
310 |
let |
|
311 |
val (lhs, rhs) = Thm.dest_equals (cprop_of def) |
|
312 |
val xs = strip_abs_vars (term_of rhs) |
|
313 |
val (_, ctxt') = Variable.add_fixes (map fst xs) ctxt |
|
314 |
||
315 |
val thy = ProofContext.theory_of ctxt' |
|
316 |
val cxs = map (cterm_of thy o Free) xs |
|
317 |
val new_lhs = Drule.list_comb (lhs, cxs) |
|
318 |
||
319 |
fun get_conv [] = Conv.rewr_conv def |
|
320 |
| get_conv (x::xs) = Conv.fun_conv (get_conv xs) |
|
321 |
in |
|
322 |
get_conv xs new_lhs |> |
|
323 |
singleton (ProofContext.export ctxt' ctxt) |
|
324 |
end |
|
325 |
*} |
|
326 |
||
327 |
lemma atomize_eqv[atomize]: |
|
328 |
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" |
|
329 |
proof |
|
330 |
assume "A \<equiv> B" |
|
331 |
then show "Trueprop A \<equiv> Trueprop B" by unfold |
|
332 |
next |
|
333 |
assume *: "Trueprop A \<equiv> Trueprop B" |
|
334 |
have "A = B" |
|
335 |
proof (cases A) |
|
336 |
case True |
|
337 |
have "A" by fact |
|
338 |
then show "A = B" using * by simp |
|
339 |
next |
|
340 |
case False |
|
341 |
have "\<not>A" by fact |
|
342 |
then show "A = B" using * by auto |
|
343 |
qed |
|
344 |
then show "A \<equiv> B" by (rule eq_reflection) |
|
345 |
qed |
|
346 |
||
347 |
ML {* |
|
348 |
fun atomize_thm thm = |
|
349 |
let |
|
350 |
val thm' = forall_intr_vars thm |
|
351 |
val thm'' = ObjectLogic.atomize (cprop_of thm') |
|
352 |
in |
|
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
353 |
Thm.freezeT (Simplifier.rewrite_rule [thm''] thm') |
139 | 354 |
end |
355 |
*} |
|
356 |
||
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
357 |
ML {* atomize_thm @{thm list.induct} *} |
139 | 358 |
|
359 |
section {* REGULARIZE *} |
|
360 |
||
361 |
text {* tyRel takes a type and builds a relation that a quantifier over this |
|
362 |
type needs to respect. *} |
|
363 |
ML {* |
|
364 |
fun tyRel ty rty rel lthy = |
|
365 |
if ty = rty |
|
366 |
then rel |
|
367 |
else (case ty of |
|
368 |
Type (s, tys) => |
|
369 |
let |
|
370 |
val tys_rel = map (fn ty => ty --> ty --> @{typ bool}) tys; |
|
371 |
val ty_out = ty --> ty --> @{typ bool}; |
|
372 |
val tys_out = tys_rel ---> ty_out; |
|
373 |
in |
|
374 |
(case (maps_lookup (ProofContext.theory_of lthy) s) of |
|
375 |
SOME (info) => list_comb (Const (#relfun info, tys_out), map (fn ty => tyRel ty rty rel lthy) tys) |
|
376 |
| NONE => HOLogic.eq_const ty |
|
377 |
) |
|
378 |
end |
|
379 |
| _ => HOLogic.eq_const ty) |
|
380 |
*} |
|
381 |
||
382 |
definition |
|
383 |
Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" |
|
384 |
where |
|
385 |
"(x \<in> p) \<Longrightarrow> (Babs p m x = m x)" |
|
386 |
(* TODO: Consider defining it with an "if"; sth like: |
|
387 |
Babs p m = \<lambda>x. if x \<in> p then m x else undefined |
|
388 |
*) |
|
389 |
||
390 |
ML {* |
|
391 |
fun needs_lift (rty as Type (rty_s, _)) ty = |
|
392 |
case ty of |
|
393 |
Type (s, tys) => |
|
394 |
(s = rty_s) orelse (exists (needs_lift rty) tys) |
|
395 |
| _ => false |
|
396 |
||
397 |
*} |
|
398 |
||
399 |
ML {* |
|
400 |
(* trm \<Rightarrow> new_trm *) |
|
401 |
fun regularise trm rty rel lthy = |
|
402 |
case trm of |
|
403 |
Abs (x, T, t) => |
|
404 |
if (needs_lift rty T) then let |
|
405 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
406 |
val v = Free (x', T); |
|
407 |
val t' = subst_bound (v, t); |
|
408 |
val rec_term = regularise t' rty rel lthy2; |
|
409 |
val lam_term = Term.lambda_name (x, v) rec_term; |
|
410 |
val sub_res_term = tyRel T rty rel lthy; |
|
411 |
val respects = Const (@{const_name Respects}, (fastype_of sub_res_term) --> T --> @{typ bool}); |
|
412 |
val res_term = respects $ sub_res_term; |
|
413 |
val ty = fastype_of trm; |
|
414 |
val rabs = Const (@{const_name Babs}, (fastype_of res_term) --> ty --> ty); |
|
415 |
val rabs_term = (rabs $ res_term) $ lam_term; |
|
416 |
in |
|
417 |
rabs_term |
|
418 |
end else let |
|
419 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
420 |
val v = Free (x', T); |
|
421 |
val t' = subst_bound (v, t); |
|
422 |
val rec_term = regularise t' rty rel lthy2; |
|
423 |
in |
|
424 |
Term.lambda_name (x, v) rec_term |
|
425 |
end |
|
426 |
| ((Const (@{const_name "All"}, at)) $ (Abs (x, T, t))) => |
|
427 |
if (needs_lift rty T) then let |
|
428 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
429 |
val v = Free (x', T); |
|
430 |
val t' = subst_bound (v, t); |
|
431 |
val rec_term = regularise t' rty rel lthy2; |
|
432 |
val lam_term = Term.lambda_name (x, v) rec_term; |
|
433 |
val sub_res_term = tyRel T rty rel lthy; |
|
434 |
val respects = Const (@{const_name Respects}, (fastype_of sub_res_term) --> T --> @{typ bool}); |
|
435 |
val res_term = respects $ sub_res_term; |
|
436 |
val ty = fastype_of lam_term; |
|
437 |
val rall = Const (@{const_name Ball}, (fastype_of res_term) --> ty --> @{typ bool}); |
|
438 |
val rall_term = (rall $ res_term) $ lam_term; |
|
439 |
in |
|
440 |
rall_term |
|
441 |
end else let |
|
442 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
443 |
val v = Free (x', T); |
|
444 |
val t' = subst_bound (v, t); |
|
445 |
val rec_term = regularise t' rty rel lthy2; |
|
446 |
val lam_term = Term.lambda_name (x, v) rec_term |
|
447 |
in |
|
448 |
Const(@{const_name "All"}, at) $ lam_term |
|
449 |
end |
|
450 |
| ((Const (@{const_name "All"}, at)) $ P) => |
|
451 |
let |
|
452 |
val (_, [al, _]) = dest_Type (fastype_of P); |
|
453 |
val ([x], lthy2) = Variable.variant_fixes [""] lthy; |
|
454 |
val v = (Free (x, al)); |
|
455 |
val abs = Term.lambda_name (x, v) (P $ v); |
|
456 |
in regularise ((Const (@{const_name "All"}, at)) $ abs) rty rel lthy2 end |
|
457 |
| ((Const (@{const_name "Ex"}, at)) $ (Abs (x, T, t))) => |
|
458 |
if (needs_lift rty T) then let |
|
459 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
460 |
val v = Free (x', T); |
|
461 |
val t' = subst_bound (v, t); |
|
462 |
val rec_term = regularise t' rty rel lthy2; |
|
463 |
val lam_term = Term.lambda_name (x, v) rec_term; |
|
464 |
val sub_res_term = tyRel T rty rel lthy; |
|
465 |
val respects = Const (@{const_name Respects}, (fastype_of sub_res_term) --> T --> @{typ bool}); |
|
466 |
val res_term = respects $ sub_res_term; |
|
467 |
val ty = fastype_of lam_term; |
|
468 |
val rall = Const (@{const_name Bex}, (fastype_of res_term) --> ty --> @{typ bool}); |
|
469 |
val rall_term = (rall $ res_term) $ lam_term; |
|
470 |
in |
|
471 |
rall_term |
|
472 |
end else let |
|
473 |
val ([x'], lthy2) = Variable.variant_fixes [x] lthy; |
|
474 |
val v = Free (x', T); |
|
475 |
val t' = subst_bound (v, t); |
|
476 |
val rec_term = regularise t' rty rel lthy2; |
|
477 |
val lam_term = Term.lambda_name (x, v) rec_term |
|
478 |
in |
|
479 |
Const(@{const_name "Ex"}, at) $ lam_term |
|
480 |
end |
|
481 |
| ((Const (@{const_name "Ex"}, at)) $ P) => |
|
482 |
let |
|
483 |
val (_, [al, _]) = dest_Type (fastype_of P); |
|
484 |
val ([x], lthy2) = Variable.variant_fixes [""] lthy; |
|
485 |
val v = (Free (x, al)); |
|
486 |
val abs = Term.lambda_name (x, v) (P $ v); |
|
487 |
in regularise ((Const (@{const_name "Ex"}, at)) $ abs) rty rel lthy2 end |
|
488 |
| a $ b => (regularise a rty rel lthy) $ (regularise b rty rel lthy) |
|
489 |
| _ => trm |
|
490 |
||
491 |
*} |
|
492 |
||
493 |
(* my version of regularise *) |
|
494 |
(****************************) |
|
495 |
||
496 |
(* some helper functions *) |
|
497 |
||
498 |
||
499 |
ML {* |
|
500 |
fun mk_babs ty ty' = Const (@{const_name "Babs"}, [ty' --> @{typ bool}, ty] ---> ty) |
|
501 |
fun mk_ball ty = Const (@{const_name "Ball"}, [ty, ty] ---> @{typ bool}) |
|
502 |
fun mk_bex ty = Const (@{const_name "Bex"}, [ty, ty] ---> @{typ bool}) |
|
503 |
fun mk_resp ty = Const (@{const_name Respects}, [[ty, ty] ---> @{typ bool}, ty] ---> @{typ bool}) |
|
504 |
*} |
|
505 |
||
506 |
(* applies f to the subterm of an abstractions, otherwise to the given term *) |
|
507 |
ML {* |
|
508 |
fun apply_subt f trm = |
|
509 |
case trm of |
|
145 | 510 |
Abs (x, T, t) => |
511 |
let |
|
512 |
val (x', t') = Term.dest_abs (x, T, t) |
|
513 |
in |
|
514 |
Term.absfree (x', T, f t') |
|
515 |
end |
|
139 | 516 |
| _ => f trm |
517 |
*} |
|
518 |
||
519 |
||
520 |
(* FIXME: assumes always the typ is qty! *) |
|
521 |
(* FIXME: if there are more than one quotient, then you have to look up the relation *) |
|
522 |
ML {* |
|
523 |
fun my_reg rel trm = |
|
524 |
case trm of |
|
525 |
Abs (x, T, t) => |
|
526 |
let |
|
527 |
val ty1 = fastype_of trm |
|
528 |
in |
|
146 | 529 |
(mk_babs ty1 T) $ (mk_resp T $ rel) $ (apply_subt (my_reg rel) trm) |
139 | 530 |
end |
531 |
| Const (@{const_name "All"}, ty) $ t => |
|
532 |
let |
|
533 |
val ty1 = domain_type ty |
|
534 |
val ty2 = domain_type ty1 |
|
535 |
in |
|
536 |
(mk_ball ty1) $ (mk_resp ty2 $ rel) $ (apply_subt (my_reg rel) t) |
|
537 |
end |
|
538 |
| Const (@{const_name "Ex"}, ty) $ t => |
|
539 |
let |
|
540 |
val ty1 = domain_type ty |
|
541 |
val ty2 = domain_type ty1 |
|
542 |
in |
|
543 |
(mk_bex ty1) $ (mk_resp ty2 $ rel) $ (apply_subt (my_reg rel) t) |
|
544 |
end |
|
545 |
| t1 $ t2 => (my_reg rel t1) $ (my_reg rel t2) |
|
546 |
| _ => trm |
|
547 |
*} |
|
548 |
||
549 |
||
550 |
(*fun prove_reg trm \<Rightarrow> thm (we might need some facts to do this) |
|
551 |
trm == new_trm |
|
552 |
*) |
|
553 |
||
141
0ffc37761e53
Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
140
diff
changeset
|
554 |
text {* Assumes that the given theorem is atomized *} |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
555 |
ML {* |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
556 |
fun build_regularize_goal thm rty rel lthy = |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
557 |
Logic.mk_implies |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
558 |
((prop_of thm), |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
559 |
(regularise (prop_of thm) rty rel lthy)) |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
560 |
*} |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
561 |
|
187 | 562 |
ML {* |
563 |
fun regularize thm rty rel rel_eqv lthy = |
|
564 |
let |
|
565 |
val g = build_regularize_goal thm rty rel lthy; |
|
566 |
fun tac ctxt = |
|
567 |
(asm_full_simp_tac ((Simplifier.context ctxt HOL_ss) addsimps |
|
568 |
[(@{thm equiv_res_forall} OF [rel_eqv]), |
|
569 |
(@{thm equiv_res_exists} OF [rel_eqv])])) THEN_ALL_NEW |
|
570 |
(((rtac @{thm RIGHT_RES_FORALL_REGULAR}) THEN' (RANGE [fn _ => all_tac, atac]) THEN' |
|
571 |
(MetisTools.metis_tac ctxt [])) ORELSE' (MetisTools.metis_tac ctxt [])); |
|
572 |
val cthm = Goal.prove lthy [] [] g (fn x => tac (#context x) 1); |
|
573 |
in |
|
574 |
cthm OF [thm] |
|
575 |
end |
|
576 |
*} |
|
577 |
||
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
578 |
section {* RepAbs injection *} |
139 | 579 |
|
161
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
580 |
(* 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
|
581 |
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
|
582 |
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
|
583 |
|
139 | 584 |
ML {* |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
585 |
fun build_repabs_term lthy thm constructors rty qty = |
139 | 586 |
let |
587 |
fun mk_rep tm = |
|
588 |
let |
|
589 |
val ty = exchange_ty rty qty (fastype_of tm) |
|
590 |
in fst (get_fun repF rty qty lthy ty) $ tm end |
|
591 |
||
592 |
fun mk_abs tm = |
|
593 |
let |
|
594 |
val ty = exchange_ty rty qty (fastype_of tm) in |
|
595 |
fst (get_fun absF rty qty lthy ty) $ tm end |
|
596 |
||
597 |
fun is_constructor (Const (x, _)) = member (op =) constructors x |
|
598 |
| is_constructor _ = false; |
|
599 |
||
600 |
fun build_aux lthy tm = |
|
601 |
case tm of |
|
602 |
Abs (a as (_, vty, _)) => |
|
603 |
let |
|
604 |
val (vs, t) = Term.dest_abs a; |
|
605 |
val v = Free(vs, vty); |
|
606 |
val t' = lambda v (build_aux lthy t) |
|
607 |
in |
|
608 |
if (not (needs_lift rty (fastype_of tm))) then t' |
|
609 |
else mk_rep (mk_abs ( |
|
610 |
if not (needs_lift rty vty) then t' |
|
611 |
else |
|
612 |
let |
|
613 |
val v' = mk_rep (mk_abs v); |
|
614 |
val t1 = Envir.beta_norm (t' $ v') |
|
615 |
in |
|
616 |
lambda v t1 |
|
617 |
end |
|
618 |
)) |
|
619 |
end |
|
620 |
| x => |
|
621 |
let |
|
622 |
val (opp, tms0) = Term.strip_comb tm |
|
623 |
val tms = map (build_aux lthy) tms0 |
|
624 |
val ty = fastype_of tm |
|
625 |
in |
|
626 |
if (((fst (Term.dest_Const opp)) = @{const_name Respects}) handle _ => false) |
|
627 |
then (list_comb (opp, (hd tms0) :: (tl tms))) |
|
628 |
else if (is_constructor opp andalso needs_lift rty ty) then |
|
629 |
mk_rep (mk_abs (list_comb (opp,tms))) |
|
630 |
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
|
631 |
mk_rep(mk_abs(list_comb(opp,tms))) |
139 | 632 |
else if tms = [] then opp |
633 |
else list_comb(opp, tms) |
|
634 |
end |
|
635 |
in |
|
161
2ee03759a22f
Trying to get a simpler lemma with the whole infrastructure
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
160
diff
changeset
|
636 |
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
|
637 |
(build_aux lthy (Thm.prop_of thm)) |
139 | 638 |
end |
639 |
*} |
|
640 |
||
141
0ffc37761e53
Further reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
140
diff
changeset
|
641 |
text {* Assumes that it is given a regularized theorem *} |
139 | 642 |
ML {* |
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
643 |
fun build_repabs_goal ctxt thm cons rty qty = |
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
644 |
Logic.mk_equals ((Thm.prop_of thm), (build_repabs_term ctxt thm cons rty qty)) |
139 | 645 |
*} |
646 |
||
187 | 647 |
ML {* |
648 |
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} => |
|
649 |
let |
|
650 |
val pat = Drule.strip_imp_concl (cprop_of thm) |
|
651 |
val insts = Thm.match (pat, concl) |
|
652 |
in |
|
653 |
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
|
654 |
end |
187 | 655 |
handle _ => no_tac |
656 |
) |
|
657 |
*} |
|
658 |
||
659 |
ML {* |
|
660 |
fun res_forall_rsp_tac ctxt = |
|
661 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
662 |
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI} |
|
663 |
THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN' |
|
664 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
665 |
*} |
|
666 |
||
667 |
ML {* |
|
668 |
fun res_exists_rsp_tac ctxt = |
|
669 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
670 |
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI} |
|
671 |
THEN' instantiate_tac @{thm RES_EXISTS_RSP} ctxt THEN' |
|
672 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
673 |
*} |
|
674 |
||
675 |
||
676 |
ML {* |
|
677 |
fun quotient_tac quot_thm = |
|
678 |
REPEAT_ALL_NEW (FIRST' [ |
|
679 |
rtac @{thm FUN_QUOTIENT}, |
|
680 |
rtac quot_thm, |
|
681 |
rtac @{thm IDENTITY_QUOTIENT} |
|
682 |
]) |
|
683 |
*} |
|
684 |
||
685 |
ML {* |
|
686 |
fun LAMBDA_RES_TAC ctxt i st = |
|
687 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
688 |
(_ $ (_ $ (Abs(_,_,_))$(Abs(_,_,_)))) => |
|
689 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
690 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
691 |
| _ => fn _ => no_tac) i st |
|
692 |
*} |
|
693 |
||
694 |
ML {* |
|
695 |
fun WEAK_LAMBDA_RES_TAC ctxt i st = |
|
696 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
697 |
(_ $ (_ $ _$(Abs(_,_,_)))) => |
|
698 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
699 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
700 |
| (_ $ (_ $ (Abs(_,_,_))$_)) => |
|
701 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
702 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
703 |
| _ => fn _ => no_tac) i st |
|
704 |
*} |
|
705 |
||
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
706 |
ML {* |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
707 |
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
|
708 |
let |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
709 |
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
|
710 |
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
|
711 |
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
|
712 |
in |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
713 |
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
|
714 |
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
|
715 |
else no_tac |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
716 |
end |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
717 |
handle _ => no_tac) |
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
718 |
*} |
187 | 719 |
|
720 |
ML {* |
|
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
721 |
fun r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms = |
187 | 722 |
(FIRST' [ |
723 |
rtac @{thm FUN_QUOTIENT}, |
|
724 |
rtac quot_thm, |
|
725 |
rtac @{thm IDENTITY_QUOTIENT}, |
|
726 |
rtac trans_thm, |
|
727 |
LAMBDA_RES_TAC ctxt, |
|
728 |
res_forall_rsp_tac ctxt, |
|
729 |
res_exists_rsp_tac ctxt, |
|
730 |
( |
|
731 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps rsp_thms)) |
|
732 |
THEN_ALL_NEW (fn _ => no_tac) |
|
733 |
), |
|
734 |
(instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' (RANGE [quotient_tac quot_thm])), |
|
735 |
rtac refl, |
|
206
1e227c9ee915
Fixed APPLY_RSP vs Cong in the InjRepAbs tactic.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
200
diff
changeset
|
736 |
(* 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
|
737 |
(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
|
738 |
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
|
739 |
rtac @{thm ext}, |
187 | 740 |
rtac reflex_thm, |
741 |
atac, |
|
742 |
( |
|
743 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps})) |
|
744 |
THEN_ALL_NEW (fn _ => no_tac) |
|
745 |
), |
|
746 |
WEAK_LAMBDA_RES_TAC ctxt |
|
747 |
]) |
|
748 |
*} |
|
749 |
||
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
|
750 |
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
|
751 |
fun repabs_eq lthy thm constructors rty qty quot_thm reflex_thm trans_thm rsp_thms = |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
752 |
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
|
753 |
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
|
754 |
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
|
755 |
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
|
756 |
(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
|
757 |
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
|
758 |
in |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
759 |
(rt, cthm, 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
|
760 |
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
|
761 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
762 |
|
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
763 |
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
|
764 |
fun repabs_eq2 lthy (rt, thm, othm) = |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
765 |
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
|
766 |
fun tac2 ctxt = |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
767 |
(simp_tac ((Simplifier.context ctxt empty_ss) addsimps [symmetric 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
|
768 |
THEN' (rtac othm); |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
769 |
val cthm = Goal.prove lthy [] [] rt (fn x => tac2 (#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
|
770 |
in |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
771 |
cthm |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
772 |
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
|
773 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
774 |
|
187 | 775 |
section {* Cleaning the goal *} |
776 |
||
777 |
text {* Does the same as 'subst' in a given theorem *} |
|
778 |
ML {* |
|
779 |
fun eqsubst_thm ctxt thms thm = |
|
780 |
let |
|
781 |
val goalstate = Goal.init (Thm.cprop_of thm) |
|
782 |
val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of |
|
783 |
NONE => error "eqsubst_thm" |
|
784 |
| SOME th => cprem_of th 1 |
|
785 |
val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1 |
|
786 |
val cgoal = cterm_of (ProofContext.theory_of ctxt) (Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a')) |
|
787 |
val rt = Toplevel.program (fn () => Goal.prove_internal [] cgoal (fn _ => tac)); |
|
788 |
in |
|
789 |
Simplifier.rewrite_rule [rt] thm |
|
790 |
end |
|
791 |
*} |
|
792 |
||
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
|
793 |
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
|
794 |
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
|
795 |
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
|
796 |
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
|
797 |
val e1 = @{thm fun_cong} OF [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
|
798 |
val f = eqsubst_thm ctxt @{thms fun_map.simps} e1 |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
799 |
in |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
800 |
thm :: (add_lower_defs_aux ctxt f) |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
801 |
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
|
802 |
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
|
803 |
*} |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
804 |
|
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
805 |
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
|
806 |
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
|
807 |
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
|
808 |
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
|
809 |
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
|
810 |
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
|
811 |
val defs_sym = map (fn t => eq_reflection OF [t]) defs_all |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
812 |
in |
ca1a24aa822e
Finished the code for adding lower defs, and more things moved to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
187
diff
changeset
|
813 |
map Thm.varifyT defs_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
|
814 |
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
|
815 |
*} |
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 |
|
191
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
817 |
text {* the proper way to do it *} |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
818 |
ML {* |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
819 |
fun findabs rty tm = |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
820 |
case tm of |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
821 |
Abs(_, T, b) => |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
822 |
let |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
823 |
val b' = subst_bound ((Free ("x", T)), b); |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
824 |
val tys = findabs rty b' |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
825 |
val ty = fastype_of tm |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
826 |
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
|
827 |
end |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
828 |
| f $ a => (findabs rty f) @ (findabs rty a) |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
829 |
| _ => [] |
b97f3f5fbc18
Symmetry of integer addition
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
190
diff
changeset
|
830 |
*} |
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
|
831 |
|
197
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
832 |
ML {* |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
833 |
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
|
834 |
let |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
835 |
val (_, [lty, rty]) = dest_Type typ; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
836 |
val thy = ProofContext.theory_of lthy; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
837 |
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
|
838 |
val inst = [SOME lcty, NONE, SOME rcty]; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
839 |
val lpi = Drule.instantiate' inst [] @{thm LAMBDA_PRS}; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
840 |
val tac = |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
841 |
(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
|
842 |
(quotient_tac quot_thm); |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
843 |
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
|
844 |
val ts = @{thm HOL.sym} OF [t] |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
845 |
in |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
846 |
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
|
847 |
end |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
848 |
*} |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
849 |
|
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
850 |
ML {* |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
851 |
fun simp_allex_prs lthy quot thm = |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
852 |
let |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
853 |
val rwf = @{thm FORALL_PRS} OF [quot]; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
854 |
val rwfs = @{thm "HOL.sym"} OF [rwf]; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
855 |
val rwe = @{thm EXISTS_PRS} OF [quot]; |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
856 |
val rwes = @{thm "HOL.sym"} OF [rwe] |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
857 |
in |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
858 |
(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
|
859 |
end |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
860 |
handle _ => thm |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
861 |
*} |
c0f2db9a243b
Further reordering in Int code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
193
diff
changeset
|
862 |
|
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
863 |
ML {* |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
864 |
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
|
865 |
val t_a = atomize_thm t; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
866 |
val t_r = regularize t_a rty rel rel_eqv lthy; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
867 |
val t_t1 = repabs_eq lthy t_r consts rty qty quot rel_refl trans2 rsp_thms; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
868 |
val t_t2 = repabs_eq2 lthy t_t1; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
869 |
val abs = findabs rty (prop_of t_a); |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
870 |
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
|
871 |
fun simp_lam_prs lthy thm = |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
872 |
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
|
873 |
handle _ => thm |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
874 |
val t_l = simp_lam_prs lthy t_t2; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
875 |
val t_a = simp_allex_prs lthy quot t_l; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
876 |
val t_defs_sym = add_lower_defs lthy t_defs; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
877 |
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
|
878 |
val t_r = MetaSimplifier.rewrite_rule [reps_same] t_d; |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
879 |
in |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
880 |
ObjectLogic.rulify t_r |
187 | 881 |
end |
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
882 |
*} |
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
883 |
|
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
884 |
end |