src/Tools/isac/BaseDefinitions/Know_Store.thy
author wenzelm
Fri, 09 Dec 2022 12:59:16 +0100
changeset 60617 553becff0a78
parent 60609 5967b6e610b5
child 60629 20c3d272d79c
permissions -rw-r--r--
removed obsolete "extend" operation;
walther@59887
     1
(*  Title:      src/Tools/isac/Know_Store.thy
wneuper@59586
     2
    Author:     Mathias Lehnfeld
walther@59871
     3
Walther@60547
     4
Store of Theory_Data of all knowledge required by the Lucas-Interpreter.
walther@59890
     5
Walther@60547
     6
Types of elements are defined in "xxxxx-def.sml". These files have companion files "xxxxx.sml" 
Walther@60547
     7
with all further code, located at appropriate positions in the file structure.
Walther@60547
     8
(The separation of "xxxxx-def.sml" from "xxxxx.sml" should be overcome by
Walther@60547
     9
appropriate use of polymorphic high order functions.)
walther@59871
    10
Walther@60547
    11
Notable are Problem.T and MethodC.T; these are trees with a structure different from
Walther@60547
    12
Isabelle's theories dependencies.
wneuper@59586
    13
*)
wneuper@59586
    14
wenzelm@60286
    15
theory Know_Store
wenzelm@60286
    16
  imports Complex_Main
wenzelm@60313
    17
  keywords "rule_set_knowledge" "calculation" :: thy_decl
wenzelm@60223
    18
begin
wneuper@59586
    19
wenzelm@60223
    20
setup \<open>
wenzelm@60223
    21
  ML_Antiquotation.conditional \<^binding>\<open>isac_test\<close>
wenzelm@60223
    22
    (fn _ => Options.default_bool \<^system_option>\<open>isac_test\<close>)
wenzelm@60223
    23
\<close>
wenzelm@60223
    24
wneuper@59586
    25
ML_file libraryC.sml
walther@59880
    26
ML_file theoryC.sml
walther@59868
    27
ML_file unparseC.sml
walther@59874
    28
ML_file "rule-def.sml"
walther@59875
    29
ML_file "thmC-def.sml"
Walther@60557
    30
ML_file "eval-def.sml"
Walther@60535
    31
ML_file "rewrite-order.sml"
wneuper@59586
    32
ML_file rule.sml
Walther@60583
    33
ML_file "references-def.sml"
Walther@60602
    34
ML_file "cas-def.sml"
Walther@60557
    35
ML_file "model-pattern.sml"
walther@59909
    36
ML_file "error-pattern-def.sml"
walther@59850
    37
ML_file "rule-set.sml"
walther@59882
    38
walther@59891
    39
ML_file "store.sml"
walther@59892
    40
ML_file "check-unique.sml"
walther@59893
    41
ML_file "problem-def.sml"
walther@59893
    42
ML_file "method-def.sml"
Walther@60505
    43
ML_file "formalise.sml"
Walther@60505
    44
ML_file "example.sml"
walther@59917
    45
ML_file "thy-write.sml"
walther@59882
    46
wneuper@59586
    47
ML \<open>
wneuper@59586
    48
\<close> ML \<open>
wneuper@59587
    49
\<close> ML \<open>
wneuper@59586
    50
\<close>
wneuper@59586
    51
section \<open>Knowledge elements for problems and methods\<close>
Walther@60547
    52
text \<open>
Walther@60554
    53
  \<open>ML_structure Problem\<close>, \<open>ML_structure MethodC\<close> and \<open>Example\<close>s are held by "Know_Store".
wneuper@59586
    54
Walther@60554
    55
  The structure of \<open>ML_structure Problem\<close> and \<open>ML_structure MethodC\<close> is independent from 
Walther@60554
    56
  theories' dependency graph. Thus the respective elements are stored as \<open>TermC.as_string\<close>
Walther@60554
    57
  and parsed on the fly within the current @{ML_structure Context},
