139 val bd_Card_order = hd bd_Card_orders; |
139 val bd_Card_order = hd bd_Card_orders; |
140 val bd_Cinfinite = bd_Cinfinite_of_bnf (hd bnfs); |
140 val bd_Cinfinite = bd_Cinfinite_of_bnf (hd bnfs); |
141 val bd_Cnotzeros = map bd_Cnotzero_of_bnf bnfs; |
141 val bd_Cnotzeros = map bd_Cnotzero_of_bnf bnfs; |
142 val bd_Cnotzero = hd bd_Cnotzeros; |
142 val bd_Cnotzero = hd bd_Cnotzeros; |
143 val in_bds = map in_bd_of_bnf bnfs; |
143 val in_bds = map in_bd_of_bnf bnfs; |
|
144 val sym_map_comps = map (fn bnf => map_comp_of_bnf bnf RS sym) bnfs; |
144 val map_comp's = map map_comp'_of_bnf bnfs; |
145 val map_comp's = map map_comp'_of_bnf bnfs; |
145 val map_congs = map map_cong_of_bnf bnfs; |
146 val map_congs = map map_cong_of_bnf bnfs; |
146 val map_ids = map map_id_of_bnf bnfs; |
147 val map_ids = map map_id_of_bnf bnfs; |
147 val map_id's = map map_id'_of_bnf bnfs; |
148 val map_id's = map map_id'_of_bnf bnfs; |
148 val map_wpulls = map map_wpull_of_bnf bnfs; |
149 val map_wpulls = map map_wpull_of_bnf bnfs; |
978 val foldT = Library.foldr1 HOLogic.mk_prodT (map2 (curry op -->) Ts activeAs); |
979 val foldT = Library.foldr1 HOLogic.mk_prodT (map2 (curry op -->) Ts activeAs); |
979 val rec_sTs = map (Term.typ_subst_atomic (activeBs ~~ Ts)) prod_sTs; |
980 val rec_sTs = map (Term.typ_subst_atomic (activeBs ~~ Ts)) prod_sTs; |
980 val rec_maps = map (Term.subst_atomic_types (activeBs ~~ Ts)) map_fsts; |
981 val rec_maps = map (Term.subst_atomic_types (activeBs ~~ Ts)) map_fsts; |
981 val rec_maps_rev = map (Term.subst_atomic_types (activeBs ~~ Ts)) map_fsts_rev; |
982 val rec_maps_rev = map (Term.subst_atomic_types (activeBs ~~ Ts)) map_fsts_rev; |
982 val rec_fsts = map (Term.subst_atomic_types (activeBs ~~ Ts)) fsts; |
983 val rec_fsts = map (Term.subst_atomic_types (activeBs ~~ Ts)) fsts; |
|
984 val rec_UNIVs = map2 (HOLogic.mk_UNIV oo curry HOLogic.mk_prodT) Ts activeAs; |
983 |
985 |
984 val (((((((((Izs1, Izs1'), (Izs2, Izs2')), (xFs, xFs')), yFs), (AFss, AFss')), |
986 val (((((((((Izs1, Izs1'), (Izs2, Izs2')), (xFs, xFs')), yFs), (AFss, AFss')), |
985 (fold_f, fold_f')), fs), rec_ss), names_lthy) = names_lthy |
987 (fold_f, fold_f')), fs), rec_ss), names_lthy) = names_lthy |
986 |> mk_Frees' "z1" Ts |
988 |> mk_Frees' "z1" Ts |
987 ||>> mk_Frees' "z2" Ts' |
989 ||>> mk_Frees' "z2" Ts' |
1215 |
1217 |
1216 fun rec_bind i = Binding.suffix_name ("_" ^ ctor_recN) (nth bs (i - 1)); |
1218 fun rec_bind i = Binding.suffix_name ("_" ^ ctor_recN) (nth bs (i - 1)); |
1217 val rec_name = Binding.name_of o rec_bind; |
1219 val rec_name = Binding.name_of o rec_bind; |
1218 val rec_def_bind = rpair [] o Thm.def_binding o rec_bind; |
1220 val rec_def_bind = rpair [] o Thm.def_binding o rec_bind; |
1219 |
1221 |
|
1222 val rec_strs = |
|
1223 map3 (fn ctor => fn prod_s => fn mapx => |
|
1224 mk_convol (HOLogic.mk_comp (ctor, Term.list_comb (mapx, passive_ids @ rec_fsts)), prod_s)) |
|
1225 ctors rec_ss rec_maps; |
|
1226 |
1220 fun rec_spec i T AT = |
1227 fun rec_spec i T AT = |
1221 let |
1228 let |
1222 val recT = Library.foldr (op -->) (rec_sTs, T --> AT); |
1229 val recT = Library.foldr (op -->) (rec_sTs, T --> AT); |
1223 val maps = map3 (fn ctor => fn prod_s => fn mapx => |
|
1224 mk_convol (HOLogic.mk_comp (ctor, Term.list_comb (mapx, passive_ids @ rec_fsts)), prod_s)) |
|
1225 ctors rec_ss rec_maps; |
|
1226 |
1230 |
1227 val lhs = Term.list_comb (Free (rec_name i, recT), rec_ss); |
1231 val lhs = Term.list_comb (Free (rec_name i, recT), rec_ss); |
1228 val rhs = HOLogic.mk_comp (snd_const (HOLogic.mk_prodT (T, AT)), mk_fold Ts maps i); |
1232 val rhs = HOLogic.mk_comp (snd_const (HOLogic.mk_prodT (T, AT)), mk_fold Ts rec_strs i); |
1229 in |
1233 in |
1230 mk_Trueprop_eq (lhs, rhs) |
1234 mk_Trueprop_eq (lhs, rhs) |
1231 end; |
1235 end; |
1232 |
1236 |
1233 val ((rec_frees, (_, rec_def_frees)), (lthy, lthy_old)) = |
1237 val ((rec_frees, (_, rec_def_frees)), (lthy, lthy_old)) = |
1261 map2 (fn goal => fn foldx => |
1265 map2 (fn goal => fn foldx => |
1262 Goal.prove_sorry lthy [] [] goal (mk_rec_tac rec_defs foldx fst_rec_pair_thms) |
1266 Goal.prove_sorry lthy [] [] goal (mk_rec_tac rec_defs foldx fst_rec_pair_thms) |
1263 |> Thm.close_derivation) |
1267 |> Thm.close_derivation) |
1264 goals ctor_fold_thms |
1268 goals ctor_fold_thms |
1265 end; |
1269 end; |
|
1270 |
|
1271 val rec_unique_mor_thm = |
|
1272 let |
|
1273 val id_fs = map2 (fn T => fn f => mk_convol (HOLogic.id_const T, f)) Ts fs; |
|
1274 val prem = HOLogic.mk_Trueprop (mk_mor UNIVs ctors rec_UNIVs rec_strs id_fs); |
|
1275 fun mk_fun_eq f i = HOLogic.mk_eq (f, mk_rec rec_ss i); |
|
1276 val unique = HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj (map2 mk_fun_eq fs ks)); |
|
1277 in |
|
1278 Goal.prove_sorry lthy [] [] |
|
1279 (fold_rev Logic.all (rec_ss @ fs) (Logic.mk_implies (prem, unique))) |
|
1280 (mk_rec_unique_mor_tac rec_defs fst_rec_pair_thms fold_unique_mor_thm) |
|
1281 |> Thm.close_derivation |
|
1282 end; |
|
1283 |
|
1284 val ctor_rec_unique_thms = |
|
1285 split_conj_thm (split_conj_prems n |
|
1286 (mor_UNIV_thm RS @{thm ssubst[of _ _ "%x. x"]} RS rec_unique_mor_thm) |
|
1287 |> Local_Defs.unfold lthy (@{thms convol_o o_id id_o o_assoc[symmetric] fst_convol} @ |
|
1288 map_ids @ sym_map_comps) OF replicate n @{thm arg_cong2[of _ _ _ _ convol, OF refl]}); |
1266 |
1289 |
1267 val timer = time (timer "rec definitions & thms"); |
1290 val timer = time (timer "rec definitions & thms"); |
1268 |
1291 |
1269 val (ctor_induct_thm, induct_params) = |
1292 val (ctor_induct_thm, induct_params) = |
1270 let |
1293 let |
1815 val notes = |
1838 val notes = |
1816 [(ctor_dtorN, ctor_dtor_thms), |
1839 [(ctor_dtorN, ctor_dtor_thms), |
1817 (ctor_exhaustN, ctor_exhaust_thms), |
1840 (ctor_exhaustN, ctor_exhaust_thms), |
1818 (ctor_foldN, ctor_fold_thms), |
1841 (ctor_foldN, ctor_fold_thms), |
1819 (ctor_fold_uniqueN, ctor_fold_unique_thms), |
1842 (ctor_fold_uniqueN, ctor_fold_unique_thms), |
|
1843 (ctor_rec_uniqueN, ctor_rec_unique_thms), |
1820 (ctor_injectN, ctor_inject_thms), |
1844 (ctor_injectN, ctor_inject_thms), |
1821 (ctor_recN, ctor_rec_thms), |
1845 (ctor_recN, ctor_rec_thms), |
1822 (dtor_ctorN, dtor_ctor_thms), |
1846 (dtor_ctorN, dtor_ctor_thms), |
1823 (dtor_exhaustN, dtor_exhaust_thms), |
1847 (dtor_exhaustN, dtor_exhaust_thms), |
1824 (dtor_injectN, dtor_inject_thms)] |
1848 (dtor_injectN, dtor_inject_thms)] |