src/Tools/induction.ML
author wenzelm
Mon Dec 14 11:20:31 2015 +0100 (2015-12-14)
changeset 61844 007d3b34080f
parent 61841 4d3527b94f2a
child 67149 e61557884799
permissions -rw-r--r--
tuned signature;
wenzelm@59931
     1
(*  Title:      Tools/induction.ML
wenzelm@59931
     2
    Author:     Tobias Nipkow, TU Muenchen
wenzelm@59931
     3
wenzelm@59931
     4
Alternative proof method "induction" that gives induction hypotheses the
wenzelm@59931
     5
name "IH".
wenzelm@59931
     6
*)
wenzelm@59931
     7
nipkow@45014
     8
signature INDUCTION =
nipkow@45014
     9
sig
wenzelm@61844
    10
  val induction_context_tactic: bool -> (binding option * (term * bool)) option list list ->
nipkow@45014
    11
    (string * typ) list list -> term option list -> thm list option ->
wenzelm@61841
    12
    thm list -> int -> context_tactic
wenzelm@61844
    13
  val induction_tac: Proof.context -> bool -> (binding option * (term * bool)) option list list ->
wenzelm@61844
    14
    (string * typ) list list -> term option list -> thm list option ->
wenzelm@61844
    15
    thm list -> int -> tactic
nipkow@45014
    16
end
nipkow@45014
    17
nipkow@45014
    18
structure Induction: INDUCTION =
nipkow@45014
    19
struct
nipkow@45014
    20
nipkow@45014
    21
val ind_hypsN = "IH";
nipkow@45014
    22
nipkow@45014
    23
fun preds_of t =
wenzelm@59931
    24
  (case strip_comb t of
nipkow@45014
    25
    (p as Var _, _) => [p]
nipkow@45014
    26
  | (p as Free _, _) => [p]
wenzelm@59931
    27
  | (_, ts) => maps preds_of ts);
nipkow@45014
    28
wenzelm@61844
    29
val induction_context_tactic =
wenzelm@61844
    30
  Induct.gen_induct_context_tactic (fn arg as ((cases, consumes), th) =>
wenzelm@61844
    31
    if not (forall (null o #2 o #1) cases) then arg
wenzelm@61844
    32
    else
wenzelm@61844
    33
      let
wenzelm@61844
    34
        val (prems, concl) = Logic.strip_horn (Thm.prop_of th);
wenzelm@61844
    35
        val prems' = drop consumes prems;
wenzelm@61844
    36
        val ps = preds_of concl;
wenzelm@61844
    37
  
wenzelm@61844
    38
        fun hname_of t =
wenzelm@61844
    39
          if exists_subterm (member (op aconv) ps) t
wenzelm@61844
    40
          then ind_hypsN else Rule_Cases.case_hypsN;
wenzelm@61844
    41
  
wenzelm@61844
    42
        val hnamess = map (map hname_of o Logic.strip_assums_hyp) prems';
wenzelm@61844
    43
        val n = Int.min (length hnamess, length cases);
wenzelm@61844
    44
        val cases' =
wenzelm@61844
    45
          map (fn (((cn, _), concls), hns) => ((cn, hns), concls))
wenzelm@61844
    46
            (take n cases ~~ take n hnamess);
wenzelm@61844
    47
      in ((cases', consumes), th) end);
nipkow@45014
    48
wenzelm@61844
    49
fun induction_tac ctxt x1 x2 x3 x4 x5 x6 x7 =
wenzelm@61844
    50
  Method.NO_CONTEXT_TACTIC ctxt (induction_context_tactic x1 x2 x3 x4 x5 x6 x7);
nipkow@45014
    51
wenzelm@61844
    52
val _ =
wenzelm@61844
    53
  Theory.local_setup (Induct.gen_induct_setup @{binding induction} induction_context_tactic);
nipkow@45014
    54
nipkow@45014
    55
end