Walther@60554
    58
  while being loaded into \<open>ML_structure Calc\<close>.
wneuper@59586
    59
Walther@60555
    60
  Note: From the children of eb89f586b0b2 onwards the old functions (\<open>term TermC.typ_a2real\<close> etc)
Walther@60555
    61
  are adapted for "adapt_to_type on the fly" until further clarification.
Walther@60555
    62
  Why \<open>ML_structure Problem\<close> and \<open>ML_structure MethodC\<close> are not parsed on the fly
Walther@60555
    63
  within the current \<open>ML_structure Context\<close> see \<open>ML_structure Refine\<close>
Walther@60554
    64
\<open>\<close>
Walther@60554
    65
  Most elements of \<open>ML_structure Problem\<close> and \<open>ML_structure MethodC\<close> are implemented in 
Walther@60554
    66
  \<open>directory Knowledge/\<close> but some of them are implemented in \<open>directory ProgLang/\<close>already; 
Walther@60554
    67
  thus \<open>theory Know_Store\<close> got this location in the directory structure.
Walther@60554
    68
Walther@60554
    69
  \<open>term Know_Store.get_*\<close> retrieves all * of the respective theory PLUS of all ancestor theories.
Walther@60547
    70
\<close> ML \<open>
Walther@60609
    71
signature KNOW_STORE =
wneuper@59586
    72
sig
Walther@60547
    73
  val get_rew_ords: theory -> Rewrite_Ord.T list
Walther@60547
    74
  val add_rew_ords: Rewrite_Ord.T list -> theory -> theory
walther@59879
    75
  val get_rlss: theory -> (Rule_Set.id * (ThyC.id * Rule_Set.T)) list
walther@59879
    76
  val add_rlss: (Rule_Set.id * (ThyC.id * Rule_Set.T)) list -> theory -> theory
Walther@60538
    77
  val get_calcs: theory -> (Eval_Def.prog_id * (Eval_Def.const_id * Eval_Def.ml_fun)) list
Walther@60538
    78
  val add_calcs: (Eval_Def.prog_id * (Eval_Def.const_id * Eval_Def.ml_fun)) list -> theory -> theory
Walther@60547
    79
  val get_cass: theory -> CAS_Def.T list
Walther@60547
    80
  val add_cass: CAS_Def.T list -> theory -> theory
Walther@60495
    81
  val get_pbls: theory -> Probl_Def.store
Walther@60502
    82
  val add_pbls: Proof.context -> (Probl_Def.T * References_Def.id) list -> theory -> theory
walther@59895
    83
  val get_mets: theory -> Meth_Def.store
Walther@60502
    84
  val add_mets: Proof.context -> (Meth_Def.T * References_Def.id) list -> theory -> theory
Walther@60505
    85
  val get_expls: theory -> Example.store
Walther@60505
    86
  val add_expls: (Example.T * Store.key) list -> theory -> theory
walther@59917
    87
  val get_thes: theory -> (Thy_Write.thydata Store.node) list
Walther@60563
    88
  val add_thes: (Thy_Write.thydata * Thy_Write.theID) list -> theory -> theory
walther@59917
    89
  val insert_fillpats: (Thy_Write.theID * Error_Pattern_Def.fill_in list) list -> theory -> theory 
Walther@60608
    90
  val get_ref_last_thy: unit -> theory
Walther@60608
    91
  val set_ref_last_thy: theory -> unit
Walther@60608
    92
  val get_via_last_thy: ThyC.id -> theory (* only used for Subproblem retrieving respective thy *)
Walther@60508
    93
end;
wneuper@59586
    94
Walther@60609
    95
structure Know_Store(**): KNOW_STORE(**) =
wneuper@59586
    96
struct
wneuper@59586
    97
  structure Data = Theory_Data (
Walther@60547
    98
    type T = Rewrite_Ord.T list;
Walther@60506
    99
    val empty = [];
Walther@60506
   100
    val merge = merge Rewrite_Ord.equal;
Walther@60506
   101
    );  
