src/HOL/Tools/datatype_rep_proofs.ML
changeset 7015 85be09eb136c
parent 6522 2f6cec5c046f
child 7205 dab2be236bfc
     1.1 --- a/src/HOL/Tools/datatype_rep_proofs.ML	Fri Jul 16 12:09:48 1999 +0200
     1.2 +++ b/src/HOL/Tools/datatype_rep_proofs.ML	Fri Jul 16 12:14:04 1999 +0200
     1.3 @@ -12,13 +12,16 @@
     1.4  
     1.5  *)
     1.6  
     1.7 +val foo = ref [TrueI];
     1.8 +
     1.9  signature DATATYPE_REP_PROOFS =
    1.10  sig
    1.11    val representation_proofs : bool -> DatatypeAux.datatype_info Symtab.table ->
    1.12      string list -> (int * (string * DatatypeAux.dtyp list *
    1.13        (string * DatatypeAux.dtyp list) list)) list list -> (string * sort) list ->
    1.14          (string * mixfix) list -> (string * mixfix) list list -> theory ->
    1.15 -          theory * thm list list * thm list list * thm
    1.16 +          theory * thm list list * thm list list * thm list list *
    1.17 +            DatatypeAux.simproc_dist list * thm
    1.18  end;
    1.19  
    1.20  structure DatatypeRepProofs : DATATYPE_REP_PROOFS =
    1.21 @@ -43,15 +46,22 @@
    1.22  fun representation_proofs flat_names (dt_info : datatype_info Symtab.table)
    1.23        new_type_names descr sorts types_syntax constr_syntax thy =
    1.24    let
    1.25 -    val Univ_thy = the (get_thy "Univ" thy);
    1.26 -    val node_name = Sign.intern_tycon (Theory.sign_of Univ_thy) "node";
    1.27 -    val [In0_name, In1_name, Scons_name, Leaf_name, Numb_name] =
    1.28 -      map (Sign.intern_const (Theory.sign_of Univ_thy))
    1.29 -        ["In0", "In1", "Scons", "Leaf", "Numb"];
    1.30 +    val Datatype_thy = theory "Datatype";
    1.31 +    val node_name = Sign.intern_tycon (Theory.sign_of Datatype_thy) "node";
    1.32 +    val [In0_name, In1_name, Scons_name, Leaf_name, Numb_name, Lim_name,
    1.33 +      Funs_name, o_name] =
    1.34 +      map (Sign.intern_const (Theory.sign_of Datatype_thy))
    1.35 +        ["In0", "In1", "Scons", "Leaf", "Numb", "Lim", "Funs", "op o"];
    1.36 +
    1.37      val [In0_inject, In1_inject, Scons_inject, Leaf_inject, In0_eq, In1_eq,
    1.38 -      In0_not_In1, In1_not_In0] = map (get_thm Univ_thy)
    1.39 -        ["In0_inject", "In1_inject", "Scons_inject", "Leaf_inject", "In0_eq",
    1.40 -         "In1_eq", "In0_not_In1", "In1_not_In0"];
    1.41 +         In0_not_In1, In1_not_In0, Funs_mono, FunsI, Lim_inject,
    1.42 +         Funs_inv, FunsD, Funs_rangeE, Funs_nonempty] = map (get_thm Datatype_thy)
    1.43 +        ["In0_inject", "In1_inject", "Scons_inject", "Leaf_inject", "In0_eq", "In1_eq",
    1.44 +         "In0_not_In1", "In1_not_In0", "Funs_mono", "FunsI", "Lim_inject",
    1.45 +         "Funs_inv", "FunsD", "Funs_rangeE", "Funs_nonempty"];
    1.46 +
    1.47 +    val Funs_IntE = (Int_lower2 RS Funs_mono RS
    1.48 +      (Int_lower1 RS Funs_mono RS Int_greatest) RS subsetD) RS IntE;
    1.49  
    1.50      val descr' = flat descr;
    1.51  
    1.52 @@ -65,19 +75,23 @@
    1.53  
    1.54      val tyvars = map (fn (_, (_, Ts, _)) => map dest_DtTFree Ts) (hd descr);
    1.55      val leafTs' = get_nonrec_types descr' sorts;
    1.56 -    val unneeded_vars = hd tyvars \\ foldr add_typ_tfree_names (leafTs', []);
    1.57 +    val branchTs = get_branching_types descr' sorts;
    1.58 +    val branchT = if null branchTs then HOLogic.unitT
    1.59 +      else fold_bal (fn (T, U) => Type ("+", [T, U])) branchTs;
    1.60 +    val unneeded_vars = hd tyvars \\ foldr add_typ_tfree_names (leafTs' @ branchTs, []);
    1.61      val leafTs = leafTs' @ (map (fn n => TFree (n, the (assoc (sorts, n)))) unneeded_vars);
    1.62      val recTs = get_rec_types descr' sorts;
    1.63      val newTs = take (length (hd descr), recTs);
    1.64      val oldTs = drop (length (hd descr), recTs);
    1.65      val sumT = if null leafTs then HOLogic.unitT
    1.66        else fold_bal (fn (T, U) => Type ("+", [T, U])) leafTs;
    1.67 -    val Univ_elT = HOLogic.mk_setT (Type (node_name, [sumT]));
    1.68 +    val Univ_elT = HOLogic.mk_setT (Type (node_name, [sumT, branchT]));
    1.69      val UnivT = HOLogic.mk_setT Univ_elT;
    1.70  
    1.71      val In0 = Const (In0_name, Univ_elT --> Univ_elT);
    1.72      val In1 = Const (In1_name, Univ_elT --> Univ_elT);
    1.73      val Leaf = Const (Leaf_name, sumT --> Univ_elT);
    1.74 +    val Lim = Const (Lim_name, (branchT --> Univ_elT) --> Univ_elT);
    1.75  
    1.76      (* make injections needed for embedding types in leaves *)
    1.77  
    1.78 @@ -103,6 +117,25 @@
    1.79        else
    1.80          foldr1 (HOLogic.mk_binop Scons_name) ts);
    1.81  
    1.82 +    (* function spaces *)
    1.83 +
    1.84 +    fun mk_fun_inj T' x =
    1.85 +      let
    1.86 +        fun mk_inj T n i =
    1.87 +          if n = 1 then x else
    1.88 +          let
    1.89 +            val n2 = n div 2;
    1.90 +            val Type (_, [T1, T2]) = T;
    1.91 +            val sum_case = Const ("sum_case", [T1 --> Univ_elT, T2 --> Univ_elT, T] ---> Univ_elT)
    1.92 +          in
    1.93 +            if i <= n2 then
    1.94 +              sum_case $ (mk_inj T1 n2 i) $ Const ("arbitrary", T2 --> Univ_elT)
    1.95 +            else
    1.96 +              sum_case $ Const ("arbitrary", T1 --> Univ_elT) $ mk_inj T2 (n - n2) (i - n2)
    1.97 +          end
    1.98 +      in mk_inj branchT (length branchTs) (1 + find_index_eq T' branchTs)
    1.99 +      end;
   1.100 +
   1.101      (************** generate introduction rules for representing set **********)
   1.102  
   1.103      val _ = message "Constructing representing sets ...";
   1.104 @@ -116,6 +149,14 @@
   1.105                in (j + 1, (HOLogic.mk_mem (free_t,
   1.106                  Const (nth_elem (k, rep_set_names), UnivT)))::prems, free_t::ts)
   1.107                end
   1.108 +          | mk_prem (DtType ("fun", [T, DtRec k]), (j, prems, ts)) =
   1.109 +              let val T' = typ_of_dtyp descr' sorts T;
   1.110 +                  val free_t = mk_Free "x" (T' --> Univ_elT) j
   1.111 +              in (j + 1, (HOLogic.mk_mem (free_t,
   1.112 +                Const (Funs_name, UnivT --> HOLogic.mk_setT (T' --> Univ_elT)) $
   1.113 +                  Const (nth_elem (k, rep_set_names), UnivT)))::prems,
   1.114 +                    Lim $ mk_fun_inj T' free_t::ts)
   1.115 +              end
   1.116            | mk_prem (dt, (j, prems, ts)) =
   1.117                let val T = typ_of_dtyp descr' sorts dt
   1.118                in (j + 1, prems, (Leaf $ mk_inj T (mk_Free "x" T j))::ts)
   1.119 @@ -136,16 +177,17 @@
   1.120      val (thy2, {raw_induct = rep_induct, intrs = rep_intrs, ...}) =
   1.121        setmp InductivePackage.quiet_mode (!quiet_mode)
   1.122          (InductivePackage.add_inductive_i false true big_rec_name false true false
   1.123 -           consts [] (map (fn x => (("", x), [])) intr_ts) [] []) thy1;
   1.124 +           consts [] (map (fn x => (("", x), [])) intr_ts) [Funs_mono] []) thy1;
   1.125  
   1.126      (********************************* typedef ********************************)
   1.127  
   1.128      val thy3 = add_path flat_names big_name (foldl (fn (thy, ((((name, mx), tvs), c), name')) =>
   1.129        setmp TypedefPackage.quiet_mode true
   1.130          (TypedefPackage.add_typedef_i_no_def name' (name, tvs, mx) c [] []
   1.131 -          (Some (QUIET_BREADTH_FIRST (has_fewer_prems 1) (resolve_tac rep_intrs 1)))) thy)
   1.132 -            (parent_path flat_names thy2, types_syntax ~~ tyvars ~~ (take (length newTs, consts)) ~~
   1.133 -              new_type_names));
   1.134 +          (Some (QUIET_BREADTH_FIRST (has_fewer_prems 1)
   1.135 +            (resolve_tac (Funs_nonempty::rep_intrs) 1)))) thy)
   1.136 +              (parent_path flat_names thy2, types_syntax ~~ tyvars ~~
   1.137 +                (take (length newTs, consts)) ~~ new_type_names));
   1.138  
   1.139      (*********************** definition of constructors ***********************)
   1.140  
   1.141 @@ -171,6 +213,13 @@
   1.142            in (case dt of
   1.143                DtRec m => (j + 1, free_t::l_args, (Const (nth_elem (m, all_rep_names),
   1.144                  T --> Univ_elT) $ free_t)::r_args)
   1.145 +            | DtType ("fun", [T', DtRec m]) =>
   1.146 +                let val ([T''], T''') = strip_type T
   1.147 +                in (j + 1, free_t::l_args, (Lim $ mk_fun_inj T''
   1.148 +                  (Const (o_name, [T''' --> Univ_elT, T, T''] ---> Univ_elT) $
   1.149 +                    Const (nth_elem (m, all_rep_names), T''' --> Univ_elT) $ free_t))::r_args)
   1.150 +                end
   1.151 +
   1.152              | _ => (j + 1, free_t::l_args, (Leaf $ mk_inj T free_t)::r_args))
   1.153            end;
   1.154  
   1.155 @@ -200,8 +249,8 @@
   1.156          val sg = Theory.sign_of thy;
   1.157          val rep_const = cterm_of sg
   1.158            (Const (Sign.intern_const sg ("Rep_" ^ tname), T --> Univ_elT));
   1.159 -        val cong' = cterm_instantiate [(cterm_of sg cong_f, rep_const)] arg_cong;
   1.160 -        val dist = cterm_instantiate [(cterm_of sg distinct_f, rep_const)] distinct_lemma;
   1.161 +        val cong' = standard (cterm_instantiate [(cterm_of sg cong_f, rep_const)] arg_cong);
   1.162 +        val dist = standard (cterm_instantiate [(cterm_of sg distinct_f, rep_const)] distinct_lemma);
   1.163          val (thy', defs', eqns', _) = foldl ((make_constr_def tname T) (length constrs))
   1.164            ((add_path flat_names tname thy, defs, [], 1), constrs ~~ constr_syntax)
   1.165        in
   1.166 @@ -282,23 +331,34 @@
   1.167          val rep_const = Const (rep_name, T --> Univ_elT);
   1.168          val constr = Const (cname, argTs ---> T);
   1.169  
   1.170 -        fun process_arg ks' ((i2, i2', ts), dt) =
   1.171 +        fun process_arg ks' ((i2, i2', ts, Ts), dt) =
   1.172            let val T' = typ_of_dtyp descr' sorts dt
   1.173            in (case dt of
   1.174                DtRec j => if j mem ks' then
   1.175 -                  (i2 + 1, i2' + 1, ts @ [mk_Free "y" Univ_elT i2'])
   1.176 +                  (i2 + 1, i2' + 1, ts @ [mk_Free "y" Univ_elT i2'], Ts @ [Univ_elT])
   1.177                  else
   1.178                    (i2 + 1, i2', ts @ [Const (nth_elem (j, all_rep_names),
   1.179 -                    T' --> Univ_elT) $ mk_Free "x" T' i2])
   1.180 -            | _ => (i2 + 1, i2', ts @ [Leaf $ mk_inj T' (mk_Free "x" T' i2)]))
   1.181 +                    T' --> Univ_elT) $ mk_Free "x" T' i2], Ts)
   1.182 +            | (DtType ("fun", [_, DtRec j])) =>
   1.183 +                let val ([T''], T''') = strip_type T'
   1.184 +                in if j mem ks' then
   1.185 +                    (i2 + 1, i2' + 1, ts @ [Lim $ mk_fun_inj T''
   1.186 +                      (mk_Free "y" (T'' --> Univ_elT) i2')], Ts @ [T'' --> Univ_elT])
   1.187 +                  else
   1.188 +                    (i2 + 1, i2', ts @ [Lim $ mk_fun_inj T''
   1.189 +                      (Const (o_name, [T''' --> Univ_elT, T', T''] ---> Univ_elT) $
   1.190 +                        Const (nth_elem (j, all_rep_names), T''' --> Univ_elT) $
   1.191 +                          mk_Free "x" T' i2)], Ts)
   1.192 +                end
   1.193 +            | _ => (i2 + 1, i2', ts @ [Leaf $ mk_inj T' (mk_Free "x" T' i2)], Ts))
   1.194            end;
   1.195  
   1.196 -        val (i2, i2', ts) = foldl (process_arg ks) ((1, 1, []), cargs);
   1.197 +        val (i2, i2', ts, Ts) = foldl (process_arg ks) ((1, 1, [], []), cargs);
   1.198          val xs = map (uncurry (mk_Free "x")) (argTs ~~ (1 upto (i2 - 1)));
   1.199 -        val ys = map (mk_Free "y" Univ_elT) (1 upto (i2' - 1));
   1.200 +        val ys = map (uncurry (mk_Free "y")) (Ts ~~ (1 upto (i2' - 1)));
   1.201          val f = list_abs_free (map dest_Free (xs @ ys), mk_univ_inj ts n i);
   1.202  
   1.203 -        val (_, _, ts') = foldl (process_arg []) ((1, 1, []), cargs);
   1.204 +        val (_, _, ts', _) = foldl (process_arg []) ((1, 1, [], []), cargs);
   1.205          val eqn = HOLogic.mk_Trueprop (HOLogic.mk_eq
   1.206            (rep_const $ list_comb (constr, xs), mk_univ_inj ts' n i))
   1.207  
   1.208 @@ -340,6 +400,21 @@
   1.209  
   1.210      (* prove isomorphism properties *)
   1.211  
   1.212 +    fun mk_funs_inv thm =
   1.213 +      let
   1.214 +        val [_, t] = prems_of Funs_inv;
   1.215 +        val [_ $ (_ $ _ $ R)] = Logic.strip_assums_hyp t;
   1.216 +        val _ $ (_ $ (r $ (a $ _)) $ _) = Logic.strip_assums_concl t;
   1.217 +        val [_ $ (_ $ _ $ R')] = prems_of thm;
   1.218 +        val _ $ (_ $ (r' $ (a' $ _)) $ _) = concl_of thm;
   1.219 +        val inv' = cterm_instantiate (map 
   1.220 +          ((pairself (cterm_of (sign_of_thm thm))) o
   1.221 +           (apsnd (map_term_types (incr_tvar 1))))
   1.222 +             [(R, R'), (r, r'), (a, a')]) Funs_inv
   1.223 +      in
   1.224 +        rule_by_tactic (atac 2) (thm RSN (2, inv'))
   1.225 +      end;
   1.226 +
   1.227      (* prove  x : dt_rep_set_i --> x : range dt_Rep_i *)
   1.228  
   1.229      fun mk_iso_t (((set_name, iso_name), i), T) =
   1.230 @@ -355,8 +430,6 @@
   1.231      val iso_t = HOLogic.mk_Trueprop (mk_conj (map mk_iso_t
   1.232        (rep_set_names ~~ all_rep_names ~~ (0 upto (length descr' - 1)) ~~ recTs)));
   1.233  
   1.234 -    val newT_Abs_inverse_thms = map (fn (iso, _, _) => iso RS subst) newT_iso_axms;
   1.235 -
   1.236      (* all the theorems are proved by one single simultaneous induction *)
   1.237  
   1.238      val iso_thms = if length descr = 1 then [] else
   1.239 @@ -365,14 +438,19 @@
   1.240             [indtac rep_induct 1,
   1.241              REPEAT (rtac TrueI 1),
   1.242              REPEAT (EVERY
   1.243 -              [REPEAT (etac rangeE 1),
   1.244 -               REPEAT (eresolve_tac newT_Abs_inverse_thms 1),
   1.245 +              [rewrite_goals_tac [mk_meta_eq Collect_mem_eq],
   1.246 +               REPEAT (etac Funs_IntE 1),
   1.247 +               REPEAT (eresolve_tac [rangeE, Funs_rangeE] 1),
   1.248 +               REPEAT (eresolve_tac (map (fn (iso, _, _) => iso RS subst) newT_iso_axms @
   1.249 +                 map (fn (iso, _, _) => mk_funs_inv iso RS subst) newT_iso_axms) 1),
   1.250                 TRY (hyp_subst_tac 1),
   1.251                 rtac (sym RS range_eqI) 1,
   1.252                 resolve_tac iso_char_thms 1])])));
   1.253  
   1.254 -    val Abs_inverse_thms = newT_Abs_inverse_thms @ (map (fn r =>
   1.255 -      r RS mp RS f_inv_f RS subst) iso_thms);
   1.256 +    val Abs_inverse_thms' = (map #1 newT_iso_axms) @ map (fn r => r RS mp RS f_inv_f) iso_thms;
   1.257 +
   1.258 +    val Abs_inverse_thms = map (fn r => r RS subst) (Abs_inverse_thms' @
   1.259 +      map mk_funs_inv Abs_inverse_thms');
   1.260  
   1.261      (* prove  inj dt_Rep_i  and  dt_Rep_i x : dt_rep_set_i *)
   1.262  
   1.263 @@ -395,7 +473,7 @@
   1.264          val (ind_concl1, ind_concl2) = ListPair.unzip (map mk_ind_concl ds);
   1.265  
   1.266          val rewrites = map mk_meta_eq iso_char_thms;
   1.267 -        val inj_thms' = map (fn r => r RS injD) inj_thms;
   1.268 +        val inj_thms' = flat (map (fn r => [r RS injD, r RS inj_o]) inj_thms);
   1.269  
   1.270          val inj_thm = prove_goalw_cterm [] (cterm_of (Theory.sign_of thy5)
   1.271            (HOLogic.mk_Trueprop (mk_conj ind_concl1))) (fn _ =>
   1.272 @@ -411,8 +489,9 @@
   1.273                     ORELSE (EVERY
   1.274                       [REPEAT (etac Scons_inject 1),
   1.275                        REPEAT (dresolve_tac
   1.276 -                        (inj_thms' @ [Leaf_inject, Inl_inject, Inr_inject]) 1),
   1.277 -                      REPEAT (EVERY [etac allE 1, dtac mp 1, atac 1]),
   1.278 +                        (inj_thms' @ [Leaf_inject, Lim_inject, Inl_inject, Inr_inject]) 1),
   1.279 +                      REPEAT ((EVERY [etac allE 1, dtac mp 1, atac 1]) ORELSE
   1.280 +                              (dtac inj_fun_lemma 1 THEN atac 1)),
   1.281                        TRY (hyp_subst_tac 1),
   1.282                        rtac refl 1])])])]);
   1.283  
   1.284 @@ -425,11 +504,11 @@
   1.285  	       (HOLogic.mk_Trueprop (mk_conj ind_concl2)))
   1.286  	      (fn _ =>
   1.287  	       [indtac induction 1,
   1.288 -		rewrite_goals_tac rewrites,
   1.289 +		rewrite_goals_tac (o_def :: rewrites),
   1.290  		REPEAT (EVERY
   1.291  			[resolve_tac rep_intrs 1,
   1.292 -			 REPEAT ((atac 1) ORELSE
   1.293 -				 (resolve_tac elem_thms 1))])]);
   1.294 +			 REPEAT (FIRST [atac 1, etac spec 1,
   1.295 +				 resolve_tac (FunsI :: elem_thms) 1])])]);
   1.296  
   1.297        in (inj_thms @ inj_thms'', elem_thms @ (split_conj_thm elem_thm))
   1.298        end;
   1.299 @@ -446,19 +525,18 @@
   1.300      fun prove_constr_rep_thm eqn =
   1.301        let
   1.302          val inj_thms = map (fn (r, _) => r RS inj_onD) newT_iso_inj_thms;
   1.303 -        val rewrites = constr_defs @ (map (mk_meta_eq o #2) newT_iso_axms)
   1.304 +        val rewrites = o_def :: constr_defs @ (map (mk_meta_eq o #2) newT_iso_axms)
   1.305        in prove_goalw_cterm [] (cterm_of (Theory.sign_of thy5) eqn) (fn _ =>
   1.306          [resolve_tac inj_thms 1,
   1.307           rewrite_goals_tac rewrites,
   1.308           rtac refl 1,
   1.309           resolve_tac rep_intrs 2,
   1.310 -         REPEAT (resolve_tac iso_elem_thms 1)])
   1.311 +         REPEAT (resolve_tac (FunsI :: iso_elem_thms) 1)])
   1.312        end;
   1.313  
   1.314      (*--------------------------------------------------------------*)
   1.315      (* constr_rep_thms and rep_congs are used to prove distinctness *)
   1.316 -    (* of constructors internally.                                  *)
   1.317 -    (* the external version uses dt_case which is not defined yet   *)
   1.318 +    (* of constructors.                                             *)
   1.319      (*--------------------------------------------------------------*)
   1.320  
   1.321      val constr_rep_thms = map (map prove_constr_rep_thm) constr_rep_eqns;
   1.322 @@ -467,27 +545,45 @@
   1.323        dist_lemma::(rep_thms @ [In0_eq, In1_eq, In0_not_In1, In1_not_In0]))
   1.324          (constr_rep_thms ~~ dist_lemmas);
   1.325  
   1.326 +    fun prove_distinct_thms (_, []) = []
   1.327 +      | prove_distinct_thms (dist_rewrites', t::_::ts) =
   1.328 +          let
   1.329 +            val dist_thm = prove_goalw_cterm [] (cterm_of (Theory.sign_of thy5) t) (fn _ =>
   1.330 +              [simp_tac (HOL_ss addsimps dist_rewrites') 1])
   1.331 +          in dist_thm::(standard (dist_thm RS not_sym))::
   1.332 +            (prove_distinct_thms (dist_rewrites', ts))
   1.333 +          end;
   1.334 +
   1.335 +    val distinct_thms = map prove_distinct_thms (dist_rewrites ~~
   1.336 +      DatatypeProp.make_distincts new_type_names descr sorts thy5);
   1.337 +
   1.338 +    val simproc_dists = map (fn ((((_, (_, _, constrs)), rep_thms), congr), dists) =>
   1.339 +      if length constrs < !DatatypeProp.dtK then FewConstrs dists
   1.340 +      else ManyConstrs (congr, HOL_basic_ss addsimps rep_thms)) (hd descr ~~
   1.341 +        constr_rep_thms ~~ rep_congs ~~ distinct_thms);
   1.342 +
   1.343      (* prove injectivity of constructors *)
   1.344  
   1.345      fun prove_constr_inj_thm rep_thms t =
   1.346 -      let val inj_thms = Scons_inject::(map make_elim
   1.347 +      let val inj_thms = Scons_inject::sum_case_inject::(map make_elim
   1.348          ((map (fn r => r RS injD) iso_inj_thms) @
   1.349 -          [In0_inject, In1_inject, Leaf_inject, Inl_inject, Inr_inject]))
   1.350 +          [In0_inject, In1_inject, Leaf_inject, Inl_inject, Inr_inject, Lim_inject]))
   1.351        in prove_goalw_cterm [] (cterm_of (Theory.sign_of thy5) t) (fn _ =>
   1.352          [rtac iffI 1,
   1.353           REPEAT (etac conjE 2), hyp_subst_tac 2, rtac refl 2,
   1.354           dresolve_tac rep_congs 1, dtac box_equals 1,
   1.355 -         REPEAT (resolve_tac rep_thms 1),
   1.356 +         REPEAT (resolve_tac rep_thms 1), rewrite_goals_tac [o_def],
   1.357           REPEAT (eresolve_tac inj_thms 1),
   1.358 -         hyp_subst_tac 1,
   1.359 -         REPEAT (resolve_tac [conjI, refl] 1)])
   1.360 +         REPEAT (ares_tac [conjI] 1 ORELSE (EVERY [rtac ext 1, dtac fun_cong 1,
   1.361 +                  eresolve_tac inj_thms 1, atac 1]))])
   1.362        end;
   1.363  
   1.364      val constr_inject = map (fn (ts, thms) => map (prove_constr_inj_thm thms) ts)
   1.365        ((DatatypeProp.make_injs descr sorts) ~~ constr_rep_thms);
   1.366  
   1.367 -    val thy6 = store_thmss "inject" new_type_names
   1.368 -      constr_inject (parent_path flat_names thy5);
   1.369 +    val thy6 = thy5 |> parent_path flat_names |>
   1.370 +      store_thmss "inject" new_type_names constr_inject |>
   1.371 +      store_thmss "distinct" new_type_names distinct_thms;
   1.372  
   1.373      (*************************** induction theorem ****************************)
   1.374  
   1.375 @@ -538,17 +634,18 @@
   1.376        (DatatypeProp.make_ind descr sorts)) (fn prems =>
   1.377          [rtac indrule_lemma' 1, indtac rep_induct 1,
   1.378           EVERY (map (fn (prem, r) => (EVERY
   1.379 -           [REPEAT (eresolve_tac Abs_inverse_thms 1),
   1.380 +           [REPEAT (eresolve_tac (Funs_IntE::Abs_inverse_thms) 1),
   1.381              simp_tac (HOL_basic_ss addsimps ((symmetric r)::Rep_inverse_thms')) 1,
   1.382 -            DEPTH_SOLVE_1 (ares_tac [prem] 1)]))
   1.383 -              (prems ~~ (constr_defs @ (map mk_meta_eq iso_char_thms))))]);
   1.384 +            DEPTH_SOLVE_1 (ares_tac [prem] 1 ORELSE (EVERY [rewrite_goals_tac [o_def],
   1.385 +              rtac allI 1, dtac FunsD 1, etac CollectD 1]))]))
   1.386 +                (prems ~~ (constr_defs @ (map mk_meta_eq iso_char_thms))))]);
   1.387  
   1.388      val thy7 = thy6 |>
   1.389        Theory.add_path big_name |>
   1.390        PureThy.add_thms [(("induct", dt_induct), [])] |>
   1.391        Theory.parent_path;
   1.392  
   1.393 -  in (thy7, constr_inject, dist_rewrites, dt_induct)
   1.394 +  in (thy7, constr_inject, distinct_thms, dist_rewrites, simproc_dists, dt_induct)
   1.395    end;
   1.396  
   1.397  end;