test/Tools/isac/Interpret/error-pattern.sml
author Walther Neuper <walther.neuper@jku.at>
Fri, 01 May 2020 15:28:40 +0200
changeset 59921 0766dade4a78
parent 59920 33913fe24685
child 59942 d6261de56fb0
permissions -rw-r--r--
separate Solve_Step.check, repair ALL of Test_Isac_Short
walther@59909
     1
(* Title: "Interpret/error-pattern.sml"
akargl@42176
     2
   Author: Walther Neuper 060225,
neuper@37906
     3
   (c) due to copyright terms 
walther@59860
     4
walther@59860
     5
Strange ERROR "Undefined fact: "all_left""
neuper@37906
     6
*)
neuper@37906
     7
neuper@37906
     8
"-----------------------------------------------------------------";
neuper@37906
     9
"table of contents -----------------------------------------------";
neuper@37906
    10
"-----------------------------------------------------------------";
neuper@37906
    11
"appendForm with miniscript with mini-subpbl:";
neuper@37906
    12
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@37906
    13
"--------- appendFormula: on Frm + equ_nrls ----------------------";
neuper@37906
    14
"--------- appendFormula: on Res + NO deriv ----------------------";
neuper@37906
    15
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
neuper@37906
    16
"replaceForm with miniscript with mini-subpbl:";
neuper@37906
    17
"--------- replaceFormula: on Res + = ----------------------------";
neuper@37906
    18
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
neuper@37906
    19
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
neuper@37906
    20
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
    21
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
    22
(* 040307 copied from informtest.sml ... old versions
neuper@37906
    23
"--------- maximum-example, UC: Modeling / modifyCalcHead --------";*)
neuper@37906
    24
"--------- syntax error ------------------------------------------";
neuper@37906
    25
"CAS-command:";
neuper@37906
    26
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
    27
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
walther@59772
    28
"--------- locate_input_term [rational,simplification] ----------------------";
neuper@37906
    29
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
    30
"--------- Take as 1st tac, start from exp -----------------------";
walther@59845
    31
"--------- implicit_take, start with <NEW> (CAS input) ---------------";
walther@59909
    32
"--------- build fun check_for' ------------------------------";
walther@59909
    33
"--------- build fun check_for' ?bdv -------------------------";
walther@59909
    34
"--------- build fun check_for ------------------------";
walther@59909
    35
"--------- embed fun check_for ------------------------";
walther@59909
    36
"--------- embed fun find_fill_patterns ---------------------------";
neuper@48895
    37
"--------- build fun is_exactly_equal, inputFillFormula ----------";
wneuper@59262
    38
"--------- fun appl_adds -----------------------------------------";
wneuper@59264
    39
"--------- fun concat_deriv --------------------------------------";
wneuper@59264
    40
"--------- handle an input formula -------------------------------";
wneuper@59264
    41
"--------- fun dropwhile' ----------------------------------------";
neuper@37906
    42
"-----------------------------------------------------------------";
neuper@37906
    43
"-----------------------------------------------------------------";
neuper@37906
    44
"-----------------------------------------------------------------";
neuper@37906
    45
neuper@37906
    46
neuper@37906
    47
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@37906
    48
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@37906
    49
"--------- appendFormula: on Res + equ_nrls ----------------------";
neuper@48790
    50
 val Prog sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
walther@59868
    51
 (writeln o UnparseC.term) sc;
neuper@48790
    52
 val Prog sc = (#scr o get_met) ["Test","solve_linear"];
walther@59868
    53
 (writeln o UnparseC.term) sc;
neuper@37906
    54
s1210629013@55445
    55
 reset_states ();
neuper@41970
    56
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
    57
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
    58
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
    59
 Iterator 1; moveActiveRoot 1;
wneuper@59248
    60
 autoCalculate 1 CompleteCalcHead;
walther@59747
    61
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
walther@59747
    62
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
    63
wneuper@59123
    64
 appendFormula 1 "-2 * 1 + (1 + x) = 0" (*|> Future.join*); refFormula 1 (get_pos 1 1);
neuper@37906
    65
 val ((pt,_),_) = get_calc 1;
wneuper@59279
    66
 val str = pr_ctree pr_short pt;
neuper@48895
    67
if str =
neuper@48895
    68
(".    ----- pblobj -----\n" ^
neuper@48895
    69
"1.   x + 1 = 2\n" ^
neuper@48895
    70
"2.   x + 1 + -1 * 2 = 0\n" ^
neuper@48895
    71
"2.1.   x + 1 + -1 * 2 = 0\n" ^
neuper@48895
    72
"2.2.   1 + x + -1 * 2 = 0\n" ^
neuper@48895
    73
"2.3.   1 + (x + -1 * 2) = 0\n" ^
neuper@48895
    74
"2.4.   1 + (x + -2) = 0\n" ^
neuper@48895
    75
"2.5.   1 + (x + -2 * 1) = 0\n" ^
neuper@48895
    76
"2.6.   1 + x + -2 * 1 = 0\n" ) then ()
neuper@48895
    77
else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
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;
walther@59868
    91
 if "-2 * 1 + (1 + x) = 0" = UnparseC.term (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_*)
neuper@48895
    95
(* <ERROR> error in kernel </ERROR> ALREADY IN 2009-2*)
neuper@48895
    96
(*========== inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 =============
neuper@37906
    97
 val (_,(tac,_,_)::_) = get_calc 1;
neuper@37906
    98
 if tac = Rewrite_Set "Test_simplify" then ()
neuper@38031
    99
 else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
neuper@48895
   100
============ inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 ============*)
akargl@42209
   101
wneuper@59248
   102
 autoCalculate 1 CompleteCalc;
neuper@37906
   103
 val ((pt,_),_) = get_calc 1;
walther@59868
   104
 if "[x = 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
neuper@38031
   105
 else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
wneuper@59248
   106
 (* autoCalculate 1 CompleteCalc;
neuper@37906
   107
   val ((pt,p),_) = get_calc 1;
neuper@37906
   108
   (writeln o istates2str) (get_obj g_loc pt [ ]);  
neuper@37906
   109
   (writeln o istates2str) (get_obj g_loc pt [1]);  
neuper@37906
   110
   (writeln o istates2str) (get_obj g_loc pt [2]);  
neuper@37906
   111
   (writeln o istates2str) (get_obj g_loc pt [3]);  
neuper@37906
   112
   (writeln o istates2str) (get_obj g_loc pt [3,1]);  
neuper@37906
   113
   (writeln o istates2str) (get_obj g_loc pt [3,2]);  
neuper@37906
   114
   (writeln o istates2str) (get_obj g_loc pt [4]);  
neuper@37906
   115
neuper@37906
   116
   *)
neuper@37906
   117
"----------------------------------------------------------";
akargl@42176
   118
walther@59907
   119
 val fod = Derive.do_one (@{theory "Isac_Knowledge"}) Atools_erls 
walther@59852
   120
		       ((#rules o Rule_Set.rep) Test_simplify)
akargl@42176
   121
		       (sqrt_right false (@{theory "Pure"})) NONE 
neuper@37906
   122
		       (str2term "x + 1 + -1 * 2 = 0");
walther@59906
   123
 (writeln o Derive.trtas2str) fod;
neuper@37906
   124
walther@59907
   125
 val ifod = Derive.do_one (@{theory "Isac_Knowledge"}) Atools_erls 
walther@59852
   126
		       ((#rules o Rule_Set.rep) Test_simplify)
akargl@42176
   127
		       (sqrt_right false (@{theory "Pure"})) NONE 
neuper@37906
   128
		       (str2term "-2 * 1 + (1 + x) = 0");
walther@59906
   129
 (writeln o Derive.trtas2str) ifod;
akargl@42176
   130
 fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
neuper@37906
   131
 val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
walther@59906
   132
 val der = fod' @ (map Derive.rev_deriv' rifod');
walther@59906
   133
 (writeln o Derive.trtas2str) der;
neuper@37906
   134
 "----------------------------------------------------------";
wneuper@59252
   135
DEconstrCalcTree 1;
neuper@37906
   136
neuper@37906
   137
"--------- appendFormula: on Frm + equ_nrls ----------------------";
neuper@37906
   138
"--------- appendFormula: on Frm + equ_nrls ----------------------";
neuper@37906
   139
"--------- appendFormula: on Frm + equ_nrls ----------------------";
s1210629013@55445
   140
 reset_states ();
neuper@41970
   141
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   142
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   143
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   144
 Iterator 1; moveActiveRoot 1;
wneuper@59248
   145
 autoCalculate 1 CompleteCalcHead;
walther@59747
   146
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
wneuper@59123
   147
 appendFormula 1 "2+ -1 + x = 2" (*|> Future.join*); refFormula 1 (get_pos 1 1);
neuper@37906
   148
neuper@37906
   149
 moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
neuper@37906
   150
neuper@37906
   151
 moveDown 1 ([1  ],Frm); refFormula 1 ([1,1],Frm); 
neuper@37906
   152
 moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res); 
neuper@37906
   153
 moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res); 
neuper@37906
   154
 moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res); 
neuper@37906
   155
 moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res); 
neuper@37906
   156
 moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res); 
neuper@37906
   157
 moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res); 
neuper@37906
   158
 val ((pt,_),_) = get_calc 1;
walther@59868
   159
 if "2 + -1 + x = 2" = UnparseC.term (fst (get_obj g_result pt [1,6])) then()
neuper@38031
   160
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
neuper@37906
   161
neuper@37906
   162
 fetchProposedTactic 1; (*takes Iterator 1 _1_*)
neuper@37906
   163
 val (_,(tac,_,_)::_) = get_calc 1;
wneuper@59253
   164
 case tac of Rewrite_Set "norm_equation" => ()
wneuper@59253
   165
 | _ => error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
wneuper@59248
   166
 autoCalculate 1 CompleteCalc;
neuper@37906
   167
 val ((pt,_),_) = get_calc 1;
walther@59868
   168
 if "[x = 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
neuper@38031
   169
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
wneuper@59252
   170
DEconstrCalcTree 1;
neuper@37906
   171
neuper@37906
   172
"--------- appendFormula: on Res + NO deriv ----------------------";
neuper@37906
   173
"--------- appendFormula: on Res + NO deriv ----------------------";
neuper@37906
   174
"--------- appendFormula: on Res + NO deriv ----------------------";
s1210629013@55445
   175
 reset_states ();
neuper@41970
   176
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   177
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   178
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   179
 Iterator 1; moveActiveRoot 1;
wneuper@59248
   180
 autoCalculate 1 CompleteCalcHead;