Walther@60547
   102
  fun get_rew_ords thy = Data.get thy
Walther@60547
   103
  fun add_rew_ords rlss = Data.map (curry (Library.merge Rewrite_Ord.equal) rlss)
Walther@60506
   104
Walther@60506
   105
  structure Data = Theory_Data (
walther@59879
   106
    type T = (Rule_Set.id * (ThyC.id * Rule_Set.T)) list;
Walther@60547
   107
                            (* ^^^^^ would allow same Rls_Set.id for different thys, NOT impl. *)
wneuper@59586
   108
    val empty = [];
walther@59852
   109
    val merge = Rule_Set.to_kestore;
wneuper@59586
   110
    );  
wneuper@59586
   111
  fun get_rlss thy = Data.get thy
Walther@60521
   112
  fun add_rlss rlss = Data.map (curry (Library.merge Rule_Set.equal) rlss)
wneuper@59586
   113
wneuper@59586
   114
  structure Data = Theory_Data (
Walther@60538
   115
    type T = (Eval_Def.prog_id * (Eval_Def.const_id * Eval_Def.ml_fun)) list;
wneuper@59586
   116
    val empty = [];
Walther@60538
   117
    val merge = merge Eval_Def.equal;
wneuper@59586
   118
    );                                                              
wneuper@59586
   119
  fun get_calcs thy = Data.get thy
Walther@60538
   120
  fun add_calcs calcs = Data.map (curry (Library.merge Eval_Def.equal) calcs)
wneuper@59586
   121
wneuper@59586
   122
  structure Data = Theory_Data (
Walther@60547
   123
    type T = (term * (References_Def.T * CAS_Def.generate_fn)) list;
wneuper@59586
   124
    val empty = [];
walther@59896
   125
    val merge = merge CAS_Def.equal;
wneuper@59586
   126
    );                                                              
Walther@60547
   127
  fun get_cass thy = Data.get thy
Walther@60547
   128
  fun add_cass cas = Data.map (curry (Library.merge CAS_Def.equal) cas)
wneuper@59586
   129
wneuper@59586
   130
  structure Data = Theory_Data (
walther@59894
   131
    type T = Probl_Def.store;
walther@59894
   132
    val empty = [Probl_Def.empty_store];
walther@59897
   133
    val merge = Store.merge;
wneuper@59586
   134
    );
Walther@60495
   135
  fun get_pbls thy = Data.get thy;
Walther@60502
   136
  fun add_pbls ctxt pbts thy =
Walther@60502
   137
    let
Walther@60502
   138
      fun add_pbt (pbt as {guh,...}, pblID) =
Walther@60502
   139
        (* the pblID has the leaf-element as first; better readability achieved *)
Walther@60502
   140
        (if (Config.get ctxt check_unique) then Probl_Def.check_unique guh (Data.get thy) else ();
Walther@60502
   141
          rev pblID |> Store.insert pblID pbt);
Walther@60502
   142
    in Data.map (fold add_pbt pbts) thy end;
wneuper@59586
   143
wneuper@59586
   144
  structure Data = Theory_Data (
walther@59895
   145
    type T = Meth_Def.store;
walther@59895
   146
    val empty = [Meth_Def.empty_store];
walther@59897
   147
    val merge = Store.merge;
wneuper@59586
   148
    );
wneuper@59586
   149
  val get_mets = Data.get;
Walther@60502
   150
  fun add_mets ctxt mets thy =
Walther@60502
   151
    let
Walther@60502
   152
      fun add_met (met as {guh,...}, metID) =
Walther@60502
   153
        (if (Config.get ctxt check_unique) then Meth_Def.check_unique guh (Data.get thy) else ();
Walther@60502
   154
          Store.insert metID met metID);
Walther@60502
   155
    in Data.map (fold add_met mets) thy end;
wneuper@59586
   156
