test/Tools/isac/Interpret/inform.sml
author Walther Neuper <neuper@ist.tugraz.at>
Sat, 26 Jul 2014 14:10:05 +0200
changeset 55482 8417ebc575b6
parent 55480 1738bef7d5d3
child 59111 c730b643bc0e
permissions -rw-r--r--
added test which identified error in fun getTactic <-- string_of_thmI
akargl@42176
     1
(* Title: tests on inform.sml
akargl@42176
     2
   Author: Walther Neuper 060225,
neuper@37906
     3
   (c) due to copyright terms 
neuper@37906
     4
neuper@37906
     5
use"../smltest/ME/inform.sml";
neuper@37906
     6
use"inform.sml";
neuper@37906
     7
*)
neuper@37906
     8
neuper@37906
     9
"-----------------------------------------------------------------";
neuper@37906
    10
"table of contents -----------------------------------------------";
neuper@37906
    11
"-----------------------------------------------------------------";
neuper@37906
    12
"appendForm with miniscript with mini-subpbl:";
neuper@37906
    13
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@37906
    14
"--------- appendFormula: on Frm + equ_nrls ----------------------";
neuper@37906
    15
"--------- appendFormula: on Res + NO deriv ----------------------";
neuper@37906
    16
"--------- appendFormula: on Res + late deriv --------------------";
neuper@37906
    17
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
neuper@37906
    18
"replaceForm with miniscript with mini-subpbl:";
neuper@37906
    19
"--------- replaceFormula: on Res + = ----------------------------";
neuper@37906
    20
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
neuper@37906
    21
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
neuper@37906
    22
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
    23
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
    24
(* 040307 copied from informtest.sml ... old versions
neuper@37906
    25
"--------- maximum-example, UC: Modeling / modifyCalcHead --------";*)
neuper@37906
    26
"--------- syntax error ------------------------------------------";
neuper@37906
    27
"CAS-command:";
neuper@37906
    28
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
    29
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
    30
"--------- inform [rational,simplification] ----------------------";
neuper@37906
    31
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
    32
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
    33
"--------- init_form, start with <NEW> (CAS input) ---------------";
neuper@42423
    34
"--------- build fun check_err_patt ------------------------------";
neuper@42426
    35
"--------- build fun check_err_patt ?bdv -------------------------";
neuper@42428
    36
"--------- build fun check_error_patterns ------------------------";
neuper@42428
    37
"--------- embed fun check_error_patterns ------------------------";
neuper@48895
    38
"--------- build fun get_fillpats --------------------------------";
neuper@42430
    39
"--------- embed fun find_fillpatterns ---------------------------";
neuper@48895
    40
"--------- build fun is_exactly_equal, inputFillFormula ----------";
neuper@37906
    41
"-----------------------------------------------------------------";
neuper@37906
    42
"-----------------------------------------------------------------";
neuper@37906
    43
"-----------------------------------------------------------------";
neuper@37906
    44
neuper@37906
    45
neuper@37906
    46
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@37906
    47
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@37906
    48
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@48790
    49
 val Prog sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
neuper@37906
    50
 (writeln o term2str) sc;
neuper@48790
    51
 val Prog sc = (#scr o get_met) ["Test","solve_linear"];
neuper@37906
    52
 (writeln o term2str) sc;
neuper@37906
    53
s1210629013@55445
    54
 reset_states ();
neuper@41970
    55
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
    56
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
    57
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
    58
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
    59
 autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
    60
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
s1210629013@55446
    61
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
    62
s1210629013@55402
    63
 appendFormula 1 "-2 * 1 + (1 + x) = 0" |> Future.join; refFormula 1 (get_pos 1 1);
neuper@37906
    64
 val ((pt,_),_) = get_calc 1;
neuper@37906
    65
 val str = pr_ptree pr_short pt;
neuper@48895
    66
if str =
neuper@48895
    67
(".    ----- pblobj -----\n" ^
neuper@48895
    68
"1.   x + 1 = 2\n" ^
neuper@48895
    69
"2.   x + 1 + -1 * 2 = 0\n" ^
neuper@48895
    70
"2.1.   x + 1 + -1 * 2 = 0\n" ^
neuper@48895
    71
"2.2.   1 + x + -1 * 2 = 0\n" ^
neuper@48895
    72
"2.3.   1 + (x + -1 * 2) = 0\n" ^
neuper@48895
    73
"2.4.   1 + (x + -2) = 0\n" ^
neuper@48895
    74
"2.5.   1 + (x + -2 * 1) = 0\n" ^
neuper@48895
    75
"2.6.   1 + x + -2 * 1 = 0\n" ) then ()
neuper@48895
    76
else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
neuper@37906
    77
neuper@37906
    78
 moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
neuper@37906
    79
 moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
neuper@37906
    80
neuper@37906
    81
 (*the seven steps of detailed derivation*)
neuper@37906
    82
 moveDown 1 ([1  ],Res); refFormula 1 ([2,1],Frm); 
neuper@37906
    83
 moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
neuper@37906
    84
 moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
neuper@37906
    85
 moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res); 
neuper@37906
    86
 moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
neuper@37906
    87
 moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
neuper@37906
    88
 moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
neuper@37906
    89
 val ((pt,_),_) = get_calc 1;
neuper@37906
    90
 if "-2 * 1 + (1 + x) = 0" = term2str (fst (get_obj g_result pt [2,6])) then()
neuper@38031
    91
 else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
neuper@37906
    92
neuper@37906
    93
 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
neuper@48895
    94
(* <ERROR> error in kernel </ERROR> ALREADY IN 2009-2*)
neuper@48895
    95
(*========== inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 =============
neuper@37906
    96
 val (_,(tac,_,_)::_) = get_calc 1;
neuper@37906
    97
 if tac = Rewrite_Set "Test_simplify" then ()
neuper@38031
    98
 else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
neuper@48895
    99
============ inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 ============*)
akargl@42209
   100
s1210629013@55446
   101
 autoCalculate' 1 CompleteCalc;
neuper@37906
   102
 val ((pt,_),_) = get_calc 1;
neuper@37906
   103
 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@38031
   104
 else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
s1210629013@55446
   105
 (* autoCalculate' 1 CompleteCalc;
neuper@37906
   106
   val ((pt,p),_) = get_calc 1;
neuper@37906
   107
   (writeln o istates2str) (get_obj g_loc pt [ ]);  
neuper@37906
   108
   (writeln o istates2str) (get_obj g_loc pt [1]);  
neuper@37906
   109
   (writeln o istates2str) (get_obj g_loc pt [2]);  
neuper@37906
   110
   (writeln o istates2str) (get_obj g_loc pt [3]);  
neuper@37906
   111
   (writeln o istates2str) (get_obj g_loc pt [3,1]);  
neuper@37906
   112
   (writeln o istates2str) (get_obj g_loc pt [3,2]);  
neuper@37906
   113
   (writeln o istates2str) (get_obj g_loc pt [4]);  
neuper@37906
   114
neuper@37906
   115
   *)
neuper@37906
   116
"----------------------------------------------------------";
akargl@42176
   117
akargl@42176
   118
 val fod = make_deriv (@{theory "Isac"}) Atools_erls 
neuper@37906
   119
		       ((#rules o rep_rls) Test_simplify)
akargl@42176
   120
		       (sqrt_right false (@{theory "Pure"})) NONE 
neuper@37906
   121
		       (str2term "x + 1 + -1 * 2 = 0");
neuper@37906
   122
 (writeln o trtas2str) fod;
neuper@37906
   123
akargl@42176
   124
 val ifod = make_deriv (@{theory "Isac"}) Atools_erls 
neuper@37906
   125
		       ((#rules o rep_rls) Test_simplify)
akargl@42176
   126
		       (sqrt_right false (@{theory "Pure"})) NONE 
neuper@37906
   127
		       (str2term "-2 * 1 + (1 + x) = 0");
neuper@37906
   128
 (writeln o trtas2str) ifod;
akargl@42176
   129
 fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
neuper@37906
   130
 val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
neuper@37906
   131
 val der = fod' @ (map rev_deriv' rifod');
neuper@37906
   132
 (writeln o trtas2str) der;
neuper@37906
   133
 "----------------------------------------------------------";
neuper@37906
   134
neuper@37906
   135
neuper@37906
   136
"--------- appendFormula: on Frm + equ_nrls ----------------------";
neuper@37906
   137
"--------- appendFormula: on Frm + equ_nrls ----------------------";
neuper@37906
   138
"--------- appendFormula: on Frm + equ_nrls ----------------------";
s1210629013@55445
   139
 reset_states ();
neuper@41970
   140
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   141
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   142
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   143
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
   144
 autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
   145
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
s1210629013@55402
   146
 appendFormula 1 "2+ -1 + x = 2" |> Future.join; refFormula 1 (get_pos 1 1);
neuper@37906
   147
neuper@37906
   148
 moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
neuper@37906
   149
neuper@37906
   150
 moveDown 1 ([1  ],Frm); refFormula 1 ([1,1],Frm); 
neuper@37906
   151
 moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res); 
neuper@37906
   152
 moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res); 
neuper@37906
   153
 moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res); 
neuper@37906
   154
 moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res); 