walther@59747
   181
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
walther@59747
   182
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   183
wneuper@59123
   184
 appendFormula 1 "x = 2" (*|> Future.join*);
neuper@37906
   185
 val ((pt,p),_) = get_calc 1;
wneuper@59279
   186
 val str = pr_ctree pr_short pt;
neuper@37906
   187
 writeln str;
neuper@37906
   188
 if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" andalso p = ([1], Res)
neuper@37906
   189
 then ()
neuper@38031
   190
 else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
neuper@37906
   191
neuper@37906
   192
 fetchProposedTactic 1;
neuper@37906
   193
 val (_,(tac,_,_)::_) = get_calc 1;
wneuper@59253
   194
 case tac of Rewrite_Set "Test_simplify" => ()
wneuper@59253
   195
 | _ => error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
wneuper@59248
   196
 autoCalculate 1 CompleteCalc;
neuper@37906
   197
 val ((pt,_),_) = get_calc 1;
walther@59868
   198
 if "[x = 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
neuper@38031
   199
 else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
wneuper@59252
   200
DEconstrCalcTree 1;
neuper@37906
   201
neuper@37906
   202
"--------- appendFormula: on Res + late deriv --------------------";
neuper@37906
   203
"--------- appendFormula: on Res + late deriv --------------------";
neuper@37906
   204
"--------- appendFormula: on Res + late deriv --------------------";
walther@59794
   205
(*cp with "fun me" to test/../lucas-interpreter.sml:
walther@59794
   206
 re-build: fun locate_input_term ---------------------------------------------------"; 
walther@59794
   207
*)
s1210629013@55445
   208
 reset_states ();
neuper@41970
   209
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   210
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   211
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   212
 Iterator 1; moveActiveRoot 1;
wneuper@59248
   213
 autoCalculate 1 CompleteCalcHead;
walther@59747
   214
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
walther@59747
   215
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   216
wneuper@59123
   217
 appendFormula 1 "x = 1" (*|> Future.join*);
neuper@37906
   218
 val ((pt,p),_) = get_calc 1;
wneuper@59279
   219
 val str = pr_ctree pr_short pt;
neuper@37906
   220
 writeln str;
neuper@37906
   221
 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
   222
 then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
neuper@38031
   223
 else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
akargl@42176
   224
neuper@37906
   225
 fetchProposedTactic 1;
neuper@37906
   226
 val (_,(tac,_,_)::_) = get_calc 1;
wneuper@59253
   227
 case tac of Check_Postcond ["LINEAR", "univariate", "equation", "test"] => ()
wneuper@59253
   228
 | _ => error "inform.sml: diff.behav.appendFormula: Res + late d 2";
wneuper@59248
   229
 autoCalculate 1 CompleteCalc;
neuper@37906
   230
 val ((pt,_),_) = get_calc 1;
walther@59868
   231
 if "[x = 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
neuper@38031
   232
 else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
wneuper@59252
   233
DEconstrCalcTree 1;
neuper@37906
   234
neuper@37906
   235
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
neuper@37906
   236
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
neuper@37906
   237
"--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
s1210629013@55445
   238
 reset_states ();
neuper@41970
   239
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   240
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   241
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   242
 Iterator 1; moveActiveRoot 1;
wneuper@59248
   243
 autoCalculate 1 CompleteCalcHead;
walther@59747
   244
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
walther@59747
   245
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
wneuper@59123
   246
 appendFormula 1 "[x = 3 + -2*1]" (*|> Future.join*);
neuper@37906
   247
 val ((pt,p),_) = get_calc 1;
wneuper@59279
   248
 val str = pr_ctree pr_short pt;
neuper@37906
   249
 writeln str;
neuper@37906
   250
 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
   251
 else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
wneuper@59248
   252
 autoCalculate 1 CompleteCalc;
neuper@37906
   253
 val ((pt,p),_) = get_calc 1;
walther@59868
   254
 if "[x = 3 + -2 * 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
neuper@37906
   255
 (*       ~~~~~~~~~~ simplify as last step in any script ?!*)
neuper@38031
   256
 else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
wneuper@59252
   257
DEconstrCalcTree 1;
neuper@37906
   258
neuper@37906
   259
"--------- replaceFormula: on Res + = ----------------------------";
neuper@37906
   260
"--------- replaceFormula: on Res + = ----------------------------";
neuper@37906
   261
"--------- replaceFormula: on Res + = ----------------------------";
s1210629013@55445
   262
 reset_states ();
neuper@41970
   263
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   264
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   265
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   266
 Iterator 1; moveActiveRoot 1;
wneuper@59248
   267
 autoCalculate 1 CompleteCalcHead;
walther@59747
   268
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
walther@59747
   269
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
walther@59747
   270
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
neuper@37906
   271
neuper@37906
   272
 replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
neuper@37906
   273
 val ((pt,_),_) = get_calc 1;
wneuper@59279
   274
 val str = pr_ctree pr_short pt;
akargl@42176
   275
neuper@48895
   276
(* before AK110725 this was
neuper@48895
   277
".    ----- pblobj -----\n
neuper@48895
   278
1.   x + 1 = 2\n
neuper@48895
   279
2.   x + 1 + -1 * 2 = 0\n
neuper@48895
   280
2.1.   x + 1 + -1 * 2 = 0\n
neuper@48895
   281
2.2.   1 + x + -1 * 2 = 0\n
neuper@48895
   282
2.3.   1 + (x + -1 * 2) = 0\n
neuper@48895
   283
2.4.   1 + (x + -2) = 0\n
neuper@48895
   284
2.5.   1 + (x + -2 * 1) = 0\n
neuper@48895
   285
2.6.   1 + x + -2 * 1 = 0\n";
neuper@48895
   286
*)
neuper@48895
   287
if str = 
neuper@48895
   288
".    ----- pblobj -----\n"^
neuper@48895
   289
"1.   x + 1 = 2\n"^
neuper@48895
   290
"2.   x + 1 + -1 * 2 = 0\n"^
neuper@48895
   291
"2.1.   x + 1 + -1 * 2 = 0\n"^
neuper@48895
   292
"2.2.   1 + x + -1 * 2 = 0\n"^
neuper@48895
   293
"2.3.   1 + (x + -1 * 2) = 0\n"^
neuper@48895
   294
"2.4.   1 + (x + -2) = 0\n"^
neuper@48895
   295
"2.5.   1 + (x + -2 * 1) = 0\n"^
neuper@48895
   296
"2.6.   1 + x + -2 * 1 = 0\n" then()
neuper@48895
   297
else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
akargl@42176
   298
wneuper@59248
   299
 autoCalculate 1 CompleteCalc;
akargl@42176
   300
 val ((pt,pos as (p,_)),_) = get_calc 1;
walther@59868
   301
 if pos = ([],Res) andalso "[x = 1]" = (UnparseC.term o fst) (get_obj g_result pt p) then()
neuper@38031
   302
 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
wneuper@59252
   303
DEconstrCalcTree 1;
neuper@37906
   304
neuper@37906
   305
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
neuper@37906
   306
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
neuper@37906
   307
"--------- replaceFormula: on Res + = 1st Nd ---------------------";
s1210629013@55445
   308
 reset_states ();
neuper@41970
   309
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   310
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   311
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   312
 Iterator 1; moveActiveRoot 1;
wneuper@59248
   313
 autoCalculate 1 CompleteCalcHead;
walther@59747
   314
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
walther@59747
   315
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   316
neuper@37906
   317
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
neuper@37906
   318
 val ((pt,_),_) = get_calc 1;
wneuper@59279
   319
 val str = pr_ctree pr_short pt;
neuper@37906
   320
 writeln str;
akargl@42176
   321
 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
   322
 else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
wneuper@59248
   323
 autoCalculate 1 CompleteCalc;
akargl@42176
   324
 val ((pt,pos as (p,_)),_) = get_calc 1;
walther@59868
   325
 if pos = ([],Res) andalso "[x = 1]" = (UnparseC.term o fst)(get_obj g_result pt p) then()
neuper@38031
   326
 else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
wneuper@59252
   327
DEconstrCalcTree 1;
neuper@37906
   328
neuper@37906
   329
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
neuper@37906
   330
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
neuper@37906
   331
"--------- replaceFormula: on Frm + = 1st Nd ---------------------";
s1210629013@55445
   332
 reset_states ();
neuper@41970
   333
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   334
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   335
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   336
 Iterator 1; moveActiveRoot 1;
wneuper@59248
   337
 autoCalculate 1 CompleteCalcHead;
walther@59747
   338
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   339
neuper@37906
   340
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
neuper@37906
   341
 val ((pt,_),_) = get_calc 1;
wneuper@59279
   342
 val str = pr_ctree pr_short pt;
neuper@37906
   343
 writeln str;
akargl@42176
   344
 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
   345
 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
wneuper@59248
   346
 autoCalculate 1 CompleteCalc;
akargl@42176
   347
 val ((pt,pos as (p,_)),_) = get_calc 1;
walther@59868
   348
 if pos = ([],Res) andalso "[x = 1]" = (UnparseC.term o fst)(get_obj g_result pt p) then()
neuper@38031
   349
 else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
wneuper@59252
   350
DEconstrCalcTree 1;
neuper@37906
   351
neuper@37906
   352
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
   353
"--------- replaceFormula: cut calculation -----------------------";
neuper@37906
   354
"--------- replaceFormula: cut calculation -----------------------";
s1210629013@55445
   355
 reset_states ();
neuper@41970
   356
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   357
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   358
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   359
 Iterator 1; moveActiveRoot 1;
wneuper@59248
   360
 autoCalculate 1 CompleteCalc;
neuper@37906
   361
 moveActiveRoot 1; moveActiveDown 1;
neuper@37906
   362
 if get_pos 1 1 = ([1], Frm) then ()
neuper@38031
   363
 else error "inform.sml: diff.behav. cut calculation 1";
neuper@37906
   364
neuper@37906
   365
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
neuper@37906
   366
 val ((pt,p),_) = get_calc 1;
wneuper@59279
   367
 val str = pr_ctree pr_short pt;
neuper@37906
   368
 writeln str;
neuper@37906
   369
 if p = ([1], Res) then ()
neuper@38031
   370
 else error "inform.sml: diff.behav. cut calculation 2";
neuper@37906
   371
neuper@37906
   372
neuper@37906
   373
