src/sml/ME/script.sml
author wneuper
Fri, 02 Sep 2005 09:55:13 +0200
branchstart_Take
changeset 363 6775fe2103e4
parent 362 7480fabbd309
child 364 91959e402f51
permissions -rw-r--r--
Biegelinie#Script intermediate,
made typecheck in match_ags depending on Isac.thy
wneuper@340
     1
(* interpreter for scripts
wneuper@340
     2
   (c) Walther Neuper 2000
wneuper@340
     3
wneuper@340
     4
use"~/proto2/isac/src/sml/ME/script.sml";
wneuper@340
     5
*)
wneuper@339
     6
wneuper@339
     7
signature INTERPRETER =
wneuper@339
     8
sig
wneuper@339
     9
  (*type ets (list of executed tactics) see sequent.sml*)
wneuper@339
    10
wneuper@339
    11
  datatype locate
wneuper@339
    12
    = NotLocatable
wneuper@339
    13
    | Steps of (tac_ * mout * ptree * pos' * cid * safe (* ets*)) list
wneuper@339
    14
(*    | ToDo of ets 28.4.02*)
wneuper@339
    15
wneuper@339
    16
  (*diss: next-tactic-function*)
wneuper@339
    17
  val next_tac : theory' -> ptree * pos' -> metID -> scr -> ets -> tac_
wneuper@339
    18
  (*diss: locate-function*)
wneuper@339
    19
  val locate_gen : theory'
wneuper@339
    20
                   -> tac_
wneuper@339
    21
                      -> ptree * pos' -> scr * rls -> ets -> loc_ -> locate
wneuper@339
    22
wneuper@339
    23
  val sel_rules : ptree -> pos' -> tac list
wneuper@339
    24
  val init_form : scr -> ets -> loc_ * term option (*FIXME not up to date*)
wneuper@339
    25
  val formal_args : term -> term list
wneuper@339
    26
wneuper@339
    27
  (*shift to library ...*)
wneuper@339
    28
  val inst_abs : theory' -> term -> term
wneuper@339
    29
  val itms2args : metID -> itm list -> term list
wneuper@339
    30
  val user_interrupt : loc_ * (tac_ * env * env * term * term * safe)
wneuper@339
    31
  (*val empty : term*) 
wneuper@339
    32
end 
wneuper@339
    33
wneuper@339
    34
wneuper@339
    35
wneuper@339
    36
wneuper@339
    37
(*
wneuper@339
    38
structure Interpreter : INTERPRETER =
wneuper@339
    39
struct
wneuper@339
    40
*)
wneuper@339
    41
wneuper@339
    42
val string_of_thm' = (implode o tl o drop_last o explode o string_of_thm);
wneuper@339
    43
(*
wneuper@339
    44
  string_of_thm sym;
wneuper@339
    45
val it = "\"?s = ?t ==> ?t = ?s\"" : string
wneuper@339
    46
  string_of_thm' sym;
wneuper@339
    47
val it = "?s = ?t ==> ?t = ?s" : string*)
wneuper@339
    48
wneuper@339
    49
type step =     (*data for creating a new node in the ptree;
wneuper@339
    50
		 designed for use:
wneuper@339
    51
               	 fun ass* scrstate steps =
wneuper@339
    52
               	 ... case ass* scrstate steps of
wneuper@339
    53
               	     Assoc (scrstate, steps) => ... ass* scrstate steps*)
wneuper@339
    54
    tac_       (*transformed from associated tac*)
wneuper@339
    55
    * mout       (*result with indentation etc.*)
wneuper@339
    56
    * ptree      (*containing node created by tac_ + resp. scrstate*)
wneuper@339
    57
    * pos'       (*position in ptree; ptree * pos' is the proofstate*)
wneuper@339
    58
    * pos' list; (*of ptree-nodes probably cut (by fst tac_)*)
wneuper@339
    59
val e_step = (Empty_Tac_, EmptyMout, EmptyPtree, e_pos',[]:pos' list):step;
wneuper@339
    60
wneuper@339
    61
fun rule2thm' (Thm (id, thm)) = (id, string_of_thm thm):thm'
wneuper@339
    62
  | rule2thm' r = raise error ("rule2thm': not defined for "^(rule2str r));
wneuper@339
    63
wneuper@339
    64
(*.makes a (rule,term) list to a Step (m, mout, pt', p', cid) for solve;
wneuper@339
    65
   complicated with current t in rrlsstate.*)
wneuper@339
    66
fun rts2steps steps ((pt,p),(f,f'',rss,rts),(thy',ro,er,pa)) [(r, (f', am))] =
wneuper@339
    67
    let val thy = assoc_thy thy'
wneuper@339
    68
	val m = Rewrite' (thy',ro,er,pa, rule2thm' r, f, (f', am))