wneuper@59586
   157
  structure Data = Theory_Data (
Walther@60505
   158
    type T = Example.store;
Walther@60505
   159
    val empty = [Example.empty_store];
Walther@60505
   160
    val merge = Store.merge;
Walther@60505
   161
    );
Walther@60505
   162
  val get_expls = Data.get;
Walther@60505
   163
  fun add_expls expls thy =
Walther@60505
   164
    let
Walther@60505
   165
      fun add_expl (expl, expl_id) = Store.insert expl_id expl expl_id;
Walther@60505
   166
    in Data.map (fold add_expl expls) thy end;
Walther@60505
   167
Walther@60505
   168
  structure Data = Theory_Data (
walther@59917
   169
    type T = (Thy_Write.thydata Store.node) list;
wneuper@59586
   170
    val empty = [];
Walther@60563
   171
    val merge = Store.merge;
wneuper@59586
   172
    );                                                              
wneuper@59586
   173
  fun get_thes thy = Data.get thy
wneuper@59586
   174
  fun add_thes thes thy = let
walther@59917
   175
    fun add_the (thydata, theID) = Thy_Write.add_thydata ([], theID) thydata
wneuper@59586
   176
  in Data.map (fold add_the thes) thy end;
wneuper@59586
   177
  fun insert_fillpats fis thy =
wneuper@59586
   178
    let
wneuper@59586
   179
      fun update_elem (theID, fillpats) =
wneuper@59586
   180
        let
walther@59897
   181
          val hthm = Store.get (Data.get thy) theID theID
walther@59917
   182
          val hthm' = Thy_Write.update_hthm hthm fillpats
wneuper@59586
   183
            handle ERROR _ =>
walther@59962
   184
              raise ERROR ("insert_fillpats: " ^ strs2str theID ^ "must address a theorem")
walther@59897
   185
        in Store.update theID theID hthm' end
wneuper@59586
   186
    in Data.map (fold update_elem fis) thy end
wneuper@59586
   187
Walther@60608
   188
  val last_thy = Synchronized.var "finally_knowledge_complete" @{theory};
Walther@60608
   189
  fun set_ref_last_thy thy = Synchronized.change last_thy (fn _ => thy); (* never RE-set ! *)
Walther@60608
   190
  fun get_ref_last_thy () = Synchronized.value last_thy;
Walther@60608
   191
Walther@60608
   192
fun get_via_last_thy thy_id =
Walther@60608
   193
  let
Walther@60608
   194
    val last_thy = get_ref_last_thy ()
Walther@60608
   195
    val known_thys = Theory.nodes_of last_thy
Walther@60608
   196
  in 
Walther@60608
   197
    (find_first (fn thy => Context.theory_name thy = thy_id) known_thys
Walther@60608
   198
      |> the)
Walther@60608
   199
    handle Option.Option => raise ERROR ("get_via_last_thy fails with " ^ quote thy_id)
Walther@60608
   200
  end
Walther@60543
   201
Walther@60543
   202
(**)end(*struct*);
wneuper@59586
   203
\<close>
wneuper@59586
   204
wenzelm@60286
   205
wenzelm@60286
   206
subsection \<open>Isar command syntax\<close>
wenzelm@60286
   207
wenzelm@60286
   208
ML \<open>
wenzelm@60286
   209
local
wenzelm@60286
   210
wenzelm@60286
   211
val parse_rule = Parse.name -- Parse.!!! (\<^keyword>\<open>=\<close> |-- Parse.ML_source);
wenzelm@60286
   212
wenzelm@60286
   213
val ml = ML_Lex.read;
wenzelm@60286
   214
wenzelm@60286
   215
fun ml_rule thy (name, source) =
wenzelm@60286
   216
  ml "(" @ ml (ML_Syntax.print_string name) @ ml ", " @
wenzelm@60286
   217
  ml "(" @ ml (ML_Syntax.print_string (Context.theory_name thy)) @ ml ", " @
wenzelm@60286
   218
  ML_Lex.read_source source @ ml "))";
