src/HOL/HOLCF/Tools/Domain/domain_constructors.ML
changeset 40774 0437dbc127b3
parent 40327 1dfdbd66093a
child 40832 4352ca878c41
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/HOLCF/Tools/Domain/domain_constructors.ML	Sat Nov 27 16:08:10 2010 -0800
     1.3 @@ -0,0 +1,975 @@
     1.4 +(*  Title:      HOLCF/Tools/Domain/domain_constructors.ML
     1.5 +    Author:     Brian Huffman
     1.6 +
     1.7 +Defines constructor functions for a given domain isomorphism
     1.8 +and proves related theorems.
     1.9 +*)
    1.10 +
    1.11 +signature DOMAIN_CONSTRUCTORS =
    1.12 +sig
    1.13 +  type constr_info =
    1.14 +    {
    1.15 +      iso_info : Domain_Take_Proofs.iso_info,
    1.16 +      con_specs : (term * (bool * typ) list) list,
    1.17 +      con_betas : thm list,
    1.18 +      nchotomy : thm,
    1.19 +      exhaust : thm,
    1.20 +      compacts : thm list,
    1.21 +      con_rews : thm list,
    1.22 +      inverts : thm list,
    1.23 +      injects : thm list,
    1.24 +      dist_les : thm list,
    1.25 +      dist_eqs : thm list,
    1.26 +      cases : thm list,
    1.27 +      sel_rews : thm list,
    1.28 +      dis_rews : thm list,
    1.29 +      match_rews : thm list
    1.30 +    }
    1.31 +  val add_domain_constructors :
    1.32 +      binding
    1.33 +      -> (binding * (bool * binding option * typ) list * mixfix) list
    1.34 +      -> Domain_Take_Proofs.iso_info
    1.35 +      -> theory
    1.36 +      -> constr_info * theory;
    1.37 +end;
    1.38 +
    1.39 +
    1.40 +structure Domain_Constructors :> DOMAIN_CONSTRUCTORS =
    1.41 +struct
    1.42 +
    1.43 +open HOLCF_Library;
    1.44 +
    1.45 +infixr 6 ->>;
    1.46 +infix -->>;
    1.47 +infix 9 `;
    1.48 +
    1.49 +type constr_info =
    1.50 +  {
    1.51 +    iso_info : Domain_Take_Proofs.iso_info,
    1.52 +    con_specs : (term * (bool * typ) list) list,
    1.53 +    con_betas : thm list,
    1.54 +    nchotomy : thm,
    1.55 +    exhaust : thm,
    1.56 +    compacts : thm list,
    1.57 +    con_rews : thm list,
    1.58 +    inverts : thm list,
    1.59 +    injects : thm list,
    1.60 +    dist_les : thm list,
    1.61 +    dist_eqs : thm list,
    1.62 +    cases : thm list,
    1.63 +    sel_rews : thm list,
    1.64 +    dis_rews : thm list,
    1.65 +    match_rews : thm list
    1.66 +  }
    1.67 +
    1.68 +(************************** miscellaneous functions ***************************)
    1.69 +
    1.70 +val simple_ss = HOL_basic_ss addsimps simp_thms;
    1.71 +
    1.72 +val beta_rules =
    1.73 +  @{thms beta_cfun cont_id cont_const cont2cont_APP cont2cont_LAM'} @
    1.74 +  @{thms cont2cont_fst cont2cont_snd cont2cont_Pair};
    1.75 +
    1.76 +val beta_ss = HOL_basic_ss addsimps (simp_thms @ beta_rules);
    1.77 +
    1.78 +fun define_consts
    1.79 +    (specs : (binding * term * mixfix) list)
    1.80 +    (thy : theory)
    1.81 +    : (term list * thm list) * theory =
    1.82 +  let
    1.83 +    fun mk_decl (b, t, mx) = (b, fastype_of t, mx);
    1.84 +    val decls = map mk_decl specs;
    1.85 +    val thy = Cont_Consts.add_consts decls thy;
    1.86 +    fun mk_const (b, T, mx) = Const (Sign.full_name thy b, T);
    1.87 +    val consts = map mk_const decls;
    1.88 +    fun mk_def c (b, t, mx) =
    1.89 +      (Binding.suffix_name "_def" b, Logic.mk_equals (c, t));
    1.90 +    val defs = map2 mk_def consts specs;
    1.91 +    val (def_thms, thy) =
    1.92 +      Global_Theory.add_defs false (map Thm.no_attributes defs) thy;
    1.93 +  in
    1.94 +    ((consts, def_thms), thy)
    1.95 +  end;
    1.96 +
    1.97 +fun prove
    1.98 +    (thy : theory)
    1.99 +    (defs : thm list)
   1.100 +    (goal : term)
   1.101 +    (tacs : {prems: thm list, context: Proof.context} -> tactic list)
   1.102 +    : thm =
   1.103 +  let
   1.104 +    fun tac {prems, context} =
   1.105 +      rewrite_goals_tac defs THEN
   1.106 +      EVERY (tacs {prems = map (rewrite_rule defs) prems, context = context})
   1.107 +  in
   1.108 +    Goal.prove_global thy [] [] goal tac
   1.109 +  end;
   1.110 +
   1.111 +fun get_vars_avoiding
   1.112 +    (taken : string list)
   1.113 +    (args : (bool * typ) list)
   1.114 +    : (term list * term list) =
   1.115 +  let
   1.116 +    val Ts = map snd args;
   1.117 +    val ns = Name.variant_list taken (Datatype_Prop.make_tnames Ts);
   1.118 +    val vs = map Free (ns ~~ Ts);
   1.119 +    val nonlazy = map snd (filter_out (fst o fst) (args ~~ vs));
   1.120 +  in
   1.121 +    (vs, nonlazy)
   1.122 +  end;
   1.123 +
   1.124 +fun get_vars args = get_vars_avoiding [] args;
   1.125 +
   1.126 +(************** generating beta reduction rules from definitions **************)
   1.127 +
   1.128 +local
   1.129 +  fun arglist (Const _ $ Abs (s, T, t)) =
   1.130 +      let
   1.131 +        val arg = Free (s, T);
   1.132 +        val (args, body) = arglist (subst_bound (arg, t));
   1.133 +      in (arg :: args, body) end
   1.134 +    | arglist t = ([], t);
   1.135 +in
   1.136 +  fun beta_of_def thy def_thm =
   1.137 +      let
   1.138 +        val (con, lam) = Logic.dest_equals (concl_of def_thm);
   1.139 +        val (args, rhs) = arglist lam;
   1.140 +        val lhs = list_ccomb (con, args);
   1.141 +        val goal = mk_equals (lhs, rhs);
   1.142 +        val cs = ContProc.cont_thms lam;
   1.143 +        val betas = map (fn c => mk_meta_eq (c RS @{thm beta_cfun})) cs;
   1.144 +      in
   1.145 +        prove thy (def_thm::betas) goal (K [rtac reflexive_thm 1])
   1.146 +      end;
   1.147 +end;
   1.148 +
   1.149 +(******************************************************************************)
   1.150 +(************* definitions and theorems for constructor functions *************)
   1.151 +(******************************************************************************)
   1.152 +
   1.153 +fun add_constructors
   1.154 +    (spec : (binding * (bool * typ) list * mixfix) list)
   1.155 +    (abs_const : term)
   1.156 +    (iso_locale : thm)
   1.157 +    (thy : theory)
   1.158 +    =
   1.159 +  let
   1.160 +
   1.161 +    (* get theorems about rep and abs *)
   1.162 +    val abs_strict = iso_locale RS @{thm iso.abs_strict};
   1.163 +
   1.164 +    (* get types of type isomorphism *)
   1.165 +    val (rhsT, lhsT) = dest_cfunT (fastype_of abs_const);
   1.166 +
   1.167 +    fun vars_of args =
   1.168 +      let
   1.169 +        val Ts = map snd args;
   1.170 +        val ns = Datatype_Prop.make_tnames Ts;
   1.171 +      in
   1.172 +        map Free (ns ~~ Ts)
   1.173 +      end;
   1.174 +
   1.175 +    (* define constructor functions *)
   1.176 +    val ((con_consts, con_defs), thy) =
   1.177 +      let
   1.178 +        fun one_arg (lazy, T) var = if lazy then mk_up var else var;
   1.179 +        fun one_con (_,args,_) = mk_stuple (map2 one_arg args (vars_of args));
   1.180 +        fun mk_abs t = abs_const ` t;
   1.181 +        val rhss = map mk_abs (mk_sinjects (map one_con spec));
   1.182 +        fun mk_def (bind, args, mx) rhs =
   1.183 +          (bind, big_lambdas (vars_of args) rhs, mx);
   1.184 +      in
   1.185 +        define_consts (map2 mk_def spec rhss) thy
   1.186 +      end;
   1.187 +
   1.188 +    (* prove beta reduction rules for constructors *)
   1.189 +    val con_betas = map (beta_of_def thy) con_defs;
   1.190 +
   1.191 +    (* replace bindings with terms in constructor spec *)
   1.192 +    val spec' : (term * (bool * typ) list) list =
   1.193 +      let fun one_con con (b, args, mx) = (con, args);
   1.194 +      in map2 one_con con_consts spec end;
   1.195 +
   1.196 +    (* prove exhaustiveness of constructors *)
   1.197 +    local
   1.198 +      fun arg2typ n (true,  T) = (n+1, mk_upT (TVar (("'a", n), @{sort cpo})))
   1.199 +        | arg2typ n (false, T) = (n+1, TVar (("'a", n), @{sort pcpo}));
   1.200 +      fun args2typ n [] = (n, oneT)
   1.201 +        | args2typ n [arg] = arg2typ n arg
   1.202 +        | args2typ n (arg::args) =
   1.203 +          let
   1.204 +            val (n1, t1) = arg2typ n arg;
   1.205 +            val (n2, t2) = args2typ n1 args
   1.206 +          in (n2, mk_sprodT (t1, t2)) end;
   1.207 +      fun cons2typ n [] = (n, oneT)
   1.208 +        | cons2typ n [con] = args2typ n (snd con)
   1.209 +        | cons2typ n (con::cons) =
   1.210 +          let
   1.211 +            val (n1, t1) = args2typ n (snd con);
   1.212 +            val (n2, t2) = cons2typ n1 cons
   1.213 +          in (n2, mk_ssumT (t1, t2)) end;
   1.214 +      val ct = ctyp_of thy (snd (cons2typ 1 spec'));
   1.215 +      val thm1 = instantiate' [SOME ct] [] @{thm exh_start};
   1.216 +      val thm2 = rewrite_rule (map mk_meta_eq @{thms ex_bottom_iffs}) thm1;
   1.217 +      val thm3 = rewrite_rule [mk_meta_eq @{thm conj_assoc}] thm2;
   1.218 +
   1.219 +      val y = Free ("y", lhsT);
   1.220 +      fun one_con (con, args) =
   1.221 +        let
   1.222 +          val (vs, nonlazy) = get_vars_avoiding ["y"] args;
   1.223 +          val eqn = mk_eq (y, list_ccomb (con, vs));
   1.224 +          val conj = foldr1 mk_conj (eqn :: map mk_defined nonlazy);
   1.225 +        in Library.foldr mk_ex (vs, conj) end;
   1.226 +      val goal = mk_trp (foldr1 mk_disj (mk_undef y :: map one_con spec'));
   1.227 +      (* first rules replace "y = UU \/ P" with "rep$y = UU \/ P" *)
   1.228 +      val tacs = [
   1.229 +          rtac (iso_locale RS @{thm iso.casedist_rule}) 1,
   1.230 +          rewrite_goals_tac [mk_meta_eq (iso_locale RS @{thm iso.iso_swap})],
   1.231 +          rtac thm3 1];
   1.232 +    in
   1.233 +      val nchotomy = prove thy con_betas goal (K tacs);
   1.234 +      val exhaust =
   1.235 +          (nchotomy RS @{thm exh_casedist0})
   1.236 +          |> rewrite_rule @{thms exh_casedists}
   1.237 +          |> Drule.zero_var_indexes;
   1.238 +    end;
   1.239 +
   1.240 +    (* prove compactness rules for constructors *)
   1.241 +    val compacts =
   1.242 +      let
   1.243 +        val rules = @{thms compact_sinl compact_sinr compact_spair
   1.244 +                           compact_up compact_ONE};
   1.245 +        val tacs =
   1.246 +          [rtac (iso_locale RS @{thm iso.compact_abs}) 1,
   1.247 +           REPEAT (resolve_tac rules 1 ORELSE atac 1)];
   1.248 +        fun con_compact (con, args) =
   1.249 +          let
   1.250 +            val vs = vars_of args;
   1.251 +            val con_app = list_ccomb (con, vs);
   1.252 +            val concl = mk_trp (mk_compact con_app);
   1.253 +            val assms = map (mk_trp o mk_compact) vs;
   1.254 +            val goal = Logic.list_implies (assms, concl);
   1.255 +          in
   1.256 +            prove thy con_betas goal (K tacs)
   1.257 +          end;
   1.258 +      in
   1.259 +        map con_compact spec'
   1.260 +      end;
   1.261 +
   1.262 +    (* prove strictness rules for constructors *)
   1.263 +    local
   1.264 +      fun con_strict (con, args) = 
   1.265 +        let
   1.266 +          val rules = abs_strict :: @{thms con_strict_rules};
   1.267 +          val (vs, nonlazy) = get_vars args;
   1.268 +          fun one_strict v' =
   1.269 +            let
   1.270 +              val UU = mk_bottom (fastype_of v');
   1.271 +              val vs' = map (fn v => if v = v' then UU else v) vs;
   1.272 +              val goal = mk_trp (mk_undef (list_ccomb (con, vs')));
   1.273 +              val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1];
   1.274 +            in prove thy con_betas goal (K tacs) end;
   1.275 +        in map one_strict nonlazy end;
   1.276 +
   1.277 +      fun con_defin (con, args) =
   1.278 +        let
   1.279 +          fun iff_disj (t, []) = HOLogic.mk_not t
   1.280 +            | iff_disj (t, ts) = mk_eq (t, foldr1 HOLogic.mk_disj ts);
   1.281 +          val (vs, nonlazy) = get_vars args;
   1.282 +          val lhs = mk_undef (list_ccomb (con, vs));
   1.283 +          val rhss = map mk_undef nonlazy;
   1.284 +          val goal = mk_trp (iff_disj (lhs, rhss));
   1.285 +          val rule1 = iso_locale RS @{thm iso.abs_bottom_iff};
   1.286 +          val rules = rule1 :: @{thms con_bottom_iff_rules};
   1.287 +          val tacs = [simp_tac (HOL_ss addsimps rules) 1];
   1.288 +        in prove thy con_betas goal (K tacs) end;
   1.289 +    in
   1.290 +      val con_stricts = maps con_strict spec';
   1.291 +      val con_defins = map con_defin spec';
   1.292 +      val con_rews = con_stricts @ con_defins;
   1.293 +    end;
   1.294 +
   1.295 +    (* prove injectiveness of constructors *)
   1.296 +    local
   1.297 +      fun pgterm rel (con, args) =
   1.298 +        let
   1.299 +          fun prime (Free (n, T)) = Free (n^"'", T)
   1.300 +            | prime t             = t;
   1.301 +          val (xs, nonlazy) = get_vars args;
   1.302 +          val ys = map prime xs;
   1.303 +          val lhs = rel (list_ccomb (con, xs), list_ccomb (con, ys));
   1.304 +          val rhs = foldr1 mk_conj (ListPair.map rel (xs, ys));
   1.305 +          val concl = mk_trp (mk_eq (lhs, rhs));
   1.306 +          val zs = case args of [_] => [] | _ => nonlazy;
   1.307 +          val assms = map (mk_trp o mk_defined) zs;
   1.308 +          val goal = Logic.list_implies (assms, concl);
   1.309 +        in prove thy con_betas goal end;
   1.310 +      val cons' = filter (fn (_, args) => not (null args)) spec';
   1.311 +    in
   1.312 +      val inverts =
   1.313 +        let
   1.314 +          val abs_below = iso_locale RS @{thm iso.abs_below};
   1.315 +          val rules1 = abs_below :: @{thms sinl_below sinr_below spair_below up_below};
   1.316 +          val rules2 = @{thms up_defined spair_defined ONE_defined}
   1.317 +          val rules = rules1 @ rules2;
   1.318 +          val tacs = [asm_simp_tac (simple_ss addsimps rules) 1];
   1.319 +        in map (fn c => pgterm mk_below c (K tacs)) cons' end;
   1.320 +      val injects =
   1.321 +        let
   1.322 +          val abs_eq = iso_locale RS @{thm iso.abs_eq};
   1.323 +          val rules1 = abs_eq :: @{thms sinl_eq sinr_eq spair_eq up_eq};
   1.324 +          val rules2 = @{thms up_defined spair_defined ONE_defined}
   1.325 +          val rules = rules1 @ rules2;
   1.326 +          val tacs = [asm_simp_tac (simple_ss addsimps rules) 1];
   1.327 +        in map (fn c => pgterm mk_eq c (K tacs)) cons' end;
   1.328 +    end;
   1.329 +
   1.330 +    (* prove distinctness of constructors *)
   1.331 +    local
   1.332 +      fun map_dist (f : 'a -> 'a -> 'b) (xs : 'a list) : 'b list =
   1.333 +        flat (map_index (fn (i, x) => map (f x) (nth_drop i xs)) xs);
   1.334 +      fun prime (Free (n, T)) = Free (n^"'", T)
   1.335 +        | prime t             = t;
   1.336 +      fun iff_disj (t, []) = mk_not t
   1.337 +        | iff_disj (t, ts) = mk_eq (t, foldr1 mk_disj ts);
   1.338 +      fun iff_disj2 (t, [], us) = mk_not t
   1.339 +        | iff_disj2 (t, ts, []) = mk_not t
   1.340 +        | iff_disj2 (t, ts, us) =
   1.341 +          mk_eq (t, mk_conj (foldr1 mk_disj ts, foldr1 mk_disj us));
   1.342 +      fun dist_le (con1, args1) (con2, args2) =
   1.343 +        let
   1.344 +          val (vs1, zs1) = get_vars args1;
   1.345 +          val (vs2, zs2) = get_vars args2 |> pairself (map prime);
   1.346 +          val lhs = mk_below (list_ccomb (con1, vs1), list_ccomb (con2, vs2));
   1.347 +          val rhss = map mk_undef zs1;
   1.348 +          val goal = mk_trp (iff_disj (lhs, rhss));
   1.349 +          val rule1 = iso_locale RS @{thm iso.abs_below};
   1.350 +          val rules = rule1 :: @{thms con_below_iff_rules};
   1.351 +          val tacs = [simp_tac (HOL_ss addsimps rules) 1];
   1.352 +        in prove thy con_betas goal (K tacs) end;
   1.353 +      fun dist_eq (con1, args1) (con2, args2) =
   1.354 +        let
   1.355 +          val (vs1, zs1) = get_vars args1;
   1.356 +          val (vs2, zs2) = get_vars args2 |> pairself (map prime);
   1.357 +          val lhs = mk_eq (list_ccomb (con1, vs1), list_ccomb (con2, vs2));
   1.358 +          val rhss1 = map mk_undef zs1;
   1.359 +          val rhss2 = map mk_undef zs2;
   1.360 +          val goal = mk_trp (iff_disj2 (lhs, rhss1, rhss2));
   1.361 +          val rule1 = iso_locale RS @{thm iso.abs_eq};
   1.362 +          val rules = rule1 :: @{thms con_eq_iff_rules};
   1.363 +          val tacs = [simp_tac (HOL_ss addsimps rules) 1];
   1.364 +        in prove thy con_betas goal (K tacs) end;
   1.365 +    in
   1.366 +      val dist_les = map_dist dist_le spec';
   1.367 +      val dist_eqs = map_dist dist_eq spec';
   1.368 +    end;
   1.369 +
   1.370 +    val result =
   1.371 +      {
   1.372 +        con_consts = con_consts,
   1.373 +        con_betas = con_betas,
   1.374 +        nchotomy = nchotomy,
   1.375 +        exhaust = exhaust,
   1.376 +        compacts = compacts,
   1.377 +        con_rews = con_rews,
   1.378 +        inverts = inverts,
   1.379 +        injects = injects,
   1.380 +        dist_les = dist_les,
   1.381 +        dist_eqs = dist_eqs
   1.382 +      };
   1.383 +  in
   1.384 +    (result, thy)
   1.385 +  end;
   1.386 +
   1.387 +(******************************************************************************)
   1.388 +(**************** definition and theorems for case combinator *****************)
   1.389 +(******************************************************************************)
   1.390 +
   1.391 +fun add_case_combinator
   1.392 +    (spec : (term * (bool * typ) list) list)
   1.393 +    (lhsT : typ)
   1.394 +    (dbind : binding)
   1.395 +    (con_betas : thm list)
   1.396 +    (exhaust : thm)
   1.397 +    (iso_locale : thm)
   1.398 +    (rep_const : term)
   1.399 +    (thy : theory)
   1.400 +    : ((typ -> term) * thm list) * theory =
   1.401 +  let
   1.402 +
   1.403 +    (* prove rep/abs rules *)
   1.404 +    val rep_strict = iso_locale RS @{thm iso.rep_strict};
   1.405 +    val abs_inverse = iso_locale RS @{thm iso.abs_iso};
   1.406 +
   1.407 +    (* calculate function arguments of case combinator *)
   1.408 +    val tns = map fst (Term.add_tfreesT lhsT []);
   1.409 +    val resultT = TFree (Name.variant tns "'t", @{sort pcpo});
   1.410 +    fun fTs T = map (fn (_, args) => map snd args -->> T) spec;
   1.411 +    val fns = Datatype_Prop.indexify_names (map (K "f") spec);
   1.412 +    val fs = map Free (fns ~~ fTs resultT);
   1.413 +    fun caseT T = fTs T -->> (lhsT ->> T);
   1.414 +
   1.415 +    (* definition of case combinator *)
   1.416 +    local
   1.417 +      val case_bind = Binding.suffix_name "_case" dbind;
   1.418 +      fun lambda_arg (lazy, v) t =
   1.419 +          (if lazy then mk_fup else I) (big_lambda v t);
   1.420 +      fun lambda_args []      t = mk_one_case t
   1.421 +        | lambda_args (x::[]) t = lambda_arg x t
   1.422 +        | lambda_args (x::xs) t = mk_ssplit (lambda_arg x (lambda_args xs t));
   1.423 +      fun one_con f (_, args) =
   1.424 +        let
   1.425 +          val Ts = map snd args;
   1.426 +          val ns = Name.variant_list fns (Datatype_Prop.make_tnames Ts);
   1.427 +          val vs = map Free (ns ~~ Ts);
   1.428 +        in
   1.429 +          lambda_args (map fst args ~~ vs) (list_ccomb (f, vs))
   1.430 +        end;
   1.431 +      fun mk_sscases [t] = mk_strictify t
   1.432 +        | mk_sscases ts = foldr1 mk_sscase ts;
   1.433 +      val body = mk_sscases (map2 one_con fs spec);
   1.434 +      val rhs = big_lambdas fs (mk_cfcomp (body, rep_const));
   1.435 +      val ((case_consts, case_defs), thy) =
   1.436 +          define_consts [(case_bind, rhs, NoSyn)] thy;
   1.437 +      val case_name = Sign.full_name thy case_bind;
   1.438 +    in
   1.439 +      val case_def = hd case_defs;
   1.440 +      fun case_const T = Const (case_name, caseT T);
   1.441 +      val case_app = list_ccomb (case_const resultT, fs);
   1.442 +      val thy = thy;
   1.443 +    end;
   1.444 +
   1.445 +    (* define syntax for case combinator *)
   1.446 +    (* TODO: re-implement case syntax using a parse translation *)
   1.447 +    local
   1.448 +      open Syntax
   1.449 +      fun syntax c = Syntax.mark_const (fst (dest_Const c));
   1.450 +      fun xconst c = Long_Name.base_name (fst (dest_Const c));
   1.451 +      fun c_ast authentic con =
   1.452 +          Constant (if authentic then syntax con else xconst con);
   1.453 +      fun showint n = string_of_int (n+1);
   1.454 +      fun expvar n = Variable ("e" ^ showint n);
   1.455 +      fun argvar n (m, _) = Variable ("a" ^ showint n ^ "_" ^ showint m);
   1.456 +      fun argvars n args = map_index (argvar n) args;
   1.457 +      fun app s (l, r) = mk_appl (Constant s) [l, r];
   1.458 +      val cabs = app "_cabs";
   1.459 +      val capp = app @{const_syntax Rep_cfun};
   1.460 +      val capps = Library.foldl capp
   1.461 +      fun con1 authentic n (con,args) =
   1.462 +          Library.foldl capp (c_ast authentic con, argvars n args);
   1.463 +      fun case1 authentic (n, c) =
   1.464 +          app "_case1" (con1 authentic n c, expvar n);
   1.465 +      fun arg1 (n, (con,args)) = List.foldr cabs (expvar n) (argvars n args);
   1.466 +      fun when1 n (m, c) =
   1.467 +          if n = m then arg1 (n, c) else (Constant @{const_syntax UU});
   1.468 +      val case_constant = Constant (syntax (case_const dummyT));
   1.469 +      fun case_trans authentic =
   1.470 +          ParsePrintRule
   1.471 +            (app "_case_syntax"
   1.472 +              (Variable "x",
   1.473 +               foldr1 (app "_case2") (map_index (case1 authentic) spec)),
   1.474 +             capp (capps (case_constant, map_index arg1 spec), Variable "x"));
   1.475 +      fun one_abscon_trans authentic (n, c) =
   1.476 +          ParsePrintRule
   1.477 +            (cabs (con1 authentic n c, expvar n),
   1.478 +             capps (case_constant, map_index (when1 n) spec));
   1.479 +      fun abscon_trans authentic =
   1.480 +          map_index (one_abscon_trans authentic) spec;
   1.481 +      val trans_rules : ast Syntax.trrule list =
   1.482 +          case_trans false :: case_trans true ::
   1.483 +          abscon_trans false @ abscon_trans true;
   1.484 +    in
   1.485 +      val thy = Sign.add_trrules_i trans_rules thy;
   1.486 +    end;
   1.487 +
   1.488 +    (* prove beta reduction rule for case combinator *)
   1.489 +    val case_beta = beta_of_def thy case_def;
   1.490 +
   1.491 +    (* prove strictness of case combinator *)
   1.492 +    val case_strict =
   1.493 +      let
   1.494 +        val defs = case_beta :: map mk_meta_eq [rep_strict, @{thm cfcomp2}];
   1.495 +        val goal = mk_trp (mk_strict case_app);
   1.496 +        val rules = @{thms sscase1 ssplit1 strictify1 one_case1};
   1.497 +        val tacs = [resolve_tac rules 1];
   1.498 +      in prove thy defs goal (K tacs) end;
   1.499 +        
   1.500 +    (* prove rewrites for case combinator *)
   1.501 +    local
   1.502 +      fun one_case (con, args) f =
   1.503 +        let
   1.504 +          val (vs, nonlazy) = get_vars args;
   1.505 +          val assms = map (mk_trp o mk_defined) nonlazy;
   1.506 +          val lhs = case_app ` list_ccomb (con, vs);
   1.507 +          val rhs = list_ccomb (f, vs);
   1.508 +          val concl = mk_trp (mk_eq (lhs, rhs));
   1.509 +          val goal = Logic.list_implies (assms, concl);
   1.510 +          val defs = case_beta :: con_betas;
   1.511 +          val rules1 = @{thms strictify2 sscase2 sscase3 ssplit2 fup2 ID1};
   1.512 +          val rules2 = @{thms con_bottom_iff_rules};
   1.513 +          val rules3 = @{thms cfcomp2 one_case2};
   1.514 +          val rules = abs_inverse :: rules1 @ rules2 @ rules3;
   1.515 +          val tacs = [asm_simp_tac (beta_ss addsimps rules) 1];
   1.516 +        in prove thy defs goal (K tacs) end;
   1.517 +    in
   1.518 +      val case_apps = map2 one_case spec fs;
   1.519 +    end
   1.520 +
   1.521 +  in
   1.522 +    ((case_const, case_strict :: case_apps), thy)
   1.523 +  end
   1.524 +
   1.525 +(******************************************************************************)
   1.526 +(************** definitions and theorems for selector functions ***************)
   1.527 +(******************************************************************************)
   1.528 +
   1.529 +fun add_selectors
   1.530 +    (spec : (term * (bool * binding option * typ) list) list)
   1.531 +    (rep_const : term)
   1.532 +    (abs_inv : thm)
   1.533 +    (rep_strict : thm)
   1.534 +    (rep_bottom_iff : thm)
   1.535 +    (con_betas : thm list)
   1.536 +    (thy : theory)
   1.537 +    : thm list * theory =
   1.538 +  let
   1.539 +
   1.540 +    (* define selector functions *)
   1.541 +    val ((sel_consts, sel_defs), thy) =
   1.542 +      let
   1.543 +        fun rangeT s = snd (dest_cfunT (fastype_of s));
   1.544 +        fun mk_outl s = mk_cfcomp (from_sinl (dest_ssumT (rangeT s)), s);
   1.545 +        fun mk_outr s = mk_cfcomp (from_sinr (dest_ssumT (rangeT s)), s);
   1.546 +        fun mk_sfst s = mk_cfcomp (sfst_const (dest_sprodT (rangeT s)), s);
   1.547 +        fun mk_ssnd s = mk_cfcomp (ssnd_const (dest_sprodT (rangeT s)), s);
   1.548 +        fun mk_down s = mk_cfcomp (from_up (dest_upT (rangeT s)), s);
   1.549 +
   1.550 +        fun sels_of_arg s (lazy, NONE,   T) = []
   1.551 +          | sels_of_arg s (lazy, SOME b, T) =
   1.552 +            [(b, if lazy then mk_down s else s, NoSyn)];
   1.553 +        fun sels_of_args s [] = []
   1.554 +          | sels_of_args s (v :: []) = sels_of_arg s v
   1.555 +          | sels_of_args s (v :: vs) =
   1.556 +            sels_of_arg (mk_sfst s) v @ sels_of_args (mk_ssnd s) vs;
   1.557 +        fun sels_of_cons s [] = []
   1.558 +          | sels_of_cons s ((con, args) :: []) = sels_of_args s args
   1.559 +          | sels_of_cons s ((con, args) :: cs) =
   1.560 +            sels_of_args (mk_outl s) args @ sels_of_cons (mk_outr s) cs;
   1.561 +        val sel_eqns : (binding * term * mixfix) list =
   1.562 +            sels_of_cons rep_const spec;
   1.563 +      in
   1.564 +        define_consts sel_eqns thy
   1.565 +      end
   1.566 +
   1.567 +    (* replace bindings with terms in constructor spec *)
   1.568 +    val spec2 : (term * (bool * term option * typ) list) list =
   1.569 +      let
   1.570 +        fun prep_arg (lazy, NONE, T) sels = ((lazy, NONE, T), sels)
   1.571 +          | prep_arg (lazy, SOME _, T) sels =
   1.572 +            ((lazy, SOME (hd sels), T), tl sels);
   1.573 +        fun prep_con (con, args) sels =
   1.574 +            apfst (pair con) (fold_map prep_arg args sels);
   1.575 +      in
   1.576 +        fst (fold_map prep_con spec sel_consts)
   1.577 +      end;
   1.578 +
   1.579 +    (* prove selector strictness rules *)
   1.580 +    val sel_stricts : thm list =
   1.581 +      let
   1.582 +        val rules = rep_strict :: @{thms sel_strict_rules};
   1.583 +        val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1];
   1.584 +        fun sel_strict sel =
   1.585 +          let
   1.586 +            val goal = mk_trp (mk_strict sel);
   1.587 +          in
   1.588 +            prove thy sel_defs goal (K tacs)
   1.589 +          end
   1.590 +      in
   1.591 +        map sel_strict sel_consts
   1.592 +      end
   1.593 +
   1.594 +    (* prove selector application rules *)
   1.595 +    val sel_apps : thm list =
   1.596 +      let
   1.597 +        val defs = con_betas @ sel_defs;
   1.598 +        val rules = abs_inv :: @{thms sel_app_rules};
   1.599 +        val tacs = [asm_simp_tac (simple_ss addsimps rules) 1];
   1.600 +        fun sel_apps_of (i, (con, args: (bool * term option * typ) list)) =
   1.601 +          let
   1.602 +            val Ts : typ list = map #3 args;
   1.603 +            val ns : string list = Datatype_Prop.make_tnames Ts;
   1.604 +            val vs : term list = map Free (ns ~~ Ts);
   1.605 +            val con_app : term = list_ccomb (con, vs);
   1.606 +            val vs' : (bool * term) list = map #1 args ~~ vs;
   1.607 +            fun one_same (n, sel, T) =
   1.608 +              let
   1.609 +                val xs = map snd (filter_out fst (nth_drop n vs'));
   1.610 +                val assms = map (mk_trp o mk_defined) xs;
   1.611 +                val concl = mk_trp (mk_eq (sel ` con_app, nth vs n));
   1.612 +                val goal = Logic.list_implies (assms, concl);
   1.613 +              in
   1.614 +                prove thy defs goal (K tacs)
   1.615 +              end;
   1.616 +            fun one_diff (n, sel, T) =
   1.617 +              let
   1.618 +                val goal = mk_trp (mk_eq (sel ` con_app, mk_bottom T));
   1.619 +              in
   1.620 +                prove thy defs goal (K tacs)
   1.621 +              end;
   1.622 +            fun one_con (j, (_, args')) : thm list =
   1.623 +              let
   1.624 +                fun prep (i, (lazy, NONE, T)) = NONE
   1.625 +                  | prep (i, (lazy, SOME sel, T)) = SOME (i, sel, T);
   1.626 +                val sels : (int * term * typ) list =
   1.627 +                  map_filter prep (map_index I args');
   1.628 +              in
   1.629 +                if i = j
   1.630 +                then map one_same sels
   1.631 +                else map one_diff sels
   1.632 +              end
   1.633 +          in
   1.634 +            flat (map_index one_con spec2)
   1.635 +          end
   1.636 +      in
   1.637 +        flat (map_index sel_apps_of spec2)
   1.638 +      end
   1.639 +
   1.640 +  (* prove selector definedness rules *)
   1.641 +    val sel_defins : thm list =
   1.642 +      let
   1.643 +        val rules = rep_bottom_iff :: @{thms sel_bottom_iff_rules};
   1.644 +        val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1];
   1.645 +        fun sel_defin sel =
   1.646 +          let
   1.647 +            val (T, U) = dest_cfunT (fastype_of sel);
   1.648 +            val x = Free ("x", T);
   1.649 +            val lhs = mk_eq (sel ` x, mk_bottom U);
   1.650 +            val rhs = mk_eq (x, mk_bottom T);
   1.651 +            val goal = mk_trp (mk_eq (lhs, rhs));
   1.652 +          in
   1.653 +            prove thy sel_defs goal (K tacs)
   1.654 +          end
   1.655 +        fun one_arg (false, SOME sel, T) = SOME (sel_defin sel)
   1.656 +          | one_arg _                    = NONE;
   1.657 +      in
   1.658 +        case spec2 of
   1.659 +          [(con, args)] => map_filter one_arg args
   1.660 +        | _             => []
   1.661 +      end;
   1.662 +
   1.663 +  in
   1.664 +    (sel_stricts @ sel_defins @ sel_apps, thy)
   1.665 +  end
   1.666 +
   1.667 +(******************************************************************************)
   1.668 +(************ definitions and theorems for discriminator functions ************)
   1.669 +(******************************************************************************)
   1.670 +
   1.671 +fun add_discriminators
   1.672 +    (bindings : binding list)
   1.673 +    (spec : (term * (bool * typ) list) list)
   1.674 +    (lhsT : typ)
   1.675 +    (exhaust : thm)
   1.676 +    (case_const : typ -> term)
   1.677 +    (case_rews : thm list)
   1.678 +    (thy : theory) =
   1.679 +  let
   1.680 +
   1.681 +    fun vars_of args =
   1.682 +      let
   1.683 +        val Ts = map snd args;
   1.684 +        val ns = Datatype_Prop.make_tnames Ts;
   1.685 +      in
   1.686 +        map Free (ns ~~ Ts)
   1.687 +      end;
   1.688 +
   1.689 +    (* define discriminator functions *)
   1.690 +    local
   1.691 +      fun dis_fun i (j, (con, args)) =
   1.692 +        let
   1.693 +          val (vs, nonlazy) = get_vars args;
   1.694 +          val tr = if i = j then @{term TT} else @{term FF};
   1.695 +        in
   1.696 +          big_lambdas vs tr
   1.697 +        end;
   1.698 +      fun dis_eqn (i, bind) : binding * term * mixfix =
   1.699 +        let
   1.700 +          val dis_bind = Binding.prefix_name "is_" bind;
   1.701 +          val rhs = list_ccomb (case_const trT, map_index (dis_fun i) spec);
   1.702 +        in
   1.703 +          (dis_bind, rhs, NoSyn)
   1.704 +        end;
   1.705 +    in
   1.706 +      val ((dis_consts, dis_defs), thy) =
   1.707 +          define_consts (map_index dis_eqn bindings) thy
   1.708 +    end;
   1.709 +
   1.710 +    (* prove discriminator strictness rules *)
   1.711 +    local
   1.712 +      fun dis_strict dis =
   1.713 +        let val goal = mk_trp (mk_strict dis);
   1.714 +        in prove thy dis_defs goal (K [rtac (hd case_rews) 1]) end;
   1.715 +    in
   1.716 +      val dis_stricts = map dis_strict dis_consts;
   1.717 +    end;
   1.718 +
   1.719 +    (* prove discriminator/constructor rules *)
   1.720 +    local
   1.721 +      fun dis_app (i, dis) (j, (con, args)) =
   1.722 +        let
   1.723 +          val (vs, nonlazy) = get_vars args;
   1.724 +          val lhs = dis ` list_ccomb (con, vs);
   1.725 +          val rhs = if i = j then @{term TT} else @{term FF};
   1.726 +          val assms = map (mk_trp o mk_defined) nonlazy;
   1.727 +          val concl = mk_trp (mk_eq (lhs, rhs));
   1.728 +          val goal = Logic.list_implies (assms, concl);
   1.729 +          val tacs = [asm_simp_tac (beta_ss addsimps case_rews) 1];
   1.730 +        in prove thy dis_defs goal (K tacs) end;
   1.731 +      fun one_dis (i, dis) =
   1.732 +          map_index (dis_app (i, dis)) spec;
   1.733 +    in
   1.734 +      val dis_apps = flat (map_index one_dis dis_consts);
   1.735 +    end;
   1.736 +
   1.737 +    (* prove discriminator definedness rules *)
   1.738 +    local
   1.739 +      fun dis_defin dis =
   1.740 +        let
   1.741 +          val x = Free ("x", lhsT);
   1.742 +          val simps = dis_apps @ @{thms dist_eq_tr};
   1.743 +          val tacs =
   1.744 +            [rtac @{thm iffI} 1,
   1.745 +             asm_simp_tac (HOL_basic_ss addsimps dis_stricts) 2,
   1.746 +             rtac exhaust 1, atac 1,
   1.747 +             DETERM_UNTIL_SOLVED (CHANGED
   1.748 +               (asm_full_simp_tac (simple_ss addsimps simps) 1))];
   1.749 +          val goal = mk_trp (mk_eq (mk_undef (dis ` x), mk_undef x));
   1.750 +        in prove thy [] goal (K tacs) end;
   1.751 +    in
   1.752 +      val dis_defins = map dis_defin dis_consts;
   1.753 +    end;
   1.754 +
   1.755 +  in
   1.756 +    (dis_stricts @ dis_defins @ dis_apps, thy)
   1.757 +  end;
   1.758 +
   1.759 +(******************************************************************************)
   1.760 +(*************** definitions and theorems for match combinators ***************)
   1.761 +(******************************************************************************)
   1.762 +
   1.763 +fun add_match_combinators
   1.764 +    (bindings : binding list)
   1.765 +    (spec : (term * (bool * typ) list) list)
   1.766 +    (lhsT : typ)
   1.767 +    (exhaust : thm)
   1.768 +    (case_const : typ -> term)
   1.769 +    (case_rews : thm list)
   1.770 +    (thy : theory) =
   1.771 +  let
   1.772 +
   1.773 +    (* get a fresh type variable for the result type *)
   1.774 +    val resultT : typ =
   1.775 +      let
   1.776 +        val ts : string list = map fst (Term.add_tfreesT lhsT []);
   1.777 +        val t : string = Name.variant ts "'t";
   1.778 +      in TFree (t, @{sort pcpo}) end;
   1.779 +
   1.780 +    (* define match combinators *)
   1.781 +    local
   1.782 +      val x = Free ("x", lhsT);
   1.783 +      fun k args = Free ("k", map snd args -->> mk_matchT resultT);
   1.784 +      val fail = mk_fail resultT;
   1.785 +      fun mat_fun i (j, (con, args)) =
   1.786 +        let
   1.787 +          val (vs, nonlazy) = get_vars_avoiding ["x","k"] args;
   1.788 +        in
   1.789 +          if i = j then k args else big_lambdas vs fail
   1.790 +        end;
   1.791 +      fun mat_eqn (i, (bind, (con, args))) : binding * term * mixfix =
   1.792 +        let
   1.793 +          val mat_bind = Binding.prefix_name "match_" bind;
   1.794 +          val funs = map_index (mat_fun i) spec
   1.795 +          val body = list_ccomb (case_const (mk_matchT resultT), funs);
   1.796 +          val rhs = big_lambda x (big_lambda (k args) (body ` x));
   1.797 +        in
   1.798 +          (mat_bind, rhs, NoSyn)
   1.799 +        end;
   1.800 +    in
   1.801 +      val ((match_consts, match_defs), thy) =
   1.802 +          define_consts (map_index mat_eqn (bindings ~~ spec)) thy
   1.803 +    end;
   1.804 +
   1.805 +    (* register match combinators with fixrec package *)
   1.806 +    local
   1.807 +      val con_names = map (fst o dest_Const o fst) spec;
   1.808 +      val mat_names = map (fst o dest_Const) match_consts;
   1.809 +    in
   1.810 +      val thy = Fixrec.add_matchers (con_names ~~ mat_names) thy;
   1.811 +    end;
   1.812 +
   1.813 +    (* prove strictness of match combinators *)
   1.814 +    local
   1.815 +      fun match_strict mat =
   1.816 +        let
   1.817 +          val (T, (U, V)) = apsnd dest_cfunT (dest_cfunT (fastype_of mat));
   1.818 +          val k = Free ("k", U);
   1.819 +          val goal = mk_trp (mk_eq (mat ` mk_bottom T ` k, mk_bottom V));
   1.820 +          val tacs = [asm_simp_tac (beta_ss addsimps case_rews) 1];
   1.821 +        in prove thy match_defs goal (K tacs) end;
   1.822 +    in
   1.823 +      val match_stricts = map match_strict match_consts;
   1.824 +    end;
   1.825 +
   1.826 +    (* prove match/constructor rules *)
   1.827 +    local
   1.828 +      val fail = mk_fail resultT;
   1.829 +      fun match_app (i, mat) (j, (con, args)) =
   1.830 +        let
   1.831 +          val (vs, nonlazy) = get_vars_avoiding ["k"] args;
   1.832 +          val (_, (kT, _)) = apsnd dest_cfunT (dest_cfunT (fastype_of mat));
   1.833 +          val k = Free ("k", kT);
   1.834 +          val lhs = mat ` list_ccomb (con, vs) ` k;
   1.835 +          val rhs = if i = j then list_ccomb (k, vs) else fail;
   1.836 +          val assms = map (mk_trp o mk_defined) nonlazy;
   1.837 +          val concl = mk_trp (mk_eq (lhs, rhs));
   1.838 +          val goal = Logic.list_implies (assms, concl);
   1.839 +          val tacs = [asm_simp_tac (beta_ss addsimps case_rews) 1];
   1.840 +        in prove thy match_defs goal (K tacs) end;
   1.841 +      fun one_match (i, mat) =
   1.842 +          map_index (match_app (i, mat)) spec;
   1.843 +    in
   1.844 +      val match_apps = flat (map_index one_match match_consts);
   1.845 +    end;
   1.846 +
   1.847 +  in
   1.848 +    (match_stricts @ match_apps, thy)
   1.849 +  end;
   1.850 +
   1.851 +(******************************************************************************)
   1.852 +(******************************* main function ********************************)
   1.853 +(******************************************************************************)
   1.854 +
   1.855 +fun add_domain_constructors
   1.856 +    (dbind : binding)
   1.857 +    (spec : (binding * (bool * binding option * typ) list * mixfix) list)
   1.858 +    (iso_info : Domain_Take_Proofs.iso_info)
   1.859 +    (thy : theory) =
   1.860 +  let
   1.861 +    val dname = Binding.name_of dbind;
   1.862 +    val _ = writeln ("Proving isomorphism properties of domain "^dname^" ...");
   1.863 +
   1.864 +    val bindings = map #1 spec;
   1.865 +
   1.866 +    (* retrieve facts about rep/abs *)
   1.867 +    val lhsT = #absT iso_info;
   1.868 +    val {rep_const, abs_const, ...} = iso_info;
   1.869 +    val abs_iso_thm = #abs_inverse iso_info;
   1.870 +    val rep_iso_thm = #rep_inverse iso_info;
   1.871 +    val iso_locale = @{thm iso.intro} OF [abs_iso_thm, rep_iso_thm];
   1.872 +    val rep_strict = iso_locale RS @{thm iso.rep_strict};
   1.873 +    val abs_strict = iso_locale RS @{thm iso.abs_strict};
   1.874 +    val rep_bottom_iff = iso_locale RS @{thm iso.rep_bottom_iff};
   1.875 +    val abs_bottom_iff = iso_locale RS @{thm iso.abs_bottom_iff};
   1.876 +    val iso_rews = [abs_iso_thm, rep_iso_thm, abs_strict, rep_strict];
   1.877 +
   1.878 +    (* qualify constants and theorems with domain name *)
   1.879 +    val thy = Sign.add_path dname thy;
   1.880 +
   1.881 +    (* define constructor functions *)
   1.882 +    val (con_result, thy) =
   1.883 +      let
   1.884 +        fun prep_arg (lazy, sel, T) = (lazy, T);
   1.885 +        fun prep_con (b, args, mx) = (b, map prep_arg args, mx);
   1.886 +        val con_spec = map prep_con spec;
   1.887 +      in
   1.888 +        add_constructors con_spec abs_const iso_locale thy
   1.889 +      end;
   1.890 +    val {con_consts, con_betas, nchotomy, exhaust, compacts, con_rews,
   1.891 +          inverts, injects, dist_les, dist_eqs} = con_result;
   1.892 +
   1.893 +    (* prepare constructor spec *)
   1.894 +    val con_specs : (term * (bool * typ) list) list =
   1.895 +      let
   1.896 +        fun prep_arg (lazy, sel, T) = (lazy, T);
   1.897 +        fun prep_con c (b, args, mx) = (c, map prep_arg args);
   1.898 +      in
   1.899 +        map2 prep_con con_consts spec
   1.900 +      end;
   1.901 +
   1.902 +    (* define case combinator *)
   1.903 +    val ((case_const : typ -> term, cases : thm list), thy) =
   1.904 +        add_case_combinator con_specs lhsT dbind
   1.905 +          con_betas exhaust iso_locale rep_const thy
   1.906 +
   1.907 +    (* define and prove theorems for selector functions *)
   1.908 +    val (sel_thms : thm list, thy : theory) =
   1.909 +      let
   1.910 +        val sel_spec : (term * (bool * binding option * typ) list) list =
   1.911 +          map2 (fn con => fn (b, args, mx) => (con, args)) con_consts spec;
   1.912 +      in
   1.913 +        add_selectors sel_spec rep_const
   1.914 +          abs_iso_thm rep_strict rep_bottom_iff con_betas thy
   1.915 +      end;
   1.916 +
   1.917 +    (* define and prove theorems for discriminator functions *)
   1.918 +    val (dis_thms : thm list, thy : theory) =
   1.919 +        add_discriminators bindings con_specs lhsT
   1.920 +          exhaust case_const cases thy;
   1.921 +
   1.922 +    (* define and prove theorems for match combinators *)
   1.923 +    val (match_thms : thm list, thy : theory) =
   1.924 +        add_match_combinators bindings con_specs lhsT
   1.925 +          exhaust case_const cases thy;
   1.926 +
   1.927 +    (* restore original signature path *)
   1.928 +    val thy = Sign.parent_path thy;
   1.929 +
   1.930 +    (* bind theorem names in global theory *)
   1.931 +    val (_, thy) =
   1.932 +      let
   1.933 +        fun qualified name = Binding.qualified true name dbind;
   1.934 +        val names = "bottom" :: map (fn (b,_,_) => Binding.name_of b) spec;
   1.935 +        val dname = fst (dest_Type lhsT);
   1.936 +        val simp = Simplifier.simp_add;
   1.937 +        val case_names = Rule_Cases.case_names names;
   1.938 +        val cases_type = Induct.cases_type dname;
   1.939 +      in
   1.940 +        Global_Theory.add_thmss [
   1.941 +          ((qualified "iso_rews"  , iso_rews    ), [simp]),
   1.942 +          ((qualified "nchotomy"  , [nchotomy]  ), []),
   1.943 +          ((qualified "exhaust"   , [exhaust]   ), [case_names, cases_type]),
   1.944 +          ((qualified "case_rews" , cases       ), [simp]),
   1.945 +          ((qualified "compacts"  , compacts    ), [simp]),
   1.946 +          ((qualified "con_rews"  , con_rews    ), [simp]),
   1.947 +          ((qualified "sel_rews"  , sel_thms    ), [simp]),
   1.948 +          ((qualified "dis_rews"  , dis_thms    ), [simp]),
   1.949 +          ((qualified "dist_les"  , dist_les    ), [simp]),
   1.950 +          ((qualified "dist_eqs"  , dist_eqs    ), [simp]),
   1.951 +          ((qualified "inverts"   , inverts     ), [simp]),
   1.952 +          ((qualified "injects"   , injects     ), [simp]),
   1.953 +          ((qualified "match_rews", match_thms  ), [simp])] thy
   1.954 +      end;
   1.955 +
   1.956 +    val result =
   1.957 +      {
   1.958 +        iso_info = iso_info,
   1.959 +        con_specs = con_specs,
   1.960 +        con_betas = con_betas,
   1.961 +        nchotomy = nchotomy,
   1.962 +        exhaust = exhaust,
   1.963 +        compacts = compacts,
   1.964 +        con_rews = con_rews,
   1.965 +        inverts = inverts,
   1.966 +        injects = injects,
   1.967 +        dist_les = dist_les,
   1.968 +        dist_eqs = dist_eqs,
   1.969 +        cases = cases,
   1.970 +        sel_rews = sel_thms,
   1.971 +        dis_rews = dis_thms,
   1.972 +        match_rews = match_thms
   1.973 +      };
   1.974 +  in
   1.975 +    (result, thy)
   1.976 +  end;
   1.977 +
   1.978 +end;