src/Tools/isac/calcelems.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 21 May 2012 16:56:01 +0200
changeset 42430 5b629bb1c073
parent 42429 e24d0af5d705
child 42434 9e9debbe1501
permissions -rw-r--r--
added fun FindFillpatterns

TODO: separate "error pattern #" from "no derivation found"
neuper@37906
     1
(* elements of calculations.
neuper@37906
     2
   they are partially held in association lists as ref's for
neuper@37906
     3
   switching language levels (meta-string, object-values).
neuper@37906
     4
   in order to keep these ref's during re-evaluation of code,
neuper@42399
     5
   they are defined here at the beginning of the code.
neuper@42399
     6
   Author: Walther Neuper 2003
neuper@42399
     7
   (c) copyright due to lincense terms
neuper@37906
     8
*)
neuper@37906
     9
neuper@38061
    10
(*
neuper@38061
    11
structure CalcElems =
neuper@38061
    12
struct
neuper@38061
    13
*)
neuper@37906
    14
val linefeed = (curry op^) "\n";
neuper@37906
    15
type authors = string list;
neuper@37906
    16
neuper@37906
    17
type cterm' = string;
neuper@37906
    18
val empty_cterm' = "empty_cterm'";
neuper@42399
    19
neuper@42399
    20
type thmID = string;    (* identifier for a thm (the shortest possible identifier)       *)
neuper@42399
    21
type thmDeriv = string; (* thyID ^"."^ xxx ^"."^ thmID, see fun thmID_of_derivation_name *)
neuper@42399
    22
neuper@37906
    23
type thm' = thmID * cterm';(*WN060610 deprecated in favour of thm''*)
neuper@37906
    24
type thm'' = thmID * term;
neuper@37906
    25
type rls' = string;
neuper@42399
    26
neuper@40836
    27
