1 (* Title: tests on inform.sml
2 Author: Walther Neuper 060225,
3 (c) due to copyright terms
5 use"../smltest/ME/inform.sml";
9 "-----------------------------------------------------------------";
10 "table of contents -----------------------------------------------";
11 "-----------------------------------------------------------------";
12 "appendForm with miniscript with mini-subpbl:";
13 "--------- appendFormula: on Res + equ_nrls ----------------------";
14 "--------- appendFormula: on Frm + equ_nrls ----------------------";
15 "--------- appendFormula: on Res + NO deriv ----------------------";
16 "--------- appendFormula: on Res + late deriv --------------------";
17 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
18 "replaceForm with miniscript with mini-subpbl:";
19 "--------- replaceFormula: on Res + = ----------------------------";
20 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
21 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
22 "--------- replaceFormula: cut calculation -----------------------";
23 "--------- replaceFormula: cut calculation -----------------------";
24 (* 040307 copied from informtest.sml ... old versions
25 "--------- maximum-example, UC: Modeling / modifyCalcHead --------";*)
26 "--------- syntax error ------------------------------------------";
28 "--------- CAS-command on ([],Pbl) -------------------------------";
29 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
30 "--------- inform [rational,simplification] ----------------------";
31 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
32 "--------- Take as 1st tac, start from exp -----------------------";
33 "--------- init_form, start with <NEW> (CAS input) ---------------";
34 "--------- build fun check_err_patt ------------------------------";
35 "--------- build fun check_err_patt ?bdv -------------------------";
36 "--------- build fun check_error_patterns ------------------------";
37 "--------- embed fun check_error_patterns ------------------------";
38 "--------- embed fun find_fillpatterns ---------------------------";
39 "-----------------------------------------------------------------";
40 "-----------------------------------------------------------------";
41 "-----------------------------------------------------------------";
44 "--------- appendFormula: on Res + equ_nrls ----------------------";
45 "--------- appendFormula: on Res + equ_nrls ----------------------";
46 "--------- appendFormula: on Res + equ_nrls ----------------------";
48 val Script sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
49 (writeln o term2str) sc;
50 val Script sc = (#scr o get_met) ["Test","solve_linear"];
51 (writeln o term2str) sc;
54 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
55 ("Test", ["sqroot-test","univariate","equation","test"],
56 ["Test","squ-equ-test-subpbl1"]))];
57 Iterator 1; moveActiveRoot 1;
58 autoCalculate 1 CompleteCalcHead;
59 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
60 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
62 appendFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
63 val ((pt,_),_) = get_calc 1;
64 val str = pr_ptree pr_short pt;
67 (*============ inhibit exn AK110726 ==============================================
68 (* 2nd string should be the same as 1st one *)
69 ". ----- pblobj -----\n1. x + 1 = 2\n2. x + 1 + -1 * 2 = 0\n2.1. x + 1 + -1 * 2 = 0\n2.2. 1 + x + -1 * 2 = 0\n2.3. 1 + (x + -1 * 2) = 0\n2.4. 1 + (x + -2) = 0\n2.5. 1 + (x + -2 * 1) = 0\n2.6. 1 + x + -2 * 1 = 0\n";
70 ". ----- pblobj -----\n1. x + 1 = 2\n2. x + 1 + -1 * 2 = 0\n2.1. x + 1 + -1 * 2 = 0\n2.2. -1 * 2 + (x + 1) = 0\n2.3. -1 * 2 + (1 + x) = 0\n2.4. 1 + (-1 * 2 + x) = 0\n2.5. 1 + (-2 + x) = 0\n2.6. 1 + (-2 * 1 + x) = 0\n";
71 if str = ". ----- pblobj -----\n1. x + 1 = 2\n2. x + 1 + -1 * 2 = 0\n2.1. x + 1 + -1 * 2 = 0\n2.2. -1 * 2 + (x + 1) = 0\n2.3. -1 * 2 + (1 + x) = 0\n2.4. 1 + (-1 * 2 + x) = 0\n2.5. 1 + (-2 + x) = 0\n2.6. 1 + (-2 * 1 + x) = 0\n" then ()
72 else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
73 ============ inhibit exn AK110726 ==============================================*)
75 moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
76 moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
78 (*the seven steps of detailed derivation*)
79 moveDown 1 ([1 ],Res); refFormula 1 ([2,1],Frm);
80 moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
81 moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
82 moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res);
83 moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
84 moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
85 moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
86 val ((pt,_),_) = get_calc 1;
87 if "-2 * 1 + (1 + x) = 0" = term2str (fst (get_obj g_result pt [2,6])) then()
88 else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
90 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
92 (*============ inhibit exn AK110725 ==============================================
93 (* ERROR: exception Bind raised *)
94 val (_,(tac,_,_)::_) = get_calc 1;
95 if tac = Rewrite_Set "Test_simplify" then ()
96 else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
97 ============ inhibit exn AK110725 ==============================================*)
99 autoCalculate 1 CompleteCalc;
100 val ((pt,_),_) = get_calc 1;
101 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
102 else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
103 (* autoCalculate 1 CompleteCalc;
104 val ((pt,p),_) = get_calc 1;
105 (writeln o istates2str) (get_obj g_loc pt [ ]);
106 (writeln o istates2str) (get_obj g_loc pt [1]);
107 (writeln o istates2str) (get_obj g_loc pt [2]);
108 (writeln o istates2str) (get_obj g_loc pt [3]);
109 (writeln o istates2str) (get_obj g_loc pt [3,1]);
110 (writeln o istates2str) (get_obj g_loc pt [3,2]);
111 (writeln o istates2str) (get_obj g_loc pt [4]);
114 "----------------------------------------------------------";
116 val fod = make_deriv (@{theory "Isac"}) Atools_erls
117 ((#rules o rep_rls) Test_simplify)
118 (sqrt_right false (@{theory "Pure"})) NONE
119 (str2term "x + 1 + -1 * 2 = 0");
120 (writeln o trtas2str) fod;
122 val ifod = make_deriv (@{theory "Isac"}) Atools_erls
123 ((#rules o rep_rls) Test_simplify)
124 (sqrt_right false (@{theory "Pure"})) NONE
125 (str2term "-2 * 1 + (1 + x) = 0");
126 (writeln o trtas2str) ifod;
127 fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
128 val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
129 val der = fod' @ (map rev_deriv' rifod');
130 (writeln o trtas2str) der;
131 "----------------------------------------------------------";
134 "--------- appendFormula: on Frm + equ_nrls ----------------------";
135 "--------- appendFormula: on Frm + equ_nrls ----------------------";
136 "--------- appendFormula: on Frm + equ_nrls ----------------------";
138 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
139 ("Test", ["sqroot-test","univariate","equation","test"],
140 ["Test","squ-equ-test-subpbl1"]))];
141 Iterator 1; moveActiveRoot 1;
142 autoCalculate 1 CompleteCalcHead;
143 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
144 appendFormula 1 "2+ -1 + x = 2"; refFormula 1 (get_pos 1 1);
146 moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
148 moveDown 1 ([1 ],Frm); refFormula 1 ([1,1],Frm);
149 moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res);
150 moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res);
151 moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res);
152 moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res);
153 moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res);
154 moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res);
155 val ((pt,_),_) = get_calc 1;
156 if "2 + -1 + x = 2" = term2str (fst (get_obj g_result pt [1,6])) then()
157 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
159 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
160 val (_,(tac,_,_)::_) = get_calc 1;
161 if tac = Rewrite_Set "norm_equation" then ()
162 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
163 autoCalculate 1 CompleteCalc;
164 val ((pt,_),_) = get_calc 1;
165 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
166 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
169 "--------- appendFormula: on Res + NO deriv ----------------------";
170 "--------- appendFormula: on Res + NO deriv ----------------------";
171 "--------- appendFormula: on Res + NO deriv ----------------------";
173 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
174 ("Test", ["sqroot-test","univariate","equation","test"],
175 ["Test","squ-equ-test-subpbl1"]))];
176 Iterator 1; moveActiveRoot 1;
177 autoCalculate 1 CompleteCalcHead;
178 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
179 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
181 appendFormula 1 "x = 2";
182 val ((pt,p),_) = get_calc 1;
183 val str = pr_ptree pr_short pt;
185 if str = ". ----- pblobj -----\n1. x + 1 = 2\n" andalso p = ([1], Res)
187 else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
189 fetchProposedTactic 1;
190 val (_,(tac,_,_)::_) = get_calc 1;
191 if tac = Rewrite_Set "Test_simplify" then ()
192 else error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
193 autoCalculate 1 CompleteCalc;
194 val ((pt,_),_) = get_calc 1;
195 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
196 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
199 "--------- appendFormula: on Res + late deriv --------------------";
200 "--------- appendFormula: on Res + late deriv --------------------";
201 "--------- appendFormula: on Res + late deriv --------------------";
203 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
204 ("Test", ["sqroot-test","univariate","equation","test"],
205 ["Test","squ-equ-test-subpbl1"]))];
206 Iterator 1; moveActiveRoot 1;
207 autoCalculate 1 CompleteCalcHead;
208 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
209 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
211 appendFormula 1 "x = 1";
212 val ((pt,p),_) = get_calc 1;
213 val str = pr_ptree pr_short pt;
215 if str = ". ----- pblobj -----\n1. x + 1 = 2\n2. x + 1 + -1 * 2 = 0\n3. ----- pblobj -----\n3.1. -1 + x = 0\n3.2. x = 0 + -1 * -1\n3.2.1. x = 0 + -1 * -1\n3.2.2. x = 0 + 1\n" andalso p = ([3,2], Res)
216 then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
217 else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
219 fetchProposedTactic 1;
220 val (_,(tac,_,_)::_) = get_calc 1;
221 if tac = Check_Postcond ["linear", "univariate", "equation", "test"] then ()
222 else error "inform.sml: diff.behav.appendFormula: Res + late d 2";
223 autoCalculate 1 CompleteCalc;
224 val ((pt,_),_) = get_calc 1;
225 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
226 else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
229 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
230 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
231 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
233 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
234 ("Test", ["sqroot-test","univariate","equation","test"],
235 ["Test","squ-equ-test-subpbl1"]))];
236 Iterator 1; moveActiveRoot 1;
237 autoCalculate 1 CompleteCalcHead;
238 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
239 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
240 appendFormula 1 "[x = 3 + -2*1]";
241 val ((pt,p),_) = get_calc 1;
242 val str = pr_ptree pr_short pt;
244 if str=". ----- pblobj -----\n1. x + 1 = 2\n2. x + 1 + -1 * 2 = 0\n3. ----- pblobj -----\n3.1. -1 + x = 0\n3.2. x = 0 + -1 * -1\n4. [x = 1]\n4.1. [x = 1]\n4.2. [x = -2 + 3]\n4.3. [x = 3 + -2]\n" then ()
245 else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
246 autoCalculate 1 CompleteCalc;
247 val ((pt,p),_) = get_calc 1;
248 if "[x = 3 + -2 * 1]" = term2str (fst (get_obj g_result pt [])) then ()
249 (* ~~~~~~~~~~ simplify as last step in any script ?!*)
250 else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
254 "--------- replaceFormula: on Res + = ----------------------------";
255 "--------- replaceFormula: on Res + = ----------------------------";
256 "--------- replaceFormula: on Res + = ----------------------------";
258 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
259 ("Test", ["sqroot-test","univariate","equation","test"],
260 ["Test","squ-equ-test-subpbl1"]))];
261 Iterator 1; moveActiveRoot 1;
262 autoCalculate 1 CompleteCalcHead;
263 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
264 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
265 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
267 replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
268 val ((pt,_),_) = get_calc 1;
269 val str = pr_ptree pr_short pt;
272 (*============ inhibit exn AK110725 ==============================================
273 (* 2nd string should be the same as 1st one *)
274 ". ----- pblobj -----\n1. x + 1 = 2\n2. x + 1 + -1 * 2 = 0\n2.1. x + 1 + -1 * 2 = 0\n2.2. 1 + x + -1 * 2 = 0\n2.3. 1 + (x + -1 * 2) = 0\n2.4. 1 + (x + -2) = 0\n2.5. 1 + (x + -2 * 1) = 0\n2.6. 1 + x + -2 * 1 = 0\n";
275 ". ----- pblobj -----\n1. x + 1 = 2\n2. x + 1 + -1 * 2 = 0\n2.1. x + 1 + -1 * 2 = 0\n2.2. -1 * 2 + (x + 1) = 0\n2.3. -1 * 2 + (1 + x) = 0\n2.4. 1 + (-1 * 2 + x) = 0\n2.5. 1 + (-2 + x) = 0\n2.6. 1 + (-2 * 1 + x) = 0\n";
276 if str = ". ----- pblobj -----\n1. x + 1 = 2\n2. x + 1 + -1 * 2 = 0\n2.1. x + 1 + -1 * 2 = 0\n2.2. -1 * 2 + (x + 1) = 0\n2.3. -1 * 2 + (1 + x) = 0\n2.4. 1 + (-1 * 2 + x) = 0\n2.5. 1 + (-2 + x) = 0\n2.6. 1 + (-2 * 1 + x) = 0\n" then()
277 else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
278 ============ inhibit exn AK110725 ==============================================*)
280 autoCalculate 1 CompleteCalc;
281 val ((pt,pos as (p,_)),_) = get_calc 1;
282 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst) (get_obj g_result pt p) then()
283 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
286 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
287 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
288 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
290 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
291 ("Test", ["sqroot-test","univariate","equation","test"],
292 ["Test","squ-equ-test-subpbl1"]))];
293 Iterator 1; moveActiveRoot 1;
294 autoCalculate 1 CompleteCalcHead;
295 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
296 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
298 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
299 val ((pt,_),_) = get_calc 1;
300 val str = pr_ptree pr_short pt;
302 if str= ". ----- pblobj -----\n1. x + 1 = 2\n1.1. x + 1 = 2\n1.2. 1 + x = 2\n1.3. 1 + x = -2 + 4\n1.4. x + 1 = -2 + 4\n" then ()
303 else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
304 autoCalculate 1 CompleteCalc;
305 val ((pt,pos as (p,_)),_) = get_calc 1;
306 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
307 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
310 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
311 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
312 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
314 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
315 ("Test", ["sqroot-test","univariate","equation","test"],
316 ["Test","squ-equ-test-subpbl1"]))];
317 Iterator 1; moveActiveRoot 1;
318 autoCalculate 1 CompleteCalcHead;
319 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
321 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
322 val ((pt,_),_) = get_calc 1;
323 val str = pr_ptree pr_short pt;
325 if str= ". ----- pblobj -----\n1. x + 1 = 2\n1.1. x + 1 = 2\n1.2. 1 + x = 2\n1.3. 1 + x = -2 + 4\n1.4. x + 1 = -2 + 4\n" then ()
326 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
327 autoCalculate 1 CompleteCalc;
328 val ((pt,pos as (p,_)),_) = get_calc 1;
329 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
330 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
333 "--------- replaceFormula: cut calculation -----------------------";
334 "--------- replaceFormula: cut calculation -----------------------";
335 "--------- replaceFormula: cut calculation -----------------------";
337 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
338 ("Test", ["sqroot-test","univariate","equation","test"],
339 ["Test","squ-equ-test-subpbl1"]))];
340 Iterator 1; moveActiveRoot 1;
341 autoCalculate 1 CompleteCalc;
342 moveActiveRoot 1; moveActiveDown 1;
343 if get_pos 1 1 = ([1], Frm) then ()
344 else error "inform.sml: diff.behav. cut calculation 1";
346 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
347 val ((pt,p),_) = get_calc 1;
348 val str = pr_ptree pr_short pt;
350 if p = ([1], Res) then ()
351 else error "inform.sml: diff.behav. cut calculation 2";
354 (* 040307 copied from informtest.sml; ... old version
355 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
356 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
357 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
360 val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
361 "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
362 "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
363 "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
364 (*^^^ these are the elements for the root-problem (in variants)*)
365 (*vvv these are elements required for subproblems*)
366 "boundVariable a","boundVariable b","boundVariable alpha",
367 "interval {x::real. 0 <= x & x <= 2*r}",
368 "interval {x::real. 0 <= x & x <= 2*r}",
369 "interval {x::real. 0 <= x & x <= pi}",
370 "errorBound (eps=(0::real))"]
371 (*specifying is not interesting for this example*)
372 val spec = ("DiffApp", ["maximum_of","function"],
373 ["DiffApp","max_by_calculus"]);
374 (*the empty model with descriptions for user-guidance by Model_Problem*)
375 val empty_model = [Given ["fixedValues []"],
376 Find ["maximum", "valuesFor"],
377 Relate ["relations []"]];
380 (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
381 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
382 (*val nxt = ("Model_Problem", ...*)
383 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
385 val (p,_,f,nxt,_,pt) = me nxt p c pt;
386 (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
387 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
389 (0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
390 (0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
391 (0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
392 (0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
394 (*the empty CalcHead is checked w.r.t the model and re-established as such*)
395 val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, e_spec);
396 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
397 if ocalhd2str ocalhd = "(Pbl, ??.empty, [\n(0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),\n(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),\n(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),\n(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))], [], \n(\"e_domID\", [\"e_pblID\"], [\"e_metID\"]) )" then () else error "informtest.sml: diff.behav. max 1";
399 (*there is one input to the model (could be more)*)
401 input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
402 Find ["maximum", "valuesFor"],
403 Relate ["relations"]], Pbl, e_spec);
404 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
405 if ocalhd2str ocalhd = "(Pbl, ??.empty, [\n(1 ,[1,2,3] ,true ,#Given ,Cor fixedValues [r = Arbfix] ,(fix_, [[r = Arbfix]])),\n(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),\n(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),\n(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))], [], \n(\"e_domID\", [\"e_pblID\"], [\"e_metID\"]) )" then ()
406 else error "informtest.sml: diff.behav. max 2";
408 (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
409 val (b,pt''''',ocalhd) =
410 input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
411 Find ["maximum A", "valuesFor [a,b]"],
412 Relate ["relations [A=a*b, a/2=r*sin alpha, \
413 \b/2=r*cos alpha]"]], Pbl, e_spec);
414 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl;
415 if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
417 (*this input is complete in variant 1 (variant 3 does not work yet)*)
418 val (b,pt''''',ocalhd) =
419 input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
420 Find ["maximum A", "valuesFor [a,b]"],
421 Relate ["relations [A=a*b, \
422 \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]],
424 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl;
426 modifycalcheadOK2xml 111 (bool2str b) ocalhd;
429 "--------- syntax error ------------------------------------------";
430 "--------- syntax error ------------------------------------------";
431 "--------- syntax error ------------------------------------------";
433 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
434 ("Test", ["sqroot-test","univariate","equation","test"],
435 ["Test","squ-equ-test-subpbl1"]))];
436 Iterator 1; moveActiveRoot 1;
437 autoCalculate 1 CompleteCalcHead;
438 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
439 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
441 appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
442 val ((pt,_),_) = get_calc 1;
443 val str = pr_ptree pr_short pt;
445 if str = ". ----- pblobj -----\n1. x + 1 = 2\n" then ()
446 else error "inform.sml: diff.behav.appendFormula: syntax error";
449 "--------- CAS-command on ([],Pbl) -------------------------------";
450 "--------- CAS-command on ([],Pbl) -------------------------------";
451 "--------- CAS-command on ([],Pbl) -------------------------------";
452 val (p,_,f,nxt,_,pt) =
453 CalcTreeTEST [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
454 val ifo = "solve(x+1=2,x)";
455 val (_,(_,c,(pt,p))) = inform ([],[],(pt,p)) "solve(x+1=2,x)";
457 val nxt = ("Apply_Method",Apply_Method ["Test","squ-equ-test-subpbl1"]);
458 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
459 if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
460 else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
463 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
464 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
465 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
467 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
470 replaceFormula 1 "solve(x+1=2,x)";
471 autoCalculate 1 CompleteCalc;
472 val ((pt,p),_) = get_calc 1;
474 if p = ([], Res) then ()
475 else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
478 "--------- inform [rational,simplification] ----------------------";
479 "--------- inform [rational,simplification] ----------------------";
480 "--------- inform [rational,simplification] ----------------------";
482 CalcTree [(["Term (4/x - 3/y - 1)", "normalform N"],
483 ("Rational",["rational","simplification"],
484 ["simplification","of_rationals"]))];
485 Iterator 1; moveActiveRoot 1;
486 autoCalculate 1 CompleteCalcHead;
487 autoCalculate 1 (Step 1);
488 autoCalculate 1 (Step 1);
489 autoCalculate 1 (Step 1);
490 autoCalculate 1 (Step 1);
491 "--- input the next formula that _should_ be presented by mat-engine";
492 appendFormula 1 "(4 * y + -3 * x) / (x * y) + -1";
493 val ((pt,p),_) = get_calc 1;
494 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
495 else error ("inform.sml: [rational,simplification] 1");
497 "--- input the next formula that would be presented by mat-engine";
498 (*autoCalculate 1 (Step 1);*)
499 appendFormula 1 "(4 * y + -3 * x + -1 * (x * y)) / (x * y)";
500 val ((pt,p),_) = get_calc 1;
501 if p = ([5], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
502 else error ("inform.sml: [rational,simplification] 2");
504 "--- input the exact final result";(*TODO: Exception- LIST "last_elem" raised*)
505 appendFormula 1 "(-3 * x + 4 * y + -1 * x * y) / (x * y)";
506 val ((pt,p),_) = get_calc 1;
507 if p = ([6], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
508 else error ("inform.sml: [rational,simplification] 3");
511 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
512 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
513 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
514 val t = str2term "Diff (x^^^2 + x + 1, x)";
515 case t of Const ("Diff.Diff", _) $ _ => ()
517 error "diff.sml behav.changed for CAS Diff (..., x)";
519 "-----------------------------------------------------------------";
521 (*2>*)CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
522 (*3>*)Iterator 1;moveActiveRoot 1;
523 "----- here the Headline has been finished";
524 (*4>*)moveActiveFormula 1 ([],Pbl);
525 (*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
526 val ((pt,_),_) = get_calc 1;
527 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
529 val (SOME istate, NONE) = loc;
531 writeln"-----------------------------------------------------------";
533 writeln (itms2str_ ctxt probl);
534 writeln (itms2str_ ctxt meth);
536 (*============ inhibit exn AK110725 ==============================================
537 (* ERROR: Argument: istate : istate * Proof.context Reason:
538 Can't unify istate to istate * Proof.context *)
539 writeln (istate2str istate);
540 ============ inhibit exn AK110725 ==============================================*)
544 refFormula 1 ([],Pbl) (*--> correct CalcHead*);
545 (*081016 NOT necessary (but leave it in Java):*)
546 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
547 "----- here the CalcHead has been completed --- ONCE MORE ?????";
549 (***difference II***)
550 val ((pt,p),_) = get_calc 1;
551 (*val p = ([], Pbl)*)
552 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
554 val (SOME istate, NONE) = loc;
555 (*============ inhibit exn AK110725 ==============================================
556 (* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
557 print_depth 5; writeln (istate2str istate); print_depth 3;
558 ============ inhibit exn AK110725 ==============================================*)
561 ??.empty, Sundef, false)*)
562 print_depth 5; spec; print_depth 3;
564 ["derivative_of", "function"],
565 ["diff", "differentiate_on_R"]) : spec*)
566 writeln (itms2str_ ctxt probl);
568 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
569 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
570 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
571 writeln (itms2str_ ctxt meth);
573 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
574 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
575 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
576 writeln"-----------------------------------------------------------";
577 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
578 (*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
579 autoCalculate 1 CompleteCalc;
580 val ((pt,p),_) = get_calc 1;
581 val Form res = (#1 o pt_extract) (pt, ([],Res));
583 if p = ([], Res) andalso term2str res = "1 + 2 * x" then ()
584 else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
587 "--------- Take as 1st tac, start from exp -----------------------";
588 "--------- Take as 1st tac, start from exp -----------------------";
589 "--------- Take as 1st tac, start from exp -----------------------";
590 (*the following input is copied from BridgeLog Java <==> SML,
591 omitting unnecessary inputs*)
593 (*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac",["derivative_of","function"],["diff","differentiate_on_R"]))];
594 (*3>*)Iterator 1; moveActiveRoot 1;
596 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
597 (***difference II***)
598 val ((pt,_),_) = get_calc 1;
599 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
601 val (SOME istate, NONE) = loc;
602 (*============ inhibit exn AK110725 ==============================================
603 (* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
604 print_depth 5; writeln (istate2str istate); print_depth 3;
605 ============ inhibit exn AK110725 ==============================================*)
608 ??.empty, Sundef, false)*)
609 print_depth 5; spec; print_depth 3;
611 ["derivative_of", "function"],
612 ["diff", "differentiate_on_R"]) : spec*)
613 writeln (itms2str_ ctxt probl);
615 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
616 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
617 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
618 writeln (itms2str_ ctxt meth);
620 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
621 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
622 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
623 writeln"-----------------------------------------------------------";
624 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
625 autoCalculate 1 (Step 1);
626 val ((pt,p),_) = get_calc 1;
627 val Form res = (#1 o pt_extract) (pt, p);
628 if term2str res = "d_d x (x ^^^ 2 + x + 1)" then ()
629 else error "diff.sml Diff (x^2 + x + 1, x) from exp";
632 "--------- init_form, start with <NEW> (CAS input) ---------------";
633 "--------- init_form, start with <NEW> (CAS input) ---------------";
634 "--------- init_form, start with <NEW> (CAS input) ---------------";
636 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
637 (*[[from sml: > @@@@@begin@@@@@
639 [[from sml: <CALCTREE>
640 [[from sml: <CALCID> 1 </CALCID>
641 [[from sml: </CALCTREE>
642 [[from sml: @@@@@end@@@@@*)
644 (*[[from sml: > @@@@@begin@@@@@
646 [[from sml: <ADDUSER>
647 [[from sml: <CALCID> 1 </CALCID>
648 [[from sml: <USERID> 1 </USERID>
649 [[from sml: </ADDUSER>
650 [[from sml: @@@@@end@@@@@*)
652 (*[[from sml: > @@@@@begin@@@@@
654 [[from sml: <CALCITERATOR>
655 [[from sml: <CALCID> 1 </CALCID>
656 [[from sml: <POSITION>
657 [[from sml: <INTLIST>
658 [[from sml: </INTLIST>
659 [[from sml: <POS> Pbl </POS>
660 [[from sml: </POSITION>
661 [[from sml: </CALCITERATOR>
662 [[from sml: @@@@@end@@@@@*)
663 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
664 (*[[from sml: > @@@@@begin@@@@@ STILL CORRECT
666 [[from sml: <GETELEMENTSFROMTO>
667 [[from sml: <CALCID> 1 </CALCID>
668 [[from sml: <FORMHEADS>
669 [[from sml: <CALCFORMULA>
670 [[from sml: <POSITION>
671 [[from sml: <INTLIST>
672 [[from sml: </INTLIST>
673 [[from sml: <POS> Pbl </POS>
674 [[from sml: </POSITION>
675 [[from sml: <FORMULA>
677 [[from sml: <ISA> ________________________________________________ </ISA>
678 [[from sml: </MATHML>
680 [[from sml: </FORMULA>
681 [[from sml: </CALCFORMULA>
682 [[from sml: </FORMHEADS>
683 [[from sml: </GETELEMENTSFROMTO>
684 [[from sml: @@@@@end@@@@@*)
685 refFormula 1 ([],Pbl);
686 (*[[from sml: > @@@@@begin@@@@@ STILL CORRECT
688 [[from sml: <REFFORMULA>
689 [[from sml: <CALCID> 1 </CALCID>
690 [[from sml: <CALCHEAD status = "incorrect">
691 [[from sml: <POSITION>
692 [[from sml: <INTLIST>
693 [[from sml: </INTLIST>
694 [[from sml: <POS> Pbl </POS>
695 [[from sml: </POSITION>
698 [[from sml: <ISA> Problem (e_domID, [e_pblID]) </ISA>
699 [[from sml: </MATHML>
702 [[from sml: <GIVEN> </GIVEN>
703 [[from sml: <WHERE> </WHERE>
704 [[from sml: <FIND> </FIND>
705 [[from sml: <RELATE> </RELATE>
707 [[from sml: <BELONGSTO> Pbl </BELONGSTO>
708 [[from sml: <SPECIFICATION>
709 [[from sml: <THEORYID> e_domID </THEORYID>
710 [[from sml: <PROBLEMID>
711 [[from sml: <STRINGLIST>
712 [[from sml: <STRING> e_pblID </STRING>
713 [[from sml: </STRINGLIST>
714 [[from sml: </PROBLEMID>
715 [[from sml: <METHODID>
716 [[from sml: <STRINGLIST>
717 [[from sml: <STRING> e_metID </STRING>
718 [[from sml: </STRINGLIST>
719 [[from sml: </METHODID>
720 [[from sml: </SPECIFICATION>
721 [[from sml: </CALCHEAD>
722 [[from sml: </REFFORMULA>
723 [[from sml: @@@@@end@@@@@*)
724 moveActiveFormula 1 ([],Pbl);
725 (*[[from sml: > @@@@@begin@@@@@
727 [[from sml: <CALCITERATOR>
728 [[from sml: <CALCID> 1 </CALCID>
729 [[from sml: <POSITION>
730 [[from sml: <INTLIST>
731 [[from sml: </INTLIST>
732 [[from sml: <POS> Pbl </POS>
733 [[from sml: </POSITION>
734 [[from sml: </CALCITERATOR>
735 [[from sml: @@@@@end@@@@@*)
736 replaceFormula 1 "Simplify (1+2)";
737 (*[[from sml: > @@@@@begin@@@@@
739 [[from sml: <REPLACEFORMULA>
740 [[from sml: <CALCID> 1 </CALCID>
741 [[from sml: <CALCCHANGED>
742 [[from sml: <UNCHANGED>
743 [[from sml: <INTLIST>
744 [[from sml: </INTLIST>
745 [[from sml: <POS> Pbl </POS>
746 [[from sml: </UNCHANGED>
747 [[from sml: <DELETED>
748 [[from sml: <INTLIST>
749 [[from sml: </INTLIST>
750 [[from sml: <POS> Pbl </POS>
751 [[from sml: </DELETED>
752 [[from sml: <GENERATED>
753 [[from sml: <INTLIST>
754 [[from sml: </INTLIST>
755 [[from sml: <POS> Met </POS> DIFFERENCE: Pbl
756 [[from sml: </GENERATED>
757 [[from sml: </CALCCHANGED>
758 [[from sml: </REPLACEFORMULA>
759 [[from sml: @@@@@end@@@@@*)
760 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(* DIFFERENCE: Pbl*);
774 <ISA> Simplify (1 + 2) </ISA> WORKS !!!!!
781 getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
782 (*[[from sml: > @@@@@begin@@@@@
784 [[from sml: <SYSERROR>
785 [[from sml: <CALCID> 1 </CALCID>
786 [[from sml: <ERROR> error in getFormulaeFromTo </ERROR>
787 [[from sml: </SYSERROR>
788 [[from sml: @@@@@end@@@@@*)
789 (*step into getFormulaeFromTo --- bug corrected...*)
791 "--------- build fun check_err_patt ------------------------------";
792 "--------- build fun check_err_patt ------------------------------";
793 "--------- build fun check_err_patt ------------------------------";
794 val subst = [(str2term "bdv", str2term "x")]: subst;
795 val rls = norm_Rational
796 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
797 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
798 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "1 / 2");
800 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
801 rew_sub thy 1 [] e_rew_ord e_rls false [] (Trueprop $ pat) res;
802 if rewritten then NONE else SOME "e_errpatID";
804 val norm_res = case rewrite_set_ (Isac()) false rls res' of
806 | SOME (norm_res, _) => norm_res
808 val norm_inf = case rewrite_set_ (Isac()) false rls inf of
810 | SOME (norm_inf, _) => norm_inf;
815 val pat = parse_patt @{theory} "(?a + ?b)/?a = ?b";
816 val (res, inf) = (str2term "(2 + 3)/2", str2term "3");
817 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
818 then () else error "error patt example1 changed";
820 val pat = parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
821 val (res, inf) = (str2term "(2 + 3)/(2 + 4)", str2term "3 / 4");
822 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
823 then () else error "error patt example2 changed";
825 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
826 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
827 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
828 then () else error "error patt example3 changed";
830 val inf = str2term "1 / 2";
831 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
832 then () else error "error patt example3 changed";
834 "--------- build fun check_err_patt ?bdv -------------------------";
835 "--------- build fun check_err_patt ?bdv -------------------------";
836 "--------- build fun check_err_patt ?bdv -------------------------";
837 val subst = [(str2term "bdv", str2term "x")]: subst;
838 val t = str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))";
839 val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
840 if term2str t = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3" then ()
841 else error "build fun check_err_patt ?bdv changed 1";
844 val pat = parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)";
845 val (res, inf) = (str2term "2 * x + d_d x (sin (x ^^^ 4))", str2term "2 * x + cos (4 * x ^^^ 3)");
847 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
848 rew_sub thy 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) res;
849 if term2str res' = "2 * x + cos (d_d x (x ^^^ 4))" andalso rewritten then ()
850 else error "build fun check_err_patt ?bdv changed 2";
852 val norm_res = case rewrite_set_inst_ (Isac()) false subst rls res' of
854 | SOME (norm_res, _) => norm_res;
855 if term2str norm_res = "2 * x + cos (4 * x ^^^ 3)" then ()
856 else error "build fun check_err_patt ?bdv changed 3";
858 val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
860 | SOME (norm_inf, _) => norm_inf;
861 if term2str norm_inf = "2 * x + cos (4 * x ^^^ 3)" then ()
862 else error "build fun check_err_patt ?bdv changed 4";
865 if norm_res = norm_inf then ()
866 else error "build fun check_err_patt ?bdv changed 5";
868 if check_err_patt (res, inf) (subst: subst) ("errpatID": errpatID, pat) rls = SOME "errpatID"
869 then () else error "error patt example1 changed";
871 "--------- build fun check_error_patterns ------------------------";
872 "--------- build fun check_error_patterns ------------------------";
873 "--------- build fun check_error_patterns ------------------------";
875 (str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))",
876 str2term "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)");
877 val {errpats, nrls = rls, scr = Script prog, ...} = get_met ["diff", "differentiate_on_R"]
879 val env = [(str2term "v_v", str2term "x")];
881 [e_errpat, (*generalised for testing*)
882 ("chain-rule-diff-both",
883 [parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
884 parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
885 parse_patt @{theory} "d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)",
886 parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
887 parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
888 [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain},
889 @{thm diff_ln_chain}, @{thm diff_exp_chain}])]: errpat list;
891 case check_error_patterns (res, inf) (prog, env) (errpats, rls) of SOME _ => ()
892 | NONE => error "check_error_patterns broken";
895 "--------- embed fun check_error_patterns ------------------------";
896 "--------- embed fun check_error_patterns ------------------------";
897 "--------- embed fun check_error_patterns ------------------------";
900 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
901 ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
904 autoCalculate 1 CompleteCalcHead;
905 autoCalculate 1 (Step 1);
906 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
907 (*autoCalculate 1 (Step 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
909 "~~~~~ fun appendFormula, args:"; val (cI, (ifo:cterm')) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
911 val pos as (_,p_) = get_pos cI 1; (*pos = ([1], Res)*)
916 val (_, _, (pt, ([2], Res))) = cs';
918 [(([], Frm), Diff (x ^^^ 2 + sin (x ^^^ 4), x)),
919 (([1], Frm), d_d x (x ^^^ 2 + sin (x ^^^ 4))),
920 (([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))), <<=== input follos: "...+ cos(4.x^3)"
921 (([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4))] *)
923 "~~~~~ fun inform, args:"; val ((cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate'), istr) =
925 val SOME f_in = parse (assoc_thy "Isac") istr
926 val f_in = term_of f_in
927 val pos_pred = lev_back' pos
928 (* f_pred ---"step pos cs"---> f_succ in appendFormula
929 TODO.WN120517: one starting point for redesign of pos' *)
930 val (f_pred, f_succ) = (get_curr_formula (pt, pos_pred), get_curr_formula (pt, pos));
932 term2str f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
933 term2str f_succ = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)";
935 f_succ = f_in; (* = false*)
936 cas_input f_in; (* = NONE*)
937 val msg_calcstate' = compare_step ([], [], (pt, pos_pred)) f_in
938 val ("no derivation found", calcstate') = msg_calcstate';
939 val pp = par_pblobj pt p
940 val {errpats, nrls, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
941 val ScrState (env, _, _, _, _, _) = get_istate pt pos;
942 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
943 SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
944 | NONE => msg_calcstate';
946 "~~~~~ from inform return val:"; val () = ();
947 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
949 | NONE => error "check_error_patterns broken";
952 case inform cs' (encode ifo) of
953 ("error pattern #chain-rule-diff-both#", calcstate') => ()
954 | _ => error "inform with (positive) check_error_patterns broken"
956 "--------- embed fun find_fillpatterns ---------------------------";
957 "--------- embed fun find_fillpatterns ---------------------------";
958 "--------- embed fun find_fillpatterns ---------------------------";
961 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
962 ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
965 autoCalculate 1 CompleteCalcHead;
966 autoCalculate 1 (Step 1);
967 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
968 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)";
969 (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
971 <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
973 "~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
974 val ((pt, _), _) = get_calc cI
975 val pos = get_pos cI 1;
976 "~~~~~ fun find_fillpatterns, args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
977 val f_curr = get_curr_formula (pt, pos); (* = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"*)
978 val pp = par_pblobj pt p
979 val {errpats, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
980 val ScrState (env, _, _, _, _, _) = get_istate pt pos
981 val subst = get_bdv_subst prog env
982 val errpatthms = errpats
983 |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
984 |> map (#3: errpat -> thm list)
987 case map (get_fillpats subst f_curr errpatID) errpatthms |> flat of
988 ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if term2str tm =
989 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
990 then () else error "find_fillpatterns changed 1a"
991 | _ => error "find_fillpatterns changed 1b"
993 "~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
994 (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
995 val thmDeriv = Thm.get_name_hint thm
996 val (part, thyID) = thy_containing_thm thmDeriv
997 val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
998 val Hthm {fillpats, ...} = get_the theID
999 val some = map (get_fillform subst (thm, form) errpatID) fillpats;
1001 case some |> filter is_some |> map the of
1002 ("fill-d_d-arg", tm, thm, subsopt) :: _ => if term2str tm =
1003 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
1004 then () else error "find_fillpatterns changed 2a"
1005 | _ => error "find_fillpatterns changed 2b"
1007 "~~~~~ fun get_fillform, args:";
1008 val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
1009 (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
1010 val (form', _, _, rewritten) =
1011 rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
1013 if term2str form' = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
1014 else error "find_fillpatterns changed 3";
1016 "~~~~~ to findFillpatterns return val:"; val (fillpats) =
1017 (map (get_fillpats (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
1019 val msg = "fill patterns " ^
1020 ((map ((apsnd term2str) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
1022 "fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1023 " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" ^
1024 "#fill-both-args#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1025 " =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3" ^
1026 "#fill-d_d#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1027 " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1 x (x ^^^ 4)" ^
1028 "#fill-inner-deriv#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1029 " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1" ^
1030 "#fill-all#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) = d_d x (x ^^^ 2) + ?_dummy_1#"
1031 then () else error "find_fillpatterns changed 4";