wenzelm@60286
   219
wenzelm@60286
   220
fun ml_rules thy args =
Walther@60588
   221
  ml "Theory.setup (Know_Store.add_rlss [" @
wenzelm@60286
   222
    flat (separate (ml ",") (map (ml_rule thy) args)) @ ml "])";
wenzelm@60286
   223
wenzelm@60286
   224
val _ =
wenzelm@60289
   225
  Outer_Syntax.command \<^command_keyword>\<open>rule_set_knowledge\<close> "register ISAC rule set to Knowledge Store"
wenzelm@60286
   226
    (Parse.and_list1 parse_rule >> (fn args => Toplevel.theory (fn thy =>
wenzelm@60286
   227
      thy |> Context.theory_map
wenzelm@60286
   228
        (ML_Context.expression (Position.thread_data ()) (ml_rules thy args)))));
wenzelm@60286
   229
wenzelm@60313
   230
val calc_name =
wenzelm@60313
   231
  Parse.name -- (\<^keyword>\<open>(\<close> |-- Parse.const --| \<^keyword>\<open>)\<close>) ||
wenzelm@60313
   232
  Scan.ahead Parse.name -- Parse.const;
wenzelm@60313
   233
wenzelm@60313
   234
val _ =
wenzelm@60313
   235
  Outer_Syntax.command \<^command_keyword>\<open>calculation\<close>
wenzelm@60313
   236
    "prepare ISAC calculation and register it to Knowledge Store"
wenzelm@60313
   237
    (calc_name -- (\<^keyword>\<open>=\<close> |-- Parse.!!! Parse.ML_source) >> (fn ((calcID, const), source) =>
wenzelm@60313
   238
      Toplevel.theory (fn thy =>
wenzelm@60313
   239
        let
wenzelm@60313
   240
          val ctxt = Proof_Context.init_global thy;
wenzelm@60313
   241
          val Const (c, _) = Proof_Context.read_const {proper = true, strict = true} ctxt const;
wenzelm@60314
   242
          val set_data =
wenzelm@60313
   243
            ML_Context.expression (Input.pos_of source)
Walther@60538
   244
              (ml "Theory.setup (Eval_Def.ml_fun_to_store (" @ ML_Lex.read_source source @ ml "))")
wenzelm@60313
   245
            |> Context.theory_map;
Walther@60538
   246
          val eval = Eval_Def.ml_fun_from_store (set_data thy);
Walther@60588
   247
        in Know_Store.add_calcs [(calcID, (c, eval))] thy end)))
wenzelm@60313
   248
wenzelm@60286
   249
in end;
wenzelm@60286
   250
\<close>
wenzelm@60286
   251
wenzelm@60286
   252
wneuper@59586
   253
section \<open>Re-use existing access functions for knowledge elements\<close>
wneuper@59586
   254
text \<open>
Walther@60508
   255
  The independence of problems' and methods' structure from theory dependency structure
Walther@60508
   256
  enforces the access functions to use "Isac_Knowledge",
Walther@60508
   257
  the final theory which comprises all knowledge defined.
wneuper@59586
   258
\<close>
wneuper@59586
   259
ML \<open>
Walther@60608
   260
val get_ref_last_thy = Know_Store.get_ref_last_thy;
wneuper@59586
   261
Walther@60550
   262
(*val get_rew_ord: Proof.context -> string -> Rewrite_Ord.function*)
Walther@60547
   263
fun get_rew_ord ctxt (id: Rewrite_Ord.id) = 
Walther@60588
   264
  case AList.lookup (op =) (Know_Store.get_rew_ords (Proof_Context.theory_of ctxt)) id of
Walther@60547
   265
    SOME function => function: Rewrite_Ord.function
Walther@60547
   266
  | NONE => raise ERROR ("rewrite-order \"" ^ id ^ "\" missing in theory \"" ^ 
Walther@60547
   267
    (ctxt |> Proof_Context.theory_of |> Context.theory_name) ^ "\" (and ancestors)" ^
Walther@60547
   268
    "\nTODO exception hierarchy needs to be established.")
