src/Tools/isac/BaseDefinitions/rule.sml
author wneuper <Walther.Neuper@jku.at>
Tue, 10 Jan 2023 17:07:53 +0100
changeset 60647 ea7db4f4f837
parent 60645 43e858cf9567
child 60648 976b99bcfc96
permissions -rw-r--r--
eliminate use of Thy_Info 10: arg. ctxt for Rule.to_string finished
walther@59866
     1
(* Title:  BaseDefinitions/rule.sml
walther@59850
     2
   Author: Walther Neuper 2018
wneuper@59415
     3
   (c) copyright due to lincense terms
walther@59850
     4
walther@59858
     5
TODO: use "Rule" for renaming identifiers.
walther@59861
     6
Some stuff waits for later rounds of restructuring, e.g. TermC.empty
wneuper@59415
     7
*)
wneuper@59415
     8
wneuper@59415
     9
signature RULE =
walther@59850
    10
sig
walther@59850
    11
  datatype rule = datatype Rule_Def.rule
walther@59850
    12
  datatype program = datatype Rule_Def.program
walther@59849
    13
walther@59867
    14
  val set_id: Rule_Def.rule_set -> string
Walther@60645
    15
  val id: rule -> string
Walther@60645
    16
  val equal: rule * rule -> bool
Walther@60647
    17
  val to_string: Proof.context -> rule -> string
Walther@60645
    18
  val to_string_short: rule -> string
Walther@60436
    19
  val s_to_string: rule list -> string
walther@59864
    20
Walther@60647
    21
  val thm: Proof.context -> rule -> thm
walther@60017
    22
  val distinct' : rule list -> rule list
walther@59914
    23
walther@59876
    24
  val thm_id: rule -> string
Walther@60647
    25
  val eval: Proof.context -> rule -> string * Rule_Def.eval_fn
Walther@60647
    26
  val rls: Proof.context -> rule -> Rule_Def.rule_set
wenzelm@60294
    27
wenzelm@60294
    28
  val make_eval: string -> Rule_Def.eval_fn -> rule
walther@59850
    29
end
wneuper@59415
    30
wneuper@59415
    31
(**)
wneuper@59415
    32
structure Rule(**): RULE(**) =
wneuper@59415
    33
struct
wneuper@59415
    34
(**)
wneuper@59415
    35
walther@59867
    36
datatype rule = datatype Rule_Def.rule;
walther@59867
    37
datatype program = datatype Rule_Def.program;
walther@59876
    38
type is_as_string = string;
walther@59850
    39
Walther@60537
    40
type calc = Rule_Def.eval_ml_from_prog
Walther@60537
    41
type calID = Rule_Def.eval_const_id;
walther@59867
    42
type eval_fn = Rule_Def.eval_fn;
wneuper@59416
    43
walther@60384
    44
fun set_id Rule_Def.Empty = "empty"
walther@59867
    45
  | set_id (Rule_Def.Repeat {id, ...}) = id
walther@59878
    46
  | set_id (Rule_Def.Sequence {id, ...}) = id
walther@59867
    47
  | set_id (Rule_Def.Rrls {id, ...}) = id;
wneuper@59416
    48
walther@59867
    49
fun id (Rule_Def.Thm (id, _)) = id
walther@59878
    50
  | id (Rule_Def.Eval (id, _)) = id
walther@59867
    51
  | id (Rule_Def.Cal1 (id, _)) = id
walther@59867
    52
  | id (Rule_Def.Rls_ rls) = set_id rls
walther@59867
    53
  | id Rule_Def.Erule = "Erule";
walther@59867
    54
fun equal (Rule_Def.Thm (thm1, _), Rule_Def.Thm (thm2, _)) = thm1 = thm2
walther@59878
    55
  | equal (Rule_Def.Eval (id1, _), Rule_Def.Eval (id2, _)) = id1 = id2
walther@59867
    56
  | equal (Rule_Def.Rls_ rls1, Rule_Def.Rls_ rls2) = set_id rls1 = set_id rls2
walther@59867
    57
  | equal _ = false;
walther@60017
    58
fun distinct' rs = distinct equal rs
walther@59861
    59
Walther@60647
    60
fun to_string _ Rule_Def.Erule = "Erule" 
Walther@60647
    61
  | to_string ctxt (Rule_Def.Thm (str, thm)) =
Walther@60630
    62
    "Thm (\"" ^ str ^ "\", " ^ ThmC_Def.string_of_thm_PIDE ctxt thm ^ ")"
Walther@60647
    63
  | to_string _ (Rule_Def.Eval (str, _)) = "Eval (\"" ^ str ^ "\",fn)"
Walther@60647
    64
  | to_string _ (Rule_Def.Cal1 (str, _)) = "Cal1 (\"" ^ str ^ "\",fn)"
Walther@60647
    65
  | to_string _ (Rule_Def.Rls_ rls) = "Rls_ (\"" ^ set_id rls ^ "\")";
walther@59867
    66
fun to_string_short Rule_Def.Erule = "Erule"
walther@59867
    67
  | to_string_short (Rule_Def.Thm (str, _)) = "Thm (\"" ^ str ^ "\",\"\")"
walther@59878
    68
  | to_string_short (Rule_Def.Eval (str, _)) = "Eval (\"" ^ str ^ "\",fn)"
walther@59867
    69
  | to_string_short (Rule_Def.Cal1 (str, _)) = "Cal1 (\"" ^ str ^ "\",fn)"
walther@59867
    70
  | to_string_short (Rule_Def.Rls_ rls) = "Rls_ (\"" ^ set_id rls ^ "\")";
Walther@60436
    71
fun s_to_string rules = rules |> map to_string_short |> commas |> enclose "[" "]" 
walther@59864
    72
walther@59876
    73
fun thm_id (Rule_Def.Thm (id, _)) = id
walther@59876
    74
  | thm_id _ = raise ERROR ("Rule.thm_id: uncovered case " (* ^ to_string r *))
Walther@60647
    75
fun thm _ (Rule_Def.Thm (_, thm)) = thm
Walther@60647
    76
  | thm ctxt r = raise ERROR ("Rule.thm: uncovered case " ^ to_string ctxt r)
walther@59876
    77
Walther@60647
    78
fun eval _ (Eval e) = e
Walther@60647
    79
  | eval ctxt r = raise ERROR ("Rule.eval NOT FOR " ^ to_string ctxt r)
Walther@60647
    80
fun rls _ (Rls_ rls) = rls
Walther@60647
    81
  | rls ctxt r = raise ERROR ("Rule.rls NOT FOR " ^ to_string ctxt r) 
walther@60389
    82
wenzelm@60294
    83
wenzelm@60294
    84
(* ML antiquotations *)
wenzelm@60294
    85
wenzelm@60294
    86
val make_eval = curry Eval;
wenzelm@60294
    87
wenzelm@60294
    88
val _ = Theory.setup
wenzelm@60294
    89
  (ML_Antiquotation.value_embedded \<^binding>\<open>rule_eval\<close>
wenzelm@60294
    90
    (Args.const {proper = true, strict = true} >>
wenzelm@60294
    91
      (fn name => "Rule.make_eval " ^ ML_Syntax.print_string name)));
wenzelm@60294
    92
walther@59861
    93
(**)end(**)