(* 040307 copied from informtest.sml; ... old version 
neuper@37906
   374
 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
neuper@37906
   375
 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
neuper@37906
   376
 "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
neuper@37906
   377
neuper@37906
   378
 val p = ([],Pbl);
neuper@37906
   379
 val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
neuper@37906
   380
	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
neuper@37906
   381
	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
wneuper@59582
   382
        "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos (alpha::real)]",
neuper@37906
   383
	      (*^^^ these are the elements for the root-problem (in variants)*)
neuper@37906
   384
              (*vvv these are elements required for subproblems*)
neuper@37906
   385
	      "boundVariable a","boundVariable b","boundVariable alpha",
neuper@37906
   386
	      "interval {x::real. 0 <= x & x <= 2*r}",
neuper@37906
   387
	      "interval {x::real. 0 <= x & x <= 2*r}",
neuper@37906
   388
	      "interval {x::real. 0 <= x & x <= pi}",
neuper@37906
   389
	      "errorBound (eps=(0::real))"]
neuper@37906
   390
 (*specifying is not interesting for this example*)
neuper@38058
   391
 val spec = ("DiffApp", ["maximum_of","function"], 
neuper@37906
   392
	     ["DiffApp","max_by_calculus"]);
neuper@37906
   393
 (*the empty model with descriptions for user-guidance by Model_Problem*)
neuper@37906
   394
 val empty_model = [Given ["fixedValues []"],
neuper@37906
   395
		    Find ["maximum", "valuesFor"],
neuper@37906
   396
		    Relate ["relations []"]];
neuper@37906
   397
neuper@37906
   398
