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