71 SOME (t, _) => t |
71 SOME (t, _) => t |
72 | _ => error "Solve_quotient_assm failed. Possibly a quotient theorem is missing." |
72 | _ => error "Solve_quotient_assm failed. Possibly a quotient theorem is missing." |
73 |
73 |
74 |
74 |
75 fun prep_trm thy (x, (T, t)) = |
75 fun prep_trm thy (x, (T, t)) = |
76 (Thm.cterm_of thy (Var (x, T)), Thm.cterm_of thy t) |
76 (Thm.global_cterm_of thy (Var (x, T)), Thm.global_cterm_of thy t) |
77 |
77 |
78 fun prep_ty thy (x, (S, ty)) = |
78 fun prep_ty thy (x, (S, ty)) = |
79 (Thm.ctyp_of thy (TVar (x, S)), Thm.ctyp_of thy ty) |
79 (Thm.global_ctyp_of thy (TVar (x, S)), Thm.global_ctyp_of thy ty) |
80 |
80 |
81 fun get_match_inst thy pat trm = |
81 fun get_match_inst thy pat trm = |
82 let |
82 let |
83 val univ = Unify.matchers (Context.Theory thy) [(pat, trm)] |
83 val univ = Unify.matchers (Context.Theory thy) [(pat, trm)] |
84 val SOME (env, _) = Seq.pull univ (* raises Bind, if no unifier *) (* FIXME fragile *) |
84 val SOME (env, _) = Seq.pull univ (* raises Bind, if no unifier *) (* FIXME fragile *) |
98 *) |
98 *) |
99 fun calculate_inst ctxt ball_bex_thm redex R1 R2 = |
99 fun calculate_inst ctxt ball_bex_thm redex R1 R2 = |
100 let |
100 let |
101 val thy = Proof_Context.theory_of ctxt |
101 val thy = Proof_Context.theory_of ctxt |
102 fun get_lhs thm = fst (Logic.dest_equals (Thm.concl_of thm)) |
102 fun get_lhs thm = fst (Logic.dest_equals (Thm.concl_of thm)) |
103 val ty_inst = map (SOME o Thm.ctyp_of thy) [domain_type (fastype_of R2)] |
103 val ty_inst = map (SOME o Thm.global_ctyp_of thy) [domain_type (fastype_of R2)] |
104 val trm_inst = map (SOME o Thm.cterm_of thy) [R2, R1] |
104 val trm_inst = map (SOME o Thm.global_cterm_of thy) [R2, R1] |
105 in |
105 in |
106 (case try (Drule.instantiate' ty_inst trm_inst) ball_bex_thm of |
106 (case try (Drule.instantiate' ty_inst trm_inst) ball_bex_thm of |
107 NONE => NONE |
107 NONE => NONE |
108 | SOME thm' => |
108 | SOME thm' => |
109 (case try (get_match_inst thy (get_lhs thm')) redex of |
109 (case try (get_match_inst thy (get_lhs thm')) redex of |
197 (case Thm.term_of ctrm of |
197 (case Thm.term_of ctrm of |
198 (Const (@{const_name Quot_True}, _) $ x) => |
198 (Const (@{const_name Quot_True}, _) $ x) => |
199 let |
199 let |
200 val fx = fnctn x; |
200 val fx = fnctn x; |
201 val thy = Proof_Context.theory_of ctxt; |
201 val thy = Proof_Context.theory_of ctxt; |
202 val cx = Thm.cterm_of thy x; |
202 val cx = Thm.global_cterm_of thy x; |
203 val cfx = Thm.cterm_of thy fx; |
203 val cfx = Thm.global_cterm_of thy fx; |
204 val cxt = Thm.ctyp_of thy (fastype_of x); |
204 val cxt = Thm.global_ctyp_of thy (fastype_of x); |
205 val cfxt = Thm.ctyp_of thy (fastype_of fx); |
205 val cfxt = Thm.global_ctyp_of thy (fastype_of fx); |
206 val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QT_imp} |
206 val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QT_imp} |
207 in |
207 in |
208 Conv.rewr_conv thm ctrm |
208 Conv.rewr_conv thm ctrm |
209 end) |
209 end) |
210 |
210 |
249 let |
249 let |
250 val ty_x = fastype_of x |
250 val ty_x = fastype_of x |
251 val ty_b = fastype_of qt_arg |
251 val ty_b = fastype_of qt_arg |
252 val ty_f = range_type (fastype_of f) |
252 val ty_f = range_type (fastype_of f) |
253 val thy = Proof_Context.theory_of context |
253 val thy = Proof_Context.theory_of context |
254 val ty_inst = map (SOME o Thm.ctyp_of thy) [ty_x, ty_b, ty_f] |
254 val ty_inst = map (SOME o Thm.global_ctyp_of thy) [ty_x, ty_b, ty_f] |
255 val t_inst = map (SOME o Thm.cterm_of thy) [R2, f, g, x, y]; |
255 val t_inst = map (SOME o Thm.global_cterm_of thy) [R2, f, g, x, y]; |
256 val inst_thm = Drule.instantiate' ty_inst |
256 val inst_thm = Drule.instantiate' ty_inst |
257 ([NONE, NONE, NONE] @ t_inst) @{thm apply_rspQ3} |
257 ([NONE, NONE, NONE] @ t_inst) @{thm apply_rspQ3} |
258 in |
258 in |
259 (rtac inst_thm THEN' SOLVED' (quotient_tac context)) 1 |
259 (rtac inst_thm THEN' SOLVED' (quotient_tac context)) 1 |
260 end |
260 end |
266 *) |
266 *) |
267 fun equals_rsp_tac R ctxt = |
267 fun equals_rsp_tac R ctxt = |
268 let |
268 let |
269 val thy = Proof_Context.theory_of ctxt |
269 val thy = Proof_Context.theory_of ctxt |
270 in |
270 in |
271 case try (Thm.cterm_of thy) R of (* There can be loose bounds in R *) |
271 case try (Thm.global_cterm_of thy) R of (* There can be loose bounds in R *) |
272 SOME ctm => |
272 SOME ctm => |
273 let |
273 let |
274 val ty = domain_type (fastype_of R) |
274 val ty = domain_type (fastype_of R) |
275 in |
275 in |
276 case try (Drule.instantiate' [SOME (Thm.ctyp_of thy ty)] |
276 case try (Drule.instantiate' [SOME (Thm.global_ctyp_of thy ty)] |
277 [SOME (Thm.cterm_of thy R)]) @{thm equals_rsp} of |
277 [SOME (Thm.global_cterm_of thy R)]) @{thm equals_rsp} of |
278 SOME thm => rtac thm THEN' quotient_tac ctxt |
278 SOME thm => rtac thm THEN' quotient_tac ctxt |
279 | NONE => K no_tac |
279 | NONE => K no_tac |
280 end |
280 end |
281 | _ => K no_tac |
281 | _ => K no_tac |
282 end |
282 end |
286 (case try bare_concl goal of |
286 (case try bare_concl goal of |
287 SOME (rel $ _ $ (rep $ (abs $ _))) => |
287 SOME (rel $ _ $ (rep $ (abs $ _))) => |
288 (let |
288 (let |
289 val thy = Proof_Context.theory_of ctxt; |
289 val thy = Proof_Context.theory_of ctxt; |
290 val (ty_a, ty_b) = dest_funT (fastype_of abs); |
290 val (ty_a, ty_b) = dest_funT (fastype_of abs); |
291 val ty_inst = map (SOME o Thm.ctyp_of thy) [ty_a, ty_b]; |
291 val ty_inst = map (SOME o Thm.global_ctyp_of thy) [ty_a, ty_b]; |
292 in |
292 in |
293 case try (map (SOME o Thm.cterm_of thy)) [rel, abs, rep] of |
293 case try (map (SOME o Thm.global_cterm_of thy)) [rel, abs, rep] of |
294 SOME t_inst => |
294 SOME t_inst => |
295 (case try (Drule.instantiate' ty_inst t_inst) @{thm rep_abs_rsp} of |
295 (case try (Drule.instantiate' ty_inst t_inst) @{thm rep_abs_rsp} of |
296 SOME inst_thm => (rtac inst_thm THEN' quotient_tac ctxt) i |
296 SOME inst_thm => (rtac inst_thm THEN' quotient_tac ctxt) i |
297 | NONE => no_tac) |
297 | NONE => no_tac) |
298 | NONE => no_tac |
298 | NONE => no_tac |
476 (Const (@{const_name map_fun}, _) $ r1 $ a2) $ (Abs _) => |
476 (Const (@{const_name map_fun}, _) $ r1 $ a2) $ (Abs _) => |
477 let |
477 let |
478 val thy = Proof_Context.theory_of ctxt |
478 val thy = Proof_Context.theory_of ctxt |
479 val (ty_b, ty_a) = dest_funT (fastype_of r1) |
479 val (ty_b, ty_a) = dest_funT (fastype_of r1) |
480 val (ty_c, ty_d) = dest_funT (fastype_of a2) |
480 val (ty_c, ty_d) = dest_funT (fastype_of a2) |
481 val tyinst = map (SOME o Thm.ctyp_of thy) [ty_a, ty_b, ty_c, ty_d] |
481 val tyinst = map (SOME o Thm.global_ctyp_of thy) [ty_a, ty_b, ty_c, ty_d] |
482 val tinst = [NONE, NONE, SOME (Thm.cterm_of thy r1), NONE, SOME (Thm.cterm_of thy a2)] |
482 val tinst = [NONE, NONE, SOME (Thm.global_cterm_of thy r1), NONE, SOME (Thm.global_cterm_of thy a2)] |
483 val thm1 = Drule.instantiate' tyinst tinst @{thm lambda_prs[THEN eq_reflection]} |
483 val thm1 = Drule.instantiate' tyinst tinst @{thm lambda_prs[THEN eq_reflection]} |
484 val thm2 = solve_quotient_assm ctxt (solve_quotient_assm ctxt thm1) |
484 val thm2 = solve_quotient_assm ctxt (solve_quotient_assm ctxt thm1) |
485 val thm3 = rewrite_rule ctxt @{thms id_apply[THEN eq_reflection]} thm2 |
485 val thm3 = rewrite_rule ctxt @{thms id_apply[THEN eq_reflection]} thm2 |
486 val (insp, inst) = |
486 val (insp, inst) = |
487 if ty_c = ty_d |
487 if ty_c = ty_d |
488 then make_inst_id (Thm.term_of (Thm.lhs_of thm3)) (Thm.term_of ctrm) |
488 then make_inst_id (Thm.term_of (Thm.lhs_of thm3)) (Thm.term_of ctrm) |
489 else make_inst (Thm.term_of (Thm.lhs_of thm3)) (Thm.term_of ctrm) |
489 else make_inst (Thm.term_of (Thm.lhs_of thm3)) (Thm.term_of ctrm) |
490 val thm4 = |
490 val thm4 = |
491 Drule.instantiate_normalize ([], [(Thm.cterm_of thy insp, Thm.cterm_of thy inst)]) thm3 |
491 Drule.instantiate_normalize ([], [(Thm.global_cterm_of thy insp, Thm.global_cterm_of thy inst)]) thm3 |
492 in |
492 in |
493 Conv.rewr_conv thm4 ctrm |
493 Conv.rewr_conv thm4 ctrm |
494 end |
494 end |
495 | _ => Conv.all_conv ctrm) |
495 | _ => Conv.all_conv ctrm) |
496 |
496 |
555 fun gen_frees_tac ctxt = |
555 fun gen_frees_tac ctxt = |
556 SUBGOAL (fn (concl, i) => |
556 SUBGOAL (fn (concl, i) => |
557 let |
557 let |
558 val thy = Proof_Context.theory_of ctxt |
558 val thy = Proof_Context.theory_of ctxt |
559 val vrs = Term.add_frees concl [] |
559 val vrs = Term.add_frees concl [] |
560 val cvrs = map (Thm.cterm_of thy o Free) vrs |
560 val cvrs = map (Thm.global_cterm_of thy o Free) vrs |
561 val concl' = apply_under_Trueprop (all_list vrs) concl |
561 val concl' = apply_under_Trueprop (all_list vrs) concl |
562 val goal = Logic.mk_implies (concl', concl) |
562 val goal = Logic.mk_implies (concl', concl) |
563 val rule = Goal.prove ctxt [] [] goal |
563 val rule = Goal.prove ctxt [] [] goal |
564 (K (EVERY1 [inst_spec_tac (rev cvrs), assume_tac ctxt])) |
564 (K (EVERY1 [inst_spec_tac (rev cvrs), assume_tac ctxt])) |
565 in |
565 in |
615 handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm |
615 handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm |
616 val inj_goal = Quotient_Term.inj_repabs_trm_chk ctxt (reg_goal, qtrm') |
616 val inj_goal = Quotient_Term.inj_repabs_trm_chk ctxt (reg_goal, qtrm') |
617 handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm |
617 handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm |
618 in |
618 in |
619 Drule.instantiate' [] |
619 Drule.instantiate' [] |
620 [SOME (Thm.cterm_of thy rtrm'), |
620 [SOME (Thm.global_cterm_of thy rtrm'), |
621 SOME (Thm.cterm_of thy reg_goal), |
621 SOME (Thm.global_cterm_of thy reg_goal), |
622 NONE, |
622 NONE, |
623 SOME (Thm.cterm_of thy inj_goal)] procedure_thm |
623 SOME (Thm.global_cterm_of thy inj_goal)] procedure_thm |
624 end |
624 end |
625 |
625 |
626 |
626 |
627 (* Since we use Ball and Bex during the lifting and descending, |
627 (* Since we use Ball and Bex during the lifting and descending, |
628 we cannot deal with lemmas containing them, unless we unfold |
628 we cannot deal with lemmas containing them, unless we unfold |
675 handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm |
675 handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm |
676 val inj_goal = Quotient_Term.inj_repabs_trm_chk ctxt (reg_goal, qtrm') |
676 val inj_goal = Quotient_Term.inj_repabs_trm_chk ctxt (reg_goal, qtrm') |
677 handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm |
677 handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm |
678 in |
678 in |
679 Drule.instantiate' [] |
679 Drule.instantiate' [] |
680 [SOME (Thm.cterm_of thy reg_goal), |
680 [SOME (Thm.global_cterm_of thy reg_goal), |
681 NONE, |
681 NONE, |
682 SOME (Thm.cterm_of thy inj_goal)] partiality_procedure_thm |
682 SOME (Thm.global_cterm_of thy inj_goal)] partiality_procedure_thm |
683 end |
683 end |
684 |
684 |
685 |
685 |
686 fun partiality_descend_procedure_tac ctxt simps = |
686 fun partiality_descend_procedure_tac ctxt simps = |
687 let |
687 let |