neuper@37906
   155
 moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res); 
neuper@37906
   156
 moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res); 
neuper@37906
   157
 val ((pt,_),_) = get_calc 1;
neuper@37906
   158
 if "2 + -1 + x = 2" = term2str (fst (get_obj g_result pt [1,6])) then()
neuper@38031
   159
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
neuper@37906
   160
neuper@37906
   161
 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
neuper@37906
   162
 val (_,(tac,_,_)::_) = get_calc 1;
neuper@37906
   163
 if tac = Rewrite_Set "norm_equation" then ()
neuper@38031
   164
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
s1210629013@55446
   165
 autoCalculate' 1 CompleteCalc;
neuper@37906
   166
 val ((pt,_),_) = get_calc 1;
neuper@37906
   167
 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@38031
   168
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
neuper@37906
   169
neuper@37906
   170
neuper@37906
   171
"--------- appendFormula: on Res + NO deriv ----------------------";
neuper@37906
   172
"--------- appendFormula: on Res + NO deriv ----------------------";
neuper@37906
   173
"--------- appendFormula: on Res + NO deriv ----------------------";
s1210629013@55445
   174
 reset_states ();
neuper@41970
   175
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   176
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   177
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   178
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
   179
 autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
   180
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
s1210629013@55446
   181
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   182
s1210629013@55402
   183
 appendFormula 1 "x = 2" |> Future.join;
neuper@37906
   184
 val ((pt,p),_) = get_calc 1;
neuper@37906
   185
 val str = pr_ptree pr_short pt;
neuper@37906
   186
 writeln str;
neuper@37906
   187
 if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" andalso p = ([1], Res)
neuper@37906
   188
 then ()
neuper@38031
   189
 else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
neuper@37906
   190
neuper@37906
   191
 fetchProposedTactic 1;
neuper@37906
   192
 val (_,(tac,_,_)::_) = get_calc 1;
neuper@37906
   193
 if tac = Rewrite_Set "Test_simplify" then ()
neuper@38031
   194
 else error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
s1210629013@55446
   195
 autoCalculate' 1 CompleteCalc;
neuper@37906
   196
 val ((pt,_),_) = get_calc 1;
neuper@37906
   197
 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@38031
   198
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
neuper@37906
   199
neuper@37906
   200
neuper@37906
   201
"--------- appendFormula: on Res + late deriv --------------------";
neuper@37906
   202
"--------- appendFormula: on Res + late deriv --------------------";
neuper@37906
   203
"--------- appendFormula: on Res + late deriv --------------------";
s1210629013@55445
   204
 reset_states ();
neuper@41970
   205
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   206
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   207
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   208
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
   209
 autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
   210
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
s1210629013@55446
   211
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   212
s1210629013@55402
   213
 appendFormula 1 "x = 1" |> Future.join;
neuper@37906
   214
 val ((pt,p),_) = get_calc 1;
neuper@37906
   215
 val str = pr_ptree pr_short pt;
neuper@37906
   216
 writeln str;
neuper@37906
   217
 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)
neuper@37906
   218
 then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
neuper@38031
   219
 else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
akargl@42176
   220
neuper@37906
   221
 fetchProposedTactic 1;
neuper@37906
   222
 val (_,(tac,_,_)::_) = get_calc 1;
neuper@55279
   223
 if tac = Check_Postcond ["LINEAR", "univariate", "equation", "test"] then ()
neuper@38031
   224
 else error "inform.sml: diff.behav.appendFormula: Res + late d 2";
s1210629013@55446
   225
 autoCalculate' 1 CompleteCalc;
neuper@37906
   226
 val ((pt,_),_) = get_calc 1;
neuper@37906
   227
 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@38031
   228
 else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
neuper@37906
   229
neuper@37906
   230
neuper@37906
   231
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
neuper@37906
   232
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
neuper@37906
   233
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
s1210629013@55445
   234
 reset_states ();
neuper@41970
   235
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   236
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   237
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   238
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
   239
 autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
   240
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
s1210629013@55446
   241
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
s1210629013@55402
   242
 appendFormula 1 "[x = 3 + -2*1]" |> Future.join;
neuper@37906
   243
 val ((pt,p),_) = get_calc 1;
neuper@37906
   244
 val str = pr_ptree pr_short pt;
neuper@37906
   245
 writeln str;
neuper@37906
   246
 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 ()
neuper@38031
   247
 else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
s1210629013@55446
   248
 autoCalculate' 1 CompleteCalc;
neuper@37906
   249
 val ((pt,p),_) = get_calc 1;
neuper@37906
   250
 if "[x = 3 + -2 * 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@37906
   251
 (*       ~~~~~~~~~~ simplify as last step in any script ?!*)
neuper@38031
   252
 else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
neuper@37906
   253
neuper@37906
   254
neuper@37906
   255
neuper@37906
   256
"--------- replaceFormula: on Res + = ----------------------------";
neuper@37906
   257
"--------- replaceFormula: on Res + = ----------------------------";
neuper@37906
   258
"--------- replaceFormula: on Res + = ----------------------------";
s1210629013@55445
   259
 reset_states ();
neuper@41970
   260
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   261
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   262
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   263
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
   264
 autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
   265
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
s1210629013@55446
   266
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
s1210629013@55446
   267
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
neuper@37906
   268
neuper@37906
   269
 replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
neuper@37906
   270
 val ((pt,_),_) = get_calc 1;
neuper@37906
   271
 val str = pr_ptree pr_short pt;
akargl@42176
   272
neuper@48895
   273
(* before AK110725 this was
neuper@48895
   274
".    ----- pblobj -----\n
neuper@48895
   275
1.   x + 1 = 2\n
neuper@48895
   276
2.   x + 1 + -1 * 2 = 0\n
neuper@48895
   277
2.1.   x + 1 + -1 * 2 = 0\n
neuper@48895
   278
2.2.   1 + x + -1 * 2 = 0\n
neuper@48895
   279
2.3.   1 + (x + -1 * 2) = 0\n
neuper@48895
   280
2.4.   1 + (x + -2) = 0\n
neuper@48895
   281
2.5.   1 + (x + -2 * 1) = 0\n
neuper@48895
   282
2.6.   1 + x + -2 * 1 = 0\n";
neuper@48895
   283
*)
neuper@48895
   284
if str = 
neuper@48895
   285
".    ----- pblobj -----\n"^
neuper@48895
   286
"1.   x + 1 = 2\n"^
neuper@48895
   287
"2.   x + 1 + -1 * 2 = 0\n"^
neuper@48895
   288
"2.1.   x + 1 + -1 * 2 = 0\n"^
neuper@48895
   289
"2.2.   1 + x + -1 * 2 = 0\n"^
neuper@48895
   290
"2.3.   1 + (x + -1 * 2) = 0\n"^
neuper@48895
   291
"2.4.   1 + (x + -2) = 0\n"^
neuper@48895
   292
"2.5.   1 + (x + -2 * 1) = 0\n"^
neuper@48895
   293
"2.6.   1 + x + -2 * 1 = 0\n" then()
neuper@48895
   294
else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
akargl@42176
   295
s1210629013@55446
   296
 autoCalculate' 1 CompleteCalc;
akargl@42176
   297
 val ((pt,pos as (p,_)),_) = get_calc 1;
akargl@42176
   298
 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst) (get_obj g_result pt p) then()
neuper@38031
   299
 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
neuper@37906
   300
neuper@37906
   301
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
neuper@37906
   302
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
neuper@37906
   303
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
s1210629013@55445
   304
 reset_states ();
neuper@41970
   305
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   306
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   307
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   308
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
   309
 autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
   310
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
s1210629013@55446
   311
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   312
neuper@37906
   313
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
neuper@37906
   314
 val ((pt,_),_) = get_calc 1;
neuper@37906
   315
 val str = pr_ptree pr_short pt;
neuper@37906
   316
 writeln str;
akargl@42176
   317
 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 ()
neuper@38031
   318
 else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
s1210629013@55446
   319
 autoCalculate' 1 CompleteCalc;
akargl@42176
   320
 val ((pt,pos as (p,_)),_) = get_calc 1;
akargl@42176
   321
 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
neuper@38031
   322
 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
neuper@37906
   323
neuper@37906
   324
neuper@37906
   325
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
neuper@37906
   326
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
neuper@37906
   327
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
s1210629013@55445
   328
 reset_states ();
neuper@41970
   329
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   330
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   331
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   332
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
   333
 autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
   334
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   335
neuper@37906
   336
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
neuper@37906
   337
 val ((pt,_),_) = get_calc 1;
neuper@37906
   338
 val str = pr_ptree pr_short pt;
neuper@37906
   339
 writeln str;
akargl@42176
   340
 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 ()
