1 (* Title: test/../script.sml
2 Author: Walther Neuper 050908
3 (c) copyright due to lincense terms.
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 "-----------------------------------------------------------------";
15 "-----------------------------------------------------------------";
16 "-----------------------------------------------------------------";
18 val thy= @{theory Isac};
20 "----------- WN0509 why does next_tac doesnt find Substitute -----";
21 "----------- WN0509 why does next_tac doesnt find Substitute -----";
22 "----------- WN0509 why does next_tac doesnt find Substitute -----";
24 (*replace met 'IntegrierenUndKonstanteBestimmen' with this script...*)
26 "Script BiegelinieScript " ^
27 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real) " ^
28 "(rb_rb::bool list) (rm_rm::bool list) = " ^
29 " (let q___q = Take (M_b v_v = q__q); " ^
30 " (M1__M1::bool) = ((Substitute [v_v = 0])) q___q " ^
33 val sc' = ((inst_abs thy) o term_of o the o (parse thy)) str;
36 "Script BiegelinieScript " ^
37 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real) " ^
38 "(rb_rb::bool list) (rm_rm::bool list) = " ^
39 " (M1__M1::bool) = ((Substitute [v_v = 0]) @@ " ^
40 " in True)";(*..doesnt find Substitute with ..@@ !!!!!!!!!!!!!!!!!!!!!*)
43 "Script BiegelinieScript " ^
44 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real) " ^
45 "(rb_rb::bool list) (rm_rm::bool list) = " ^
46 " (let q___q = Take (q_q v_v = q__q); " ^
47 " (M1__M1::bool) = Substitute [v_v = 0] q___q ; " ^
48 " M1__m1 = Substitute [M_b 0 = 0] M1__M1 " ^
52 "Script BiegelinieScript " ^
53 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real) " ^
54 "(rb_rb::bool list) (rm_rm::bool list) = " ^
55 " (let q___q = Take (q_q v_v = q__q); " ^
56 " (M1__M1::bool) = Substitute [v_v = 0] q___q ; " ^
57 " M1__M1 = Substitute [v_v = 1] q___q ; " ^
58 " M1__M1 = Substitute [v_v = 2] q___q ; " ^
59 " M1__M1 = Substitute [v_v = 3] q___q ; " ^
60 " M1__M1 = Substitute [M_b 0 = 0] M1__M1 " ^
64 "Script BiegelinieScript " ^
65 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real) " ^
66 "(rb_rb::bool list) (rm_rm::bool list) = " ^
67 " (let q___q = Take (M_b v_v = q__q); " ^
68 " (M1__M1::bool) = Substitute [v_v = 0] q___q ; " ^
69 " M2__M2 = Take q___q ; " ^
70 " M2__M2 = Substitute [v_v = 2] q___q " ^
74 val sc' = ((inst_abs thy) o term_of o the o (parse thy)) str;
77 val {scr = Script sc,...} = get_met ["IntegrierenUndKonstanteBestimmen"];
78 (*---------------------------------------------------------------------
79 if sc = sc' then () else error"script.sml, doesnt find Substitute #1";
80 ---------------------------------------------------------------------*)
82 "----------- WN0509 Substitute 2nd part --------------------------";
83 "----------- WN0509 Substitute 2nd part --------------------------";
84 "----------- WN0509 Substitute 2nd part --------------------------";
85 (*replace met 'IntegrierenUndKonstanteBestimmen' with this script...*)
86 val str = (*Substitute ; Substitute works*)
87 "Script BiegelinieScript " ^
88 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real) " ^
89 "(rb_rb::bool list) (rm_rm::bool list) = "^
90 (*begin after the 2nd integrate*)
91 " (let M__M = Take (M_b v_v = q__q); " ^
92 " e1__e1 = nth_nth 1 rm_rm ; " ^
93 " (x1__x1::real) = argument_in (lhs e1__e1); " ^
94 " (M1__M1::bool) = Substitute [v_v = x1__x1] M__M; " ^
95 " M1__M1 = Substitute [e1__e1] M1__M1 " ^
98 val sc' = ((inst_abs thy) o term_of o the o (parse thy)) str;
101 val str = (*Substitute @@ Substitute does NOT work???*)
102 "Script BiegelinieScript " ^
103 "(l_l::real) (q__q::real) (v_v::real) (b_b::real=>real) " ^
104 "(rb_rb::bool list) (rm_rm::bool list) = "^
105 (*begin after the 2nd integrate*)
106 " (let M__M = Take (M_b v_v = q__q); " ^
107 " e1__e1 = nth_nth 1 rm_rm ; " ^
108 " (x1__x1::real) = argument_in (lhs e1__e1); " ^
109 " (M1__M1::bool) = ((Substitute [v_v = x1__x1]) @@ " ^
110 " (Substitute [e1__e1])) M__M " ^
114 val {scr = Script sc,...} = get_met ["IntegrierenUndKonstanteBestimmen"];
115 (*---------------------------------------------------------------------
116 if sc = sc' then () else error "script.sml, doesnt find Substitute #1";
117 ---------------------------------------------------------------------*)
118 val fmz = ["Traegerlaenge L",
119 "Streckenlast (- q_0 * x^^^2 / 2 + x * c + c_2)",
121 "RandbedingungenBiegung [y 0 = 0, y L = 0]",
122 "RandbedingungenMoment [M_b 0 = 0, M_b L = 0]",
123 "FunktionsVariable x"];
125 ("Biegelinie",["MomentBestimmte","Biegelinien"],
126 ["IntegrierenUndKonstanteBestimmen"]);
127 val p = e_pos'; val c = [];
128 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
129 val (p,_,f,nxt,_,pt) = me nxt p c pt; val (p,_,f,nxt,_,pt) = me nxt p c pt;
130 val (p,_,f,nxt,_,pt) = me nxt p c pt; val (p,_,f,nxt,_,pt) = me nxt p c pt;
131 val (p,_,f,nxt,_,pt) = me nxt p c pt; val (p,_,f,nxt,_,pt) = me nxt p c pt;
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;
135 val (p,_,f,nxt,_,pt) = me nxt p c pt;
136 case nxt of (_, Apply_Method ["IntegrierenUndKonstanteBestimmen"]) => ()
137 | _ => error "script.sml, doesnt find Substitute #2";
138 (* ERROR: caused by f2str f *)
141 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f(*------------------------*);
142 trace_rewrite:=false;
143 (*Exception TYPE raised:
144 Illegal type for constant "HOL.eq" :: "[real, bool] => bool"
145 Atools.argument'_in (Tools.lhs (ListG.nth_ (1 + -1 + -1) [])) =
146 ListG.nth_ (1 + -1 + -1) []
149 ("Illegal type for constant \"op =\" :: \"[real, bool] => bool\"",
151 [Const ("HOL.Trueprop", "bool => prop") $
152 (Const ("HOL.eq", "[RealDef.real, bool] => bool") $ ... $ ...)])
154 ... this was because eval_argument_in took "argument_in (lhs (M_b 0 = 0))"
155 ie. the argument had not been simplified before ^^^^^^^^^^^^^^^
156 thus corrected eval_argument_in OK*)
157 val {srls,...} = get_met ["IntegrierenUndKonstanteBestimmen"];
158 val e1__e1 = str2term "NTH 1 [M_b 0 = 0, M_b L = 0]";
159 val e1__e1 = eval_listexpr_ @{theory Biegelinie} srls e1__e1; term2str e1__e1;
160 if term2str e1__e1 = "M_b 0 = 0"
162 else error"script.sml diff.beh. eval_listexpr_ nth_nth 1 [...";
164 (*TODO.WN050913 ??? doesnt eval_listexpr_ go into subterms ???...
165 val x1__ = str2term"argument_in (lhs (M_b 0 = 0))";
166 val x1__ = eval_listexpr_ Biegelinie.thy srls x1__; term2str x1__;
168 calculate_ Biegelinie.thy ("Tools.lhs", eval_rhs"eval_lhs_") x1__;
169 val SOME (str, t) = eval_lhs 0 "Tools.lhs" (str2term"lhs (M_b 0 = 0)") 0;*)
171 val l__l = str2term "lhs (M_b 0 = 0)";
172 val l__l = eval_listexpr_ @{theory Biegelinie} srls l__l; term2str l__l;
173 val SOME (str, t) = eval_lhs 0 "Tools.lhs" (str2term "lhs (M_b 0 = 0)") 0;
175 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f (*------------------------*);
176 if nxt = ("Rewrite", Rewrite ("Belastung_Querkraft", "Biegelinie.Belastung_Querkraft"))
177 then () else error "";
180 "----------- fun sel_appl_atomic_tacs ----------------------------";
181 "----------- fun sel_appl_atomic_tacs ----------------------------";
182 "----------- fun sel_appl_atomic_tacs ----------------------------";
185 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
186 ("Test", ["sqroot-test","univariate","equation","test"],
187 ["Test","squ-equ-test-subpbl1"]))];
190 autoCalculate 1 CompleteCalcHead;
191 autoCalculate 1 (Step 1);
192 autoCalculate 1 (Step 1);
193 val ((pt, p), _) = get_calc 1; show_pt pt;
194 val appltacs = sel_appl_atomic_tacs pt p;
196 (*========== inhibit exn AK110721 ================================================
197 (*(*These SHOULD be the same*)
200 [Rewrite ("radd_commute", "?m + ?n = ?n + ?m"),
201 Rewrite ("radd_assoc", "?m + ?n + ?k = ?m + (?n + ?k)"),
202 Calculate "TIMES"];*)
205 [Rewrite ("radd_commute", "?m + ?n = ?n + ?m"),
206 Rewrite ("radd_assoc", "?m + ?n + ?k = ?m + (?n + ?k)"),
207 Calculate "TIMES"] then ()
208 else error "script.sml fun sel_appl_atomic_tacs diff.behav.";
209 ========== inhibit exn AK110721 ================================================*)
211 trace_script := true;
212 trace_script := false;
213 applyTactic 1 p (hd appltacs);
214 val ((pt, p), _) = get_calc 1; show_pt pt;
215 val appltacs = sel_appl_atomic_tacs pt p;
217 (*(* AK110722 Debugging start*)
218 (*applyTactic 1 p (hd appltacs); WAS assy: call by ([3], Pbl)*)
219 "~~~~~ fun applyTactic, args:"; val ((cI:calcID), ip, tac) = (1, p, (hd appltacs));
220 val ((pt, _), _) = get_calc cI;
221 val p = get_pos cI 1;
227 (*locatetac tac (pt, ip); (*WAS assy: call by ([3], Pbl)*)*)
228 "~~~~~ fun locatetac, args:"; val (tac, (ptp as (pt, p))) = (tac, (pt, ip));
229 val (mI,m) = mk_tac'_ tac;
231 applicable_in p pt m ; (*Appl*)
233 member op = specsteps mI; (*false*)
235 (*loc_solve_ (mI,m) ptp; (*Argument: (mI, m) : string * tac Reason: Can't unify tac_ with tac*)*)
236 loc_solve_; (*without _ ??? result is -> lOc writing error ???*)
237 (*val it = fn: string * tac_ -> ptree * (pos * pos_) -> lOc_*)
238 (mI,m); (*string * tac*)
239 ptp (*ptree * pos'*);
241 "~~~~~ fun loc_solve_, args:"; val (m ,(pt,pos)) = ((mI,m), ptp);
242 (*val (msg, cs') = solve m (pt, pos);
243 (*Argument: m : string * tac Reason: Can't unify tac_ with tac (Different type constructors)*)*)
248 "~~~~~ fun solve, args:"; val ((mI,m), (pt, po as (p,p_))) = (m, (pt, pos));
249 (*solve has still p_!!!!!!!!!!!!!!!!!!!!!!!!!*)
251 e_metID = get_obj g_metID pt (par_pblobj pt p); (*false*)
252 val ctxt = get_ctxt pt po;
254 (*generate1 (assoc_thy (get_obj g_domID pt (par_pblobj pt p))) m (e_istate, ctxt) (p,p_) pt;
255 (*Argument: m : tac Reason: Can't unify tac_ with tac (Different type constructors)*)*)
256 (assoc_thy (get_obj g_domID pt (par_pblobj pt p)));
259 (*not finished - error continues in fun generate1*)
260 (* AK110722 Debugging end*)*)
261 (*========== inhibit exn AK110721 ================================================
262 "----- WN080102 these vvv do not work, because locatetac starts the search" ^
264 (* AK110722 ERROR: assy: call by ([3], Pbl) *)
265 applyTactic 1 p (hd appltacs);
266 ============ inhibit exn AK110721 ==============================================*)
268 autoCalculate 1 CompleteCalc;
270 "----------- fun init_form, fun get_stac -------------------------";
271 "----------- fun init_form, fun get_stac -------------------------";
272 "----------- fun init_form, fun get_stac -------------------------";
273 val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
274 val (dI',pI',mI') = ("Test",["sqroot-test","univariate","equation","test"],
275 ["Test","squ-equ-test-subpbl1"]);
276 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
277 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
278 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
279 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
280 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
281 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
282 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
283 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
284 "~~~~~ fun me, args:"; val (_,tac) = nxt;
285 "~~~~~ fun locatetac, args:"; val ptp as (pt, p) = (pt, p);
286 val (mI,m) = mk_tac'_ tac;
287 val Appl m = applicable_in p pt m;
288 member op = specsteps mI; (*false*)
289 "~~~~~ fun loc_solve_, args:"; val (m, (pt, pos) ) = ((mI, m), ptp);
290 "~~~~~ fun solve, args:"; val (("Apply_Method", Apply_Method' (mI,_,_,_)), pos as (p,_)) = (m, pos);
291 val {srls, ...} = get_met mI;
292 val PblObj {meth=itms, ...} = get_obj I pt p;
293 val thy' = get_obj g_domID pt p;
294 val thy = assoc_thy thy';
295 val (is as ScrState (env,_,_,_,_,_), ctxt, sc) = init_scrstate thy itms mI;
296 val ini = init_form thy sc env;
297 "----- fun init_form, args:"; val (Script sc) = sc;
298 "----- fun get_stac, args:"; val (y, h $ body) = (thy, sc);
299 case get_stac thy sc of SOME (Free ("e_e", _)) => ()
300 | _ => error "script: Const (?, ?) in script (as term) changed";;
303 "----------- x+1=2 start SubProblem 'stac2tac_ TODO: no match for ";
304 "----------- x+1=2 start SubProblem 'stac2tac_ TODO: no match for ";
305 "----------- x+1=2 start SubProblem 'stac2tac_ TODO: no match for ";
306 val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
308 ("Test", ["sqroot-test","univariate","equation","test"],
309 ["Test","squ-equ-test-subpbl1"]);
310 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
311 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
312 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
313 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
314 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
315 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
316 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
317 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
318 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
319 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
320 (*val (p,_,f,nxt,_,pt) = me nxt p [1] pt; WAS: Empty_Tac, helpless*)
322 "~~~~~ fun me, args:"; val (_,tac) = nxt;
323 val (pt, p) = case locatetac tac (pt,p) of
324 ("ok", (_, _, ptp)) => ptp | _ => error "script.sml locatetac";
325 "~~~~~ fun step, args:"; val (ip as (_,p_), (ptp as (pt,p), tacis)) = (p, ((pt, e_pos'), []))
326 val pIopt = get_pblID (pt,ip); (*SOME ["linear", "univariate", "equation", "test"]*)
328 member op = [Pbl,Met] p_ andalso is_none (get_obj g_env pt (fst p)); (*= false*)
329 "~~~~~ fun nxt_solve_, args:"; val (ptp as (pt, pos as (p, p_))) = (pt, ip);
330 (*WAS stac2tac_ TODO: no match for SubProblem*)
331 val thy' = get_obj g_domID pt (par_pblobj pt p);
332 val (srls, is, sc) = from_pblobj_or_detail' thy' (p,p_) pt;
333 "~~~~~ fun next_tac, args:"; val (thy, (ptp as (pt,(p,_)):ptree * pos'), (sc as Script (h $ body)),
334 (ScrState (E,l,a,v,s,b), ctxt)) = ((thy',srls), (pt,pos), sc, is);
335 l; (*= [R, L, R, L, R, R]*)
336 val Appy (m', scrst as (_,_,_,v,_,_)) = nstep_up thy ptp sc E l Skip_ a v;
337 "~~~~~ dont like to go into nstep_up...";
338 val t = str2term ("SubProblem" ^
339 "(Test', [linear, univariate, equation, test], [Test, solve_linear])" ^
340 "[BOOL (-1 + x = 0), REAL x]");
341 val (tac, tac_) = stac2tac_ pt @{theory "Isac"} t; (*WAS stac2tac_ TODO: no match for SubProblem*)
344 | _ => error "script.sml x+1=2 start SubProblem from script";
347 "----------- Take as 1st stac in script --------------------------";
348 "----------- Take as 1st stac in script --------------------------";
349 "----------- Take as 1st stac in script --------------------------";
350 val p = e_pos'; val c = [];
351 val (p,_,f,nxt,_,pt) =
353 [(["functionTerm (x^^^2 + 1)", "integrateBy x", "antiDerivative FF"],
354 ("Integrate", ["integrate","function"], ["diff","integration"]))];
355 val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = ("Tac ", ...) --> Add_Given...*)
356 val (p,_,f,nxt,_,pt) = me nxt p c pt;
357 val (p,_,f,nxt,_,pt) = me nxt p c pt;
358 val (p,_,f,nxt,_,pt) = me nxt p c pt;
359 val (p,_,f,nxt,_,pt) = me nxt p c pt;
360 val (p,_,f,nxt,_,pt) = me nxt p c pt;
361 val (p,_,f,nxt,_,pt) = me nxt p c pt;
362 case nxt of (_, Apply_Method ["diff", "integration"]) => ()
363 | _ => error "integrate.sml -- me method [diff,integration] -- spec";
364 "----- step 8: returns nxt = Rewrite_Set_Inst ([\"(bdv, x)\"],\"integration\")";
366 "~~~~~ fun me, args:"; val (((_,tac):tac'_), (p:pos'), _, (pt:ptree)) = (nxt, p, c, pt);
367 "~~~~~ fun locatetac, args:"; val (tac, (ptp as (pt, p))) = (tac, (pt,p));
368 val (mI,m) = mk_tac'_ tac;
369 val Appl m = applicable_in p pt m;
370 member op = specsteps mI (*false*);
371 "~~~~~ fun loc_solve_, args:"; val (m, (pt,pos)) = ((mI,m), ptp);
372 "~~~~~ fun solve, args:"; val ((_, m as Apply_Method' (mI, _, _, _)), (pt, (pos as (p,_)))) =
374 val {srls, ...} = get_met mI;
375 val PblObj {meth=itms, ...} = get_obj I pt p;
376 val thy' = get_obj g_domID pt p;
377 val thy = assoc_thy thy';
378 val (is as ScrState (env,_,_,_,_,_), ctxt, sc) = init_scrstate thy itms mI;
379 val ini = init_form thy sc env;
382 val (m', (is', ctxt'), _) = next_tac (thy', srls) (pt, (p, Res)) sc (is, ctxt);
383 val d = e_rls (*FIXME: get simplifier from domID*);
384 "~~~~~ fun locate_gen, args:"; val ((ts as (thy',srls)), (m:tac_), ((pt,p):ptree * pos'),
385 (scr as Script (h $ body),d), (ScrState (E,l,a,v,S,b), ctxt)) =
386 ((thy',srls), m', (pt,(p, Res)), (sc,d), (is', ctxt'));
387 val thy = assoc_thy thy';
388 l = [] orelse ((*init.in solve..Apply_Method...*)
389 (last_elem o fst) p = 0 andalso snd p = Res); (*true*)
390 "~~~~~ fun assy, args:"; val (ya, (is as (E,l,a,v,S,b),ss),
391 (Const ("HOL.Let",_) $ e $ (Abs (id,T,body)))) =
392 ((thy',ctxt,srls,d,Aundef), ((E,[R],a,v,S,b), [(m,EmptyMout,pt,p,[])]), body);
393 (*check: true*) term2str e = "Take (Integral f_f D v_v)";
394 "~~~~~ fun assy, args:"; val ((thy',ctxt,sr,d,ap), (is as (E,l,a,v,S,b), (m,_,pt,(p,p_),c)::ss), t) =
395 (ya, ((E , l@[L,R], a,v,S,b),ss), e);
396 val (a', STac stac) = handle_leaf "locate" thy' sr E a v t;
397 (* val ctxt = get_ctxt pt (p,p_)
398 exception PTREE "get_obj: pos = [0] does not exist" raised
399 (line 908 of "/usr/local/isabisac/src/Tools/isac/Interpret/ctree.sml")*)