100 val dummy = assert_all is_Free rec_params |
100 val dummy = assert_all is_Free rec_params |
101 (fn t => "Param in recursion term not a free variable: " ^ |
101 (fn t => "Param in recursion term not a free variable: " ^ |
102 Sign.string_of_term sign t); |
102 Sign.string_of_term sign t); |
103 |
103 |
104 (*** Construct the fixedpoint definition ***) |
104 (*** Construct the fixedpoint definition ***) |
105 val mk_variant = variant (foldr add_term_names (intr_tms, [])); |
105 val mk_variant = variant (Library.foldr add_term_names (intr_tms, [])); |
106 |
106 |
107 val z' = mk_variant"z" and X' = mk_variant"X" and w' = mk_variant"w"; |
107 val z' = mk_variant"z" and X' = mk_variant"X" and w' = mk_variant"w"; |
108 |
108 |
109 fun dest_tprop (Const("Trueprop",_) $ P) = P |
109 fun dest_tprop (Const("Trueprop",_) $ P) = P |
110 | dest_tprop Q = error ("Ill-formed premise of introduction rule: " ^ |
110 | dest_tprop Q = error ("Ill-formed premise of introduction rule: " ^ |
111 Sign.string_of_term sign Q); |
111 Sign.string_of_term sign Q); |
112 |
112 |
113 (*Makes a disjunct from an introduction rule*) |
113 (*Makes a disjunct from an introduction rule*) |
114 fun fp_part intr = (*quantify over rule's free vars except parameters*) |
114 fun fp_part intr = (*quantify over rule's free vars except parameters*) |
115 let val prems = map dest_tprop (strip_imp_prems intr) |
115 let val prems = map dest_tprop (strip_imp_prems intr) |
116 val dummy = seq (fn rec_hd => seq (chk_prem rec_hd) prems) rec_hds |
116 val dummy = List.app (fn rec_hd => List.app (chk_prem rec_hd) prems) rec_hds |
117 val exfrees = term_frees intr \\ rec_params |
117 val exfrees = term_frees intr \\ rec_params |
118 val zeq = FOLogic.mk_eq (Free(z',iT), #1 (rule_concl intr)) |
118 val zeq = FOLogic.mk_eq (Free(z',iT), #1 (rule_concl intr)) |
119 in foldr FOLogic.mk_exists |
119 in Library.foldr FOLogic.mk_exists |
120 (exfrees, fold_bal FOLogic.mk_conj (zeq::prems)) |
120 (exfrees, fold_bal FOLogic.mk_conj (zeq::prems)) |
121 end; |
121 end; |
122 |
122 |
123 (*The Part(A,h) terms -- compose injections to make h*) |
123 (*The Part(A,h) terms -- compose injections to make h*) |
124 fun mk_Part (Bound 0) = Free(X',iT) (*no mutual rec, no Part needed*) |
124 fun mk_Part (Bound 0) = Free(X',iT) (*no mutual rec, no Part needed*) |
136 mk_Collect(z', dom_sum, |
136 mk_Collect(z', dom_sum, |
137 fold_bal FOLogic.mk_disj part_intrs)); |
137 fold_bal FOLogic.mk_disj part_intrs)); |
138 |
138 |
139 val fp_rhs = Fp.oper $ dom_sum $ fp_abs |
139 val fp_rhs = Fp.oper $ dom_sum $ fp_abs |
140 |
140 |
141 val dummy = seq (fn rec_hd => deny (rec_hd occs fp_rhs) |
141 val dummy = List.app (fn rec_hd => deny (rec_hd occs fp_rhs) |
142 "Illegal occurrence of recursion operator") |
142 "Illegal occurrence of recursion operator") |
143 rec_hds; |
143 rec_hds; |
144 |
144 |
145 (*** Make the new theory ***) |
145 (*** Make the new theory ***) |
146 |
146 |
171 | _ => rec_tms ~~ (*define the sets as Parts*) |
171 | _ => rec_tms ~~ (*define the sets as Parts*) |
172 map (subst_atomic [(Free(X',iT),big_rec_tm)]) parts)); |
172 map (subst_atomic [(Free(X',iT),big_rec_tm)]) parts)); |
173 |
173 |
174 (*tracing: print the fixedpoint definition*) |
174 (*tracing: print the fixedpoint definition*) |
175 val dummy = if !Ind_Syntax.trace then |
175 val dummy = if !Ind_Syntax.trace then |
176 seq (writeln o Sign.string_of_term sign o #2) axpairs |
176 List.app (writeln o Sign.string_of_term sign o #2) axpairs |
177 else () |
177 else () |
178 |
178 |
179 (*add definitions of the inductive sets*) |
179 (*add definitions of the inductive sets*) |
180 val thy1 = thy |> Theory.add_path big_rec_base_name |
180 val thy1 = thy |> Theory.add_path big_rec_base_name |
181 |> (#1 o PureThy.add_defs_i false (map Thm.no_attributes axpairs)) |
181 |> (#1 o PureThy.add_defs_i false (map Thm.no_attributes axpairs)) |
309 | add_induct_prem ind_alist (prem,iprems) = prem :: iprems; |
309 | add_induct_prem ind_alist (prem,iprems) = prem :: iprems; |
310 |
310 |
311 (*Make a premise of the induction rule.*) |
311 (*Make a premise of the induction rule.*) |
312 fun induct_prem ind_alist intr = |
312 fun induct_prem ind_alist intr = |
313 let val quantfrees = map dest_Free (term_frees intr \\ rec_params) |
313 let val quantfrees = map dest_Free (term_frees intr \\ rec_params) |
314 val iprems = foldr (add_induct_prem ind_alist) |
314 val iprems = Library.foldr (add_induct_prem ind_alist) |
315 (Logic.strip_imp_prems intr,[]) |
315 (Logic.strip_imp_prems intr,[]) |
316 val (t,X) = Ind_Syntax.rule_concl intr |
316 val (t,X) = Ind_Syntax.rule_concl intr |
317 val (SOME pred) = gen_assoc (op aconv) (ind_alist, X) |
317 val (SOME pred) = gen_assoc (op aconv) (ind_alist, X) |
318 val concl = FOLogic.mk_Trueprop (pred $ t) |
318 val concl = FOLogic.mk_Trueprop (pred $ t) |
319 in list_all_free (quantfrees, Logic.list_implies (iprems,concl)) end |
319 in list_all_free (quantfrees, Logic.list_implies (iprems,concl)) end |
330 val ind_prems = map (induct_prem (map (rpair pred) rec_tms)) |
330 val ind_prems = map (induct_prem (map (rpair pred) rec_tms)) |
331 intr_tms; |
331 intr_tms; |
332 |
332 |
333 val dummy = if !Ind_Syntax.trace then |
333 val dummy = if !Ind_Syntax.trace then |
334 (writeln "ind_prems = "; |
334 (writeln "ind_prems = "; |
335 seq (writeln o Sign.string_of_term sign1) ind_prems; |
335 List.app (writeln o Sign.string_of_term sign1) ind_prems; |
336 writeln "raw_induct = "; print_thm raw_induct) |
336 writeln "raw_induct = "; print_thm raw_induct) |
337 else (); |
337 else (); |
338 |
338 |
339 |
339 |
340 (*We use a MINIMAL simpset. Even FOL_ss contains too many simpules. |
340 (*We use a MINIMAL simpset. Even FOL_ss contains too many simpules. |
388 fun mk_predpair rec_tm = |
388 fun mk_predpair rec_tm = |
389 let val rec_name = (#1 o dest_Const o head_of) rec_tm |
389 let val rec_name = (#1 o dest_Const o head_of) rec_tm |
390 val pfree = Free(pred_name ^ "_" ^ Sign.base_name rec_name, |
390 val pfree = Free(pred_name ^ "_" ^ Sign.base_name rec_name, |
391 elem_factors ---> FOLogic.oT) |
391 elem_factors ---> FOLogic.oT) |
392 val qconcl = |
392 val qconcl = |
393 foldr FOLogic.mk_all |
393 Library.foldr FOLogic.mk_all |
394 (elem_frees, |
394 (elem_frees, |
395 FOLogic.imp $ |
395 FOLogic.imp $ |
396 (Ind_Syntax.mem_const $ elem_tuple $ rec_tm) |
396 (Ind_Syntax.mem_const $ elem_tuple $ rec_tm) |
397 $ (list_comb (pfree, elem_frees))) |
397 $ (list_comb (pfree, elem_frees))) |
398 in (CP.ap_split elem_type FOLogic.oT pfree, |
398 in (CP.ap_split elem_type FOLogic.oT pfree, |