neuper@38031
   341
 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
s1210629013@55446
   342
 autoCalculate' 1 CompleteCalc;
akargl@42176
   343
 val ((pt,pos as (p,_)),_) = get_calc 1;
akargl@42176
   344
 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
neuper@38031
   345
 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
neuper@37906
   346
neuper@37906
   347
neuper@37906
   348
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
   349
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
   350
"--------- replaceFormula: cut calculation -----------------------";
s1210629013@55445
   351
 reset_states ();
neuper@41970
   352
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   353
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   354
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   355
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
   356
 autoCalculate' 1 CompleteCalc;
neuper@37906
   357
 moveActiveRoot 1; moveActiveDown 1;
neuper@37906
   358
 if get_pos 1 1 = ([1], Frm) then ()
neuper@38031
   359
 else error "inform.sml: diff.behav. cut calculation 1";
neuper@37906
   360
neuper@37906
   361
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
neuper@37906
   362
 val ((pt,p),_) = get_calc 1;
neuper@37906
   363
 val str = pr_ptree pr_short pt;
neuper@37906
   364
 writeln str;
neuper@37906
   365
 if p = ([1], Res) then ()
neuper@38031
   366
 else error "inform.sml: diff.behav. cut calculation 2";
neuper@37906
   367
neuper@37906
   368
neuper@37906
   369
(* 040307 copied from informtest.sml; ... old version 
neuper@37906
   370
 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
neuper@37906
   371
 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
neuper@37906
   372
 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
neuper@37906
   373
neuper@37906
   374
 val p = ([],Pbl);
neuper@37906
   375
 val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
neuper@37906
   376
	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
neuper@37906
   377
	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
neuper@37906
   378
	      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
neuper@37906
   379
	      (*^^^ these are the elements for the root-problem (in variants)*)
neuper@37906
   380
              (*vvv these are elements required for subproblems*)
neuper@37906
   381
	      "boundVariable a","boundVariable b","boundVariable alpha",
neuper@37906
   382
	      "interval {x::real. 0 <= x & x <= 2*r}",
neuper@37906
   383
	      "interval {x::real. 0 <= x & x <= 2*r}",
neuper@37906
   384
	      "interval {x::real. 0 <= x & x <= pi}",
neuper@37906
   385
	      "errorBound (eps=(0::real))"]
neuper@37906
   386
 (*specifying is not interesting for this example*)
neuper@38058
   387
 val spec = ("DiffApp", ["maximum_of","function"], 
neuper@37906
   388
	     ["DiffApp","max_by_calculus"]);
neuper@37906
   389
 (*the empty model with descriptions for user-guidance by Model_Problem*)
neuper@37906
   390
 val empty_model = [Given ["fixedValues []"],
neuper@37906
   391
		    Find ["maximum", "valuesFor"],
neuper@37906
   392
		    Relate ["relations []"]];
neuper@37906
   393
neuper@37906
   394