(*.a 'guh'='globally unique handle' is a string unique for each element
neuper@37906
    28
   of isac's KEStore and persistent over time
neuper@37906
    29
   (in particular under shifts within the respective hierarchy);
neuper@40836
    30
   specialty for thys:
neuper@37906
    31
   # guh NOT resistant agains shifts from one thy to another
neuper@37906
    32
   (which is the price for Isabelle's design: thy's overwrite ids of subthy's)
neuper@37906
    33
   # requirement for matchTheory: induce guh from tac + current thy
neuper@37906
    34
   (see 'fun thy_containing_thm', 'fun thy_containing_rls' etc.)
neuper@40836
    35
   TODO: introduce to pbl, met.*)
neuper@37906
    36
type guh = string;
neuper@37906
    37
val e_guh = "e_guh":guh;
neuper@37906
    38
neuper@37906
    39
type xml = string;
neuper@37906
    40
neuper@37906
    41
(*. eval function calling sml code during rewriting.*)
neuper@37906
    42
type eval_fn = (string -> term -> theory -> (string * term) option);
neuper@37906
    43
fun e_evalfn (_:'a) (_:term) (_:theory) = NONE:(string * term) option;
neuper@37906
    44
(*. op in isa-term 'Const(op,_)' .*)
neuper@37906
    45
type calID = string;
neuper@37906
    46
type cal = (calID * eval_fn);
neuper@37906
    47
(*. fun calculate_ fetches the evaluation-function via this list. *)
neuper@37906
    48
type calcID = string;
neuper@37906
    49
type calc = (calcID * cal);
neuper@37906
    50
neuper@37906
    51
type subs' = (cterm' * cterm') list; (*16.11.00 for FE-KE*)
neuper@37906
    52
type subst = (term * term) list; (*here for ets2str*)
neuper@37906
    53
val e_subst = []:(term * term) list;
neuper@37906
    54
neuper@37906
    55
(*TODO.WN060610 make use of "type rew_ord" total*)
neuper@37906
    56
type rew_ord' = string;
neuper@37906
    57
val e_rew_ord' = "e_rew_ord" : rew_ord';
neuper@37906
    58
type rew_ord_ = subst -> Term.term * Term.term -> bool;
neuper@37906
    59
fun dummy_ord (_:subst) (_:term,_:term) = true;
neuper@37906
    60
val e_rew_ord_ = dummy_ord;
neuper@37906
    61
type rew_ord = rew_ord' * rew_ord_;
neuper@37906
    62
val e_rew_ord = dummy_ord; (* TODO.WN071231 clarify identifiers..e_rew_ordX*)
neuper@37906
    63
val e_rew_ordX = (e_rew_ord', e_rew_ord_) : rew_ord;
neuper@37906
    64
neuper@37906
    65
neuper@40836
    66
datatype rule =
neuper@37906
    67
  Erule                (*.the empty rule                     .*)
neuper@40836
    68
| Thm of (string * Basic_Thm.thm)(*.a theorem, ie (identifier, Thm.thm).*)
neuper@37906
    69
| Calc of string *     (*.sml-code manipulating a (sub)term  .*)
neuper@37906
    70
	  (string -> term -> theory -> (string * term) option)
neuper@37906
    71
| Cal1 of string *     (*.sml-code applied only to whole term
neuper@37906
    72
                          or left/right-hand-side of eqality .*)
neuper@37906
    73
	  (string -> term -> theory -> (string * term) option)
neuper@37906
    74
| Rls_ of rls          (*.ie. rule sets may be nested.*)
neuper@40836
    75
and scr =
neuper@40836
    76
    EmptyScr
neuper@37906
    77
  | Script of term (*for met*)
neuper@40836
    78
  | Rfuns of {init_state : term ->
neuper@40836
    79
     (term *          (*the current formula:
neuper@37906
    80
                        goes locate_gen -> next_tac via istate*)
neuper@37906
    81
      term *          (*the final formula*)
neuper@37906
    82
      rule list       (*of reverse rewrite set (#1#)*)
neuper@37906
    83
	    list *    (*may be serveral, eg. in norm_rational*)
neuper@37906
    84
      (rule *         (*Thm (+ Thm generated from Calc) resulting in ...*)
neuper@37906
    85
       (term *        (*... rewrite with ...*)
neuper@37906
    86
	term list))   (*... assumptions*)
neuper@37906
    87
	  list),      (*derivation from given term to normalform
neuper@40836
    88
		       in reverse order with sym_thm;
neuper@37906
    89
                       (#1#) could be extracted from here #1*)
neuper@37906
    90
neuper@37906
    91
	      normal_form: term -> (term * term list) option,
neuper@40836
    92
	      locate_rule: rule list list -> term -> rule
neuper@37906
    93
			   -> (rule * (term * term list)) list,
neuper@37906
    94
	      next_rule  : rule list list -> term -> rule option,
neuper@40836
    95
	      attach_form: rule list list -> term -> term
neuper@37906
    96
			   -> (rule * (term * term list)) list}
neuper@40836
    97
neuper@37906
    98
and rls =
neuper@37906
    99
    Erls                          (*for init e_rls*)
neuper@40836
   100
neuper@37906
   101
  | Rls of (*a confluent and terminating ruleset, in general         *)
neuper@37906
   102
    {id : string,          (*for trace_rewrite:=true                 *)
neuper@37906
   103
     preconds : term list, (*unused WN020820                         *)
neuper@37906
   104
     (*WN060616 for efficiency...
neuper@37906
   105
      bdvs    : false,       (*set in prep_rls for get_bdvs *)*)
neuper@37906
   106
     rew_ord  : rew_ord,   (*for rules*)
neuper@37906
   107
     erls     : rls,       (*for the conditions in rules             *)
neuper@37906
   108
     srls     : rls,       (*for evaluation of list_fns in script    *)
neuper@37906
   109
     calc     : calc list, (*for Calculate in scr, set by prep_rls   *)
neuper@37906
   110
     rules    : rule list,
neuper@37906
   111
     scr      : scr}       (*Script term: generating intermed.steps  *)
neuper@37906
   112
  | Seq of (*a sequence of rules to be tried only once               *)
neuper@37906
   113
    {id : string,          (*for trace_rewrite:=true                 *)
neuper@37906
   114
     preconds : term list, (*unused 20.8.02                          *)
neuper@37906
   115
     (*WN060616 for efficiency...
neuper@37906
   116
      bdvs    : false,       (*set in prep_rls for get_bdvs *)*)
neuper@37906
   117
     rew_ord  : rew_ord,   (*for rules                               *)
neuper@37906
   118
     erls     : rls,       (*for the conditions in rules             *)
neuper@37906
   119
     srls     : rls,       (*for evaluation of list_fns in script    *)
neuper@40836
   120
     calc     : calc list, (*for Calculate in scr, set by prep_rls   *)
neuper@37906
   121
     rules    : rule list,
neuper@37906
   122
     scr      : scr}  (*Script term  (how to restrict type ???)*)
neuper@37906
   123
  (*Rrls call SML-code and simulate an rls
neuper@37906
   124
    difference: there is always _ONE_ redex rewritten in 1 call,
neuper@37906
   125
    thus wrap Rrls by: Rls (Rls_ ...)*)
neuper@40836
   126
neuper@38036
   127
  | Rrls of (* for 'reverse rewriting' by SML-functions instead Script        *)
neuper@38036
   128
    {id : string,          (* for trace_rewrite := true                       *)
neuper@40836
   129
     prepat  : (term list *(* preconds, eval with subst from pattern;
neuper@38036
   130
                              if [HOLogic.true_const], match decides alone    *)
neuper@38036
   131
		term )     (* pattern matched with current (sub)term          *)
neuper@38036
   132
		   list,   (* meta-conjunction is or                          *)
neuper@38036
   133
     rew_ord  : rew_ord,   (* for rules                                       *)
neuper@38036
   134
     erls     : rls,       (* for the conditions in rules and preconds        *)
neuper@38036
   135
     calc     : calc list, (* for Calculate in scr, set automatic.in prep_rls *)
neuper@38036
   136
     scr      : scr};      (* Rfuns {...}  (how to restrict type ???)         *)
neuper@37906
   137
(*1.8.02 ad (how to restrict type ???): scr should be usable indepentently
neuper@37906
   138
  from rls, and then contain both Script _AND_ Rfuns !!!*)
neuper@37906
   139
neuper@40836
   140
fun thy2ctxt' thy' = ProofContext.init_global (Thy_Info.get_theory thy');(*FIXXXME thy-ctxt*)
neuper@37928
   141
fun thy2ctxt thy = ProofContext.init_global thy;(*FIXXXME thy-ctxt*)
neuper@37906
   142
neuper@41991
   143
fun Isac _ = ProofContext.theory_of (thy2ctxt' "Isac"); (*@{theory "Isac"}*)
neuper@37906
   144
neuper@40836
   145
val e_rule = Thm ("refl", @{thm refl});
neuper@37906
   146
fun id_of_thm (Thm (id, _)) = id
neuper@38031
   147
  | id_of_thm _ = error "id_of_thm";
neuper@37906
   148
fun thm_of_thm (Thm (_, thm)) = thm
neuper@38031
   149
  | thm_of_thm _ = error "thm_of_thm";
neuper@37906
   150
fun rep_thm_G' (Thm (thmid, thm)) = (thmid, thm);
neuper@38061
   151
neuper@38061
   152
fun thmID_of_derivation_name dn = last_elem (space_explode "." dn);
neuper@38061
   153
fun thyID_of_derivation_name dn = hd (space_explode "." dn);
neuper@38061
   154
neuper@37906
   155
fun eq_thmI ((thmid1 : thmID, _ : thm), (thmid2 : thmID, _ : thm)) =
neuper@37906
   156
    (strip_thy thmid1) = (strip_thy thmid2);
neuper@42372
   157
(*WN120201 weakened*)
neuper@42372
   158
fun eq_thmI ((thmid1 : thmID, _ : thm), (thmid2 : thmID, _)) = thmid1 = thmid2;
neuper@38002
   159
(*version typed weaker WN100910*)
neuper@38002
   160
fun eq_thmI' ((thmid1, _), (thmid2, _)) =
neuper@38061
   161
    (thmID_of_derivation_name thmid1) = (thmID_of_derivation_name thmid2);
neuper@37906
   162
neuper@37906
   163
neuper@37906
   164
val string_of_thm =  Thm.get_name_hint; (*FIXME.2009*)
neuper@37906
   165
(*check for [.] as caused by "fun assoc_thm'"*)
neuper@37906
   166
fun string_of_thmI thm =
neuper@37906
   167
    let val ct' = (de_quote o string_of_thm) thm
neuper@40836
   168
	val (a, b) = split_nlast (5, Symbol.explode ct')
neuper@40836
   169
    in case b of
neuper@37906
   170
	   [" ", " ","[", ".", "]"] => implode a
neuper@37906
   171
	 | _ => ct'
neuper@37906
   172
    end;
neuper@37906
   173
neuper@37906
   174
(*.id requested for all, Rls,Seq,Rrls.*)
neuper@37906
   175
fun id_rls Erls = "e_rls" (*WN060714 quick and dirty: recursive defs!*)
neuper@37906
   176
  | id_rls (Rls {id,...}) = id
neuper@37906
   177
  | id_rls (Seq {id,...}) = id
neuper@37906
   178
  | id_rls (Rrls {id,...}) = id;
neuper@37906
   179
val rls2str = id_rls;
neuper@37906
   180
fun id_rule (Thm (id, _)) = id
neuper@37906
   181
  | id_rule (Calc (id, _)) = id
neuper@37906
   182
  | id_rule (Rls_ rls) = id_rls rls;
neuper@37906
   183
neuper@37906
   184
fun get_rules (Rls {rules,...}) = rules
neuper@37906
   185
  | get_rules (Seq {rules,...}) = rules
neuper@37906
   186
  | get_rules (Rrls _) = [];
neuper@37906
   187
neuper@37906
   188
fun rule2str Erule = "Erule"
neuper@37906
   189
  | rule2str (Thm (str, thm)) = "Thm (\""^str^"\","^(string_of_thmI thm)^")"
neuper@37906
   190
  | rule2str (Calc (str,f))  = "Calc (\""^str^"\",fn)"
neuper@37906
   191
  | rule2str (Cal1 (str,f))  = "Cal1 (\""^str^"\",fn)"
neuper@37906
   192
  | rule2str (Rls_ rls) = "Rls_ (\""^id_rls rls^"\")";
neuper@37906
   193
fun rule2str' Erule = "Erule"
neuper@37906
   194
  | rule2str' (Thm (str, thm)) = "Thm (\""^str^"\",\"\")"
neuper@37906
   195
  | rule2str' (Calc (str,f))  = "Calc (\""^str^"\",fn)"
neuper@37906
   196
  | rule2str' (Cal1 (str,f))  = "Cal1 (\""^str^"\",fn)"
neuper@37906
   197
  | rule2str' (Rls_ rls) = "Rls_ (\""^id_rls rls^"\")";
neuper@37906
   198
neuper@37906
   199
(*WN080102 compare eq_rule ?!?*)
neuper@37906
   200
fun eqrule (Thm (id1,_), Thm (id2,_)) = id1 = id2
neuper@37906
   201
  | eqrule (Calc (id1,_), Calc (id2,_)) = id1 = id2
neuper@37906
   202
  | eqrule (Cal1 (id1,_), Cal1 (id2,_)) = id1 = id2
neuper@37906
   203
  | eqrule (Rls_ _, Rls_ _) = false (*{id=id1}{id=id2} = id1 = id2 FIXXME*)
neuper@37906
   204
  | eqrule _ = false;
neuper@37906
   205
neuper@37906
   206
neuper@37906
   207
type rrlsstate =      (*state for reverse rewriting*)
neuper@40836
   208
     (term *          (*the current formula:
neuper@37906
   209
                        goes locate_gen -> next_tac via istate*)
neuper@37906
   210
      term *          (*the final formula*)
neuper@37906
   211
      rule list       (*of reverse rewrite set (#1#)*)
neuper@37906
   212
	    list *    (*may be serveral, eg. in norm_rational*)
neuper@37906
   213
      (rule *         (*Thm (+ Thm generated from Calc) resulting in ...*)
neuper@37906
   214
       (term *        (*... rewrite with ...*)
neuper@37906
   215
	term list))   (*... assumptions*)
neuper@37906
   216
	  list);      (*derivation from given term to normalform
neuper@40836
   217
		       in reverse order with sym_thm;
neuper@37906
   218
                       (#1#) could be extracted from here #1*)
neuper@37906
   219
val e_type = Type("empty",[]);
neuper@37906
   220
val a_type = TFree("'a",[]);
neuper@37906
   221
val e_term = Const("empty",e_type);
neuper@37906
   222
val a_term = Free("empty",a_type);
neuper@37906
   223
val e_rrlsstate = (e_term,e_term,[[e_rule]],[(e_rule,(e_term,[]))]):rrlsstate;
neuper@37906
   224
neuper@37906
   225
neuper@37906
   226
neuper@37906
   227
neuper@37906
   228
(*22.2.02: ging auf Linux nicht (Stefan)
neuper@37906
   229
val e_scr = Script ((term_of o the o (parse thy)) "e_script");*)
neuper@37906
   230
val e_term = Const("empty", Type("'a", []));
neuper@37906
   231
val e_scr = Script e_term;
neuper@37906
   232
neuper@37906
   233
neuper@37906
   234
(*ad thm':
neuper@37906
   235
   there are two kinds of theorems ...
neuper@37906
   236
   (1) known by isabelle
neuper@37906
   237
   (2) not known, eg. calc_thm, instantiated rls
neuper@37906
   238
       the latter have a thmid "#..."
neuper@37906
   239
   and thus outside isa we ALWAYS transport both (thmid,string_of_thmI)
neuper@37906
   240
   and have a special assoc_thm / assoc_rls in this interface      *)
neuper@38058
   241
type theory' = string; (* = domID ^".thy" WN.101011 ABOLISH !*)
neuper@38058
   242
type domID = string;   (* domID ^".thy" = theory' WN.101011 replace by thyID*)
neuper@37906
   243
type thyID = string;    (*WN.3.11.03 TODO: replace domID with thyID*)
neuper@37906
   244
neuper@37906
   245
fun string_of_thy thy = Context.theory_name thy: theory';
neuper@37906
   246
val theory2domID = string_of_thy;
neuper@37906
   247
val theory2thyID = (get_thy o string_of_thy) : theory -> thyID;
neuper@37906
   248
val theory2theory' = string_of_thy;
neuper@37906
   249
val theory2str = string_of_thy; (*WN050903 ..most consistent naming*)
neuper@40836
   250
val theory2str' = implode o (drop_last_n 4) o Symbol.explode o string_of_thy;
neuper@40836
   251
(*> theory2str' (Thy_Info.get_theory "Isac");
neuper@37906
   252
al it = "Isac" : string
neuper@37906
   253
*)
neuper@37906
   254
neuper@38058
   255
fun thyID2theory' (thyID:thyID) = thyID;
neuper@38058
   256
(*
neuper@40836
   257
    let val ss = Symbol.explode thyID
neuper@37906
   258
	val ext = implode (takelast (4, ss))
neuper@37906
   259
    in if ext = ".thy" then thyID : theory' (*disarm abuse of thyID*)
neuper@37906
   260
       else thyID ^ ".thy"
neuper@37906
   261
    end;
neuper@38058
   262
*)
neuper@37906
   263
(* thyID2theory' "Isac" (*ok*);
neuper@38050
   264
val it = "Isac" : theory'
neuper@38050
   265
 > thyID2theory' "Isac" (*abuse, goes ok...*);
neuper@38050
   266
val it = "Isac" : theory'
neuper@37906
   267
*)
neuper@37906
   268
neuper@38058
   269
fun theory'2thyID (theory':theory') = theory';
neuper@38058
   270
(*
neuper@40836
   271
    let val ss = Symbol.explode theory'
neuper@37906
   272
	val ext = implode (takelast (4, ss))
neuper@37906
   273
    in if ext = ".thy" then ((implode o (drop_last_n 4)) ss) : thyID
neuper@37906
   274
       else theory' (*disarm abuse of theory'*)
neuper@37906
   275
    end;
neuper@38058
   276
*)
neuper@38050
   277
(* theory'2thyID "Isac";
neuper@37906
   278
val it = "Isac" : thyID
neuper@37906
   279
> theory'2thyID "Isac";
neuper@37906
   280
val it = "Isac" : thyID*)
neuper@37906
   281
neuper@37906
   282
neuper@37906
   283
(*. WN0509 discussion:
neuper@37906
   284
#############################################################################
neuper@37906
   285
#   How to manage theorys in subproblems wrt. the requirement,              #
neuper@37906
   286
#   that scripts should be re-usable ?                                      #
neuper@37906
   287
#############################################################################
neuper@37906
   288
neuper@37988
   289
    eg. 'Script Solve_rat_equation' calls 'SubProblem (RatEq',..'
neuper@37906
   290
    which would not allow to 'solve (y'' = -M_b / EI, M_b)' by this script
neuper@40836
   291
    because Biegelinie.thy is subthy of RatEq.thy and thus Biegelinie.M_b
neuper@37906
   292
    is unknown in RatEq.thy and M_b cannot be parsed into the scripts guard
neuper@37906
   293
    (see match_ags).
neuper@37906
   294
neuper@37906
   295
    Preliminary solution:
neuper@38011
   296
    # the thy in 'SubProblem (thy', pbl, arglist)' is not taken automatically,
neuper@38011
   297
    # instead the 'maxthy (rootthy pt) thy' is taken for each subpbl
neuper@40836
   298
    # however, a thy specified by the user in the rootpbl may lead to
neuper@40836
   299
      errors in far-off subpbls (which are not yet reported properly !!!)
neuper@37906
   300
      and interactively specifiying thys in subpbl is not very relevant.
neuper@37906
   301
neuper@37906
   302
    Other solutions possible:
neuper@40836
   303
    # always parse and type-check with Thy_Info.get_theory "Isac"
neuper@37906
   304
      (rejected tue to the vague idea eg. to re-use equations for R in C etc.)
neuper@37906
   305
    # regard the subthy-relation in specifying thys of subpbls
neuper@38011
   306
    # specifically handle 'SubProblem (undefined, pbl, arglist)'
neuper@37906
   307
    # ???
neuper@37906
   308
.*)
neuper@40836
   309
(*WN0509 TODO "ProtoPure" ... would be more consistent
neuper@37906
   310
  with assoc_thy <--> theory2theory' +FIXME assoc_thy "e_domID" -> Script.thy*)
neuper@37906
   311
val e_domID = "e_domID":domID;
neuper@37906
   312
neuper@37906
   313
(*the key into the hierarchy ob theory elements*)
neuper@37906
   314
type theID = string list;
neuper@37906
   315
val e_theID = ["e_theID"];
neuper@37906
   316
val theID2str = strs2str;
neuper@37906
   317
(*theID eg. is ["IsacKnowledge", "Test", "Rulesets", "ac_plus_times"]*)
neuper@37906
   318
fun theID2thyID (theID:theID) =
neuper@37906
   319
    if length theID >= 3 then (last_elem o (drop_last_n 2)) theID : thyID
neuper@38031
   320
    else error ("theID2thyID called with "^ theID2str theID);
neuper@37906
   321
neuper@37906
   322
(*the key into the hierarchy ob problems*)
neuper@37906
   323
type pblID = string list; (* domID::...*)
neuper@37906
   324
val e_pblID = ["e_pblID"]:pblID;
neuper@37906
   325
val pblID2str = strs2str;
neuper@37906
   326
neuper@37906
   327
(*the key into the hierarchy ob methods*)
neuper@37906
   328
type metID = string list;
neuper@37906
   329
val e_metID = ["e_metID"]:metID;
neuper@37906
   330
val metID2str = strs2str;
neuper@37906
   331
neuper@37906
   332
(*either theID or pblID or metID*)
neuper@37906
   333
type kestoreID = string list;
neuper@37906
   334
val e_kestoreID = ["e_kestoreID"];
neuper@37906
   335
val kestoreID2str = strs2str;
neuper@37906
   336
neuper@37906
   337
(*for distinction of contexts*)
neuper@37906
   338
datatype ketype = Exp_ | Thy_ | Pbl_ | Met_;
neuper@37906
   339
fun ketype2str Exp_ = "Exp_"
neuper@40836
   340
  | ketype2str Thy_ = "Thy_"
neuper@40836
   341
  | ketype2str Pbl_ = "Pbl_"
neuper@37906
   342
  | ketype2str Met_ = "Met_";
neuper@37906
   343
fun ketype2str' Exp_ = "Example"
neuper@40836
   344
  | ketype2str' Thy_ = "Theory"
neuper@40836
   345
  | ketype2str' Pbl_ = "Problem"
neuper@37906
   346
  | ketype2str' Met_ = "Method";
neuper@37906
   347
neuper@37906
   348
(*see 'How to manage theorys in subproblems' at 'type thyID'*)
neuper@38006
   349
val theory'  = Unsynchronized.ref ([]:(theory' * theory) list);
neuper@37906
   350
neuper@42400
   351
(* theories for html representation: Isabelle, Knowledge, ProgLang *)
neuper@42400
   352
val isabthys = Unsynchronized.ref ([] : theory list);
neuper@42400
   353
val knowthys = Unsynchronized.ref ([] : theory list);
neuper@42400
   354
val progthys = Unsynchronized.ref ([] : theory list);
neuper@37906
   355
neuper@37906
   356
(*rewrite orders, also stored in 'type met' and type 'and rls'
neuper@37906
   357
  The association list is required for 'rewrite.."rew_ord"..'
neuper@37947
   358
  WN0509 tests not well-organized: see smltest/Knowledge/termorder.sml*)
neuper@38007
   359
val rew_ord' =
neuper@38007
   360
    Unsynchronized.ref
neuper@38007
   361
        ([]:(rew_ord' *        (*the key for the association list         *)
neuper@37906
   362
	     (subst 	       (*the bound variables - they get high order*)
neuper@37906
   363
	      -> (term * term) (*(t1, t2) to be compared                  *)
neuper@37906
   364
	      -> bool))        (*if t1 <= t2 then true else false         *)
neuper@37906
   365
		list);         (*association list                         *)
neuper@38061
   366
neuper@37906
   367
rew_ord' := overwritel (!rew_ord', [("e_rew_ord", e_rew_ord),
neuper@37906
   368
				    ("dummy_ord", dummy_ord)]);
neuper@37906
   369
neuper@37906
   370
neuper@37906
   371
(*WN060120 a hack to get alltogether run again with minimal effort:
neuper@37906
   372
  theory' is inserted for creating thy_hierarchy; calls for assoc_rls
neuper@37906
   373
  need not be called*)
neuper@38006
   374
val ruleset' = Unsynchronized.ref ([]:(rls' * (theory' * rls)) list);
neuper@37906
   375
neuper@37906
   376
(*FIXME.040207 calclist': used by prep_rls, NOT in met*)
neuper@38006
   377
val calclist'= Unsynchronized.ref ([]: calc list);
neuper@37906
   378
neuper@42429
   379
(* error patterns and fill patterns *)
neuper@42429
   380
type errpatID = string
neuper@42429
   381
type errpat =
neuper@42429
   382
  errpatID    (* one identifier for a list of patterns                       
neuper@42429
   383
                 DESIGN ?TODO: errpatID list for hierarchy of errpats ?      *)
neuper@42429
   384
  * term list (* error patterns                                              *)
neuper@42429
   385
  * thm list  (* thms related to error patterns; note that respective lhs 
neuper@42429
   386
                 do not match (which reflects student's error).
neuper@42429
   387
                 fillpatterns are stored with these thms.                    *)
neuper@42429
   388
neuper@42429
   389
(* for (at least) 2 kinds of access:
neuper@42429
   390
  (1) given an errpatID, find the respective fillpats (e.g. in fun find_fill_pats)
neuper@42429
   391
  (2) given a thm, find respective fillpats *)
neuper@42429
   392
type fillpatID = string
neuper@42429
   393
type fillpat =
neuper@42429
   394
  fillpatID   (* DESIGN ?TODO: give an order w.r.t difficulty ? *)
neuper@42429
   395
  * term      (* the pattern with fill-in gaps                  *)
neuper@42429
   396
  * errpatID; (* which the fillpat would be a help for          
neuper@42429
   397
                 DESIGN ?TODO: list for several patterns ?      *)
neuper@42429
   398
neuper@37906
   399
(*.the hierarchy of thydata.*)
neuper@37906
   400
neuper@37906
   401
(*.'a is for pbt | met.*)
neuper@37906
   402
(*WN.24.4.03 -"- ... type parameters; afterwards naming inconsistent*)
neuper@40836
   403
datatype 'a ptyp =
neuper@37906
   404
	 Ptyp of string *   (*element within pblID*)
neuper@37906
   405
		 'a list *  (*several pbts with different domIDs/thy
neuper@37906
   406
			      TODO: select by subthy (isaref.p.69)
neuper@37906
   407
			      presently only _ONE_ elem*)
neuper@37906
   408
		 ('a ptyp) list;   (*the children nodes*)
neuper@37906
   409
neuper@37906
   410
(*.datatype for collecting thydata for hierarchy.*)
neuper@37906
   411
(*WN060720 more consistent naming would be 'type thyelem' or 'thelem'*)
neuper@37906
   412
(*WN0606 Htxt contains html which does not belong to the sml-kernel*)
neuper@37906
   413
datatype thydata = Html of {guh: guh,
neuper@37906
   414
			    coursedesign: authors,
neuper@37906
   415
			    mathauthors: authors,
neuper@37906
   416
			    html: string} (*html; for demos before database*)
neuper@37906
   417
		 | Hthm of {guh: guh,
neuper@37906
   418
			    coursedesign: authors,
neuper@37906
   419
			    mathauthors: authors,
neuper@42429
   420
			    fillpats: fillpat list,
neuper@38002
   421
			    thm: term}
neuper@37906
   422
		 | Hrls of {guh: guh,
neuper@37906
   423
			    coursedesign: authors,
neuper@37906
   424
			    mathauthors: authors,
neuper@37906
   425
			    (*like   vvvvvvvvvvvvv val ruleset'
neuper@37906
   426
			     WN060711 redesign together !*)
neuper@37906
   427
			    thy_rls: (thyID * rls)}
neuper@37906
   428
		 | Hcal of {guh: guh,
neuper@37906
   429
			    coursedesign: authors,
neuper@37906
   430
			    mathauthors: authors,
neuper@37906
   431
			    calc: calc}
neuper@37906
   432
		 | Hord of {guh: guh,
neuper@37906
   433
			    coursedesign: authors,
neuper@37906
   434
			    mathauthors: authors,
neuper@37906
   435
			    ord: (subst -> (term * term) -> bool)};
neuper@37906
   436
val e_thydata = Html {guh="e_guh", coursedesign=[], mathauthors=[], html=""};
neuper@37906
   437
neuper@37906
   438
type thehier = (thydata ptyp) list;
neuper@38061
   439
val thehier = Unsynchronized.ref ([] : thehier); (*WN101011 make argument, del*)
neuper@37906
   440
neuper@40836
   441
(* an association list, gets the value once in Isac.ML.
neuper@38061
   442
   stores Isabelle's thms as terms for compatibility with Theory.axioms_of.
neuper@38061
   443
   WN1-1-28 make this data arguments and del ref ?*)
neuper@42400
   444
val isab_thm_thy = Unsynchronized.ref ([] : (thmDeriv * term) list);
neuper@42400
   445
val isabthys = Unsynchronized.ref ([] : theory list);
neuper@42400
   446
neuper@42400
   447
val first_ProgLang_thy = Unsynchronized.ref (@{theory Pure});
neuper@42400
   448
val first_Knowledge_thy = Unsynchronized.ref (@{theory Pure});
neuper@37906
   449
neuper@37906
   450
neuper@37906
   451
type path = string;
neuper@37906
   452
type filename = string;
neuper@37906
   453
neuper@37906
   454
(*val xxx = fn: a b => (a,b);   ??? fun-definition ???*)
neuper@37906
   455
local
neuper@37906
   456
    fun ii (_:term) = e_rrlsstate;
neuper@37906
   457
    fun no (_:term) = SOME (e_term,[e_term]);
neuper@37906
   458
    fun lo (_:rule list list) (_:term) (_:rule) = [(e_rule,(e_term,[e_term]))];
neuper@37906
   459
    fun ne (_:rule list list) (_:term) = SOME e_rule;
neuper@37906
   460
    fun fo (_:rule list list) (_:term) (_:term) = [(e_rule,(e_term,[e_term]))];
neuper@37906
   461
in
neuper@37906
   462
val e_rfuns = Rfuns {init_state=ii,normal_form=no,locate_rule=lo,
neuper@37906
   463
		     next_rule=ne,attach_form=fo};
neuper@37906
   464
end;
neuper@37906
   465
neuper@40836
   466
val e_rls =
neuper@37906
   467
  Rls{id = "e_rls",
neuper@40836
   468
      preconds = [],
neuper@37906
   469
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37906
   470
      erls = Erls,srls = Erls,
neuper@37906
   471
      calc = [],
neuper@37906
   472
      rules = [], scr = EmptyScr}:rls;
neuper@37906
   473
val e_rrls = Rrls {id = "e_rrls",
neuper@37906
   474
		   prepat = [],
neuper@37906
   475
		   rew_ord = ("dummy_ord", dummy_ord),
neuper@37906
   476
		   erls = Erls,
neuper@37906
   477
		   calc = [],
neuper@37906
   478
		   (*asm_thm=[],*)
neuper@37906
   479
		   scr=e_rfuns}:rls;
neuper@37906
   480
ruleset' := overwritel (!ruleset', [("e_rls",("Tools",e_rls)),
neuper@37906
   481
				    ("e_rrls",("Tools",e_rrls))
neuper@37906
   482
				    ]);
neuper@37906
   483
neuper@37906
   484
fun rep_rls (Rls {id,preconds,rew_ord,erls,srls,calc,(*asm_thm,*)rules,scr}) =
neuper@37906
   485
  {id=id,preconds=preconds,rew_ord=rew_ord,erls=erls,srls=srls,calc=calc,
neuper@37906
   486
   (*asm_thm=asm_thm,*)rules=rules,scr=scr}
neuper@37906
   487
  | rep_rls (Seq {id,preconds,rew_ord,erls,srls,calc,(*asm_thm,*)rules,scr}) =
neuper@37906
   488
  {id=id,preconds=preconds,rew_ord=rew_ord,erls=erls,srls=srls,calc=calc,
neuper@37906
   489
   (*asm_thm=asm_thm,*)rules=rules,scr=scr}
neuper@37906
   490
  | rep_rls Erls = rep_rls e_rls
neuper@37906
   491
  | rep_rls (Rrls {id,...})  = rep_rls e_rls
neuper@38031
   492
    (*error("rep_rls doesn't take apart reverse-rewrite-rule-sets: "^id)*);
neuper@40836
   493
(*| rep_rls (Seq {id,...})  =
neuper@38031
   494
    error("rep_rls doesn't take apart reverse-rewrite-rule-sets: "^id);
neuper@37906
   495
--1.7.03*)
neuper@40836
   496
fun rep_rrls
neuper@40836
   497
	(Rrls {id,(*asm_thm,*) calc, erls, prepat, rew_ord,
neuper@37906
   498
	       scr=Rfuns
neuper@37906
   499
		       {attach_form,init_state,locate_rule,
neuper@37906
   500
			next_rule,normal_form}}) =
neuper@40836
   501
    {id=id,(*asm_thm=asm_thm,*) calc=calc, erls=erls, prepat=prepat,
neuper@40836
   502
     rew_ord=rew_ord, attach_form=attach_form, init_state=init_state,
neuper@37906
   503
     locate_rule=locate_rule, next_rule=next_rule, normal_form=normal_form}
neuper@40836
   504
  | rep_rrls (Rls {id,...}) =
neuper@38031
   505
    error ("rep_rrls doesn't take apart (normal) rule-sets: "^id)
neuper@40836
   506
  | rep_rrls (Seq {id,...}) =
neuper@38031
   507
    error ("rep_rrls doesn't take apart (normal) rule-sets: "^id);
neuper@37906
   508
neuper@37906
   509
fun append_rls id (Rls {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
neuper@37906
   510
			rules =rs,scr=sc}) r =
neuper@37906
   511
    (Rls{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
neuper@37906
   512
	 rules = rs @ r,scr=sc}:rls)
neuper@37906
   513
  | append_rls id (Seq {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
neuper@37906
   514
			rules =rs,scr=sc}) r =
neuper@37906
   515
    (Seq{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
neuper@37906
   516
	 rules = rs @ r,scr=sc}:rls)
neuper@40836
   517
  | append_rls id (Rrls _) _ =
neuper@38031
   518
    error ("append_rls: not for reverse-rewrite-rule-set "^id);
neuper@37906
   519
neuper@37906
   520
(*. are _atomic_ rules equal ?.*)
neuper@37906
   521
(*WN080102 compare eqrule ?!?*)
neuper@37906
   522
fun eq_rule (Thm (thm1,_), Thm (thm2,_)) = thm1 = thm2
neuper@37906
   523
  | eq_rule (Calc (id1,_), Calc (id2,_)) = id1 = id2
neuper@37906
   524
  | eq_rule (Rls_ rls1, Rls_ rls2) = id_rls rls1 = id_rls rls2
neuper@37906
   525
  (*id_rls checks for Rls, Seq, Rrls*)
neuper@37906
   526
  | eq_rule _ = false;
neuper@37906
   527
neuper@37906
   528
fun merge_rls _ Erls rls = rls
neuper@37906
   529
  | merge_rls _ rls Erls = rls
neuper@37906
   530
  | merge_rls id
neuper@37906
   531
	(Rls {id=id1,preconds=pc1,rew_ord=ro1,erls=er1,srls=sr1,calc=ca1,
neuper@40836
   532
	      (*asm_thm=at1,*)rules =rs1,scr=sc1})
neuper@37906
   533
	(r2 as Rls {id=id2,preconds=pc2,rew_ord=ro2,erls=er2,srls=sr2,calc=ca2,
neuper@37906
   534
	      (*asm_thm=at2,*)rules =rs2,scr=sc2}) =
neuper@37906
   535
	(Rls {id=id,preconds=pc1 @ ((#preconds o rep_rls) r2),
neuper@37906
   536
	      rew_ord=ro1,erls=merge_rls "" er1 er2(*er1*),
neuper@40836
   537
	      srls=merge_rls ("merged_"^id1^"_"^((#id o rep_rls) r2)) sr1
neuper@37906
   538
			     ((#srls o rep_rls) r2),
neuper@37906
   539
	      calc=ca1 @ ((#calc o rep_rls) r2),
neuper@37906
   540
	      (*asm_thm=at1 @ ((#asm_thm o rep_rls) r2),*)
neuper@37906
   541
	      rules = gen_union eq_rule rule2str (rs1, (#rules o rep_rls) r2),
neuper@37906
   542
	      scr=sc1}:rls)
neuper@37906
   543
  | merge_rls id
neuper@37906
   544
	(Seq {id=id1,preconds=pc1,rew_ord=ro1,erls=er1,srls=sr1,calc=ca1,
neuper@40836
   545
	      (*asm_thm=at1,*)rules =rs1,scr=sc1})
neuper@37906
   546
	(r2 as Seq {id=id2,preconds=pc2,rew_ord=ro2,erls=er2,srls=sr2,calc=ca2,
neuper@37906
   547
	      (*asm_thm=at2,*)rules =rs2,scr=sc2}) =
neuper@37906
   548
	(Seq {id=id,preconds=pc1 @ ((#preconds o rep_rls) r2),
neuper@37906
   549
	      rew_ord=ro1,erls=merge_rls "" er1 er2(*er1*),
neuper@40836
   550
	      srls=merge_rls ("merged_"^id1^"_"^((#id o rep_rls) r2)) sr1
neuper@37906
   551
			     ((#srls o rep_rls) r2),
neuper@37906
   552
	      calc=ca1 @ ((#calc o rep_rls) r2),
neuper@37906
   553
	      (*asm_thm=at1 @ ((#asm_thm o rep_rls) r2),*)
neuper@37906
   554
	      rules = gen_union eq_rule rule2str (rs1, (#rules o rep_rls) r2),
neuper@37906
   555
	      scr=sc1}:rls)
neuper@40836
   556
  | merge_rls _ _ _ =
neuper@38031
   557
    error "merge_rls: not for reverse-rewrite-rule-sets\
neuper@37906
   558
		\and not for mixed Rls -- Seq";
neuper@37906
   559
fun remove_rls id (Rls {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
neuper@37906
   560
		     (*asm_thm=at,*)rules =rs,scr=sc}) r =
neuper@37906
   561
    (Rls{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
neuper@37906
   562
	 (*asm_thm=at,*)rules = gen_rems eq_rule (rs, r),
neuper@37906
   563
	 scr=sc}:rls)
neuper@37906
   564
  | remove_rls id (Seq {id=_,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
neuper@37906
   565
		     (*asm_thm=at,*)rules =rs,scr=sc}) r =
neuper@37906
   566
    (Seq{id=id,preconds=pc,rew_ord=ro,erls=er,srls=sr,calc=ca,
neuper@37906
   567
	 (*asm_thm=at,*)rules = gen_rems eq_rule (rs, r),
neuper@37906
   568
	 scr=sc}:rls)
neuper@40836
   569
  | remove_rls id (Rrls _) _ = error
neuper@37906
   570
                   ("remove_rls: not for reverse-rewrite-rule-set "^id);
neuper@37906
   571
neuper@37906
   572
(*!!!> gen_rems (op=) ([1,2,3,4], [3,4,5]);
neuper@37906
   573
val it = [1, 2] : int list*)
neuper@37906
   574
neuper@37906
   575
(*elder version: migrated 3 calls in smtest to memrls
neuper@40836
   576
fun mem_rls id rls =
neuper@37906
   577
    case find_first ((curry op=) id) (map id_rule ((#rules o rep_rls) rls)) of
neuper@37906
   578
	SOME _ => true | NONE => false;*)
neuper@37906
   579
fun memrls r (Rls {rules,...}) = gen_mem eqrule (r, rules)
neuper@37906
   580
  | memrls r (Seq {rules,...}) = gen_mem eqrule (r, rules)
neuper@38031
   581
  | memrls r _ = error ("memrls: incomplete impl. r= "^(rule2str r));
neuper@37906
   582
fun rls_get_thm rls (id: xstring) =
neuper@40836
   583
    case find_first (curry eq_rule e_rule)
neuper@37906
   584
		    ((#rules o rep_rls) rls) of
neuper@37906
   585
	SOME thm => SOME thm | NONE => NONE;
neuper@37906
   586
neuper@38031
   587
fun assoc' ([], key) = error ("ME_Isa: '"^key^"' not known")
neuper@37906
   588
  | assoc' ((keyi, xi) :: pairs, key) =
neuper@37906
   589
      if key = keyi then SOME xi else assoc' (pairs, key);
neuper@37906
   590
neuper@37927
   591
(*100818 fun assoc_thy (thy:theory') = ((the o assoc')(!theory',thy))
neuper@38031
   592
  handle _ => error ("ME_Isa: thy '"^thy^"' not in system");*)
neuper@38056
   593
fun assoc_thy (thy:theory') =
neuper@40836
   594
    if thy = "e_domID" then (Thy_Info.get_theory "Script") (*lower bound of Knowledge*)
neuper@40836
   595
    else (Thy_Info.get_theory thy)
neuper@38056
   596
         handle _ => error ("ME_Isa: thy '" ^ thy ^ "' not in system");
neuper@40836
   597
neuper@42318
   598
(*.associate an rls-identifier with an rls; related to 'fun assoc_rls'; WN111014?fun get_rls ?
neuper@37906
   599
   these are NOT compatible to "fun assoc_thm'" in that they do NOT handle
neuper@37906
   600
   overlays by re-using an identifier in different thys.*)
neuper@37906
   601
fun assoc_rls (rls:rls') = ((#2 o the o assoc')(!ruleset',rls))
neuper@38031
   602
  handle _ => error ("ME_Isa: '"^rls^"' not in system");
neuper@37906
   603
(*fun assoc_rls (rls:rls') = ((the o assoc')(!ruleset',rls))
neuper@38031
   604
  handle _ => error ("ME_Isa: '"^rls^"' not in system");*)
neuper@37906
   605
neuper@37906
   606
(*.overwrite an element in an association list and pair it with a thyID
neuper@37906
   607
   in order to create the thy_hierarchy;
neuper@37906
   608
   overwrites existing rls' even if they are defined in a different thy;
neuper@37906
   609
   this is related to assoc_rls, TODO.WN060120: assoc_rew_ord, assoc_calc;.*)
neuper@40836
   610
(*WN060120 ...these are NOT compatible to "fun assoc_thm'" in that
neuper@37906
   611
   they do NOT handle overlays by re-using an identifier in different thys;
neuper@37906
   612
   "thyID.rlsID" would be a good solution, if the "." would be possible
neuper@37906
   613
   in scripts...
neuper@37906
   614
   actually a hack to get alltogether run again with minimal effort*)
neuper@37906
   615
fun insthy thy' (rls', rls) = (rls', (thy', rls));
neuper@37906
   616
fun overwritelthy thy (al, bl:(rls' * rls) list) =
neuper@37906
   617
    let val bl' = map (insthy ((get_thy o theory2theory') thy)) bl
neuper@37906
   618
    in overwritel (al, bl') end;
neuper@37906
   619
neuper@37906
   620
fun assoc_rew_ord ro = ((the o assoc') (!rew_ord',ro))
neuper@38031
   621
  handle _ => error ("ME_Isa: rew_ord '"^ro^"' not in system");
neuper@37906
   622
(*get the string for stac from rule*)
neuper@38031
   623
fun assoc_calc ([], key) = error ("assoc_calc: '"^ key ^"' not found")
neuper@37906
   624
  | assoc_calc ((calc, (keyi, xi)) :: pairs, key) =
neuper@37906
   625
      if key = keyi then calc else assoc_calc (pairs, key);
neuper@37906
   626
(*only used for !calclist'...*)
neuper@40836
   627
fun assoc1 ([], key) = error ("assoc1 (for met.calc=): '"^ key
neuper@37906
   628
				    ^"' not found")
neuper@37906
   629
  | assoc1 ((all as (keyi, _)) :: pairs, key) =
neuper@37906
   630
      if key = keyi then all else assoc1 (pairs, key);
neuper@37906
   631
neuper@37906
   632
(*TODO.WN080102 clarify usage of type cal and type calc..*)
neuper@40836
   633
fun calID2calcID (calID : calID) =
neuper@38031
   634
    let fun ass [] = error ("calID2calcID: "^calID^"not in calclist'")
neuper@37906
   635
	  | ass ((calci, (cali, eval_fn))::ids) =
neuper@37906
   636
	    if calID = cali then calci
neuper@37906
   637
	    else ass ids
neuper@37906
   638
    in ass (!calclist') : calcID end;
neuper@37906
   639
neuper@38013
   640
fun term2str t = Print_Mode.setmp [] (Syntax.string_of_term
neuper@42430
   641
  (ProofContext.init_global (Thy_Info.get_theory "Isac"))) t;
neuper@38051
   642
neuper@38022
   643
fun terms2str ts = (strs2str o (map term2str )) ts;
neuper@38022
   644
(*terms2str [t1,t2] = "[\"1 + 2\",\"abc\"]";*)
neuper@38022
   645
fun terms2str' ts = (strs2str' o (map term2str )) ts;
neuper@38022
   646
(*terms2str' [t1,t2] = "[1 + 2,abc]";*)
neuper@38022
   647
fun terms2strs ts = (map term2str) ts;
neuper@38022
   648
(*terms2strs [t1,t2] = ["1 + 2", "abc"];*)
neuper@38013
   649
neuper@38053
   650
fun termopt2str (SOME t) = "SOME " ^ term2str t
neuper@38053
   651
  | termopt2str NONE = "NONE";
neuper@38053
   652
neuper@40836
   653
fun type2str typ =
neuper@42376
   654
  Print_Mode.setmp [] (Syntax.string_of_typ (thy2ctxt' "Isac")) typ;
neuper@37906
   655
val string_of_typ = type2str;
neuper@42376
   656
fun string_of_typ_thy thy typ =
neuper@42376
   657
  Print_Mode.setmp [] (Syntax.string_of_typ (thy2ctxt thy)) typ;
neuper@37906
   658
neuper@40836
   659
fun subst2str (s:subst) =
neuper@40836
   660
    (strs2str o
neuper@37906
   661
     (map (linefeed o pair2str o
neuper@40836
   662
	   (apsnd term2str) o
neuper@37906
   663
	   (apfst term2str)))) s;
neuper@40836
   664
fun subst2str' (s:subst) =
neuper@40836
   665
    (strs2str' o
neuper@37906
   666
     (map (pair2str o
neuper@40836
   667
	   (apsnd term2str) o
neuper@37906
   668
	   (apfst term2str)))) s;
neuper@37906
   669
(*> subst2str' [(str2term "bdv", str2term "x"),
neuper@37906
   670
		(str2term "bdv_2", str2term "y")];
neuper@37906
   671
val it = "[(bdv, x)]" : string
neuper@37906
   672
*)
neuper@37906
   673
val env2str = subst2str;
neuper@37906
   674
neuper@37906
   675
neuper@37906
   676
(*recursive defs:*)
neuper@37906
   677
fun scr2str (Script s) = "Script "^(term2str s)
neuper@37906
   678
  | scr2str (Rfuns _)  = "Rfuns";
neuper@37906
   679
neuper@37906
   680
neuper@37906
   681
fun maxthy thy1 thy2 = if Theory.subthy (thy1, thy2) then thy2 else thy1;
neuper@37906
   682
neuper@37906
   683
neuper@37906
   684
(*.trace internal steps of isac's rewriter*)
neuper@38006
   685
val trace_rewrite = Unsynchronized.ref false;
neuper@37906
   686
(*.depth of recursion in traces of the rewriter, if trace_rewrite:=true.*)
neuper@38006
   687
val depth = Unsynchronized.ref 99999;
neuper@37906
   688
(*.no of rewrites exceeding this int -> NO rewrite.*)
neuper@37906
   689
(*WN060829 still unused...*)
neuper@38006
   690
val lim_rewrite = Unsynchronized.ref 99999;
neuper@37906
   691
(*.no of derivation-elements exceeding this int -> SOME derivation-elements.*)
neuper@38006
   692
val lim_deriv = Unsynchronized.ref 100;
neuper@37906
   693
(*.switch for checking guhs unique before storing a pbl or met;
neuper@37906
   694
   set true at startup (done at begin of ROOT.ML)
neuper@37906
   695
   set false for editing IsacKnowledge (done at end of ROOT.ML).*)
neuper@41905
   696
val check_guhs_unique = Unsynchronized.ref true;
neuper@37906
   697
neuper@37906
   698
neuper@37906
   699
datatype lrd = (*elements of a path (=loc_) into an Isabelle term*)
neuper@40836
   700
	 L     (*go left at $*)
neuper@37906
   701
       | R     (*go right at $*)
neuper@37906
   702
       | D;     (*go down at Abs*)
neuper@37906
   703
type loc_ = lrd list;
neuper@37906
   704
fun ldr2str L = "L"
neuper@37906
   705
  | ldr2str R = "R"
neuper@37906
   706
  | ldr2str D = "D";
neuper@37906
   707
fun loc_2str (k:loc_) = (strs2str' o (map ldr2str)) k;
neuper@37906
   708
neuper@38061
   709
(*
neuper@38061
   710
end (*struct*)
neuper@38061
   711
*)