1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/Tools/isac/Interpret/error-pattern.sml Sat Mar 07 15:37:37 2020 +0100
1.3 @@ -0,0 +1,1383 @@
1.4 +(* Title: tests on inform.sml
1.5 + Author: Walther Neuper 060225,
1.6 + (c) due to copyright terms
1.7 +*)
1.8 +
1.9 +"-----------------------------------------------------------------";
1.10 +"table of contents -----------------------------------------------";
1.11 +"-----------------------------------------------------------------";
1.12 +"appendForm with miniscript with mini-subpbl:";
1.13 +"--------- appendFormula: on Res + equ_nrls ----------------------";
1.14 +"--------- appendFormula: on Frm + equ_nrls ----------------------";
1.15 +"--------- appendFormula: on Res + NO deriv ----------------------";
1.16 +"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
1.17 +"replaceForm with miniscript with mini-subpbl:";
1.18 +"--------- replaceFormula: on Res + = ----------------------------";
1.19 +"--------- replaceFormula: on Res + = 1st Nd ---------------------";
1.20 +"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
1.21 +"--------- replaceFormula: cut calculation -----------------------";
1.22 +"--------- replaceFormula: cut calculation -----------------------";
1.23 +(* 040307 copied from informtest.sml ... old versions
1.24 +"--------- maximum-example, UC: Modeling / modifyCalcHead --------";*)
1.25 +"--------- syntax error ------------------------------------------";
1.26 +"CAS-command:";
1.27 +"--------- CAS-command on ([],Pbl) -------------------------------";
1.28 +"--------- CAS-command on ([],Pbl) FE-interface ------------------";
1.29 +"--------- locate_input_term [rational,simplification] ----------------------";
1.30 +"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
1.31 +"--------- Take as 1st tac, start from exp -----------------------";
1.32 +"--------- init_form, start with <NEW> (CAS input) ---------------";
1.33 +"--------- build fun check_err_patt ------------------------------";
1.34 +"--------- build fun check_err_patt ?bdv -------------------------";
1.35 +"--------- build fun check_error_patterns ------------------------";
1.36 +"--------- embed fun check_error_patterns ------------------------";
1.37 +"--------- build fun get_fillpats --------------------------------";
1.38 +"--------- embed fun find_fillpatterns ---------------------------";
1.39 +"--------- build fun is_exactly_equal, inputFillFormula ----------";
1.40 +"--------- fun appl_adds -----------------------------------------";
1.41 +"--------- fun concat_deriv --------------------------------------";
1.42 +"--------- handle an input formula -------------------------------";
1.43 +"--------- fun dropwhile' ----------------------------------------";
1.44 +"-----------------------------------------------------------------";
1.45 +"-----------------------------------------------------------------";
1.46 +"-----------------------------------------------------------------";
1.47 +
1.48 +
1.49 +"--------- appendFormula: on Res + equ_nrls ----------------------";
1.50 +"--------- appendFormula: on Res + equ_nrls ----------------------";
1.51 +"--------- appendFormula: on Res + equ_nrls ----------------------";
1.52 + val Prog sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
1.53 + (writeln o term2str) sc;
1.54 + val Prog sc = (#scr o get_met) ["Test","solve_linear"];
1.55 + (writeln o term2str) sc;
1.56 +
1.57 + reset_states ();
1.58 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.59 + ("Test", ["sqroot-test","univariate","equation","test"],
1.60 + ["Test","squ-equ-test-subpbl1"]))];
1.61 + Iterator 1; moveActiveRoot 1;
1.62 + autoCalculate 1 CompleteCalcHead;
1.63 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
1.64 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
1.65 +
1.66 + appendFormula 1 "-2 * 1 + (1 + x) = 0" (*|> Future.join*); refFormula 1 (get_pos 1 1);
1.67 + val ((pt,_),_) = get_calc 1;
1.68 + val str = pr_ctree pr_short pt;
1.69 +if str =
1.70 +(". ----- pblobj -----\n" ^
1.71 +"1. x + 1 = 2\n" ^
1.72 +"2. x + 1 + -1 * 2 = 0\n" ^
1.73 +"2.1. x + 1 + -1 * 2 = 0\n" ^
1.74 +"2.2. 1 + x + -1 * 2 = 0\n" ^
1.75 +"2.3. 1 + (x + -1 * 2) = 0\n" ^
1.76 +"2.4. 1 + (x + -2) = 0\n" ^
1.77 +"2.5. 1 + (x + -2 * 1) = 0\n" ^
1.78 +"2.6. 1 + x + -2 * 1 = 0\n" ) then ()
1.79 +else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
1.80 +
1.81 + moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
1.82 + moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
1.83 +
1.84 + (*the seven steps of detailed derivation*)
1.85 + moveDown 1 ([1 ],Res); refFormula 1 ([2,1],Frm);
1.86 + moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
1.87 + moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
1.88 + moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res);
1.89 + moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
1.90 + moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
1.91 + moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
1.92 + val ((pt,_),_) = get_calc 1;
1.93 + if "-2 * 1 + (1 + x) = 0" = term2str (fst (get_obj g_result pt [2,6])) then()
1.94 + else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
1.95 +
1.96 + fetchProposedTactic 1; (*takes Iterator 1 _1_*)
1.97 +(* <ERROR> error in kernel </ERROR> ALREADY IN 2009-2*)
1.98 +(*========== inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 =============
1.99 + val (_,(tac,_,_)::_) = get_calc 1;
1.100 + if tac = Rewrite_Set "Test_simplify" then ()
1.101 + else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
1.102 +============ inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 ============*)
1.103 +
1.104 + autoCalculate 1 CompleteCalc;
1.105 + val ((pt,_),_) = get_calc 1;
1.106 + if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
1.107 + else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
1.108 + (* autoCalculate 1 CompleteCalc;
1.109 + val ((pt,p),_) = get_calc 1;
1.110 + (writeln o istates2str) (get_obj g_loc pt [ ]);
1.111 + (writeln o istates2str) (get_obj g_loc pt [1]);
1.112 + (writeln o istates2str) (get_obj g_loc pt [2]);
1.113 + (writeln o istates2str) (get_obj g_loc pt [3]);
1.114 + (writeln o istates2str) (get_obj g_loc pt [3,1]);
1.115 + (writeln o istates2str) (get_obj g_loc pt [3,2]);
1.116 + (writeln o istates2str) (get_obj g_loc pt [4]);
1.117 +
1.118 + *)
1.119 +"----------------------------------------------------------";
1.120 +
1.121 + val fod = make_deriv (@{theory "Isac_Knowledge"}) Atools_erls
1.122 + ((#rules o rep_rls) Test_simplify)
1.123 + (sqrt_right false (@{theory "Pure"})) NONE
1.124 + (str2term "x + 1 + -1 * 2 = 0");
1.125 + (writeln o trtas2str) fod;
1.126 +
1.127 + val ifod = make_deriv (@{theory "Isac_Knowledge"}) Atools_erls
1.128 + ((#rules o rep_rls) Test_simplify)
1.129 + (sqrt_right false (@{theory "Pure"})) NONE
1.130 + (str2term "-2 * 1 + (1 + x) = 0");
1.131 + (writeln o trtas2str) ifod;
1.132 + fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
1.133 + val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
1.134 + val der = fod' @ (map rev_deriv' rifod');
1.135 + (writeln o trtas2str) der;
1.136 + "----------------------------------------------------------";
1.137 +DEconstrCalcTree 1;
1.138 +
1.139 +"--------- appendFormula: on Frm + equ_nrls ----------------------";
1.140 +"--------- appendFormula: on Frm + equ_nrls ----------------------";
1.141 +"--------- appendFormula: on Frm + equ_nrls ----------------------";
1.142 + reset_states ();
1.143 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.144 + ("Test", ["sqroot-test","univariate","equation","test"],
1.145 + ["Test","squ-equ-test-subpbl1"]))];
1.146 + Iterator 1; moveActiveRoot 1;
1.147 + autoCalculate 1 CompleteCalcHead;
1.148 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
1.149 + appendFormula 1 "2+ -1 + x = 2" (*|> Future.join*); refFormula 1 (get_pos 1 1);
1.150 +
1.151 + moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
1.152 +
1.153 + moveDown 1 ([1 ],Frm); refFormula 1 ([1,1],Frm);
1.154 + moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res);
1.155 + moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res);
1.156 + moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res);
1.157 + moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res);
1.158 + moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res);
1.159 + moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res);
1.160 + val ((pt,_),_) = get_calc 1;
1.161 + if "2 + -1 + x = 2" = term2str (fst (get_obj g_result pt [1,6])) then()
1.162 + else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
1.163 +
1.164 + fetchProposedTactic 1; (*takes Iterator 1 _1_*)
1.165 + val (_,(tac,_,_)::_) = get_calc 1;
1.166 + case tac of Rewrite_Set "norm_equation" => ()
1.167 + | _ => error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
1.168 + autoCalculate 1 CompleteCalc;
1.169 + val ((pt,_),_) = get_calc 1;
1.170 + if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
1.171 + else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
1.172 +DEconstrCalcTree 1;
1.173 +
1.174 +"--------- appendFormula: on Res + NO deriv ----------------------";
1.175 +"--------- appendFormula: on Res + NO deriv ----------------------";
1.176 +"--------- appendFormula: on Res + NO deriv ----------------------";
1.177 + reset_states ();
1.178 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.179 + ("Test", ["sqroot-test","univariate","equation","test"],
1.180 + ["Test","squ-equ-test-subpbl1"]))];
1.181 + Iterator 1; moveActiveRoot 1;
1.182 + autoCalculate 1 CompleteCalcHead;
1.183 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
1.184 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
1.185 +
1.186 + appendFormula 1 "x = 2" (*|> Future.join*);
1.187 + val ((pt,p),_) = get_calc 1;
1.188 + val str = pr_ctree pr_short pt;
1.189 + writeln str;
1.190 + if str = ". ----- pblobj -----\n1. x + 1 = 2\n" andalso p = ([1], Res)
1.191 + then ()
1.192 + else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
1.193 +
1.194 + fetchProposedTactic 1;
1.195 + val (_,(tac,_,_)::_) = get_calc 1;
1.196 + case tac of Rewrite_Set "Test_simplify" => ()
1.197 + | _ => error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
1.198 + autoCalculate 1 CompleteCalc;
1.199 + val ((pt,_),_) = get_calc 1;
1.200 + if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
1.201 + else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
1.202 +DEconstrCalcTree 1;
1.203 +
1.204 +"--------- appendFormula: on Res + late deriv --------------------";
1.205 +"--------- appendFormula: on Res + late deriv --------------------";
1.206 +"--------- appendFormula: on Res + late deriv --------------------";
1.207 +(*cp with "fun me" to test/../lucas-interpreter.sml:
1.208 + re-build: fun locate_input_term ---------------------------------------------------";
1.209 +*)
1.210 + reset_states ();
1.211 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.212 + ("Test", ["sqroot-test","univariate","equation","test"],
1.213 + ["Test","squ-equ-test-subpbl1"]))];
1.214 + Iterator 1; moveActiveRoot 1;
1.215 + autoCalculate 1 CompleteCalcHead;
1.216 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
1.217 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
1.218 +
1.219 + appendFormula 1 "x = 1" (*|> Future.join*);
1.220 + val ((pt,p),_) = get_calc 1;
1.221 + val str = pr_ctree pr_short pt;
1.222 + writeln str;
1.223 + 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)
1.224 + then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
1.225 + else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
1.226 +
1.227 + fetchProposedTactic 1;
1.228 + val (_,(tac,_,_)::_) = get_calc 1;
1.229 + case tac of Check_Postcond ["LINEAR", "univariate", "equation", "test"] => ()
1.230 + | _ => error "inform.sml: diff.behav.appendFormula: Res + late d 2";
1.231 + autoCalculate 1 CompleteCalc;
1.232 + val ((pt,_),_) = get_calc 1;
1.233 + if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
1.234 + else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
1.235 +DEconstrCalcTree 1;
1.236 +
1.237 +"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
1.238 +"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
1.239 +"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
1.240 + reset_states ();
1.241 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.242 + ("Test", ["sqroot-test","univariate","equation","test"],
1.243 + ["Test","squ-equ-test-subpbl1"]))];
1.244 + Iterator 1; moveActiveRoot 1;
1.245 + autoCalculate 1 CompleteCalcHead;
1.246 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
1.247 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
1.248 + appendFormula 1 "[x = 3 + -2*1]" (*|> Future.join*);
1.249 + val ((pt,p),_) = get_calc 1;
1.250 + val str = pr_ctree pr_short pt;
1.251 + writeln str;
1.252 + 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 ()
1.253 + else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
1.254 + autoCalculate 1 CompleteCalc;
1.255 + val ((pt,p),_) = get_calc 1;
1.256 + if "[x = 3 + -2 * 1]" = term2str (fst (get_obj g_result pt [])) then ()
1.257 + (* ~~~~~~~~~~ simplify as last step in any script ?!*)
1.258 + else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
1.259 +DEconstrCalcTree 1;
1.260 +
1.261 +"--------- replaceFormula: on Res + = ----------------------------";
1.262 +"--------- replaceFormula: on Res + = ----------------------------";
1.263 +"--------- replaceFormula: on Res + = ----------------------------";
1.264 + reset_states ();
1.265 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.266 + ("Test", ["sqroot-test","univariate","equation","test"],
1.267 + ["Test","squ-equ-test-subpbl1"]))];
1.268 + Iterator 1; moveActiveRoot 1;
1.269 + autoCalculate 1 CompleteCalcHead;
1.270 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
1.271 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
1.272 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
1.273 +
1.274 + replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
1.275 + val ((pt,_),_) = get_calc 1;
1.276 + val str = pr_ctree pr_short pt;
1.277 +
1.278 +(* before AK110725 this was
1.279 +". ----- pblobj -----\n
1.280 +1. x + 1 = 2\n
1.281 +2. x + 1 + -1 * 2 = 0\n
1.282 +2.1. x + 1 + -1 * 2 = 0\n
1.283 +2.2. 1 + x + -1 * 2 = 0\n
1.284 +2.3. 1 + (x + -1 * 2) = 0\n
1.285 +2.4. 1 + (x + -2) = 0\n
1.286 +2.5. 1 + (x + -2 * 1) = 0\n
1.287 +2.6. 1 + x + -2 * 1 = 0\n";
1.288 +*)
1.289 +if str =
1.290 +". ----- pblobj -----\n"^
1.291 +"1. x + 1 = 2\n"^
1.292 +"2. x + 1 + -1 * 2 = 0\n"^
1.293 +"2.1. x + 1 + -1 * 2 = 0\n"^
1.294 +"2.2. 1 + x + -1 * 2 = 0\n"^
1.295 +"2.3. 1 + (x + -1 * 2) = 0\n"^
1.296 +"2.4. 1 + (x + -2) = 0\n"^
1.297 +"2.5. 1 + (x + -2 * 1) = 0\n"^
1.298 +"2.6. 1 + x + -2 * 1 = 0\n" then()
1.299 +else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
1.300 +
1.301 + autoCalculate 1 CompleteCalc;
1.302 + val ((pt,pos as (p,_)),_) = get_calc 1;
1.303 + if pos = ([],Res) andalso "[x = 1]" = (term2str o fst) (get_obj g_result pt p) then()
1.304 + else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
1.305 +DEconstrCalcTree 1;
1.306 +
1.307 +"--------- replaceFormula: on Res + = 1st Nd ---------------------";
1.308 +"--------- replaceFormula: on Res + = 1st Nd ---------------------";
1.309 +"--------- replaceFormula: on Res + = 1st Nd ---------------------";
1.310 + reset_states ();
1.311 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.312 + ("Test", ["sqroot-test","univariate","equation","test"],
1.313 + ["Test","squ-equ-test-subpbl1"]))];
1.314 + Iterator 1; moveActiveRoot 1;
1.315 + autoCalculate 1 CompleteCalcHead;
1.316 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
1.317 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
1.318 +
1.319 + replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
1.320 + val ((pt,_),_) = get_calc 1;
1.321 + val str = pr_ctree pr_short pt;
1.322 + writeln str;
1.323 + 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 ()
1.324 + else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
1.325 + autoCalculate 1 CompleteCalc;
1.326 + val ((pt,pos as (p,_)),_) = get_calc 1;
1.327 + if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
1.328 + else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
1.329 +DEconstrCalcTree 1;
1.330 +
1.331 +"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
1.332 +"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
1.333 +"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
1.334 + reset_states ();
1.335 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.336 + ("Test", ["sqroot-test","univariate","equation","test"],
1.337 + ["Test","squ-equ-test-subpbl1"]))];
1.338 + Iterator 1; moveActiveRoot 1;
1.339 + autoCalculate 1 CompleteCalcHead;
1.340 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
1.341 +
1.342 + replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
1.343 + val ((pt,_),_) = get_calc 1;
1.344 + val str = pr_ctree pr_short pt;
1.345 + writeln str;
1.346 + 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 ()
1.347 + else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
1.348 + autoCalculate 1 CompleteCalc;
1.349 + val ((pt,pos as (p,_)),_) = get_calc 1;
1.350 + if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
1.351 + else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
1.352 +DEconstrCalcTree 1;
1.353 +
1.354 +"--------- replaceFormula: cut calculation -----------------------";
1.355 +"--------- replaceFormula: cut calculation -----------------------";
1.356 +"--------- replaceFormula: cut calculation -----------------------";
1.357 + reset_states ();
1.358 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.359 + ("Test", ["sqroot-test","univariate","equation","test"],
1.360 + ["Test","squ-equ-test-subpbl1"]))];
1.361 + Iterator 1; moveActiveRoot 1;
1.362 + autoCalculate 1 CompleteCalc;
1.363 + moveActiveRoot 1; moveActiveDown 1;
1.364 + if get_pos 1 1 = ([1], Frm) then ()
1.365 + else error "inform.sml: diff.behav. cut calculation 1";
1.366 +
1.367 + replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
1.368 + val ((pt,p),_) = get_calc 1;
1.369 + val str = pr_ctree pr_short pt;
1.370 + writeln str;
1.371 + if p = ([1], Res) then ()
1.372 + else error "inform.sml: diff.behav. cut calculation 2";
1.373 +
1.374 +
1.375 +(* 040307 copied from informtest.sml; ... old version
1.376 + "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
1.377 + "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
1.378 + "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
1.379 +
1.380 + val p = ([],Pbl);
1.381 + val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
1.382 + "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
1.383 + "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
1.384 + "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos (alpha::real)]",
1.385 + (*^^^ these are the elements for the root-problem (in variants)*)
1.386 + (*vvv these are elements required for subproblems*)
1.387 + "boundVariable a","boundVariable b","boundVariable alpha",
1.388 + "interval {x::real. 0 <= x & x <= 2*r}",
1.389 + "interval {x::real. 0 <= x & x <= 2*r}",
1.390 + "interval {x::real. 0 <= x & x <= pi}",
1.391 + "errorBound (eps=(0::real))"]
1.392 + (*specifying is not interesting for this example*)
1.393 + val spec = ("DiffApp", ["maximum_of","function"],
1.394 + ["DiffApp","max_by_calculus"]);
1.395 + (*the empty model with descriptions for user-guidance by Model_Problem*)
1.396 + val empty_model = [Given ["fixedValues []"],
1.397 + Find ["maximum", "valuesFor"],
1.398 + Relate ["relations []"]];
1.399 +
1.400 +
1.401 + (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
1.402 + val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
1.403 + (*val nxt = ("Model_Problem", ...*)
1.404 + val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
1.405 +
1.406 + val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.407 + (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
1.408 + val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
1.409 +(*[
1.410 +(0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
1.411 +(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
1.412 +(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
1.413 +(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
1.414 +
1.415 + (*the empty CalcHead is checked w.r.t the model and re-established as such*)
1.416 + val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, e_spec);
1.417 + val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
1.418 + 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";
1.419 +
1.420 + (*there is one input to the model (could be more)*)
1.421 + val (b,pt,ocalhd) =
1.422 + input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
1.423 + Find ["maximum", "valuesFor"],
1.424 + Relate ["relations"]], Pbl, e_spec);
1.425 + val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl;
1.426 + 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 ()
1.427 + else error "informtest.sml: diff.behav. max 2";
1.428 +
1.429 + (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
1.430 + val (b,pt''''',ocalhd) =
1.431 + input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
1.432 + Find ["maximum A", "valuesFor [a,b]"],
1.433 + Relate ["relations [A=a*b, a/2=r*sin alpha, \
1.434 + \b/2=r*cos alpha]"]], Pbl, e_spec);
1.435 + val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl;
1.436 + if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
1.437 +
1.438 + (*this input is complete in variant 1 (variant 3 does not work yet)*)
1.439 + val (b,pt''''',ocalhd) =
1.440 + input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
1.441 + Find ["maximum A", "valuesFor [a,b]"],
1.442 + Relate ["relations [A=a*b, \
1.443 + \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]],
1.444 + Pbl, e_spec);
1.445 + val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl;
1.446 +
1.447 + modifycalcheadOK2xml 111 (bool2str b) ocalhd;
1.448 +*)
1.449 +DEconstrCalcTree 1;
1.450 +
1.451 +"--------- syntax error ------------------------------------------";
1.452 +"--------- syntax error ------------------------------------------";
1.453 +"--------- syntax error ------------------------------------------";
1.454 + reset_states ();
1.455 + CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"],
1.456 + ("Test", ["sqroot-test","univariate","equation","test"],
1.457 + ["Test","squ-equ-test-subpbl1"]))];
1.458 + Iterator 1; moveActiveRoot 1;
1.459 + autoCalculate 1 CompleteCalcHead;
1.460 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
1.461 + autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
1.462 +
1.463 + appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
1.464 + val ((pt,_),_) = get_calc 1;
1.465 + val str = pr_ctree pr_short pt;
1.466 + writeln str;
1.467 + if str = ". ----- pblobj -----\n1. x + 1 = 2\n" then ()
1.468 + else error "inform.sml: diff.behav.appendFormula: syntax error";
1.469 +DEconstrCalcTree 1;
1.470 +
1.471 +"--------- CAS-command on ([],Pbl) -------------------------------";
1.472 +"--------- CAS-command on ([],Pbl) -------------------------------";
1.473 +"--------- CAS-command on ([],Pbl) -------------------------------";
1.474 +val (p,_,f,nxt,_,pt) =
1.475 + CalcTreeTEST [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
1.476 +val ifo = "solve(x+1=2,x)";
1.477 +val (_,(_,c,(pt,p))) = Step_Solve.by_term (pt,p) "solve(x+1=2,x)";
1.478 +show_pt pt;
1.479 +val nxt = (Apply_Method ["Test","squ-equ-test-subpbl1"]);
1.480 +val (p,_,f,nxt,_,pt) = me nxt p [] pt;
1.481 +if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
1.482 +else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
1.483 +DEconstrCalcTree 1;
1.484 +
1.485 +"--------- CAS-command on ([],Pbl) FE-interface ------------------";
1.486 +"--------- CAS-command on ([],Pbl) FE-interface ------------------";
1.487 +"--------- CAS-command on ([],Pbl) FE-interface ------------------";
1.488 +reset_states ();
1.489 +CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
1.490 +Iterator 1;
1.491 +moveActiveRoot 1;
1.492 +replaceFormula 1 "solve(x+1=2,x)";
1.493 +autoCalculate 1 CompleteCalc;
1.494 +val ((pt,p),_) = get_calc 1;
1.495 +show_pt pt;
1.496 +if p = ([], Res) then ()
1.497 +else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
1.498 +DEconstrCalcTree 1;
1.499 +
1.500 +"--------- inform [rational,simplification] ----------------------";
1.501 +"--------- inform [rational,simplification] ----------------------";
1.502 +"--------- inform [rational,simplification] ----------------------";
1.503 +reset_states ();
1.504 +CalcTree [(["Term (a * x / (b * x) + c * x / (d * x) + e / f)", "normalform N"],
1.505 + ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1.506 +Iterator 1; moveActiveRoot 1;
1.507 +autoCalculate 1 CompleteCalcHead;
1.508 +
1.509 +"--- (-1) give a preview on the calculation without any input";
1.510 +(*
1.511 +autoCalculate 1 CompleteCalc;
1.512 +val ((pt, p), _) = get_calc 1;
1.513 +show_pt pt;
1.514 +[
1.515 +(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
1.516 +(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
1.517 +(([1], Res), a / b + c / d + e / f), <--- (1) input arbitrary
1.518 +(([2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.519 +(([3], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
1.520 +(([4], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)), <--- (2) input next
1.521 +(([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))] <--- (3) is also final result
1.522 + EXAMPLE NOT OPTIMAL
1.523 +*)
1.524 +"--- (0) user input as the *first* step does not work, thus impdo at least 1 step";
1.525 +autoCalculate 1 (Steps 1);
1.526 +autoCalculate 1 (Steps 1);
1.527 +val ((pt, p), _) = get_calc 1;
1.528 +(*show_pt pt;
1.529 +[
1.530 +(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
1.531 +(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
1.532 +(([1], Res), a / b + c / d + e / f)]
1.533 +*)
1.534 +"--- (1) input an arbitrary next formula";
1.535 +appendFormula 1 "((a * d) + (c * b)) / (b * d) + e / f" (*|> Future.join*);
1.536 +val ((pt, p), _) = get_calc 1;
1.537 +(*show_pt pt;
1.538 +[
1.539 +(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
1.540 +(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
1.541 +(([1], Res), a / b + c / d + e / f),
1.542 +(([2,1], Frm), a / b + c / d + e / f),
1.543 +(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.544 +(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
1.545 +(([2], Res), (a * d + c * b) / (b * d) + e / f)]
1.546 +*)
1.547 +val ((pt,p),_) = get_calc 1;
1.548 +if p = ([2], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
1.549 +else error ("inform.sml: [rational,simplification] 1");
1.550 +
1.551 +"--- (2) input the next formula that would be presented by mat-engine";
1.552 +(* generate a preview:
1.553 +autoCalculate 1 (Steps 1);
1.554 +val ((pt, p), _) = get_calc 1;
1.555 +show_pt pt;
1.556 +[
1.557 +(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
1.558 +(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
1.559 +(([1], Res), a / b + c / d + e / f),
1.560 +(([2,1], Frm), a / b + c / d + e / f),
1.561 +(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.562 +(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
1.563 +(([2], Res), (a * d + c * b) / (b * d) + e / f),
1.564 +(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] <--- input this
1.565 +*)
1.566 +appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
1.567 +val ((pt, p), _) = get_calc 1;
1.568 +(*show_pt pt;
1.569 +[
1.570 +(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
1.571 +(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
1.572 +(([1], Res), a / b + c / d + e / f),
1.573 +(([2,1], Frm), a / b + c / d + e / f),
1.574 +(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.575 +(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
1.576 +(([2], Res), (a * d + c * b) / (b * d) + e / f),
1.577 +(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))]
1.578 +*)
1.579 +if p = ([3], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
1.580 +else error ("inform.sml: [rational,simplification] 2");
1.581 +
1.582 +"--- (3) input the exact final result";
1.583 +appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
1.584 +val ((pt, p), _) = get_calc 1;
1.585 +(*show_pt pt;
1.586 +[
1.587 +(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
1.588 +(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
1.589 +(([1], Res), a / b + c / d + e / f),
1.590 +(([2,1], Frm), a / b + c / d + e / f),
1.591 +(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.592 +(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
1.593 +(([2], Res), (a * d + c * b) / (b * d) + e / f),
1.594 +(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.595 +(([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.596 +(([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
1.597 +(([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.598 +(([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))]
1.599 +*)
1.600 +if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
1.601 +else error ("inform.sml: [rational,simplification] 3");
1.602 +
1.603 +"--- (4) finish the calculation + check the postcondition (in the future)";
1.604 +autoCalculate 1 CompleteCalc;
1.605 +val ((pt, p), _) = get_calc 1;
1.606 +val (t, asm) = get_obj g_result pt [];
1.607 +if term2str t = "(a * d * f + b * c * f + b * d * e) / (b * d * f)" andalso
1.608 +terms2str asm = "[\"b * d * f \<noteq> 0\",\"d \<noteq> 0\",\"b \<noteq> 0\",\"a * x / (b * x) + c * x / (d * x) + e / f is_ratpolyexp\"]"
1.609 +then () else error "inform [rational,simplification] changed at end";
1.610 +(*show_pt pt;
1.611 +[
1.612 +(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
1.613 +(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
1.614 +(([1], Res), a / b + c / d + e / f),
1.615 +(([2,1], Frm), a / b + c / d + e / f),
1.616 +(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.617 +(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
1.618 +(([2], Res), (a * d + c * b) / (b * d) + e / f),
1.619 +(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.620 +(([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.621 +(([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
1.622 +(([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.623 +(([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
1.624 +(([5], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
1.625 +(([6], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)),
1.626 +(([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))]
1.627 +*)
1.628 +DEconstrCalcTree 1;
1.629 +
1.630 +"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
1.631 +"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
1.632 +"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
1.633 +val t = str2term "Diff (x^^^2 + x + 1, x)";
1.634 +case t of Const ("Diff.Diff", _) $ _ => ()
1.635 + | _ => raise
1.636 + error "diff.sml behav.changed for CAS Diff (..., x)";
1.637 +atomty t;
1.638 +"-----------------------------------------------------------------";
1.639 +(*1>*)reset_states ();
1.640 +(*2>*)CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
1.641 +(*3>*)Iterator 1;moveActiveRoot 1;
1.642 +"----- here the Headline has been finished";
1.643 +(*4>*)moveActiveFormula 1 ([],Pbl);
1.644 +(*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
1.645 +val ((pt,_),_) = get_calc 1;
1.646 +val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
1.647 +val NONE = env;
1.648 +val (SOME istate, NONE) = loc;
1.649 +(*default_print_depth 5;*)
1.650 +writeln"-----------------------------------------------------------";
1.651 +spec;
1.652 +writeln (itms2str_ ctxt probl);
1.653 +writeln (itms2str_ ctxt meth);
1.654 +writeln (istate2str (fst istate));
1.655 +
1.656 +refFormula 1 ([],Pbl) (*--> correct CalcHead*);
1.657 + (*081016 NOT necessary (but leave it in Java):*)
1.658 +(*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
1.659 +"----- here the CalcHead has been completed --- ONCE MORE ?????";
1.660 +
1.661 +(***difference II***)
1.662 +val ((pt,p),_) = get_calc 1;
1.663 +(*val p = ([], Pbl)*)
1.664 +val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
1.665 +val NONE = env;
1.666 +val (SOME istate, NONE) = loc;
1.667 +(*default_print_depth 5;*) writeln (istate2str (fst istate)); (*default_print_depth 3;*)
1.668 +(*Pstate ([],
1.669 + [], NONE,
1.670 + ??.empty, Sundef, false)*)
1.671 +(*default_print_depth 5;*) spec; (*default_print_depth 3;*)
1.672 +(*("Isac_Knowledge",
1.673 + ["derivative_of", "function"],
1.674 + ["diff", "differentiate_on_R"]) : spec*)
1.675 +writeln (itms2str_ ctxt probl);
1.676 +(*[
1.677 +(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
1.678 +(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
1.679 +(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
1.680 +writeln (itms2str_ ctxt meth);
1.681 +(*[
1.682 +(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
1.683 +(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
1.684 +(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
1.685 +writeln"-----------------------------------------------------------";
1.686 +(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
1.687 +(*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
1.688 +autoCalculate 1 CompleteCalc;
1.689 +val ((pt,p),_) = get_calc 1;
1.690 +val Form res = (#1 o pt_extract) (pt, ([],Res));
1.691 +show_pt pt;
1.692 +if p = ([], Res) andalso term2str res = "1 + 2 * x" then ()
1.693 +else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
1.694 +DEconstrCalcTree 1;
1.695 +
1.696 +"--------- Take as 1st tac, start from exp -----------------------";
1.697 +"--------- Take as 1st tac, start from exp -----------------------";
1.698 +"--------- Take as 1st tac, start from exp -----------------------";
1.699 +(*the following input is copied from BridgeLog Java <==> SML,
1.700 + omitting unnecessary inputs*)
1.701 +(*1>*)reset_states ();
1.702 +(*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac_Knowledge",["derivative_of","function"],["diff","differentiate_on_R"]))];
1.703 +(*3>*)Iterator 1; moveActiveRoot 1;
1.704 +
1.705 +(*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
1.706 +(***difference II***)
1.707 +val ((pt,_),_) = get_calc 1;
1.708 +val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
1.709 +val NONE = env;
1.710 +val (SOME istate, NONE) = loc;
1.711 +(*default_print_depth 5;*) writeln (istate2str (fst istate)); (*default_print_depth 3;*)
1.712 +(*Pstate ([],
1.713 + [], NONE,
1.714 + ??.empty, Sundef, false)*)
1.715 +(*default_print_depth 5;*) spec; (*default_print_depth 3;*)
1.716 +(*("Isac_Knowledge",
1.717 + ["derivative_of", "function"],
1.718 + ["diff", "differentiate_on_R"]) : spec*)
1.719 +writeln (itms2str_ ctxt probl);
1.720 +(*[
1.721 +(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
1.722 +(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
1.723 +(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
1.724 +writeln (itms2str_ ctxt meth);
1.725 +(*[
1.726 +(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
1.727 +(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
1.728 +(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
1.729 +writeln"-----------------------------------------------------------";
1.730 +(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
1.731 +autoCalculate 1 (Steps 1);
1.732 +val ((pt,p),_) = get_calc 1;
1.733 +val Form res = (#1 o pt_extract) (pt, p);
1.734 +if term2str res = "d_d x (x ^^^ 2 + x + 1)" then ()
1.735 +else error "diff.sml Diff (x^2 + x + 1, x) from exp";
1.736 +DEconstrCalcTree 1;
1.737 +
1.738 +"--------- init_form, start with <NEW> (CAS input) ---------------";
1.739 +"--------- init_form, start with <NEW> (CAS input) ---------------";
1.740 +"--------- init_form, start with <NEW> (CAS input) ---------------";
1.741 +reset_states ();
1.742 +CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
1.743 +(*[[from sml: > @@@@@begin@@@@@
1.744 +[[from sml: 1
1.745 +[[from sml: <CALCTREE>
1.746 +[[from sml: <CALCID> 1 </CALCID>
1.747 +[[from sml: </CALCTREE>
1.748 +[[from sml: @@@@@end@@@@@*)
1.749 +Iterator 1;
1.750 +(*[[from sml: > @@@@@begin@@@@@
1.751 +[[from sml: 1
1.752 +[[from sml: <ADDUSER>
1.753 +[[from sml: <CALCID> 1 </CALCID>
1.754 +[[from sml: <USERID> 1 </USERID>
1.755 +[[from sml: </ADDUSER>
1.756 +[[from sml: @@@@@end@@@@@*)
1.757 +moveActiveRoot 1;
1.758 +(*[[from sml: > @@@@@begin@@@@@
1.759 +[[from sml: 1
1.760 +[[from sml: <CALCITERATOR>
1.761 +[[from sml: <CALCID> 1 </CALCID>
1.762 +[[from sml: <POSITION>
1.763 +[[from sml: <INTLIST>
1.764 +[[from sml: </INTLIST>
1.765 +[[from sml: <POS> Pbl </POS>
1.766 +[[from sml: </POSITION>
1.767 +[[from sml: </CALCITERATOR>
1.768 +[[from sml: @@@@@end@@@@@*)
1.769 +getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
1.770 +(*[[from sml: > @@@@@begin@@@@@ STILL CORRECT
1.771 +[[from sml: 1
1.772 +[[from sml: <GETELEMENTSFROMTO>
1.773 +[[from sml: <CALCID> 1 </CALCID>
1.774 +[[from sml: <FORMHEADS>
1.775 +[[from sml: <CALCFORMULA>
1.776 +[[from sml: <POSITION>
1.777 +[[from sml: <INTLIST>
1.778 +[[from sml: </INTLIST>
1.779 +[[from sml: <POS> Pbl </POS>
1.780 +[[from sml: </POSITION>
1.781 +[[from sml: <FORMULA>
1.782 +[[from sml: <MATHML>
1.783 +[[from sml: <ISA> ________________________________________________ </ISA>
1.784 +[[from sml: </MATHML>
1.785 +[[from sml:
1.786 +[[from sml: </FORMULA>
1.787 +[[from sml: </CALCFORMULA>
1.788 +[[from sml: </FORMHEADS>
1.789 +[[from sml: </GETELEMENTSFROMTO>
1.790 +[[from sml: @@@@@end@@@@@*)
1.791 +refFormula 1 ([],Pbl);
1.792 +(*[[from sml: > @@@@@begin@@@@@ STILL CORRECT
1.793 +[[from sml: 1
1.794 +[[from sml: <REFFORMULA>
1.795 +[[from sml: <CALCID> 1 </CALCID>
1.796 +[[from sml: <CALCHEAD status = "incorrect">
1.797 +[[from sml: <POSITION>
1.798 +[[from sml: <INTLIST>
1.799 +[[from sml: </INTLIST>
1.800 +[[from sml: <POS> Pbl </POS>
1.801 +[[from sml: </POSITION>
1.802 +[[from sml: <HEAD>
1.803 +[[from sml: <MATHML>
1.804 +[[from sml: <ISA> Problem (e_domID, [e_pblID]) </ISA>
1.805 +[[from sml: </MATHML>
1.806 +[[from sml: </HEAD>
1.807 +[[from sml: <MODEL>
1.808 +[[from sml: <GIVEN> </GIVEN>
1.809 +[[from sml: <WHERE> </WHERE>
1.810 +[[from sml: <FIND> </FIND>
1.811 +[[from sml: <RELATE> </RELATE>
1.812 +[[from sml: </MODEL>
1.813 +[[from sml: <BELONGSTO> Pbl </BELONGSTO>
1.814 +[[from sml: <SPECIFICATION>
1.815 +[[from sml: <THEORYID> e_domID </THEORYID>
1.816 +[[from sml: <PROBLEMID>
1.817 +[[from sml: <STRINGLIST>
1.818 +[[from sml: <STRING> e_pblID </STRING>
1.819 +[[from sml: </STRINGLIST>
1.820 +[[from sml: </PROBLEMID>
1.821 +[[from sml: <METHODID>
1.822 +[[from sml: <STRINGLIST>
1.823 +[[from sml: <STRING> e_metID </STRING>
1.824 +[[from sml: </STRINGLIST>
1.825 +[[from sml: </METHODID>
1.826 +[[from sml: </SPECIFICATION>
1.827 +[[from sml: </CALCHEAD>
1.828 +[[from sml: </REFFORMULA>
1.829 +[[from sml: @@@@@end@@@@@*)
1.830 +moveActiveFormula 1 ([],Pbl);
1.831 +(*[[from sml: > @@@@@begin@@@@@
1.832 +[[from sml: 1
1.833 +[[from sml: <CALCITERATOR>
1.834 +[[from sml: <CALCID> 1 </CALCID>
1.835 +[[from sml: <POSITION>
1.836 +[[from sml: <INTLIST>
1.837 +[[from sml: </INTLIST>
1.838 +[[from sml: <POS> Pbl </POS>
1.839 +[[from sml: </POSITION>
1.840 +[[from sml: </CALCITERATOR>
1.841 +[[from sml: @@@@@end@@@@@*)
1.842 +replaceFormula 1 "Simplify (1+2)";
1.843 +(*[[from sml: > @@@@@begin@@@@@
1.844 +[[from sml: 1
1.845 +[[from sml: <REPLACEFORMULA>
1.846 +[[from sml: <CALCID> 1 </CALCID>
1.847 +[[from sml: <CALCCHANGED>
1.848 +[[from sml: <UNCHANGED>
1.849 +[[from sml: <INTLIST>
1.850 +[[from sml: </INTLIST>
1.851 +[[from sml: <POS> Pbl </POS>
1.852 +[[from sml: </UNCHANGED>
1.853 +[[from sml: <DELETED>
1.854 +[[from sml: <INTLIST>
1.855 +[[from sml: </INTLIST>
1.856 +[[from sml: <POS> Pbl </POS>
1.857 +[[from sml: </DELETED>
1.858 +[[from sml: <GENERATED>
1.859 +[[from sml: <INTLIST>
1.860 +[[from sml: </INTLIST>
1.861 +[[from sml: <POS> Met </POS> DIFFERENCE: Pbl
1.862 +[[from sml: </GENERATED>
1.863 +[[from sml: </CALCCHANGED>
1.864 +[[from sml: </REPLACEFORMULA>
1.865 +[[from sml: @@@@@end@@@@@*)
1.866 +getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(* DIFFERENCE: Pbl*);
1.867 +(*@@@@@begin@@@@@
1.868 + 1
1.869 +<GETELEMENTSFROMTO>
1.870 + <CALCID> 1 </CALCID>
1.871 + <FORMHEADS>
1.872 + <CALCFORMULA>
1.873 + <POSITION>
1.874 + <INTLIST>
1.875 + </INTLIST>
1.876 + <POS> Pbl </POS>
1.877 + </POSITION>
1.878 + <FORMULA>
1.879 + <MATHML>
1.880 + <ISA> Simplify (1 + 2) </ISA> WORKS !!!!!
1.881 + </MATHML>
1.882 + </FORMULA>
1.883 + </CALCFORMULA>
1.884 + </FORMHEADS>
1.885 +</GETELEMENTSFROMTO>
1.886 +@@@@@end@@@@@*)
1.887 +getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
1.888 +(*[[from sml: > @@@@@begin@@@@@
1.889 +[[from sml: 1
1.890 +[[from sml: <SYSERROR>
1.891 +[[from sml: <CALCID> 1 </CALCID>
1.892 +[[from sml: <ERROR> error in getFormulaeFromTo </ERROR>
1.893 +[[from sml: </SYSERROR>
1.894 +[[from sml: @@@@@end@@@@@*)
1.895 +(*step into getFormulaeFromTo --- bug corrected...*)
1.896 +
1.897 +"--------- build fun check_err_patt ------------------------------";
1.898 +"--------- build fun check_err_patt ------------------------------";
1.899 +"--------- build fun check_err_patt ------------------------------";
1.900 +val subst = [(str2term "bdv", str2term "x")]: subst;
1.901 +val rls = norm_Rational
1.902 +val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
1.903 +val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
1.904 +val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "1 / 2");
1.905 +
1.906 +val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
1.907 + rew_sub thy 1 [] e_rew_ord e_rls false [] (HOLogic.Trueprop $ pat) res;
1.908 +if rewritten then NONE else SOME "e_errpatID";
1.909 +
1.910 +val norm_res = case rewrite_set_ (Isac()) false rls res' of
1.911 + NONE => res'
1.912 +| SOME (norm_res, _) => norm_res
1.913 +
1.914 +val norm_inf = case rewrite_set_ (Isac()) false rls inf of
1.915 + NONE => inf
1.916 +| SOME (norm_inf, _) => norm_inf;
1.917 +
1.918 +res' = inf;
1.919 +norm_res = norm_inf;
1.920 +
1.921 +val pat = parse_patt @{theory} "(?a + ?b)/?a = ?b";
1.922 +val (res, inf) = (str2term "(2 + 3)/2", str2term "3");
1.923 +if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
1.924 +then () else error "error patt example1 changed";
1.925 +
1.926 +val pat = parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
1.927 +val (res, inf) = (str2term "(2 + 3)/(2 + 4)", str2term "3 / 4");
1.928 +if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
1.929 +then () else error "error patt example2 changed";
1.930 +
1.931 +val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
1.932 +val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
1.933 +if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
1.934 +then () else error "error patt example3 changed";
1.935 +
1.936 +val inf = str2term "1 / 2";
1.937 +if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
1.938 +then () else error "error patt example3 changed";
1.939 +
1.940 +"--------- build fun check_err_patt ?bdv -------------------------";
1.941 +"--------- build fun check_err_patt ?bdv -------------------------";
1.942 +"--------- build fun check_err_patt ?bdv -------------------------";
1.943 +val subst = [(str2term "bdv", str2term "x")]: subst;
1.944 +val t = str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))";
1.945 +val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
1.946 +if term2str t = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3" then ()
1.947 +else error "build fun check_err_patt ?bdv changed 1";
1.948 +
1.949 +val rls = norm_diff
1.950 +val pat = parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)";
1.951 +val (res, inf) = (str2term "2 * x + d_d x (sin (x ^^^ 4))", str2term "2 * x + cos (4 * x ^^^ 3)");
1.952 +
1.953 +val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
1.954 + rew_sub thy 1 subst e_rew_ord e_rls false [] (HOLogic.Trueprop $ pat) res;
1.955 +if term2str res' = "2 * x + cos (d_d x (x ^^^ 4))" andalso rewritten then ()
1.956 +else error "build fun check_err_patt ?bdv changed 2";
1.957 +
1.958 +val norm_res = case rewrite_set_inst_ (Isac()) false subst rls res' of
1.959 + NONE => res'
1.960 +| SOME (norm_res, _) => norm_res;
1.961 +if term2str norm_res = "2 * x + cos (4 * x ^^^ 3)" then ()
1.962 +else error "build fun check_err_patt ?bdv changed 3";
1.963 +
1.964 +val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
1.965 + NONE => inf
1.966 +| SOME (norm_inf, _) => norm_inf;
1.967 +if term2str norm_inf = "2 * x + cos (4 * x ^^^ 3)" then ()
1.968 +else error "build fun check_err_patt ?bdv changed 4";
1.969 +
1.970 +res' = inf;
1.971 +if norm_res = norm_inf then ()
1.972 +else error "build fun check_err_patt ?bdv changed 5";
1.973 +
1.974 +if check_err_patt (res, inf) (subst: subst) ("errpatID": errpatID, pat) rls = SOME "errpatID"
1.975 +then () else error "error patt example1 changed";
1.976 +
1.977 +"--------- build fun check_error_patterns ------------------------";
1.978 +"--------- build fun check_error_patterns ------------------------";
1.979 +"--------- build fun check_error_patterns ------------------------";
1.980 +val (res, inf) =
1.981 + (str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))",
1.982 + str2term "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)");
1.983 +val {errpats, nrls = rls, scr = Prog prog, ...} = get_met ["diff", "differentiate_on_R"]
1.984 +
1.985 +val env = [(str2term "v_v", str2term "x")];
1.986 +val errpats =
1.987 + [e_errpat, (*generalised for testing*)
1.988 + ("chain-rule-diff-both",
1.989 + [parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
1.990 + parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
1.991 + parse_patt @{theory} "d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)",
1.992 + parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
1.993 + parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
1.994 + [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain},
1.995 + @{thm diff_ln_chain}, @{thm diff_exp_chain}])]: errpat list;
1.996 +case check_error_patterns (res, inf) (prog, env) (errpats, rls) of SOME _ => ()
1.997 +| NONE => error "check_error_patterns broken";
1.998 +DEconstrCalcTree 1;
1.999 +
1.1000 +"--------- embed fun check_error_patterns ------------------------";
1.1001 +"--------- embed fun check_error_patterns ------------------------";
1.1002 +"--------- embed fun check_error_patterns ------------------------";
1.1003 +reset_states ();
1.1004 +CalcTree
1.1005 +[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
1.1006 + ("Isac_Knowledge", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
1.1007 +Iterator 1;
1.1008 +moveActiveRoot 1;
1.1009 +autoCalculate 1 CompleteCalcHead;
1.1010 +autoCalculate 1 (Steps 1);
1.1011 +autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
1.1012 +(*autoCalculate 1 (Steps 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
1.1013 +
1.1014 +"~~~~~ fun appendFormula , args:"; val (cI, (ifo:cterm')) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
1.1015 +"~~~~~ fun appendFormula' , args:"; val (cI, (ifo: Rule.cterm')) = (cI, ifo);
1.1016 + val cs = get_calc cI
1.1017 + val pos = get_pos cI 1;
1.1018 +(*+*)if pos = ([1], Res) then () else error "inform with (positive) check_error_patterns broken 1";
1.1019 + val ("ok", cs' as (_, _, ptp)) = (*case*) Step.do_next pos cs (*of*);
1.1020 + (*case*) Step_Solve.by_term ptp (encode ifo) (*of*); (*ERROR WAS: "no derivation found"*)
1.1021 +"~~~~~ fun Step_Solve.by_term , args:"; val (((*next_*)cs as (_, _, (pt, pos as (p, _))): Chead.calcstate'), istr)
1.1022 + = (cs', (encode ifo));
1.1023 + val ctxt = get_ctxt pt pos (*see TODO.thy*)
1.1024 + val SOME f_in = (*case*) TermC.parse (Celem.assoc_thy "Isac_Knowledge") istr (*of*);
1.1025 + val f_in = Thm.term_of f_in
1.1026 + val pos_pred = lev_back' pos
1.1027 + val f_pred = Ctree.get_curr_formula (pt, pos_pred);
1.1028 + (*if*) f_pred = f_in; (*else*)
1.1029 + val NONE = (*case*) In_Chead.cas_input f_in (*of*);
1.1030 + (*old* )val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
1.1031 + (*old*)val {scr = prog, ...} = Specify.get_met metID
1.1032 + (*old*)val istate = get_istate_LI pt pos
1.1033 + (*old*)val ctxt = get_ctxt pt pos
1.1034 + ( *old*)
1.1035 + val LI.Not_Derivable =
1.1036 + (*case*) LI.locate_input_term (pt, pos) f_in (*of*);
1.1037 + val pp = Ctree.par_pblobj pt p
1.1038 + val (errpats, nrls, prog) = case Specify.get_met (Ctree.get_obj Ctree.g_metID pt pp) of
1.1039 + {errpats, nrls, scr = Rule.Prog prog, ...} => (errpats, nrls, prog)
1.1040 + | _ => error "inform: uncovered case of get_met"
1.1041 +;
1.1042 +(*+*)if errpats2str 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 ^^^ ?n) = ?n * ?u ^^^ (?n - 1)\",\"d_d ?bdv (LogExp.ln ?u) = 1 / ?u\",\"d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u\"],\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 ^^^ ?n) = ?n * ?u ^^^ (?n - 1) * d_d ?bdv ?u\",\"d_d ?bdv (LogExp.ln ?u) = d_d ?bdv ?u / ?u\",\"d_d ?bdv (E_ ^^^ ?u) = E_ ^^^ ?u * d_d ?x ?u\"]]"
1.1043 +(*+*)then () else error "inform with (positive) check_error_patterns broken 3";
1.1044 +
1.1045 + val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
1.1046 +;
1.1047 +(*+*)if term2str f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
1.1048 +(*+*) term2str f_in = "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)"
1.1049 +(*+*)then () else error "inform with (positive) check_error_patterns broken 2";
1.1050 +
1.1051 + val SOME "chain-rule-diff-both" = (*case*) Error_Pattern.check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) (*of*);
1.1052 +
1.1053 +"--- final check:";
1.1054 +(*+*)val (_, _, ptp') = cs';
1.1055 +case Step_Solve.by_term ptp' (encode ifo) of
1.1056 + ("error pattern #chain-rule-diff-both#", calcstate') => ()
1.1057 +| _ => error "inform with (positive) check_error_patterns broken"
1.1058 +
1.1059 +
1.1060 +"--------- embed fun find_fillpatterns ---------------------------";
1.1061 +"--------- embed fun find_fillpatterns ---------------------------";
1.1062 +"--------- embed fun find_fillpatterns ---------------------------";
1.1063 +reset_states ();
1.1064 +CalcTree
1.1065 +[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
1.1066 + ("Isac_Knowledge", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
1.1067 +Iterator 1;
1.1068 +moveActiveRoot 1;
1.1069 +autoCalculate 1 CompleteCalcHead;
1.1070 +autoCalculate 1 (Steps 1);
1.1071 +autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
1.1072 +appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)" (*|> Future.join*);
1.1073 + (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
1.1074 + (*or
1.1075 + <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
1.1076 +
1.1077 +"~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
1.1078 + val ((pt, _), _) = get_calc cI
1.1079 + val pos = get_pos cI 1;
1.1080 +"~~~~~ fun find_fillpatterns , args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
1.1081 + val f_curr = Ctree.get_curr_formula (pt, pos);
1.1082 + val pp = Ctree.par_pblobj pt p
1.1083 + val (errpats, prog) = case Specify.get_met (Ctree.get_obj Ctree.g_metID pt pp) of
1.1084 + {errpats, scr = Rule.Prog prog, ...} => (errpats, prog)
1.1085 + | _ => error "find_fillpatterns: uncovered case of get_met"
1.1086 + val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
1.1087 + val subst = Rtools.get_bdv_subst prog env
1.1088 + val errpatthms = errpats
1.1089 + |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
1.1090 + |> map (#3: errpat -> thm list)
1.1091 + |> flat;
1.1092 +
1.1093 +case map (get_fillpats subst f_curr errpatID) errpatthms |> flat of
1.1094 + ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if term2str tm =
1.1095 + "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
1.1096 + then () else error "find_fillpatterns changed 1a"
1.1097 +| _ => error "find_fillpatterns changed 1b"
1.1098 +
1.1099 +"~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
1.1100 + (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
1.1101 + val thmDeriv = Thm.get_name_hint thm
1.1102 + val (part, thyID) = thy_containing_thm thmDeriv
1.1103 + val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
1.1104 + val Hthm {fillpats, ...} = get_the theID
1.1105 + val some = map (get_fillform subst (thm, form) errpatID) fillpats;
1.1106 +
1.1107 +case some |> filter is_some |> map the of
1.1108 + ("fill-d_d-arg", tm, thm, subsopt) :: _ => if term2str tm =
1.1109 + "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
1.1110 + then () else error "find_fillpatterns changed 2a"
1.1111 +| _ => error "find_fillpatterns changed 2b"
1.1112 +
1.1113 +"~~~~~ fun get_fillform, args:";
1.1114 + val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
1.1115 + (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
1.1116 +val (form', _, _, rewritten) =
1.1117 + rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (HOLogic.Trueprop $ pat) form;
1.1118 +
1.1119 +if term2str form' = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
1.1120 +else error "find_fillpatterns changed 3";
1.1121 +
1.1122 +"~~~~~ to findFillpatterns return val:"; val (fillpats) =
1.1123 + (map (get_fillpats (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
1.1124 +
1.1125 +"vvv--- dropped this code WN120730";
1.1126 +val msg = "fill patterns " ^
1.1127 + ((map ((apsnd term2str) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
1.1128 +msg =
1.1129 + "fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1.1130 + " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" ^
1.1131 + "#fill-both-args#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1.1132 + " =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3" ^
1.1133 + "#fill-d_d#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1.1134 + " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1 x (x ^^^ 4)" ^
1.1135 + "#fill-inner-deriv#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
1.1136 + " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1" ^
1.1137 + "#fill-all#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) = d_d x (x ^^^ 2) + ?_dummy_1#";
1.1138 +"^^^--- dropped this code WN120730";
1.1139 +
1.1140 +if (map #1 fillpats) =
1.1141 + ["fill-d_d-arg", "fill-both-args", "fill-d_d", "fill-inner-deriv", "fill-all"]
1.1142 +then () else error "find_fillpatterns changed 4b";
1.1143 +DEconstrCalcTree 1;
1.1144 +
1.1145 +"--------- build fun is_exactly_equal, inputFillFormula ----------";
1.1146 +"--------- build fun is_exactly_equal, inputFillFormula ----------";
1.1147 +"--------- build fun is_exactly_equal, inputFillFormula ----------";
1.1148 +reset_states ();
1.1149 +CalcTree
1.1150 +[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"],
1.1151 + ("Isac_Knowledge", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
1.1152 +Iterator 1;
1.1153 +moveActiveRoot 1;
1.1154 +autoCalculate 1 CompleteCalcHead;
1.1155 +autoCalculate 1 (Steps 1);
1.1156 +autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
1.1157 +appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)" (*|> Future.join*); (*<<<<<<<=========================*)
1.1158 +(* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
1.1159 + would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
1.1160 + results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
1.1161 + instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
1.1162 + val ((pt,pos), _) = get_calc 1;
1.1163 + val p = get_pos 1 1;
1.1164 + val (Form f, _, asms) = pt_extract (pt, p);
1.1165 +
1.1166 + if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" then
1.1167 + case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"],
1.1168 + ("diff_sum", thm)) =>
1.1169 + if (term2str o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
1.1170 + else error "embed fun get_fillform changed 11"
1.1171 + | _ => error "embed fun get_fillform changed 12"
1.1172 + else error "embed fun get_fillform changed 13";
1.1173 +
1.1174 +findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
1.1175 +(*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
1.1176 + d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
1.1177 + val ((pt,pos),_) = get_calc 1;
1.1178 + val p = get_pos 1 1;
1.1179 +
1.1180 + val (Form f, _, asms) = pt_extract (pt, p);
1.1181 + if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" then
1.1182 + case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"],
1.1183 + ("diff_sum", thm)) =>
1.1184 + if (term2str o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
1.1185 + else error "embed fun get_fillform changed 21"
1.1186 + | _ => error "embed fun get_fillform changed 22"
1.1187 + else error "embed fun get_fillform changed 23";
1.1188 +
1.1189 +requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
1.1190 + (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
1.1191 + val ((pt,pos),_) = get_calc 1;
1.1192 + val p = get_pos 1 1;
1.1193 + val (Form f, _, asms) = pt_extract (pt, p);
1.1194 + if p = ([1], Res) andalso existpt [2] pt
1.1195 + andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"
1.1196 + then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"],
1.1197 + ("diff_sum", thm)) =>
1.1198 + if (term2str o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
1.1199 + else error "embed fun get_fillform changed 31"
1.1200 + | _ => error "embed fun get_fillform changed 32"
1.1201 + else error "embed fun get_fillform changed 33";
1.1202 +
1.1203 +(* input a formula which exactly fills the gaps in a "fillformula"
1.1204 + presented to the learner immediately before by "requestFillformula (errpatID, fillpatID)":
1.1205 + errpatID: lhs of the respective thm = lhs of fillformula with fillpatID.
1.1206 + the respective thm is in the ctree ................
1.1207 +*)
1.1208 +"~~~~~ fun inputFillFormula, args:"; val (cI, ifo) =
1.1209 + (1, "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)");
1.1210 + val ((pt, _), _) = get_calc cI
1.1211 + val pos = get_pos cI 1;
1.1212 +
1.1213 +"~~~~~ fun is_exactly_equal, args:"; val ((pt, pos as (p, p_)), istr) = ((pt, pos), ifo);
1.1214 + val SOME ifo = parseNEW (assoc_thy "Isac_Knowledge" |> thy2ctxt) istr
1.1215 + val p' = lev_on p;
1.1216 + val tac = get_obj g_tac pt p';
1.1217 +val Rewrite_Inst ([bbb as "(''bdv'', x)"], ("diff_sin_chain", ttt)) = tac;
1.1218 +if (term2str o Thm.prop_of) ttt = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
1.1219 +else error "inputFillFormula changed 10";
1.1220 + val Appl rew = applicable_in pos pt tac;
1.1221 + val Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) = rew;
1.1222 +
1.1223 +"~~~~~ to inputFillFormula return val:"; val ("ok", tac) = ("ok", tac);
1.1224 + val ("ok", (_, c, ptp as (_,p'))) = Step.by_tactic tac (pt, pos);
1.1225 + upd_calc cI (ptp, []);
1.1226 + upd_ipos cI 1 p';
1.1227 + autocalculateOK2xml cI pos (if null c then p' else last_elem c) p';
1.1228 +
1.1229 +"~~~~~ final check:";
1.1230 +val ((pt, _),_) = get_calc 1;
1.1231 +val p = get_pos 1 1;
1.1232 +val (Form f, _, asms) = pt_extract (pt, p);
1.1233 + if p = ([2], Res) andalso term2str f = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)"
1.1234 + then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"],
1.1235 + ("diff_sin_chain", thm)) =>
1.1236 + if (term2str o Thm.prop_of) thm = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
1.1237 + else error "inputFillFormula changed 111"
1.1238 + | _ => error "inputFillFormula changed 112"
1.1239 + else error "inputFillFormula changed 113";
1.1240 +
1.1241 +"--------- fun appl_adds -----------------------------------------";
1.1242 +"--------- fun appl_adds -----------------------------------------";
1.1243 +"--------- fun appl_adds -----------------------------------------";
1.1244 +(* val (dI, oris, ppc, pbt, selct::ss) =
1.1245 + (dI, pors, probl, ppc, map itms2fstr probl);
1.1246 + ...vvv
1.1247 + *)
1.1248 +(* val (dI, oris, ppc, pbt, (selct::ss))=
1.1249 + (#1 (some_spec ospec spec), oris, []:itm list,
1.1250 + ((#ppc o get_pbt) (#2 (some_spec ospec spec))),(imodel2fstr imodel));
1.1251 + val iii = appl_adds dI oris ppc pbt (selct::ss);
1.1252 + tracing(itms2str_ thy iii);
1.1253 +
1.1254 + val itm = appl_add' dI oris ppc pbt selct;
1.1255 + val ppc = insert_ppc' itm ppc;
1.1256 +
1.1257 + val _::selct::ss = (selct::ss);
1.1258 + val itm = appl_add' dI oris ppc pbt selct;
1.1259 + val ppc = insert_ppc' itm ppc;
1.1260 +
1.1261 + val _::selct::ss = (selct::ss);
1.1262 + val itm = appl_add' dI oris ppc pbt selct;
1.1263 + val ppc = insert_ppc' itm ppc;
1.1264 + tracing(itms2str_ thy ppc);
1.1265 +
1.1266 + val _::selct::ss = (selct::ss);
1.1267 + val itm = appl_add' dI oris ppc pbt selct;
1.1268 + val ppc = insert_ppc' itm ppc;
1.1269 + *)
1.1270 +"--------- fun concat_deriv --------------------------------------";
1.1271 +"--------- fun concat_deriv --------------------------------------";
1.1272 +"--------- fun concat_deriv --------------------------------------";
1.1273 +(*
1.1274 + val ({rew_ord, erls, rules,...}, fo, ifo) =
1.1275 + (rep_rls Test_simplify, str2term "x+1+ -1*2=0", str2term "-2*1+(x+1)=0");
1.1276 + (tracing o trtas2str) fod';
1.1277 +> ["
1.1278 +(x + 1 + -1 * 2 = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (x + 1) = 0, []))","
1.1279 +(-1 * 2 + (x + 1) = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (1 + x) = 0, []))","
1.1280 +(-1 * 2 + (1 + x) = 0, Thm ("radd_left_commute","?x + (?y + ?z) = ?y + (?x + ?z)"), (1 + (-1 * 2 + x) = 0, []))","
1.1281 +(1 + (-1 * 2 + x) = 0, Thm ("#mult_Float ((~1,0), (0,0)) __ ((2,0), (0,0))","-1 * 2 = -2"), (1 + (-2 + x) = 0, []))"]
1.1282 +val it = () : unit
1.1283 + (tracing o trtas2str) (map rev_deriv' rifod');
1.1284 +> ["
1.1285 +(1 + (-2 + x) = 0, Thm ("sym_#mult_Float ((~2,0), (0,0)) __ ((1,0), (0,0))","-2 = -2 * 1"), (1 + (-2 * 1 + x) = 0, []))","
1.1286 +(1 + (-2 * 1 + x) = 0, Thm ("sym_radd_left_commute","?y + (?x + ?z) = ?x + (?y + ?z)"), (-2 * 1 + (1 + x) = 0, []))","
1.1287 +(-2 * 1 + (1 + x) = 0, Thm ("sym_radd_commute","?n + ?m = ?m + ?n"), (-2 * 1 + (x + 1) = 0, []))"]
1.1288 +val it = () : unit
1.1289 +*)
1.1290 +"--------- handle an input formula -------------------------------";
1.1291 +"--------- handle an input formula -------------------------------";
1.1292 +"--------- handle an input formula -------------------------------";
1.1293 +(*
1.1294 +Untersuchung zur Formeleingabe (appendFormula, replaceFormla) zu einer Anregung von Alan Krempler:
1.1295 +Welche RICHTIGEN Formeln koennen NICHT abgeleitet werden,
1.1296 +wenn Abteilungen nur auf gleichem Level gesucht werden ?
1.1297 +WN.040216
1.1298 +
1.1299 +Beispiele zum Equationsolver von Richard Lang aus /src/sml/kbtest/rlang.sml
1.1300 +
1.1301 +------------------------------------------------------------------------------
1.1302 +"Schalk I s.87 Bsp 52a ((5*x)/(x - 2) - x/(x+2)=4)";
1.1303 +------------------------------------------------------------------------------
1.1304 +1. "5 * x / (x - 2) - x / (x + 2) = 4"
1.1305 +...
1.1306 +4. "12 * x + 4 * x ^^^ 2 = 4 * (-4 + x ^^^ 2)",Subproblem["normalise", "poly"..
1.1307 +...
1.1308 +4.3. "16 + 12 * x = 0", Subproblem["degree_1", "polynomial", "univariate"..
1.1309 +...
1.1310 +4.3.3. "[x = -4 / 3]")), Check_elementwise "Assumptions"
1.1311 +...
1.1312 +"[x = -4 / 3]"
1.1313 +------------------------------------------------------------------------------
1.1314 +(1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
1.1315 +
1.1316 +(4.1)..(4.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
1.1317 +------------------------------------------------------------------------------
1.1318 +
1.1319 +
1.1320 +------------------------------------------------------------------------------
1.1321 +"Schalk I s.87 Bsp 55b (x/(x^^^2 - 6*x+9) - 1/(x^^^2 - 3*x) =1/x)";
1.1322 +------------------------------------------------------------------------------
1.1323 +1. "x / (x ^^^ 2 - 6 * x + 9) - 1 / (x ^^^ 2 - 3 * x) = 1 / x"
1.1324 +...
1.1325 +4. "(3 + (-1 * x + x ^^^ 2)) * x = 1 * (9 * x + (x ^^^ 3 + -6 * x ^^^ 2))"
1.1326 + Subproblem["normalise", "polynomial", "univariate"..
1.1327 +...
1.1328 +4.4. "-6 * x + 5 * x ^^^ 2 = 0", Subproblem["bdv_only", "degree_2", "poly"..
1.1329 +...
1.1330 +4.4.4. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
1.1331 +4.4.5. "[x = 0, x = 6 / 5]"
1.1332 +...
1.1333 +5. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
1.1334 + "[x = 6 / 5]"
1.1335 +------------------------------------------------------------------------------
1.1336 +(1)..(4): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite schiebt [Ableitung waere in 4.4.x]
1.1337 +
1.1338 +(4.1)..(4.4.5): keine 'richtige' Eingabe kann abgeleitet werden, die dem Ergebnis "[x = 6 / 5]" aequivalent ist [Ableitung waere in 5.]
1.1339 +------------------------------------------------------------------------------
1.1340 +
1.1341 +
1.1342 +------------------------------------------------------------------------------
1.1343 +"Schalk II s.56 Bsp 73b (sqrt(x+1)+sqrt(4*x+4)=sqrt(9*x+9))";
1.1344 +------------------------------------------------------------------------------
1.1345 +1. "sqrt (x + 1) + sqrt (4 * x + 4) = sqrt (9 * x + 9)"
1.1346 +...
1.1347 +6. "13 + 13 * x + -2 * sqrt ((4 + 4 * x) * (9 + 9 * x)) = 1 + x"
1.1348 + Subproblem["sq", "rootX", "univariate", "equation"]
1.1349 +...
1.1350 +6.6. "144 + 288 * x + 144 * x ^^^ 2 = 144 + x ^^^ 2 + 288 * x + 143 * x ^^^ 2"
1.1351 + Subproblem["normalise", "polynomial", "univariate", "equation"]
1.1352 +...
1.1353 +6.6.3 "0 = 0" Subproblem["degree_0", "polynomial", "univariate", "equation"]
1.1354 +... Or_to_List
1.1355 +6.6.3.2 "UniversalList"
1.1356 +------------------------------------------------------------------------------
1.1357 +(1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die eine der Wurzeln auf die andere Seite verschieb [Ableitung ware in 6.6.n]
1.1358 +
1.1359 +(6.1)..(6.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 6.6.n]
1.1360 +------------------------------------------------------------------------------
1.1361 +*)
1.1362 +(*sh. comments auf 498*)
1.1363 +"--------- fun dropwhile' ----------------------------------------";
1.1364 +"--------- fun dropwhile' ----------------------------------------";
1.1365 +"--------- fun dropwhile' ----------------------------------------";
1.1366 +(*
1.1367 + fun equal a b = a=b;
1.1368 + val foder = [0,1,2,3,4,5]; val ifoder = [11,12,3,4,5];
1.1369 + val r_foder = rev foder; val r_ifoder = rev ifoder;
1.1370 + dropwhile' equal r_foder r_ifoder;
1.1371 +> vval it = ([0, 1, 2, 3], [3, 12, 11]) : int list * int list
1.1372 +
1.1373 + val foder = [3,4,5]; val ifoder = [11,12,3,4,5];
1.1374 + val r_foder = rev foder; val r_ifoder = rev ifoder;
1.1375 + dropwhile' equal r_foder r_ifoder;
1.1376 +> val it = ([3], [3, 12, 11]) : int list * int list
1.1377 +
1.1378 + val foder = [5]; val ifoder = [11,12,3,4,5];
1.1379 + val r_foder = rev foder; val r_ifoder = rev ifoder;
1.1380 + dropwhile' equal r_foder r_ifoder;
1.1381 +> val it = ([5], [5, 4, 3, 12, 11]) : int list * int list
1.1382 +
1.1383 + val foder = [10,11,12,13,14,15]; val ifoder = [11,12,3,4,5];
1.1384 + val r_foder = rev foder; val r_ifoder = rev ifoder;
1.1385 + dropwhile' equal r_foder r_ifoder;
1.1386 +> *** dropwhile': did not start with equal elements*)