author | Christian Urban <urbanc@in.tum.de> |
Mon, 07 Dec 2009 21:54:14 +0100 | |
changeset 611 | bb5d3278f02e |
parent 610 | 2bee5ca44ef5 |
parent 608 | 678315da994e |
child 612 | ec37a279ca55 |
permissions | -rw-r--r-- |
597 | 1 |
theory QuotMain |
600
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
2 |
imports QuotScript QuotProd Prove |
597 | 3 |
uses ("quotient_info.ML") |
4 |
("quotient.ML") |
|
5 |
("quotient_def.ML") |
|
6 |
begin |
|
7 |
||
8 |
||
9 |
locale QUOT_TYPE = |
|
10 |
fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
|
11 |
and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b" |
|
12 |
and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)" |
|
13 |
assumes equivp: "equivp R" |
|
14 |
and rep_prop: "\<And>y. \<exists>x. Rep y = R x" |
|
15 |
and rep_inverse: "\<And>x. Abs (Rep x) = x" |
|
16 |
and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)" |
|
17 |
and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)" |
|
18 |
begin |
|
19 |
||
20 |
definition |
|
21 |
ABS::"'a \<Rightarrow> 'b" |
|
22 |
where |
|
23 |
"ABS x \<equiv> Abs (R x)" |
|
24 |
||
25 |
definition |
|
26 |
REP::"'b \<Rightarrow> 'a" |
|
27 |
where |
|
28 |
"REP a = Eps (Rep a)" |
|
29 |
||
30 |
lemma lem9: |
|
31 |
shows "R (Eps (R x)) = R x" |
|
32 |
proof - |
|
33 |
have a: "R x x" using equivp by (simp add: equivp_reflp_symp_transp reflp_def) |
|
34 |
then have "R x (Eps (R x))" by (rule someI) |
|
35 |
then show "R (Eps (R x)) = R x" |
|
36 |
using equivp unfolding equivp_def by simp |
|
37 |
qed |
|
38 |
||
39 |
theorem thm10: |
|
40 |
shows "ABS (REP a) \<equiv> a" |
|
41 |
apply (rule eq_reflection) |
|
42 |
unfolding ABS_def REP_def |
|
43 |
proof - |
|
44 |
from rep_prop |
|
45 |
obtain x where eq: "Rep a = R x" by auto |
|
46 |
have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp |
|
47 |
also have "\<dots> = Abs (R x)" using lem9 by simp |
|
48 |
also have "\<dots> = Abs (Rep a)" using eq by simp |
|
49 |
also have "\<dots> = a" using rep_inverse by simp |
|
50 |
finally |
|
51 |
show "Abs (R (Eps (Rep a))) = a" by simp |
|
52 |
qed |
|
53 |
||
54 |
lemma REP_refl: |
|
55 |
shows "R (REP a) (REP a)" |
|
56 |
unfolding REP_def |
|
57 |
by (simp add: equivp[simplified equivp_def]) |
|
58 |
||
59 |
lemma lem7: |
|
60 |
shows "(R x = R y) = (Abs (R x) = Abs (R y))" |
|
61 |
apply(rule iffI) |
|
62 |
apply(simp) |
|
63 |
apply(drule rep_inject[THEN iffD2]) |
|
64 |
apply(simp add: abs_inverse) |
|
65 |
done |
|
66 |
||
67 |
theorem thm11: |
|
68 |
shows "R r r' = (ABS r = ABS r')" |
|
69 |
unfolding ABS_def |
|
70 |
by (simp only: equivp[simplified equivp_def] lem7) |
|
71 |
||
72 |
||
73 |
lemma REP_ABS_rsp: |
|
74 |
shows "R f (REP (ABS g)) = R f g" |
|
75 |
and "R (REP (ABS g)) f = R g f" |
|
76 |
by (simp_all add: thm10 thm11) |
|
77 |
||
78 |
lemma Quotient: |
|
79 |
"Quotient R ABS REP" |
|
80 |
apply(unfold Quotient_def) |
|
81 |
apply(simp add: thm10) |
|
82 |
apply(simp add: REP_refl) |
|
83 |
apply(subst thm11[symmetric]) |
|
84 |
apply(simp add: equivp[simplified equivp_def]) |
|
85 |
done |
|
86 |
||
87 |
lemma R_trans: |
|
88 |
assumes ab: "R a b" |
|
89 |
and bc: "R b c" |
|
90 |
shows "R a c" |
|
91 |
proof - |
|
92 |
have tr: "transp R" using equivp equivp_reflp_symp_transp[of R] by simp |
|
93 |
moreover have ab: "R a b" by fact |
|
94 |
moreover have bc: "R b c" by fact |
|
95 |
ultimately show "R a c" unfolding transp_def by blast |
|
96 |
qed |
|
97 |
||
98 |
lemma R_sym: |
|
99 |
assumes ab: "R a b" |
|
100 |
shows "R b a" |
|
101 |
proof - |
|
102 |
have re: "symp R" using equivp equivp_reflp_symp_transp[of R] by simp |
|
103 |
then show "R b a" using ab unfolding symp_def by blast |
|
104 |
qed |
|
105 |
||
106 |
lemma R_trans2: |
|
107 |
assumes ac: "R a c" |
|
108 |
and bd: "R b d" |
|
109 |
shows "R a b = R c d" |
|
110 |
using ac bd |
|
111 |
by (blast intro: R_trans R_sym) |
|
112 |
||
113 |
lemma REPS_same: |
|
114 |
shows "R (REP a) (REP b) \<equiv> (a = b)" |
|
115 |
proof - |
|
116 |
have "R (REP a) (REP b) = (a = b)" |
|
117 |
proof |
|
118 |
assume as: "R (REP a) (REP b)" |
|
119 |
from rep_prop |
|
120 |
obtain x y |
|
121 |
where eqs: "Rep a = R x" "Rep b = R y" by blast |
|
122 |
from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp |
|
123 |
then have "R x (Eps (R y))" using lem9 by simp |
|
124 |
then have "R (Eps (R y)) x" using R_sym by blast |
|
125 |
then have "R y x" using lem9 by simp |
|
126 |
then have "R x y" using R_sym by blast |
|
127 |
then have "ABS x = ABS y" using thm11 by simp |
|
128 |
then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp |
|
129 |
then show "a = b" using rep_inverse by simp |
|
130 |
next |
|
131 |
assume ab: "a = b" |
|
132 |
have "reflp R" using equivp equivp_reflp_symp_transp[of R] by simp |
|
133 |
then show "R (REP a) (REP b)" unfolding reflp_def using ab by auto |
|
134 |
qed |
|
135 |
then show "R (REP a) (REP b) \<equiv> (a = b)" by simp |
|
136 |
qed |
|
137 |
||
138 |
end |
|
139 |
||
140 |
section {* type definition for the quotient type *} |
|
141 |
||
142 |
(* the auxiliary data for the quotient types *) |
|
143 |
use "quotient_info.ML" |
|
144 |
||
145 |
declare [[map * = (prod_fun, prod_rel)]] |
|
146 |
declare [[map "fun" = (fun_map, fun_rel)]] |
|
600
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
147 |
(* FIXME: This should throw an exception: |
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
148 |
declare [[map "option" = (bla, blu)]] |
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
149 |
*) |
597 | 150 |
|
151 |
(* identity quotient is not here as it has to be applied first *) |
|
152 |
lemmas [quotient_thm] = |
|
600
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
153 |
fun_quotient prod_quotient |
597 | 154 |
|
155 |
lemmas [quotient_rsp] = |
|
600
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
156 |
quot_rel_rsp pair_rsp |
597 | 157 |
|
158 |
(* fun_map is not here since equivp is not true *) |
|
159 |
(* TODO: option, ... *) |
|
160 |
lemmas [quotient_equiv] = |
|
600
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
161 |
identity_equivp prod_equivp |
597 | 162 |
|
163 |
ML {* maps_lookup @{theory} "*" *} |
|
164 |
ML {* maps_lookup @{theory} "fun" *} |
|
165 |
||
166 |
||
167 |
(* definition of the quotient types *) |
|
168 |
(* FIXME: should be called quotient_typ.ML *) |
|
169 |
use "quotient.ML" |
|
170 |
||
171 |
||
172 |
(* lifting of constants *) |
|
173 |
use "quotient_def.ML" |
|
174 |
||
175 |
section {* Simset setup *} |
|
176 |
||
177 |
(* since HOL_basic_ss is too "big", we need to set up *) |
|
178 |
(* our own minimal simpset *) |
|
179 |
ML {* |
|
180 |
fun mk_minimal_ss ctxt = |
|
181 |
Simplifier.context ctxt empty_ss |
|
182 |
setsubgoaler asm_simp_tac |
|
183 |
setmksimps (mksimps []) |
|
184 |
*} |
|
185 |
||
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
|
186 |
ML {* |
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
187 |
(* TODO/FIXME not needed anymore? *) |
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
188 |
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac) |
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
|
189 |
|
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
|
190 |
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
|
191 |
*} |
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
192 |
|
597 | 193 |
section {* atomize *} |
194 |
||
195 |
lemma atomize_eqv[atomize]: |
|
196 |
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)" |
|
197 |
proof |
|
198 |
assume "A \<equiv> B" |
|
199 |
then show "Trueprop A \<equiv> Trueprop B" by unfold |
|
200 |
next |
|
201 |
assume *: "Trueprop A \<equiv> Trueprop B" |
|
202 |
have "A = B" |
|
203 |
proof (cases A) |
|
204 |
case True |
|
205 |
have "A" by fact |
|
206 |
then show "A = B" using * by simp |
|
207 |
next |
|
208 |
case False |
|
209 |
have "\<not>A" by fact |
|
210 |
then show "A = B" using * by auto |
|
211 |
qed |
|
212 |
then show "A \<equiv> B" by (rule eq_reflection) |
|
213 |
qed |
|
214 |
||
215 |
ML {* |
|
216 |
fun atomize_thm thm = |
|
217 |
let |
|
218 |
val thm' = Thm.freezeT (forall_intr_vars thm) |
|
219 |
val thm'' = ObjectLogic.atomize (cprop_of thm') |
|
220 |
in |
|
221 |
@{thm equal_elim_rule1} OF [thm'', thm'] |
|
222 |
end |
|
223 |
*} |
|
224 |
||
225 |
section {* infrastructure about id *} |
|
226 |
||
600
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
227 |
(* TODO: think where should this be *) |
597 | 228 |
lemma prod_fun_id: "prod_fun id id \<equiv> id" |
229 |
by (rule eq_reflection) (simp add: prod_fun_def) |
|
230 |
||
600
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
231 |
(* FIXME: make it a list and add map_id to it *) |
597 | 232 |
lemmas id_simps = |
233 |
fun_map_id[THEN eq_reflection] |
|
234 |
id_apply[THEN eq_reflection] |
|
235 |
id_def[THEN eq_reflection,symmetric] |
|
600
5d932e7a856c
List moved after QuotMain
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
597
diff
changeset
|
236 |
prod_fun_id |
597 | 237 |
|
238 |
ML {* |
|
239 |
fun simp_ids thm = |
|
240 |
MetaSimplifier.rewrite_rule @{thms id_simps} thm |
|
241 |
*} |
|
242 |
||
243 |
section {* Debugging infrastructure for testing tactics *} |
|
244 |
||
245 |
ML {* |
|
246 |
fun my_print_tac ctxt s i thm = |
|
247 |
let |
|
248 |
val prem_str = nth (prems_of thm) (i - 1) |
|
249 |
|> Syntax.string_of_term ctxt |
|
250 |
handle Subscript => "no subgoal" |
|
251 |
val _ = tracing (s ^ "\n" ^ prem_str) |
|
252 |
in |
|
253 |
Seq.single thm |
|
254 |
end *} |
|
255 |
||
256 |
ML {* |
|
257 |
fun DT ctxt s tac i thm = |
|
258 |
let |
|
259 |
val before_goal = nth (prems_of thm) (i - 1) |
|
260 |
|> Syntax.string_of_term ctxt |
|
261 |
val before_msg = ["before: " ^ s, before_goal, "after: " ^ s] |
|
262 |
|> cat_lines |
|
263 |
in |
|
264 |
EVERY [tac i, my_print_tac ctxt before_msg i] thm |
|
265 |
end |
|
266 |
||
267 |
fun NDT ctxt s tac thm = tac thm |
|
268 |
*} |
|
269 |
||
270 |
section {* Matching of terms and types *} |
|
271 |
||
272 |
ML {* |
|
273 |
fun matches_typ (ty, ty') = |
|
274 |
case (ty, ty') of |
|
275 |
(_, TVar _) => true |
|
276 |
| (TFree x, TFree x') => x = x' |
|
277 |
| (Type (s, tys), Type (s', tys')) => |
|
278 |
s = s' andalso |
|
279 |
if (length tys = length tys') |
|
280 |
then (List.all matches_typ (tys ~~ tys')) |
|
281 |
else false |
|
282 |
| _ => false |
|
283 |
*} |
|
284 |
||
285 |
ML {* |
|
286 |
fun matches_term (trm, trm') = |
|
287 |
case (trm, trm') of |
|
288 |
(_, Var _) => true |
|
289 |
| (Const (s, ty), Const (s', ty')) => s = s' andalso matches_typ (ty, ty') |
|
290 |
| (Free (x, ty), Free (x', ty')) => x = x' andalso matches_typ (ty, ty') |
|
291 |
| (Bound i, Bound j) => i = j |
|
292 |
| (Abs (_, T, t), Abs (_, T', t')) => matches_typ (T, T') andalso matches_term (t, t') |
|
293 |
| (t $ s, t' $ s') => matches_term (t, t') andalso matches_term (s, s') |
|
294 |
| _ => false |
|
295 |
*} |
|
296 |
||
297 |
section {* Regularization *} |
|
298 |
||
299 |
(* |
|
300 |
Regularizing an rtrm means: |
|
301 |
- quantifiers over a type that needs lifting are replaced by |
|
302 |
bounded quantifiers, for example: |
|
303 |
\<forall>x. P \<Longrightarrow> \<forall>x \<in> (Respects R). P / All (Respects R) P |
|
304 |
||
305 |
the relation R is given by the rty and qty; |
|
306 |
||
307 |
- abstractions over a type that needs lifting are replaced |
|
308 |
by bounded abstractions: |
|
309 |
\<lambda>x. P \<Longrightarrow> Ball (Respects R) (\<lambda>x. P) |
|
310 |
||
311 |
- equalities over the type being lifted are replaced by |
|
312 |
corresponding relations: |
|
313 |
A = B \<Longrightarrow> A \<approx> B |
|
314 |
||
315 |
example with more complicated types of A, B: |
|
316 |
A = B \<Longrightarrow> (op = \<Longrightarrow> op \<approx>) A B |
|
317 |
*) |
|
318 |
||
319 |
ML {* |
|
320 |
(* builds the relation that is the argument of respects *) |
|
321 |
fun mk_resp_arg lthy (rty, qty) = |
|
322 |
let |
|
323 |
val thy = ProofContext.theory_of lthy |
|
324 |
in |
|
325 |
if rty = qty |
|
326 |
then HOLogic.eq_const rty |
|
327 |
else |
|
328 |
case (rty, qty) of |
|
329 |
(Type (s, tys), Type (s', tys')) => |
|
330 |
if s = s' |
|
331 |
then let |
|
332 |
val SOME map_info = maps_lookup thy s |
|
333 |
val args = map (mk_resp_arg lthy) (tys ~~ tys') |
|
334 |
in |
|
335 |
list_comb (Const (#relfun map_info, dummyT), args) |
|
336 |
end |
|
337 |
else let |
|
338 |
val SOME qinfo = quotdata_lookup_thy thy s' |
|
339 |
(* FIXME: check in this case that the rty and qty *) |
|
340 |
(* FIXME: correspond to each other *) |
|
341 |
val (s, _) = dest_Const (#rel qinfo) |
|
342 |
(* FIXME: the relation should only be the string *) |
|
343 |
(* FIXME: and the type needs to be calculated as below; *) |
|
344 |
(* FIXME: maybe one should actually have a term *) |
|
345 |
(* FIXME: and one needs to force it to have this type *) |
|
346 |
in |
|
347 |
Const (s, rty --> rty --> @{typ bool}) |
|
348 |
end |
|
349 |
| _ => HOLogic.eq_const dummyT |
|
350 |
(* FIXME: check that the types correspond to each other? *) |
|
351 |
end |
|
352 |
*} |
|
353 |
||
354 |
ML {* |
|
355 |
val mk_babs = Const (@{const_name Babs}, dummyT) |
|
356 |
val mk_ball = Const (@{const_name Ball}, dummyT) |
|
357 |
val mk_bex = Const (@{const_name Bex}, dummyT) |
|
358 |
val mk_resp = Const (@{const_name Respects}, dummyT) |
|
359 |
*} |
|
360 |
||
361 |
ML {* |
|
362 |
(* - applies f to the subterm of an abstraction, *) |
|
363 |
(* otherwise to the given term, *) |
|
364 |
(* - used by regularize, therefore abstracted *) |
|
365 |
(* variables do not have to be treated specially *) |
|
366 |
||
367 |
fun apply_subt f trm1 trm2 = |
|
368 |
case (trm1, trm2) of |
|
369 |
(Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t') |
|
370 |
| _ => f trm1 trm2 |
|
371 |
||
372 |
(* the major type of All and Ex quantifiers *) |
|
373 |
fun qnt_typ ty = domain_type (domain_type ty) |
|
374 |
*} |
|
375 |
||
376 |
ML {* |
|
377 |
(* produces a regularized version of rtm *) |
|
378 |
(* - the result is still not completely typed *) |
|
379 |
(* - does not need any special treatment of *) |
|
380 |
(* bound variables *) |
|
381 |
||
382 |
fun regularize_trm lthy rtrm qtrm = |
|
383 |
case (rtrm, qtrm) of |
|
384 |
(Abs (x, ty, t), Abs (x', ty', t')) => |
|
385 |
let |
|
386 |
val subtrm = Abs(x, ty, regularize_trm lthy t t') |
|
387 |
in |
|
388 |
if ty = ty' |
|
389 |
then subtrm |
|
390 |
else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm |
|
391 |
end |
|
392 |
||
393 |
| (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') => |
|
394 |
let |
|
395 |
val subtrm = apply_subt (regularize_trm lthy) t t' |
|
396 |
in |
|
397 |
if ty = ty' |
|
398 |
then Const (@{const_name "All"}, ty) $ subtrm |
|
399 |
else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
|
400 |
end |
|
401 |
||
402 |
| (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') => |
|
403 |
let |
|
404 |
val subtrm = apply_subt (regularize_trm lthy) t t' |
|
405 |
in |
|
406 |
if ty = ty' |
|
407 |
then Const (@{const_name "Ex"}, ty) $ subtrm |
|
408 |
else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
|
409 |
end |
|
410 |
||
411 |
| (* equalities need to be replaced by appropriate equivalence relations *) |
|
412 |
(Const (@{const_name "op ="}, ty), Const (@{const_name "op ="}, ty')) => |
|
413 |
if ty = ty' |
|
414 |
then rtrm |
|
415 |
else mk_resp_arg lthy (domain_type ty, domain_type ty') |
|
416 |
||
417 |
| (* in this case we check whether the given equivalence relation is correct *) |
|
418 |
(rel, Const (@{const_name "op ="}, ty')) => |
|
419 |
let |
|
420 |
val exc = LIFT_MATCH "regularise (relation mismatch)" |
|
421 |
val rel_ty = (fastype_of rel) handle TERM _ => raise exc |
|
422 |
val rel' = mk_resp_arg lthy (domain_type rel_ty, domain_type ty') |
|
423 |
in |
|
424 |
if rel' = rel |
|
425 |
then rtrm |
|
426 |
else raise exc |
|
427 |
end |
|
428 |
| (_, Const (s, _)) => |
|
429 |
let |
|
430 |
fun same_name (Const (s, _)) (Const (s', _)) = (s = s') |
|
431 |
| same_name _ _ = false |
|
432 |
in |
|
433 |
if same_name rtrm qtrm |
|
434 |
then rtrm |
|
435 |
else |
|
436 |
let |
|
437 |
fun exc1 s = LIFT_MATCH ("regularize (constant " ^ s ^ " not found)") |
|
438 |
val exc2 = LIFT_MATCH ("regularize (constant mismatch)") |
|
439 |
val thy = ProofContext.theory_of lthy |
|
440 |
val rtrm' = (#rconst (qconsts_lookup thy s)) handle NotFound => raise (exc1 s) |
|
441 |
in |
|
442 |
if matches_term (rtrm, rtrm') |
|
443 |
then rtrm |
|
444 |
else raise exc2 |
|
445 |
end |
|
446 |
end |
|
447 |
||
448 |
| (t1 $ t2, t1' $ t2') => |
|
449 |
(regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2') |
|
450 |
||
451 |
| (Free (x, ty), Free (x', ty')) => |
|
452 |
(* this case cannot arrise as we start with two fully atomized terms *) |
|
453 |
raise (LIFT_MATCH "regularize (frees)") |
|
454 |
||
455 |
| (Bound i, Bound i') => |
|
456 |
if i = i' |
|
457 |
then rtrm |
|
458 |
else raise (LIFT_MATCH "regularize (bounds mismatch)") |
|
459 |
||
460 |
| (rt, qt) => |
|
461 |
raise (LIFT_MATCH "regularize (default)") |
|
462 |
*} |
|
463 |
||
464 |
ML {* |
|
465 |
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
|
466 |
(K (print_tac "equiv tac")) THEN' |
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
parents:
602
diff
changeset
|
467 |
REPEAT_ALL_NEW (resolve_tac (equiv_rules_get ctxt)) |
597 | 468 |
*} |
469 |
||
470 |
ML {* |
|
471 |
fun equiv_solver_tac ss = equiv_tac (Simplifier.the_context ss) |
|
472 |
val equiv_solver = Simplifier.mk_solver' "Equivalence goal solver" equiv_solver_tac |
|
473 |
*} |
|
474 |
||
475 |
ML {* |
|
476 |
fun prep_trm thy (x, (T, t)) = |
|
477 |
(cterm_of thy (Var (x, T)), cterm_of thy t) |
|
478 |
||
479 |
fun prep_ty thy (x, (S, ty)) = |
|
480 |
(ctyp_of thy (TVar (x, S)), ctyp_of thy ty) |
|
481 |
*} |
|
482 |
||
483 |
ML {* |
|
484 |
fun matching_prs thy pat trm = |
|
485 |
let |
|
486 |
val univ = Unify.matchers thy [(pat, trm)] |
|
487 |
val SOME (env, _) = Seq.pull univ |
|
488 |
val tenv = Vartab.dest (Envir.term_env env) |
|
489 |
val tyenv = Vartab.dest (Envir.type_env env) |
|
490 |
in |
|
491 |
(map (prep_ty thy) tyenv, map (prep_trm thy) tenv) |
|
492 |
end |
|
493 |
*} |
|
494 |
||
495 |
ML {* |
|
496 |
fun calculate_instance ctxt thm redex R1 R2 = |
|
497 |
let |
|
498 |
val thy = ProofContext.theory_of ctxt |
|
499 |
val goal = Const (@{const_name "equivp"}, dummyT) $ R2 |
|
500 |
|> Syntax.check_term ctxt |
|
501 |
|> HOLogic.mk_Trueprop |
|
502 |
val eqv_prem = Goal.prove ctxt [] [] goal (fn {context,...} => equiv_tac context 1) |
|
503 |
val thm = (@{thm eq_reflection} OF [thm OF [eqv_prem]]) |
|
504 |
val R1c = cterm_of thy R1 |
|
505 |
val thmi = Drule.instantiate' [] [SOME R1c] thm |
|
506 |
val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) redex |
|
507 |
val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi) |
|
508 |
in |
|
509 |
SOME thm2 |
|
510 |
end |
|
511 |
handle _ => NONE |
|
512 |
(* FIXME/TODO: what is the place where the exception can be raised: matching_prs? *) |
|
513 |
*} |
|
514 |
||
515 |
ML {* |
|
516 |
fun ball_bex_range_simproc ss redex = |
|
517 |
let |
|
518 |
val ctxt = Simplifier.the_context ss |
|
519 |
in |
|
520 |
case redex of |
|
521 |
(Const (@{const_name "Ball"}, _) $ (Const (@{const_name "Respects"}, _) $ |
|
522 |
(Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) => |
|
523 |
calculate_instance ctxt @{thm ball_reg_eqv_range} redex R1 R2 |
|
524 |
| (Const (@{const_name "Bex"}, _) $ (Const (@{const_name "Respects"}, _) $ |
|
525 |
(Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) => |
|
526 |
calculate_instance ctxt @{thm bex_reg_eqv_range} redex R1 R2 |
|
527 |
| _ => NONE |
|
528 |
end |
|
529 |
*} |
|
530 |
||
531 |
lemma eq_imp_rel: |
|
532 |
shows "equivp R \<Longrightarrow> a = b \<longrightarrow> R a b" |
|
533 |
by (simp add: equivp_reflp) |
|
534 |
||
535 |
(* FIXME/TODO: How does regularizing work? *) |
|
536 |
(* FIXME/TODO: needs to be adapted |
|
537 |
||
538 |
To prove that the raw theorem implies the regularised one, |
|
539 |
we try in order: |
|
540 |
||
541 |
- Reflexivity of the relation |
|
542 |
- Assumption |
|
543 |
- Elimnating quantifiers on both sides of toplevel implication |
|
544 |
- Simplifying implications on both sides of toplevel implication |
|
545 |
- Ball (Respects ?E) ?P = All ?P |
|
546 |
- (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q |
|
547 |
||
548 |
*) |
|
549 |
ML {* |
|
550 |
fun regularize_tac ctxt = |
|
551 |
let |
|
552 |
val thy = ProofContext.theory_of ctxt |
|
553 |
val pat_ball = @{term "Ball (Respects (R1 ===> R2)) P"} |
|
554 |
val pat_bex = @{term "Bex (Respects (R1 ===> R2)) P"} |
|
555 |
val simproc = Simplifier.simproc_i thy "" [pat_ball, pat_bex] (K (ball_bex_range_simproc)) |
|
556 |
val simpset = (mk_minimal_ss 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
|
557 |
addsimps @{thms ball_reg_eqv bex_reg_eqv babs_reg_eqv} |
597 | 558 |
addsimprocs [simproc] addSolver equiv_solver |
559 |
(* 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
|
560 |
(* can this cause loops in equiv_tac ? *) |
597 | 561 |
val eq_eqvs = map (fn x => @{thm eq_imp_rel} OF [x]) (equiv_rules_get ctxt) |
562 |
in |
|
563 |
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
|
564 |
REPEAT_ALL_NEW (CHANGED o FIRST' [ |
597 | 565 |
rtac @{thm ball_reg_right}, |
566 |
rtac @{thm bex_reg_left}, |
|
567 |
resolve_tac (Inductive.get_monos ctxt), |
|
568 |
rtac @{thm ball_all_comm}, |
|
569 |
rtac @{thm 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
|
570 |
resolve_tac eq_eqvs, |
606
38aa6b67a80b
clarified the function examples
Christian Urban <urbanc@in.tum.de>
parents:
605
diff
changeset
|
571 |
(* should be equivalent to the above, but causes loops: *) |
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
|
572 |
(* rtac @{thm eq_imp_rel} THEN' SOLVES' (equiv_tac ctxt), *) |
606
38aa6b67a80b
clarified the function examples
Christian Urban <urbanc@in.tum.de>
parents:
605
diff
changeset
|
573 |
(* the culprit is aslread rtac @{thm eq_imp_rel} *) |
597 | 574 |
simp_tac simpset]) |
575 |
end |
|
576 |
*} |
|
577 |
||
578 |
section {* Injections of rep and abses *} |
|
579 |
||
580 |
(* |
|
581 |
Injecting repabs means: |
|
582 |
||
583 |
For abstractions: |
|
584 |
* If the type of the abstraction doesn't need lifting we recurse. |
|
585 |
* If it does we add RepAbs around the whole term and check if the |
|
586 |
variable needs lifting. |
|
587 |
* If it doesn't then we recurse |
|
588 |
* If it does we recurse and put 'RepAbs' around all occurences |
|
589 |
of the variable in the obtained subterm. This in combination |
|
590 |
with the RepAbs above will let us change the type of the |
|
591 |
abstraction with rewriting. |
|
592 |
For applications: |
|
593 |
* If the term is 'Respects' applied to anything we leave it unchanged |
|
594 |
* If the term needs lifting and the head is a constant that we know |
|
595 |
how to lift, we put a RepAbs and recurse |
|
596 |
* If the term needs lifting and the head is a free applied to subterms |
|
597 |
(if it is not applied we treated it in Abs branch) then we |
|
598 |
put RepAbs and recurse |
|
599 |
* Otherwise just recurse. |
|
600 |
*) |
|
601 |
||
602 |
ML {* |
|
603 |
fun mk_repabs lthy (T, T') trm = |
|
604 |
Quotient_Def.get_fun repF lthy (T, T') |
|
605 |
$ (Quotient_Def.get_fun absF lthy (T, T') $ trm) |
|
606 |
*} |
|
607 |
||
608 |
ML {* |
|
609 |
(* bound variables need to be treated properly, *) |
|
610 |
(* as the type of subterms need to be calculated *) |
|
611 |
(* in the abstraction case *) |
|
612 |
||
613 |
fun inj_repabs_trm lthy (rtrm, qtrm) = |
|
614 |
case (rtrm, qtrm) of |
|
615 |
(Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') => |
|
616 |
Const (@{const_name "Ball"}, T) $ r $ (inj_repabs_trm lthy (t, t')) |
|
617 |
||
618 |
| (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') => |
|
619 |
Const (@{const_name "Bex"}, T) $ r $ (inj_repabs_trm lthy (t, t')) |
|
620 |
||
621 |
| (Const (@{const_name "Babs"}, T) $ r $ t, t' as (Abs _)) => |
|
622 |
Const (@{const_name "Babs"}, T) $ r $ (inj_repabs_trm lthy (t, t')) |
|
623 |
||
624 |
| (Abs (x, T, t), Abs (x', T', t')) => |
|
625 |
let |
|
626 |
val rty = fastype_of rtrm |
|
627 |
val qty = fastype_of qtrm |
|
628 |
val (y, s) = Term.dest_abs (x, T, t) |
|
629 |
val (_, s') = Term.dest_abs (x', T', t') |
|
630 |
val yvar = Free (y, T) |
|
631 |
val result = Term.lambda_name (y, yvar) (inj_repabs_trm lthy (s, s')) |
|
632 |
in |
|
633 |
if rty = qty |
|
634 |
then result |
|
635 |
else mk_repabs lthy (rty, qty) result |
|
636 |
end |
|
637 |
||
638 |
| (t $ s, t' $ s') => |
|
639 |
(inj_repabs_trm lthy (t, t')) $ (inj_repabs_trm lthy (s, s')) |
|
640 |
||
641 |
| (Free (_, T), Free (_, T')) => |
|
642 |
if T = T' |
|
643 |
then rtrm |
|
644 |
else mk_repabs lthy (T, T') rtrm |
|
645 |
||
646 |
| (_, Const (@{const_name "op ="}, _)) => rtrm |
|
647 |
||
648 |
(* FIXME: check here that rtrm is the corresponding definition for the const *) |
|
649 |
| (_, Const (_, T')) => |
|
650 |
let |
|
651 |
val rty = fastype_of rtrm |
|
652 |
in |
|
653 |
if rty = T' |
|
654 |
then rtrm |
|
655 |
else mk_repabs lthy (rty, T') rtrm |
|
656 |
end |
|
657 |
||
658 |
| _ => raise (LIFT_MATCH "injection") |
|
659 |
*} |
|
660 |
||
661 |
section {* RepAbs Injection Tactic *} |
|
662 |
||
663 |
ML {* |
|
664 |
fun quotient_tac ctxt = |
|
665 |
REPEAT_ALL_NEW (FIRST' |
|
666 |
[rtac @{thm identity_quotient}, |
|
667 |
resolve_tac (quotient_rules_get ctxt)]) |
|
668 |
*} |
|
669 |
||
670 |
(* solver for the simplifier *) |
|
671 |
ML {* |
|
672 |
fun quotient_solver_tac ss = quotient_tac (Simplifier.the_context ss) |
|
673 |
val quotient_solver = Simplifier.mk_solver' "Quotient goal solver" quotient_solver_tac |
|
674 |
*} |
|
675 |
||
676 |
ML {* |
|
677 |
fun solve_quotient_assums ctxt thm = |
|
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
|
678 |
let |
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
|
679 |
val goal = hd (Drule.strip_imp_prems (cprop_of thm)) |
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
|
680 |
in |
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
|
681 |
thm OF [Goal.prove_internal [] goal (fn _ => quotient_tac ctxt 1)] |
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
|
682 |
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
|
683 |
handle _ => error "solve_quotient_assums failed. Maybe a quotient_thm is missing" |
597 | 684 |
*} |
685 |
||
686 |
(* Not used *) |
|
687 |
(* It proves the Quotient assumptions by calling quotient_tac *) |
|
688 |
ML {* |
|
689 |
fun solve_quotient_assum i ctxt thm = |
|
690 |
let |
|
691 |
val tac = |
|
692 |
(compose_tac (false, thm, i)) THEN_ALL_NEW |
|
693 |
(quotient_tac ctxt); |
|
694 |
val gc = Drule.strip_imp_concl (cprop_of thm); |
|
695 |
in |
|
696 |
Goal.prove_internal [] gc (fn _ => tac 1) |
|
697 |
end |
|
698 |
handle _ => error "solve_quotient_assum" |
|
699 |
*} |
|
700 |
||
701 |
definition |
|
702 |
"QUOT_TRUE x \<equiv> True" |
|
703 |
||
704 |
ML {* |
|
705 |
fun find_qt_asm asms = |
|
706 |
let |
|
707 |
fun find_fun trm = |
|
708 |
case trm of |
|
709 |
(Const(@{const_name Trueprop}, _) $ (Const (@{const_name QUOT_TRUE}, _) $ _)) => true |
|
710 |
| _ => false |
|
711 |
in |
|
712 |
case find_first find_fun asms of |
|
713 |
SOME (_ $ (_ $ (f $ a))) => (f, a) |
|
714 |
| SOME _ => error "find_qt_asm: no pair" |
|
715 |
| NONE => error "find_qt_asm: no assumption" |
|
716 |
end |
|
717 |
*} |
|
718 |
||
719 |
(* |
|
720 |
To prove that the regularised theorem implies the abs/rep injected, |
|
721 |
we try: |
|
722 |
||
723 |
1) theorems 'trans2' from the appropriate QUOT_TYPE |
|
724 |
2) remove lambdas from both sides: lambda_rsp_tac |
|
725 |
3) remove Ball/Bex from the right hand side |
|
726 |
4) use user-supplied RSP theorems |
|
727 |
5) remove rep_abs from the right side |
|
728 |
6) reflexivity of equality |
|
729 |
7) split applications of lifted type (apply_rsp) |
|
730 |
8) split applications of non-lifted type (cong_tac) |
|
731 |
9) apply extentionality |
|
732 |
A) reflexivity of the relation |
|
733 |
B) assumption |
|
734 |
(Lambdas under respects may have left us some assumptions) |
|
735 |
C) proving obvious higher order equalities by simplifying fun_rel |
|
736 |
(not sure if it is still needed?) |
|
737 |
D) unfolding lambda on one side |
|
738 |
E) simplifying (= ===> =) for simpler respectfulness |
|
739 |
||
740 |
*) |
|
741 |
||
742 |
lemma quot_true_dests: |
|
743 |
shows QT_all: "QUOT_TRUE (All P) \<Longrightarrow> QUOT_TRUE P" |
|
744 |
and QT_ex: "QUOT_TRUE (Ex P) \<Longrightarrow> QUOT_TRUE P" |
|
745 |
and QT_lam: "QUOT_TRUE (\<lambda>x. P x) \<Longrightarrow> (\<And>x. QUOT_TRUE (P x))" |
|
746 |
and QT_ext: "(\<And>x. QUOT_TRUE (a x) \<Longrightarrow> f x = g x) \<Longrightarrow> (QUOT_TRUE a \<Longrightarrow> f = g)" |
|
747 |
apply(simp_all add: QUOT_TRUE_def ext) |
|
748 |
done |
|
749 |
||
750 |
lemma QUOT_TRUE_i: "(QUOT_TRUE (a :: bool) \<Longrightarrow> P) \<Longrightarrow> P" |
|
751 |
by (simp add: QUOT_TRUE_def) |
|
752 |
||
753 |
lemma QUOT_TRUE_imp: "QUOT_TRUE a \<equiv> QUOT_TRUE b" |
|
754 |
by (simp add: QUOT_TRUE_def) |
|
755 |
||
756 |
ML {* |
|
757 |
fun quot_true_conv1 ctxt fnctn ctrm = |
|
758 |
case (term_of ctrm) of |
|
759 |
(Const (@{const_name QUOT_TRUE}, _) $ x) => |
|
760 |
let |
|
761 |
val fx = fnctn x; |
|
762 |
val thy = ProofContext.theory_of ctxt; |
|
763 |
val cx = cterm_of thy x; |
|
764 |
val cfx = cterm_of thy fx; |
|
765 |
val cxt = ctyp_of thy (fastype_of x); |
|
766 |
val cfxt = ctyp_of thy (fastype_of fx); |
|
767 |
val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QUOT_TRUE_imp} |
|
768 |
in |
|
769 |
Conv.rewr_conv thm ctrm |
|
770 |
end |
|
771 |
*} |
|
772 |
||
773 |
ML {* |
|
774 |
fun quot_true_conv ctxt fnctn ctrm = |
|
775 |
case (term_of ctrm) of |
|
776 |
(Const (@{const_name QUOT_TRUE}, _) $ _) => |
|
777 |
quot_true_conv1 ctxt fnctn ctrm |
|
778 |
| _ $ _ => Conv.comb_conv (quot_true_conv ctxt fnctn) ctrm |
|
779 |
| Abs _ => Conv.abs_conv (fn (_, ctxt) => quot_true_conv ctxt fnctn) ctxt ctrm |
|
780 |
| _ => Conv.all_conv ctrm |
|
781 |
*} |
|
782 |
||
783 |
ML {* |
|
784 |
fun quot_true_tac ctxt fnctn = CONVERSION |
|
785 |
((Conv.params_conv ~1 (fn ctxt => |
|
786 |
(Conv.prems_conv ~1 (quot_true_conv ctxt fnctn)))) ctxt) |
|
787 |
*} |
|
788 |
||
789 |
ML {* fun dest_comb (f $ a) = (f, a) *} |
|
790 |
ML {* fun dest_bcomb ((_ $ l) $ r) = (l, r) *} |
|
791 |
(* TODO: Can this be done easier? *) |
|
792 |
ML {* |
|
793 |
fun unlam t = |
|
794 |
case t of |
|
795 |
(Abs a) => snd (Term.dest_abs a) |
|
796 |
| _ => unlam (Abs("", domain_type (fastype_of t), (incr_boundvars 1 t) $ (Bound 0))) |
|
797 |
*} |
|
798 |
||
799 |
ML {* |
|
800 |
fun dest_fun_type (Type("fun", [T, S])) = (T, S) |
|
801 |
| dest_fun_type _ = error "dest_fun_type" |
|
802 |
*} |
|
803 |
||
804 |
ML {* |
|
805 |
val bare_concl = HOLogic.dest_Trueprop o Logic.strip_assums_concl |
|
806 |
*} |
|
807 |
||
808 |
ML {* |
|
809 |
val apply_rsp_tac = |
|
810 |
Subgoal.FOCUS (fn {concl, asms, context,...} => |
|
811 |
case ((HOLogic.dest_Trueprop (term_of concl))) of |
|
812 |
((R2 $ (f $ x) $ (g $ y))) => |
|
813 |
(let |
|
814 |
val (asmf, asma) = find_qt_asm (map term_of asms); |
|
815 |
in |
|
816 |
if (fastype_of asmf) = (fastype_of f) then no_tac else let |
|
817 |
val ty_a = fastype_of x; |
|
818 |
val ty_b = fastype_of asma; |
|
819 |
val ty_c = range_type (type_of f); |
|
820 |
val thy = ProofContext.theory_of context; |
|
821 |
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c]; |
|
822 |
val thm = Drule.instantiate' ty_inst [] @{thm apply_rsp} |
|
823 |
val te = solve_quotient_assums context thm |
|
824 |
val t_inst = map (SOME o (cterm_of thy)) [R2, f, g, x, y]; |
|
825 |
val thm = Drule.instantiate' [] t_inst te |
|
826 |
in |
|
827 |
compose_tac (false, thm, 2) 1 |
|
828 |
end |
|
829 |
end |
|
830 |
handle ERROR "find_qt_asm: no pair" => no_tac) |
|
831 |
| _ => no_tac) |
|
832 |
*} |
|
833 |
||
834 |
ML {* |
|
835 |
fun rep_abs_rsp_tac ctxt = |
|
836 |
SUBGOAL (fn (goal, i) => |
|
837 |
case (bare_concl goal) of |
|
838 |
(rel $ _ $ (rep $ (abs $ _))) => |
|
839 |
(let |
|
840 |
val thy = ProofContext.theory_of ctxt; |
|
841 |
val (ty_a, ty_b) = dest_fun_type (fastype_of abs); |
|
842 |
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b]; |
|
843 |
val t_inst = map (SOME o (cterm_of thy)) [rel, abs, rep]; |
|
844 |
val thm = Drule.instantiate' ty_inst t_inst @{thm rep_abs_rsp} |
|
845 |
val te = solve_quotient_assums ctxt thm |
|
846 |
in |
|
847 |
rtac te i |
|
848 |
end |
|
849 |
handle _ => no_tac) |
|
850 |
| _ => no_tac) |
|
851 |
*} |
|
852 |
||
853 |
ML {* |
|
854 |
fun inj_repabs_tac_match ctxt trans2 = SUBGOAL (fn (goal, i) => |
|
855 |
(case (bare_concl goal) of |
|
856 |
(* (R1 ===> R2) (\<lambda>x\<dots>) (\<lambda>y\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *) |
|
857 |
((Const (@{const_name fun_rel}, _) $ _ $ _) $ (Abs _) $ (Abs _)) |
|
858 |
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam |
|
859 |
||
860 |
(* (op =) (Ball\<dots>) (Ball\<dots>) ----> (op =) (\<dots>) (\<dots>) *) |
|
861 |
| (Const (@{const_name "op ="},_) $ |
|
862 |
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
863 |
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _)) |
|
864 |
=> rtac @{thm ball_rsp} THEN' dtac @{thm QT_all} |
|
865 |
||
866 |
(* (R1 ===> op =) (Ball\<dots>) (Ball\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Ball\<dots>x) = (Ball\<dots>y) *) |
|
867 |
| (Const (@{const_name fun_rel}, _) $ _ $ _) $ |
|
868 |
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
869 |
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) |
|
870 |
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam |
|
871 |
||
872 |
(* (op =) (Bex\<dots>) (Bex\<dots>) ----> (op =) (\<dots>) (\<dots>) *) |
|
873 |
| Const (@{const_name "op ="},_) $ |
|
874 |
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
875 |
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) |
|
876 |
=> rtac @{thm bex_rsp} THEN' dtac @{thm QT_ex} |
|
877 |
||
878 |
(* (R1 ===> op =) (Bex\<dots>) (Bex\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Bex\<dots>x) = (Bex\<dots>y) *) |
|
879 |
| (Const (@{const_name fun_rel}, _) $ _ $ _) $ |
|
880 |
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
881 |
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) |
|
882 |
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam |
|
883 |
||
884 |
| (_ $ |
|
885 |
(Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $ |
|
886 |
(Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _)) |
|
887 |
=> rtac @{thm babs_rsp} THEN' RANGE [quotient_tac ctxt] |
|
888 |
||
889 |
(* reflexivity of operators arising from Cong_tac *) |
|
890 |
| Const (@{const_name "op ="},_) $ _ $ _ |
|
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
|
891 |
=> rtac @{thm refl} (*ORELSE' |
597 | 892 |
(resolve_tac trans2 THEN' RANGE [ |
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
|
893 |
quot_true_tac ctxt (fst o dest_bcomb), quot_true_tac ctxt (snd o dest_bcomb)])*) |
597 | 894 |
|
895 |
(* TODO: These patterns should should be somehow combined and generalized... *) |
|
896 |
| (Const (@{const_name fun_rel}, _) $ _ $ _) $ |
|
897 |
(Const (@{const_name fun_rel}, _) $ _ $ _) $ |
|
898 |
(Const (@{const_name fun_rel}, _) $ _ $ _) |
|
899 |
=> rtac @{thm quot_rel_rsp} THEN_ALL_NEW quotient_tac ctxt |
|
900 |
||
901 |
| (Const (@{const_name fun_rel}, _) $ _ $ _) $ |
|
902 |
(Const (@{const_name prod_rel}, _) $ _ $ _) $ |
|
903 |
(Const (@{const_name prod_rel}, _) $ _ $ _) |
|
904 |
=> rtac @{thm quot_rel_rsp} THEN_ALL_NEW quotient_tac ctxt |
|
905 |
||
906 |
(* respectfulness of constants; in particular of a simple relation *) |
|
907 |
| _ $ (Const _) $ (Const _) (* fun_rel, list_rel, etc but not equality *) |
|
908 |
=> resolve_tac (rsp_rules_get ctxt) THEN_ALL_NEW quotient_tac ctxt |
|
909 |
||
910 |
(* R (\<dots>) (Rep (Abs \<dots>)) ----> R (\<dots>) (\<dots>) *) |
|
911 |
(* observe ---> *) |
|
912 |
| _ $ _ $ _ |
|
913 |
=> rep_abs_rsp_tac ctxt |
|
914 |
||
915 |
| _ => error "inj_repabs_tac not a relation" |
|
916 |
) i) |
|
917 |
*} |
|
918 |
||
919 |
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
|
920 |
fun inj_repabs_step_tac ctxt rel_refl trans2 = |
597 | 921 |
(FIRST' [ |
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
|
922 |
NDT ctxt "0" (inj_repabs_tac_match ctxt trans2), |
597 | 923 |
(* 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
|
924 |
|
597 | 925 |
NDT ctxt "A" (apply_rsp_tac ctxt THEN' |
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
|
926 |
RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)]), |
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
|
927 |
|
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
|
928 |
(* TODO/FIXME: I had to move this after the apply_rsp_tac - is this right *) |
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
|
929 |
NDT ctxt "B" (resolve_tac trans2 THEN' |
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
|
930 |
RANGE [quot_true_tac ctxt (fst o dest_bcomb), quot_true_tac ctxt (snd o dest_bcomb)]), |
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
|
931 |
|
597 | 932 |
(* (op =) (t $ \<dots>) (t' $ \<dots>) ----> Cong provided type of t does not need lifting *) |
933 |
(* merge with previous tactic *) |
|
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
|
934 |
NDT ctxt "C" (Cong_Tac.cong_tac @{thm cong} THEN' |
597 | 935 |
(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
|
936 |
|
597 | 937 |
(* (op =) (\<lambda>x\<dots>) (\<lambda>x\<dots>) ----> (op =) (\<dots>) (\<dots>) *) |
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
|
938 |
NDT ctxt "D" (rtac @{thm ext} THEN' quot_true_tac ctxt unlam), |
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
|
939 |
|
597 | 940 |
(* resolving with R x y assumptions *) |
941 |
NDT ctxt "E" (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
|
942 |
|
597 | 943 |
(* reflexivity of the basic relations *) |
944 |
(* R \<dots> \<dots> *) |
|
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
|
945 |
NDT ctxt "F" (resolve_tac rel_refl) |
597 | 946 |
]) |
947 |
*} |
|
948 |
||
949 |
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
|
950 |
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
|
951 |
let |
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
|
952 |
val rel_refl = map (fn x => @{thm equivp_reflp} OF [x]) (equiv_rules_get 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
|
953 |
val trans2 = map (fn x => @{thm equals_rsp} OF [x]) (quotient_rules_get 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
|
954 |
in |
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
|
955 |
inj_repabs_step_tac ctxt rel_refl trans2 |
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
|
956 |
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
|
957 |
*} |
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
|
958 |
|
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
|
959 |
ML {* |
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
|
960 |
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
|
961 |
REPEAT_ALL_NEW (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
|
962 |
(* if this is too slow we can inline the code above *) |
597 | 963 |
*} |
964 |
||
965 |
section {* Cleaning of the theorem *} |
|
966 |
||
967 |
ML {* |
|
968 |
fun make_inst lhs t = |
|
969 |
let |
|
970 |
val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs; |
|
971 |
val _ $ (Abs (_, _, g)) = t; |
|
972 |
fun mk_abs i t = |
|
973 |
if incr_boundvars i u aconv t then Bound i |
|
974 |
else (case t of |
|
975 |
t1 $ t2 => mk_abs i t1 $ mk_abs i t2 |
|
976 |
| Abs (s, T, t') => Abs (s, T, mk_abs (i + 1) t') |
|
977 |
| Bound j => if i = j then error "make_inst" else t |
|
978 |
| _ => t); |
|
979 |
in (f, Abs ("x", T, mk_abs 0 g)) end; |
|
980 |
*} |
|
981 |
||
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
982 |
(* Since the patterns for the lhs are different; there are 2 different make-insts *) |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
983 |
ML {* |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
984 |
fun make_inst2 lhs t = |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
985 |
let |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
986 |
val _ $ (Abs (_, _, (_ $ ((f as Var (_, Type ("fun", [T, _]))) $ u)))) = lhs; |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
987 |
val _ = tracing "a"; |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
988 |
val _ $ (Abs (_, _, (_ $ g))) = t; |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
989 |
fun mk_abs i t = |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
990 |
if incr_boundvars i u aconv t then Bound i |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
991 |
else (case t of |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
992 |
t1 $ t2 => mk_abs i t1 $ mk_abs i t2 |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
993 |
| Abs (s, T, t') => Abs (s, T, mk_abs (i + 1) t') |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
994 |
| Bound j => if i = j then error "make_inst" else t |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
995 |
| _ => t); |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
996 |
in (f, Abs ("x", T, mk_abs 0 g)) end; |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
997 |
*} |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
998 |
|
597 | 999 |
ML {* |
1000 |
fun lambda_prs_simple_conv ctxt ctrm = |
|
1001 |
case (term_of ctrm) of |
|
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
1002 |
((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
|
1003 |
(let |
597 | 1004 |
val thy = ProofContext.theory_of ctxt |
1005 |
val (ty_b, ty_a) = dest_fun_type (fastype_of r1) |
|
1006 |
val (ty_c, ty_d) = dest_fun_type (fastype_of a2) |
|
1007 |
val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d] |
|
1008 |
val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)] |
|
1009 |
val lpi = Drule.instantiate' tyinst tinst @{thm lambda_prs} |
|
1010 |
val te = @{thm eq_reflection} OF [solve_quotient_assums ctxt (solve_quotient_assums ctxt lpi)] |
|
1011 |
val _ = 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
|
1012 |
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
|
1013 |
(let |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
1014 |
val ts = MetaSimplifier.rewrite_rule @{thms id_simps} te |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
1015 |
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
|
1016 |
in |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
1017 |
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
|
1018 |
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
|
1019 |
let |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
1020 |
val (insp, inst) = make_inst2 (term_of (Thm.lhs_of te)) (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
|
1021 |
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
|
1022 |
in |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
1023 |
MetaSimplifier.rewrite_rule @{thms id_simps} td |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
1024 |
end); |
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
600
diff
changeset
|
1025 |
val _ = if not (Term.is_Const a2 andalso fst (dest_Const a2) = @{const_name "id"}) then |
597 | 1026 |
(tracing "lambda_prs"; |
1027 |
tracing ("redex:\n" ^ (Syntax.string_of_term ctxt (term_of ctrm))); |
|
1028 |
tracing ("lpi rule:\n" ^ (Syntax.string_of_term ctxt (prop_of lpi))); |
|
1029 |
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
|
1030 |
tracing ("ti rule:\n" ^ (Syntax.string_of_term ctxt (prop_of ti)))) |
597 | 1031 |
else () |
1032 |
in |
|
1033 |
Conv.rewr_conv ti ctrm |
|
1034 |
end |
|
608
678315da994e
Handling of errors in lambda_prs_conv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
606
diff
changeset
|
1035 |
handle _ => Conv.all_conv ctrm) |
597 | 1036 |
| _ => Conv.all_conv ctrm |
1037 |
*} |
|
1038 |
||
1039 |
ML {* |
|
1040 |
val lambda_prs_conv = |
|
1041 |
More_Conv.top_conv lambda_prs_simple_conv |
|
1042 |
||
1043 |
fun lambda_prs_tac ctxt = CONVERSION (lambda_prs_conv ctxt) |
|
1044 |
*} |
|
1045 |
||
1046 |
(* |
|
1047 |
Cleaning the theorem consists of three rewriting steps. |
|
1048 |
The first two need to be done before fun_map is unfolded |
|
1049 |
||
1050 |
1) lambda_prs: |
|
1051 |
(Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) ----> f |
|
1052 |
||
1053 |
Implemented as conversion since it is not a pattern. |
|
1054 |
||
1055 |
2) all_prs (the same for exists): |
|
1056 |
Ball (Respects R) ((abs ---> id) f) ----> All f |
|
1057 |
||
1058 |
Rewriting with definitions from the argument defs |
|
1059 |
(rep ---> abs) oldConst ----> newconst |
|
1060 |
||
1061 |
3) Quotient_rel_rep: |
|
1062 |
Rel (Rep x) (Rep y) ----> x = y |
|
1063 |
||
1064 |
Quotient_abs_rep: |
|
1065 |
Abs (Rep x) ----> x |
|
1066 |
||
1067 |
id_simps; fun_map.simps |
|
1068 |
*) |
|
1069 |
||
1070 |
ML {* |
|
1071 |
fun clean_tac lthy = |
|
1072 |
let |
|
1073 |
val thy = ProofContext.theory_of lthy; |
|
1074 |
val defs = map (Thm.varifyT o symmetric o #def) (qconsts_dest thy) |
|
1075 |
(* FIXME: shouldn't the definitions already be varified? *) |
|
1076 |
val thms1 = @{thms all_prs ex_prs} @ defs |
|
1077 |
val thms2 = @{thms eq_reflection[OF fun_map.simps]} |
|
1078 |
@ @{thms id_simps Quotient_abs_rep Quotient_rel_rep} |
|
1079 |
fun simps thms = (mk_minimal_ss lthy) addsimps thms addSolver quotient_solver |
|
1080 |
in |
|
1081 |
EVERY' [lambda_prs_tac lthy, |
|
1082 |
simp_tac (simps thms1), |
|
1083 |
simp_tac (simps thms2), |
|
1084 |
TRY o rtac refl] |
|
1085 |
end |
|
1086 |
*} |
|
1087 |
||
1088 |
section {* Genralisation of free variables in a goal *} |
|
1089 |
||
1090 |
ML {* |
|
1091 |
fun inst_spec ctrm = |
|
1092 |
Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec} |
|
1093 |
||
1094 |
fun inst_spec_tac ctrms = |
|
1095 |
EVERY' (map (dtac o inst_spec) ctrms) |
|
1096 |
||
1097 |
fun all_list xs trm = |
|
1098 |
fold (fn (x, T) => fn t' => HOLogic.mk_all (x, T, t')) xs trm |
|
1099 |
||
1100 |
fun apply_under_Trueprop f = |
|
1101 |
HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop |
|
1102 |
||
1103 |
fun gen_frees_tac ctxt = |
|
1104 |
SUBGOAL (fn (concl, i) => |
|
1105 |
let |
|
1106 |
val thy = ProofContext.theory_of ctxt |
|
1107 |
val vrs = Term.add_frees concl [] |
|
1108 |
val cvrs = map (cterm_of thy o Free) vrs |
|
1109 |
val concl' = apply_under_Trueprop (all_list vrs) concl |
|
1110 |
val goal = Logic.mk_implies (concl', concl) |
|
1111 |
val rule = Goal.prove ctxt [] [] goal |
|
1112 |
(K (EVERY1 [inst_spec_tac (rev cvrs), atac])) |
|
1113 |
in |
|
1114 |
rtac rule i |
|
1115 |
end) |
|
1116 |
*} |
|
1117 |
||
1118 |
section {* General outline of the lifting procedure *} |
|
1119 |
||
1120 |
(* - A is the original raw theorem *) |
|
1121 |
(* - B is the regularized theorem *) |
|
1122 |
(* - C is the rep/abs injected version of B *) |
|
1123 |
(* - D is the lifted theorem *) |
|
1124 |
(* *) |
|
1125 |
(* - b is the regularization step *) |
|
1126 |
(* - c is the rep/abs injection step *) |
|
1127 |
(* - d is the cleaning part *) |
|
1128 |
||
1129 |
lemma lifting_procedure: |
|
1130 |
assumes a: "A" |
|
606
38aa6b67a80b
clarified the function examples
Christian Urban <urbanc@in.tum.de>
parents:
605
diff
changeset
|
1131 |
and b: "A \<longrightarrow> B" |
597 | 1132 |
and c: "B = C" |
1133 |
and d: "C = D" |
|
1134 |
shows "D" |
|
1135 |
using a b c d |
|
1136 |
by simp |
|
1137 |
||
1138 |
ML {* |
|
1139 |
fun lift_match_error ctxt fun_str rtrm qtrm = |
|
1140 |
let |
|
1141 |
val rtrm_str = Syntax.string_of_term ctxt rtrm |
|
1142 |
val qtrm_str = Syntax.string_of_term ctxt qtrm |
|
1143 |
val msg = [enclose "[" "]" fun_str, "The quotient theorem\n", qtrm_str, |
|
1144 |
"and the lifted theorem\n", rtrm_str, "do not match"] |
|
1145 |
in |
|
1146 |
error (space_implode " " msg) |
|
1147 |
end |
|
1148 |
*} |
|
1149 |
||
1150 |
ML {* |
|
1151 |
fun procedure_inst ctxt rtrm qtrm = |
|
1152 |
let |
|
1153 |
val thy = ProofContext.theory_of ctxt |
|
1154 |
val rtrm' = HOLogic.dest_Trueprop rtrm |
|
1155 |
val qtrm' = HOLogic.dest_Trueprop qtrm |
|
1156 |
val reg_goal = |
|
1157 |
Syntax.check_term ctxt (regularize_trm ctxt rtrm' qtrm') |
|
1158 |
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm |
|
1159 |
val _ = warning "Regularization done." |
|
1160 |
val inj_goal = |
|
1161 |
Syntax.check_term ctxt (inj_repabs_trm ctxt (reg_goal, qtrm')) |
|
1162 |
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm |
|
1163 |
val _ = warning "RepAbs Injection done." |
|
1164 |
in |
|
1165 |
Drule.instantiate' [] |
|
1166 |
[SOME (cterm_of thy rtrm'), |
|
1167 |
SOME (cterm_of thy reg_goal), |
|
1168 |
SOME (cterm_of thy inj_goal)] @{thm lifting_procedure} |
|
1169 |
end |
|
1170 |
*} |
|
1171 |
||
1172 |
(* Left for debugging *) |
|
1173 |
ML {* |
|
1174 |
fun procedure_tac ctxt rthm = |
|
1175 |
ObjectLogic.full_atomize_tac |
|
1176 |
THEN' gen_frees_tac ctxt |
|
1177 |
THEN' CSUBGOAL (fn (gl, i) => |
|
1178 |
let |
|
1179 |
val rthm' = atomize_thm rthm |
|
1180 |
val rule = procedure_inst ctxt (prop_of rthm') (term_of gl) |
|
1181 |
val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb gl))] @{thm QUOT_TRUE_i} |
|
1182 |
in |
|
1183 |
(rtac rule THEN' RANGE [rtac rthm', (fn _ => all_tac), rtac thm]) i |
|
1184 |
end) |
|
1185 |
*} |
|
1186 |
||
1187 |
ML {* |
|
1188 |
fun lift_tac ctxt rthm = |
|
1189 |
ObjectLogic.full_atomize_tac |
|
1190 |
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
|
1191 |
THEN' CSUBGOAL (fn (goal, i) => |
597 | 1192 |
let |
1193 |
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
|
1194 |
val rule = procedure_inst ctxt (prop_of rthm') (term_of goal) |
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
|
1195 |
val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb goal))] @{thm QUOT_TRUE_i} |
597 | 1196 |
in |
1197 |
(rtac rule THEN' |
|
1198 |
RANGE [rtac rthm', |
|
1199 |
regularize_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
|
1200 |
rtac thm THEN' all_inj_repabs_tac ctxt, |
597 | 1201 |
clean_tac ctxt]) i |
1202 |
end) |
|
1203 |
*} |
|
1204 |
||
1205 |
end |
|
1206 |