1 (* Handle user-input during the specify- and the solve-phase.
4 (c) due to copyright terms
19 | Given of cterm' list
20 | Relate of cterm' list
22 val imodel2fstr : iitem list -> (string * cterm') list
25 val Isac : 'a -> theory
28 SpecifyTools.ori list ->
29 SpecifyTools.itm list ->
30 ('a * (Term.term * Term.term)) list ->
31 string * cterm' -> SpecifyTools.itm
34 SpecifyTools.ori list ->
35 SpecifyTools.itm list ->
36 (string * (Term.term * Term.term)) list ->
37 (string * string) list -> SpecifyTools.itm list *)
38 (* val cas_input : string -> ptree * ocalhd *)
41 (Term.term * Term.term list) list ->
42 pblID * SpecifyTools.itm list * metID * SpecifyTools.itm list *
43 (bool * Term.term) list *)
45 calcstate' -> Term.term -> string * calcstate'
47 'a * ((Term.term * Term.term) list -> Term.term * Term.term -> bool)
53 bool * (Term.term * rule * (Term.term * Term.term list)) list *)
54 val dropwhile' : (* systest/auto-inform.sml *)
55 ('a -> 'b -> bool) -> 'a list -> 'b list -> 'a list * 'b list
58 Term.term * Term.term list ->
59 int list * bool * string * SpecifyTools.itm_ *)
60 (* val e_icalhd : icalhd *)
61 val eq7 : ''a * ''b -> ''a * (''b * 'c) -> bool
62 val equal : ''a -> ''a -> bool
64 SpecifyTools.ori list -> SpecifyTools.itm -> SpecifyTools.ori list *)
65 (* val filter_sep : ('a -> bool) -> 'a list -> 'a list * 'a list *)
66 (* val flattup2 : 'a * ('b * 'c * 'd * 'e) -> 'a * 'b * 'c * 'd * 'e *)
69 (''a * (Term.term * Term.term)) list ->
70 ''a * string -> int list * bool * ''a * SpecifyTools.itm_ *)
72 calcstate' -> cterm' -> string * calcstate'
73 val input_icalhd : ptree -> icalhd -> ptree * ocalhd
74 (* val is_Par : SpecifyTools.itm -> bool *)
75 (* val is_casinput : cterm' -> fmz -> bool *)
76 (* val is_e_ts : Term.term list -> bool *)
77 (* val itms2fstr : SpecifyTools.itm -> string * string *)
81 Term.term * rule * (Term.term * Term.term list) ->
82 tac * tac_ * (pos' * istate) *)
84 'a -> int -> SpecifyTools.ori list -> SpecifyTools.itm list
85 (* val par2fstr : SpecifyTools.itm -> string * cterm' *)
86 (* val parsitm : theory -> SpecifyTools.itm -> SpecifyTools.itm *)
87 val rev_deriv' : 'a * rule * ('b * 'c) -> 'b * rule * ('a * 'c)
90 (string * (Term.term * Term.term)) list ->
91 (string * string) list -> SpecifyTools.itm list *)
99 (***. handle an input calc-head .***)
101 (*------------------------------------------------------------------(**)
102 structure inform :INFORM =
104 (**)------------------------------------------------------------------*)
108 (*Where is never input*)
109 | Find of cterm' list
110 | Relate of cterm' list;
112 type imodel = iitem list;
114 (*calc-head as input*)
116 pos' * (*the position of the calc-head in the calc-tree
117 pos' as (p,p_) where p_ is neglected due to pos_ below*)
118 cterm' * (*the headline*)
119 imodel * (*the model (without Find) of the calc-head*)
120 pos_ * (*model belongs to Pbl or Met*)
121 spec; (*specification: domID, pblID, metID*)
122 val e_icalhd = (e_pos', "", [Given [""]], Pbl, e_spec): icalhd;
124 fun is_casinput (hdf: cterm') ((fmz_, spec): fmz) =
125 hdf <> "" andalso fmz_ = [] andalso spec = e_spec;
127 (*.handle an input as into an algebra system.*)
128 fun dtss2itm_ ppc (d, ts) =
129 let val (f, (d, id)) = the (find_first ((curry op= d) o
130 (#1: (term * term) -> term) o
131 (#2: pbt_ -> (term * term))) ppc)
132 in ([1], true, f, Cor ((d, ts), (id, ts))) end;
134 fun flattup2 (a,(b,c,d,e)) = (a,b,c,d,e);
136 fun cas_input_ ((dI,pI,mI): spec) dtss = (*WN110515 reconsider thy..ctxt*)
138 val thy = assoc_thy dI
139 val {ppc, ...} = get_pbt pI
140 val its_ = map (dtss2itm_ ppc) dtss (*([1],true,"#Given",Cor (...))*)
141 val its = add_id its_
142 val pits = map flattup2 its
147 case refine_pbl thy pI pits of
148 SOME (pI,_) => (pI, (hd o #met o get_pbt) pI)
149 | NONE => (pI, (hd o #met o get_pbt) pI)
150 val {ppc, pre, prls, ...} = get_met mI
151 val its_ = map (dtss2itm_ ppc) dtss (*([1],true,"#Given",Cor (...))*)
152 val its = add_id its_
153 val mits = map flattup2 its
154 val pre = check_preconds thy prls pre mits
155 val ctxt = e_ctxt (*WN110515 cas_input_ DOESNT WORK*)
156 in (pI, pits: itm list, mI, mits: itm list, pre, ctxt) end;
159 (* check if the input term is a CAScmd and return a ptree with a _complete_ calchead *)
161 let val (h,argl) = strip_comb hdt
163 case assoc_cas (assoc_thy "Isac") h of
165 | SOME (spec as (dI,_,_), argl2dtss) =>
167 val dtss = argl2dtss argl
168 val (pI, pits, mI, mits, pre, ctxt) = cas_input_ spec dtss
169 val spec = (dI, pI, mI)
171 cappend_problem e_ptree [] (e_istate, e_ctxt) ([], e_spec) ([], e_spec, hdt)
172 val pt = update_spec pt [] spec
173 val pt = update_pbl pt [] pits
174 val pt = update_met pt [] mits
175 val pt = update_ctxt pt [] ctxt
176 in SOME (pt, (true, Met, hdt, mits, pre, spec) : ocalhd) end
179 (*lazy evaluation for (Thy_Info.get_theory "Isac")*)
180 fun Isac _ = assoc_thy "Isac";
182 (*re-parse itms with a new thy and prepare for checking with ori list*)
183 fun parsitm dI (itm as (i,v,b,f, Cor ((d,ts),_)):itm) =
185 val t = comp_dts (d,ts);
186 val s = term_to_string''' dI t;
187 (*this ^ should raise the exn on unability of re-parsing dts*)
189 handle _ => ((i,v,false,f, Syn (term2str t)):itm))
190 | parsitm dI (itm as (i,v,b,f, Syn str)) =
191 (let val t = (term_of o the o (parse dI)) str
192 in (i,v,b,f, Par str) end
193 handle _ => (i,v,b,f, Syn str))
194 | parsitm dI (itm as (i,v,b,f, Typ str)) =
195 (let val t = (term_of o the o (parse dI)) str
196 in (i,v,b,f, Par str) end
197 handle _ => (i,v,b,f, Syn str))
198 | parsitm dI (itm as (i,v,_,f, Inc ((d,ts),_))) =
199 (let val t = comp_dts (d,ts);
200 val s = term_to_string''' dI t;
201 (*this ^ should raise the exn on unability of re-parsing dts*)
203 handle _ => ((i,v,false,f, Syn (term2str t)):itm))
204 | parsitm dI (itm as (i,v,_,f, Sup (d,ts))) =
205 (let val t = comp_dts (d,ts);
206 val s = term_to_string''' dI t;
207 (*this ^ should raise the exn on unability of re-parsing dts*)
209 handle _ => ((i,v,false,f, Syn (term2str t)):itm))
210 | parsitm dI (itm as (i,v,_,f, Mis (d,t'))) =
212 val s = term_to_string''' dI t;
213 (*this ^ should raise the exn on unability of re-parsing dts*)
215 handle _ => ((i,v,false,f, Syn (term2str t)):itm))
216 | parsitm dI (itm as (i,v,_,f, Par _)) =
217 error ("parsitm (" ^ itm2str_ (thy2ctxt dI) itm ^ "): Par should be internal");
219 (*separate a list to a pair of elements that do NOT satisfy the predicate,
220 and of elements that satisfy the predicate, i.e. (false, true)*)
221 fun filter_sep pred xs =
222 let fun filt ab [] = ab
223 | filt (a,b) (x :: xs) = if pred x
224 then filt (a,b@[x]) xs
225 else filt (a@[x],b) xs
226 in filt ([],[]) xs end;
227 fun is_Par ((_,_,_,_,Par _):itm) = true
230 fun is_e_ts [] = true
231 | is_e_ts [Const ("List.list.Nil", _)] = true
234 (*WN.9.11.03 copied from fun appl_add (in modspec.sml)*)
235 (* val (sel,ct) = selct;
236 val (dI, oris, ppc, pbt, (sel, ct))=
237 (#1 (some_spec ospec spec), oris, []:itm list,
238 ((#ppc o get_pbt) (#2 (some_spec ospec spec))),
239 hd (imodel2fstr imodel));
241 fun appl_add' dI oris ppc pbt (sel, ct) =
243 val ctxt = assoc_thy dI |> thy2ctxt;
244 in case parseNEW ctxt ct of
245 NONE => (0,[],false,sel, Syn ct):itm
246 | SOME t => (case is_known ctxt sel oris t of
248 (case is_notyet_input ctxt ppc all ori' pbt of
250 | (msg,_) => error ("appl_add': " ^ msg))
251 | (_, (i, v, _, d, ts), _) => if is_e_ts ts then
252 (i, v, false, sel, Inc ((d, ts), (e_term, []))) else
253 (i, v, false, sel, Sup (d, ts)))
256 (*.generate preliminary itm_ from a strin (with field "#Given" etc.).*)
257 (* val (f, str) = hd selcts;
259 fun eq7 (f, d) (f', (d', _)) = f=f' andalso d=d';
260 fun fstr2itm_ thy pbt (f, str) =
261 let val topt = parse thy str
263 NONE => ([], false, f, Syn str)
265 (* val SOME ct = parse thy str;
267 let val (d,ts) = (split_dts o term_of) ct
268 val popt = find_first (eq7 (f,d)) pbt
270 NONE => ([1](*??*), true(*??*), f, Sup (d,ts))
271 | SOME (f, (d, id)) => ([1], true, f, Cor ((d,ts), (id, ts)))
276 (*.input into empty PblObj, i.e. empty fmz+origin (unknown example).*)
277 fun unknown_expl dI pbt selcts =
279 val thy = assoc_thy dI
280 val its_ = map (fstr2itm_ thy pbt) selcts (*([1],true,"#Given",Cor (...))*)
281 val its = add_id its_
282 in (map flattup2 its): itm list end;
287 (*WN.11.03 for input_icalhd, ~ specify_additem for Add_Given/_Find/_Relation
288 appl_add': generate 1 item
289 appl_add' . is_known: parse, get data from oris (vats, all (elems if list)..)
290 appl_add' . is_notyet_input: compare with items in model already input
291 insert_ppc': insert this 1 item*)
292 (* val (dI,oris,ppc,pbt,selcts) =((#1 (some_spec ospec spec)),oris,[(*!!*)],
293 ((#ppc o get_pbt) (#2 (some_spec ospec spec))),
294 (imodel2fstr imodel));
296 fun appl_adds dI [] _ pbt selcts = unknown_expl dI pbt selcts
297 (*already present itms in model are being overwritten*)
298 | appl_adds dI oris ppc pbt [] = ppc
299 | appl_adds dI oris ppc pbt (selct::ss) =
300 (* val selct = (sel, string_of_cterm ct);
302 let val itm = appl_add' dI oris ppc pbt selct;
303 in appl_adds dI oris (insert_ppc' itm ppc) pbt ss end;
304 (* val (dI, oris, ppc, pbt, selct::ss) =
305 (dI, pors, probl, ppc, map itms2fstr probl);
308 (* val (dI, oris, ppc, pbt, (selct::ss))=
309 (#1 (some_spec ospec spec), oris, []:itm list,
310 ((#ppc o get_pbt) (#2 (some_spec ospec spec))),(imodel2fstr imodel));
311 val iii = appl_adds dI oris ppc pbt (selct::ss);
312 tracing(itms2str_ thy iii);
314 val itm = appl_add' dI oris ppc pbt selct;
315 val ppc = insert_ppc' itm ppc;
317 val _::selct::ss = (selct::ss);
318 val itm = appl_add' dI oris ppc pbt selct;
319 val ppc = insert_ppc' itm ppc;
321 val _::selct::ss = (selct::ss);
322 val itm = appl_add' dI oris ppc pbt selct;
323 val ppc = insert_ppc' itm ppc;
324 tracing(itms2str_ thy ppc);
326 val _::selct::ss = (selct::ss);
327 val itm = appl_add' dI oris ppc pbt selct;
328 val ppc = insert_ppc' itm ppc;
332 fun oris2itms _ _ ([]:ori list) = ([]:itm list)
333 | oris2itms pbt vat ((i,v,f,d,ts)::(os: ori list)) =
335 then (i,v,true,f,Cor ((d,ts),(e_term,[])))::(oris2itms pbt vat os)
336 else oris2itms pbt vat os;
338 fun filter_dsc oris itm =
339 filter_out ((curry op= ((d_in o #5) (itm:itm))) o
340 (#4:ori -> term)) oris;
345 fun par2fstr ((_,_,_,f, Par s):itm) = (f, s)
346 | par2fstr itm = error ("par2fstr: called with " ^
347 itm2str_ (thy2ctxt' "Isac") itm);
348 fun itms2fstr ((_,_,_,f, Cor ((d,ts),_)):itm) = (f, comp_dts'' (d,ts))
349 | itms2fstr (_,_,_,f, Syn str) = (f, str)
350 | itms2fstr (_,_,_,f, Typ str) = (f, str)
351 | itms2fstr (_,_,_,f, Inc ((d,ts),_)) = (f, comp_dts'' (d,ts))
352 | itms2fstr (_,_,_,f, Sup (d,ts)) = (f, comp_dts'' (d,ts))
353 | itms2fstr (_,_,_,f, Mis (d,t)) = (f, term2str (d $ t))
354 | itms2fstr (itm as (_,_,_,f, Par _)) =
355 error ("parsitm ("^itm2str_ (thy2ctxt' "Isac") itm ^
356 "): Par should be internal");
358 fun imodel2fstr iitems =
361 | xxx is ((Given strs)::iis) = xxx (is @ (map (pair "#Given") strs)) iis
362 | xxx is ((Find strs)::iis) = xxx (is @ (map (pair "#Find") strs)) iis
363 | xxx is ((Relate strs)::iis) = xxx (is @ (map (pair "#Relate") strs)) iis
364 in xxx [] iitems end;
366 (* input a calchead, WN110505 "prep_oris -> (_, ctxt)" not handled properly *)
367 fun input_icalhd pt (((p,_), hdf, imodel, Pbl, spec as (dI,pI,mI)):icalhd) =
368 let val PblObj {fmz = fmz as (fmz_,_), origin = (oris, ospec, hdf'),
369 spec = sspec as (sdI,spI,smI), probl, meth, ...} = get_obj I pt p;
370 in if is_casinput hdf fmz then the (cas_input (str2term hdf))
371 else (*hacked WN0602 ~~~ ~~~~~~~~~, ..dropped !*)
372 let val (pos_, pits, mits) =
374 then let val its = map (parsitm (assoc_thy dI)) probl;
375 val (its, trms) = filter_sep is_Par its;
376 val pbt = (#ppc o get_pbt) (#2(some_spec ospec sspec));
377 in (Pbl, appl_adds dI oris its pbt (map par2fstr trms), meth) end
379 then if pI = snd3 ospec then (Pbl, probl, meth)
381 let val pbt = (#ppc o get_pbt) pI
382 val dI' = #1 (some_spec ospec spec)
383 val oris = if pI = #2 ospec then oris
384 else prep_ori fmz_(assoc_thy"Isac") pbt |> #1;
385 in (Pbl, appl_adds dI' oris probl pbt
386 (map itms2fstr probl), meth) end
387 else if mI <> smI (*FIXME.WN0311: what if probl is incomplete?!*)
388 then let val met = (#ppc o get_met) mI
389 val mits = complete_metitms oris probl meth met
390 in if foldl and_ (true, map #3 mits)
391 then (Pbl, probl, mits) else (Met, probl, mits)
393 else (Pbl, appl_adds (#1 (some_spec ospec spec)) oris [(*!!!*)]
394 ((#ppc o get_pbt) (#2 (some_spec ospec spec)))
395 (imodel2fstr imodel), meth);
396 val pt = update_spec pt p spec;
398 then let val {prls,where_,...} = get_pbt (#2 (some_spec ospec spec))
399 val pre =check_preconds(assoc_thy"Isac")prls where_ pits
400 in (update_pbl pt p pits,
401 (ocalhd_complete pits pre spec, Pbl, hdf', pits, pre, spec):ocalhd)
403 else let val {prls,pre,...} = get_met (#3 (some_spec ospec spec))
404 val pre = check_preconds (assoc_thy"Isac") prls pre mits
405 in (update_met pt p mits,
406 (ocalhd_complete mits pre spec, Met, hdf', mits, pre, spec):ocalhd)
410 | input_icalhd pt ((p,_), hdf, imodel, _(*Met*), spec as (dI,pI,mI)) =
411 error "input_icalhd Met not impl.";
414 (***. handle an input formula .***)
416 Untersuchung zur Formeleingabe (appendFormula, replaceFormla) zu einer Anregung von Alan Krempler:
417 Welche RICHTIGEN Formeln koennen NICHT abgeleitet werden,
418 wenn Abteilungen nur auf gleichem Level gesucht werden ?
421 Beispiele zum Equationsolver von Richard Lang aus /src/sml/kbtest/rlang.sml
423 ------------------------------------------------------------------------------
424 "Schalk I s.87 Bsp 52a ((5*x)/(x - 2) - x/(x+2)=4)";
425 ------------------------------------------------------------------------------
426 1. "5 * x / (x - 2) - x / (x + 2) = 4"
428 4. "12 * x + 4 * x ^^^ 2 = 4 * (-4 + x ^^^ 2)",Subproblem["normalize", "poly"..
430 4.3. "16 + 12 * x = 0", Subproblem["degree_1", "polynomial", "univariate"..
432 4.3.3. "[x = -4 / 3]")), Check_elementwise "Assumptions"
435 ------------------------------------------------------------------------------
436 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
438 (4.1)..(4.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
439 ------------------------------------------------------------------------------
442 ------------------------------------------------------------------------------
443 "Schalk I s.87 Bsp 55b (x/(x^^^2 - 6*x+9) - 1/(x^^^2 - 3*x) =1/x)";
444 ------------------------------------------------------------------------------
445 1. "x / (x ^^^ 2 - 6 * x + 9) - 1 / (x ^^^ 2 - 3 * x) = 1 / x"
447 4. "(3 + (-1 * x + x ^^^ 2)) * x = 1 * (9 * x + (x ^^^ 3 + -6 * x ^^^ 2))"
448 Subproblem["normalize", "polynomial", "univariate"..
450 4.4. "-6 * x + 5 * x ^^^ 2 = 0", Subproblem["bdv_only", "degree_2", "poly"..
452 4.4.4. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
453 4.4.5. "[x = 0, x = 6 / 5]"
455 5. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
457 ------------------------------------------------------------------------------
458 (1)..(4): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite schiebt [Ableitung waere in 4.4.x]
460 (4.1)..(4.4.5): keine 'richtige' Eingabe kann abgeleitet werden, die dem Ergebnis "[x = 6 / 5]" aequivalent ist [Ableitung waere in 5.]
461 ------------------------------------------------------------------------------
464 ------------------------------------------------------------------------------
465 "Schalk II s.56 Bsp 73b (sqrt(x+1)+sqrt(4*x+4)=sqrt(9*x+9))";
466 ------------------------------------------------------------------------------
467 1. "sqrt (x + 1) + sqrt (4 * x + 4) = sqrt (9 * x + 9)"
469 6. "13 + 13 * x + -2 * sqrt ((4 + 4 * x) * (9 + 9 * x)) = 1 + x"
470 Subproblem["sq", "root'", "univariate", "equation"]
472 6.6. "144 + 288 * x + 144 * x ^^^ 2 = 144 + x ^^^ 2 + 288 * x + 143 * x ^^^ 2"
473 Subproblem["normalize", "polynomial", "univariate", "equation"]
475 6.6.3 "0 = 0" Subproblem["degree_0", "polynomial", "univariate", "equation"]
477 6.6.3.2 "UniversalList"
478 ------------------------------------------------------------------------------
479 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die eine der Wurzeln auf die andere Seite verschieb [Ableitung ware in 6.6.n]
481 (6.1)..(6.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 6.6.n]
482 ------------------------------------------------------------------------------
484 (*sh. comments auf 498*)
488 (*the lists contain eq-al elem-pairs at the beginning;
489 return first list reverted (again) - ie. in order as required subsequently*)
490 fun dropwhile' equal (f1::f2::fs) (i1::i2::is) =
492 if equal f2 i2 then dropwhile' equal (f2::fs) (i2::is)
493 else (rev (f1::f2::fs), i1::i2::is)
494 else error "dropwhile': did not start with equal elements"
495 | dropwhile' equal (f::fs) [i] =
496 if equal f i then (rev (f::fs), [i])
497 else error "dropwhile': did not start with equal elements"
498 | dropwhile' equal [f] (i::is) =
499 if equal f i then ([f], i::is)
500 else error "dropwhile': did not start with equal elements";
503 val foder = [0,1,2,3,4,5]; val ifoder = [11,12,3,4,5];
504 val r_foder = rev foder; val r_ifoder = rev ifoder;
505 dropwhile' equal r_foder r_ifoder;
506 > vval it = ([0, 1, 2, 3], [3, 12, 11]) : int list * int list
508 val foder = [3,4,5]; val ifoder = [11,12,3,4,5];
509 val r_foder = rev foder; val r_ifoder = rev ifoder;
510 dropwhile' equal r_foder r_ifoder;
511 > val it = ([3], [3, 12, 11]) : int list * int list
513 val foder = [5]; val ifoder = [11,12,3,4,5];
514 val r_foder = rev foder; val r_ifoder = rev ifoder;
515 dropwhile' equal r_foder r_ifoder;
516 > val it = ([5], [5, 4, 3, 12, 11]) : int list * int list
518 val foder = [10,11,12,13,14,15]; 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 > *** dropwhile': did not start with equal elements*)
523 (*040214: version for concat_deriv*)
524 fun rev_deriv' (t, r, (t', a)) = (t', sym_rule r, (t, a));
526 fun mk_tacis ro erls (t, r as Thm _, (t', a)) =
527 (Rewrite (rule2thm' r),
528 Rewrite' ("Isac", fst ro, erls, false, rule2thm' r, t, (t', a)),
529 (e_pos'(*to be updated before generate tacis!!!*), (Uistate, e_ctxt)))
530 | mk_tacis ro erls (t, r as Rls_ rls, (t', a)) =
531 (Rewrite_Set (rule2rls' r),
532 Rewrite_Set' ("Isac", false, rls, t, (t', a)),
533 (e_pos'(*to be updated before generate tacis!!!*), (Uistate, e_ctxt)));
535 (*fo = ifo excluded already in inform*)
536 fun concat_deriv rew_ord erls rules fo ifo =
537 let fun derivat ([]:(term * rule * (term * term list)) list) = e_term
538 | derivat dt = (#1 o #3 o last_elem) dt
539 fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1=t2
540 val fod = make_deriv (Isac"") erls rules (snd rew_ord) NONE fo
541 val ifod = make_deriv (Isac"") erls rules (snd rew_ord) NONE ifo
542 in case (fod, ifod) of
543 ([], []) => if fo = ifo then (true, [])
545 | (fod, []) => if derivat fod = ifo
546 then (true, fod) (*ifo is normal form*)
548 | ([], ifod) => if fo = derivat ifod
549 then (true, ((map rev_deriv') o rev) ifod)
552 if derivat fod = derivat ifod (*common normal form found*)
553 then let val (fod', rifod') =
554 dropwhile' equal (rev fod) (rev ifod)
555 in (true, fod' @ (map rev_deriv' rifod')) end
559 val ({rew_ord, erls, rules,...}, fo, ifo) =
560 (rep_rls Test_simplify, str2term "x+1+ -1*2=0", str2term "-2*1+(x+1)=0");
561 (tracing o trtas2str) fod';
563 (x + 1 + -1 * 2 = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (x + 1) = 0, []))","
564 (-1 * 2 + (x + 1) = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (1 + x) = 0, []))","
565 (-1 * 2 + (1 + x) = 0, Thm ("radd_left_commute","?x + (?y + ?z) = ?y + (?x + ?z)"), (1 + (-1 * 2 + x) = 0, []))","
566 (1 + (-1 * 2 + x) = 0, Thm ("#mult_Float ((~1,0), (0,0)) __ ((2,0), (0,0))","-1 * 2 = -2"), (1 + (-2 + x) = 0, []))"]
568 (tracing o trtas2str) (map rev_deriv' rifod');
570 (1 + (-2 + x) = 0, Thm ("sym_#mult_Float ((~2,0), (0,0)) __ ((1,0), (0,0))","-2 = -2 * 1"), (1 + (-2 * 1 + x) = 0, []))","
571 (1 + (-2 * 1 + x) = 0, Thm ("sym_radd_left_commute","?y + (?x + ?z) = ?x + (?y + ?z)"), (-2 * 1 + (1 + x) = 0, []))","
572 (-2 * 1 + (1 + x) = 0, Thm ("sym_radd_commute","?n + ?m = ?m + ?n"), (-2 * 1 + (x + 1) = 0, []))"]
577 (* compare inform with ctree.form at current pos by nrls;
578 if found, embed the derivation generated during comparison
579 if not, let the mat-engine compute the next ctree.form *)
580 (*structure copied from complete_solve
581 CAUTION: tacis in returned calcstate' do NOT construct resulting ptp --
582 all_modspec etc. has to be inserted at Subproblem'*)
583 fun compare_step ((tacis, c, ptp as (pt, pos as (p,p_))): calcstate') ifo =
587 Frm => get_obj g_form pt p
588 | Res => (fst o (get_obj g_result pt)) p
589 | _ => e_term (*on PblObj is fo <> ifo*);
590 val {nrls, ...} = get_met (get_obj g_metID pt (par_pblobj pt p))
591 val {rew_ord, erls, rules, ...} = rep_rls nrls
592 val (found, der) = concat_deriv rew_ord erls rules fo ifo; (*<---------------*)
597 val tacis' = map (mk_tacis rew_ord erls) der;
598 val (c', ptp) = embed_deriv tacis' ptp;
599 in ("ok", (tacis (*@ tacis'?WN050408*), c @ c', ptp)) end
602 then ("no derivation found", (tacis, c, ptp): calcstate')
605 val cs' as (tacis, c', ptp) = nxt_solve_ ptp; (*<---------------------*)
606 val cs' as (tacis, c'', ptp) =
608 ((Subproblem _, _, _)::_) =>
610 val ptp as (pt, (p,_)) = all_modspec ptp
611 val mI = get_obj g_metID pt p
613 nxt_solv (Apply_Method' (mI, NONE, e_istate, e_ctxt)) (e_istate, e_ctxt) ptp
616 in compare_step (tacis, c @ c' @ c'', ptp) ifo end
619 (* check if (agreed result, input formula) matches the error pattern "pat" modulo simplifier rls *)
620 fun check_err_patt (res, inf) (subst: subst) (errpatID: errpatID, pat) rls =
622 val (res', _, _, rewritten) =
623 rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) res;
628 val norm_res = case rewrite_set_inst_ (Isac()) false subst rls res' of
630 | SOME (norm_res, _) => norm_res
631 val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
633 | SOME (norm_inf, _) => norm_inf
634 in if norm_res = norm_inf then SOME errpatID else NONE
639 (* check if (agreed result, input formula) matches SOME error pattern modulo simplifier rls;
640 (prog, env) for retrieval of casual substitution for bdv in the pattern. *)
641 fun check_error_patterns (res, inf) (prog, env) (errpats, rls) =
643 val (_, subst) = get_bdv_subst prog env
644 fun scan (_, [], _) = NONE
645 | scan (errpatID, errpat :: errpats, _) =
646 case check_err_patt (res, inf) (subst: subst) (errpatID, errpat) rls of
647 NONE => scan (errpatID, errpats, [])
648 | SOME errpatID => SOME errpatID
650 | scans (group :: groups) =
653 | SOME errpatID => SOME errpatID
654 in scans errpats end;
656 (*.handle a user-input formula, which may be a CAS-command, too.
658 create a calchead, and do 1 step
659 TOOODO.WN0602 works only for the root-problem !!!
660 formula, which is no CAS-command:
661 compare iform with calc-tree.form at pos by equ_nrls and all subsequent pos;
662 collect all the tacs applied by the way;
663 if "no derivation found" then check_error_patterns.
664 ALTERNATIVE: check_error_patterns _within_ compare_step seems too expensive.*)
665 fun inform (cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate') istr =
666 case parse (assoc_thy "Isac") istr of
669 val f_in = term_of f_in
670 val f_succ = get_curr_formula (pt, pos);
673 then ("same-formula", cs) (* ctree not cut with replaceFormula *)
675 case cas_input f_in of
676 SOME (pt, _) => ("ok",([], [], (pt, (p, Met))))
679 val pos_pred = lev_back' pos
680 (* f_pred ---"step pos cs"---> f_succ in appendFormula *)
681 val f_pred = get_curr_formula (pt, pos_pred)
682 val msg_calcstate' = compare_step ([], [], (pt, pos_pred)) f_in (*<<=====*)
683 (*last step re-calc in compare_step TODO before WN09*)
685 case msg_calcstate' of
686 ("no derivation found", calcstate') =>
688 val pp = par_pblobj pt p
689 val {errpats, nrls, scr = Prog prog, ...} = get_met (get_obj g_metID pt pp)
690 val ScrState (env, _, _, _, _, _) = get_istate pt pos
692 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
693 SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
694 | NONE => msg_calcstate'
696 | _ => msg_calcstate'
699 | NONE => ("syntax error in '" ^ istr ^ "'", e_calcstate');
701 (* fill-in patterns an forms.
702 returns thm required by "fun in_fillform *)
703 fun get_fillform (subs_opt, subst) (thm, form) errpatID ((fillpatID, pat, erpaID): fillpat) =
705 val (form', _, _, rewritten) =
706 rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
707 in (*the fillpat of the thm must be dedicated to errpatID*)
708 if errpatID = erpaID andalso rewritten
709 then SOME (fillpatID, HOLogic.mk_eq (form, form'), thm, subs_opt) else NONE end;
711 fun get_fillpats subst form errpatID thm =
713 val thmDeriv = Thm.get_name_hint thm
714 val (part, thyID) = thy_containing_thm thmDeriv
715 val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
716 val Hthm {fillpats, ...} = get_the theID
717 val some = map (get_fillform subst (thm, form) errpatID) fillpats
718 in some |> filter is_some |> map the end;
720 fun find_fillpatterns (pt, pos as (p, _): pos') errpatID =
722 val f_curr = get_curr_formula (pt, pos);
723 val pp = par_pblobj pt p
724 val {errpats, scr = Prog prog, ...} = get_met (get_obj g_metID pt pp)
725 val ScrState (env, _, _, _, _, _) = get_istate pt pos
726 val subst = get_bdv_subst prog env
727 val errpatthms = errpats
728 |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
729 |> map (#3: errpat -> thm list)
731 in map (get_fillpats subst f_curr errpatID) errpatthms |> flat end;
733 (* check if an input formula is exactly equal the rewrite from a rule
734 which is stored at the pos where the input is stored of "ok". *)
735 fun is_exactly_equal (pt, pos as (p, _)) istr =
736 case parseNEW (assoc_thy "Isac" |> thy2ctxt) istr of
737 NONE => ("syntax error in '" ^ istr ^ "'", Tac "")
741 val tac = get_obj g_tac pt p';
743 case applicable_in pos pt tac of
744 Notappl msg => (msg, Tac "")
747 val res = case rew of
748 Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) => res
749 | Rewrite' (_, _, _, _, _, _, (res, _)) => res
752 then ("input does not exactly fill the gaps", Tac "")
757 (* fetch errpatIDs from an arbitrary tactic *)
758 fun fetchErrorpatterns tac =
762 Rewrite_Set rlsID => rlsID
763 | Rewrite_Set_Inst (_, rlsID) => rlsID
765 val (part, thyID) = thy_containing_rls "Isac" rlsID;
766 val Hrls {thy_rls = (_, rls), ...} = get_the [part, thyID, "Rulesets", rlsID]
768 Rls {errpatts, ...} => errpatts
769 | Seq {errpatts, ...} => errpatts
770 | Rrls {errpatts, ...} => errpatts
774 (*------------------------------------------------------------------(**)
777 (**)------------------------------------------------------------------*)