src/Tools/isac/BaseDefinitions/celem-8.sml
author Walther Neuper <walther.neuper@jku.at>
Sun, 19 Apr 2020 12:22:37 +0200
changeset 59887 4616b145b1cd
parent 59886 106e7d8723ca
child 59888 2c2fdf9dd52d
permissions -rw-r--r--
rename KEStore to Know_Store, replace respect.part of Celem with Celem1

note: the latter was NOT restricted to Know_Store, because redefinition in calcelems.sml
(i.e. "datatype 'a ptyp = Celem1.Ptyp of ... Celem.ptyp") did not work.
walther@59882
     1
(* Title:  BaseDefinitions/celem-8.sml
walther@59882
     2
   Author: Walther Neuper
walther@59882
     3
   (c) due to copyright terms
walther@59882
     4
walther@59882
     5
          *)
walther@59882
     6
signature CALCELEMENT_8 =
walther@59882
     7
(*/------- to Celem8 -------\*)
walther@59882
     8
(*\------- to Celem8 -------/*)
walther@59882
     9
sig
walther@59884
    10
(*/------- to Celem8 -------\*)
walther@59884
    11
  type authors
walther@59884
    12
  datatype thydata
walther@59884
    13
    = Hcal of {calc: Rule_Def.calc, coursedesign: authors, guh: Celem2.guh, mathauthors: authors}
walther@59884
    14
    | Hord of {coursedesign: authors, guh: Celem2.guh, mathauthors: authors, ord: (term * term) list -> term * term -> bool}
walther@59884
    15
    | Hrls of {coursedesign: authors, guh: Celem2.guh, mathauthors: authors, thy_rls: ThyC.id * Rule_Set.T}
walther@59884
    16
    | Hthm of {coursedesign: authors, fillpats: Error_Fill_Def.fillpat list, guh: Celem2.guh, mathauthors: authors, thm: thm}
walther@59884
    17
    | Html of {coursedesign: authors, guh: Celem2.guh, html: string, mathauthors: authors}
walther@59884
    18
  type theID
walther@59884
    19
  val the2str: thydata -> string
walther@59884
    20
  val thes2str: thydata list -> string
walther@59884
    21
  val theID2thyID: theID -> ThyC.id
walther@59884
    22
  val add_thydata: string list * string list -> thydata -> thydata Celem1.ptyp list -> thydata Celem1.ptyp list
walther@59884
    23
  val update_hthm: thydata -> Error_Fill_Def.fillpat list -> thydata
walther@59884
    24
(*\------- to Celem8 -------/*)
walther@59882
    25
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
walther@59882
    26
  (*NONE*)
walther@59886
    27
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
walther@59882
    28
  (*NONE*)
walther@59886
    29
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
walther@59882
    30
end
walther@59882
    31
walther@59882
    32
(**)
walther@59882
    33
structure Celem8(**): CALCELEMENT_8(**) =
walther@59882
    34
struct
walther@59882
    35
(**)
walther@59882
    36
walther@59882
    37
(*/------- to Celem8 -------\*)
walther@59884
    38
(*the key into the hierarchy ob theory elements*)
walther@59884
    39
type theID = string list;
walther@59884
    40
val theID2str = strs2str; (*theID eg. is ["IsacKnowledge", "Test", "Rulesets", "ac_plus_times"]*)
walther@59884
    41
fun theID2thyID theID =
walther@59884
    42
  if length theID >= 3 then (last_elem o (drop_last_n 2)) theID
walther@59884
    43
  else error ("theID2thyID called with " ^ theID2str theID);
walther@59884
    44
type authors = string list;
walther@59884
    45
(* datatype for collecting thydata for hierarchy *)
walther@59884
    46
(*WN060720 more consistent naming would be 'type thyelem' or 'thelem'*)
walther@59884
    47
datatype thydata =
walther@59884
    48
  Html of {guh: Celem2.guh, coursedesign: authors, mathauthors: authors, html: string}
walther@59884
    49
| Hthm of {guh: Celem2.guh, coursedesign: authors, mathauthors: authors, fillpats: Error_Fill_Def.fillpat list,
walther@59884
    50
   thm: thm} (* here no sym_thm, thus no thmID required *)
walther@59884
    51
| Hrls of {guh: Celem2.guh, coursedesign: authors, mathauthors: authors, thy_rls: (ThyC.id * Rule_Set.T)}
walther@59884
    52
| Hcal of {guh: Celem2.guh, coursedesign: authors, mathauthors: authors, calc: Rule_Def.calc}
walther@59884
    53