Walther@60506
   269
Walther@60550
   270
(*val get_rls: Proof.context -> Rule_Set.id -> Rule_Def.rule_set*)
Walther@60547
   271
fun get_rls ctxt (id : Rule_Set.id) =
Walther@60588
   272
  case AList.lookup (op =) (Know_Store.get_rlss (Proof_Context.theory_of ctxt)) id of
Walther@60543
   273
    SOME (_, rls) => rls
Walther@60547
   274
  | NONE => raise ERROR ("rls \"" ^ id ^ "\" missing in theory \"" ^ 
Walther@60543
   275
    (ctxt |> Proof_Context.theory_of |> Context.theory_name) ^ "\" (and ancestors)" ^
Walther@60543
   276
    "\nTODO exception hierarchy needs to be established.")
Walther@60543
   277
Walther@60550
   278
(*val get_calc: Proof.context -> Eval_Def.prog_id -> 
Walther@60550
   279
  Eval_Def.prog_id * (Eval_Def.const_id * Eval_Def.ml_fun)*)
Walther@60550
   280
fun get_calc ctxt (id: Eval_Def.prog_id) = 
Walther@60588
   281
  case AList.lookup (op =) (Know_Store.get_calcs (Proof_Context.theory_of ctxt)) id of
Walther@60550
   282
    SOME const_id__ml_fun => (id, const_id__ml_fun)
Walther@60550
   283
  | NONE => raise ERROR ("ml-calculation \"" ^ id ^ "\" missing in theory \"" ^ 
Walther@60550
   284
    (ctxt |> Proof_Context.theory_of |> Context.theory_name) ^ "\" (and ancestors)" ^
Walther@60550
   285
    "\nTODO exception hierarchy needs to be established.")
Walther@60550
   286
Walther@60550
   287
(*val get_calc_prog_id: Proof.context -> Eval_Def.const_id -> Eval_Def.prog_id*)
Walther@60550
   288
fun get_calc_prog_id ctxt (const_id: Eval_Def.const_id) =
Walther@60550
   289
  let
Walther@60550
   290
    fun assoc ([], prog_id) =
Walther@60550
   291
        raise ERROR ("ml-calculation \"" ^ prog_id ^ "\" missing in theory \"" ^ 
Walther@60550
   292
          (ctxt |> Proof_Context.theory_of |> Context.theory_name) ^ "\" (and ancestors)." ^
Walther@60550
   293
          "\nThus " ^ quote const_id  ^ " cannot be retrieved." ^
Walther@60550
   294
          "\nTODO exception hierarchy needs to be established.")
Walther@60550
   295
      | assoc ((prog_id, (const_id, _)) :: pairs, key) =
Walther@60550
   296
          if key = const_id then prog_id else assoc (pairs, key);
Walther@60588
   297
  in assoc (ctxt |> Proof_Context.theory_of |> Know_Store.get_calcs, const_id) end;
wneuper@59586
   298
Walther@60550
   299
(*val get_cas: Proof.context -> term -> References_Def.T * CAS_Def.generate_fn*)
Walther@60547
   300
fun get_cas ctxt tm = 
Walther@60588
   301
  case AList.lookup (op =) (Know_Store.get_cass (Proof_Context.theory_of ctxt)) tm of
Walther@60547
   302
    SOME refs__gen_fun => refs__gen_fun: References_Def.T * CAS_Def.generate_fn
Walther@60547
   303
  | NONE => raise ERROR ("CAS_Cmd \"" ^ 
Walther@60608
   304
    UnparseC.term_in_thy (get_ref_last_thy ()) tm ^ "\" missing in theory \"" ^ 
Walther@60547
   305
    (ctxt |> Proof_Context.theory_of |> Context.theory_name) ^ "\" (and ancestors)" ^
Walther@60547
   306
    "\nTODO exception hierarchy needs to be established.")
