test/Tools/isac/Interpret/inform.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 21 May 2012 16:56:01 +0200
changeset 42430 5b629bb1c073
parent 42428 aaca5c033fa4
child 42431 22f0435fdfe2
permissions -rw-r--r--
added fun FindFillpatterns

TODO: separate "error pattern #" from "no derivation found"
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@42430
    38
"--------- embed fun find_fillpatterns ---------------------------";
neuper@37906
    39
"-----------------------------------------------------------------";
neuper@37906
    40
"-----------------------------------------------------------------";
neuper@37906
    41
"-----------------------------------------------------------------";
neuper@37906
    42
neuper@37906
    43
neuper@37906
    44
neuper@37906
    45
neuper@37906
    46
neuper@37906
    47
neuper@37906
    48
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@37906
    49
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@37906
    50
"--------- appendFormula: on Res + equ_nrls ----------------------";
akargl@42176
    51
neuper@37906
    52
 val Script sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
neuper@37906
    53
 (writeln o term2str) sc;
neuper@37906
    54
 val Script sc = (#scr o get_met) ["Test","solve_linear"];
neuper@37906
    55
 (writeln o term2str) sc;
neuper@37906
    56
neuper@37906
    57
 states:=[];
neuper@41970
    58
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
    59
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
    60
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
    61
 Iterator 1; moveActiveRoot 1;
neuper@37906
    62
 autoCalculate 1 CompleteCalcHead;
neuper@37906
    63
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
    64
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
    65
neuper@37906
    66
 appendFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
neuper@37906
    67
 val ((pt,_),_) = get_calc 1;
neuper@37906
    68
 val str = pr_ptree pr_short pt;
akargl@42176
    69
neuper@37906
    70
 writeln str;
akargl@42209
    71
(*============ inhibit exn AK110726 ==============================================
akargl@42176
    72
(* 2nd string should be the same as 1st one *)
akargl@42176
    73
".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   1 + x + -1 * 2 = 0\n2.3.   1 + (x + -1 * 2) = 0\n2.4.   1 + (x + -2) = 0\n2.5.   1 + (x + -2 * 1) = 0\n2.6.   1 + x + -2 * 1 = 0\n";
akargl@42176
    74
".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   -1 * 2 + (x + 1) = 0\n2.3.   -1 * 2 + (1 + x) = 0\n2.4.   1 + (-1 * 2 + x) = 0\n2.5.   1 + (-2 + x) = 0\n2.6.   1 + (-2 * 1 + x) = 0\n";
neuper@37906
    75
 if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   -1 * 2 + (x + 1) = 0\n2.3.   -1 * 2 + (1 + x) = 0\n2.4.   1 + (-1 * 2 + x) = 0\n2.5.   1 + (-2 + x) = 0\n2.6.   1 + (-2 * 1 + x) = 0\n" then ()
akargl@42209
    76
   else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
akargl@42209
    77
============ inhibit exn AK110726 ==============================================*)
neuper@37906
    78
neuper@37906
    79
 moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
neuper@37906
    80
 moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
neuper@37906
    81
neuper@37906
    82
 (*the seven steps of detailed derivation*)
neuper@37906
    83
 moveDown 1 ([1  ],Res); refFormula 1 ([2,1],Frm); 
neuper@37906
    84
 moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
neuper@37906
    85
 moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
neuper@37906
    86
 moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res); 
neuper@37906
    87
 moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
neuper@37906
    88
 moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
neuper@37906
    89
 moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
neuper@37906
    90
 val ((pt,_),_) = get_calc 1;
neuper@37906
    91
 if "-2 * 1 + (1 + x) = 0" = term2str (fst (get_obj g_result pt [2,6])) then()
neuper@38031
    92
 else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
neuper@37906
    93
neuper@37906
    94
 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
akargl@42209
    95
akargl@42176
    96
(*============ inhibit exn AK110725 ==============================================
akargl@42176
    97
(* ERROR: exception Bind raised *)
neuper@37906
    98
 val (_,(tac,_,_)::_) = get_calc 1;
neuper@37906
    99
 if tac = Rewrite_Set "Test_simplify" then ()
neuper@38031
   100
 else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
akargl@42176
   101
============ inhibit exn AK110725 ==============================================*)
akargl@42209
   102
neuper@37906
   103
 autoCalculate 1 CompleteCalc;
neuper@37906
   104
 val ((pt,_),_) = get_calc 1;
neuper@37906
   105
 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@38031
   106
 else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
neuper@37906
   107
 (* autoCalculate 1 CompleteCalc;
neuper@37906
   108
   val ((pt,p),_) = get_calc 1;
neuper@37906
   109
   (writeln o istates2str) (get_obj g_loc pt [ ]);  
neuper@37906
   110
   (writeln o istates2str) (get_obj g_loc pt [1]);  
neuper@37906
   111
   (writeln o istates2str) (get_obj g_loc pt [2]);  
neuper@37906
   112
   (writeln o istates2str) (get_obj g_loc pt [3]);  
neuper@37906
   113
   (writeln o istates2str) (get_obj g_loc pt [3,1]);  
neuper@37906
   114
   (writeln o istates2str) (get_obj g_loc pt [3,2]);  
neuper@37906
   115
   (writeln o istates2str) (get_obj g_loc pt [4]);  
neuper@37906
   116
neuper@37906
   117
   *)
neuper@37906
   118
"----------------------------------------------------------";
akargl@42176
   119
akargl@42176
   120
 val fod = make_deriv (@{theory "Isac"}) Atools_erls 
neuper@37906
   121
		       ((#rules o rep_rls) Test_simplify)
akargl@42176
   122
		       (sqrt_right false (@{theory "Pure"})) NONE 
neuper@37906
   123
		       (str2term "x + 1 + -1 * 2 = 0");
neuper@37906
   124
 (writeln o trtas2str) fod;
neuper@37906
   125
akargl@42176
   126
 val ifod = make_deriv (@{theory "Isac"}) Atools_erls 
neuper@37906
   127
		       ((#rules o rep_rls) Test_simplify)
akargl@42176
   128
		       (sqrt_right false (@{theory "Pure"})) NONE 
neuper@37906
   129
		       (str2term "-2 * 1 + (1 + x) = 0");
neuper@37906
   130
 (writeln o trtas2str) ifod;
akargl@42176
   131
 fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
neuper@37906
   132
 val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
neuper@37906
   133
 val der = fod' @ (map rev_deriv' rifod');
neuper@37906
   134
 (writeln o trtas2str) der;
neuper@37906
   135
 "----------------------------------------------------------";
neuper@37906
   136
neuper@37906
   137
neuper@37906
   138
"--------- appendFormula: on Frm + equ_nrls ----------------------";
neuper@37906
   139
"--------- appendFormula: on Frm + equ_nrls ----------------------";
neuper@37906
   140
"--------- appendFormula: on Frm + equ_nrls ----------------------";
neuper@37906
   141
 states:=[];
neuper@41970
   142
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   143
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   144
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   145
 Iterator 1; moveActiveRoot 1;
neuper@37906
   146
 autoCalculate 1 CompleteCalcHead;
neuper@37906
   147
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
neuper@37906
   148
 appendFormula 1 "2+ -1 + x = 2"; refFormula 1 (get_pos 1 1);
neuper@37906
   149
neuper@37906
   150
 moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
neuper@37906
   151
neuper@37906
   152
 moveDown 1 ([1  ],Frm); refFormula 1 ([1,1],Frm); 
neuper@37906
   153
 moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res); 
neuper@37906
   154
 moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res); 
neuper@37906
   155
 moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res); 
neuper@37906
   156
 moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res); 
