src/HOL/Tools/Function/measure_functions.ML
author haftmann
Tue Jun 23 12:09:30 2009 +0200 (2009-06-23)
changeset 31775 2b04504fcb69
parent 26875 src/HOL/Tools/function_package/measure_functions.ML@e18574413bc4
child 31902 862ae16a799d
permissions -rw-r--r--
uniformly capitialized names for subdirectories
haftmann@31775
     1
(*  Title:       HOL/Tools/Function/measure_functions.ML
krauss@26875
     2
    Author:      Alexander Krauss, TU Muenchen
krauss@26875
     3
krauss@26875
     4
Measure functions, generated heuristically
krauss@26875
     5
*)
krauss@26875
     6
krauss@26875
     7
signature MEASURE_FUNCTIONS =
krauss@26875
     8
sig
krauss@26875
     9
krauss@26875
    10
  val get_measure_functions : Proof.context -> typ -> term list
krauss@26875
    11
  val setup : theory -> theory                                                      
krauss@26875
    12
krauss@26875
    13
end
krauss@26875
    14
krauss@26875
    15
structure MeasureFunctions : MEASURE_FUNCTIONS = 
krauss@26875
    16
struct 
krauss@26875
    17
krauss@26875
    18
(** User-declared size functions **)
krauss@26875
    19
structure MeasureHeuristicRules = NamedThmsFun(
krauss@26875
    20
  val name = "measure_function" 
krauss@26875
    21
  val description = "Rules that guide the heuristic generation of measure functions"
krauss@26875
    22
);
krauss@26875
    23
krauss@26875
    24
fun mk_is_measures t = Const (@{const_name "is_measure"}, fastype_of t --> HOLogic.boolT) $ t
krauss@26875
    25
krauss@26875
    26
fun find_measures ctxt T =
krauss@26875
    27
  DEPTH_SOLVE (resolve_tac (MeasureHeuristicRules.get ctxt) 1) 
krauss@26875
    28
    (HOLogic.mk_Trueprop (mk_is_measures (Var (("f",0), T --> HOLogic.natT)))
krauss@26875
    29
      |> cterm_of (ProofContext.theory_of ctxt) |> Goal.init)
krauss@26875
    30
  |> Seq.map (prop_of #> (fn _ $ (_ $ (_ $ f)) => f))
krauss@26875
    31
  |> Seq.list_of
krauss@26875
    32
krauss@26875
    33
krauss@26875
    34
(** Generating Measure Functions **)
krauss@26875
    35
krauss@26875
    36
fun constant_0 T = Abs ("x", T, HOLogic.zero)
krauss@26875
    37
fun constant_1 T = Abs ("x", T, HOLogic.Suc_zero)
krauss@26875
    38
krauss@26875
    39
fun mk_funorder_funs (Type ("+", [fT, sT])) =
krauss@26875
    40
      map (fn m => SumTree.mk_sumcase fT sT HOLogic.natT m (constant_0 sT)) (mk_funorder_funs fT)
krauss@26875
    41
    @ map (fn m => SumTree.mk_sumcase fT sT HOLogic.natT (constant_0 fT) m) (mk_funorder_funs sT)
krauss@26875
    42
  | mk_funorder_funs T = [ constant_1 T ]
krauss@26875
    43
krauss@26875
    44
fun mk_ext_base_funs ctxt (Type("+", [fT, sT])) =
krauss@26875
    45
      map_product (SumTree.mk_sumcase fT sT HOLogic.natT)
krauss@26875
    46
                  (mk_ext_base_funs ctxt fT) (mk_ext_base_funs ctxt sT)
krauss@26875
    47
  | mk_ext_base_funs ctxt T = find_measures ctxt T
krauss@26875
    48
krauss@26875
    49
fun mk_all_measure_funs ctxt (T as Type ("+", _)) =
krauss@26875
    50
    mk_ext_base_funs ctxt T @ mk_funorder_funs T
krauss@26875
    51
  | mk_all_measure_funs ctxt T = find_measures ctxt T
krauss@26875
    52
krauss@26875
    53
val get_measure_functions = mk_all_measure_funs
krauss@26875
    54
krauss@26875
    55
val setup = MeasureHeuristicRules.setup
krauss@26875
    56
krauss@26875
    57
end
krauss@26875
    58