src/ZF/Tools/induct_tacs.ML
author wenzelm
Wed, 28 Nov 2001 00:46:26 +0100
changeset 12311 ce5f9e61c037
parent 12204 98115606ee42
child 14153 76a6ba67bd15
permissions -rw-r--r--
theory data: removed obsolete finish method;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
     1
(*  Title:      ZF/Tools/induct_tacs.ML
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
     2
    ID:         $Id$
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
     4
    Copyright   1994  University of Cambridge
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
     5
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
     6
Induction and exhaustion tactics for Isabelle/ZF.  The theory
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
     7
information needed to support them (and to support primrec).  Also a
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
     8
function to install other sets as if they were datatypes.
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
     9
*)
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    10
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    11
signature DATATYPE_TACTICS =
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    12
sig
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
    13
  val induct_tac: string -> int -> tactic
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
    14
  val exhaust_tac: string -> int -> tactic
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
    15
  val rep_datatype_i: thm -> thm -> thm list -> thm list -> theory -> theory
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
    16
  val rep_datatype: xstring * Args.src list -> xstring * Args.src list ->
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
    17
    (xstring * Args.src list) list -> (xstring * Args.src list) list -> theory -> theory
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
    18
  val setup: (theory -> theory) list
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    19
end;
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    20
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    21
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    22
(** Datatype information, e.g. associated theorems **)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    23
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    24
type datatype_info =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    25
  {inductive: bool,             (*true if inductive, not coinductive*)
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    26
   constructors : term list,    (*the constructors, as Consts*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    27
   rec_rewrites : thm list,     (*recursor equations*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    28
   case_rewrites : thm list,    (*case equations*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    29
   induct : thm,
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    30
   mutual_induct : thm,
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    31
   exhaustion : thm};
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    32
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    33
structure DatatypesArgs =
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    34
  struct
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    35
  val name = "ZF/datatypes";
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    36
  type T = datatype_info Symtab.table;
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    37
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    38
  val empty = Symtab.empty;
6556
daa00919502b theory data: copy;
wenzelm
parents: 6141
diff changeset
    39
  val copy = I;
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    40
  val prep_ext = I;
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    41
  val merge: T * T -> T = Symtab.merge (K true);
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    42
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    43
  fun print sg tab =
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    44
    Pretty.writeln (Pretty.strs ("datatypes:" ::
6851
526c0b90bcef cond_extern_table;
wenzelm
parents: 6556
diff changeset
    45
      map #1 (Sign.cond_extern_table sg Sign.typeK tab)));
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    46
  end;
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    47
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    48
structure DatatypesData = TheoryDataFun(DatatypesArgs);
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    49
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    50
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    51
(** Constructor information: needed to map constructors to datatypes **)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    52
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    53
type constructor_info =
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    54
  {big_rec_name : string,     (*name of the mutually recursive set*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    55
   constructors : term list,  (*the constructors, as Consts*)
6141
a6922171b396 removal of the (thm list) argument of mk_cases
paulson
parents: 6112
diff changeset
    56
   free_iffs    : thm list,   (*freeness simprules*)
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    57
   rec_rewrites : thm list};  (*recursor equations*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    58
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    59
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    60
structure ConstructorsArgs =
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    61
struct
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    62
  val name = "ZF/constructors"
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    63
  type T = constructor_info Symtab.table
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    64
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    65
  val empty = Symtab.empty
6556
daa00919502b theory data: copy;
wenzelm
parents: 6141
diff changeset
    66
  val copy = I;
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    67
  val prep_ext = I
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    68
  val merge: T * T -> T = Symtab.merge (K true)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    69
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    70
  fun print sg tab = ()   (*nothing extra to print*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    71
end;
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    72
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    73
structure ConstructorsData = TheoryDataFun(ConstructorsArgs);
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    74
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    75
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    76
structure DatatypeTactics : DATATYPE_TACTICS =
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    77
struct
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    78
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    79
fun datatype_info_sg sign name =
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    80
  (case Symtab.lookup (DatatypesData.get_sg sign, name) of
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    81
    Some info => info
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    82
  | None => error ("Unknown datatype " ^ quote name));
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    83
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    84
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    85
(*Given a variable, find the inductive set associated it in the assumptions*)
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    86
fun find_tname var Bi =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    87
  let fun mk_pair (Const("op :",_) $ Free (v,_) $ A) =
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    88
             (v, #1 (dest_Const (head_of A)))
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    89
        | mk_pair _ = raise Match
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    90
      val pairs = mapfilter (try (mk_pair o FOLogic.dest_Trueprop))
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    91
          (#2 (strip_context Bi))
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    92
  in case assoc (pairs, var) of
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    93
       None => error ("Cannot determine datatype of " ^ quote var)
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    94
     | Some t => t
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    95
  end;
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    96
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    97
(** generic exhaustion and induction tactic for datatypes
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    98
    Differences from HOL:
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    99
      (1) no checking if the induction var occurs in premises, since it always
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   100
          appears in one of them, and it's hard to check for other occurrences
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   101
      (2) exhaustion works for VARIABLES in the premises, not general terms
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   102
**)
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   103
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   104
fun exhaust_induct_tac exh var i state =
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   105
  let
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   106
    val (_, _, Bi, _) = dest_state (state, i)
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   107
    val {sign, ...} = rep_thm state
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   108
    val tn = find_tname var Bi
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   109
    val rule =
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   110
        if exh then #exhaustion (datatype_info_sg sign tn)
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   111
               else #induct  (datatype_info_sg sign tn)
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   112
    val (Const("op :",_) $ Var(ixn,_) $ _) =
6112
5e4871c5136b datatype package improvements
paulson
parents: 6092
diff changeset
   113
        (case prems_of rule of
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   114
             [] => error "induction is not available for this datatype"
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   115
           | major::_ => FOLogic.dest_Trueprop major)
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   116
    val ind_vname = Syntax.string_of_vname ixn
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   117
    val vname' = (*delete leading question mark*)
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   118
        String.substring (ind_vname, 1, size ind_vname-1)
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   119
  in
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   120
    eres_inst_tac [(vname',var)] rule i state
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   121
  end;
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   122
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   123
val exhaust_tac = exhaust_induct_tac true;
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   124
val induct_tac = exhaust_induct_tac false;
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   125
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   126
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   127
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   128
(**** declare non-datatype as datatype ****)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   129
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   130
fun rep_datatype_i elim induct case_eqns recursor_eqns thy =
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   131
  let
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   132
    val sign = sign_of thy;
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   133
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   134
    (*analyze the LHS of a case equation to get a constructor*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   135
    fun const_of (Const("op =", _) $ (_ $ c) $ _) = c
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   136
      | const_of eqn = error ("Ill-formed case equation: " ^
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   137
                              Sign.string_of_term sign eqn);
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   138
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   139
    val constructors =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   140
        map (head_of o const_of o FOLogic.dest_Trueprop o
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   141
             #prop o rep_thm) case_eqns;
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   142
6112
5e4871c5136b datatype package improvements
paulson
parents: 6092
diff changeset
   143
    val Const ("op :", _) $ _ $ data =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   144
        FOLogic.dest_Trueprop (hd (prems_of elim));
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   145
6112
5e4871c5136b datatype package improvements
paulson
parents: 6092
diff changeset
   146
    val Const(big_rec_name, _) = head_of data;
5e4871c5136b datatype package improvements
paulson
parents: 6092
diff changeset
   147
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   148
    val simps = case_eqns @ recursor_eqns;
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   149
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   150
    val dt_info =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   151
          {inductive = true,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   152
           constructors = constructors,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   153
           rec_rewrites = recursor_eqns,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   154
           case_rewrites = case_eqns,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   155
           induct = induct,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   156
           mutual_induct = TrueI,  (*No need for mutual induction*)
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   157
           exhaustion = elim};
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   158
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   159
    val con_info =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   160
          {big_rec_name = big_rec_name,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   161
           constructors = constructors,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   162
              (*let primrec handle definition by cases*)
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   163
           free_iffs = [],  (*thus we expect the necessary freeness rewrites
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   164
                              to be in the simpset already, as is the case for
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   165
                              Nat and disjoint sum*)
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   166
           rec_rewrites = (case recursor_eqns of
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   167
                               [] => case_eqns | _ => recursor_eqns)};
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   168
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   169
    (*associate with each constructor the datatype name and rewrites*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   170
    val con_pairs = map (fn c => (#1 (dest_Const c), con_info)) constructors
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   171
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   172
  in
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   173
      thy |> Theory.add_path (Sign.base_name big_rec_name)
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   174
          |> (#1 o PureThy.add_thmss [(("simps", simps), [Simplifier.simp_add_global])])
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   175
          |> DatatypesData.put
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   176
              (Symtab.update
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   177
               ((big_rec_name, dt_info), DatatypesData.get thy))
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   178
          |> ConstructorsData.put
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   179
               (foldr Symtab.update (con_pairs, ConstructorsData.get thy))
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   180
          |> Theory.parent_path
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   181
  end;
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   182
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   183
fun rep_datatype raw_elim raw_induct raw_case_eqns raw_recursor_eqns thy =
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   184
  let
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   185
    val (thy', (((elims, inducts), case_eqns), recursor_eqns)) = thy
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   186
      |> IsarThy.apply_theorems [raw_elim]
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   187
      |>>> IsarThy.apply_theorems [raw_induct]
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   188
      |>>> IsarThy.apply_theorems raw_case_eqns
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   189
      |>>> IsarThy.apply_theorems raw_recursor_eqns;
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   190
  in
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   191
    thy' |> rep_datatype_i (PureThy.single_thm "elimination" elims)
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   192
      (PureThy.single_thm "induction" inducts) case_eqns recursor_eqns
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   193
  end;
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   194
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   195
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   196
(* theory setup *)
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   197
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   198
val setup =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   199
 [DatatypesData.init,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   200
  ConstructorsData.init,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   201
  Method.add_methods
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   202
    [("induct_tac", Method.goal_args Args.name induct_tac,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   203
      "induct_tac emulation (dynamic instantiation!)"),
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   204
     ("case_tac", Method.goal_args Args.name case_tac,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   205
      "case_tac emulation (dynamic instantiation!)")]];
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   206
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   207
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   208
(* outer syntax *)
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   209
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   210
local structure P = OuterParse and K = OuterSyntax.Keyword in
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   211
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   212
val rep_datatype_decl =
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   213
  (P.$$$ "elimination" |-- P.!!! P.xthm) --
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   214
  (P.$$$ "induction" |-- P.!!! P.xthm) --
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   215
  (P.$$$ "case_eqns" |-- P.!!! P.xthms1) --
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   216
  Scan.optional (P.$$$ "recursor_eqns" |-- P.!!! P.xthms1) []
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   217
  >> (fn (((x, y), z), w) => rep_datatype x y z w);
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   218
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   219
val rep_datatypeP =
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   220
  OuterSyntax.command "rep_datatype" "represent existing set inductively" K.thy_decl
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   221
    (rep_datatype_decl >> Toplevel.theory);
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   222
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   223
val _ = OuterSyntax.add_keywords ["elimination", "induction", "case_eqns", "recursor_eqns"];
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   224
val _ = OuterSyntax.add_parsers [rep_datatypeP];
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   225
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   226
end;
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   227
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   228
end;
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   229
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   230
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   231
val exhaust_tac = DatatypeTactics.exhaust_tac;
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   232
val induct_tac  = DatatypeTactics.induct_tac;