wneuper@339
    69
	val is = RrlsState (f',f'',rss,rts)
wneuper@339
    70
	val p = case p of (p',Frm) => p | (p',Res) => (lev_on p',Res)
wneuper@339
    71
	val (p', cid, mout, pt') = generate1 thy m is p pt
wneuper@339
    72
    in (is, (m, mout, pt', p', cid)::steps) end
wneuper@339
    73
  | rts2steps steps ((pt,p),(f,f'',rss,rts),(thy',ro,er,pa)) 
wneuper@339
    74
	      ((r, (f', am))::rts') =
wneuper@339
    75
    let val thy = assoc_thy thy'
wneuper@339
    76
	val m = Rewrite' (thy',ro,er,pa, rule2thm' r, f, (f', am))
wneuper@339
    77
	val is = RrlsState (f',f'',rss,rts)
wneuper@339
    78
	val p = case p of (p',Frm) => p | (p',Res) => (lev_on p',Res)
wneuper@339
    79
	val (p', cid, mout, pt') = generate1 thy m is p pt
wneuper@339
    80
    in rts2steps ((m, mout, pt', p', cid)::steps) 
wneuper@339
    81
		 ((pt',p'),(f',f'',rss,rts),(thy',ro,er,pa)) rts' end;
wneuper@339
    82
wneuper@339
    83
wneuper@339
    84
val trace_locate = ref false; (*23.11.01*)
wneuper@339
    85
wneuper@339
    86
(*. functions for the environment stack .*)
wneuper@339
    87
fun accessenv id es = the (assoc((top es):env, id))
wneuper@339
    88
    handle _ => error ("accessenv: "^(free2str id)^" not in env");
wneuper@339
    89
fun updateenv id vl (es:env stack) = 
wneuper@339
    90
    (push (overwrite(top es, (id, vl))) (pop es)):env stack;
wneuper@339
    91
fun pushenv id vl (es:env stack) = 
wneuper@339
    92
    (push (overwrite(top es, (id, vl))) es):env stack;
wneuper@339
    93
val popenv = pop:env stack -> env stack;
wneuper@339
    94
wneuper@339
    95
wneuper@339
    96
wneuper@339
    97
fun de_esc_underscore str =
wneuper@339
    98
  let fun scan [] = []
wneuper@339
    99
	| scan (s::ss) = if s = "'" then (scan ss)
wneuper@339
   100
			 else (s::(scan ss))
wneuper@339
   101
  in (implode o scan o explode) str end;
wneuper@339
   102
(*
wneuper@339
   103
> val str = "Rewrite_Set_Inst";
wneuper@339
   104
> val esc = esc_underscore str;
wneuper@339
   105
val it = "Rewrite'_Set'_Inst" : string
wneuper@339
   106
> val des = de_esc_underscore esc;
wneuper@339
   107
 val des = de_esc_underscore esc;*)
wneuper@339
   108
wneuper@339
   109
wneuper@339
   110
(*WN.12.5.03 not used any more,
wneuper@339
   111
  tacs are more stable than listepxr: subst_tacexpr
wneuper@339
   112
fun is_listexpr t = 
wneuper@339
   113
  (((ids_of o head_of) t) inter (!listexpr)) <> [];
wneuper@339
   114
----*)
wneuper@339
   115
wneuper@339
   116
(*go at a location in a script and fetch the contents*)
wneuper@339
   117
fun go [] t = t
wneuper@339
   118
  | go (D::p) (Abs(s,ty,t0)) = go (p:loc_) t0
wneuper@339
   119
  | go (L::p) (t1 $ t2) = go p t1
wneuper@339
   120
  | go (R::p) (t1 $ t2) = go p t2
wneuper@339
   121
  | go l _ = raise error ("go: no "^(loc_2str l));
wneuper@339
   122
(*
wneuper@339
   123
> val t = (term_of o the o (parse thy)) "a+b";
wneuper@339
   124
val it = Const (#,#) $ Free (#,#) $ Free ("b","RealDef.real") : term
wneuper@339
   125
> val plus_a = go [L] t; 
wneuper@339
   126
> val b = go [R] t; 
wneuper@339
   127
> val plus = go [L,L] t; 
wneuper@339
   128
> val a = go [L,R] t;
wneuper@339
   129
wneuper@339
   130
> val t = (term_of o the o (parse thy)) "a+b+c";
wneuper@339
   131
val t = Const (#,#) $ (# $ # $ Free #) $ Free ("c","RealDef.real") : term
wneuper@339
   132
> val pl_pl_a_b = go [L] t; 
wneuper@339
   133
> val c = go [R] t; 
wneuper@339
   134
> val a = go [L,R,L,R] t; 
wneuper@339
   135
> val b = go [L,R,R] t; 
wneuper@339
   136
*)
wneuper@339
   137
wneuper@339
   138
wneuper@339
   139
(* get a subterm t with test t, and record location *)
wneuper@339
   140
fun get l test (t as Const (s,T)) = 
wneuper@339
   141
    if test t then Some (l,t) else None
wneuper@339
   142
  | get l test (t as Free (s,T)) = 
wneuper@339
   143
    if test t then Some (l,t) else None 
wneuper@339
   144
  | get l test (t as Bound n) =
wneuper@339
   145
    if test t then Some (l,t) else None 
wneuper@339
   146
  | get l test (t as Var (s,T)) =
wneuper@339
   147
    if test t then Some (l,t) else None
wneuper@339
   148
  | get l test (t as Abs (s,T,body)) =
wneuper@339
   149
    if test t then Some (l:loc_,t) else get ((l@[D]):loc_) test body
wneuper@339
   150
  | get l test (t as t1 $ t2) =
wneuper@339
   151
    if test t then Some (l,t) 
wneuper@339
   152
    else case get (l@[L]) test t1 of 
wneuper@339
   153
      None => get (l@[R]) test t2
wneuper@339
   154
    | Some (l',t') => Some (l',t');
wneuper@339
   155
(*18.6.00
wneuper@339
   156
> val sss = ((term_of o the o (parse thy))
wneuper@339
   157
  "Script Solve_root_equation (eq_::bool) (v_::real) (err_::bool) =\
wneuper@339
   158
   \ (let e_ = Try (Rewrite square_equation_left True eq_) \
wneuper@339
   159
   \  in [e_])");
wneuper@339
   160
          ______ compares head_of !!
wneuper@339
   161
> get [] (eq_str "Let") sss;            [R]
wneuper@339
   162
> get [] (eq_str "Script.Try") sss;     [R,L,R]
wneuper@339
   163
> get [] (eq_str "Script.Rewrite") sss; [R,L,R,R]
wneuper@339
   164
> get [] (eq_str "True") sss;           [R,L,R,R,L,R]
wneuper@339
   165
> get [] (eq_str "e_") sss;             [R,R]
wneuper@339
   166
*)
wneuper@339
   167
wneuper@339
   168
fun test_negotiable t = ((strip_thy o (term_str Script.thy) o head_of) t) 
wneuper@339
   169
  mem (!negotiable);
wneuper@339
   170
wneuper@339
   171
(*30.4.02: vvv--- doesnt work with curried functions ---> get_tac ------
wneuper@339
   172
(*18.6.00: below _ALL_ negotiables must be in fun-patterns !
wneuper@339
   173
  then the last (non)pattern must be a subproblem*)
wneuper@339
   174
fun init_frm thy (Const ("Script.Rewrite",_) $ _ $ _ $ eq) = Some eq
wneuper@339
   175
  | init_frm thy (Const ("Script.Rewrite'_Inst",_) $ _ $ _ $ _ $ eq) = Some eq
wneuper@339
   176
  | init_frm thy (Const ("Script.Rewrite'_Set",_) $ _ $ _ $ eq) = Some eq
wneuper@339
   177
  | init_frm thy (Const ("Script.Rewrite'_Set'_Inst",_) $ _ $ _ $ _ $ eq) = 
wneuper@339
   178
    Some eq
wneuper@339
   179
  | init_frm thy (Const ("Script.Calculate",_) $ _ $ t) = Some t
wneuper@339
   180
  | init_frm thy t = 
wneuper@339
   181
  (*if ((strip_thy o (term_str thy) o head_of) t) mem (!subpbls)
wneuper@339
   182
    then None 
wneuper@339
   183
  else *)raise error ("init_frm: not impl. for "^
wneuper@339
   184
		    (Sign.string_of_term (sign_of thy) t));
wneuper@339
   185
wneuper@339
   186
> val t = (term_of o the o (parse thy)) 
wneuper@339
   187
 "Rewrite square_equation_left True (sqrt(#9+#4*x)=sqrt x + sqrt(#5+x))";
wneuper@339
   188
> val Some ini = init_frm thy t;
wneuper@339
   189
> Sign.string_of_term (sign_of thy) ini;
wneuper@339
   190
val it = "sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x)" : string
wneuper@339
   191
wneuper@339
   192
> val t = (term_of o the o (parse thy)) 
wneuper@339
   193
 "solve_univar (Reals, [univar,equation], no_met) e1_ v1_";
wneuper@339
   194
> val ini = init_frm thy t;
wneuper@339
   195
> Sign.string_of_term (sign_of thy) ini;
wneuper@339
   196
val it = "empty" : string
wneuper@339
   197
wneuper@339
   198
> val t = (term_of o the o (parse thy)) 
wneuper@339
   199
 "Rewrite_Set norm_equation False x + #1 = #2";
wneuper@339
   200
> val Some ini = init_frm thy t;
wneuper@339
   201
> Sign.string_of_term (sign_of thy) ini;
wneuper@339
   202
val it = "x + #1 = #2" : string                                                
wneuper@339
   203
wneuper@339
   204
> val t = (term_of o the o (parse thy)) 
wneuper@339
   205
 "Rewrite_Set_Inst [(bdv,x)] isolate_bdv False x + #1 = #2";
wneuper@339
   206
> val Some ini = init_frm thy t;
wneuper@339
   207
> Sign.string_of_term (sign_of thy) ini;
wneuper@339
   208
val it = "x + #1 = #2" : string                           *)
wneuper@339
   209
wneuper@339
   210
wneuper@339
   211
(*.get argument of first stactic in a script for init_form.*)
wneuper@339
   212
fun get_stac thy (h $ body) =
wneuper@339
   213
(* 
wneuper@339
   214
   *)
wneuper@339
   215
  let
wneuper@339
   216
    fun get_t y (Const ("Script.Seq",_) $ e1 $ e2) a = 
wneuper@339
   217
    	(case get_t y e1 a of None => get_t y e2 a | la => la)
wneuper@339
   218
      | get_t y (Const ("Script.Seq",_) $ e1 $ e2 $ a) _ = 
wneuper@339
   219
    	(case get_t y e1 a of None => get_t y e2 a | la => la)
wneuper@339
   220
      | get_t y (Const ("Script.Try",_) $ e) a = get_t y e a
wneuper@339
   221
      | get_t y (Const ("Script.Try",_) $ e $ a) _ = get_t y e a
wneuper@339
   222
      | get_t y (Const ("Script.Repeat",_) $ e) a = get_t y e a
wneuper@339
   223
      | get_t y (Const ("Script.Repeat",_) $ e $ a) _ = get_t y e a
wneuper@339
   224
      | get_t y (Const ("Script.Or",_) $e1 $ e2) a =
wneuper@339
   225
    	(case get_t y e1 a of None => get_t y e2 a | la => la)
wneuper@339
   226
      | get_t y (Const ("Script.Or",_) $e1 $ e2 $ a) _ =
wneuper@339
   227
    	(case get_t y e1 a of None => get_t y e2 a | la => la)
wneuper@339
   228
      | get_t y (Const ("Script.While",_) $ c $ e) a = get_t y e a
wneuper@339
   229
      | get_t y (Const ("Script.While",_) $ c $ e $ a) _ = get_t y e a
wneuper@339
   230
      | get_t y (Const ("Script.Letpar",_) $ e1 $ Abs (_,_,e2)) a = 
wneuper@339
   231
    	(case get_t y e1 a of None => get_t y e2 a | la => la)
wneuper@339
   232
    (*| get_t y (Const ("Let",_) $ e1 $ Abs (_,_,e2)) a =
wneuper@339
   233
    	(writeln("get_t: Let e1= "^(term2str e1)^", e2= "^(term2str e2));
wneuper@339
   234
	 case get_t y e1 a of None => get_t y e2 a | la => la)
wneuper@339
   235
      | get_t y (Abs (_,_,e)) a = get_t y e a*)
wneuper@339
   236
      | get_t y (Const ("Let",_) $ e1 $ Abs (_,_,e2)) a =
wneuper@339
   237
    	get_t y e1 a (*don't go deeper without evaluation !*)
wneuper@339
   238
      | get_t y (Const ("If",_) $ c $ e1 $ e2) a = None
wneuper@339
   239
    	(*(case get_t y e1 a of None => get_t y e2 a | la => la)*)
wneuper@339
   240
    
wneuper@339
   241
      | get_t y (Const ("Script.Rewrite",_) $ _ $ _ $ a) _ = Some a
wneuper@339
   242
      | get_t y (Const ("Script.Rewrite",_) $ _ $ _    ) a = Some a
wneuper@339
   243
      | get_t y (Const ("Script.Rewrite'_Inst",_) $ _ $ _ $ _ $ a) _ = Some a
wneuper@339
   244
      | get_t y (Const ("Script.Rewrite'_Inst",_) $ _ $ _ $ _ )    a = Some a
wneuper@339
   245
      | get_t y (Const ("Script.Rewrite'_Set",_) $ _ $ _ $ a) _ = Some a
wneuper@339
   246
      | get_t y (Const ("Script.Rewrite'_Set",_) $ _ $ _ )    a = Some a
wneuper@339
   247
      | get_t y (Const ("Script.Rewrite'_Set'_Inst",_) $ _ $ _ $ _ $a)_ =Some a
wneuper@339
   248
      | get_t y (Const ("Script.Rewrite'_Set'_Inst",_) $ _ $ _ $ _ )  a =Some a
wneuper@339
   249
      | get_t y (Const ("Script.Calculate",_) $ _ $ a) _ = Some a
wneuper@339
   250
      | get_t y (Const ("Script.Calculate",_) $ _ )    a = Some a
wneuper@339
   251
    
wneuper@339
   252
      | get_t y (Const ("Script.Substitute",_) $ _ $ a) _ = Some a
wneuper@339
   253
      | get_t y (Const ("Script.Substitute",_) $ _ )    a = Some a
wneuper@339
   254
    
wneuper@339
   255
      | get_t y (Const ("Script.SubProblem",_) $ _ $ _) _ = None
wneuper@339
   256
wneuper@339
   257
      | get_t y x _ =  
wneuper@339
   258
	((*writeln ("### get_t yac: list-expr "^(term2str x));*)
wneuper@339
   259
	 None)
wneuper@339
   260
in get_t thy body e_term end;
wneuper@339
   261
    
wneuper@339
   262
(*FIXME: get 1st stac by next_stac [] instead of ... ?? 29.7.02*)
wneuper@339
   263
(* val Script sc = scr;
wneuper@339
   264
   *)
wneuper@339
   265
fun init_form thy (Script sc) env =
wneuper@339
   266
  (case get_stac thy sc of
wneuper@339
   267
     None => None (*raise error ("init_form: no 1st stac in "^
wneuper@339
   268
			  (Sign.string_of_term (sign_of thy) sc))*)
wneuper@339
   269
   | Some stac => Some (subst_atomic env stac))
wneuper@339
   270
  | init_form _ _ _ = raise error "init_form: no match";
wneuper@339
   271
wneuper@339
   272
(* use"ME/script.sml";
wneuper@339
   273
   use"script.sml";
wneuper@339
   274
   *)
wneuper@339
   275
wneuper@339
   276
wneuper@339
   277
wneuper@339
   278
(*the 'iteration-argument' of a stac (args not eval)*)
wneuper@339
   279
fun itr_arg _ (Const ("Script.Rewrite'_Inst",_) $ _ $ _ $ _ $ v) = v
wneuper@339
   280
  | itr_arg _ (Const ("Script.Rewrite",_) $ _ $ _ $ v) = v
wneuper@339
   281
  | itr_arg _ (Const ("Script.Rewrite'_Set'_Inst",_) $ _ $ _ $ _ $ v) = v
wneuper@339
   282
  | itr_arg _ (Const ("Script.Rewrite'_Set",_) $ _ $ _ $ v) = v
wneuper@339
   283
  | itr_arg _ (Const ("Script.Calculate",_) $ _ $ v) = v
wneuper@339
   284
  | itr_arg _ (Const ("Script.Check'_elementwise",_) $ consts $ _) = consts
wneuper@339
   285
  | itr_arg _ (Const ("Script.Or'_to'_List",_) $ _) = e_term
wneuper@339
   286
  | itr_arg _ (Const ("Script.Tac",_) $ _) = e_term
wneuper@339
   287
  | itr_arg _ (Const ("Script.SubProblem",_) $ _ $ _) = e_term
wneuper@339
   288
  | itr_arg thy t = raise error 
wneuper@339
   289
    ("itr_arg not impl. for "^
wneuper@339
   290
     (Sign.string_of_term (sign_of (assoc_thy thy)) t));
wneuper@339
   291
(* val t = (term_of o the o (parse thy))"Rewrite rroot_square_inv False e_";
wneuper@339
   292
> itr_arg "Script.thy" t;
wneuper@339
   293
val it = Free ("e_","RealDef.real") : term 
wneuper@339
   294
> val t = (term_of o the o (parse thy))"xxx";
wneuper@339
   295
> itr_arg "Script.thy" t;
wneuper@339
   296
*** itr_arg not impl. for xxx
wneuper@339
   297
uncaught exception ERROR
wneuper@339
   298
  raised at: library.ML:1114.35-1114.40*)
wneuper@339
   299
wneuper@339
   300
wneuper@362
   301
(*.get the arguments of the script out of the scripts parsetree.*)
wneuper@339
   302
fun formal_args scr = (fst o split_last o snd o strip_comb) scr;
wneuper@339
   303
(*
wneuper@361
   304
> formal_args scr;
wneuper@339
   305
  [Free ("f_","RealDef.real"),Free ("v_","RealDef.real"),
wneuper@339
   306
   Free ("eqs_","bool List.list")] : term list
wneuper@339
   307
*)
wneuper@339
   308
wneuper@362
   309
(*.get the identifier of the script out of the scripts parsetree.*)
wneuper@362
   310
fun id_of_scr sc = (id_of o fst o strip_comb) sc;
wneuper@362
   311
wneuper@339
   312
wneuper@339
   313
(*26.5.02: not clear, when a is available in ass_up for eva-_true*)
wneuper@339
   314
fun upd_env_opt env (Some a, v) = upd_env env (a,v)
wneuper@339
   315
  | upd_env_opt env (None, v) = 
wneuper@339
   316
    (writeln("*** upd_env_opt: (None,"^(term2str v)^")");env);
wneuper@339
   317
wneuper@339
   318
wneuper@339
   319
type dsc = typ; (*<-> nam..unknow in Descript.thy*)
wneuper@339
   320
fun typ_str (Type (s,_)) = s
wneuper@339
   321
  | typ_str (TFree(s,_)) = s
wneuper@339
   322
  | typ_str (TVar ((s,i),_)) = s^(string_of_int i);
wneuper@339
   323
	     
wneuper@339
   324
(*get the _result_-type of a description*)
wneuper@339
   325
fun dsc_valT (Const (_,(Type (_,[_,T])))) = (strip_thy o typ_str) T;
wneuper@339
   326
(*> val t = (term_of o the o (parse thy)) "equality";
wneuper@339
   327
> val T = type_of t;
wneuper@339
   328
val T = "bool => Tools.una" : typ
wneuper@339
   329
> val dsc = dsc_valT t;
wneuper@339
   330
val dsc = "una" : string
wneuper@339
   331
wneuper@339
   332
> val t = (term_of o the o (parse thy)) "fixedValues";
wneuper@339
   333
> val T = type_of t;
wneuper@339
   334
val T = "bool List.list => Tools.nam" : typ
wneuper@339
   335
> val dsc = dsc_valT t;
wneuper@339
   336
val dsc = "nam" : string*)
wneuper@339
   337
wneuper@339
   338
(*.from penv in itm_ make args for script depending on type of description.*)
wneuper@339
   339
(*6.5.03 TODO: push penv into script -- and drop mk_arg here || drop penv
wneuper@339
   340
  9.5.03 penv postponed: penv = env for script at the moment, (*mk_arg*)*)
wneuper@339
   341
fun mk_arg thy d [] = raise error ("mk_arg: no data for "^
wneuper@339
   342
			       (Sign.string_of_term (sign_of thy) d))
wneuper@339
   343
  | mk_arg thy d [t] = 
wneuper@339
   344
    (case dsc_valT d of
wneuper@339
   345
	 "una" => [t]
wneuper@339
   346
       | "nam" => 
wneuper@339
   347
	 [case t of
wneuper@339
   348
	      r as (Const ("op =",_) $ _ $ _) => r
wneuper@339
   349
	    | _ => raise error 
wneuper@339
   350
			     ("mk_arg: dsc-typ 'nam' applied to non-equality "^
wneuper@339
   351
			      (Sign.string_of_term (sign_of thy) t))]
wneuper@339
   352
       | s => raise error ("mk_arg: not impl. for "^s))
wneuper@339
   353
    
wneuper@339
   354
  | mk_arg thy d (t::ts) = (mk_arg thy d [t]) @ (mk_arg thy d ts);
wneuper@339
   355
(* 
wneuper@339
   356
 val d = d_in itm_;
wneuper@339
   357
 val [t] = ts_in itm_;
wneuper@339
   358
mk_arg thy
wneuper@339
   359
*)
wneuper@339
   360
wneuper@339
   361
wneuper@339
   362
wneuper@339
   363
wneuper@339
   364
(*.create the actual parameters (args) of script: their order 
wneuper@359
   365
  is given by the order in met.pat .*)
wneuper@339
   366
(*WN.5.5.03: ?: does this allow for different descriptions ???
wneuper@339
   367
             ?: why not taken from formal args of script ???
wneuper@339
   368
!: FIXXXME penv: push it here in itms2args into script-evaluation*)
wneuper@359
   369
(* val (thy, mI, itms) = (thy, metID, itms);
wneuper@339
   370
   *)
wneuper@339
   371
fun itms2args thy mI (itms:itm list) =
wneuper@359
   372
    let val mvat = max_vt itms
wneuper@359
   373
	fun okv mvat (_,vats,b,_,_) = mvat mem vats andalso b
wneuper@359
   374
	val itms = filter (okv mvat) itms
wneuper@359
   375
	fun test_dsc d (_,_,_,_,itm_) = (d = d_in itm_)
wneuper@359
   376
	fun itm2arg itms (_,(d,_)) =
wneuper@359
   377
	    case find_first (test_dsc d) itms of
wneuper@359
   378
		None => 
wneuper@359
   379
		raise error ("itms2args: '"^term2str d^"' not in itms")
wneuper@359
   380
	      (*| Some (_,_,_,_,itm_) => mk_arg thy (d_in itm_) (ts_in itm_);
wneuper@359
   381
               penv postponed; presently penv holds already env for script*)
wneuper@359
   382
	      | Some (_,_,_,_,itm_) => penvval_in itm_
wneuper@359
   383
	fun sel_given_find (s,_) = (s = "#Given") orelse (s = "#Find")
wneuper@359
   384
	val pats = (#ppc o get_met) mI
wneuper@359
   385
    in (flat o (map (itm2arg itms))) pats end;
wneuper@339
   386
(*
wneuper@339
   387
> val sc = ... Solve_root_equation ...
wneuper@339
   388
> val mI = ("Script.thy","sqrt-equ-test");
wneuper@339
   389
> val PblObj{meth={ppc=itms,...},...} = get_obj I pt [];
wneuper@339
   390
> val ts = itms2args thy mI itms;
wneuper@339
   391
> map (Sign.string_of_term (sign_of thy)) ts;
wneuper@339
   392
["sqrt (#9 + #4 * x) = sqrt x + sqrt (#5 + x)","x","#0"] : string list
wneuper@339
   393
*)
wneuper@339
   394
wneuper@359
   395
wneuper@339
   396
(*["bool_ (1+x=2)","real_ x"] --match_ags--> oris 
wneuper@363
   397
  --oris2fmz_vals--> ["equality (1+x=2)","boundVariable x","solutions L"]*)
wneuper@339
   398
fun oris2fmz_vals oris =
wneuper@339
   399
    let fun ori2fmz_vals ((_,_,_,dsc,ts):ori) = 
wneuper@339
   400
	    ((term2str o comp_dts') (dsc, ts), last_elem ts) 
wneuper@339
   401
	    handle _ => raise error ("ori2fmz_env called with "^terms2str ts)
wneuper@339
   402
    in (split_list o (map ori2fmz_vals)) oris end;
wneuper@339
   403
wneuper@339
   404
(*detour necessary, because generate1 delivers a string-result*)
wneuper@339
   405
fun mout2term thy (Form' (FormKF (_,_,_,_,res))) = 
wneuper@339
   406
  (term_of o the o (parse (assoc_thy thy))) res
wneuper@339
   407
  | mout2term thy (Form' (PpcKF _)) = e_term;(*3.8.01: res of subpbl 
wneuper@339
   408
					   at time of detection in script*)
wneuper@339
   409
wneuper@339
   410
(*.convert a script-tac to a tac (and SubProblem to tac_, too).*)
wneuper@339
   411
fun stac2tac_ thy (Const ("Script.Rewrite",_) $ Free (thmID,_) $ _ $ f) =
wneuper@339
   412
    let val tid = (de_esc_underscore o strip_thy) thmID
wneuper@339
   413
    in (Rewrite (tid, (de_quote o string_of_thm o 
wneuper@339
   414
		       (assoc_thm' thy)) (tid,"")), Empty_Tac_) end
wneuper@339
   415
(* val (thy,
wneuper@339
   416
	mm as(Const ("Script.Rewrite'_Inst",_) $  sub $ Free(thmID,_) $ _ $ f))
wneuper@339
   417
     = (assoc_thy th,stac);
wneuper@339
   418
   stac2tac_ thy mm;
wneuper@339
   419
wneuper@339
   420
   assoc_thm' (assoc_thy "Isac.thy") (tid,"");
wneuper@339
   421
   assoc_thm' Isac.thy (tid,"");
wneuper@339
   422
   *)
wneuper@339
   423
  | stac2tac_ thy (Const ("Script.Rewrite'_Inst",_) $ 
wneuper@339
   424
	       sub $ Free (thmID,_) $ _ $ f) =
wneuper@339
   425
  let val subML = ((map isapair2pair) o isalist2list) sub
wneuper@339
   426
    val subStr = subst2subs subML
wneuper@339
   427
    val tid = (de_esc_underscore o strip_thy) thmID (*4.10.02 unnoetig*)
wneuper@339
   428
  in (Rewrite_Inst 
wneuper@339
   429
	  (subStr, (tid, (de_quote o string_of_thm o
wneuper@339
   430
			  (assoc_thm' thy)) (tid,""))), Empty_Tac_) end
wneuper@339
   431
      
wneuper@339
   432
  | stac2tac_ thy (Const ("Script.Rewrite'_Set",_) $ Free (rls,_) $ _ $ f)=
wneuper@339
   433
  (Rewrite_Set ((de_esc_underscore o strip_thy) rls), Empty_Tac_)
wneuper@339
   434
wneuper@339
   435
  | stac2tac_ thy (Const ("Script.Rewrite'_Set'_Inst",_) $ 
wneuper@339
   436
	       sub $ Free (rls,_) $ _ $ f) =
wneuper@339
   437
  let val subML = ((map isapair2pair) o isalist2list) sub;
wneuper@339
   438
    val subStr = subst2subs subML;
wneuper@339
   439
  in (Rewrite_Set_Inst (subStr,rls), Empty_Tac_) end
wneuper@339
   440
wneuper@339
   441
  | stac2tac_ thy (Const ("Script.Calculate",_) $ Free (op_,_) $ f) =
wneuper@339
   442
  (Calculate op_, Empty_Tac_)
wneuper@339
   443
wneuper@340
   444
  | stac2tac_ thy (Const ("Script.Take",_) $ t) =
wneuper@340
   445
  (Take (term2str t), Empty_Tac_)
wneuper@340
   446
wneuper@340
   447
  | stac2tac_ thy (Const ("Script.Substitute",_) $ isasub) =
wneuper@340
   448
  (Substitute ((subst2subs o isasub2subst) isasub), Empty_Tac_)
wneuper@340
   449
wneuper@339
   450
(*12.1.01.*)
wneuper@339
   451
  | stac2tac_ thy (Const("Script.Check'_elementwise",_) $ _ $ 
wneuper@339
   452
		    (set as Const ("Collect",_) $ Abs (_,_,pred))) = 
wneuper@339
   453
  (Check_elementwise (Sign.string_of_term (sign_of thy) pred), 
wneuper@339
   454
   (*set*)Empty_Tac_)
wneuper@339
   455
wneuper@339
   456
  | stac2tac_ thy (Const("Script.Or'_to'_List",_) $ _ ) = 
wneuper@339
   457
  (Or_to_List, Empty_Tac_)
wneuper@339
   458
wneuper@339
   459
(*12.1.01.for subproblem_equation_dummy in root-equation *)
wneuper@339
   460
  | stac2tac_ thy (Const ("Script.Tac",_) $ Free (str,_)) = 
wneuper@339
   461
  (Tac ((de_esc_underscore o strip_thy) str),  Empty_Tac_) 
wneuper@339
   462
		    (*L_ will come from pt in appl_in*)
wneuper@339
   463
wneuper@339
   464
  (*3.12.03 copied from assod SubProblem*)
wneuper@339
   465
(* val Const ("Script.SubProblem",_) $
wneuper@339
   466
			 (Const ("Pair",_) $
wneuper@339
   467
				Free (dI',_) $ 
wneuper@339
   468
				(Const ("Pair",_) $ pI' $ mI')) $ ags' =
wneuper@339
   469
    str2term 
wneuper@339
   470
    "SubProblem (Test_,[linear,univariate,equation,test],[Test,solve_linear])\
wneuper@339
   471
    \ [bool_ (-1+x=0), real_ x]";
wneuper@339
   472
*)
wneuper@339
   473
  | stac2tac_ thy (Const ("Script.SubProblem",_) $
wneuper@339
   474
			 (Const ("Pair",_) $
wneuper@339
   475
				Free (dI',_) $ 
wneuper@339
   476
				(Const ("Pair",_) $ pI' $ mI')) $ ags') =
wneuper@339
   477
(*compare "| assod _ (Subproblem'"*)
wneuper@339
   478
    let val dI = ((implode o drop_last o explode) dI')^".thy";
wneuper@339
   479
	val pI = ((map (de_esc_underscore o free2str)) o isalist2list) pI';
wneuper@339
   480
	val mI = ((map (de_esc_underscore o free2str)) o isalist2list) mI';
wneuper@339
   481
	val ags = isalist2list ags';
wneuper@339
   482
	val thy = assoc_thy dI;
wneuper@339
   483
	val (pI, pors, mI) = 
wneuper@339
   484
	    if mI = ["no_met"] 
wneuper@339
   485
	    then let val pors = match_ags thy ((#ppc o get_pbt) pI) ags;
wneuper@339
   486
		     val pI' = refine_ori' pors pI;
wneuper@339
   487
		 in (pI', pors (*refinement over models with diff.prec only*), 
wneuper@339
   488
		     (hd o #met o get_pbt) pI') end
wneuper@339
   489
	    else (pI, match_ags thy ((#ppc o get_pbt) pI) ags, mI);
wneuper@339
   490
        val (fmz_, vals) = oris2fmz_vals pors;
wneuper@339
   491
	val {cas,ppc,thy,...} = get_pbt pI
wneuper@339
   492
	val dI = theory2theory' thy (*take dI from _refined_ pbl*)
wneuper@339
   493
	val hdl = case cas of
wneuper@339
   494
		      None => pblterm dI pI
wneuper@339
   495
		    | Some t => subst_atomic ((vars_of_pbl_' ppc) ~~~ vals) t
wneuper@339
   496
        val f = subpbl (strip_thy dI) pI
wneuper@339
   497
    in (Subproblem (dI, pI),
wneuper@339
   498
	Subproblem' ((dI, pI, mI), pors, hdl, fmz_, f))
wneuper@339
   499
    end
wneuper@339
   500
wneuper@339
   501
  | stac2tac_ thy t = raise error 
wneuper@339
   502
  ("stac2tac_ TODO: no match for "^
wneuper@339
   503
   (Sign.string_of_term (sign_of thy) t));
wneuper@339
   504
(*
wneuper@339
   505
> val t = (term_of o the o (parse thy)) 
wneuper@339
   506
 "Rewrite_Set_Inst [(bdv,v_::real)] isolate_bdv False (x=a+#1)";
wneuper@339
   507
> stac2tac_ t;
wneuper@339
   508
val it = Rewrite_Set_Inst ([(#,#)],"isolate_bdv") : tac
wneuper@339
   509
wneuper@339
   510
> val t = (term_of o the o (parse SqRoot.thy)) 
wneuper@339
   511
"(SubProblem (SqRoot_,[equation,univariate],(SqRoot_,solve_linear))\
wneuper@339
   512
   \         [bool_ e_, real_ v_])::bool list";
wneuper@339
   513
> stac2tac_ SqRoot.thy t;
wneuper@339
   514
val it = (Subproblem ("SqRoot.thy",[#,#]),Const (#,#) $ (# $ # $ (# $ #)))
wneuper@339
   515
*)
wneuper@339
   516
wneuper@339
   517
fun stac2tac thy t = (fst o stac2tac_ thy) t;
wneuper@339
   518
wneuper@339
   519
(*24.6.02 unused, use subst_stac instead !*)
wneuper@339
   520
fun is_stac t =
wneuper@339
   521
    (stac2tac_ Script.thy t; true)
wneuper@339
   522
    handle _ => false;
wneuper@339
   523
wneuper@339
   524
wneuper@339
   525
wneuper@339
   526
(*.get the stactics and problems of a script as tacs
wneuper@339
   527
  instantiated with the current environment;
wneuper@339
   528
  l is the location which generated the given formula.*)
wneuper@339
   529
(*WN.12.5.03: quick-and-dirty repair for listexpressions*)
wneuper@339
   530
fun is_spec_pos Pbl = true
wneuper@339
   531
  | is_spec_pos Met = true
wneuper@339
   532
  | is_spec_pos _ = false;
wneuper@339
   533
wneuper@339
   534
fun sel_rules _ (([],Res):pos') = 
wneuper@339
   535
    raise PTREE "no tactics applicable at the end of a calculation"
wneuper@339
   536
| sel_rules pt (p,p_) =
wneuper@339
   537
  if is_spec_pos p_ 
wneuper@339
   538
  then [get_obj g_tac pt p]
wneuper@339
   539
  else
wneuper@339
   540
    let val pp = par_pblobj pt p;
wneuper@339
   541
	val thy' = (get_obj g_domID pt pp):theory';
wneuper@339
   542
	val thy = assoc_thy thy';
wneuper@339
   543
	val metID = get_obj g_metID pt pp;
wneuper@339
   544
	val metID' =if metID =e_metID then(thd3 o snd3)(get_obj g_origin pt pp)
wneuper@339
   545
		     else metID;
wneuper@339
   546
        val Script sc = (#scr o get_met) metID';
wneuper@339
   547
	val ScrState (env,_,_,_,_,_) = get_istate pt (p,p_);
wneuper@339
   548
    in map ((stac2tac thy) o rep_stacexpr o 
wneuper@339
   549
	    (subst_stacexpr env None e_term)) (stacpbls sc) end;
wneuper@339
   550
(*
wneuper@339
   551
> val Script sc = (#scr o get_met) ("SqRoot.thy","sqrt-equ-test");
wneuper@339
   552
> val env = [((term_of o the o (parse Isac.thy)) "bdv",
wneuper@339
   553
             (term_of o the o (parse Isac.thy)) "x")];
wneuper@339
   554
> map ((stac2tac thy) o (subst_stacexpr env None e_term)) (stacpbls sc);
wneuper@339
   555
*)
wneuper@339
   556
wneuper@339
   557
wneuper@339
   558
wneuper@339
   559
wneuper@339
   560
wneuper@339
   561
(*test a term for being a _list_ (set ?) of constants; could be more rigorous*)
wneuper@339
   562
fun list_of_consts (Const ("List.list.Cons",_) $ _ $ _) = true
wneuper@339
   563
  | list_of_consts (Const ("List.list.Nil",_)) = true
wneuper@339
   564
  | list_of_consts _ = false;
wneuper@339
   565
(*val ttt = (term_of o the o (parse thy)) "[x=#1,x=#2,x=#3]";
wneuper@339
   566
> list_of_consts ttt;
wneuper@339
   567
val it = true : bool
wneuper@339
   568
> val ttt = (term_of o the o (parse thy)) "[]";
wneuper@339
   569
> list_of_consts ttt;
wneuper@339
   570
val it = true : bool*)
wneuper@339
   571
wneuper@339
   572
wneuper@339
   573
wneuper@339
   574
wneuper@339
   575
wneuper@339
   576
(* 15.1.01: evaluation of preds only works occasionally,
wneuper@339
   577
            but luckily for the 2 examples of root-equ:
wneuper@339
   578
> val s = ((term_of o the o (parse thy)) "x",
wneuper@339
   579
	   (term_of o the o (parse thy)) "-#5//#12");
wneuper@339
   580
> val asm = (term_of o the o (parse thy)) 
wneuper@339
   581
             "#0 <= #9 + #4 * x  &  #0 <= sqrt x + sqrt (#-3 + x)";
wneuper@339
   582
> val pred = subst_atomic [s] asm;
wneuper@339
   583
> rewrite_set_ thy false (cterm_of (sign_of thy) pred);
wneuper@339
   584
val it = None : (cterm * cterm list) option !!!!!!!!!!!!!!!!!!!!!!!!!!!!
wneuper@339
   585
> eval_true' (string_of_thy thy) "eval_rls" (subst_atomic [s] pred);
wneuper@339
   586
val it = false : bool
wneuper@339
   587
wneuper@339
   588
> val s = ((term_of o the o (parse thy)) "x",
wneuper@339
   589
	   (term_of o the o (parse thy)) "#4");
wneuper@339
   590
> val asm = (term_of o the o (parse thy)) 
wneuper@339
   591
             "#0 <= #9 + #4 * x  &  #0 <= sqrt x + sqrt (#5 + x)";
wneuper@339
   592
> val pred = subst_atomic [s] asm;
wneuper@339
   593
> rewrite_set_ thy false (cterm_of (sign_of thy) pred);
wneuper@339
   594
val it = Some ("True & True",[]) : (cterm * cterm list) option
wneuper@339
   595
> eval_true' (string_of_thy thy) "eval_rls" (subst_atomic [s] pred);
wneuper@339
   596
val it = true : bool`*)
wneuper@339
   597
wneuper@339
   598
(*for check_elementwise: take apart the set, ev. instantiate assumptions
wneuper@339
   599
fun rep_set thy pt p (set as Const ("Collect",_) $ Abs _) =
wneuper@339
   600
  let val (_ $ Abs (bdv,T,pred)) = inst_abs thy set;
wneuper@339
   601
    val bdv = Free (bdv,T);
wneuper@339
   602
    val pred = if pred <> Const ("Script.Assumptions",bool)
wneuper@339
   603
		 then pred 
wneuper@339
   604
	       else (mk_and o (map fst)) (get_assumptions_ pt (p,Res))
wneuper@339
   605
  in (bdv, pred) end
wneuper@339
   606
  | rep_set thy _ _ set = 
wneuper@339
   607
    raise error ("check_elementwise: no set "^ (*from script*)
wneuper@339
   608
		 (Sign.string_of_term (sign_of thy) set));
wneuper@339
   609
(*> val set = (term_of o the o (parse thy)) "{(x::real). Assumptions}";
wneuper@339
   610
> val p = [];
wneuper@339
   611
> val pt = union_asm pt p [("#0 <= sqrt x + sqrt (#5 + x)",[11]),
wneuper@339
   612
                           ("#0 <= #9 + #4 * x",[22]),
wneuper@339
   613
			   ("#0 <= x ^^^ #2 + #5 * x",[33]),
wneuper@339
   614
			   ("#0 <= #2 + x",[44])];
wneuper@339
   615
> val (bdv,pred) = rep_set thy pt p set;
wneuper@339
   616
val bdv = Free ("x","RealDef.real") : term
wneuper@339
   617
> writeln (Sign.string_of_term (sign_of thy) pred);
wneuper@339
   618
((#0 <= sqrt x + sqrt (#5 + x) & #0 <= #9 + #4 * x) &
wneuper@339
   619
 #0 <= x ^^^ #2 + #5 * x) &
wneuper@339
   620
#0 <= #2 + x
wneuper@339
   621
*)
wneuper@339
   622
--------------------------------------------11.6.03--was unused*)
wneuper@339
   623
wneuper@339
   624
wneuper@339
   625
wneuper@339
   626
wneuper@339
   627
datatype ass = 
wneuper@339
   628
  Ass of tac_ *  (*SubProblem gets args instantiated in assod*)
wneuper@339
   629
	 term      (*for itr_arg,result in ets*)
wneuper@339
   630
| AssWeak of tac_ *
wneuper@339
   631
	     term  (*for itr_arg,result in ets*)
wneuper@339
   632
| NotAss;
wneuper@339
   633
wneuper@339
   634
(*.assod: tac_ associated with stac w.r.t. d
wneuper@339
   635
returns
wneuper@339
   636
 Ass    : associated: e.g. thmID in stac = thmID in m
wneuper@339
   637
                       +++ arg   in stac = arg   in m
wneuper@339
   638
 AssWeak: weakly ass.:e.g. thmID in stac = thmID in m, //arg//
wneuper@339
   639
 NotAss :             e.g. thmID in stac/=/thmID in m (not =)
wneuper@339
   640
8.01:
wneuper@339
   641
 tac_ SubProblem with args completed from script
wneuper@339
   642
.*)
wneuper@339
   643
fun assod d (m as Rewrite_Inst' (thy',rod,rls,put,subs,(thmID,thm),f,(f',asm)))
wneuper@339
   644
  (Const ("Script.Rewrite'_Inst",_) $ subs_ $ Free (thmID_,idT) $ b $ f_) = 
wneuper@339
   645
   if thmID = thmID_ then 
wneuper@339
   646
    if f = f_ then ((*writeln"3### assod ..Ass";*)Ass (m,f')) 
wneuper@339
   647
    else ((*writeln"3### assod ..AssWeak";*)AssWeak(m, f'))
wneuper@339
   648
  else ((*writeln"3### assod ..NotAss";*)NotAss)
wneuper@339
   649
wneuper@339
   650
  | assod d (m as Rewrite' (thy,rod,rls,put,(thmID,thm),f,(f',asm))) 
wneuper@339
   651
  (t as Const ("Script.Rewrite",_) $ Free (thmID_,idT) $ b $ f_) =
wneuper@339
   652
  ((*writeln("3### assod: stac = "^
wneuper@339
   653
	   (Sign.string_of_term (sign_of (assoc_thy thy)) t));
wneuper@339
   654
   writeln("3### assod: f(m)= "^
wneuper@339
   655
	   (Sign.string_of_term (sign_of (assoc_thy thy)) f));*)
wneuper@339
   656
   if thmID = thmID_ then 
wneuper@339
   657
    if f = f_ then ((*writeln"3### assod ..Ass";*)Ass (m,f')) 
wneuper@339
   658
    else ((*writeln"### assod ..AssWeak";
wneuper@339
   659
	  writeln("### assod: f(m)  = "^
wneuper@339
   660
		  (Sign.string_of_term (sign_of (assoc_thy thy)) f));
wneuper@339
   661
	  writeln("### assod: f(stac)= "^
wneuper@339
   662
		  (Sign.string_of_term (sign_of (assoc_thy thy)) f_));*)
wneuper@339
   663
	  AssWeak (m,f'))
wneuper@339
   664
  else ((*writeln"3### assod ..NotAss";*)NotAss))
wneuper@339
   665
wneuper@339
   666
(*val f = (term_of o the o (parse thy))"#0+(sqrt(sqrt(sqrt a))^^^#2)^^^#2=#0";
wneuper@339
   667
> val f'= (term_of o the o (parse thy))"#0+(sqrt(sqrt a))^^^#2=#0";
wneuper@339
   668
> val m =   Rewrite'("Script.thy","tless_true","eval_rls",false,
wneuper@339
   669
 ("rroot_square_inv",""),f,(f',[]));
wneuper@339
   670
> val stac = (term_of o the o (parse thy))
wneuper@339
   671
 "Rewrite rroot_square_inv False (#0+(sqrt(sqrt(sqrt a))^^^#2)^^^#2=#0)";
wneuper@339
   672
> assod e_rls m stac;
wneuper@339
   673
val it =
wneuper@339
   674
  (Some (Rewrite' (#,#,#,#,#,#,#)),Const ("empty","RealDef.real"),
wneuper@339
   675
   Const ("empty","RealDef.real")) : tac_ option * term * term*)
wneuper@339
   676
wneuper@339
   677
  | assod d (m as Rewrite_Set_Inst' (thy',put,sub,rls,f,(f',asm))) 
wneuper@339
   678
  (Const ("Script.Rewrite'_Set'_Inst",_) $ sub_ $ Free (rls_,_) $ _ $ f_)= 
wneuper@339
   679
  if id_rls rls = rls_ then 
wneuper@339
   680
    if f = f_ then Ass (m,f') else AssWeak (m,f')
wneuper@339
   681
  else NotAss
wneuper@339
   682
wneuper@339
   683
  | assod d (m as Detail_Set_Inst' (thy',put,sub,rls,f,(f',asm))) 
wneuper@339
   684
  (Const ("Script.Rewrite'_Set'_Inst",_) $ sub_ $ Free (rls_,_) $ _ $ f_)= 
wneuper@339
   685
  if id_rls rls = rls_ then 
wneuper@339
   686
    if f = f_ then Ass (m,f') else AssWeak (m,f')
wneuper@339
   687
  else NotAss
wneuper@339
   688
wneuper@339
   689
  | assod d (m as Rewrite_Set' (thy,put,rls,f,(f',asm))) 
wneuper@339
   690
  (Const ("Script.Rewrite'_Set",_) $ Free (rls_,_) $ _ $ f_) = 
wneuper@339
   691
  if id_rls rls = rls_ then 
wneuper@339
   692
    if f = f_ then Ass (m,f') else AssWeak (m,f')
wneuper@339
   693
  else NotAss
wneuper@339
   694
wneuper@339
   695
  | assod d (m as Detail_Set' (thy,put,rls,f,(f',asm))) 
wneuper@339
   696
  (Const ("Script.Rewrite'_Set",_) $ Free (rls_,_) $ _ $ f_) = 
wneuper@339
   697
  if id_rls rls = rls_ then 
wneuper@339
   698
    if f = f_ then Ass (m,f') else AssWeak (m,f')
wneuper@339
   699
  else NotAss
wneuper@339
   700
wneuper@339
   701
  | assod d (m as Calculate' (thy',op_,f,(f',thm'))) 
wneuper@339
   702
  (Const ("Script.Calculate",_) $ Free (op__,_) $ f_) = 
wneuper@339
   703
  if op_ = op__ then
wneuper@339
   704
    if f = f_ then Ass (m,f') else AssWeak (m,f')
wneuper@339
   705
  else NotAss
wneuper@339
   706
wneuper@339
   707
  | assod _ (m as Check_elementwise' (consts,_,(consts_chkd,_)))
wneuper@339
   708
    (Const ("Script.Check'_elementwise",_) $ consts' $ _) =
wneuper@339
   709
    ((*writeln("### assod Check'_elementwise: consts= "^(term2str consts)^
wneuper@339
   710
	     ", consts'= "^(term2str consts'));
wneuper@339
   711
     atomty(assoc_thy "Isac.thy")consts; atomty(assoc_thy "Isac.thy")consts';*)
wneuper@339
   712
     if consts = consts' then ((*writeln"### assod Check'_elementwise: Ass";*)
wneuper@339
   713
			       Ass (m, consts_chkd))
wneuper@339
   714
     else ((*writeln"### assod Check'_elementwise: NotAss";*) NotAss))
wneuper@339
   715
wneuper@339
   716
  | assod _ (m as Or_to_List' (ors, list)) 
wneuper@339
   717
	  (Const ("Script.Or'_to'_List",_) $ _) =
wneuper@339
   718
	  Ass (m, list) 
wneuper@339
   719
wneuper@341
   720
  | assod _ (m as Take' term) 
wneuper@341
   721
	  (Const ("Script.Take",_) $ _) =
wneuper@341
   722
	  Ass (m, term)
wneuper@341
   723
wneuper@341
   724
  | assod _ (m as Substitute' (_, _, res)) 
wneuper@341
   725
	  (Const ("Script.Substitute",_) $ _ $ _) =
wneuper@341
   726
	  Ass (m, res) 
wneuper@341
   727
(* val t = str2term "Substitute [(x, 3)] (x^^^2 + x + 1)";
wneuper@341
   728
   val (Const ("Script.Substitute",_) $ _ $ _) = t;
wneuper@341
   729
   *)
wneuper@341
   730
wneuper@339
   731
  | assod _ (m as Tac_ (thy,f,id,f'))  
wneuper@339
   732
    (Const ("Script.Tac",_) $ Free (id',_)) =
wneuper@339
   733
    if id = id' then Ass (m, ((term_of o the o (parse thy)) f'))
wneuper@339
   734
    else NotAss
wneuper@339
   735
wneuper@339
   736
wneuper@339
   737
(* val t = str2term 
wneuper@339
   738
              "SubProblem (DiffApp_,[make,function],[no_met]) \
wneuper@339
   739
	      \[real_ m_, real_ v_, bool_list_ rs_]";
wneuper@339
   740
wneuper@339
   741
 val (Subproblem' ((domID,pblID,metID),_,_,_,f)) = m;
wneuper@339
   742
 val (Const ("Script.SubProblem",_) $
wneuper@339
   743
		 (Const ("Pair",_) $
wneuper@339
   744
			Free (dI',_) $
wneuper@339
   745
			(Const ("Pair",_) $ pI' $ mI')) $ ags') = stac;
wneuper@339
   746
 *)
wneuper@339
   747
  | assod _ (Subproblem' ((domID,pblID,metID),_,_,_,f))
wneuper@339
   748
	  (Const ("Script.SubProblem",_) $
wneuper@339
   749
		 (Const ("Pair",_) $
wneuper@339
   750
			Free (dI',_) $ 
wneuper@339
   751
			(Const ("Pair",_) $ pI' $ mI')) $ ags') =
wneuper@339
   752
(*compare "| stac2tac_ thy (Const ("Script.SubProblem",_)"*)
wneuper@339
   753
    let val dI = ((implode o drop_last o explode) dI')^".thy";
wneuper@339
   754
	val pI = ((map (de_esc_underscore o free2str)) o isalist2list) pI';
wneuper@339
   755
	val mI = ((map (de_esc_underscore o free2str)) o isalist2list) mI';
wneuper@339
   756
	val ags = isalist2list ags';
wneuper@339
   757
	val thy = assoc_thy dI;
wneuper@339
   758
	val (pI, pors, mI) = 
wneuper@339
   759
	    if mI = ["no_met"] 
wneuper@339
   760
	    then let val pors = match_ags thy ((#ppc o get_pbt) pI) ags;
wneuper@339
   761
		     val pI' = refine_ori' pors pI;
wneuper@339
   762
		 in (pI', pors (*refinement over models with diff.prec only*), 
wneuper@339
   763
		     (hd o #met o get_pbt) pI') end
wneuper@339
   764
	    else (pI, match_ags thy ((#ppc o get_pbt) pI) ags, mI);
wneuper@339
   765
        val (fmz_, vals) = oris2fmz_vals pors;
wneuper@339
   766
	val {cas, ppc,...} = get_pbt pI
wneuper@339
   767
	val {cas, ppc, thy,...} = get_pbt pI
wneuper@339
   768
	val dI = theory2theory' thy (*take dI from _refined_ pbl*)
wneuper@339
   769
	val hdl = case cas of
wneuper@339
   770
		      None => pblterm dI pI
wneuper@339
   771
		    | Some t => subst_atomic ((vars_of_pbl_' ppc) ~~~ vals) t
wneuper@339
   772
        val f = subpbl (strip_thy dI) pI
wneuper@339
   773
    in if domID = dI andalso pblID = pI
wneuper@339
   774
       then Ass (Subproblem' ((dI, pI, mI), pors, hdl, fmz_, f), f) 
wneuper@339
   775
       else NotAss
wneuper@339
   776
    end
wneuper@339
   777
wneuper@339
   778
  | assod d m t = 
wneuper@339
   779
    (
wneuper@341
   780
writeln("### assod: NotAss m= "^(tac_2str m)^" ,\n stac= "^(term2str t));
wneuper@339
   781
     NotAss);
wneuper@339
   782
wneuper@339
   783
wneuper@339
   784
wneuper@339
   785
fun tac_2tac (Refine_Tacitly' (pI,_,_,_,_)) = Refine_Tacitly pI
wneuper@339
   786
  | tac_2tac (Model_Problem' (pI,_))        = Model_Problem pI
wneuper@339
   787
  | tac_2tac (Add_Given' (t,_))             = Add_Given t
wneuper@339
   788
  | tac_2tac (Add_Find' (t,_))              = Add_Find t
wneuper@339
   789
  | tac_2tac (Add_Relation' (t,_))          = Add_Relation t
wneuper@339
   790
 
wneuper@339
   791
  | tac_2tac (Specify_Theory' dI)           = Specify_Theory dI
wneuper@339
   792
  | tac_2tac (Specify_Problem' (dI,_))      = Specify_Problem dI
wneuper@339
   793
  | tac_2tac (Specify_Method' (dI,_,_))     = Specify_Method dI
wneuper@339
   794
  
wneuper@339
   795
  | tac_2tac (Rewrite' (thy,rod,erls,put,(thmID,thm),f,(f',asm))) =
wneuper@339
   796
    Rewrite (thmID,thm)
wneuper@339
   797
wneuper@339
   798
  | tac_2tac (Rewrite_Inst' (thy,rod,erls,put,sub,(thmID,thm),f,(f',asm)))=
wneuper@339
   799
    Rewrite_Inst (subst2subs sub,(thmID,thm))
wneuper@339
   800
wneuper@339
   801
  | tac_2tac (Rewrite_Set' (thy,put,rls,f,(f',asm))) = 
wneuper@339
   802
    Rewrite_Set (id_rls rls)
wneuper@339
   803
wneuper@339
   804
  | tac_2tac (Detail_Set' (thy,put,rls,f,(f',asm))) = 
wneuper@339
   805
    Detail_Set (id_rls rls)
wneuper@339
   806
wneuper@339
   807
  | tac_2tac (Rewrite_Set_Inst' (thy,put,sub,rls,f,(f',asm))) = 
wneuper@339
   808
    Rewrite_Set_Inst (subst2subs sub,id_rls rls)
wneuper@339
   809
wneuper@339
   810
  | tac_2tac (Detail_Set_Inst' (thy,put,sub,rls,f,(f',asm))) = 
wneuper@339
   811
    Detail_Set_Inst (subst2subs sub,id_rls rls)
wneuper@339
   812
wneuper@339
   813
  | tac_2tac (Calculate' (thy,op_,t,(t',thm'))) = Calculate (op_)
wneuper@339
   814
wneuper@339
   815
  | tac_2tac (Check_elementwise' (consts,pred,consts')) =
wneuper@339
   816
    Check_elementwise pred
wneuper@339
   817
wneuper@339
   818
  | tac_2tac (Or_to_List' _) = Or_to_List
wneuper@342
   819
  | tac_2tac (Take' term) = Take (term2str term)
wneuper@342
   820
  | tac_2tac (Substitute' (subs, t, res)) = Substitute (subst2subs subs) 
wneuper@339
   821
wneuper@339
   822
  | tac_2tac (Tac_ (_,f,id,f')) = Tac id
wneuper@339
   823
wneuper@339
   824
  | tac_2tac (Subproblem' ((domID, pblID, _), _, _,_,_)) = 
wneuper@339
   825
		  Subproblem (domID, pblID)
wneuper@339
   826
  | tac_2tac (Check_Postcond' (pblID, _)) = 
wneuper@339
   827
		  Check_Postcond pblID
wneuper@339
   828
  | tac_2tac Empty_Tac_ = Empty_Tac
wneuper@339
   829
wneuper@339
   830
  | tac_2tac m = 
wneuper@339
   831
  raise error ("tac_2tac: not impl. for "^(tac_2str m));
wneuper@339
   832
wneuper@339
   833
wneuper@339
   834
wneuper@339
   835
wneuper@339
   836
(** decompose tac_ to a rule and to (lhs,rhs)
wneuper@339
   837
    unly needed                            ~~~ **)
wneuper@339
   838
wneuper@339
   839
val idT = Type ("Script.ID",[]);
wneuper@339
   840
(*val tt = (term_of o the o (parse thy)) "square_equation_left::ID";
wneuper@339
   841
type_of tt = idT;
wneuper@339
   842
val it = true : bool
wneuper@339
   843
*)
wneuper@339
   844
(* 13.3.01
wneuper@339
   845
v
wneuper@339
   846
*)
wneuper@339
   847
fun make_rule thy t =
wneuper@339
   848
  let val ct = cterm_of (sign_of thy) (Trueprop $ t)
wneuper@339
   849
  in Thm (string_of_cterm ct, make_thm ct) end;
wneuper@339
   850
wneuper@339
   851
(* val (Rewrite_Inst'(thy',rod,rls,put,subs,(thmID,thm),f,(f',asm)))=m;
wneuper@339
   852
   *)
wneuper@339
   853
(*decompose tac_ to a rule and to (lhs,rhs) for ets FIXME.12.03: obsolete!
wneuper@342
   854
 NOTE.12.03: also used for msg 'not locatable' ?!: 'Subproblem' missing !!!
wneuper@342
   855
WN0508 only use in tac_2res, which uses only last return-value*)
wneuper@339
   856
fun rep_tac_ (Rewrite_Inst' 
wneuper@339
   857
		 (thy',rod,rls,put,subs,(thmID,thm),f,(f',asm))) = 
wneuper@339
   858
  let val fT = type_of f;
wneuper@339
   859
    val b = if put then HOLogic.true_const else HOLogic.false_const;
wneuper@339
   860
    val sT = (type_of o fst o hd) subs;
wneuper@339
   861
    val subs' = list2isalist (HOLogic.mk_prodT (sT, sT))
wneuper@339
   862
      (map HOLogic.mk_prod subs);
wneuper@339
   863
    val sT' = type_of subs';
wneuper@339
   864
    val lhs = Const ("Script.Rewrite'_Inst",[sT',idT,(*fT*)bool,fT] ---> fT) 
wneuper@339
   865
      $ subs' $ Free (thmID,idT) $ b $ f;
wneuper@339
   866
  in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end
wneuper@339
   867
(*Fehlersuche 25.4.01
wneuper@339
   868
(a)----- als String zusammensetzen:
wneuper@339
   869
ML> Sign.string_of_term (sign_of thy)f; 
wneuper@339
   870
val it = "d_d x #4 + d_d x (x ^^^ #2 + #3 * x)" : string
wneuper@339
   871
ML> Sign.string_of_term (sign_of thy)f'; 
wneuper@339
   872
val it = "#0 + d_d x (x ^^^ #2 + #3 * x)" : string
wneuper@339
   873
ML> subs;
wneuper@339
   874
val it = [(Free ("bdv","RealDef.real"),Free ("x","RealDef.real"))] : subst
wneuper@339
   875
> val tt = (term_of o the o (parse thy))
wneuper@339
   876
  "(Rewrite_Inst[(bdv,x)]diff_const False(d_d x #4 + d_d x (x ^^^ #2 + #3 * x)))=(#0 + d_d x (x ^^^ #2 + #3 * x))";
wneuper@339
   877
> atomty thy tt;
wneuper@339
   878
ML> writeln(Sign.string_of_term (sign_of thy)tt); 
wneuper@339
   879
(Rewrite_Inst [(bdv,x)] diff_const False d_d x #4 + d_d x (x ^^^ #2 + #3 * x)) =
wneuper@339
   880
 #0 + d_d x (x ^^^ #2 + #3 * x)
wneuper@339
   881
wneuper@339
   882
(b)----- laut rep_tac_:
wneuper@339
   883
> val ttt=HOLogic.mk_eq (lhs,f');
wneuper@339
   884
> atomty thy ttt;
wneuper@339
   885
wneuper@339
   886
wneuper@339
   887
(*Fehlersuche 1-2Monate vor 4.01:*)
wneuper@339
   888
> val tt = (term_of o the o (parse thy))
wneuper@339
   889
  "Rewrite_Inst[(bdv,x)]square_equation_left True(x=#1+#2)";
wneuper@339
   890
> atomty thy tt;
wneuper@339
   891
wneuper@339
   892
> val f = (term_of o the o (parse thy)) "x=#1+#2";
wneuper@339
   893
> val f' = (term_of o the o (parse thy)) "x=#3";
wneuper@339
   894
> val subs = [((term_of o the o (parse thy)) "bdv",
wneuper@339
   895
	       (term_of o the o (parse thy)) "x")];
wneuper@339
   896
> val sT = (type_of o fst o hd) subs;
wneuper@339
   897
> val subs' = list2isalist (HOLogic.mk_prodT (sT, sT))
wneuper@339
   898
			      (map HOLogic.mk_prod subs);
wneuper@339
   899
> val sT' = type_of subs';
wneuper@339
   900
> val lhs = Const ("Script.Rewrite'_Inst",[sT',idT,fT,fT] ---> fT) 
wneuper@339
   901
  $ subs' $ Free (thmID,idT) $ HOLogic.true_const $ f;
wneuper@339
   902
> lhs = tt;
wneuper@339
   903
val it = true : bool
wneuper@339
   904
> rep_tac_ (Rewrite_Inst' 
wneuper@339
   905
	       ("Script.thy","tless_true","eval_rls",false,subs,
wneuper@339
   906
		("square_equation_left",""),f,(f',[])));
wneuper@339
   907
*)
wneuper@339
   908
  | rep_tac_ (Rewrite' (thy',rod,rls,put,(thmID,thm),f,(f',asm)))=
wneuper@339
   909
  let 
wneuper@339
   910
    val fT = type_of f;
wneuper@339
   911
    val b = if put then HOLogic.true_const else HOLogic.false_const;
wneuper@339
   912
    val lhs = Const ("Script.Rewrite",[idT,HOLogic.boolT,fT] ---> fT)
wneuper@339
   913
      $ Free (thmID,idT) $ b $ f;
wneuper@339
   914
  in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end
wneuper@339
   915
(* 
wneuper@339
   916
> val tt = (term_of o the o (parse thy)) (*____   ____..test*)
wneuper@339
   917
  "Rewrite square_equation_left True (x=#1+#2) = (x=#3)";
wneuper@339
   918
wneuper@339
   919
> val f = (term_of o the o (parse thy)) "x=#1+#2";
wneuper@339
   920
> val f' = (term_of o the o (parse thy)) "x=#3";
wneuper@339
   921
> val Thm (id,thm) = 
wneuper@339
   922
  rep_tac_ (Rewrite' 
wneuper@339
   923
   ("Script.thy","tless_true","eval_rls",false,
wneuper@339
   924
    ("square_equation_left",""),f,(f',[])));
wneuper@339
   925
> val Some ct = parse thy   
wneuper@339
   926
  "Rewrite square_equation_left True (x=#1+#2)"; 
wneuper@339
   927
> rewrite_ Script.thy tless_true eval_rls true thm ct;
wneuper@339
   928
val it = Some ("x = #3",[]) : (cterm * cterm list) option
wneuper@339
   929
*)
wneuper@339
   930
  | rep_tac_ (Rewrite_Set_Inst' 
wneuper@342
   931
		 (thy',put,subs,rls,f,(f',asm))) =
wneuper@342
   932
    (e_rule, (e_term, f'))
wneuper@342
   933
(*WN050824: type error ...
wneuper@339
   934
  let val fT = type_of f;
wneuper@339
   935
    val sT = (type_of o fst o hd) subs;
wneuper@339
   936
    val subs' = list2isalist (HOLogic.mk_prodT (sT, sT))
wneuper@339
   937
      (map HOLogic.mk_prod subs);
wneuper@339
   938
    val sT' = type_of subs';
wneuper@339
   939
    val b = if put then HOLogic.true_const else HOLogic.false_const
wneuper@339
   940
    val lhs = Const ("Script.Rewrite'_Set'_Inst",
wneuper@339
   941
		     [sT',idT,fT,fT] ---> fT) 
wneuper@339
   942
      $ subs' $ Free (id_rls rls,idT) $ b $ f;
wneuper@342
   943
  in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end*)
wneuper@339
   944
(* ... vals from Rewrite_Inst' ...
wneuper@339
   945
> rep_tac_ (Rewrite_Set_Inst' 
wneuper@339
   946
	       ("Script.thy",false,subs,
wneuper@339
   947
		"isolate_bdv",f,(f',[])));
wneuper@339
   948
*)
wneuper@339
   949
(* val (Rewrite_Set' (thy',put,rls,f,(f',asm)))=m;
wneuper@339
   950
*)
wneuper@339
   951
  | rep_tac_ (Rewrite_Set' (thy',put,rls,f,(f',asm)))=
wneuper@339
   952
  let val fT = type_of f;
wneuper@339
   953
    val b = if put then HOLogic.true_const else HOLogic.false_const;
wneuper@339
   954
    val lhs = Const ("Script.Rewrite'_Set",[idT,bool,fT] ---> fT) 
wneuper@339
   955
      $ Free (id_rls rls,idT) $ b $ f;
wneuper@339
   956
  in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end
wneuper@339
   957
(* 13.3.01:
wneuper@339
   958
val thy = assoc_thy thy';
wneuper@339
   959
val t = HOLogic.mk_eq (lhs,f');
wneuper@339
   960
make_rule thy t;
wneuper@339
   961
--------------------------------------------------
wneuper@339
   962
val lll = (term_of o the o (parse thy)) 
wneuper@339
   963
  "Rewrite_Set SqRoot_simplify False (d_d x (x ^^^ #2 + #3 * x) + d_d x #4)";
wneuper@339
   964
wneuper@339
   965
--------------------------------------------------
wneuper@339
   966
> val f = (term_of o the o (parse thy)) "x=#1+#2";
wneuper@339
   967
> val f' = (term_of o the o (parse thy)) "x=#3";
wneuper@339
   968
> val Thm (id,thm) = 
wneuper@339
   969
  rep_tac_ (Rewrite_Set' 
wneuper@339
   970
   ("Script.thy",false,"SqRoot_simplify",f,(f',[])));
wneuper@339
   971
val id = "(Rewrite_Set SqRoot_simplify True x = #1 + #2) = (x = #3)" : string
wneuper@339
   972
val thm = "(Rewrite_Set SqRoot_simplify True x = #1 + #2) = (x = #3)" : thm
wneuper@339
   973
*)
wneuper@339
   974
  | rep_tac_ (Calculate' (thy',op_,f,(f',thm')))=
wneuper@339
   975
  let val fT = type_of f;
wneuper@339
   976
    val lhs = Const ("Script.Calculate",[idT,fT] ---> fT) 
wneuper@339
   977
      $ Free (op_,idT) $ f
wneuper@339
   978
  in (((make_rule (assoc_thy thy')) o HOLogic.mk_eq) (lhs,f'),(lhs,f')) end
wneuper@339
   979
(*
wneuper@339
   980
> val lhs'=(term_of o the o (parse thy))"Calculate plus (#1+#2)";
wneuper@339
   981
  ... test-root-equ.sml: calculate ...
wneuper@339
   982
> val Appl m'=applicable_in p pt (Calculate "plus");
wneuper@339
   983
> val (lhs,_)=tac_2etac m';
wneuper@339
   984
> lhs'=lhs;
wneuper@339
   985
val it = true : bool*)
wneuper@339
   986
  | rep_tac_ (Check_elementwise' (t,str,(t',asm)))  = (Erule, (e_term, t'))
wneuper@339
   987
  | rep_tac_ (Subproblem' (_,_,_,_,t'))  = (Erule, (e_term, t'))
wneuper@340
   988
  | rep_tac_ (Take' (t'))  = (Erule, (e_term, t'))
wneuper@340
   989
  | rep_tac_ (Substitute' (subst,t,t'))  = (Erule, (e_term, t'))
wneuper@339
   990
  | rep_tac_ (Or_to_List' (t, t'))  = (Erule, (t, t'))
wneuper@339
   991
  | rep_tac_ m = raise error ("rep_tac_: not impl.for "^
wneuper@339
   992
				 (tac_2str m));
wneuper@339
   993
wneuper@339
   994
(*"N.3.6.03------
wneuper@339
   995
fun tac_2rule m = (fst o rep_tac_) m;
wneuper@339
   996
fun tac_2etac m = (snd o rep_tac_) m;
wneuper@339
   997
fun tac_2tac m = (fst o snd o rep_tac_) m;*)
wneuper@339
   998
fun tac_2res m = (snd o snd o rep_tac_) m;(*ONLYuse of rep_tac_
wneuper@339
   999
					        FIXXXXME: simplify rep_tac_*)
wneuper@339
  1000
wneuper@339
  1001
wneuper@339
  1002
(* use"ME/script.sml";
wneuper@339
  1003
   use"script.sml";
wneuper@339
  1004
   *)
wneuper@339
  1005
wneuper@339
  1006
wneuper@339
  1007
wneuper@339
  1008
wneuper@339
  1009
(** locate an applicable stactic in a script **)
wneuper@339
  1010
wneuper@339
  1011
datatype assoc = (*ExprVal in the sense of denotational semantics*)
wneuper@339
  1012
  Assoc of     (*the stac is associated, strongly or weakly*)
wneuper@339
  1013
  scrstate *       (*the current; returned for next_tac etc. outside ass* *)  
wneuper@339
  1014
  (step list)    (*list of steps done until associated stac found;
wneuper@339
  1015
	           initiated with the data for doing the 1st step,
wneuper@339
  1016
                   thus the head holds these data further on,
wneuper@339
  1017
		   while the tail holds steps finished (incl.scrstate in ptree)*)
wneuper@339
  1018
| NasApp of   (*stac not associated, but applicable, ptree-node generated*)
wneuper@339
  1019
  scrstate * (step list)
wneuper@339
  1020
| NasNap of     (*stac not associated, not applicable, nothing generated;
wneuper@339
  1021
	         for distinction in Or, for leaving iterations, leaving Seq,
wneuper@339
  1022
		 evaluate scriptexpressions*)
wneuper@339
  1023
  term * env;
wneuper@339
  1024
fun assoc2str (Assoc     _) = "Assoc"
wneuper@339
  1025
  | assoc2str (NasNap  _) = "NasNap"
wneuper@339
  1026
  | assoc2str (NasApp _) = "NasApp";
wneuper@339
  1027
wneuper@339
  1028
wneuper@339
  1029
datatype asap = (*arg. of assy _only_ for distinction w.r.t. Or*)
wneuper@339
  1030
  Aundef   (*undefined: set only by (topmost) Or*)
wneuper@339
  1031
| AssOnly  (*do not execute appl stacs - there could be an associated
wneuper@339
  1032
	     in parallel Or-branch*)
wneuper@339
  1033
| AssGen;  (*no Ass(Weak) found within Or, thus 
wneuper@339
  1034
             search for _applicable_ stacs, execute and generate pt*)
wneuper@339
  1035
(*this constructions doesnt allow arbitrary nesting of Or !!!*)
wneuper@339
  1036
wneuper@339
  1037
wneuper@339
  1038
(*assy, ass_up, astep_up scanning for locate_gen at stactic in a script.
wneuper@339
  1039
  search is clearly separated into (1)-(2):
wneuper@339
  1040
  (1) assy is recursive descent;
wneuper@339
  1041
  (2) ass_up resumes interpretation at a location somewhere in the script;
wneuper@339
  1042
      astep_up does only get to the parentnode of the scriptexpr.
wneuper@339
  1043
  consequence:
wneuper@339
  1044
  * call of (2) means _always_ that in this branch below
wneuper@339
  1045
    there was an appl.stac (Repeat, Or e1, ...)
wneuper@339
  1046
*)
wneuper@339
  1047
wneuper@339
  1048
fun assy ya (is as (E,l,a,v,S,b),ss)
wneuper@339
  1049
	  (Const ("Let",_) $ e $ (Abs (id,T,body))) =
wneuper@339
  1050
    ((*writeln("### assy Let$e$Abs: is=");
wneuper@339
  1051
     writeln(istate2str (ScrState is));*)
wneuper@339
  1052
     case assy ya ((E , l@[L,R], a,v,S,b),ss) e of
wneuper@339
  1053
	 NasApp ((E',l,a,v,S,bb),ss) => 
wneuper@339
  1054
	 let val id' = mk_Free (id, T);
wneuper@339
  1055
	     val E' = upd_env E' (id', v);
wneuper@339
  1056
	 (*val _=writeln("### assy Let -> NasApp");*)
wneuper@339
  1057
	 in assy ya ((E', l@[R,D], a,v,S,b),ss) body end
wneuper@339
  1058
     | NasNap (v,E) => 	 
wneuper@339
  1059
	 let val id' = mk_Free (id, T);
wneuper@339
  1060
	   val E' = upd_env E (id', v);
wneuper@339
  1061
	   (*val _=writeln("### assy Let -> NasNap");*)
wneuper@339
  1062
	 in assy ya ((E', l@[R,D], a,v,S,b),ss) body end
wneuper@339
  1063
     | ay => ay)
wneuper@339
  1064
wneuper@339
  1065
  | assy (ya as (((thy,srls),_),_)) ((E,l,_,v,S,b),ss) 
wneuper@339
  1066
	 (Const ("Script.While",_) $ c $ e $ a) =
wneuper@339
  1067
    ((*writeln("### assy While $ c $ e $ a, upd_env= "^
wneuper@339
  1068
	     (subst2str (upd_env E (a,v))));*)
wneuper@339
  1069
     if eval_true_ thy srls (subst_atomic (upd_env E (a,v)) c) 
wneuper@339
  1070
     then assy ya ((E, l@[L,R], Some a,v,S,b),ss)  e
wneuper@339
  1071
     else NasNap (v, E))
wneuper@339
  1072
   
wneuper@339
  1073
  | assy (ya as (((thy,srls),_),_)) ((E,l,a,v,S,b),ss) 
wneuper@339
  1074
	 (Const ("Script.While",_) $ c $ e) =
wneuper@339
  1075
    ((*writeln("### assy While, l= "^(loc_2str l));*)
wneuper@339
  1076
     if eval_true_ thy srls (subst_atomic (upd_env_opt E (a,v)) c) 
wneuper@339
  1077
     then assy ya ((E, l@[R], a,v,S,b),ss) e
wneuper@339
  1078
     else NasNap (v, E)) 
wneuper@339
  1079
wneuper@339
  1080
  | assy (ya as (((thy,srls),_),_)) ((E,l,a,v,S,b),ss) 
wneuper@339
  1081
	 (Const ("If",_) $ c $ e1 $ e2) =
wneuper@339
  1082
    (if eval_true_ thy srls (subst_atomic (upd_env_opt E (a,v)) c) 
wneuper@339
  1083
     then assy ya ((E, l@[L,R], a,v,S,b),ss) e1
wneuper@339
  1084
     else assy ya ((E, l@[  R], a,v,S,b),ss) e2) 
wneuper@339
  1085
wneuper@339
  1086
  | assy ya ((E,l,_,v,S,b),ss) (Const ("Script.Try",_) $ e $ a) =
wneuper@339
  1087
  ((*writeln("### assy Try, l= "^(loc_2str l));*)
wneuper@339
  1088
    case assy ya ((E, l@[L,R], Some a,v,S,b),ss) e of
wneuper@339
  1089
     ay => ay) 
wneuper@339
  1090
wneuper@339
  1091
  | assy ya ((E,l,a,v,S,b),ss) (Const ("Script.Try",_) $ e) =
wneuper@339
  1092
  ((*writeln("### assy Try, l= "^(loc_2str l));*)
wneuper@339
  1093
    case assy ya ((E, l@[R], a,v,S,b),ss) e of
wneuper@339
  1094
     ay => ay)
wneuper@339
  1095
wneuper@339
  1096
  | assy ya ((E,l,_,v,S,b),ss) (Const ("Script.Seq",_) $e1 $ e2 $ a) =
wneuper@339
  1097
    ((*writeln("### assy Seq $e1 $ e2 $ a, E= "^(subst2str E));*)
wneuper@339
  1098
     case assy ya ((E, l@[L,L,R], Some a,v,S,b),ss) e1 of
wneuper@339
  1099
	 NasNap (v, E) => assy ya ((E, l@[L,R], Some a,v,S,b),ss) e2
wneuper@339
  1100
       | NasApp ((E,_,_,v,_,_),ss) => 
wneuper@339
  1101
	 assy ya ((E, l@[L,R], Some a,v,S,b),ss) e2
wneuper@339
  1102
       | ay => ay)
wneuper@339
  1103
wneuper@339
  1104
  | assy ya ((E,l,a,v,S,b),ss) (Const ("Script.Seq",_) $e1 $ e2) =
wneuper@339
  1105
    (case assy ya ((E, l@[L,R], a,v,S,b),ss) e1 of
wneuper@339
  1106
	 NasNap (v, E) => assy ya ((E, l@[R], a,v,S,b),ss) e2
wneuper@339
  1107
       | NasApp ((E,_,_,v,_,_),ss) => 
wneuper@339
  1108
	 assy ya ((E, l@[R], a,v,S,b),ss) e2
wneuper@339
  1109
       | ay => ay)
wneuper@339
  1110
    
wneuper@339
  1111
  | assy ya ((E,l,_,v,S,b),ss) (Const ("Script.Repeat",_) $ e $ a) =
wneuper@339
  1112
    assy ya ((E,(l@[L,R]),Some a,v,S,b),ss) e
wneuper@339
  1113
wneuper@339
  1114
  | assy ya ((E,l,a,v,S,b),ss) (Const ("Script.Repeat",_) $ e) =
wneuper@339
  1115
    assy ya ((E,(l@[R]),a,v,S,b),ss) e
wneuper@339
  1116
wneuper@339
  1117
(*15.6.02: ass,app Or nochmals "uberlegen FIXXXME*)
wneuper@339
  1118
  | assy (y, Aundef) ((E,l,_,v,S,b),ss) (Const ("Script.Or",_) $e1 $ e2 $ a) =
wneuper@339
  1119
    (case assy (y, AssOnly) ((E,(l@[L,L,R]),Some a,v,S,b),ss) e1 of
wneuper@339
  1120
	 NasNap (v, E) => 
wneuper@339
  1121
	 (case assy (y, AssOnly) ((E,(l@[L,R]),Some a,v,S,b),ss) e2 of
wneuper@339
  1122
	      NasNap (v, E) => 
wneuper@339
  1123
	      (case assy (y, AssGen) ((E,(l@[L,L,R]),Some a,v,S,b),ss) e1 of
wneuper@339
  1124
	       NasNap (v, E) => 
wneuper@339
  1125
	       assy (y, AssGen) ((E, (l@[L,R]), Some a,v,S,b),ss) e2
wneuper@339
  1126
	     | ay => ay)
wneuper@339
  1127
	    | ay =>(ay))
wneuper@339
  1128
       | NasApp _ => raise error ("assy: FIXXXME ///must not return NasApp///")
wneuper@339
  1129
       | ay => (ay))
wneuper@339
  1130
wneuper@339
  1131
  | assy ya ((E,l,a,v,S,b),ss) (Const ("Script.Or",_) $e1 $ e2) =
wneuper@339
  1132
    (case assy ya ((E,(l@[L,R]),a,v,S,b),ss) e1 of
wneuper@339
  1133
	 NasNap (v, E) => 
wneuper@339
  1134
	 assy ya ((E,(l@[R]),a,v,S,b),ss) e2
wneuper@339
  1135
       | ay => (ay)) 
wneuper@339
  1136
(* val ((m,_,pt,(p,p_),c)::ss) = [(m,EmptyMout,pt,p,[])];
wneuper@339
  1137
   val t = (term_of o the o (parse Isac.thy)) "Rewrite rmult_1 False";
wneuper@339
  1138
wneuper@339
  1139
   val (ap,(p,p_),c,ss) = (Aundef,p,[],[]);
wneuper@339
  1140
   assy (((thy',srls),d),ap) ((E,l,a,v,S,b), (m,EmptyMout,pt,(p,p_),c)::ss) t;
wneuper@339
  1141
   *) 
wneuper@339
  1142
wneuper@339
  1143
  | assy (((thy',sr),d),ap) (is as (E,l,a,v,S,b), (m,_,pt,(p,p_),c)::ss) t =
wneuper@341
  1144
    ((*writeln("### assy, m = "^tac_2str m);
wneuper@341
  1145
     writeln("### assy, (p,p_) = "^pos'2str (p,p_));
wneuper@341
  1146
     writeln("### assy, is= ");
wneuper@339
  1147
     writeln(istate2str (ScrState is));*)
wneuper@339
  1148
     case subst_stacexpr E a v t of
wneuper@339
  1149
	Expr s => 
wneuper@339
  1150
	((*writeln("### assy: listexpr t= "^(term2str t)); 
wneuper@339
  1151
         writeln("### assy, E= "^(env2str E));
wneuper@339
  1152
	 writeln("### assy, eval(..)= "^(term2str
wneuper@339
  1153
	       (eval_listexpr_ (assoc_thy thy') sr
wneuper@339
  1154
			       (subst_atomic (upd_env_opt E (a,v)) t))));*)
wneuper@339
  1155
	  NasNap (eval_listexpr_ (assoc_thy thy') sr
wneuper@339
  1156
			       (subst_atomic (upd_env_opt E (a,v)) t), E))
wneuper@339
  1157
      (* val STac stac = subst_stacexpr E a v t;
wneuper@339
  1158
         *)
wneuper@339
  1159
      | STac stac =>
wneuper@341
  1160
	let (*val _=writeln("### assy, stac = "^term2str stac);*)
wneuper@341
  1161
	    val p' = case p_ of Frm => p | Res => lev_on p
wneuper@339
  1162
			      | _ => raise error ("assy: call by "^
wneuper@339
  1163
						  (pos'2str (p,p_)));
wneuper@339
  1164
	in case assod d m stac of
wneuper@339
  1165
	 Ass (m,v') =>
wneuper@341
  1166
	 let (*val _=writeln("### assy: Ass ("^tac_2str m^", 
wneuper@341
  1167
					     "^term2str v'^")");*)
wneuper@340
  1168
	     val (p'',c',f',pt') = generate1 (assoc_thy thy') m 
wneuper@339
  1169
			        (ScrState (E,l,a,v',S,true)) (p',p_) pt;
wneuper@339
  1170
	   in Assoc ((E,l,a,v',S,true), (m,f',pt',p'',c @ c')::ss) end
wneuper@339
  1171
       | AssWeak (m,v') => 
wneuper@339
  1172
	   let val (p'',c',f',pt') = generate1 (assoc_thy thy') m 
wneuper@339
  1173
			         (ScrState (E,l,a,v',S,false)) (p',p_) pt;
wneuper@339
  1174
	   in Assoc ((E,l,a,v',S,false), (m,f',pt',p'',c @ c')::ss) end
wneuper@339
  1175
       | NotAss =>
wneuper@341
  1176
	   ((*writeln("### assy, NotAss");*)
wneuper@341
  1177
	    case ap of   (*switch for Or: 1st AssOnly, 2nd AssGen*)
wneuper@339
  1178
	      AssOnly => (NasNap (v, E))
wneuper@339
  1179
	    | gen => (case applicable_in (p,p_) pt 
wneuper@339
  1180
					 (stac2tac (assoc_thy thy') stac) of
wneuper@339
  1181
			Appl m' =>
wneuper@339
  1182
			  let val is = (E,l,a,tac_2res m',S,false(*FIXXXME*))
wneuper@339
  1183
			      val (p'',c',f',pt') =
wneuper@339
  1184
			      generate1 (assoc_thy thy') m' (ScrState is) (p',p_) pt;
wneuper@339
  1185
			  in NasApp (is,(m,f',pt',p'',c @ c')::ss) end
wneuper@339
  1186
		      | Notappl _ => 
wneuper@339
  1187
			    (NasNap (v, E))
wneuper@339
  1188
			    )
wneuper@339
  1189
		)
wneuper@339
  1190
       end);
wneuper@339
  1191
(* (astep_up ((thy',scr,d),NasApp_) ((E,l,a,v,S,b),[(m,EmptyMout,pt,p,[])])) handle e => print_exn_G e;
wneuper@339
  1192
  *)
wneuper@339
  1193
wneuper@339
  1194
wneuper@341
  1195
(* val (ys as (y,s,Script sc,d),(is as (E,l,a,v,S,b),ss),Const ("Let",_) $ _) =
wneuper@341
  1196
       (ys, ((E,up,a,v,S,b),ss), go up sc);
wneuper@339
  1197
   *)
wneuper@339
  1198
fun ass_up (ys as (y,s,Script sc,d)) (is as (E,l,a,v,S,b),ss) 
wneuper@339
  1199
	   (Const ("Let",_) $ _) =
wneuper@339
  1200
    let (*val _= writeln("### ass_up1 Let$e: is=")
wneuper@339
  1201
	val _= writeln(istate2str (ScrState is))*)
wneuper@339
  1202
	val l = drop_last l; (*comes from e, goes to Abs*)
wneuper@339
  1203
      val (Const ("Let",_) $ e $ (Abs (i,T,body))) = go l sc;
wneuper@339
  1204
      val i = mk_Free (i, T);
wneuper@339
  1205
      val E = upd_env E (i, v);
wneuper@339
  1206
      (*val _=writeln("### ass_up2 Let$e: E="^(subst2str E));*)
wneuper@339
  1207
    in case assy (((y,s),d),Aundef) ((E, l@[R,D], a,v,S,b),ss) body of
wneuper@339
  1208
	   Assoc iss => Assoc iss
wneuper@339
  1209
	 | NasApp iss => astep_up ys iss 
wneuper@339
  1210
	 | NasNap (v, E) => astep_up ys ((E,l,a,v,S,b),ss) end
wneuper@339
  1211
wneuper@339
  1212
  | ass_up ys iss (Abs (_,_,_)) = 
wneuper@339
  1213
    astep_up ys iss (*TODO 5.9.00: env ?*)
wneuper@339
  1214
wneuper@339
  1215
  | ass_up ys (iss as (is,_)) (Const ("Let",_) $ e $ (Abs (i,T,b)))=
wneuper@339
  1216
    ((*writeln("### ass_up Let$e$Abs: is=");
wneuper@339
  1217
     writeln(istate2str (ScrState is));*)
wneuper@339
  1218
     astep_up ys iss) (*TODO 5.9.00: env ?*)
wneuper@339
  1219
wneuper@339
  1220
wneuper@339
  1221
  | ass_up ysa iss (Const ("Script.Seq",_) $ _ $ _ $ _) = 
wneuper@339
  1222
    astep_up ysa iss (*all has been done in (*2*) below*)
wneuper@339
  1223
wneuper@339
  1224
  | ass_up ysa iss (Const ("Script.Seq",_) $ _ $ _) = 
wneuper@339
  1225
    astep_up ysa iss (*2*: comes from e2*)
wneuper@339
  1226
wneuper@339
  1227
  | ass_up (ysa as (y,s,Script sc,d)) (is as (E,l,a,v,S,b),ss)
wneuper@339
  1228
	   (Const ("Script.Seq",_) $ _ ) = (*2*: comes from e1, goes to e2*)
wneuper@339
  1229
    let val up = drop_last l;
wneuper@339
  1230
	val Const ("Script.Seq",_) $ _ $ e2 = go up sc
wneuper@339
  1231
	(*val _= writeln("### ass_up Seq$e: is=")
wneuper@339
  1232
	val _= writeln(istate2str (ScrState is))*)
wneuper@339
  1233
    in case assy (((y,s),d),Aundef) ((E, up@[R], a,v,S,b),ss) e2 of
wneuper@339
  1234
	   NasNap (v,E) => astep_up ysa ((E,up,a,v,S,b),ss)
wneuper@339
  1235
	 | NasApp iss => astep_up ysa iss
wneuper@339
  1236
	 | ay => ay end
wneuper@339
  1237
wneuper@339
  1238
  | ass_up ysa iss (Const ("Script.Try",_) $ e $ _) =
wneuper@339
  1239
    astep_up ysa iss
wneuper@339
  1240
wneuper@339
  1241
  | ass_up ysa iss (Const ("Script.Try",_) $ e) =
wneuper@339
  1242
    astep_up ysa iss
wneuper@339
  1243
wneuper@339
  1244
  | ass_up (ys as (y,s,_,d)) ((E,l,_,v,S,b),ss)
wneuper@339
  1245
	   (Const ("Script.While",_) $ c $ e $ a) =
wneuper@339
  1246
    ((*writeln("### ass_up: While c= "^
wneuper@339
  1247
	     (term2str (subst_atomic (upd_env E (a,v)) c)));*)
wneuper@339
  1248
     if eval_true_ y s (subst_atomic (upd_env E (a,v)) c)
wneuper@339
  1249
    then (case assy (((y,s),d),Aundef) ((E, l@[L,R], Some a,v,S,b),ss) e of 
wneuper@339
  1250
       NasNap (v,E') => astep_up ys ((E',l, Some a,v,S,b),ss)
wneuper@339
  1251
     | NasApp ((E',l,a,v,S,b),ss) =>
wneuper@339
  1252
       ass_up ys ((E',l,a,v,S,b),ss) t
wneuper@339
  1253
     | ay => ay)
wneuper@339
  1254
    else astep_up ys ((E,l, Some a,v,S,b),ss)
wneuper@339
  1255
	 )
wneuper@339
  1256
wneuper@339
  1257
  | ass_up (ys as (y,s,_,d)) ((E,l,a,v,S,b),ss)
wneuper@339
  1258
	   (Const ("Script.While",_) $ c $ e) =
wneuper@339
  1259
    if eval_true_ y s (subst_atomic (upd_env_opt E (a,v)) c)
wneuper@339
  1260
    then (case assy (((y,s),d),Aundef) ((E, l@[R], a,v,S,b),ss) e of 
wneuper@339
  1261
       NasNap (v,E') => astep_up ys ((E',l, a,v,S,b),ss)
wneuper@339
  1262
     | NasApp ((E',l,a,v,S,b),ss) =>
wneuper@339
  1263
       ass_up ys ((E',l,a,v,S,b),ss) t
wneuper@339
  1264
     | ay => ay)
wneuper@339
  1265
    else astep_up ys ((E,l, a,v,S,b),ss)
wneuper@339
  1266
wneuper@339
  1267
  | ass_up y iss (Const ("If",_) $ _ $ _ $ _) = astep_up y iss
wneuper@339
  1268
wneuper@339
  1269
  | ass_up (ys as (y,s,_,d)) ((E,l,_,v,S,b),ss)
wneuper@339
  1270
	   (t as Const ("Script.Repeat",_) $ e $ a) =
wneuper@339
  1271
  (case assy (((y,s),d), Aundef) ((E, (l@[L,R]), Some a,v,S,b),ss) e of 
wneuper@339
  1272
       NasNap (v,E') => astep_up ys ((E',l, Some a,v,S,b),ss)
wneuper@339
  1273
     | NasApp ((E',l,a,v,S,b),ss) =>
wneuper@339
  1274
       ass_up ys ((E',l,a,v,S,b),ss) t
wneuper@339
  1275
     | ay => ay)
wneuper@339
  1276
wneuper@339
  1277
  | ass_up (ys as (y,s,_,d)) (is as ((E,l,a,v,S,b),ss)) 
wneuper@339
  1278
	   (t as Const ("Script.Repeat",_) $ e) =
wneuper@339
  1279
  (case assy (((y,s),d), Aundef) ((E, (l@[R]), a,v,S,b),ss) e of 
wneuper@339
  1280
       NasNap (v', E') => astep_up ys ((E',l,a,v',S,b),ss)
wneuper@339
  1281
     | NasApp ((E',l,a,v',S,bb),ss) => 
wneuper@339
  1282
       ass_up ys ((E',l,a,v',S,b),ss) t
wneuper@339
  1283
     | ay => ay)
wneuper@339
  1284
wneuper@339
  1285
  | ass_up y iss (Const ("Script.Or",_) $ _ $ _ $ _) = astep_up y iss
wneuper@339
  1286
wneuper@339
  1287
  | ass_up y iss (Const ("Script.Or",_) $ _ $ _) = astep_up y iss
wneuper@339
  1288
wneuper@339
  1289
  | ass_up y ((E,l,a,v,S,b),ss) (Const ("Script.Or",_) $ _ ) = 
wneuper@339
  1290
    astep_up y ((E, (drop_last l), a,v,S,b),ss)
wneuper@339
  1291
wneuper@339
  1292
  | ass_up  y iss t =
wneuper@339
  1293
    raise error ("ass_up not impl for t= "^(term2str t))
wneuper@339
  1294
(* 9.6.03
wneuper@339
  1295
   val (ys as (_,_,Script sc,_), ss) = 
wneuper@339
  1296
       ((thy',srls,scr,d), [(m,EmptyMout,pt,p,[])]:step list);
wneuper@339
  1297
   astep_up ys ((E,l,a,v,S,b),ss);
wneuper@340
  1298
wneuper@340
  1299
   val ((ys as (_,_,Script sc,_)), ((E,l,a,v,S,b),ss)) = 
wneuper@340
  1300
       ((thy',srls,scr,d), ((E,l,a,v,S,b), [(m,EmptyMout,pt,p,[])]));
wneuper@339
  1301
   *)  
wneuper@339
  1302
and astep_up (ys as (_,_,Script sc,_)) ((E,l,a,v,S,b),ss) =
wneuper@339
  1303
  if 1 < length l 
wneuper@339
  1304
    then 
wneuper@339
  1305
      let val up = drop_last l;
wneuper@339
  1306
	  (*val _= writeln("### astep_up: E= "env2str E);*)
wneuper@339
  1307
      in ass_up ys ((E,up,a,v,S,b),ss) (go up sc) end
wneuper@339
  1308
  else (NasNap (v, E))
wneuper@339
  1309
;
wneuper@339
  1310
wneuper@339
  1311
wneuper@339
  1312
wneuper@339
  1313
wneuper@339
  1314
wneuper@339
  1315
(* use"ME/script.sml";
wneuper@339
  1316
   use"script.sml";
wneuper@339
  1317
 term2str (go up sc);
wneuper@339
  1318
wneuper@339
  1319
   *)
wneuper@339
  1320
wneuper@339
  1321
(*check if there are tacs for rewriting only*)
wneuper@339
  1322
fun rew_only ([]:step list) = true
wneuper@339
  1323
  | rew_only (((Rewrite' _          ,_,_,_,_))::ss) = rew_only ss
wneuper@339
  1324
  | rew_only (((Rewrite_Inst' _     ,_,_,_,_))::ss) = rew_only ss
wneuper@339
  1325
  | rew_only (((Rewrite_Set' _      ,_,_,_,_))::ss) = rew_only ss
wneuper@339
  1326
  | rew_only (((Rewrite_Set_Inst' _ ,_,_,_,_))::ss) = rew_only ss
wneuper@339
  1327
  | rew_only (((Calculate' _        ,_,_,_,_))::ss) = rew_only ss
wneuper@339
  1328
  | rew_only (((Begin_Trans' _      ,_,_,_,_))::ss) = rew_only ss
wneuper@339
  1329
  | rew_only (((End_Trans' _        ,_,_,_,_))::ss) = rew_only ss
wneuper@339
  1330
  | rew_only _ = false; 
wneuper@339
  1331
  
wneuper@339
  1332
wneuper@339
  1333
datatype locate =
wneuper@339
  1334
  Steps of istate      (*producing hd of step list (which was latest)
wneuper@339
  1335
	                 for next_tac, for reporting Safe|Unsafe to DG*)
wneuper@339
  1336
	   * step      (*(scrstate producing this step is in ptree !)*) 
wneuper@339
  1337
		 list  (*locate_gen may produce intermediate steps*)
wneuper@339
  1338
| NotLocatable;        (*no (m Ass m') or (m AssWeak m') found*)
wneuper@339
  1339
wneuper@339
  1340
wneuper@339
  1341
wneuper@339
  1342
(* locate_gen tries to locate an input tac m in the script. 
wneuper@339
  1343
   pursuing this goal the script is executed until an (m' equiv m) is found,
wneuper@339
  1344
   or the end of the script
wneuper@339
  1345
args
wneuper@339
  1346
   m   : input by the user, already checked by applicable_in,
wneuper@339
  1347
         (to be searched within Or; and _not_ an m doing the step on ptree !)
wneuper@339
  1348
   p,pt: (incl ets) at the time of input
wneuper@339
  1349
   scr : the script
wneuper@339
  1350
   d   : canonical simplifier for locating Take, Substitute, Subproblems etc.
wneuper@339
  1351
   ets : ets at the time of input
wneuper@339
  1352
   l   : the location (in scr) of the stac which generated the current formula
wneuper@339
  1353
returns
wneuper@339
  1354
   Steps: pt,p (incl. ets) with m done
wneuper@339
  1355
          pos' list of proofobjs cut (from generate)
wneuper@339
  1356
          safe: implied from last proofobj
wneuper@339
  1357
	  ets:
wneuper@339
  1358
   ///ToDo : ets contains a list of tacs to be done before m can be done
wneuper@339
  1359
          NOT IMPL. -- "error: do other step before"
wneuper@339
  1360
   NotLocatable: thus generate_hard
wneuper@339
  1361
*)
wneuper@339
  1362
(* val (Rewrite'(_,ro,er,pa,(id,str),f,_), p, Rfuns {locate_rule=lo,...},
wneuper@339
  1363
	RrlsState (_,f'',rss,rts)) = (m, (p,p_), sc, is);
wneuper@339
  1364
   *)
wneuper@339
  1365
fun locate_gen (thy',_) (Rewrite'(_,ro,er,pa,(id,str),f,_)) (pt,p) 
wneuper@339
  1366
	       (Rfuns {locate_rule=lo,...}, d) (RrlsState (_,f'',rss,rts)) = 
wneuper@339
  1367
    (case lo rss f (Thm (id, mk_thm (assoc_thy thy') str)) of
wneuper@339
  1368
	 [] => NotLocatable
wneuper@339
  1369
       | rts' => 
wneuper@339
  1370
	 Steps (rts2steps [] ((pt,p),(f,f'',rss,rts),(thy',ro,er,pa)) rts'))
wneuper@339
  1371
(* val p as(p',p_)=(p,p_);val scr as Script(h $ body)=sc;val (E,l,a,v,S,bb)=is;
wneuper@339
  1372
   locate_gen (thy':theory') (m:tac_) ((pt,p):ptree * pos') 
wneuper@339
  1373
	      (scr,d) (E,l,a,v,S,bb);
wneuper@339
  1374
   9.6.03
wneuper@339
  1375
   val ts = (thy',srls);
wneuper@339
  1376
   val p = (p,p_);
wneuper@339
  1377
   val (scr as Script (h $ body)) = (sc);
wneuper@339
  1378
   val ScrState (E,l,a,v,S,b) = (is);
wneuper@339
  1379
wneuper@340
  1380
   val (ts as (thy',srls), m, (pt,p), 
wneuper@340
  1381
	(scr as Script (h $ body),d), (ScrState (E,l,a,v,S,b))) = 
wneuper@340
  1382
       ((thy',srls), m,  (pt,(p,p_)), (sc,d), is);
wneuper@339
  1383
   locate_gen (thy',srls) m (pt,p) (Script(h $ body),d)(ScrState(E,l,a,v,S,b));
wneuper@340
  1384
wneuper@340
  1385
   val (ts as (thy',srls), m, (pt,p), 
wneuper@340
  1386
	(scr as Script (h $ body),d), (ScrState (E,l,a,v,S,b))) = 
wneuper@340
  1387
       ((thy',srls), m',  (pt,(lev_on p,Frm)), (sc,d), is');
wneuper@339
  1388
   *)
wneuper@339
  1389
  | locate_gen (ts as (thy',srls)) (m:tac_) ((pt,p):ptree * pos') 
wneuper@339
  1390
	       (scr as Script (h $ body),d) (ScrState (E,l,a,v,S,b))  = 
wneuper@339
  1391
  let (*val _= writeln("### locate_gen-----------------: is=");
wneuper@342
  1392
      val _= writeln( istate2str (ScrState (E,l,a,v,S,b)));
wneuper@342
  1393
      val _= writeln("### locate_gen: l= "^loc_2str l^", p= "^pos'2str p)*)
wneuper@339
  1394
      val thy = assoc_thy thy';
wneuper@341
  1395
  in case if l=[] orelse (*init.in solve..Apply_Method*)p = ([0],Res)
wneuper@341
  1396
	  then (assy ((ts,d),Aundef) ((E,[R],a,v,S,b),
wneuper@341
  1397
				      [(m,EmptyMout,pt,p,[])]) body)
wneuper@339
  1398
(* val Assoc (iss as (is as (_,_,_,_,_,bb), ss as ((m',f',pt',p',c')::_))) =
wneuper@339
  1399
       (astep_up (thy',srls,scr,d) ((E,l,a,v,S,b),[(m,EmptyMout,pt,p,[])]));
wneuper@339
  1400
       (assy ((ts,d),Aundef) ((E,[R],a,v,S,b),[(m,EmptyMout,pt,p,[])]) body);
wneuper@339
  1401
  *)
wneuper@339
  1402
	  else (astep_up (thy',srls,scr,d) ((E,l,a,v,S,b),
wneuper@341
  1403
					    [(m,EmptyMout,pt,p,[])]) ) of
wneuper@339
  1404
	 Assoc (iss as (is as (_,_,_,_,_,bb), ss as ((m',f',pt',p',c')::_))) =>
wneuper@341
  1405
	 ((*writeln("### locate_gen Assoc: p'="^(pos'2str p'));*)
wneuper@339
  1406
	  if bb then Steps (ScrState is, ss)
wneuper@339
  1407
	 else if rew_only ss (*andalso 'not bb'= associated weakly*)
wneuper@339
  1408
	 then let (*val _=writeln("### locate_gen, bef g1: p="^(pos'2str p));*)
wneuper@339
  1409
		  val (po,p_) = p;
wneuper@339
  1410
                  val po' = case p_ of Frm => po | Res => lev_on po
wneuper@339
  1411
		  (*WN.12.03: noticed, that pos is also updated in assy !?!
wneuper@339
  1412
		   instead take p' from Assoc ?????????????????????????????*)
wneuper@339
  1413
                  val (p'',c'',f'',pt'') = 
wneuper@339
  1414
		      generate1 thy m (ScrState is) (po',p_) pt;
wneuper@339
  1415
	      (*val _=writeln("### locate_gen, aft g1: p''="^(pos'2str p''));*)
wneuper@339
  1416
	      (*drop the intermediate steps !*)
wneuper@339
  1417
	      in Steps (ScrState is, [(m, f'',pt'',p'',c'')]) end
wneuper@339
  1418
	 else Steps (ScrState is, ss))
wneuper@339
  1419
	
wneuper@339
  1420
     | NasApp _ (*[((E,l,a,v,S,bb),(m',f',pt',p',c'))] => 
wneuper@339
  1421
	   raise error ("locate_gen: should not have got NasApp, ets =")*)
wneuper@339
  1422
       => NotLocatable
wneuper@339
  1423
     | NasNap (_,_) =>
wneuper@339
  1424
       if l=[] then NotLocatable
wneuper@339
  1425
       else (*scan from begin of script for rew_only*)
wneuper@339
  1426
	   (case assy ((ts,d),Aundef) ((E,[R],a,v,Unsafe,b),
wneuper@339
  1427
					 [(m,EmptyMout,pt,p,[])]) body  of
wneuper@339
  1428
		Assoc (iss as (is as (_,_,_,_,_,bb), 
wneuper@339
  1429
			       ss as ((m',f',pt',p',c')::_))) =>
wneuper@339
  1430
		    ((*writeln"4### locate_gen Assoc after Fini";*)
wneuper@339
  1431
		     if rew_only ss
wneuper@341
  1432
		     then let val(p'',c'',f'',pt'') = 
wneuper@341
  1433
				 generate1 thy m (ScrState is) p' pt;
wneuper@339
  1434
			  (*drop the intermediate steps !*)
wneuper@339
  1435
			  in Steps (ScrState is, [(m, f'',pt'',p'',c'')]) end
wneuper@339
  1436
		     else NotLocatable)
wneuper@339
  1437
	      | _ => ((*writeln ("#### locate_gen: after Fini");*)
wneuper@339
  1438
		      NotLocatable))
wneuper@339
  1439
  end
wneuper@339
  1440
  | locate_gen _ m _ (sc,_) is = 
wneuper@339
  1441
    raise error ("locate_gen: wrong arguments,\n tac= "^(tac_2str m)^
wneuper@339
  1442
		 ",\n scr= "^(scr2str sc)^",\n istate= "^(istate2str is));
wneuper@339
  1443
wneuper@339
  1444
wneuper@339
  1445
wneuper@339
  1446
(** find the next stactic in a script **)
wneuper@339
  1447
wneuper@339
  1448
datatype appy =  (*ExprVal in the sense of denotational semantics*)
wneuper@339
  1449
    Appy of      (*applicable stac found, search stalled*)
wneuper@339
  1450
    tac_ *       (*tac_ associated (fun assod) with stac*)
wneuper@339
  1451
    scrstate     (*after determination of stac WN.18.8.03*)
wneuper@339
  1452
  | Napp of      (*stac found was not applicable; 
wneuper@339
  1453
	           this mode may become Skip in Repeat, Try and Or*)
wneuper@339
  1454
    env (*stack*)  (*popped while nxt_up*)
wneuper@339
  1455
  | Skip of      (*for restart after Appy, for leaving iterations,
wneuper@339
  1456
	           for passing the value of scriptexpressions,
wneuper@339
  1457
		   and for finishing the script successfully*)
wneuper@339
  1458
    term * env (*stack*);
wneuper@339
  1459
wneuper@339
  1460
(*appy, nxt_up, nstep_up scanning for next_tac.
wneuper@339
  1461
  search is clearly separated into (1)-(2):
wneuper@339
  1462
  (1) appy is recursive descent;
wneuper@339
  1463
  (2) nxt_up resumes interpretation at a location somewhere in the script;
wneuper@339
  1464
      nstep_up does only get to the parentnode of the scriptexpr.
wneuper@339
  1465
  consequence:
wneuper@339
  1466
  * call of (2) means _always_ that in this branch below
wneuper@339
  1467
    there was an appl.stac (Repeat, Or e1, ...)
wneuper@339
  1468
*)
wneuper@339
  1469
wneuper@339
  1470
datatype appy_ = (*as argument in nxt_up, nstep_up, from appy*)
wneuper@339
  1471
       (*  Appy is only (final) returnvalue, not argument during search
wneuper@339
  1472
       |*) Napp_ (*ev. detects 'script is not appropriate for this example'*)
wneuper@339
  1473
       | Skip_;  (*detects 'script successfully finished'
wneuper@339
  1474
		   also used as init-value for resuming; this works,
wneuper@339
  1475
	           because 'nxt_up Or e1' treats as Appy*)
wneuper@339
  1476
wneuper@339
  1477
fun appy thy ptp E l
wneuper@339
  1478
  (t as Const ("Let",_) $ e $ (Abs (i,T,b))) a v =
wneuper@339
  1479
  ((*writeln("### appy Let$e$Abs: is=");
wneuper@339
  1480
   writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*)
wneuper@339
  1481
   case appy thy ptp E (l@[L,R]) e a v of
wneuper@339
  1482
     Skip (res, E) => 
wneuper@339
  1483
       let (*val _= writeln("### appy Let "^(term2str t));
wneuper@339
  1484
	 val _= writeln("### appy Let: Skip res ="^(term2str res));*)
wneuper@339
  1485
       (*val (i',b') = variant_abs (i,T,b); WN.15.5.03
wneuper@339
  1486
	 val i = mk_Free(i',T);             WN.15.5.03 *)   
wneuper@339
  1487
	 val E' = upd_env E (Free (i,T), res);
wneuper@339
  1488
       in appy thy ptp E' (l@[R,D]) b a v end
wneuper@339
  1489
   | ay => ay)
wneuper@339
  1490
wneuper@339
  1491
  | appy (thy as (th,sr)) ptp E l
wneuper@339
  1492
  (t as Const ("Script.While"(*1*),_) $ c $ e $ a) _ v = (*ohne n. 28.9.00*)
wneuper@339
  1493
  ((*writeln("### appy While $ c $ e $ a, upd_env= "^
wneuper@339
  1494
	   (subst2str (upd_env E (a,v))));*)
wneuper@339
  1495
   if eval_true_ th sr (subst_atomic (upd_env E (a,v)) c)
wneuper@339
  1496
    then appy thy ptp E (l@[L,R]) e (Some a) v
wneuper@339
  1497
  else Skip (v, E))
wneuper@339
  1498
wneuper@339
  1499
  | appy (thy as (th,sr)) ptp E l
wneuper@339
  1500
  (t as Const ("Script.While"(*2*),_) $ c $ e) a v =(*ohne nachdenken 28.9.00*)
wneuper@339
  1501
  ((*writeln("### appy While $ c $ e, upd_env= "^
wneuper@339
  1502
	   (subst2str (upd_env_opt E (a,v))));*)
wneuper@339
  1503
   if eval_true_ th sr (subst_atomic (upd_env_opt E (a,v)) c)
wneuper@339
  1504
    then appy thy ptp E (l@[R]) e a v
wneuper@339
  1505
  else Skip (v, E))
wneuper@339
  1506
wneuper@339
  1507
  | appy (thy as (th,sr)) ptp E l (t as Const ("If",_) $ c $ e1 $ e2) a v =
wneuper@339
  1508
    ((*writeln("### appy If: t= "^(term2str t));
wneuper@339
  1509
     writeln("### appy If: c= "^(term2str(subst_atomic(upd_env_opt E(a,v))c)));
wneuper@339
  1510
     writeln("### appy If: thy= "^(fst thy));*)
wneuper@339
  1511
     if eval_true_ th sr (subst_atomic (upd_env_opt E (a,v)) c)
wneuper@339
  1512
     then ((*writeln("### appy If: true");*)appy thy ptp E (l@[L,R]) e1 a v)
wneuper@339
  1513
     else ((*writeln("### appy If: false");*)appy thy ptp E (l@[  R]) e2 a v))
wneuper@339
  1514
wneuper@339
  1515
  | appy thy ptp E (*env*) l
wneuper@339
  1516
  (Const ("Script.Repeat"(*1*),_) $ e $ a) _ v = 
wneuper@339
  1517
    ((*writeln("### appy Repeat a: ");*)
wneuper@339
  1518
     appy thy ptp E (*env*) (l@[L,R]) e (Some a) v)
wneuper@339
  1519
wneuper@339
  1520
  | appy thy ptp E (*env*) l
wneuper@339
  1521
  (Const ("Script.Repeat"(*2*),_) $ e) a v = 
wneuper@339
  1522
    ((*writeln("3### appy Repeat: a= "^
wneuper@339
  1523
	     (Sign.string_of_term (sign_of (assoc_thy thy)) a));*)
wneuper@339
  1524
     appy thy ptp E (*env*) (l@[R]) e a v)
wneuper@339
  1525
wneuper@339
  1526
  | appy thy ptp E l
wneuper@339
  1527
  (t as Const ("Script.Try",_) $ e $ a) _ v =
wneuper@339
  1528
  (case appy thy ptp E (l@[L,R]) e (Some a) v of
wneuper@339
  1529
     Napp E => ((*writeln("### appy Try "^
wneuper@339
  1530
			  (Sign.string_of_term (sign_of (assoc_thy thy)) t));*)
wneuper@339
  1531
		 Skip (v, E))
wneuper@339
  1532
   | ay => ay)
wneuper@339
  1533
(* val (l,t as Const ("Script.Try",_) $ e) = (l@[L,R],e1);
wneuper@339
  1534
   appy thy ptp E l t a v;
wneuper@339
  1535
   *)
wneuper@339
  1536
  | appy thy ptp E l
wneuper@339
  1537
  (t as Const ("Script.Try",_) $ e) a v =
wneuper@339
  1538
  (case appy thy ptp E (l@[R]) e a v of
wneuper@339
  1539
     Napp E => ((*writeln("### appy Try "^
wneuper@339
  1540
			  (Sign.string_of_term (sign_of (assoc_thy thy)) t));*)
wneuper@339
  1541
		 Skip (v, E))
wneuper@339
  1542
   | ay => ay)
wneuper@339
  1543
wneuper@339
  1544
wneuper@339
  1545
  | appy thy ptp E l
wneuper@339
  1546
	 (Const ("Script.Or"(*1*),_) $e1 $ e2 $ a) _ v =
wneuper@339
  1547
    (case appy thy ptp E (l@[L,L,R]) e1 (Some a) v of
wneuper@339
  1548
	 Appy lme => Appy lme
wneuper@339
  1549
       | _ => appy thy ptp E (*env*) (l@[L,R]) e2 (Some a) v)
wneuper@339
  1550
    
wneuper@339
  1551
  | appy thy ptp E l
wneuper@339
  1552
	 (Const ("Script.Or"(*2*),_) $e1 $ e2) a v =
wneuper@339
  1553
    (case appy thy ptp E (l@[L,R]) e1 a v of
wneuper@339
  1554
	 Appy lme => Appy lme
wneuper@339
  1555
       | _ => appy thy ptp E (l@[R]) e2 a v)
wneuper@339
  1556
    
wneuper@339
  1557
wneuper@339
  1558
  | appy thy ptp E l
wneuper@339
  1559
	 (Const ("Script.Seq"(*1*),_) $e1 $ e2 $ a) _ v =
wneuper@339
  1560
    ((*writeln("### appy Seq $ e1 $ e2 $ a, upd_env= "^
wneuper@339
  1561
	     (subst2str (upd_env E (a,v))));*)
wneuper@339
  1562
     case appy thy ptp E (l@[L,L,R]) e1 (Some a) v of
wneuper@339
  1563
	 Skip (v,E) => appy thy ptp E (l@[L,R]) e2 (Some a) v
wneuper@339
  1564
       | ay => ay)
wneuper@339
  1565
(* val (l,t as Const ("Script.Seq",_) $e1 $ e2) = (up@[R],e2);
wneuper@339
  1566
   appy thy ptp E l t a v;
wneuper@339
  1567
   *)    
wneuper@339
  1568
  | appy thy ptp E l
wneuper@339
  1569
	 (Const ("Script.Seq",_) $e1 $ e2) a v =
wneuper@339
  1570
    (case appy thy ptp E (l@[L,R]) e1 a v of
wneuper@339
  1571
	 Skip (v,E) => appy thy ptp E (l@[R]) e2 a v
wneuper@339
  1572
       | ay => ay)
wneuper@339
  1573
    
wneuper@339
  1574
  (*here at the end, this must be a stactic
wneuper@339
  1575
    wrt. diss. missing checks: stac in ets, stac ready*)
wneuper@339
  1576
(* val (pt, p) = ptp;
wneuper@339
  1577
   val t = (term_of o the o (parse SqRoot.thy))
wneuper@339
  1578
	       "Rewrite square_equation_left True";
wneuper@339
  1579
wneuper@339
  1580
   val (pt, p) = ptp;
wneuper@339
  1581
   val t = (term_of o the o (parseold SqRoot.thy))
wneuper@339
  1582
	       "Check_elementwise L_ {v_. Assumptions} ";
wneuper@339
  1583
wneuper@339
  1584
   val ((pt,p),l,t,a,v) = (ptp,[R],body,None,e_term);
wneuper@339
  1585
   val t = body;   
wneuper@339
  1586
   val t = (term_of o the o (parseold SqRoot.thy))
wneuper@339
  1587
	       "Rewrite square_equation_left True";
wneuper@339
  1588
   val a = Some ((term_of o the o (parseold SqRoot.thy)) "e_::bool");
wneuper@339
  1589
wneuper@339
  1590
   val ((pt,p),l,t,a,v) = (ptp,[R],body,None,e_term);
wneuper@339
  1591
wneuper@339
  1592
   val (thy as (th,sr),(pt,p),l,t) = (thy,ptp,l@[R],e);
wneuper@339
  1593
wneuper@339
  1594
   val (thy as (th,sr),(pt,p),l,t) = (thy,ptp,l@[R],v);
wneuper@339
  1595
wneuper@339
  1596
val ((th,sr), t, p) = (thy, 
wneuper@339
  1597
		       str2term "Rewrite real_plus_binom_pow2 False", (p,p_));
wneuper@339
  1598
wneuper@339
  1599
   val (thy as (th,sr),(pt,p),l,t) = (thy,ptp,up@[R,D],body);
wneuper@339
  1600
   appy (th,sr) (pt, p) E l t a v;
wneuper@342
  1601
val (thy as (th,sr),(pt, p),E,l,t,a,v) = (thy,ptp,E,up@[R,D],body, a, v);
wneuper@339
  1602
   *)
wneuper@339
  1603
  | appy (thy as (th,sr)) (pt, p) E l t a v =
wneuper@339
  1604
    (case subst_stacexpr E a v t of
wneuper@339
  1605
	Expr s => ((*writeln("### appy, listexpr= "^(term2str t));
wneuper@339
  1606
          writeln("### appy, E= "^(env2str E));
wneuper@339
  1607
	  writeln("### appy, eval(..)= "^(term2str
wneuper@339
  1608
	       (eval_listexpr_ (assoc_thy th) sr
wneuper@339
  1609
			       (subst_atomic (upd_env_opt E (a,v)) t))));*)
wneuper@339
  1610
	  Skip (eval_listexpr_ (assoc_thy th) sr
wneuper@339
  1611
			       (subst_atomic (upd_env_opt E (a,v)) t), E))
wneuper@339
  1612
(* val STac stac = subst_stacexpr E a v t;
wneuper@339
  1613
   *)
wneuper@339
  1614
     | STac stac =>
wneuper@339
  1615
	let
wneuper@361
  1616
	 val _= writeln("### appy t, stac= "^(term2str stac))
wneuper@361
  1617
(*--->>*)
wneuper@339
  1618
         (*val _= writeln("### appy t, vor  stac2tac_ is="); 
wneuper@339
  1619
           val _= writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*)
wneuper@339
  1620
	   val (m,m') = stac2tac_ (assoc_thy th) stac;
wneuper@339
  1621
       (*val _= writeln("### appy t, nach stac2tac, m= "^(tac2str m));*)
wneuper@339
  1622
       in case m of 
wneuper@339
  1623
	      Subproblem _ => Appy (m', (E,l,a,tac_2res m',Sundef,false))
wneuper@339
  1624
	    | _ => (case applicable_in p pt m of
wneuper@342
  1625
(* val Appl m' = applicable_in p pt m;
wneuper@342
  1626
   *)
wneuper@339
  1627
			Appl m' => 
wneuper@341
  1628
			((*writeln("### appy: Appy");*)
wneuper@339
  1629
			 Appy (m', (E,l,a,tac_2res m',Sundef,false)))
wneuper@339
  1630
		      | _ => ((*writeln("### appy: Napp");*)Napp E)) 
wneuper@339
  1631
	end);
wneuper@339
  1632
	 
wneuper@339
  1633
wneuper@339
  1634
(* val (scr as Script sc, l, t as Const ("Let",_) $ _) =
wneuper@339
  1635
       (Script sc, up, go up sc);
wneuper@339
  1636
   nxt_up thy ptp (Script sc) E l ay t a v;
wneuper@342
  1637
val (thy,ptp,scr as (Script sc),E,l,ay,t as Const ("Let",_) $ _, a, v)=
wneuper@342
  1638
    (thy,ptp,Script sc,E,up,ay,go up sc,a,v);
wneuper@339
  1639
   *)
wneuper@339
  1640
fun nxt_up thy ptp (scr as (Script sc)) E l ay
wneuper@339
  1641
    (t as Const ("Let",_) $ _) a v = (*comes from let=...*)
wneuper@339
  1642
    ((*writeln("### nxt_up1 Let$e: is=");
wneuper@339
  1643
     writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*)
wneuper@339
  1644
     if ay = Napp_
wneuper@339
  1645
    then nstep_up thy ptp scr E (drop_last l) Napp_ a v
wneuper@339
  1646
    else (*Skip_*)
wneuper@339
  1647
	let val up = drop_last l;
wneuper@339
  1648
	    val (Const ("Let",_) $ e $ (Abs (i,T,body))) = go up sc;
wneuper@339
  1649
            val i = mk_Free (i, T);
wneuper@339
  1650
            val E = upd_env E (i, v);
wneuper@339
  1651
          (*val _= writeln("### nxt_up2 Let$e: is=");
wneuper@339
  1652
            val _= writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*)
wneuper@339
  1653
	in case appy thy ptp (E) (up@[R,D]) body a v  of
wneuper@339
  1654
	       Appy lre => Appy lre
wneuper@339
  1655
	     | Napp E => nstep_up thy ptp scr E up Napp_ a v
wneuper@339
  1656
	     | Skip (v,E) => nstep_up thy ptp scr E up Skip_ a v end)
wneuper@339
  1657
	    
wneuper@339
  1658
  | nxt_up thy ptp scr E l ay
wneuper@339
  1659
    (t as Abs (_,_,_)) a v = 
wneuper@339
  1660
    ((*writeln("### nxt_up Abs: "^
wneuper@339
  1661
	     (Sign.string_of_term (sign_of (assoc_thy thy)) t));*)
wneuper@339
  1662
     nstep_up thy ptp scr E (*enr*) l ay a v)
wneuper@339
  1663
wneuper@339
  1664
  | nxt_up thy ptp scr E l ay
wneuper@339
  1665
    (t as Const ("Let",_) $ e $ (Abs (i,T,b))) a v =
wneuper@339
  1666
    ((*writeln("### nxt_up Let$e$Abs: is=");
wneuper@339
  1667
     writeln(istate2str (ScrState (E,l,a,v,Sundef,false)));*)
wneuper@339
  1668
     (*writeln("### nxt_up Let e Abs: "^
wneuper@339
  1669
	     (Sign.string_of_term (sign_of (assoc_thy thy)) t));*)
wneuper@339
  1670
     nstep_up thy ptp scr (*upd_env*) E (*a,v)*) 
wneuper@339
  1671
	      (*eno,upd_env env (iar,res),iar,res,saf*) l ay a v)
wneuper@339
  1672
wneuper@339
  1673
  (*no appy_: never causes Napp -> Helpless*)
wneuper@339
  1674
  | nxt_up (thy as (th,sr)) ptp scr E l _ 
wneuper@339
  1675
  (Const ("Script.While"(*1*),_) $ c $ e $ _) a v = 
wneuper@339
  1676
  if eval_true_ th sr (subst_atomic (upd_env_opt E (a,v)) c) 
wneuper@339
  1677
    then case appy thy ptp E (l@[L,R]) e a v of
wneuper@339
  1678
	     Appy lr => Appy lr
wneuper@339
  1679
	   | Napp E => nstep_up thy ptp scr E l Skip_ a v
wneuper@339
  1680
	   | Skip (v,E) => nstep_up thy ptp scr E l Skip_ a v
wneuper@339
  1681
  else nstep_up thy ptp scr E l Skip_ a v
wneuper@339
  1682
wneuper@339
  1683
  (*no appy_: never causes Napp - Helpless*)
wneuper@339
  1684
  | nxt_up (thy as (th,sr)) ptp scr E l _ 
wneuper@339
  1685
  (Const ("Script.While"(*2*),_) $ c $ e) a v = 
wneuper@339
  1686
  if eval_true_ th sr (subst_atomic (upd_env_opt E (a,v)) c) 
wneuper@339
  1687
    then case appy thy ptp E (l@[R]) e a v of
wneuper@339
  1688
	     Appy lr => Appy lr
wneuper@339
  1689
	   | Napp E => nstep_up thy ptp scr E l Skip_ a v
wneuper@339
  1690
	   | Skip (v,E) => nstep_up thy ptp scr E l Skip_ a v
wneuper@339
  1691
  else nstep_up thy ptp scr E l Skip_ a v
wneuper@339
  1692
wneuper@339
  1693
(* val (scr, l) = (Script sc, up);
wneuper@339
  1694
   *)
wneuper@339
  1695
  | nxt_up thy ptp scr E l ay (Const ("If",_) $ _ $ _ $ _) a v = 
wneuper@339
  1696
    nstep_up thy ptp scr E l ay a v
wneuper@339
  1697
wneuper@339
  1698
  | nxt_up thy ptp scr E l _ (*no appy_: there was already a stac below*)
wneuper@339
  1699
  (Const ("Script.Repeat"(*1*),T) $ e $ _) a v =
wneuper@339
  1700
    (case appy thy ptp (*upd_env*) E (*a,v)*) ((l@[L,R]):loc_) e a v  of
wneuper@339
  1701
      Appy lr => Appy lr
wneuper@339
  1702
    | Napp E => ((*writeln("### nxt_up Repeat a: ");*)
wneuper@339
  1703
		 nstep_up thy ptp scr E l Skip_ a v)
wneuper@339
  1704
    | Skip (v,E) => ((*writeln("### nxt_up Repeat: Skip res ="^
wneuper@339
  1705
		(Sign.string_of_term(sign_of (assoc_thy thy)) res'));*)
wneuper@339
  1706
		    nstep_up thy ptp scr E l Skip_ a v))
wneuper@339
  1707
wneuper@339
  1708
  | nxt_up thy ptp scr E l _ (*no appy_: there was already a stac below*)
wneuper@339
  1709
  (Const ("Script.Repeat"(*2*),T) $ e) a v =
wneuper@339
  1710
    (case appy thy ptp (*upd_env*) E (*a,v)*) ((l@[R]):loc_) e a v  of
wneuper@339
  1711
      Appy lr => Appy lr
wneuper@339
  1712
    | Napp E => ((*writeln("### nxt_up Repeat a: ");*)
wneuper@339
  1713
		 nstep_up thy ptp scr E l Skip_ a v)
wneuper@339
  1714
    | Skip (v,E) => ((*writeln("### nxt_up Repeat: Skip res ="^
wneuper@339
  1715
		(Sign.string_of_term(sign_of (assoc_thy thy)) res'));*)
wneuper@339
  1716
		    nstep_up thy ptp scr E l Skip_ a v))
wneuper@339
  1717
wneuper@339
  1718
(* val (scr,l,t) = (Script sc,up,go up sc);
wneuper@339
  1719
   nxt_up thy ptp scr E l ay t a v;
wneuper@339
  1720
   *)
wneuper@339
  1721
  | nxt_up thy ptp scr E l _ (*makes Napp to Skip*)
wneuper@339
  1722
  (t as Const ("Script.Try",_) $ e $ _) a v = 
wneuper@339
  1723
    ((*writeln("### nxt_up Try "^
wneuper@339
  1724
	     (Sign.string_of_term (sign_of (assoc_thy thy)) t));*)
wneuper@339
  1725
     nstep_up thy ptp scr E l Skip_ a v )
wneuper@339
  1726
wneuper@339
  1727
  | nxt_up thy ptp scr E l _ (*makes Napp to Skip*)
wneuper@339
  1728
  (t as Const ("Script.Try"(*2*),_) $ e) a v = 
wneuper@339
  1729
    ((*writeln("### nxt_up Try "^
wneuper@339
  1730
	     (Sign.string_of_term (sign_of (assoc_thy thy)) t));*)
wneuper@339
  1731
     nstep_up thy ptp scr (*upd_env*) E (*a,v)*) l Skip_ a v)
wneuper@339
  1732
wneuper@339
  1733
wneuper@339
  1734
  | nxt_up thy ptp scr E l ay
wneuper@339
  1735
  (Const ("Script.Or",_) $ _ $ _ $ _) a v = nstep_up thy ptp scr E l ay a v
wneuper@339
  1736
wneuper@339
  1737
  | nxt_up thy ptp scr E l ay
wneuper@339
  1738
  (Const ("Script.Or",_) $ _ $ _) a v = nstep_up thy ptp scr E l ay a v
wneuper@339
  1739
wneuper@339
  1740
  | nxt_up thy ptp scr E l ay
wneuper@339
  1741
  (Const ("Script.Or",_) $ _ ) a v = 
wneuper@339
  1742
    nstep_up thy ptp scr E (drop_last l) ay a v
wneuper@339
  1743
wneuper@339
  1744
wneuper@339
  1745
  | nxt_up thy ptp scr E l ay (*all has been done in (*2*) below*)
wneuper@339
  1746
  (Const ("Script.Seq"(*1*),_) $ _ $ _ $ _) a v =
wneuper@339
  1747
    nstep_up thy ptp scr E l ay a v
wneuper@339
  1748
wneuper@339
  1749
  | nxt_up thy ptp scr E l ay (*comes from e2*)
wneuper@339
  1750
	   (Const ("Script.Seq"(*2*),_) $ _ $ e2) a v =
wneuper@339
  1751
    nstep_up thy ptp scr E l ay a v
wneuper@339
  1752
(* val (scr as Script sc,l,t) = (Script sc,up,go up sc);
wneuper@339
  1753
   !! Const ("Script.Seq",_ $ _ 
wneuper@339
  1754
   nxt_up thy ptp scr E l ay t a v;
wneuper@339
  1755
   *)
wneuper@339
  1756
  | nxt_up thy ptp (scr as Script sc) E l ay (*comes from e1*)
wneuper@339
  1757
	   (Const ("Script.Seq",_) $ _ ) a v = 
wneuper@339
  1758
    if ay = Napp_
wneuper@339
  1759
    then nstep_up thy ptp scr E (drop_last l) Napp_ a v
wneuper@339
  1760
    else (*Skip_*)
wneuper@339
  1761
	let val up = drop_last l;
wneuper@339
  1762
	    val Const ("Script.Seq"(*2*),_) $ _ $ e2 = go up sc;
wneuper@339
  1763
	in case appy thy ptp E (up@[R]) e2 a v  of
wneuper@339
  1764
	    Appy lr => Appy lr
wneuper@339
  1765
	  | Napp E => nstep_up thy ptp scr E up Napp_ a v
wneuper@339
  1766
	  | Skip (v,E) => nstep_up thy ptp scr E up Skip_ a v end
wneuper@339
  1767
wneuper@339
  1768
  | nxt_up (thy,_) ptp scr E l ay t a v =
wneuper@339
  1769
  raise error ("nxt_up not impl for "^
wneuper@339
  1770
	       (Sign.string_of_term (sign_of (assoc_thy thy)) t))
wneuper@339
  1771
wneuper@339
  1772
(* val (Script sc, ay) = (scr,Skip_);
wneuper@339
  1773
   val (Script sc, ay) = (sc,Skip_);
wneuper@342
  1774
val (thy, ptp, (Script sc), E, l, ay, a, v)=(thy, ptp, sc, E, l, Skip_, a, v);
wneuper@342
  1775
*)
wneuper@339
  1776
and nstep_up thy ptp (Script sc) E l ay a v = 
wneuper@339
  1777
  ((*writeln("### nstep_up from: "^(loc_2str l));
wneuper@339
  1778
   writeln("### nstep_up from: "^
wneuper@339
  1779
	   (Sign.string_of_term (sign_of (assoc_thy thy)) (go l sc)));*)
wneuper@339
  1780
   if 1 < length l 
wneuper@339
  1781
   then 
wneuper@339
  1782
       let 
wneuper@339
  1783
	   val up = drop_last l; 
wneuper@339
  1784
       in ((*writeln("### nstep_up to: "^
wneuper@339
  1785
	      (Sign.string_of_term (sign_of (assoc_thy thy)) (go up sc)));*)
wneuper@339
  1786
	   nxt_up thy ptp (Script sc) E up ay (go up sc) a v ) end
wneuper@339
  1787
   else (*interpreted to end*)
wneuper@339
  1788
       if ay = Skip_ then Skip (v, E) else Napp E 
wneuper@339
  1789
);
wneuper@339
  1790
wneuper@339
  1791
(* decide for the next applicable stac in the script;
wneuper@339
  1792
   returns (stactic, value) - the value in case the script is finished 
wneuper@339
  1793
   12.8.02:         ~~~~~ and no assumptions ??? FIXME ???
wneuper@339
  1794
   20.8.02: must return p in case of finished, because the next script
wneuper@339
  1795
            consulted need not be the calling script:
wneuper@339
  1796
            in case of detail ie. _inserted_ PrfObjs, the next stac
wneuper@339
  1797
            has to searched in a script with PblObj.status<>Complete !
wneuper@339
  1798
            (.. not true for other details ..PrfObj ??????????????????
wneuper@339
  1799
   20.8.02: do NOT return safe (is only changed in locate !!!)
wneuper@339
  1800
*)
wneuper@339
  1801
(* val (thy, (pt,p), Rfuns {next_rule=ne,...}, RrlsState (f,f',rss,_)) = 
wneuper@339
  1802
       (thy', (pt,p), sc, RrlsState (ii t));
wneuper@339
  1803
   val (thy, (pt,p), Rfuns {next_rule=ne,...}, RrlsState (f,f',rss,_)) = 
wneuper@339
  1804
       (thy', (pt',p'), sc, is');
wneuper@339
  1805
   *)
wneuper@339
  1806
fun next_tac (thy,_) (pt,p) (Rfuns {next_rule,...}) (RrlsState(f,f',rss,_))=
wneuper@339
  1807
    if f = f' then (End_Detail' (f',[])(*8.6.03*), Uistate, 
wneuper@339
  1808
		    (f', Sundef(*FIXME is no value of next_tac! vor 8.6.03*)))
wneuper@339
  1809
                                                          (*finished*)
wneuper@339
  1810
    else (case next_rule rss f of
wneuper@339
  1811
	      None => (Empty_Tac_, Uistate, (e_term, Sundef)) 	  (*helpless*)
wneuper@339
  1812
(* val Some (Thm (id,thm)) = next_rule rss f;
wneuper@339
  1813
   *)
wneuper@339
  1814
	    | Some (Thm (id,thm))(*8.6.03: muss auch f' liefern ?!!*) => 
wneuper@339
  1815
	      (Rewrite' (thy, "e_rew_ord", e_rls,(*!?!8.6.03*) false,
wneuper@339
  1816
			 (id, string_of_thm' thm), f,(e_term,[(*!?!8.6.03*)])),
wneuper@339
  1817
	       Uistate, (e_term, Sundef)))                 (*next stac*)
wneuper@339
  1818
wneuper@339
  1819
(* val(thy, ptp as (pt,(p,_)), sc as Script (h $ body),ScrState (E,l,a,v,s,b))=
wneuper@339
  1820
       ((thy',srls), (pt,pos), sc, is);
wneuper@339
  1821
   next_tac thy ptp (Script (h $ body)) (ScrState (E,l,a,v,s,b));
wneuper@339
  1822
wneuper@339
  1823
   val(thy, ptp as (pt,(p,_)), sc as Script (h $ body),ScrState (E,l,a,v,s,b))=
wneuper@339
  1824
       ((thy',srls), (pt,(p,Frm)), sc, is);
wneuper@342
  1825
   val(thy, ptp as (pt,(p,_)), sc as Script (h $ body),ScrState (E,l,a,v,s,b))=
wneuper@342
  1826
      ((thy',srls), (pt,pos), sc, is);
wneuper@339
  1827
 *)
wneuper@339
  1828
  | next_tac thy (ptp as (pt,(p,_)):ptree * pos') (sc as Script (h $ body)) 
wneuper@339
  1829
	     (ScrState (E,l,a,v,s,b)) =
wneuper@339
  1830
  ((*writeln("### next_tac-----------------: E= ");
wneuper@339
  1831
   writeln( istate2str (ScrState (E,l,a,v,s,b)));*)
wneuper@339
  1832
   case if l=[] then appy thy ptp E [R] body None e_term
wneuper@339
  1833
       else nstep_up thy ptp sc E l Skip_ a v of
wneuper@339
  1834
      Skip (v,_) =>                                              (*finished*)
wneuper@339
  1835
      (case par_pbl_det pt p of
wneuper@339
  1836
	   (true, p', _) => 
wneuper@339
  1837
	   let val (_,pblID,_) = get_obj g_spec pt p';
wneuper@339
  1838
	   in (Check_Postcond' (pblID, (v, [(*8.6.03 NO asms???*)])), 
wneuper@339
  1839
	       e_istate, (v,s)) end
wneuper@339
  1840
	 | (_,p',rls') => (End_Detail' (e_term,[])(*8.6.03*), e_istate, (v,s)))
wneuper@339
  1841
    | Napp _ => (Empty_Tac_, e_istate, (e_term, Sundef))         (*helpless*)
wneuper@339
  1842
    | Appy (m', scrst as (_,_,_,v,_,_)) => (m', ScrState scrst,
wneuper@339
  1843
			   (v, Sundef)))                         (*next stac*)
wneuper@339
  1844
wneuper@339
  1845
  | next_tac _ _ _ is = raise error ("next_tac: not impl for "^
wneuper@339
  1846
				     (istate2str is));
wneuper@339
  1847
wneuper@343
  1848
wneuper@343
  1849
wneuper@343
  1850
wneuper@362
  1851
(*.create the initial interpreter state from the items of the guard.*)
wneuper@359
  1852
(* val (thy, itms, metID) = (thy, itms, mI);
wneuper@339
  1853
   *)
wneuper@339
  1854
fun init_scrstate thy itms metID =
wneuper@343
  1855
    let val actuals = itms2args thy metID itms;
wneuper@339
  1856
	val scr as Script sc = (#scr o get_met) metID;
wneuper@343
  1857
        val formals = formal_args sc
wneuper@343
  1858
	(*expects same sequence of (actual) args in itms 
wneuper@343
  1859
          and (formal) args in met*)
wneuper@343
  1860
	fun relate_args env [] [] = env
wneuper@343
  1861
	  | relate_args env _ [] = 
wneuper@362
  1862
	    raise error ("ERROR in creating the environment for '"
wneuper@362
  1863
			 ^id_of_scr sc^"' from \nthe items of the guard of "
wneuper@362
  1864
			 ^metID2str metID^",\n\
wneuper@362
  1865
			 \formal arg(s) miss actual arg(s):\n"
wneuper@362
  1866
			 ^(string_of_int o length) formals
wneuper@362
  1867
			 ^" formals: "^terms2str formals^"\n"
wneuper@362
  1868
			 ^(string_of_int o length) actuals
wneuper@362
  1869
			 ^" actuals: "^terms2str actuals)
wneuper@343
  1870
	  | relate_args env [] actual_finds = env (*may drop Find!*)
wneuper@343
  1871
	  | relate_args env (a::aa) (f::ff) = 
wneuper@343
  1872
	    if type_of a = type_of f 
wneuper@362
  1873
	    then relate_args (env @ [(a, f)]) aa ff else 
wneuper@362
  1874
	    raise error ("ERROR in creating the environment for '"
wneuper@362
  1875
			 ^id_of_scr sc^"' from \nthe items of the guard of "
wneuper@362
  1876
			 ^metID2str metID^",\n\			 
wneuper@362
  1877
			 \different types of formal arg and actual arg:'\n\
wneuper@362
  1878
			 \formal: '"^term2str a^"::"^(type2str o type_of) a^"'\n\
wneuper@362
  1879
			 \actual: '"^term2str f^"::"^(type2str o type_of) f^"'\n\
wneuper@362
  1880
			 \in\n\
wneuper@362
  1881
			 \formals: "^terms2str formals^"\n\
wneuper@362
  1882
			 \actuals: "^terms2str actuals)
wneuper@343
  1883
        val env = relate_args [] formals actuals;
wneuper@339
  1884
    in (ScrState (env,[],None,e_term,Safe,true), scr):istate * scr end;
wneuper@339
  1885
wneuper@339
  1886
(*.decide, where to get script/istate from:
wneuper@339
  1887
   (*1*) from PblObj.env: at begin of script if no init_form
wneuper@339
  1888
   (*2*) from PblObj/PrfObj: if stac is in the middle of the script
wneuper@339
  1889
   (*3*) from rls/PrfObj: in case of detail a ruleset.*)
wneuper@339
  1890
fun from_pblobj_or_detail' thy' (p,p_) pt =
wneuper@339
  1891
    if p_ mem [Pbl,Met]
wneuper@339
  1892
    then case get_obj g_env pt p of
wneuper@339
  1893
	     None => raise error "from_pblobj_or_detail': no istate"
wneuper@339
  1894
	   | Some is =>
wneuper@339
  1895
	     let val metID = get_obj g_metID pt p
wneuper@339
  1896
		 val {srls,...} = get_met metID
wneuper@339
  1897
	     in (srls, is, (#scr o get_met) metID) end
wneuper@339
  1898
    else
wneuper@339
  1899
    let val (pbl,p',rls') = par_pbl_det pt p
wneuper@339
  1900
    in if pbl 
wneuper@339
  1901
       then (*2*)
wneuper@339
  1902
	   let val thy = assoc_thy thy'
wneuper@339
  1903
	       val PblObj{meth=itms,...} = get_obj I pt p'
wneuper@339
  1904
	       val metID = get_obj g_metID pt p'
wneuper@339
  1905
	       val {srls,...} = get_met metID
wneuper@339
  1906
	   in (*if last_elem p = 0 (*nothing written to pt yet*)
wneuper@339
  1907
	      then let val (is, sc) = init_scrstate thy itms metID
wneuper@339
  1908
		   in (srls, is, sc) end
wneuper@339
  1909
	      else*) (srls, get_istate pt (p,p_), (#scr o get_met) metID)
wneuper@339
  1910
	   end
wneuper@339
  1911
       else (*3*)
wneuper@339
  1912
	   (e_rls, (*FIXME: get from pbl or met !!!
wneuper@339
  1913
		    unused for Rrls in locate_gen, next_tac*)
wneuper@339
  1914
	    get_istate pt (p,p_),
wneuper@339
  1915
	    case rls' of
wneuper@339
  1916
		Rls {scr=scr,...} => scr
wneuper@339
  1917
	      | Rrls {scr=rfuns,...} => rfuns)
wneuper@339
  1918
    end;
wneuper@339
  1919
wneuper@339
  1920
(*.get script and istate from PblObj, see (*1*) above.*)
wneuper@339
  1921
fun from_pblobj' thy' (p,p_) pt = 
wneuper@339
  1922
    let val p' = par_pblobj pt p
wneuper@339
  1923
	val thy = assoc_thy thy'
wneuper@339
  1924
	val PblObj{meth=itms,...} = get_obj I pt p'
wneuper@339
  1925
	val metID = get_obj g_metID pt p'
wneuper@339
  1926
	val {srls,scr,...} = get_met metID
wneuper@339
  1927
    in if last_elem p = 0 (*nothing written to pt yet*)
wneuper@339
  1928
       then let val (is, scr) = init_scrstate thy itms metID
wneuper@339
  1929
	    in (srls, is, scr) end
wneuper@339
  1930
       else (srls, get_istate pt (p,p_), scr)
wneuper@339
  1931
    end;
wneuper@339
  1932
    
wneuper@339
  1933
(*
wneuper@339
  1934
end
wneuper@339
  1935
open Interpreter;
wneuper@339
  1936
*)
wneuper@339
  1937
wneuper@339
  1938
(* use"ME/script.sml";
wneuper@339
  1939
   use"script.sml";
wneuper@339
  1940
   *)