neuper@37906
   157
 moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res); 
neuper@37906
   158
 moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res); 
neuper@37906
   159
 val ((pt,_),_) = get_calc 1;
neuper@37906
   160
 if "2 + -1 + x = 2" = term2str (fst (get_obj g_result pt [1,6])) then()
neuper@38031
   161
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
neuper@37906
   162
neuper@37906
   163
 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
neuper@37906
   164
 val (_,(tac,_,_)::_) = get_calc 1;
neuper@37906
   165
 if tac = Rewrite_Set "norm_equation" then ()
neuper@38031
   166
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
neuper@37906
   167
 autoCalculate 1 CompleteCalc;
neuper@37906
   168
 val ((pt,_),_) = get_calc 1;
neuper@37906
   169
 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@38031
   170
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
neuper@37906
   171
neuper@37906
   172
neuper@37906
   173
"--------- appendFormula: on Res + NO deriv ----------------------";
neuper@37906
   174
"--------- appendFormula: on Res + NO deriv ----------------------";
neuper@37906
   175
"--------- appendFormula: on Res + NO deriv ----------------------";
neuper@37906
   176
 states:=[];
neuper@41970
   177
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   178
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   179
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   180
 Iterator 1; moveActiveRoot 1;
neuper@37906
   181
 autoCalculate 1 CompleteCalcHead;
neuper@37906
   182
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   183
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   184
neuper@37906
   185
 appendFormula 1 "x = 2";
neuper@37906
   186
 val ((pt,p),_) = get_calc 1;
neuper@37906
   187
 val str = pr_ptree pr_short pt;
neuper@37906
   188
 writeln str;
neuper@37906
   189
 if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" andalso p = ([1], Res)
neuper@37906
   190
 then ()
neuper@38031
   191
 else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
neuper@37906
   192
neuper@37906
   193
 fetchProposedTactic 1;
neuper@37906
   194
 val (_,(tac,_,_)::_) = get_calc 1;
neuper@37906
   195
 if tac = Rewrite_Set "Test_simplify" then ()
neuper@38031
   196
 else error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
neuper@37906
   197
 autoCalculate 1 CompleteCalc;
neuper@37906
   198
 val ((pt,_),_) = get_calc 1;
neuper@37906
   199
 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@38031
   200
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
neuper@37906
   201
neuper@37906
   202
neuper@37906
   203
"--------- appendFormula: on Res + late deriv --------------------";
neuper@37906
   204
"--------- appendFormula: on Res + late deriv --------------------";
neuper@37906
   205
"--------- appendFormula: on Res + late deriv --------------------";
neuper@37906
   206
 states:=[];
neuper@41970
   207
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   208
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   209
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   210
 Iterator 1; moveActiveRoot 1;
neuper@37906
   211
 autoCalculate 1 CompleteCalcHead;
neuper@37906
   212
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   213
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   214
neuper@37906
   215
 appendFormula 1 "x = 1";
neuper@37906
   216
 val ((pt,p),_) = get_calc 1;
neuper@37906
   217
 val str = pr_ptree pr_short pt;
neuper@37906
   218
 writeln str;
neuper@37906
   219
 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
   220
 then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
neuper@38031
   221
 else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
akargl@42176
   222
neuper@37906
   223
 fetchProposedTactic 1;
neuper@37906
   224
 val (_,(tac,_,_)::_) = get_calc 1;
neuper@37906
   225
 if tac = Check_Postcond ["linear", "univariate", "equation", "test"] then ()
neuper@38031
   226
 else error "inform.sml: diff.behav.appendFormula: Res + late d 2";
neuper@37906
   227
 autoCalculate 1 CompleteCalc;
neuper@37906
   228
 val ((pt,_),_) = get_calc 1;
neuper@37906
   229
 if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@38031
   230
 else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
neuper@37906
   231
neuper@37906
   232
neuper@37906
   233
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
neuper@37906
   234
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
neuper@37906
   235
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
neuper@37906
   236
 states:=[];
neuper@41970
   237
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   238
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   239
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   240
 Iterator 1; moveActiveRoot 1;
neuper@37906
   241
 autoCalculate 1 CompleteCalcHead;
neuper@37906
   242
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   243
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   244
 appendFormula 1 "[x = 3 + -2*1]";
neuper@37906
   245
 val ((pt,p),_) = get_calc 1;
neuper@37906
   246
 val str = pr_ptree pr_short pt;
neuper@37906
   247
 writeln str;
neuper@37906
   248
 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
   249
 else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
neuper@37906
   250
 autoCalculate 1 CompleteCalc;
neuper@37906
   251
 val ((pt,p),_) = get_calc 1;
neuper@37906
   252
 if "[x = 3 + -2 * 1]" = term2str (fst (get_obj g_result pt [])) then ()
neuper@37906
   253
 (*       ~~~~~~~~~~ simplify as last step in any script ?!*)
neuper@38031
   254
 else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
neuper@37906
   255
neuper@37906
   256
neuper@37906
   257
neuper@37906
   258
"--------- replaceFormula: on Res + = ----------------------------";
neuper@37906
   259
"--------- replaceFormula: on Res + = ----------------------------";
neuper@37906
   260
"--------- replaceFormula: on Res + = ----------------------------";
neuper@37906
   261
 states:=[];
neuper@41970
   262
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   263
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   264
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   265
 Iterator 1; moveActiveRoot 1;
neuper@37906
   266
 autoCalculate 1 CompleteCalcHead;
neuper@37906
   267
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   268
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   269
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
neuper@37906
   270
neuper@37906
   271
 replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
neuper@37906
   272
 val ((pt,_),_) = get_calc 1;
neuper@37906
   273
 val str = pr_ptree pr_short pt;
neuper@37906
   274
 writeln str;
akargl@42176
   275
akargl@42176
   276