| Hord of {guh: Celem2.guh, coursedesign: authors, mathauthors: authors,
walther@59884
    54
    ord: (UnparseC.subst -> (term * term) -> bool)};
walther@59884
    55
fun the2str (Html {guh, ...}) = guh
walther@59884
    56
  | the2str (Hthm {guh, ...}) = guh
walther@59884
    57
  | the2str (Hrls {guh, ...}) = guh
walther@59884
    58
  | the2str (Hcal {guh, ...}) = guh
walther@59884
    59
  | the2str (Hord {guh, ...}) = guh
walther@59884
    60
fun thes2str thes = map the2str thes |> list2str;
walther@59884
    61
(*\------- to Celem8 -------/*)
walther@59884
    62
walther@59884
    63
(*/------- to Celem8 -------\*)
walther@59884
    64
(* notes on thehier concerning sym_thmID theorems (created in derivations, reverse rewriting)
walther@59884
    65
     (a): thehier does not contain sym_thmID theorems
walther@59884
    66
     (b): lookup for sym_thmID directly from Isabelle using sym_thm
walther@59884
    67
          (within math-engine NO lookup in thehier -- within java in *.xml only!)
walther@59884
    68
TODO (c): export from thehier to xml
walther@59884
    69
TODO (c1)   creates one entry for "thmID" (and NONE for "sym_thmID") in the hierarchy
walther@59884
    70
TODO (c2)   creates 2 files "thy_*-thm-thmID.xml" and "thy_*-thm-sym_thmID.xml"
walther@59884
    71
TODO (d): 1 entry in the MiniBrowser's hierarchy (generated from xml)
walther@59884
    72
          stands for both, "thmID" and "sym_thmID" 
walther@59884
    73
TODO (d1)   lookup from calctxt          
walther@59884
    74
TODO (d1)   lookup from from rule set in MiniBrowser *)
walther@59884
    75
type thehier = (thydata Celem1.ptyp) list;
walther@59887
    76
(* required to determine sequence of main nodes of thehier in Know_Store.thy *)
walther@59884
    77
fun part2guh [str] = (case str of
walther@59884
    78
	  "Isabelle" => "thy_isab_" ^ str ^ "-part" : Celem2.guh
walther@59884
    79
      | "IsacScripts" => "thy_scri_" ^ str ^ "-part"
walther@59884
    80
      | "IsacKnowledge" => "thy_isac_" ^ str ^ "-part"
walther@59884
    81
      | str => raise ERROR ("thy2guh: called with \""^ str ^"\""))
walther@59884
    82
  | part2guh theID = raise ERROR ("part2guh called with theID = \"" ^ theID2str theID ^ "'");
walther@59884
    83
walther@59884
    84
fun thy2guh [part, thyID] = (case part of
walther@59884
    85
      "Isabelle" => "thy_isab_" ^ thyID
walther@59884
    86
    | "IsacScripts" => "thy_scri_" ^ thyID
walther@59884
    87
    | "IsacKnowledge" => "thy_isac_" ^ thyID
walther@59884
    88
    | str => raise ERROR ("thy2guh: called with \"" ^ str ^ "\""))