Walther@60551
   307
Walther@60550
   308
(*for starting an Exmaple by CAS_Cmd*)
Walther@60550
   309
(*val get_cas_global: term -> References_Def.T * CAS_Def.generate_fn*)
Walther@60550
   310
fun get_cas_global tm =
Walther@60550
   311
  let
Walther@60608
   312
    val thy = get_ref_last_thy ()
Walther@60550
   313
  in
Walther@60588
   314
    case AList.lookup (op =) (Know_Store.get_cass thy) tm of
Walther@60550
   315
      NONE => (writeln ("CAS_Cmd \"" ^ 
Walther@60550
   316
          UnparseC.term_in_thy thy tm ^ "\" missing in theory \"" ^ 
Walther@60550
   317
          (thy |> Context.theory_name) ^ "\" (and ancestors).");
Walther@60550
   318
        NONE)
Walther@60550
   319
    | SOME refs__gen_fun => SOME refs__gen_fun
Walther@60550
   320
  end
Walther@60550
   321
wneuper@59586
   322
Walther@60608
   323
fun get_pbls () = get_ref_last_thy () |> Know_Store.get_pbls;
Walther@60608
   324
fun get_mets () = get_ref_last_thy () |> Know_Store.get_mets;
Walther@60608
   325
fun get_thes () = get_ref_last_thy () |> Know_Store.get_thes;
Walther@60608
   326
fun get_expls () = get_ref_last_thy () |> Know_Store.get_expls;
wneuper@59586
   327
\<close>
wenzelm@60286
   328
wenzelm@60289
   329
rule_set_knowledge
wenzelm@60286
   330
  empty = \<open>Rule_Set.empty\<close> and
wenzelm@60286
   331
  e_rrls = \<open>Rule_Set.e_rrls\<close>
wneuper@59586
   332
wneuper@59586
   333
section \<open>determine sequence of main parts in thehier\<close>
wneuper@59586
   334
setup \<open>
Walther@60588
   335
Know_Store.add_thes
walther@59917
   336
  [(Thy_Write.Html {guh = Thy_Write.part2guh ["IsacKnowledge"], html = "",
wneuper@59586
   337
    mathauthors = ["Isac team"], coursedesign = []}, ["IsacKnowledge"]),
walther@59917
   338
  (Thy_Write.Html {guh = Thy_Write.part2guh ["Isabelle"], html = "",
wneuper@59586
   339
    mathauthors = ["Isabelle team, TU Munich"], coursedesign = []}, ["Isabelle"]),
walther@59917
   340
  (Thy_Write.Html {guh = Thy_Write.part2guh ["IsacScripts"], html = "",
wneuper@59586
   341
    mathauthors = ["Isac team"], coursedesign = []}, ["IsacScripts"])]
wneuper@59586
   342
\<close>
wneuper@59586
   343
Walther@60588
   344
section \<open>Functions for checking Know_Store\<close>
wneuper@59586
   345
ML \<open>
walther@59851
   346
fun short_string_of_rls Rule_Set.Empty = "Erls"
walther@59851
   347
  | short_string_of_rls (Rule_Def.Repeat {calc, rules, ...}) =
wneuper@59586
   348
    "Rls {#calc = " ^ string_of_int (length calc) ^
wneuper@59586
   349
    ", #rules = " ^ string_of_int (length rules) ^ ", ..."
walther@59878
   350
  | short_string_of_rls (Rule_Set.Sequence {calc, rules, ...}) =
wneuper@59586
   351
    "Seq {#calc = " ^ string_of_int (length calc) ^
wneuper@59586
   352
    ", #rules = " ^ string_of_int (length rules) ^ ", ..."
walther@59850
   353
  | short_string_of_rls (Rule_Set.Rrls _) = "Rrls {...}";
wneuper@59586
   354