(*============ inhibit exn AK110725 ==============================================
akargl@42176
   277
(* 2nd string should be the same as 1st one *)
akargl@42176
   278
".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   1 + x + -1 * 2 = 0\n2.3.   1 + (x + -1 * 2) = 0\n2.4.   1 + (x + -2) = 0\n2.5.   1 + (x + -2 * 1) = 0\n2.6.   1 + x + -2 * 1 = 0\n";
akargl@42176
   279
".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   -1 * 2 + (x + 1) = 0\n2.3.   -1 * 2 + (1 + x) = 0\n2.4.   1 + (-1 * 2 + x) = 0\n2.5.   1 + (-2 + x) = 0\n2.6.   1 + (-2 * 1 + x) = 0\n";
akargl@42176
   280
 if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   -1 * 2 + (x + 1) = 0\n2.3.   -1 * 2 + (1 + x) = 0\n2.4.   1 + (-1 * 2 + x) = 0\n2.5.   1 + (-2 + x) = 0\n2.6.   1 + (-2 * 1 + x) = 0\n" then()
neuper@38031
   281
 else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
akargl@42176
   282
============ inhibit exn AK110725 ==============================================*)
akargl@42176
   283
neuper@37906
   284
 autoCalculate 1 CompleteCalc;
akargl@42176
   285
 val ((pt,pos as (p,_)),_) = get_calc 1;
akargl@42176
   286
 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst) (get_obj g_result pt p) then()
neuper@38031
   287
 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
neuper@37906
   288
 
neuper@37906
   289
neuper@37906
   290
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
neuper@37906
   291
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
neuper@37906
   292
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
neuper@37906
   293
 states:=[];
neuper@41970
   294
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   295
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   296
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   297
 Iterator 1; moveActiveRoot 1;
neuper@37906
   298
 autoCalculate 1 CompleteCalcHead;
neuper@37906
   299
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   300
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   301
neuper@37906
   302
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
neuper@37906
   303
 val ((pt,_),_) = get_calc 1;
neuper@37906
   304
 val str = pr_ptree pr_short pt;
neuper@37906
   305
 writeln str;
akargl@42176
   306
 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
   307
 else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
neuper@37906
   308
 autoCalculate 1 CompleteCalc;
akargl@42176
   309
 val ((pt,pos as (p,_)),_) = get_calc 1;
akargl@42176
   310
 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
neuper@38031
   311
 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
neuper@37906
   312
neuper@37906
   313
neuper@37906
   314
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
neuper@37906
   315
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
neuper@37906
   316
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
neuper@37906
   317
 states:=[];
neuper@41970
   318
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   319
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   320
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   321
 Iterator 1; moveActiveRoot 1;
neuper@37906
   322
 autoCalculate 1 CompleteCalcHead;
neuper@37906
   323
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   324
neuper@37906
   325
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
neuper@37906
   326
 val ((pt,_),_) = get_calc 1;
neuper@37906
   327
 val str = pr_ptree pr_short pt;
neuper@37906
   328
 writeln str;
akargl@42176
   329
 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
   330
 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
neuper@37906
   331
 autoCalculate 1 CompleteCalc;
akargl@42176
   332
 val ((pt,pos as (p,_)),_) = get_calc 1;
akargl@42176
   333
 if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
neuper@38031
   334
 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
neuper@37906
   335
neuper@37906
   336
neuper@37906
   337
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
   338
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
   339
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
   340
 states:=[];
neuper@41970
   341
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   342
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   343
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   344
 Iterator 1; moveActiveRoot 1;
neuper@37906
   345
 autoCalculate 1 CompleteCalc;
neuper@37906
   346
 moveActiveRoot 1; moveActiveDown 1;
neuper@37906
   347
 if get_pos 1 1 = ([1], Frm) then ()
neuper@38031
   348
 else error "inform.sml: diff.behav. cut calculation 1";
neuper@37906
   349
neuper@37906
   350
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
neuper@37906
   351
 val ((pt,p),_) = get_calc 1;
neuper@37906
   352
 val str = pr_ptree pr_short pt;
neuper@37906
   353
 writeln str;
neuper@37906
   354
 if p = ([1], Res) then ()
neuper@38031
   355
 else error "inform.sml: diff.behav. cut calculation 2";
neuper@37906
   356
neuper@37906
   357
neuper@37906
   358
(* 040307 copied from informtest.sml; ... old version 
neuper@37906
   359
 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
neuper@37906
   360
 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
neuper@37906
   361
 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
neuper@37906
   362
neuper@37906
   363
 val p = ([],Pbl);
neuper@37906
   364
 val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
neuper@37906
   365
	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
neuper@37906
   366
	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
neuper@37906
   367
	      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
neuper@37906
   368
	      (*^^^ these are the elements for the root-problem (in variants)*)
neuper@37906
   369
              (*vvv these are elements required for subproblems*)
neuper@37906
   370
	      "boundVariable a","boundVariable b","boundVariable alpha",
neuper@37906
   371
	      "interval {x::real. 0 <= x & x <= 2*r}",
neuper@37906
   372
	      "interval {x::real. 0 <= x & x <= 2*r}",
neuper@37906
   373
	      "interval {x::real. 0 <= x & x <= pi}",
neuper@37906
   374
	      "errorBound (eps=(0::real))"]
neuper@37906
   375
 (*specifying is not interesting for this example*)
neuper@38058
   376
 val spec = ("DiffApp", ["maximum_of","function"], 
neuper@37906
   377
	     ["DiffApp","max_by_calculus"]);
neuper@37906
   378
 (*the empty model with descriptions for user-guidance by Model_Problem*)
neuper@37906
   379
 val empty_model = [Given ["fixedValues []"],
neuper@37906
   380
		    Find ["maximum", "valuesFor"],
neuper@37906
   381
		    Relate ["relations []"]];
neuper@37906
   382
neuper@37906
   383
