1 (* Title: "Interpret/error-pattern.sml"
2 Author: Walther Neuper 060225,
3 (c) due to copyright terms
5 Strange ERROR "Undefined fact: "all_left""
8 "-----------------------------------------------------------------";
9 "table of contents -----------------------------------------------";
10 "-----------------------------------------------------------------";
11 "appendForm with miniscript with mini-subpbl:";
12 "--------- appendFormula: on Res + equ_nrls ----------------------";
13 "--------- appendFormula: on Frm + equ_nrls ----------------------";
14 "--------- appendFormula: on Res + NO deriv ----------------------";
15 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
16 "replaceForm with miniscript with mini-subpbl:";
17 "--------- replaceFormula: on Res + = ----------------------------";
18 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
19 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
20 "--------- replaceFormula: cut calculation -----------------------";
21 "--------- replaceFormula: cut calculation -----------------------";
22 (* 040307 copied from informtest.sml ... old versions
23 "--------- maximum-example, UC: Modeling / modifyCalcHead --------";*)
24 "--------- syntax error ------------------------------------------";
26 (*"--------- CAS-command on ([],Pbl) -------------------------------";*)
27 (*"--------- CAS-command on ([],Pbl) FE-interface ------------------";*)
28 "--------- locate_input_term [rational,simplification] ----------------------";
29 (*"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";*)
30 "--------- Take as 1st tac, start from exp -----------------------";
31 (*"--------- implicit_take, start with <NEW> (CAS input) ---------------";*)
32 "--------- build fun check_for' ------------------------------";
33 "--------- build fun check_for' ?bdv -------------------------";
34 "--------- build fun check_for ------------------------";
35 "--------- embed fun check_for ------------------------";
36 "----------- re-build: fill_from_store without thy-hierarchy -----------------------------------";
37 "--------- embed fun find_fill_patterns ---------------------------";
38 "--------- build fun is_exactly_equal, inputFillFormula ----------";
39 "--------- fun appl_adds -----------------------------------------";
40 "--------- fun concat_deriv --------------------------------------";
41 "--------- handle an input formula -------------------------------";
42 "--------- fun dropwhile' ----------------------------------------";
43 "-----------------------------------------------------------------";
44 "-----------------------------------------------------------------";
45 "-----------------------------------------------------------------";
48 "--------- appendFormula: on Res + equ_nrls ----------------------";
49 "--------- appendFormula: on Res + equ_nrls ----------------------";
50 "--------- appendFormula: on Res + equ_nrls ----------------------";
51 val Prog sc = (#program o MethodC.from_store ctxt) ["Test", "squ-equ-test-subpbl1"];
52 (writeln o UnparseC.term @{context}) sc;
53 val Prog sc = (#program o MethodC.from_store ctxt) ["Test", "solve_linear"];
54 (writeln o UnparseC.term @{context}) sc;
57 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
58 ("Test", ["sqroot-test", "univariate", "equation", "test"],
59 ["Test", "squ-equ-test-subpbl1"]))];
60 Iterator 1; moveActiveRoot 1;
61 autoCalculate 1 CompleteCalcHead;
62 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
63 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
65 appendFormula 1 "- 2 * 1 + (1 + x) = 0" (*|> Future.join*); refFormula 1 (States.get_pos 1 1);
66 val ((pt,_),_) = States.get_calc 1;
67 val str = pr_ctree ctxt pr_short pt;
69 (". ----- pblobj -----\n" ^
71 "2. x + 1 + - 1 * 2 = 0\n" ^
72 "2.1. x + 1 + - 1 * 2 = 0\n" ^
73 "2.2. 1 + x + - 1 * 2 = 0\n" ^
74 "2.3. 1 + (x + - 1 * 2) = 0\n" ^
75 "2.4. 1 + (x + - 2) = 0\n" ^
76 "2.5. 1 + (x + - 2 * 1) = 0\n" ^
77 "2.6. 1 + x + - 2 * 1 = 0\n" ) then ()
78 else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
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,_),_) = States.get_calc 1;
92 if "- 2 * 1 + (1 + x) = 0" = UnparseC.term @{context} (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_*)
96 (* <ERROR> error in kernel </ERROR> ALREADY IN 2009-2*)
97 (*========== inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 =============
98 val (_,(tac,_,_)::_) = States.get_calc 1;
99 if tac = Rewrite_Set "Test_simplify" then ()
100 else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
101 ============ inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 ============*)
103 autoCalculate 1 CompleteCalc;
104 val ((pt,_),_) = States.get_calc 1;
105 if "[x = 1]" = UnparseC.term @{context} (fst (get_obj g_result pt [])) then ()
106 else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
107 (* autoCalculate 1 CompleteCalc;
108 val ((pt,p),_) = States.get_calc 1;
109 (writeln o istates2str) (get_obj g_loc pt [ ]);
110 (writeln o istates2str) (get_obj g_loc pt [1]);
111 (writeln o istates2str) (get_obj g_loc pt [2]);
112 (writeln o istates2str) (get_obj g_loc pt [3]);
113 (writeln o istates2str) (get_obj g_loc pt [3,1]);
114 (writeln o istates2str) (get_obj g_loc pt [3,2]);
115 (writeln o istates2str) (get_obj g_loc pt [4]);
118 "----------------------------------------------------------";
120 val fod = Derive.do_one (Proof_Context.init_global @{theory "Isac_Knowledge"}) Atools_erls
121 ((#rules o Rule_Set.rep) Test_simplify)
122 (sqrt_right false) NONE
123 (ParseC.parse_test @{context} "x + 1 + - 1 * 2 = 0");
124 (writeln o (Derive.trtas2str ctxt)) fod;
126 val ifod = Derive.do_one (Proof_Context.init_global @{theory "Isac_Knowledge"}) Atools_erls
127 ((#rules o Rule_Set.rep) Test_simplify)
128 (sqrt_right false) NONE
129 (ParseC.parse_test @{context} "- 2 * 1 + (1 + x) = 0");
130 (writeln o (Derive.trtas2str ctxt)) ifod;
131 fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
132 val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
133 val der = fod' @ (map (Derive.rev_deriv' ctxt) rifod');
134 (writeln o (Derive.trtas2str ctxt)) der;
135 "----------------------------------------------------------";
138 "--------- appendFormula: on Frm + equ_nrls ----------------------";
139 "--------- appendFormula: on Frm + equ_nrls ----------------------";
140 "--------- appendFormula: on Frm + equ_nrls ----------------------";
142 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
143 ("Test", ["sqroot-test", "univariate", "equation", "test"],
144 ["Test", "squ-equ-test-subpbl1"]))];
145 Iterator 1; moveActiveRoot 1;
146 autoCalculate 1 CompleteCalcHead;
147 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1) (*x + 1 = 2*);
148 appendFormula 1 "2+ - 1 + x = 2" (*|> Future.join*); refFormula 1 (States.get_pos 1 1);
150 moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
152 moveDown 1 ([1 ],Frm); refFormula 1 ([1,1],Frm);
153 moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res);
154 moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res);
155 moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res);
156 moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res);
157 moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res);
158 moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res);
159 val ((pt,_),_) = States.get_calc 1;
160 if "2 + - 1 + x = 2" = UnparseC.term @{context} (fst (get_obj g_result pt [1,6])) then()
161 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
163 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
164 val (_,(tac,_,_)::_) = States.get_calc 1;
165 case tac of Rewrite_Set "norm_equation" => ()
166 | _ => error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
167 autoCalculate 1 CompleteCalc;
168 val ((pt,_),_) = States.get_calc 1;
169 if "[x = 1]" = UnparseC.term @{context} (fst (get_obj g_result pt [])) then ()
170 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
173 "--------- appendFormula: on Res + NO deriv ----------------------";
174 "--------- appendFormula: on Res + NO deriv ----------------------";
175 "--------- appendFormula: on Res + NO deriv ----------------------";
177 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
178 ("Test", ["sqroot-test", "univariate", "equation", "test"],
179 ["Test", "squ-equ-test-subpbl1"]))];
180 Iterator 1; moveActiveRoot 1;
181 autoCalculate 1 CompleteCalcHead;
182 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
183 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
185 appendFormula 1 "x = 2" (*|> Future.join*);
186 val ((pt,p),_) = States.get_calc 1;
187 val str = pr_ctree ctxt pr_short pt;
189 if str = ". ----- pblobj -----\n1. x + 1 = 2\n" andalso p = ([1], Res)
191 else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
193 fetchProposedTactic 1;
194 val (_,(tac,_,_)::_) = States.get_calc 1;
195 case tac of Rewrite_Set "Test_simplify" => ()
196 | _ => error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
197 autoCalculate 1 CompleteCalc;
198 val ((pt,_),_) = States.get_calc 1;
199 if "[x = 1]" = UnparseC.term @{context} (fst (get_obj g_result pt [])) then ()
200 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
203 "--------- appendFormula: on Res + late deriv --------------------";
204 "--------- appendFormula: on Res + late deriv --------------------";
205 "--------- appendFormula: on Res + late deriv --------------------";
206 (*cp with "fun me" to test/../lucas-interpreter.sml:
207 re-build: fun locate_input_term ---------------------------------------------------";
210 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
211 ("Test", ["sqroot-test", "univariate", "equation", "test"],
212 ["Test", "squ-equ-test-subpbl1"]))];
213 Iterator 1; moveActiveRoot 1;
214 autoCalculate 1 CompleteCalcHead;
215 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
216 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
218 appendFormula 1 "x = 1" (*|> Future.join*);
219 val ((pt,p),_) = States.get_calc 1;
220 val str = pr_ctree ctxt pr_short pt;
222 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)
223 then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
224 else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
226 fetchProposedTactic 1;
227 val (_,(tac,_,_)::_) = States.get_calc 1;
228 case tac of Check_Postcond ["LINEAR", "univariate", "equation", "test"] => ()
229 | _ => error "inform.sml: diff.behav.appendFormula: Res + late d 2";
230 autoCalculate 1 CompleteCalc;
231 val ((pt,_),_) = States.get_calc 1;
232 if "[x = 1]" = UnparseC.term @{context} (fst (get_obj g_result pt [])) then ()
233 else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
236 "--------- appendFormula: on Res + late deriv [x = 3 + - 2]---///--";
237 "--------- appendFormula: on Res + late deriv [x = 3 + - 2]---///--";
238 "--------- appendFormula: on Res + late deriv [x = 3 + - 2]---///--";
240 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
241 ("Test", ["sqroot-test", "univariate", "equation", "test"],
242 ["Test", "squ-equ-test-subpbl1"]))];
243 Iterator 1; moveActiveRoot 1;
244 autoCalculate 1 CompleteCalcHead;
245 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
246 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
247 appendFormula 1 "[x = 3 + -2*1]" (*|> Future.join*);
248 val ((pt,p),_) = States.get_calc 1;
249 val str = pr_ctree ctxt pr_short pt;
251 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 ()
252 else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
253 autoCalculate 1 CompleteCalc;
254 val ((pt,p),_) = States.get_calc 1;
255 if "[x = 3 + - 2 * 1]" = UnparseC.term @{context} (fst (get_obj g_result pt [])) then ()
256 (* ~~~~~~~~~~ simplify as last step in any script ?!*)
257 else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
260 "--------- replaceFormula: on Res + = ----------------------------";
261 "--------- replaceFormula: on Res + = ----------------------------";
262 "--------- replaceFormula: on Res + = ----------------------------";
264 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
265 ("Test", ["sqroot-test", "univariate", "equation", "test"],
266 ["Test", "squ-equ-test-subpbl1"]))];
267 Iterator 1; moveActiveRoot 1;
268 autoCalculate 1 CompleteCalcHead;
269 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
270 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
271 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*- 1 + x*);
273 replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (States.get_pos 1 1);
274 val ((pt,_),_) = States.get_calc 1;
275 val str = pr_ctree ctxt pr_short pt;
277 (* before AK110725 this was
278 ". ----- pblobj -----\n
280 2. x + 1 + - 1 * 2 = 0\n
281 2.1. x + 1 + - 1 * 2 = 0\n
282 2.2. 1 + x + - 1 * 2 = 0\n
283 2.3. 1 + (x + - 1 * 2) = 0\n
284 2.4. 1 + (x + -2) = 0\n
285 2.5. 1 + (x + -2 * 1) = 0\n
286 2.6. 1 + x + -2 * 1 = 0\n";
289 ". ----- pblobj -----\n"^
291 "2. x + 1 + - 1 * 2 = 0\n"^
292 "2.1. x + 1 + - 1 * 2 = 0\n"^
293 "2.2. 1 + x + - 1 * 2 = 0\n"^
294 "2.3. 1 + (x + - 1 * 2) = 0\n"^
295 "2.4. 1 + (x + - 2) = 0\n"^
296 "2.5. 1 + (x + - 2 * 1) = 0\n"^
297 "2.6. 1 + x + - 2 * 1 = 0\n" then()
298 else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
300 autoCalculate 1 CompleteCalc;
301 val ((pt,pos as (p,_)),_) = States.get_calc 1;
302 if pos = ([],Res) andalso "[x = 1]" = (UnparseC.term @{context} o fst) (get_obj g_result pt p) then()
303 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
306 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
307 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
308 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
310 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
311 ("Test", ["sqroot-test", "univariate", "equation", "test"],
312 ["Test", "squ-equ-test-subpbl1"]))];
313 Iterator 1; moveActiveRoot 1;
314 autoCalculate 1 CompleteCalcHead;
315 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
316 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
318 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (States.get_pos 1 1);
319 val ((pt,_),_) = States.get_calc 1;
320 val str = pr_ctree ctxt pr_short pt;
322 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 ()
323 else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
324 autoCalculate 1 CompleteCalc;
325 val ((pt,pos as (p,_)),_) = States.get_calc 1;
326 if pos = ([],Res) andalso "[x = 1]" = (UnparseC.term @{context} o fst)(get_obj g_result pt p) then()
327 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
330 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
331 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
332 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
334 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
335 ("Test", ["sqroot-test", "univariate", "equation", "test"],
336 ["Test", "squ-equ-test-subpbl1"]))];
337 Iterator 1; moveActiveRoot 1;
338 autoCalculate 1 CompleteCalcHead;
339 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
341 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (States.get_pos 1 1);
342 val ((pt,_),_) = States.get_calc 1;
343 val str = pr_ctree ctxt pr_short pt;
345 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 ()
346 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
347 autoCalculate 1 CompleteCalc;
348 val ((pt,pos as (p,_)),_) = States.get_calc 1;
349 if pos = ([],Res) andalso "[x = 1]" = (UnparseC.term @{context} o fst)(get_obj g_result pt p) then()
350 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
353 "--------- replaceFormula: cut calculation -----------------------";
354 "--------- replaceFormula: cut calculation -----------------------";
355 "--------- replaceFormula: cut calculation -----------------------";
357 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
358 ("Test", ["sqroot-test", "univariate", "equation", "test"],
359 ["Test", "squ-equ-test-subpbl1"]))];
360 Iterator 1; moveActiveRoot 1;
361 autoCalculate 1 CompleteCalc;
362 moveActiveRoot 1; moveActiveDown 1;
363 if States.get_pos 1 1 = ([1], Frm) then ()
364 else error "inform.sml: diff.behav. cut calculation 1";
366 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (States.get_pos 1 1);
367 val ((pt,p),_) = States.get_calc 1;
368 val str = pr_ctree ctxt pr_short pt;
370 if p = ([1], Res) then ()
371 else error "inform.sml: diff.behav. cut calculation 2";
374 (* 040307 copied from informtest.sml; ... old version
375 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
376 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
377 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
380 val elems = ["fixedValues [r=Arbfix]", "maximum A", "valuesFor [a,b]",
381 "relations [A=a*b, (a/2) \<up> 2 + (b/2) \<up> 2 = r \<up> 2]",
382 "relations [A=a*b, (a/2) \<up> 2 + (b/2) \<up> 2 = r \<up> 2]",
383 "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos (alpha::real)]",
384 (* \<up> these are the elements for the root-problem (in variants)*)
385 (*vvv these are elements required for subproblems*)
386 "boundVariable a", "boundVariable b", "boundVariable alpha",
387 "interval {x::real. 0 <= x & x <= 2*r}",
388 "interval {x::real. 0 <= x & x <= 2*r}",
389 "interval {x::real. 0 <= x & x <= pi}",
390 "errorBound (eps=(0::real))"]
391 (*specifying is not interesting for this example*)
392 val spec = ("Diff_App", ["maximum_of", "function"],
393 ["Diff_App", "max_by_calculus"]);
394 (*the empty model with descriptions for user-guidance by Model_Problem*)
395 val empty_model = [Given ["fixedValues []"],
396 Find ["maximum", "valuesFor"],
397 Relate ["relations []"]];
400 (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
401 val (p,_,f,nxt,_,pt) = Test_Code.init_calc @{context} [(elems, spec)];
402 (*val nxt = ("Model_Problem", ...*)
403 val pbl = get_obj g_pbl pt (fst p); (writeln o (I_Model.to_string ctxt)) pbl;
405 val (p,_,f,nxt,_,pt) = me nxt p c pt;
406 (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
407 val pbl = get_obj g_pbl pt (fst p); (writeln o (I_Model.to_string ctxt)) pbl;
409 (0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
410 (0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
411 (0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
412 (0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
414 (*the empty CalcHead is checked w.r.t the model and re-established as such*)
415 val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, References.empty);
416 val pbl = get_obj g_pbl pt (fst p); (writeln o (I_Model.to_string ctxt)) pbl;
417 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(\"ThyC.id_empty\", [\"e_pblID\"], [\"e_metID\"]) )" then () else error "informtest.sml: diff.behav. max 1";
419 (*there is one input to the model (could be more)*)
421 input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
422 Find ["maximum", "valuesFor"],
423 Relate ["relations"]], Pbl, References.empty);
424 val pbl = get_obj g_pbl pt (fst p); (writeln o (I_Model.to_string ctxt)) pbl;
425 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(\"ThyC.id_empty\", [\"e_pblID\"], [\"e_metID\"]) )" then ()
426 else error "informtest.sml: diff.behav. max 2";
428 (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
429 val (b,pt''''',ocalhd) =
430 input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
431 Find ["maximum A", "valuesFor [a,b]"],
432 Relate ["relations [A=a*b, a/2=r*sin alpha, \
433 \b/2=r*cos alpha]"]], Pbl, References.empty);
434 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (I_Model.to_string ctxt)) pbl;
435 if ocalhd2str ocalhd = ------------ \<up> \<up> \<up> ^ missing !!!*)
437 (*this input is complete in variant 1 (variant 3 does not work yet)*)
438 val (b,pt''''',ocalhd) =
439 input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
440 Find ["maximum A", "valuesFor [a,b]"],
441 Relate ["relations [A=a*b, \
442 \(a/2) \<up> 2 + (b/2) \<up> 2 = r \<up> 2]"]],
443 Pbl, References.empty);
444 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (I_Model.to_string ctxt)) pbl;
446 modifycalcheadOK2xml 111 (bool2str b) ocalhd;
450 "--------- syntax error ------------------------------------------";
451 "--------- syntax error ------------------------------------------";
452 "--------- syntax error ------------------------------------------";
454 CalcTree @{context} [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
455 ("Test", ["sqroot-test", "univariate", "equation", "test"],
456 ["Test", "squ-equ-test-subpbl1"]))];
457 Iterator 1; moveActiveRoot 1;
458 autoCalculate 1 CompleteCalcHead;
459 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
460 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
462 (*appendFormula 1 " x - "; ..ERROR Inner syntax error: unexpected end of input
463 Failed to parse term *)
464 val ((pt,_),_) = States.get_calc 1;
465 val str = pr_ctree ctxt pr_short pt;
467 if str = ". ----- pblobj -----\n1. x + 1 = 2\n" then ()
468 else error "inform.sml: diff.behav.appendFormula: syntax error";
471 (*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
472 "--------- CAS-command on ([],Pbl) -------------------------------";
473 "--------- CAS-command on ([],Pbl) -------------------------------";
474 "--------- CAS-command on ([],Pbl) -------------------------------";
475 val (p,_,f,nxt,_,pt) =
476 Test_Code.init_calc @{context} [([], References.empty)];
477 val ifo = "solve(x+1=2,x)";
478 val (_,(_,c,(pt,p))) = Step_Solve.by_term (pt,p) "solve(x+1=2,x)";
480 This trick \<up> \<up> \<up> micked input of \<up> \<up> \<up> \<up> \<up> ^^ in the front-end.
481 The trick worked in changeset fbaff8cf0179, it does not work in 59c5dd27d589 anymore
482 (TODO hg bisect ?) and raises the ERROR Undefined fact: "xfoldr_Nil".
484 Compare tests "CAS-command" in test/../inssort.sml etc.
485 ---------------------------------------------------------------------------------------------
486 Test_Tool.show_pt pt;
487 val nxt = (Apply_Method ["Test", "squ-equ-test-subpbl1"]);
488 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
489 if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
490 else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
492 -----------------------------------------------------------------------------------------------*)
494 (*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
495 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
496 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
497 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
499 CalcTree @{context} [([], References.empty)];
502 replaceFormula 1 "solve(x+1=2,x)";
503 autoCalculate 1 CompleteCalc;
504 val ((pt,p),_) = States.get_calc 1;
505 Test_Tool.show_pt pt;
506 if p = ([], Res) then ()
507 else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
509 -----------------------------------------------------------------------------------------------*)
511 "--------- inform [rational,simplification] ----------------------";
512 "--------- inform [rational,simplification] ----------------------";
513 "--------- inform [rational,simplification] ----------------------";
515 CalcTree @{context} [(["Term (a * x / (b * x) + c * x / (d * x) + e / f)", "normalform N"],
516 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
517 Iterator 1; moveActiveRoot 1;
518 autoCalculate 1 CompleteCalcHead;
520 "--- (- 1) give a preview on the calculation without any input";
522 autoCalculate 1 CompleteCalc;
523 val ((pt, p), _) = States.get_calc 1;
524 Test_Tool.show_pt pt;
526 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
527 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
528 (([1], Res), a / b + c / d + e / f), <--- (1) input arbitrary
529 (([2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
530 (([3], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
531 (([4], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)), <--- (2) input next
532 (([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))] <--- (3) is also final result
535 "--- (0) user input as the *first* step does not work, thus impdo at least 1 step";
536 autoCalculate 1 (Steps 1);
537 autoCalculate 1 (Steps 1);
538 val ((pt, p), _) = States.get_calc 1;
539 (*Test_Tool.show_pt pt;
541 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
542 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
543 (([1], Res), a / b + c / d + e / f)]
545 "--- (1) input an arbitrary next formula";
546 appendFormula 1 "((a * d) + (c * b)) / (b * d) + e / f" (*|> Future.join*);
547 val ((pt, p), _) = States.get_calc 1;
548 (*Test_Tool.show_pt pt;
550 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
551 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
552 (([1], Res), a / b + c / d + e / f),
553 (([2,1], Frm), a / b + c / d + e / f),
554 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
555 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
556 (([2], Res), (a * d + c * b) / (b * d) + e / f)]
558 val ((pt,p),_) = States.get_calc 1;
559 if p = ([2], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
560 else error ("inform.sml: [rational,simplification] 1");
562 "--- (2) input the next formula that would be presented by mat-engine";
563 (* generate a preview:
564 autoCalculate 1 (Steps 1);
565 val ((pt, p), _) = States.get_calc 1;
566 Test_Tool.show_pt pt;
568 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
569 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
570 (([1], Res), a / b + c / d + e / f),
571 (([2,1], Frm), a / b + c / d + e / f),
572 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
573 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
574 (([2], Res), (a * d + c * b) / (b * d) + e / f),
575 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] <--- input this
577 appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
578 val ((pt, p), _) = States.get_calc 1;
579 (*Test_Tool.show_pt pt;
581 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
582 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
583 (([1], Res), a / b + c / d + e / f),
584 (([2,1], Frm), a / b + c / d + e / f),
585 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
586 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
587 (([2], Res), (a * d + c * b) / (b * d) + e / f),
588 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))]
590 if p = ([3], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
591 else error ("inform.sml: [rational,simplification] 2");
593 "--- (3) input the exact final result";
594 appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
595 val ((pt, p), _) = States.get_calc 1;
596 (*Test_Tool.show_pt pt;
598 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
599 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
600 (([1], Res), a / b + c / d + e / f),
601 (([2,1], Frm), a / b + c / d + e / f),
602 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
603 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
604 (([2], Res), (a * d + c * b) / (b * d) + e / f),
605 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
606 (([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
607 (([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
608 (([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
609 (([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))]
611 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
612 else error ("inform.sml: [rational,simplification] 3");
614 "--- (4) finish the calculation + check the postcondition (in the future)";
615 autoCalculate 1 CompleteCalc;
616 val ((pt, p), _) = States.get_calc 1;
617 val (t, asm) = get_obj g_result pt [];
618 if UnparseC.term @{context} t = "(a * d * f + b * c * f + b * d * e) / (b * d * f)" andalso
619 UnparseC.terms @{context} asm =(*"[\"b * d * f \<noteq> 0\",\"d \<noteq> 0\",\"b \<noteq> 0\",\"a * x / (b * x) + c * x / (d * x) + e / f is_ratpolyexp\"]"*)
620 "[]" (*..found broken in child of 33913fe24685, error covered by CAS-command *)
621 then () else error "inform [rational,simplification] changed at end";
622 (*Test_Tool.show_pt pt;
624 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
625 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
626 (([1], Res), a / b + c / d + e / f),
627 (([2,1], Frm), a / b + c / d + e / f),
628 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
629 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
630 (([2], Res), (a * d + c * b) / (b * d) + e / f),
631 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
632 (([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
633 (([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
634 (([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
635 (([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
636 (([5], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
637 (([6], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)),
638 (([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))]
642 (*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
643 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
644 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
645 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
646 val t = ParseC.parse_test @{context} "Diff (x \<up> 2 + x + 1, x)";
647 case t of Const (\<^const_name>\<open>Diff\<close>, _) $ _ => ()
649 error "diff.sml behav.changed for CAS Diff (..., x)";
650 TermC.atom_trace_detail @{context} t;
651 "-----------------------------------------------------------------";
652 (*1>*)States.reset ();
653 (*2>*)CalcTree @{context} [([], References.empty)];
654 (*3>*)Iterator 1;moveActiveRoot 1;
655 "----- here the Headline has been finished";
656 (*4>*)moveActiveFormula 1 ([],Pbl);
657 (*5>*)replaceFormula 1 "Diff (x \<up> 2 + x + 1, x)";
658 val ((pt,_),_) = States.get_calc 1;
659 val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
660 val (SOME istate, NONE) = loc;
661 (*default_print_depth 5;*)
662 writeln"-----------------------------------------------------------";
664 writeln (I_Model.to_string ctxt probl);
665 writeln (I_Model.to_string ctxt meth);
666 writeln (Istate.string_of ctxt (fst istate));
668 refFormula 1 ([],Pbl) (*--> correct CalcHead*);
669 (*081016 NOT necessary (but leave it in Java):*)
670 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
671 "----- here the CalcHead has been completed --- ONCE MORE ?????";
673 (***difference II***)
674 val ((pt,p),_) = States.get_calc 1;
675 (*val p = ([], Pbl)*)
676 val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
677 val (SOME istate, NONE) = loc;
678 (*default_print_depth 5;*) writeln (Istate.string_of ctxt (fst istate)); (*default_print_depth 3;*)
681 ??.empty, Sundef, false)*)
682 (*default_print_depth 5;*) spec; (*default_print_depth 3;*)
684 ["derivative_of", "function"],
685 ["diff", "differentiate_on_R"]) : spec*)
686 writeln (I_Model.to_string ctxt probl);
688 (1 ,[1] ,true ,#Given ,Cor functionTerm (x \<up> 2 + x + 1) ,(f_, [x \<up> 2 + x + 1])),
689 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
690 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
691 writeln (I_Model.to_string ctxt meth);
693 (1 ,[1] ,true ,#Given ,Cor functionTerm (x \<up> 2 + x + 1) ,(f_, [x \<up> 2 + x + 1])),
694 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
695 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
696 writeln"-----------------------------------------------------------";
697 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
698 (*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
699 autoCalculate 1 CompleteCalc;
700 val ((pt,p),_) = States.get_calc 1;
701 val Form res = (#1 o ME_Misc.pt_extract) (pt, ([],Res));
702 Test_Tool.show_pt pt;
704 if p = ([], Res) andalso UnparseC.term @{context} res = "1 + 2 * x" then ()
705 else error "diff.sml behav.changed for Diff (x \<up> 2 + x + 1, x)";
707 -----------------------------------------------------------------------------------------------*)
709 "--------- Take as 1st tac, start from exp -----------------------";
710 "--------- Take as 1st tac, start from exp -----------------------";
711 "--------- Take as 1st tac, start from exp -----------------------";
712 (*the following input is copied from BridgeLog Java <==> SML,
713 omitting unnecessary inputs*)
714 (*1>*)States.reset ();
715 (*2>*)CalcTree @{context} [(["functionTerm (x \<up> 2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac_Knowledge",["derivative_of", "function"],["diff", "differentiate_on_R"]))];
716 (*3>*)Iterator 1; moveActiveRoot 1;
718 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
719 (***difference II***)
720 val ((pt,_),_) = States.get_calc 1;
721 val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
722 val (SOME istate, NONE) = loc;
723 (*default_print_depth 5;*) writeln (Istate.string_of ctxt (fst istate)); (*default_print_depth 3;*)
726 ??.empty, Sundef, false)*)
727 (*default_print_depth 5;*) spec; (*default_print_depth 3;*)
729 ["derivative_of", "function"],
730 ["diff", "differentiate_on_R"]) : spec*)
731 writeln (I_Model.to_string ctxt probl);
733 (1 ,[1] ,true ,#Given ,Cor functionTerm (x \<up> 2 + x + 1) ,(f_, [x \<up> 2 + x + 1])),
734 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
735 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
736 writeln (I_Model.to_string ctxt meth);
738 (1 ,[1] ,true ,#Given ,Cor functionTerm (x \<up> 2 + x + 1) ,(f_, [x \<up> 2 + x + 1])),
739 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
740 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
741 writeln"-----------------------------------------------------------";
742 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
743 autoCalculate 1 (Steps 1);
744 val ((pt,p),_) = States.get_calc 1;
745 val Form res = (#1 o (ME_Misc.pt_extract ctxt)) (pt, p);
746 if UnparseC.term @{context} res = "d_d x (x \<up> 2 + x + 1)" then ()
747 else error "diff.sml Diff (x \<up> 2 + x + 1, x) from exp";
750 (*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
751 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
752 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
753 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
755 CalcTree @{context} [([], References.empty)];
756 (*[[from sml: > @@@@@begin@@@@@
758 [[from sml: <CALCTREE>
759 [[from sml: <CALCID> 1 </CALCID>
760 [[from sml: </CALCTREE>
761 [[from sml: @@@@@end@@@@@*)
763 (*[[from sml: > @@@@@begin@@@@@
765 [[from sml: <ADDUSER>
766 [[from sml: <CALCID> 1 </CALCID>
767 [[from sml: <USERID> 1 </USERID>
768 [[from sml: </ADDUSER>
769 [[from sml: @@@@@end@@@@@*)
771 (*[[from sml: > @@@@@begin@@@@@
773 [[from sml: <CALCITERATOR>
774 [[from sml: <CALCID> 1 </CALCID>
775 [[from sml: <POSITION>
776 [[from sml: <INTLIST>
777 [[from sml: </INTLIST>
778 [[from sml: <POS> Pbl </POS>
779 [[from sml: </POSITION>
780 [[from sml: </CALCITERATOR>
781 [[from sml: @@@@@end@@@@@*)
782 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
783 (*[[from sml: > @@@@@begin@@@@@ STILL CORRECT
785 [[from sml: <GETELEMENTSFROMTO>
786 [[from sml: <CALCID> 1 </CALCID>
787 [[from sml: <FORMHEADS>
788 [[from sml: <CALCFORMULA>
789 [[from sml: <POSITION>
790 [[from sml: <INTLIST>
791 [[from sml: </INTLIST>
792 [[from sml: <POS> Pbl </POS>
793 [[from sml: </POSITION>
794 [[from sml: <FORMULA>
796 [[from sml: <ISA> ________________________________________________ </ISA>
797 [[from sml: </MATHML>
799 [[from sml: </FORMULA>
800 [[from sml: </CALCFORMULA>
801 [[from sml: </FORMHEADS>
802 [[from sml: </GETELEMENTSFROMTO>
803 [[from sml: @@@@@end@@@@@*)
804 refFormula 1 ([],Pbl);
805 (*[[from sml: > @@@@@begin@@@@@ STILL CORRECT
807 [[from sml: <REFFORMULA>
808 [[from sml: <CALCID> 1 </CALCID>
809 [[from sml: <CALCHEAD status = "incorrect">
810 [[from sml: <POSITION>
811 [[from sml: <INTLIST>
812 [[from sml: </INTLIST>
813 [[from sml: <POS> Pbl </POS>
814 [[from sml: </POSITION>
817 [[from sml: <ISA> Problem (ThyC.id_empty, [e_pblID]) </ISA>
818 [[from sml: </MATHML>
821 [[from sml: <GIVEN> </GIVEN>
822 [[from sml: <WHERE> </WHERE>
823 [[from sml: <FIND> </FIND>
824 [[from sml: <RELATE> </RELATE>
826 [[from sml: <BELONGSTO> Pbl </BELONGSTO>
827 [[from sml: <SPECIFICATION>
828 [[from sml: <THEORYID> ThyC.id_empty </THEORYID>
829 [[from sml: <PROBLEMID>
830 [[from sml: <STRINGLIST>
831 [[from sml: <STRING> Problem.id_empty </STRING>
832 [[from sml: </STRINGLIST>
833 [[from sml: </PROBLEMID>
834 [[from sml: <METHODID>
835 [[from sml: <STRINGLIST>
836 [[from sml: <STRING> e_metID </STRING>
837 [[from sml: </STRINGLIST>
838 [[from sml: </METHODID>
839 [[from sml: </SPECIFICATION>
840 [[from sml: </CALCHEAD>
841 [[from sml: </REFFORMULA>
842 [[from sml: @@@@@end@@@@@*)
843 moveActiveFormula 1 ([],Pbl);
844 (*[[from sml: > @@@@@begin@@@@@
846 [[from sml: <CALCITERATOR>
847 [[from sml: <CALCID> 1 </CALCID>
848 [[from sml: <POSITION>
849 [[from sml: <INTLIST>
850 [[from sml: </INTLIST>
851 [[from sml: <POS> Pbl </POS>
852 [[from sml: </POSITION>
853 [[from sml: </CALCITERATOR>
854 [[from sml: @@@@@end@@@@@*)
855 replaceFormula 1 "Simplify (1+2)";
856 (*[[from sml: > @@@@@begin@@@@@
858 [[from sml: <REPLACEFORMULA>
859 [[from sml: <CALCID> 1 </CALCID>
860 [[from sml: <CALCCHANGED>
861 [[from sml: <UNCHANGED>
862 [[from sml: <INTLIST>
863 [[from sml: </INTLIST>
864 [[from sml: <POS> Pbl </POS>
865 [[from sml: </UNCHANGED>
866 [[from sml: <DELETED>
867 [[from sml: <INTLIST>
868 [[from sml: </INTLIST>
869 [[from sml: <POS> Pbl </POS>
870 [[from sml: </DELETED>
871 [[from sml: <GENERATED>
872 [[from sml: <INTLIST>
873 [[from sml: </INTLIST>
874 [[from sml: <POS> Met </POS> DIFFERENCE: Pbl
875 [[from sml: </GENERATED>
876 [[from sml: </CALCCHANGED>
877 [[from sml: </REPLACEFORMULA>
878 [[from sml: @@@@@end@@@@@*)
879 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(* DIFFERENCE: Pbl*);
893 <ISA> Simplify (1 + 2) </ISA> WORKS !!!!!
900 getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
901 (*[[from sml: > @@@@@begin@@@@@
903 [[from sml: <SYSERROR>
904 [[from sml: <CALCID> 1 </CALCID>
905 [[from sml: <ERROR> error in getFormulaeFromTo </ERROR>
906 [[from sml: </SYSERROR>
907 [[from sml: @@@@@end@@@@@*)
908 (*step into getFormulaeFromTo --- bug corrected...*)
909 -----------------------------------------------------------------------------------------------*)
911 "--------- build fun check_for' ------------------------------";
912 "--------- build fun check_for' ------------------------------";
913 "--------- build fun check_for' ------------------------------";
914 val subst = [(ParseC.parse_test @{context} "bdv", ParseC.parse_test @{context} "x")]: subst;
915 val rls = norm_Rational
916 val SOME pat = ParseC.patt_opt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
917 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/(3 + 4)", ParseC.parse_test @{context} "2 / 4");
918 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/(3 + 4)", ParseC.parse_test @{context} "1 / 2");
920 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern TermC.matches in res*)
921 rew_sub ctxt 1 [] Rewrite_Ord.function_empty Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
922 if rewritten then NONE else SOME "e_errpatID";
924 val norm_res = case rewrite_set_ ctxt false rls res' of
926 | SOME (norm_res, _) => norm_res
928 val norm_inf = case rewrite_set_ ctxt false rls inf of
930 | SOME (norm_inf, _) => norm_inf;
935 val SOME pat = ParseC.patt_opt @{theory} "(?a + ?b)/?a = ?b";
936 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/2", ParseC.parse_test @{context} "3");
937 if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
938 then () else error "error patt example1 changed";
940 val SOME pat = ParseC.patt_opt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
941 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/(2 + 4)", ParseC.parse_test @{context} "3 / 4");
942 if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
943 then () else error "error patt example2 changed";
945 val SOME pat = ParseC.patt_opt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
946 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/(3 + 4)", ParseC.parse_test @{context} "2 / 4");
947 if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
948 then () else error "error patt example3 changed";
950 val inf = ParseC.parse_test @{context} "1 / 2";
951 if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
952 then () else error "error patt example3 changed";
954 "--------- build fun check_for' ?bdv -------------------------";
955 "--------- build fun check_for' ?bdv -------------------------";
956 "--------- build fun check_for' ?bdv -------------------------";
957 val ctxt = Proof_Context.init_global @{theory}
958 val subst = [(ParseC.parse_test @{context} "bdv", ParseC.parse_test @{context} "x")]: subst;
959 val t = ParseC.parse_test @{context} "d_d x (x \<up> 2 + sin (x \<up> 4))";
960 val SOME (t, _) = rewrite_set_inst_ ctxt false subst norm_diff t;
961 if UnparseC.term @{context} t = "2 * x + cos (x \<up> 4) * 4 * x \<up> 3" then ()
962 else error "build fun check_for' ?bdv changed 1";
965 val SOME pat = ParseC.patt_opt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)";
966 val (res, inf) = (ParseC.parse_test @{context} "2 * x + d_d x (sin (x \<up> 4))", ParseC.parse_test @{context} "2 * x + cos (4 * x \<up> 3)");
968 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern TermC.matches in res*)
969 rew_sub ctxt 1 subst Rewrite_Ord.function_empty Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
970 if UnparseC.term @{context} res' = "2 * x + cos (d_d x (x \<up> 4))" andalso rewritten then ()
971 else error "build fun check_for' ?bdv changed 2";
973 val norm_res = case rewrite_set_inst_ ctxt false subst rls res' of
975 | SOME (norm_res, _) => norm_res;
976 if UnparseC.term @{context} norm_res = "2 * x + cos (4 * x \<up> 3)" then ()
977 else error "build fun check_for' ?bdv changed 3";
979 val norm_inf = case rewrite_set_inst_ ctxt false subst rls inf of
981 | SOME (norm_inf, _) => norm_inf;
982 if UnparseC.term @{context} norm_inf = "2 * x + cos (4 * x \<up> 3)" then ()
983 else error "build fun check_for' ?bdv changed 4";
986 if norm_res = norm_inf then ()
987 else error "build fun check_for' ?bdv changed 5";
989 if Error_Pattern.check_for' ctxt (res, inf) (subst: subst) ("errpatID": Error_Pattern.id, pat) rls = SOME "errpatID"
990 then () else error "error patt example1 changed";
992 "--------- build fun check_for ------------------------";
993 "--------- build fun check_for ------------------------";
994 "--------- build fun check_for ------------------------";
996 (ParseC.parse_test @{context} "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))",
997 ParseC.parse_test @{context} "d_d x (x \<up> 2) + cos (4 * x \<up> 3)");
998 val {errpats, rew_rls = rls, program = Prog prog, ...} = MethodC.from_store ctxt ["diff", "differentiate_on_R"]
1000 val env = [(ParseC.parse_test @{context} "v_v", ParseC.parse_test @{context} "x")];
1002 [Error_Pattern.empty, (*generalised for testing*)
1003 ("chain-rule-diff-both",
1004 [ParseC.patt_opt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)" |> the,
1005 ParseC.patt_opt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)" |> the,
1006 ParseC.patt_opt @{theory} "d_d ?bdv (?u \<up> ?n) = ?n * ?u \<up> (?n - 1)" |> the,
1007 ParseC.patt_opt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u" |> the,
1008 ParseC.patt_opt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u" |> the],
1009 [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain},
1010 @{thm diff_ln_chain}, @{thm diff_exp_chain}])];
1011 case Error_Pattern.check_for ctxt (res, inf) (prog, env) (errpats, rls) of SOME _ => ()
1012 | NONE => error "Error_Pattern.check_for broken";
1015 "--------- embed fun check_for ------------------------";
1016 "--------- embed fun check_for ------------------------";
1017 "--------- embed fun check_for ------------------------";
1020 [(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"],
1021 ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
1024 autoCalculate 1 CompleteCalcHead;
1025 autoCalculate 1 (Steps 1);
1026 autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))*)
1027 (*autoCalculate 1 (Steps 1);([2], Res), d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x (x \<up> \<up> 4)*)
1029 "~~~~~ fun appendFormula , args:"; val (cI, (ifo:TermC.as_string)) = (1, "d_d x (x \<up> 2) + cos (4 * x \<up> 3)");
1030 "~~~~~ fun appendFormula' , args:"; val (cI, (ifo: TermC.as_string)) = (cI, ifo);
1031 val cs = States.get_calc cI
1032 val pos = States.get_pos cI 1;
1033 (*+*)if pos = ([1], Res) then () else error "inform with (positive) Error_Pattern.check_for broken 1";
1034 val ("ok", cs' as (_, _, ptp)) = (*case*) Step.do_next pos cs (*of*);
1035 (*case*) Step_Solve.by_term ptp (encode ifo) (*of*); (*ERROR WAS: "no derivation found"*)
1036 "~~~~~ fun Step_Solve.by_term , args:"; val (((*next_*)cs as (_, _, (pt, pos as (p, _))): Calc.state_post), istr)
1037 = (cs', (encode ifo));
1038 val ctxt = get_ctxt pt pos (*see TODO.thy*)
1039 val SOME f_in = (*case*) ParseC.term_opt ctxt istr (*of*);
1040 val pos_pred = lev_back' pos
1041 val f_pred = Ctree.get_curr_formula (pt, pos_pred);
1042 (*if*) f_pred = f_in; (*else*)
1043 val NONE = (*case*) CAS_Cmd.input f_in (*of*);
1044 (*old* )val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
1045 (*old*)val {program = prog, ...} = MethodC.from_store ctxt metID
1046 (*old*)val istate = get_istate_LI pt pos
1047 (*old*)val ctxt = get_ctxt pt pos
1049 val LI.Not_Derivable =
1050 (*case*) LI.locate_input_term (pt, pos) f_in (*of*);
1051 val met_id = Ctree.get_obj Ctree.g_metID pt (Ctree.par_pblobj pt p)
1052 val (errpats, rew_rls, prog) = case MethodC.from_store' (Know_Store.get_via_last_thy "Build_Thydata") met_id of
1053 {errpats, rew_rls, program = Rule.Prog prog, ...} => (errpats, rew_rls, prog)
1054 | _ => error "inform: uncovered case of MethodC.from_store ctxt"
1056 (*+*)if Error_Pattern.s_to_string ctxt errpats = "[(\"chain-rule-diff-both\",\n[d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u), d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u), d_d ?bdv (?u \<up> ?n) = ?n * ?u \<up> (?n - 1)],\n[\"d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u\", \"d_d ?bdv (cos ?u) = - sin ?u * d_d ?bdv ?u\", \"d_d ?bdv (?u \<up> ?n) = ?n * ?u \<up> (?n - 1) * d_d ?bdv ?u\"]]"
1057 (*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 3";
1059 val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
1061 (*+*)if UnparseC.term @{context} f_pred = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" andalso
1062 (*+*) UnparseC.term @{context} f_in = "d_d x (x \<up> 2) + cos (4 * x \<up> 3)"
1063 (*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 2";
1065 val SOME "chain-rule-diff-both" = (*case*) Error_Pattern.check_for ctxt (f_pred, f_in) (prog, env) (errpats, rew_rls) (*of*);
1068 (*+*)val (_, _, ptp') = cs';
1069 case Step_Solve.by_term ptp' (encode ifo) of
1070 ("error pattern #chain-rule-diff-both#", calcstate') => ()
1071 | _ => error "inform with (positive) Error_Pattern.check_for broken"
1074 "----------- re-build: fill_from_store without thy-hierarchy -----------------------------------";
1075 "----------- re-build: fill_from_store without thy-hierarchy -----------------------------------";
1076 "----------- re-build: fill_from_store without thy-hierarchy -----------------------------------";
1078 val c = []: int list
1079 val (p,_,f,nxt,_,pt) = Test_Code.init_calc @{context}
1080 [(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"],
1081 ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
1082 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1083 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1084 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1085 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1086 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1087 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1088 val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = Apply_Method ["diff", "differentiate_on_R"]*)
1089 val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = Rewrite_Inst (["(''bdv'', x)"], ("diff_sum", "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v"))*)
1091 val "d_d x (x \<up> 2 + sin (x \<up> 4))" = f2str f;
1092 val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = Rewrite_Inst (["(''bdv'', x)"], ("diff_sin_chain", "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u"))*)
1094 val "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" = f2str f
1096 val return_of_me = me nxt p c pt; (*nxt = Rewrite_Inst (["(''bdv'', x)"], ("diff_pow", "d_d ?bdv (?bdv \<up> ?n) = ?n * ?bdv \<up> (?n - 1)"))*)
1098 val "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" = f2str f;
1099 (* "d_d x (x \<up> 2) + cos (x \<up> 4)" .. wrong user input within next step *)
1100 (*//------------------ step into find_fill_patterns ----------------------------------------\\*)
1101 (* INSTEAD OF STEPPING INTO me WE DO SO FOR Kernel.findFillpatterns cI errpatID =
1103 val ((pt, _), _) = States.get_calc cI
1104 val pos = States.get_pos cI 1;
1105 val fillpats = Error_Pattern.find_fill_patterns (pt, pos) errpatID
1107 "~~~~~ fun findFillpatterns , args:"; val (pt, p, errpatID) = (pt, p, "chain-rule-diff-both");
1108 "~~~~~ fun find_fill_patterns , args:"; val ((pt, pos as (p, _)), id) = ((pt, p), errpatID);
1110 val f_curr = Ctree.get_curr_formula (pt, pos);
1111 val pp = Ctree.par_pblobj pt p
1112 val (errpats, prog) = case MethodC.from_store ctxt (Ctree.get_obj Ctree.g_metID pt pp) of
1113 {errpats, program = Rule.Prog prog, ...} => (errpats, prog)
1114 | _ => error "find_fill_patterns: uncovered case of MethodC.from_store ctxt"
1116 val ctxt = Ctree.get_ctxt pt pos
1117 val f_curr = Ctree.get_curr_formula (pt, pos)
1118 val met_id = Ctree.get_obj Ctree.g_metID pt (Ctree.par_pblobj pt p)
1119 val (errpats, prog) = case MethodC.from_store' (Know_Store.get_via_last_thy "Build_Thydata") met_id of
1120 {errpats, program = Rule.Prog prog, ...} => (errpats, prog)
1121 | _ => error "find_fill_patterns: uncovered case of MethodC.from_store ctxt"
1124 (*+*)val 1 = length errpats(*ONLY WITH from_store' @{theory (*!!!*)Build_Thydata}*)
1125 val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
1126 val subst = Subst.for_bdv ctxt prog env
1127 val errpatthms = errpats
1128 |> filter ((curry op = errpatID) o (#1: Error_Pattern.T -> Error_Pattern.id))
1129 |> map (#3: Error_Pattern.T -> thm list)
1132 (*+*)val 3 = length errpatthms;
1133 (*+*)val 5 = length (get_fill_ins @{theory} "diff_sin_chain");
1136 fill_from_store ctxt subst f_curr errpatID) errpatthms |> flat (*of*);
1137 "~~~~~ fun fill_from_store , args:"; val (ctxt, subst, form, (*id*)errpat_id, thm) =
1138 (ctxt, subst, f_curr, errpatID, hd errpatthms);
1139 val thm_id_long = Thm.get_name_hint thm
1141 (*+*)val "Diff.diff_sin_chain" = thm_id_long;
1142 (*+*)val "diff_sin_chain" = ThmC.cut_id thm_id_long;
1144 val thm_id = ThmC.cut_id thm_id_long
1147 Error_Pattern.get_fill_ins (Proof_Context.theory_of ctxt) thm_id;
1148 "~~~~~ fun get_fill_ins , args:"; val (thy, thm_id) =
1149 ((Proof_Context.theory_of ctxt), thm_id);
1150 (*case*) AList.lookup (op =) (get_fill_inss thy) thm_id (*of*);
1151 val ERROR "fill_ins for thm \"diff_sin_chain\" missing in theory \"Isac_Knowledge\" (and ancestors)\nTODO exception hierarchy needs to be established." =
1152 ERROR ("fill_ins for thm \"" ^ thm_id ^ "\" missing in theory \"" ^
1153 (thy |> ThyC.id_of) ^ "\" (and ancestors)" ^
1154 "\nTODO exception hierarchy needs to be established.");
1156 (*return to fill_from_store..*)
1157 val some = map (fill_form ctxt subst (thm, form) errpat_id) fill_ins;
1158 val return_fill_from_store = some |> filter is_some |> map the;
1160 (* final test ... ----------------------------------------------------------------------------*)
1161 (*+*)if length return_fill_from_store = 5 then
1162 (*+*) case return_fill_from_store of
1163 (*+*) ("fill-d_d-arg", tm, thm, subsopt) :: _ => if UnparseC.term @{context} tm =
1164 (*+*) "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4)) =\nd_d x (x \<up> 2) + cos (x \<up> 4) * d_d x ?_dummy_1"
1165 (*+*) then () else error "find_fill_patterns changed 2a"
1166 (*+*) | _ => error "find_fill_patterns changed 2b"
1167 (*+*)else error "find_fill_patterns changed 2c";
1168 (*-------------------- stop step into find_fill_patterns -------------------------------------*)
1169 (*\\------------------ step into find_fill_patterns ----------------------------------------//*)
1171 val (p,_,f,nxt,_,pt) = return_of_me
1172 val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = Rewrite_Inst (["(''bdv'', x)"], ("diff_pow", "d_d ?bdv (?bdv \<up> ?n) = ?n * ?bdv \<up> (?n - 1)"))*)
1174 val "d_d x (x \<up> 2) + cos (x \<up> 4) * (4 * x \<up> (4 - 1))" = f2str f;
1175 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1176 val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = Check_Postcond ["derivative_of", "function"]*)
1177 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1179 val "2 * x + cos (x \<up> 4) * 4 * x \<up> 3" = f2str f
1180 val End_Proof' = nxt;
1183 "--------- embed fun find_fill_patterns ---------------------------";
1184 "--------- embed fun find_fill_patterns ---------------------------";
1185 "--------- embed fun find_fill_patterns ---------------------------";
1188 [(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"],
1189 ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
1192 autoCalculate 1 CompleteCalcHead;
1193 autoCalculate 1 (Steps 1);
1194 autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))*)
1195 appendFormula 1 "d_d x (x \<up> 2) + cos (4 * x \<up> 3)";
1196 (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
1198 <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
1199 "~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
1200 val ((pt, _), _) = States.get_calc cI
1201 val pos = States.get_pos cI 1;
1203 val return_from_find_fill_patterns = find_fill_patterns (pt, pos) errpatID;
1206 (* final test ... ----------------------------------------------------------------------------*)
1207 val 6 = length return_from_find_fill_patterns
1208 val (fill_in_id, term, thm, subst) :: _ = return_from_find_fill_patterns
1210 val "fill-d_d-arg" = fill_in_id
1211 val "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4)) =\nd_d x (x \<up> 2) + cos (x \<up> 4) * d_d x ?_dummy_1" =
1212 UnparseC.term @{context} term
1213 val "Diff.diff_sin_chain" = Thm.get_name_hint thm
1214 val "[(''bdv'', x)]" = subst |> the |> Subst.string_of_input;
1217 "--------- build fun is_exactly_equal, inputFillFormula ----------";
1218 "--------- build fun is_exactly_equal, inputFillFormula ----------";
1219 "--------- build fun is_exactly_equal, inputFillFormula ----------";
1222 [(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"],
1223 ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
1226 autoCalculate 1 CompleteCalcHead;
1227 autoCalculate 1 (Steps 1);
1228 autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))*)
1229 appendFormula 1 "d_d x (x \<up> 2) + cos (4 * x \<up> 3)" (*|> Future.join*); (*<<<<<<<=========================*)
1230 (* the check for errpat is maximally liberal (whole term modulo "rew_rls" from "type met"),
1231 would recognize "cos (4 * x \<up> (4 - 1)) + 2 * x" as well.
1232 results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
1233 instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
1234 val ((pt,pos), _) = States.get_calc 1;
1235 val p = States.get_pos 1 1;
1236 val (Form f, _, asms) = ME_Misc.pt_extract ctxt (pt, p);
1238 if p = ([1], Res) andalso UnparseC.term @{context} f = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" then
1239 case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"],
1240 ("diff_sum", thm)) =>
1241 if (UnparseC.term @{context} o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
1242 else error "embed fun fill_form changed 11"
1243 | _ => error "embed fun fill_form changed 12"
1244 else error "embed fun fill_form changed 13";
1246 findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
1247 (*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x \<up> 2) + d_d x (sin (x \<up> 4)) =
1248 d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
1249 val ((pt,pos),_) = States.get_calc 1;
1250 val p = States.get_pos 1 1;
1252 val (Form f, _, asms) = ME_Misc.pt_extract ctxt (pt, p);
1253 if p = ([1], Res) andalso UnparseC.term @{context} f = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" then
1254 case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"],
1255 ("diff_sum", thm)) =>
1256 if (UnparseC.term @{context} o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
1257 else error "embed fun fill_form changed 21"
1258 | _ => error "embed fun fill_form changed 22"
1259 else error "embed fun fill_form changed 23";
1261 requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
1262 (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
1263 val ((pt,pos),_) = States.get_calc 1;
1264 val p = States.get_pos 1 1;
1265 val (Form f, _, asms) = ME_Misc.pt_extract ctxt (pt, p);
1266 if p = ([1], Res) andalso existpt [2] pt
1267 andalso UnparseC.term @{context} f = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))"
1268 then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"],
1269 ("diff_sum", thm)) =>
1270 if (UnparseC.term @{context} o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
1271 else error "embed fun fill_form changed 31"
1272 | _ => error "embed fun fill_form changed 32"
1273 else error "embed fun fill_form changed 33";
1275 (* input a formula which exactly fills the gaps in a "fillformula"
1276 presented to the learner immediately before by "requestFillformula (errpatID, fillpatID)":
1277 errpatID: lhs of the respective thm = lhs of fillformula with fillpatID.
1278 the respective thm is in the ctree ................
1280 "~~~~~ fun inputFillFormula, args:"; val (cI, ifo) =
1281 (1, "d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x (x \<up> 4)");
1282 val ((pt, _), _) = States.get_calc cI
1283 val pos = States.get_pos cI 1;
1285 "~~~~~ fun is_exactly_equal, args:"; val ((pt, pos as (p, p_)), istr) = ((pt, pos), ifo);
1286 val SOME ifo = ParseC.term_opt (ThyC.get_theory @{context} "Isac_Knowledge" |> Proof_Context.init_global) istr
1288 val tac = get_obj g_tac pt p';
1289 val Rewrite_Inst ([bbb as "(''bdv'', x)"], ("diff_sin_chain", ttt)) = tac;
1290 if (UnparseC.term @{context} o Thm.prop_of) ttt = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
1291 else error "inputFillFormula changed 10";
1292 val Applicable.Yes rew = Step.check tac (pt, pos);
1293 val Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) = rew;
1295 "~~~~~ to inputFillFormula return val:"; val ("ok", tac) = ("ok", tac);
1296 val ("ok", (_, c, ptp as (_,p'))) = Step.by_tactic tac (pt, pos);
1297 States.upd_calc cI (ptp, []);
1298 States.upd_ipos cI 1 p';
1299 autocalculateOK2xml cI pos (if null c then p' else last_elem c) p';
1301 "~~~~~ final check:";
1302 val ((pt, _),_) = States.get_calc 1;
1303 val p = States.get_pos 1 1;
1304 val (Form f, _, asms) = ME_Misc.pt_extract ctxt (pt, p);
1305 if p = ([2], Res) andalso UnparseC.term @{context} f = "d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x (x \<up> 4)"
1306 then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"],
1307 ("diff_sin_chain", thm)) =>
1308 if (UnparseC.term @{context} o Thm.prop_of) thm = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
1309 else error "inputFillFormula changed 111"
1310 | _ => error "inputFillFormula changed 112"
1311 else error "inputFillFormula changed 113";
1313 "--------- fun appl_adds -----------------------------------------";
1314 "--------- fun appl_adds -----------------------------------------";
1315 "--------- fun appl_adds -----------------------------------------";
1316 (* val (dI, oris, model, pbt, selct::ss) =
1317 (dI, pors, probl, model, map itms2fstr probl);
1320 (* val (dI, oris, model, pbt, (selct::ss))=
1321 (#1 (References.select_input ospec spec), oris, []:I_Model.T,
1322 ((#model o Problem.from_store) (#2 (References.select_input ospec spec))),(imodel2fstr imodel));
1323 val iii = appl_adds dI oris model pbt (selct::ss);
1324 tracing(I_Model.to_string thy iii);
1326 val itm = add_single' dI oris model pbt selct;
1327 val model = I_Model.add itm model;
1329 val _::selct::ss = (selct::ss);
1330 val itm = add_single' dI oris model pbt selct;
1331 val model = I_Model.add itm model;
1333 val _::selct::ss = (selct::ss);
1334 val itm = add_single' dI oris model pbt selct;
1335 val model = I_Model.add itm model;
1336 tracing(I_Model.to_string thy model);
1338 val _::selct::ss = (selct::ss);
1339 val itm = add_single' dI oris model pbt selct;
1340 val model = I_Model.add itm model;
1342 "--------- fun concat_deriv --------------------------------------";
1343 "--------- fun concat_deriv --------------------------------------";
1344 "--------- fun concat_deriv --------------------------------------";
1346 val ({rew_ord, asm_rls, rules,...}, fo, ifo) =
1347 (Rule_Set.rep Test_simplify, ParseC.parse_test @{context} "x+1+ - 1*2=0", ParseC.parse_test @{context} "-2*1+(x+1)=0");
1348 (tracing o Derive.trtas2str) fod';
1350 (x + 1 + - 1 * 2 = 0, Thm ("radd_commute", "?m + ?n = ?n + ?m"), (- 1 * 2 + (x + 1) = 0, []))", "
1351 (- 1 * 2 + (x + 1) = 0, Thm ("radd_commute", "?m + ?n = ?n + ?m"), (- 1 * 2 + (1 + x) = 0, []))", "
1352 (- 1 * 2 + (1 + x) = 0, Thm ("radd_left_commute", "?x + (?y + ?z) = ?y + (?x + ?z)"), (1 + (- 1 * 2 + x) = 0, []))", "
1353 (1 + (- 1 * 2 + x) = 0, Thm ("#mult_Float ((~1,0), (0,0)) __ ((2,0), (0,0))", "- 1 * 2 = -2"), (1 + (-2 + x) = 0, []))"]
1355 (tracing o Derive.trtas2str) (map Derive.rev_deriv' rifod');
1357 (1 + (-2 + x) = 0, Thm ("sym_#mult_Float ((~2,0), (0,0)) __ ((1,0), (0,0))", "-2 = -2 * 1"), (1 + (-2 * 1 + x) = 0, []))", "
1358 (1 + (-2 * 1 + x) = 0, Thm ("sym_radd_left_commute", "?y + (?x + ?z) = ?x + (?y + ?z)"), (-2 * 1 + (1 + x) = 0, []))", "
1359 (-2 * 1 + (1 + x) = 0, Thm ("sym_radd_commute", "?n + ?m = ?m + ?n"), (-2 * 1 + (x + 1) = 0, []))"]
1362 "--------- handle an input formula -------------------------------";
1363 "--------- handle an input formula -------------------------------";
1364 "--------- handle an input formula -------------------------------";
1366 Untersuchung zur Formeleingabe (appendFormula, replaceFormla) zu einer Anregung von Alan Krempler:
1367 Welche RICHTIGEN Formeln koennen NICHT abgeleitet werden,
1368 wenn Abteilungen nur auf gleichem Level gesucht werden ?
1371 Beispiele zum Equationsolver von Richard Lang aus /src/sml/kbtest/rlang.sml
1373 ------------------------------------------------------------------------------
1374 "Schalk I s.87 Bsp 52a ((5*x)/(x - 2) - x/(x+2)=4)";
1375 ------------------------------------------------------------------------------
1376 1. "5 * x / (x - 2) - x / (x + 2) = 4"
1378 4. "12 * x + 4 * x \<up> 2 = 4 * (-4 + x \<up> 2)",Subproblem["normalise", "poly"..
1380 4.3. "16 + 12 * x = 0", Subproblem["degree_1", "polynomial", "univariate"..
1382 4.3.3. "[x = -4 / 3]")), Check_elementwise "Assumptions"
1385 ------------------------------------------------------------------------------
1386 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
1388 (4.1)..(4.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
1389 ------------------------------------------------------------------------------
1392 ------------------------------------------------------------------------------
1393 "Schalk I s.87 Bsp 55b (x/(x \<up> 2 - 6*x+9) - 1/(x \<up> 2 - 3*x) =1/x)";
1394 ------------------------------------------------------------------------------
1395 1. "x / (x \<up> 2 - 6 * x + 9) - 1 / (x \<up> 2 - 3 * x) = 1 / x"
1397 4. "(3 + (- 1 * x + x \<up> 2)) * x = 1 * (9 * x + (x \<up> 3 + -6 * x \<up> 2))"
1398 Subproblem["normalise", "polynomial", "univariate"..
1400 4.4. "-6 * x + 5 * x \<up> 2 = 0", Subproblem["bdv_only", "degree_2", "poly"..
1402 4.4.4. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
1403 4.4.5. "[x = 0, x = 6 / 5]"
1405 5. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
1407 ------------------------------------------------------------------------------
1408 (1)..(4): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite schiebt [Ableitung waere in 4.4.x]
1410 (4.1)..(4.4.5): keine 'richtige' Eingabe kann abgeleitet werden, die dem Ergebnis "[x = 6 / 5]" aequivalent ist [Ableitung waere in 5.]
1411 ------------------------------------------------------------------------------
1414 ------------------------------------------------------------------------------
1415 "Schalk II s.56 Bsp 73b (sqrt(x+1)+sqrt(4*x+4)=sqrt(9*x+9))";
1416 ------------------------------------------------------------------------------
1417 1. "sqrt (x + 1) + sqrt (4 * x + 4) = sqrt (9 * x + 9)"
1419 6. "13 + 13 * x + -2 * sqrt ((4 + 4 * x) * (9 + 9 * x)) = 1 + x"
1420 Subproblem["sq", "rootX", "univariate", "equation"]
1422 6.6. "144 + 288 * x + 144 * x \<up> 2 = 144 + x \<up> 2 + 288 * x + 143 * x \<up> 2"
1423 Subproblem["normalise", "polynomial", "univariate", "equation"]
1424 ...6.6.3 "0 = 0" Subproblem["degree_0", "polynomial", "univariate", "equation"]
1426 6.6.3.2 "UniversalList"
1427 ------------------------------------------------------------------------------
1428 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die eine der Wurzeln auf die andere Seite verschieb [Ableitung ware in 6.6.n]
1430 (6.1)..(6.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 6.6.n]
1431 ------------------------------------------------------------------------------
1433 (*sh. comments auf 498*)
1434 "--------- fun dropwhile' ----------------------------------------";
1435 "--------- fun dropwhile' ----------------------------------------";
1436 "--------- fun dropwhile' ----------------------------------------";
1438 fun equal a b = a=b;
1439 val foder = [0,1,2,3,4,5]; val ifoder = [11,12,3,4,5];
1440 val r_foder = rev foder; val r_ifoder = rev ifoder;
1441 dropwhile' equal r_foder r_ifoder;
1442 > vval it = ([0, 1, 2, 3], [3, 12, 11]) : int list * int list
1444 val foder = [3,4,5]; val ifoder = [11,12,3,4,5];
1445 val r_foder = rev foder; val r_ifoder = rev ifoder;
1446 dropwhile' equal r_foder r_ifoder;
1447 > val it = ([3], [3, 12, 11]) : int list * int list
1449 val foder = [5]; val ifoder = [11,12,3,4,5];
1450 val r_foder = rev foder; val r_ifoder = rev ifoder;
1451 dropwhile' equal r_foder r_ifoder;
1452 > val it = ([5], [5, 4, 3, 12, 11]) : int list * int list
1454 val foder = [10,11,12,13,14,15]; val ifoder = [11,12,3,4,5];
1455 val r_foder = rev foder; val r_ifoder = rev ifoder;
1456 dropwhile' equal r_foder r_ifoder;
1457 > *** dropwhile': did not start with equal elements*)