188 val rel_xtor_co_inducts_inst = |
188 val rel_xtor_co_inducts_inst = |
189 let |
189 let |
190 val extract = |
190 val extract = |
191 case_fp fp (snd o Term.dest_comb) (snd o Term.dest_comb o fst o Term.dest_comb); |
191 case_fp fp (snd o Term.dest_comb) (snd o Term.dest_comb o fst o Term.dest_comb); |
192 val raw_phis = map (extract o HOLogic.dest_Trueprop o Thm.concl_of) rel_xtor_co_inducts; |
192 val raw_phis = map (extract o HOLogic.dest_Trueprop o Thm.concl_of) rel_xtor_co_inducts; |
193 val thetas = AList.group (op =) |
193 val thetas = |
194 (mutual_cliques ~~ map (apply2 (Thm.cterm_of lthy)) (raw_phis ~~ pre_phis)); |
194 AList.group (op =) |
195 in |
195 (mutual_cliques ~~ |
196 map2 (Drule.cterm_instantiate o the o AList.lookup (op =) thetas) |
196 map (fn (t, u) => (#1 (dest_Var t), Thm.cterm_of lthy u)) (raw_phis ~~ pre_phis)); |
|
197 in |
|
198 map2 (infer_instantiate lthy o the o AList.lookup (op =) thetas) |
197 mutual_cliques rel_xtor_co_inducts |
199 mutual_cliques rel_xtor_co_inducts |
198 end |
200 end |
199 |
201 |
200 val xtor_rel_co_induct = |
202 val xtor_rel_co_induct = |
201 mk_xtor_rel_co_induct_thm fp (@{map 3} cast castAs castBs pre_rels) pre_phis rels phis xs ys |
203 mk_xtor_rel_co_induct_thm fp (@{map 3} cast castAs castBs pre_rels) pre_phis rels phis xs ys |
212 val (Ps, names_lthy) = names_lthy |
214 val (Ps, names_lthy) = names_lthy |
213 |> mk_Frees "P" (map (fn T => T --> HOLogic.boolT) fpTs); |
215 |> mk_Frees "P" (map (fn T => T --> HOLogic.boolT) fpTs); |
214 fun mk_Grp_id P = |
216 fun mk_Grp_id P = |
215 let val T = domain_type (fastype_of P); |
217 let val T = domain_type (fastype_of P); |
216 in mk_Grp (HOLogic.Collect_const T $ P) (HOLogic.id_const T) end; |
218 in mk_Grp (HOLogic.Collect_const T $ P) (HOLogic.id_const T) end; |
217 val cts = map (SOME o Thm.cterm_of lthy) (map HOLogic.eq_const As @ map mk_Grp_id Ps); |
219 val cts = |
|
220 map (SOME o Thm.cterm_of names_lthy) (map HOLogic.eq_const As @ map mk_Grp_id Ps); |
218 fun mk_fp_type_copy_thms thm = map (curry op RS thm) |
221 fun mk_fp_type_copy_thms thm = map (curry op RS thm) |
219 @{thms type_copy_Abs_o_Rep type_copy_vimage2p_Grp_Rep}; |
222 @{thms type_copy_Abs_o_Rep type_copy_vimage2p_Grp_Rep}; |
220 fun mk_type_copy_thms thm = map (curry op RS thm) |
223 fun mk_type_copy_thms thm = map (curry op RS thm) |
221 @{thms type_copy_Rep_o_Abs type_copy_vimage2p_Grp_Abs}; |
224 @{thms type_copy_Rep_o_Abs type_copy_vimage2p_Grp_Abs}; |
222 in |
225 in |
223 cterm_instantiate_pos cts xtor_rel_co_induct |
226 infer_instantiate' names_lthy cts xtor_rel_co_induct |
224 |> singleton (Proof_Context.export names_lthy lthy) |
227 |> singleton (Proof_Context.export names_lthy lthy) |
225 |> unfold_thms lthy (@{thms eq_le_Grp_id_iff all_simps(1,2)[symmetric]} @ |
228 |> unfold_thms lthy (@{thms eq_le_Grp_id_iff all_simps(1,2)[symmetric]} @ |
226 fp_or_nesting_rel_eqs) |
229 fp_or_nesting_rel_eqs) |
227 |> funpow n (fn thm => thm RS spec) |
230 |> funpow n (fn thm => thm RS spec) |
228 |> unfold_thms lthy (@{thm eq_alt} :: map rel_Grp_of_bnf bnfs @ map_id0s) |
231 |> unfold_thms lthy (@{thm eq_alt} :: map rel_Grp_of_bnf bnfs @ map_id0s) |
235 end |
238 end |
236 | Greatest_FP => |
239 | Greatest_FP => |
237 let |
240 let |
238 val cts = NONE :: map (SOME o Thm.cterm_of lthy) (map HOLogic.eq_const As); |
241 val cts = NONE :: map (SOME o Thm.cterm_of lthy) (map HOLogic.eq_const As); |
239 in |
242 in |
240 cterm_instantiate_pos cts xtor_rel_co_induct |
243 infer_instantiate' lthy cts xtor_rel_co_induct |
241 |> unfold_thms lthy (@{thms le_fun_def le_bool_def all_simps(1,2)[symmetric]} @ |
244 |> unfold_thms lthy (@{thms le_fun_def le_bool_def all_simps(1,2)[symmetric]} @ |
242 fp_or_nesting_rel_eqs) |
245 fp_or_nesting_rel_eqs) |
243 |> funpow (2 * n) (fn thm => thm RS spec) |
246 |> funpow (2 * n) (fn thm => thm RS spec) |
244 |> Conv.fconv_rule (Object_Logic.atomize lthy) |
247 |> Conv.fconv_rule (Object_Logic.atomize lthy) |
245 |> funpow n (fn thm => thm RS mp) |
248 |> funpow n (fn thm => thm RS mp) |