neuper@37906
   399
 (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
neuper@37906
   400
 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
neuper@37906
   401
 (*val nxt = ("Model_Problem", ...*)
neuper@37924
   402
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   403
neuper@37906
   404
 val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   405
 (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
neuper@37924
   406
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   407
(*[
neuper@37906
   408
(0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
neuper@37906
   409
(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
neuper@37906
   410
(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
neuper@37906
   411
(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
neuper@37906
   412
neuper@37906
   413
 (*the empty CalcHead is checked w.r.t the model and re-established as such*)
walther@59902
   414
 val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, Spec.empty);
neuper@37924
   415
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
walther@59879
   416
 if ocalhd2str ocalhd = "(Pbl, ??.empty, [\n(0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),\n(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),\n(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),\n(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))], [], \n(\"ThyC.id_empty\", [\"e_pblID\"], [\"e_metID\"]) )" then () else error "informtest.sml: diff.behav. max 1";
neuper@37906
   417
neuper@37906
   418
 (*there is one input to the model (could be more)*)
neuper@37906
   419
 val (b,pt,ocalhd) = 
neuper@37906
   420
     input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
neuper@37906
   421
			     Find ["maximum", "valuesFor"],
walther@59902
   422
			     Relate ["relations"]], Pbl, Spec.empty);
neuper@37924
   423
 val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
walther@59879
   424
 if ocalhd2str ocalhd = "(Pbl, ??.empty, [\n(1 ,[1,2,3] ,true ,#Given ,Cor fixedValues [r = Arbfix] ,(fix_, [[r = Arbfix]])),\n(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),\n(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),\n(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))], [], \n(\"ThyC.id_empty\", [\"e_pblID\"], [\"e_metID\"]) )" then () 
neuper@38031
   425
 else error "informtest.sml: diff.behav. max 2";
neuper@37906
   426
neuper@37906
   427
 (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
neuper@37906
   428
 val (b,pt''''',ocalhd) = 
neuper@37906
   429
     input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
neuper@37906
   430
			     Find ["maximum A", "valuesFor [a,b]"],
neuper@37906
   431
			     Relate ["relations [A=a*b, a/2=r*sin alpha, \
walther@59902
   432
				     \b/2=r*cos alpha]"]], Pbl, Spec.empty);
neuper@37924
   433
 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   434
 if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
neuper@37906
   435
neuper@37906
   436
 (*this input is complete in variant 1 (variant 3 does not work yet)*)
neuper@37906
   437
 val (b,pt''''',ocalhd) = 
neuper@37906
   438
     input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
neuper@37906
   439
			     Find ["maximum A", "valuesFor [a,b]"],
neuper@37906
   440
			     Relate ["relations [A=a*b, \
neuper@37906
   441
				     \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]], 
walther@59902
   442
		      Pbl, Spec.empty);
neuper@37924
   443
 val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
neuper@37906
   444
neuper@37906
   445
 modifycalcheadOK2xml 111 (bool2str b) ocalhd;
neuper@37906
   446
*)
wneuper@59252
   447
DEconstrCalcTree 1;
neuper@37906
   448
neuper@37906
   449
"--------- syntax error ------------------------------------------";
neuper@37906
   450
"--------- syntax error ------------------------------------------";
neuper@37906
   451
"--------- syntax error ------------------------------------------";
s1210629013@55445
   452
 reset_states ();
neuper@41970
   453
 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   454
	    ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   455
	     ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   456
 Iterator 1; moveActiveRoot 1;
wneuper@59248
   457
 autoCalculate 1 CompleteCalcHead;
walther@59747
   458
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
walther@59747
   459
 autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
neuper@37906
   460
neuper@37906
   461
 appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
neuper@37906
   462
 val ((pt,_),_) = get_calc 1;
wneuper@59279
   463
 val str = pr_ctree pr_short pt;
neuper@37906
   464
 writeln str;
neuper@37906
   465
 if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" then ()
neuper@38031
   466
 else error "inform.sml: diff.behav.appendFormula: syntax error";
wneuper@59252
   467
DEconstrCalcTree 1;
neuper@37906
   468
neuper@37906
   469
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   470
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   471
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   472
val (p,_,f,nxt,_,pt) = 
walther@59903
   473
    CalcTreeTEST [([], ("empty_thy_id", ["empty_probl_id"], ["empty_meth_id"]))];
neuper@37906
   474
val ifo = "solve(x+1=2,x)";
walther@59798
   475
val (_,(_,c,(pt,p))) = Step_Solve.by_term (pt,p) "solve(x+1=2,x)";
walther@59921
   476
(*
walther@59921
   477
  This trick           ^^^^^^^^^ micked input of ^^^^^^^^^^^^^^^^^ in the front-end.
walther@59921
   478
  The trick worked in changeset fbaff8cf0179, it does not work in 59c5dd27d589 anymore
walther@59921
   479
  (TODO hg bisect ?) and raises the ERROR Undefined fact: "xfoldr_Nil".
walther@59921
   480
walther@59921
   481
  Compare tests "CAS-command" in test/../inssort.sml etc.
walther@59921
   482
  ---------------------------------------------------------------------------------------------
neuper@37906
   483
show_pt pt;
walther@59749
   484
val nxt = (Apply_Method ["Test","squ-equ-test-subpbl1"]);
neuper@37906
   485
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@37906
   486
if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
neuper@38031
   487
else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
wneuper@59252
   488
DEconstrCalcTree 1;
walther@59921
   489
-----------------------------------------------------------------------------------------------*)
neuper@37906
   490
neuper@37906
   491
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
   492
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
   493
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
s1210629013@55445
   494
reset_states ();
walther@59903
   495
CalcTree [([], ("empty_thy_id", ["empty_probl_id"], ["empty_meth_id"]))];
neuper@37906
   496
Iterator 1;
neuper@37906
   497
moveActiveRoot 1;
neuper@37906
   498
replaceFormula 1 "solve(x+1=2,x)";
wneuper@59248
   499
autoCalculate 1 CompleteCalc;
neuper@37906
   500
val ((pt,p),_) = get_calc 1;
neuper@37906
   501
show_pt pt;
neuper@37906
   502
if p = ([], Res) then ()
neuper@38031
   503
else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
wneuper@59252
   504
DEconstrCalcTree 1;
neuper@37906
   505
wneuper@59562
   506
"--------- inform [rational,simplification] ----------------------";
wneuper@59562
   507
"--------- inform [rational,simplification] ----------------------";
wneuper@59562
   508
"--------- inform [rational,simplification] ----------------------";
s1210629013@55445
   509
reset_states ();
neuper@52105
   510
CalcTree [(["Term (a * x / (b * x) + c * x / (d * x) + e / f)", "normalform N"],
neuper@52105
   511
	("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
neuper@37906
   512
Iterator 1; moveActiveRoot 1;
wneuper@59248
   513
autoCalculate 1 CompleteCalcHead;
neuper@52105
   514
neuper@52105
   515
"--- (-1) give a preview on the calculation without any input";
neuper@52105
   516
(*
wneuper@59248
   517
autoCalculate 1 CompleteCalc;
neuper@52105
   518
val ((pt, p), _) = get_calc 1;
neuper@52105
   519
show_pt pt;
neuper@52105
   520
[
neuper@52105
   521
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   522
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   523
(([1], Res), a / b + c / d + e / f),                             <--- (1) input arbitrary
neuper@52105
   524
(([2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   525
(([3], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   526
(([4], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)), <--- (2) input next
neuper@52105
   527
(([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))]  <--- (3) is also final result
neuper@52105
   528
                                                                          EXAMPLE NOT OPTIMAL
neuper@52105
   529
*)
neuper@52105
   530
"--- (0) user input as the *first* step does not work, thus impdo at least 1 step";
walther@59747
   531
autoCalculate 1 (Steps 1);
walther@59747
   532
autoCalculate 1 (Steps 1);
neuper@52105
   533
val ((pt, p), _) = get_calc 1;
neuper@52105
   534
(*show_pt pt;
neuper@52105
   535
[
neuper@52105
   536
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   537
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   538
(([1], Res), a / b + c / d + e / f)] 
neuper@52105
   539
*)
neuper@52105
   540
"--- (1) input an arbitrary next formula";
wneuper@59123
   541
appendFormula 1 "((a * d) + (c * b)) / (b * d) + e / f" (*|> Future.join*);
neuper@52105
   542
val ((pt, p), _) = get_calc 1;
neuper@52105
   543
(*show_pt pt;
neuper@52105
   544
[
neuper@52105
   545
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   546
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   547
(([1], Res), a / b + c / d + e / f),
neuper@52105
   548
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   549
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   550
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   551
(([2], Res), (a * d + c * b) / (b * d) + e / f)] 
neuper@52105
   552
*)
neuper@37906
   553
val ((pt,p),_) = get_calc 1;
neuper@52105
   554
if p = ([2], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
neuper@38031
   555
else error ("inform.sml: [rational,simplification] 1");
neuper@37906
   556
neuper@52105
   557
"--- (2) input the next formula that would be presented by mat-engine";
neuper@52105
   558
(* generate a preview:
walther@59747
   559
autoCalculate 1 (Steps 1);
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))]   <--- input this
neuper@52105
   571
*)
wneuper@59123
   572
appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
neuper@52105
   573
val ((pt, p), _) = get_calc 1;
neuper@52105
   574
(*show_pt pt;
neuper@52105
   575
[
neuper@52105
   576
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   577
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   578
(([1], Res), a / b + c / d + e / f),
neuper@52105
   579
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   580
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   581
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   582
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   583
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
neuper@52105
   584
*)
neuper@52105
   585
if p = ([3], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
neuper@38031
   586
else error ("inform.sml: [rational,simplification] 2");
neuper@37906
   587
neuper@52105
   588
"--- (3) input the exact final result";
wneuper@59123
   589
appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
neuper@52105
   590
val ((pt, p), _) = get_calc 1;
neuper@52105
   591
(*show_pt pt;
neuper@52105
   592
[
neuper@52105
   593
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   594
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   595
(([1], Res), a / b + c / d + e / f),
neuper@52105
   596
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   597
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   598
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   599
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   600
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   601
(([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   602
(([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   603
(([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   604
(([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
neuper@52105
   605
*)
neuper@52105
   606
if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
neuper@38031
   607
else error ("inform.sml: [rational,simplification] 3");
neuper@52105
   608
neuper@52105
   609
"--- (4) finish the calculation + check the postcondition (in the future)";
wneuper@59248
   610
autoCalculate 1 CompleteCalc;
neuper@52105
   611
val ((pt, p), _) = get_calc 1;
neuper@52105
   612
val (t, asm) = get_obj g_result pt [];
walther@59868
   613
if UnparseC.term t = "(a * d * f + b * c * f + b * d * e) / (b * d * f)" andalso
walther@59921
   614
UnparseC.terms asm =(*"[\"b * d * f \<noteq> 0\",\"d \<noteq> 0\",\"b \<noteq> 0\",\"a * x / (b * x) + c * x / (d * x) + e / f is_ratpolyexp\"]"*)
walther@59921
   615
                    "[]" (*..found broken in child of 33913fe24685, error covered by  CAS-command *)
neuper@52105
   616
then () else error "inform [rational,simplification] changed at end";
neuper@52105
   617
(*show_pt pt;
neuper@52105
   618
[
neuper@52105
   619
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   620
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   621
(([1], Res), a / b + c / d + e / f),
neuper@52105
   622
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   623
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   624
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   625
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   626
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   627
(([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   628
(([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   629
(([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   630
(([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   631
(([5], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   632
(([6], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)),
neuper@52105
   633
(([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))] 
neuper@52105
   634
*)
wneuper@59252
   635
DEconstrCalcTree 1;
neuper@37906
   636
neuper@37906
   637
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   638
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   639
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   640
val t = str2term "Diff (x^^^2 + x + 1, x)";
neuper@37906
   641
case t of Const ("Diff.Diff", _) $ _ => ()
neuper@37906
   642
	| _ => raise 
neuper@37906
   643
	      error "diff.sml behav.changed for CAS Diff (..., x)";
neuper@37906
   644
atomty t;
neuper@37906
   645
"-----------------------------------------------------------------";
s1210629013@55445
   646
(*1>*)reset_states ();
walther@59903
   647
(*2>*)CalcTree [([], ("empty_thy_id", ["empty_probl_id"], ["empty_meth_id"]))];
neuper@37906
   648
(*3>*)Iterator 1;moveActiveRoot 1;
neuper@37906
   649
"----- here the Headline has been finished";
neuper@37906
   650
(*4>*)moveActiveFormula 1 ([],Pbl);
neuper@37906
   651
(*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
neuper@37906
   652
val ((pt,_),_) = get_calc 1;
walther@59921
   653
val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
neuper@37926
   654
val (SOME istate, NONE) = loc;
wneuper@59348
   655
(*default_print_depth 5;*)
neuper@37906
   656
writeln"-----------------------------------------------------------";
neuper@37906
   657
spec;
neuper@37924
   658
writeln (itms2str_ ctxt probl);
neuper@37924
   659
writeln (itms2str_ ctxt meth);
walther@59844
   660
writeln (Istate.string_of (fst istate));
neuper@37906
   661
neuper@37906
   662
refFormula 1 ([],Pbl) (*--> correct CalcHead*);
neuper@37906
   663
 (*081016 NOT necessary (but leave it in Java):*)
wneuper@59248
   664
(*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
neuper@37906
   665
"----- here the CalcHead has been completed --- ONCE MORE ?????";
neuper@37906
   666
neuper@37906
   667
(***difference II***)
neuper@37906
   668
val ((pt,p),_) = get_calc 1;
neuper@37906
   669
(*val p = ([], Pbl)*)
walther@59921
   670
val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
neuper@37926
   671
val (SOME istate, NONE) = loc;
walther@59844
   672
(*default_print_depth 5;*) writeln (Istate.string_of (fst istate));  (*default_print_depth 3;*)
wneuper@59583
   673
(*Pstate ([],
neuper@37926
   674
 [], NONE,
neuper@37906
   675
 ??.empty, Sundef, false)*)
wneuper@59348
   676
(*default_print_depth 5;*) spec; (*default_print_depth 3;*)
wneuper@59592
   677
(*("Isac_Knowledge",
neuper@37906
   678
      ["derivative_of", "function"],
neuper@37906
   679
      ["diff", "differentiate_on_R"]) : spec*)
neuper@37924
   680
writeln (itms2str_ ctxt probl);
neuper@37906
   681
(*[
neuper@37906
   682
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   683
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   684
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37924
   685
writeln (itms2str_ ctxt meth);
neuper@37906
   686
(*[
neuper@37906
   687
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   688
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   689
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37906
   690
writeln"-----------------------------------------------------------";
neuper@37906
   691
(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
neuper@37906
   692
(*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
wneuper@59248
   693
autoCalculate 1 CompleteCalc;
neuper@37906
   694
val ((pt,p),_) = get_calc 1;
neuper@37906
   695
val Form res = (#1 o pt_extract) (pt, ([],Res));
neuper@37906
   696
show_pt pt;
walther@59868
   697
if p = ([], Res) andalso UnparseC.term res = "1 + 2 * x" then ()
neuper@38031
   698
else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
wneuper@59252
   699
DEconstrCalcTree 1;
neuper@37906
   700
neuper@37906
   701
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   702
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   703
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   704
(*the following input is copied from BridgeLog Java <==> SML,
neuper@37906
   705
  omitting unnecessary inputs*)
s1210629013@55445
   706
(*1>*)reset_states ();
wneuper@59592
   707
(*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac_Knowledge",["derivative_of","function"],["diff","differentiate_on_R"]))];
neuper@37906
   708
(*3>*)Iterator 1; moveActiveRoot 1;
neuper@37906
   709
wneuper@59248
   710
(*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
neuper@37906
   711
(***difference II***)
neuper@37906
   712
val ((pt,_),_) = get_calc 1;
walther@59921
   713
val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
neuper@37926
   714
val (SOME istate, NONE) = loc;
walther@59844
   715
(*default_print_depth 5;*) writeln (Istate.string_of (fst istate));  (*default_print_depth 3;*)
wneuper@59583
   716
(*Pstate ([],
neuper@37926
   717
 [], NONE,
neuper@37906
   718
 ??.empty, Sundef, false)*)
wneuper@59348
   719
(*default_print_depth 5;*) spec; (*default_print_depth 3;*)
wneuper@59592
   720
(*("Isac_Knowledge",
neuper@37906
   721
      ["derivative_of", "function"],
neuper@37906
   722
      ["diff", "differentiate_on_R"]) : spec*)
neuper@37924
   723
writeln (itms2str_ ctxt probl);
neuper@37906
   724
(*[
neuper@37906
   725
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   726
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   727
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37924
   728
writeln (itms2str_ ctxt meth);
neuper@37906
   729
(*[
neuper@37906
   730
(1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
neuper@37906
   731
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   732
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37906
   733
writeln"-----------------------------------------------------------";
neuper@37906
   734
(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
walther@59747
   735
autoCalculate 1 (Steps 1);
neuper@37906
   736
val ((pt,p),_) = get_calc 1;
neuper@37906
   737
val Form res = (#1 o pt_extract) (pt, p);
walther@59868
   738
if UnparseC.term res = "d_d x (x ^^^ 2 + x + 1)" then ()
neuper@38031
   739
else error "diff.sml Diff (x^2 + x + 1, x) from exp";
wneuper@59252
   740
DEconstrCalcTree 1;
neuper@37906
   741
walther@59845
   742
"--------- implicit_take, start with <NEW> (CAS input) ---------------";
walther@59845
   743
"--------- implicit_take, start with <NEW> (CAS input) ---------------";
walther@59845
   744
"--------- implicit_take, start with <NEW> (CAS input) ---------------";
s1210629013@55445
   745
reset_states ();
walther@59903
   746
CalcTree [([], ("empty_thy_id", ["empty_probl_id"], ["empty_meth_id"]))];
neuper@37906
   747
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   748
[[from sml:  1 
neuper@37906
   749
[[from sml: <CALCTREE>
neuper@37906
   750
[[from sml:    <CALCID> 1 </CALCID>
neuper@37906
   751
[[from sml: </CALCTREE>
neuper@37906
   752
[[from sml: @@@@@end@@@@@*)
neuper@37906
   753
Iterator 1;
neuper@37906
   754
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   755
[[from sml:  1 
neuper@37906
   756
[[from sml: <ADDUSER>
neuper@37906
   757
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   758
[[from sml:   <USERID> 1 </USERID>
neuper@37906
   759
[[from sml: </ADDUSER>
neuper@37906
   760
[[from sml: @@@@@end@@@@@*)
neuper@37906
   761
moveActiveRoot 1;
neuper@37906
   762
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   763
[[from sml:  1 
neuper@37906
   764
[[from sml: <CALCITERATOR>
neuper@37906
   765
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   766
[[from sml:   <POSITION>
neuper@37906
   767
[[from sml:     <INTLIST>
neuper@37906
   768
[[from sml:     </INTLIST>
neuper@37906
   769
[[from sml:     <POS> Pbl </POS>
neuper@37906
   770
[[from sml:   </POSITION>
neuper@37906
   771
[[from sml: </CALCITERATOR>
neuper@37906
   772
[[from sml: @@@@@end@@@@@*)
neuper@37906
   773
getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
neuper@37906
   774
(*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
neuper@37906
   775
[[from sml:  1 
neuper@37906
   776
[[from sml: <GETELEMENTSFROMTO>
neuper@37906
   777
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   778
[[from sml:   <FORMHEADS>
neuper@37906
   779
[[from sml:     <CALCFORMULA>
neuper@37906
   780
[[from sml:       <POSITION>
neuper@37906
   781
[[from sml:         <INTLIST>
neuper@37906
   782
[[from sml:         </INTLIST>
neuper@37906
   783
[[from sml:         <POS> Pbl </POS>
neuper@37906
   784
[[from sml:       </POSITION>
neuper@37906
   785
[[from sml:       <FORMULA>
neuper@37906
   786
[[from sml:         <MATHML>
neuper@37906
   787
[[from sml:           <ISA> ________________________________________________ </ISA>
neuper@37906
   788
[[from sml:         </MATHML>
neuper@37906
   789
[[from sml: 
neuper@37906
   790
[[from sml:       </FORMULA>
neuper@37906
   791
[[from sml:     </CALCFORMULA>
neuper@37906
   792
[[from sml:   </FORMHEADS>
neuper@37906
   793
[[from sml: </GETELEMENTSFROMTO>
neuper@37906
   794
[[from sml: @@@@@end@@@@@*)
neuper@37906
   795
refFormula 1 ([],Pbl);
neuper@37906
   796
(*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
neuper@37906
   797
[[from sml:  1 
neuper@37906
   798
[[from sml: <REFFORMULA>
neuper@37906
   799
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   800
[[from sml:   <CALCHEAD status = "incorrect">
neuper@37906
   801
[[from sml:     <POSITION>
neuper@37906
   802
[[from sml:       <INTLIST>
neuper@37906
   803
[[from sml:       </INTLIST>
neuper@37906
   804
[[from sml:       <POS> Pbl </POS>
neuper@37906
   805
[[from sml:     </POSITION>
neuper@37906
   806
[[from sml:     <HEAD>
neuper@37906
   807
[[from sml:       <MATHML>
walther@59879
   808
[[from sml:         <ISA> Problem (ThyC.id_empty, [e_pblID]) </ISA>
neuper@37906
   809
[[from sml:       </MATHML>
neuper@37906
   810
[[from sml:     </HEAD>
neuper@37906
   811
[[from sml:     <MODEL>
neuper@37906
   812
[[from sml:       <GIVEN>  </GIVEN>
neuper@37906
   813
[[from sml:       <WHERE>  </WHERE>
neuper@37906
   814
[[from sml:       <FIND>  </FIND>
neuper@37906
   815
[[from sml:       <RELATE>  </RELATE>
neuper@37906
   816
[[from sml:     </MODEL>
neuper@37906
   817
[[from sml:     <BELONGSTO> Pbl </BELONGSTO>
neuper@37906
   818
[[from sml:     <SPECIFICATION>
walther@59879
   819
[[from sml:       <THEORYID> ThyC.id_empty </THEORYID>
neuper@37906
   820
[[from sml:       <PROBLEMID>
neuper@37906
   821
[[from sml:         <STRINGLIST>
walther@59903
   822
[[from sml:           <STRING> Problem.id_empty </STRING>
neuper@37906
   823
[[from sml:         </STRINGLIST>
neuper@37906
   824
[[from sml:       </PROBLEMID>
neuper@37906
   825
[[from sml:       <METHODID>
neuper@37906
   826
[[from sml:         <STRINGLIST>
neuper@37906
   827
[[from sml:           <STRING> e_metID </STRING>
neuper@37906
   828
[[from sml:         </STRINGLIST>
neuper@37906
   829
[[from sml:       </METHODID>
neuper@37906
   830
[[from sml:     </SPECIFICATION>
neuper@37906
   831
[[from sml:   </CALCHEAD>
neuper@37906
   832
[[from sml: </REFFORMULA>
neuper@37906
   833
[[from sml: @@@@@end@@@@@*)
neuper@37906
   834
moveActiveFormula 1 ([],Pbl);
neuper@37906
   835
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   836
[[from sml:  1 
neuper@37906
   837
[[from sml: <CALCITERATOR>
neuper@37906
   838
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   839
[[from sml:   <POSITION>
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:   </POSITION>
neuper@37906
   844
[[from sml: </CALCITERATOR>
neuper@37906
   845
[[from sml: @@@@@end@@@@@*)
neuper@37906
   846
replaceFormula 1 "Simplify (1+2)";
neuper@37906
   847
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   848
[[from sml:  1 
neuper@37906
   849
[[from sml: <REPLACEFORMULA>
neuper@37906
   850
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   851
[[from sml:   <CALCCHANGED>
neuper@37906
   852
[[from sml:     <UNCHANGED>
neuper@37906
   853
[[from sml:       <INTLIST>
neuper@37906
   854
[[from sml:       </INTLIST>
neuper@37906
   855
[[from sml:       <POS> Pbl </POS>
neuper@37906
   856
[[from sml:     </UNCHANGED>
neuper@37906
   857
[[from sml:     <DELETED>
neuper@37906
   858
[[from sml:       <INTLIST>
neuper@37906
   859
[[from sml:       </INTLIST>
neuper@37906
   860
[[from sml:       <POS> Pbl </POS>
neuper@37906
   861
[[from sml:     </DELETED>
neuper@37906
   862
[[from sml:     <GENERATED>
neuper@37906
   863
[[from sml:       <INTLIST>
neuper@37906
   864
[[from sml:       </INTLIST>
neuper@37906
   865
[[from sml:       <POS> Met </POS>                           DIFFERENCE: Pbl
neuper@37906
   866
[[from sml:     </GENERATED>
neuper@37906
   867
[[from sml:   </CALCCHANGED>
neuper@37906
   868
[[from sml: </REPLACEFORMULA>
neuper@37906
   869
[[from sml: @@@@@end@@@@@*)
neuper@37906
   870
getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(*              DIFFERENCE: Pbl*);
neuper@37906
   871
(*@@@@@begin@@@@@
neuper@37906
   872
 1
neuper@37906
   873
<GETELEMENTSFROMTO>
neuper@37906
   874
  <CALCID> 1 </CALCID>
neuper@37906
   875
  <FORMHEADS>
neuper@37906
   876
    <CALCFORMULA>
neuper@37906
   877
      <POSITION>
neuper@37906
   878
        <INTLIST>
neuper@37906
   879
        </INTLIST>
neuper@37906
   880
        <POS> Pbl </POS>
neuper@37906
   881
      </POSITION>
neuper@37906
   882
      <FORMULA>
neuper@37906
   883
        <MATHML>
neuper@37906
   884
          <ISA> Simplify (1 + 2) </ISA>                      WORKS !!!!!
neuper@37906
   885
        </MATHML>
neuper@37906
   886
      </FORMULA>
neuper@37906
   887
    </CALCFORMULA>
neuper@37906
   888
  </FORMHEADS>
neuper@37906
   889
</GETELEMENTSFROMTO>
neuper@37906
   890
@@@@@end@@@@@*)
neuper@37906
   891
getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
neuper@37906
   892
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   893
[[from sml:  1 
neuper@37906
   894
[[from sml: <SYSERROR>
neuper@37906
   895
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   896
[[from sml:   <ERROR> error in getFormulaeFromTo </ERROR>
neuper@37906
   897
[[from sml: </SYSERROR>
neuper@37906
   898
[[from sml: @@@@@end@@@@@*)
neuper@37906
   899
(*step into getFormulaeFromTo --- bug corrected...*)
neuper@42423
   900
walther@59909
   901
"--------- build fun check_for' ------------------------------";
walther@59909
   902
"--------- build fun check_for' ------------------------------";
walther@59909
   903
"--------- build fun check_for' ------------------------------";
neuper@42426
   904
val subst = [(str2term "bdv", str2term "x")]: subst;
neuper@42423
   905
val rls = norm_Rational
neuper@42423
   906
val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
neuper@42423
   907
val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
neuper@42423
   908
val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "1 / 2");
neuper@42423
   909
neuper@42426
   910
val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
walther@59852
   911
  rew_sub thy 1 [] e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
neuper@42423
   912
if rewritten then NONE else SOME "e_errpatID";
neuper@42423
   913
neuper@42423
   914
val norm_res = case rewrite_set_ (Isac()) false rls res' of
neuper@42423
   915
  NONE => res'
neuper@42423
   916
| SOME (norm_res, _) => norm_res
neuper@42423
   917
neuper@42423
   918
val norm_inf = case rewrite_set_ (Isac()) false rls inf of
neuper@42423
   919
  NONE => inf
neuper@42423
   920
| SOME (norm_inf, _) => norm_inf;
neuper@42423
   921
neuper@42423
   922
res' = inf;
neuper@42423
   923
norm_res = norm_inf;
neuper@42423
   924
neuper@42423
   925
val pat = parse_patt @{theory} "(?a + ?b)/?a = ?b";
neuper@42423
   926
val (res, inf) = (str2term "(2 + 3)/2", str2term "3");
walther@59909
   927
if check_for' (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   928
then () else error "error patt example1 changed";
neuper@42423
   929
neuper@42423
   930
val pat = parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
neuper@42423
   931
val (res, inf) = (str2term "(2 + 3)/(2 + 4)", str2term "3 / 4");
walther@59909
   932
if check_for' (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   933
then () else error "error patt example2 changed";
neuper@42423
   934
neuper@42423
   935
val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
neuper@42423
   936
val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
walther@59909
   937
if check_for' (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   938
then () else error "error patt example3 changed";
neuper@42423
   939
neuper@42423
   940
val inf =  str2term "1 / 2";
walther@59909
   941
if check_for' (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   942
then () else error "error patt example3 changed";
neuper@42423
   943
walther@59909
   944
"--------- build fun check_for' ?bdv -------------------------";
walther@59909
   945
"--------- build fun check_for' ?bdv -------------------------";
walther@59909
   946
"--------- build fun check_for' ?bdv -------------------------";
neuper@42426
   947
val subst = [(str2term "bdv", str2term "x")]: subst;
neuper@42426
   948
val t = str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))";
neuper@42426
   949
val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
walther@59868
   950
if UnparseC.term t = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3" then ()
walther@59909
   951
else error "build fun check_for' ?bdv changed 1"; 
neuper@42423
   952
neuper@42426
   953
val rls = norm_diff
neuper@42426
   954
val pat = parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)"; 
neuper@42426
   955
val (res, inf) = (str2term "2 * x + d_d x (sin (x ^^^ 4))", str2term "2 * x + cos (4 * x ^^^ 3)");
neuper@42426
   956
neuper@42426
   957
val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
walther@59852
   958
  rew_sub thy 1 subst e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
walther@59868
   959
if UnparseC.term res' = "2 * x + cos (d_d x (x ^^^ 4))" andalso rewritten then ()
walther@59909
   960
else error "build fun check_for' ?bdv changed 2";
neuper@42426
   961
neuper@42426
   962
val norm_res = case rewrite_set_inst_ (Isac()) false subst rls  res' of
neuper@42426
   963
  NONE => res'
neuper@42426
   964
| SOME (norm_res, _) => norm_res;
walther@59868
   965
if UnparseC.term norm_res = "2 * x + cos (4 * x ^^^ 3)" then ()
walther@59909
   966
else error "build fun check_for' ?bdv changed 3";
neuper@42426
   967
neuper@42426
   968
val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
neuper@42426
   969
  NONE => inf
neuper@42426
   970
| SOME (norm_inf, _) => norm_inf;
walther@59868
   971
if UnparseC.term norm_inf = "2 * x + cos (4 * x ^^^ 3)" then ()
walther@59909
   972
else error "build fun check_for' ?bdv changed 4";
neuper@42426
   973
neuper@42426
   974
res' = inf;
neuper@42426
   975
if norm_res = norm_inf then ()
walther@59909
   976
else error "build fun check_for' ?bdv changed 5";
neuper@42426
   977
walther@59921
   978
if Error_Pattern.check_for' (res, inf) (subst: subst) ("errpatID": Error_Pattern.id, pat) rls = SOME "errpatID"
neuper@42426
   979
then () else error "error patt example1 changed";
neuper@42426
   980
walther@59909
   981
"--------- build fun check_for ------------------------";
walther@59909
   982
"--------- build fun check_for ------------------------";
walther@59909
   983
"--------- build fun check_for ------------------------";
neuper@42428
   984
val (res, inf) =
neuper@42428
   985
  (str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))",
neuper@42428
   986
   str2term "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)");
neuper@48790
   987
val {errpats, nrls = rls, scr = Prog prog, ...} = get_met ["diff", "differentiate_on_R"]
neuper@42426
   988
neuper@42428
   989
val env = [(str2term "v_v", str2term "x")];
neuper@42428
   990
val errpats =
neuper@42428
   991
  [e_errpat, (*generalised for testing*)
neuper@42428
   992
   ("chain-rule-diff-both",
neuper@42428
   993
     [parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
neuper@42428
   994
      parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
neuper@42428
   995
      parse_patt @{theory} "d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)",
neuper@42428
   996
      parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
neuper@42428
   997
      parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
neuper@42428
   998
     [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain}, 
walther@59921
   999
      @{thm diff_ln_chain}, @{thm  diff_exp_chain}])];
walther@59844
  1000
case Error_Pattern.check_for (res, inf) (prog, env) (errpats, rls) of SOME _ => () 
walther@59844
  1001
| NONE => error "Error_Pattern.check_for broken";
wneuper@59252
  1002
DEconstrCalcTree 1;
neuper@42428
  1003
walther@59909
  1004
"--------- embed fun check_for ------------------------";
walther@59909
  1005
"--------- embed fun check_for ------------------------";
walther@59909
  1006
"--------- embed fun check_for ------------------------";
wneuper@59562
  1007
reset_states ();     
neuper@42428
  1008
CalcTree
neuper@42428
  1009
[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
wneuper@59592
  1010
  ("Isac_Knowledge", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
neuper@42428
  1011
Iterator 1;
neuper@42428
  1012
moveActiveRoot 1;
wneuper@59248
  1013
autoCalculate 1 CompleteCalcHead;
walther@59747
  1014
autoCalculate 1 (Steps 1);
walther@59747
  1015
autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
walther@59747
  1016
(*autoCalculate 1 (Steps 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
neuper@42428
  1017
walther@59865
  1018
"~~~~~ fun appendFormula , args:"; val (cI, (ifo:TermC.as_string)) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
walther@59868
  1019
"~~~~~ fun appendFormula' , args:"; val (cI, (ifo: TermC.as_string)) = (cI, ifo);
wneuper@59562
  1020
    val cs = get_calc cI
wneuper@59562
  1021
    val pos = get_pos cI 1;
walther@59844
  1022
(*+*)if pos = ([1], Res) then () else error "inform with (positive) Error_Pattern.check_for broken 1";
walther@59798
  1023
    val ("ok", cs' as (_, _, ptp)) = (*case*) Step.do_next pos cs (*of*);
walther@59798
  1024
      (*case*) Step_Solve.by_term ptp (encode ifo) (*of*); (*ERROR WAS: "no derivation found"*)
walther@59797
  1025
"~~~~~ fun Step_Solve.by_term , args:"; val (((*next_*)cs as (_, _, (pt, pos as (p, _))): Chead.calcstate'), istr)
wneuper@59562
  1026
  = (cs', (encode ifo));
wneuper@59562
  1027
    val ctxt = get_ctxt pt pos (*see TODO.thy*)
walther@59881
  1028
    val SOME f_in = (*case*) TermC.parse (ThyC.get_theory "Isac_Knowledge") istr (*of*);
wneuper@59562
  1029
    	  val f_in = Thm.term_of f_in
wneuper@59562
  1030
        val pos_pred = lev_back' pos
wneuper@59562
  1031
    	  val f_pred = Ctree.get_curr_formula (pt, pos_pred);
wneuper@59562
  1032
        (*if*) f_pred = f_in; (*else*)
walther@59822
  1033
          val NONE = (*case*) In_Chead.cas_input f_in (*of*);
walther@59795
  1034
       (*old* )val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
walther@59795
  1035
       (*old*)val {scr = prog, ...} = Specify.get_met metID
walther@59807
  1036
       (*old*)val istate = get_istate_LI pt pos
walther@59795
  1037
       (*old*)val ctxt = get_ctxt pt pos
walther@59795
  1038
       ( *old*)
walther@59795
  1039
       val LI.Not_Derivable =
walther@59795
  1040
             (*case*) LI.locate_input_term (pt, pos) f_in (*of*);
wneuper@59562
  1041
            		  val pp = Ctree.par_pblobj pt p
wneuper@59562
  1042
            		  val (errpats, nrls, prog) = case Specify.get_met (Ctree.get_obj Ctree.g_metID pt pp) of
wneuper@59562
  1043
              		    {errpats, nrls, scr = Rule.Prog prog, ...} => (errpats, nrls, prog)
wneuper@59562
  1044
              		  | _ => error "inform: uncovered case of get_met"
wneuper@59562
  1045
;
walther@59921
  1046
(*+*)if Error_Pattern.s_to_string errpats = "[(\"chain-rule-diff-both\",\n[\"d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)\",\"d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)\",\"d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)\",\"d_d ?bdv (LogExp.ln ?u) = 1 / ?u\",\"d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u\"],\n[\"d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u\",\"d_d ?bdv (cos ?u) = - sin ?u * d_d ?bdv ?u\",\"d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1) * d_d ?bdv ?u\",\"d_d ?bdv (LogExp.ln ?u) = d_d ?bdv ?u / ?u\",\"d_d ?bdv (E_ ^^^ ?u) = E_ ^^^ ?u * d_d ?x ?u\"]]"
walther@59844
  1047
(*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 3";
neuper@42428
  1048
walther@59807
  1049
            		  val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
wneuper@59562
  1050
;
walther@59868
  1051
(*+*)if UnparseC.term f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
walther@59868
  1052
(*+*)   UnparseC.term f_in = "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)"
walther@59844
  1053
(*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 2";
neuper@42428
  1054
walther@59909
  1055
             val SOME "chain-rule-diff-both" = (*case*) Error_Pattern.check_for (f_pred, f_in) (prog, env) (errpats, nrls) (*of*);
neuper@42428
  1056
neuper@42428
  1057
"--- final check:";
walther@59798
  1058
(*+*)val (_, _, ptp') = cs';
walther@59798
  1059
case Step_Solve.by_term ptp' (encode ifo) of
neuper@42428
  1060
  ("error pattern #chain-rule-diff-both#", calcstate') => ()
walther@59844
  1061
| _ => error "inform with (positive) Error_Pattern.check_for broken"
neuper@42428
  1062
neuper@48895
  1063
walther@59909
  1064
"--------- embed fun find_fill_patterns ---------------------------";
walther@59909
  1065
"--------- embed fun find_fill_patterns ---------------------------";
walther@59909
  1066
"--------- embed fun find_fill_patterns ---------------------------";
s1210629013@55445
  1067
reset_states ();
neuper@42430
  1068
CalcTree
neuper@42430
  1069
[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
wneuper@59592
  1070
  ("Isac_Knowledge", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
neuper@42430
  1071
Iterator 1;
neuper@42430
  1072
moveActiveRoot 1;
wneuper@59248
  1073
autoCalculate 1 CompleteCalcHead;
walther@59747
  1074
autoCalculate 1 (Steps 1);
walther@59747
  1075
autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
wneuper@59123
  1076
appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)" (*|> Future.join*);
neuper@42430
  1077
  (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
neuper@42432
  1078
  (*or
neuper@42432
  1079
    <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
neuper@42430
  1080
neuper@42433
  1081
"~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
neuper@42430
  1082
  val ((pt, _), _) = get_calc cI
neuper@42430
  1083
				val pos = get_pos cI 1;
walther@59909
  1084
"~~~~~ fun find_fill_patterns , args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
walther@59685
  1085
    val f_curr = Ctree.get_curr_formula (pt, pos);
walther@59685
  1086
    val pp = Ctree.par_pblobj pt p
walther@59685
  1087
    val (errpats, prog) = case Specify.get_met (Ctree.get_obj Ctree.g_metID pt pp) of
walther@59685
  1088
      {errpats, scr = Rule.Prog prog, ...} => (errpats, prog)
walther@59909
  1089
    | _ => error "find_fill_patterns: uncovered case of get_met"
walther@59807
  1090
    val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
walther@59911
  1091
    val subst = Subst.for_bdv prog env
neuper@42430
  1092
    val errpatthms = errpats
walther@59921
  1093
      |> filter ((curry op = errpatID) o (#1: Error_Pattern.T -> Error_Pattern.id))
walther@59921
  1094
      |> map (#3: Error_Pattern.T -> thm list)
neuper@42430
  1095
      |> flat;
neuper@42430
  1096
walther@59909
  1097
case map (Error_Pattern.fill_from_store subst f_curr errpatID) errpatthms |> flat of
walther@59868
  1098
  ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if UnparseC.term tm = 
neuper@42432
  1099
    "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
walther@59909
  1100
    then () else error "find_fill_patterns changed 1a"
walther@59909
  1101
| _ => error "find_fill_patterns changed 1b"
neuper@42430
  1102
walther@59909
  1103
"~~~~~ fun fill_from_store, args:"; val (subst, form, errpatID, thm) =
neuper@42432
  1104
  (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
neuper@42430
  1105
        val thmDeriv = Thm.get_name_hint thm
walther@59921
  1106
        val (part, thyID) = Thy_Read.thy_containing_thm thmDeriv
walther@59876
  1107
        val theID = [part, thyID, "Theorems", ThmC.cut_id thmDeriv]
walther@59921
  1108
        val Thy_Write.Hthm {fillpats, ...} = get_the theID
walther@59909
  1109
        val some = map (Error_Pattern.fill_form subst (thm, form) errpatID) fillpats;
neuper@42430
  1110
neuper@42430
  1111
case some |> filter is_some |> map the of
walther@59868
  1112
  ("fill-d_d-arg", tm, thm, subsopt) :: _ => if UnparseC.term tm = 
neuper@42432
  1113
    "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
walther@59909
  1114
    then () else error "find_fill_patterns changed 2a"
walther@59909
  1115
| _ => error "find_fill_patterns changed 2b"
neuper@42430
  1116
walther@59909
  1117
"~~~~~ fun fill_form, args:";
neuper@42433
  1118
  val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
neuper@42433
  1119
  (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
neuper@42433
  1120
val (form', _, _, rewritten) =
walther@59852
  1121
      rew_sub (Isac()) 1 subst e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) form;
neuper@42432
  1122
walther@59868
  1123
if UnparseC.term form' = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
walther@59909
  1124
else error "find_fill_patterns changed 3";
neuper@42432
  1125
neuper@42433
  1126
"~~~~~ to findFillpatterns return val:"; val (fillpats) =
walther@59909
  1127
  (map (Error_Pattern.fill_from_store (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
neuper@42432
  1128
neuper@42450
  1129
"vvv--- dropped this code WN120730";
neuper@42433
  1130
val msg = "fill patterns " ^
walther@59868
  1131
  ((map ((apsnd UnparseC.term) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
neuper@42450
  1132
msg =
neuper@42432
  1133
  "fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
neuper@42432
  1134
    " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" ^
neuper@42432
  1135
  "#fill-both-args#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
neuper@42432
  1136
    " =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3" ^
neuper@42432
  1137
  "#fill-d_d#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
neuper@42432
  1138
    " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1 x (x ^^^ 4)" ^
neuper@42432
  1139
  "#fill-inner-deriv#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
neuper@42432
  1140
    " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1" ^
neuper@42450
  1141
  "#fill-all#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) = d_d x (x ^^^ 2) + ?_dummy_1#";
neuper@42450
  1142
"^^^--- dropped this code WN120730";
neuper@42450
  1143
neuper@42450
  1144
if (map #1 fillpats) =
neuper@42450
  1145
  ["fill-d_d-arg", "fill-both-args", "fill-d_d", "fill-inner-deriv", "fill-all"]
walther@59909
  1146
then () else error "find_fill_patterns changed 4b";
wneuper@59252
  1147
DEconstrCalcTree 1;
neuper@42450
  1148
neuper@42437
  1149
"--------- build fun is_exactly_equal, inputFillFormula ----------";
neuper@42437
  1150
"--------- build fun is_exactly_equal, inputFillFormula ----------";
neuper@42437
  1151
"--------- build fun is_exactly_equal, inputFillFormula ----------";
s1210629013@55445
  1152
reset_states ();
neuper@42437
  1153
CalcTree
neuper@42437
  1154
[(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
wneuper@59592
  1155
  ("Isac_Knowledge", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
neuper@42437
  1156
Iterator 1;
neuper@42437
  1157
moveActiveRoot 1;
wneuper@59248
  1158
autoCalculate 1 CompleteCalcHead;
walther@59747
  1159
autoCalculate 1 (Steps 1);
walther@59747
  1160
autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
wneuper@59123
  1161
appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)" (*|> Future.join*); (*<<<<<<<=========================*)
neuper@42437
  1162
(* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
neuper@42437
  1163
  would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
neuper@42437
  1164
  results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
neuper@42437
  1165
  instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
neuper@42437
  1166
  val ((pt,pos), _) = get_calc 1;
neuper@42437
  1167
  val p = get_pos 1 1;
neuper@42437
  1168
  val (Form f, _, asms) = pt_extract (pt, p);
neuper@42437
  1169
walther@59868
  1170
  if p = ([1], Res) andalso UnparseC.term f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" then
wneuper@59497
  1171
    case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
wneuper@59253
  1172
      ("diff_sum", thm)) =>
walther@59868
  1173
      if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
walther@59909
  1174
      else error "embed fun fill_form changed 11"
walther@59909
  1175
    | _ => error "embed fun fill_form changed 12"
walther@59909
  1176
  else error "embed fun fill_form changed 13";
neuper@42437
  1177
neuper@42437
  1178
findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
neuper@42437
  1179
(*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
neuper@42437
  1180
  d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
neuper@42437
  1181
  val ((pt,pos),_) = get_calc 1;
neuper@42437
  1182
  val p = get_pos 1 1;
neuper@42437
  1183
neuper@42437
  1184
  val (Form f, _, asms) = pt_extract (pt, p);
walther@59868
  1185
  if p = ([1], Res) andalso UnparseC.term f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" then
wneuper@59497
  1186
    case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
wneuper@59253
  1187
      ("diff_sum", thm)) =>
walther@59868
  1188
      if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
walther@59909
  1189
      else error "embed fun fill_form changed 21"
walther@59909
  1190
    | _ => error "embed fun fill_form changed 22"
walther@59909
  1191
  else error "embed fun fill_form changed 23";
neuper@42437
  1192
neuper@42437
  1193
requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
neuper@42437
  1194
  (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
neuper@42437
  1195
  val ((pt,pos),_) = get_calc 1;
neuper@42437
  1196
  val p = get_pos 1 1;
neuper@42437
  1197
  val (Form f, _, asms) = pt_extract (pt, p);
wneuper@59253
  1198
  if p = ([1], Res) andalso existpt [2] pt
walther@59868
  1199
    andalso UnparseC.term f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"
wneuper@59497
  1200
  then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
wneuper@59253
  1201
      ("diff_sum", thm)) =>
walther@59868
  1202
      if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
walther@59909
  1203
      else error "embed fun fill_form changed 31"
walther@59909
  1204
    | _ => error "embed fun fill_form changed 32"
walther@59909
  1205
  else error "embed fun fill_form changed 33";
neuper@42437
  1206
neuper@42437
  1207
(* input a formula which exactly fills the gaps in a "fillformula"
neuper@42437
  1208
   presented to the learner immediately before by "requestFillformula (errpatID, fillpatID)":
neuper@42437
  1209
   errpatID: lhs of the respective thm = lhs of fillformula with fillpatID.
neuper@42437
  1210
   the respective thm is in the ctree ................
neuper@42437
  1211
*)
neuper@42437
  1212
"~~~~~ fun inputFillFormula, args:"; val (cI, ifo) =
neuper@42437
  1213
  (1, "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)");
neuper@42437
  1214
    val ((pt, _), _) = get_calc cI
neuper@42437
  1215
    val pos = get_pos cI 1;
neuper@42437
  1216
neuper@42437
  1217
"~~~~~ fun is_exactly_equal, args:"; val ((pt, pos as (p, p_)), istr) = ((pt, pos), ifo);
walther@59881
  1218
  val SOME ifo = parseNEW (ThyC.get_theory "Isac_Knowledge" |> ThyC.to_ctxt) istr
neuper@42437
  1219
  val p' = lev_on p;
neuper@42437
  1220
  val tac = get_obj g_tac pt p';
wneuper@59497
  1221
val Rewrite_Inst ([bbb as "(''bdv'', x)"], ("diff_sin_chain", ttt)) = tac;
walther@59868
  1222
if (UnparseC.term o Thm.prop_of) ttt = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
wneuper@59252
  1223
else error "inputFillFormula changed 10";
walther@59921
  1224
  val Applicable.Yes rew = Step.check tac (pt, pos);
neuper@42437
  1225
  val Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) = rew;
neuper@42437
  1226
neuper@42437
  1227
"~~~~~ to inputFillFormula return val:"; val ("ok", tac) = ("ok", tac);
walther@59804
  1228
  val ("ok", (_, c, ptp as (_,p'))) = Step.by_tactic tac (pt, pos);
neuper@42437
  1229
    upd_calc cI (ptp, []);
neuper@42437
  1230
    upd_ipos cI 1 p';
neuper@42437
  1231
    autocalculateOK2xml cI pos (if null c then p' else last_elem c) p';
neuper@42437
  1232
neuper@42437
  1233
"~~~~~ final check:";
neuper@42437
  1234
val ((pt, _),_) = get_calc 1;
neuper@42437
  1235
val p = get_pos 1 1;
neuper@42437
  1236
val (Form f, _, asms) = pt_extract (pt, p);
walther@59868
  1237
  if p = ([2], Res) andalso UnparseC.term f = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)"
wneuper@59497
  1238
  then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
wneuper@59253
  1239
      ("diff_sin_chain", thm)) =>
walther@59868
  1240
      if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
wneuper@59253
  1241
      else error "inputFillFormula changed 111"
wneuper@59253
  1242
    | _ => error "inputFillFormula changed 112"
wneuper@59253
  1243
  else error "inputFillFormula changed 113";
neuper@42437
  1244
wneuper@59262
  1245
"--------- fun appl_adds -----------------------------------------";
wneuper@59262
  1246
"--------- fun appl_adds -----------------------------------------";
wneuper@59262
  1247
"--------- fun appl_adds -----------------------------------------";
wneuper@59262
  1248
(* val (dI, oris, ppc, pbt, selct::ss) = 
wneuper@59262
  1249
       (dI, pors, probl, ppc, map itms2fstr probl);
wneuper@59262
  1250
   ...vvv
wneuper@59262
  1251
   *)
wneuper@59262
  1252
(* val (dI, oris, ppc, pbt, (selct::ss))=
wneuper@59262
  1253
       (#1 (some_spec ospec spec), oris, []:itm list,
wneuper@59262
  1254
	((#ppc o get_pbt) (#2 (some_spec ospec spec))),(imodel2fstr imodel));
wneuper@59262
  1255
   val iii = appl_adds dI oris ppc pbt (selct::ss); 
wneuper@59262
  1256
   tracing(itms2str_ thy iii);
wneuper@59262
  1257
wneuper@59262
  1258
 val itm = appl_add' dI oris ppc pbt selct;
wneuper@59262
  1259
 val ppc = insert_ppc' itm ppc;
wneuper@59262
  1260
wneuper@59262
  1261
 val _::selct::ss = (selct::ss);
wneuper@59262
  1262
 val itm = appl_add' dI oris ppc pbt selct;
wneuper@59262
  1263
 val ppc = insert_ppc' itm ppc;
wneuper@59262
  1264
wneuper@59262
  1265
 val _::selct::ss = (selct::ss);
wneuper@59262
  1266
 val itm = appl_add' dI oris ppc pbt selct;
wneuper@59262
  1267
 val ppc = insert_ppc' itm ppc;
wneuper@59262
  1268
 tracing(itms2str_ thy ppc);
wneuper@59262
  1269
wneuper@59262
  1270
 val _::selct::ss = (selct::ss);
wneuper@59262
  1271
 val itm = appl_add' dI oris ppc pbt selct;
wneuper@59262
  1272
 val ppc = insert_ppc' itm ppc;
wneuper@59262
  1273
   *)
wneuper@59264
  1274
"--------- fun concat_deriv --------------------------------------";
wneuper@59264
  1275
"--------- fun concat_deriv --------------------------------------";
wneuper@59264
  1276
"--------- fun concat_deriv --------------------------------------";
wneuper@59264
  1277
(*
wneuper@59264
  1278
 val ({rew_ord, erls, rules,...}, fo, ifo) = 
walther@59852
  1279
     (Rule_Set.rep Test_simplify, str2term "x+1+ -1*2=0", str2term "-2*1+(x+1)=0");
walther@59906
  1280
 (tracing o Derive.trtas2str) fod';
wneuper@59264
  1281
> ["
wneuper@59264
  1282
(x + 1 + -1 * 2 = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (x + 1) = 0, []))","
wneuper@59264
  1283
(-1 * 2 + (x + 1) = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (1 + x) = 0, []))","
wneuper@59264
  1284
(-1 * 2 + (1 + x) = 0, Thm ("radd_left_commute","?x + (?y + ?z) = ?y + (?x + ?z)"), (1 + (-1 * 2 + x) = 0, []))","
wneuper@59264
  1285
(1 + (-1 * 2 + x) = 0, Thm ("#mult_Float ((~1,0), (0,0)) __ ((2,0), (0,0))","-1 * 2 = -2"), (1 + (-2 + x) = 0, []))"]
wneuper@59264
  1286
val it = () : unit
walther@59906
  1287
 (tracing o Derive.trtas2str) (map Derive.rev_deriv' rifod');
wneuper@59264
  1288
> ["
wneuper@59264
  1289
(1 + (-2 + x) = 0, Thm ("sym_#mult_Float ((~2,0), (0,0)) __ ((1,0), (0,0))","-2 = -2 * 1"), (1 + (-2 * 1 + x) = 0, []))","
wneuper@59264
  1290
(1 + (-2 * 1 + x) = 0, Thm ("sym_radd_left_commute","?y + (?x + ?z) = ?x + (?y + ?z)"), (-2 * 1 + (1 + x) = 0, []))","
wneuper@59264
  1291
(-2 * 1 + (1 + x) = 0, Thm ("sym_radd_commute","?n + ?m = ?m + ?n"), (-2 * 1 + (x + 1) = 0, []))"]
wneuper@59264
  1292
val it = () : unit
wneuper@59264
  1293
*)
wneuper@59264
  1294
"--------- handle an input formula -------------------------------";
wneuper@59264
  1295
"--------- handle an input formula -------------------------------";
wneuper@59264
  1296
"--------- handle an input formula -------------------------------";
wneuper@59264
  1297
(*
wneuper@59264
  1298
Untersuchung zur Formeleingabe (appendFormula, replaceFormla) zu einer Anregung von Alan Krempler:
wneuper@59264
  1299
Welche RICHTIGEN Formeln koennen NICHT abgeleitet werden, 
wneuper@59264
  1300
wenn Abteilungen nur auf gleichem Level gesucht werden ?
wneuper@59264
  1301
WN.040216 
wneuper@59264
  1302
wneuper@59264
  1303
Beispiele zum Equationsolver von Richard Lang aus /src/sml/kbtest/rlang.sml
wneuper@59264
  1304
wneuper@59264
  1305
------------------------------------------------------------------------------
wneuper@59264
  1306
"Schalk I s.87 Bsp 52a ((5*x)/(x - 2) - x/(x+2)=4)";
wneuper@59264
  1307
------------------------------------------------------------------------------
wneuper@59264
  1308
1. "5 * x / (x - 2) - x / (x + 2) = 4"
wneuper@59264
  1309
...
wneuper@59367
  1310
4. "12 * x + 4 * x ^^^ 2 = 4 * (-4 + x ^^^ 2)",Subproblem["normalise", "poly"..
wneuper@59264
  1311
...
wneuper@59264
  1312
4.3. "16 + 12 * x = 0", Subproblem["degree_1", "polynomial", "univariate"..
wneuper@59264
  1313
...
wneuper@59264
  1314
4.3.3. "[x = -4 / 3]")), Check_elementwise "Assumptions"
wneuper@59264
  1315
...
wneuper@59264
  1316
"[x = -4 / 3]"
wneuper@59264
  1317
------------------------------------------------------------------------------
wneuper@59264
  1318
(1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
wneuper@59264
  1319
wneuper@59264
  1320
(4.1)..(4.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
wneuper@59264
  1321
------------------------------------------------------------------------------
wneuper@59264
  1322
wneuper@59264
  1323
wneuper@59264
  1324
------------------------------------------------------------------------------
wneuper@59264
  1325
"Schalk I s.87 Bsp 55b (x/(x^^^2 - 6*x+9) - 1/(x^^^2 - 3*x) =1/x)";
wneuper@59264
  1326
------------------------------------------------------------------------------
wneuper@59264
  1327
1. "x / (x ^^^ 2 - 6 * x + 9) - 1 / (x ^^^ 2 - 3 * x) = 1 / x"
wneuper@59264
  1328
...
wneuper@59264
  1329
4. "(3 + (-1 * x + x ^^^ 2)) * x = 1 * (9 * x + (x ^^^ 3 + -6 * x ^^^ 2))"
wneuper@59367
  1330
                         Subproblem["normalise", "polynomial", "univariate"..
wneuper@59264
  1331
...
wneuper@59264
  1332
4.4. "-6 * x + 5 * x ^^^ 2 = 0", Subproblem["bdv_only", "degree_2", "poly"..
wneuper@59264
  1333
...
wneuper@59264
  1334
4.4.4. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
wneuper@59264
  1335
4.4.5. "[x = 0, x = 6 / 5]"
wneuper@59264
  1336
...
wneuper@59264
  1337
5. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
wneuper@59264
  1338
   "[x = 6 / 5]"
wneuper@59264
  1339
------------------------------------------------------------------------------
wneuper@59264
  1340
(1)..(4): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite schiebt [Ableitung waere in 4.4.x]
wneuper@59264
  1341
wneuper@59264
  1342
(4.1)..(4.4.5): keine 'richtige' Eingabe kann abgeleitet werden, die dem Ergebnis "[x = 6 / 5]" aequivalent ist [Ableitung waere in 5.]
wneuper@59264
  1343
------------------------------------------------------------------------------
wneuper@59264
  1344
wneuper@59264
  1345
wneuper@59264
  1346
------------------------------------------------------------------------------
wneuper@59264
  1347
"Schalk II s.56 Bsp 73b (sqrt(x+1)+sqrt(4*x+4)=sqrt(9*x+9))";
wneuper@59264
  1348
------------------------------------------------------------------------------
wneuper@59264
  1349
1. "sqrt (x + 1) + sqrt (4 * x + 4) = sqrt (9 * x + 9)"
wneuper@59264
  1350
...
wneuper@59264
  1351
6. "13 + 13 * x + -2 * sqrt ((4 + 4 * x) * (9 + 9 * x)) = 1 + x"
wneuper@59489
  1352
                             Subproblem["sq", "rootX", "univariate", "equation"]
wneuper@59264
  1353
...
wneuper@59264
  1354
6.6. "144 + 288 * x + 144 * x ^^^ 2 = 144 + x ^^^ 2 + 288 * x + 143 * x ^^^ 2"
wneuper@59367
  1355
                Subproblem["normalise", "polynomial", "univariate", "equation"]
wneuper@59264
  1356
...
wneuper@59264
  1357
6.6.3 "0 = 0"    Subproblem["degree_0", "polynomial", "univariate", "equation"]
wneuper@59264
  1358
...                                       Or_to_List
wneuper@59264
  1359
6.6.3.2 "UniversalList"
wneuper@59264
  1360
------------------------------------------------------------------------------
wneuper@59264
  1361
(1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die eine der Wurzeln auf die andere Seite verschieb [Ableitung ware in 6.6.n]
wneuper@59264
  1362
wneuper@59264
  1363
(6.1)..(6.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 6.6.n]
wneuper@59264
  1364
------------------------------------------------------------------------------
wneuper@59264
  1365
*)
wneuper@59264
  1366
(*sh. comments auf 498*)
wneuper@59264
  1367
"--------- fun dropwhile' ----------------------------------------";
wneuper@59264
  1368
"--------- fun dropwhile' ----------------------------------------";
wneuper@59264
  1369
"--------- fun dropwhile' ----------------------------------------";
wneuper@59264
  1370
(*
wneuper@59264
  1371
 fun equal a b = a=b;
wneuper@59264
  1372
 val foder = [0,1,2,3,4,5]; val ifoder = [11,12,3,4,5];
wneuper@59264
  1373
 val r_foder = rev foder;  val r_ifoder = rev ifoder;
wneuper@59264
  1374
 dropwhile' equal r_foder r_ifoder;
wneuper@59264
  1375
> vval it = ([0, 1, 2, 3], [3, 12, 11]) : int list * int list
wneuper@59264
  1376
wneuper@59264
  1377
 val foder = [3,4,5]; val ifoder = [11,12,3,4,5];
wneuper@59264
  1378
 val r_foder = rev foder;  val r_ifoder = rev ifoder;
wneuper@59264
  1379
 dropwhile' equal r_foder r_ifoder;
wneuper@59264
  1380
> val it = ([3], [3, 12, 11]) : int list * int list
wneuper@59264
  1381
wneuper@59264
  1382
 val foder = [5]; val ifoder = [11,12,3,4,5];
wneuper@59264
  1383
 val r_foder = rev foder;  val r_ifoder = rev ifoder;
wneuper@59264
  1384
 dropwhile' equal r_foder r_ifoder;
wneuper@59264
  1385
> val it = ([5], [5, 4, 3, 12, 11]) : int list * int list
wneuper@59264
  1386
wneuper@59264
  1387
 val foder = [10,11,12,13,14,15]; val ifoder = [11,12,3,4,5];
wneuper@59264
  1388
 val r_foder = rev foder;  val r_ifoder = rev ifoder;
wneuper@59264
  1389
 dropwhile' equal r_foder r_ifoder;
wneuper@59264
  1390
> *** dropwhile': did not start with equal elements*)