src/ZF/Tools/induct_tacs.ML
author hoelzl
Tue, 13 Oct 2009 13:40:26 +0200
changeset 32920 ccfb774af58c
parent 32231 95b8afcbb0ed
child 32952 aeb1e44fbc19
permissions -rw-r--r--
order conjunctions to be printed without parentheses
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
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
     3
    Copyright   1994  University of Cambridge
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
     4
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
     5
Induction and exhaustion tactics for Isabelle/ZF.  The theory
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
     6
information needed to support them (and to support primrec).  Also a
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
     7
function to install other sets as if they were datatypes.
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
     8
*)
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
     9
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    10
signature DATATYPE_TACTICS =
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    11
sig
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26939
diff changeset
    12
  val induct_tac: Proof.context -> string -> int -> tactic
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26939
diff changeset
    13
  val exhaust_tac: Proof.context -> string -> int -> tactic
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
    14
  val rep_datatype_i: thm -> thm -> thm list -> thm list -> theory -> theory
26336
a0e2b706ce73 renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents: 24867
diff changeset
    15
  val rep_datatype: Facts.ref * Attrib.src list -> Facts.ref * Attrib.src list ->
a0e2b706ce73 renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents: 24867
diff changeset
    16
    (Facts.ref * Attrib.src list) list -> (Facts.ref * Attrib.src list) list -> theory -> theory
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
    17
  val setup: theory -> theory
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    18
end;
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    19
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    20
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    21
(** Datatype information, e.g. associated theorems **)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    22
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    23
type datatype_info =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    24
  {inductive: bool,             (*true if inductive, not coinductive*)
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    25
   constructors : term list,    (*the constructors, as Consts*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    26
   rec_rewrites : thm list,     (*recursor equations*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    27
   case_rewrites : thm list,    (*case equations*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    28
   induct : thm,
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    29
   mutual_induct : thm,
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    30
   exhaustion : thm};
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    31
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    32
structure DatatypesData = TheoryDataFun
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22101
diff changeset
    33
(
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    34
  type T = datatype_info Symtab.table;
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    35
  val empty = Symtab.empty;
6556
daa00919502b theory data: copy;
wenzelm
parents: 6141
diff changeset
    36
  val copy = I;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    37
  val extend = I;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    38
  fun merge _ tabs : T = Symtab.merge (K true) tabs;
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22101
diff changeset
    39
);
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    40
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    41
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
(** Constructor information: needed to map constructors to datatypes **)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    44
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    45
type constructor_info =
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    46
  {big_rec_name : string,     (*name of the mutually recursive set*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    47
   constructors : term list,  (*the constructors, as Consts*)
6141
a6922171b396 removal of the (thm list) argument of mk_cases
paulson
parents: 6112
diff changeset
    48
   free_iffs    : thm list,   (*freeness simprules*)
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    49
   rec_rewrites : thm list};  (*recursor equations*)
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
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    52
structure ConstructorsData = TheoryDataFun
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22101
diff changeset
    53
(
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    54
  type T = constructor_info Symtab.table
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    55
  val empty = Symtab.empty
6556
daa00919502b theory data: copy;
wenzelm
parents: 6141
diff changeset
    56
  val copy = I;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    57
  val extend = I
26618
wenzelm
parents: 26336
diff changeset
    58
  fun merge _ tabs : T = Symtab.merge (K true) tabs;
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22101
diff changeset
    59
);
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
    60
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    61
structure DatatypeTactics : DATATYPE_TACTICS =
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    62
struct
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    63
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    64
fun datatype_info thy name =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17314
diff changeset
    65
  (case Symtab.lookup (DatatypesData.get thy) name of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15462
diff changeset
    66
    SOME info => info
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15462
diff changeset
    67
  | NONE => error ("Unknown datatype " ^ quote name));
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    68
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    69
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    70
(*Given a variable, find the inductive set associated it in the assumptions*)
14153
76a6ba67bd15 new case_tac
paulson
parents: 12311
diff changeset
    71
exception Find_tname of string
76a6ba67bd15 new case_tac
paulson
parents: 12311
diff changeset
    72
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    73
fun find_tname var Bi =
24826
78e6a3cea367 avoid unnamed infixes;
wenzelm
parents: 24725
diff changeset
    74
  let fun mk_pair (Const(@{const_name mem},_) $ Free (v,_) $ A) =
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    75
             (v, #1 (dest_Const (head_of A)))
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    76
        | mk_pair _ = raise Match
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
    77
      val pairs = List.mapPartial (try (mk_pair o FOLogic.dest_Trueprop))
32231
95b8afcbb0ed moved METAHYPS to old_goals.ML (cf. SUBPROOF and FOCUS in subgoal.ML for properly localized versions of the same idea);
wenzelm
parents: 30541
diff changeset
    78
          (#2 (OldGoals.strip_context Bi))
17314
04e21a27c0ad introduces some modern-style AList operations
haftmann
parents: 17223
diff changeset
    79
  in case AList.lookup (op =) pairs var of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15462
diff changeset
    80
       NONE => raise Find_tname ("Cannot determine datatype of " ^ quote var)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15462
diff changeset
    81
     | SOME t => t
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    82
  end;
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    83
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    84
(** generic exhaustion and induction tactic for datatypes
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    85
    Differences from HOL:
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    86
      (1) no checking if the induction var occurs in premises, since it always
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    87
          appears in one of them, and it's hard to check for other occurrences
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    88
      (2) exhaustion works for VARIABLES in the premises, not general terms
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    89
**)
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    90
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26939
diff changeset
    91
fun exhaust_induct_tac exh ctxt var i state =
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    92
  let
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26939
diff changeset
    93
    val thy = ProofContext.theory_of ctxt
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    94
    val (_, _, Bi, _) = dest_state (state, i)
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
    95
    val tn = find_tname var Bi
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
    96
    val rule =
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    97
        if exh then #exhaustion (datatype_info thy tn)
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    98
               else #induct  (datatype_info thy tn)
24826
78e6a3cea367 avoid unnamed infixes;
wenzelm
parents: 24725
diff changeset
    99
    val (Const(@{const_name mem},_) $ Var(ixn,_) $ _) =
6112
5e4871c5136b datatype package improvements
paulson
parents: 6092
diff changeset
   100
        (case prems_of rule of
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   101
             [] => error "induction is not available for this datatype"
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   102
           | major::_ => FOLogic.dest_Trueprop major)
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   103
  in
27239
f2f42f9fa09d pervasive RuleInsts;
wenzelm
parents: 27208
diff changeset
   104
    eres_inst_tac ctxt [(ixn, var)] rule i state
14153
76a6ba67bd15 new case_tac
paulson
parents: 12311
diff changeset
   105
  end
76a6ba67bd15 new case_tac
paulson
parents: 12311
diff changeset
   106
  handle Find_tname msg =>
76a6ba67bd15 new case_tac
paulson
parents: 12311
diff changeset
   107
            if exh then (*try boolean case analysis instead*)
27208
5fe899199f85 proper context for tactics derived from res_inst_tac;
wenzelm
parents: 26939
diff changeset
   108
                case_tac ctxt var i state
14153
76a6ba67bd15 new case_tac
paulson
parents: 12311
diff changeset
   109
            else error msg;
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   110
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   111
val exhaust_tac = exhaust_induct_tac true;
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   112
val induct_tac = exhaust_induct_tac false;
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   113
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   114
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   115
(**** declare non-datatype as datatype ****)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   116
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   117
fun rep_datatype_i elim induct case_eqns recursor_eqns thy =
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   118
  let
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   119
    (*analyze the LHS of a case equation to get a constructor*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   120
    fun const_of (Const("op =", _) $ (_ $ c) $ _) = c
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   121
      | const_of eqn = error ("Ill-formed case equation: " ^
26939
1035c89b4c02 moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents: 26618
diff changeset
   122
                              Syntax.string_of_term_global thy eqn);
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   123
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   124
    val constructors =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   125
        map (head_of o const_of o FOLogic.dest_Trueprop o
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   126
             #prop o rep_thm) case_eqns;
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   127
24826
78e6a3cea367 avoid unnamed infixes;
wenzelm
parents: 24725
diff changeset
   128
    val Const (@{const_name mem}, _) $ _ $ data =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   129
        FOLogic.dest_Trueprop (hd (prems_of elim));
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   130
6112
5e4871c5136b datatype package improvements
paulson
parents: 6092
diff changeset
   131
    val Const(big_rec_name, _) = head_of data;
5e4871c5136b datatype package improvements
paulson
parents: 6092
diff changeset
   132
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   133
    val simps = case_eqns @ recursor_eqns;
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   134
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   135
    val dt_info =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   136
          {inductive = true,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   137
           constructors = constructors,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   138
           rec_rewrites = recursor_eqns,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   139
           case_rewrites = case_eqns,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   140
           induct = induct,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   141
           mutual_induct = TrueI,  (*No need for mutual induction*)
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   142
           exhaustion = elim};
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   143
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   144
    val con_info =
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   145
          {big_rec_name = big_rec_name,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   146
           constructors = constructors,
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   147
              (*let primrec handle definition by cases*)
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   148
           free_iffs = [],  (*thus we expect the necessary freeness rewrites
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   149
                              to be in the simpset already, as is the case for
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   150
                              Nat and disjoint sum*)
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   151
           rec_rewrites = (case recursor_eqns of
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   152
                               [] => case_eqns | _ => recursor_eqns)};
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   153
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   154
    (*associate with each constructor the datatype name and rewrites*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   155
    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
   156
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6065
diff changeset
   157
  in
17223
430edc6b7826 curried_lookup/update;
wenzelm
parents: 17057
diff changeset
   158
    thy
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 30280
diff changeset
   159
    |> Sign.add_path (Long_Name.base_name big_rec_name)
29579
cb520b766e00 binding replaces bstring
haftmann
parents: 27353
diff changeset
   160
    |> PureThy.add_thmss [((Binding.name "simps", simps), [Simplifier.simp_add])] |> snd
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17314
diff changeset
   161
    |> DatatypesData.put (Symtab.update (big_rec_name, dt_info) (DatatypesData.get thy))
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17314
diff changeset
   162
    |> ConstructorsData.put (fold_rev Symtab.update con_pairs (ConstructorsData.get thy))
24712
64ed05609568 proper Sign operations instead of Theory aliases;
wenzelm
parents: 22846
diff changeset
   163
    |> Sign.parent_path
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   164
  end;
6065
3b4a29166f26 induct_tac and exhaust_tac
paulson
parents:
diff changeset
   165
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   166
fun rep_datatype raw_elim raw_induct raw_case_eqns raw_recursor_eqns thy =
24725
04b676d1a1fe Attrib.eval_thms;
wenzelm
parents: 24712
diff changeset
   167
  let
04b676d1a1fe Attrib.eval_thms;
wenzelm
parents: 24712
diff changeset
   168
    val ctxt = ProofContext.init thy;
26336
a0e2b706ce73 renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents: 24867
diff changeset
   169
    val elim = Facts.the_single "elimination" (Attrib.eval_thms ctxt [raw_elim]);
a0e2b706ce73 renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents: 24867
diff changeset
   170
    val induct = Facts.the_single "induction" (Attrib.eval_thms ctxt [raw_induct]);
24725
04b676d1a1fe Attrib.eval_thms;
wenzelm
parents: 24712
diff changeset
   171
    val case_eqns = Attrib.eval_thms ctxt raw_case_eqns;
04b676d1a1fe Attrib.eval_thms;
wenzelm
parents: 24712
diff changeset
   172
    val recursor_eqns = Attrib.eval_thms ctxt raw_recursor_eqns;
04b676d1a1fe Attrib.eval_thms;
wenzelm
parents: 24712
diff changeset
   173
  in rep_datatype_i elim induct case_eqns recursor_eqns thy end;
12175
5cf58a1799a7 rearranged inductive package for Isar;
wenzelm
parents: 12109
diff changeset
   174
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   175
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   176
(* theory setup *)
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   177
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   178
val setup =
30541
9f168bdc468a simplified method setup;
wenzelm
parents: 30364
diff changeset
   179
  Method.setup @{binding induct_tac}
9f168bdc468a simplified method setup;
wenzelm
parents: 30364
diff changeset
   180
    (Args.goal_spec -- Scan.lift Args.name >>
9f168bdc468a simplified method setup;
wenzelm
parents: 30364
diff changeset
   181
      (fn (quant, s) => fn ctxt => SIMPLE_METHOD'' quant (induct_tac ctxt s)))
9f168bdc468a simplified method setup;
wenzelm
parents: 30364
diff changeset
   182
    "induct_tac emulation (dynamic instantiation!)" #>
9f168bdc468a simplified method setup;
wenzelm
parents: 30364
diff changeset
   183
  Method.setup @{binding case_tac}
9f168bdc468a simplified method setup;
wenzelm
parents: 30364
diff changeset
   184
   (Args.goal_spec -- Scan.lift Args.name >>
9f168bdc468a simplified method setup;
wenzelm
parents: 30364
diff changeset
   185
      (fn (quant, s) => fn ctxt => SIMPLE_METHOD'' quant (exhaust_tac ctxt s)))
9f168bdc468a simplified method setup;
wenzelm
parents: 30364
diff changeset
   186
    "datatype case_tac emulation (dynamic instantiation!)";
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   187
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   188
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   189
(* outer syntax *)
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   190
17057
0934ac31985f OuterKeyword;
wenzelm
parents: 16458
diff changeset
   191
local structure P = OuterParse and K = OuterKeyword in
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   192
27353
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 27239
diff changeset
   193
val _ = List.app OuterKeyword.keyword ["elimination", "induction", "case_eqns", "recursor_eqns"];
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24826
diff changeset
   194
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   195
val rep_datatype_decl =
22101
6d13239d5f52 moved parts of OuterParse to SpecParse;
wenzelm
parents: 21350
diff changeset
   196
  (P.$$$ "elimination" |-- P.!!! SpecParse.xthm) --
6d13239d5f52 moved parts of OuterParse to SpecParse;
wenzelm
parents: 21350
diff changeset
   197
  (P.$$$ "induction" |-- P.!!! SpecParse.xthm) --
6d13239d5f52 moved parts of OuterParse to SpecParse;
wenzelm
parents: 21350
diff changeset
   198
  (P.$$$ "case_eqns" |-- P.!!! SpecParse.xthms1) --
6d13239d5f52 moved parts of OuterParse to SpecParse;
wenzelm
parents: 21350
diff changeset
   199
  Scan.optional (P.$$$ "recursor_eqns" |-- P.!!! SpecParse.xthms1) []
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   200
  >> (fn (((x, y), z), w) => rep_datatype x y z w);
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   201
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24826
diff changeset
   202
val _ =
12204
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   203
  OuterSyntax.command "rep_datatype" "represent existing set inductively" K.thy_decl
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   204
    (rep_datatype_decl >> Toplevel.theory);
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   205
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   206
end;
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   207
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   208
end;
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   209
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   210
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   211
val exhaust_tac = DatatypeTactics.exhaust_tac;
98115606ee42 Isar version of 'rep_datatype';
wenzelm
parents: 12175
diff changeset
   212
val induct_tac  = DatatypeTactics.induct_tac;