fun check_kestore_rls (rls', (thyID, rls)) =
wneuper@59586
   355
  "(" ^ rls' ^ ", (" ^ thyID ^ ", " ^ short_string_of_rls rls ^ "))";
wneuper@59586
   356
Walther@60537
   357
fun check_kestore_calc ((id, (c, _)) : Rule_Def.eval_ml_from_prog)  = "(" ^ id ^ ", (" ^ c ^ ", fn))";
wneuper@59586
   358
walther@59846
   359
(* we avoid term_to_string''' defined later *)
walther@59896
   360
fun check_kestore_cas ((t, (s, _)) : CAS_Def.T) =
walther@59846
   361
  "(" ^ (Print_Mode.setmp [] (Syntax.string_of_term (Config.put show_markup false
walther@59985
   362
  (Proof_Context.init_global @{theory})))) t ^ ", " ^ References_Def.to_string s ^ ")";
wneuper@59586
   363
wneuper@59586
   364
fun count_kestore_ptyps [] = 0
walther@59897
   365
  | count_kestore_ptyps ((Store.Node (_, _, ps)) :: ps') =
wneuper@59586
   366
      1 + count_kestore_ptyps ps  + count_kestore_ptyps ps';
walther@59897
   367
fun check_kestore_ptyp' strfun (Store.Node (key, pbts, pts)) = "Ptyp (" ^ (quote key) ^ ", " ^
walther@59888
   368
      (strfun pbts) ^ ", " ^ (map (check_kestore_ptyp' strfun) pts |> list2str) ^ ")" |> linefeed;
walther@59894
   369
val check_kestore_ptyp = check_kestore_ptyp' Probl_Def.s_to_string;
walther@59897
   370
fun ptyp_ord ((Store.Node (s1, _, _)), (Store.Node (s2, _, _))) = string_ord (s1, s2);
walther@59894
   371
fun pbt_ord ({guh = guh'1, ...} : Probl_Def.T, {guh = guh'2, ...} : Probl_Def.T) = string_ord (guh'1, guh'2);
wneuper@59586
   372
fun sort_kestore_ptyp' _ [] = []
walther@59897
   373
  | sort_kestore_ptyp' ordfun ((Store.Node (key, pbts, ps)) :: ps') =
walther@59897
   374
     ((Store.Node (key, sort ordfun pbts, sort_kestore_ptyp' ordfun ps |> sort ptyp_ord))
wneuper@59586
   375
       :: sort_kestore_ptyp' ordfun ps');
wneuper@59586
   376
val sort_kestore_ptyp = sort_kestore_ptyp' pbt_ord;
wneuper@59586
   377
walther@59895
   378
fun metguh2str ({guh,...} : Meth_Def.T) = guh : string;
walther@59897
   379
fun check_kestore_met (mp: Meth_Def.T Store.node) =
wneuper@59586
   380
      check_kestore_ptyp' (fn xs => map metguh2str xs |> strs2str) mp;
walther@59895
   381
fun met_ord ({guh = guh'1, ...} : Meth_Def.T, {guh = guh'2, ...} : Meth_Def.T) = string_ord (guh'1, guh'2);
wneuper@59586
   382
val sort_kestore_met = sort_kestore_ptyp' met_ord;
wneuper@59586
   383
walther@59917
   384
fun check_kestore_thes thes = ((map writeln) o (map (check_kestore_ptyp' Thy_Write.thes2str))) thes
wneuper@59586
   385
fun write_thes thydata_list =
wneuper@59586
   386
  thydata_list 
walther@59917
   387
    |> map (fn (id, the) => (Thy_Write.theID2str id, Thy_Write.the2str the))
wneuper@59586
   388
    |> map pair2str
wneuper@59586
   389
    |> map writeln
wneuper@59586
   390
\<close>
wneuper@59586
   391
ML \<open>
wneuper@59586
   392
\<close> ML \<open>
wneuper@59586
   393
\<close> ML \<open>
wneuper@59586
   394
\<close>
wneuper@59586
   395
end