neuper@37906
   395
 (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
neuper@37906
   396
 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
neuper@37906
   397
 (*val nxt = ("Model_Problem", ...*)
neuper@37924
   398
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   399
neuper@37906
   400
 val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   401
 (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
neuper@37924
   402
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   403
(*[
neuper@37906
   404
(0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
neuper@37906
   405
(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
neuper@37906
   406
(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
neuper@37906
   407
(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
neuper@37906
   408
neuper@37906
   409
 (*the empty CalcHead is checked w.r.t the model and re-established as such*)
neuper@37906
   410
 val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, e_spec);
neuper@37924
   411
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@38031
   412
 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";
neuper@37906
   413
neuper@37906
   414
 (*there is one input to the model (could be more)*)
neuper@37906
   415
 val (b,pt,ocalhd) = 
neuper@37906
   416
     input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
neuper@37906
   417
			     Find ["maximum", "valuesFor"],
neuper@37906
   418
			     Relate ["relations"]], Pbl, e_spec);
neuper@37924
   419
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   420
 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 () 
neuper@38031
   421
 else error "informtest.sml: diff.behav. max 2";
neuper@37906
   422
neuper@37906
   423
 (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
neuper@37906
   424
 val (b,pt''''',ocalhd) = 
neuper@37906
   425
     input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
neuper@37906
   426
			     Find ["maximum A", "valuesFor [a,b]"],
neuper@37906
   427
			     Relate ["relations [A=a*b, a/2=r*sin alpha, \
neuper@37906
   428
				     \b/2=r*cos alpha]"]], Pbl, e_spec);
neuper@37924
   429
 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   430
 if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
neuper@37906
   431
neuper@37906
   432
 (*this input is complete in variant 1 (variant 3 does not work yet)*)
neuper@37906
   433
 val (b,pt''''',ocalhd) = 
neuper@37906
   434
     input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
neuper@37906
   435
			     Find ["maximum A", "valuesFor [a,b]"],
neuper@37906
   436
			     Relate ["relations [A=a*b, \
neuper@37906
   437
				     \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]], 
neuper@37906
   438
		      Pbl, e_spec);
neuper@37924
   439
 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   440
neuper@37906
   441
 modifycalcheadOK2xml 111 (bool2str b) ocalhd;
neuper@37906
   442
*)
neuper@37906
   443
neuper@37906
   444
"--------- syntax error ------------------------------------------";
neuper@37906
   445
"--------- syntax error ------------------------------------------";
neuper@37906
   446
"--------- syntax error ------------------------------------------";
s1210629013@55445
   447
 reset_states ();
neuper@41970
   448
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   449
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   450
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   451
 Iterator 1; moveActiveRoot 1;
s1210629013@55446
   452
 autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
   453
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
s1210629013@55446
   454
 autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   455
neuper@37906
   456
 appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
neuper@37906
   457
 val ((pt,_),_) = get_calc 1;
neuper@37906
   458
 val str = pr_ptree pr_short pt;
neuper@37906
   459
 writeln str;
neuper@37906
   460
 if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" then ()
neuper@38031
   461
 else error "inform.sml: diff.behav.appendFormula: syntax error";
neuper@37906
   462
neuper@37906
   463
neuper@37906
   464
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   465
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   466
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   467
val (p,_,f,nxt,_,pt) = 
neuper@37906
   468
    CalcTreeTEST [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
neuper@37906
   469
val ifo = "solve(x+1=2,x)";
neuper@37906
   470
val (_,(_,c,(pt,p))) = inform ([],[],(pt,p)) "solve(x+1=2,x)";
neuper@37906
   471
show_pt pt;
neuper@37906
   472
val nxt = ("Apply_Method",Apply_Method ["Test","squ-equ-test-subpbl1"]);
neuper@37906
   473
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@37906
   474
if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
neuper@38031
   475
else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
neuper@37906
   476
neuper@37906
   477
neuper@37906
   478
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
   479
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
   480
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
s1210629013@55445
   481
reset_states ();
neuper@37906
   482
CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
neuper@37906
   483
Iterator 1;
neuper@37906
   484
moveActiveRoot 1;
neuper@37906
   485
replaceFormula 1 "solve(x+1=2,x)";
s1210629013@55446
   486
autoCalculate' 1 CompleteCalc;
neuper@37906
   487
val ((pt,p),_) = get_calc 1;
neuper@37906
   488
show_pt pt;
neuper@37906
   489
if p = ([], Res) then ()
neuper@38031
   490
else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
neuper@37906
   491
neuper@37906
   492
neuper@37906
   493
"--------- inform [rational,simplification] ----------------------";
neuper@37906
   494
"--------- inform [rational,simplification] ----------------------";
neuper@37906
   495
"--------- inform [rational,simplification] ----------------------";
s1210629013@55445
   496
reset_states ();
neuper@52105
   497
CalcTree [(["Term (a * x / (b * x) + c * x / (d * x) + e / f)", "normalform N"],
neuper@52105
   498
	("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
neuper@37906
   499
Iterator 1; moveActiveRoot 1;
s1210629013@55446
   500
autoCalculate' 1 CompleteCalcHead;
neuper@52105
   501
neuper@52105
   502
"--- (-1) give a preview on the calculation without any input";
neuper@52105
   503
(*
s1210629013@55446
   504
autoCalculate' 1 CompleteCalc;
neuper@52105
   505
val ((pt, p), _) = get_calc 1;
neuper@52105
   506
show_pt pt;
neuper@52105
   507
[
neuper@52105
   508
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   509
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   510
(([1], Res), a / b + c / d + e / f),                             <--- (1) input arbitrary
neuper@52105
   511
(([2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   512
(([3], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   513
(([4], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)), <--- (2) input next
neuper@52105
   514
(([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))]  <--- (3) is also final result
neuper@52105
   515
                                                                          EXAMPLE NOT OPTIMAL
neuper@52105
   516
*)
neuper@52105
   517
"--- (0) user input as the *first* step does not work, thus impdo at least 1 step";
s1210629013@55446
   518
autoCalculate' 1 (Step 1);
s1210629013@55446
   519
autoCalculate' 1 (Step 1);
neuper@52105
   520
val ((pt, p), _) = get_calc 1;
neuper@52105
   521
(*show_pt pt;
neuper@52105
   522
[
neuper@52105
   523
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   524
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   525
(([1], Res), a / b + c / d + e / f)] 
neuper@52105
   526
*)
neuper@52105
   527
"--- (1) input an arbitrary next formula";
s1210629013@55402
   528
appendFormula 1 "((a * d) + (c * b)) / (b * d) + e / f" |> Future.join;
neuper@52105
   529
val ((pt, p), _) = get_calc 1;
neuper@52105
   530
(*show_pt pt;
neuper@52105
   531
[
neuper@52105
   532
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   533
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   534
(([1], Res), a / b + c / d + e / f),
neuper@52105
   535
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   536
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   537
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   538
(([2], Res), (a * d + c * b) / (b * d) + e / f)] 
neuper@52105
   539
*)
neuper@37906
   540
val ((pt,p),_) = get_calc 1;
neuper@52105
   541
if p = ([2], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
neuper@38031
   542
else error ("inform.sml: [rational,simplification] 1");
neuper@37906
   543
neuper@52105
   544
"--- (2) input the next formula that would be presented by mat-engine";
neuper@52105
   545
(* generate a preview:
s1210629013@55446
   546
autoCalculate' 1 (Step 1);
neuper@52105
   547
val ((pt, p), _) = get_calc 1;
neuper@52105
   548
show_pt pt;
neuper@52105
   549
[
neuper@52105
   550
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   551
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   552
(([1], Res), a / b + c / d + e / f),
neuper@52105
   553
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   554
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   555
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   556
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   557
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))]   <--- input this
neuper@52105
   558
*)
s1210629013@55402
   559
appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" |> Future.join;
neuper@52105
   560
val ((pt, p), _) = get_calc 1;
neuper@52105
   561
(*show_pt pt;
neuper@52105
   562
[
neuper@52105
   563
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   564
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   565
(([1], Res), a / b + c / d + e / f),
neuper@52105
   566
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   567
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   568
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   569
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   570
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
neuper@52105
   571
*)
neuper@52105
   572
if p = ([3], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
neuper@38031
   573
else error ("inform.sml: [rational,simplification] 2");
neuper@37906
   574
neuper@52105
   575
"--- (3) input the exact final result";
s1210629013@55402
   576
appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" |> Future.join;
neuper@52105
   577
val ((pt, p), _) = get_calc 1;
neuper@52105
   578
(*show_pt pt;
neuper@52105
   579
[
neuper@52105
   580
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   581
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   582
(([1], Res), a / b + c / d + e / f),
neuper@52105
   583
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   584
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   585
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   586
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   587
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   588
(([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   589
(([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   590
(([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   591
(([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
neuper@52105
   592
*)
neuper@52105
   593
if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
neuper@38031
   594
else error ("inform.sml: [rational,simplification] 3");
neuper@52105
   595
neuper@52105
   596
"--- (4) finish the calculation + check the postcondition (in the future)";
s1210629013@55446
   597
autoCalculate' 1 CompleteCalc;
neuper@52105
   598
val ((pt, p), _) = get_calc 1;
neuper@52105
   599
val (t, asm) = get_obj g_result pt [];
neuper@52105
   600
if term2str t = "(a * d * f + b * c * f + b * d * e) / (b * d * f)" andalso
neuper@52105
   601
terms2str asm = "[\"b * d * f ~= 0\",\"d ~= 0\",\"b ~= 0\"," ^
neuper@52105
   602
  "\"a * x / (b * x) + c * x / (d * x) + e / f is_ratpolyexp\"]"
neuper@52105
   603
then () else error "inform [rational,simplification] changed at end";
neuper@52105
   604
(*show_pt pt;
neuper@52105
   605
[
neuper@52105
   606
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   607
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   608
(([1], Res), a / b + c / d + e / f),
neuper@52105
   609
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   610
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   611
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   612
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   613
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   614
(([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   615
(([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   616
(([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   617
(([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   618
(([5], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   619
(([6], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)),
neuper@52105
   620
(([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))] 
neuper@52105
   621
*)
neuper@37906
   622
neuper@37906
   623
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   624
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   625
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   626
val t = str2term "Diff (x^^^2 + x + 1, x)";
neuper@37906
   627
case t of Const ("Diff.Diff", _) $ _ => ()
neuper@37906
   628
	| _ => raise 
neuper@37906
   629
	      error "diff.sml behav.changed for CAS Diff (..., x)";
neuper@37906
   630
atomty t;
neuper@37906
   631
"-----------------------------------------------------------------";
s1210629013@55445
   632
(*1>*)reset_states ();
neuper@37906
   633
(*2>*)CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
neuper@37906
   634
(*3>*)Iterator 1;moveActiveRoot 1;
neuper@37906
   635
"----- here the Headline has been finished";
neuper@37906
   636
(*4>*)moveActiveFormula 1 ([],Pbl);
neuper@37906
   637
(*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
neuper@37906
   638
val ((pt,_),_) = get_calc 1;
neuper@37906
   639
val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
neuper@37926
   640
val NONE = env;
neuper@37926
   641
val (SOME istate, NONE) = loc;
neuper@37906
   642
print_depth 5;
neuper@37906
   643
writeln"-----------------------------------------------------------";
neuper@37906
   644
spec;
neuper@37924
   645
writeln (itms2str_ ctxt probl);
neuper@37924
   646
writeln (itms2str_ ctxt meth);
neuper@48895
   647
writeln (istate2str (fst istate));
neuper@37906
   648
neuper@37906
   649
refFormula 1 ([],Pbl) (*--> correct CalcHead*);
neuper@37906
   650
 (*081016 NOT necessary (but leave it in Java):*)
s1210629013@55446
   651
(*6>*)(*completeCalcHead*)autoCalculate' 1 CompleteCalcHead;
neuper@37906
   652
"----- here the CalcHead has been completed --- ONCE MORE ?????";
neuper@37906
   653
neuper@37906
   654
(***difference II***)
neuper@37906
   655
val ((pt,p),_) = get_calc 1;
neuper@37906
   656
(*val p = ([], Pbl)*)
neuper@37906
   657
val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
neuper@37926
   658
val NONE = env;
neuper@37926
   659
val (SOME istate, NONE) = loc;
neuper@48895
   660
print_depth 5; writeln (istate2str (fst istate));  print_depth 3;
neuper@37906
   661
(*ScrState ([],
neuper@37926
   662
 [], NONE,
neuper@37906
   663
 ??.empty, Sundef, false)*)
neuper@37906
   664
print_depth 5; spec; print_depth 3;
neuper@38050
   665
(*("Isac",
neuper@37906
   666
      ["derivative_of", "function"],
neuper@37906
   667
      ["diff", "differentiate_on_R"]) : spec*)
neuper@37924
   668
writeln (itms2str_ ctxt probl);
neuper@37906
   669
(*[
neuper@37906
   670
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   671
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   672
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37924
   673
writeln (itms2str_ ctxt meth);
neuper@37906
   674
(*[
neuper@37906
   675
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   676
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   677
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37906
   678
writeln"-----------------------------------------------------------";
neuper@37906
   679
(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
neuper@37906
   680
(*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
s1210629013@55446
   681
autoCalculate' 1 CompleteCalc;
neuper@37906
   682
val ((pt,p),_) = get_calc 1;
neuper@37906
   683
val Form res = (#1 o pt_extract) (pt, ([],Res));
neuper@37906
   684
show_pt pt;
neuper@37906
   685
if p = ([], Res) andalso term2str res = "1 + 2 * x" then ()
neuper@38031
   686
else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
neuper@37906
   687
neuper@37906
   688
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   689
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   690
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   691
(*the following input is copied from BridgeLog Java <==> SML,
neuper@37906
   692
  omitting unnecessary inputs*)
s1210629013@55445
   693
(*1>*)reset_states ();
akargl@42176
   694
(*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac",["derivative_of","function"],["diff","differentiate_on_R"]))];
neuper@37906
   695
(*3>*)Iterator 1; moveActiveRoot 1;
neuper@37906
   696
s1210629013@55446
   697
(*6>*)(*completeCalcHead*)autoCalculate' 1 CompleteCalcHead;
neuper@37906
   698
(***difference II***)
neuper@37906
   699
val ((pt,_),_) = get_calc 1;
neuper@37906
   700
val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
neuper@37926
   701
val NONE = env;
neuper@37926
   702
val (SOME istate, NONE) = loc;
neuper@48895
   703
print_depth 5; writeln (istate2str (fst istate));  print_depth 3;
neuper@37906
   704
(*ScrState ([],
neuper@37926
   705
 [], NONE,
neuper@37906
   706
 ??.empty, Sundef, false)*)
neuper@37906
   707
print_depth 5; spec; print_depth 3;
neuper@38050
   708
(*("Isac",
neuper@37906
   709
      ["derivative_of", "function"],
neuper@37906
   710
      ["diff", "differentiate_on_R"]) : spec*)
neuper@37924
   711
writeln (itms2str_ ctxt probl);
neuper@37906
   712
(*[
neuper@37906
   713
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   714
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   715
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37924
   716
writeln (itms2str_ ctxt meth);
neuper@37906
   717
(*[
neuper@37906
   718
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   719
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   720
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37906
   721
writeln"-----------------------------------------------------------";
neuper@37906
   722
(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
s1210629013@55446
   723
autoCalculate' 1 (Step 1);
neuper@37906
   724
val ((pt,p),_) = get_calc 1;
neuper@37906
   725
val Form res = (#1 o pt_extract) (pt, p);
neuper@37906
   726
if term2str res = "d_d x (x ^^^ 2 + x + 1)" then ()
neuper@38031
   727
else error "diff.sml Diff (x^2 + x + 1, x) from exp";
neuper@37906
   728
neuper@37906
   729
"--------- init_form, start with <NEW> (CAS input) ---------------";
neuper@37906
   730
"--------- init_form, start with <NEW> (CAS input) ---------------";
neuper@37906
   731
"--------- init_form, start with <NEW> (CAS input) ---------------";
s1210629013@55445
   732
reset_states ();
neuper@37906
   733
CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
neuper@37906
   734
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   735
[[from sml:  1 
neuper@37906
   736
[[from sml: <CALCTREE>
neuper@37906
   737
[[from sml:    <CALCID> 1 </CALCID>
neuper@37906
   738
[[from sml: </CALCTREE>
neuper@37906
   739
[[from sml: @@@@@end@@@@@*)
neuper@37906
   740
Iterator 1;
neuper@37906
   741
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   742
[[from sml:  1 
neuper@37906
   743
[[from sml: <ADDUSER>
neuper@37906
   744
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   745
[[from sml:   <USERID> 1 </USERID>
neuper@37906
   746
[[from sml: </ADDUSER>
neuper@37906
   747
[[from sml: @@@@@end@@@@@*)
neuper@37906
   748
moveActiveRoot 1;
neuper@37906
   749
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   750
[[from sml:  1 
neuper@37906
   751
[[from sml: <CALCITERATOR>
neuper@37906
   752
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   753
[[from sml:   <POSITION>
neuper@37906
   754
[[from sml:     <INTLIST>
neuper@37906
   755
[[from sml:     </INTLIST>
neuper@37906
   756
[[from sml:     <POS> Pbl </POS>
neuper@37906
   757
[[from sml:   </POSITION>
neuper@37906
   758
[[from sml: </CALCITERATOR>
neuper@37906
   759
[[from sml: @@@@@end@@@@@*)
neuper@37906
   760
getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
neuper@37906
   761
(*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
neuper@37906
   762
[[from sml:  1 
neuper@37906
   763
[[from sml: <GETELEMENTSFROMTO>
neuper@37906
   764
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   765
[[from sml:   <FORMHEADS>
neuper@37906
   766
[[from sml:     <CALCFORMULA>
neuper@37906
   767
[[from sml:       <POSITION>
neuper@37906
   768
[[from sml:         <INTLIST>
neuper@37906
   769
[[from sml:         </INTLIST>
neuper@37906
   770
[[from sml:         <POS> Pbl </POS>
neuper@37906
   771
[[from sml:       </POSITION>
neuper@37906
   772
[[from sml:       <FORMULA>
neuper@37906
   773
[[from sml:         <MATHML>
neuper@37906
   774
[[from sml:           <ISA> ________________________________________________ </ISA>
neuper@37906
   775
[[from sml:         </MATHML>
neuper@37906
   776
[[from sml: 
neuper@37906
   777
[[from sml:       </FORMULA>
neuper@37906
   778
[[from sml:     </CALCFORMULA>
neuper@37906
   779
[[from sml:   </FORMHEADS>
neuper@37906
   780
[[from sml: </GETELEMENTSFROMTO>
neuper@37906
   781
[[from sml: @@@@@end@@@@@*)
neuper@37906
   782
refFormula 1 ([],Pbl);
neuper@37906
   783
(*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
neuper@37906
   784
[[from sml:  1 
neuper@37906
   785
[[from sml: <REFFORMULA>
neuper@37906
   786
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   787
[[from sml:   <CALCHEAD status = "incorrect">
neuper@37906
   788
[[from sml:     <POSITION>
neuper@37906
   789
[[from sml:       <INTLIST>
neuper@37906
   790
[[from sml:       </INTLIST>
neuper@37906
   791
[[from sml:       <POS> Pbl </POS>
neuper@37906
   792
[[from sml:     </POSITION>
neuper@37906
   793
[[from sml:     <HEAD>
neuper@37906
   794
[[from sml:       <MATHML>
neuper@37906
   795
[[from sml:         <ISA> Problem (e_domID, [e_pblID]) </ISA>
neuper@37906
   796
[[from sml:       </MATHML>
neuper@37906
   797
[[from sml:     </HEAD>
neuper@37906
   798
[[from sml:     <MODEL>
neuper@37906
   799
[[from sml:       <GIVEN>  </GIVEN>
neuper@37906
   800
[[from sml:       <WHERE>  </WHERE>
neuper@37906
   801
[[from sml:       <FIND>  </FIND>
neuper@37906
   802
[[from sml:       <RELATE>  </RELATE>
neuper@37906
   803
[[from sml:     </MODEL>
neuper@37906
   804
[[from sml:     <BELONGSTO> Pbl </BELONGSTO>
neuper@37906
   805
[[from sml:     <SPECIFICATION>
neuper@37906
   806
[[from sml:       <THEORYID> e_domID </THEORYID>
neuper@37906
   807
[[from sml:       <PROBLEMID>
neuper@37906
   808
[[from sml:         <STRINGLIST>
neuper@37906
   809
[[from sml:           <STRING> e_pblID </STRING>
neuper@37906
   810
[[from sml:         </STRINGLIST>
neuper@37906
   811
[[from sml:       </PROBLEMID>
neuper@37906
   812
[[from sml:       <METHODID>
neuper@37906
   813
[[from sml:         <STRINGLIST>
neuper@37906
   814
[[from sml:           <STRING> e_metID </STRING>
neuper@37906
   815
[[from sml:         </STRINGLIST>
neuper@37906
   816
[[from sml:       </METHODID>
neuper@37906
   817
[[from sml:     </SPECIFICATION>
neuper@37906
   818
[[from sml:   </CALCHEAD>
neuper@37906
   819
[[from sml: </REFFORMULA>
neuper@37906
   820
[[from sml: @@@@@end@@@@@*)
neuper@37906
   821
moveActiveFormula 1 ([],Pbl);
neuper@37906
   822
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   823
[[from sml:  1 
neuper@37906
   824
[[from sml: <CALCITERATOR>
neuper@37906
   825
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   826
[[from sml:   <POSITION>
neuper@37906
   827
[[from sml:     <INTLIST>
neuper@37906
   828
[[from sml:     </INTLIST>
neuper@37906
   829
[[from sml:     <POS> Pbl </POS>
neuper@37906
   830
[[from sml:   </POSITION>
neuper@37906
   831
[[from sml: </CALCITERATOR>
neuper@37906
   832
[[from sml: @@@@@end@@@@@*)
neuper@37906
   833
replaceFormula 1 "Simplify (1+2)";
neuper@37906
   834
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   835
[[from sml:  1 
neuper@37906
   836
[[from sml: <REPLACEFORMULA>
neuper@37906
   837
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   838
[[from sml:   <CALCCHANGED>
neuper@37906
   839
[[from sml:     <UNCHANGED>
neuper@37906
   840
[[from sml:       <INTLIST>
neuper@37906
   841
[[from sml:       </INTLIST>
neuper@37906
   842
[[from sml:       <POS> Pbl </POS>
neuper@37906
   843
[[from sml:     </UNCHANGED>
neuper@37906
   844
[[from sml:     <DELETED>
neuper@37906
   845
[[from sml:       <INTLIST>
neuper@37906
   846
[[from sml:       </INTLIST>
neuper@37906
   847
[[from sml:       <POS> Pbl </POS>
neuper@37906
   848
[[from sml:     </DELETED>
neuper@37906
   849
[[from sml:     <GENERATED>
neuper@37906
   850
[[from sml:       <INTLIST>
neuper@37906
   851
[[from sml:       </INTLIST>
neuper@37906
   852
[[from sml:       <POS> Met </POS>                           DIFFERENCE: Pbl
neuper@37906
   853
[[from sml:     </GENERATED>
neuper@37906
   854
[[from sml:   </CALCCHANGED>
neuper@37906
   855
[[from sml: </REPLACEFORMULA>
neuper@37906
   856
[[from sml: @@@@@end@@@@@*)
neuper@37906
   857
getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(*              DIFFERENCE: Pbl*);
neuper@37906
   858
(*@@@@@begin@@@@@
neuper@37906
   859
 1
neuper@37906
   860
<GETELEMENTSFROMTO>
neuper@37906
   861
  <CALCID> 1 </CALCID>
neuper@37906
   862
  <FORMHEADS>
neuper@37906
   863
    <CALCFORMULA>
neuper@37906
   864
      <POSITION>
neuper@37906
   865
        <INTLIST>
neuper@37906
   866
        </INTLIST>
neuper@37906
   867
        <POS> Pbl </POS>
neuper@37906
   868
      </POSITION>
neuper@37906
   869
      <FORMULA>
neuper@37906
   870
        <MATHML>
neuper@37906
   871
          <ISA> Simplify (1 + 2) </ISA>                      WORKS !!!!!
neuper@37906
   872
        </MATHML>
neuper@37906
   873
      </FORMULA>
neuper@37906
   874
    </CALCFORMULA>
neuper@37906
   875
  </FORMHEADS>
neuper@37906
   876
</GETELEMENTSFROMTO>
neuper@37906
   877
@@@@@end@@@@@*)
neuper@37906
   878
getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
neuper@37906
   879
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   880
[[from sml:  1 
neuper@37906
   881
[[from sml: <SYSERROR>
neuper@37906
   882
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   883
[[from sml:   <ERROR> error in getFormulaeFromTo </ERROR>
neuper@37906
   884
[[from sml: </SYSERROR>
neuper@37906
   885
[[from sml: @@@@@end@@@@@*)
neuper@37906
   886
(*step into getFormulaeFromTo --- bug corrected...*)
neuper@42423
   887
neuper@42423
   888
"--------- build fun check_err_patt ------------------------------";
neuper@42423
   889
"--------- build fun check_err_patt ------------------------------";
neuper@42423
   890
"--------- build fun check_err_patt ------------------------------";
neuper@42426
   891
val subst = [(str2term "bdv", str2term "x")]: subst;
neuper@42423
   892
val rls = norm_Rational
neuper@42423
   893
val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
neuper@42423
   894
val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
neuper@42423
   895
val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "1 / 2");
neuper@42423
   896
neuper@42426
   897
val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
neuper@42423
   898
  rew_sub thy 1 [] e_rew_ord e_rls false [] (Trueprop $ pat) res;
neuper@42423
   899
if rewritten then NONE else SOME "e_errpatID";
neuper@42423
   900
neuper@42423
   901
val norm_res = case rewrite_set_ (Isac()) false rls res' of
neuper@42423
   902
  NONE => res'
neuper@42423
   903
| SOME (norm_res, _) => norm_res
neuper@42423
   904
neuper@42423
   905
val norm_inf = case rewrite_set_ (Isac()) false rls inf of
neuper@42423
   906
  NONE => inf
neuper@42423
   907
| SOME (norm_inf, _) => norm_inf;
neuper@42423
   908
neuper@42423
   909
res' = inf;
neuper@42423
   910
norm_res = norm_inf;
neuper@42423
   911
neuper@42423
   912
val pat = parse_patt @{theory} "(?a + ?b)/?a = ?b";
neuper@42423
   913
val (res, inf) = (str2term "(2 + 3)/2", str2term "3");
neuper@42426
   914
if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   915
then () else error "error patt example1 changed";
neuper@42423
   916
neuper@42423
   917
val pat = parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
neuper@42423
   918
val (res, inf) = (str2term "(2 + 3)/(2 + 4)", str2term "3 / 4");
neuper@42426
   919
if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   920
then () else error "error patt example2 changed";
neuper@42423
   921
neuper@42423
   922
val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
neuper@42423
   923
val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
neuper@42426
   924
if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   925
then () else error "error patt example3 changed";
neuper@42423
   926
neuper@42423
   927
val inf =  str2term "1 / 2";
neuper@42426
   928
if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   929
then () else error "error patt example3 changed";
neuper@42423
   930
neuper@42426
   931
"--------- build fun check_err_patt ?bdv -------------------------";
neuper@42426
   932
"--------- build fun check_err_patt ?bdv -------------------------";
neuper@42426
   933
"--------- build fun check_err_patt ?bdv -------------------------";
neuper@42426
   934
val subst = [(str2term "bdv", str2term "x")]: subst;
neuper@42426
   935
val t = str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))";
neuper@42426
   936
val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
neuper@42426
   937
if term2str t = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3" then ()
neuper@42426
   938
else error "build fun check_err_patt ?bdv changed 1"; 
neuper@42423
   939
neuper@42426
   940
val rls = norm_diff
neuper@42426
   941
val pat = parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)"; 
neuper@42426
   942
val (res, inf) = (str2term "2 * x + d_d x (sin (x ^^^ 4))", str2term "2 * x + cos (4 * x ^^^ 3)");
neuper@42426
   943
neuper@42426
   944
val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
neuper@42426
   945
  rew_sub thy 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) res;
neuper@42426
   946
if term2str res' = "2 * x + cos (d_d x (x ^^^ 4))" andalso rewritten then ()
neuper@42426
   947
else error "build fun check_err_patt ?bdv changed 2";
neuper@42426
   948
neuper@42426
   949
val norm_res = case rewrite_set_inst_ (Isac()) false subst rls  res' of
neuper@42426
   950
  NONE => res'
neuper@42426
   951
| SOME (norm_res, _) => norm_res;
neuper@42426
   952
if term2str norm_res = "2 * x + cos (4 * x ^^^ 3)" then ()
neuper@42426
   953
else error "build fun check_err_patt ?bdv changed 3";
neuper@42426
   954
neuper@42426
   955
val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
neuper@42426
   956
  NONE => inf
neuper@42426
   957
| SOME (norm_inf, _) => norm_inf;
neuper@42426
   958
if term2str norm_inf = "2 * x + cos (4 * x ^^^ 3)" then ()
neuper@42426
   959
else error "build fun check_err_patt ?bdv changed 4";
neuper@42426
   960
neuper@42426
   961
res' = inf;
neuper@42426
   962
if norm_res = norm_inf then ()
neuper@42426
   963
else error "build fun check_err_patt ?bdv changed 5";
neuper@42426
   964
neuper@42426
   965
if check_err_patt (res, inf) (subst: subst) ("errpatID": errpatID, pat) rls = SOME "errpatID"
neuper@42426
   966
then () else error "error patt example1 changed";
neuper@42426
   967
neuper@42428
   968
"--------- build fun check_error_patterns ------------------------";
neuper@42428
   969
"--------- build fun check_error_patterns ------------------------";
neuper@42428
   970
"--------- build fun check_error_patterns ------------------------";
neuper@42428
   971
val (res, inf) =
neuper@42428
   972
  (str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))",
neuper@42428
   973
   str2term "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)");
neuper@48790
   974
val {errpats, nrls = rls, scr = Prog prog, ...} = get_met ["diff", "differentiate_on_R"]
neuper@42426
   975
neuper@42428
   976
val env = [(str2term "v_v", str2term "x")];
neuper@42428
   977
val errpats =
neuper@42428
   978
  [e_errpat, (*generalised for testing*)
neuper@42428
   979
   ("chain-rule-diff-both",
neuper@42428
   980
     [parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
neuper@42428
   981
      parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
neuper@42428
   982
      parse_patt @{theory} "d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)",
neuper@42428
   983
      parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
neuper@42428
   984
      parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
neuper@42428
   985
     [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain}, 
neuper@42428
   986
      @{thm diff_ln_chain}, @{thm  diff_exp_chain}])]: errpat list;
neuper@42428
   987
case check_error_patterns (res, inf) (prog, env) (errpats, rls) of SOME _ => () 
neuper@42428
   988
| NONE => error "check_error_patterns broken";
neuper@42428
   989
neuper@42428
   990
"--------- embed fun check_error_patterns ------------------------";
neuper@42428
   991
"--------- embed fun check_error_patterns ------------------------";
neuper@42428
   992
"--------- embed fun check_error_patterns ------------------------";
s1210629013@55445
   993
reset_states ();
neuper@42428
   994
CalcTree
neuper@42428
   995
[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
neuper@42428
   996
  ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
neuper@42428
   997
Iterator 1;
neuper@42428
   998
moveActiveRoot 1;
s1210629013@55446
   999
autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
  1000
autoCalculate' 1 (Step 1);
s1210629013@55446
  1001
autoCalculate' 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
s1210629013@55446
  1002
(*autoCalculate' 1 (Step 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
neuper@42428
  1003
neuper@42428
  1004
"~~~~~ fun appendFormula, args:"; val (cI, (ifo:cterm')) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
neuper@42428
  1005
val cs = get_calc cI
neuper@42428
  1006
val pos as (_,p_) = get_pos cI 1; (*pos = ([1], Res)*)
neuper@42428
  1007
val cs' = 
neuper@42428
  1008
    case step pos cs of
neuper@42428
  1009
	    ("ok", cs') => cs';
neuper@42428
  1010
neuper@42428
  1011
val (_, _, (pt, ([2], Res))) = cs';
neuper@42428
  1012
(*show_pt pt;
neuper@42428
  1013
  [(([], Frm), Diff (x ^^^ 2 + sin (x ^^^ 4), x)),
neuper@42428
  1014
   (([1], Frm), d_d x (x ^^^ 2 + sin (x ^^^ 4))),
neuper@42428
  1015
   (([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))), <<=== input follos: "...+ cos(4.x^3)"
neuper@42428
  1016
   (([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4))] *)
neuper@42428
  1017
neuper@42428
  1018
"~~~~~ fun inform, args:"; val ((cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate'), istr) =
neuper@42428
  1019
  (cs', (encode ifo));
neuper@42428
  1020
val 	SOME f_in = parse (assoc_thy "Isac") istr
neuper@42428
  1021
val f_in = term_of f_in
neuper@42428
  1022
val pos_pred = lev_back' pos
neuper@42428
  1023
			(* f_pred ---"step pos cs"---> f_succ in appendFormula
neuper@42428
  1024
   TODO.WN120517: one starting point for redesign of pos' *)
neuper@42432
  1025
val (f_pred, f_succ) = (get_curr_formula (pt, pos_pred), get_curr_formula (pt, pos));
neuper@42428
  1026
	
neuper@42428
  1027
term2str f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
neuper@42428
  1028
term2str f_succ = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)";
neuper@42428
  1029
neuper@42428
  1030
			f_succ = f_in; (* = false*)
neuper@42428
  1031
cas_input f_in; (* = NONE*)
neuper@42428
  1032
val msg_calcstate' = compare_step ([], [], (pt, pos_pred)) f_in
neuper@42428
  1033
val ("no derivation found", calcstate') = msg_calcstate';
neuper@42428
  1034
			                 val pp = par_pblobj pt p
neuper@48790
  1035
			                 val {errpats, nrls, scr = Prog prog, ...} = get_met (get_obj g_metID pt pp)
neuper@42428
  1036
			                 val ScrState (env, _, _, _, _, _) = get_istate pt pos;
neuper@42428
  1037
                 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
neuper@42428
  1038
			                   SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
neuper@42428
  1039
			                 | NONE => msg_calcstate';
neuper@42428
  1040
neuper@42428
  1041
"~~~~~ from inform return val:"; val () = ();
neuper@42428
  1042
case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
neuper@42428
  1043
			  SOME errpatID => ()
neuper@42428
  1044
			| NONE => error "check_error_patterns broken";
neuper@42428
  1045
neuper@42428
  1046
"--- final check:";
neuper@42428
  1047
case inform cs' (encode ifo) of
neuper@42428
  1048
  ("error pattern #chain-rule-diff-both#", calcstate') => ()
neuper@42428
  1049
| _ => error "inform with (positive) check_error_patterns broken"
neuper@42428
  1050
neuper@48895
  1051
"--------- build fun get_fillpats --------------------------------";
neuper@48895
  1052
"--------- build fun get_fillpats --------------------------------";
neuper@48895
  1053
"--------- build fun get_fillpats --------------------------------";
neuper@48895
  1054
(*cause for this test was: wrong thy in Build_Thydata.thy in 
neuper@48895
  1055
  insert_fillpats ["IsacKnowledge", "Diff", "Theorems", "diff_sin_chain"]*)
neuper@48895
  1056
val f_curr = str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"
neuper@48895
  1057
val errpatID = "chain-rule-diff-both"
neuper@48895
  1058
  val {errpats, scr = Prog prog, ...} = get_met ["diff", "differentiate_on_R"]
neuper@48895
  1059
val env = 
neuper@48895
  1060
  [(str2term "f_f", str2term "x ^^^ 2 + sin (x ^^^ 4)"),
neuper@48895
  1061
   (str2term "v_v", str2term "x"),
neuper@48895
  1062
   (str2term "f_f'", str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))")]
neuper@48895
  1063
  val subst = get_bdv_subst prog env
neuper@48895
  1064
  val errpatthms = errpats
neuper@48895
  1065
    |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
neuper@48895
  1066
    |> map (#3: errpat -> thm list)
neuper@48895
  1067
    |> flat;
neuper@48895
  1068
"~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
neuper@48895
  1069
  (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
neuper@48895
  1070
        val thmDeriv = Thm.get_name_hint thm
neuper@48895
  1071
        val (part, thyID) = thy_containing_thm thmDeriv
neuper@48895
  1072
        val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
neuper@48895
  1073
        val Hthm {fillpats, ...} = get_the theID
neuper@48895
  1074
        val some = map (get_fillform subst (thm, form) errpatID) fillpats;
neuper@48895
  1075
"~~~~~ fun get_fillform, args:";
neuper@48895
  1076
  val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
neuper@48895
  1077
  (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
neuper@48895
  1078
  val (form', _, _, rewritten) =
neuper@48895
  1079
        rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
neuper@48895
  1080
"~~~~~ fun rew_sub, args:"; val (thy, i, bdv, tless, rls, put_asm, lrd:lrd list, r, t) = 
neuper@48895
  1081
  ((Isac()), 1, subst, e_rew_ord, e_rls, false, [], (Trueprop $ pat), form);
neuper@48895
  1082
     val (lhs, rhs) = (HOLogic.dest_eq o HOLogic.dest_Trueprop
neuper@48895
  1083
                       o Logic.strip_imp_concl) r;
neuper@48895
  1084
(*/-------------catch the planned exception*)
neuper@48895
  1085
(let
neuper@48895
  1086
     val r' = Envir.subst_term (Pattern.match thy (lhs, t) 
neuper@48895
  1087
					      (Vartab.empty, Vartab.empty)) r;
neuper@48895
  1088
in 111 end
neuper@48895
  1089
) handle PATTERN (*because only a subterm matches*) => 111;
neuper@48895
  1090
case t of t1 $ t2 => 
neuper@48895
  1091
	  let val (t2', asm2, lrd, rew2) = rew_sub thy i bdv tless rls put_asm (lrd@[R]) r t2
neuper@48895
  1092
	  in 
neuper@48895
  1093
	    if rew2 then (t1 $ t2', asm2, lrd, true) else
neuper@48895
  1094
	      let val (t1', asm1, lrd, rew1) = rew_sub thy i bdv tless rls put_asm (lrd@[L]) r t1
neuper@48895
  1095
	      in if rew1 then (t1' $ t2, asm1, lrd, true) else (t1 $ t2,[], lrd, false) end
neuper@48895
  1096
	  end;
neuper@48895
  1097
(*catch the planned exception-------------/*)
neuper@48895
  1098
neuper@48895
  1099
val t1 $ t2 = t;
neuper@48895
  1100
val (t2', asm2, lrd, rew2) = rew_sub thy i bdv tless rls put_asm (lrd@[R]) r t2;
neuper@48895
  1101
"~~~~~ fun rew_sub, args:"; val (thy, i, bdv, tless, rls, put_asm, lrd:lrd list, r, t) = 
neuper@48895
  1102
  (thy, i, bdv, tless, rls, put_asm, (lrd@[R]), r, t2);
neuper@48895
  1103
     val (lhs, rhs) = (HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r;
neuper@48895
  1104
     val r' = Envir.subst_term (Pattern.match thy (lhs, t) (Vartab.empty, Vartab.empty)) r;
neuper@48895
  1105
     val p' = map HOLogic.dest_Trueprop ((fst o Logic.strip_prems) (Logic.count_prems r', [], r'));
neuper@48895
  1106
     val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r';
neuper@48895
  1107
if term2str t' = "cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
neuper@48895
  1108
  else error "get_fillpats changed 1"
neuper@48895
  1109
neuper@42430
  1110
"--------- embed fun find_fillpatterns ---------------------------";
neuper@42430
  1111
"--------- embed fun find_fillpatterns ---------------------------";
neuper@42430
  1112
"--------- embed fun find_fillpatterns ---------------------------";
s1210629013@55445
  1113
reset_states ();
neuper@42430
  1114
CalcTree
neuper@42430
  1115
[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
neuper@42430
  1116
  ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
neuper@42430
  1117
Iterator 1;
neuper@42430
  1118
moveActiveRoot 1;
s1210629013@55446
  1119
autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
  1120
autoCalculate' 1 (Step 1);
s1210629013@55446
  1121
autoCalculate' 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
s1210629013@55402
  1122
appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)" |> Future.join;
neuper@42430
  1123
  (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
neuper@42432
  1124
  (*or
neuper@42432
  1125
    <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
neuper@42430
  1126
neuper@42433
  1127
"~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
neuper@42430
  1128
  val ((pt, _), _) = get_calc cI
neuper@42430
  1129
				val pos = get_pos cI 1;
neuper@42432
  1130
"~~~~~ fun find_fillpatterns, args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
neuper@42432
  1131
	    val f_curr = get_curr_formula (pt, pos); (* = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"*)
neuper@42430
  1132
    val pp = par_pblobj pt p
neuper@48895
  1133
    val {errpats, scr = Prog prog, ...} = get_met (get_obj g_metID pt pp)
neuper@42430
  1134
    val ScrState (env, _, _, _, _, _) = get_istate pt pos
neuper@42430
  1135
    val subst = get_bdv_subst prog env
neuper@42430
  1136
    val errpatthms = errpats
neuper@42430
  1137
      |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
neuper@42430
  1138
      |> map (#3: errpat -> thm list)
neuper@42430
  1139
      |> flat;
neuper@42430
  1140
neuper@42430
  1141
case map (get_fillpats subst f_curr errpatID) errpatthms |> flat of
neuper@42433
  1142
  ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if term2str tm = 
neuper@42432
  1143
    "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
neuper@42432
  1144
    then () else error "find_fillpatterns changed 1a"
neuper@42432
  1145
| _ => error "find_fillpatterns changed 1b"
neuper@42430
  1146
neuper@42430
  1147
"~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
neuper@42432
  1148
  (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
neuper@42430
  1149
        val thmDeriv = Thm.get_name_hint thm
neuper@42430
  1150
        val (part, thyID) = thy_containing_thm thmDeriv
neuper@42430
  1151
        val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
neuper@42430
  1152
        val Hthm {fillpats, ...} = get_the theID
neuper@42433
  1153
        val some = map (get_fillform subst (thm, form) errpatID) fillpats;
neuper@42430
  1154
neuper@42430
  1155
case some |> filter is_some |> map the of
neuper@42433
  1156
  ("fill-d_d-arg", tm, thm, subsopt) :: _ => if term2str tm = 
neuper@42432
  1157
    "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
neuper@42432
  1158
    then () else error "find_fillpatterns changed 2a"
neuper@42432
  1159
| _ => error "find_fillpatterns changed 2b"
neuper@42430
  1160
neuper@42433
  1161
"~~~~~ fun get_fillform, args:";
neuper@42433
  1162
  val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
neuper@42433
  1163
  (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
neuper@42433
  1164
val (form', _, _, rewritten) =
neuper@42432
  1165
      rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
neuper@42432
  1166
neuper@42432
  1167
if term2str form' = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
neuper@42432
  1168
else error "find_fillpatterns changed 3";
neuper@42432
  1169
neuper@42433
  1170
"~~~~~ to findFillpatterns return val:"; val (fillpats) =
neuper@42433
  1171
  (map (get_fillpats (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
neuper@42432
  1172
neuper@42450
  1173
"vvv--- dropped this code WN120730";
neuper@42433
  1174
val msg = "fill patterns " ^
neuper@42433
  1175
  ((map ((apsnd term2str) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
neuper@42450
  1176
msg =
neuper@42432
  1177
  "fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
neuper@42432
  1178
    " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" ^
neuper@42432
  1179
  "#fill-both-args#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
neuper@42432
  1180
    " =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3" ^
neuper@42432
  1181
  "#fill-d_d#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
neuper@42432
  1182
    " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1 x (x ^^^ 4)" ^
neuper@42432
  1183
  "#fill-inner-deriv#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
neuper@42432
  1184
    " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1" ^
neuper@42450
  1185
  "#fill-all#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) = d_d x (x ^^^ 2) + ?_dummy_1#";
neuper@42450
  1186
"^^^--- dropped this code WN120730";
neuper@42450
  1187
neuper@42450
  1188
if (map #1 fillpats) =
neuper@42450
  1189
  ["fill-d_d-arg", "fill-both-args", "fill-d_d", "fill-inner-deriv", "fill-all"]
neuper@42450
  1190
then () else error "find_fillpatterns changed 4b";
neuper@42450
  1191
neuper@42437
  1192
"--------- build fun is_exactly_equal, inputFillFormula ----------";
neuper@42437
  1193
"--------- build fun is_exactly_equal, inputFillFormula ----------";
neuper@42437
  1194
"--------- build fun is_exactly_equal, inputFillFormula ----------";
s1210629013@55445
  1195
reset_states ();
neuper@42437
  1196
CalcTree
neuper@42437
  1197
[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
neuper@42437
  1198
  ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
neuper@42437
  1199
Iterator 1;
neuper@42437
  1200
moveActiveRoot 1;
s1210629013@55446
  1201
autoCalculate' 1 CompleteCalcHead;
s1210629013@55446
  1202
autoCalculate' 1 (Step 1);
s1210629013@55446
  1203
autoCalculate' 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
s1210629013@55402
  1204
appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)" |> Future.join; (*<<<<<<<=========================*)
neuper@42437
  1205
(* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
neuper@42437
  1206
  would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
neuper@42437
  1207
  results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
neuper@42437
  1208
  instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
neuper@42437
  1209
  val ((pt,pos), _) = get_calc 1;
neuper@42437
  1210
  val p = get_pos 1 1;
neuper@42437
  1211
  val (Form f, _, asms) = pt_extract (pt, p);
neuper@42437
  1212
neuper@42437
  1213
  if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
neuper@55480
  1214
    get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], 
neuper@55480
  1215
      ("diff_sum", "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v"))
neuper@42437
  1216
  then () else error "embed fun get_fillform changed 1";
neuper@42437
  1217
neuper@42437
  1218
findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
neuper@42437
  1219
(*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
neuper@42437
  1220
  d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
neuper@42437
  1221
  val ((pt,pos),_) = get_calc 1;
neuper@42437
  1222
  val p = get_pos 1 1;
neuper@42437
  1223
neuper@42437
  1224
  val (Form f, _, asms) = pt_extract (pt, p);
neuper@42437
  1225
  if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
neuper@55480
  1226
    get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], 
neuper@55480
  1227
      ("diff_sum", "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v"))
neuper@55480
  1228
  then () else error "embed fun get_fillform changed 2";
neuper@42437
  1229
neuper@42437
  1230
requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
neuper@42437
  1231
  (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
neuper@42437
  1232
  val ((pt,pos),_) = get_calc 1;
neuper@42437
  1233
  val p = get_pos 1 1;
neuper@42437
  1234
  val (Form f, _, asms) = pt_extract (pt, p);
neuper@42437
  1235
  if p = ([1], Res) andalso existpt [2] pt andalso
neuper@42437
  1236
    term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
neuper@55480
  1237
    get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], 
neuper@55480
  1238
      ("diff_sum", "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v"))
neuper@42437
  1239
  then () else error "embed fun get_fillform changed 3";
neuper@42437
  1240
neuper@42437
  1241
(* input a formula which exactly fills the gaps in a "fillformula"
neuper@42437
  1242
   presented to the learner immediately before by "requestFillformula (errpatID, fillpatID)":
neuper@42437
  1243
   errpatID: lhs of the respective thm = lhs of fillformula with fillpatID.
neuper@42437
  1244
   the respective thm is in the ctree ................
neuper@42437
  1245
*)
neuper@42437
  1246
"~~~~~ fun inputFillFormula, args:"; val (cI, ifo) =
neuper@42437
  1247
  (1, "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)");
neuper@42437
  1248
    val ((pt, _), _) = get_calc cI
neuper@42437
  1249
    val pos = get_pos cI 1;
neuper@42437
  1250
neuper@42437
  1251
"~~~~~ fun is_exactly_equal, args:"; val ((pt, pos as (p, p_)), istr) = ((pt, pos), ifo);
neuper@42437
  1252
  val SOME ifo = parseNEW (assoc_thy "Isac" |> thy2ctxt) istr
neuper@42437
  1253
  val p' = lev_on p;
neuper@42437
  1254
  val tac = get_obj g_tac pt p';
neuper@55482
  1255
if tac = Rewrite_Inst (["(bdv, x)"], ("diff_sin_chain", "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u"))
neuper@55482
  1256
then () else error "inputFillFormula changed 10";
neuper@42437
  1257
  val Appl rew = applicable_in pos pt tac;
neuper@42437
  1258
  val Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) = rew;
neuper@42437
  1259
neuper@42437
  1260
"~~~~~ to inputFillFormula return val:"; val ("ok", tac) = ("ok", tac);
neuper@42437
  1261
  val ("ok", (_, c, ptp as (_,p'))) = locatetac tac (pt, pos);
neuper@42437
  1262
    upd_calc cI (ptp, []);
neuper@42437
  1263
    upd_ipos cI 1 p';
neuper@42437
  1264
    autocalculateOK2xml cI pos (if null c then p' else last_elem c) p';
neuper@42437
  1265
neuper@42437
  1266
"~~~~~ final check:";
neuper@42437
  1267
val ((pt, _),_) = get_calc 1;
neuper@42437
  1268
val p = get_pos 1 1;
neuper@42437
  1269
val (Form f, _, asms) = pt_extract (pt, p);
neuper@42437
  1270
if p = ([2], Res) andalso
neuper@42437
  1271
  term2str f = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)" andalso
neuper@55482
  1272
  get_obj g_tac pt (fst p) =
neuper@55482
  1273
    Rewrite_Inst (["(bdv, x)"], ("diff_sin_chain", "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u"))
neuper@42437
  1274
then () else error "inputFillFormula changed 11";
neuper@42437
  1275