src/HOL/Tools/datatype_rep_proofs.ML
author paulson
Wed, 03 Feb 1999 13:26:07 +0100
changeset 6171 cd237a10cbf8
parent 6092 d9db67970c73
child 6394 3d9fd50fcc43
permissions -rw-r--r--
inj is now a translation of inj_on
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     1
(*  Title:      HOL/Tools/datatype_rep_proofs.ML
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     2
    ID:         $Id$
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     3
    Author:     Stefan Berghofer
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     4
    Copyright   1998  TU Muenchen
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     5
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     6
Definitional introduction of datatypes
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     7
Proof of characteristic theorems:
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     8
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     9
 - injectivity of constructors
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    10
 - distinctness of constructors (internal version)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    11
 - induction theorem
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    12
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    13
*)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    14
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    15
signature DATATYPE_REP_PROOFS =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    16
sig
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    17
  val representation_proofs : bool -> DatatypeAux.datatype_info Symtab.table ->
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    18
    string list -> (int * (string * DatatypeAux.dtyp list *
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    19
      (string * DatatypeAux.dtyp list) list)) list list -> (string * sort) list ->
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    20
        (string * mixfix) list -> (string * mixfix) list list -> theory ->
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    21
          theory * thm list list * thm list list * thm
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    22
end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    23
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    24
structure DatatypeRepProofs : DATATYPE_REP_PROOFS =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    25
struct
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    26
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    27
open DatatypeAux;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    28
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    29
val (_ $ (_ $ (_ $ (distinct_f $ _) $ _))) = hd (prems_of distinct_lemma);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    30
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    31
(* figure out internal names *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    32
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    33
val image_name = Sign.intern_const (sign_of Set.thy) "op ``";
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    34
val UNIV_name = Sign.intern_const (sign_of Set.thy) "UNIV";
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    35
val inj_on_name = Sign.intern_const (sign_of Fun.thy) "inj_on";
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    36
val inv_name = Sign.intern_const (sign_of Fun.thy) "inv";
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    37
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    38
fun exh_thm_of (dt_info : datatype_info Symtab.table) tname =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    39
  #exhaustion (the (Symtab.lookup (dt_info, tname)));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    40
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    41
(******************************************************************************)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    42
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    43
fun representation_proofs flat_names (dt_info : datatype_info Symtab.table)
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    44
      new_type_names descr sorts types_syntax constr_syntax thy =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    45
  let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    46
    val Univ_thy = the (get_thy "Univ" thy);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    47
    val node_name = Sign.intern_tycon (sign_of Univ_thy) "node";
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    48
    val [In0_name, In1_name, Scons_name, Leaf_name, Numb_name] =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    49
      map (Sign.intern_const (sign_of Univ_thy))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    50
        ["In0", "In1", "Scons", "Leaf", "Numb"];
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    51
    val [In0_inject, In1_inject, Scons_inject, Leaf_inject, In0_eq, In1_eq,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    52
      In0_not_In1, In1_not_In0] = map (get_thm Univ_thy)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    53
        ["In0_inject", "In1_inject", "Scons_inject", "Leaf_inject", "In0_eq",
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    54
         "In1_eq", "In0_not_In1", "In1_not_In0"];
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    55
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    56
    val descr' = flat descr;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    57
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    58
    val big_name = space_implode "_" new_type_names;
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    59
    val thy1 = add_path flat_names big_name thy;
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    60
    val big_rec_name = big_name ^ "_rep_set";
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    61
    val rep_set_names = map (Sign.full_name (sign_of thy1))
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    62
      (if length descr' = 1 then [big_rec_name] else
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    63
        (map ((curry (op ^) (big_rec_name ^ "_")) o string_of_int)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    64
          (1 upto (length descr'))));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    65
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    66
    val tyvars = map (fn (_, (_, Ts, _)) => map dest_DtTFree Ts) (hd descr);
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    67
    val leafTs' = get_nonrec_types descr' sorts;
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    68
    val unneeded_vars = hd tyvars \\ foldr add_typ_tfree_names (leafTs', []);
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
    69
    val leafTs = leafTs' @ (map (fn n => TFree (n, the (assoc (sorts, n)))) unneeded_vars);
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    70
    val recTs = get_rec_types descr' sorts;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    71
    val newTs = take (length (hd descr), recTs);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    72
    val oldTs = drop (length (hd descr), recTs);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    73
    val sumT = if null leafTs then HOLogic.unitT
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    74
      else fold_bal (fn (T, U) => Type ("+", [T, U])) leafTs;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    75
    val Univ_elT = HOLogic.mk_setT (Type (node_name, [sumT]));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    76
    val UnivT = HOLogic.mk_setT Univ_elT;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    77
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    78
    val In0 = Const (In0_name, Univ_elT --> Univ_elT);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    79
    val In1 = Const (In1_name, Univ_elT --> Univ_elT);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    80
    val Leaf = Const (Leaf_name, sumT --> Univ_elT);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    81
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    82
    (* make injections needed for embedding types in leaves *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    83
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    84
    fun mk_inj T' x =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    85
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    86
        fun mk_inj' T n i =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    87
          if n = 1 then x else
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    88
          let val n2 = n div 2;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    89
              val Type (_, [T1, T2]) = T
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    90
          in
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    91
            if i <= n2 then
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    92
              Const ("Inl", T1 --> T) $ (mk_inj' T1 n2 i)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    93
            else
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    94
              Const ("Inr", T2 --> T) $ (mk_inj' T2 (n - n2) (i - n2))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    95
          end
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    96
      in mk_inj' sumT (length leafTs) (1 + find_index_eq T' leafTs)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    97
      end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    98
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    99
    (* make injections for constructors *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   100
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   101
    fun mk_univ_inj ts = access_bal (ap In0, ap In1, if ts = [] then
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   102
        Const ("arbitrary", Univ_elT)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   103
      else
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   104
        foldr1 (HOLogic.mk_binop Scons_name) ts);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   105
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   106
    (************** generate introduction rules for representing set **********)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   107
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   108
    val _ = message "Constructing representing sets...";
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   109
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   110
    (* make introduction rule for a single constructor *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   111
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   112
    fun make_intr s n (i, (_, cargs)) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   113
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   114
        fun mk_prem (DtRec k, (j, prems, ts)) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   115
              let val free_t = mk_Free "x" Univ_elT j
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   116
              in (j + 1, (HOLogic.mk_mem (free_t,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   117
                Const (nth_elem (k, rep_set_names), UnivT)))::prems, free_t::ts)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   118
              end
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   119
          | mk_prem (dt, (j, prems, ts)) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   120
              let val T = typ_of_dtyp descr' sorts dt
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   121
              in (j + 1, prems, (Leaf $ mk_inj T (mk_Free "x" T j))::ts)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   122
              end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   123
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   124
        val (_, prems, ts) = foldr mk_prem (cargs, (1, [], []));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   125
        val concl = HOLogic.mk_Trueprop (HOLogic.mk_mem
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   126
          (mk_univ_inj ts n i, Const (s, UnivT)))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   127
      in Logic.list_implies (map HOLogic.mk_Trueprop prems, concl)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   128
      end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   129
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   130
    val consts = map (fn s => Const (s, UnivT)) rep_set_names;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   131
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   132
    val intr_ts = flat (map (fn ((_, (_, _, constrs)), rep_set_name) =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   133
      map (make_intr rep_set_name (length constrs))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   134
        ((1 upto (length constrs)) ~~ constrs)) (descr' ~~ rep_set_names));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   135
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   136
    val (thy2, {raw_induct = rep_induct, intrs = rep_intrs, ...}) =
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   137
      setmp InductivePackage.quiet_mode (!quiet_mode)
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   138
        (InductivePackage.add_inductive_i false true big_rec_name false true false
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   139
           consts intr_ts [] []) thy1;
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   140
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   141
    (********************************* typedef ********************************)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   142
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   143
    val thy3 = add_path flat_names big_name (foldl (fn (thy, ((((name, mx), tvs), c), name')) =>
5696
c2c2214f8037 quiet proofs;
wenzelm
parents: 5661
diff changeset
   144
      setmp TypedefPackage.quiet_mode true
c2c2214f8037 quiet proofs;
wenzelm
parents: 5661
diff changeset
   145
        (TypedefPackage.add_typedef_i_no_def name' (name, tvs, mx) c [] []
c2c2214f8037 quiet proofs;
wenzelm
parents: 5661
diff changeset
   146
          (Some (QUIET_BREADTH_FIRST (has_fewer_prems 1) (resolve_tac rep_intrs 1)))) thy)
c2c2214f8037 quiet proofs;
wenzelm
parents: 5661
diff changeset
   147
            (parent_path flat_names thy2, types_syntax ~~ tyvars ~~ (take (length newTs, consts)) ~~
c2c2214f8037 quiet proofs;
wenzelm
parents: 5661
diff changeset
   148
              new_type_names));
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   149
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   150
    (*********************** definition of constructors ***********************)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   151
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   152
    val big_rep_name = (space_implode "_" new_type_names) ^ "_Rep_";
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   153
    val rep_names = map (curry op ^ "Rep_") new_type_names;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   154
    val rep_names' = map (fn i => big_rep_name ^ (string_of_int i))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   155
      (1 upto (length (flat (tl descr))));
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   156
    val all_rep_names = map (Sign.intern_const (sign_of thy3)) rep_names @
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   157
      map (Sign.full_name (sign_of thy3)) rep_names';
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   158
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   159
    (* isomorphism declarations *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   160
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   161
    val iso_decls = map (fn (T, s) => (s, T --> Univ_elT, NoSyn))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   162
      (oldTs ~~ rep_names');
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   163
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   164
    (* constructor definitions *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   165
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   166
    fun make_constr_def tname T n ((thy, defs, eqns, i), ((cname, cargs), (cname', mx))) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   167
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   168
        fun constr_arg (dt, (j, l_args, r_args)) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   169
          let val T = typ_of_dtyp descr' sorts dt;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   170
              val free_t = mk_Free "x" T j
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   171
          in (case dt of
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   172
              DtRec m => (j + 1, free_t::l_args, (Const (nth_elem (m, all_rep_names),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   173
                T --> Univ_elT) $ free_t)::r_args)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   174
            | _ => (j + 1, free_t::l_args, (Leaf $ mk_inj T free_t)::r_args))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   175
          end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   176
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   177
        val (_, l_args, r_args) = foldr constr_arg (cargs, (1, [], []));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   178
        val constrT = (map (typ_of_dtyp descr' sorts) cargs) ---> T;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   179
        val abs_name = Sign.intern_const (sign_of thy) ("Abs_" ^ tname);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   180
        val rep_name = Sign.intern_const (sign_of thy) ("Rep_" ^ tname);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   181
        val lhs = list_comb (Const (cname, constrT), l_args);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   182
        val rhs = mk_univ_inj r_args n i;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   183
        val def = equals T $ lhs $ (Const (abs_name, Univ_elT --> T) $ rhs);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   184
        val def_name = (Sign.base_name cname) ^ "_def";
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   185
        val eqn = HOLogic.mk_Trueprop (HOLogic.mk_eq
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   186
          (Const (rep_name, T --> Univ_elT) $ lhs, rhs));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   187
        val thy' = thy |>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   188
          Theory.add_consts_i [(cname', constrT, mx)] |>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   189
          Theory.add_defs_i [(def_name, def)];
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   190
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   191
      in (thy', defs @ [get_axiom thy' def_name], eqns @ [eqn], i + 1)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   192
      end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   193
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   194
    (* constructor definitions for datatype *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   195
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   196
    fun dt_constr_defs ((thy, defs, eqns, rep_congs, dist_lemmas),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   197
        ((((_, (_, _, constrs)), tname), T), constr_syntax)) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   198
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   199
        val _ $ (_ $ (cong_f $ _) $ _) = concl_of arg_cong;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   200
        val sg = sign_of thy;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   201
        val rep_const = cterm_of sg
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   202
          (Const (Sign.intern_const sg ("Rep_" ^ tname), T --> Univ_elT));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   203
        val cong' = cterm_instantiate [(cterm_of sg cong_f, rep_const)] arg_cong;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   204
        val dist = cterm_instantiate [(cterm_of sg distinct_f, rep_const)] distinct_lemma;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   205
        val (thy', defs', eqns', _) = foldl ((make_constr_def tname T) (length constrs))
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   206
          ((add_path flat_names tname thy, defs, [], 1), constrs ~~ constr_syntax)
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   207
      in
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   208
        (parent_path flat_names thy', defs', eqns @ [eqns'],
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   209
          rep_congs @ [cong'], dist_lemmas @ [dist])
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   210
      end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   211
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   212
    val (thy4, constr_defs, constr_rep_eqns, rep_congs, dist_lemmas) = foldl dt_constr_defs
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   213
      ((thy3 |> Theory.add_consts_i iso_decls |> parent_path flat_names, [], [], [], []),
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   214
        hd descr ~~ new_type_names ~~ newTs ~~ constr_syntax);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   215
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   216
    (*********** isomorphisms for new types (introduced by typedef) ***********)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   217
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   218
    val _ = message "Proving isomorphism properties...";
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   219
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   220
    (* get axioms from theory *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   221
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   222
    val newT_iso_axms = map (fn s =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   223
      (get_axiom thy4 ("Abs_" ^ s ^ "_inverse"),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   224
       get_axiom thy4 ("Rep_" ^ s ^ "_inverse"),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   225
       get_axiom thy4 ("Rep_" ^ s))) new_type_names;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   226
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   227
    (*------------------------------------------------*)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   228
    (* prove additional theorems:                     *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   229
    (*  inj_on dt_Abs_i rep_set_i  and  inj dt_Rep_i  *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   230
    (*------------------------------------------------*)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   231
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   232
    fun prove_newT_iso_inj_thm (((s, (thm1, thm2, _)), T), rep_set_name) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   233
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   234
        val sg = sign_of thy4;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   235
        val RepT = T --> Univ_elT;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   236
        val Rep_name = Sign.intern_const sg ("Rep_" ^ s);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   237
        val AbsT = Univ_elT --> T;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   238
        val Abs_name = Sign.intern_const sg ("Abs_" ^ s);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   239
6171
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   240
        val inj_Abs_thm = 
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   241
	    prove_goalw_cterm [] 
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   242
	      (cterm_of sg
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   243
	       (HOLogic.mk_Trueprop 
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   244
		(Const (inj_on_name, [AbsT, UnivT] ---> HOLogic.boolT) $
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   245
		 Const (Abs_name, AbsT) $ Const (rep_set_name, UnivT))))
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   246
              (fn _ => [rtac inj_on_inverseI 1, etac thm1 1]);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   247
6171
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   248
        val setT = HOLogic.mk_setT T
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   249
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   250
        val inj_Rep_thm =
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   251
	    prove_goalw_cterm []
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   252
	      (cterm_of sg
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   253
	       (HOLogic.mk_Trueprop
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   254
		(Const (inj_on_name, [RepT, setT] ---> HOLogic.boolT) $
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   255
		 Const (Rep_name, RepT) $ Const (UNIV_name, setT))))
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   256
              (fn _ => [rtac inj_inverseI 1, rtac thm2 1])
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   257
6171
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   258
      in (inj_Abs_thm, inj_Rep_thm) end;
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   259
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   260
    val newT_iso_inj_thms = map prove_newT_iso_inj_thm
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   261
      (new_type_names ~~ newT_iso_axms ~~ newTs ~~
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   262
        take (length newTs, rep_set_names));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   263
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   264
    (********* isomorphisms between existing types and "unfolded" types *******)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   265
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   266
    (*---------------------------------------------------------------------*)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   267
    (* isomorphisms are defined using primrec-combinators:                 *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   268
    (* generate appropriate functions for instantiating primrec-combinator *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   269
    (*                                                                     *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   270
    (*   e.g.  dt_Rep_i = list_rec ... (%h t y. In1 ((Leaf h) $ y))        *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   271
    (*                                                                     *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   272
    (* also generate characteristic equations for isomorphisms             *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   273
    (*                                                                     *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   274
    (*   e.g.  dt_Rep_i (cons h t) = In1 ((dt_Rep_j h) $ (dt_Rep_i t))     *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   275
    (*---------------------------------------------------------------------*)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   276
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   277
    fun make_iso_def k ks n ((fs, eqns, i), (cname, cargs)) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   278
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   279
        val argTs = map (typ_of_dtyp descr' sorts) cargs;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   280
        val T = nth_elem (k, recTs);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   281
        val rep_name = nth_elem (k, all_rep_names);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   282
        val rep_const = Const (rep_name, T --> Univ_elT);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   283
        val constr = Const (cname, argTs ---> T);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   284
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   285
        fun process_arg ks' ((i2, i2', ts), dt) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   286
          let val T' = typ_of_dtyp descr' sorts dt
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   287
          in (case dt of
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   288
              DtRec j => if j mem ks' then
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   289
                  (i2 + 1, i2' + 1, ts @ [mk_Free "y" Univ_elT i2'])
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   290
                else
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   291
                  (i2 + 1, i2', ts @ [Const (nth_elem (j, all_rep_names),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   292
                    T' --> Univ_elT) $ mk_Free "x" T' i2])
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   293
            | _ => (i2 + 1, i2', ts @ [Leaf $ mk_inj T' (mk_Free "x" T' i2)]))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   294
          end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   295
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   296
        val (i2, i2', ts) = foldl (process_arg ks) ((1, 1, []), cargs);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   297
        val xs = map (uncurry (mk_Free "x")) (argTs ~~ (1 upto (i2 - 1)));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   298
        val ys = map (mk_Free "y" Univ_elT) (1 upto (i2' - 1));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   299
        val f = list_abs_free (map dest_Free (xs @ ys), mk_univ_inj ts n i);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   300
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   301
        val (_, _, ts') = foldl (process_arg []) ((1, 1, []), cargs);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   302
        val eqn = HOLogic.mk_Trueprop (HOLogic.mk_eq
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   303
          (rep_const $ list_comb (constr, xs), mk_univ_inj ts' n i))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   304
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   305
      in (fs @ [f], eqns @ [eqn], i + 1) end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   306
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   307
    (* define isomorphisms for all mutually recursive datatypes in list ds *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   308
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   309
    fun make_iso_defs (ds, (thy, char_thms)) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   310
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   311
        val ks = map fst ds;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   312
        val (_, (tname, _, _)) = hd ds;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   313
        val {rec_rewrites, rec_names, ...} = the (Symtab.lookup (dt_info, tname));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   314
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   315
        fun process_dt ((fs, eqns, isos), (k, (tname, _, constrs))) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   316
          let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   317
            val (fs', eqns', _) = foldl (make_iso_def k ks (length constrs))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   318
              ((fs, eqns, 1), constrs);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   319
            val iso = (nth_elem (k, recTs), nth_elem (k, all_rep_names))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   320
          in (fs', eqns', isos @ [iso]) end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   321
        
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   322
        val (fs, eqns, isos) = foldl process_dt (([], [], []), ds);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   323
        val fTs = map fastype_of fs;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   324
        val defs = map (fn (rec_name, (T, iso_name)) => ((Sign.base_name iso_name) ^ "_def",
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   325
          equals (T --> Univ_elT) $ Const (iso_name, T --> Univ_elT) $
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   326
            list_comb (Const (rec_name, fTs @ [T] ---> Univ_elT), fs))) (rec_names ~~ isos);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   327
        val thy' = Theory.add_defs_i defs thy;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   328
        val def_thms = map (get_axiom thy') (map fst defs);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   329
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   330
        (* prove characteristic equations *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   331
5553
ae42b36a50c2 renamed mk_meta_eq to mk_eq
oheimb
parents: 5303
diff changeset
   332
        val rewrites = def_thms @ (map mk_meta_eq rec_rewrites);
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   333
        val char_thms' = map (fn eqn => prove_goalw_cterm rewrites
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   334
          (cterm_of (sign_of thy') eqn) (fn _ => [rtac refl 1])) eqns;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   335
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   336
      in (thy', char_thms' @ char_thms) end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   337
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   338
    val (thy5, iso_char_thms) = foldr make_iso_defs
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   339
      (tl descr, (add_path flat_names big_name thy4, []));
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   340
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   341
    (* prove isomorphism properties *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   342
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   343
    (* prove  x : dt_rep_set_i --> x : range dt_Rep_i *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   344
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   345
    fun mk_iso_t (((set_name, iso_name), i), T) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   346
      let val isoT = T --> Univ_elT
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   347
      in HOLogic.imp $ 
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   348
        HOLogic.mk_mem (mk_Free "x" Univ_elT i, Const (set_name, UnivT)) $
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   349
          (if i < length newTs then Const ("True", HOLogic.boolT)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   350
           else HOLogic.mk_mem (mk_Free "x" Univ_elT i,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   351
             Const (image_name, [isoT, HOLogic.mk_setT T] ---> UnivT) $
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   352
               Const (iso_name, isoT) $ Const (UNIV_name, HOLogic.mk_setT T)))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   353
      end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   354
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   355
    val iso_t = HOLogic.mk_Trueprop (mk_conj (map mk_iso_t
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   356
      (rep_set_names ~~ all_rep_names ~~ (0 upto (length descr' - 1)) ~~ recTs)));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   357
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   358
    val newT_Abs_inverse_thms = map (fn (iso, _, _) => iso RS subst) newT_iso_axms;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   359
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   360
    (* all the theorems are proved by one single simultaneous induction *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   361
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   362
    val iso_thms = if length descr = 1 then [] else
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   363
      drop (length newTs, split_conj_thm
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   364
        (prove_goalw_cterm [] (cterm_of (sign_of thy5) iso_t) (fn _ =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   365
           [indtac rep_induct 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   366
            REPEAT (rtac TrueI 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   367
            REPEAT (EVERY
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   368
              [REPEAT (etac rangeE 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   369
               REPEAT (eresolve_tac newT_Abs_inverse_thms 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   370
               TRY (hyp_subst_tac 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   371
               rtac (sym RS range_eqI) 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   372
               resolve_tac iso_char_thms 1])])));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   373
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   374
    val Abs_inverse_thms = newT_Abs_inverse_thms @ (map (fn r =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   375
      r RS mp RS f_inv_f RS subst) iso_thms);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   376
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   377
    (* prove  inj dt_Rep_i  and  dt_Rep_i x : dt_rep_set_i *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   378
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   379
    fun prove_iso_thms (ds, (inj_thms, elem_thms)) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   380
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   381
        val (_, (tname, _, _)) = hd ds;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   382
        val {induction, ...} = the (Symtab.lookup (dt_info, tname));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   383
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   384
        fun mk_ind_concl (i, _) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   385
          let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   386
            val T = nth_elem (i, recTs);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   387
            val Rep_t = Const (nth_elem (i, all_rep_names), T --> Univ_elT);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   388
            val rep_set_name = nth_elem (i, rep_set_names)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   389
          in (HOLogic.all_const T $ Abs ("y", T, HOLogic.imp $
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   390
                HOLogic.mk_eq (Rep_t $ mk_Free "x" T i, Rep_t $ Bound 0) $
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   391
                  HOLogic.mk_eq (mk_Free "x" T i, Bound 0)),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   392
              HOLogic.mk_mem (Rep_t $ mk_Free "x" T i, Const (rep_set_name, UnivT)))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   393
          end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   394
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   395
        val (ind_concl1, ind_concl2) = ListPair.unzip (map mk_ind_concl ds);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   396
5553
ae42b36a50c2 renamed mk_meta_eq to mk_eq
oheimb
parents: 5303
diff changeset
   397
        val rewrites = map mk_meta_eq iso_char_thms;
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   398
        val inj_thms' = map (fn r => r RS injD) inj_thms;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   399
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   400
        val inj_thm = prove_goalw_cterm [] (cterm_of (sign_of thy5)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   401
          (HOLogic.mk_Trueprop (mk_conj ind_concl1))) (fn _ =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   402
            [indtac induction 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   403
             REPEAT (EVERY
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   404
               [rtac allI 1, rtac impI 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   405
                exh_tac (exh_thm_of dt_info) 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   406
                REPEAT (EVERY
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   407
                  [hyp_subst_tac 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   408
                   rewrite_goals_tac rewrites,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   409
                   REPEAT (dresolve_tac [In0_inject, In1_inject] 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   410
                   (eresolve_tac [In0_not_In1 RS notE, In1_not_In0 RS notE] 1)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   411
                   ORELSE (EVERY
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   412
                     [REPEAT (etac Scons_inject 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   413
                      REPEAT (dresolve_tac
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   414
                        (inj_thms' @ [Leaf_inject, Inl_inject, Inr_inject]) 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   415
                      REPEAT (EVERY [etac allE 1, dtac mp 1, atac 1]),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   416
                      TRY (hyp_subst_tac 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   417
                      rtac refl 1])])])]);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   418
6171
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   419
        val inj_thms'' = map (fn r => r RS datatype_injI)
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   420
                             (split_conj_thm inj_thm);
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   421
6171
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   422
        val elem_thm = 
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   423
	    prove_goalw_cterm []
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   424
	      (cterm_of (sign_of thy5)
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   425
	       (HOLogic.mk_Trueprop (mk_conj ind_concl2)))
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   426
	      (fn _ =>
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   427
	       [indtac induction 1,
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   428
		rewrite_goals_tac rewrites,
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   429
		REPEAT (EVERY
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   430
			[resolve_tac rep_intrs 1,
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   431
			 REPEAT ((atac 1) ORELSE
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6092
diff changeset
   432
				 (resolve_tac elem_thms 1))])]);
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   433
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   434
      in (inj_thms @ inj_thms'', elem_thms @ (split_conj_thm elem_thm))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   435
      end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   436
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   437
    val (iso_inj_thms, iso_elem_thms) = foldr prove_iso_thms
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   438
      (tl descr, (map snd newT_iso_inj_thms, map #3 newT_iso_axms));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   439
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   440
    (******************* freeness theorems for constructors *******************)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   441
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   442
    val _ = message "Proving freeness of constructors...";
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   443
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   444
    (* prove theorem  Rep_i (Constr_j ...) = Inj_j ...  *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   445
    
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   446
    fun prove_constr_rep_thm eqn =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   447
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   448
        val inj_thms = map (fn (r, _) => r RS inj_onD) newT_iso_inj_thms;
5553
ae42b36a50c2 renamed mk_meta_eq to mk_eq
oheimb
parents: 5303
diff changeset
   449
        val rewrites = constr_defs @ (map (mk_meta_eq o #2) newT_iso_axms)
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   450
      in prove_goalw_cterm [] (cterm_of (sign_of thy5) eqn) (fn _ =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   451
        [resolve_tac inj_thms 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   452
         rewrite_goals_tac rewrites,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   453
         rtac refl 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   454
         resolve_tac rep_intrs 2,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   455
         REPEAT (resolve_tac iso_elem_thms 1)])
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   456
      end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   457
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   458
    (*--------------------------------------------------------------*)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   459
    (* constr_rep_thms and rep_congs are used to prove distinctness *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   460
    (* of constructors internally.                                  *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   461
    (* the external version uses dt_case which is not defined yet   *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   462
    (*--------------------------------------------------------------*)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   463
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   464
    val constr_rep_thms = map (map prove_constr_rep_thm) constr_rep_eqns;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   465
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   466
    val dist_rewrites = map (fn (rep_thms, dist_lemma) =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   467
      dist_lemma::(rep_thms @ [In0_eq, In1_eq, In0_not_In1, In1_not_In0]))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   468
        (constr_rep_thms ~~ dist_lemmas);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   469
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   470
    (* prove injectivity of constructors *)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   471
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   472
    fun prove_constr_inj_thm rep_thms t =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   473
      let val inj_thms = Scons_inject::(map make_elim
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   474
        ((map (fn r => r RS injD) iso_inj_thms) @
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   475
          [In0_inject, In1_inject, Leaf_inject, Inl_inject, Inr_inject]))
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   476
      in prove_goalw_cterm [] (cterm_of (sign_of thy5) t) (fn _ =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   477
        [rtac iffI 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   478
         REPEAT (etac conjE 2), hyp_subst_tac 2, rtac refl 2,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   479
         dresolve_tac rep_congs 1, dtac box_equals 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   480
         REPEAT (resolve_tac rep_thms 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   481
         REPEAT (eresolve_tac inj_thms 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   482
         hyp_subst_tac 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   483
         REPEAT (resolve_tac [conjI, refl] 1)])
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   484
      end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   485
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   486
    val constr_inject = map (fn (ts, thms) => map (prove_constr_inj_thm thms) ts)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   487
      ((DatatypeProp.make_injs descr sorts) ~~ constr_rep_thms);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   488
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   489
    val thy6 = store_thmss "inject" new_type_names
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   490
      constr_inject (parent_path flat_names thy5);
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   491
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   492
    (*************************** induction theorem ****************************)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   493
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   494
    val _ = message "Proving induction rule for datatypes...";
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   495
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   496
    val Rep_inverse_thms = (map (fn (_, iso, _) => iso RS subst) newT_iso_axms) @
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   497
      (map (fn r => r RS inv_f_f RS subst) (drop (length newTs, iso_inj_thms)));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   498
    val Rep_inverse_thms' = map (fn r => r RS inv_f_f)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   499
      (drop (length newTs, iso_inj_thms));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   500
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   501
    fun mk_indrule_lemma ((prems, concls), ((i, _), T)) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   502
      let
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   503
        val Rep_t = Const (nth_elem (i, all_rep_names), T --> Univ_elT) $
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   504
          mk_Free "x" T i;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   505
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   506
        val Abs_t = if i < length newTs then
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   507
            Const (Sign.intern_const (sign_of thy6)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   508
              ("Abs_" ^ (nth_elem (i, new_type_names))), Univ_elT --> T)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   509
          else Const (inv_name, [T --> Univ_elT, Univ_elT] ---> T) $
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   510
            Const (nth_elem (i, all_rep_names), T --> Univ_elT)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   511
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   512
      in (prems @ [HOLogic.imp $ HOLogic.mk_mem (Rep_t,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   513
            Const (nth_elem (i, rep_set_names), UnivT)) $
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   514
              (mk_Free "P" (T --> HOLogic.boolT) (i + 1) $ (Abs_t $ Rep_t))],
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   515
          concls @ [mk_Free "P" (T --> HOLogic.boolT) (i + 1) $ mk_Free "x" T i])
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   516
      end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   517
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   518
    val (indrule_lemma_prems, indrule_lemma_concls) =
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   519
      foldl mk_indrule_lemma (([], []), (descr' ~~ recTs));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   520
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   521
    val cert = cterm_of (sign_of thy6);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   522
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   523
    val indrule_lemma = prove_goalw_cterm [] (cert
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   524
      (Logic.mk_implies
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   525
        (HOLogic.mk_Trueprop (mk_conj indrule_lemma_prems),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   526
         HOLogic.mk_Trueprop (mk_conj indrule_lemma_concls)))) (fn prems =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   527
           [cut_facts_tac prems 1, REPEAT (etac conjE 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   528
            REPEAT (EVERY
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   529
              [TRY (rtac conjI 1), resolve_tac Rep_inverse_thms 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   530
               etac mp 1, resolve_tac iso_elem_thms 1])]);
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   531
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   532
    val Ps = map head_of (dest_conj (HOLogic.dest_Trueprop (concl_of indrule_lemma)));
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   533
    val frees = if length Ps = 1 then [Free ("P", snd (dest_Var (hd Ps)))] else
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   534
      map (Free o apfst fst o dest_Var) Ps;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   535
    val indrule_lemma' = cterm_instantiate (map cert Ps ~~ map cert frees) indrule_lemma;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   536
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   537
    val dt_induct = prove_goalw_cterm [] (cert
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   538
      (DatatypeProp.make_ind descr sorts)) (fn prems =>
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   539
        [rtac indrule_lemma' 1, indtac rep_induct 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   540
         EVERY (map (fn (prem, r) => (EVERY
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   541
           [REPEAT (eresolve_tac Abs_inverse_thms 1),
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   542
            simp_tac (HOL_basic_ss addsimps ((symmetric r)::Rep_inverse_thms')) 1,
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   543
            DEPTH_SOLVE_1 (ares_tac [prem] 1)]))
5553
ae42b36a50c2 renamed mk_meta_eq to mk_eq
oheimb
parents: 5303
diff changeset
   544
              (prems ~~ (constr_defs @ (map mk_meta_eq iso_char_thms))))]);
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   545
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   546
    val thy7 = thy6 |>
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   547
      Theory.add_path big_name |>
6092
d9db67970c73 eliminated tthm type and Attribute structure;
wenzelm
parents: 5696
diff changeset
   548
      PureThy.add_thms [(("induct", dt_induct), [])] |>
5661
6ecb6ea25f19 - Changed structure of name spaces
berghofe
parents: 5553
diff changeset
   549
      Theory.parent_path;
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   550
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   551
  in (thy7, constr_inject, dist_rewrites, dt_induct)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   552
  end;
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   553
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
   554
end;