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