src/HOL/Tools/BNF/bnf_lfp_size.ML
changeset 56642 15cd15f9b40c
parent 56640 0a35354137a5
child 56643 41d3596d8a64
equal deleted inserted replaced
56641:029997d3b5d8 56642:15cd15f9b40c
     3     Copyright   2014
     3     Copyright   2014
     4 
     4 
     5 Generation of size functions for new-style datatypes.
     5 Generation of size functions for new-style datatypes.
     6 *)
     6 *)
     7 
     7 
     8 structure BNF_LFP_Size : sig end =
     8 signature BNF_LFP_SIZE =
       
     9 sig
       
    10   val register_size: string -> string -> thm list -> thm list -> theory -> theory
       
    11 end;
       
    12 
       
    13 structure BNF_LFP_Size : BNF_LFP_SIZE =
     9 struct
    14 struct
    10 
    15 
    11 open BNF_Util
    16 open BNF_Util
    12 open BNF_Tactics
    17 open BNF_Tactics
    13 open BNF_Def
    18 open BNF_Def
    25   val empty = Symtab.empty;
    30   val empty = Symtab.empty;
    26   val extend = I
    31   val extend = I
    27   fun merge data = Symtab.merge (K true) data;
    32   fun merge data = Symtab.merge (K true) data;
    28 );
    33 );
    29 
    34 
       
    35 fun register_size T_name size_name size_simps size_o_maps =
       
    36   Data.map (Symtab.update_new (T_name, (size_name, (size_simps, size_o_maps))));
       
    37 
    30 val zero_nat = @{const zero_class.zero (nat)};
    38 val zero_nat = @{const zero_class.zero (nat)};
    31 
    39 
    32 fun mk_plus_nat (t1, t2) = Const (@{const_name Groups.plus},
    40 fun mk_plus_nat (t1, t2) = Const (@{const_name Groups.plus},
    33   HOLogic.natT --> HOLogic.natT --> HOLogic.natT) $ t1 $ t2;
    41   HOLogic.natT --> HOLogic.natT --> HOLogic.natT) $ t1 $ t2;
    34 
    42 
    50   HEADGOAL (rtac (ctor_rec_o_map RS trans) THEN'
    58   HEADGOAL (rtac (ctor_rec_o_map RS trans) THEN'
    51     K (PRIMITIVE (Conv.fconv_rule Thm.eta_long_conversion)) THEN' asm_simp_tac
    59     K (PRIMITIVE (Conv.fconv_rule Thm.eta_long_conversion)) THEN' asm_simp_tac
    52       (ss_only (pre_map_defs @ distinct Thm.eq_thm_prop abs_inverses @ rec_o_map_simp_thms) ctxt));
    60       (ss_only (pre_map_defs @ distinct Thm.eq_thm_prop abs_inverses @ rec_o_map_simp_thms) ctxt));
    53 
    61 
    54 val size_o_map_simp_thms =
    62 val size_o_map_simp_thms =
    55   @{thms o_apply prod_inj_map inj_on_id snd_comp_apfst[unfolded apfst_def]};
    63   @{thms prod_inj_map inj_on_id snd_comp_apfst[unfolded apfst_def]};
    56 
    64 
    57 fun mk_size_o_map_tac ctxt size_def rec_o_map inj_maps size_maps =
    65 fun mk_size_o_map_tac ctxt size_def rec_o_map inj_maps size_maps =
    58   unfold_thms_tac ctxt [size_def] THEN
    66   unfold_thms_tac ctxt [size_def] THEN
    59   HEADGOAL (rtac (rec_o_map RS trans) THEN'
    67   HEADGOAL (rtac (rec_o_map RS trans) THEN'
    60     asm_simp_tac (ss_only (inj_maps @ size_maps @ size_o_map_simp_thms) ctxt));
    68     asm_simp_tac (ss_only (inj_maps @ size_maps @ size_o_map_simp_thms) ctxt)) THEN
       
    69   IF_UNSOLVED (unfold_thms_tac ctxt [o_apply] THEN HEADGOAL (rtac refl));
    61 
    70 
    62 fun generate_size (fp_sugars as ({T = Type (_, As), BT = Type (_, Bs), fp = Least_FP,
    71 fun generate_size (fp_sugars as ({T = Type (_, As), BT = Type (_, Bs), fp = Least_FP,
    63         fp_res = {bnfs = fp_bnfs, xtor_co_rec_o_map_thms = ctor_rec_o_maps, ...}, nested_bnfs, ...}
    72         fp_res = {bnfs = fp_bnfs, xtor_co_rec_o_map_thms = ctor_rec_o_maps, ...}, nested_bnfs, ...}
    64       : fp_sugar) :: _) thy =
    73       : fp_sugar) :: _) thy =
    65     let
    74     let