77 |
77 |
78 type corec_spec = |
78 type corec_spec = |
79 {corec: term, |
79 {corec: term, |
80 disc_exhausts: thm list, |
80 disc_exhausts: thm list, |
81 sel_defs: thm list, |
81 sel_defs: thm list, |
82 nested_maps: thm list, |
82 fp_nesting_maps: thm list, |
83 nested_map_idents: thm list, |
83 fp_nesting_map_idents: thm list, |
84 nested_map_comps: thm list, |
84 fp_nesting_map_comps: thm list, |
85 ctr_specs: corec_ctr_spec list}; |
85 ctr_specs: corec_ctr_spec list}; |
86 |
86 |
87 exception NOT_A_MAP of term; |
87 exception NOT_A_MAP of term; |
88 |
88 |
89 fun not_codatatype ctxt T = |
89 fun not_codatatype ctxt T = |
373 |
373 |
374 fun corec_specs_of bs arg_Ts res_Ts callers callssss0 lthy0 = |
374 fun corec_specs_of bs arg_Ts res_Ts callers callssss0 lthy0 = |
375 let |
375 let |
376 val thy = Proof_Context.theory_of lthy0; |
376 val thy = Proof_Context.theory_of lthy0; |
377 |
377 |
378 val ((missing_res_Ts, perm0_kks, fp_sugars as {nested_bnfs, |
378 val ((missing_res_Ts, perm0_kks, fp_sugars as {fp_nesting_bnfs, |
379 common_co_inducts = common_coinduct_thms, ...} :: _, (_, gfp_sugar_thms)), lthy) = |
379 common_co_inducts = common_coinduct_thms, ...} :: _, (_, gfp_sugar_thms)), lthy) = |
380 nested_to_mutual_fps Greatest_FP bs res_Ts callers callssss0 lthy0; |
380 nested_to_mutual_fps Greatest_FP bs res_Ts callers callssss0 lthy0; |
381 |
381 |
382 val perm_fp_sugars = sort (int_ord o pairself #fp_res_index) fp_sugars; |
382 val perm_fp_sugars = sort (int_ord o pairself #fp_res_index) fp_sugars; |
383 |
383 |
462 |
462 |
463 fun mk_spec ({T, ctr_sugar as {disc_exhausts, sel_defs, ...}, co_rec = corec, |
463 fun mk_spec ({T, ctr_sugar as {disc_exhausts, sel_defs, ...}, co_rec = corec, |
464 co_rec_thms = corec_thms, disc_co_recs = disc_corecs, |
464 co_rec_thms = corec_thms, disc_co_recs = disc_corecs, |
465 sel_co_recss = sel_corecss, ...} : fp_sugar) p_is q_isss f_isss f_Tsss = |
465 sel_co_recss = sel_corecss, ...} : fp_sugar) p_is q_isss f_isss f_Tsss = |
466 {corec = mk_co_rec thy Greatest_FP (substAT T) perm_Cs' corec, disc_exhausts = disc_exhausts, |
466 {corec = mk_co_rec thy Greatest_FP (substAT T) perm_Cs' corec, disc_exhausts = disc_exhausts, |
467 sel_defs = sel_defs, nested_maps = maps (map_thms_of_typ lthy o T_of_bnf) nested_bnfs, |
467 sel_defs = sel_defs, |
468 nested_map_idents = map (unfold_thms lthy @{thms id_def} o map_id0_of_bnf) nested_bnfs, |
468 fp_nesting_maps = maps (map_thms_of_typ lthy o T_of_bnf) fp_nesting_bnfs, |
469 nested_map_comps = map map_comp_of_bnf nested_bnfs, |
469 fp_nesting_map_idents = |
|
470 map (unfold_thms lthy @{thms id_def} o map_id0_of_bnf) fp_nesting_bnfs, |
|
471 fp_nesting_map_comps = map map_comp_of_bnf fp_nesting_bnfs, |
470 ctr_specs = mk_ctr_specs ctr_sugar p_is q_isss f_isss f_Tsss corec_thms disc_corecs |
472 ctr_specs = mk_ctr_specs ctr_sugar p_is q_isss f_isss f_Tsss corec_thms disc_corecs |
471 sel_corecss}; |
473 sel_corecss}; |
472 in |
474 in |
473 ((is_some gfp_sugar_thms, map5 mk_spec fp_sugars p_iss q_issss f_issss f_Tssss, missing_res_Ts, |
475 ((is_some gfp_sugar_thms, map5 mk_spec fp_sugars p_iss q_issss f_issss f_Tssss, missing_res_Ts, |
474 co_induct_of common_coinduct_thms, strong_co_induct_of common_coinduct_thms, |
476 co_induct_of common_coinduct_thms, strong_co_induct_of common_coinduct_thms, |
1171 |> pair (#disc (nth ctr_specs ctr_no)) |
1173 |> pair (#disc (nth ctr_specs ctr_no)) |
1172 |> pair eqn_pos |
1174 |> pair eqn_pos |
1173 |> single |
1175 |> single |
1174 end; |
1176 end; |
1175 |
1177 |
1176 fun prove_sel ({sel_defs, nested_maps, nested_map_idents, nested_map_comps, ctr_specs, ...} |
1178 fun prove_sel ({sel_defs, fp_nesting_maps, fp_nesting_map_idents, fp_nesting_map_comps, |
1177 : corec_spec) (disc_eqns : coeqn_data_disc list) excludesss |
1179 ctr_specs, ...} : corec_spec) (disc_eqns : coeqn_data_disc list) excludesss |
1178 ({fun_name, fun_T, fun_args, ctr, sel, rhs_term, code_rhs_opt, eqn_pos, ...} |
1180 ({fun_name, fun_T, fun_args, ctr, sel, rhs_term, code_rhs_opt, eqn_pos, ...} |
1179 : coeqn_data_sel) = |
1181 : coeqn_data_sel) = |
1180 let |
1182 let |
1181 val SOME ctr_spec = find_first (curry (op =) ctr o #ctr) ctr_specs; |
1183 val SOME ctr_spec = find_first (curry (op =) ctr o #ctr) ctr_specs; |
1182 val ctr_no = find_index (curry (op =) ctr o #ctr) ctr_specs; |
1184 val ctr_no = find_index (curry (op =) ctr o #ctr) ctr_specs; |
1193 |> HOLogic.mk_Trueprop o HOLogic.mk_eq |
1195 |> HOLogic.mk_Trueprop o HOLogic.mk_eq |
1194 |> curry Logic.list_implies (map HOLogic.mk_Trueprop prems) |
1196 |> curry Logic.list_implies (map HOLogic.mk_Trueprop prems) |
1195 |> curry Logic.list_all (map dest_Free fun_args); |
1197 |> curry Logic.list_all (map dest_Free fun_args); |
1196 val (distincts, _, _, sel_splits, sel_split_asms) = case_thms_of_term lthy rhs_term; |
1198 val (distincts, _, _, sel_splits, sel_split_asms) = case_thms_of_term lthy rhs_term; |
1197 in |
1199 in |
1198 mk_primcorec_sel_tac lthy def_thms distincts sel_splits sel_split_asms nested_maps |
1200 mk_primcorec_sel_tac lthy def_thms distincts sel_splits sel_split_asms fp_nesting_maps |
1199 nested_map_idents nested_map_comps sel_corec k m excludesss |
1201 fp_nesting_map_idents fp_nesting_map_comps sel_corec k m excludesss |
1200 |> K |> Goal.prove_sorry lthy [] [] goal |
1202 |> K |> Goal.prove_sorry lthy [] [] goal |
1201 |> Thm.close_derivation |
1203 |> Thm.close_derivation |
1202 |> `(is_some code_rhs_opt ? fold_thms lthy sel_defs) (*mildly too aggressive*) |
1204 |> `(is_some code_rhs_opt ? fold_thms lthy sel_defs) (*mildly too aggressive*) |
1203 |> pair sel |
1205 |> pair sel |
1204 |> pair eqn_pos |
1206 |> pair eqn_pos |