neuper@37906
   384
 (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
neuper@37906
   385
 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
neuper@37906
   386
 (*val nxt = ("Model_Problem", ...*)
neuper@37924
   387
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   388
neuper@37906
   389
 val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   390
 (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
neuper@37924
   391
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   392
(*[
neuper@37906
   393
(0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
neuper@37906
   394
(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
neuper@37906
   395
(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
neuper@37906
   396
(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
neuper@37906
   397
neuper@37906
   398
 (*the empty CalcHead is checked w.r.t the model and re-established as such*)
neuper@37906
   399
 val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, e_spec);
neuper@37924
   400
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@38031
   401
 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
   402
neuper@37906
   403
 (*there is one input to the model (could be more)*)
neuper@37906
   404
 val (b,pt,ocalhd) = 
neuper@37906
   405
     input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
neuper@37906
   406
			     Find ["maximum", "valuesFor"],
neuper@37906
   407
			     Relate ["relations"]], Pbl, e_spec);
neuper@37924
   408
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   409
 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
   410
 else error "informtest.sml: diff.behav. max 2";
neuper@37906
   411
neuper@37906
   412
 (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
neuper@37906
   413
 val (b,pt''''',ocalhd) = 
neuper@37906
   414
     input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
neuper@37906
   415
			     Find ["maximum A", "valuesFor [a,b]"],
neuper@37906
   416
			     Relate ["relations [A=a*b, a/2=r*sin alpha, \
neuper@37906
   417
				     \b/2=r*cos alpha]"]], Pbl, e_spec);
neuper@37924
   418
 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   419
 if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
neuper@37906
   420
neuper@37906
   421
 (*this input is complete in variant 1 (variant 3 does not work yet)*)
neuper@37906
   422
 val (b,pt''''',ocalhd) = 
neuper@37906
   423
     input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
neuper@37906
   424
			     Find ["maximum A", "valuesFor [a,b]"],
neuper@37906
   425
			     Relate ["relations [A=a*b, \
neuper@37906
   426
				     \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]], 
neuper@37906
   427
		      Pbl, e_spec);
neuper@37924
   428
 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   429
neuper@37906
   430
 modifycalcheadOK2xml 111 (bool2str b) ocalhd;
neuper@37906
   431
*)
neuper@37906
   432
neuper@37906
   433
"--------- syntax error ------------------------------------------";
neuper@37906
   434
"--------- syntax error ------------------------------------------";
neuper@37906
   435
"--------- syntax error ------------------------------------------";
neuper@37906
   436
 states:=[];
neuper@41970
   437
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   438
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   439
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   440
 Iterator 1; moveActiveRoot 1;
neuper@37906
   441
 autoCalculate 1 CompleteCalcHead;
neuper@37906
   442
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   443
 autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   444
neuper@37906
   445
 appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
neuper@37906
   446
 val ((pt,_),_) = get_calc 1;
neuper@37906
   447
 val str = pr_ptree pr_short pt;
neuper@37906
   448
 writeln str;
neuper@37906
   449
 if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" then ()
neuper@38031
   450
 else error "inform.sml: diff.behav.appendFormula: syntax error";
neuper@37906
   451
neuper@37906
   452
neuper@37906
   453
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   454
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   455
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   456
val (p,_,f,nxt,_,pt) = 
neuper@37906
   457
    CalcTreeTEST [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
neuper@37906
   458
val ifo = "solve(x+1=2,x)";
neuper@37906
   459
val (_,(_,c,(pt,p))) = inform ([],[],(pt,p)) "solve(x+1=2,x)";
neuper@37906
   460
show_pt pt;
neuper@37906
   461
val nxt = ("Apply_Method",Apply_Method ["Test","squ-equ-test-subpbl1"]);
neuper@37906
   462
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@37906
   463
if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
neuper@38031
   464
else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
neuper@37906
   465
neuper@37906
   466
neuper@37906
   467
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
   468
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
   469
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
   470
states:=[];
neuper@37906
   471
CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
neuper@37906
   472
Iterator 1;
neuper@37906
   473
moveActiveRoot 1;
neuper@37906
   474
replaceFormula 1 "solve(x+1=2,x)";
neuper@37906
   475
autoCalculate 1 CompleteCalc;
neuper@37906
   476
val ((pt,p),_) = get_calc 1;
neuper@37906
   477
show_pt pt;
neuper@37906
   478
if p = ([], Res) then ()
neuper@38031
   479
else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
neuper@37906
   480
neuper@37906
   481
neuper@37906
   482
"--------- inform [rational,simplification] ----------------------";
neuper@37906
   483
"--------- inform [rational,simplification] ----------------------";
neuper@37906
   484
"--------- inform [rational,simplification] ----------------------";
neuper@37906
   485
states:=[];
neuper@38083
   486
CalcTree [(["Term (4/x - 3/y - 1)", "normalform N"],
neuper@38058
   487
	   ("Rational",["rational","simplification"],
neuper@37906
   488
	    ["simplification","of_rationals"]))];
neuper@37906
   489
Iterator 1; moveActiveRoot 1;
neuper@37906
   490
autoCalculate 1 CompleteCalcHead;
neuper@37906
   491
autoCalculate 1 (Step 1);
neuper@37906
   492
autoCalculate 1 (Step 1);
neuper@37906
   493
autoCalculate 1 (Step 1);
neuper@37906
   494
autoCalculate 1 (Step 1);
neuper@37906
   495
"--- input the next formula that _should_ be presented by mat-engine";
neuper@37906
   496
appendFormula 1 "(4 * y + -3 * x) / (x * y) + -1";
neuper@37906
   497
val ((pt,p),_) = get_calc 1;
neuper@37906
   498
if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
neuper@38031
   499
else error ("inform.sml: [rational,simplification] 1");
neuper@37906
   500
neuper@37906
   501
"--- input the next formula that would be presented by mat-engine";
neuper@37906
   502
(*autoCalculate 1 (Step 1);*)
neuper@37906
   503
appendFormula 1 "(4 * y + -3 * x + -1 * (x * y)) / (x * y)";
neuper@37906
   504
val ((pt,p),_) = get_calc 1;
neuper@37906
   505
if p = ([5], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
neuper@38031
   506
else error ("inform.sml: [rational,simplification] 2");
neuper@37906
   507
neuper@37906
   508
"--- input the exact final result";(*TODO: Exception- LIST "last_elem" raised*)
neuper@37906
   509
appendFormula 1 "(-3 * x + 4 * y + -1 * x * y) / (x * y)";
neuper@37906
   510
val ((pt,p),_) = get_calc 1;
neuper@37906
   511
if p = ([6], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
neuper@38031
   512
else error ("inform.sml: [rational,simplification] 3");
neuper@37906
   513
show_pt pt;
neuper@37906
   514
neuper@37906
   515
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   516
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   517
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   518
val t = str2term "Diff (x^^^2 + x + 1, x)";
neuper@37906
   519
case t of Const ("Diff.Diff", _) $ _ => ()
neuper@37906
   520
	| _ => raise 
neuper@37906
   521
	      error "diff.sml behav.changed for CAS Diff (..., x)";
neuper@37906
   522
atomty t;
neuper@37906
   523
"-----------------------------------------------------------------";
neuper@37906
   524
(*1>*)states:=[];
neuper@37906
   525
(*2>*)CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
neuper@37906
   526
(*3>*)Iterator 1;moveActiveRoot 1;
neuper@37906
   527
"----- here the Headline has been finished";
neuper@37906
   528
(*4>*)moveActiveFormula 1 ([],Pbl);
neuper@37906
   529
(*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
neuper@37906
   530
val ((pt,_),_) = get_calc 1;
neuper@37906
   531
val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
neuper@37926
   532
val NONE = env;
neuper@37926
   533
val (SOME istate, NONE) = loc;
neuper@37906
   534
print_depth 5;
neuper@37906
   535
writeln"-----------------------------------------------------------";
neuper@37906
   536
spec;
neuper@37924
   537
writeln (itms2str_ ctxt probl);
neuper@37924
   538
writeln (itms2str_ ctxt meth);
akargl@42209
   539
akargl@42176
   540
(*============ inhibit exn AK110725 ==============================================
akargl@42209
   541
(* ERROR: Argument: istate : istate * Proof.context Reason: 
akargl@42209
   542
        Can't unify istate to istate * Proof.context *)
neuper@37906
   543
writeln (istate2str istate);
akargl@42176
   544
============ inhibit exn AK110725 ==============================================*)
neuper@37906
   545
neuper@37906
   546
print_depth 3;
neuper@37906
   547
neuper@37906
   548
refFormula 1 ([],Pbl) (*--> correct CalcHead*);
neuper@37906
   549
 (*081016 NOT necessary (but leave it in Java):*)
neuper@37906
   550
(*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
neuper@37906
   551
"----- here the CalcHead has been completed --- ONCE MORE ?????";
neuper@37906
   552
neuper@37906
   553
(***difference II***)
neuper@37906
   554
val ((pt,p),_) = get_calc 1;
neuper@37906
   555
(*val p = ([], Pbl)*)
neuper@37906
   556
val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
neuper@37926
   557
val NONE = env;
neuper@37926
   558
val (SOME istate, NONE) = loc;
akargl@42176
   559
(*============ inhibit exn AK110725 ==============================================
akargl@42176
   560
(* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
neuper@37906
   561
print_depth 5; writeln (istate2str istate);  print_depth 3;
akargl@42176
   562
============ inhibit exn AK110725 ==============================================*)
neuper@37906
   563
(*ScrState ([],
neuper@37926
   564
 [], NONE,
neuper@37906
   565
 ??.empty, Sundef, false)*)
neuper@37906
   566
print_depth 5; spec; print_depth 3;
neuper@38050
   567
(*("Isac",
neuper@37906
   568
      ["derivative_of", "function"],
neuper@37906
   569
      ["diff", "differentiate_on_R"]) : spec*)
neuper@37924
   570
writeln (itms2str_ ctxt probl);
neuper@37906
   571
(*[
neuper@37906
   572
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   573
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   574
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37924
   575
writeln (itms2str_ ctxt meth);
neuper@37906
   576
(*[
neuper@37906
   577
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   578
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   579
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37906
   580
writeln"-----------------------------------------------------------";
neuper@37906
   581
(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
neuper@37906
   582
(*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
neuper@37906
   583
autoCalculate 1 CompleteCalc;
neuper@37906
   584
val ((pt,p),_) = get_calc 1;
neuper@37906
   585
val Form res = (#1 o pt_extract) (pt, ([],Res));
neuper@37906
   586
show_pt pt;
neuper@37906
   587
if p = ([], Res) andalso term2str res = "1 + 2 * x" then ()
neuper@38031
   588
else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
neuper@37906
   589
neuper@37906
   590
neuper@37906
   591
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   592
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   593
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   594
(*the following input is copied from BridgeLog Java <==> SML,
neuper@37906
   595
  omitting unnecessary inputs*)
neuper@37906
   596
(*1>*)states:=[];
akargl@42176
   597
(*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac",["derivative_of","function"],["diff","differentiate_on_R"]))];
neuper@37906
   598
(*3>*)Iterator 1; moveActiveRoot 1;
neuper@37906
   599
neuper@37906
   600
(*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
neuper@37906
   601
(***difference II***)
neuper@37906
   602
val ((pt,_),_) = get_calc 1;
neuper@37906
   603
val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
neuper@37926
   604
val NONE = env;
neuper@37926
   605
val (SOME istate, NONE) = loc;
akargl@42176
   606
(*============ inhibit exn AK110725 ==============================================
akargl@42176
   607
(* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
neuper@37906
   608
print_depth 5; writeln (istate2str istate);  print_depth 3;
akargl@42176
   609
============ inhibit exn AK110725 ==============================================*)
neuper@37906
   610
(*ScrState ([],
neuper@37926
   611
 [], NONE,
neuper@37906
   612
 ??.empty, Sundef, false)*)
neuper@37906
   613
print_depth 5; spec; print_depth 3;
neuper@38050
   614
(*("Isac",
neuper@37906
   615
      ["derivative_of", "function"],
neuper@37906
   616
      ["diff", "differentiate_on_R"]) : spec*)
neuper@37924
   617
writeln (itms2str_ ctxt probl);
neuper@37906
   618
(*[
neuper@37906
   619
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   620
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   621
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37924
   622
writeln (itms2str_ ctxt meth);
neuper@37906
   623
(*[
neuper@37906
   624
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   625
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   626
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37906
   627
writeln"-----------------------------------------------------------";
neuper@37906
   628
(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
neuper@37906
   629
autoCalculate 1 (Step 1);
neuper@37906
   630
val ((pt,p),_) = get_calc 1;
neuper@37906
   631
val Form res = (#1 o pt_extract) (pt, p);
neuper@37906
   632
if term2str res = "d_d x (x ^^^ 2 + x + 1)" then ()
neuper@38031
   633
else error "diff.sml Diff (x^2 + x + 1, x) from exp";
neuper@37906
   634
neuper@37906
   635
neuper@37906
   636
"--------- init_form, start with <NEW> (CAS input) ---------------";
neuper@37906
   637
"--------- init_form, start with <NEW> (CAS input) ---------------";
neuper@37906
   638
"--------- init_form, start with <NEW> (CAS input) ---------------";
neuper@37906
   639
states:=[];
neuper@37906
   640
CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
neuper@37906
   641
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   642
[[from sml:  1 
neuper@37906
   643
[[from sml: <CALCTREE>
neuper@37906
   644
[[from sml:    <CALCID> 1 </CALCID>
neuper@37906
   645
[[from sml: </CALCTREE>
neuper@37906
   646
[[from sml: @@@@@end@@@@@*)
neuper@37906
   647
Iterator 1;
neuper@37906
   648
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   649
[[from sml:  1 
neuper@37906
   650
[[from sml: <ADDUSER>
neuper@37906
   651
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   652
[[from sml:   <USERID> 1 </USERID>
neuper@37906
   653
[[from sml: </ADDUSER>
neuper@37906
   654
[[from sml: @@@@@end@@@@@*)
neuper@37906
   655
moveActiveRoot 1;
neuper@37906
   656
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   657
[[from sml:  1 
neuper@37906
   658
[[from sml: <CALCITERATOR>
neuper@37906
   659
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   660
[[from sml:   <POSITION>
neuper@37906
   661
[[from sml:     <INTLIST>
neuper@37906
   662
[[from sml:     </INTLIST>
neuper@37906
   663
[[from sml:     <POS> Pbl </POS>
neuper@37906
   664
[[from sml:   </POSITION>
neuper@37906
   665
[[from sml: </CALCITERATOR>
neuper@37906
   666
[[from sml: @@@@@end@@@@@*)
neuper@37906
   667
getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
neuper@37906
   668
(*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
neuper@37906
   669
[[from sml:  1 
neuper@37906
   670
[[from sml: <GETELEMENTSFROMTO>
neuper@37906
   671
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   672
[[from sml:   <FORMHEADS>
neuper@37906
   673
[[from sml:     <CALCFORMULA>
neuper@37906
   674
[[from sml:       <POSITION>
neuper@37906
   675
[[from sml:         <INTLIST>
neuper@37906
   676
[[from sml:         </INTLIST>
neuper@37906
   677
[[from sml:         <POS> Pbl </POS>
neuper@37906
   678
[[from sml:       </POSITION>
neuper@37906
   679
[[from sml:       <FORMULA>
neuper@37906
   680
[[from sml:         <MATHML>
neuper@37906
   681
[[from sml:           <ISA> ________________________________________________ </ISA>
neuper@37906
   682
[[from sml:         </MATHML>
neuper@37906
   683
[[from sml: 
neuper@37906
   684
[[from sml:       </FORMULA>
neuper@37906
   685
[[from sml:     </CALCFORMULA>
neuper@37906
   686
[[from sml:   </FORMHEADS>
neuper@37906
   687
[[from sml: </GETELEMENTSFROMTO>
neuper@37906
   688
[[from sml: @@@@@end@@@@@*)
neuper@37906
   689
refFormula 1 ([],Pbl);
neuper@37906
   690
(*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
neuper@37906
   691
[[from sml:  1 
neuper@37906
   692
[[from sml: <REFFORMULA>
neuper@37906
   693
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   694
[[from sml:   <CALCHEAD status = "incorrect">
neuper@37906
   695
[[from sml:     <POSITION>
neuper@37906
   696
[[from sml:       <INTLIST>
neuper@37906
   697
[[from sml:       </INTLIST>
neuper@37906
   698
[[from sml:       <POS> Pbl </POS>
neuper@37906
   699
[[from sml:     </POSITION>
neuper@37906
   700
[[from sml:     <HEAD>
neuper@37906
   701
[[from sml:       <MATHML>
neuper@37906
   702
[[from sml:         <ISA> Problem (e_domID, [e_pblID]) </ISA>
neuper@37906
   703
[[from sml:       </MATHML>
neuper@37906
   704
[[from sml:     </HEAD>
neuper@37906
   705
[[from sml:     <MODEL>
neuper@37906
   706
[[from sml:       <GIVEN>  </GIVEN>
neuper@37906
   707
[[from sml:       <WHERE>  </WHERE>
neuper@37906
   708
[[from sml:       <FIND>  </FIND>
neuper@37906
   709
[[from sml:       <RELATE>  </RELATE>
neuper@37906
   710
[[from sml:     </MODEL>
neuper@37906
   711
[[from sml:     <BELONGSTO> Pbl </BELONGSTO>
neuper@37906
   712
[[from sml:     <SPECIFICATION>
neuper@37906
   713
[[from sml:       <THEORYID> e_domID </THEORYID>
neuper@37906
   714
[[from sml:       <PROBLEMID>
neuper@37906
   715
[[from sml:         <STRINGLIST>
neuper@37906
   716
[[from sml:           <STRING> e_pblID </STRING>
neuper@37906
   717
[[from sml:         </STRINGLIST>
neuper@37906
   718
[[from sml:       </PROBLEMID>
neuper@37906
   719
[[from sml:       <METHODID>
neuper@37906
   720
[[from sml:         <STRINGLIST>
neuper@37906
   721
[[from sml:           <STRING> e_metID </STRING>
neuper@37906
   722
[[from sml:         </STRINGLIST>
neuper@37906
   723
[[from sml:       </METHODID>
neuper@37906
   724
[[from sml:     </SPECIFICATION>
neuper@37906
   725
[[from sml:   </CALCHEAD>
neuper@37906
   726
[[from sml: </REFFORMULA>
neuper@37906
   727
[[from sml: @@@@@end@@@@@*)
neuper@37906
   728
moveActiveFormula 1 ([],Pbl);
neuper@37906
   729
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   730
[[from sml:  1 
neuper@37906
   731
[[from sml: <CALCITERATOR>
neuper@37906
   732
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   733
[[from sml:   <POSITION>
neuper@37906
   734
[[from sml:     <INTLIST>
neuper@37906
   735
[[from sml:     </INTLIST>
neuper@37906
   736
[[from sml:     <POS> Pbl </POS>
neuper@37906
   737
[[from sml:   </POSITION>
neuper@37906
   738
[[from sml: </CALCITERATOR>
neuper@37906
   739
[[from sml: @@@@@end@@@@@*)
neuper@37906
   740
replaceFormula 1 "Simplify (1+2)";
neuper@37906
   741
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   742
[[from sml:  1 
neuper@37906
   743
[[from sml: <REPLACEFORMULA>
neuper@37906
   744
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   745
[[from sml:   <CALCCHANGED>
neuper@37906
   746
[[from sml:     <UNCHANGED>
neuper@37906
   747
[[from sml:       <INTLIST>
neuper@37906
   748
[[from sml:       </INTLIST>
neuper@37906
   749
[[from sml:       <POS> Pbl </POS>
neuper@37906
   750
[[from sml:     </UNCHANGED>
neuper@37906
   751
[[from sml:     <DELETED>
neuper@37906
   752
[[from sml:       <INTLIST>
neuper@37906
   753
[[from sml:       </INTLIST>
neuper@37906
   754
[[from sml:       <POS> Pbl </POS>
neuper@37906
   755
[[from sml:     </DELETED>
neuper@37906
   756
[[from sml:     <GENERATED>
neuper@37906
   757
[[from sml:       <INTLIST>
neuper@37906
   758
[[from sml:       </INTLIST>
neuper@37906
   759
[[from sml:       <POS> Met </POS>                           DIFFERENCE: Pbl
neuper@37906
   760
[[from sml:     </GENERATED>
neuper@37906
   761
[[from sml:   </CALCCHANGED>
neuper@37906
   762
[[from sml: </REPLACEFORMULA>
neuper@37906
   763
[[from sml: @@@@@end@@@@@*)
neuper@37906
   764
getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(*              DIFFERENCE: Pbl*);
neuper@37906
   765
(*@@@@@begin@@@@@
neuper@37906
   766
 1
neuper@37906
   767
<GETELEMENTSFROMTO>
neuper@37906
   768
  <CALCID> 1 </CALCID>
neuper@37906
   769
  <FORMHEADS>
neuper@37906
   770
    <CALCFORMULA>
neuper@37906
   771
      <POSITION>
neuper@37906
   772
        <INTLIST>
neuper@37906
   773
        </INTLIST>
neuper@37906
   774
        <POS> Pbl </POS>
neuper@37906
   775
      </POSITION>
neuper@37906
   776
      <FORMULA>
neuper@37906
   777
        <MATHML>
neuper@37906
   778
          <ISA> Simplify (1 + 2) </ISA>                      WORKS !!!!!
neuper@37906
   779
        </MATHML>
neuper@37906
   780
      </FORMULA>
neuper@37906
   781
    </CALCFORMULA>
neuper@37906
   782
  </FORMHEADS>
neuper@37906
   783
</GETELEMENTSFROMTO>
neuper@37906
   784
@@@@@end@@@@@*)
neuper@37906
   785
getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
neuper@37906
   786
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   787
[[from sml:  1 
neuper@37906
   788
[[from sml: <SYSERROR>
neuper@37906
   789
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   790
[[from sml:   <ERROR> error in getFormulaeFromTo </ERROR>
neuper@37906
   791
[[from sml: </SYSERROR>
neuper@37906
   792
[[from sml: @@@@@end@@@@@*)
neuper@37906
   793
(*step into getFormulaeFromTo --- bug corrected...*)
neuper@42423
   794
neuper@42423
   795
"--------- build fun check_err_patt ------------------------------";
neuper@42423
   796
"--------- build fun check_err_patt ------------------------------";
neuper@42423
   797
"--------- build fun check_err_patt ------------------------------";
neuper@42426
   798
val subst = [(str2term "bdv", str2term "x")]: subst;
neuper@42423
   799
val rls = norm_Rational
neuper@42423
   800
val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
neuper@42423
   801
val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
neuper@42423
   802
val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "1 / 2");
neuper@42423
   803
neuper@42426
   804
val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
neuper@42423
   805
  rew_sub thy 1 [] e_rew_ord e_rls false [] (Trueprop $ pat) res;
neuper@42423
   806
if rewritten then NONE else SOME "e_errpatID";
neuper@42423
   807
neuper@42423
   808
val norm_res = case rewrite_set_ (Isac()) false rls res' of
neuper@42423
   809
  NONE => res'
neuper@42423
   810
| SOME (norm_res, _) => norm_res
neuper@42423
   811
neuper@42423
   812
val norm_inf = case rewrite_set_ (Isac()) false rls inf of
neuper@42423
   813
  NONE => inf
neuper@42423
   814
| SOME (norm_inf, _) => norm_inf;
neuper@42423
   815
neuper@42423
   816
res' = inf;
neuper@42423
   817
norm_res = norm_inf;
neuper@42423
   818
neuper@42423
   819
val pat = parse_patt @{theory} "(?a + ?b)/?a = ?b";
neuper@42423
   820
val (res, inf) = (str2term "(2 + 3)/2", str2term "3");
neuper@42426
   821
if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   822
then () else error "error patt example1 changed";
neuper@42423
   823
neuper@42423
   824
val pat = parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
neuper@42423
   825
val (res, inf) = (str2term "(2 + 3)/(2 + 4)", str2term "3 / 4");
neuper@42426
   826
if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   827
then () else error "error patt example2 changed";
neuper@42423
   828
neuper@42423
   829
val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
neuper@42423
   830
val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
neuper@42426
   831
if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   832
then () else error "error patt example3 changed";
neuper@42423
   833
neuper@42423
   834
val inf =  str2term "1 / 2";
neuper@42426
   835
if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   836
then () else error "error patt example3 changed";
neuper@42423
   837
neuper@42426
   838
"--------- build fun check_err_patt ?bdv -------------------------";
neuper@42426
   839
"--------- build fun check_err_patt ?bdv -------------------------";
neuper@42426
   840
"--------- build fun check_err_patt ?bdv -------------------------";
neuper@42426
   841
val subst = [(str2term "bdv", str2term "x")]: subst;
neuper@42426
   842
val t = str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))";
neuper@42426
   843
val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
neuper@42426
   844
if term2str t = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3" then ()
neuper@42426
   845
else error "build fun check_err_patt ?bdv changed 1"; 
neuper@42423
   846
neuper@42426
   847
val rls = norm_diff
neuper@42426
   848
val pat = parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)"; 
neuper@42426
   849
val (res, inf) = (str2term "2 * x + d_d x (sin (x ^^^ 4))", str2term "2 * x + cos (4 * x ^^^ 3)");
neuper@42426
   850
neuper@42426
   851
val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
neuper@42426
   852
  rew_sub thy 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) res;
neuper@42426
   853
if term2str res' = "2 * x + cos (d_d x (x ^^^ 4))" andalso rewritten then ()
neuper@42426
   854
else error "build fun check_err_patt ?bdv changed 2";
neuper@42426
   855
neuper@42426
   856
val norm_res = case rewrite_set_inst_ (Isac()) false subst rls  res' of
neuper@42426
   857
  NONE => res'
neuper@42426
   858
| SOME (norm_res, _) => norm_res;
neuper@42426
   859
if term2str norm_res = "2 * x + cos (4 * x ^^^ 3)" then ()
neuper@42426
   860
else error "build fun check_err_patt ?bdv changed 3";
neuper@42426
   861
neuper@42426
   862
val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
neuper@42426
   863
  NONE => inf
neuper@42426
   864
| SOME (norm_inf, _) => norm_inf;
neuper@42426
   865
if term2str norm_inf = "2 * x + cos (4 * x ^^^ 3)" then ()
neuper@42426
   866
else error "build fun check_err_patt ?bdv changed 4";
neuper@42426
   867
neuper@42426
   868
res' = inf;
neuper@42426
   869
if norm_res = norm_inf then ()
neuper@42426
   870
else error "build fun check_err_patt ?bdv changed 5";
neuper@42426
   871
neuper@42426
   872
if check_err_patt (res, inf) (subst: subst) ("errpatID": errpatID, pat) rls = SOME "errpatID"
neuper@42426
   873
then () else error "error patt example1 changed";
neuper@42426
   874
neuper@42428
   875
"--------- build fun check_error_patterns ------------------------";
neuper@42428
   876
"--------- build fun check_error_patterns ------------------------";
neuper@42428
   877
"--------- build fun check_error_patterns ------------------------";
neuper@42428
   878
val (res, inf) =
neuper@42428
   879
  (str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))",
neuper@42428
   880
   str2term "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)");
neuper@42428
   881
val {errpats, nrls = rls, scr = Script prog, ...} = get_met ["diff", "differentiate_on_R"]
neuper@42426
   882
neuper@42428
   883
val env = [(str2term "v_v", str2term "x")];
neuper@42428
   884
val errpats =
neuper@42428
   885
  [e_errpat, (*generalised for testing*)
neuper@42428
   886
   ("chain-rule-diff-both",
neuper@42428
   887
     [parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
neuper@42428
   888
      parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
neuper@42428
   889
      parse_patt @{theory} "d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)",
neuper@42428
   890
      parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
neuper@42428
   891
      parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
neuper@42428
   892
     [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain}, 
neuper@42428
   893
      @{thm diff_ln_chain}, @{thm  diff_exp_chain}])]: errpat list;
neuper@42428
   894
neuper@42428
   895
case check_error_patterns (res, inf) (prog, env) (errpats, rls) of SOME _ => () 
neuper@42428
   896
| NONE => error "check_error_patterns broken";
neuper@42428
   897
neuper@42428
   898
neuper@42428
   899
"--------- embed fun check_error_patterns ------------------------";
neuper@42428
   900
"--------- embed fun check_error_patterns ------------------------";
neuper@42428
   901
"--------- embed fun check_error_patterns ------------------------";
neuper@42428
   902
states:=[];
neuper@42428
   903
CalcTree
neuper@42428
   904
[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
neuper@42428
   905
  ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
neuper@42428
   906
Iterator 1;
neuper@42428
   907
moveActiveRoot 1;
neuper@42428
   908
autoCalculate 1 CompleteCalcHead;
neuper@42428
   909
autoCalculate 1 (Step 1);
neuper@42428
   910
autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
neuper@42428
   911
(*autoCalculate 1 (Step 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
neuper@42428
   912
neuper@42428
   913
"~~~~~ fun appendFormula, args:"; val (cI, (ifo:cterm')) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
neuper@42428
   914
val cs = get_calc cI
neuper@42428
   915
val pos as (_,p_) = get_pos cI 1; (*pos = ([1], Res)*)
neuper@42428
   916
val cs' = 
neuper@42428
   917
    case step pos cs of
neuper@42428
   918
	    ("ok", cs') => cs';
neuper@42428
   919
neuper@42428
   920
val (_, _, (pt, ([2], Res))) = cs';
neuper@42428
   921
(*show_pt pt;
neuper@42428
   922
  [(([], Frm), Diff (x ^^^ 2 + sin (x ^^^ 4), x)),
neuper@42428
   923
   (([1], Frm), d_d x (x ^^^ 2 + sin (x ^^^ 4))),
neuper@42428
   924
   (([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))), <<=== input follos: "...+ cos(4.x^3)"
neuper@42428
   925
   (([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4))] *)
neuper@42428
   926
neuper@42428
   927
"~~~~~ fun inform, args:"; val ((cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate'), istr) =
neuper@42428
   928
  (cs', (encode ifo));
neuper@42428
   929
val 	SOME f_in = parse (assoc_thy "Isac") istr
neuper@42428
   930
val f_in = term_of f_in
neuper@42428
   931
val pos_pred = lev_back' pos
neuper@42428
   932
			(* f_pred ---"step pos cs"---> f_succ in appendFormula
neuper@42428
   933
   TODO.WN120517: one starting point for redesign of pos' *)
neuper@42428
   934
val (f_pred, f_succ) = (get_pred_formula (pt, pos_pred), get_pred_formula (pt, pos));
neuper@42428
   935
	
neuper@42428
   936
term2str f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
neuper@42428
   937
term2str f_succ = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)";
neuper@42428
   938
neuper@42428
   939
			f_succ = f_in; (* = false*)
neuper@42428
   940
cas_input f_in; (* = NONE*)
neuper@42428
   941
val msg_calcstate' = compare_step ([], [], (pt, pos_pred)) f_in
neuper@42428
   942
val ("no derivation found", calcstate') = msg_calcstate';
neuper@42428
   943
			                 val pp = par_pblobj pt p
neuper@42428
   944
			                 val {errpats, nrls, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
neuper@42428
   945
			                 val ScrState (env, _, _, _, _, _) = get_istate pt pos;
neuper@42428
   946
                 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
neuper@42428
   947
			                   SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
neuper@42428
   948
			                 | NONE => msg_calcstate';
neuper@42428
   949
neuper@42428
   950
"~~~~~ from inform return val:"; val () = ();
neuper@42428
   951
case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
neuper@42428
   952
			  SOME errpatID => ()
neuper@42428
   953
			| NONE => error "check_error_patterns broken";
neuper@42428
   954
neuper@42428
   955
"--- final check:";
neuper@42428
   956
case inform cs' (encode ifo) of
neuper@42428
   957
  ("error pattern #chain-rule-diff-both#", calcstate') => ()
neuper@42428
   958
| _ => error "inform with (positive) check_error_patterns broken"
neuper@42428
   959
neuper@42430
   960
"--------- embed fun find_fillpatterns ---------------------------";
neuper@42430
   961
"--------- embed fun find_fillpatterns ---------------------------";
neuper@42430
   962
"--------- embed fun find_fillpatterns ---------------------------";
neuper@42430
   963
states:=[];
neuper@42430
   964
CalcTree
neuper@42430
   965
[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
neuper@42430
   966
  ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
neuper@42430
   967
Iterator 1;
neuper@42430
   968
moveActiveRoot 1;
neuper@42430
   969
autoCalculate 1 CompleteCalcHead;
neuper@42430
   970
autoCalculate 1 (Step 1);
neuper@42430
   971
autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
neuper@42430
   972
appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)";
neuper@42430
   973
  (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
neuper@42430
   974
  (*TODO BACK TO <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
neuper@42430
   975
neuper@42430
   976
"~~~~~ fun FindFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
neuper@42430
   977
  val ((pt, _), _) = get_calc cI
neuper@42430
   978
				val pos = get_pos cI 1;
neuper@42430
   979
			"~~~~~ fun find_fillpatterns, args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
neuper@42430
   980
	    val f_curr = get_pred_formula (pt, pos); (* = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"*)
neuper@42430
   981
    val pp = par_pblobj pt p
neuper@42430
   982
			    val {errpats, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
neuper@42430
   983
    val ScrState (env, _, _, _, _, _) = get_istate pt pos
neuper@42430
   984
    val subst = get_bdv_subst prog env
neuper@42430
   985
    val errpatthms = errpats
neuper@42430
   986
      |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
neuper@42430
   987
      |> map (#3: errpat -> thm list)
neuper@42430
   988
      |> flat;
neuper@42430
   989
neuper@42430
   990
case map (get_fillpats subst f_curr errpatID) errpatthms |> flat of
neuper@42430
   991
 ("fill-d_d-arg",
neuper@42430
   992
  "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@42430
   993
    :: _ => ()
neuper@42430
   994
| _ => error "find_fillpatterns changed"
neuper@42430
   995
neuper@42430
   996
"~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
neuper@42430
   997
  (subst, f_curr, errpatID, hd errpatthms);
neuper@42430
   998
        val thmDeriv = Thm.get_name_hint thm
neuper@42430
   999
        val (part, thyID) = thy_containing_thm thmDeriv
neuper@42430
  1000
        val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
neuper@42430
  1001
        val Hthm {fillpats, ...} = get_the theID
neuper@42430
  1002
        val some = map (get_fillform subst form errpatID) fillpats;
neuper@42430
  1003
neuper@42430
  1004
case some |> filter is_some |> map the of
neuper@42430
  1005
  ("fill-d_d-arg",
neuper@42430
  1006
  "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@42430
  1007
    :: _ => ()
neuper@42430
  1008
| _ => error "get_fillpats changed"
neuper@42430
  1009