author | Christian Urban <urbanc@in.tum.de> |
Thu, 26 Nov 2009 03:18:38 +0100 | |
changeset 391 | 58947b7232ef |
parent 390 | 1dd6a21cdd1c |
parent 389 | d67240113f68 |
child 398 | fafcc54e531d |
permissions | -rw-r--r-- |
0 | 1 |
theory QuotMain |
6 | 2 |
imports QuotScript QuotList Prove |
264
d0581fbc096c
split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
263
diff
changeset
|
3 |
uses ("quotient_info.ML") |
d0581fbc096c
split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
263
diff
changeset
|
4 |
("quotient.ML") |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
5 |
("quotient_def.ML") |
0 | 6 |
begin |
7 |
||
8 |
locale QUOT_TYPE = |
|
9 |
fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
|
10 |
and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b" |
|
11 |
and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)" |
|
12 |
assumes equiv: "EQUIV R" |
|
13 |
and rep_prop: "\<And>y. \<exists>x. Rep y = R x" |
|
14 |
and rep_inverse: "\<And>x. Abs (Rep x) = x" |
|
15 |
and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)" |
|
16 |
and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)" |
|
15 | 17 |
begin |
0 | 18 |
|
19 |
definition |
|
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
20 |
ABS::"'a \<Rightarrow> 'b" |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
21 |
where |
0 | 22 |
"ABS x \<equiv> Abs (R x)" |
23 |
||
24 |
definition |
|
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
25 |
REP::"'b \<Rightarrow> 'a" |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
26 |
where |
0 | 27 |
"REP a = Eps (Rep a)" |
28 |
||
15 | 29 |
lemma lem9: |
0 | 30 |
shows "R (Eps (R x)) = R x" |
31 |
proof - |
|
32 |
have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def) |
|
33 |
then have "R x (Eps (R x))" by (rule someI) |
|
15 | 34 |
then show "R (Eps (R x)) = R x" |
0 | 35 |
using equiv unfolding EQUIV_def by simp |
36 |
qed |
|
37 |
||
38 |
theorem thm10: |
|
24
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
39 |
shows "ABS (REP a) \<equiv> a" |
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
40 |
apply (rule eq_reflection) |
6885fa184e89
Merged with my changes from the morning:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
23
diff
changeset
|
41 |
unfolding ABS_def REP_def |
0 | 42 |
proof - |
15 | 43 |
from rep_prop |
0 | 44 |
obtain x where eq: "Rep a = R x" by auto |
45 |
have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp |
|
46 |
also have "\<dots> = Abs (R x)" using lem9 by simp |
|
47 |
also have "\<dots> = Abs (Rep a)" using eq by simp |
|
48 |
also have "\<dots> = a" using rep_inverse by simp |
|
49 |
finally |
|
50 |
show "Abs (R (Eps (Rep a))) = a" by simp |
|
51 |
qed |
|
52 |
||
15 | 53 |
lemma REP_refl: |
0 | 54 |
shows "R (REP a) (REP a)" |
55 |
unfolding REP_def |
|
56 |
by (simp add: equiv[simplified EQUIV_def]) |
|
57 |
||
58 |
lemma lem7: |
|
22 | 59 |
shows "(R x = R y) = (Abs (R x) = Abs (R y))" |
0 | 60 |
apply(rule iffI) |
61 |
apply(simp) |
|
62 |
apply(drule rep_inject[THEN iffD2]) |
|
63 |
apply(simp add: abs_inverse) |
|
64 |
done |
|
15 | 65 |
|
0 | 66 |
theorem thm11: |
67 |
shows "R r r' = (ABS r = ABS r')" |
|
68 |
unfolding ABS_def |
|
69 |
by (simp only: equiv[simplified EQUIV_def] lem7) |
|
70 |
||
4 | 71 |
|
2 | 72 |
lemma REP_ABS_rsp: |
4 | 73 |
shows "R f (REP (ABS g)) = R f g" |
74 |
and "R (REP (ABS g)) f = R g f" |
|
23 | 75 |
by (simp_all add: thm10 thm11) |
4 | 76 |
|
0 | 77 |
lemma QUOTIENT: |
78 |
"QUOTIENT R ABS REP" |
|
79 |
apply(unfold QUOTIENT_def) |
|
80 |
apply(simp add: thm10) |
|
81 |
apply(simp add: REP_refl) |
|
82 |
apply(subst thm11[symmetric]) |
|
83 |
apply(simp add: equiv[simplified EQUIV_def]) |
|
84 |
done |
|
85 |
||
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
86 |
lemma R_trans: |
49 | 87 |
assumes ab: "R a b" |
88 |
and bc: "R b c" |
|
22 | 89 |
shows "R a c" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
90 |
proof - |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
91 |
have tr: "TRANS R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
92 |
moreover have ab: "R a b" by fact |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
93 |
moreover have bc: "R b c" by fact |
22 | 94 |
ultimately show "R a c" unfolding TRANS_def by blast |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
95 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
96 |
|
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
97 |
lemma R_sym: |
49 | 98 |
assumes ab: "R a b" |
22 | 99 |
shows "R b a" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
100 |
proof - |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
101 |
have re: "SYM R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
22 | 102 |
then show "R b a" using ab unfolding SYM_def by blast |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
103 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
104 |
|
49 | 105 |
lemma R_trans2: |
106 |
assumes ac: "R a c" |
|
22 | 107 |
and bd: "R b d" |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
108 |
shows "R a b = R c d" |
200
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
109 |
using ac bd |
d6a24dad5882
made quotients compatiple with Nominal; updated keyword file
Christian Urban <urbanc@in.tum.de>
parents:
198
diff
changeset
|
110 |
by (blast intro: R_trans R_sym) |
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
111 |
|
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
112 |
lemma REPS_same: |
25
9020ee23a020
The tactic with REPEAT, CHANGED and a proper simpset.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
24
diff
changeset
|
113 |
shows "R (REP a) (REP b) \<equiv> (a = b)" |
38 | 114 |
proof - |
115 |
have "R (REP a) (REP b) = (a = b)" |
|
116 |
proof |
|
117 |
assume as: "R (REP a) (REP b)" |
|
118 |
from rep_prop |
|
119 |
obtain x y |
|
120 |
where eqs: "Rep a = R x" "Rep b = R y" by blast |
|
121 |
from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp |
|
122 |
then have "R x (Eps (R y))" using lem9 by simp |
|
123 |
then have "R (Eps (R y)) x" using R_sym by blast |
|
124 |
then have "R y x" using lem9 by simp |
|
125 |
then have "R x y" using R_sym by blast |
|
126 |
then have "ABS x = ABS y" using thm11 by simp |
|
127 |
then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp |
|
128 |
then show "a = b" using rep_inverse by simp |
|
129 |
next |
|
130 |
assume ab: "a = b" |
|
131 |
have "REFL R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
|
132 |
then show "R (REP a) (REP b)" unfolding REFL_def using ab by auto |
|
133 |
qed |
|
134 |
then show "R (REP a) (REP b) \<equiv> (a = b)" by simp |
|
21
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
135 |
qed |
d15121412caa
Added more useful quotient facts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
20
diff
changeset
|
136 |
|
0 | 137 |
end |
138 |
||
139 |
section {* type definition for the quotient type *} |
|
140 |
||
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
141 |
(* the auxiliary data for the quotient types *) |
264
d0581fbc096c
split quotient.ML into two files
Christian Urban <urbanc@in.tum.de>
parents:
263
diff
changeset
|
142 |
use "quotient_info.ML" |
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
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 |
|
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
152 |
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
153 |
(* definition of the quotient types *) |
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
154 |
(* FIXME: should be called quotient_typ.ML *) |
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
155 |
use "quotient.ML" |
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
156 |
|
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
parents:
267
diff
changeset
|
157 |
|
277
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
158 |
(* lifting of constants *) |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
159 |
use "quotient_def.ML" |
37636f2b1c19
separated the quotient_def into a separate file
Christian Urban <urbanc@in.tum.de>
parents:
275
diff
changeset
|
160 |
|
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
161 |
(* TODO: Consider defining it with an "if"; sth like: |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
162 |
Babs p m = \<lambda>x. if x \<in> p then m x else undefined |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
163 |
*) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
164 |
definition |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
165 |
Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
166 |
where |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
167 |
"(x \<in> p) \<Longrightarrow> (Babs p m x = m x)" |
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents:
307
diff
changeset
|
168 |
|
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
parents:
307
diff
changeset
|
169 |
|
139 | 170 |
section {* ATOMIZE *} |
171 |
||
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
172 |
lemma atomize_eqv[atomize]: |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
173 |
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" |
139 | 174 |
proof |
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
175 |
assume "A \<equiv> B" |
139 | 176 |
then show "Trueprop A \<equiv> Trueprop B" by unfold |
177 |
next |
|
178 |
assume *: "Trueprop A \<equiv> Trueprop B" |
|
179 |
have "A = B" |
|
180 |
proof (cases A) |
|
181 |
case True |
|
182 |
have "A" by fact |
|
183 |
then show "A = B" using * by simp |
|
184 |
next |
|
185 |
case False |
|
186 |
have "\<not>A" by fact |
|
187 |
then show "A = B" using * by auto |
|
188 |
qed |
|
189 |
then show "A \<equiv> B" by (rule eq_reflection) |
|
190 |
qed |
|
191 |
||
192 |
ML {* |
|
193 |
fun atomize_thm thm = |
|
194 |
let |
|
221 | 195 |
val thm' = Thm.freezeT (forall_intr_vars thm) |
139 | 196 |
val thm'' = ObjectLogic.atomize (cprop_of thm') |
197 |
in |
|
221 | 198 |
@{thm Pure.equal_elim_rule1} OF [thm'', thm'] |
139 | 199 |
end |
200 |
*} |
|
201 |
||
140
00d141f2daa7
Further reorganizing the file
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
139
diff
changeset
|
202 |
ML {* atomize_thm @{thm list.induct} *} |
139 | 203 |
|
387 | 204 |
section {* infrastructure about id *} |
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
205 |
|
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
206 |
(* Need to have a meta-equality *) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
207 |
lemma id_def_sym: "(\<lambda>x. x) \<equiv> id" |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
208 |
by (simp add: id_def) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
209 |
(* TODO: can be also obtained with: *) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
210 |
ML {* symmetric (eq_reflection OF @{thms id_def}) *} |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
211 |
|
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
212 |
lemma prod_fun_id: "prod_fun id id \<equiv> id" |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
213 |
by (rule eq_reflection) (simp add: prod_fun_def) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
214 |
|
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
215 |
lemma map_id: "map id \<equiv> id" |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
216 |
apply (rule eq_reflection) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
217 |
apply (rule ext) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
218 |
apply (rule_tac list="x" in list.induct) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
219 |
apply (simp_all) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
220 |
done |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
221 |
|
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
222 |
ML {* |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
223 |
fun simp_ids lthy thm = |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
224 |
MetaSimplifier.rewrite_rule @{thms eq_reflection[OF FUN_MAP_I] eq_reflection[OF id_apply] id_def_sym prod_fun_id map_id} thm |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
225 |
*} |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
226 |
|
387 | 227 |
section {* Does the same as 'subst' in a given theorem *} |
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
228 |
|
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
229 |
ML {* |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
230 |
fun eqsubst_thm ctxt thms thm = |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
231 |
let |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
232 |
val goalstate = Goal.init (Thm.cprop_of thm) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
233 |
val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
234 |
NONE => error "eqsubst_thm" |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
235 |
| SOME th => cprem_of th 1 |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
236 |
val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1 |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
237 |
val goal = Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a'); |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
238 |
val cgoal = cterm_of (ProofContext.theory_of ctxt) goal |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
239 |
val rt = Goal.prove_internal [] cgoal (fn _ => tac); |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
240 |
in |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
241 |
@{thm Pure.equal_elim_rule1} OF [rt, thm] |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
242 |
end |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
243 |
*} |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
244 |
|
387 | 245 |
section {* Infrastructure about definitions *} |
246 |
||
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
247 |
text {* expects atomized definition *} |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
248 |
ML {* |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
249 |
fun add_lower_defs_aux lthy thm = |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
250 |
let |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
251 |
val e1 = @{thm fun_cong} OF [thm]; |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
252 |
val f = eqsubst_thm lthy @{thms fun_map.simps} e1; |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
253 |
val g = simp_ids lthy f |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
254 |
in |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
255 |
(simp_ids lthy thm) :: (add_lower_defs_aux lthy g) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
256 |
end |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
257 |
handle _ => [simp_ids lthy thm] |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
258 |
*} |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
259 |
|
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
260 |
ML {* |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
261 |
fun add_lower_defs lthy def = |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
262 |
let |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
263 |
val def_pre_sym = symmetric def |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
264 |
val def_atom = atomize_thm def_pre_sym |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
265 |
val defs_all = add_lower_defs_aux lthy def_atom |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
266 |
in |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
267 |
map Thm.varifyT defs_all |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
268 |
end |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
269 |
*} |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
270 |
|
387 | 271 |
section {* infrastructure about collecting theorems for calling lifting *} |
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
272 |
|
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
264
diff
changeset
|
273 |
ML {* |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
274 |
fun lookup_quot_data lthy qty = |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
275 |
let |
311
77fc6f3c0343
changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents:
310
diff
changeset
|
276 |
val qty_name = fst (dest_Type qty) |
314 | 277 |
val SOME quotdata = quotdata_lookup lthy qty_name |
311
77fc6f3c0343
changed the quotdata to be a symtab table (needs fixing)
Christian Urban <urbanc@in.tum.de>
parents:
310
diff
changeset
|
278 |
(* cu: Changed the lookup\<dots>not sure whether this works *) |
303
991b0e53f9dc
More code cleaning and commenting
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
302
diff
changeset
|
279 |
(* TODO: Should no longer be needed *) |
257
68bd5c2a1b96
Fixed quotdata_lookup.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
255
diff
changeset
|
280 |
val rty = Logic.unvarifyT (#rtyp quotdata) |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
281 |
val rel = #rel quotdata |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
282 |
val rel_eqv = #equiv_thm quotdata |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
283 |
val rel_refl_pre = @{thm EQUIV_REFL} OF [rel_eqv] |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
284 |
val rel_refl = @{thm spec} OF [MetaSimplifier.rewrite_rule [@{thm REFL_def}] rel_refl_pre] |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
285 |
in |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
286 |
(rty, rel, rel_refl, rel_eqv) |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
287 |
end |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
288 |
*} |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
289 |
|
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
290 |
ML {* |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
291 |
fun lookup_quot_thms lthy qty_name = |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
292 |
let |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
293 |
val thy = ProofContext.theory_of lthy; |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
294 |
val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2") |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
295 |
val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same") |
269 | 296 |
val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10") |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
297 |
val quot = PureThy.get_thm thy ("QUOTIENT_" ^ qty_name) |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
298 |
in |
269 | 299 |
(trans2, reps_same, absrep, quot) |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
300 |
end |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
301 |
*} |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
302 |
|
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
303 |
ML {* |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
304 |
fun lookup_quot_consts defs = |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
305 |
let |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
306 |
fun dest_term (a $ b) = (a, b); |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
307 |
val def_terms = map (snd o Logic.dest_equals o concl_of) defs; |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
308 |
in |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
309 |
map (fst o dest_Const o snd o dest_term) def_terms |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
310 |
end |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
311 |
*} |
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
312 |
|
275
34ad627ac5d5
fixed definition of PLUS
Christian Urban <urbanc@in.tum.de>
parents:
274
diff
changeset
|
313 |
|
273
b82e765ca464
Lifting 'fold1.simps(2)' and some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
270
diff
changeset
|
314 |
|
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
315 |
(******************************************) |
325 | 316 |
(******************************************) |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
317 |
(* version with explicit qtrm *) |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
318 |
(******************************************) |
325 | 319 |
(******************************************) |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
320 |
|
348
b1f83c7a8674
More theorems lifted in the goal-directed way.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
347
diff
changeset
|
321 |
|
338
62b188959c8a
Move atomize_goal to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
336
diff
changeset
|
322 |
ML {* |
383
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
323 |
(* |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
324 |
Regularizing an rtrm means: |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
325 |
- quantifiers over a type that needs lifting are replaced by |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
326 |
bounded quantifiers, for example: |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
327 |
\<forall>x. P \<Longrightarrow> \<forall>x \<in> (Respects R). P / All (Respects R) P |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
328 |
|
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
329 |
the relation R is given by the rty and qty; |
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
330 |
|
383
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
331 |
- abstractions over a type that needs lifting are replaced |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
332 |
by bounded abstractions: |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
333 |
\<lambda>x. P \<Longrightarrow> Ball (Respects R) (\<lambda>x. P) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
334 |
|
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
335 |
- equalities over the type being lifted are replaced by |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
336 |
corresponding relations: |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
337 |
A = B \<Longrightarrow> A \<approx> B |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
338 |
|
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
339 |
example with more complicated types of A, B: |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
340 |
A = B \<Longrightarrow> (op = \<Longrightarrow> op \<approx>) A B |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
341 |
*) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
342 |
|
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
343 |
|
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
344 |
(* builds the relation that is the argument of respects *) |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
345 |
fun mk_resp_arg lthy (rty, qty) = |
319 | 346 |
let |
347 |
val thy = ProofContext.theory_of lthy |
|
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
348 |
in |
334 | 349 |
if rty = qty |
350 |
then HOLogic.eq_const rty |
|
351 |
else |
|
352 |
case (rty, qty) of |
|
353 |
(Type (s, tys), Type (s', tys')) => |
|
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
354 |
if s = s' |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
355 |
then let |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
356 |
val SOME map_info = maps_lookup thy s |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
357 |
val args = map (mk_resp_arg lthy) (tys ~~ tys') |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
358 |
in |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
359 |
list_comb (Const (#relfun map_info, dummyT), args) |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
360 |
end |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
361 |
else let |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
362 |
val SOME qinfo = quotdata_lookup_thy thy s' |
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
363 |
(* FIXME: check in this case that the rty and qty *) |
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
364 |
(* FIXME: correspond to each other *) |
353
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents:
351
diff
changeset
|
365 |
val (s, _) = dest_Const (#rel qinfo) |
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents:
351
diff
changeset
|
366 |
(* FIXME: the relation should only be the string *) |
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents:
351
diff
changeset
|
367 |
(* FIXME: and the type needs to be calculated as below *) |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
368 |
in |
353
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
parents:
351
diff
changeset
|
369 |
Const (s, rty --> rty --> @{typ bool}) |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
370 |
end |
334 | 371 |
| _ => HOLogic.eq_const dummyT |
351 | 372 |
(* FIXME: check that the types correspond to each other? *) |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
373 |
end |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
374 |
*} |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
375 |
|
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
376 |
ML {* |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
377 |
val mk_babs = Const (@{const_name "Babs"}, dummyT) |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
378 |
val mk_ball = Const (@{const_name "Ball"}, dummyT) |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
379 |
val mk_bex = Const (@{const_name "Bex"}, dummyT) |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
380 |
val mk_resp = Const (@{const_name Respects}, dummyT) |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
381 |
*} |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
382 |
|
323 | 383 |
|
384 |
ML {* |
|
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
385 |
(* - applies f to the subterm of an abstraction, *) |
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
386 |
(* otherwise to the given term, *) |
351 | 387 |
(* - used by REGULARIZE, therefore abstracted *) |
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
388 |
(* variables do not have to be treated specially *) |
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
389 |
|
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
390 |
fun apply_subt f trm1 trm2 = |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
391 |
case (trm1, trm2) of |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
392 |
(Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t') |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
393 |
| _ => f trm1 trm2 |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
394 |
|
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
395 |
(* the major type of All and Ex quantifiers *) |
334 | 396 |
fun qnt_typ ty = domain_type (domain_type ty) |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
397 |
*} |
319 | 398 |
|
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
399 |
ML {* |
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
400 |
(* produces a regularized version of rtm *) |
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
401 |
(* - the result is still not completely typed *) |
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
402 |
(* - does not need any special treatment of *) |
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
403 |
(* bound variables *) |
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
404 |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
405 |
fun REGULARIZE_trm lthy rtrm qtrm = |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
406 |
case (rtrm, qtrm) of |
325 | 407 |
(Abs (x, ty, t), Abs (x', ty', t')) => |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
408 |
let |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
409 |
val subtrm = REGULARIZE_trm lthy t t' |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
410 |
in |
325 | 411 |
if ty = ty' |
412 |
then Abs (x, ty, subtrm) |
|
326
e755a5da14c8
my first version of repabs injection
Christian Urban <urbanc@in.tum.de>
parents:
325
diff
changeset
|
413 |
else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
414 |
end |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
415 |
| (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') => |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
416 |
let |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
417 |
val subtrm = apply_subt (REGULARIZE_trm lthy) t t' |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
418 |
in |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
419 |
if ty = ty' |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
420 |
then Const (@{const_name "All"}, ty) $ subtrm |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
421 |
else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
422 |
end |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
423 |
| (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') => |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
424 |
let |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
425 |
val subtrm = apply_subt (REGULARIZE_trm lthy) t t' |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
426 |
in |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
427 |
if ty = ty' |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
428 |
then Const (@{const_name "Ex"}, ty) $ subtrm |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
429 |
else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
430 |
end |
351 | 431 |
(* FIXME: Should = only be replaced, when fully applied? *) |
432 |
(* Then there must be a 2nd argument *) |
|
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
433 |
| (Const (@{const_name "op ="}, ty) $ t, Const (@{const_name "op ="}, ty') $ t') => |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
434 |
let |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
435 |
val subtrm = REGULARIZE_trm lthy t t' |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
436 |
in |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
437 |
if ty = ty' |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
438 |
then Const (@{const_name "op ="}, ty) $ subtrm |
349
f507f088de73
domain_type in regularizing equality
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
348
diff
changeset
|
439 |
else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
440 |
end |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
441 |
| (t1 $ t2, t1' $ t2') => |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
442 |
(REGULARIZE_trm lthy t1 t1') $ (REGULARIZE_trm lthy t2 t2') |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
443 |
| (Free (x, ty), Free (x', ty')) => |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
444 |
if x = x' |
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
445 |
then rtrm (* FIXME: check whether types corresponds *) |
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
446 |
else raise (LIFT_MATCH "regularize (frees)") |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
447 |
| (Bound i, Bound i') => |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
448 |
if i = i' |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
449 |
then rtrm |
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
450 |
else raise (LIFT_MATCH "regularize (bounds)") |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
451 |
| (Const (s, ty), Const (s', ty')) => |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
452 |
if s = s' andalso ty = ty' |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
453 |
then rtrm |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
454 |
else rtrm (* FIXME: check correspondence according to definitions *) |
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
455 |
| (rt, qt) => |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
456 |
raise (LIFT_MATCH "regularize (default)") |
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
457 |
*} |
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
458 |
|
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
parents:
319
diff
changeset
|
459 |
ML {* |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
460 |
fun mk_REGULARIZE_goal lthy rtrm qtrm = |
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
461 |
Logic.mk_implies (rtrm, Syntax.check_term lthy (REGULARIZE_trm lthy rtrm qtrm)) |
319 | 462 |
*} |
293
653460d3e849
tuned the code in quotient and quotient_def
Christian Urban <urbanc@in.tum.de>
parents:
292
diff
changeset
|
463 |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
464 |
(* |
383
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
465 |
To prove that the raw theorem implies the regularised one, |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
466 |
we try in order: |
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
467 |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
468 |
- Reflexivity of the relation |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
469 |
- Assumption |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
470 |
- Elimnating quantifiers on both sides of toplevel implication |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
471 |
- Simplifying implications on both sides of toplevel implication |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
472 |
- Ball (Respects ?E) ?P = All ?P |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
473 |
- (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
474 |
|
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
475 |
*) |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
476 |
|
390 | 477 |
lemma my_equiv_res_forallR: |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
478 |
fixes P::"'a \<Rightarrow> bool" |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
479 |
fixes Q::"'b \<Rightarrow> bool" |
390 | 480 |
assumes b: "(All Q) \<longrightarrow> (All P)" |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
481 |
shows "(All Q) \<longrightarrow> Ball (Respects E) P" |
390 | 482 |
using b by auto |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
483 |
|
390 | 484 |
lemma my_equiv_res_forallL: |
485 |
fixes P::"'a \<Rightarrow> bool" |
|
486 |
fixes Q::"'b \<Rightarrow> bool" |
|
487 |
assumes a: "EQUIV E" |
|
488 |
assumes b: "(All Q) \<longrightarrow> (All P)" |
|
489 |
shows "Ball (Respects E) P \<longrightarrow> (All P)" |
|
490 |
using a b |
|
491 |
unfolding EQUIV_def |
|
492 |
by (metis IN_RESPECTS) |
|
493 |
||
494 |
lemma my_equiv_res_existsR: |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
495 |
fixes P::"'a \<Rightarrow> bool" |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
496 |
fixes Q::"'b \<Rightarrow> bool" |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
497 |
assumes a: "EQUIV E" |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
498 |
and b: "(Ex Q) \<longrightarrow> (Ex P)" |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
499 |
shows "(Ex Q) \<longrightarrow> Bex (Respects E) P" |
390 | 500 |
using a b |
501 |
unfolding EQUIV_def |
|
502 |
by (metis IN_RESPECTS) |
|
503 |
||
504 |
lemma my_equiv_res_existsL: |
|
505 |
fixes P::"'a \<Rightarrow> bool" |
|
506 |
fixes Q::"'b \<Rightarrow> bool" |
|
507 |
assumes b: "(Ex Q) \<longrightarrow> (Ex P)" |
|
508 |
shows "Bex (Respects E) Q \<longrightarrow> (Ex P)" |
|
509 |
using b |
|
510 |
by (auto) |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
511 |
|
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
512 |
lemma universal_twice: |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
513 |
assumes *: "\<And>x. (P x \<longrightarrow> Q x)" |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
514 |
shows "(\<forall>x. P x) \<longrightarrow> (\<forall>x. Q x)" |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
515 |
using * by auto |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
516 |
|
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
517 |
lemma implication_twice: |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
518 |
assumes a: "c \<longrightarrow> a" |
390 | 519 |
assumes b: "b \<longrightarrow> d" |
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
520 |
shows "(a \<longrightarrow> b) \<longrightarrow> (c \<longrightarrow> d)" |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
521 |
using a b by auto |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
522 |
|
330
1a0f0b758071
a little tuning of comments
Christian Urban <urbanc@in.tum.de>
parents:
326
diff
changeset
|
523 |
(* version of REGULARIZE_tac including debugging information *) |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
524 |
ML {* |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
525 |
fun my_print_tac ctxt s thm = |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
526 |
let |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
527 |
val prems_str = prems_of thm |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
528 |
|> map (Syntax.string_of_term ctxt) |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
529 |
|> cat_lines |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
530 |
val _ = tracing (s ^ "\n" ^ prems_str) |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
531 |
in |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
532 |
Seq.single thm |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
533 |
end |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
534 |
|
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
535 |
fun DT ctxt s tac = EVERY' [tac, K (my_print_tac ctxt ("after " ^ s))] |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
536 |
*} |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
537 |
|
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
538 |
ML {* |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
539 |
fun REGULARIZE_tac' lthy rel_refl rel_eqv = |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
540 |
(REPEAT1 o FIRST1) |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
541 |
[(K (print_tac "start")) THEN' (K no_tac), |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
542 |
DT lthy "1" (rtac rel_refl), |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
543 |
DT lthy "2" atac, |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
544 |
DT lthy "3" (rtac @{thm universal_twice}), |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
545 |
DT lthy "4" (rtac @{thm impI} THEN' atac), |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
546 |
DT lthy "5" (rtac @{thm implication_twice}), |
390 | 547 |
DT lthy "6" (rtac @{thm my_equiv_res_forallR}), |
548 |
DT lthy "7" (rtac (rel_eqv RS @{thm my_equiv_res_existsR})), |
|
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
549 |
(* For a = b \<longrightarrow> a \<approx> b *) |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
550 |
DT lthy "8" (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl), |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
551 |
DT lthy "9" (rtac @{thm RIGHT_RES_FORALL_REGULAR})] |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
552 |
*} |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
553 |
|
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
554 |
ML {* |
383
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
555 |
fun regularize_tac ctxt rel_eqv rel_refl = |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
556 |
(ObjectLogic.full_atomize_tac) THEN' |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
557 |
REPEAT_ALL_NEW (FIRST' [ |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
558 |
rtac rel_refl, |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
559 |
atac, |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
560 |
rtac @{thm universal_twice}, |
390 | 561 |
rtac @{thm impI} THEN' atac, |
383
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
562 |
rtac @{thm implication_twice}, |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
563 |
EqSubst.eqsubst_tac ctxt [0] |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
564 |
[(@{thm equiv_res_forall} OF [rel_eqv]), |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
565 |
(@{thm equiv_res_exists} OF [rel_eqv])], |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
566 |
(* For a = b \<longrightarrow> a \<approx> b *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
567 |
(rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl), |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
568 |
(rtac @{thm RIGHT_RES_FORALL_REGULAR}) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
569 |
]); |
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
570 |
*} |
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
parents:
320
diff
changeset
|
571 |
|
390 | 572 |
ML {* |
573 |
fun regularize_tac ctxt rel_eqv rel_refl = |
|
574 |
(ObjectLogic.full_atomize_tac) THEN' |
|
575 |
REPEAT_ALL_NEW (FIRST' |
|
576 |
[(K (print_tac "start")) THEN' (K no_tac), |
|
577 |
DT ctxt "1" (rtac rel_refl), |
|
578 |
DT ctxt "2" atac, |
|
579 |
DT ctxt "3" (rtac @{thm universal_twice}), |
|
580 |
DT ctxt "4" (rtac @{thm impI} THEN' atac), |
|
581 |
DT ctxt "5" (rtac @{thm implication_twice}), |
|
582 |
DT ctxt "6" (EqSubst.eqsubst_tac ctxt [0] |
|
583 |
[(@{thm equiv_res_forall} OF [rel_eqv]), |
|
584 |
(@{thm equiv_res_exists} OF [rel_eqv])]), |
|
585 |
(* For a = b \<longrightarrow> a \<approx> b *) |
|
586 |
DT ctxt "7" (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl), |
|
587 |
DT ctxt "8" (rtac @{thm RIGHT_RES_FORALL_REGULAR}) |
|
588 |
]); |
|
589 |
*} |
|
590 |
||
591 |
thm RIGHT_RES_FORALL_REGULAR |
|
592 |
||
593 |
section {* Injections of REP and ABSes *} |
|
383
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
594 |
|
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
595 |
(* |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
596 |
Injecting REPABS means: |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
597 |
|
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
598 |
For abstractions: |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
599 |
* If the type of the abstraction doesn't need lifting we recurse. |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
600 |
* If it does we add RepAbs around the whole term and check if the |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
601 |
variable needs lifting. |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
602 |
* If it doesn't then we recurse |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
603 |
* If it does we recurse and put 'RepAbs' around all occurences |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
604 |
of the variable in the obtained subterm. This in combination |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
605 |
with the RepAbs above will let us change the type of the |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
606 |
abstraction with rewriting. |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
607 |
For applications: |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
608 |
* If the term is 'Respects' applied to anything we leave it unchanged |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
609 |
* If the term needs lifting and the head is a constant that we know |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
610 |
how to lift, we put a RepAbs and recurse |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
611 |
* If the term needs lifting and the head is a free applied to subterms |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
612 |
(if it is not applied we treated it in Abs branch) then we |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
613 |
put RepAbs and recurse |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
614 |
* Otherwise just recurse. |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
615 |
*) |
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
616 |
|
336
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
617 |
ML {* |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
618 |
fun mk_repabs lthy (T, T') trm = |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
619 |
Quotient_Def.get_fun repF lthy (T, T') |
354
2eb6d527dfe4
addded a tactic, which sets up the three goals of the `algorithm'
Christian Urban <urbanc@in.tum.de>
parents:
353
diff
changeset
|
620 |
$ (Quotient_Def.get_fun absF lthy (T, T') $ trm) |
336
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
621 |
*} |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
622 |
|
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
623 |
ML {* |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
624 |
(* bound variables need to be treated properly, *) |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
625 |
(* as the type of subterms need to be calculated *) |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
626 |
|
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
627 |
fun inj_REPABS lthy (rtrm, qtrm) = |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
628 |
let |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
629 |
val rty = fastype_of rtrm |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
630 |
val qty = fastype_of qtrm |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
631 |
in |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
632 |
case (rtrm, qtrm) of |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
633 |
(Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') => |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
634 |
Const (@{const_name "Ball"}, T) $ r $ (inj_REPABS lthy (t, t')) |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
635 |
| (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') => |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
636 |
Const (@{const_name "Bex"}, T) $ r $ (inj_REPABS lthy (t, t')) |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
637 |
| (Const (@{const_name "Babs"}, T) $ r $ t, t') => |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
638 |
Const (@{const_name "Babs"}, T) $ r $ (inj_REPABS lthy (t, t')) |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
639 |
| (Abs (x, T, t), Abs (x', T', t')) => |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
640 |
let |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
641 |
val (y, s) = Term.dest_abs (x, T, t) |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
642 |
val (_, s') = Term.dest_abs (x', T', t') |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
643 |
val yvar = Free (y, T) |
345
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
644 |
val result = lambda yvar (inj_REPABS lthy (s, s')) |
336
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
645 |
in |
345
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
646 |
if rty = qty |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
647 |
then result |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
648 |
else mk_repabs lthy (rty, qty) result |
336
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
649 |
end |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
650 |
| _ => |
345
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
651 |
(* FIXME / TODO: this is a case that needs to be looked at *) |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
652 |
(* - variables get a rep-abs insde and outside an application *) |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
653 |
(* - constants only get a rep-abs on the outside of the application *) |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
654 |
(* - applications get a rep-abs insde and outside an application *) |
336
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
655 |
let |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
656 |
val (rhead, rargs) = strip_comb rtrm |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
657 |
val (qhead, qargs) = strip_comb qtrm |
345
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
658 |
val rargs' = map (inj_REPABS lthy) (rargs ~~ qargs) |
336
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
659 |
in |
345
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
660 |
if rty = qty |
355
abc6bfd0576e
More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
354
diff
changeset
|
661 |
then |
abc6bfd0576e
More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
354
diff
changeset
|
662 |
case (rhead, qhead) of |
abc6bfd0576e
More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
354
diff
changeset
|
663 |
(Free (_, T), Free (_, T')) => |
abc6bfd0576e
More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
354
diff
changeset
|
664 |
if T = T' then list_comb (rhead, rargs') |
abc6bfd0576e
More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
354
diff
changeset
|
665 |
else list_comb (mk_repabs lthy (T, T') rhead, rargs') |
abc6bfd0576e
More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
354
diff
changeset
|
666 |
| _ => list_comb (rhead, rargs') |
345
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
667 |
else |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
668 |
case (rhead, qhead, length rargs') of |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
669 |
(Const _, Const _, 0) => mk_repabs lthy (rty, qty) rhead |
355
abc6bfd0576e
More fixes for inj_REPABS
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
354
diff
changeset
|
670 |
| (Free (_, T), Free (_, T'), 0) => mk_repabs lthy (T, T') rhead |
345
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
671 |
| (Const _, Const _, _) => mk_repabs lthy (rty, qty) (list_comb (rhead, rargs')) |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
672 |
| (Free (x, T), Free (x', T'), _) => |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
673 |
mk_repabs lthy (rty, qty) (list_comb (mk_repabs lthy (T, T') rhead, rargs')) |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
674 |
| (Abs _, Abs _, _ ) => |
573e2b625e8e
a version of inj_REPABS (needs to be looked at again later)
Christian Urban <urbanc@in.tum.de>
parents:
341
diff
changeset
|
675 |
mk_repabs lthy (rty, qty) (list_comb (inj_REPABS lthy (rhead, qhead), rargs')) |
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
676 |
| _ => raise (LIFT_MATCH "injection") |
336
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
677 |
end |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
678 |
end |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
679 |
*} |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
680 |
|
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
681 |
ML {* |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
682 |
fun mk_inj_REPABS_goal lthy (rtrm, qtrm) = |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
683 |
Logic.mk_equals (rtrm, Syntax.check_term lthy (inj_REPABS lthy (rtrm, qtrm))) |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
684 |
*} |
e6b6e5ba0cc5
Moved new repabs_inj code to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
334
diff
changeset
|
685 |
|
387 | 686 |
section {* RepAbs injection tactic *} |
687 |
(* |
|
688 |
||
689 |
To prove that the regularised theorem implies the abs/rep injected, we first |
|
690 |
atomize it and then try: |
|
691 |
||
692 |
1) theorems 'trans2' from the appropriate QUOT_TYPE |
|
693 |
2) remove lambdas from both sides (LAMBDA_RES_TAC) |
|
694 |
3) remove Ball/Bex from the right hand side |
|
695 |
4) use user-supplied RSP theorems |
|
696 |
5) remove rep_abs from the right side |
|
697 |
6) reflexivity of equality |
|
698 |
7) split applications of lifted type (apply_rsp) |
|
699 |
8) split applications of non-lifted type (cong_tac) |
|
700 |
9) apply extentionality |
|
701 |
10) reflexivity of the relation |
|
702 |
11) assumption |
|
703 |
(Lambdas under respects may have left us some assumptions) |
|
704 |
12) proving obvious higher order equalities by simplifying fun_rel |
|
705 |
(not sure if it is still needed?) |
|
706 |
13) unfolding lambda on one side |
|
707 |
14) simplifying (= ===> =) for simpler respectfullness |
|
708 |
||
709 |
*) |
|
710 |
||
711 |
ML {* |
|
712 |
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} => |
|
713 |
let |
|
714 |
val pat = Drule.strip_imp_concl (cprop_of thm) |
|
715 |
val insts = Thm.match (pat, concl) |
|
716 |
in |
|
717 |
rtac (Drule.instantiate insts thm) 1 |
|
718 |
end |
|
719 |
handle _ => no_tac) |
|
720 |
*} |
|
721 |
||
722 |
ML {* |
|
723 |
fun CHANGED' tac = (fn i => CHANGED (tac i)) |
|
724 |
*} |
|
725 |
||
726 |
ML {* |
|
727 |
fun quotient_tac quot_thm = |
|
728 |
REPEAT_ALL_NEW (FIRST' [ |
|
729 |
rtac @{thm FUN_QUOTIENT}, |
|
730 |
rtac quot_thm, |
|
731 |
rtac @{thm IDENTITY_QUOTIENT}, |
|
732 |
(* For functional identity quotients, (op = ---> op =) *) |
|
733 |
CHANGED' ( |
|
734 |
(simp_tac (HOL_ss addsimps @{thms eq_reflection[OF FUN_MAP_I] eq_reflection[OF id_apply] id_def_sym prod_fun_id map_id} |
|
735 |
))) |
|
736 |
]) |
|
737 |
*} |
|
738 |
||
739 |
ML {* |
|
740 |
fun LAMBDA_RES_TAC ctxt i st = |
|
741 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
742 |
(_ $ (_ $ (Abs(_, _, _)) $ (Abs(_, _, _)))) => |
|
743 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
744 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
745 |
| _ => fn _ => no_tac) i st |
|
746 |
*} |
|
747 |
||
748 |
ML {* |
|
749 |
fun WEAK_LAMBDA_RES_TAC ctxt i st = |
|
750 |
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of |
|
751 |
(_ $ (_ $ _ $ (Abs(_, _, _)))) => |
|
752 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
753 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
754 |
| (_ $ (_ $ (Abs(_, _, _)) $ _)) => |
|
755 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN' |
|
756 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI}) |
|
757 |
| _ => fn _ => no_tac) i st |
|
758 |
*} |
|
759 |
||
760 |
ML {* (* Legacy *) |
|
761 |
fun needs_lift (rty as Type (rty_s, _)) ty = |
|
762 |
case ty of |
|
763 |
Type (s, tys) => |
|
764 |
(s = rty_s) orelse (exists (needs_lift rty) tys) |
|
765 |
| _ => false |
|
766 |
||
767 |
*} |
|
768 |
||
769 |
ML {* |
|
770 |
fun APPLY_RSP_TAC rty = Subgoal.FOCUS (fn {concl, ...} => |
|
771 |
let |
|
772 |
val (_ $ (R $ (f $ _) $ (_ $ _))) = term_of concl; |
|
773 |
val pat = Drule.strip_imp_concl (cprop_of @{thm APPLY_RSP}); |
|
774 |
val insts = Thm.match (pat, concl) |
|
775 |
in |
|
776 |
if needs_lift rty (type_of f) then |
|
777 |
rtac (Drule.instantiate insts @{thm APPLY_RSP}) 1 |
|
778 |
else no_tac |
|
779 |
end |
|
780 |
handle _ => no_tac) |
|
781 |
*} |
|
782 |
||
783 |
ML {* |
|
784 |
val ball_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} => |
|
785 |
let |
|
786 |
val _ $ (_ $ (Const (@{const_name Ball}, _) $ _) $ |
|
787 |
(Const (@{const_name Ball}, _) $ _)) = term_of concl |
|
788 |
in |
|
789 |
((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps})) |
|
790 |
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI} |
|
791 |
THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN' |
|
792 |
(simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1 |
|
793 |
end |
|
794 |
handle _ => no_tac) |
|
795 |
*} |
|
796 |
||
797 |
ML {* |
|
798 |
val bex_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} => |
|
799 |
let |
|
800 |
val _ $ (_ $ (Const (@{const_name Bex}, _) $ _) $ |
|
801 |
(Const (@{const_name Bex}, _) $ _)) = term_of concl |
|
802 |
in |
|
803 |
((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps})) |
|
804 |
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI} |
|
805 |
THEN' instantiate_tac @{thm RES_EXISTS_RSP} ctxt THEN' |
|
806 |
(simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1 |
|
807 |
end |
|
808 |
handle _ => no_tac) |
|
809 |
*} |
|
810 |
||
811 |
ML {* |
|
812 |
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac) |
|
813 |
*} |
|
814 |
||
815 |
ML {* |
|
816 |
fun r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms = |
|
817 |
(FIRST' [ |
|
818 |
rtac trans_thm, |
|
819 |
LAMBDA_RES_TAC ctxt, |
|
389 | 820 |
rtac @{thm RES_FORALL_RSP}, |
387 | 821 |
ball_rsp_tac ctxt, |
389 | 822 |
rtac @{thm RES_EXISTS_RSP}, |
387 | 823 |
bex_rsp_tac ctxt, |
824 |
FIRST' (map rtac rsp_thms), |
|
825 |
rtac refl, |
|
826 |
(instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' (RANGE [SOLVES' (quotient_tac quot_thm)])), |
|
827 |
(APPLY_RSP_TAC rty ctxt THEN' (RANGE [SOLVES' (quotient_tac quot_thm), SOLVES' (quotient_tac quot_thm)])), |
|
828 |
Cong_Tac.cong_tac @{thm cong}, |
|
829 |
rtac @{thm ext}, |
|
830 |
rtac reflex_thm, |
|
831 |
atac, |
|
832 |
SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps})), |
|
833 |
WEAK_LAMBDA_RES_TAC ctxt, |
|
834 |
CHANGED' (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ})) |
|
835 |
]) |
|
836 |
*} |
|
837 |
||
838 |
||
839 |
(****************************************) |
|
840 |
(* cleaning of the theorem *) |
|
841 |
(****************************************) |
|
842 |
||
843 |
||
844 |
||
845 |
(* changes (?'a ?'b raw) (?'a ?'b quo) (int 'b raw \<Rightarrow> bool) to (int 'b quo \<Rightarrow> bool) *) |
|
846 |
ML {* |
|
847 |
fun exchange_ty lthy rty qty ty = |
|
848 |
let |
|
849 |
val thy = ProofContext.theory_of lthy |
|
850 |
in |
|
851 |
if Sign.typ_instance thy (ty, rty) then |
|
852 |
let |
|
853 |
val inst = Sign.typ_match thy (rty, ty) Vartab.empty |
|
854 |
in |
|
855 |
Envir.subst_type inst qty |
|
856 |
end |
|
857 |
else |
|
858 |
let |
|
859 |
val (s, tys) = dest_Type ty |
|
860 |
in |
|
861 |
Type (s, map (exchange_ty lthy rty qty) tys) |
|
862 |
end |
|
863 |
end |
|
864 |
handle TYPE _ => ty (* for dest_Type *) |
|
865 |
*} |
|
866 |
||
867 |
||
868 |
ML {* |
|
869 |
fun find_matching_types rty ty = |
|
870 |
if Type.raw_instance (Logic.varifyT ty, rty) |
|
871 |
then [ty] |
|
872 |
else |
|
873 |
let val (s, tys) = dest_Type ty in |
|
874 |
flat (map (find_matching_types rty) tys) |
|
875 |
end |
|
876 |
handle TYPE _ => [] |
|
877 |
*} |
|
878 |
||
879 |
ML {* |
|
880 |
fun negF absF = repF |
|
881 |
| negF repF = absF |
|
882 |
||
883 |
fun get_fun flag qenv lthy ty = |
|
884 |
let |
|
885 |
||
886 |
fun get_fun_aux s fs = |
|
887 |
(case (maps_lookup (ProofContext.theory_of lthy) s) of |
|
888 |
SOME info => list_comb (Const (#mapfun info, dummyT), fs) |
|
889 |
| NONE => error ("no map association for type " ^ s)) |
|
890 |
||
891 |
fun get_const flag qty = |
|
892 |
let |
|
893 |
val thy = ProofContext.theory_of lthy |
|
894 |
val qty_name = Long_Name.base_name (fst (dest_Type qty)) |
|
895 |
in |
|
896 |
case flag of |
|
897 |
absF => Const (Sign.full_bname thy ("ABS_" ^ qty_name), dummyT) |
|
898 |
| repF => Const (Sign.full_bname thy ("REP_" ^ qty_name), dummyT) |
|
899 |
end |
|
900 |
||
901 |
fun mk_identity ty = Abs ("", ty, Bound 0) |
|
902 |
||
903 |
in |
|
904 |
if (AList.defined (op=) qenv ty) |
|
905 |
then (get_const flag ty) |
|
906 |
else (case ty of |
|
907 |
TFree _ => mk_identity ty |
|
908 |
| Type (_, []) => mk_identity ty |
|
909 |
| Type ("fun" , [ty1, ty2]) => |
|
910 |
let |
|
911 |
val fs_ty1 = get_fun (negF flag) qenv lthy ty1 |
|
912 |
val fs_ty2 = get_fun flag qenv lthy ty2 |
|
913 |
in |
|
914 |
get_fun_aux "fun" [fs_ty1, fs_ty2] |
|
915 |
end |
|
916 |
| Type (s, tys) => get_fun_aux s (map (get_fun flag qenv lthy) tys) |
|
917 |
| _ => error ("no type variables allowed")) |
|
918 |
end |
|
919 |
*} |
|
920 |
||
921 |
ML {* |
|
922 |
fun get_fun_OLD flag (rty, qty) lthy ty = |
|
923 |
let |
|
924 |
val tys = find_matching_types rty ty; |
|
925 |
val qenv = map (fn t => (exchange_ty lthy rty qty t, t)) tys; |
|
926 |
val xchg_ty = exchange_ty lthy rty qty ty |
|
927 |
in |
|
928 |
get_fun flag qenv lthy xchg_ty |
|
929 |
end |
|
930 |
*} |
|
931 |
||
932 |
ML {* |
|
389 | 933 |
fun applic_prs_old lthy rty qty absrep ty = |
387 | 934 |
let |
935 |
val rty = Logic.varifyT rty; |
|
936 |
val qty = Logic.varifyT qty; |
|
937 |
fun absty ty = |
|
938 |
exchange_ty lthy rty qty ty |
|
939 |
fun mk_rep tm = |
|
940 |
let |
|
941 |
val ty = exchange_ty lthy qty rty (fastype_of tm) |
|
942 |
in Syntax.check_term lthy ((get_fun_OLD repF (rty, qty) lthy ty) $ tm) end; |
|
943 |
fun mk_abs tm = |
|
944 |
let |
|
945 |
val ty = fastype_of tm |
|
946 |
in Syntax.check_term lthy ((get_fun_OLD absF (rty, qty) lthy ty) $ tm) end |
|
947 |
val (l, ltl) = Term.strip_type ty; |
|
948 |
val nl = map absty l; |
|
949 |
val vs = map (fn _ => "x") l; |
|
950 |
val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy; |
|
951 |
val args = map Free (vfs ~~ nl); |
|
952 |
val lhs = list_comb((Free (fname, nl ---> ltl)), args); |
|
953 |
val rargs = map mk_rep args; |
|
954 |
val f = Free (fname, nl ---> ltl); |
|
955 |
val rhs = mk_abs (list_comb((mk_rep f), rargs)); |
|
956 |
val eq = Logic.mk_equals (rhs, lhs); |
|
957 |
val ceq = cterm_of (ProofContext.theory_of lthy') eq; |
|
958 |
val sctxt = HOL_ss addsimps (absrep :: @{thms fun_map.simps}); |
|
959 |
val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1) |
|
960 |
val t_id = MetaSimplifier.rewrite_rule @{thms id_def_sym} t; |
|
961 |
in |
|
962 |
singleton (ProofContext.export lthy' lthy) t_id |
|
963 |
end |
|
964 |
*} |
|
965 |
||
389 | 966 |
ML {* |
967 |
fun applic_prs lthy absrep (rty, qty) = |
|
968 |
let |
|
969 |
fun mk_rep (T, T') tm = (Quotient_Def.get_fun repF lthy (T, T')) $ tm; |
|
970 |
fun mk_abs (T, T') tm = (Quotient_Def.get_fun absF lthy (T, T')) $ tm; |
|
971 |
val (raty, rgty) = Term.strip_type rty; |
|
972 |
val (qaty, qgty) = Term.strip_type qty; |
|
973 |
val vs = map (fn _ => "x") qaty; |
|
974 |
val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy; |
|
975 |
val f = Free (fname, qaty ---> qgty); |
|
976 |
val args = map Free (vfs ~~ qaty); |
|
977 |
val rhs = list_comb(f, args); |
|
978 |
val largs = map2 mk_rep (raty ~~ qaty) args; |
|
979 |
val lhs = mk_abs (rgty, qgty) (list_comb((mk_rep (raty ---> rgty, qaty ---> qgty) f), largs)); |
|
980 |
val llhs = Syntax.check_term lthy lhs; |
|
981 |
val eq = Logic.mk_equals (llhs, rhs); |
|
982 |
val ceq = cterm_of (ProofContext.theory_of lthy') eq; |
|
983 |
val sctxt = HOL_ss addsimps (absrep :: @{thms fun_map.simps map_id id_apply}); |
|
984 |
val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1) |
|
985 |
val t_id = MetaSimplifier.rewrite_rule @{thms eq_reflection[OF id_apply] id_def_sym} t; |
|
986 |
in |
|
987 |
singleton (ProofContext.export lthy' lthy) t_id |
|
988 |
end |
|
989 |
*} |
|
387 | 990 |
|
991 |
ML {* |
|
992 |
fun findaps_all rty tm = |
|
993 |
case tm of |
|
994 |
Abs(_, T, b) => |
|
995 |
findaps_all rty (subst_bound ((Free ("x", T)), b)) |
|
996 |
| (f $ a) => (findaps_all rty f @ findaps_all rty a) |
|
997 |
| Free (_, (T as (Type ("fun", (_ :: _))))) => |
|
998 |
(if needs_lift rty T then [T] else []) |
|
999 |
| _ => []; |
|
1000 |
fun findaps rty tm = distinct (op =) (findaps_all rty tm) |
|
1001 |
*} |
|
1002 |
||
1003 |
||
1004 |
ML {* |
|
389 | 1005 |
fun find_aps_all rtm qtm = |
1006 |
case (rtm, qtm) of |
|
1007 |
(Abs(_, T1, s1), Abs(_, T2, s2)) => |
|
1008 |
find_aps_all (subst_bound ((Free ("x", T1)), s1)) (subst_bound ((Free ("x", T2)), s2)) |
|
1009 |
| (((f1 as (Free (_, T1))) $ a1), ((f2 as (Free (_, T2))) $ a2)) => |
|
1010 |
let |
|
1011 |
val sub = (find_aps_all f1 f2) @ (find_aps_all a1 a2) |
|
1012 |
in |
|
1013 |
if T1 = T2 then sub else (T1, T2) :: sub |
|
1014 |
end |
|
1015 |
| ((f1 $ a1), (f2 $ a2)) => (find_aps_all f1 f2) @ (find_aps_all a1 a2) |
|
1016 |
| _ => []; |
|
1017 |
||
1018 |
fun find_aps rtm qtm = distinct (op =) (find_aps_all rtm qtm) |
|
1019 |
*} |
|
1020 |
||
1021 |
ML {* |
|
387 | 1022 |
(* FIXME: allex_prs and lambda_prs can be one function *) |
1023 |
fun allex_prs_tac lthy quot = |
|
1024 |
(EqSubst.eqsubst_tac lthy [0] @{thms FORALL_PRS[symmetric] EXISTS_PRS[symmetric]}) |
|
1025 |
THEN' (quotient_tac quot); |
|
1026 |
*} |
|
1027 |
||
1028 |
ML {* |
|
1029 |
let |
|
1030 |
val parser = Args.context -- Scan.lift Args.name_source |
|
1031 |
fun term_pat (ctxt, str) = |
|
1032 |
str |> ProofContext.read_term_pattern ctxt |
|
1033 |
|> ML_Syntax.print_term |
|
1034 |
|> ML_Syntax.atomic |
|
1035 |
in |
|
1036 |
ML_Antiquote.inline "term_pat" (parser >> term_pat) |
|
1037 |
end |
|
1038 |
*} |
|
1039 |
||
1040 |
ML {* |
|
1041 |
fun prep_trm thy (x, (T, t)) = |
|
1042 |
(cterm_of thy (Var (x, T)), cterm_of thy t) |
|
1043 |
||
1044 |
fun prep_ty thy (x, (S, ty)) = |
|
1045 |
(ctyp_of thy (TVar (x, S)), ctyp_of thy ty) |
|
1046 |
*} |
|
1047 |
||
1048 |
ML {* |
|
1049 |
fun matching_prs thy pat trm = |
|
1050 |
let |
|
1051 |
val univ = Unify.matchers thy [(pat, trm)] |
|
1052 |
val SOME (env, _) = Seq.pull univ |
|
1053 |
val tenv = Vartab.dest (Envir.term_env env) |
|
1054 |
val tyenv = Vartab.dest (Envir.type_env env) |
|
1055 |
in |
|
1056 |
(map (prep_ty thy) tyenv, map (prep_trm thy) tenv) |
|
1057 |
end |
|
1058 |
*} |
|
1059 |
||
1060 |
ML {* |
|
1061 |
fun lambda_prs_conv1 ctxt quot ctrm = |
|
1062 |
case (term_of ctrm) of ((Const (@{const_name "fun_map"}, _) $ r1 $ a2) $ (Abs _)) => |
|
1063 |
let |
|
1064 |
val (_, [ty_b, ty_a]) = dest_Type (fastype_of r1); |
|
1065 |
val (_, [ty_c, ty_d]) = dest_Type (fastype_of a2); |
|
1066 |
val thy = ProofContext.theory_of ctxt; |
|
1067 |
val [cty_a, cty_b, cty_c, cty_d] = map (ctyp_of thy) [ty_a, ty_b, ty_c, ty_d] |
|
1068 |
val tyinst = [SOME cty_a, SOME cty_b, SOME cty_c, SOME cty_d]; |
|
1069 |
val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)] |
|
1070 |
val lpi = Drule.instantiate' tyinst tinst @{thm LAMBDA_PRS}; |
|
1071 |
val tac = |
|
1072 |
(compose_tac (false, lpi, 2)) THEN_ALL_NEW |
|
1073 |
(quotient_tac quot); |
|
1074 |
val gc = Drule.strip_imp_concl (cprop_of lpi); |
|
1075 |
val t = Goal.prove_internal [] gc (fn _ => tac 1) |
|
1076 |
val te = @{thm eq_reflection} OF [t] |
|
1077 |
val ts = MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] te |
|
1078 |
val tl = Thm.lhs_of ts |
|
1079 |
(* val _ = tracing (Syntax.string_of_term @{context} (term_of ctrm));*) |
|
1080 |
(* val _ = tracing (Syntax.string_of_term @{context} (term_of tl));*) |
|
1081 |
val insts = matching_prs (ProofContext.theory_of ctxt) (term_of tl) (term_of ctrm); |
|
1082 |
val ti = Drule.eta_contraction_rule (Drule.instantiate insts ts); |
|
1083 |
(* val _ = tracing (Syntax.string_of_term @{context} (term_of (cprop_of ti)));*) |
|
1084 |
in |
|
1085 |
Conv.rewr_conv ti ctrm |
|
1086 |
end |
|
1087 |
(* TODO: We can add a proper error message... *) |
|
1088 |
handle Bind => Conv.all_conv ctrm |
|
1089 |
||
1090 |
*} |
|
1091 |
||
1092 |
(* quot stands for the QUOTIENT theorems: *) |
|
1093 |
(* could be potentially all of them *) |
|
1094 |
ML {* |
|
1095 |
fun lambda_prs_conv ctxt quot ctrm = |
|
1096 |
case (term_of ctrm) of |
|
1097 |
(Const (@{const_name "fun_map"}, _) $ _ $ _) $ (Abs _) => |
|
1098 |
(Conv.arg_conv (Conv.abs_conv (fn (_, ctxt) => lambda_prs_conv ctxt quot) ctxt) |
|
1099 |
then_conv (lambda_prs_conv1 ctxt quot)) ctrm |
|
1100 |
| _ $ _ => Conv.comb_conv (lambda_prs_conv ctxt quot) ctrm |
|
1101 |
| Abs _ => Conv.abs_conv (fn (_, ctxt) => lambda_prs_conv ctxt quot) ctxt ctrm |
|
1102 |
| _ => Conv.all_conv ctrm |
|
1103 |
*} |
|
1104 |
||
1105 |
ML {* |
|
1106 |
fun lambda_prs_tac ctxt quot = CSUBGOAL (fn (goal, i) => |
|
1107 |
CONVERSION |
|
1108 |
(Conv.params_conv ~1 (fn ctxt => |
|
1109 |
(Conv.prems_conv ~1 (lambda_prs_conv ctxt quot) then_conv |
|
1110 |
Conv.concl_conv ~1 (lambda_prs_conv ctxt quot))) ctxt) i) |
|
1111 |
*} |
|
1112 |
||
1113 |
ML {* |
|
389 | 1114 |
fun clean_tac lthy quot defs reps_same absrep aps = |
387 | 1115 |
let |
1116 |
val lower = flat (map (add_lower_defs lthy) defs) |
|
389 | 1117 |
val aps_thms = map (applic_prs lthy absrep) aps |
387 | 1118 |
in |
1119 |
EVERY' [TRY o REPEAT_ALL_NEW (allex_prs_tac lthy quot), |
|
1120 |
lambda_prs_tac lthy quot, |
|
389 | 1121 |
TRY o REPEAT_ALL_NEW (EqSubst.eqsubst_tac lthy [0] aps_thms), |
387 | 1122 |
TRY o REPEAT_ALL_NEW (EqSubst.eqsubst_tac lthy [0] lower), |
1123 |
simp_tac (HOL_ss addsimps [reps_same])] |
|
1124 |
end |
|
1125 |
*} |
|
381
991db758a72d
More moving from QuotMain to UnusedQuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
379
diff
changeset
|
1126 |
|
383
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1127 |
(* Genralisation of free variables in a goal *) |
347
7e82493c6253
Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
346
diff
changeset
|
1128 |
|
7e82493c6253
Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
346
diff
changeset
|
1129 |
ML {* |
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1130 |
fun inst_spec ctrm = |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1131 |
let |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1132 |
val cty = ctyp_of_term ctrm |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1133 |
in |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1134 |
Drule.instantiate' [SOME cty] [NONE, SOME ctrm] @{thm spec} |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1135 |
end |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1136 |
|
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1137 |
fun inst_spec_tac ctrms = |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1138 |
EVERY' (map (dtac o inst_spec) ctrms) |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1139 |
|
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1140 |
fun abs_list (xs, t) = |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1141 |
fold (fn (x, T) => fn t' => HOLogic.all_const T $ (lambda (Free (x, T)) t')) xs t |
362 | 1142 |
|
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1143 |
fun gen_frees_tac ctxt = |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1144 |
SUBGOAL (fn (concl, i) => |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1145 |
let |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1146 |
val thy = ProofContext.theory_of ctxt |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1147 |
val concl' = HOLogic.dest_Trueprop concl |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1148 |
val vrs = Term.add_frees concl' [] |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1149 |
val cvrs = map (cterm_of thy o Free) vrs |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1150 |
val concl'' = HOLogic.mk_Trueprop (abs_list (vrs, concl')) |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1151 |
val goal = Logic.mk_implies (concl'', concl) |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1152 |
val rule = Goal.prove ctxt [] [] goal |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1153 |
(K ((inst_spec_tac (rev cvrs) THEN' atac) 1)) |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1154 |
in |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1155 |
rtac rule i |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1156 |
end) |
362 | 1157 |
*} |
1158 |
||
383
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1159 |
(* General outline of the lifting procedure *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1160 |
(* **************************************** *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1161 |
(* *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1162 |
(* - A is the original raw theorem *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1163 |
(* - B is the regularized theorem *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1164 |
(* - C is the rep/abs injected version of B *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1165 |
(* - D is the lifted theorem *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1166 |
(* *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1167 |
(* - b is the regularization step *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1168 |
(* - c is the rep/abs injection step *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1169 |
(* - d is the cleaning part *) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1170 |
|
360
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1171 |
lemma procedure: |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1172 |
assumes a: "A" |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1173 |
and b: "A \<Longrightarrow> B" |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1174 |
and c: "B = C" |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1175 |
and d: "C = D" |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1176 |
shows "D" |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1177 |
using a b c d |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1178 |
by simp |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1179 |
|
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1180 |
ML {* |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1181 |
fun lift_error ctxt fun_str rtrm qtrm = |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1182 |
let |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1183 |
val rtrm_str = Syntax.string_of_term ctxt rtrm |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1184 |
val qtrm_str = Syntax.string_of_term ctxt qtrm |
388 | 1185 |
val msg = [enclose "[" "]" fun_str, "The quotient theorem\n", qtrm_str, |
1186 |
"and the lifted theorem\n", rtrm_str, "do not match"] |
|
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1187 |
in |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1188 |
error (space_implode " " msg) |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1189 |
end |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1190 |
*} |
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1191 |
|
360
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1192 |
ML {* |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1193 |
fun procedure_inst ctxt rtrm qtrm = |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1194 |
let |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1195 |
val thy = ProofContext.theory_of ctxt |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1196 |
val rtrm' = HOLogic.dest_Trueprop rtrm |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1197 |
val qtrm' = HOLogic.dest_Trueprop qtrm |
383
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1198 |
val reg_goal = |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1199 |
Syntax.check_term ctxt (REGULARIZE_trm ctxt rtrm' qtrm') |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1200 |
handle (LIFT_MATCH s) => lift_error ctxt s rtrm qtrm |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1201 |
val inj_goal = |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1202 |
Syntax.check_term ctxt (inj_REPABS ctxt (reg_goal, qtrm')) |
73a3670fb00e
comments tuning and slight reordering
Christian Urban <urbanc@in.tum.de>
parents:
382
diff
changeset
|
1203 |
handle (LIFT_MATCH s) => lift_error ctxt s rtrm qtrm |
360
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1204 |
in |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1205 |
Drule.instantiate' [] |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1206 |
[SOME (cterm_of thy rtrm'), |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1207 |
SOME (cterm_of thy reg_goal), |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1208 |
SOME (cterm_of thy inj_goal)] |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1209 |
@{thm procedure} |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1210 |
end |
362 | 1211 |
*} |
389 | 1212 |
|
1213 |
(* Left for debugging *) |
|
362 | 1214 |
ML {* |
389 | 1215 |
fun procedure_tac lthy rthm = |
1216 |
ObjectLogic.full_atomize_tac |
|
1217 |
THEN' gen_frees_tac lthy |
|
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
parents:
372
diff
changeset
|
1218 |
THEN' Subgoal.FOCUS (fn {context, concl, ...} => |
389 | 1219 |
let |
1220 |
val rthm' = atomize_thm rthm |
|
1221 |
val rule = procedure_inst context (prop_of rthm') (term_of concl) |
|
1222 |
in |
|
1223 |
rtac rule THEN' rtac rthm' |
|
1224 |
end 1) lthy |
|
360
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1225 |
*} |
07fb696efa3d
Moved cleaning to QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
359
diff
changeset
|
1226 |
|
361 | 1227 |
ML {* |
389 | 1228 |
fun lift_tac lthy rthm rel_eqv rel_refl rty quot trans2 rsp_thms reps_same absrep defs = |
1229 |
ObjectLogic.full_atomize_tac |
|
1230 |
THEN' gen_frees_tac lthy |
|
1231 |
THEN' Subgoal.FOCUS (fn {context, concl, ...} => |
|
1232 |
let |
|
1233 |
val rthm' = atomize_thm rthm |
|
1234 |
val rule = procedure_inst context (prop_of rthm') (term_of concl) |
|
1235 |
val aps = find_aps (prop_of rthm') (term_of concl) |
|
1236 |
in |
|
1237 |
rtac rule THEN' RANGE [ |
|
1238 |
rtac rthm', |
|
1239 |
regularize_tac lthy rel_eqv rel_refl, |
|
1240 |
REPEAT_ALL_NEW (r_mk_comb_tac lthy rty quot rel_refl trans2 rsp_thms), |
|
1241 |
clean_tac lthy quot defs reps_same absrep aps |
|
1242 |
] |
|
1243 |
end 1) lthy |
|
361 | 1244 |
*} |
1245 |
||
198
ff4425e000db
Completely cleaned Int.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
197
diff
changeset
|
1246 |
end |
239
02b14a21761a
Cleaning of the interface to lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
236
diff
changeset
|
1247 |
|
347
7e82493c6253
Finished temporary goal-directed lift_theorem wrapper.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
346
diff
changeset
|
1248 |