1 (* Title: solve an example by interpreting a method's script
2 Author: Walther Neuper 1999
3 (c) copyright due to lincense terms.
4 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
5 10 20 30 40 50 60 70 80 90 100
8 fun safe (ScrState (_,_,_,_,s,_)) = s
9 | safe (RrlsState _) = Safe;
12 type tac'_ = mstID * tac; (*DG <-> ME*)
13 val e_tac'_ = ("Empty_Tac", Empty_Tac):tac'_;
15 fun mk_tac'_ m = case m of
16 Init_Proof (ppc, spec) => ("Init_Proof", Init_Proof (ppc, spec ))
17 | Model_Problem => ("Model_Problem", Model_Problem)
18 | Refine_Tacitly pblID => ("Refine_Tacitly", Refine_Tacitly pblID)
19 | Refine_Problem pblID => ("Refine_Problem", Refine_Problem pblID)
20 | Add_Given cterm' => ("Add_Given", Add_Given cterm')
21 | Del_Given cterm' => ("Del_Given", Del_Given cterm')
22 | Add_Find cterm' => ("Add_Find", Add_Find cterm')
23 | Del_Find cterm' => ("Del_Find", Del_Find cterm')
24 | Add_Relation cterm' => ("Add_Relation", Add_Relation cterm')
25 | Del_Relation cterm' => ("Del_Relation", Del_Relation cterm')
27 | Specify_Theory domID => ("Specify_Theory", Specify_Theory domID)
28 | Specify_Problem pblID => ("Specify_Problem", Specify_Problem pblID)
29 | Specify_Method metID => ("Specify_Method", Specify_Method metID)
30 | Apply_Method metID => ("Apply_Method", Apply_Method metID)
31 | Check_Postcond pblID => ("Check_Postcond", Check_Postcond pblID)
32 | Free_Solve => ("Free_Solve",Free_Solve)
34 | Rewrite_Inst (subs, thm') => ("Rewrite_Inst", Rewrite_Inst (subs, thm'))
35 | Rewrite thm' => ("Rewrite", Rewrite thm')
36 | Rewrite_Asm thm' => ("Rewrite_Asm", Rewrite_Asm thm')
37 | Rewrite_Set_Inst (subs, rls')
38 => ("Rewrite_Set_Inst", Rewrite_Set_Inst (subs, rls'))
39 | Rewrite_Set rls' => ("Rewrite_Set", Rewrite_Set rls')
40 | End_Ruleset => ("End_Ruleset", End_Ruleset)
42 | End_Detail => ("End_Detail", End_Detail)
43 | Detail_Set rls' => ("Detail_Set", Detail_Set rls')
44 | Detail_Set_Inst (s, rls') => ("Detail_Set_Inst", Detail_Set_Inst (s, rls'))
46 | Calculate op_ => ("Calculate", Calculate op_)
47 | Substitute sube => ("Substitute", Substitute sube)
48 | Apply_Assumption cts' => ("Apply_Assumption", Apply_Assumption cts')
50 | Take cterm' => ("Take", Take cterm')
51 | Take_Inst cterm' => ("Take_Inst", Take_Inst cterm')
52 | Group (con, ints) => ("Group", Group (con, ints))
53 | Subproblem (domID, pblID) => ("Subproblem", Subproblem (domID, pblID))
55 | Subproblem_Full(spec,cts')=> ("Subproblem_Full", Subproblem_Full(spec,cts'))
57 | End_Subproblem => ("End_Subproblem",End_Subproblem)
58 | CAScmd cterm' => ("CAScmd", CAScmd cterm')
60 | Split_And => ("Split_And", Split_And)
61 | Conclude_And => ("Conclude_And", Conclude_And)
62 | Split_Or => ("Split_Or", Split_Or)
63 | Conclude_Or => ("Conclude_Or", Conclude_Or)
64 | Begin_Trans => ("Begin_Trans", Begin_Trans)
65 | End_Trans => ("End_Trans", End_Trans)
66 | Begin_Sequ => ("Begin_Sequ", Begin_Sequ)
67 | End_Sequ => ("End_Sequ", Begin_Sequ)
68 | Split_Intersect => ("Split_Intersect", Split_Intersect)
69 | End_Intersect => ("End_Intersect", End_Intersect)
70 | Check_elementwise cterm' => ("Check_elementwise", Check_elementwise cterm')
71 | Or_to_List => ("Or_to_List", Or_to_List)
72 | Collect_Trues => ("Collect_Results", Collect_Trues)
74 | Empty_Tac => ("Empty_Tac",Empty_Tac)
75 | Tac string => ("Tac",Tac string)
76 | User => ("User",User)
77 | End_Proof' => ("End_Proof'",End_Proof');
80 val empty_tac'_ = (mk_tac'_ Empty_Tac):tac'_;
82 fun mk_tac ((_,m):tac'_) = m;
83 fun mk_mstID ((mI,_):tac'_) = mI;
85 fun tac'_2str ((ID,ms):tac'_) = ID ^ (tac2str ms);
86 (* TODO: tac2str, tac'_2str NOT tested *)
90 type squ = ptree; (* TODO: safe etc. *)
92 (*13.9.02--------------
93 type ctr = (loc * pos) list;
94 val ops = [("PLUS","Groups.plus_class.plus"),("MINUS","Groups.minus_class.minus"),("TIMES","Groups.times_class.times"),
95 ("cancel","cancel"),("pow","pow"),("sqrt","sqrt")];
97 @{term "PLUS"}; (*Free ("PLUS", "'a") : term*)
98 @{term "plus"}; (*Const ("Groups.plus_class.plus", "'a => 'a => 'a")*)
99 @{term "MINUS"}; (*Free ("MINUS", "'a")*)
100 @{term "minus"}; (*Const ("Groups.minus_class.minus", "'a => 'a => 'a")*)
101 @{term "TIMES"}; (*Free ("TIMES", "'a")*)
102 @{term "times"}; (*Const ("Groups.times_class.times", "'a => 'a => 'a")*)
103 @{term "CANCEL"}; (*Free ("CANCEL", "'a")*)
104 @{term "cancel"}; (*Free ("cancel", "'a")*)
105 @{term "POWER"}; (*Free ("POWER", "'a")*)
106 @{term "pow"}; (*Free ("pow", "'a")*)
107 @{term "SQRT"}; (*Free ("SQRT", "'a")*)
108 @{term "sqrt"}; (*Const ("NthRoot.sqrt", "RealDef.real => RealDef.real")*)
111 case assoc (ops, op_) of
112 SOME op' => op' | NONE => error ("op_intern: no op= "^op_);
113 -----------------------*)
117 (* use"ME/solve.sml";
120 val ttt = (term_of o the o (parse thy))"Substitute [(bdv,x)] g";
121 val ttt = (term_of o the o (parse thy))"Rewrite thmid True g";
123 Const ("Script.Rewrite'_Inst",_) $ sub $ Free (thm',_) $ Const (pa,_) $ f'
128 val specsteps = ["Init_Proof","Refine_Tacitly","Refine_Problem",
129 "Model_Problem",(*"Match_Problem",*)
130 "Add_Given","Del_Given","Add_Find","Del_Find",
131 "Add_Relation","Del_Relation",
132 "Specify_Theory","Specify_Problem","Specify_Method"];
134 "-----------------------------------------------------------------------";
137 fun step2taci ((tac_, _, pt, p, _):step) = (*FIXXME.040312: redesign step*)
138 (tac_2tac tac_, tac_, (p, get_loc pt p)):taci;
141 (*FIXME.WN050821 compare solve ... nxt_solv*)
142 (* val ("Apply_Method",Apply_Method' (mI,_))=(mI,m);
143 val (("Apply_Method",Apply_Method' (mI,_,_)),pt, pos as (p,_))=(m,pt, pos);
145 fun solve ("Apply_Method", m as Apply_Method' (mI, _, _, _)) (pt:ptree, (pos as (p,_))) =
146 let val {srls, ...} = get_met mI;
147 val PblObj {meth=itms, ...} = get_obj I pt p;
148 val thy' = get_obj g_domID pt p;
149 val thy = assoc_thy thy';
150 val (is as ScrState (env,_,_,_,_,_), ctxt, sc) = init_scrstate thy itms mI;
151 val ini = init_form thy sc env;
155 SOME t => (* val SOME t = ini;
157 let val (pos,c,_,pt) =
158 generate1 thy (Apply_Method' (mI, SOME t, is, ctxt))
159 (is, ctxt) (lev_on p, Frm)(*implicit Take*) pt;
160 in ("ok",([(Apply_Method mI, Apply_Method' (mI, SOME t, is, ctxt),
161 ((lev_on p, Frm), (is, ctxt)))], c, (pt,pos)):calcstate')
163 | NONE => (*execute the first tac in the Script, compare solve m*)
164 let val (m', (is', ctxt'), _) = next_tac (thy', srls) (pt, (p, Res)) sc (is, ctxt);
165 val d = e_rls (*FIXME: get simplifier from domID*);
167 case locate_gen (thy',srls) m' (pt,(p, Res))(sc,d) (is', ctxt') of
168 Steps (is'', ss as (m'',f',pt',p',c')::_) =>
169 (* val Steps (is'', ss as (m'',f',pt',p',c')::_) =
170 locate_gen (thy',srls) m' (pt,(p,Res)) (sc,d) is';
172 ("ok", (map step2taci ss, c', (pt',p')))
174 let val (p,ps,f,pt) =
175 generate_hard (assoc_thy "Isac") m (p,Frm) pt;
176 in ("not-found-in-script",
177 ([(tac_2tac m, m, (pos, (is, ctxt)))], ps, (pt,p))) end
178 (*just-before------------------------------------------------------
179 ("ok",([(Apply_Method mI,Apply_Method'(mI,NONE,e_istate),
181 [], (update_env pt (fst pos) (SOME is),pos)))
182 -----------------------------------------------------------------*)
186 | solve ("Free_Solve", Free_Solve') (pt,po as (p,_)) =
187 let (*val _=tracing"###solve Free_Solve";*)
188 val p' = lev_dn_ (p,Res);
189 val pt = update_metID pt (par_pblobj pt p) e_metID;
190 in ("ok", ([(Empty_Tac, Empty_Tac_, (po, (Uistate, e_ctxt)))], [], (pt,p')))
193 | solve ("Check_Postcond",Check_Postcond' (pI,_)) (pt,(pos as (p,p_))) =
194 let (*val _=tracing"###solve Check_Postcond";*)
195 val pp = par_pblobj pt p
197 (case get_obj g_tac pt p of
198 Check_elementwise _ => (*collects and instantiates asms*)
199 (snd o (get_obj g_result pt)) p
200 | _ => get_assumptions_ pt (p,p_))
201 handle _ => [] (*WN.27.5.03 asms in subpbls not completely clear*)
202 val metID = get_obj g_metID pt pp;
203 val {srls=srls,scr=sc,...} = get_met metID;
204 val loc as (ScrState (E,l,a,_,_,b), ctxt) = get_loc pt (p,p_);
205 val thy' = get_obj g_domID pt pp;
206 val thy = assoc_thy thy';
207 val (_,_,(scval,scsaf)) = next_tac (thy',srls) (pt,(p,p_)) sc loc;
212 val is = ScrState (E,l,a,scval,scsaf,b)
213 val tac_ = Check_Postcond'(pI,(scval, map term2str asm))
214 val (pos,ps,f,pt) = generate1 thy tac_ (is, ctxt) (pp,Res) pt;
215 in ("ok", ([(Check_Postcond pI, tac_, ((pp,Res),(is, ctxt)))], ps,(pt,pos))) end
217 let (*resume script of parpbl, transfer value of subpbl-script*)
218 val ppp = par_pblobj pt (lev_up p);
219 val thy' = get_obj g_domID pt ppp;
220 val thy = assoc_thy thy';
221 val metID = get_obj g_metID pt ppp;
222 val sc = (#scr o get_met) metID;
223 val (ScrState (E,l,a,_,_,b), ctxt') = get_loc pt (pp(*!/p/*),Frm);
224 val ctxt'' = transfer_from_subproblem ctxt ctxt'
225 val ((p,p_),ps,f,pt) =
226 generate1 thy (Check_Postcond' (pI, (scval, map term2str asm)))
227 (ScrState (E,l,a,scval,scsaf,b), ctxt'') (pp,Res) pt;
228 in ("ok", ([(Check_Postcond pI, Check_Postcond'(pI,(scval, map term2str asm)),
229 ((pp,Res), (ScrState (E,l,a,scval,scsaf,b), ctxt'')))],ps,(pt,(p,p_))))
233 | solve (_,End_Proof'') (pt, (p,p_)) =
235 ((*(([],Res),Uistate,Empty_Tac_), EmptyMout, Empty_Tac, Safe,*)
236 [(Empty_Tac,Empty_Tac_,(([],Res),(Uistate, e_ctxt)))],[],(pt,(p,p_))))
238 (*-----------vvvvvvvvvvv could be done by generate1 ?!?*)
239 | solve (_,End_Detail' t) (pt,(p,p_)) =
240 let val pr as (p',_) = (lev_up p, Res)
241 val pp = par_pblobj pt p
242 val r = (fst o (get_obj g_result pt)) p'
243 (*Rewrite_Set* done at Detail_Set*: this result is already in ptree*)
244 val thy' = get_obj g_domID pt pp
245 val (srls, is, sc) = from_pblobj' thy' pr pt
246 val (tac_,is',_) = next_tac (thy',srls) (pt,pr) sc is
247 in ("ok", ((*((pp,Frm(*???*)),is,tac_),
248 Form' (FormKF (~1, EdUndef, length p', Nundef, term2str r)),
249 tac_2tac tac_, Sundef,*)
250 [(End_Detail, End_Detail' t ,
251 ((p,p_), get_loc pt (p,p_)))], [], (pt,pr))) end
253 | solve (mI,m) (pt, po as (p,p_)) =
254 (* val ((mI,m), (pt, po as (p,p_))) = (m, (pt, pos));
256 if e_metID = get_obj g_metID pt (par_pblobj pt p)(*29.8.02:
257 could be detail, too !!*)
258 then let val ((p,p_),ps,f,pt) =
259 generate1 (assoc_thy (get_obj g_domID pt (par_pblobj pt p)))
260 m (e_istate, e_ctxt) (p,p_) pt;
261 in ("no-method-specified", (*Free_Solve*)
262 ((*((p,p_),Uistate,Empty_Tac_),f, Empty_Tac, Unsafe,*)
263 [(Empty_Tac,Empty_Tac_, ((p,p_),(Uistate, e_ctxt)))], ps, (pt,(p,p_)))) end
266 val thy' = get_obj g_domID pt (par_pblobj pt p);
267 val (srls, is, sc) = from_pblobj_or_detail' thy' (p,p_) pt;
268 (*val _= tracing("### solve, before locate_gen p="^(pos'2str(p,p_)));*)
269 val d = e_rls; (*FIXME: canon.simplifier for domain is missing
270 8.01: generate from domID?*)
271 in case locate_gen (thy',srls) m (pt,(p,p_)) (sc,d) is of
272 Steps (is', ss as (m',f',pt',p',c')::_) =>
273 (* val Steps (is', ss as (m',f',pt',p',c')::_) =
274 locate_gen (thy',srls) m (pt,(p,p_)) (sc,d) is;
276 let (*val _= tracing("### solve, after locate_gen: is= ")
277 val _= tracing(istate2str is')*)
279 case p' of (*change from solve to model subpbl*)
280 (_,Pbl) => nxt_model_pbl m' (pt',p')
281 | _ => fst3 (next_tac (thy',srls) (pt',p') sc is');*)
282 (*27.8.02:next_tac may change to other branches in pt FIXXXXME*)
283 in ("ok", ((*(p',is',nxt_), f', tac_2tac nxt_, safe is',*)
284 map step2taci ss, c', (pt',p'))) end
286 let val (p,ps,f,pt) =
287 generate_hard (assoc_thy "Isac") m (p,p_) pt;
288 in ("not-found-in-script",
289 ((*(p,Uistate,Empty_Tac_),f, Empty_Tac, Unsafe,*)
290 [(tac_2tac m, m, (po,is))], ps, (pt,p))) end
294 (*FIXME.WN050821 compare solve ... nxt_solv*)
295 (* nxt_solv (Apply_Method' vvv FIXME: get args in applicable_in *)
296 fun nxt_solv (Apply_Method' (mI,_,_,_)) _ (pt:ptree, pos as (p,_)) =
297 (* val ((Apply_Method' (mI,_,_)), _, (pt:ptree, pos as (p,_))) =
298 ((Apply_Method' (mI, NONE, e_istate)), e_istate, ptp);
300 let val {srls,ppc,...} = get_met mI;
301 val PblObj{meth=itms,origin=(oris,_,_),probl,...} = get_obj I pt p;
302 val itms = if itms <> [] then itms
303 else complete_metitms oris probl [] ppc
304 val thy' = get_obj g_domID pt p;
305 val thy = assoc_thy thy';
306 val (is as ScrState (env,_,_,_,_,_), ctxt, scr) = init_scrstate thy itms mI;
307 val ini = init_form thy scr env;
310 SOME t => (* val SOME t = ini;
312 let val pos = ((lev_on o lev_dn) p, Frm)
313 val tac_ = Apply_Method' (mI, SOME t, is, ctxt);
314 val (pos,c,_,pt) = (*implicit Take*)
315 generate1 thy tac_ (is, ctxt) pos pt
316 (*val _= ("### nxt_solv Apply_Method, pos= "^pos'2str (lev_on p,Frm));*)
317 in ([(Apply_Method mI, tac_, (pos, (is, ctxt)))], c, (pt, pos)):calcstate' end
319 let val pt = update_env pt (fst pos) (SOME (is, ctxt))
320 val (tacis, c, ptp) = nxt_solve_ (pt, pos)
322 [(Apply_Method mI, Apply_Method' (mI, NONE, e_istate, e_ctxt), (pos, (is, ctxt)))],
325 (* val ("Check_Postcond",Check_Postcond' (pI,_)) = (mI,m);
326 val (Check_Postcond' (pI,_), _, (pt, pos as (p,p_))) =
329 (*TODO.WN050913 remove unnecessary code below*)
330 | nxt_solv (Check_Postcond' (pI,_)) _ (pt, pos as (p,p_)) =
331 let (*val _=tracing"###solve Check_Postcond";*)
332 val pp = par_pblobj pt p
333 val asm = (case get_obj g_tac pt p of
334 Check_elementwise _ => (*collects and instantiates asms*)
335 (snd o (get_obj g_result pt)) p
336 | _ => get_assumptions_ pt (p,p_))
337 handle _ => [] (*WN.27.5.03 asms in subpbls not completely clear*)
338 val metID = get_obj g_metID pt pp;
339 val {srls=srls,scr=sc,...} = get_met metID;
340 val loc as (ScrState (E,l,a,_,_,b), ctxt) = get_loc pt (p,p_);
341 (*val _= tracing("### solve Check_postc, subpbl pos= "^(pos'2str (p,p_)));
342 val _= tracing("### solve Check_postc, is= "^(istate2str is));*)
343 val thy' = get_obj g_domID pt pp;
344 val thy = assoc_thy thy';
345 val (_,_,(scval,scsaf)) = next_tac (thy',srls) (pt,(p,p_)) sc loc;
346 (*val _= tracing("### solve Check_postc, scval= "^(term2str scval));*)
348 let val is = ScrState (E,l,a,scval,scsaf,b)
349 val tac_ = Check_Postcond'(pI,(scval, map term2str asm))
350 val ((p,p_),ps,f,pt) =
351 generate1 thy tac_ (is, ctxt) (pp,Res) pt;
352 in ([(Check_Postcond pI, tac_, ((pp,Res), (is, ctxt)))],ps,(pt, (p,p_))) end
355 (*resume script of parpbl, transfer value of subpbl-script*)
356 val ppp = par_pblobj pt (lev_up p);
357 val thy' = get_obj g_domID pt ppp;
358 val thy = assoc_thy thy';
359 val metID = get_obj g_metID pt ppp;
360 val {scr,...} = get_met metID;
361 val (ScrState (E,l,a,_,_,b), ctxt') = get_loc pt (pp(*!/p/*),Frm)
362 val ctxt'' = transfer_from_subproblem ctxt ctxt'
363 val tac_ = Check_Postcond' (pI, (scval, map term2str asm))
364 val is = ScrState (E,l,a,scval,scsaf,b)
365 val ((p,p_),ps,f,pt) = generate1 thy tac_ (is, ctxt'') (pp, Res) pt;
366 (*val (nx,is',_) = next_tac (thy',srls) (pt,(p,p_)) scr is;WN050913*)
367 in ([(Check_Postcond pI, tac_, ((pp, Res), (is, ctxt'')))], ps, (pt, (p,p_))) end
370 | nxt_solv (End_Proof'') _ ptp = ([], [], ptp)
372 | nxt_solv tac_ is (pt, pos as (p,p_)) =
373 (* val (pt, pos as (p,p_)) = ptp;
375 let val pos = case pos of
376 (p, Met) => ((lev_on o lev_dn) p, Frm)(*begin script*)
377 | (p, Res) => (lev_on p,Res) (*somewhere in script*)
378 | _ => pos (*somewhere in script*)
379 (*val _= tracing"### nxt_solv4 Apply_Method: stored is =";
380 val _= tracing(istate2str is);*)
381 val (pos',c,_,pt) = generate1 (assoc_thy "Isac") tac_ is pos pt;
382 in ([(tac_2tac tac_, tac_, (pos,is))], c, (pt, pos')) end
385 (*(p,p_), (([],Res),Uistate,Empty_Tac_), EmptyMout, Empty_Tac, Safe, pt*)
388 (*.find the next tac from the script, nxt_solv will update the ptree.*)
389 (* val (ptp as (pt,pos as (p,p_))) = ptp';
390 val (ptp as (pt, pos as (p,p_))) = ptp'';
391 val (ptp as (pt, pos as (p,p_))) = ptp;
392 val (ptp as (pt, pos as (p,p_))) = (pt,ip);
393 val (ptp as (pt, pos as (p,p_))) = (pt, pos);
395 and nxt_solve_ (ptp as (pt, pos as (p,p_))) =
396 if e_metID = get_obj g_metID pt (par_pblobj pt p)
397 then ([], [], (pt,(p,p_))):calcstate'
400 val thy' = get_obj g_domID pt (par_pblobj pt p);
401 val (srls, is, sc) = from_pblobj_or_detail' thy' (p,p_) pt;
402 val (tac_,is,(t,_)) = next_tac (thy',srls) (pt,pos) sc is;
403 (*TODO here ^^^ return finished/helpless/ok !*)
405 End_Detail' _ => ([(End_Detail, End_Detail' (t,[(*FIXME.040215*)]),
406 (pos, is))], [], (pt, pos))
407 | _ => nxt_solv tac_ is ptp end;
409 (*.says how may steps of a calculation should be done by "fun autocalc".*)
410 (*TODO.WN0512 redesign togehter with autocalc ?*)
412 Step of int (*1 do #int steps; may stop in model/specify:
413 IS VERY INEFFICIENT IN MODEL/SPECIY*)
414 | CompleteModel (*2 complete modeling
415 if model complete, finish specifying + start solving*)
416 | CompleteCalcHead (*3 complete model/specify in one go + start solving*)
417 | CompleteToSubpbl (*4 stop at the next begin of a subproblem,
418 if none, complete the actual (sub)problem*)
419 | CompleteSubpbl (*5 complete the actual (sub)problem (incl.ev.subproblems)*)
420 | CompleteCalc; (*6 complete the calculation as a whole*)
421 fun autoord (Step _ ) = 1
422 | autoord CompleteModel = 2
423 | autoord CompleteCalcHead = 3
424 | autoord CompleteToSubpbl = 4
425 | autoord CompleteSubpbl = 5
426 | autoord CompleteCalc = 6;
428 (* val (auto, c, (ptp as (_, p))) = (auto, (c@c'), ptp);
430 fun complete_solve auto c (ptp as (_, p): ptree * pos') =
431 if p = ([], Res) then ("end-of-calculation", [], ptp) else
432 case nxt_solve_ ptp of
433 ((Subproblem _, tac_, (_, is))::_, c', ptp') =>
434 (* val ptp' = ptp''';
436 if autoord auto < 5 then ("ok", c@c', ptp)
437 else let val ptp = all_modspec ptp';
438 val (_, c'', ptp) = all_solve auto (c@c') ptp;
439 in complete_solve auto (c@c'@c'') ptp end
440 | ((Check_Postcond _, tac_, (_, is))::_, c', ptp' as (_, p')) =>
441 if autoord auto < 6 orelse p' = ([],Res) then ("ok", c@c', ptp')
442 else complete_solve auto (c@c') ptp'
443 | ((End_Detail, _, _)::_, c', ptp') =>
444 if autoord auto < 6 then ("ok", c@c', ptp')
445 else complete_solve auto (c@c') ptp'
446 | (_, c', ptp') => complete_solve auto (c@c') ptp'
447 (* val (tacis, c', ptp') = nxt_solve_ ptp;
448 val (tacis, c', ptp'') = nxt_solve_ ptp';
449 val (tacis, c', ptp''') = nxt_solve_ ptp'';
450 val (tacis, c', ptp'''') = nxt_solve_ ptp''';
451 val (tacis, c', ptp''''') = nxt_solve_ ptp'''';
453 and all_solve auto c (ptp as (pt, (p,_)): ptree * pos') =
454 (* val (ptp as (pt, (p,_))) = ptp;
455 val (ptp as (pt, (p,_))) = ptp';
456 val (ptp as (pt, (p,_))) = (pt, pos);
458 let val (_,_,mI) = get_obj g_spec pt p;
459 val (_, c', ptp) = nxt_solv (Apply_Method' (mI, NONE, e_istate, e_ctxt))
460 (e_istate, e_ctxt) ptp;
461 in complete_solve auto (c@c') ptp end;
462 (*@@@ vvv @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*)
463 fun complete_solve auto c (ptp as (_, p as (_,p_)): ptree * pos') =
464 if p = ([], Res) then ("end-of-calculation", [], ptp) else
465 if member op = [Pbl,Met] p_
466 then let val ptp = all_modspec ptp
467 val (_, c', ptp) = all_solve auto c ptp
468 in complete_solve auto (c@c') ptp end
469 else case nxt_solve_ ptp of
470 ((Subproblem _, tac_, (_, is))::_, c', ptp') =>
471 if autoord auto < 5 then ("ok", c@c', ptp)
472 else let val ptp = all_modspec ptp'
473 val (_, c'', ptp) = all_solve auto (c@c') ptp
474 in complete_solve auto (c@c'@c'') ptp end
475 | ((Check_Postcond _, tac_, (_, is))::_, c', ptp' as (_, p')) =>
476 if autoord auto < 6 orelse p' = ([],Res) then ("ok", c@c', ptp')
477 else complete_solve auto (c@c') ptp'
478 | ((End_Detail, _, _)::_, c', ptp') =>
479 if autoord auto < 6 then ("ok", c@c', ptp')
480 else complete_solve auto (c@c') ptp'
481 | (_, c', ptp') => complete_solve auto (c@c') ptp'
482 and all_solve auto c (ptp as (pt, (p,_)): ptree * pos') =
483 let val (_,_,mI) = get_obj g_spec pt p
484 val (_, c', ptp) = nxt_solv (Apply_Method' (mI, NONE, e_istate, e_ctxt))
485 (e_istate, e_ctxt) ptp
486 in complete_solve auto (c@c') ptp end;
488 (*.aux.fun for detailrls with Rrls, reverse rewriting.*)
489 (* val (nds, t, ((rule, (t', asm)) :: rts)) = ([], t, rul_terms);
491 fun rul_terms_2nds nds t [] = nds
492 | rul_terms_2nds nds t ((rule, res as (t', _)) :: rts) =
493 (append_atomic [] (e_istate, e_ctxt) t (rule2tac [] rule) res Complete EmptyPtree) ::
494 (rul_terms_2nds nds t' rts);
497 (*. detail steps done internally by Rewrite_Set*
498 into ctree by use of a script .*)
499 (* val (pt, (p,p_)) = (pt, pos);
501 fun detailrls pt ((p,p_):pos') =
502 let val t = get_obj g_form pt p
503 val tac = get_obj g_tac pt p
504 val rls = (assoc_rls o rls_of) tac
506 (* val Rrls {scr = Rfuns {init_state,...},...} = rls;
508 Rrls {scr = Rfuns {init_state,...},...} =>
509 let val (_,_,_,rul_terms) = init_state t
510 val newnds = rul_terms_2nds [] t rul_terms
511 val pt''' = ins_chn newnds pt p
512 in ("detailrls", pt''', (p @ [length newnds], Res):pos') end
514 let val is = init_istate tac t
515 (*TODO.WN060602 ScrState (["(t_, Problem (Isac,[equation,univar]))"]
516 is wrong for simpl, but working ?!? *)
517 val tac_ = Apply_Method' (e_metID(*WN0402: see generate1 !?!*),
519 val pos' = ((lev_on o lev_dn) p, Frm)
520 val thy = assoc_thy "Isac"
521 val (_,_,_,pt') = (*implicit Take*)generate1 thy tac_ (is, e_ctxt) pos' pt
522 val (_,_,(pt'',_)) = complete_solve CompleteSubpbl [] (pt',pos')
523 val newnds = children (get_nd pt'' p)
524 val pt''' = ins_chn newnds pt p
525 (*complete_solve cuts branches after*)
526 in ("detailrls", pt'''(*, get_formress [] ((lev_on o lev_dn) p)cn*),
527 (p @ [length newnds], Res):pos') end
532 (* val(mI,m)=m;val ppp=p;(*!!!*)val(p,p_)=pos;val(_,pt,_)=ppp(*!!!*);
533 get_form ((mI,m):tac'_) ((p,p_):pos') ppp;
535 fun get_form ((mI,m):tac'_) ((p,p_):pos') pt =
536 case applicable_in (p,p_) pt m of
537 Notappl e => Error' (Error_ e)
539 (* val Appl m=applicable_in (p,p_) pt m;
541 if member op = specsteps mI
542 then let val (_,_,f,_,_,_) = specify m (p,p_) [] pt
544 else let val (*_,_,f,_,_,_*)_ = solve (mI,m) (pt,(p,p_))
545 in (*f*) EmptyMout end;