src/HOL/Tools/Quotient/quotient_tacs.ML
changeset 42361 23f352990944
parent 41451 892e67be8304
child 43333 2bdec7f430d3
equal deleted inserted replaced
42360:da8817d01e7c 42361:23f352990944
    96    we rely on unification/instantiation to check whether the
    96    we rely on unification/instantiation to check whether the
    97    theorem applies and return NONE if it doesn't.
    97    theorem applies and return NONE if it doesn't.
    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 = ProofContext.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 ctyp_of thy) [domain_type (fastype_of R2)]
   103     val ty_inst = map (SOME o ctyp_of thy) [domain_type (fastype_of R2)]
   104     val trm_inst = map (SOME o cterm_of thy) [R2, R1]
   104     val trm_inst = map (SOME o 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
   154 
   154 
   155 fun eq_imp_rel_get ctxt = map (OF1 eq_imp_rel) (Quotient_Info.equiv_rules_get ctxt)
   155 fun eq_imp_rel_get ctxt = map (OF1 eq_imp_rel) (Quotient_Info.equiv_rules_get ctxt)
   156 
   156 
   157 fun regularize_tac ctxt =
   157 fun regularize_tac ctxt =
   158   let
   158   let
   159     val thy = ProofContext.theory_of ctxt
   159     val thy = Proof_Context.theory_of ctxt
   160     val ball_pat = @{term "Ball (Respects (R1 ===> R2)) P"}
   160     val ball_pat = @{term "Ball (Respects (R1 ===> R2)) P"}
   161     val bex_pat = @{term "Bex (Respects (R1 ===> R2)) P"}
   161     val bex_pat = @{term "Bex (Respects (R1 ===> R2)) P"}
   162     val simproc =
   162     val simproc =
   163       Simplifier.simproc_global_i thy "" [ball_pat, bex_pat] (K (ball_bex_range_simproc))
   163       Simplifier.simproc_global_i thy "" [ball_pat, bex_pat] (K (ball_bex_range_simproc))
   164     val simpset =
   164     val simpset =
   199 fun quot_true_simple_conv ctxt fnctn ctrm =
   199 fun quot_true_simple_conv ctxt fnctn ctrm =
   200   case term_of ctrm of
   200   case term_of ctrm of
   201     (Const (@{const_name Quot_True}, _) $ x) =>
   201     (Const (@{const_name Quot_True}, _) $ x) =>
   202       let
   202       let
   203         val fx = fnctn x;
   203         val fx = fnctn x;
   204         val thy = ProofContext.theory_of ctxt;
   204         val thy = Proof_Context.theory_of ctxt;
   205         val cx = cterm_of thy x;
   205         val cx = cterm_of thy x;
   206         val cfx = cterm_of thy fx;
   206         val cfx = cterm_of thy fx;
   207         val cxt = ctyp_of thy (fastype_of x);
   207         val cxt = ctyp_of thy (fastype_of x);
   208         val cfxt = ctyp_of thy (fastype_of fx);
   208         val cfxt = ctyp_of thy (fastype_of fx);
   209         val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QT_imp}
   209         val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QT_imp}
   251           else
   251           else
   252             let
   252             let
   253               val ty_x = fastype_of x
   253               val ty_x = fastype_of x
   254               val ty_b = fastype_of qt_arg
   254               val ty_b = fastype_of qt_arg
   255               val ty_f = range_type (fastype_of f)
   255               val ty_f = range_type (fastype_of f)
   256               val thy = ProofContext.theory_of context
   256               val thy = Proof_Context.theory_of context
   257               val ty_inst = map (SOME o (ctyp_of thy)) [ty_x, ty_b, ty_f]
   257               val ty_inst = map (SOME o (ctyp_of thy)) [ty_x, ty_b, ty_f]
   258               val t_inst = map (SOME o (cterm_of thy)) [R2, f, g, x, y];
   258               val t_inst = map (SOME o (cterm_of thy)) [R2, f, g, x, y];
   259               val inst_thm = Drule.instantiate' ty_inst
   259               val inst_thm = Drule.instantiate' ty_inst
   260                 ([NONE, NONE, NONE] @ t_inst) @{thm apply_rsp}
   260                 ([NONE, NONE, NONE] @ t_inst) @{thm apply_rsp}
   261             in
   261             in
   267 (* Instantiates and applies 'equals_rsp'. Since the theorem is
   267 (* Instantiates and applies 'equals_rsp'. Since the theorem is
   268    complex we rely on instantiation to tell us if it applies
   268    complex we rely on instantiation to tell us if it applies
   269 *)
   269 *)
   270 fun equals_rsp_tac R ctxt =
   270 fun equals_rsp_tac R ctxt =
   271   let
   271   let
   272     val thy = ProofContext.theory_of ctxt
   272     val thy = Proof_Context.theory_of ctxt
   273   in
   273   in
   274     case try (cterm_of thy) R of (* There can be loose bounds in R *)
   274     case try (cterm_of thy) R of (* There can be loose bounds in R *)
   275       SOME ctm =>
   275       SOME ctm =>
   276         let
   276         let
   277           val ty = domain_type (fastype_of R)
   277           val ty = domain_type (fastype_of R)
   288   SUBGOAL (fn (goal, i) =>
   288   SUBGOAL (fn (goal, i) =>
   289     (case try bare_concl goal of
   289     (case try bare_concl goal of
   290       SOME (rel $ _ $ (rep $ (Bound _ $ _))) => no_tac
   290       SOME (rel $ _ $ (rep $ (Bound _ $ _))) => no_tac
   291     | SOME (rel $ _ $ (rep $ (abs $ _))) =>
   291     | SOME (rel $ _ $ (rep $ (abs $ _))) =>
   292         let
   292         let
   293           val thy = ProofContext.theory_of ctxt;
   293           val thy = Proof_Context.theory_of ctxt;
   294           val (ty_a, ty_b) = dest_funT (fastype_of abs);
   294           val (ty_a, ty_b) = dest_funT (fastype_of abs);
   295           val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
   295           val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
   296         in
   296         in
   297           case try (map (SOME o (cterm_of thy))) [rel, abs, rep] of
   297           case try (map (SOME o (cterm_of thy))) [rel, abs, rep] of
   298             SOME t_inst =>
   298             SOME t_inst =>
   476 *)
   476 *)
   477 fun lambda_prs_simple_conv ctxt ctrm =
   477 fun lambda_prs_simple_conv ctxt ctrm =
   478   (case term_of ctrm of
   478   (case term_of ctrm of
   479     (Const (@{const_name map_fun}, _) $ r1 $ a2) $ (Abs _) =>
   479     (Const (@{const_name map_fun}, _) $ r1 $ a2) $ (Abs _) =>
   480       let
   480       let
   481         val thy = ProofContext.theory_of ctxt
   481         val thy = Proof_Context.theory_of ctxt
   482         val (ty_b, ty_a) = dest_funT (fastype_of r1)
   482         val (ty_b, ty_a) = dest_funT (fastype_of r1)
   483         val (ty_c, ty_d) = dest_funT (fastype_of a2)
   483         val (ty_c, ty_d) = dest_funT (fastype_of a2)
   484         val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d]
   484         val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d]
   485         val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
   485         val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
   486         val thm1 = Drule.instantiate' tyinst tinst @{thm lambda_prs[THEN eq_reflection]}
   486         val thm1 = Drule.instantiate' tyinst tinst @{thm lambda_prs[THEN eq_reflection]}
   554   HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
   554   HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
   555 
   555 
   556 fun gen_frees_tac ctxt =
   556 fun gen_frees_tac ctxt =
   557   SUBGOAL (fn (concl, i) =>
   557   SUBGOAL (fn (concl, i) =>
   558     let
   558     let
   559       val thy = ProofContext.theory_of ctxt
   559       val thy = Proof_Context.theory_of ctxt
   560       val vrs = Term.add_frees concl []
   560       val vrs = Term.add_frees concl []
   561       val cvrs = map (cterm_of thy o Free) vrs
   561       val cvrs = map (cterm_of thy o Free) vrs
   562       val concl' = apply_under_Trueprop (all_list vrs) concl
   562       val concl' = apply_under_Trueprop (all_list vrs) concl
   563       val goal = Logic.mk_implies (concl', concl)
   563       val goal = Logic.mk_implies (concl', concl)
   564       val rule = Goal.prove ctxt [] [] goal
   564       val rule = Goal.prove ctxt [] [] goal
   598     error msg
   598     error msg
   599   end
   599   end
   600 
   600 
   601 fun procedure_inst ctxt rtrm qtrm =
   601 fun procedure_inst ctxt rtrm qtrm =
   602   let
   602   let
   603     val thy = ProofContext.theory_of ctxt
   603     val thy = Proof_Context.theory_of ctxt
   604     val rtrm' = HOLogic.dest_Trueprop rtrm
   604     val rtrm' = HOLogic.dest_Trueprop rtrm
   605     val qtrm' = HOLogic.dest_Trueprop qtrm
   605     val qtrm' = HOLogic.dest_Trueprop qtrm
   606     val reg_goal = Quotient_Term.regularize_trm_chk ctxt (rtrm', qtrm')
   606     val reg_goal = Quotient_Term.regularize_trm_chk ctxt (rtrm', qtrm')
   607       handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm
   607       handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm
   608     val inj_goal = Quotient_Term.inj_repabs_trm_chk ctxt (reg_goal, qtrm')
   608     val inj_goal = Quotient_Term.inj_repabs_trm_chk ctxt (reg_goal, qtrm')
   702     val ((_, [rthm']), ctxt') = Variable.import true [rthm] ctxt
   702     val ((_, [rthm']), ctxt') = Variable.import true [rthm] ctxt
   703     val goal = Quotient_Term.derive_qtrm ctxt' qtys (prop_of rthm')
   703     val goal = Quotient_Term.derive_qtrm ctxt' qtys (prop_of rthm')
   704   in
   704   in
   705     Goal.prove ctxt' [] [] goal
   705     Goal.prove ctxt' [] [] goal
   706       (K (HEADGOAL (lift_single_tac ctxt' simps rthm')))
   706       (K (HEADGOAL (lift_single_tac ctxt' simps rthm')))
   707     |> singleton (ProofContext.export ctxt' ctxt)
   707     |> singleton (Proof_Context.export ctxt' ctxt)
   708   end
   708   end
   709 
   709 
   710 
   710 
   711 (* lifting as an attribute *)
   711 (* lifting as an attribute *)
   712 
   712