test/Tools/isac/Interpret/error-pattern.sml
author wneuper <walther.neuper@jku.at>
Tue, 20 Jul 2021 14:37:56 +0200
changeset 60339 0d22a6bf1fc6
parent 60336 dcb37736d573
child 60340 0ee698b0a703
permissions -rw-r--r--
//reduce the number of TermC.parse*; "//"means: tests broken .

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