src/HOLCF/Tools/Domain/domain_theorems.ML
author huffman
Thu Oct 14 13:28:31 2010 -0700 (2010-10-14)
changeset 40016 2eff1cbc1ccb
parent 40014 7469b323e260
child 40017 575d3aa1f3c5
permissions -rw-r--r--
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
     1 (*  Title:      HOLCF/Tools/Domain/domain_theorems.ML
     2     Author:     David von Oheimb
     3     Author:     Brian Huffman
     4 
     5 Proof generator for domain command.
     6 *)
     7 
     8 val HOLCF_ss = @{simpset};
     9 
    10 signature DOMAIN_THEOREMS =
    11 sig
    12   val comp_theorems :
    13       binding * Domain_Library.eq list ->
    14       (binding * (binding * (bool * binding option * typ) list * mixfix) list) list ->
    15       Domain_Take_Proofs.iso_info list ->
    16       Domain_Take_Proofs.take_induct_info ->
    17       Domain_Constructors.constr_info list ->
    18       theory -> thm list * theory
    19 
    20   val quiet_mode: bool Unsynchronized.ref;
    21   val trace_domain: bool Unsynchronized.ref;
    22 end;
    23 
    24 structure Domain_Theorems :> DOMAIN_THEOREMS =
    25 struct
    26 
    27 val quiet_mode = Unsynchronized.ref false;
    28 val trace_domain = Unsynchronized.ref false;
    29 
    30 fun message s = if !quiet_mode then () else writeln s;
    31 fun trace s = if !trace_domain then tracing s else ();
    32 
    33 open Domain_Library;
    34 infixr 0 ===>;
    35 infixr 0 ==>;
    36 infix 0 == ; 
    37 infix 1 ===;
    38 infix 1 ~= ;
    39 infix 1 <<;
    40 infix 1 ~<<;
    41 infix 9 `   ;
    42 infix 9 `% ;
    43 infix 9 `%%;
    44 infixr 9 oo;
    45 
    46 (* ----- general proof facilities ------------------------------------------- *)
    47 
    48 local
    49 
    50 fun map_typ f g (Type (c, Ts)) = Type (g c, map (map_typ f g) Ts)
    51   | map_typ f _ (TFree (x, S)) = TFree (x, map f S)
    52   | map_typ f _ (TVar (xi, S)) = TVar (xi, map f S);
    53 
    54 fun map_term f g h (Const (c, T)) = Const (h c, map_typ f g T)
    55   | map_term f g _ (Free (x, T)) = Free (x, map_typ f g T)
    56   | map_term f g _ (Var (xi, T)) = Var (xi, map_typ f g T)
    57   | map_term _ _ _ (t as Bound _) = t
    58   | map_term f g h (Abs (x, T, t)) = Abs (x, map_typ f g T, map_term f g h t)
    59   | map_term f g h (t $ u) = map_term f g h t $ map_term f g h u;
    60 
    61 in
    62 
    63 fun intern_term thy =
    64   map_term (Sign.intern_class thy) (Sign.intern_type thy) (Sign.intern_const thy);
    65 
    66 end;
    67 
    68 fun legacy_infer_term thy t =
    69   let val ctxt = ProofContext.set_mode ProofContext.mode_schematic (ProofContext.init_global thy)
    70   in singleton (Syntax.check_terms ctxt) (intern_term thy t) end;
    71 
    72 fun pg'' thy defs t tacs =
    73   let
    74     val t' = legacy_infer_term thy t;
    75     val asms = Logic.strip_imp_prems t';
    76     val prop = Logic.strip_imp_concl t';
    77     fun tac {prems, context} =
    78       rewrite_goals_tac defs THEN
    79       EVERY (tacs {prems = map (rewrite_rule defs) prems, context = context})
    80   in Goal.prove_global thy [] asms prop tac end;
    81 
    82 fun pg' thy defs t tacsf =
    83   let
    84     fun tacs {prems, context} =
    85       if null prems then tacsf context
    86       else cut_facts_tac prems 1 :: tacsf context;
    87   in pg'' thy defs t tacs end;
    88 
    89 (* FIXME!!!!!!!!! *)
    90 (* We should NEVER re-parse variable names as strings! *)
    91 (* The names can conflict with existing constants or other syntax! *)
    92 fun case_UU_tac ctxt rews i v =
    93   InductTacs.case_tac ctxt (v^"=UU") i THEN
    94   asm_simp_tac (HOLCF_ss addsimps rews) i;
    95 
    96 (******************************************************************************)
    97 (***************************** proofs about take ******************************)
    98 (******************************************************************************)
    99 
   100 fun take_theorems
   101     (specs : (binding * (binding * (bool * binding option * typ) list * mixfix) list) list)
   102     (iso_infos : Domain_Take_Proofs.iso_info list)
   103     (take_info : Domain_Take_Proofs.take_induct_info)
   104     (constr_infos : Domain_Constructors.constr_info list)
   105     (thy : theory) : thm list list * theory =
   106 let
   107   open HOLCF_Library;
   108 
   109   val {take_consts, take_Suc_thms, deflation_take_thms, ...} = take_info;
   110   val deflation_thms = Domain_Take_Proofs.get_deflation_thms thy;
   111 
   112   val n = Free ("n", @{typ nat});
   113   val n' = @{const Suc} $ n;
   114 
   115   local
   116     val newTs = map #absT iso_infos;
   117     val subs = newTs ~~ map (fn t => t $ n) take_consts;
   118     fun is_ID (Const (c, _)) = (c = @{const_name ID})
   119       | is_ID _              = false;
   120   in
   121     fun map_of_arg v T =
   122       let val m = Domain_Take_Proofs.map_of_typ thy subs T;
   123       in if is_ID m then v else mk_capply (m, v) end;
   124   end
   125 
   126   fun prove_take_apps
   127       ((((dbind, spec), iso_info), take_const), constr_info) thy =
   128     let
   129       val {con_consts, con_betas, ...} = constr_info;
   130       val {abs_inverse, ...} = iso_info;
   131       fun prove_take_app (con_const : term) (bind, args, mx) =
   132         let
   133           val Ts = map (fn (_, _, T) => T) args;
   134           val ns = Name.variant_list ["n"] (Datatype_Prop.make_tnames Ts);
   135           val vs = map Free (ns ~~ Ts);
   136           val lhs = mk_capply (take_const $ n', list_ccomb (con_const, vs));
   137           val rhs = list_ccomb (con_const, map2 map_of_arg vs Ts);
   138           val goal = mk_trp (mk_eq (lhs, rhs));
   139           val rules =
   140               [abs_inverse] @ con_betas @ @{thms take_con_rules}
   141               @ take_Suc_thms @ deflation_thms @ deflation_take_thms;
   142           val tac = simp_tac (HOL_basic_ss addsimps rules) 1;
   143         in
   144           Goal.prove_global thy [] [] goal (K tac)
   145         end;
   146       val take_apps = map2 prove_take_app con_consts spec;
   147     in
   148       yield_singleton Global_Theory.add_thmss
   149         ((Binding.qualified true "take_rews" dbind, take_apps),
   150         [Simplifier.simp_add]) thy
   151     end;
   152 in
   153   fold_map prove_take_apps
   154     (specs ~~ iso_infos ~~ take_consts ~~ constr_infos) thy
   155 end;
   156 
   157 (* ----- general proofs ----------------------------------------------------- *)
   158 
   159 val all2E = @{lemma "!x y . P x y ==> (P x y ==> R) ==> R" by simp}
   160 
   161 (******************************************************************************)
   162 (****************************** induction rules *******************************)
   163 (******************************************************************************)
   164 
   165 fun prove_induction
   166     (comp_dbind : binding, eqs : eq list)
   167     (take_rews : thm list)
   168     (take_info : Domain_Take_Proofs.take_induct_info)
   169     (thy : theory) =
   170 let
   171   val comp_dname = Sign.full_name thy comp_dbind;
   172   val dnames = map (fst o fst) eqs;
   173   val conss  = map  snd        eqs;
   174   fun dc_take dn = %%:(dn^"_take");
   175   val x_name = idx_name dnames "x";
   176   val P_name = idx_name dnames "P";
   177   val pg = pg' thy;
   178 
   179   local
   180     fun ga s dn = Global_Theory.get_thm thy (dn ^ "." ^ s);
   181     fun gts s dn = Global_Theory.get_thms thy (dn ^ "." ^ s);
   182   in
   183     val axs_rep_iso = map (ga "rep_iso") dnames;
   184     val axs_abs_iso = map (ga "abs_iso") dnames;
   185     val exhausts = map (ga  "exhaust" ) dnames;
   186     val con_rews  = maps (gts "con_rews" ) dnames;
   187   end;
   188 
   189   val {take_consts, ...} = take_info;
   190   val {take_0_thms, take_Suc_thms, chain_take_thms, ...} = take_info;
   191   val {lub_take_thms, finite_defs, reach_thms, ...} = take_info;
   192   val {take_induct_thms, ...} = take_info;
   193 
   194   fun one_con p (con, args) =
   195     let
   196       val P_names = map P_name (1 upto (length dnames));
   197       val vns = Name.variant_list P_names (map vname args);
   198       val nonlazy_vns = map snd (filter_out (is_lazy o fst) (args ~~ vns));
   199       fun ind_hyp arg = %:(P_name (1 + rec_of arg)) $ bound_arg args arg;
   200       val t1 = mk_trp (%:p $ con_app2 con (bound_arg args) args);
   201       val t2 = lift ind_hyp (filter is_rec args, t1);
   202       val t3 = lift_defined (bound_arg vns) (nonlazy_vns, t2);
   203     in Library.foldr mk_All (vns, t3) end;
   204 
   205   fun one_eq ((p, cons), concl) =
   206     mk_trp (%:p $ UU) ===> Logic.list_implies (map (one_con p) cons, concl);
   207 
   208   fun ind_term concf = Library.foldr one_eq
   209     (mapn (fn n => fn x => (P_name n, x)) 1 conss,
   210      mk_trp (foldr1 mk_conj (mapn concf 1 dnames)));
   211   val take_ss = HOL_ss addsimps (@{thm Rep_CFun_strict1} :: take_rews);
   212   fun quant_tac ctxt i = EVERY
   213     (mapn (fn n => fn _ => res_inst_tac ctxt [(("x", 0), x_name n)] spec i) 1 dnames);
   214 
   215   fun ind_prems_tac prems = EVERY
   216     (maps (fn cons =>
   217       (resolve_tac prems 1 ::
   218         maps (fn (_,args) => 
   219           resolve_tac prems 1 ::
   220           map (K(atac 1)) (nonlazy args) @
   221           map (K(atac 1)) (filter is_rec args))
   222         cons))
   223       conss);
   224   local
   225     fun rec_to ns lazy_rec (n,cons) = forall (exists (fn arg => 
   226           is_rec arg andalso not (member (op =) ns (rec_of arg)) andalso
   227           ((rec_of arg =  n andalso not (lazy_rec orelse is_lazy arg)) orelse 
   228             rec_of arg <> n andalso rec_to (rec_of arg::ns) 
   229               (lazy_rec orelse is_lazy arg) (n, (List.nth(conss,rec_of arg))))
   230           ) o snd) cons;
   231     fun warn (n,cons) =
   232       if rec_to [] false (n,cons)
   233       then (warning ("domain "^List.nth(dnames,n)^" is empty!"); true)
   234       else false;
   235 
   236   in
   237     val n__eqs = mapn (fn n => fn (_,cons) => (n,cons)) 0 eqs;
   238     val is_emptys = map warn n__eqs;
   239     val is_finite = #is_finite take_info;
   240     val _ = if is_finite
   241             then message ("Proving finiteness rule for domain "^comp_dname^" ...")
   242             else ();
   243   end;
   244   val _ = trace " Proving finite_ind...";
   245   val finite_ind =
   246     let
   247       fun concf n dn = %:(P_name n) $ (dc_take dn $ %:"n" `%(x_name n));
   248       val goal = ind_term concf;
   249 
   250       fun tacf {prems, context} =
   251         let
   252           val tacs1 = [
   253             quant_tac context 1,
   254             simp_tac HOL_ss 1,
   255             InductTacs.induct_tac context [[SOME "n"]] 1,
   256             simp_tac (take_ss addsimps prems) 1,
   257             TRY (safe_tac HOL_cs)];
   258           fun arg_tac arg =
   259                         (* FIXME! case_UU_tac *)
   260             case_UU_tac context (prems @ con_rews) 1
   261               (List.nth (dnames, rec_of arg) ^ "_take n$" ^ vname arg);
   262           fun con_tacs (con, args) = 
   263             asm_simp_tac take_ss 1 ::
   264             map arg_tac (filter is_nonlazy_rec args) @
   265             [resolve_tac prems 1] @
   266             map (K (atac 1)) (nonlazy args) @
   267             map (K (etac spec 1)) (filter is_rec args);
   268           fun cases_tacs (cons, exhaust) =
   269             res_inst_tac context [(("y", 0), "x")] exhaust 1 ::
   270             asm_simp_tac (take_ss addsimps prems) 1 ::
   271             maps con_tacs cons;
   272         in
   273           tacs1 @ maps cases_tacs (conss ~~ exhausts)
   274         end;
   275     in pg'' thy [] goal tacf end;
   276 
   277 (* ----- theorems concerning finiteness and induction ----------------------- *)
   278 
   279   val global_ctxt = ProofContext.init_global thy;
   280 
   281   val _ = trace " Proving ind...";
   282   val ind =
   283     if is_finite
   284     then (* finite case *)
   285       let
   286         fun concf n dn = %:(P_name n) $ %:(x_name n);
   287         fun tacf {prems, context} =
   288           let
   289             fun finite_tacs (take_induct, fin_ind) = [
   290                 rtac take_induct 1,
   291                 rtac fin_ind 1,
   292                 ind_prems_tac prems];
   293           in
   294             TRY (safe_tac HOL_cs) ::
   295             maps finite_tacs (take_induct_thms ~~ atomize global_ctxt finite_ind)
   296           end;
   297       in pg'' thy [] (ind_term concf) tacf end
   298 
   299     else (* infinite case *)
   300       let
   301         val goal =
   302           let
   303             fun one_adm n _ = mk_trp (mk_adm (%:(P_name n)));
   304             fun concf n dn = %:(P_name n) $ %:(x_name n);
   305           in Logic.list_implies (mapn one_adm 1 dnames, ind_term concf) end;
   306         val cont_rules =
   307             @{thms cont_id cont_const cont2cont_Rep_CFun
   308                    cont2cont_fst cont2cont_snd};
   309         val subgoal =
   310           let
   311             val Ts = map (Type o fst) eqs;
   312             val P_names = Datatype_Prop.indexify_names (map (K "P") dnames);
   313             val x_names = Datatype_Prop.indexify_names (map (K "x") dnames);
   314             val P_types = map (fn T => T --> HOLogic.boolT) Ts;
   315             val Ps = map Free (P_names ~~ P_types);
   316             val xs = map Free (x_names ~~ Ts);
   317             val n = Free ("n", HOLogic.natT);
   318             val goals =
   319                 map (fn ((P,t),x) => P $ HOLCF_Library.mk_capply (t $ n, x))
   320                   (Ps ~~ take_consts ~~ xs);
   321           in
   322             HOLogic.mk_Trueprop
   323             (HOLogic.mk_all ("n", HOLogic.natT, foldr1 HOLogic.mk_conj goals))
   324           end;
   325         fun tacf {prems, context} =
   326           let
   327             val subtac =
   328                 EVERY [rtac allI 1, rtac finite_ind 1, ind_prems_tac prems];
   329             val subthm = Goal.prove context [] [] subgoal (K subtac);
   330           in
   331             map (fn ax_reach => rtac (ax_reach RS subst) 1) reach_thms @ [
   332             cut_facts_tac (subthm :: take (length dnames) prems) 1,
   333             REPEAT (rtac @{thm conjI} 1 ORELSE
   334                     EVERY [etac @{thm admD [OF _ ch2ch_Rep_CFunL]} 1,
   335                            resolve_tac chain_take_thms 1,
   336                            asm_simp_tac HOL_basic_ss 1])
   337             ]
   338           end;
   339       in pg'' thy [] goal tacf end;
   340 
   341 val case_ns =
   342   let
   343     val adms =
   344         if is_finite then [] else
   345         if length dnames = 1 then ["adm"] else
   346         map (fn s => "adm_" ^ Long_Name.base_name s) dnames;
   347     val bottoms =
   348         if length dnames = 1 then ["bottom"] else
   349         map (fn s => "bottom_" ^ Long_Name.base_name s) dnames;
   350     fun one_eq bot (_,cons) =
   351           bot :: map (fn (c,_) => Long_Name.base_name c) cons;
   352   in adms @ flat (map2 one_eq bottoms eqs) end;
   353 
   354 val inducts = Project_Rule.projections (ProofContext.init_global thy) ind;
   355 fun ind_rule (dname, rule) =
   356     ((Binding.empty, [rule]),
   357      [Rule_Cases.case_names case_ns, Induct.induct_type dname]);
   358 
   359 in
   360   thy
   361   |> snd o Global_Theory.add_thmss [
   362      ((Binding.qualified true "finite_induct" comp_dbind, [finite_ind]), []),
   363      ((Binding.qualified true "induct"        comp_dbind, [ind]       ), [])]
   364   |> (snd o Global_Theory.add_thmss (map ind_rule (dnames ~~ inducts)))
   365 end; (* prove_induction *)
   366 
   367 (******************************************************************************)
   368 (************************ bisimulation and coinduction ************************)
   369 (******************************************************************************)
   370 
   371 fun prove_coinduction
   372     (comp_dbind : binding, eqs : eq list)
   373     (take_rews : thm list)
   374     (take_lemmas : thm list)
   375     (thy : theory) : theory =
   376 let
   377 
   378 val dnames = map (fst o fst) eqs;
   379 val comp_dname = Sign.full_name thy comp_dbind;
   380 fun dc_take dn = %%:(dn^"_take");
   381 val x_name = idx_name dnames "x"; 
   382 val n_eqs = length eqs;
   383 
   384 (* ----- define bisimulation predicate -------------------------------------- *)
   385 
   386 local
   387   open HOLCF_Library
   388   val dtypes  = map (Type o fst) eqs;
   389   val relprod = mk_tupleT (map (fn tp => tp --> tp --> boolT) dtypes);
   390   val bisim_bind = Binding.suffix_name "_bisim" comp_dbind;
   391   val bisim_type = relprod --> boolT;
   392 in
   393   val (bisim_const, thy) =
   394       Sign.declare_const ((bisim_bind, bisim_type), NoSyn) thy;
   395 end;
   396 
   397 local
   398 
   399   fun legacy_infer_term thy t =
   400       singleton (Syntax.check_terms (ProofContext.init_global thy)) (intern_term thy t);
   401   fun legacy_infer_prop thy t = legacy_infer_term thy (Type.constraint propT t);
   402   fun infer_props thy = map (apsnd (legacy_infer_prop thy));
   403   fun add_defs_i x = Global_Theory.add_defs false (map Thm.no_attributes x);
   404   fun add_defs_infer defs thy = add_defs_i (infer_props thy defs) thy;
   405 
   406   fun one_con (con, args) =
   407     let
   408       val nonrec_args = filter_out is_rec args;
   409       val    rec_args = filter is_rec args;
   410       val    recs_cnt = length rec_args;
   411       val allargs     = nonrec_args @ rec_args
   412                         @ map (upd_vname (fn s=> s^"'")) rec_args;
   413       val allvns      = map vname allargs;
   414       fun vname_arg s arg = if is_rec arg then vname arg^s else vname arg;
   415       val vns1        = map (vname_arg "" ) args;
   416       val vns2        = map (vname_arg "'") args;
   417       val allargs_cnt = length nonrec_args + 2*recs_cnt;
   418       val rec_idxs    = (recs_cnt-1) downto 0;
   419       val nonlazy_idxs = map snd (filter_out (fn (arg,_) => is_lazy arg)
   420                                              (allargs~~((allargs_cnt-1) downto 0)));
   421       fun rel_app i ra = proj (Bound(allargs_cnt+2)) eqs (rec_of ra) $ 
   422                               Bound (2*recs_cnt-i) $ Bound (recs_cnt-i);
   423       val capps =
   424           List.foldr
   425             mk_conj
   426             (mk_conj(
   427              Bound(allargs_cnt+1)===list_ccomb(%%:con,map (bound_arg allvns) vns1),
   428              Bound(allargs_cnt+0)===list_ccomb(%%:con,map (bound_arg allvns) vns2)))
   429             (mapn rel_app 1 rec_args);
   430     in
   431       List.foldr
   432         mk_ex
   433         (Library.foldr mk_conj
   434                        (map (defined o Bound) nonlazy_idxs,capps)) allvns
   435     end;
   436   fun one_comp n (_,cons) =
   437       mk_all (x_name(n+1),
   438       mk_all (x_name(n+1)^"'",
   439       mk_imp (proj (Bound 2) eqs n $ Bound 1 $ Bound 0,
   440       foldr1 mk_disj (mk_conj(Bound 1 === UU,Bound 0 === UU)
   441                       ::map one_con cons))));
   442   val bisim_eqn =
   443       %%:(comp_dname^"_bisim") ==
   444          mk_lam("R", foldr1 mk_conj (mapn one_comp 0 eqs));
   445 
   446 in
   447   val (ax_bisim_def, thy) =
   448       yield_singleton add_defs_infer
   449         (Binding.qualified true "bisim_def" comp_dbind, bisim_eqn) thy;
   450 end; (* local *)
   451 
   452 (* ----- theorem concerning coinduction ------------------------------------- *)
   453 
   454 local
   455   val pg = pg' thy;
   456   val xs = mapn (fn n => K (x_name n)) 1 dnames;
   457   fun bnd_arg n i = Bound(2*(n_eqs - n)-i-1);
   458   val take_ss = HOL_ss addsimps (@{thm Rep_CFun_strict1} :: take_rews);
   459   val sproj = prj (fn s => K("fst("^s^")")) (fn s => K("snd("^s^")"));
   460   val _ = trace " Proving coind_lemma...";
   461   val coind_lemma =
   462     let
   463       fun mk_prj n _ = proj (%:"R") eqs n $ bnd_arg n 0 $ bnd_arg n 1;
   464       fun mk_eqn n dn =
   465         (dc_take dn $ %:"n" ` bnd_arg n 0) ===
   466         (dc_take dn $ %:"n" ` bnd_arg n 1);
   467       fun mk_all2 (x,t) = mk_all (x, mk_all (x^"'", t));
   468       val goal =
   469         mk_trp (mk_imp (%%:(comp_dname^"_bisim") $ %:"R",
   470           Library.foldr mk_all2 (xs,
   471             Library.foldr mk_imp (mapn mk_prj 0 dnames,
   472               foldr1 mk_conj (mapn mk_eqn 0 dnames)))));
   473       fun x_tacs ctxt n x = [
   474         rotate_tac (n+1) 1,
   475         etac all2E 1,
   476         eres_inst_tac ctxt [(("P", 1), sproj "R" eqs n^" "^x^" "^x^"'")] (mp RS disjE) 1,
   477         TRY (safe_tac HOL_cs),
   478         REPEAT (CHANGED (asm_simp_tac take_ss 1))];
   479       fun tacs ctxt = [
   480         rtac impI 1,
   481         InductTacs.induct_tac ctxt [[SOME "n"]] 1,
   482         simp_tac take_ss 1,
   483         safe_tac HOL_cs] @
   484         flat (mapn (x_tacs ctxt) 0 xs);
   485     in pg [ax_bisim_def] goal tacs end;
   486 in
   487   val _ = trace " Proving coind...";
   488   val coind = 
   489     let
   490       fun mk_prj n x = mk_trp (proj (%:"R") eqs n $ %:x $ %:(x^"'"));
   491       fun mk_eqn x = %:x === %:(x^"'");
   492       val goal =
   493         mk_trp (%%:(comp_dname^"_bisim") $ %:"R") ===>
   494           Logic.list_implies (mapn mk_prj 0 xs,
   495             mk_trp (foldr1 mk_conj (map mk_eqn xs)));
   496       val tacs =
   497         TRY (safe_tac HOL_cs) ::
   498         maps (fn take_lemma => [
   499           rtac take_lemma 1,
   500           cut_facts_tac [coind_lemma] 1,
   501           fast_tac HOL_cs 1])
   502         take_lemmas;
   503     in pg [] goal (K tacs) end;
   504 end; (* local *)
   505 
   506 in thy |> snd o Global_Theory.add_thmss
   507     [((Binding.qualified true "coinduct" comp_dbind, [coind]), [])]
   508 end; (* let *)
   509 
   510 fun comp_theorems
   511     (comp_dbind : binding, eqs : eq list)
   512     (specs : (binding * (binding * (bool * binding option * typ) list * mixfix) list) list)
   513     (iso_infos : Domain_Take_Proofs.iso_info list)
   514     (take_info : Domain_Take_Proofs.take_induct_info)
   515     (constr_infos : Domain_Constructors.constr_info list)
   516     (thy : theory) =
   517 let
   518 val map_tab = Domain_Take_Proofs.get_map_tab thy;
   519 
   520 val dnames = map (fst o fst) eqs;
   521 val comp_dname = Sign.full_name thy comp_dbind;
   522 
   523 (* ----- getting the composite axiom and definitions ------------------------ *)
   524 
   525 (* Test for indirect recursion *)
   526 local
   527   fun indirect_arg arg =
   528       rec_of arg = ~1 andalso Datatype_Aux.is_rec_type (dtyp_of arg);
   529   fun indirect_con (_, args) = exists indirect_arg args;
   530   fun indirect_eq (_, cons) = exists indirect_con cons;
   531 in
   532   val is_indirect = exists indirect_eq eqs;
   533   val _ =
   534       if is_indirect
   535       then message "Indirect recursion detected, skipping proofs of (co)induction rules"
   536       else message ("Proving induction properties of domain "^comp_dname^" ...");
   537 end;
   538 
   539 (* theorems about take *)
   540 
   541 val (take_rewss, thy) =
   542     take_theorems specs iso_infos take_info constr_infos thy;
   543 
   544 val {take_lemma_thms, take_0_thms, take_strict_thms, ...} = take_info;
   545 
   546 val take_rews = take_0_thms @ take_strict_thms @ flat take_rewss;
   547 
   548 (* prove induction rules, unless definition is indirect recursive *)
   549 val thy =
   550     if is_indirect then thy else
   551     prove_induction (comp_dbind, eqs) take_rews take_info thy;
   552 
   553 val thy =
   554     if is_indirect then thy else
   555     prove_coinduction (comp_dbind, eqs) take_rews take_lemma_thms thy;
   556 
   557 in
   558   (take_rews, thy)
   559 end; (* let *)
   560 end; (* struct *)