test/Tools/isac/Interpret/script.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Mon, 07 Dec 2015 14:10:59 +0100
changeset 59188 c477d0f79ab9
parent 55480 1738bef7d5d3
child 59248 5eba5e6d5266
permissions -rw-r--r--
Isabelle2014-->15: closed Thm.thy applied to tests

Note:
# concerns the funs: assbl_thm, cterm_of-->global_cterm_of, make_thm,
prop_of, rep_thm, rep_thm_G, therm_of.
# tests have not been run since start of Isabelle2014-->15.
     1 (* Title:  test/../script.sml
     2    Author: Walther Neuper 050908
     3    (c) copyright due to lincense terms.
     4 *)
     5 "-----------------------------------------------------------------";
     6 "table of contents -----------------------------------------------";
     7 "-----------------------------------------------------------------";
     8 "----------- WN0509 why does next_tac doesnt find Substitute -----";
     9 "----------- WN0509 Substitute 2nd part --------------------------";
    10 "----------- fun sel_appl_atomic_tacs ----------------------------";
    11 "----------- fun init_form, fun get_stac -------------------------";
    12 "----------- x+1=2 start SubProblem 'stac2tac_ TODO: no match for ";
    13 "----------- Take as 1st stac in script --------------------------";
    14 "----------- 'trace_script' from outside 'fun me '----------------";
    15 "----------- fun sel_rules ---------------------------------------";
    16 "----------- fun sel_appl_atomic_tacs ----------------------------";
    17 "-----------------------------------------------------------------";
    18 "-----------------------------------------------------------------";
    19 "-----------------------------------------------------------------";
    20 
    21 val thy =  @{theory Isac};
    22 
    23 "----------- WN0509 why does next_tac doesnt find Substitute -----";
    24 "----------- WN0509 why does next_tac doesnt find Substitute -----";
    25 "----------- WN0509 why does next_tac doesnt find Substitute -----";
    26 
    27 (*replace met 'IntegrierenUndKonstanteBestimmen' with this script...*)
    28 val str = (*#1#*)
    29 "Script BiegelinieScript                                             " ^ 
    30 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real)              " ^ 
    31 "(rb_rb::bool list) (rm_rm::bool list) =                             " ^
    32 "  (let q___q = Take (M_b v_v = q__q);                               " ^
    33 "       (M1__M1::bool) = ((Substitute [v_v = 0])) q___q              " ^
    34 " in True)";
    35 
    36 val sc' = ((inst_abs thy) o Thm.term_of o the o (parse thy)) str;
    37 
    38 val str = (*#2#*)
    39 "Script BiegelinieScript                                             " ^ 
    40 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real)              " ^ 
    41 "(rb_rb::bool list) (rm_rm::bool list) =                             " ^ 
    42 "       (M1__M1::bool) = ((Substitute [v_v = 0]) @@                  " ^
    43 " in True)";(*..doesnt find Substitute with ..@@ !!!!!!!!!!!!!!!!!!!!!*)
    44 
    45 val str = (*#3#*)
    46 "Script BiegelinieScript                                             " ^
    47 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real)              " ^
    48 "(rb_rb::bool list) (rm_rm::bool list) =                             " ^
    49 "  (let q___q = Take (q_q v_v = q__q);                               " ^
    50 "      (M1__M1::bool) = Substitute [v_v = 0]      q___q ;            " ^
    51 "       M1__m1 =        Substitute [M_b 0 = 0]  M1__M1               " ^
    52 " in True)"
    53 ;
    54 val str = (*#4#*)
    55 "Script BiegelinieScript                                             " ^
    56 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real)              " ^
    57 "(rb_rb::bool list) (rm_rm::bool list) =                             " ^
    58 "  (let q___q = Take (q_q v_v = q__q);                               " ^
    59 "      (M1__M1::bool) = Substitute [v_v = 0]      q___q ;            " ^
    60 "       M1__M1 =        Substitute [v_v = 1]      q___q ;            " ^
    61 "       M1__M1 =        Substitute [v_v = 2]      q___q ;            " ^
    62 "       M1__M1 =        Substitute [v_v = 3]      q___q ;            " ^
    63 "       M1__M1 =        Substitute [M_b 0 = 0]  M1__M1               " ^
    64 " in True)"
    65 ;
    66 val str = (*#5#*)
    67 "Script BiegelinieScript                                             " ^
    68 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real)              " ^
    69 "(rb_rb::bool list) (rm_rm::bool list) =                             " ^
    70 "  (let q___q = Take (M_b v_v = q__q);                               " ^
    71 "      (M1__M1::bool) = Substitute [v_v = 0]      q___q ;            " ^
    72 "       M2__M2 = Take q___q ;                                        " ^
    73 "       M2__M2 =        Substitute [v_v = 2]      q___q              " ^
    74 " in True)"
    75 ;
    76 
    77 val sc' = ((inst_abs thy) o Thm.term_of o the o (parse thy)) str;
    78 atomty sc';
    79 
    80 val {scr = Prog sc,...} = get_met ["IntegrierenUndKonstanteBestimmen"];
    81 (*---------------------------------------------------------------------
    82 if sc = sc' then () else error"script.sml, doesnt find Substitute #1";
    83 ---------------------------------------------------------------------*)
    84 
    85 "----------- WN0509 Substitute 2nd part --------------------------";
    86 "----------- WN0509 Substitute 2nd part --------------------------";
    87 "----------- WN0509 Substitute 2nd part --------------------------";
    88 (*replace met 'IntegrierenUndKonstanteBestimmen' with this script...*)
    89 val str = (*Substitute ; Substitute works*)
    90 "Script BiegelinieScript                                             " ^
    91 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real)              " ^
    92 "(rb_rb::bool list) (rm_rm::bool list) =                             "^
    93 (*begin after the 2nd integrate*)
    94 "  (let M__M = Take (M_b v_v = q__q);                                " ^
    95 "       e1__e1 = nth_nth 1 rm_rm ;                                   " ^
    96 "       (x1__x1::real) = argument_in (lhs e1__e1);                   " ^
    97 "       (M1__M1::bool) = Substitute [v_v = x1__x1] M__M;             " ^
    98 "        M1__M1        = Substitute [e1__e1] M1__M1                  " ^
    99 " in True)"
   100 ;
   101 val sc' = ((inst_abs thy) o Thm.term_of o the o (parse thy)) str;
   102 atomty sc';
   103 
   104 val str = (*Substitute @@ Substitute does NOT work???*)
   105 "Script BiegelinieScript                                             " ^
   106 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real)              " ^
   107 "(rb_rb::bool list) (rm_rm::bool list) =                             "^
   108 (*begin after the 2nd integrate*)
   109 "  (let M__M = Take (M_b v_v = q__q);                                " ^
   110 "       e1__e1 = nth_nth 1 rm_rm ;                                   " ^
   111 "       (x1__x1::real) = argument_in (lhs e1__e1);                   " ^
   112 "       (M1__M1::bool) = ((Substitute [v_v = x1__x1]) @@             " ^
   113 "                       (Substitute [e1__e1]))        M__M           " ^
   114 " in True)"
   115 ;
   116 
   117 val {scr = Prog sc,...} = get_met ["IntegrierenUndKonstanteBestimmen"];
   118 (*---------------------------------------------------------------------
   119 if sc = sc' then () else error "script.sml, doesnt find Substitute #1";
   120 ---------------------------------------------------------------------*)
   121 val fmz = ["Traegerlaenge L",
   122 	   "Streckenlast (- q_0 * x^^^2 / 2 + x * c + c_2)",
   123 	   "Biegelinie y",
   124 	   "RandbedingungenBiegung [y 0 = 0, y L = 0]",
   125 	   "RandbedingungenMoment [M_b 0 = 0, M_b L = 0]",
   126 	   "FunktionsVariable x"];
   127 val (dI',pI',mI') =
   128   ("Biegelinie",["MomentBestimmte","Biegelinien"],
   129    ["IntegrierenUndKonstanteBestimmen"]);
   130 val p = e_pos'; val c = [];
   131 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   132 val (p,_,f,nxt,_,pt) = me nxt p c pt; val (p,_,f,nxt,_,pt) = me nxt p c pt;
   133 val (p,_,f,nxt,_,pt) = me nxt p c pt; val (p,_,f,nxt,_,pt) = me nxt p c pt;
   134 val (p,_,f,nxt,_,pt) = me nxt p c pt; val (p,_,f,nxt,_,pt) = me nxt p c pt;
   135 val (p,_,f,nxt,_,pt) = me nxt p c pt; val (p,_,f,nxt,_,pt) = me nxt p c pt;
   136 val (p,_,f,nxt,_,pt) = me nxt p c pt; val (p,_,f,nxt,_,pt) = me nxt p c pt;
   137 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   138 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   139 case nxt of (_, Apply_Method ["IntegrierenUndKonstanteBestimmen"]) => ()
   140 	  | _ => error "script.sml, doesnt find Substitute #2";
   141 (* ERROR: caused by f2str f *)
   142 trace_rewrite := false;
   143 
   144 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f(*------------------------*);
   145 trace_rewrite:=false;
   146   (*Exception TYPE raised:
   147     Illegal type for constant "HOL.eq" :: "[real, bool] => bool"
   148     Atools.argument'_in (Tools.lhs (ListG.nth_ (1 + -1 + -1) [])) =
   149     ListG.nth_ (1 + -1 + -1) []
   150     Exception-
   151        TYPE
   152           ("Illegal type for constant \"op =\" :: \"[real, bool] => bool\"",
   153              [],
   154              [Const ("HOL.Trueprop", "bool => prop") $
   155                    (Const ("HOL.eq", "["Real.real, bool] => bool") $ ... $ ...)])
   156        raised
   157     ... this was because eval_argument_in took "argument_in (lhs (M_b 0 = 0))"
   158     ie. the argument had not been simplified before          ^^^^^^^^^^^^^^^
   159     thus corrected eval_argument_in OK*)
   160 val {srls,...} = get_met ["IntegrierenUndKonstanteBestimmen"];
   161 val e1__e1 = str2term "NTH 1 [M_b 0 = 0, M_b L = 0]";
   162 val e1__e1 = eval_listexpr_ @{theory Biegelinie} srls e1__e1; term2str e1__e1;
   163 if term2str e1__e1 = "M_b 0 = 0"
   164   then ()
   165   else error"script.sml diff.beh. eval_listexpr_ nth_nth 1 [...";
   166 
   167 (*TODO.WN050913 ??? doesnt eval_listexpr_ go into subterms ???...
   168  val x1__ = str2term"argument_in (lhs (M_b 0 = 0))";
   169  val x1__ = eval_listexpr_ Biegelinie.thy srls x1__; term2str x1__;
   170  (*no rewrite*)
   171  calculate_ Biegelinie.thy ("Tools.lhs", eval_rhs"eval_lhs_") x1__;
   172  val SOME (str, t) = eval_lhs 0 "Tools.lhs" (str2term"lhs (M_b 0 = 0)") 0;*)
   173 
   174 val l__l = str2term "lhs (M_b 0 = 0)";
   175 val l__l = eval_listexpr_ @{theory Biegelinie} srls l__l; term2str l__l;
   176 val SOME (str, t) = eval_lhs 0 "Tools.lhs" (str2term "lhs (M_b 0 = 0)") 0;
   177 
   178 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f (*------------------------*);
   179 if nxt = ("Rewrite", Rewrite ("Belastung_Querkraft", "- qq ?x = Q' ?x"))
   180 then () else error "--- WN0509 Substitute 2nd part --- changed";
   181 
   182 
   183 "----------- fun sel_appl_atomic_tacs ----------------------------";
   184 "----------- fun sel_appl_atomic_tacs ----------------------------";
   185 "----------- fun sel_appl_atomic_tacs ----------------------------";
   186 
   187 reset_states ();
   188 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   189   ("Test", ["sqroot-test","univariate","equation","test"],
   190    ["Test","squ-equ-test-subpbl1"]))];
   191 Iterator 1;
   192 moveActiveRoot 1;
   193 autoCalculate' 1 CompleteCalcHead;
   194 autoCalculate' 1 (Step 1);
   195 autoCalculate' 1 (Step 1);
   196 val ((pt, p), _) = get_calc 1; show_pt pt;
   197 val appltacs = sel_appl_atomic_tacs pt p;
   198 if appltacs = 
   199   [Rewrite ("radd_commute", "?m + ?n = ?n + ?m"), 
   200   Rewrite ("add_assoc", "?a + ?b + ?c = ?a + (?b + ?c)"), Calculate "TIMES"]
   201 then () else error "script.sml fun sel_appl_atomic_tacs diff.behav.";
   202 
   203 trace_script := true;
   204 trace_script := false;
   205 applyTactic 1 p (hd appltacs);
   206 val ((pt, p), _) = get_calc 1; show_pt pt;
   207 val appltacs = sel_appl_atomic_tacs pt p;
   208 (*applyTactic 1 p (hd appltacs); WAS assy: call by ([3], Pbl)*)
   209 
   210 "~~~~~ fun applyTactic, args:"; val ((cI:calcID), ip, tac) = (1, p, (hd appltacs));
   211 val ((pt, _), _) = get_calc cI;
   212 val p = get_pos cI 1;
   213 locatetac;
   214 locatetac tac;
   215 
   216 (*locatetac tac (pt, ip); (*WAS assy: call by ([3], Pbl)*)*)
   217 "~~~~~ fun locatetac, args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, ip));
   218 val (mI,m) = mk_tac'_ tac;
   219 applicable_in p pt m ; (*Appl*)
   220 member op = specsteps mI; (*false*)
   221 (*loc_solve_ (mI,m) ptp; (*Argument: (mI, m) : string * tac Reason: Can't unify tac_ with tac*)*)
   222 loc_solve_; (*without _ ??? result is -> lOc writing error ???*)
   223 (*val it = fn: string * tac_ -> ptree * (pos * pos_) -> lOc_*)
   224 (mI,m); (*string * tac*)
   225 ptp (*ptree * pos'*);
   226 "~~~~~ fun loc_solve_, args:"; val (m ,(pt,pos)) = ((mI,m), ptp);
   227 (*val (msg, cs') = solve m (pt, pos);
   228 (*Argument: m : string * tac Reason: Can't unify tac_ with tac (Different type constructors)*)*)
   229 m;
   230 (pt, pos);
   231 "~~~~~ fun solve, args:"; val ((mI,m), (pt, po as (p,p_))) = (m, (pt, pos));
   232 (*solve has still p_!!!!!!!!!!!!!!!!!!!!!!!!!*)
   233 
   234 e_metID = get_obj g_metID pt (par_pblobj pt p); (*false*)
   235 val ctxt = get_ctxt pt po;
   236 
   237 (*generate1 (assoc_thy (get_obj g_domID pt (par_pblobj pt p))) m (e_istate, ctxt) (p,p_) pt;
   238 (*Argument: m : tac Reason: Can't unify tac_ with tac (Different type constructors)*)*)
   239 (assoc_thy (get_obj g_domID pt (par_pblobj pt p)));
   240 assoc_thy;
   241 
   242 autoCalculate' 1 CompleteCalc;
   243 
   244 "----------- fun init_form, fun get_stac -------------------------";
   245 "----------- fun init_form, fun get_stac -------------------------";
   246 "----------- fun init_form, fun get_stac -------------------------";
   247 val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
   248 val (dI',pI',mI') = ("Test",["sqroot-test","univariate","equation","test"],
   249   ["Test","squ-equ-test-subpbl1"]);
   250 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   251 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   252 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   253 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   254 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   255 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   256 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   257 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   258 "~~~~~ fun me, args:"; val (_,tac) = nxt;
   259 "~~~~~ fun locatetac, args:"; val ptp as (pt, p) = (pt, p);
   260 val (mI,m) = mk_tac'_ tac;
   261 val Appl m = applicable_in p pt m;
   262 member op = specsteps mI; (*false*)
   263 "~~~~~ fun loc_solve_, args:"; val (m, (pt, pos) ) = ((mI, m), ptp);
   264 "~~~~~ fun solve, args:"; val (("Apply_Method", Apply_Method' (mI,_,_,_)), pos as (p,_)) = (m, pos);
   265 val {srls, ...} = get_met mI;
   266 val PblObj {meth=itms, ...} = get_obj I pt p;
   267 val thy' = get_obj g_domID pt p;
   268 val thy = assoc_thy thy';
   269 val (is as ScrState (env,_,_,_,_,_), ctxt, sc) = init_scrstate thy itms mI;
   270 val ini = init_form thy sc env;
   271 "----- fun init_form, args:"; val (Prog sc) = sc;
   272 "----- fun get_stac, args:"; val (y, h $ body) = (thy, sc);
   273 case get_stac thy sc of SOME (Free ("e_e", _)) => ()
   274 | _ => error "script: Const (?, ?) in script (as term) changed";;
   275 
   276 
   277 "----------- x+1=2 start SubProblem 'stac2tac_ TODO: no match for ";
   278 "----------- x+1=2 start SubProblem 'stac2tac_ TODO: no match for ";
   279 "----------- x+1=2 start SubProblem 'stac2tac_ TODO: no match for ";
   280 val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
   281 val (dI',pI',mI') =
   282   ("Test", ["sqroot-test","univariate","equation","test"],
   283    ["Test","squ-equ-test-subpbl1"]);
   284 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   285 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
   286 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
   287 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
   288 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
   289 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
   290 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
   291 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
   292 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
   293 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
   294 (*val (p,_,f,nxt,_,pt) = me nxt p [1] pt; WAS: Empty_Tac, helpless*)
   295 show_pt pt;
   296 "~~~~~ fun me, args:"; val (_,tac) = nxt;
   297 val (pt, p) = case locatetac tac (pt,p) of
   298 	("ok", (_, _, ptp))  => ptp | _ => error "script.sml locatetac";
   299 "~~~~~ fun step, args:"; val (ip as (_,p_), (ptp as (pt,p), tacis)) = (p, ((pt, e_pos'), []))
   300 val pIopt = get_pblID (pt,ip); (*SOME ["LINEAR", "univariate", "equation", "test"]*)
   301 tacis; (*= []*)
   302 member op = [Pbl,Met] p_ andalso is_none (get_obj g_env pt (fst p)); (*= false*)
   303 "~~~~~ fun nxt_solve_, args:"; val (ptp as (pt, pos as (p, p_))) = (pt, ip);
   304                                  (*WAS stac2tac_ TODO: no match for SubProblem*)
   305 val thy' = get_obj g_domID pt (par_pblobj pt p);
   306 val (srls, is, sc) = from_pblobj_or_detail' thy' (p,p_) pt;
   307 "~~~~~ fun next_tac, args:"; val (thy, (ptp as (pt,(p,_)):ptree * pos'), (sc as Prog (h $ body)), 
   308 	                               (ScrState (E,l,a,v,s,b), ctxt)) = ((thy',srls), (pt,pos), sc, is);
   309 l; (*= [R, L, R, L, R, R]*)
   310 val Appy (m', scrst as (_,_,_,v,_,_)) = nstep_up thy ptp sc E l Skip_ a v;
   311 "~~~~~ dont like to go into nstep_up...";
   312 val t = str2term ("SubProblem" ^ 
   313   "(Test', [LINEAR, univariate, equation, test], [Test, solve_linear])" ^
   314   "[BOOL (-1 + x = 0), REAL x]");
   315 val (tac, tac_) = stac2tac_ pt @{theory "Isac"} t; (*WAS stac2tac_ TODO: no match for SubProblem*)
   316 case tac_ of 
   317   Subproblem' _ => ()
   318 | _ => error "script.sml x+1=2 start SubProblem from script";
   319 
   320 
   321 "----------- Take as 1st stac in script --------------------------";
   322 "----------- Take as 1st stac in script --------------------------";
   323 "----------- Take as 1st stac in script --------------------------";
   324 val p = e_pos'; val c = []; 
   325 val (p,_,f,nxt,_,pt) = 
   326     CalcTreeTEST 
   327         [(["functionTerm (x^^^2 + 1)", "integrateBy x", "antiDerivative FF"],
   328           ("Integrate", ["integrate","function"], ["diff","integration"]))];
   329 val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = ("Tac ", ...) --> Add_Given...*)
   330 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   331 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   332 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   333 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   334 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   335 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   336 case nxt of (_, Apply_Method ["diff", "integration"]) => ()
   337           | _ => error "integrate.sml -- me method [diff,integration] -- spec";
   338 "----- step 8: returns nxt = Rewrite_Set_Inst ([\"(bdv, x)\"],\"integration\")";
   339 
   340 "~~~~~ fun me, args:"; val (((_,tac):tac'_), (p:pos'), _, (pt:ptree)) = (nxt, p, c, pt);
   341 "~~~~~ fun locatetac, args:"; val (tac, (ptp as (pt, p))) = (tac, (pt,p));
   342 val (mI,m) = mk_tac'_ tac;
   343 val Appl m = applicable_in p pt m;
   344 member op = specsteps mI (*false*);
   345 "~~~~~ fun loc_solve_, args:"; val (m, (pt,pos)) = ((mI,m), ptp);
   346 "~~~~~ fun solve, args:"; val ((_, m as Apply_Method' (mI, _, _, _)), (pt, (pos as (p,_)))) = 
   347                             (m, (pt, pos));
   348 val {srls, ...} = get_met mI;
   349         val PblObj {meth=itms, ...} = get_obj I pt p;
   350         val thy' = get_obj g_domID pt p;
   351         val thy = assoc_thy thy';
   352         val (is as ScrState (env,_,_,_,_,_), ctxt, sc) = init_scrstate thy itms mI;
   353         val ini = init_form thy sc env;
   354         val p = lev_dn p;
   355 ini = NONE; (*true*)
   356             val (m', (is', ctxt'), _) = next_tac (thy', srls) (pt, (p, Res)) sc (is, ctxt);
   357 	            val d = e_rls (*FIXME: get simplifier from domID*);
   358 "~~~~~ fun locate_gen, args:"; val ((ts as (thy',srls)), (m:tac_), ((pt,p):ptree * pos'), 
   359 	                     (scr as Prog (h $ body),d), (ScrState (E,l,a,v,S,b), ctxt)) = 
   360                    ((thy',srls), m', (pt,(p, Res)), (sc,d), (is', ctxt'));
   361 val thy = assoc_thy thy';
   362 l = [] orelse ((*init.in solve..Apply_Method...*)
   363 			         (last_elem o fst) p = 0 andalso snd p = Res); (*true*)
   364 "~~~~~ fun assy, args:"; val (ya, (is as (E,l,a,v,S,b),ss), 
   365                    (Const ("HOL.Let",_) $ e $ (Abs (id,T,body)))) = 
   366                  ((thy',ctxt,srls,d,Aundef), ((E,[R],a,v,S,b), [(m,EmptyMout,pt,p,[])]), body);
   367  (*check: true*) term2str e = "Take (Integral f_f D v_v)";
   368 "~~~~~ fun assy, args:"; val ((thy',ctxt,sr,d,ap), (is as (E,l,a,v,S,b), (m,_,pt,(p,p_),c)::ss), t) = 
   369                            (ya, ((E , l@[L,R], a,v,S,b),ss), e);
   370 val (a', STac stac) = handle_leaf "locate" thy' sr E a v t;
   371 (*             val ctxt = get_ctxt pt (p,p_)
   372 exception PTREE "get_obj: pos = [0] does not exist" raised 
   373 (line 908 of "/usr/local/isabisac/src/Tools/isac/Interpret/ctree.sml")*)
   374 
   375 
   376 "----------- 'trace_script' from outside 'fun me '----------------";
   377 "----------- 'trace_script' from outside 'fun me '----------------";
   378 "----------- 'trace_script' from outside 'fun me '----------------";
   379 val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
   380 val (dI',pI',mI') =
   381    ("Test", ["sqroot-test","univariate","equation","test"],
   382     ["Test","squ-equ-test-subpbl1"]);
   383 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   384 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   385 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   386 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   387 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   388 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   389 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   390 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "squ-equ-test-subpbl1"]*)
   391 (*from_pblobj_or_detail': no istate = from_pblobj_or_detail' "Isac" p pt;*)
   392 
   393 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*---------------------------------------------------*)
   394 val (p'''', pt'''') = (p, pt);
   395 f2str f = "x + 1 = 2";          snd nxt = Rewrite_Set "norm_equation";
   396 val (p, p_) = p(* = ([1], Frm)*);
   397 val (srls, (ScrState scrstate, ctxt), Prog sc) = from_pblobj_or_detail' "Isac" (p, p_) pt;
   398 val (env, loc_, curry_arg, res, Safe, true) = scrstate;
   399   env2str env = "[\"\n(e_e, x + 1 = 2)\",\"\n(v_v, x)\"]";
   400   loc_ = [];
   401   curry_arg = NONE;
   402   term2str res = "??.empty";                     (* scrstate before starting interpretation *)
   403 (*term2str (go loc_ sc) = "Prog Solve_root_equation e_e v_v = ...*)
   404 
   405 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   406 val (p'''', pt'''') = (p, pt);
   407 f2str f = "x + 1 + -1 * 2 = 0"; snd nxt = Rewrite_Set "Test_simplify";
   408 val (p, p_) = p(* = ([1], Res)*);
   409 val (srls, (ScrState scrstate, ctxt), Prog sc) = from_pblobj_or_detail' "Isac" (p, p_) pt;
   410 val (env, loc_, curry_arg, res, Safe, true) = scrstate;
   411   env2str env = "[\"\n(e_e, x + 1 = 2)\",\"\n(v_v, x)\"]";
   412   loc_ = [R, L, R, L, L, R, R];
   413   curry_arg = SOME (str2term "e_e::bool");
   414   term2str res = "x + 1 + -1 * 2 = 0";(* scrstate after norm_equation, before Test_simplify *)
   415 term2str (go loc_ sc) = "Rewrite_Set norm_equation False";
   416 
   417 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   418 val (p'''', pt'''') = (p, pt);
   419 f2str f = "-1 + x = 0"; snd nxt = Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"]);
   420 val (p, p_) = p(* = ([2], Res)*);
   421 val (srls, (ScrState scrstate, ctxt), Prog sc) = from_pblobj_or_detail' "Isac" (p, p_) pt;
   422 val (env, loc_, curry_arg, res, Safe, false) = scrstate;
   423   env2str env = "[\"\n(e_e, x + 1 = 2)\",\"\n(v_v, x)\"]";
   424   loc_ = [R, L, R, L, R, R];
   425   curry_arg = SOME (str2term "e_e::bool");
   426   term2str res = "-1 + x = 0";           (* scrstate after Test_simplify, before Subproblem *)
   427 term2str (go loc_ sc) = "Rewrite_Set Test_simplify False";
   428 
   429 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   430 val (p'''', pt'''') = (p, pt);     (*f2str f = exception Match; ...is a model, not a formula*)
   431 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   432 val (p'''', pt'''') = (p, pt);
   433 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   434 val (p'''', pt'''') = (p, pt);
   435 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   436 val (p'''', pt'''') = (p, pt);
   437 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   438 val (p'''', pt'''') = (p, pt);
   439 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   440 val (p'''', pt'''') = (p, pt);
   441 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   442 val (p'''', pt'''') = (p, pt);
   443 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*nxt = Apply_Method ["Test", "solve_linear"]*)
   444 (*from_pblobj_or_detail': no istate = from_pblobj_or_detail' "Isac" p pt;*)
   445 
   446 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*---------------------------------------------------*)
   447 val (p'''', pt'''') = (p, pt);
   448 f2str f = "-1 + x = 0"; snd nxt = Rewrite_Set_Inst (["(bdv, x)"], "isolate_bdv");
   449 val (p, p_) = p(* = ([3, 1], Frm)*);
   450 val (srls, (ScrState scrstate, ctxt), Prog sc) = from_pblobj_or_detail' "Isac" (p, p_) pt;
   451 val (env, loc_, curry_arg, res, Safe, true) = scrstate;
   452   env2str env = "[\"\n(e_e, -1 + x = 0)\",\"\n(v_v, x)\"]";
   453   loc_ = [];
   454   curry_arg = NONE;
   455   term2str res = "??.empty";                     (* scrstate before starting interpretation *)
   456 (*term2str (go loc_ sc) = "Prog Solve_linear e_e v_v = ...*)
   457 
   458 val (p,_,f,nxt,_,pt) = me nxt p'''' [] pt''''; (*-------------------------------------------*)
   459 val (p'''', pt'''') = (p, pt);
   460 f2str f = "x = 0 + -1 * -1"; snd nxt = Rewrite_Set "Test_simplify";
   461 val (p, p_) = p(* = ([3, 1], Res)*);
   462 val (srls, (ScrState scrstate, ctxt), Prog sc) = from_pblobj_or_detail' "Isac" (p, p_) pt;
   463 val (env, loc_, curry_arg, res, Safe, true) = scrstate;
   464   env2str env = "[\"\n(e_e, -1 + x = 0)\",\"\n(v_v, x)\"]";
   465   loc_ = [R, L, R, L, R, L, R];
   466   curry_arg = SOME (str2term "e_e::bool");
   467   term2str res = "x = 0 + -1 * -1";(* scrstate after isolate_bdv, before Test_simplify *)
   468 term2str (go loc_ sc) = "Rewrite_Set_Inst [(bdv, v_v)] isolate_bdv False";
   469 
   470 "----------- fun sel_rules ---------------------------------------";
   471 "----------- fun sel_rules ---------------------------------------";
   472 "----------- fun sel_rules ---------------------------------------";
   473 (* compare test/../interface.sml
   474 "--------- getTactic, fetchApplicableTactics ------------";
   475 *)
   476  reset_states ();
   477  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   478    ("Test", ["sqroot-test","univariate","equation","test"],
   479     ["Test","squ-equ-test-subpbl1"]))];
   480  Iterator 1;
   481  moveActiveRoot 1;
   482  autoCalculate' 1 CompleteCalc;
   483  val ((pt,_),_) = get_calc 1;
   484  show_pt pt;
   485 
   486 (*UC\label{SOLVE:MANUAL:TACTIC:listall} UC 30.3.2.2 p.175*)
   487  val tacs = sel_rules pt ([],Pbl);
   488  if tacs = [Apply_Method ["Test", "squ-equ-test-subpbl1"]] then ()
   489  else error "script.sml: diff.behav. in sel_rules ([],Pbl)";
   490 
   491  val tacs = sel_rules pt ([1],Res);
   492  if tacs = [Rewrite_Set "norm_equation", Rewrite_Set "Test_simplify",
   493       Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"]),
   494       Check_elementwise "Assumptions"] then ()
   495  else error "script.sml: diff.behav. in sel_rules ([1],Res)";
   496 
   497  val tacs = sel_rules pt ([3],Pbl);
   498  if tacs = [Apply_Method ["Test", "solve_linear"]] then ()
   499  else error "script.sml: diff.behav. in sel_rules ([3],Pbl)";
   500 
   501  val tacs = sel_rules pt ([3,1],Res);
   502  if tacs = [Rewrite_Set_Inst (["(bdv, x)"], "isolate_bdv"),
   503       Rewrite_Set "Test_simplify"] then ()
   504  else error "script.sml: diff.behav. in sel_rules ([3,1],Res)";
   505 
   506  val tacs = sel_rules pt ([3],Res);
   507  if tacs = [Rewrite_Set "norm_equation", Rewrite_Set "Test_simplify",
   508       Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"]),
   509       Check_elementwise "Assumptions"] then ()
   510  else error "script.sml: diff.behav. in sel_rules ([3],Res)";
   511 
   512  val tacs = (sel_rules pt ([],Res)) handle PTREE str => [Tac str];
   513  if tacs = [Tac "no tactics applicable at the end of a calculation"] then ()
   514  else error "script.sml: diff.behav. in sel_rules ([],Res)";
   515 
   516 "----------- fun sel_appl_atomic_tacs ----------------------------";
   517 "----------- fun sel_appl_atomic_tacs ----------------------------";
   518 "----------- fun sel_appl_atomic_tacs ----------------------------";
   519  reset_states ();
   520  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   521    ("Test", ["sqroot-test","univariate","equation","test"],
   522     ["Test","squ-equ-test-subpbl1"]))];
   523  Iterator 1;
   524  moveActiveRoot 1;
   525  autoCalculate' 1 CompleteCalc;
   526 
   527 (*UC\label{SOLVE:MANUAL:TACTIC:listall} UC 30.3.2.2 p.175*)
   528  fetchApplicableTactics 1 99999 ([],Pbl);
   529 
   530  fetchApplicableTactics 1 99999 ([1],Res);
   531 "~~~~~ fun fetchApplicableTactics, args:"; val (cI, (scope:int), (p:pos')) = (1, 99999, ([1],Res));
   532 val ((pt, _), _) = get_calc cI;
   533 (*version 1:*)
   534 if sel_rules pt p = [Rewrite_Set "norm_equation", Rewrite_Set "Test_simplify",
   535   Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"]),
   536   Check_elementwise "Assumptions"] then ()
   537 else error "fetchApplicableTactics ([1],Res) changed";
   538 (*version 2:*)
   539 (*WAS:
   540 sel_appl_atomic_tacs pt p;
   541 ...
   542 ### atomic_appl_tacs: not impl. for tac='Subproblem(Test,["LINEAR","univariate","equation","test"])' 
   543 ### atomic_appl_tacs: not impl. for tac = 'Check_elementwise "Assumptions"' 
   544 *)
   545 
   546 "~~~~~ fun sel_appl_atomic_tacs, args:"; val (pt, (p,p_)) = (pt, p);
   547 is_spec_pos p_ = false;
   548         val pp = par_pblobj pt p
   549         val thy' = (get_obj g_domID pt pp):theory'
   550         val thy = assoc_thy thy'
   551         val metID = get_obj g_metID pt pp
   552         val metID' =
   553           if metID = e_metID 
   554           then (thd3 o snd3) (get_obj g_origin pt pp)
   555           else metID
   556         val {scr=Prog sc,srls,erls,rew_ord'=ro,...} = get_met metID'
   557         val ScrState (env,_,a,v,_,_) = get_istate pt (p,p_)
   558         val alltacs = (*we expect at least 1 stac in a script*)
   559           map ((stac2tac pt thy) o rep_stacexpr o #2 o
   560            (handle_leaf "selrul" thy' srls env a v)) (stacpbls sc)
   561         val f =
   562           case p_ of
   563               Frm => get_obj g_form pt p
   564             | Res => (fst o (get_obj g_result pt)) p
   565 (*WN120611 stopped and took version 1 again for fetchApplicableTactics !
   566 (distinct o flat o (map (atomic_appl_tacs thy ro erls f))) alltacs
   567 ...
   568 ### atomic_appl_tacs: not impl. for tac='Subproblem(Test,["LINEAR","univariate","equation","test"])' 
   569 ### atomic_appl_tacs: not impl. for tac = 'Check_elementwise "Assumptions"' 
   570 *)
   571