src/HOL/Tools/BNF/bnf_fp_def_sugar.ML
changeset 56347 6edbd4d20717
parent 56254 a2dd9200854d
child 56376 5a93b8f928a2
equal deleted inserted replaced
56346:42533f8f4729 56347:6edbd4d20717
    30 
    30 
    31   val morph_fp_sugar: morphism -> fp_sugar -> fp_sugar
    31   val morph_fp_sugar: morphism -> fp_sugar -> fp_sugar
    32   val transfer_fp_sugar: Proof.context -> fp_sugar -> fp_sugar
    32   val transfer_fp_sugar: Proof.context -> fp_sugar -> fp_sugar
    33   val fp_sugar_of: Proof.context -> string -> fp_sugar option
    33   val fp_sugar_of: Proof.context -> string -> fp_sugar option
    34   val fp_sugars_of: Proof.context -> fp_sugar list
    34   val fp_sugars_of: Proof.context -> fp_sugar list
       
    35   val fp_sugar_interpretation: (fp_sugar -> theory -> theory) -> theory -> theory
       
    36   val register_fp_sugar: string -> fp_sugar -> local_theory -> local_theory
    35 
    37 
    36   val co_induct_of: 'a list -> 'a
    38   val co_induct_of: 'a list -> 'a
    37   val strong_co_induct_of: 'a list -> 'a
    39   val strong_co_induct_of: 'a list -> 'a
    38 
    40 
    39   val flat_corec_preds_predsss_gettersss: 'a list -> 'a list list list -> 'a list list list ->
    41   val flat_corec_preds_predsss_gettersss: 'a list -> 'a list list list -> 'a list list list ->
    73     (typ list list * typ list list list list * term list list * term list list list list) option ->
    75     (typ list list * typ list list list list * term list list * term list list list list) option ->
    74     (string -> binding) -> typ list -> typ list -> term list -> term -> Proof.context ->
    76     (string -> binding) -> typ list -> typ list -> term list -> term -> Proof.context ->
    75     (term * thm) * Proof.context
    77     (term * thm) * Proof.context
    76   val define_corec: 'a * term list * term list list
    78   val define_corec: 'a * term list * term list list
    77       * ((term list list * term list list list) * typ list) -> (string -> binding) -> 'b list ->
    79       * ((term list list * term list list list) * typ list) -> (string -> binding) -> 'b list ->
    78     typ list -> term list -> term -> Proof.context -> (term * thm) * local_theory
    80     typ list -> term list -> term -> local_theory -> (term * thm) * local_theory
    79   val derive_induct_recs_thms_for_types: BNF_Def.bnf list ->
    81   val derive_induct_recs_thms_for_types: BNF_Def.bnf list ->
    80      ('a * typ list list list list * term list list * 'b) option -> thm -> thm list ->
    82      ('a * typ list list list list * term list list * 'b) option -> thm -> thm list ->
    81      BNF_Def.bnf list -> BNF_Def.bnf list -> typ list -> typ list -> typ list ->
    83      BNF_Def.bnf list -> BNF_Def.bnf list -> typ list -> typ list -> typ list ->
    82      typ list list list -> thm list -> thm list -> thm list -> term list list -> thm list list ->
    84      typ list list list -> thm list -> thm list -> thm list -> term list list -> thm list list ->
    83      term list -> thm list -> Proof.context -> lfp_sugar_thms
    85      term list -> thm list -> Proof.context -> lfp_sugar_thms
    84   val derive_coinduct_corecs_thms_for_types: BNF_Def.bnf list ->
    86   val derive_coinduct_corecs_thms_for_types: BNF_Def.bnf list ->
    85     string * term list * term list list * ((term list list * term list list list) * typ list) ->
    87     string * term list * term list list * ((term list list * term list list list) * typ list) ->
    86     thm -> thm list -> thm list -> thm list -> BNF_Def.bnf list -> typ list -> typ list ->
    88     thm -> thm list -> thm list -> thm list -> BNF_Def.bnf list -> typ list -> typ list ->
    87     typ list -> typ list list list -> int list list -> int list list -> int list -> thm list ->
    89     typ list -> typ list list list -> int list list -> int list list -> int list -> thm list ->
    88     thm list -> (thm -> thm) -> thm list list -> Ctr_Sugar.ctr_sugar list -> term list ->
    90     thm list -> (thm -> thm) -> thm list list -> Ctr_Sugar.ctr_sugar list -> term list ->
    89     thm list -> (thm list -> thm list) -> local_theory -> gfp_sugar_thms
    91     thm list -> (thm list -> thm list) -> Proof.context -> gfp_sugar_thms
    90 
    92 
    91   type co_datatype_spec =
    93   type co_datatype_spec =
    92     ((((binding option * (typ * sort)) list * binding) * (binding * binding)) * mixfix)
    94     ((((binding option * (typ * sort)) list * binding) * (binding * binding)) * mixfix)
    93     * ((binding, binding * typ, term) Ctr_Sugar.ctr_spec * mixfix) list
    95     * ((binding, binding * typ, term) Ctr_Sugar.ctr_spec * mixfix) list
    94 
    96 
   160    co_inducts = map (Morphism.thm phi) co_inducts,
   162    co_inducts = map (Morphism.thm phi) co_inducts,
   161    co_rec_thms = map (Morphism.thm phi) co_rec_thms,
   163    co_rec_thms = map (Morphism.thm phi) co_rec_thms,
   162    disc_co_recs = map (Morphism.thm phi) disc_co_recs,
   164    disc_co_recs = map (Morphism.thm phi) disc_co_recs,
   163    sel_co_recss = map (map (Morphism.thm phi)) sel_co_recss};
   165    sel_co_recss = map (map (Morphism.thm phi)) sel_co_recss};
   164 
   166 
   165 val transfer_fp_sugar =
   167 val transfer_fp_sugar = morph_fp_sugar o Morphism.transfer_morphism o Proof_Context.theory_of;
   166   morph_fp_sugar o Morphism.transfer_morphism o Proof_Context.theory_of;
       
   167 
   168 
   168 structure Data = Generic_Data
   169 structure Data = Generic_Data
   169 (
   170 (
   170   type T = fp_sugar Symtab.table;
   171   type T = fp_sugar Symtab.table;
   171   val empty = Symtab.empty;
   172   val empty = Symtab.empty;
   181   Symtab.fold (cons o transfer_fp_sugar ctxt o snd) (Data.get (Context.Proof ctxt)) [];
   182   Symtab.fold (cons o transfer_fp_sugar ctxt o snd) (Data.get (Context.Proof ctxt)) [];
   182 
   183 
   183 fun co_induct_of (i :: _) = i;
   184 fun co_induct_of (i :: _) = i;
   184 fun strong_co_induct_of [_, s] = s;
   185 fun strong_co_induct_of [_, s] = s;
   185 
   186 
       
   187 structure FP_Sugar_Interpretation = Interpretation
       
   188 (
       
   189   type T = fp_sugar;
       
   190   val eq: T * T -> bool = op = o pairself #T;
       
   191 );
       
   192 
       
   193 val fp_sugar_interpretation = FP_Sugar_Interpretation.interpretation;
       
   194 
   186 fun register_fp_sugar key fp_sugar =
   195 fun register_fp_sugar key fp_sugar =
   187   Local_Theory.declaration {syntax = false, pervasive = true}
   196   Local_Theory.declaration {syntax = false, pervasive = true}
   188     (fn phi => Data.map (Symtab.update (key, morph_fp_sugar phi fp_sugar)));
   197     (fn phi => Data.map (Symtab.update (key, morph_fp_sugar phi fp_sugar)))
       
   198   #> Local_Theory.background_theory (FP_Sugar_Interpretation.data fp_sugar);
   189 
   199 
   190 fun register_fp_sugars Xs fp pre_bnfs absT_infos nested_bnfs nesting_bnfs (fp_res as {Ts, ...})
   200 fun register_fp_sugars Xs fp pre_bnfs absT_infos nested_bnfs nesting_bnfs (fp_res as {Ts, ...})
   191     ctrXs_Tsss ctr_defss ctr_sugars co_recs mapss common_co_inducts co_inductss co_rec_thmss
   201     ctrXs_Tsss ctr_defss ctr_sugars co_recs mapss common_co_inducts co_inductss co_rec_thmss
   192     disc_co_recss sel_co_recsss lthy =
   202     disc_co_recss sel_co_recsss lthy =
   193   (0, lthy)
   203   (0, lthy)