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