src/ZF/Tools/induct_tacs.ML
changeset 27208 5fe899199f85
parent 26939 1035c89b4c02
child 27239 f2f42f9fa09d
equal deleted inserted replaced
27207:548e2d3105b9 27208:5fe899199f85
     8 function to install other sets as if they were datatypes.
     8 function to install other sets as if they were datatypes.
     9 *)
     9 *)
    10 
    10 
    11 signature DATATYPE_TACTICS =
    11 signature DATATYPE_TACTICS =
    12 sig
    12 sig
    13   val induct_tac: string -> int -> tactic
    13   val induct_tac: Proof.context -> string -> int -> tactic
    14   val exhaust_tac: string -> int -> tactic
    14   val exhaust_tac: Proof.context -> string -> int -> tactic
    15   val rep_datatype_i: thm -> thm -> thm list -> thm list -> theory -> theory
    15   val rep_datatype_i: thm -> thm -> thm list -> thm list -> theory -> theory
    16   val rep_datatype: Facts.ref * Attrib.src list -> Facts.ref * Attrib.src list ->
    16   val rep_datatype: Facts.ref * Attrib.src list -> Facts.ref * Attrib.src list ->
    17     (Facts.ref * Attrib.src list) list -> (Facts.ref * Attrib.src list) list -> theory -> theory
    17     (Facts.ref * Attrib.src list) list -> (Facts.ref * Attrib.src list) list -> theory -> theory
    18   val setup: theory -> theory
    18   val setup: theory -> theory
    19 end;
    19 end;
    87       (1) no checking if the induction var occurs in premises, since it always
    87       (1) no checking if the induction var occurs in premises, since it always
    88           appears in one of them, and it's hard to check for other occurrences
    88           appears in one of them, and it's hard to check for other occurrences
    89       (2) exhaustion works for VARIABLES in the premises, not general terms
    89       (2) exhaustion works for VARIABLES in the premises, not general terms
    90 **)
    90 **)
    91 
    91 
    92 fun exhaust_induct_tac exh var i state =
    92 fun exhaust_induct_tac exh ctxt var i state =
    93   let
    93   let
       
    94     val thy = ProofContext.theory_of ctxt
    94     val (_, _, Bi, _) = dest_state (state, i)
    95     val (_, _, Bi, _) = dest_state (state, i)
    95     val thy = Thm.theory_of_thm state
       
    96     val tn = find_tname var Bi
    96     val tn = find_tname var Bi
    97     val rule =
    97     val rule =
    98         if exh then #exhaustion (datatype_info thy tn)
    98         if exh then #exhaustion (datatype_info thy tn)
    99                else #induct  (datatype_info thy tn)
    99                else #induct  (datatype_info thy tn)
   100     val (Const(@{const_name mem},_) $ Var(ixn,_) $ _) =
   100     val (Const(@{const_name mem},_) $ Var(ixn,_) $ _) =
   101         (case prems_of rule of
   101         (case prems_of rule of
   102              [] => error "induction is not available for this datatype"
   102              [] => error "induction is not available for this datatype"
   103            | major::_ => FOLogic.dest_Trueprop major)
   103            | major::_ => FOLogic.dest_Trueprop major)
   104   in
   104   in
   105     Tactic.eres_inst_tac' [(ixn, var)] rule i state
   105     RuleInsts.eres_inst_tac ctxt [(ixn, var)] rule i state
   106   end
   106   end
   107   handle Find_tname msg =>
   107   handle Find_tname msg =>
   108             if exh then (*try boolean case analysis instead*)
   108             if exh then (*try boolean case analysis instead*)
   109                 case_tac var i state
   109                 case_tac ctxt var i state
   110             else error msg;
   110             else error msg;
   111 
   111 
   112 val exhaust_tac = exhaust_induct_tac true;
   112 val exhaust_tac = exhaust_induct_tac true;
   113 val induct_tac = exhaust_induct_tac false;
   113 val induct_tac = exhaust_induct_tac false;
   114 
   114 
   176 
   176 
   177 (* theory setup *)
   177 (* theory setup *)
   178 
   178 
   179 val setup =
   179 val setup =
   180   Method.add_methods
   180   Method.add_methods
   181     [("induct_tac", Method.goal_args Args.name induct_tac,
   181     [("induct_tac", Method.goal_args_ctxt Args.name induct_tac,
   182       "induct_tac emulation (dynamic instantiation!)"),
   182       "induct_tac emulation (dynamic instantiation!)"),
   183      ("case_tac", Method.goal_args Args.name exhaust_tac,
   183      ("case_tac", Method.goal_args_ctxt Args.name exhaust_tac,
   184       "datatype case_tac emulation (dynamic instantiation!)")];
   184       "datatype case_tac emulation (dynamic instantiation!)")];
   185 
   185 
   186 
   186 
   187 (* outer syntax *)
   187 (* outer syntax *)
   188 
   188