test/Tools/isac/Interpret/error-pattern.sml
author wneuper <Walther.Neuper@jku.at>
Thu, 20 Oct 2022 10:23:38 +0200
changeset 60571 19a172de0bb5
parent 60565 f92963a33fe3
child 60577 ca9f84786137
permissions -rw-r--r--
followup 6a: tests run from @{context} without sessions
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:";
Walther@60571
    26
(*"--------- CAS-command on ([],Pbl) -------------------------------";*)
Walther@60571
    27
(*"--------- CAS-command on ([],Pbl) FE-interface ------------------";*)
walther@59772
    28
"--------- locate_input_term [rational,simplification] ----------------------";
Walther@60571
    29
(*"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";*)
neuper@37906
    30
"--------- Take as 1st tac, start from exp -----------------------";
Walther@60571
    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@60559
    50
 val Prog sc = (#scr o MethodC.from_store ctxt) ["Test", "squ-equ-test-subpbl1"];
walther@59868
    51
 (writeln o UnparseC.term) sc;
Walther@60559
    52
 val Prog sc = (#scr o MethodC.from_store ctxt) ["Test", "solve_linear"];
walther@59868
    53
 (writeln o UnparseC.term) sc;
neuper@37906
    54
Walther@60549
    55
 States.reset ();
Walther@60571
    56
 CalcTree @{context} [(["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@60549
    61
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
Walther@60549
    62
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
neuper@37906
    63
Walther@60549
    64
 appendFormula 1 "- 2 * 1 + (1 + x) = 0" (*|> Future.join*); refFormula 1 (States.get_pos 1 1);
Walther@60549
    65
 val ((pt,_),_) = States.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);
Walther@60549
    90
 val ((pt,_),_) = States.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 =============
Walther@60549
    97
 val (_,(tac,_,_)::_) = States.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;
Walther@60549
   103
 val ((pt,_),_) = States.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;
Walther@60549
   107
   val ((pt,p),_) = States.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@60565
   122
		       (TermC.parse_test @{context} "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@60565
   128
		       (TermC.parse_test @{context} "- 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 ----------------------";
Walther@60549
   140
 States.reset ();
Walther@60571
   141
 CalcTree @{context} [(["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@60549
   146
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1) (*x + 1 = 2*);
Walther@60549
   147
 appendFormula 1 "2+ - 1 + x = 2" (*|> Future.join*); refFormula 1 (States.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); 
Walther@60549
   158
 val ((pt,_),_) = States.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_*)
Walther@60549
   163
 val (_,(tac,_,_)::_) = States.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;
Walther@60549
   167
 val ((pt,_),_) = States.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 ----------------------";
Walther@60549
   175
 States.reset ();
Walther@60571
   176
 CalcTree @{context} [(["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@60549
   181
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
Walther@60549
   182
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
neuper@37906
   183
wneuper@59123
   184
 appendFormula 1 "x = 2" (*|> Future.join*);
Walther@60549
   185
 val ((pt,p),_) = States.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;
Walther@60549
   193
 val (_,(tac,_,_)::_) = States.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;
Walther@60549
   197
 val ((pt,_),_) = States.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
*)
Walther@60549
   208
 States.reset ();
Walther@60571
   209
 CalcTree @{context} [(["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@60549
   214
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
Walther@60549
   215
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
neuper@37906
   216
wneuper@59123
   217
 appendFormula 1 "x = 1" (*|> Future.join*);
Walther@60549
   218
 val ((pt,p),_) = States.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;
Walther@60549
   226
 val (_,(tac,_,_)::_) = States.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;
Walther@60549
   230
 val ((pt,_),_) = States.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]---///--";
Walther@60549
   238
 States.reset ();
Walther@60571
   239
 CalcTree @{context} [(["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@60549
   244
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
Walther@60549
   245
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
wneuper@59123
   246
 appendFormula 1 "[x = 3 + -2*1]" (*|> Future.join*);
Walther@60549
   247
 val ((pt,p),_) = States.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;
Walther@60549
   253
 val ((pt,p),_) = States.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 + = ----------------------------";
Walther@60549
   262
 States.reset ();
Walther@60571
   263
 CalcTree @{context} [(["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@60549
   268
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
Walther@60549
   269
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
Walther@60549
   270
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*- 1 + x*);
neuper@37906
   271
Walther@60549
   272
 replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (States.get_pos 1 1);
Walther@60549
   273
 val ((pt,_),_) = States.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
*)
Walther@60523
   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;
Walther@60549
   300
 val ((pt,pos as (p,_)),_) = States.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 ---------------------";
Walther@60549
   308
 States.reset ();
Walther@60571
   309
 CalcTree @{context} [(["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@60549
   314
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
Walther@60549
   315
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
neuper@37906
   316
Walther@60549
   317
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (States.get_pos 1 1);
Walther@60549
   318
 val ((pt,_),_) = States.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;
Walther@60549
   324
 val ((pt,pos as (p,_)),_) = States.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 ---------------------";
Walther@60549
   332
 States.reset (); 
Walther@60571
   333
 CalcTree @{context} [(["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@60549
   338
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
neuper@37906
   339
Walther@60549
   340
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (States.get_pos 1 1);
Walther@60549
   341
 val ((pt,_),_) = States.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;
Walther@60549
   347
 val ((pt,pos as (p,_)),_) = States.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 -----------------------";
Walther@60549
   355
 States.reset ();
Walther@60571
   356
 CalcTree @{context} [(["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;
Walther@60549
   362
 if States.get_pos 1 1 = ([1], Frm) then ()
neuper@38031
   363
 else error "inform.sml: diff.behav. cut calculation 1";
neuper@37906
   364
Walther@60549
   365
 replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (States.get_pos 1 1);
Walther@60549
   366
 val ((pt,p),_) = States.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 !!!!!!!!!!!!!!!!!!*)
Walther@60571
   400
 val (p,_,f,nxt,_,pt) = Test_Code.init_calc @{context} [(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 ------------------------------------------";
Walther@60549
   452
 States.reset ();
Walther@60571
   453
 CalcTree @{context} [(["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@60549
   458
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 = 2*)
Walther@60549
   459
 autoCalculate 1 (Steps 1); refFormula 1 (States.get_pos 1 1);(*x + 1 + - 1 * 2 = 0*);
neuper@37906
   460
neuper@37906
   461
 appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
Walther@60549
   462
 val ((pt,_),_) = States.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
Walther@60571
   469
(*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
neuper@37906
   470
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   471
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   472
"--------- CAS-command on ([],Pbl) -------------------------------";
neuper@37906
   473
val (p,_,f,nxt,_,pt) = 
Walther@60571
   474
    Test_Code.init_calc @{context} [([], References.empty)];
walther@60340
   475
val ifo = "solve(x+1=2,x)";
walther@60340
   476
val (_,(_,c,(pt,p))) = Step_Solve.by_term (pt,p) "solve(x+1=2,x)";
Walther@60571
   477
( *
walther@60242
   478
  This trick           \<up> \<up> \<up> micked input of \<up> \<up> \<up> \<up>  \<up> ^^ in the front-end.
walther@59921
   479
  The trick worked in changeset fbaff8cf0179, it does not work in 59c5dd27d589 anymore
walther@59921
   480
  (TODO hg bisect ?) and raises the ERROR Undefined fact: "xfoldr_Nil".
walther@59921
   481
walther@59921
   482
  Compare tests "CAS-command" in test/../inssort.sml etc.
walther@59921
   483
  ---------------------------------------------------------------------------------------------
walther@59983
   484
Test_Tool.show_pt pt;
walther@59997
   485
val nxt = (Apply_Method ["Test", "squ-equ-test-subpbl1"]);
neuper@37906
   486
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@37906
   487
if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
neuper@38031
   488
else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
wneuper@59252
   489
DEconstrCalcTree 1;
walther@59921
   490
-----------------------------------------------------------------------------------------------*)
neuper@37906
   491
Walther@60571
   492
(*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
neuper@37906
   493
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
   494
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
neuper@37906
   495
"--------- CAS-command on ([],Pbl) FE-interface ------------------";
Walther@60549
   496
States.reset ();
Walther@60571
   497
CalcTree @{context} [([], References.empty)];
neuper@37906
   498
Iterator 1;
neuper@37906
   499
moveActiveRoot 1;
walther@60340
   500
replaceFormula 1 "solve(x+1=2,x)";
wneuper@59248
   501
autoCalculate 1 CompleteCalc;
Walther@60549
   502
val ((pt,p),_) = States.get_calc 1;
walther@59983
   503
Test_Tool.show_pt pt;
neuper@37906
   504
if p = ([], Res) then ()
neuper@38031
   505
else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
wneuper@59252
   506
DEconstrCalcTree 1;
Walther@60571
   507
-----------------------------------------------------------------------------------------------*)
neuper@37906
   508
wneuper@59562
   509
"--------- inform [rational,simplification] ----------------------";
wneuper@59562
   510
"--------- inform [rational,simplification] ----------------------";
wneuper@59562
   511
"--------- inform [rational,simplification] ----------------------";
Walther@60549
   512
States.reset ();
Walther@60571
   513
CalcTree @{context} [(["Term (a * x / (b * x) + c * x / (d * x) + e / f)", "normalform N"],
neuper@52105
   514
	("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
neuper@37906
   515
Iterator 1; moveActiveRoot 1;
wneuper@59248
   516
autoCalculate 1 CompleteCalcHead;
neuper@52105
   517
walther@60324
   518
"--- (- 1) give a preview on the calculation without any input";
neuper@52105
   519
(*
wneuper@59248
   520
autoCalculate 1 CompleteCalc;
Walther@60549
   521
val ((pt, p), _) = States.get_calc 1;
walther@59983
   522
Test_Tool.show_pt pt;
neuper@52105
   523
[
neuper@52105
   524
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   525
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   526
(([1], Res), a / b + c / d + e / f),                             <--- (1) input arbitrary
neuper@52105
   527
(([2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   528
(([3], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   529
(([4], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)), <--- (2) input next
neuper@52105
   530
(([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))]  <--- (3) is also final result
neuper@52105
   531
                                                                          EXAMPLE NOT OPTIMAL
neuper@52105
   532
*)
neuper@52105
   533
"--- (0) user input as the *first* step does not work, thus impdo at least 1 step";
walther@59747
   534
autoCalculate 1 (Steps 1);
walther@59747
   535
autoCalculate 1 (Steps 1);
Walther@60549
   536
val ((pt, p), _) = States.get_calc 1;
walther@59983
   537
(*Test_Tool.show_pt pt;
neuper@52105
   538
[
neuper@52105
   539
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   540
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   541
(([1], Res), a / b + c / d + e / f)] 
neuper@52105
   542
*)
neuper@52105
   543
"--- (1) input an arbitrary next formula";
wneuper@59123
   544
appendFormula 1 "((a * d) + (c * b)) / (b * d) + e / f" (*|> Future.join*);
Walther@60549
   545
val ((pt, p), _) = States.get_calc 1;
walther@59983
   546
(*Test_Tool.show_pt pt;
neuper@52105
   547
[
neuper@52105
   548
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   549
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   550
(([1], Res), a / b + c / d + e / f),
neuper@52105
   551
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   552
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   553
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   554
(([2], Res), (a * d + c * b) / (b * d) + e / f)] 
neuper@52105
   555
*)
Walther@60549
   556
val ((pt,p),_) = States.get_calc 1;
neuper@52105
   557
if p = ([2], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
neuper@38031
   558
else error ("inform.sml: [rational,simplification] 1");
neuper@37906
   559
neuper@52105
   560
"--- (2) input the next formula that would be presented by mat-engine";
neuper@52105
   561
(* generate a preview:
walther@59747
   562
autoCalculate 1 (Steps 1);
Walther@60549
   563
val ((pt, p), _) = States.get_calc 1;
walther@59983
   564
Test_Tool.show_pt pt;
neuper@52105
   565
[
neuper@52105
   566
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   567
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   568
(([1], Res), a / b + c / d + e / f),
neuper@52105
   569
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   570
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   571
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   572
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   573
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))]   <--- input this
neuper@52105
   574
*)
wneuper@59123
   575
appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
Walther@60549
   576
val ((pt, p), _) = States.get_calc 1;
walther@59983
   577
(*Test_Tool.show_pt pt;
neuper@52105
   578
[
neuper@52105
   579
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   580
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   581
(([1], Res), a / b + c / d + e / f),
neuper@52105
   582
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   583
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   584
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   585
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   586
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
neuper@52105
   587
*)
neuper@52105
   588
if p = ([3], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
neuper@38031
   589
else error ("inform.sml: [rational,simplification] 2");
neuper@37906
   590
neuper@52105
   591
"--- (3) input the exact final result";
wneuper@59123
   592
appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
Walther@60549
   593
val ((pt, p), _) = States.get_calc 1;
walther@59983
   594
(*Test_Tool.show_pt pt;
neuper@52105
   595
[
neuper@52105
   596
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   597
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   598
(([1], Res), a / b + c / d + e / f),
neuper@52105
   599
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   600
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   601
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   602
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   603
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   604
(([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   605
(([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   606
(([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   607
(([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
neuper@52105
   608
*)
neuper@52105
   609
if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
neuper@38031
   610
else error ("inform.sml: [rational,simplification] 3");
neuper@52105
   611
neuper@52105
   612
"--- (4) finish the calculation + check the postcondition (in the future)";
wneuper@59248
   613
autoCalculate 1 CompleteCalc;
Walther@60549
   614
val ((pt, p), _) = States.get_calc 1;
neuper@52105
   615
val (t, asm) = get_obj g_result pt [];
walther@59868
   616
if UnparseC.term t = "(a * d * f + b * c * f + b * d * e) / (b * d * f)" andalso
walther@59921
   617
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
   618
                    "[]" (*..found broken in child of 33913fe24685, error covered by  CAS-command *)
neuper@52105
   619
then () else error "inform [rational,simplification] changed at end";
walther@59983
   620
(*Test_Tool.show_pt pt;
neuper@52105
   621
[
neuper@52105
   622
(([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
neuper@52105
   623
(([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
neuper@52105
   624
(([1], Res), a / b + c / d + e / f),
neuper@52105
   625
(([2,1], Frm), a / b + c / d + e / f),
neuper@52105
   626
(([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   627
(([2,2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   628
(([2], Res), (a * d + c * b) / (b * d) + e / f),
neuper@52105
   629
(([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   630
(([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   631
(([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   632
(([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   633
(([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
neuper@52105
   634
(([5], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
neuper@52105
   635
(([6], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)),
neuper@52105
   636
(([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))] 
neuper@52105
   637
*)
wneuper@59252
   638
DEconstrCalcTree 1;
neuper@37906
   639
Walther@60571
   640
(*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
neuper@37906
   641
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   642
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
neuper@37906
   643
"--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
Walther@60565
   644
val t = TermC.parse_test @{context} "Diff (x \<up> 2 + x + 1, x)";
walther@60336
   645
case t of Const (\<^const_name>\<open>Diff\<close>, _) $ _ => ()
neuper@37906
   646
	| _ => raise 
neuper@37906
   647
	      error "diff.sml behav.changed for CAS Diff (..., x)";
walther@60230
   648
TermC.atomty t;
neuper@37906
   649
"-----------------------------------------------------------------";
Walther@60549
   650
(*1>*)States.reset ();
Walther@60571
   651
(*2>*)CalcTree @{context} [([], References.empty)];
neuper@37906
   652
(*3>*)Iterator 1;moveActiveRoot 1;
neuper@37906
   653
"----- here the Headline has been finished";
neuper@37906
   654
(*4>*)moveActiveFormula 1 ([],Pbl);
walther@60242
   655
(*5>*)replaceFormula 1 "Diff (x \<up> 2 + x + 1, x)";
Walther@60549
   656
val ((pt,_),_) = States.get_calc 1;
walther@59921
   657
val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
neuper@37926
   658
val (SOME istate, NONE) = loc;
wneuper@59348
   659
(*default_print_depth 5;*)
neuper@37906
   660
writeln"-----------------------------------------------------------";
neuper@37906
   661
spec;
walther@59942
   662
writeln (I_Model.to_string ctxt probl);
walther@59942
   663
writeln (I_Model.to_string ctxt meth);
walther@59844
   664
writeln (Istate.string_of (fst istate));
neuper@37906
   665
neuper@37906
   666
refFormula 1 ([],Pbl) (*--> correct CalcHead*);
neuper@37906
   667
 (*081016 NOT necessary (but leave it in Java):*)
wneuper@59248
   668
(*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
neuper@37906
   669
"----- here the CalcHead has been completed --- ONCE MORE ?????";
neuper@37906
   670
neuper@37906
   671
(***difference II***)
Walther@60549
   672
val ((pt,p),_) = States.get_calc 1;
neuper@37906
   673
(*val p = ([], Pbl)*)
walther@59921
   674
val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
neuper@37926
   675
val (SOME istate, NONE) = loc;
walther@59844
   676
(*default_print_depth 5;*) writeln (Istate.string_of (fst istate));  (*default_print_depth 3;*)
wneuper@59583
   677
(*Pstate ([],
neuper@37926
   678
 [], NONE,
neuper@37906
   679
 ??.empty, Sundef, false)*)
wneuper@59348
   680
(*default_print_depth 5;*) spec; (*default_print_depth 3;*)
wneuper@59592
   681
(*("Isac_Knowledge",
neuper@37906
   682
      ["derivative_of", "function"],
neuper@37906
   683
      ["diff", "differentiate_on_R"]) : spec*)
walther@59942
   684
writeln (I_Model.to_string ctxt probl);
neuper@37906
   685
(*[
walther@60242
   686
(1 ,[1] ,true ,#Given ,Cor functionTerm (x \<up> 2 + x + 1) ,(f_, [x \<up> 2 + x + 1])),
neuper@37906
   687
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   688
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
walther@59942
   689
writeln (I_Model.to_string ctxt meth);
neuper@37906
   690
(*[
walther@60242
   691
(1 ,[1] ,true ,#Given ,Cor functionTerm (x \<up> 2 + x + 1) ,(f_, [x \<up> 2 + x + 1])),
neuper@37906
   692
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   693
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37906
   694
writeln"-----------------------------------------------------------";
neuper@37906
   695
(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
neuper@37906
   696
(*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
wneuper@59248
   697
autoCalculate 1 CompleteCalc;
Walther@60549
   698
val ((pt,p),_) = States.get_calc 1;
walther@59983
   699
val Form res = (#1 o ME_Misc.pt_extract) (pt, ([],Res));
walther@59983
   700
Test_Tool.show_pt pt;
walther@60242
   701
walther@59868
   702
if p = ([], Res) andalso UnparseC.term res = "1 + 2 * x" then ()
walther@60242
   703
else error "diff.sml behav.changed for Diff (x \<up> 2 + x + 1, x)";
wneuper@59252
   704
DEconstrCalcTree 1;
Walther@60571
   705
-----------------------------------------------------------------------------------------------*)
neuper@37906
   706
neuper@37906
   707
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   708
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   709
"--------- Take as 1st tac, start from exp -----------------------";
neuper@37906
   710
(*the following input is copied from BridgeLog Java <==> SML,
neuper@37906
   711
  omitting unnecessary inputs*)
Walther@60549
   712
(*1>*)States.reset ();
Walther@60571
   713
(*2>*)CalcTree @{context} [(["functionTerm (x \<up> 2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac_Knowledge",["derivative_of", "function"],["diff", "differentiate_on_R"]))];
neuper@37906
   714
(*3>*)Iterator 1; moveActiveRoot 1;
neuper@37906
   715
wneuper@59248
   716
(*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
neuper@37906
   717
(***difference II***)
Walther@60549
   718
val ((pt,_),_) = States.get_calc 1;
walther@59921
   719
val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
neuper@37926
   720
val (SOME istate, NONE) = loc;
walther@59844
   721
(*default_print_depth 5;*) writeln (Istate.string_of (fst istate));  (*default_print_depth 3;*)
wneuper@59583
   722
(*Pstate ([],
neuper@37926
   723
 [], NONE,
neuper@37906
   724
 ??.empty, Sundef, false)*)
wneuper@59348
   725
(*default_print_depth 5;*) spec; (*default_print_depth 3;*)
wneuper@59592
   726
(*("Isac_Knowledge",
neuper@37906
   727
      ["derivative_of", "function"],
neuper@37906
   728
      ["diff", "differentiate_on_R"]) : spec*)
walther@59942
   729
writeln (I_Model.to_string ctxt probl);
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]))]*)
walther@59942
   734
writeln (I_Model.to_string ctxt meth);
neuper@37906
   735
(*[
walther@60242
   736
(1 ,[1] ,true ,#Given ,Cor functionTerm (x \<up> 2 + x + 1) ,(f_, [x \<up> 2 + x + 1])),
neuper@37906
   737
(2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
akargl@42176
   738
(3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
neuper@37906
   739
writeln"-----------------------------------------------------------";
neuper@37906
   740
(*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
walther@59747
   741
autoCalculate 1 (Steps 1);
Walther@60549
   742
val ((pt,p),_) = States.get_calc 1;
walther@59983
   743
val Form res = (#1 o ME_Misc.pt_extract) (pt, p);
walther@60242
   744
if UnparseC.term res = "d_d x (x \<up> 2 + x + 1)" then ()
walther@60242
   745
else error "diff.sml Diff (x \<up> 2 + x + 1, x) from exp";
wneuper@59252
   746
DEconstrCalcTree 1;
neuper@37906
   747
Walther@60571
   748
(*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
walther@59845
   749
"--------- implicit_take, start with <NEW> (CAS input) ---------------";
walther@59845
   750
"--------- implicit_take, start with <NEW> (CAS input) ---------------";
walther@59845
   751
"--------- implicit_take, start with <NEW> (CAS input) ---------------";
Walther@60549
   752
States.reset ();
Walther@60571
   753
CalcTree @{context} [([], References.empty)];
neuper@37906
   754
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   755
[[from sml:  1 
neuper@37906
   756
[[from sml: <CALCTREE>
neuper@37906
   757
[[from sml:    <CALCID> 1 </CALCID>
neuper@37906
   758
[[from sml: </CALCTREE>
neuper@37906
   759
[[from sml: @@@@@end@@@@@*)
neuper@37906
   760
Iterator 1;
neuper@37906
   761
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   762
[[from sml:  1 
neuper@37906
   763
[[from sml: <ADDUSER>
neuper@37906
   764
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   765
[[from sml:   <USERID> 1 </USERID>
neuper@37906
   766
[[from sml: </ADDUSER>
neuper@37906
   767
[[from sml: @@@@@end@@@@@*)
neuper@37906
   768
moveActiveRoot 1;
neuper@37906
   769
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   770
[[from sml:  1 
neuper@37906
   771
[[from sml: <CALCITERATOR>
neuper@37906
   772
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   773
[[from sml:   <POSITION>
neuper@37906
   774
[[from sml:     <INTLIST>
neuper@37906
   775
[[from sml:     </INTLIST>
neuper@37906
   776
[[from sml:     <POS> Pbl </POS>
neuper@37906
   777
[[from sml:   </POSITION>
neuper@37906
   778
[[from sml: </CALCITERATOR>
neuper@37906
   779
[[from sml: @@@@@end@@@@@*)
neuper@37906
   780
getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
neuper@37906
   781
(*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
neuper@37906
   782
[[from sml:  1 
neuper@37906
   783
[[from sml: <GETELEMENTSFROMTO>
neuper@37906
   784
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   785
[[from sml:   <FORMHEADS>
neuper@37906
   786
[[from sml:     <CALCFORMULA>
neuper@37906
   787
[[from sml:       <POSITION>
neuper@37906
   788
[[from sml:         <INTLIST>
neuper@37906
   789
[[from sml:         </INTLIST>
neuper@37906
   790
[[from sml:         <POS> Pbl </POS>
neuper@37906
   791
[[from sml:       </POSITION>
neuper@37906
   792
[[from sml:       <FORMULA>
neuper@37906
   793
[[from sml:         <MATHML>
neuper@37906
   794
[[from sml:           <ISA> ________________________________________________ </ISA>
neuper@37906
   795
[[from sml:         </MATHML>
neuper@37906
   796
[[from sml: 
neuper@37906
   797
[[from sml:       </FORMULA>
neuper@37906
   798
[[from sml:     </CALCFORMULA>
neuper@37906
   799
[[from sml:   </FORMHEADS>
neuper@37906
   800
[[from sml: </GETELEMENTSFROMTO>
neuper@37906
   801
[[from sml: @@@@@end@@@@@*)
neuper@37906
   802
refFormula 1 ([],Pbl);
neuper@37906
   803
(*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
neuper@37906
   804
[[from sml:  1 
neuper@37906
   805
[[from sml: <REFFORMULA>
neuper@37906
   806
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   807
[[from sml:   <CALCHEAD status = "incorrect">
neuper@37906
   808
[[from sml:     <POSITION>
neuper@37906
   809
[[from sml:       <INTLIST>
neuper@37906
   810
[[from sml:       </INTLIST>
neuper@37906
   811
[[from sml:       <POS> Pbl </POS>
neuper@37906
   812
[[from sml:     </POSITION>
neuper@37906
   813
[[from sml:     <HEAD>
neuper@37906
   814
[[from sml:       <MATHML>
walther@59879
   815
[[from sml:         <ISA> Problem (ThyC.id_empty, [e_pblID]) </ISA>
neuper@37906
   816
[[from sml:       </MATHML>
neuper@37906
   817
[[from sml:     </HEAD>
neuper@37906
   818
[[from sml:     <MODEL>
neuper@37906
   819
[[from sml:       <GIVEN>  </GIVEN>
neuper@37906
   820
[[from sml:       <WHERE>  </WHERE>
neuper@37906
   821
[[from sml:       <FIND>  </FIND>
neuper@37906
   822
[[from sml:       <RELATE>  </RELATE>
neuper@37906
   823
[[from sml:     </MODEL>
neuper@37906
   824
[[from sml:     <BELONGSTO> Pbl </BELONGSTO>
neuper@37906
   825
[[from sml:     <SPECIFICATION>
walther@59879
   826
[[from sml:       <THEORYID> ThyC.id_empty </THEORYID>
neuper@37906
   827
[[from sml:       <PROBLEMID>
neuper@37906
   828
[[from sml:         <STRINGLIST>
walther@59903
   829
[[from sml:           <STRING> Problem.id_empty </STRING>
neuper@37906
   830
[[from sml:         </STRINGLIST>
neuper@37906
   831
[[from sml:       </PROBLEMID>
neuper@37906
   832
[[from sml:       <METHODID>
neuper@37906
   833
[[from sml:         <STRINGLIST>
neuper@37906
   834
[[from sml:           <STRING> e_metID </STRING>
neuper@37906
   835
[[from sml:         </STRINGLIST>
neuper@37906
   836
[[from sml:       </METHODID>
neuper@37906
   837
[[from sml:     </SPECIFICATION>
neuper@37906
   838
[[from sml:   </CALCHEAD>
neuper@37906
   839
[[from sml: </REFFORMULA>
neuper@37906
   840
[[from sml: @@@@@end@@@@@*)
neuper@37906
   841
moveActiveFormula 1 ([],Pbl);
neuper@37906
   842
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   843
[[from sml:  1 
neuper@37906
   844
[[from sml: <CALCITERATOR>
neuper@37906
   845
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   846
[[from sml:   <POSITION>
neuper@37906
   847
[[from sml:     <INTLIST>
neuper@37906
   848
[[from sml:     </INTLIST>
neuper@37906
   849
[[from sml:     <POS> Pbl </POS>
neuper@37906
   850
[[from sml:   </POSITION>
neuper@37906
   851
[[from sml: </CALCITERATOR>
neuper@37906
   852
[[from sml: @@@@@end@@@@@*)
neuper@37906
   853
replaceFormula 1 "Simplify (1+2)";
neuper@37906
   854
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   855
[[from sml:  1 
neuper@37906
   856
[[from sml: <REPLACEFORMULA>
neuper@37906
   857
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   858
[[from sml:   <CALCCHANGED>
neuper@37906
   859
[[from sml:     <UNCHANGED>
neuper@37906
   860
[[from sml:       <INTLIST>
neuper@37906
   861
[[from sml:       </INTLIST>
neuper@37906
   862
[[from sml:       <POS> Pbl </POS>
neuper@37906
   863
[[from sml:     </UNCHANGED>
neuper@37906
   864
[[from sml:     <DELETED>
neuper@37906
   865
[[from sml:       <INTLIST>
neuper@37906
   866
[[from sml:       </INTLIST>
neuper@37906
   867
[[from sml:       <POS> Pbl </POS>
neuper@37906
   868
[[from sml:     </DELETED>
neuper@37906
   869
[[from sml:     <GENERATED>
neuper@37906
   870
[[from sml:       <INTLIST>
neuper@37906
   871
[[from sml:       </INTLIST>
neuper@37906
   872
[[from sml:       <POS> Met </POS>                           DIFFERENCE: Pbl
neuper@37906
   873
[[from sml:     </GENERATED>
neuper@37906
   874
[[from sml:   </CALCCHANGED>
neuper@37906
   875
[[from sml: </REPLACEFORMULA>
neuper@37906
   876
[[from sml: @@@@@end@@@@@*)
neuper@37906
   877
getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(*              DIFFERENCE: Pbl*);
neuper@37906
   878
(*@@@@@begin@@@@@
neuper@37906
   879
 1
neuper@37906
   880
<GETELEMENTSFROMTO>
neuper@37906
   881
  <CALCID> 1 </CALCID>
neuper@37906
   882
  <FORMHEADS>
neuper@37906
   883
    <CALCFORMULA>
neuper@37906
   884
      <POSITION>
neuper@37906
   885
        <INTLIST>
neuper@37906
   886
        </INTLIST>
neuper@37906
   887
        <POS> Pbl </POS>
neuper@37906
   888
      </POSITION>
neuper@37906
   889
      <FORMULA>
neuper@37906
   890
        <MATHML>
neuper@37906
   891
          <ISA> Simplify (1 + 2) </ISA>                      WORKS !!!!!
neuper@37906
   892
        </MATHML>
neuper@37906
   893
      </FORMULA>
neuper@37906
   894
    </CALCFORMULA>
neuper@37906
   895
  </FORMHEADS>
neuper@37906
   896
</GETELEMENTSFROMTO>
neuper@37906
   897
@@@@@end@@@@@*)
neuper@37906
   898
getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
neuper@37906
   899
(*[[from sml: > @@@@@begin@@@@@
neuper@37906
   900
[[from sml:  1 
neuper@37906
   901
[[from sml: <SYSERROR>
neuper@37906
   902
[[from sml:   <CALCID> 1 </CALCID>
neuper@37906
   903
[[from sml:   <ERROR> error in getFormulaeFromTo </ERROR>
neuper@37906
   904
[[from sml: </SYSERROR>
neuper@37906
   905
[[from sml: @@@@@end@@@@@*)
neuper@37906
   906
(*step into getFormulaeFromTo --- bug corrected...*)
Walther@60571
   907
-----------------------------------------------------------------------------------------------*)
neuper@42423
   908
walther@59909
   909
"--------- build fun check_for' ------------------------------";
walther@59909
   910
"--------- build fun check_for' ------------------------------";
walther@59909
   911
"--------- build fun check_for' ------------------------------";
Walther@60565
   912
val subst = [(TermC.parse_test @{context} "bdv", TermC.parse_test @{context} "x")]: subst;
neuper@42423
   913
val rls = norm_Rational
walther@60230
   914
val pat = TermC.parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
Walther@60565
   915
val (res, inf) = (TermC.parse_test @{context} "(2 + 3)/(3 + 4)", TermC.parse_test @{context} "2 / 4");
Walther@60565
   916
val (res, inf) = (TermC.parse_test @{context} "(2 + 3)/(3 + 4)", TermC.parse_test @{context} "1 / 2");
neuper@42423
   917
walther@60230
   918
val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern TermC.matches in res*)
Walther@60509
   919
  rew_sub ctxt 1 [] Rewrite_Ord.function_empty Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
neuper@42423
   920
if rewritten then NONE else SOME "e_errpatID";
neuper@42423
   921
Walther@60500
   922
val norm_res = case rewrite_set_ ctxt false rls res' of
neuper@42423
   923
  NONE => res'
neuper@42423
   924
| SOME (norm_res, _) => norm_res
neuper@42423
   925
Walther@60500
   926
val norm_inf = case rewrite_set_ ctxt false rls inf of
neuper@42423
   927
  NONE => inf
neuper@42423
   928
| SOME (norm_inf, _) => norm_inf;
neuper@42423
   929
neuper@42423
   930
res' = inf;
neuper@42423
   931
norm_res = norm_inf;
neuper@42423
   932
walther@60230
   933
val pat = TermC.parse_patt @{theory} "(?a + ?b)/?a = ?b";
Walther@60565
   934
val (res, inf) = (TermC.parse_test @{context} "(2 + 3)/2", TermC.parse_test @{context} "3");
Walther@60523
   935
if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   936
then () else error "error patt example1 changed";
neuper@42423
   937
walther@60230
   938
val pat = TermC.parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
Walther@60565
   939
val (res, inf) = (TermC.parse_test @{context} "(2 + 3)/(2 + 4)", TermC.parse_test @{context} "3 / 4");
Walther@60523
   940
if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   941
then () else error "error patt example2 changed";
neuper@42423
   942
walther@60230
   943
val pat = TermC.parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
Walther@60565
   944
val (res, inf) = (TermC.parse_test @{context} "(2 + 3)/(3 + 4)", TermC.parse_test @{context} "2 / 4");
Walther@60523
   945
if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   946
then () else error "error patt example3 changed";
neuper@42423
   947
Walther@60565
   948
val inf =  TermC.parse_test @{context} "1 / 2";
Walther@60523
   949
if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
neuper@42423
   950
then () else error "error patt example3 changed";
neuper@42423
   951
walther@59909
   952
"--------- build fun check_for' ?bdv -------------------------";
walther@59909
   953
"--------- build fun check_for' ?bdv -------------------------";
walther@59909
   954
"--------- build fun check_for' ?bdv -------------------------";
Walther@60500
   955
val ctxt = Proof_Context.init_global @{theory}
Walther@60565
   956
val subst = [(TermC.parse_test @{context} "bdv", TermC.parse_test @{context} "x")]: subst;
Walther@60565
   957
val t = TermC.parse_test @{context} "d_d x (x \<up> 2 + sin (x \<up> 4))";
Walther@60500
   958
val SOME (t, _) = rewrite_set_inst_ ctxt false subst norm_diff t;
walther@60242
   959
if UnparseC.term t = "2 * x + cos (x \<up> 4) * 4 * x \<up> 3" then ()
walther@59909
   960
else error "build fun check_for' ?bdv changed 1"; 
neuper@42423
   961
neuper@42426
   962
val rls = norm_diff
walther@60230
   963
val pat = TermC.parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)"; 
Walther@60565
   964
val (res, inf) = (TermC.parse_test @{context} "2 * x + d_d x (sin (x \<up> 4))", TermC.parse_test @{context} "2 * x + cos (4 * x \<up> 3)");
neuper@42426
   965
walther@60230
   966
val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern TermC.matches in res*)
Walther@60509
   967
  rew_sub ctxt 1 subst Rewrite_Ord.function_empty Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
walther@60242
   968
if UnparseC.term res' = "2 * x + cos (d_d x (x \<up> 4))" andalso rewritten then ()
walther@59909
   969
else error "build fun check_for' ?bdv changed 2";
neuper@42426
   970
Walther@60500
   971
val norm_res = case rewrite_set_inst_ ctxt false subst rls  res' of
neuper@42426
   972
  NONE => res'
neuper@42426
   973
| SOME (norm_res, _) => norm_res;
walther@60242
   974
if UnparseC.term norm_res = "2 * x + cos (4 * x \<up> 3)" then ()
walther@59909
   975
else error "build fun check_for' ?bdv changed 3";
neuper@42426
   976
Walther@60500
   977
val norm_inf = case rewrite_set_inst_ ctxt false subst rls inf of
neuper@42426
   978
  NONE => inf
neuper@42426
   979
| SOME (norm_inf, _) => norm_inf;
walther@60242
   980
if UnparseC.term norm_inf = "2 * x + cos (4 * x \<up> 3)" then ()
walther@59909
   981
else error "build fun check_for' ?bdv changed 4";
neuper@42426
   982
neuper@42426
   983
res' = inf;
neuper@42426
   984
if norm_res = norm_inf then ()
walther@59909
   985
else error "build fun check_for' ?bdv changed 5";
neuper@42426
   986
Walther@60523
   987
if Error_Pattern.check_for' ctxt (res, inf) (subst: subst) ("errpatID": Error_Pattern.id, pat) rls = SOME "errpatID"
neuper@42426
   988
then () else error "error patt example1 changed";
neuper@42426
   989
walther@59909
   990
"--------- build fun check_for ------------------------";
walther@59909
   991
"--------- build fun check_for ------------------------";
walther@59909
   992
"--------- build fun check_for ------------------------";
neuper@42428
   993
val (res, inf) =
Walther@60565
   994
  (TermC.parse_test @{context} "d_d x (x \<up> 2) + d_d x (sin (x \<up>  4))",
Walther@60565
   995
   TermC.parse_test @{context} "d_d x (x \<up> 2) + cos (4 * x \<up> 3)");
Walther@60559
   996
val {errpats, nrls = rls, scr = Prog prog, ...} = MethodC.from_store ctxt ["diff", "differentiate_on_R"]
neuper@42426
   997
Walther@60565
   998
val env = [(TermC.parse_test @{context} "v_v", TermC.parse_test @{context} "x")];
neuper@42428
   999
val errpats =
walther@59971
  1000
  [Error_Pattern.empty, (*generalised for testing*)
neuper@42428
  1001
   ("chain-rule-diff-both",
walther@60230
  1002
     [TermC.parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
walther@60230
  1003
      TermC.parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
walther@60242
  1004
      TermC.parse_patt @{theory} "d_d ?bdv (?u \<up> ?n) = ?n * ?u \<up> (?n - 1)",
walther@60230
  1005
      TermC.parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
walther@60230
  1006
      TermC.parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
neuper@42428
  1007
     [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain}, 
walther@59921
  1008
      @{thm diff_ln_chain}, @{thm  diff_exp_chain}])];
Walther@60523
  1009
case Error_Pattern.check_for ctxt (res, inf) (prog, env) (errpats, rls) of SOME _ => () 
walther@59844
  1010
| NONE => error "Error_Pattern.check_for broken";
wneuper@59252
  1011
DEconstrCalcTree 1;
neuper@42428
  1012
walther@59909
  1013
"--------- embed fun check_for ------------------------";
walther@59909
  1014
"--------- embed fun check_for ------------------------";
walther@59909
  1015
"--------- embed fun check_for ------------------------";
Walther@60549
  1016
States.reset ();     
Walther@60571
  1017
CalcTree @{context}
walther@60242
  1018
[(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"], 
walther@59997
  1019
  ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
neuper@42428
  1020
Iterator 1;
neuper@42428
  1021
moveActiveRoot 1;
wneuper@59248
  1022
autoCalculate 1 CompleteCalcHead;
walther@59747
  1023
autoCalculate 1 (Steps 1);
walther@60242
  1024
autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))*)
walther@60242
  1025
(*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
  1026
walther@60242
  1027
"~~~~~ fun appendFormula , args:"; val (cI, (ifo:TermC.as_string)) = (1, "d_d x (x \<up> 2) + cos (4 * x \<up> 3)");
walther@59868
  1028
"~~~~~ fun appendFormula' , args:"; val (cI, (ifo: TermC.as_string)) = (cI, ifo);
Walther@60549
  1029
    val cs = States.get_calc cI
Walther@60549
  1030
    val pos = States.get_pos cI 1;
walther@59844
  1031
(*+*)if pos = ([1], Res) then () else error "inform with (positive) Error_Pattern.check_for broken 1";
walther@59798
  1032
    val ("ok", cs' as (_, _, ptp)) = (*case*) Step.do_next pos cs (*of*);
walther@59798
  1033
      (*case*) Step_Solve.by_term ptp (encode ifo) (*of*); (*ERROR WAS: "no derivation found"*)
walther@59981
  1034
"~~~~~ fun Step_Solve.by_term , args:"; val (((*next_*)cs as (_, _, (pt, pos as (p, _))): Calc.state_post), istr)
wneuper@59562
  1035
  = (cs', (encode ifo));
wneuper@59562
  1036
    val ctxt = get_ctxt pt pos (*see TODO.thy*)
Walther@60424
  1037
    val SOME f_in = (*case*) TermC.parseNEW ctxt istr (*of*);
wneuper@59562
  1038
        val pos_pred = lev_back' pos
wneuper@59562
  1039
    	  val f_pred = Ctree.get_curr_formula (pt, pos_pred);
wneuper@59562
  1040
        (*if*) f_pred = f_in; (*else*)
walther@59982
  1041
          val NONE = (*case*) CAS_Cmd.input f_in (*of*);
walther@59795
  1042
       (*old* )val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
Walther@60559
  1043
       (*old*)val {scr = prog, ...} = MethodC.from_store ctxt metID
walther@59807
  1044
       (*old*)val istate = get_istate_LI pt pos
walther@59795
  1045
       (*old*)val ctxt = get_ctxt pt pos
walther@59795
  1046
       ( *old*)
walther@59795
  1047
       val LI.Not_Derivable =
walther@59795
  1048
             (*case*) LI.locate_input_term (pt, pos) f_in (*of*);
wneuper@59562
  1049
            		  val pp = Ctree.par_pblobj pt p
Walther@60559
  1050
            		  val (errpats, nrls, prog) = case MethodC.from_store ctxt (Ctree.get_obj Ctree.g_metID pt pp) of
wneuper@59562
  1051
              		    {errpats, nrls, scr = Rule.Prog prog, ...} => (errpats, nrls, prog)
Walther@60559
  1052
              		  | _ => error "inform: uncovered case of MethodC.from_store ctxt"
wneuper@59562
  1053
;
walther@60278
  1054
(*+*)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
  1055
(*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 3";
neuper@42428
  1056
walther@59807
  1057
            		  val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
wneuper@59562
  1058
;
walther@60242
  1059
(*+*)if UnparseC.term f_pred = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" andalso
walther@60242
  1060
(*+*)   UnparseC.term f_in = "d_d x (x \<up> 2) + cos (4 * x \<up> 3)"
walther@59844
  1061
(*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 2";
neuper@42428
  1062
Walther@60523
  1063
             val SOME "chain-rule-diff-both" = (*case*) Error_Pattern.check_for ctxt (f_pred, f_in) (prog, env) (errpats, nrls) (*of*);
neuper@42428
  1064
neuper@42428
  1065
"--- final check:";
walther@59798
  1066
(*+*)val (_, _, ptp') = cs';
walther@59798
  1067
case Step_Solve.by_term ptp' (encode ifo) of
neuper@42428
  1068
  ("error pattern #chain-rule-diff-both#", calcstate') => ()
walther@59844
  1069
| _ => error "inform with (positive) Error_Pattern.check_for broken"
neuper@42428
  1070
neuper@48895
  1071
walther@59909
  1072
"--------- embed fun find_fill_patterns ---------------------------";
walther@59909
  1073
"--------- embed fun find_fill_patterns ---------------------------";
walther@59909
  1074
"--------- embed fun find_fill_patterns ---------------------------";
Walther@60549
  1075
States.reset ();
Walther@60571
  1076
CalcTree @{context}
walther@60242
  1077
[(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"], 
walther@59997
  1078
  ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
neuper@42430
  1079
Iterator 1;
neuper@42430
  1080
moveActiveRoot 1;
wneuper@59248
  1081
autoCalculate 1 CompleteCalcHead;
walther@59747
  1082
autoCalculate 1 (Steps 1);
walther@60242
  1083
autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))*)
walther@60242
  1084
appendFormula 1 "d_d x (x \<up> 2) + cos (4 * x \<up> 3)" (*|> Future.join*);
neuper@42430
  1085
  (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
neuper@42432
  1086
  (*or
neuper@42432
  1087
    <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
neuper@42430
  1088
neuper@42433
  1089
"~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
Walther@60549
  1090
  val ((pt, _), _) = States.get_calc cI
Walther@60549
  1091
				val pos = States.get_pos cI 1;
walther@59909
  1092
"~~~~~ fun find_fill_patterns , args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
walther@59685
  1093
    val f_curr = Ctree.get_curr_formula (pt, pos);
walther@59685
  1094
    val pp = Ctree.par_pblobj pt p
Walther@60559
  1095
    val (errpats, prog) = case MethodC.from_store ctxt (Ctree.get_obj Ctree.g_metID pt pp) of
walther@59685
  1096
      {errpats, scr = Rule.Prog prog, ...} => (errpats, prog)
Walther@60559
  1097
    | _ => error "find_fill_patterns: uncovered case of MethodC.from_store ctxt"
walther@59807
  1098
    val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
walther@59911
  1099
    val subst = Subst.for_bdv prog env
neuper@42430
  1100
    val errpatthms = errpats
walther@59921
  1101
      |> filter ((curry op = errpatID) o (#1: Error_Pattern.T -> Error_Pattern.id))
walther@59921
  1102
      |> map (#3: Error_Pattern.T -> thm list)
neuper@42430
  1103
      |> flat;
neuper@42430
  1104
Walther@60524
  1105
case map (Error_Pattern.fill_from_store ctxt subst f_curr errpatID) errpatthms |> flat of
walther@59868
  1106
  ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if UnparseC.term tm = 
walther@60242
  1107
    "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
  1108
    then () else error "find_fill_patterns changed 1a"
walther@59909
  1109
| _ => error "find_fill_patterns changed 1b"
neuper@42430
  1110
Walther@60563
  1111
"~~~~~ fun fill_from_store, args:"; val (ctxt, subst, form, errpatID, thm) =
Walther@60563
  1112
  (ctxt, subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
neuper@42430
  1113
        val thmDeriv = Thm.get_name_hint thm
walther@59921
  1114
        val (part, thyID) = Thy_Read.thy_containing_thm thmDeriv
walther@59876
  1115
        val theID = [part, thyID, "Theorems", ThmC.cut_id thmDeriv]
Walther@60563
  1116
        val Thy_Write.Hthm {fillpats, ...} = Thy_Read.from_store ctxt theID
Walther@60524
  1117
        val some = map (Error_Pattern.fill_form ctxt subst (thm, form) errpatID) fillpats;
neuper@42430
  1118
neuper@42430
  1119
case some |> filter is_some |> map the of
walther@59868
  1120
  ("fill-d_d-arg", tm, thm, subsopt) :: _ => if UnparseC.term tm = 
walther@60242
  1121
    "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
  1122
    then () else error "find_fill_patterns changed 2a"
walther@59909
  1123
| _ => error "find_fill_patterns changed 2b"
neuper@42430
  1124
walther@59909
  1125
"~~~~~ fun fill_form, args:";
neuper@42433
  1126
  val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
neuper@42433
  1127
  (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
neuper@42433
  1128
val (form', _, _, rewritten) =
Walther@60509
  1129
      rew_sub ctxt 1 subst Rewrite_Ord.function_empty Rule_Set.empty false [] (HOLogic.Trueprop $ pat) form;
neuper@42432
  1130
walther@60242
  1131
if UnparseC.term form' = "d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x ?_dummy_1" then ()
walther@59909
  1132
else error "find_fill_patterns changed 3";
neuper@42432
  1133
neuper@42433
  1134
"~~~~~ to findFillpatterns return val:"; val (fillpats) =
Walther@60524
  1135
  (map (Error_Pattern.fill_from_store ctxt (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
neuper@42432
  1136
neuper@42450
  1137
"vvv--- dropped this code WN120730";
neuper@42433
  1138
val msg = "fill patterns " ^
walther@59868
  1139
  ((map ((apsnd UnparseC.term) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
neuper@42450
  1140
msg =
walther@60242
  1141
  "fill patterns #fill-d_d-arg#d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" ^
walther@60242
  1142
    " =\nd_d x (x \<up> 2) + cos (x \<up> 4) * d_d x ?_dummy_1" ^
walther@60242
  1143
  "#fill-both-args#d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" ^
walther@60242
  1144
    " =\nd_d x (x \<up> 2) + cos ?_dummy_2 * d_d x ?_dummy_3" ^
walther@60242
  1145
  "#fill-d_d#d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" ^
walther@60242
  1146
    " =\nd_d x (x \<up> 2) + cos (x \<up> 4) * ?_dummy_1 x (x \<up> 4)" ^
walther@60242
  1147
  "#fill-inner-deriv#d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" ^
walther@60242
  1148
    " =\nd_d x (x \<up> 2) + cos (x \<up> 4) * ?_dummy_1" ^
walther@60242
  1149
  "#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
  1150
" \<up> --- dropped this code WN120730";
neuper@42450
  1151
neuper@42450
  1152
if (map #1 fillpats) =
neuper@42450
  1153
  ["fill-d_d-arg", "fill-both-args", "fill-d_d", "fill-inner-deriv", "fill-all"]
walther@59909
  1154
then () else error "find_fill_patterns changed 4b";
wneuper@59252
  1155
DEconstrCalcTree 1;
neuper@42450
  1156
neuper@42437
  1157
"--------- build fun is_exactly_equal, inputFillFormula ----------";
neuper@42437
  1158
"--------- build fun is_exactly_equal, inputFillFormula ----------";
neuper@42437
  1159
"--------- build fun is_exactly_equal, inputFillFormula ----------";
Walther@60549
  1160
States.reset ();
Walther@60571
  1161
CalcTree @{context}
walther@60242
  1162
[(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"], 
walther@59997
  1163
  ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
neuper@42437
  1164
Iterator 1;
neuper@42437
  1165
moveActiveRoot 1;
wneuper@59248
  1166
autoCalculate 1 CompleteCalcHead;
walther@59747
  1167
autoCalculate 1 (Steps 1);
walther@60242
  1168
autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))*)
walther@60242
  1169
appendFormula 1 "d_d x (x \<up> 2) + cos (4 * x \<up> 3)" (*|> Future.join*); (*<<<<<<<=========================*)
neuper@42437
  1170
(* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
walther@60242
  1171
  would recognize "cos (4 * x \<up> (4 - 1)) + 2 * x" as well.
neuper@42437
  1172
  results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
neuper@42437
  1173
  instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
Walther@60549
  1174
  val ((pt,pos), _) = States.get_calc 1;
Walther@60549
  1175
  val p = States.get_pos 1 1;
walther@59983
  1176
  val (Form f, _, asms) = ME_Misc.pt_extract (pt, p);
neuper@42437
  1177
walther@60242
  1178
  if p = ([1], Res) andalso UnparseC.term f = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" then
wneuper@59497
  1179
    case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
wneuper@59253
  1180
      ("diff_sum", thm)) =>
walther@59868
  1181
      if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
walther@59909
  1182
      else error "embed fun fill_form changed 11"
walther@59909
  1183
    | _ => error "embed fun fill_form changed 12"
walther@59909
  1184
  else error "embed fun fill_form changed 13";
neuper@42437
  1185
neuper@42437
  1186
findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
walther@60242
  1187
(*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x \<up> 2) + d_d x (sin (x \<up>  4)) =
walther@60242
  1188
  d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
Walther@60549
  1189
  val ((pt,pos),_) = States.get_calc 1;
Walther@60549
  1190
  val p = States.get_pos 1 1;
neuper@42437
  1191
walther@59983
  1192
  val (Form f, _, asms) = ME_Misc.pt_extract (pt, p);
walther@60242
  1193
  if p = ([1], Res) andalso UnparseC.term f = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" then
wneuper@59497
  1194
    case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
wneuper@59253
  1195
      ("diff_sum", thm)) =>
walther@59868
  1196
      if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
walther@59909
  1197
      else error "embed fun fill_form changed 21"
walther@59909
  1198
    | _ => error "embed fun fill_form changed 22"
walther@59909
  1199
  else error "embed fun fill_form changed 23";
neuper@42437
  1200
neuper@42437
  1201
requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
neuper@42437
  1202
  (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
Walther@60549
  1203
  val ((pt,pos),_) = States.get_calc 1;
Walther@60549
  1204
  val p = States.get_pos 1 1;
walther@59983
  1205
  val (Form f, _, asms) = ME_Misc.pt_extract (pt, p);
wneuper@59253
  1206
  if p = ([1], Res) andalso existpt [2] pt
walther@60242
  1207
    andalso UnparseC.term f = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))"
wneuper@59497
  1208
  then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
wneuper@59253
  1209
      ("diff_sum", thm)) =>
walther@59868
  1210
      if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
walther@59909
  1211
      else error "embed fun fill_form changed 31"
walther@59909
  1212
    | _ => error "embed fun fill_form changed 32"
walther@59909
  1213
  else error "embed fun fill_form changed 33";
neuper@42437
  1214
neuper@42437
  1215
(* input a formula which exactly fills the gaps in a "fillformula"
neuper@42437
  1216
   presented to the learner immediately before by "requestFillformula (errpatID, fillpatID)":
neuper@42437
  1217
   errpatID: lhs of the respective thm = lhs of fillformula with fillpatID.
neuper@42437
  1218
   the respective thm is in the ctree ................
neuper@42437
  1219
*)
neuper@42437
  1220
"~~~~~ fun inputFillFormula, args:"; val (cI, ifo) =
walther@60242
  1221
  (1, "d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x (x \<up> 4)");
Walther@60549
  1222
    val ((pt, _), _) = States.get_calc cI
Walther@60549
  1223
    val pos = States.get_pos cI 1;
neuper@42437
  1224
neuper@42437
  1225
"~~~~~ fun is_exactly_equal, args:"; val ((pt, pos as (p, p_)), istr) = ((pt, pos), ifo);
walther@60360
  1226
  val SOME ifo = parseNEW (ThyC.get_theory "Isac_Knowledge" |> Proof_Context.init_global) istr
neuper@42437
  1227
  val p' = lev_on p;
neuper@42437
  1228
  val tac = get_obj g_tac pt p';
wneuper@59497
  1229
val Rewrite_Inst ([bbb as "(''bdv'', x)"], ("diff_sin_chain", ttt)) = tac;
walther@59868
  1230
if (UnparseC.term o Thm.prop_of) ttt = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
wneuper@59252
  1231
else error "inputFillFormula changed 10";
walther@59921
  1232
  val Applicable.Yes rew = Step.check tac (pt, pos);
neuper@42437
  1233
  val Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) = rew;
neuper@42437
  1234
neuper@42437
  1235
"~~~~~ to inputFillFormula return val:"; val ("ok", tac) = ("ok", tac);
walther@59804
  1236
  val ("ok", (_, c, ptp as (_,p'))) = Step.by_tactic tac (pt, pos);
Walther@60549
  1237
    States.upd_calc cI (ptp, []);
Walther@60549
  1238
    States.upd_ipos cI 1 p';
neuper@42437
  1239
    autocalculateOK2xml cI pos (if null c then p' else last_elem c) p';
neuper@42437
  1240
neuper@42437
  1241
"~~~~~ final check:";
Walther@60549
  1242
val ((pt, _),_) = States.get_calc 1;
Walther@60549
  1243
val p = States.get_pos 1 1;
walther@59983
  1244
val (Form f, _, asms) = ME_Misc.pt_extract (pt, p);
walther@60242
  1245
  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
  1246
  then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
wneuper@59253
  1247
      ("diff_sin_chain", thm)) =>
walther@59868
  1248
      if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
wneuper@59253
  1249
      else error "inputFillFormula changed 111"
wneuper@59253
  1250
    | _ => error "inputFillFormula changed 112"
wneuper@59253
  1251
  else error "inputFillFormula changed 113";
neuper@42437
  1252
wneuper@59262
  1253
"--------- fun appl_adds -----------------------------------------";
wneuper@59262
  1254
"--------- fun appl_adds -----------------------------------------";
wneuper@59262
  1255
"--------- fun appl_adds -----------------------------------------";
wneuper@59262
  1256
(* val (dI, oris, ppc, pbt, selct::ss) = 
wneuper@59262
  1257
       (dI, pors, probl, ppc, map itms2fstr probl);
wneuper@59262
  1258
   ...vvv
wneuper@59262
  1259
   *)
wneuper@59262
  1260
(* val (dI, oris, ppc, pbt, (selct::ss))=
Walther@60494
  1261
       (#1 (References.select_input ospec spec), oris, []:I_Model.T,
Walther@60494
  1262
	((#ppc o Problem.from_store) (#2 (References.select_input ospec spec))),(imodel2fstr imodel));
wneuper@59262
  1263
   val iii = appl_adds dI oris ppc pbt (selct::ss); 
walther@59942
  1264
   tracing(I_Model.to_string thy iii);
wneuper@59262
  1265
walther@59956
  1266
 val itm = add_single' dI oris ppc pbt selct;
walther@59988
  1267
 val ppc = I_Model.add itm ppc;
wneuper@59262
  1268
wneuper@59262
  1269
 val _::selct::ss = (selct::ss);
walther@59956
  1270
 val itm = add_single' dI oris ppc pbt selct;
walther@59988
  1271
 val ppc = I_Model.add itm ppc;
wneuper@59262
  1272
wneuper@59262
  1273
 val _::selct::ss = (selct::ss);
walther@59956
  1274
 val itm = add_single' dI oris ppc pbt selct;
walther@59988
  1275
 val ppc = I_Model.add itm ppc;
walther@59942
  1276
 tracing(I_Model.to_string thy ppc);
wneuper@59262
  1277
wneuper@59262
  1278
 val _::selct::ss = (selct::ss);
walther@59956
  1279
 val itm = add_single' dI oris ppc pbt selct;
walther@59988
  1280
 val ppc = I_Model.add itm ppc;
wneuper@59262
  1281
   *)
wneuper@59264
  1282
"--------- fun concat_deriv --------------------------------------";
wneuper@59264
  1283
"--------- fun concat_deriv --------------------------------------";
wneuper@59264
  1284
"--------- fun concat_deriv --------------------------------------";
wneuper@59264
  1285
(*
wneuper@59264
  1286
 val ({rew_ord, erls, rules,...}, fo, ifo) = 
Walther@60565
  1287
     (Rule_Set.rep Test_simplify, TermC.parse_test @{context} "x+1+ - 1*2=0", TermC.parse_test @{context} "-2*1+(x+1)=0");
walther@59906
  1288
 (tracing o Derive.trtas2str) fod';
wneuper@59264
  1289
> ["
walther@60324
  1290
(x + 1 + - 1 * 2 = 0, Thm ("radd_commute", "?m + ?n = ?n + ?m"), (- 1 * 2 + (x + 1) = 0, []))", "
walther@60324
  1291
(- 1 * 2 + (x + 1) = 0, Thm ("radd_commute", "?m + ?n = ?n + ?m"), (- 1 * 2 + (1 + x) = 0, []))", "
walther@60324
  1292
(- 1 * 2 + (1 + x) = 0, Thm ("radd_left_commute", "?x + (?y + ?z) = ?y + (?x + ?z)"), (1 + (- 1 * 2 + x) = 0, []))", "
walther@60324
  1293
(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
  1294
val it = () : unit
walther@59906
  1295
 (tracing o Derive.trtas2str) (map Derive.rev_deriv' rifod');
wneuper@59264
  1296
> ["
walther@59997
  1297
(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
  1298
(1 + (-2 * 1 + x) = 0, Thm ("sym_radd_left_commute", "?y + (?x + ?z) = ?x + (?y + ?z)"), (-2 * 1 + (1 + x) = 0, []))", "
walther@59997
  1299
(-2 * 1 + (1 + x) = 0, Thm ("sym_radd_commute", "?n + ?m = ?m + ?n"), (-2 * 1 + (x + 1) = 0, []))"]
wneuper@59264
  1300
val it = () : unit
wneuper@59264
  1301
*)
wneuper@59264
  1302
"--------- handle an input formula -------------------------------";
wneuper@59264
  1303
"--------- handle an input formula -------------------------------";
wneuper@59264
  1304
"--------- handle an input formula -------------------------------";
wneuper@59264
  1305
(*
wneuper@59264
  1306
Untersuchung zur Formeleingabe (appendFormula, replaceFormla) zu einer Anregung von Alan Krempler:
wneuper@59264
  1307
Welche RICHTIGEN Formeln koennen NICHT abgeleitet werden, 
wneuper@59264
  1308
wenn Abteilungen nur auf gleichem Level gesucht werden ?
wneuper@59264
  1309
WN.040216 
wneuper@59264
  1310
wneuper@59264
  1311
Beispiele zum Equationsolver von Richard Lang aus /src/sml/kbtest/rlang.sml
wneuper@59264
  1312
wneuper@59264
  1313
------------------------------------------------------------------------------
wneuper@59264
  1314
"Schalk I s.87 Bsp 52a ((5*x)/(x - 2) - x/(x+2)=4)";
wneuper@59264
  1315
------------------------------------------------------------------------------
wneuper@59264
  1316
1. "5 * x / (x - 2) - x / (x + 2) = 4"
wneuper@59264
  1317
...
walther@60242
  1318
4. "12 * x + 4 * x \<up> 2 = 4 * (-4 + x \<up> 2)",Subproblem["normalise", "poly"..
wneuper@59264
  1319
...
wneuper@59264
  1320
4.3. "16 + 12 * x = 0", Subproblem["degree_1", "polynomial", "univariate"..
wneuper@59264
  1321
...
wneuper@59264
  1322
4.3.3. "[x = -4 / 3]")), Check_elementwise "Assumptions"
wneuper@59264
  1323
...
wneuper@59264
  1324
"[x = -4 / 3]"
wneuper@59264
  1325
------------------------------------------------------------------------------
wneuper@59264
  1326
(1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
wneuper@59264
  1327
wneuper@59264
  1328
(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
  1329
------------------------------------------------------------------------------
wneuper@59264
  1330
wneuper@59264
  1331
wneuper@59264
  1332
------------------------------------------------------------------------------
walther@60242
  1333
"Schalk I s.87 Bsp 55b (x/(x \<up> 2 - 6*x+9) - 1/(x \<up> 2 - 3*x) =1/x)";
wneuper@59264
  1334
------------------------------------------------------------------------------
walther@60242
  1335
1. "x / (x \<up> 2 - 6 * x + 9) - 1 / (x \<up> 2 - 3 * x) = 1 / x"
wneuper@59264
  1336
...
walther@60324
  1337
4. "(3 + (- 1 * x + x \<up> 2)) * x = 1 * (9 * x + (x \<up> 3 + -6 * x \<up> 2))"
wneuper@59367
  1338
                         Subproblem["normalise", "polynomial", "univariate"..
wneuper@59264
  1339
...
walther@60242
  1340
4.4. "-6 * x + 5 * x \<up> 2 = 0", Subproblem["bdv_only", "degree_2", "poly"..
wneuper@59264
  1341
...
wneuper@59264
  1342
4.4.4. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
wneuper@59264
  1343
4.4.5. "[x = 0, x = 6 / 5]"
wneuper@59264
  1344
...
wneuper@59264
  1345
5. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
wneuper@59264
  1346
   "[x = 6 / 5]"
wneuper@59264
  1347
------------------------------------------------------------------------------
wneuper@59264
  1348
(1)..(4): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite schiebt [Ableitung waere in 4.4.x]
wneuper@59264
  1349
wneuper@59264
  1350
(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
  1351
------------------------------------------------------------------------------
wneuper@59264
  1352
wneuper@59264
  1353
wneuper@59264
  1354
------------------------------------------------------------------------------
wneuper@59264
  1355
"Schalk II s.56 Bsp 73b (sqrt(x+1)+sqrt(4*x+4)=sqrt(9*x+9))";
wneuper@59264
  1356
------------------------------------------------------------------------------
wneuper@59264
  1357
1. "sqrt (x + 1) + sqrt (4 * x + 4) = sqrt (9 * x + 9)"
wneuper@59264
  1358
...
wneuper@59264
  1359
6. "13 + 13 * x + -2 * sqrt ((4 + 4 * x) * (9 + 9 * x)) = 1 + x"
wneuper@59489
  1360
                             Subproblem["sq", "rootX", "univariate", "equation"]
wneuper@59264
  1361
...
walther@60242
  1362
6.6. "144 + 288 * x + 144 * x \<up> 2 = 144 + x \<up> 2 + 288 * x + 143 * x \<up> 2"
wneuper@59367
  1363
                Subproblem["normalise", "polynomial", "univariate", "equation"]
walther@60242
  1364
...6.6.3 "0 = 0"    Subproblem["degree_0", "polynomial", "univariate", "equation"]
wneuper@59264
  1365
...                                       Or_to_List
wneuper@59264
  1366
6.6.3.2 "UniversalList"
wneuper@59264
  1367
------------------------------------------------------------------------------
wneuper@59264
  1368
(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
  1369
wneuper@59264
  1370
(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
  1371
------------------------------------------------------------------------------
wneuper@59264
  1372
*)
wneuper@59264
  1373
(*sh. comments auf 498*)
wneuper@59264
  1374
"--------- fun dropwhile' ----------------------------------------";
wneuper@59264
  1375
"--------- fun dropwhile' ----------------------------------------";
wneuper@59264
  1376
"--------- fun dropwhile' ----------------------------------------";
wneuper@59264
  1377
(*
wneuper@59264
  1378
 fun equal a b = a=b;
wneuper@59264
  1379
 val foder = [0,1,2,3,4,5]; val ifoder = [11,12,3,4,5];
wneuper@59264
  1380
 val r_foder = rev foder;  val r_ifoder = rev ifoder;
wneuper@59264
  1381
 dropwhile' equal r_foder r_ifoder;
wneuper@59264
  1382
> vval it = ([0, 1, 2, 3], [3, 12, 11]) : int list * int list
wneuper@59264
  1383
wneuper@59264
  1384
 val foder = [3,4,5]; val ifoder = [11,12,3,4,5];
wneuper@59264
  1385
 val r_foder = rev foder;  val r_ifoder = rev ifoder;
wneuper@59264
  1386
 dropwhile' equal r_foder r_ifoder;
wneuper@59264
  1387
> val it = ([3], [3, 12, 11]) : int list * int list
wneuper@59264
  1388
wneuper@59264
  1389
 val foder = [5]; val ifoder = [11,12,3,4,5];
wneuper@59264
  1390
 val r_foder = rev foder;  val r_ifoder = rev ifoder;
wneuper@59264
  1391
 dropwhile' equal r_foder r_ifoder;
wneuper@59264
  1392
> val it = ([5], [5, 4, 3, 12, 11]) : int list * int list
wneuper@59264
  1393
wneuper@59264
  1394
 val foder = [10,11,12,13,14,15]; val ifoder = [11,12,3,4,5];
wneuper@59264
  1395
 val r_foder = rev foder;  val r_ifoder = rev ifoder;
wneuper@59264
  1396
 dropwhile' equal r_foder r_ifoder;
wneuper@59264
  1397
> *** dropwhile': did not start with equal elements*)