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 "--------- embed fun get_fillformula -----------------------------";
40 "-----------------------------------------------------------------";
41 "-----------------------------------------------------------------";
42 "-----------------------------------------------------------------";
49 "--------- appendFormula: on Res + equ_nrls ----------------------";
50 "--------- appendFormula: on Res + equ_nrls ----------------------";
51 "--------- appendFormula: on Res + equ_nrls ----------------------";
53 val Script sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
54 (writeln o term2str) sc;
55 val Script sc = (#scr o get_met) ["Test","solve_linear"];
56 (writeln o term2str) sc;
59 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
60 ("Test", ["sqroot-test","univariate","equation","test"],
61 ["Test","squ-equ-test-subpbl1"]))];
62 Iterator 1; moveActiveRoot 1;
63 autoCalculate 1 CompleteCalcHead;
64 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
65 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
67 appendFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
68 val ((pt,_),_) = get_calc 1;
69 val str = pr_ptree pr_short pt;
72 (*============ inhibit exn AK110726 ==============================================
73 (* 2nd string should be the same as 1st one *)
74 ". ----- 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";
75 ". ----- 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";
76 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 ()
77 else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
78 ============ inhibit exn AK110726 ==============================================*)
80 moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
81 moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
83 (*the seven steps of detailed derivation*)
84 moveDown 1 ([1 ],Res); refFormula 1 ([2,1],Frm);
85 moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
86 moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
87 moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res);
88 moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
89 moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
90 moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
91 val ((pt,_),_) = get_calc 1;
92 if "-2 * 1 + (1 + x) = 0" = term2str (fst (get_obj g_result pt [2,6])) then()
93 else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
95 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
97 (*============ inhibit exn AK110725 ==============================================
98 (* ERROR: exception Bind raised *)
99 val (_,(tac,_,_)::_) = get_calc 1;
100 if tac = Rewrite_Set "Test_simplify" then ()
101 else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
102 ============ inhibit exn AK110725 ==============================================*)
104 autoCalculate 1 CompleteCalc;
105 val ((pt,_),_) = get_calc 1;
106 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
107 else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
108 (* autoCalculate 1 CompleteCalc;
109 val ((pt,p),_) = get_calc 1;
110 (writeln o istates2str) (get_obj g_loc pt [ ]);
111 (writeln o istates2str) (get_obj g_loc pt [1]);
112 (writeln o istates2str) (get_obj g_loc pt [2]);
113 (writeln o istates2str) (get_obj g_loc pt [3]);
114 (writeln o istates2str) (get_obj g_loc pt [3,1]);
115 (writeln o istates2str) (get_obj g_loc pt [3,2]);
116 (writeln o istates2str) (get_obj g_loc pt [4]);
119 "----------------------------------------------------------";
121 val fod = make_deriv (@{theory "Isac"}) Atools_erls
122 ((#rules o rep_rls) Test_simplify)
123 (sqrt_right false (@{theory "Pure"})) NONE
124 (str2term "x + 1 + -1 * 2 = 0");
125 (writeln o trtas2str) fod;
127 val ifod = make_deriv (@{theory "Isac"}) Atools_erls
128 ((#rules o rep_rls) Test_simplify)
129 (sqrt_right false (@{theory "Pure"})) NONE
130 (str2term "-2 * 1 + (1 + x) = 0");
131 (writeln o trtas2str) ifod;
132 fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
133 val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
134 val der = fod' @ (map rev_deriv' rifod');
135 (writeln o trtas2str) der;
136 "----------------------------------------------------------";
139 "--------- appendFormula: on Frm + equ_nrls ----------------------";
140 "--------- appendFormula: on Frm + equ_nrls ----------------------";
141 "--------- appendFormula: on Frm + equ_nrls ----------------------";
143 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
144 ("Test", ["sqroot-test","univariate","equation","test"],
145 ["Test","squ-equ-test-subpbl1"]))];
146 Iterator 1; moveActiveRoot 1;
147 autoCalculate 1 CompleteCalcHead;
148 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
149 appendFormula 1 "2+ -1 + x = 2"; refFormula 1 (get_pos 1 1);
151 moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
153 moveDown 1 ([1 ],Frm); refFormula 1 ([1,1],Frm);
154 moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res);
155 moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res);
156 moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res);
157 moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res);
158 moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res);
159 moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res);
160 val ((pt,_),_) = get_calc 1;
161 if "2 + -1 + x = 2" = term2str (fst (get_obj g_result pt [1,6])) then()
162 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
164 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
165 val (_,(tac,_,_)::_) = get_calc 1;
166 if tac = Rewrite_Set "norm_equation" then ()
167 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
168 autoCalculate 1 CompleteCalc;
169 val ((pt,_),_) = get_calc 1;
170 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
171 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
174 "--------- appendFormula: on Res + NO deriv ----------------------";
175 "--------- appendFormula: on Res + NO deriv ----------------------";
176 "--------- appendFormula: on Res + NO deriv ----------------------";
178 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
179 ("Test", ["sqroot-test","univariate","equation","test"],
180 ["Test","squ-equ-test-subpbl1"]))];
181 Iterator 1; moveActiveRoot 1;
182 autoCalculate 1 CompleteCalcHead;
183 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
184 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
186 appendFormula 1 "x = 2";
187 val ((pt,p),_) = get_calc 1;
188 val str = pr_ptree pr_short pt;
190 if str = ". ----- pblobj -----\n1. x + 1 = 2\n" andalso p = ([1], Res)
192 else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
194 fetchProposedTactic 1;
195 val (_,(tac,_,_)::_) = get_calc 1;
196 if tac = Rewrite_Set "Test_simplify" then ()
197 else error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
198 autoCalculate 1 CompleteCalc;
199 val ((pt,_),_) = get_calc 1;
200 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
201 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
204 "--------- appendFormula: on Res + late deriv --------------------";
205 "--------- appendFormula: on Res + late deriv --------------------";
206 "--------- appendFormula: on Res + late deriv --------------------";
208 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
209 ("Test", ["sqroot-test","univariate","equation","test"],
210 ["Test","squ-equ-test-subpbl1"]))];
211 Iterator 1; moveActiveRoot 1;
212 autoCalculate 1 CompleteCalcHead;
213 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
214 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
216 appendFormula 1 "x = 1";
217 val ((pt,p),_) = get_calc 1;
218 val str = pr_ptree pr_short pt;
220 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)
221 then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
222 else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
224 fetchProposedTactic 1;
225 val (_,(tac,_,_)::_) = get_calc 1;
226 if tac = Check_Postcond ["linear", "univariate", "equation", "test"] then ()
227 else error "inform.sml: diff.behav.appendFormula: Res + late d 2";
228 autoCalculate 1 CompleteCalc;
229 val ((pt,_),_) = get_calc 1;
230 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
231 else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
234 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
235 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
236 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
238 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
239 ("Test", ["sqroot-test","univariate","equation","test"],
240 ["Test","squ-equ-test-subpbl1"]))];
241 Iterator 1; moveActiveRoot 1;
242 autoCalculate 1 CompleteCalcHead;
243 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
244 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
245 appendFormula 1 "[x = 3 + -2*1]";
246 val ((pt,p),_) = get_calc 1;
247 val str = pr_ptree pr_short pt;
249 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 ()
250 else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
251 autoCalculate 1 CompleteCalc;
252 val ((pt,p),_) = get_calc 1;
253 if "[x = 3 + -2 * 1]" = term2str (fst (get_obj g_result pt [])) then ()
254 (* ~~~~~~~~~~ simplify as last step in any script ?!*)
255 else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
259 "--------- replaceFormula: on Res + = ----------------------------";
260 "--------- replaceFormula: on Res + = ----------------------------";
261 "--------- replaceFormula: on Res + = ----------------------------";
263 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
264 ("Test", ["sqroot-test","univariate","equation","test"],
265 ["Test","squ-equ-test-subpbl1"]))];
266 Iterator 1; moveActiveRoot 1;
267 autoCalculate 1 CompleteCalcHead;
268 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
269 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
270 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
272 replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
273 val ((pt,_),_) = get_calc 1;
274 val str = pr_ptree pr_short pt;
277 (*============ inhibit exn AK110725 ==============================================
278 (* 2nd string should be the same as 1st one *)
279 ". ----- 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";
280 ". ----- 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";
281 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()
282 else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
283 ============ inhibit exn AK110725 ==============================================*)
285 autoCalculate 1 CompleteCalc;
286 val ((pt,pos as (p,_)),_) = get_calc 1;
287 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst) (get_obj g_result pt p) then()
288 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
291 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
292 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
293 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
295 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
296 ("Test", ["sqroot-test","univariate","equation","test"],
297 ["Test","squ-equ-test-subpbl1"]))];
298 Iterator 1; moveActiveRoot 1;
299 autoCalculate 1 CompleteCalcHead;
300 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
301 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
303 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
304 val ((pt,_),_) = get_calc 1;
305 val str = pr_ptree pr_short pt;
307 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 ()
308 else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
309 autoCalculate 1 CompleteCalc;
310 val ((pt,pos as (p,_)),_) = get_calc 1;
311 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
312 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
315 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
316 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
317 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
319 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
320 ("Test", ["sqroot-test","univariate","equation","test"],
321 ["Test","squ-equ-test-subpbl1"]))];
322 Iterator 1; moveActiveRoot 1;
323 autoCalculate 1 CompleteCalcHead;
324 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
326 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
327 val ((pt,_),_) = get_calc 1;
328 val str = pr_ptree pr_short pt;
330 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 ()
331 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
332 autoCalculate 1 CompleteCalc;
333 val ((pt,pos as (p,_)),_) = get_calc 1;
334 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
335 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
338 "--------- replaceFormula: cut calculation -----------------------";
339 "--------- replaceFormula: cut calculation -----------------------";
340 "--------- replaceFormula: cut calculation -----------------------";
342 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
343 ("Test", ["sqroot-test","univariate","equation","test"],
344 ["Test","squ-equ-test-subpbl1"]))];
345 Iterator 1; moveActiveRoot 1;
346 autoCalculate 1 CompleteCalc;
347 moveActiveRoot 1; moveActiveDown 1;
348 if get_pos 1 1 = ([1], Frm) then ()
349 else error "inform.sml: diff.behav. cut calculation 1";
351 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
352 val ((pt,p),_) = get_calc 1;
353 val str = pr_ptree pr_short pt;
355 if p = ([1], Res) then ()
356 else error "inform.sml: diff.behav. cut calculation 2";
359 (* 040307 copied from informtest.sml; ... old version
360 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
361 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
362 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
365 val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
366 "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
367 "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
368 "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
369 (*^^^ these are the elements for the root-problem (in variants)*)
370 (*vvv these are elements required for subproblems*)
371 "boundVariable a","boundVariable b","boundVariable alpha",
372 "interval {x::real. 0 <= x & x <= 2*r}",
373 "interval {x::real. 0 <= x & x <= 2*r}",
374 "interval {x::real. 0 <= x & x <= pi}",
375 "errorBound (eps=(0::real))"]
376 (*specifying is not interesting for this example*)
377 val spec = ("DiffApp", ["maximum_of","function"],
378 ["DiffApp","max_by_calculus"]);
379 (*the empty model with descriptions for user-guidance by Model_Problem*)
380 val empty_model = [Given ["fixedValues []"],
381 Find ["maximum", "valuesFor"],
382 Relate ["relations []"]];
385 (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
386 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
387 (*val nxt = ("Model_Problem", ...*)
388 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
390 val (p,_,f,nxt,_,pt) = me nxt p c pt;
391 (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
392 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
394 (0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
395 (0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
396 (0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
397 (0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
399 (*the empty CalcHead is checked w.r.t the model and re-established as such*)
400 val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, e_spec);
401 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
402 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";
404 (*there is one input to the model (could be more)*)
406 input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
407 Find ["maximum", "valuesFor"],
408 Relate ["relations"]], Pbl, e_spec);
409 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
410 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 ()
411 else error "informtest.sml: diff.behav. max 2";
413 (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
414 val (b,pt''''',ocalhd) =
415 input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
416 Find ["maximum A", "valuesFor [a,b]"],
417 Relate ["relations [A=a*b, a/2=r*sin alpha, \
418 \b/2=r*cos alpha]"]], Pbl, e_spec);
419 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl;
420 if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
422 (*this input is complete in variant 1 (variant 3 does not work yet)*)
423 val (b,pt''''',ocalhd) =
424 input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
425 Find ["maximum A", "valuesFor [a,b]"],
426 Relate ["relations [A=a*b, \
427 \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]],
429 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl;
431 modifycalcheadOK2xml 111 (bool2str b) ocalhd;
434 "--------- syntax error ------------------------------------------";
435 "--------- syntax error ------------------------------------------";
436 "--------- syntax error ------------------------------------------";
438 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
439 ("Test", ["sqroot-test","univariate","equation","test"],
440 ["Test","squ-equ-test-subpbl1"]))];
441 Iterator 1; moveActiveRoot 1;
442 autoCalculate 1 CompleteCalcHead;
443 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
444 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
446 appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
447 val ((pt,_),_) = get_calc 1;
448 val str = pr_ptree pr_short pt;
450 if str = ". ----- pblobj -----\n1. x + 1 = 2\n" then ()
451 else error "inform.sml: diff.behav.appendFormula: syntax error";
454 "--------- CAS-command on ([],Pbl) -------------------------------";
455 "--------- CAS-command on ([],Pbl) -------------------------------";
456 "--------- CAS-command on ([],Pbl) -------------------------------";
457 val (p,_,f,nxt,_,pt) =
458 CalcTreeTEST [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
459 val ifo = "solve(x+1=2,x)";
460 val (_,(_,c,(pt,p))) = inform ([],[],(pt,p)) "solve(x+1=2,x)";
462 val nxt = ("Apply_Method",Apply_Method ["Test","squ-equ-test-subpbl1"]);
463 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
464 if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
465 else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
468 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
469 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
470 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
472 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
475 replaceFormula 1 "solve(x+1=2,x)";
476 autoCalculate 1 CompleteCalc;
477 val ((pt,p),_) = get_calc 1;
479 if p = ([], Res) then ()
480 else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
483 "--------- inform [rational,simplification] ----------------------";
484 "--------- inform [rational,simplification] ----------------------";
485 "--------- inform [rational,simplification] ----------------------";
487 CalcTree [(["Term (4/x - 3/y - 1)", "normalform N"],
488 ("Rational",["rational","simplification"],
489 ["simplification","of_rationals"]))];
490 Iterator 1; moveActiveRoot 1;
491 autoCalculate 1 CompleteCalcHead;
492 autoCalculate 1 (Step 1);
493 autoCalculate 1 (Step 1);
494 autoCalculate 1 (Step 1);
495 autoCalculate 1 (Step 1);
496 "--- input the next formula that _should_ be presented by mat-engine";
497 appendFormula 1 "(4 * y + -3 * x) / (x * y) + -1";
498 val ((pt,p),_) = get_calc 1;
499 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
500 else error ("inform.sml: [rational,simplification] 1");
502 "--- input the next formula that would be presented by mat-engine";
503 (*autoCalculate 1 (Step 1);*)
504 appendFormula 1 "(4 * y + -3 * x + -1 * (x * y)) / (x * y)";
505 val ((pt,p),_) = get_calc 1;
506 if p = ([5], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
507 else error ("inform.sml: [rational,simplification] 2");
509 "--- input the exact final result";(*TODO: Exception- LIST "last_elem" raised*)
510 appendFormula 1 "(-3 * x + 4 * y + -1 * x * y) / (x * y)";
511 val ((pt,p),_) = get_calc 1;
512 if p = ([6], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
513 else error ("inform.sml: [rational,simplification] 3");
516 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
517 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
518 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
519 val t = str2term "Diff (x^^^2 + x + 1, x)";
520 case t of Const ("Diff.Diff", _) $ _ => ()
522 error "diff.sml behav.changed for CAS Diff (..., x)";
524 "-----------------------------------------------------------------";
526 (*2>*)CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
527 (*3>*)Iterator 1;moveActiveRoot 1;
528 "----- here the Headline has been finished";
529 (*4>*)moveActiveFormula 1 ([],Pbl);
530 (*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
531 val ((pt,_),_) = get_calc 1;
532 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
534 val (SOME istate, NONE) = loc;
536 writeln"-----------------------------------------------------------";
538 writeln (itms2str_ ctxt probl);
539 writeln (itms2str_ ctxt meth);
541 (*============ inhibit exn AK110725 ==============================================
542 (* ERROR: Argument: istate : istate * Proof.context Reason:
543 Can't unify istate to istate * Proof.context *)
544 writeln (istate2str istate);
545 ============ inhibit exn AK110725 ==============================================*)
549 refFormula 1 ([],Pbl) (*--> correct CalcHead*);
550 (*081016 NOT necessary (but leave it in Java):*)
551 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
552 "----- here the CalcHead has been completed --- ONCE MORE ?????";
554 (***difference II***)
555 val ((pt,p),_) = get_calc 1;
556 (*val p = ([], Pbl)*)
557 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
559 val (SOME istate, NONE) = loc;
560 (*============ inhibit exn AK110725 ==============================================
561 (* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
562 print_depth 5; writeln (istate2str istate); print_depth 3;
563 ============ inhibit exn AK110725 ==============================================*)
566 ??.empty, Sundef, false)*)
567 print_depth 5; spec; print_depth 3;
569 ["derivative_of", "function"],
570 ["diff", "differentiate_on_R"]) : spec*)
571 writeln (itms2str_ ctxt probl);
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 (itms2str_ ctxt meth);
578 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
579 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
580 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
581 writeln"-----------------------------------------------------------";
582 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
583 (*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
584 autoCalculate 1 CompleteCalc;
585 val ((pt,p),_) = get_calc 1;
586 val Form res = (#1 o pt_extract) (pt, ([],Res));
588 if p = ([], Res) andalso term2str res = "1 + 2 * x" then ()
589 else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
592 "--------- Take as 1st tac, start from exp -----------------------";
593 "--------- Take as 1st tac, start from exp -----------------------";
594 "--------- Take as 1st tac, start from exp -----------------------";
595 (*the following input is copied from BridgeLog Java <==> SML,
596 omitting unnecessary inputs*)
598 (*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac",["derivative_of","function"],["diff","differentiate_on_R"]))];
599 (*3>*)Iterator 1; moveActiveRoot 1;
601 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
602 (***difference II***)
603 val ((pt,_),_) = get_calc 1;
604 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
606 val (SOME istate, NONE) = loc;
607 (*============ inhibit exn AK110725 ==============================================
608 (* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
609 print_depth 5; writeln (istate2str istate); print_depth 3;
610 ============ inhibit exn AK110725 ==============================================*)
613 ??.empty, Sundef, false)*)
614 print_depth 5; spec; print_depth 3;
616 ["derivative_of", "function"],
617 ["diff", "differentiate_on_R"]) : spec*)
618 writeln (itms2str_ ctxt probl);
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 (itms2str_ ctxt meth);
625 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
626 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
627 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
628 writeln"-----------------------------------------------------------";
629 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
630 autoCalculate 1 (Step 1);
631 val ((pt,p),_) = get_calc 1;
632 val Form res = (#1 o pt_extract) (pt, p);
633 if term2str res = "d_d x (x ^^^ 2 + x + 1)" then ()
634 else error "diff.sml Diff (x^2 + x + 1, x) from exp";
637 "--------- init_form, start with <NEW> (CAS input) ---------------";
638 "--------- init_form, start with <NEW> (CAS input) ---------------";
639 "--------- init_form, start with <NEW> (CAS input) ---------------";
641 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
642 (*[[from sml: > @@@@@begin@@@@@
644 [[from sml: <CALCTREE>
645 [[from sml: <CALCID> 1 </CALCID>
646 [[from sml: </CALCTREE>
647 [[from sml: @@@@@end@@@@@*)
649 (*[[from sml: > @@@@@begin@@@@@
651 [[from sml: <ADDUSER>
652 [[from sml: <CALCID> 1 </CALCID>
653 [[from sml: <USERID> 1 </USERID>
654 [[from sml: </ADDUSER>
655 [[from sml: @@@@@end@@@@@*)
657 (*[[from sml: > @@@@@begin@@@@@
659 [[from sml: <CALCITERATOR>
660 [[from sml: <CALCID> 1 </CALCID>
661 [[from sml: <POSITION>
662 [[from sml: <INTLIST>
663 [[from sml: </INTLIST>
664 [[from sml: <POS> Pbl </POS>
665 [[from sml: </POSITION>
666 [[from sml: </CALCITERATOR>
667 [[from sml: @@@@@end@@@@@*)
668 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
669 (*[[from sml: > @@@@@begin@@@@@ STILL CORRECT
671 [[from sml: <GETELEMENTSFROMTO>
672 [[from sml: <CALCID> 1 </CALCID>
673 [[from sml: <FORMHEADS>
674 [[from sml: <CALCFORMULA>
675 [[from sml: <POSITION>
676 [[from sml: <INTLIST>
677 [[from sml: </INTLIST>
678 [[from sml: <POS> Pbl </POS>
679 [[from sml: </POSITION>
680 [[from sml: <FORMULA>
682 [[from sml: <ISA> ________________________________________________ </ISA>
683 [[from sml: </MATHML>
685 [[from sml: </FORMULA>
686 [[from sml: </CALCFORMULA>
687 [[from sml: </FORMHEADS>
688 [[from sml: </GETELEMENTSFROMTO>
689 [[from sml: @@@@@end@@@@@*)
690 refFormula 1 ([],Pbl);
691 (*[[from sml: > @@@@@begin@@@@@ STILL CORRECT
693 [[from sml: <REFFORMULA>
694 [[from sml: <CALCID> 1 </CALCID>
695 [[from sml: <CALCHEAD status = "incorrect">
696 [[from sml: <POSITION>
697 [[from sml: <INTLIST>
698 [[from sml: </INTLIST>
699 [[from sml: <POS> Pbl </POS>
700 [[from sml: </POSITION>
703 [[from sml: <ISA> Problem (e_domID, [e_pblID]) </ISA>
704 [[from sml: </MATHML>
707 [[from sml: <GIVEN> </GIVEN>
708 [[from sml: <WHERE> </WHERE>
709 [[from sml: <FIND> </FIND>
710 [[from sml: <RELATE> </RELATE>
712 [[from sml: <BELONGSTO> Pbl </BELONGSTO>
713 [[from sml: <SPECIFICATION>
714 [[from sml: <THEORYID> e_domID </THEORYID>
715 [[from sml: <PROBLEMID>
716 [[from sml: <STRINGLIST>
717 [[from sml: <STRING> e_pblID </STRING>
718 [[from sml: </STRINGLIST>
719 [[from sml: </PROBLEMID>
720 [[from sml: <METHODID>
721 [[from sml: <STRINGLIST>
722 [[from sml: <STRING> e_metID </STRING>
723 [[from sml: </STRINGLIST>
724 [[from sml: </METHODID>
725 [[from sml: </SPECIFICATION>
726 [[from sml: </CALCHEAD>
727 [[from sml: </REFFORMULA>
728 [[from sml: @@@@@end@@@@@*)
729 moveActiveFormula 1 ([],Pbl);
730 (*[[from sml: > @@@@@begin@@@@@
732 [[from sml: <CALCITERATOR>
733 [[from sml: <CALCID> 1 </CALCID>
734 [[from sml: <POSITION>
735 [[from sml: <INTLIST>
736 [[from sml: </INTLIST>
737 [[from sml: <POS> Pbl </POS>
738 [[from sml: </POSITION>
739 [[from sml: </CALCITERATOR>
740 [[from sml: @@@@@end@@@@@*)
741 replaceFormula 1 "Simplify (1+2)";
742 (*[[from sml: > @@@@@begin@@@@@
744 [[from sml: <REPLACEFORMULA>
745 [[from sml: <CALCID> 1 </CALCID>
746 [[from sml: <CALCCHANGED>
747 [[from sml: <UNCHANGED>
748 [[from sml: <INTLIST>
749 [[from sml: </INTLIST>
750 [[from sml: <POS> Pbl </POS>
751 [[from sml: </UNCHANGED>
752 [[from sml: <DELETED>
753 [[from sml: <INTLIST>
754 [[from sml: </INTLIST>
755 [[from sml: <POS> Pbl </POS>
756 [[from sml: </DELETED>
757 [[from sml: <GENERATED>
758 [[from sml: <INTLIST>
759 [[from sml: </INTLIST>
760 [[from sml: <POS> Met </POS> DIFFERENCE: Pbl
761 [[from sml: </GENERATED>
762 [[from sml: </CALCCHANGED>
763 [[from sml: </REPLACEFORMULA>
764 [[from sml: @@@@@end@@@@@*)
765 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(* DIFFERENCE: Pbl*);
779 <ISA> Simplify (1 + 2) </ISA> WORKS !!!!!
786 getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
787 (*[[from sml: > @@@@@begin@@@@@
789 [[from sml: <SYSERROR>
790 [[from sml: <CALCID> 1 </CALCID>
791 [[from sml: <ERROR> error in getFormulaeFromTo </ERROR>
792 [[from sml: </SYSERROR>
793 [[from sml: @@@@@end@@@@@*)
794 (*step into getFormulaeFromTo --- bug corrected...*)
796 "--------- build fun check_err_patt ------------------------------";
797 "--------- build fun check_err_patt ------------------------------";
798 "--------- build fun check_err_patt ------------------------------";
799 val subst = [(str2term "bdv", str2term "x")]: subst;
800 val rls = norm_Rational
801 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
802 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
803 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "1 / 2");
805 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
806 rew_sub thy 1 [] e_rew_ord e_rls false [] (Trueprop $ pat) res;
807 if rewritten then NONE else SOME "e_errpatID";
809 val norm_res = case rewrite_set_ (Isac()) false rls res' of
811 | SOME (norm_res, _) => norm_res
813 val norm_inf = case rewrite_set_ (Isac()) false rls inf of
815 | SOME (norm_inf, _) => norm_inf;
820 val pat = parse_patt @{theory} "(?a + ?b)/?a = ?b";
821 val (res, inf) = (str2term "(2 + 3)/2", str2term "3");
822 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
823 then () else error "error patt example1 changed";
825 val pat = parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
826 val (res, inf) = (str2term "(2 + 3)/(2 + 4)", str2term "3 / 4");
827 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
828 then () else error "error patt example2 changed";
830 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
831 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
832 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
833 then () else error "error patt example3 changed";
835 val inf = str2term "1 / 2";
836 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
837 then () else error "error patt example3 changed";
839 "--------- build fun check_err_patt ?bdv -------------------------";
840 "--------- build fun check_err_patt ?bdv -------------------------";
841 "--------- build fun check_err_patt ?bdv -------------------------";
842 val subst = [(str2term "bdv", str2term "x")]: subst;
843 val t = str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))";
844 val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
845 if term2str t = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3" then ()
846 else error "build fun check_err_patt ?bdv changed 1";
849 val pat = parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)";
850 val (res, inf) = (str2term "2 * x + d_d x (sin (x ^^^ 4))", str2term "2 * x + cos (4 * x ^^^ 3)");
852 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
853 rew_sub thy 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) res;
854 if term2str res' = "2 * x + cos (d_d x (x ^^^ 4))" andalso rewritten then ()
855 else error "build fun check_err_patt ?bdv changed 2";
857 val norm_res = case rewrite_set_inst_ (Isac()) false subst rls res' of
859 | SOME (norm_res, _) => norm_res;
860 if term2str norm_res = "2 * x + cos (4 * x ^^^ 3)" then ()
861 else error "build fun check_err_patt ?bdv changed 3";
863 val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
865 | SOME (norm_inf, _) => norm_inf;
866 if term2str norm_inf = "2 * x + cos (4 * x ^^^ 3)" then ()
867 else error "build fun check_err_patt ?bdv changed 4";
870 if norm_res = norm_inf then ()
871 else error "build fun check_err_patt ?bdv changed 5";
873 if check_err_patt (res, inf) (subst: subst) ("errpatID": errpatID, pat) rls = SOME "errpatID"
874 then () else error "error patt example1 changed";
876 "--------- build fun check_error_patterns ------------------------";
877 "--------- build fun check_error_patterns ------------------------";
878 "--------- build fun check_error_patterns ------------------------";
880 (str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))",
881 str2term "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)");
882 val {errpats, nrls = rls, scr = Script prog, ...} = get_met ["diff", "differentiate_on_R"]
884 val env = [(str2term "v_v", str2term "x")];
886 [e_errpat, (*generalised for testing*)
887 ("chain-rule-diff-both",
888 [parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
889 parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
890 parse_patt @{theory} "d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)",
891 parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
892 parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
893 [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain},
894 @{thm diff_ln_chain}, @{thm diff_exp_chain}])]: errpat list;
896 case check_error_patterns (res, inf) (prog, env) (errpats, rls) of SOME _ => ()
897 | NONE => error "check_error_patterns broken";
900 "--------- embed fun check_error_patterns ------------------------";
901 "--------- embed fun check_error_patterns ------------------------";
902 "--------- embed fun check_error_patterns ------------------------";
905 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
906 ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
909 autoCalculate 1 CompleteCalcHead;
910 autoCalculate 1 (Step 1);
911 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
912 (*autoCalculate 1 (Step 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
914 "~~~~~ fun appendFormula, args:"; val (cI, (ifo:cterm')) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
916 val pos as (_,p_) = get_pos cI 1; (*pos = ([1], Res)*)
921 val (_, _, (pt, ([2], Res))) = cs';
923 [(([], Frm), Diff (x ^^^ 2 + sin (x ^^^ 4), x)),
924 (([1], Frm), d_d x (x ^^^ 2 + sin (x ^^^ 4))),
925 (([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))), <<=== input follos: "...+ cos(4.x^3)"
926 (([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4))] *)
928 "~~~~~ fun inform, args:"; val ((cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate'), istr) =
930 val SOME f_in = parse (assoc_thy "Isac") istr
931 val f_in = term_of f_in
932 val pos_pred = lev_back' pos
933 (* f_pred ---"step pos cs"---> f_succ in appendFormula
934 TODO.WN120517: one starting point for redesign of pos' *)
935 val (f_pred, f_succ) = (get_curr_formula (pt, pos_pred), get_curr_formula (pt, pos));
937 term2str f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
938 term2str f_succ = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)";
940 f_succ = f_in; (* = false*)
941 cas_input f_in; (* = NONE*)
942 val msg_calcstate' = compare_step ([], [], (pt, pos_pred)) f_in
943 val ("no derivation found", calcstate') = msg_calcstate';
944 val pp = par_pblobj pt p
945 val {errpats, nrls, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
946 val ScrState (env, _, _, _, _, _) = get_istate pt pos;
947 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
948 SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
949 | NONE => msg_calcstate';
951 "~~~~~ from inform return val:"; val () = ();
952 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
954 | NONE => error "check_error_patterns broken";
957 case inform cs' (encode ifo) of
958 ("error pattern #chain-rule-diff-both#", calcstate') => ()
959 | _ => error "inform with (positive) check_error_patterns broken"
961 "--------- embed fun find_fillpatterns ---------------------------";
962 "--------- embed fun find_fillpatterns ---------------------------";
963 "--------- embed fun find_fillpatterns ---------------------------";
966 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
967 ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
970 autoCalculate 1 CompleteCalcHead;
971 autoCalculate 1 (Step 1);
972 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
973 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)";
974 (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
976 <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
978 "~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
979 val ((pt, _), _) = get_calc cI
980 val pos = get_pos cI 1;
981 "~~~~~ fun find_fillpatterns, args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
982 val f_curr = get_curr_formula (pt, pos); (* = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"*)
983 val pp = par_pblobj pt p
984 val {errpats, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
985 val ScrState (env, _, _, _, _, _) = get_istate pt pos
986 val subst = get_bdv_subst prog env
987 val errpatthms = errpats
988 |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
989 |> map (#3: errpat -> thm list)
992 case map (get_fillpats subst f_curr errpatID) errpatthms |> flat of
993 ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if term2str tm =
994 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
995 then () else error "find_fillpatterns changed 1a"
996 | _ => error "find_fillpatterns changed 1b"
998 "~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
999 (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
1000 val thmDeriv = Thm.get_name_hint thm
1001 val (part, thyID) = thy_containing_thm thmDeriv
1002 val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
1003 val Hthm {fillpats, ...} = get_the theID
1004 val some = map (get_fillform subst (thm, form) errpatID) fillpats;
1006 case some |> filter is_some |> map the of
1007 ("fill-d_d-arg", tm, thm, subsopt) :: _ => if term2str tm =
1008 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
1009 then () else error "find_fillpatterns changed 2a"
1010 | _ => error "find_fillpatterns changed 2b"
1012 "~~~~~ fun get_fillform, args:";
1013 val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
1014 (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
1015 val (form', _, _, rewritten) =
1016 rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
1018 if term2str form' = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
1019 else error "find_fillpatterns changed 3";
1021 "~~~~~ to findFillpatterns return val:"; val (fillpats) =
1022 (map (get_fillpats (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
1024 val msg = "fill patterns " ^
1025 ((map ((apsnd term2str) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
1027 "fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1028 " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" ^
1029 "#fill-both-args#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1030 " =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3" ^
1031 "#fill-d_d#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1032 " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1 x (x ^^^ 4)" ^
1033 "#fill-inner-deriv#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1034 " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1" ^
1035 "#fill-all#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) = d_d x (x ^^^ 2) + ?_dummy_1#"
1036 then () else error "find_fillpatterns changed 4";
1039 "--------- embed fun get_fillformula -----------------------------";
1040 "--------- embed fun get_fillformula -----------------------------";
1041 "--------- embed fun get_fillformula -----------------------------";
1044 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
1045 ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
1048 autoCalculate 1 CompleteCalcHead;
1049 autoCalculate 1 (Step 1);
1050 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
1051 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)";
1052 (* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
1053 would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
1054 results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
1055 instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
1056 findFillpatterns 1 "chain-rule-diff-both";
1057 (*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
1058 d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
1060 "~~~~~ fun requestFillformula, args:"; val (cI, (errpatID, fillpatID)) =
1061 (1, ("chain-rule-diff-both", "fill-both-args"));
1062 val ((pt, _), _) = get_calc cI
1063 val pos = get_pos cI 1; (* = ([1], Res)*)
1065 "~~~~~ fun get_fillformula, args:"; val ((pt, pos as (p, _)), (errpatID, fillpatID)) =
1066 ((pt, pos), (errpatID, fillpatID));
1067 val fillforms = find_fillpatterns (pt, pos) errpatID
1069 filter ((curry op = fillpatID) o (#1: (fillpatID * term * thm * (subs option) -> fillpatID))) fillforms;
1071 val [(fillpatID, fillform, thm, subs_opt)] = fillforms;
1072 case (fillpatID, fillform, thm, subs_opt) of
1073 ("fill-both-args", tm, thm, subs_opt) => if term2str tm =
1074 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3"
1075 then () else error "get_fillformula changed 1a"
1076 | _ => error "get_fillformula changed 1b";
1078 val f_curr = get_curr_formula (pt, pos); (*already done in find_fillpatterns, too*)
1079 term2str f_curr = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
1081 "~~~~~ fun generate_inconsistent, args:";
1082 val (_, (Rewrite' (_,_,_,_, thm', f, (f', asm))), (is, ctxt), (p,_), pt) =
1084 (Rewrite' ("","",e_rls,true, (fillpatID, ""(*errpatthm known in find_fillpatterns*)),
1085 f_curr, (fillform, []))),
1086 (get_loc pt pos), (lev_on p, Und), pt);
1087 if p = [2] then () else error "generate_inconsistent changed 1";
1089 val (pt,c) = cappend_atomic pt p (is, insert_assumptions asm ctxt) f
1090 (Rewrite thm') (f', asm) Inconsistent
1091 val pt = update_branch pt p TransitiveB;
1093 "~~~~~ to get_fillformula return val:"; val (pos', _, _, pt) =
1094 ((p,Res), c, Form' (FormKF (~1,EdUndef,(length p), Nundef, term2str f')), pt);
1095 if pos' = ([2], Res) then () else error "generate_inconsistent changed 2";
1097 upd_calc cI ((pt, pos'), []); upd_ipos cI 1 pos';
1098 autocalculateOK2xml cI pos pos' pos';
1100 "~~~~~ final check:";
1101 val ((pt,pos),_) = get_calc 1;
1102 val p = get_pos 1 1;
1103 val (Form f, tac, asms) = pt_extract (pt, p);
1104 if p = ([2], Res) andalso term2str f =
1105 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3"
1106 then () else error "";
1108 show_pt pt; (*ATTENTION: omits the last step, if pt is incomplete, ([2], Res) EXISTS !*)
1109 "--------- embed fun get_fillformula -----------------------------";
1112 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
1113 ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
1116 autoCalculate 1 CompleteCalcHead;
1117 autoCalculate 1 (Step 1);
1118 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
1119 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)";
1120 (* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
1121 would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
1122 results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
1123 instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
1124 findFillpatterns 1 "chain-rule-diff-both";
1125 (*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
1126 d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
1128 "~~~~~ fun requestFillformula, args:"; val (cI, (errpatID, fillpatID)) =
1129 (1, ("chain-rule-diff-both", "fill-both-args"));
1130 val ((pt, _), _) = get_calc cI
1131 val pos = get_pos cI 1; (* = ([1], Res)*)
1133 "~~~~~ fun get_fillformula, args:"; val ((pt, pos as (p, _)), (errpatID, fillpatID)) =
1134 ((pt, pos), (errpatID, fillpatID));
1135 val fillforms = find_fillpatterns (pt, pos) errpatID
1137 filter ((curry op = fillpatID) o (#1: (fillpatID * term * thm * (subs option) -> fillpatID))) fillforms;
1139 val [(fillpatID, fillform, thm, subs_opt)] = fillforms;
1140 case (fillpatID, fillform, thm, subs_opt) of
1141 ("fill-both-args", tm, thm, subs_opt) => if term2str tm =
1142 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3"
1143 then () else error "get_fillformula changed 1a"
1144 | _ => error "get_fillformula changed 1b";
1146 val f_curr = get_curr_formula (pt, pos); (*already done in find_fillpatterns, too*)
1147 term2str f_curr = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
1149 "~~~~~ fun generate_inconsistent, args:";
1150 val (_, (Rewrite' (_,_,_,_, thm', f, (f', asm))), (is, ctxt), (p,_), pt) =
1152 (Rewrite' ("","",e_rls,true, (fillpatID, ""(*errpatthm known in find_fillpatterns*)),
1153 f_curr, (fillform, []))),
1154 (get_loc pt pos), (lev_on p, Und), pt);
1155 if p = [2] then () else error "generate_inconsistent changed 1";
1157 val (pt,c) = cappend_atomic pt p (is, insert_assumptions asm ctxt) f
1158 (Rewrite thm') (f', asm) Inconsistent
1159 val pt = update_branch pt p TransitiveB;
1161 "~~~~~ to get_fillformula return val:"; val (pos', _, _, pt) =
1162 ((p,Res), c, Form' (FormKF (~1,EdUndef,(length p), Nundef, term2str f')), pt);
1163 if pos' = ([2], Res) then () else error "generate_inconsistent changed 2";
1165 upd_calc cI ((pt, pos'), []); upd_ipos cI 1 pos';
1166 autocalculateOK2xml cI pos pos' pos';
1168 "~~~~~ final check:";
1169 val ((pt,pos),_) = get_calc 1;
1170 val p = get_pos 1 1;
1171 val (Form f, tac, asms) = pt_extract (pt, p);
1172 if p = ([2], Res) andalso term2str f =
1173 "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3"
1174 then () else error "";
1176 show_pt pt; (*ATTENTION: omits the last step, if pt is incomplete, ([2], Res) EXISTS !*)