src/HOL/Tools/Function/measure_functions.ML
changeset 57959 1bfed12a7646
parent 55968 94242fa87638
child 59498 50b60f501b05
equal deleted inserted replaced
57958:045c96e3edf0 57959:1bfed12a7646
     5 *)
     5 *)
     6 
     6 
     7 signature MEASURE_FUNCTIONS =
     7 signature MEASURE_FUNCTIONS =
     8 sig
     8 sig
     9   val get_measure_functions : Proof.context -> typ -> term list
     9   val get_measure_functions : Proof.context -> typ -> term list
    10   val setup : theory -> theory
       
    11 end
    10 end
    12 
    11 
    13 structure MeasureFunctions : MEASURE_FUNCTIONS =
    12 structure Measure_Functions : MEASURE_FUNCTIONS =
    14 struct
    13 struct
    15 
    14 
    16 (** User-declared size functions **)
    15 (** User-declared size functions **)
    17 structure Measure_Heuristic_Rules = Named_Thms
       
    18 (
       
    19   val name = @{binding measure_function}
       
    20   val description =
       
    21     "rules that guide the heuristic generation of measure functions"
       
    22 );
       
    23 
    16 
    24 fun mk_is_measure t =
    17 fun mk_is_measure t =
    25   Const (@{const_name is_measure}, fastype_of t --> HOLogic.boolT) $ t
    18   Const (@{const_name is_measure}, fastype_of t --> HOLogic.boolT) $ t
    26 
    19 
    27 fun find_measures ctxt T =
    20 fun find_measures ctxt T =
    28   DEPTH_SOLVE (resolve_tac (Measure_Heuristic_Rules.get ctxt) 1)
    21   DEPTH_SOLVE (resolve_tac (rev (Named_Theorems.get ctxt @{named_theorems measure_function})) 1)
    29     (HOLogic.mk_Trueprop (mk_is_measure (Var (("f",0), T --> HOLogic.natT)))
    22     (HOLogic.mk_Trueprop (mk_is_measure (Var (("f",0), T --> HOLogic.natT)))
    30      |> cterm_of (Proof_Context.theory_of ctxt) |> Goal.init)
    23      |> cterm_of (Proof_Context.theory_of ctxt) |> Goal.init)
    31   |> Seq.map (prop_of #> (fn _ $ (_ $ (_ $ f)) => f))
    24   |> Seq.map (prop_of #> (fn _ $ (_ $ (_ $ f)) => f))
    32   |> Seq.list_of
    25   |> Seq.list_of
    33 
    26 
    51     mk_ext_base_funs ctxt T @ mk_funorder_funs T
    44     mk_ext_base_funs ctxt T @ mk_funorder_funs T
    52   | mk_all_measure_funs ctxt T = find_measures ctxt T
    45   | mk_all_measure_funs ctxt T = find_measures ctxt T
    53 
    46 
    54 val get_measure_functions = mk_all_measure_funs
    47 val get_measure_functions = mk_all_measure_funs
    55 
    48 
    56 val setup = Measure_Heuristic_Rules.setup
       
    57 
       
    58 end
    49 end