67 disc_corec: thm, |
67 disc_corec: thm, |
68 sel_corecs: thm list}; |
68 sel_corecs: thm list}; |
69 |
69 |
70 type corec_spec = |
70 type corec_spec = |
71 {corec: term, |
71 {corec: term, |
72 nested_maps: thm list, |
|
73 nested_map_idents: thm list, |
72 nested_map_idents: thm list, |
74 nested_map_comps: thm list, |
73 nested_map_comps: thm list, |
75 ctr_specs: corec_ctr_spec list}; |
74 ctr_specs: corec_ctr_spec list}; |
76 |
75 |
77 exception AINT_NO_MAP of term; |
76 exception AINT_NO_MAP of term; |
341 in |
340 in |
342 map3 mk_spec ctrs discs selss |
341 map3 mk_spec ctrs discs selss |
343 end) |
342 end) |
344 | _ => not_codatatype ctxt res_T); |
343 | _ => not_codatatype ctxt res_T); |
345 |
344 |
346 (*FIXME: remove special cases for product and sum once they are registered as datatypes*) |
|
347 fun map_thms_of_typ ctxt (Type (s, _)) = |
|
348 if s = @{type_name prod} then |
|
349 @{thms map_pair_simp} |
|
350 else if s = @{type_name sum} then |
|
351 @{thms sum_map.simps} |
|
352 else |
|
353 (case fp_sugar_of ctxt s of |
|
354 SOME {index, mapss, ...} => nth mapss index |
|
355 | NONE => []) |
|
356 | map_thms_of_typ _ _ = []; |
|
357 |
|
358 fun corec_specs_of bs arg_Ts res_Ts get_indices callssss0 lthy = |
345 fun corec_specs_of bs arg_Ts res_Ts get_indices callssss0 lthy = |
359 let |
346 let |
360 val thy = Proof_Context.theory_of lthy; |
347 val thy = Proof_Context.theory_of lthy; |
361 |
348 |
362 val ((missing_res_Ts, perm0_kks, |
349 val ((missing_res_Ts, perm0_kks, |
447 |
434 |
448 fun mk_spec ({T, index, ctr_sugars, co_iterss = coiterss, co_iter_thmsss = coiter_thmsss, |
435 fun mk_spec ({T, index, ctr_sugars, co_iterss = coiterss, co_iter_thmsss = coiter_thmsss, |
449 disc_co_itersss = disc_coitersss, sel_co_iterssss = sel_coiterssss, ...} : fp_sugar) |
436 disc_co_itersss = disc_coitersss, sel_co_iterssss = sel_coiterssss, ...} : fp_sugar) |
450 p_is q_isss f_isss f_Tsss = |
437 p_is q_isss f_isss f_Tsss = |
451 {corec = mk_co_iter thy Greatest_FP (substAT T) perm_Cs' (co_rec_of (nth coiterss index)), |
438 {corec = mk_co_iter thy Greatest_FP (substAT T) perm_Cs' (co_rec_of (nth coiterss index)), |
452 nested_maps = maps (map_thms_of_typ lthy o T_of_bnf) nested_bnfs, |
|
453 nested_map_idents = map (unfold_thms lthy @{thms id_def} o map_id0_of_bnf) nested_bnfs, |
439 nested_map_idents = map (unfold_thms lthy @{thms id_def} o map_id0_of_bnf) nested_bnfs, |
454 nested_map_comps = map map_comp_of_bnf nested_bnfs, |
440 nested_map_comps = map map_comp_of_bnf nested_bnfs, |
455 ctr_specs = mk_ctr_specs index ctr_sugars p_is q_isss f_isss f_Tsss coiter_thmsss |
441 ctr_specs = mk_ctr_specs index ctr_sugars p_is q_isss f_isss f_Tsss coiter_thmsss |
456 disc_coitersss sel_coiterssss}; |
442 disc_coitersss sel_coiterssss}; |
457 in |
443 in |
945 |> Thm.close_derivation |
931 |> Thm.close_derivation |
946 |> pair (#disc (nth ctr_specs ctr_no)) |
932 |> pair (#disc (nth ctr_specs ctr_no)) |
947 |> single |
933 |> single |
948 end; |
934 end; |
949 |
935 |
950 fun prove_sel ({nested_maps, nested_map_idents, nested_map_comps, ctr_specs, ...} |
936 fun prove_sel ({nested_map_idents, nested_map_comps, ctr_specs, ...} : corec_spec) |
951 : corec_spec) (disc_eqns : coeqn_data_disc list) exclsss |
937 (disc_eqns : coeqn_data_disc list) exclsss |
952 ({fun_name, fun_T, fun_args, ctr, sel, rhs_term, ...} : coeqn_data_sel) = |
938 ({fun_name, fun_T, fun_args, ctr, sel, rhs_term, ...} : coeqn_data_sel) = |
953 let |
939 let |
954 val SOME ctr_spec = find_first (equal ctr o #ctr) ctr_specs; |
940 val SOME ctr_spec = find_first (equal ctr o #ctr) ctr_specs; |
955 val ctr_no = find_index (equal ctr o #ctr) ctr_specs; |
941 val ctr_no = find_index (equal ctr o #ctr) ctr_specs; |
956 val prems = the_default (maps (s_not_conj o #prems) disc_eqns) |
942 val prems = the_default (maps (s_not_conj o #prems) disc_eqns) |
966 |> HOLogic.mk_Trueprop o HOLogic.mk_eq |
952 |> HOLogic.mk_Trueprop o HOLogic.mk_eq |
967 |> curry Logic.list_implies (map HOLogic.mk_Trueprop prems) |
953 |> curry Logic.list_implies (map HOLogic.mk_Trueprop prems) |
968 |> curry Logic.list_all (map dest_Free fun_args); |
954 |> curry Logic.list_all (map dest_Free fun_args); |
969 val (distincts, _, sel_splits, sel_split_asms) = case_thms_of_term lthy [] rhs_term; |
955 val (distincts, _, sel_splits, sel_split_asms) = case_thms_of_term lthy [] rhs_term; |
970 in |
956 in |
971 mk_primcorec_sel_tac lthy def_thms distincts sel_splits sel_split_asms nested_maps |
957 mk_primcorec_sel_tac lthy def_thms distincts sel_splits sel_split_asms nested_map_idents |
972 nested_map_idents nested_map_comps sel_corec k m exclsss |
958 nested_map_comps sel_corec k m exclsss |
973 |> K |> Goal.prove lthy [] [] t |
959 |> K |> Goal.prove lthy [] [] t |
974 |> Thm.close_derivation |
960 |> Thm.close_derivation |
975 |> pair sel |
961 |> pair sel |
976 end; |
962 end; |
977 |
963 |