src/HOL/Tools/function_package/size.ML
changeset 29495 c49b4c8f2eaa
parent 28965 1de908189869
child 29579 cb520b766e00
equal deleted inserted replaced
29494:a189c6274c7a 29495:c49b4c8f2eaa
     1 (*  Title:      HOL/Tools/function_package/size.ML
     1 (*  Title:      HOL/Tools/function_package/size.ML
     2     ID:         $Id$
     2     Author:     Stefan Berghofer, Florian Haftmann & Alexander Krauss, TU Muenchen
     3     Author:     Stefan Berghofer, Florian Haftmann, TU Muenchen
       
     4 
     3 
     5 Size functions for datatypes.
     4 Size functions for datatypes.
     6 *)
     5 *)
     7 
     6 
     8 signature SIZE =
     7 signature SIZE =
    79           (((s, Free (name, U)), U), name)
    78           (((s, Free (name, U)), U), name)
    80         end) |> split_list |>> split_list;
    79         end) |> split_list |>> split_list;
    81     val param_size = AList.lookup op = param_size_fs;
    80     val param_size = AList.lookup op = param_size_fs;
    82 
    81 
    83     val extra_rewrites = descr |> map (#1 o snd) |> distinct op = |>
    82     val extra_rewrites = descr |> map (#1 o snd) |> distinct op = |>
    84       List.mapPartial (Option.map snd o lookup_size thy) |> flat;
    83       map_filter (Option.map snd o lookup_size thy) |> flat;
    85     val extra_size = Option.map fst o lookup_size thy;
    84     val extra_size = Option.map fst o lookup_size thy;
    86 
    85 
    87     val (((size_names, size_fns), def_names), def_names') =
    86     val (((size_names, size_fns), def_names), def_names') =
    88       recTs1 ~~ alt_names' |>
    87       recTs1 ~~ alt_names' |>
    89       map (fn (T as Type (s, _), optname) =>
    88       map (fn (T as Type (s, _), optname) =>
   178     (* characteristic equations for size functions *)
   177     (* characteristic equations for size functions *)
   179     fun gen_mk_size_eq p size_of size_ofp size_const T (cname, cargs) =
   178     fun gen_mk_size_eq p size_of size_ofp size_const T (cname, cargs) =
   180       let
   179       let
   181         val Ts = map (typ_of_dtyp descr sorts) cargs;
   180         val Ts = map (typ_of_dtyp descr sorts) cargs;
   182         val tnames = Name.variant_list f_names (DatatypeProp.make_tnames Ts);
   181         val tnames = Name.variant_list f_names (DatatypeProp.make_tnames Ts);
   183         val ts = List.mapPartial (fn (sT as (s, T), dt) =>
   182         val ts = map_filter (fn (sT as (s, T), dt) =>
   184           Option.map (fn sz => sz $ Free sT)
   183           Option.map (fn sz => sz $ Free sT)
   185             (if p dt then size_of_type size_of extra_size size_ofp T
   184             (if p dt then size_of_type size_of extra_size size_ofp T
   186              else NONE)) (tnames ~~ Ts ~~ cargs)
   185              else NONE)) (tnames ~~ Ts ~~ cargs)
   187       in
   186       in
   188         HOLogic.mk_Trueprop (HOLogic.mk_eq
   187         HOLogic.mk_Trueprop (HOLogic.mk_eq