src/Tools/isac/BaseDefinitions/eval-def.sml
author wenzelm
Mon, 21 Jun 2021 20:06:12 +0200
changeset 60313 8d89a214aedc
parent 60223 740ebee5948b
child 60504 8cc1415b3530
permissions -rw-r--r--
Isar command 'calculation' as front-end for KEStore_Elems.add_calcs, without change of semantics;
walther@59919
     1
(* Title:  BaseDefinitions/eval-def.sml
walther@59853
     2
   Author: Walther Neuper
walther@59853
     3
   (c) due to copyright terms
walther@59853
     4
walther@59919
     5
Here is a minimum of code required for Know_Store.thy.
walther@59919
     6
For main code see structure Eval.
walther@59853
     7
*)
walther@59919
     8
signature EVALUATE__DEFINITION =
walther@59853
     9
sig
walther@59854
    10
  eqtype calID
walther@59853
    11
  eqtype prog_calcID
walther@59853
    12
  type cal
walther@59853
    13
  type calc_elem
walther@59853
    14
  val calc_eq: calc_elem * calc_elem -> bool
wenzelm@60313
    15
  type eval_fn = Rule_Def.eval_fn
walther@59853
    16
  val e_evalfn: Rule_Def.eval_fn
wenzelm@60313
    17
  val set_data: eval_fn -> theory -> theory
wenzelm@60313
    18
  val the_data: theory -> eval_fn
walther@59853
    19
end
walther@59853
    20
walther@59853
    21
(**)
walther@59919
    22
structure Eval_Def(**): EVALUATE__DEFINITION(**) =
walther@59853
    23
struct
walther@59853
    24
(**)
walther@59853
    25
walther@59854
    26
type calID = Rule_Def.calID
walther@59853
    27
type prog_calcID = string;
walther@59853
    28
(* op in isa-term "Const(op,_)" *)
walther@59853
    29
type cal = Rule_Def.calID * Rule_Def.eval_fn;
walther@59853
    30
type calc_elem =  (* fun calculate_ fetches the evaluation-function via this list *)
walther@59853
    31
  prog_calcID *   (* a simple identifier used in programs                    *)
walther@59853
    32
  (Rule_Def.calID *        (* a long identifier used in Const                         *)
walther@59853
    33
    Rule_Def.eval_fn)      (* an ML function                                          *)
walther@59853
    34
fun calc_eq ((pi1, (ci1, _)), (pi2, (ci2, _))) =
walther@59853
    35
  if pi1 = pi2
walther@59962
    36
  then if ci1 = ci2 then true else raise ERROR ("calc_eq: " ^ ci1 ^ " <> " ^ ci2)
walther@59853
    37
  else false
walther@59854
    38
walther@59857
    39
(* eval function calling sml code during rewriting.
walther@59857
    40
Unifying "type cal" and "type calc" would make Lucas-Interpretation more efficient,
walther@59857
    41
  see "fun rule2stac": instead of 
walther@59878
    42
    Eval: calID * eval_fn -> rule
walther@59857
    43
  would be better
walther@59878
    44
    Eval: prog_calcID * (calID * eval_fn)) -> rule*)
walther@59854
    45
type eval_fn = Rule_Def.eval_fn
walther@59853
    46
fun e_evalfn (_ : 'a) (_ : term) (_ : theory) = NONE : (string * term) option;
wenzelm@60313
    47
wenzelm@60313
    48
wenzelm@60313
    49
(* theory data for Isar command 'calculation' *)
wenzelm@60313
    50
wenzelm@60313
    51
structure Data = Theory_Data
wenzelm@60313
    52
(
wenzelm@60313
    53
  type T = eval_fn option;
wenzelm@60313
    54
  val empty = NONE;
wenzelm@60313
    55
  val extend = I;
wenzelm@60313
    56
  fun merge _ = NONE;
wenzelm@60313
    57
);
wenzelm@60313
    58
wenzelm@60313
    59
val set_data = Data.put o SOME;
wenzelm@60313
    60
val the_data = the o Data.get;
wenzelm@60313
    61
walther@59853
    62
end