src/Pure/Isar/rule_cases.ML
changeset 61834 2154e6c8d52d
parent 60576 51f1d213079c
child 61853 fb7756087101
equal deleted inserted replaced
61830:4f5ab843cf5b 61834:2154e6c8d52d
     2     Author:     Markus Wenzel, TU Muenchen
     2     Author:     Markus Wenzel, TU Muenchen
     3 
     3 
     4 Annotations and local contexts of rules.
     4 Annotations and local contexts of rules.
     5 *)
     5 *)
     6 
     6 
     7 infix 1 THEN_ALL_NEW_CASES;
       
     8 
       
     9 signature BASIC_RULE_CASES =
       
    10 sig
       
    11   type cases
       
    12   type cases_state = cases * thm
       
    13   type cases_tactic = thm -> cases_state Seq.seq
       
    14   val CASES: cases -> tactic -> cases_tactic
       
    15   val EMPTY_CASES: tactic -> cases_tactic
       
    16   val SUBGOAL_CASES: (term * int -> cases_tactic) -> int -> cases_tactic
       
    17   val THEN_ALL_NEW_CASES: (int -> cases_tactic) * (int -> tactic) -> int -> cases_tactic
       
    18 end
       
    19 
       
    20 signature RULE_CASES =
     7 signature RULE_CASES =
    21 sig
     8 sig
    22   include BASIC_RULE_CASES
       
    23   datatype T = Case of
     9   datatype T = Case of
    24    {fixes: (binding * typ) list,
    10    {fixes: (binding * typ) list,
    25     assumes: (string * term list) list,
    11     assumes: (string * term list) list,
    26     binds: (indexname * term option) list,
    12     binds: (indexname * term option) list,
    27     cases: (string * T) list}
    13     cases: (string * T) list}
       
    14   type cases = (string * T option) list
    28   val case_hypsN: string
    15   val case_hypsN: string
    29   val strip_params: term -> (string * typ) list
    16   val strip_params: term -> (string * typ) list
    30   type info = ((string * string list) * string list) list
    17   type info = ((string * string list) * string list) list
    31   val make_common: Proof.context -> term -> info -> cases
    18   val make_common: Proof.context -> term -> info -> cases
    32   val make_nested: Proof.context -> term -> term -> info -> cases
    19   val make_nested: Proof.context -> term -> term -> info -> cases
   182 
   169 
   183 end;
   170 end;
   184 
   171 
   185 
   172 
   186 
   173 
   187 (** tactics with cases **)
       
   188 
       
   189 type cases_state = cases * thm;
       
   190 type cases_tactic = thm -> cases_state Seq.seq;
       
   191 
       
   192 fun CASES cases tac st = Seq.map (pair cases) (tac st);
       
   193 fun EMPTY_CASES tac = CASES [] tac;
       
   194 
       
   195 fun SUBGOAL_CASES tac i st =
       
   196   (case try Logic.nth_prem (i, Thm.prop_of st) of
       
   197     SOME goal => tac (goal, i) st
       
   198   | NONE => Seq.empty);
       
   199 
       
   200 fun (tac1 THEN_ALL_NEW_CASES tac2) i st =
       
   201   st |> tac1 i |> Seq.maps (fn (cases, st') =>
       
   202     CASES cases (Seq.INTERVAL tac2 i (i + Thm.nprems_of st' - Thm.nprems_of st)) st');
       
   203 
       
   204 
       
   205 
       
   206 (** annotations and operations on rules **)
   174 (** annotations and operations on rules **)
   207 
   175 
   208 (* consume facts *)
   176 (* consume facts *)
   209 
   177 
   210 local
   178 local
   481   (case mutual_rule ctxt ths of
   449   (case mutual_rule ctxt ths of
   482     NONE => error "Failed to join given rules into one mutual rule"
   450     NONE => error "Failed to join given rules into one mutual rule"
   483   | SOME res => res);
   451   | SOME res => res);
   484 
   452 
   485 end;
   453 end;
   486 
       
   487 structure Basic_Rule_Cases: BASIC_RULE_CASES = Rule_Cases;
       
   488 open Basic_Rule_Cases;