author | Christian Urban <urbanc@in.tum.de> |
Sat, 12 Dec 2009 18:43:42 +0100 | |
changeset 739 | 089cf9ffb711 |
parent 738 | 7142389632fd |
child 740 | d151f24427ab |
permissions | -rw-r--r-- |
597 | 1 |
theory QuotMain |
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
parents:
643
diff
changeset
|
2 |
imports QuotScript Prove |
597 | 3 |
uses ("quotient_info.ML") |
725
0d98a4c7f8dc
renamed quotient.ML to quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents:
720
diff
changeset
|
4 |
("quotient_typ.ML") |
597 | 5 |
("quotient_def.ML") |
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 equivp: "equivp 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)" |
|
17 |
begin |
|
18 |
||
19 |
definition |
|
719 | 20 |
abs::"'a \<Rightarrow> 'b" |
597 | 21 |
where |
719 | 22 |
"abs x \<equiv> Abs (R x)" |
597 | 23 |
|
24 |
definition |
|
719 | 25 |
rep::"'b \<Rightarrow> 'a" |
597 | 26 |
where |
719 | 27 |
"rep a = Eps (Rep a)" |
597 | 28 |
|
29 |
lemma lem9: |
|
30 |
shows "R (Eps (R x)) = R x" |
|
31 |
proof - |
|
32 |
have a: "R x x" using equivp by (simp add: equivp_reflp_symp_transp reflp_def) |
|
33 |
then have "R x (Eps (R x))" by (rule someI) |
|
34 |
then show "R (Eps (R x)) = R x" |
|
35 |
using equivp unfolding equivp_def by simp |
|
36 |
qed |
|
37 |
||
38 |
theorem thm10: |
|
719 | 39 |
shows "abs (rep a) \<equiv> a" |
597 | 40 |
apply (rule eq_reflection) |
719 | 41 |
unfolding abs_def rep_def |
597 | 42 |
proof - |
43 |
from rep_prop |
|
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 |
||
719 | 53 |
lemma rep_refl: |
54 |
shows "R (rep a) (rep a)" |
|
55 |
unfolding rep_def |
|
597 | 56 |
by (simp add: equivp[simplified equivp_def]) |
57 |
||
58 |
lemma lem7: |
|
59 |
shows "(R x = R y) = (Abs (R x) = Abs (R y))" |
|
60 |
apply(rule iffI) |
|
61 |
apply(simp) |
|
62 |
apply(drule rep_inject[THEN iffD2]) |
|
63 |
apply(simp add: abs_inverse) |
|
64 |
done |
|
65 |
||
66 |
theorem thm11: |
|
719 | 67 |
shows "R r r' = (abs r = abs r')" |
68 |
unfolding abs_def |
|
597 | 69 |
by (simp only: equivp[simplified equivp_def] lem7) |
70 |
||
71 |
||
719 | 72 |
lemma rep_abs_rsp: |
73 |
shows "R f (rep (abs g)) = R f g" |
|
74 |
and "R (rep (abs g)) f = R g f" |
|
597 | 75 |
by (simp_all add: thm10 thm11) |
76 |
||
77 |
lemma Quotient: |
|
719 | 78 |
"Quotient R abs rep" |
597 | 79 |
apply(unfold Quotient_def) |
80 |
apply(simp add: thm10) |
|
719 | 81 |
apply(simp add: rep_refl) |
597 | 82 |
apply(subst thm11[symmetric]) |
83 |
apply(simp add: equivp[simplified equivp_def]) |
|
84 |
done |
|
85 |
||
86 |
end |
|
87 |
||
88 |
section {* type definition for the quotient type *} |
|
89 |
||
90 |
(* the auxiliary data for the quotient types *) |
|
91 |
use "quotient_info.ML" |
|
92 |
||
699
aa157e957655
added maps-printout and tuned some comments
Christian Urban <urbanc@in.tum.de>
parents:
697
diff
changeset
|
93 |
ML {* print_mapsinfo @{context} *} |
aa157e957655
added maps-printout and tuned some comments
Christian Urban <urbanc@in.tum.de>
parents:
697
diff
changeset
|
94 |
|
597 | 95 |
declare [[map "fun" = (fun_map, fun_rel)]] |
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
96 |
|
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
parents:
643
diff
changeset
|
97 |
lemmas [quot_thm] = fun_quotient |
597 | 98 |
|
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
parents:
643
diff
changeset
|
99 |
lemmas [quot_respect] = quot_rel_rsp |
597 | 100 |
|
101 |
(* fun_map is not here since equivp is not true *) |
|
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
parents:
643
diff
changeset
|
102 |
lemmas [quot_equiv] = identity_equivp |
597 | 103 |
|
104 |
(* definition of the quotient types *) |
|
725
0d98a4c7f8dc
renamed quotient.ML to quotient_typ.ML
Christian Urban <urbanc@in.tum.de>
parents:
720
diff
changeset
|
105 |
use "quotient_typ.ML" |
597 | 106 |
|
107 |
(* lifting of constants *) |
|
108 |
use "quotient_def.ML" |
|
109 |
||
110 |
section {* Simset setup *} |
|
111 |
||
614
51a4208162ed
added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents:
613
diff
changeset
|
112 |
(* Since HOL_basic_ss is too "big" for us, *) |
51a4208162ed
added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents:
613
diff
changeset
|
113 |
(* we set up our own minimal simpset. *) |
597 | 114 |
ML {* |
115 |
fun mk_minimal_ss ctxt = |
|
116 |
Simplifier.context ctxt empty_ss |
|
117 |
setsubgoaler asm_simp_tac |
|
118 |
setmksimps (mksimps []) |
|
119 |
*} |
|
120 |
||
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
121 |
ML {* |
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
122 |
fun OF1 thm1 thm2 = thm2 RS thm1 |
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
123 |
*} |
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
124 |
|
614
51a4208162ed
added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents:
613
diff
changeset
|
125 |
section {* Atomize Infrastructure *} |
597 | 126 |
|
127 |
lemma atomize_eqv[atomize]: |
|
128 |
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" |
|
129 |
proof |
|
130 |
assume "A \<equiv> B" |
|
131 |
then show "Trueprop A \<equiv> Trueprop B" by unfold |
|
132 |
next |
|
133 |
assume *: "Trueprop A \<equiv> Trueprop B" |
|
134 |
have "A = B" |
|
135 |
proof (cases A) |
|
136 |
case True |
|
137 |
have "A" by fact |
|
138 |
then show "A = B" using * by simp |
|
139 |
next |
|
140 |
case False |
|
141 |
have "\<not>A" by fact |
|
142 |
then show "A = B" using * by auto |
|
143 |
qed |
|
144 |
then show "A \<equiv> B" by (rule eq_reflection) |
|
145 |
qed |
|
146 |
||
147 |
ML {* |
|
148 |
fun atomize_thm thm = |
|
149 |
let |
|
150 |
val thm' = Thm.freezeT (forall_intr_vars thm) |
|
151 |
val thm'' = ObjectLogic.atomize (cprop_of thm') |
|
152 |
in |
|
153 |
@{thm equal_elim_rule1} OF [thm'', thm'] |
|
154 |
end |
|
155 |
*} |
|
156 |
||
614
51a4208162ed
added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents:
613
diff
changeset
|
157 |
section {* Infrastructure about id *} |
51a4208162ed
added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents:
613
diff
changeset
|
158 |
|
668 | 159 |
lemmas [id_simps] = |
597 | 160 |
fun_map_id[THEN eq_reflection] |
161 |
id_apply[THEN eq_reflection] |
|
162 |
id_def[THEN eq_reflection,symmetric] |
|
163 |
||
612 | 164 |
section {* Computation of the Regularize Goal *} |
597 | 165 |
|
166 |
(* |
|
167 |
Regularizing an rtrm means: |
|
168 |
- quantifiers over a type that needs lifting are replaced by |
|
169 |
bounded quantifiers, for example: |
|
170 |
\<forall>x. P \<Longrightarrow> \<forall>x \<in> (Respects R). P / All (Respects R) P |
|
171 |
||
172 |
the relation R is given by the rty and qty; |
|
173 |
||
174 |
- abstractions over a type that needs lifting are replaced |
|
175 |
by bounded abstractions: |
|
176 |
\<lambda>x. P \<Longrightarrow> Ball (Respects R) (\<lambda>x. P) |
|
177 |
||
178 |
- equalities over the type being lifted are replaced by |
|
179 |
corresponding relations: |
|
180 |
A = B \<Longrightarrow> A \<approx> B |
|
181 |
||
182 |
example with more complicated types of A, B: |
|
183 |
A = B \<Longrightarrow> (op = \<Longrightarrow> op \<approx>) A B |
|
184 |
*) |
|
185 |
||
186 |
ML {* |
|
187 |
(* builds the relation that is the argument of respects *) |
|
188 |
fun mk_resp_arg lthy (rty, qty) = |
|
189 |
let |
|
190 |
val thy = ProofContext.theory_of lthy |
|
191 |
in |
|
192 |
if rty = qty |
|
193 |
then HOLogic.eq_const rty |
|
194 |
else |
|
195 |
case (rty, qty) of |
|
196 |
(Type (s, tys), Type (s', tys')) => |
|
197 |
if s = s' |
|
198 |
then let |
|
199 |
val SOME map_info = maps_lookup thy s |
|
200 |
val args = map (mk_resp_arg lthy) (tys ~~ tys') |
|
201 |
in |
|
202 |
list_comb (Const (#relfun map_info, dummyT), args) |
|
203 |
end |
|
204 |
else let |
|
205 |
val SOME qinfo = quotdata_lookup_thy thy s' |
|
206 |
(* FIXME: check in this case that the rty and qty *) |
|
207 |
(* FIXME: correspond to each other *) |
|
208 |
val (s, _) = dest_Const (#rel qinfo) |
|
209 |
(* FIXME: the relation should only be the string *) |
|
210 |
(* FIXME: and the type needs to be calculated as below; *) |
|
211 |
(* FIXME: maybe one should actually have a term *) |
|
212 |
(* FIXME: and one needs to force it to have this type *) |
|
213 |
in |
|
214 |
Const (s, rty --> rty --> @{typ bool}) |
|
215 |
end |
|
216 |
| _ => HOLogic.eq_const dummyT |
|
217 |
(* FIXME: check that the types correspond to each other? *) |
|
218 |
end |
|
219 |
*} |
|
220 |
||
221 |
ML {* |
|
222 |
val mk_babs = Const (@{const_name Babs}, dummyT) |
|
223 |
val mk_ball = Const (@{const_name Ball}, dummyT) |
|
224 |
val mk_bex = Const (@{const_name Bex}, dummyT) |
|
225 |
val mk_resp = Const (@{const_name Respects}, dummyT) |
|
226 |
*} |
|
227 |
||
228 |
ML {* |
|
229 |
(* - applies f to the subterm of an abstraction, *) |
|
230 |
(* otherwise to the given term, *) |
|
231 |
(* - used by regularize, therefore abstracted *) |
|
232 |
(* variables do not have to be treated specially *) |
|
233 |
||
234 |
fun apply_subt f trm1 trm2 = |
|
235 |
case (trm1, trm2) of |
|
236 |
(Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t') |
|
237 |
| _ => f trm1 trm2 |
|
238 |
||
239 |
(* the major type of All and Ex quantifiers *) |
|
240 |
fun qnt_typ ty = domain_type (domain_type ty) |
|
241 |
*} |
|
242 |
||
243 |
ML {* |
|
632
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
244 |
(* produces a regularized version of rtrm *) |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
245 |
(* - the result is contains dummyT *) |
597 | 246 |
(* - does not need any special treatment of *) |
247 |
(* bound variables *) |
|
248 |
||
249 |
fun regularize_trm lthy rtrm qtrm = |
|
250 |
case (rtrm, qtrm) of |
|
251 |
(Abs (x, ty, t), Abs (x', ty', t')) => |
|
252 |
let |
|
253 |
val subtrm = Abs(x, ty, regularize_trm lthy t t') |
|
254 |
in |
|
632
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
255 |
if ty = ty' then subtrm |
597 | 256 |
else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm |
257 |
end |
|
258 |
||
259 |
| (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') => |
|
260 |
let |
|
261 |
val subtrm = apply_subt (regularize_trm lthy) t t' |
|
262 |
in |
|
655 | 263 |
if ty = ty' then Const (@{const_name "All"}, ty) $ subtrm |
597 | 264 |
else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
265 |
end |
|
266 |
||
267 |
| (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') => |
|
268 |
let |
|
269 |
val subtrm = apply_subt (regularize_trm lthy) t t' |
|
270 |
in |
|
655 | 271 |
if ty = ty' then Const (@{const_name "Ex"}, ty) $ subtrm |
597 | 272 |
else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
273 |
end |
|
274 |
||
275 |
| (* equalities need to be replaced by appropriate equivalence relations *) |
|
276 |
(Const (@{const_name "op ="}, ty), Const (@{const_name "op ="}, ty')) => |
|
632
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
277 |
if ty = ty' then rtrm |
597 | 278 |
else mk_resp_arg lthy (domain_type ty, domain_type ty') |
279 |
||
280 |
| (* in this case we check whether the given equivalence relation is correct *) |
|
281 |
(rel, Const (@{const_name "op ="}, ty')) => |
|
282 |
let |
|
283 |
val exc = LIFT_MATCH "regularise (relation mismatch)" |
|
284 |
val rel_ty = (fastype_of rel) handle TERM _ => raise exc |
|
285 |
val rel' = mk_resp_arg lthy (domain_type rel_ty, domain_type ty') |
|
286 |
in |
|
655 | 287 |
if rel' = rel then rtrm else raise exc |
597 | 288 |
end |
730 | 289 |
|
736
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
290 |
| (_, Const _) => |
597 | 291 |
let |
736
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
292 |
fun same_name (Const (s, T)) (Const (s', T')) = (s = s') (*andalso (T = T')*) |
597 | 293 |
| same_name _ _ = false |
736
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
294 |
(* TODO/FIXME: This test is not enough. *) |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
295 |
(* Why? *) |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
296 |
(* Because constants can have the same name but not be the same |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
297 |
constant. All overloaded constants have the same name but because |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
298 |
of different types they do differ. |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
299 |
|
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
300 |
This code will let one write a theorem where plus on nat is |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
301 |
matched to plus on int, even if the latter is defined differently. |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
302 |
|
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
303 |
This would result in hard to understand failures in injection and |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
304 |
cleaning. *) |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
305 |
(* cu: if I also test the type, then something else breaks *) |
597 | 306 |
in |
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
657
diff
changeset
|
307 |
if same_name rtrm qtrm then rtrm |
597 | 308 |
else |
309 |
let |
|
310 |
val thy = ProofContext.theory_of lthy |
|
736
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
311 |
val qtrm_str = Syntax.string_of_term lthy qtrm |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
312 |
val exc1 = LIFT_MATCH ("regularize (constant " ^ qtrm_str ^ " not found)") |
f48b8a82c1e3
tried to improve test; but fails
Christian Urban <urbanc@in.tum.de>
parents:
735
diff
changeset
|
313 |
val exc2 = LIFT_MATCH ("regularize (constant " ^ qtrm_str ^ " mismatch)") |
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
657
diff
changeset
|
314 |
val rtrm' = (#rconst (qconsts_lookup thy qtrm)) handle NotFound => raise exc1 |
597 | 315 |
in |
730 | 316 |
if Pattern.matches thy (rtrm', rtrm) |
317 |
then rtrm else raise exc2 |
|
597 | 318 |
end |
319 |
end |
|
320 |
||
321 |
| (t1 $ t2, t1' $ t2') => |
|
322 |
(regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2') |
|
323 |
||
324 |
| (Free (x, ty), Free (x', ty')) => |
|
325 |
(* this case cannot arrise as we start with two fully atomized terms *) |
|
326 |
raise (LIFT_MATCH "regularize (frees)") |
|
327 |
||
328 |
| (Bound i, Bound i') => |
|
632
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
329 |
if i = i' then rtrm |
597 | 330 |
else raise (LIFT_MATCH "regularize (bounds mismatch)") |
331 |
||
738 | 332 |
| _ => |
730 | 333 |
let |
738 | 334 |
val rtrm_str = Syntax.string_of_term lthy rtrm |
335 |
val qtrm_str = Syntax.string_of_term lthy qtrm |
|
730 | 336 |
in |
738 | 337 |
raise (LIFT_MATCH ("regularize failed (default: " ^ rtrm_str ^ "," ^ qtrm_str ^ ")")) |
695
2eba169533b5
Found the problem with ttt3.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
694
diff
changeset
|
338 |
end |
597 | 339 |
*} |
340 |
||
612 | 341 |
section {* Regularize Tactic *} |
342 |
||
597 | 343 |
ML {* |
344 |
fun equiv_tac ctxt = |
|
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
345 |
REPEAT_ALL_NEW (resolve_tac (equiv_rules_get ctxt)) |
597 | 346 |
|
347 |
fun equiv_solver_tac ss = equiv_tac (Simplifier.the_context ss) |
|
348 |
val equiv_solver = Simplifier.mk_solver' "Equivalence goal solver" equiv_solver_tac |
|
349 |
*} |
|
350 |
||
351 |
ML {* |
|
352 |
fun prep_trm thy (x, (T, t)) = |
|
353 |
(cterm_of thy (Var (x, T)), cterm_of thy t) |
|
354 |
||
355 |
fun prep_ty thy (x, (S, ty)) = |
|
356 |
(ctyp_of thy (TVar (x, S)), ctyp_of thy ty) |
|
357 |
*} |
|
358 |
||
359 |
ML {* |
|
360 |
fun matching_prs thy pat trm = |
|
361 |
let |
|
362 |
val univ = Unify.matchers thy [(pat, trm)] |
|
363 |
val SOME (env, _) = Seq.pull univ |
|
364 |
val tenv = Vartab.dest (Envir.term_env env) |
|
365 |
val tyenv = Vartab.dest (Envir.type_env env) |
|
366 |
in |
|
367 |
(map (prep_ty thy) tyenv, map (prep_trm thy) tenv) |
|
368 |
end |
|
369 |
*} |
|
370 |
||
371 |
ML {* |
|
372 |
fun calculate_instance ctxt thm redex R1 R2 = |
|
373 |
let |
|
374 |
val thy = ProofContext.theory_of ctxt |
|
375 |
val goal = Const (@{const_name "equivp"}, dummyT) $ R2 |
|
376 |
|> Syntax.check_term ctxt |
|
377 |
|> HOLogic.mk_Trueprop |
|
738 | 378 |
val eqv_prem = Goal.prove ctxt [] [] goal (fn _ => equiv_tac ctxt 1) |
597 | 379 |
val thm = (@{thm eq_reflection} OF [thm OF [eqv_prem]]) |
380 |
val R1c = cterm_of thy R1 |
|
381 |
val thmi = Drule.instantiate' [] [SOME R1c] thm |
|
382 |
val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) redex |
|
383 |
val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi) |
|
384 |
in |
|
385 |
SOME thm2 |
|
386 |
end |
|
387 |
handle _ => NONE |
|
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
388 |
(* FIXME/TODO: what is the place where the exception is raised: matching_prs? *) |
597 | 389 |
*} |
390 |
||
391 |
ML {* |
|
392 |
fun ball_bex_range_simproc ss redex = |
|
393 |
let |
|
394 |
val ctxt = Simplifier.the_context ss |
|
395 |
in |
|
396 |
case redex of |
|
397 |
(Const (@{const_name "Ball"}, _) $ (Const (@{const_name "Respects"}, _) $ |
|
398 |
(Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) => |
|
399 |
calculate_instance ctxt @{thm ball_reg_eqv_range} redex R1 R2 |
|
400 |
| (Const (@{const_name "Bex"}, _) $ (Const (@{const_name "Respects"}, _) $ |
|
401 |
(Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) => |
|
402 |
calculate_instance ctxt @{thm bex_reg_eqv_range} redex R1 R2 |
|
403 |
| _ => NONE |
|
404 |
end |
|
405 |
*} |
|
406 |
||
407 |
lemma eq_imp_rel: |
|
408 |
shows "equivp R \<Longrightarrow> a = b \<longrightarrow> R a b" |
|
409 |
by (simp add: equivp_reflp) |
|
410 |
||
730 | 411 |
ML {* |
412 |
fun quotient_tac ctxt = |
|
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
413 |
DETERM o REPEAT_ALL_NEW (FIRST' |
730 | 414 |
[rtac @{thm identity_quotient}, |
415 |
resolve_tac (quotient_rules_get ctxt)]) |
|
416 |
||
417 |
fun quotient_solver_tac ss = quotient_tac (Simplifier.the_context ss) |
|
418 |
val quotient_solver = Simplifier.mk_solver' "Quotient goal solver" quotient_solver_tac |
|
419 |
*} |
|
597 | 420 |
|
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
421 |
ML {* |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
422 |
fun solve_quotient_assums ctxt thm = |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
423 |
let |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
424 |
val goal = hd (Drule.strip_imp_prems (cprop_of thm)) |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
425 |
in |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
426 |
thm OF [Goal.prove_internal [] goal (fn _ => quotient_tac ctxt 1)] |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
427 |
end |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
428 |
handle _ => error "solve_quotient_assums failed. Maybe a quotient_thm is missing" |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
429 |
*} |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
430 |
|
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
431 |
|
612 | 432 |
(* 0. preliminary simplification step according to *) |
433 |
thm ball_reg_eqv bex_reg_eqv babs_reg_eqv (* the latter of no use *) |
|
434 |
ball_reg_eqv_range bex_reg_eqv_range |
|
435 |
(* 1. eliminating simple Ball/Bex instances*) |
|
436 |
thm ball_reg_right bex_reg_left |
|
437 |
(* 2. monos *) |
|
438 |
(* 3. commutation rules for ball and bex *) |
|
439 |
thm ball_all_comm bex_ex_comm |
|
730 | 440 |
(* 4. then rel-equality (which need to be instantiated to avoid loops) *) |
612 | 441 |
thm eq_imp_rel |
442 |
(* 5. then simplification like 0 *) |
|
443 |
(* finally jump back to 1 *) |
|
597 | 444 |
|
697
57944c1ef728
Regularized the hard lemma.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
695
diff
changeset
|
445 |
ML {* |
597 | 446 |
fun regularize_tac ctxt = |
447 |
let |
|
448 |
val thy = ProofContext.theory_of ctxt |
|
449 |
val pat_ball = @{term "Ball (Respects (R1 ===> R2)) P"} |
|
450 |
val pat_bex = @{term "Bex (Respects (R1 ===> R2)) P"} |
|
451 |
val simproc = Simplifier.simproc_i thy "" [pat_ball, pat_bex] (K (ball_bex_range_simproc)) |
|
452 |
val simpset = (mk_minimal_ss ctxt) |
|
697
57944c1ef728
Regularized the hard lemma.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
695
diff
changeset
|
453 |
addsimps @{thms ball_reg_eqv bex_reg_eqv babs_reg_eqv babs_simp} |
57944c1ef728
Regularized the hard lemma.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
695
diff
changeset
|
454 |
addsimprocs [simproc] addSolver equiv_solver addSolver quotient_solver |
597 | 455 |
(* TODO: Make sure that there are no list_rel, pair_rel etc involved *) |
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
456 |
(* can this cause loops in equiv_tac ? *) |
612 | 457 |
val eq_eqvs = map (OF1 @{thm eq_imp_rel}) (equiv_rules_get ctxt) |
597 | 458 |
in |
459 |
simp_tac simpset THEN' |
|
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
460 |
REPEAT_ALL_NEW (CHANGED o FIRST' [ |
612 | 461 |
resolve_tac @{thms ball_reg_right bex_reg_left}, |
597 | 462 |
resolve_tac (Inductive.get_monos ctxt), |
612 | 463 |
resolve_tac @{thms ball_all_comm bex_ex_comm}, |
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
464 |
resolve_tac eq_eqvs, |
597 | 465 |
simp_tac simpset]) |
466 |
end |
|
467 |
*} |
|
468 |
||
612 | 469 |
section {* Calculation of the Injected Goal *} |
597 | 470 |
|
471 |
(* |
|
472 |
Injecting repabs means: |
|
473 |
||
474 |
For abstractions: |
|
475 |
* If the type of the abstraction doesn't need lifting we recurse. |
|
476 |
* If it does we add RepAbs around the whole term and check if the |
|
477 |
variable needs lifting. |
|
478 |
* If it doesn't then we recurse |
|
479 |
* If it does we recurse and put 'RepAbs' around all occurences |
|
480 |
of the variable in the obtained subterm. This in combination |
|
481 |
with the RepAbs above will let us change the type of the |
|
482 |
abstraction with rewriting. |
|
483 |
For applications: |
|
484 |
* If the term is 'Respects' applied to anything we leave it unchanged |
|
485 |
* If the term needs lifting and the head is a constant that we know |
|
486 |
how to lift, we put a RepAbs and recurse |
|
487 |
* If the term needs lifting and the head is a free applied to subterms |
|
488 |
(if it is not applied we treated it in Abs branch) then we |
|
489 |
put RepAbs and recurse |
|
490 |
* Otherwise just recurse. |
|
491 |
*) |
|
492 |
||
493 |
ML {* |
|
494 |
fun mk_repabs lthy (T, T') trm = |
|
495 |
Quotient_Def.get_fun repF lthy (T, T') |
|
496 |
$ (Quotient_Def.get_fun absF lthy (T, T') $ trm) |
|
497 |
*} |
|
498 |
||
499 |
ML {* |
|
500 |
(* bound variables need to be treated properly, *) |
|
501 |
(* as the type of subterms need to be calculated *) |
|
502 |
(* in the abstraction case *) |
|
503 |
||
504 |
fun inj_repabs_trm lthy (rtrm, qtrm) = |
|
505 |
case (rtrm, qtrm) of |
|
506 |
(Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') => |
|
507 |
Const (@{const_name "Ball"}, T) $ r $ (inj_repabs_trm lthy (t, t')) |
|
508 |
||
509 |
| (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') => |
|
510 |
Const (@{const_name "Bex"}, T) $ r $ (inj_repabs_trm lthy (t, t')) |
|
511 |
||
512 |
| (Const (@{const_name "Babs"}, T) $ r $ t, t' as (Abs _)) => |
|
621
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
616
diff
changeset
|
513 |
let |
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
616
diff
changeset
|
514 |
val rty = fastype_of rtrm |
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
616
diff
changeset
|
515 |
val qty = fastype_of qtrm |
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
616
diff
changeset
|
516 |
in |
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
616
diff
changeset
|
517 |
mk_repabs lthy (rty, qty) (Const (@{const_name "Babs"}, T) $ r $ (inj_repabs_trm lthy (t, t'))) |
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
616
diff
changeset
|
518 |
end |
597 | 519 |
|
520 |
| (Abs (x, T, t), Abs (x', T', t')) => |
|
521 |
let |
|
522 |
val rty = fastype_of rtrm |
|
523 |
val qty = fastype_of qtrm |
|
524 |
val (y, s) = Term.dest_abs (x, T, t) |
|
525 |
val (_, s') = Term.dest_abs (x', T', t') |
|
526 |
val yvar = Free (y, T) |
|
527 |
val result = Term.lambda_name (y, yvar) (inj_repabs_trm lthy (s, s')) |
|
528 |
in |
|
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
529 |
if rty = qty then result |
597 | 530 |
else mk_repabs lthy (rty, qty) result |
531 |
end |
|
532 |
||
533 |
| (t $ s, t' $ s') => |
|
534 |
(inj_repabs_trm lthy (t, t')) $ (inj_repabs_trm lthy (s, s')) |
|
535 |
||
536 |
| (Free (_, T), Free (_, T')) => |
|
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
537 |
if T = T' then rtrm |
597 | 538 |
else mk_repabs lthy (T, T') rtrm |
539 |
||
540 |
| (_, Const (@{const_name "op ="}, _)) => rtrm |
|
541 |
||
542 |
| (_, Const (_, T')) => |
|
543 |
let |
|
544 |
val rty = fastype_of rtrm |
|
545 |
in |
|
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
546 |
if rty = T' then rtrm |
597 | 547 |
else mk_repabs lthy (rty, T') rtrm |
548 |
end |
|
549 |
||
550 |
| _ => raise (LIFT_MATCH "injection") |
|
551 |
*} |
|
552 |
||
612 | 553 |
section {* Injection Tactic *} |
597 | 554 |
|
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
555 |
|
597 | 556 |
|
557 |
definition |
|
558 |
"QUOT_TRUE x \<equiv> True" |
|
559 |
||
560 |
ML {* |
|
561 |
fun find_qt_asm asms = |
|
562 |
let |
|
563 |
fun find_fun trm = |
|
564 |
case trm of |
|
565 |
(Const(@{const_name Trueprop}, _) $ (Const (@{const_name QUOT_TRUE}, _) $ _)) => true |
|
566 |
| _ => false |
|
567 |
in |
|
568 |
case find_first find_fun asms of |
|
569 |
SOME (_ $ (_ $ (f $ a))) => (f, a) |
|
570 |
| SOME _ => error "find_qt_asm: no pair" |
|
571 |
| NONE => error "find_qt_asm: no assumption" |
|
572 |
end |
|
573 |
*} |
|
574 |
||
575 |
(* |
|
576 |
To prove that the regularised theorem implies the abs/rep injected, |
|
577 |
we try: |
|
578 |
||
579 |
1) theorems 'trans2' from the appropriate QUOT_TYPE |
|
580 |
2) remove lambdas from both sides: lambda_rsp_tac |
|
581 |
3) remove Ball/Bex from the right hand side |
|
582 |
4) use user-supplied RSP theorems |
|
583 |
5) remove rep_abs from the right side |
|
584 |
6) reflexivity of equality |
|
585 |
7) split applications of lifted type (apply_rsp) |
|
586 |
8) split applications of non-lifted type (cong_tac) |
|
587 |
9) apply extentionality |
|
588 |
A) reflexivity of the relation |
|
589 |
B) assumption |
|
590 |
(Lambdas under respects may have left us some assumptions) |
|
591 |
C) proving obvious higher order equalities by simplifying fun_rel |
|
592 |
(not sure if it is still needed?) |
|
593 |
D) unfolding lambda on one side |
|
594 |
E) simplifying (= ===> =) for simpler respectfulness |
|
595 |
||
596 |
*) |
|
597 |
||
598 |
lemma quot_true_dests: |
|
599 |
shows QT_all: "QUOT_TRUE (All P) \<Longrightarrow> QUOT_TRUE P" |
|
600 |
and QT_ex: "QUOT_TRUE (Ex P) \<Longrightarrow> QUOT_TRUE P" |
|
601 |
and QT_lam: "QUOT_TRUE (\<lambda>x. P x) \<Longrightarrow> (\<And>x. QUOT_TRUE (P x))" |
|
602 |
and QT_ext: "(\<And>x. QUOT_TRUE (a x) \<Longrightarrow> f x = g x) \<Longrightarrow> (QUOT_TRUE a \<Longrightarrow> f = g)" |
|
655 | 603 |
by (simp_all add: QUOT_TRUE_def ext) |
597 | 604 |
|
605 |
lemma QUOT_TRUE_imp: "QUOT_TRUE a \<equiv> QUOT_TRUE b" |
|
606 |
by (simp add: QUOT_TRUE_def) |
|
607 |
||
697
57944c1ef728
Regularized the hard lemma.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
695
diff
changeset
|
608 |
lemma regularize_to_injection: "(QUOT_TRUE l \<Longrightarrow> y) \<Longrightarrow> (l = r) \<longrightarrow> y" |
57944c1ef728
Regularized the hard lemma.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
695
diff
changeset
|
609 |
by(auto simp add: QUOT_TRUE_def) |
57944c1ef728
Regularized the hard lemma.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
695
diff
changeset
|
610 |
|
597 | 611 |
ML {* |
738 | 612 |
fun quot_true_simple_conv ctxt fnctn ctrm = |
597 | 613 |
case (term_of ctrm) of |
614 |
(Const (@{const_name QUOT_TRUE}, _) $ x) => |
|
615 |
let |
|
616 |
val fx = fnctn x; |
|
617 |
val thy = ProofContext.theory_of ctxt; |
|
618 |
val cx = cterm_of thy x; |
|
619 |
val cfx = cterm_of thy fx; |
|
620 |
val cxt = ctyp_of thy (fastype_of x); |
|
621 |
val cfxt = ctyp_of thy (fastype_of fx); |
|
622 |
val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QUOT_TRUE_imp} |
|
623 |
in |
|
624 |
Conv.rewr_conv thm ctrm |
|
625 |
end |
|
626 |
*} |
|
627 |
||
628 |
ML {* |
|
629 |
fun quot_true_conv ctxt fnctn ctrm = |
|
630 |
case (term_of ctrm) of |
|
631 |
(Const (@{const_name QUOT_TRUE}, _) $ _) => |
|
738 | 632 |
quot_true_simple_conv ctxt fnctn ctrm |
597 | 633 |
| _ $ _ => Conv.comb_conv (quot_true_conv ctxt fnctn) ctrm |
634 |
| Abs _ => Conv.abs_conv (fn (_, ctxt) => quot_true_conv ctxt fnctn) ctxt ctrm |
|
635 |
| _ => Conv.all_conv ctrm |
|
636 |
*} |
|
637 |
||
638 |
ML {* |
|
738 | 639 |
fun quot_true_tac ctxt fnctn = |
640 |
CONVERSION |
|
597 | 641 |
((Conv.params_conv ~1 (fn ctxt => |
642 |
(Conv.prems_conv ~1 (quot_true_conv ctxt fnctn)))) ctxt) |
|
643 |
*} |
|
644 |
||
645 |
ML {* fun dest_comb (f $ a) = (f, a) *} |
|
646 |
ML {* fun dest_bcomb ((_ $ l) $ r) = (l, r) *} |
|
647 |
(* TODO: Can this be done easier? *) |
|
648 |
ML {* |
|
649 |
fun unlam t = |
|
650 |
case t of |
|
651 |
(Abs a) => snd (Term.dest_abs a) |
|
652 |
| _ => unlam (Abs("", domain_type (fastype_of t), (incr_boundvars 1 t) $ (Bound 0))) |
|
653 |
*} |
|
654 |
||
655 |
ML {* |
|
656 |
fun dest_fun_type (Type("fun", [T, S])) = (T, S) |
|
657 |
| dest_fun_type _ = error "dest_fun_type" |
|
658 |
*} |
|
659 |
||
660 |
ML {* |
|
661 |
val bare_concl = HOLogic.dest_Trueprop o Logic.strip_assums_concl |
|
662 |
*} |
|
663 |
||
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
664 |
thm apply_rsp |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
665 |
|
597 | 666 |
ML {* |
667 |
val apply_rsp_tac = |
|
668 |
Subgoal.FOCUS (fn {concl, asms, context,...} => |
|
739
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
669 |
case (HOLogic.dest_Trueprop (term_of concl)) of |
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
670 |
(R2 $ (f $ x) $ (g $ y)) => |
597 | 671 |
(let |
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
672 |
val (asmf, asma) = find_qt_asm (map term_of asms); |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
673 |
in |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
674 |
if (fastype_of asmf) = (fastype_of f) (* why is this test necessary *) |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
675 |
then no_tac |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
676 |
else |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
677 |
let |
739
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
678 |
val ty_a = fastype_of x |
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
679 |
val ty_b = fastype_of asma |
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
680 |
val ty_c = range_type (type_of f) (* why type_of, not fast_type? *) |
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
681 |
val thy = ProofContext.theory_of context |
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
682 |
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c] |
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
683 |
val t_inst = map (SOME o (cterm_of thy)) [R2, f, g, x, y]; |
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
684 |
val thm' = Drule.instantiate' ty_inst [] @{thm apply_rsp} |
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
685 |
val te = solve_quotient_assums context thm' |
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
686 |
val thm = Drule.instantiate' [] t_inst te |
739
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
687 |
(* why not instantiate terms 3 lines earlier *) |
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
688 |
(* \<dots> if done one gets an instantiate type conlict error ??? *) |
089cf9ffb711
tried to simplify apply_rsp_tac; failed at the moment; added some questions
Christian Urban <urbanc@in.tum.de>
parents:
738
diff
changeset
|
689 |
(* why is necessary to get rid of the quot-assms first ??? *) |
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
690 |
in |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
691 |
compose_tac (false, thm, 2) 1 |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
692 |
end |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
693 |
end |
597 | 694 |
handle ERROR "find_qt_asm: no pair" => no_tac) |
695 |
| _ => no_tac) |
|
696 |
*} |
|
697 |
||
698 |
ML {* |
|
629
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
699 |
fun equals_rsp_tac R ctxt = |
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
700 |
let |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
701 |
val ty = domain_type (fastype_of R); |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
702 |
val thy = ProofContext.theory_of ctxt |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
703 |
val thm = Drule.instantiate' |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
704 |
[SOME (ctyp_of thy ty)] [SOME (cterm_of thy R)] @{thm equals_rsp} |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
705 |
in |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
706 |
rtac thm THEN' quotient_tac ctxt |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
707 |
end |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
708 |
handle THM _ => K no_tac |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
709 |
| TYPE _ => K no_tac |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
710 |
| TERM _ => K no_tac |
629
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
711 |
*} |
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
712 |
|
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
713 |
thm rep_abs_rsp |
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
714 |
|
629
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
715 |
ML {* |
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
716 |
fun rep_abs_rsp_tac ctxt = |
597 | 717 |
SUBGOAL (fn (goal, i) => |
718 |
case (bare_concl goal) of |
|
719 |
(rel $ _ $ (rep $ (abs $ _))) => |
|
720 |
(let |
|
721 |
val thy = ProofContext.theory_of ctxt; |
|
722 |
val (ty_a, ty_b) = dest_fun_type (fastype_of abs); |
|
723 |
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b]; |
|
724 |
val t_inst = map (SOME o (cterm_of thy)) [rel, abs, rep]; |
|
725 |
val thm = Drule.instantiate' ty_inst t_inst @{thm rep_abs_rsp} |
|
726 |
in |
|
734
ac2ed047988d
annotated some questions to the code; some simple changes
Christian Urban <urbanc@in.tum.de>
parents:
730
diff
changeset
|
727 |
(rtac thm THEN' quotient_tac ctxt) i |
597 | 728 |
end |
738 | 729 |
handle _ => no_tac) (* what is the catch for ? Should go away, no? *) |
597 | 730 |
| _ => no_tac) |
731 |
*} |
|
732 |
||
733 |
ML {* |
|
629
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
734 |
fun inj_repabs_tac_match ctxt = SUBGOAL (fn (goal, i) => |
597 | 735 |
(case (bare_concl goal) of |
736 |
(* (R1 ===> R2) (\<lambda>x\<dots>) (\<lambda>y\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *) |
|
738 | 737 |
(Const (@{const_name fun_rel}, _) $ _ $ _) $ (Abs _) $ (Abs _) |
597 | 738 |
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam |
739 |
||
740 |
(* (op =) (Ball\<dots>) (Ball\<dots>) ----> (op =) (\<dots>) (\<dots>) *) |
|
741 |
| (Const (@{const_name "op ="},_) $ |
|
742 |
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
743 |
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _)) |
|
744 |
=> rtac @{thm ball_rsp} THEN' dtac @{thm QT_all} |
|
745 |
||
746 |
(* (R1 ===> op =) (Ball\<dots>) (Ball\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Ball\<dots>x) = (Ball\<dots>y) *) |
|
747 |
| (Const (@{const_name fun_rel}, _) $ _ $ _) $ |
|
748 |
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
749 |
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) |
|
750 |
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam |
|
751 |
||
752 |
(* (op =) (Bex\<dots>) (Bex\<dots>) ----> (op =) (\<dots>) (\<dots>) *) |
|
753 |
| Const (@{const_name "op ="},_) $ |
|
754 |
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
755 |
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) |
|
756 |
=> rtac @{thm bex_rsp} THEN' dtac @{thm QT_ex} |
|
757 |
||
758 |
(* (R1 ===> op =) (Bex\<dots>) (Bex\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Bex\<dots>x) = (Bex\<dots>y) *) |
|
759 |
| (Const (@{const_name fun_rel}, _) $ _ $ _) $ |
|
760 |
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
761 |
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) |
|
762 |
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam |
|
763 |
||
764 |
| (_ $ |
|
765 |
(Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
766 |
(Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _)) |
|
767 |
=> rtac @{thm babs_rsp} THEN' RANGE [quotient_tac ctxt] |
|
768 |
||
738 | 769 |
| Const (@{const_name "op ="},_) $ (R $ _ $ _) $ (_ $ _ $ _) => |
770 |
(rtac @{thm refl} ORELSE' |
|
629
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
771 |
(equals_rsp_tac R ctxt THEN' RANGE [ |
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
772 |
quot_true_tac ctxt (fst o dest_bcomb), quot_true_tac ctxt (snd o dest_bcomb)])) |
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
773 |
|
597 | 774 |
(* reflexivity of operators arising from Cong_tac *) |
629
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
775 |
| Const (@{const_name "op ="},_) $ _ $ _ => rtac @{thm refl} |
597 | 776 |
|
777 |
(* respectfulness of constants; in particular of a simple relation *) |
|
778 |
| _ $ (Const _) $ (Const _) (* fun_rel, list_rel, etc but not equality *) |
|
779 |
=> resolve_tac (rsp_rules_get ctxt) THEN_ALL_NEW quotient_tac ctxt |
|
780 |
||
781 |
(* R (\<dots>) (Rep (Abs \<dots>)) ----> R (\<dots>) (\<dots>) *) |
|
782 |
(* observe ---> *) |
|
624
c4299ce27e46
Removed pattern from quot_rel_rsp, since list_rel and all used introduced ones cannot be patterned
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
621
diff
changeset
|
783 |
| _ $ _ $ _ |
738 | 784 |
=> (rtac @{thm quot_rel_rsp} THEN_ALL_NEW quotient_tac ctxt) |
785 |
ORELSE' rep_abs_rsp_tac ctxt |
|
597 | 786 |
|
738 | 787 |
| _ => K no_tac |
597 | 788 |
) i) |
789 |
*} |
|
790 |
||
791 |
ML {* |
|
629
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
792 |
fun inj_repabs_step_tac ctxt rel_refl = |
597 | 793 |
(FIRST' [ |
686
2ff666f644cc
deleted DT/NDT diagnostic code
Christian Urban <urbanc@in.tum.de>
parents:
668
diff
changeset
|
794 |
inj_repabs_tac_match ctxt, |
597 | 795 |
(* R (t $ \<dots>) (t' $ \<dots>) ----> apply_rsp provided type of t needs lifting *) |
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
796 |
|
686
2ff666f644cc
deleted DT/NDT diagnostic code
Christian Urban <urbanc@in.tum.de>
parents:
668
diff
changeset
|
797 |
apply_rsp_tac ctxt THEN' |
2ff666f644cc
deleted DT/NDT diagnostic code
Christian Urban <urbanc@in.tum.de>
parents:
668
diff
changeset
|
798 |
RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)], |
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
799 |
|
597 | 800 |
(* (op =) (t $ \<dots>) (t' $ \<dots>) ----> Cong provided type of t does not need lifting *) |
801 |
(* merge with previous tactic *) |
|
686
2ff666f644cc
deleted DT/NDT diagnostic code
Christian Urban <urbanc@in.tum.de>
parents:
668
diff
changeset
|
802 |
Cong_Tac.cong_tac @{thm cong} THEN' |
2ff666f644cc
deleted DT/NDT diagnostic code
Christian Urban <urbanc@in.tum.de>
parents:
668
diff
changeset
|
803 |
RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)], |
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
804 |
|
597 | 805 |
(* (op =) (\<lambda>x\<dots>) (\<lambda>x\<dots>) ----> (op =) (\<dots>) (\<dots>) *) |
686
2ff666f644cc
deleted DT/NDT diagnostic code
Christian Urban <urbanc@in.tum.de>
parents:
668
diff
changeset
|
806 |
rtac @{thm ext} THEN' quot_true_tac ctxt unlam, |
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
807 |
|
597 | 808 |
(* resolving with R x y assumptions *) |
686
2ff666f644cc
deleted DT/NDT diagnostic code
Christian Urban <urbanc@in.tum.de>
parents:
668
diff
changeset
|
809 |
atac, |
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
810 |
|
597 | 811 |
(* reflexivity of the basic relations *) |
812 |
(* R \<dots> \<dots> *) |
|
686
2ff666f644cc
deleted DT/NDT diagnostic code
Christian Urban <urbanc@in.tum.de>
parents:
668
diff
changeset
|
813 |
resolve_tac rel_refl]) |
597 | 814 |
*} |
815 |
||
816 |
ML {* |
|
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
817 |
fun inj_repabs_tac ctxt = |
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
818 |
let |
612 | 819 |
val rel_refl = map (OF1 @{thm equivp_reflp}) (equiv_rules_get ctxt) |
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
820 |
in |
629
df42285e7286
trans2 replaced with equals_rsp_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
624
diff
changeset
|
821 |
inj_repabs_step_tac ctxt rel_refl |
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
822 |
end |
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
823 |
|
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
824 |
fun all_inj_repabs_tac ctxt = |
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
825 |
REPEAT_ALL_NEW (inj_repabs_tac ctxt) |
597 | 826 |
*} |
827 |
||
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
828 |
section {* Cleaning of the Theorem *} |
597 | 829 |
|
659
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
830 |
ML {* |
738 | 831 |
(* expands all fun_maps, except in front of bound variables *) |
832 |
||
659
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
833 |
fun fun_map_simple_conv xs ctxt ctrm = |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
834 |
case (term_of ctrm) of |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
835 |
((Const (@{const_name "fun_map"}, _) $ _ $ _) $ h $ _) => |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
836 |
if (member (op=) xs h) |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
837 |
then Conv.all_conv ctrm |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
838 |
else Conv.rewr_conv @{thm fun_map.simps[THEN eq_reflection]} ctrm |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
839 |
| _ => Conv.all_conv ctrm |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
840 |
|
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
841 |
fun fun_map_conv xs ctxt ctrm = |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
842 |
case (term_of ctrm) of |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
843 |
_ $ _ => (Conv.comb_conv (fun_map_conv xs ctxt) then_conv |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
844 |
fun_map_simple_conv xs ctxt) ctrm |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
845 |
| Abs _ => Conv.abs_conv (fn (x, ctxt) => fun_map_conv ((term_of x)::xs) ctxt) ctxt ctrm |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
846 |
| _ => Conv.all_conv ctrm |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
847 |
|
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
848 |
fun fun_map_tac ctxt = CONVERSION (fun_map_conv [] ctxt) |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
849 |
*} |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
850 |
|
694 | 851 |
(* Since the patterns for the lhs are different; there are 2 different make-insts *) |
631 | 852 |
(* 1: does ? \<rightarrow> id *) |
694 | 853 |
(* 2: does ? \<rightarrow> non-id *) |
737
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
854 |
ML {* |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
855 |
fun mk_abs u i t = |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
856 |
if incr_boundvars i u aconv t then Bound i |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
857 |
else (case t of |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
858 |
t1 $ t2 => (mk_abs u i t1) $ (mk_abs u i t2) |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
859 |
| Abs (s, T, t') => Abs (s, T, mk_abs u (i + 1) t') |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
860 |
| Bound j => if i = j then error "make_inst" else t |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
861 |
| _ => t) |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
862 |
|
597 | 863 |
fun make_inst lhs t = |
737
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
864 |
let |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
865 |
val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs; |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
866 |
val _ $ (Abs (_, _, g)) = t; |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
867 |
in |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
868 |
(f, Abs ("x", T, mk_abs u 0 g)) |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
869 |
end |
597 | 870 |
|
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
871 |
fun make_inst2 lhs t = |
737
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
872 |
let |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
873 |
val _ $ (Abs (_, _, (_ $ ((f as Var (_, Type ("fun", [T, _]))) $ u)))) = lhs; |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
874 |
val _ $ (Abs (_, _, (_ $ g))) = t; |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
875 |
in |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
876 |
(f, Abs ("x", T, mk_abs u 0 g)) |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
877 |
end |
631 | 878 |
*} |
879 |
||
880 |
ML {* |
|
597 | 881 |
fun lambda_prs_simple_conv ctxt ctrm = |
882 |
case (term_of ctrm) of |
|
730 | 883 |
(Const (@{const_name fun_map}, _) $ r1 $ a2) $ (Abs _) => |
608
678315da994e
Handling of errors in lambda_prs_conv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
606
diff
changeset
|
884 |
(let |
597 | 885 |
val thy = ProofContext.theory_of ctxt |
886 |
val (ty_b, ty_a) = dest_fun_type (fastype_of r1) |
|
887 |
val (ty_c, ty_d) = dest_fun_type (fastype_of a2) |
|
888 |
val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d] |
|
889 |
val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)] |
|
890 |
val lpi = Drule.instantiate' tyinst tinst @{thm lambda_prs} |
|
891 |
val te = @{thm eq_reflection} OF [solve_quotient_assums ctxt (solve_quotient_assums ctxt lpi)] |
|
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
892 |
val ti = |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
893 |
(let |
614
51a4208162ed
added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents:
613
diff
changeset
|
894 |
val ts = MetaSimplifier.rewrite_rule (id_simps_get ctxt) te |
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
895 |
val (insp, inst) = make_inst (term_of (Thm.lhs_of ts)) (term_of ctrm) |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
896 |
in |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
897 |
Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts |
608
678315da994e
Handling of errors in lambda_prs_conv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
606
diff
changeset
|
898 |
end handle _ => (* TODO handle only Bind | Error "make_inst" *) |
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
899 |
let |
631 | 900 |
val ts = MetaSimplifier.rewrite_rule (id_simps_get ctxt) te |
901 |
val _ = tracing ("ts rule:\n" ^ (Syntax.string_of_term ctxt (prop_of ts))); |
|
902 |
val _ = tracing ("redex:\n" ^ (Syntax.string_of_term ctxt (term_of ctrm))); |
|
903 |
val (insp, inst) = make_inst2 (term_of (Thm.lhs_of ts)) (term_of ctrm) |
|
904 |
in |
|
905 |
Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts |
|
906 |
end handle _ => (* TODO handle only Bind | Error "make_inst" *) |
|
907 |
let |
|
662 | 908 |
val (insp, inst) = make_inst2 (term_of (Thm.lhs_of te)) (term_of ctrm) |
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
909 |
val td = Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) te |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
910 |
in |
614
51a4208162ed
added a thm list for ids
Christian Urban <urbanc@in.tum.de>
parents:
613
diff
changeset
|
911 |
MetaSimplifier.rewrite_rule (id_simps_get ctxt) td |
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
912 |
end); |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
913 |
val _ = if not (Term.is_Const a2 andalso fst (dest_Const a2) = @{const_name "id"}) then |
597 | 914 |
(tracing "lambda_prs"; |
915 |
tracing ("redex:\n" ^ (Syntax.string_of_term ctxt (term_of ctrm))); |
|
916 |
tracing ("lpi rule:\n" ^ (Syntax.string_of_term ctxt (prop_of lpi))); |
|
917 |
tracing ("te rule:\n" ^ (Syntax.string_of_term ctxt (prop_of te))); |
|
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
918 |
tracing ("ti rule:\n" ^ (Syntax.string_of_term ctxt (prop_of ti)))) |
597 | 919 |
else () |
631 | 920 |
|
597 | 921 |
in |
922 |
Conv.rewr_conv ti ctrm |
|
923 |
end |
|
608
678315da994e
Handling of errors in lambda_prs_conv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
606
diff
changeset
|
924 |
handle _ => Conv.all_conv ctrm) |
597 | 925 |
| _ => Conv.all_conv ctrm |
926 |
*} |
|
927 |
||
928 |
ML {* |
|
929 |
val lambda_prs_conv = |
|
930 |
More_Conv.top_conv lambda_prs_simple_conv |
|
931 |
||
932 |
fun lambda_prs_tac ctxt = CONVERSION (lambda_prs_conv ctxt) |
|
933 |
*} |
|
934 |
||
659
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
935 |
(* 1. folding of definitions and preservation lemmas; *) |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
936 |
(* and simplification with *) |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
937 |
thm babs_prs all_prs ex_prs |
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
938 |
(* 2. unfolding of ---> in front of everything, except *) |
730 | 939 |
(* bound variables (this prevents lambda_prs from *) |
940 |
(* becoming stuck *) |
|
660 | 941 |
thm fun_map.simps |
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
942 |
(* 3. simplification with *) |
661 | 943 |
thm lambda_prs |
660 | 944 |
(* 4. simplification with *) |
659
86c60d55373c
moved function and tuned comment
Christian Urban <urbanc@in.tum.de>
parents:
658
diff
changeset
|
945 |
thm Quotient_abs_rep Quotient_rel_rep id_simps |
660 | 946 |
(* 5. Test for refl *) |
597 | 947 |
|
652
d8f07b5bcfae
implemented cleaning strategy with fun_map.simps on non-bounded variables; still a few rough edges
Christian Urban <urbanc@in.tum.de>
parents:
648
diff
changeset
|
948 |
ML {* |
597 | 949 |
fun clean_tac lthy = |
950 |
let |
|
951 |
val thy = ProofContext.theory_of lthy; |
|
952 |
val defs = map (Thm.varifyT o symmetric o #def) (qconsts_dest thy) |
|
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
953 |
(* FIXME: why is the Thm.varifyT needed: example where it fails is LamEx *) |
658 | 954 |
|
656
c86a47d4966e
Temporarily repeated fun_map_tac 4 times. Cleaning for all examples work.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
655
diff
changeset
|
955 |
val thms1 = defs @ (prs_rules_get lthy) @ @{thms babs_prs all_prs ex_prs} |
658 | 956 |
val thms2 = @{thms Quotient_abs_rep Quotient_rel_rep} @ (id_simps_get lthy) |
597 | 957 |
fun simps thms = (mk_minimal_ss lthy) addsimps thms addSolver quotient_solver |
958 |
in |
|
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
parents:
643
diff
changeset
|
959 |
EVERY' [simp_tac (simps thms1), |
658 | 960 |
fun_map_tac lthy, |
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
parents:
643
diff
changeset
|
961 |
lambda_prs_tac lthy, |
597 | 962 |
simp_tac (simps thms2), |
963 |
TRY o rtac refl] |
|
964 |
end |
|
965 |
*} |
|
966 |
||
689 | 967 |
section {* Tactic for Genralisation of Free Variables in a Goal *} |
597 | 968 |
|
969 |
ML {* |
|
970 |
fun inst_spec ctrm = |
|
971 |
Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec} |
|
972 |
||
973 |
fun inst_spec_tac ctrms = |
|
974 |
EVERY' (map (dtac o inst_spec) ctrms) |
|
975 |
||
976 |
fun all_list xs trm = |
|
977 |
fold (fn (x, T) => fn t' => HOLogic.mk_all (x, T, t')) xs trm |
|
978 |
||
979 |
fun apply_under_Trueprop f = |
|
980 |
HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop |
|
981 |
||
982 |
fun gen_frees_tac ctxt = |
|
983 |
SUBGOAL (fn (concl, i) => |
|
984 |
let |
|
985 |
val thy = ProofContext.theory_of ctxt |
|
986 |
val vrs = Term.add_frees concl [] |
|
987 |
val cvrs = map (cterm_of thy o Free) vrs |
|
988 |
val concl' = apply_under_Trueprop (all_list vrs) concl |
|
989 |
val goal = Logic.mk_implies (concl', concl) |
|
990 |
val rule = Goal.prove ctxt [] [] goal |
|
991 |
(K (EVERY1 [inst_spec_tac (rev cvrs), atac])) |
|
992 |
in |
|
993 |
rtac rule i |
|
994 |
end) |
|
995 |
*} |
|
996 |
||
699
aa157e957655
added maps-printout and tuned some comments
Christian Urban <urbanc@in.tum.de>
parents:
697
diff
changeset
|
997 |
section {* The General Shape of the Lifting Procedure *} |
597 | 998 |
|
699
aa157e957655
added maps-printout and tuned some comments
Christian Urban <urbanc@in.tum.de>
parents:
697
diff
changeset
|
999 |
(* - A is the original raw theorem *) |
aa157e957655
added maps-printout and tuned some comments
Christian Urban <urbanc@in.tum.de>
parents:
697
diff
changeset
|
1000 |
(* - B is the regularized theorem *) |
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1001 |
(* - C is the rep/abs injected version of B *) |
699
aa157e957655
added maps-printout and tuned some comments
Christian Urban <urbanc@in.tum.de>
parents:
697
diff
changeset
|
1002 |
(* - D is the lifted theorem *) |
aa157e957655
added maps-printout and tuned some comments
Christian Urban <urbanc@in.tum.de>
parents:
697
diff
changeset
|
1003 |
(* *) |
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1004 |
(* - 1st prem is the regularization step *) |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1005 |
(* - 2nd prem is the rep/abs injection step *) |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1006 |
(* - 3rd prem is the cleaning part *) |
699
aa157e957655
added maps-printout and tuned some comments
Christian Urban <urbanc@in.tum.de>
parents:
697
diff
changeset
|
1007 |
(* *) |
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1008 |
(* the QUOT_TRUE premise in 2 records the lifted theorem *) |
597 | 1009 |
|
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1010 |
ML {* |
737
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
1011 |
val lifting_procedure = |
4335435fcf83
trivial cleaning of make_inst
Christian Urban <urbanc@in.tum.de>
parents:
736
diff
changeset
|
1012 |
@{lemma "\<lbrakk>A; A \<longrightarrow> B; QUOT_TRUE D \<Longrightarrow> B = C; C = D\<rbrakk> \<Longrightarrow> D" by (simp add: QUOT_TRUE_def)} |
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1013 |
*} |
597 | 1014 |
|
1015 |
ML {* |
|
1016 |
fun lift_match_error ctxt fun_str rtrm qtrm = |
|
1017 |
let |
|
1018 |
val rtrm_str = Syntax.string_of_term ctxt rtrm |
|
1019 |
val qtrm_str = Syntax.string_of_term ctxt qtrm |
|
704 | 1020 |
val msg = cat_lines [enclose "[" "]" fun_str, "The quotient theorem", qtrm_str, |
1021 |
"", "does not match with original theorem", rtrm_str] |
|
597 | 1022 |
in |
704 | 1023 |
error msg |
597 | 1024 |
end |
1025 |
*} |
|
1026 |
||
1027 |
ML {* |
|
1028 |
fun procedure_inst ctxt rtrm qtrm = |
|
1029 |
let |
|
1030 |
val thy = ProofContext.theory_of ctxt |
|
1031 |
val rtrm' = HOLogic.dest_Trueprop rtrm |
|
1032 |
val qtrm' = HOLogic.dest_Trueprop qtrm |
|
1033 |
val reg_goal = |
|
1034 |
Syntax.check_term ctxt (regularize_trm ctxt rtrm' qtrm') |
|
1035 |
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm |
|
1036 |
val inj_goal = |
|
1037 |
Syntax.check_term ctxt (inj_repabs_trm ctxt (reg_goal, qtrm')) |
|
1038 |
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm |
|
1039 |
in |
|
1040 |
Drule.instantiate' [] |
|
1041 |
[SOME (cterm_of thy rtrm'), |
|
1042 |
SOME (cterm_of thy reg_goal), |
|
688
fa0f6fdac5de
simplified the instantiation of QUOT_TRUE in procedure_tac
Christian Urban <urbanc@in.tum.de>
parents:
687
diff
changeset
|
1043 |
NONE, |
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1044 |
SOME (cterm_of thy inj_goal)] lifting_procedure |
597 | 1045 |
end |
1046 |
*} |
|
1047 |
||
1048 |
ML {* |
|
616 | 1049 |
(* the tactic leaves three subgoals to be proved *) |
597 | 1050 |
fun procedure_tac ctxt rthm = |
1051 |
ObjectLogic.full_atomize_tac |
|
1052 |
THEN' gen_frees_tac ctxt |
|
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
1053 |
THEN' CSUBGOAL (fn (goal, i) => |
597 | 1054 |
let |
1055 |
val rthm' = atomize_thm rthm |
|
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
parents:
606
diff
changeset
|
1056 |
val rule = procedure_inst ctxt (prop_of rthm') (term_of goal) |
597 | 1057 |
in |
688
fa0f6fdac5de
simplified the instantiation of QUOT_TRUE in procedure_tac
Christian Urban <urbanc@in.tum.de>
parents:
687
diff
changeset
|
1058 |
(rtac rule THEN' rtac rthm') i |
597 | 1059 |
end) |
1060 |
*} |
|
1061 |
||
689 | 1062 |
section {* Automatic Proofs *} |
1063 |
||
612 | 1064 |
ML {* |
616 | 1065 |
fun SOLVES' tac = tac THEN_ALL_NEW (K no_tac) |
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1066 |
|
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1067 |
(* prints warning, if goal is unsolved *) |
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1068 |
fun WARN (tac, msg) i st = |
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1069 |
case Seq.pull ((SOLVES' tac) i st) of |
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1070 |
NONE => (warning msg; Seq.single st) |
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1071 |
| seqcell => Seq.make (fn () => seqcell) |
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1072 |
|
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1073 |
fun RANGE_WARN xs = RANGE (map WARN xs) |
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1074 |
*} |
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1075 |
|
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
parents:
614
diff
changeset
|
1076 |
ML {* |
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1077 |
local |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1078 |
|
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1079 |
val msg1 = "Regularize proof failed." |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1080 |
val msg2 = cat_lines ["Injection proof failed.", |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1081 |
"This is probably due to missing respects lemmas.", |
715
3d7a9d4d2bb6
added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
704
diff
changeset
|
1082 |
"Try invoking the injection method manually to see", |
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1083 |
"which lemmas are missing."] |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1084 |
val msg3 = "Cleaning proof failed." |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1085 |
|
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1086 |
in |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1087 |
|
612 | 1088 |
fun lift_tac ctxt rthm = |
1089 |
procedure_tac ctxt rthm |
|
688
fa0f6fdac5de
simplified the instantiation of QUOT_TRUE in procedure_tac
Christian Urban <urbanc@in.tum.de>
parents:
687
diff
changeset
|
1090 |
THEN' RANGE_WARN |
703
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1091 |
[(regularize_tac ctxt, msg1), |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1092 |
(all_inj_repabs_tac ctxt, msg2), |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1093 |
(clean_tac ctxt, msg3)] |
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1094 |
|
8b2c46e11674
reformulated the lemma lifting_procedure as ML value; gave better warning message for injection case
Christian Urban <urbanc@in.tum.de>
parents:
699
diff
changeset
|
1095 |
end |
612 | 1096 |
*} |
1097 |
||
689 | 1098 |
section {* Methods / Interface *} |
1099 |
||
632
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1100 |
ML {* |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1101 |
fun mk_method1 tac thm ctxt = |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1102 |
SIMPLE_METHOD (HEADGOAL (tac ctxt thm)) |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1103 |
|
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1104 |
fun mk_method2 tac ctxt = |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1105 |
SIMPLE_METHOD (HEADGOAL (tac ctxt)) |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1106 |
*} |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1107 |
|
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1108 |
method_setup lifting = |
637
b029f242d85d
chnaged syntax to "lifting theorem"
Christian Urban <urbanc@in.tum.de>
parents:
636
diff
changeset
|
1109 |
{* Attrib.thm >> (mk_method1 lift_tac) *} |
632
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1110 |
{* Lifting of theorems to quotient types. *} |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1111 |
|
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1112 |
method_setup lifting_setup = |
637
b029f242d85d
chnaged syntax to "lifting theorem"
Christian Urban <urbanc@in.tum.de>
parents:
636
diff
changeset
|
1113 |
{* Attrib.thm >> (mk_method1 procedure_tac) *} |
632
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1114 |
{* Sets up the three goals for the lifting procedure. *} |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1115 |
|
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1116 |
method_setup regularize = |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1117 |
{* Scan.succeed (mk_method2 regularize_tac) *} |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1118 |
{* Proves automatically the regularization goals from the lifting procedure. *} |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1119 |
|
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1120 |
method_setup injection = |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1121 |
{* Scan.succeed (mk_method2 all_inj_repabs_tac) *} |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1122 |
{* Proves automatically the rep/abs injection goals from the lifting procedure. *} |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1123 |
|
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1124 |
method_setup cleaning = |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1125 |
{* Scan.succeed (mk_method2 clean_tac) *} |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1126 |
{* Proves automatically the cleaning goals from the lifting procedure. *} |
d23416464f62
added methods for the lifting_tac and the other tacs
Christian Urban <urbanc@in.tum.de>
parents:
624
diff
changeset
|
1127 |
|
597 | 1128 |
end |
1129 |