intermed.
1 (* Handle user-input during the specify- and the solve-phase.
4 (c) due to copyright terms
20 | Given of cterm' list
21 | Relate of cterm' list
23 val imodel2fstr : iitem list -> (string * cterm') list
26 val Isac : 'a -> theory
29 SpecifyTools.ori list ->
30 SpecifyTools.itm list ->
31 ('a * (Term.term * Term.term)) list ->
32 string * cterm' -> SpecifyTools.itm
35 SpecifyTools.ori list ->
36 SpecifyTools.itm list ->
37 (string * (Term.term * Term.term)) list ->
38 (string * string) list -> SpecifyTools.itm list *)
39 (* val cas_input : string -> ptree * ocalhd *)
42 (Term.term * Term.term list) list ->
43 pblID * SpecifyTools.itm list * metID * SpecifyTools.itm list *
44 (bool * Term.term) list *)
45 val castab : castab Unsynchronized.ref
47 calcstate' -> Term.term -> string * calcstate'
49 'a * ((Term.term * Term.term) list -> Term.term * Term.term -> bool)
55 bool * (Term.term * rule * (Term.term * Term.term list)) list *)
56 val dropwhile' : (* systest/auto-inform.sml *)
57 ('a -> 'b -> bool) -> 'a list -> 'b list -> 'a list * 'b list
60 Term.term * Term.term list ->
61 int list * bool * string * SpecifyTools.itm_ *)
62 (* val e_icalhd : icalhd *)
63 val eq7 : ''a * ''b -> ''a * (''b * 'c) -> bool
64 val equal : ''a -> ''a -> bool
66 SpecifyTools.ori list -> SpecifyTools.itm -> SpecifyTools.ori list *)
67 (* val filter_sep : ('a -> bool) -> 'a list -> 'a list * 'a list *)
68 (* val flattup2 : 'a * ('b * 'c * 'd * 'e) -> 'a * 'b * 'c * 'd * 'e *)
71 (''a * (Term.term * Term.term)) list ->
72 ''a * string -> int list * bool * ''a * SpecifyTools.itm_ *)
74 calcstate' -> cterm' -> string * calcstate'
75 val input_icalhd : ptree -> icalhd -> ptree * ocalhd
76 (* val is_Par : SpecifyTools.itm -> bool *)
77 (* val is_casinput : cterm' -> fmz -> bool *)
78 (* val is_e_ts : Term.term list -> bool *)
79 (* val itms2fstr : SpecifyTools.itm -> string * string *)
83 Term.term * rule * (Term.term * Term.term list) ->
84 tac * tac_ * (pos' * istate) *)
86 'a -> int -> SpecifyTools.ori list -> SpecifyTools.itm list
87 (* val par2fstr : SpecifyTools.itm -> string * cterm' *)
88 (* val parsitm : theory -> SpecifyTools.itm -> SpecifyTools.itm *)
89 val rev_deriv' : 'a * rule * ('b * 'c) -> 'b * rule * ('a * 'c)
92 (string * (Term.term * Term.term)) list ->
93 (string * string) list -> SpecifyTools.itm list *)
101 (***. handle an input calc-head .***)
103 (*------------------------------------------------------------------(**)
104 structure inform :INFORM =
106 (**)------------------------------------------------------------------*)
110 (*Where is never input*)
111 | Find of cterm' list
112 | Relate of cterm' list;
114 type imodel = iitem list;
116 (*calc-head as input*)
118 pos' * (*the position of the calc-head in the calc-tree
119 pos' as (p,p_) where p_ is neglected due to pos_ below*)
120 cterm' * (*the headline*)
121 imodel * (*the model (without Find) of the calc-head*)
122 pos_ * (*model belongs to Pbl or Met*)
123 spec; (*specification: domID, pblID, metID*)
124 val e_icalhd = (e_pos', "", [Given [""]], Pbl, e_spec): icalhd;
126 fun is_casinput (hdf: cterm') ((fmz_, spec): fmz) =
127 hdf <> "" andalso fmz_ = [] andalso spec = e_spec;
129 (*.handle an input as into an algebra system.*)
130 fun dtss2itm_ ppc (d, ts) =
131 let val (f, (d, id)) = the (find_first ((curry op= d) o
132 (#1: (term * term) -> term) o
133 (#2: pbt_ -> (term * term))) ppc)
134 in ([1], true, f, Cor ((d, ts), (id, ts))) end;
136 fun flattup2 (a,(b,c,d,e)) = (a,b,c,d,e);
140 (*.association list with cas-commands, for generating a complete calc-head.*)
142 (term * (*cas-command, eg. 'solve'*)
143 (spec * (*theory, problem, method*)
145 (*the function generating a kind of formalization*)
146 (term list -> (*the arguments of the cas-command, eg. (x+1=2, x)*)
147 (term * (*description of an element*)
148 term list) (*value of the element (always put into a list)*)
149 list))) (*of elements in the formalization*)
150 list; (*of cas-entries in the association list*)
152 val castab = Unsynchronized.ref ([]: castab);
155 fun cas_input_ ((dI,pI,mI): spec) dtss = (*WN110515 reconsider thy..ctxt*)
157 val thy = assoc_thy dI
158 val {ppc, ...} = get_pbt pI
159 val its_ = map (dtss2itm_ ppc) dtss (*([1],true,"#Given",Cor (...))*)
160 val its = add_id its_
161 val pits = map flattup2 its
166 case refine_pbl thy pI pits of
167 SOME (pI,_) => (pI, (hd o #met o get_pbt) pI)
168 | NONE => (pI, (hd o #met o get_pbt) pI)
169 val {ppc, pre, prls, ...} = get_met mI
170 val its_ = map (dtss2itm_ ppc) dtss (*([1],true,"#Given",Cor (...))*)
171 val its = add_id its_
172 val mits = map flattup2 its
173 val pre = check_preconds thy prls pre mits
174 val ctxt = e_ctxt (*WN110515 cas_input_ DOESNT WORK*)
175 in (pI, pits: itm list, mI, mits: itm list, pre, ctxt) end;
178 (* check if the input term is a CAScmd and return a ptree with a _complete_ calchead *)
180 let val (h,argl) = strip_comb hdt
182 case assoc (!castab, h) of
184 | SOME (spec as (dI,_,_), argl2dtss) =>
186 val dtss = argl2dtss argl
187 val (pI, pits, mI, mits, pre, ctxt) = cas_input_ spec dtss
188 val spec = (dI, pI, mI)
190 cappend_problem e_ptree [] (e_istate, e_ctxt) ([], e_spec) ([], e_spec, hdt)
191 val pt = update_spec pt [] spec
192 val pt = update_pbl pt [] pits
193 val pt = update_met pt [] mits
194 val pt = update_ctxt pt [] ctxt
195 in SOME (pt, (true, Met, hdt, mits, pre, spec) : ocalhd) end
198 (*lazy evaluation for (Thy_Info.get_theory "Isac")*)
199 fun Isac _ = assoc_thy "Isac";
201 (*re-parse itms with a new thy and prepare for checking with ori list*)
202 fun parsitm dI (itm as (i,v,b,f, Cor ((d,ts),_)):itm) =
203 (* val itm as (i,v,b,f, Cor ((d,ts),_)) = hd probl;
205 (let val t = comp_dts (d,ts);
206 val s = Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt dI)) t;
207 (*this ^ should raise the exn on unability of re-parsing dts*)
208 in itm end handle _ => ((i,v,false,f, Syn (term2str t)):itm))
209 | parsitm dI (itm as (i,v,b,f, Syn str)) =
210 (let val t = (term_of o the o (parse dI)) str
211 in (i,v,b,f, Par str) end handle _ => (i,v,b,f, Syn str))
212 | parsitm dI (itm as (i,v,b,f, Typ str)) =
213 (let val t = (term_of o the o (parse dI)) str
214 in (i,v,b,f, Par str) end handle _ => (i,v,b,f, Syn str))
215 | parsitm dI (itm as (i,v,_,f, Inc ((d,ts),_))) =
216 (let val t = comp_dts (d,ts);
217 val s = Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt dI)) t;
218 (*this ^ should raise the exn on unability of re-parsing dts*)
219 in itm end handle _ => ((i,v,false,f, Syn (term2str t)):itm))
220 | parsitm dI (itm as (i,v,_,f, Sup (d,ts))) =
221 (let val t = comp_dts (d,ts);
222 val s = Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt dI)) t;
223 (*this ^ should raise the exn on unability of re-parsing dts*)
224 in itm end handle _ => ((i,v,false,f, Syn (term2str t)):itm))
225 | parsitm dI (itm as (i,v,_,f, Mis (d,t'))) =
227 val s = Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt dI)) t;
228 (*this ^ should raise the exn on unability of re-parsing dts*)
229 in itm end handle _ => ((i,v,false,f, Syn (term2str t)):itm))
230 | parsitm dI (itm as (i,v,_,f, Par _)) =
231 error ("parsitm (" ^ itm2str_ (thy2ctxt dI) itm^
232 "): Par should be internal");
234 (*separate a list to a pair of elements that do NOT satisfy the predicate,
235 and of elements that satisfy the predicate, i.e. (false, true)*)
236 fun filter_sep pred xs =
237 let fun filt ab [] = ab
238 | filt (a,b) (x :: xs) = if pred x
239 then filt (a,b@[x]) xs
240 else filt (a@[x],b) xs
241 in filt ([],[]) xs end;
242 fun is_Par ((_,_,_,_,Par _):itm) = true
245 fun is_e_ts [] = true
246 | is_e_ts [Const ("List.list.Nil", _)] = true
249 (*WN.9.11.03 copied from fun appl_add (in modspec.sml)*)
250 (* val (sel,ct) = selct;
251 val (dI, oris, ppc, pbt, (sel, ct))=
252 (#1 (some_spec ospec spec), oris, []:itm list,
253 ((#ppc o get_pbt) (#2 (some_spec ospec spec))),
254 hd (imodel2fstr imodel));
256 fun appl_add' dI oris ppc pbt (sel, ct) =
258 val ctxt = assoc_thy dI |> thy2ctxt;
259 in case parseNEW ctxt ct of
260 NONE => (0,[],false,sel, Syn ct):itm
261 | SOME t => (case is_known ctxt sel oris t of
263 (case is_notyet_input ctxt ppc all ori' pbt of
265 | (msg,_) => error ("appl_add': " ^ msg))
266 | (_, (i, v, _, d, ts), _) => if is_e_ts ts then
267 (i, v, false, sel, Inc ((d, ts), (e_term, []))) else
268 (i, v, false, sel, Sup (d, ts)))
271 (*.generate preliminary itm_ from a strin (with field "#Given" etc.).*)
272 (* val (f, str) = hd selcts;
274 fun eq7 (f, d) (f', (d', _)) = f=f' andalso d=d';
275 fun fstr2itm_ thy pbt (f, str) =
276 let val topt = parse thy str
278 NONE => ([], false, f, Syn str)
280 (* val SOME ct = parse thy str;
282 let val (d,ts) = (split_dts o term_of) ct
283 val popt = find_first (eq7 (f,d)) pbt
285 NONE => ([1](*??*), true(*??*), f, Sup (d,ts))
286 | SOME (f, (d, id)) => ([1], true, f, Cor ((d,ts), (id, ts)))
291 (*.input into empty PblObj, i.e. empty fmz+origin (unknown example).*)
292 fun unknown_expl dI pbt selcts =
294 val thy = assoc_thy dI
295 val its_ = map (fstr2itm_ thy pbt) selcts (*([1],true,"#Given",Cor (...))*)
296 val its = add_id its_
297 in (map flattup2 its): itm list end;
302 (*WN.11.03 for input_icalhd, ~ specify_additem for Add_Given/_Find/_Relation
303 appl_add': generate 1 item
304 appl_add' . is_known: parse, get data from oris (vats, all (elems if list)..)
305 appl_add' . is_notyet_input: compare with items in model already input
306 insert_ppc': insert this 1 item*)
307 (* val (dI,oris,ppc,pbt,selcts) =((#1 (some_spec ospec spec)),oris,[(*!!*)],
308 ((#ppc o get_pbt) (#2 (some_spec ospec spec))),
309 (imodel2fstr imodel));
311 fun appl_adds dI [] _ pbt selcts = unknown_expl dI pbt selcts
312 (*already present itms in model are being overwritten*)
313 | appl_adds dI oris ppc pbt [] = ppc
314 | appl_adds dI oris ppc pbt (selct::ss) =
315 (* val selct = (sel, string_of_cterm ct);
317 let val itm = appl_add' dI oris ppc pbt selct;
318 in appl_adds dI oris (insert_ppc' itm ppc) pbt ss end;
319 (* val (dI, oris, ppc, pbt, selct::ss) =
320 (dI, pors, probl, ppc, map itms2fstr probl);
323 (* val (dI, oris, ppc, pbt, (selct::ss))=
324 (#1 (some_spec ospec spec), oris, []:itm list,
325 ((#ppc o get_pbt) (#2 (some_spec ospec spec))),(imodel2fstr imodel));
326 val iii = appl_adds dI oris ppc pbt (selct::ss);
327 tracing(itms2str_ thy iii);
329 val itm = appl_add' dI oris ppc pbt selct;
330 val ppc = insert_ppc' itm ppc;
332 val _::selct::ss = (selct::ss);
333 val itm = appl_add' dI oris ppc pbt selct;
334 val ppc = insert_ppc' itm ppc;
336 val _::selct::ss = (selct::ss);
337 val itm = appl_add' dI oris ppc pbt selct;
338 val ppc = insert_ppc' itm ppc;
339 tracing(itms2str_ thy ppc);
341 val _::selct::ss = (selct::ss);
342 val itm = appl_add' dI oris ppc pbt selct;
343 val ppc = insert_ppc' itm ppc;
347 fun oris2itms _ _ ([]:ori list) = ([]:itm list)
348 | oris2itms pbt vat ((i,v,f,d,ts)::(os: ori list)) =
350 then (i,v,true,f,Cor ((d,ts),(e_term,[])))::(oris2itms pbt vat os)
351 else oris2itms pbt vat os;
353 fun filter_dsc oris itm =
354 filter_out ((curry op= ((d_in o #5) (itm:itm))) o
355 (#4:ori -> term)) oris;
360 fun par2fstr ((_,_,_,f, Par s):itm) = (f, s)
361 | par2fstr itm = error ("par2fstr: called with " ^
362 itm2str_ (thy2ctxt' "Isac") itm);
363 fun itms2fstr ((_,_,_,f, Cor ((d,ts),_)):itm) = (f, comp_dts'' (d,ts))
364 | itms2fstr (_,_,_,f, Syn str) = (f, str)
365 | itms2fstr (_,_,_,f, Typ str) = (f, str)
366 | itms2fstr (_,_,_,f, Inc ((d,ts),_)) = (f, comp_dts'' (d,ts))
367 | itms2fstr (_,_,_,f, Sup (d,ts)) = (f, comp_dts'' (d,ts))
368 | itms2fstr (_,_,_,f, Mis (d,t)) = (f, term2str (d $ t))
369 | itms2fstr (itm as (_,_,_,f, Par _)) =
370 error ("parsitm ("^itm2str_ (thy2ctxt' "Isac") itm ^
371 "): Par should be internal");
373 fun imodel2fstr iitems =
376 | xxx is ((Given strs)::iis) = xxx (is @ (map (pair "#Given") strs)) iis
377 | xxx is ((Find strs)::iis) = xxx (is @ (map (pair "#Find") strs)) iis
378 | xxx is ((Relate strs)::iis) = xxx (is @ (map (pair "#Relate") strs)) iis
379 in xxx [] iitems end;
381 (* input a calchead, WN110505 "prep_oris -> (_, ctxt)" not handled properly *)
382 fun input_icalhd pt (((p,_), hdf, imodel, Pbl, spec as (dI,pI,mI)):icalhd) =
383 let val PblObj {fmz = fmz as (fmz_,_), origin = (oris, ospec, hdf'),
384 spec = sspec as (sdI,spI,smI), probl, meth, ...} = get_obj I pt p;
385 in if is_casinput hdf fmz then the (cas_input (str2term hdf))
386 else (*hacked WN0602 ~~~ ~~~~~~~~~, ..dropped !*)
387 let val (pos_, pits, mits) =
389 then let val its = map (parsitm (assoc_thy dI)) probl;
390 val (its, trms) = filter_sep is_Par its;
391 val pbt = (#ppc o get_pbt) (#2(some_spec ospec sspec));
392 in (Pbl, appl_adds dI oris its pbt (map par2fstr trms), meth) end
394 then if pI = snd3 ospec then (Pbl, probl, meth)
396 let val pbt = (#ppc o get_pbt) pI
397 val dI' = #1 (some_spec ospec spec)
398 val oris = if pI = #2 ospec then oris
399 else prep_ori fmz_(assoc_thy"Isac") pbt |> #1;
400 in (Pbl, appl_adds dI' oris probl pbt
401 (map itms2fstr probl), meth) end
402 else if mI <> smI (*FIXME.WN0311: what if probl is incomplete?!*)
403 then let val met = (#ppc o get_met) mI
404 val mits = complete_metitms oris probl meth met
405 in if foldl and_ (true, map #3 mits)
406 then (Pbl, probl, mits) else (Met, probl, mits)
408 else (Pbl, appl_adds (#1 (some_spec ospec spec)) oris [(*!!!*)]
409 ((#ppc o get_pbt) (#2 (some_spec ospec spec)))
410 (imodel2fstr imodel), meth);
411 val pt = update_spec pt p spec;
413 then let val {prls,where_,...} = get_pbt (#2 (some_spec ospec spec))
414 val pre =check_preconds(assoc_thy"Isac")prls where_ pits
415 in (update_pbl pt p pits,
416 (ocalhd_complete pits pre spec, Pbl, hdf', pits, pre, spec):ocalhd)
418 else let val {prls,pre,...} = get_met (#3 (some_spec ospec spec))
419 val pre = check_preconds (assoc_thy"Isac") prls pre mits
420 in (update_met pt p mits,
421 (ocalhd_complete mits pre spec, Met, hdf', mits, pre, spec):ocalhd)
425 | input_icalhd pt ((p,_), hdf, imodel, _(*Met*), spec as (dI,pI,mI)) =
426 error "input_icalhd Met not impl.";
429 (***. handle an input formula .***)
431 Untersuchung zur Formeleingabe (appendFormula, replaceFormla) zu einer Anregung von Alan Krempler:
432 Welche RICHTIGEN Formeln koennen NICHT abgeleitet werden,
433 wenn Abteilungen nur auf gleichem Level gesucht werden ?
436 Beispiele zum Equationsolver von Richard Lang aus /src/sml/kbtest/rlang.sml
438 ------------------------------------------------------------------------------
439 "Schalk I s.87 Bsp 52a ((5*x)/(x - 2) - x/(x+2)=4)";
440 ------------------------------------------------------------------------------
441 1. "5 * x / (x - 2) - x / (x + 2) = 4"
443 4. "12 * x + 4 * x ^^^ 2 = 4 * (-4 + x ^^^ 2)",Subproblem["normalize", "poly"..
445 4.3. "16 + 12 * x = 0", Subproblem["degree_1", "polynomial", "univariate"..
447 4.3.3. "[x = -4 / 3]")), Check_elementwise "Assumptions"
450 ------------------------------------------------------------------------------
451 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
453 (4.1)..(4.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
454 ------------------------------------------------------------------------------
457 ------------------------------------------------------------------------------
458 "Schalk I s.87 Bsp 55b (x/(x^^^2 - 6*x+9) - 1/(x^^^2 - 3*x) =1/x)";
459 ------------------------------------------------------------------------------
460 1. "x / (x ^^^ 2 - 6 * x + 9) - 1 / (x ^^^ 2 - 3 * x) = 1 / x"
462 4. "(3 + (-1 * x + x ^^^ 2)) * x = 1 * (9 * x + (x ^^^ 3 + -6 * x ^^^ 2))"
463 Subproblem["normalize", "polynomial", "univariate"..
465 4.4. "-6 * x + 5 * x ^^^ 2 = 0", Subproblem["bdv_only", "degree_2", "poly"..
467 4.4.4. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
468 4.4.5. "[x = 0, x = 6 / 5]"
470 5. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
472 ------------------------------------------------------------------------------
473 (1)..(4): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite schiebt [Ableitung waere in 4.4.x]
475 (4.1)..(4.4.5): keine 'richtige' Eingabe kann abgeleitet werden, die dem Ergebnis "[x = 6 / 5]" aequivalent ist [Ableitung waere in 5.]
476 ------------------------------------------------------------------------------
479 ------------------------------------------------------------------------------
480 "Schalk II s.56 Bsp 73b (sqrt(x+1)+sqrt(4*x+4)=sqrt(9*x+9))";
481 ------------------------------------------------------------------------------
482 1. "sqrt (x + 1) + sqrt (4 * x + 4) = sqrt (9 * x + 9)"
484 6. "13 + 13 * x + -2 * sqrt ((4 + 4 * x) * (9 + 9 * x)) = 1 + x"
485 Subproblem["sq", "root'", "univariate", "equation"]
487 6.6. "144 + 288 * x + 144 * x ^^^ 2 = 144 + x ^^^ 2 + 288 * x + 143 * x ^^^ 2"
488 Subproblem["normalize", "polynomial", "univariate", "equation"]
490 6.6.3 "0 = 0" Subproblem["degree_0", "polynomial", "univariate", "equation"]
492 6.6.3.2 "UniversalList"
493 ------------------------------------------------------------------------------
494 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die eine der Wurzeln auf die andere Seite verschieb [Ableitung ware in 6.6.n]
496 (6.1)..(6.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 6.6.n]
497 ------------------------------------------------------------------------------
499 (*sh. comments auf 498*)
503 (*the lists contain eq-al elem-pairs at the beginning;
504 return first list reverted (again) - ie. in order as required subsequently*)
505 fun dropwhile' equal (f1::f2::fs) (i1::i2::is) =
507 if equal f2 i2 then dropwhile' equal (f2::fs) (i2::is)
508 else (rev (f1::f2::fs), i1::i2::is)
509 else error "dropwhile': did not start with equal elements"
510 | dropwhile' equal (f::fs) [i] =
511 if equal f i then (rev (f::fs), [i])
512 else error "dropwhile': did not start with equal elements"
513 | dropwhile' equal [f] (i::is) =
514 if equal f i then ([f], i::is)
515 else error "dropwhile': did not start with equal elements";
518 val foder = [0,1,2,3,4,5]; val ifoder = [11,12,3,4,5];
519 val r_foder = rev foder; val r_ifoder = rev ifoder;
520 dropwhile' equal r_foder r_ifoder;
521 > vval it = ([0, 1, 2, 3], [3, 12, 11]) : int list * int list
523 val foder = [3,4,5]; val ifoder = [11,12,3,4,5];
524 val r_foder = rev foder; val r_ifoder = rev ifoder;
525 dropwhile' equal r_foder r_ifoder;
526 > val it = ([3], [3, 12, 11]) : int list * int list
528 val foder = [5]; val ifoder = [11,12,3,4,5];
529 val r_foder = rev foder; val r_ifoder = rev ifoder;
530 dropwhile' equal r_foder r_ifoder;
531 > val it = ([5], [5, 4, 3, 12, 11]) : int list * int list
533 val foder = [10,11,12,13,14,15]; val ifoder = [11,12,3,4,5];
534 val r_foder = rev foder; val r_ifoder = rev ifoder;
535 dropwhile' equal r_foder r_ifoder;
536 > *** dropwhile': did not start with equal elements*)
538 (*040214: version for concat_deriv*)
539 fun rev_deriv' (t, r, (t', a)) = (t', sym_Thm r, (t, a));
541 fun mk_tacis ro erls (t, r as Thm _, (t', a)) =
542 (Rewrite (rule2thm' r),
543 Rewrite' ("Isac", fst ro, erls, false, rule2thm' r, t, (t', a)),
544 (e_pos'(*to be updated before generate tacis!!!*), (Uistate, e_ctxt)))
545 | mk_tacis ro erls (t, r as Rls_ rls, (t', a)) =
546 (Rewrite_Set (rule2rls' r),
547 Rewrite_Set' ("Isac", false, rls, t, (t', a)),
548 (e_pos'(*to be updated before generate tacis!!!*), (Uistate, e_ctxt)));
550 (*fo = ifo excluded already in inform*)
551 fun concat_deriv rew_ord erls rules fo ifo =
552 let fun derivat ([]:(term * rule * (term * term list)) list) = e_term
553 | derivat dt = (#1 o #3 o last_elem) dt
554 fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1=t2
555 val fod = make_deriv (Isac"") erls rules (snd rew_ord) NONE fo
556 val ifod = make_deriv (Isac"") erls rules (snd rew_ord) NONE ifo
557 in case (fod, ifod) of
558 ([], []) => if fo = ifo then (true, [])
560 | (fod, []) => if derivat fod = ifo
561 then (true, fod) (*ifo is normal form*)
563 | ([], ifod) => if fo = derivat ifod
564 then (true, ((map rev_deriv') o rev) ifod)
567 if derivat fod = derivat ifod (*common normal form found*)
568 then let val (fod', rifod') =
569 dropwhile' equal (rev fod) (rev ifod)
570 in (true, fod' @ (map rev_deriv' rifod')) end
574 val ({rew_ord, erls, rules,...}, fo, ifo) =
575 (rep_rls Test_simplify, str2term "x+1+ -1*2=0", str2term "-2*1+(x+1)=0");
576 (tracing o trtas2str) fod';
578 (x + 1 + -1 * 2 = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (x + 1) = 0, []))","
579 (-1 * 2 + (x + 1) = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (1 + x) = 0, []))","
580 (-1 * 2 + (1 + x) = 0, Thm ("radd_left_commute","?x + (?y + ?z) = ?y + (?x + ?z)"), (1 + (-1 * 2 + x) = 0, []))","
581 (1 + (-1 * 2 + x) = 0, Thm ("#mult_Float ((~1,0), (0,0)) __ ((2,0), (0,0))","-1 * 2 = -2"), (1 + (-2 + x) = 0, []))"]
583 (tracing o trtas2str) (map rev_deriv' rifod');
585 (1 + (-2 + x) = 0, Thm ("sym_#mult_Float ((~2,0), (0,0)) __ ((1,0), (0,0))","-2 = -2 * 1"), (1 + (-2 * 1 + x) = 0, []))","
586 (1 + (-2 * 1 + x) = 0, Thm ("sym_radd_left_commute","?y + (?x + ?z) = ?x + (?y + ?z)"), (-2 * 1 + (1 + x) = 0, []))","
587 (-2 * 1 + (1 + x) = 0, Thm ("sym_radd_commute","?n + ?m = ?m + ?n"), (-2 * 1 + (x + 1) = 0, []))"]
592 (* compare inform with ctree.form at current pos by nrls;
593 if found, embed the derivation generated during comparison
594 if not, let the mat-engine compute the next ctree.form *)
595 (*structure copied from complete_solve
596 CAUTION: tacis in returned calcstate' do NOT construct resulting ptp --
597 all_modspec etc. has to be inserted at Subproblem'*)
598 fun compare_step ((tacis, c, ptp as (pt, pos as (p,p_))): calcstate') ifo =
602 Frm => get_obj g_form pt p
603 | Res => (fst o (get_obj g_result pt)) p
604 | _ => e_term (*on PblObj is fo <> ifo*);
605 val {nrls, ...} = get_met (get_obj g_metID pt (par_pblobj pt p))
606 val {rew_ord, erls, rules, ...} = rep_rls nrls
607 val (found, der) = concat_deriv rew_ord erls rules fo ifo; (*<---------------*)
612 val tacis' = map (mk_tacis rew_ord erls) der;
613 val (c', ptp) = embed_deriv tacis' ptp;
614 in ("ok", (tacis (*@ tacis'?WN050408*), c @ c', ptp)) end
617 then ("no derivation found", (tacis, c, ptp): calcstate')
620 val cs' as (tacis, c', ptp) = nxt_solve_ ptp; (*<---------------------*)
621 val cs' as (tacis, c'', ptp) =
623 ((Subproblem _, _, _)::_) =>
625 val ptp as (pt, (p,_)) = all_modspec ptp
626 val mI = get_obj g_metID pt p
628 nxt_solv (Apply_Method' (mI, NONE, e_istate, e_ctxt)) (e_istate, e_ctxt) ptp
631 in compare_step (tacis, c @ c' @ c'', ptp) ifo end
634 (* check if (agreed result, input formula) matches an error pattern modulo simplifier rls*)
635 fun check_err_patt (res, inf) (subst: subst) (errpatID: errpatID, pat) rls =
637 val (res', _, _, rewritten) =
638 rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) res;
643 val norm_res = case rewrite_set_inst_ (Isac()) false subst rls res' of
645 | SOME (norm_res, _) => norm_res
646 val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
648 | SOME (norm_inf, _) => norm_inf
649 in if norm_res = norm_inf then SOME errpatID else NONE
654 (*.handle a user-input formula, which may be a CAS-command, too.
656 create a calchead, and do 1 step
657 TOOODO.WN0602 works only for the root-problem !!!
658 formula, which is no CAS-command:
659 compare iform with calc-tree.form at pos by equ_nrls and all subsequent pos;
660 collect all the tacs applied by the way;
661 if "no derivation found" then check_error_patterns.
662 ALTERNATIVE: check_error_patterns _within_ compare_step seems too expensive.*)
663 fun inform (cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate') istr =
664 case parse (assoc_thy "Isac") istr of
667 val f_in = term_of f_in
668 val f_succ = (* the formula from "step pos cs" in appendFormula*)
670 Frm => get_obj g_form pt p
671 | Res => (fst o (get_obj g_result pt)) p
672 | _ => #3 (get_obj g_origin pt p)
675 then ("same-formula", cs) (* ctree not cut with replaceFormula *)
677 case cas_input f_in of
678 SOME (pt, _) => ("ok",([], [], (pt, (p, Met))))
680 let val msg_calcstate' = compare_step ([], [], (pt, lev_back' pos)) f_in
681 (*last step re-calc in compare_step TODO before WN09*)
683 case msg_calcstate' of
684 ("no derivation found", calcstate') =>
687 val pp = par_pblobj pt p
688 val {errpats, nrls, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
689 val ScrState (env, _, _, _, _, _) = get_istate pt pos
691 case check_error_patterns (f_succ, f_in) (prog, env) (errpats, nrls) of
692 SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
693 | NONE => msg_calcstate'
697 | _ => msg_calcstate'
700 | NONE => ("syntax error in '" ^ istr ^ "'", e_calcstate');
703 (*------------------------------------------------------------------(**)
706 (**)------------------------------------------------------------------*)