src/ZF/Tools/inductive_package.ML
author nipkow
Tue Sep 21 19:11:07 1999 +0200 (1999-09-21)
changeset 7570 a9391550eea1
parent 6172 8a505e0694d0
child 7695 6d7f9f30e6df
permissions -rw-r--r--
Mod because of new solver interface.
     1 (*  Title:      ZF/inductive_package.ML
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1994  University of Cambridge
     5 
     6 Fixedpoint definition module -- for Inductive/Coinductive Definitions
     7 
     8 The functor will be instantiated for normal sums/products (inductive defs)
     9                          and non-standard sums/products (coinductive defs)
    10 
    11 Sums are used only for mutual recursion;
    12 Products are used only to derive "streamlined" induction rules for relations
    13 *)
    14 
    15 
    16 type inductive_result =
    17    {defs       : thm list,             (*definitions made in thy*)
    18     bnd_mono   : thm,                  (*monotonicity for the lfp definition*)
    19     dom_subset : thm,                  (*inclusion of recursive set in dom*)
    20     intrs      : thm list,             (*introduction rules*)
    21     elim       : thm,                  (*case analysis theorem*)
    22     mk_cases   : string -> thm,        (*generates case theorems*)
    23     induct     : thm,                  (*main induction rule*)
    24     mutual_induct : thm};              (*mutual induction rule*)
    25 
    26 
    27 (*Functor's result signature*)
    28 signature INDUCTIVE_PACKAGE =
    29   sig 
    30 
    31   (*Insert definitions for the recursive sets, which
    32      must *already* be declared as constants in parent theory!*)
    33   val add_inductive_i : 
    34       bool ->
    35       term list * term * term list * thm list * thm list * thm list * thm list
    36       -> theory -> theory * inductive_result
    37 
    38   val add_inductive : 
    39       string list * string * string list * 
    40       thm list * thm list * thm list * thm list
    41       -> theory -> theory * inductive_result
    42 
    43   end;
    44 
    45 
    46 (*Declares functions to add fixedpoint/constructor defs to a theory.
    47   Recursive sets must *already* be declared as constants.*)
    48 functor Add_inductive_def_Fun 
    49     (structure Fp: FP and Pr : PR and CP: CARTPROD and Su : SU)
    50  : INDUCTIVE_PACKAGE =
    51 struct
    52 open Logic Ind_Syntax;
    53 
    54 (*internal version, accepting terms*)
    55 fun add_inductive_i verbose (rec_tms, dom_sum, intr_tms, 
    56 			     monos, con_defs, type_intrs, type_elims) thy = 
    57  let
    58   val dummy = (*has essential ancestors?*)
    59       Theory.requires thy "Inductive" "(co)inductive definitions" 
    60 
    61   val sign = sign_of thy;
    62 
    63   (*recT and rec_params should agree for all mutually recursive components*)
    64   val rec_hds = map head_of rec_tms;
    65 
    66   val dummy = assert_all is_Const rec_hds
    67 	  (fn t => "Recursive set not previously declared as constant: " ^ 
    68 		   Sign.string_of_term sign t);
    69 
    70   (*Now we know they are all Consts, so get their names, type and params*)
    71   val rec_names = map (#1 o dest_Const) rec_hds
    72   and (Const(_,recT),rec_params) = strip_comb (hd rec_tms);
    73 
    74   val rec_base_names = map Sign.base_name rec_names;
    75   val dummy = assert_all Syntax.is_identifier rec_base_names
    76     (fn a => "Base name of recursive set not an identifier: " ^ a);
    77 
    78   local (*Checking the introduction rules*)
    79     val intr_sets = map (#2 o rule_concl_msg sign) intr_tms;
    80     fun intr_ok set =
    81 	case head_of set of Const(a,recT) => a mem rec_names | _ => false;
    82   in
    83     val dummy =  assert_all intr_ok intr_sets
    84        (fn t => "Conclusion of rule does not name a recursive set: " ^ 
    85 		Sign.string_of_term sign t);
    86   end;
    87 
    88   val dummy = assert_all is_Free rec_params
    89       (fn t => "Param in recursion term not a free variable: " ^
    90 	       Sign.string_of_term sign t);
    91 
    92   (*** Construct the fixedpoint definition ***)
    93   val mk_variant = variant (foldr add_term_names (intr_tms,[]));
    94 
    95   val z' = mk_variant"z" and X' = mk_variant"X" and w' = mk_variant"w";
    96 
    97   fun dest_tprop (Const("Trueprop",_) $ P) = P
    98     | dest_tprop Q = error ("Ill-formed premise of introduction rule: " ^ 
    99 			    Sign.string_of_term sign Q);
   100 
   101   (*Makes a disjunct from an introduction rule*)
   102   fun fp_part intr = (*quantify over rule's free vars except parameters*)
   103     let val prems = map dest_tprop (strip_imp_prems intr)
   104 	val dummy = seq (fn rec_hd => seq (chk_prem rec_hd) prems) rec_hds
   105 	val exfrees = term_frees intr \\ rec_params
   106 	val zeq = FOLogic.mk_eq (Free(z',iT), #1 (rule_concl intr))
   107     in foldr FOLogic.mk_exists
   108 	     (exfrees, fold_bal (app FOLogic.conj) (zeq::prems)) 
   109     end;
   110 
   111   (*The Part(A,h) terms -- compose injections to make h*)
   112   fun mk_Part (Bound 0) = Free(X',iT) (*no mutual rec, no Part needed*)
   113     | mk_Part h         = Part_const $ Free(X',iT) $ Abs(w',iT,h);
   114 
   115   (*Access to balanced disjoint sums via injections*)
   116   val parts = 
   117       map mk_Part (accesses_bal (ap Su.inl, ap Su.inr, Bound 0) 
   118 				(length rec_tms));
   119 
   120   (*replace each set by the corresponding Part(A,h)*)
   121   val part_intrs = map (subst_free (rec_tms ~~ parts) o fp_part) intr_tms;
   122 
   123   val fp_abs = absfree(X', iT, 
   124 		   mk_Collect(z', dom_sum, 
   125 			      fold_bal (app FOLogic.disj) part_intrs));
   126 
   127   val fp_rhs = Fp.oper $ dom_sum $ fp_abs
   128 
   129   val dummy = seq (fn rec_hd => deny (rec_hd occs fp_rhs) 
   130 			     "Illegal occurrence of recursion operator")
   131 	   rec_hds;
   132 
   133   (*** Make the new theory ***)
   134 
   135   (*A key definition:
   136     If no mutual recursion then it equals the one recursive set.
   137     If mutual recursion then it differs from all the recursive sets. *)
   138   val big_rec_base_name = space_implode "_" rec_base_names;
   139   val big_rec_name = Sign.intern_const sign big_rec_base_name;
   140 
   141   
   142   val dummy =
   143       if verbose then
   144 	  writeln ((if #1 (dest_Const Fp.oper) = "Fixedpt.lfp" then "Inductive" 
   145 		    else "Coinductive") ^ " definition " ^ big_rec_name)
   146       else ();
   147 
   148   (*Forbid the inductive definition structure from clashing with a theory
   149     name.  This restriction may become obsolete as ML is de-emphasized.*)
   150   val dummy = deny (big_rec_base_name mem (Sign.stamp_names_of sign))
   151 	       ("Definition " ^ big_rec_base_name ^ 
   152 		" would clash with the theory of the same name!");
   153 
   154   (*Big_rec... is the union of the mutually recursive sets*)
   155   val big_rec_tm = list_comb(Const(big_rec_name,recT), rec_params);
   156 
   157   (*The individual sets must already be declared*)
   158   val axpairs = map Logic.mk_defpair 
   159 	((big_rec_tm, fp_rhs) ::
   160 	 (case parts of 
   161 	     [_] => []                        (*no mutual recursion*)
   162 	   | _ => rec_tms ~~          (*define the sets as Parts*)
   163 		  map (subst_atomic [(Free(X',iT),big_rec_tm)]) parts));
   164 
   165   (*tracing: print the fixedpoint definition*)
   166   val dummy = if !Ind_Syntax.trace then
   167 	      seq (writeln o Sign.string_of_term sign o #2) axpairs
   168 	  else ()
   169 
   170   (*add definitions of the inductive sets*)
   171   val thy1 = thy |> Theory.add_path big_rec_base_name
   172                  |> PureThy.add_defs_i (map Thm.no_attributes axpairs)  
   173 
   174 
   175   (*fetch fp definitions from the theory*)
   176   val big_rec_def::part_rec_defs = 
   177     map (get_def thy1)
   178 	(case rec_names of [_] => rec_names 
   179 			 | _   => big_rec_base_name::rec_names);
   180 
   181 
   182   val sign1 = sign_of thy1;
   183 
   184   (********)
   185   val dummy = writeln "  Proving monotonicity...";
   186 
   187   val bnd_mono = 
   188       prove_goalw_cterm [] 
   189 	(cterm_of sign1
   190 		  (FOLogic.mk_Trueprop (Fp.bnd_mono $ dom_sum $ fp_abs)))
   191 	(fn _ =>
   192 	 [rtac (Collect_subset RS bnd_monoI) 1,
   193 	  REPEAT (ares_tac (basic_monos @ monos) 1)]);
   194 
   195   val dom_subset = standard (big_rec_def RS Fp.subs);
   196 
   197   val unfold = standard ([big_rec_def, bnd_mono] MRS Fp.Tarski);
   198 
   199   (********)
   200   val dummy = writeln "  Proving the introduction rules...";
   201 
   202   (*Mutual recursion?  Helps to derive subset rules for the 
   203     individual sets.*)
   204   val Part_trans =
   205       case rec_names of
   206 	   [_] => asm_rl
   207 	 | _   => standard (Part_subset RS subset_trans);
   208 
   209   (*To type-check recursive occurrences of the inductive sets, possibly
   210     enclosed in some monotonic operator M.*)
   211   val rec_typechecks = 
   212      [dom_subset] RL (asm_rl :: ([Part_trans] RL monos)) 
   213      RL [subsetD];
   214 
   215   (*Type-checking is hardest aspect of proof;
   216     disjIn selects the correct disjunct after unfolding*)
   217   fun intro_tacsf disjIn prems = 
   218     [(*insert prems and underlying sets*)
   219      cut_facts_tac prems 1,
   220      DETERM (stac unfold 1),
   221      REPEAT (resolve_tac [Part_eqI,CollectI] 1),
   222      (*Now 2-3 subgoals: typechecking, the disjunction, perhaps equality.*)
   223      rtac disjIn 2,
   224      (*Not ares_tac, since refl must be tried before equality assumptions;
   225        backtracking may occur if the premises have extra variables!*)
   226      DEPTH_SOLVE_1 (resolve_tac [refl,exI,conjI] 2 APPEND assume_tac 2),
   227      (*Now solve the equations like Tcons(a,f) = Inl(?b4)*)
   228      rewrite_goals_tac con_defs,
   229      REPEAT (rtac refl 2),
   230      (*Typechecking; this can fail*)
   231      if !Ind_Syntax.trace then print_tac "The type-checking subgoal:"
   232      else all_tac,
   233      REPEAT (FIRSTGOAL (        dresolve_tac rec_typechecks
   234 			ORELSE' eresolve_tac (asm_rl::PartE::SigmaE2::
   235 					      type_elims)
   236 			ORELSE' hyp_subst_tac)),
   237      if !Ind_Syntax.trace then print_tac "The subgoal after monos, type_elims:"
   238      else all_tac,
   239      DEPTH_SOLVE (swap_res_tac (SigmaI::subsetI::type_intrs) 1)];
   240 
   241   (*combines disjI1 and disjI2 to get the corresponding nested disjunct...*)
   242   val mk_disj_rls = 
   243       let fun f rl = rl RS disjI1
   244 	  and g rl = rl RS disjI2
   245       in  accesses_bal(f, g, asm_rl)  end;
   246 
   247   fun prove_intr (ct, tacsf) = prove_goalw_cterm part_rec_defs ct tacsf;
   248 
   249   val intrs = ListPair.map prove_intr
   250 		(map (cterm_of sign1) intr_tms,
   251 		 map intro_tacsf (mk_disj_rls(length intr_tms)))
   252 	       handle SIMPLIFIER (msg,thm) => (print_thm thm; error msg);
   253 
   254   (********)
   255   val dummy = writeln "  Proving the elimination rule...";
   256 
   257   (*Breaks down logical connectives in the monotonic function*)
   258   val basic_elim_tac =
   259       REPEAT (SOMEGOAL (eresolve_tac (Ind_Syntax.elim_rls @ Su.free_SEs)
   260 		ORELSE' bound_hyp_subst_tac))
   261       THEN prune_params_tac
   262 	  (*Mutual recursion: collapse references to Part(D,h)*)
   263       THEN fold_tac part_rec_defs;
   264 
   265   (*Elimination*)
   266   val elim = rule_by_tactic basic_elim_tac 
   267 		 (unfold RS Ind_Syntax.equals_CollectD)
   268 
   269   (*Applies freeness of the given constructors, which *must* be unfolded by
   270       the given defs.  Cannot simply use the local con_defs because  
   271       con_defs=[] for inference systems. 
   272     String s should have the form t:Si where Si is an inductive set*)
   273   fun mk_cases s = 
   274       rule_by_tactic (basic_elim_tac THEN
   275 		      ALLGOALS Asm_full_simp_tac THEN 
   276 		      basic_elim_tac)
   277 	 (assume_read (theory_of_thm elim) s
   278 	              (*Don't use thy1: it will be stale*)
   279 	  RS  elim)
   280       |> standard;
   281 
   282 
   283   fun induction_rules raw_induct thy =
   284    let
   285      val dummy = writeln "  Proving the induction rule...";
   286 
   287      (*** Prove the main induction rule ***)
   288 
   289      val pred_name = "P";            (*name for predicate variables*)
   290 
   291      (*Used to make induction rules;
   292 	ind_alist = [(rec_tm1,pred1),...] associates predicates with rec ops
   293 	prem is a premise of an intr rule*)
   294      fun add_induct_prem ind_alist (prem as Const("Trueprop",_) $ 
   295 		      (Const("op :",_)$t$X), iprems) =
   296 	  (case gen_assoc (op aconv) (ind_alist, X) of
   297 	       Some pred => prem :: FOLogic.mk_Trueprop (pred $ t) :: iprems
   298 	     | None => (*possibly membership in M(rec_tm), for M monotone*)
   299 		 let fun mk_sb (rec_tm,pred) = 
   300 			     (rec_tm, Ind_Syntax.Collect_const$rec_tm$pred)
   301 		 in  subst_free (map mk_sb ind_alist) prem :: iprems  end)
   302        | add_induct_prem ind_alist (prem,iprems) = prem :: iprems;
   303 
   304      (*Make a premise of the induction rule.*)
   305      fun induct_prem ind_alist intr =
   306        let val quantfrees = map dest_Free (term_frees intr \\ rec_params)
   307 	   val iprems = foldr (add_induct_prem ind_alist)
   308 			      (Logic.strip_imp_prems intr,[])
   309 	   val (t,X) = Ind_Syntax.rule_concl intr
   310 	   val (Some pred) = gen_assoc (op aconv) (ind_alist, X)
   311 	   val concl = FOLogic.mk_Trueprop (pred $ t)
   312        in list_all_free (quantfrees, Logic.list_implies (iprems,concl)) end
   313        handle Bind => error"Recursion term not found in conclusion";
   314 
   315      (*Minimizes backtracking by delivering the correct premise to each goal.
   316        Intro rules with extra Vars in premises still cause some backtracking *)
   317      fun ind_tac [] 0 = all_tac
   318        | ind_tac(prem::prems) i = 
   319 	     DEPTH_SOLVE_1 (ares_tac [prem, refl] i) THEN
   320 	     ind_tac prems (i-1);
   321 
   322      val pred = Free(pred_name, Ind_Syntax.iT --> FOLogic.oT);
   323 
   324      val ind_prems = map (induct_prem (map (rpair pred) rec_tms)) 
   325 			 intr_tms;
   326 
   327      val dummy = if !Ind_Syntax.trace then 
   328 		 (writeln "ind_prems = ";
   329 		  seq (writeln o Sign.string_of_term sign1) ind_prems;
   330 		  writeln "raw_induct = "; print_thm raw_induct)
   331 	     else ();
   332 
   333 
   334      (*We use a MINIMAL simpset. Even FOL_ss contains too many simpules.  
   335        If the premises get simplified, then the proofs could fail.*)
   336      val min_ss = empty_ss
   337 	   setmksimps (map mk_eq o ZF_atomize o gen_all)
   338 	   setSolver (mk_solver "minimal"
   339                       (fn prems => resolve_tac (triv_rls@prems) 
   340 				   ORELSE' assume_tac
   341 				   ORELSE' etac FalseE));
   342 
   343      val quant_induct = 
   344 	 prove_goalw_cterm part_rec_defs 
   345 	   (cterm_of sign1 
   346 	    (Logic.list_implies 
   347 	     (ind_prems, 
   348 	      FOLogic.mk_Trueprop (Ind_Syntax.mk_all_imp(big_rec_tm,pred)))))
   349 	   (fn prems =>
   350 	    [rtac (impI RS allI) 1,
   351 	     DETERM (etac raw_induct 1),
   352 	     (*Push Part inside Collect*)
   353 	     full_simp_tac (min_ss addsimps [Part_Collect]) 1,
   354 	     (*This CollectE and disjE separates out the introduction rules*)
   355 	     REPEAT (FIRSTGOAL (eresolve_tac [CollectE, disjE])),
   356 	     (*Now break down the individual cases.  No disjE here in case
   357 	       some premise involves disjunction.*)
   358 	     REPEAT (FIRSTGOAL (eresolve_tac [CollectE, exE, conjE] 
   359 				ORELSE' hyp_subst_tac)),
   360 	     ind_tac (rev prems) (length prems) ]);
   361 
   362      val dummy = if !Ind_Syntax.trace then 
   363 		 (writeln "quant_induct = "; print_thm quant_induct)
   364 	     else ();
   365 
   366 
   367      (*** Prove the simultaneous induction rule ***)
   368 
   369      (*Make distinct predicates for each inductive set*)
   370 
   371      (*The components of the element type, several if it is a product*)
   372      val elem_type = CP.pseudo_type dom_sum;
   373      val elem_factors = CP.factors elem_type;
   374      val elem_frees = mk_frees "za" elem_factors;
   375      val elem_tuple = CP.mk_tuple Pr.pair elem_type elem_frees;
   376 
   377      (*Given a recursive set and its domain, return the "fsplit" predicate
   378        and a conclusion for the simultaneous induction rule.
   379        NOTE.  This will not work for mutually recursive predicates.  Previously
   380        a summand 'domt' was also an argument, but this required the domain of
   381        mutual recursion to invariably be a disjoint sum.*)
   382      fun mk_predpair rec_tm = 
   383        let val rec_name = (#1 o dest_Const o head_of) rec_tm
   384 	   val pfree = Free(pred_name ^ "_" ^ Sign.base_name rec_name,
   385 			    elem_factors ---> FOLogic.oT)
   386 	   val qconcl = 
   387 	     foldr FOLogic.mk_all
   388 	       (elem_frees, 
   389 		FOLogic.imp $ 
   390 		(Ind_Syntax.mem_const $ elem_tuple $ rec_tm)
   391 		      $ (list_comb (pfree, elem_frees)))
   392        in  (CP.ap_split elem_type FOLogic.oT pfree, 
   393 	    qconcl)  
   394        end;
   395 
   396      val (preds,qconcls) = split_list (map mk_predpair rec_tms);
   397 
   398      (*Used to form simultaneous induction lemma*)
   399      fun mk_rec_imp (rec_tm,pred) = 
   400 	 FOLogic.imp $ (Ind_Syntax.mem_const $ Bound 0 $ rec_tm) $ 
   401 			  (pred $ Bound 0);
   402 
   403      (*To instantiate the main induction rule*)
   404      val induct_concl = 
   405 	 FOLogic.mk_Trueprop
   406 	   (Ind_Syntax.mk_all_imp
   407 	    (big_rec_tm,
   408 	     Abs("z", Ind_Syntax.iT, 
   409 		 fold_bal (app FOLogic.conj) 
   410 		 (ListPair.map mk_rec_imp (rec_tms, preds)))))
   411      and mutual_induct_concl =
   412       FOLogic.mk_Trueprop(fold_bal (app FOLogic.conj) qconcls);
   413 
   414      val dummy = if !Ind_Syntax.trace then 
   415 		 (writeln ("induct_concl = " ^
   416 			   Sign.string_of_term sign1 induct_concl);
   417 		  writeln ("mutual_induct_concl = " ^
   418 			   Sign.string_of_term sign1 mutual_induct_concl))
   419 	     else ();
   420 
   421 
   422      val lemma_tac = FIRST' [eresolve_tac [asm_rl, conjE, PartE, mp],
   423 			     resolve_tac [allI, impI, conjI, Part_eqI],
   424 			     dresolve_tac [spec, mp, Pr.fsplitD]];
   425 
   426      val need_mutual = length rec_names > 1;
   427 
   428      val lemma = (*makes the link between the two induction rules*)
   429        if need_mutual then
   430 	  (writeln "  Proving the mutual induction rule...";
   431 	   prove_goalw_cterm part_rec_defs 
   432 		 (cterm_of sign1 (Logic.mk_implies (induct_concl,
   433 						   mutual_induct_concl)))
   434 		 (fn prems =>
   435 		  [cut_facts_tac prems 1, 
   436 		   REPEAT (rewrite_goals_tac [Pr.split_eq] THEN
   437 			   lemma_tac 1)]))
   438        else (writeln "  [ No mutual induction rule needed ]";
   439 	     TrueI);
   440 
   441      val dummy = if !Ind_Syntax.trace then 
   442 		 (writeln "lemma = "; print_thm lemma)
   443 	     else ();
   444 
   445 
   446      (*Mutual induction follows by freeness of Inl/Inr.*)
   447 
   448      (*Simplification largely reduces the mutual induction rule to the 
   449        standard rule*)
   450      val mut_ss = 
   451 	 min_ss addsimps [Su.distinct, Su.distinct', Su.inl_iff, Su.inr_iff];
   452 
   453      val all_defs = con_defs @ part_rec_defs;
   454 
   455      (*Removes Collects caused by M-operators in the intro rules.  It is very
   456        hard to simplify
   457 	 list({v: tf. (v : t --> P_t(v)) & (v : f --> P_f(v))}) 
   458        where t==Part(tf,Inl) and f==Part(tf,Inr) to  list({v: tf. P_t(v)}).
   459        Instead the following rules extract the relevant conjunct.
   460      *)
   461      val cmonos = [subset_refl RS Collect_mono] RL monos
   462 		   RLN (2,[rev_subsetD]);
   463 
   464      (*Minimizes backtracking by delivering the correct premise to each goal*)
   465      fun mutual_ind_tac [] 0 = all_tac
   466        | mutual_ind_tac(prem::prems) i = 
   467 	   DETERM
   468 	    (SELECT_GOAL 
   469 	       (
   470 		(*Simplify the assumptions and goal by unfolding Part and
   471 		  using freeness of the Sum constructors; proves all but one
   472 		  conjunct by contradiction*)
   473 		rewrite_goals_tac all_defs  THEN
   474 		simp_tac (mut_ss addsimps [Part_iff]) 1  THEN
   475 		IF_UNSOLVED (*simp_tac may have finished it off!*)
   476 		  ((*simplify assumptions*)
   477 		   (*some risk of excessive simplification here -- might have
   478 		     to identify the bare minimum set of rewrites*)
   479 		   full_simp_tac 
   480 		      (mut_ss addsimps conj_simps @ imp_simps @ quant_simps) 1
   481 		   THEN
   482 		   (*unpackage and use "prem" in the corresponding place*)
   483 		   REPEAT (rtac impI 1)  THEN
   484 		   rtac (rewrite_rule all_defs prem) 1  THEN
   485 		   (*prem must not be REPEATed below: could loop!*)
   486 		   DEPTH_SOLVE (FIRSTGOAL (ares_tac [impI] ORELSE' 
   487 					   eresolve_tac (conjE::mp::cmonos))))
   488 	       ) i)
   489 	    THEN mutual_ind_tac prems (i-1);
   490 
   491      val mutual_induct_fsplit = 
   492        if need_mutual then
   493 	 prove_goalw_cterm []
   494 	       (cterm_of sign1
   495 		(Logic.list_implies 
   496 		   (map (induct_prem (rec_tms~~preds)) intr_tms,
   497 		    mutual_induct_concl)))
   498 	       (fn prems =>
   499 		[rtac (quant_induct RS lemma) 1,
   500 		 mutual_ind_tac (rev prems) (length prems)])
   501        else TrueI;
   502 
   503      (** Uncurrying the predicate in the ordinary induction rule **)
   504 
   505      (*instantiate the variable to a tuple, if it is non-trivial, in order to
   506        allow the predicate to be "opened up".
   507        The name "x.1" comes from the "RS spec" !*)
   508      val inst = 
   509 	 case elem_frees of [_] => I
   510 	    | _ => instantiate ([], [(cterm_of sign1 (Var(("x",1), Ind_Syntax.iT)), 
   511 				      cterm_of sign1 elem_tuple)]);
   512 
   513      (*strip quantifier and the implication*)
   514      val induct0 = inst (quant_induct RS spec RSN (2,rev_mp));
   515 
   516      val Const ("Trueprop", _) $ (pred_var $ _) = concl_of induct0
   517 
   518      val induct = CP.split_rule_var(pred_var, elem_type-->FOLogic.oT, induct0) 
   519 		  |> standard
   520      and mutual_induct = CP.remove_split mutual_induct_fsplit
   521     in
   522       (thy
   523 	|> PureThy.add_thms 
   524 	    [(("induct", induct), []),
   525 	     (("mutual_induct", mutual_induct), [])],
   526        induct, mutual_induct)
   527     end;  (*of induction_rules*)
   528 
   529   val raw_induct = standard ([big_rec_def, bnd_mono] MRS Fp.induct)
   530 
   531   val (thy2, induct, mutual_induct) = 
   532       if #1 (dest_Const Fp.oper) = "Fixedpt.lfp" then induction_rules raw_induct thy1
   533       else (thy1, raw_induct, TrueI)
   534   and defs = big_rec_def :: part_rec_defs
   535 
   536  in
   537    (thy2
   538 	 |> (PureThy.add_thms o map Thm.no_attributes)
   539 	      [("bnd_mono", bnd_mono),
   540 	       ("dom_subset", dom_subset),
   541 	       ("elim", elim)]
   542 	 |> (PureThy.add_thmss o map Thm.no_attributes)
   543 	       [("defs", defs),
   544 		("intrs", intrs)]
   545          |> Theory.parent_path,
   546     {defs = defs,
   547      bnd_mono = bnd_mono,
   548      dom_subset = dom_subset,
   549      intrs = intrs,
   550      elim = elim,
   551      mk_cases = mk_cases,
   552      induct = induct,
   553      mutual_induct = mutual_induct})
   554 
   555  end;
   556 
   557 
   558 (*external version, accepting strings*)
   559 fun add_inductive (srec_tms, sdom_sum, sintrs, monos,
   560 		     con_defs, type_intrs, type_elims) thy = 
   561   let val rec_tms = map (readtm (sign_of thy) Ind_Syntax.iT) srec_tms
   562       and dom_sum = readtm (sign_of thy) Ind_Syntax.iT sdom_sum
   563       and intr_tms = map (readtm (sign_of thy) propT) sintrs
   564   in  
   565     add_inductive_i true (rec_tms, dom_sum, intr_tms, 
   566 			  monos, con_defs, type_intrs, type_elims) thy
   567 
   568   end
   569 end;