src/HOL/Tools/BNF/bnf_fp_def_sugar.ML
changeset 63842 f738df816abf
parent 63841 813a574da746
child 63845 61a03e429cbd
equal deleted inserted replaced
63841:813a574da746 63842:f738df816abf
   117   val wrap_ctrs: (string -> bool) -> BNF_Util.fp_kind -> bool -> string -> thm -> int -> int list ->
   117   val wrap_ctrs: (string -> bool) -> BNF_Util.fp_kind -> bool -> string -> thm -> int -> int list ->
   118     thm -> thm -> binding list -> binding list list -> term list -> term list -> thm -> thm list ->
   118     thm -> thm -> binding list -> binding list list -> term list -> term list -> thm -> thm list ->
   119     local_theory -> Ctr_Sugar.ctr_sugar * local_theory
   119     local_theory -> Ctr_Sugar.ctr_sugar * local_theory
   120   val derive_map_set_rel_pred_thms: (string -> bool) -> BNF_Util.fp_kind -> int -> typ list ->
   120   val derive_map_set_rel_pred_thms: (string -> bool) -> BNF_Util.fp_kind -> int -> typ list ->
   121     typ list -> typ -> typ -> thm list -> thm list -> thm list -> thm list -> thm list ->
   121     typ list -> typ -> typ -> thm list -> thm list -> thm list -> thm list -> thm list ->
   122     thm list -> thm list -> thm list -> string -> BNF_Def.bnf -> BNF_Def.bnf list -> typ -> term ->
   122     thm list -> thm list -> thm list -> thm list -> string -> BNF_Def.bnf -> BNF_Def.bnf list ->
   123     thm -> thm -> thm -> thm list -> thm -> thm -> thm list -> thm -> typ list list -> term ->
   123     typ -> term -> thm -> thm -> thm -> thm list -> thm -> thm -> thm list -> thm ->
   124     Ctr_Sugar.ctr_sugar -> Proof.context ->
   124     typ list list -> term -> Ctr_Sugar.ctr_sugar -> local_theory ->
   125     (thm list * thm list * thm list list * thm list * thm list * thm list * thm list * thm list
   125     (thm list * thm list * thm list list * thm list * thm list * thm list * thm list * thm list
   126      * thm list * thm list * thm list list list list * thm list list list list * thm list
   126      * thm list * thm list * thm list list list list * thm list list list list * thm list
   127      * thm list * thm list * thm list * thm list) * local_theory
   127      * thm list * thm list * thm list * thm list) * local_theory
   128 
   128 
   129   type lfp_sugar_thms = (thm list * thm * Token.src list) * (thm list list * Token.src list)
   129   type lfp_sugar_thms = (thm list * thm * Token.src list) * (thm list list * Token.src list)
   699   in
   699   in
   700     (ctr_sugar, lthy |> Local_Theory.notes (anonymous_notes @ notes) |> snd)
   700     (ctr_sugar, lthy |> Local_Theory.notes (anonymous_notes @ notes) |> snd)
   701   end;
   701   end;
   702 
   702 
   703 fun derive_map_set_rel_pred_thms plugins fp live As Bs C E abs_inverses ctr_defs fp_nesting_set_maps
   703 fun derive_map_set_rel_pred_thms plugins fp live As Bs C E abs_inverses ctr_defs fp_nesting_set_maps
   704     fp_nesting_rel_eq_onps live_nesting_map_id0s live_nesting_set_maps live_nesting_rel_eqs
   704     fp_nesting_rel_eq_onps live_nesting_map_id0s live_nesting_map_ident0s live_nesting_set_maps
   705     live_nesting_rel_eq_onps fp_b_name fp_bnf fp_bnfs fpT ctor ctor_dtor dtor_ctor pre_map_def
   705     live_nesting_rel_eqs live_nesting_rel_eq_onps fp_b_name fp_bnf fp_bnfs fpT ctor ctor_dtor
   706     pre_set_defs pre_rel_def fp_map_thm fp_set_thms fp_rel_thm ctr_Tss abs
   706     dtor_ctor pre_map_def pre_set_defs pre_rel_def fp_map_thm fp_set_thms fp_rel_thm ctr_Tss abs
   707     ({casex, case_thms, discs, selss, sel_defs, ctrs, exhaust, exhaust_discs, disc_thmss, sel_thmss,
   707     ({casex, case_thms, discs, selss, sel_defs, ctrs, exhaust, exhaust_discs, disc_thmss, sel_thmss,
   708       injects, distincts, distinct_discsss, ...} : ctr_sugar)
   708       injects, distincts, distinct_discsss, ...} : ctr_sugar)
   709     lthy =
   709     lthy =
   710   let
   710   let
   711     val n = length ctr_Tss;
   711     val n = length ctr_Tss;
   869             val fp_map_thm' =
   869             val fp_map_thm' =
   870               if fp = Least_FP then fp_map_thm
   870               if fp = Least_FP then fp_map_thm
   871               else fp_map_thm RS ctor_cong RS (ctor_dtor RS sym RS trans);
   871               else fp_map_thm RS ctor_cong RS (ctor_dtor RS sym RS trans);
   872           in
   872           in
   873             Goal.prove_sorry lthy vars [] goal (fn {context = ctxt, prems = _} =>
   873             Goal.prove_sorry lthy vars [] goal (fn {context = ctxt, prems = _} =>
   874                mk_map_tac ctxt abs_inverses pre_map_def dtor_ctor fp_map_thm' ctr_defs')
   874               mk_map_tac ctxt abs_inverses pre_map_def dtor_ctor fp_map_thm'
       
   875                 live_nesting_map_ident0s ctr_defs')
   875             |> Thm.close_derivation
   876             |> Thm.close_derivation
   876             |> Conjunction.elim_balanced (length goals)
   877             |> Conjunction.elim_balanced (length goals)
   877           end;
   878           end;
   878 
   879 
   879         val rel_inject_thms =
   880         val rel_inject_thms =
   894             val goals = @{map 4} mk_goal ctrAs ctrBs xss yss;
   895             val goals = @{map 4} mk_goal ctrAs ctrBs xss yss;
   895             val goal = Logic.mk_conjunction_balanced goals;
   896             val goal = Logic.mk_conjunction_balanced goals;
   896             val vars = Variable.add_free_names lthy goal [];
   897             val vars = Variable.add_free_names lthy goal [];
   897           in
   898           in
   898             Goal.prove_sorry lthy vars [] goal (fn {context = ctxt, prems = _} =>
   899             Goal.prove_sorry lthy vars [] goal (fn {context = ctxt, prems = _} =>
   899                mk_rel_tac ctxt abs_inverses pre_rel_def dtor_ctor fp_rel_thm ctr_defs')
   900               mk_rel_tac ctxt abs_inverses pre_rel_def dtor_ctor fp_rel_thm live_nesting_rel_eqs
       
   901                 ctr_defs')
   900             |> Thm.close_derivation
   902             |> Thm.close_derivation
   901             |> Conjunction.elim_balanced (length goals)
   903             |> Conjunction.elim_balanced (length goals)
   902           end;
   904           end;
   903 
   905 
   904         val half_rel_distinct_thmss =
   906         val half_rel_distinct_thmss =
   923                  let
   925                  let
   924                    val goal = Logic.mk_conjunction_balanced goals;
   926                    val goal = Logic.mk_conjunction_balanced goals;
   925                    val vars = Variable.add_free_names lthy goal [];
   927                    val vars = Variable.add_free_names lthy goal [];
   926                  in
   928                  in
   927                    Goal.prove_sorry lthy vars [] goal (fn {context = ctxt, prems = _} =>
   929                    Goal.prove_sorry lthy vars [] goal (fn {context = ctxt, prems = _} =>
   928                      mk_rel_tac ctxt abs_inverses pre_rel_def dtor_ctor fp_rel_thm ctr_defs')
   930                      mk_rel_tac ctxt abs_inverses pre_rel_def dtor_ctor fp_rel_thm
       
   931                        live_nesting_rel_eqs ctr_defs')
   929                    |> Thm.close_derivation
   932                    |> Thm.close_derivation
   930                    |> Conjunction.elim_balanced (length goals)
   933                    |> Conjunction.elim_balanced (length goals)
   931                  end)
   934                  end)
   932           end;
   935           end;
   933 
   936 
  2460       in
  2463       in
  2461         (wrap_ctrs plugins fp discs_sels fp_b_name ctor_inject n ms abs_inject type_definition
  2464         (wrap_ctrs plugins fp discs_sels fp_b_name ctor_inject n ms abs_inject type_definition
  2462            disc_bindings sel_bindingss sel_default_eqs ctrs0 ctor_iff_dtor_thm ctr_defs
  2465            disc_bindings sel_bindingss sel_default_eqs ctrs0 ctor_iff_dtor_thm ctr_defs
  2463          #> (fn (ctr_sugar, lthy) =>
  2466          #> (fn (ctr_sugar, lthy) =>
  2464            derive_map_set_rel_pred_thms plugins fp live As Bs C E abs_inverses ctr_defs
  2467            derive_map_set_rel_pred_thms plugins fp live As Bs C E abs_inverses ctr_defs
  2465              fp_nesting_set_maps fp_nesting_rel_eq_onps live_nesting_map_id0s live_nesting_set_maps
  2468              fp_nesting_set_maps fp_nesting_rel_eq_onps live_nesting_map_id0s
  2466              live_nesting_rel_eqs live_nesting_rel_eq_onps fp_b_name fp_bnf fp_bnfs fpT ctor
  2469              live_nesting_map_ident0s live_nesting_set_maps live_nesting_rel_eqs
  2467              ctor_dtor dtor_ctor pre_map_def pre_set_defs pre_rel_def fp_map_thm fp_set_thms
  2470              live_nesting_rel_eq_onps fp_b_name fp_bnf fp_bnfs fpT ctor ctor_dtor dtor_ctor
  2468              fp_rel_thm ctr_Tss abs ctr_sugar lthy
  2471              pre_map_def pre_set_defs pre_rel_def fp_map_thm fp_set_thms fp_rel_thm ctr_Tss abs
       
  2472              ctr_sugar lthy
  2469            |>> pair ctr_sugar)
  2473            |>> pair ctr_sugar)
  2470          ##>>
  2474          ##>>
  2471            (if fp = Least_FP then define_rec (the recs_args_types) mk_binding fpTs Cs reps
  2475            (if fp = Least_FP then define_rec (the recs_args_types) mk_binding fpTs Cs reps
  2472             else define_corec (the corecs_args_types) mk_binding fpTs Cs abss) xtor_co_rec
  2476             else define_corec (the corecs_args_types) mk_binding fpTs Cs abss) xtor_co_rec
  2473          #>> apfst massage_res, lthy)
  2477          #>> apfst massage_res, lthy)