src/HOL/add_ind_def.ML
changeset 1397 b010f04fcb9c
parent 1189 c17a8fd0c95d
child 1465 5d7a7e439cec
equal deleted inserted replaced
1396:48bcde67391b 1397:b010f04fcb9c
    45 
    45 
    46 
    46 
    47 (*Declares functions to add fixedpoint/constructor defs to a theory*)
    47 (*Declares functions to add fixedpoint/constructor defs to a theory*)
    48 functor Add_inductive_def_Fun (Fp: FP) : ADD_INDUCTIVE_DEF =
    48 functor Add_inductive_def_Fun (Fp: FP) : ADD_INDUCTIVE_DEF =
    49 struct
    49 struct
    50 open Logic Ind_Syntax;
    50 open Ind_Syntax;
    51 
    51 
    52 (*internal version*)
    52 (*internal version*)
    53 fun add_fp_def_i (rec_tms, intr_tms) thy = 
    53 fun add_fp_def_i (rec_tms, intr_tms) thy = 
    54   let
    54   let
    55     val sign = sign_of thy;
    55     val sign = sign_of thy;
    89 
    89 
    90     (*Mutual recursion ?? *)
    90     (*Mutual recursion ?? *)
    91     val domTs = summands (dest_setT (body_type recT));
    91     val domTs = summands (dest_setT (body_type recT));
    92 	        (*alternative defn: map (dest_setT o fastype_of) rec_tms *)
    92 	        (*alternative defn: map (dest_setT o fastype_of) rec_tms *)
    93     val dom_sumT = fold_bal mk_sum domTs;
    93     val dom_sumT = fold_bal mk_sum domTs;
    94     val dom_set   = mk_setT dom_sumT;
    94     val dom_set  = mk_setT dom_sumT;
    95 
    95 
    96     val freez   = Free(z, dom_sumT)
    96     val freez   = Free(z, dom_sumT)
    97     and freeX   = Free(X, dom_set);
    97     and freeX   = Free(X, dom_set);
    98     (*type of w may be any of the domTs*)
    98     (*type of w may be any of the domTs*)
    99 
    99 
   101       | dest_tprop Q = error ("Ill-formed premise of introduction rule: " ^ 
   101       | dest_tprop Q = error ("Ill-formed premise of introduction rule: " ^ 
   102 			      Sign.string_of_term sign Q);
   102 			      Sign.string_of_term sign Q);
   103 
   103 
   104     (*Makes a disjunct from an introduction rule*)
   104     (*Makes a disjunct from an introduction rule*)
   105     fun lfp_part intr = (*quantify over rule's free vars except parameters*)
   105     fun lfp_part intr = (*quantify over rule's free vars except parameters*)
   106       let val prems = map dest_tprop (strip_imp_prems intr)
   106       let val prems = map dest_tprop (Logic.strip_imp_prems intr)
   107 	  val _ = seq (fn rec_hd => seq (chk_prem rec_hd) prems) rec_hds
   107 	  val _ = seq (fn rec_hd => seq (chk_prem rec_hd) prems) rec_hds
   108 	  val exfrees = term_frees intr \\ rec_params
   108 	  val exfrees = term_frees intr \\ rec_params
   109 	  val zeq = eq_const dom_sumT $ freez $ (#1 (rule_concl intr))
   109 	  val zeq = eq_const dom_sumT $ freez $ (#1 (rule_concl intr))
   110       in foldr mk_exists (exfrees, fold_bal (app conj) (zeq::prems)) end;
   110       in foldr mk_exists (exfrees, fold_bal (app conj) (zeq::prems)) end;
   111 
   111 
   127 
   127 
   128     val lfp_rhs = Fp.oper(X, dom_sumT, 
   128     val lfp_rhs = Fp.oper(X, dom_sumT, 
   129 			  mk_Collect(z, dom_sumT, 
   129 			  mk_Collect(z, dom_sumT, 
   130 				     fold_bal (app disj) part_intrs))
   130 				     fold_bal (app disj) part_intrs))
   131 
   131 
   132     val _ = seq (fn rec_hd => deny (rec_hd occs lfp_rhs) 
       
   133 			       "Illegal occurrence of recursion operator")
       
   134 	     rec_hds;
       
   135 
   132 
   136     (*** Make the new theory ***)
   133     (*** Make the new theory ***)
   137 
   134 
   138     (*A key definition:
   135     (*A key definition:
   139       If no mutual recursion then it equals the one recursive set.
   136       If no mutual recursion then it equals the one recursive set.
   151 	     | _ => rec_tms ~~		(*define the sets as Parts*)
   148 	     | _ => rec_tms ~~		(*define the sets as Parts*)
   152 		    map (subst_atomic [(freeX, big_rec_tm)]) parts));
   149 		    map (subst_atomic [(freeX, big_rec_tm)]) parts));
   153 
   150 
   154     val _ = seq (writeln o Sign.string_of_term sign o #2) axpairs
   151     val _ = seq (writeln o Sign.string_of_term sign o #2) axpairs
   155   
   152   
       
   153     (*Detect occurrences of operator, even with other types!*)
       
   154     val _ = (case rec_names inter (add_term_names (lfp_rhs,[])) of
       
   155 	       [] => ()
       
   156 	     | x::_ => error ("Illegal occurrence of recursion op: " ^ x ^
       
   157                                "\n\t*Consider adding type constraints*"))
       
   158 
   156   in  thy |> add_defs_i axpairs  end
   159   in  thy |> add_defs_i axpairs  end
   157 
   160 
   158 
   161 
   159 (****************************************************************OMITTED
   162 (****************************************************************OMITTED
   160 
   163