walther@59884
    89
  | thy2guh theID = raise ERROR ("thy2guh called with \"" ^ strs2str' theID ^ "\"");
walther@59884
    90
			
walther@59884
    91
fun thypart2guh ([part, thyID, thypart] : theID) = (case part of
walther@59884
    92
      "Isabelle" => "thy_isab_" ^ thyID ^ "-" ^ thypart : Celem2.guh
walther@59884
    93
    | "IsacScripts" => "thy_scri_" ^ thyID ^ "-" ^ thypart
walther@59884
    94
    | "IsacKnowledge" => "thy_isac_" ^ thyID ^ "-" ^ thypart
walther@59884
    95
    | str => raise ERROR ("thypart2guh: called with '" ^ str ^ "'"))
walther@59884
    96
  | thypart2guh strs = raise ERROR ("thypart2guh called with \"" ^ strs2str' strs ^ "\"");
walther@59884
    97
walther@59884
    98
  
walther@59884
    99
(* convert the data got via contextToThy to a globally unique handle.
walther@59884
   100
   there is another way to get the guh: get out of the 'theID' in the hierarchy *)
walther@59884
   101
fun thm2guh (isa, thyID) thmID = case isa of
walther@59884
   102
    "Isabelle" => "thy_isab_" ^ thyID ^ "-thm-" ^ strip_thy thmID : Celem2.guh
walther@59884
   103
  | "IsacKnowledge" => "thy_isac_" ^ thyID ^ "-thm-" ^ strip_thy thmID
walther@59884
   104
  | "IsacScripts" => "thy_scri_" ^ thyID ^ "-thm-" ^ strip_thy thmID
walther@59884
   105
  | _ => raise ERROR
walther@59884
   106
    ("thm2guh called with (isa, thyID) = (" ^ isa ^ ", " ^ thyID ^ ") for thm = \"" ^ thmID ^ "\"");
walther@59884
   107
walther@59884
   108
fun rls2guh (isa, thyID) rls' = case isa of
walther@59884
   109
    "Isabelle" => "thy_isab_" ^ thyID ^ "-rls-" ^ rls' : Celem2.guh
walther@59884
   110
  | "IsacKnowledge" => "thy_isac_" ^ thyID ^ "-rls-" ^ rls'
walther@59884
   111
  | "IsacScripts" => "thy_scri_" ^ thyID ^ "-rls-" ^ rls'
walther@59884
   112
  | _ => raise ERROR
walther@59884
   113
    ("rls2guh called with (isa, thyID) = (" ^ isa ^ ", " ^ thyID ^ ") for rls = \"" ^ rls' ^ "\"");
walther@59884
   114
			  
walther@59884
   115
fun cal2guh (isa, thyID) calID = case isa of
walther@59884
   116
    "Isabelle" => "thy_isab_" ^ thyID ^ "-cal-" ^ calID : Celem2.guh
walther@59884
   117
  | "IsacKnowledge" => "thy_isac_" ^ thyID ^ "-cal-" ^ calID
walther@59884
   118
  | "IsacScripts" => "thy_scri_" ^ thyID ^ "-cal-" ^ calID
walther@59884
   119
  | _ => raise ERROR
walther@59884
   120
    ("cal2guh called with (isa, thyID) = (" ^ isa ^ ", " ^ thyID ^ ") for cal = \"" ^ calID ^ "\"");
walther@59884
   121
			  
walther@59884
   122
fun ord2guh (isa, thyID) rew_ord' = case isa of
walther@59884
   123
    "Isabelle" => "thy_isab_" ^ thyID ^ "-ord-" ^ rew_ord' : Celem2.guh
walther@59884
   124
  | "IsacKnowledge" => "thy_isac_" ^ thyID ^ "-ord-" ^ rew_ord'
walther@59884
   125
  | "IsacScripts" => "thy_scri_" ^ thyID ^ "-ord-" ^ rew_ord'
walther@59884
   126
  | _ => raise ERROR
walther@59884
   127
    ("ord2guh called with (isa, thyID) = (" ^ isa ^ ", " ^ thyID ^ ") for ord = \"" ^ rew_ord' ^ "\"");
walther@59884
   128
walther@59884
   129
(* not only for thydata, but also for thy's etc *)
walther@59884
   130
(* TODO
walther@59884
   131
fun theID2guh theID = case length theID of
walther@59884
   132
    0 => error ("theID2guh: called with theID = " ^ strs2str' theID)
walther@59884
   133
  | 1 => part2guh theID
walther@59884
   134
  | 2 => thy2guh theID
walther@59884
   135
  | 3 => thypart2guh theID
walther@59884
   136
  | 4 => 
walther@59884
   137
    let val [isa, thyID, typ, elemID] = theID
walther@59884
   138
    in case typ of
walther@59884
   139
        "Theorems" => thm2guh (isa, thyID) elemID
walther@59884
   140
      | "Rulesets" => rls2guh (isa, thyID) elemID
walther@59884
   141
      | "Calculations" => cal2guh (isa, thyID) elemID
walther@59884
   142
      | "Orders" => ord2guh (isa, thyID) elemID
walther@59884
   143
      | "Theorems" => thy2guh [isa, thyID]
walther@59884
   144
      | str => raise ERROR ("theID2guh: called with theID = " ^ strs2str' theID)
walther@59884
   145
    end
walther@59884
   146
  | n => raise ERROR ("theID2guh called with theID = " ^ strs2str' theID);
walther@59884
   147
*)
walther@59884
   148
(* not only for thydata, but also for thy's etc *)
walther@59884
   149
fun theID2guh [] = raise ERROR ("theID2guh: called with []")
walther@59884
   150
  | theID2guh [str] = part2guh [str]
walther@59884
   151
  | theID2guh [s1, s2] = thy2guh [s1, s2]
walther@59884
   152
  | theID2guh [s1, s2, s3] = thypart2guh [s1, s2, s3]
walther@59884
   153
  | theID2guh (strs as [isa, thyID, typ, elemID]) = (case typ of
walther@59884
   154
      "Theorems" => thm2guh (isa, thyID) elemID
walther@59884
   155
    | "Rulesets" => rls2guh (isa, thyID) elemID
walther@59884
   156
    | "Calculations" => cal2guh (isa, thyID) elemID
walther@59884
   157
    | "Orders" => ord2guh (isa, thyID) elemID
walther@59884
   158
    | _ => raise ERROR ("theID2guh: called with theID = " ^ strs2str' strs))
walther@59884
   159
  | theID2guh strs = raise ERROR ("theID2guh called with theID = " ^ strs2str' strs);
walther@59884
   160
(*\------- to Celem8 -------/*)
walther@59884
   161
walther@59884
   162
(*/------- to Celem8 -------\*)
walther@59884
   163
(* not only for thydata, but also for thy's etc *)
walther@59884
   164
fun theID2guh [] = raise ERROR ("theID2guh: called with []")
walther@59884
   165
  | theID2guh [str] = part2guh [str]
walther@59884
   166
  | theID2guh [s1, s2] = thy2guh [s1, s2]
walther@59884
   167
  | theID2guh [s1, s2, s3] = thypart2guh [s1, s2, s3]
walther@59884
   168
  | theID2guh (strs as [isa, thyID, typ, elemID]) = (case typ of
walther@59884
   169
      "Theorems" => thm2guh (isa, thyID) elemID
walther@59884
   170
    | "Rulesets" => rls2guh (isa, thyID) elemID
walther@59884
   171
    | "Calculations" => cal2guh (isa, thyID) elemID
walther@59884
   172
    | "Orders" => ord2guh (isa, thyID) elemID
walther@59884
   173
    | _ => raise ERROR ("theID2guh: called with theID = " ^ strs2str' strs))
walther@59884
   174
  | theID2guh strs = raise ERROR ("theID2guh called with theID = " ^ strs2str' strs);
walther@59884
   175
(*\------- to Celem8 -------/*)
walther@59884
   176
(*/------- to Celem8 -------\*)
walther@59884
   177
fun Html_default exist = (Html {guh = theID2guh exist, 
walther@59884
   178
  coursedesign = ["isac team 2006"], mathauthors = [], html = ""})
walther@59884
   179
walther@59884
   180
fun fill_parents (_, [i]) thydata = Celem1.Ptyp (i, [thydata], [])
walther@59884
   181
  | fill_parents (exist, i :: is) thydata =
walther@59884
   182
    Celem1.Ptyp (i, [Html_default (exist @ [i])], [fill_parents (exist @ [i], is) thydata])
walther@59884
   183
  | fill_parents _ _ = raise ERROR "Html_default: avoid ML warning: Matches are not exhaustive"
walther@59884
   184
walther@59884
   185
fun add_thydata (exist, is) thydata [] = [fill_parents (exist, is) thydata]
walther@59884
   186
  | add_thydata (exist, [i]) data (pys as (py as Celem1.Ptyp (key, _, _)) :: pyss) = 
walther@59884
   187
    if i = key
walther@59884
   188
    then pys (* preserve existing thydata *) 
walther@59884
   189
    else py :: add_thydata (exist, [i]) data pyss
walther@59884
   190
  | add_thydata (exist, iss as (i :: is)) data ((py as Celem1.Ptyp (key, d, pys)) :: pyss) = 
walther@59884
   191
    if i = key
walther@59884
   192
    then       
walther@59884
   193
      if length pys = 0
walther@59884
   194
      then Celem1.Ptyp (key, d, [fill_parents (exist @ [i], is) data]) :: pyss
walther@59884
   195
      else Celem1.Ptyp (key, d, add_thydata (exist @ [i], is) data pys) :: pyss
walther@59884
   196
    else py :: add_thydata (exist, iss) data pyss
walther@59884
   197
  | add_thydata _ _ _ = raise ERROR "add_thydata: avoid ML warning: Matches are not exhaustive"
walther@59884
   198
walther@59884
   199
fun update_hthm (Hthm {guh, coursedesign, mathauthors, thm, ...}) fillpats' =
walther@59884
   200
  Hthm {guh = guh, coursedesign = coursedesign, mathauthors = mathauthors,
walther@59884
   201
    fillpats = fillpats', thm = thm}
walther@59884
   202
  | update_hthm _ _ = raise ERROR "update_hthm: wrong arguments";
walther@59882
   203
(*\------- to Celem8 -------/*)
walther@59882
   204
walther@59882
   205
(**)end(**)