src/HOL/Tools/BNF/bnf_fp_n2m_sugar.ML
changeset 55864 516ab2906e7e
parent 55863 fa3a1ec69a1b
child 55867 79b915f26533
equal deleted inserted replaced
55863:fa3a1ec69a1b 55864:516ab2906e7e
   243         val ((xtor_co_iterss, iters_args_types, coiters_args_types), _) =
   243         val ((xtor_co_iterss, iters_args_types, coiters_args_types), _) =
   244           mk_co_iters_prelims fp ctr_Tsss fpTs Cs absTs repTs ns mss xtor_co_iterss0 lthy;
   244           mk_co_iters_prelims fp ctr_Tsss fpTs Cs absTs repTs ns mss xtor_co_iterss0 lthy;
   245 
   245 
   246         fun mk_binding b suf = Binding.suffix_name ("_" ^ suf) b;
   246         fun mk_binding b suf = Binding.suffix_name ("_" ^ suf) b;
   247 
   247 
   248         val ((co_iterss, co_iter_defss), lthy) =
   248         val ((co_recs, co_rec_defs), lthy) =
   249           fold_map2 (fn b =>
   249           fold_map2 (fn b =>
   250             if fp = Least_FP then define_iter iters_args_types (mk_binding b) fpTs Cs reps
   250             if fp = Least_FP then define_iter iters_args_types (mk_binding b) fpTs Cs reps
   251             else define_coiter (the coiters_args_types) (mk_binding b) fpTs Cs abss)
   251             else define_coiter (the coiters_args_types) (mk_binding b) fpTs Cs abss)
   252             fp_bs (map co_rec_of xtor_co_iterss) lthy
   252             fp_bs (map co_rec_of xtor_co_iterss) lthy
   253           |>> split_list;
   253           |>> split_list;
   255         val ((common_co_inducts, co_inductss, co_rec_thmss, disc_corec_thmss, sel_corec_thmsss),
   255         val ((common_co_inducts, co_inductss, co_rec_thmss, disc_corec_thmss, sel_corec_thmsss),
   256              fp_sugar_thms) =
   256              fp_sugar_thms) =
   257           if fp = Least_FP then
   257           if fp = Least_FP then
   258             derive_induct_iters_thms_for_types pre_bnfs iters_args_types xtor_co_induct
   258             derive_induct_iters_thms_for_types pre_bnfs iters_args_types xtor_co_induct
   259               xtor_co_iter_thmss nesting_bnfs nested_bnfs fpTs Cs Xs ctrXs_Tsss fp_abs_inverses
   259               xtor_co_iter_thmss nesting_bnfs nested_bnfs fpTs Cs Xs ctrXs_Tsss fp_abs_inverses
   260               fp_type_definitions abs_inverses ctrss ctr_defss co_iterss co_iter_defss lthy
   260               fp_type_definitions abs_inverses ctrss ctr_defss co_recs co_rec_defs lthy
   261             |> `(fn ((inducts, induct, _), (rec_thmss, _)) =>
   261             |> `(fn ((inducts, induct, _), (rec_thmss, _)) =>
   262               ([induct], [inducts], rec_thmss, replicate nn [], replicate nn []))
   262               ([induct], [inducts], rec_thmss, replicate nn [], replicate nn []))
   263             ||> (fn info => (SOME info, NONE))
   263             ||> (fn info => (SOME info, NONE))
   264           else
   264           else
   265             derive_coinduct_coiters_thms_for_types pre_bnfs (the coiters_args_types) xtor_co_induct
   265             derive_coinduct_coiters_thms_for_types pre_bnfs (the coiters_args_types) xtor_co_induct
   266               dtor_injects dtor_ctors xtor_co_iter_thmss nesting_bnfs fpTs Cs Xs ctrXs_Tsss kss mss
   266               dtor_injects dtor_ctors xtor_co_iter_thmss nesting_bnfs fpTs Cs Xs ctrXs_Tsss kss mss
   267               ns fp_abs_inverses abs_inverses (fn thm => thm RS @{thm vimage2p_refl}) ctr_defss
   267               ns fp_abs_inverses abs_inverses (fn thm => thm RS @{thm vimage2p_refl}) ctr_defss
   268               ctr_sugars co_iterss co_iter_defss (Proof_Context.export lthy no_defs_lthy) lthy
   268               ctr_sugars co_recs co_rec_defs (Proof_Context.export lthy no_defs_lthy) lthy
   269             |> `(fn ((coinduct_thms_pairs, _), (corec_thmss, _), (disc_corec_thmss, _), _,
   269             |> `(fn ((coinduct_thms_pairs, _), (corec_thmss, _), (disc_corec_thmss, _), _,
   270                      (sel_corec_thmsss, _)) =>
   270                      (sel_corec_thmsss, _)) =>
   271               (map snd coinduct_thms_pairs, map fst coinduct_thms_pairs, corec_thmss,
   271               (map snd coinduct_thms_pairs, map fst coinduct_thms_pairs, corec_thmss,
   272                disc_corec_thmss, sel_corec_thmsss))
   272                disc_corec_thmss, sel_corec_thmsss))
   273             ||> (fn info => (NONE, SOME info));
   273             ||> (fn info => (NONE, SOME info));
   284            sel_co_recss = sel_corec_thmss}
   284            sel_co_recss = sel_corec_thmss}
   285           |> morph_fp_sugar phi;
   285           |> morph_fp_sugar phi;
   286 
   286 
   287         val target_fp_sugars =
   287         val target_fp_sugars =
   288           map14 mk_target_fp_sugar fpTs Xs kks pre_bnfs absT_infos ctrXs_Tsss ctr_defss ctr_sugars
   288           map14 mk_target_fp_sugar fpTs Xs kks pre_bnfs absT_infos ctrXs_Tsss ctr_defss ctr_sugars
   289             (map the_single co_iterss) mapss (transpose co_inductss) co_rec_thmss disc_corec_thmss
   289             co_recs mapss (transpose co_inductss) co_rec_thmss disc_corec_thmss sel_corec_thmsss;
   290             sel_corec_thmsss;
       
   291 
   290 
   292         val n2m_sugar = (target_fp_sugars, fp_sugar_thms);
   291         val n2m_sugar = (target_fp_sugars, fp_sugar_thms);
   293       in
   292       in
   294         (n2m_sugar, lthy |> register_n2m_sugar key n2m_sugar)
   293         (n2m_sugar, lthy |> register_n2m_sugar key n2m_sugar)
   295       end)
   294       end)