test/Tools/isac/Knowledge/integrate.sml
author Walther Neuper <neuper@ist.tugraz.at>
Thu, 23 Sep 2010 12:56:51 +0200
branchisac-update-Isa09-2
changeset 38013 e4f42a63d665
parent 38010 a37a3ab989f4
child 38014 3e11e3c2dc42
permissions -rw-r--r--
interrupted update test/../Knowledge/integrate.sml, repaired term2str

term2str by help from Florian and Jasmin; took the former.
Found at that point in integrate.sml,
that all "op +" etc need to be updated.
neuper@37906
     1
(* tests on integration over the reals
neuper@37906
     2
   author: Walther Neuper
neuper@37906
     3
   050814, 08:51
neuper@37906
     4
   (c) due to copyright terms
neuper@37906
     5
neuper@37906
     6
use"../smltest/IsacKnowledge/integrate.sml";
neuper@37906
     7
use"integrate.sml";
neuper@37906
     8
*)
neuper@38010
     9
val thy = theory "Integrate";
neuper@37906
    10
neuper@38013
    11
"--------------------------------------------------------";
neuper@38013
    12
"table of contents --------------------------------------";
neuper@38013
    13
"--------------------------------------------------------";
neuper@38013
    14
"----------- parsing ------------------------------------";
neuper@38013
    15
"----------- integrate by rewriting ---------------------";
neuper@38013
    16
"----------- test add_new_c, is_f_x ---------------------";
neuper@38013
    17
"----------- simplify by ruleset reducing make_ratpoly_in";
neuper@38013
    18
"----------- simplify by extending make_polynomial_in ---";
neuper@38013
    19
"----------- integrate by ruleset -----------------------";
neuper@38013
    20
"----------- rewrite 3rd integration in 7.27 ------------";
neuper@38013
    21
"----------- check probem type --------------------------";
neuper@38013
    22
"----------- check Scripts ------------------------------";
neuper@38013
    23
"----------- me method [diff,integration] ---------------";
neuper@38013
    24
"----------- me method [diff,integration,named] ---------";
neuper@38013
    25
"----------- me met [diff,integration,named] Biegelinie.Q";
neuper@38013
    26
"----------- interSteps [diff,integration] --------------";
neuper@38013
    27
"----------- method analog to rls 'integration' ---------";
neuper@38013
    28
"----------- Ambiguous input: Integral ?u + ?v D ?bdv = .";
neuper@38013
    29
"----------- CAS input ----------------------------------";
neuper@38013
    30
"--------------------------------------------------------";
neuper@38013
    31
"--------------------------------------------------------";
neuper@38013
    32
"--------------------------------------------------------";
neuper@37906
    33
neuper@37906
    34
neuper@37906
    35
neuper@38013
    36
"----------- parsing ------------------------------------";
neuper@38013
    37
"----------- parsing ------------------------------------";
neuper@38013
    38
"----------- parsing ------------------------------------";
neuper@38013
    39
fun str2term str = (term_of o the o (parse thy)) str;
neuper@37934
    40
fun term2s t = Syntax.string_of_term (thy2ctxt' "Integrate") t;
neuper@37906
    41
    
neuper@37924
    42
val t = str2term "Integral x D x";
neuper@37924
    43
val t = str2term "Integral x^^^2 D x";
neuper@37906
    44
atomty t;
neuper@37906
    45
neuper@37924
    46
val t = str2term "ff x is_f_x";
neuper@37906
    47
case t of Const ("Integrate.is'_f'_x", _) $ _ => ()
neuper@37906
    48
	| _ => raise error "integrate.sml: parsing: ff x is_f_x";
neuper@37906
    49
neuper@37906
    50
neuper@38013
    51
"----------- integrate by rewriting ---------------------";
neuper@38013
    52
"----------- integrate by rewriting ---------------------";
neuper@38013
    53
"----------- integrate by rewriting ---------------------";
neuper@37906
    54
val conditions_in_integration_rules =
neuper@37906
    55
Rls {id="conditions_in_integration_rules", 
neuper@37906
    56
     preconds = [], 
neuper@37906
    57
     rew_ord = ("termlessI",termlessI), 
neuper@37906
    58
     erls = Erls, 
neuper@37906
    59
     srls = Erls, calc = [],
neuper@37906
    60
     rules = [(*for rewriting conditions in Thm's*)
neuper@37906
    61
	      Calc ("Atools.occurs'_in", 
neuper@37906
    62
		    eval_occurs_in "#occurs_in_"),
neuper@37970
    63
	      Thm ("not_true",num_str @{thm not_true}),
neuper@37970
    64
	      Thm ("not_false",num_str @{thm not_false})
neuper@37906
    65
	      ],
neuper@37906
    66
     scr = EmptyScr};
neuper@37924
    67
val subs = [(str2term "bdv", str2term "x")];
neuper@37906
    68
fun rewrit thm str = 
neuper@38013
    69
    fst (the (rewrite_inst_ thy tless_true 
neuper@37906
    70
			   conditions_in_integration_rules 
neuper@37906
    71
			   true subs thm str));
neuper@38013
    72
val str = rewrit @{thm "integral_const"} (str2term "Integral 1 D x");
neuper@38013
    73
term2s str;
neuper@38013
    74
val str = rewrit @{thm "integral_const"} (str2term  "Integral M'/EJ D x");
neuper@38013
    75
term2s str;
neuper@38013
    76
val str = (rewrit @{thm "integral_const"} (str2term "Integral x D x")) 
neuper@37924
    77
    handle OPTION => str2term "no_rewrite";
neuper@37906
    78
neuper@38013
    79
val str = rewrit @{thm "integral_var"} (str2term "Integral x D x");
neuper@38013
    80
term2s str;
neuper@38013
    81
val str = (rewrit @{thm "integral_var"} (str2term "Integral a D x"))
neuper@37924
    82
    handle OPTION => str2term "no_rewrite";
neuper@37906
    83
neuper@38013
    84
val str = rewrit @{thm "integral_add"} (str2term "Integral x + 1 D x");
neuper@38013
    85
term2s str;
neuper@37906
    86
neuper@38013
    87
val str = rewrit @{thm "integral_mult"} (str2term "Integral M'/EJ * x^^^3 D x");
neuper@38013
    88
term2s str;
neuper@38013
    89
val str = (rewrit @{thm "integral_mult"} (str2term "Integral x * x D x"))
neuper@37924
    90
    handle OPTION => str2term "no_rewrite";
neuper@37906
    91
neuper@38013
    92
val str = rewrit @{thm "integral_pow"} (str2term "Integral x^^^3 D x");
neuper@38013
    93
term2s str;
neuper@37906
    94
neuper@37906
    95
neuper@38013
    96
"----------- test add_new_c, is_f_x ---------------------";
neuper@38013
    97
"----------- test add_new_c, is_f_x ---------------------";
neuper@38013
    98
"----------- test add_new_c, is_f_x ---------------------";
neuper@37906
    99
val term = str2term "x^^^2*c + c_2";
neuper@37906
   100
val cc = new_c term;
neuper@37906
   101
if term2str cc = "c_3" then () else raise error "integrate.sml: new_c ???";
neuper@37906
   102
neuper@37926
   103
val SOME (id,t') = eval_add_new_c "" "Integrate.add'_new'_c" term thy;
neuper@38013
   104
"####1###################################################";
neuper@38013
   105
term2str t' = "x ^^^ 2 * c + c_2 = op + (x ^^^ 2 * c + c_2) c_3" --REDO "op +";
neuper@38013
   106
"####2###################################################";
neuper@38013
   107
neuper@37906
   108
if term2str t' = "x ^^^ 2 * c + c_2 = x ^^^ 2 * c + c_2 + c_3" then ()
neuper@37906
   109
else raise error "intergrate.sml: diff. eval_add_new_c";
neuper@37906
   110
neuper@38013
   111
"####3###################################################";
neuper@38013
   112
neuper@37906
   113
val cc = ("Integrate.add'_new'_c", eval_add_new_c "add_new_c_");
neuper@37926
   114
val SOME (thmstr, thm) = get_calculation1_ thy cc term;
neuper@37906
   115
neuper@37926
   116
val SOME (t',_) = rewrite_set_ thy true add_new_c term;
neuper@37906
   117
if term2str t' = "x ^^^ 2 * c + c_2 + c_3" then ()
neuper@37906
   118
else raise error "intergrate.sml: diff. rewrite_set add_new_c 1";
neuper@37906
   119
neuper@37906
   120
val term = str2term "ff x = x^^^2*c + c_2";
neuper@37926
   121
val SOME (t',_) = rewrite_set_ thy true add_new_c term;
neuper@37906
   122
if term2str t' = "ff x = x ^^^ 2 * c + c_2 + c_3" then ()
neuper@37906
   123
else raise error "intergrate.sml: diff. rewrite_set add_new_c 2";
neuper@37906
   124
neuper@37906
   125
neuper@37906
   126
(*WN080222 replace call_new_c with add_new_c----------------------
neuper@37924
   127
val term = str2term "new_c (c * x^^^2 + c_2)";
neuper@37926
   128
val SOME (_,t') = eval_new_c 0 0 term 0;
neuper@37906
   129
if term2s t' = "new_c c * x ^^^ 2 + c_2 = c_3" then ()
neuper@37906
   130
else raise error "integrate.sml: eval_new_c ???";
neuper@37906
   131
neuper@37924
   132
val t = str2term "matches (?u + new_c ?v) (x ^^^ 2 / 2)";
neuper@37926
   133
val SOME (_,t') = eval_matches "" "Tools.matches" t thy; term2s t';
neuper@37906
   134
if term2s t' = "matches (?u + new_c ?v) (x ^^^ 2 / 2) = False" then ()
neuper@37906
   135
else raise error "integrate.sml: matches new_c = False";
neuper@37906
   136
neuper@37924
   137
val t = str2term "matches (?u + new_c ?v) (x ^^^ 2 / 2 + new_c x ^^^ 2 / 2)";
neuper@37926
   138
val SOME (_,t') = eval_matches "" "Tools.matches" t thy; term2s t';
neuper@37906
   139
if term2s t'="matches (?u + new_c ?v) (x ^^^ 2 / 2 + new_c x ^^^ 2 / 2) = True"
neuper@37906
   140
then () else raise error "integrate.sml: matches new_c = True";
neuper@37906
   141
neuper@37924
   142
val t = str2term "ff x is_f_x";
neuper@37926
   143
val SOME (_,t') = eval_is_f_x "" "" t thy; term2s t';
neuper@37906
   144
if term2s t' = "(ff x is_f_x) = True" then ()
neuper@37906
   145
else raise error "integrate.sml: eval_is_f_x --> true";
neuper@37906
   146
neuper@37924
   147
val t = str2term "q_0/2 * L * x is_f_x";
neuper@37926
   148
val SOME (_,t') = eval_is_f_x "" "" t thy; term2s t';
neuper@37906
   149
if term2s t' = "(q_0 / 2 * L * x is_f_x) = False" then ()
neuper@37906
   150
else raise error "integrate.sml: eval_is_f_x --> false";
neuper@37906
   151
neuper@37906
   152
val conditions_in_integration =
neuper@37906
   153
Rls {id="conditions_in_integration", 
neuper@37970
   154
     preconds = [], 
neuper@37970
   155
     rew_ord = ("termlessI",termlessI), 
neuper@37970
   156
     erls = Erls, 
neuper@37970
   157
     srls = Erls, calc = [],
neuper@37970
   158
     rules = [Calc ("Tools.matches",eval_matches ""),
neuper@37970
   159
      	Calc ("Integrate.is'_f'_x", 
neuper@37970
   160
      	      eval_is_f_x "is_f_x_"),
neuper@37970
   161
      	Thm ("not_true",num_str @{thm not_true}),
neuper@37970
   162
      	Thm ("not_false",num_str @{thm not_false})
neuper@37970
   163
      	],
neuper@37970
   164
     scr = EmptyScr};
neuper@37906
   165
fun rewrit thm t = 
neuper@38013
   166
    fst (the (rewrite_inst_ thy tless_true 
neuper@37906
   167
			    conditions_in_integration true subs thm t));
neuper@37924
   168
val t = rewrit call_for_new_c (str2term "x ^^^ 2 / 2"); term2s t;
neuper@37906
   169
val t = (rewrit call_for_new_c t)
neuper@37924
   170
    handle OPTION =>  str2term "no_rewrite";
neuper@37906
   171
neuper@37906
   172
val t = rewrit call_for_new_c 
neuper@37924
   173
	       (str2term "ff x = q_0/2 *L*x"); term2s t;
neuper@37906
   174
val t = (rewrit call_for_new_c 
neuper@37924
   175
	       (str2term "ff x = q_0 / 2 * L * x + new_c q_0 / 2 * L * x"))
neuper@37924
   176
    handle OPTION => (*NOT:  + new_c ..=..!!*)str2term "no_rewrite";
neuper@37906
   177
--------------------------------------------------------------------*)
neuper@37906
   178
neuper@37906
   179
neuper@38013
   180
"----------- simplify by ruleset reducing make_ratpoly_in";
neuper@38013
   181
"----------- simplify by ruleset reducing make_ratpoly_in";
neuper@38013
   182
"----------- simplify by ruleset reducing make_ratpoly_in";
neuper@37906
   183
val thy = Isac.thy;
neuper@37906
   184
val subs = [(str2term"bdv",str2term"x")];
neuper@37906
   185
val t = str2term "1/EI * (L * q_0 * x / 2 + -1 * q_0 * x^^^2 / 2)";
neuper@37906
   186
neuper@37906
   187
"----- stepwise from the rulesets in simplify_Integral and below-----";
neuper@37906
   188
(*###*)val rls = norm_Rational_noadd_fractions;
neuper@37906
   189
case rewrite_set_inst_ thy true subs rls t of
neuper@37926
   190
    SOME _ => raise error "integrate.sml simplify by ruleset norm_Rational_.#2"
neuper@37926
   191
  | NONE => ();
neuper@37906
   192
(* WN051028 Rational.ML 'rat_mult_div_pow' with erls = e_rls
neuper@37906
   193
applies 'rat_mult_poly_r'="?c is_polyexp ==> ?a / ?b * ?c = ?a * ?c / ?b"
neuper@37906
   194
to "(L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) / EI"
neuper@37906
   195
and keeps "..." is_polyexp" as an assumption.
neuper@37906
   196
AFTER CORRECTION in Integrate.ML as above*)
neuper@37906
   197
neuper@37906
   198
(*###*)val rls = order_add_mult_in;
neuper@37926
   199
val SOME (t,[]) = rewrite_set_ thy true rls t;
neuper@37906
   200
if term2str t = "1 / EI * (L * (q_0 * x) / 2 + -1 * (q_0 * x ^^^ 2) / 2)"then()
neuper@37906
   201
else raise error "integrate.sml simplify by ruleset order_add_mult_in #2";
neuper@37906
   202
neuper@37906
   203
(*###*)val rls = discard_parentheses;
neuper@37926
   204
val SOME (t,[]) = rewrite_set_ thy true rls t;
neuper@37906
   205
if term2str t = "1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)" then ()
neuper@37906
   206
else raise error "integrate.sml simplify by ruleset discard_parenth.. #3";
neuper@37906
   207
neuper@37970
   208
val rls = 
neuper@37970
   209
    (append_rls "separate_bdv"
neuper@37970
   210
 	       collect_bdv
neuper@37970
   211
 	       [Thm ("separate_bdv", num_str @{thm separate_bdv}),
neuper@37970
   212
 		(*"?a * ?bdv / ?b = ?a / ?b * ?bdv"*)
neuper@37970
   213
 		Thm ("separate_bdv_n", num_str @{thm separate_bdv_n}),
neuper@37970
   214
 		Thm ("separate_1_bdv", num_str @{thm separate_1_bdv}),
neuper@37970
   215
 		(*"?bdv / ?b = (1 / ?b) * ?bdv"*)
neuper@37970
   216
 		Thm ("separate_1_bdv_n", num_str @{thm separate_1_bdv_n})
neuper@37970
   217
               ]);
neuper@37926
   218
val SOME (t,[]) = rewrite_set_inst_ thy true subs rls t;
neuper@37906
   219
if term2str t = "1 / EI * (L * q_0 / 2 * x + -1 * q_0 / 2 * x ^^^ 2)" then ()
neuper@37906
   220
else raise error "integrate.sml simplify by ruleset separate_bdv.. #4";
neuper@37906
   221
neuper@37906
   222
neuper@37906
   223
val t = str2term "1/EI * (L * q_0 * x / 2 + -1 * q_0 * x^^^2 / 2)";
neuper@37906
   224
val rls = simplify_Integral;
neuper@37926
   225
val SOME (t,[]) = rewrite_set_inst_ thy true subs rls t;
neuper@37906
   226
if term2str t = "1 / EI * (L * q_0 / 2 * x + -1 * q_0 / 2 * x ^^^ 2)" then ()
neuper@37906
   227
else raise error "integrate.sml, simplify_Integral #99";
neuper@37906
   228
neuper@37906
   229
"........... 2nd integral ........................................";
neuper@37906
   230
"........... 2nd integral ........................................";
neuper@37906
   231
"........... 2nd integral ........................................";
neuper@37906
   232
val t = str2term 
neuper@37906
   233
	    "Integral 1 / EI * (L * q_0 / 2 * (x ^^^ 2 / 2) + \
neuper@37906
   234
	    \-1 * q_0 / 2 * (x ^^^ 3 / 3)) D x";
neuper@37906
   235
val rls = simplify_Integral;
neuper@37926
   236
val SOME (t,[]) = rewrite_set_inst_ thy true subs rls t;
neuper@37906
   237
if term2str t = 
neuper@37906
   238
   "Integral 1 / EI * (L * q_0 / 4 * x ^^^ 2 + -1 * q_0 / 6 * x ^^^ 3) D x"
neuper@37906
   239
then () else raise error "integrate.sml, simplify_Integral #198";
neuper@37906
   240
neuper@37906
   241
val rls = integration_rules;
neuper@37926
   242
val SOME (t,[]) = rewrite_set_ thy true rls t;
neuper@37906
   243
if term2str t = 
neuper@37906
   244
   "1 / EI * (L * q_0 / 4 * (x ^^^ 3 / 3) + -1 * q_0 / 6 * (x ^^^ 4 / 4))"
neuper@37906
   245
then () else raise error "integrate.sml, simplify_Integral #199";
neuper@37906
   246
neuper@37906
   247
neuper@37906
   248
neuper@38013
   249
"----------- simplify by extending make_polynomial_in ---";
neuper@38013
   250
"----------- simplify by extending make_polynomial_in ---";
neuper@38013
   251
"----------- simplify by extending make_polynomial_in ---";
neuper@37906
   252
trace_rewrite:=true;
neuper@37906
   253
trace_rewrite:=false;
neuper@37906
   254
(*postponed: see *)
neuper@37906
   255
neuper@37906
   256
neuper@38013
   257
"----------- integrate by ruleset -----------------------";
neuper@38013
   258
"----------- integrate by ruleset -----------------------";
neuper@38013
   259
"----------- integrate by ruleset -----------------------";
neuper@37906
   260
val rls = "integration_rules";
neuper@37906
   261
val subs = [("bdv","x::real")];
neuper@37906
   262
fun rewrit_sinst subs rls str = 
neuper@37991
   263
    fst (the (rewrite_set_inst "Integrate" true subs rls str));
neuper@37906
   264
(*~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
neuper@37906
   265
val str = rewrit_sinst subs rls "Integral x D x";
neuper@37906
   266
val str = rewrit_sinst subs rls "Integral c * x ^^^ 2 + c_2 D x";
neuper@37906
   267
if str = "c * (x ^^^ 3 / 3) + c_2 * x"
neuper@37906
   268
then () else raise error "integrate.sml: diff.behav. in integration_rules";
neuper@37906
   269
neuper@37906
   270
val rls = "add_new_c";
neuper@37906
   271
val str = rewrit_sinst subs rls "c * (x ^^^ 3 / 3) + c_2 * x";
neuper@37906
   272
if str = "c * (x ^^^ 3 / 3) + c_2 * x + c_3" then () 
neuper@37906
   273
else raise error "integrate.sml: diff.behav. in add_new_c simpl.";
neuper@37906
   274
neuper@37906
   275
val str = rewrit_sinst subs rls "F x = x ^^^ 3 / 3 + x";
neuper@37906
   276
if str = "F x = x ^^^ 3 / 3 + x + c"(*not "F x + c =..."*) then () 
neuper@37906
   277
else raise error "integrate.sml: diff.behav. in add_new_c equation";
neuper@37906
   278
neuper@37906
   279
val rls = "simplify_Integral";
neuper@37906
   280
(*~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
neuper@37906
   281
val str = "ff x = c * x + -1 * q_0 * (x ^^^ 2 / 2) + c_2";
neuper@37906
   282
val str = rewrit_sinst subs rls str;
neuper@37906
   283
if str = "ff x = c_2 + c * x + -1 * q_0 / 2 * x ^^^ 2"
neuper@37906
   284
then () else raise error "integrate.sml: diff.behav. in simplify_I #1";
neuper@37906
   285
neuper@37906
   286
val rls = "integration";
neuper@37906
   287
(*~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
neuper@37906
   288
val str = rewrit_sinst subs rls "Integral c * x ^^^ 2 + c_2 D x";
neuper@37906
   289
if str = "c_3 + c_2 * x + c / 3 * x ^^^ 3"
neuper@37906
   290
then () else raise error "integrate.sml: diff.behav. in integration #1";
neuper@37906
   291
neuper@37906
   292
val str = rewrit_sinst subs rls "Integral 3*x^^^2 + 2*x + 1 D x";
neuper@37906
   293
if str = "c + x + x ^^^ 2 + x ^^^ 3" then () 
neuper@37906
   294
else raise error "integrate.sml: diff.behav. in integration #2";
neuper@37906
   295
neuper@37906
   296
val str = rewrit_sinst subs rls 
neuper@37906
   297
"Integral 1 / EI * (L * q_0 / 2 * x + -1 * q_0 / 2 * x ^^^ 2) D x";
neuper@37906
   298
if str =
neuper@37906
   299
   "c + 1 / EI * (L * q_0 / 4 * x ^^^ 2 + -1 * q_0 / 6 * x ^^^ 3)"
neuper@37906
   300
then () else raise error "integrate.sml: diff.behav. in integration #3";
neuper@37906
   301
neuper@37906
   302
val str = "Integral "^str^" D x";
neuper@37906
   303
val str = rewrit_sinst subs rls str;
neuper@37906
   304
if str =
neuper@37906
   305
   "c_2 + c * x + 1 / EI * (L * q_0 / 12 * x ^^^ 3 + -1 * q_0 / 24 * x ^^^ 4)"
neuper@37906
   306
then () else raise error "integrate.sml: diff.behav. in integration #4";
neuper@37906
   307
neuper@37906
   308
neuper@38013
   309
"----------- rewrite 3rd integration in 7.27 ------------";
neuper@38013
   310
"----------- rewrite 3rd integration in 7.27 ------------";
neuper@38013
   311
"----------- rewrite 3rd integration in 7.27 ------------";
neuper@37906
   312
val thy = Isac.thy (*because of Undeclared constant "Biegelinie.EI*);
neuper@37906
   313
val bdv = [(str2term"bdv", str2term"x")];
neuper@37906
   314
val t = str2term
neuper@37906
   315
	    "Integral 1 / EI * ((L * q_0 * x + -1 * q_0 * x ^^^ 2) / 2) D x";
neuper@37926
   316
val SOME(t,_)= rewrite_set_inst_ thy true bdv simplify_Integral t;
neuper@37906
   317
if term2str t = 
neuper@37906
   318
   "Integral 1 / EI * (L * q_0 / 2 * x + -1 * q_0 / 2 * x ^^^ 2) D x" then ()
neuper@37906
   319
else raise error "integrate.sml 3rd integration in 7.27, simplify_Integral";
neuper@37906
   320
neuper@37926
   321
val SOME(t,_)= rewrite_set_inst_ thy true bdv integration t;
neuper@37906
   322
if term2str t = "c + 1 / EI * (L * q_0 / 4 * x ^^^ 2 + -1 * q_0 / 6 * x ^^^ 3)"
neuper@37906
   323
then () else raise error "integrate.sml 3rd integration in 7.27, integration";
neuper@37906
   324
neuper@37906
   325
neuper@38013
   326
"----------- check probem type --------------------------";
neuper@38013
   327
"----------- check probem type --------------------------";
neuper@38013
   328
"----------- check probem type --------------------------";
neuper@37994
   329
val model = {Given =["functionTerm f_f", "integrateBy v_v"],
neuper@37906
   330
	     Where =[],
neuper@37906
   331
	     Find  =["antiDerivative F_"],
neuper@37906
   332
	     With  =[],
neuper@37906
   333
	     Relate=[]}:string ppc;
neuper@38013
   334
val chkmodel = ((map (the o (parse thy))) o ppc2list) model;
neuper@37906
   335
val t1 = (term_of o hd) chkmodel;
neuper@37906
   336
val t2 = (term_of o hd o tl) chkmodel;
neuper@37906
   337
val t3 = (term_of o hd o tl o tl) chkmodel;
neuper@37906
   338
case t3 of Const ("Integrate.antiDerivative", _) $ _ => ()
neuper@37906
   339
	 | _ => raise error "integrate.sml: Integrate.antiDerivative ???";
neuper@37906
   340
neuper@37994
   341
val model = {Given =["functionTerm f_f", "integrateBy v_v"],
neuper@37906
   342
	     Where =[],
neuper@37906
   343
	     Find  =["antiDerivativeName F_"],
neuper@37906
   344
	     With  =[],
neuper@37906
   345
	     Relate=[]}:string ppc;
neuper@38013
   346
val chkmodel = ((map (the o (parse thy))) o ppc2list) model;
neuper@37906
   347
val t1 = (term_of o hd) chkmodel;
neuper@37906
   348
val t2 = (term_of o hd o tl) chkmodel;
neuper@37906
   349
val t3 = (term_of o hd o tl o tl) chkmodel;
neuper@37906
   350
case t3 of Const ("Integrate.antiDerivativeName", _) $ _ => ()
neuper@37906
   351
	 | _ => raise error "integrate.sml: Integrate.antiDerivativeName";
neuper@37906
   352
neuper@37906
   353
"----- compare 'Find's from problem, script, formalization -------";
neuper@37906
   354
val {ppc,...} = get_pbt ["named","integrate","function"];
neuper@37906
   355
val ("#Find", (Const ("Integrate.antiDerivativeName", _),
neuper@37906
   356
	       F1_ as Free ("F_", F1_type))) = last_elem ppc;
neuper@37906
   357
val {scr = Script sc,... } = get_met ["diff","integration","named"];
neuper@37906
   358
val [_,_, F2_] = formal_args sc;
neuper@37906
   359
if F1_ = F2_ then () else raise error "integrate.sml: unequal find's";
neuper@37906
   360
neuper@37906
   361
val ((dsc as Const ("Integrate.antiDerivativeName", _)) 
neuper@37924
   362
	 $ Free ("ff", F3_type)) = str2term "antiDerivativeName ff";
neuper@37906
   363
if is_dsc dsc then () else raise error "integrate.sml: no description";
neuper@37906
   364
if F1_type = F3_type then () 
neuper@37906
   365
else raise error "integrate.sml: unequal types in find's";
neuper@37906
   366
neuper@37906
   367
show_ptyps();
neuper@37906
   368
val pbl = get_pbt ["integrate","function"];
neuper@37926
   369
case #cas pbl of SOME (Const ("Integrate.Integrate",_) $ _) => ()
neuper@37906
   370
	 | _ => raise error "integrate.sml: Integrate.Integrate ???";
neuper@37906
   371
neuper@37906
   372
neuper@38013
   373
"----------- check Scripts ------------------------------";
neuper@38013
   374
"----------- check Scripts ------------------------------";
neuper@38013
   375
"----------- check Scripts ------------------------------";
neuper@37906
   376
val str = 
neuper@37994
   377
"Script IntegrationScript (f_f::real) (v_v::real) =               \
neuper@37981
   378
\  (let t_ = Take (Integral f_ D v_v)                                 \
neuper@37991
   379
\   in (Rewrite_Set_Inst [(bdv,v_v)] integration False) (t_::real))";
neuper@37906
   380
val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
neuper@37906
   381
atomty sc;
neuper@37906
   382
neuper@37906
   383
val str = 
neuper@37994
   384
"Script NamedIntegrationScript (f_f::real) (v_v::real) (F_::real=>real) = \
neuper@37981
   385
\  (let t_ = Take (F_ v_v = Integral f_ D v_v)                         \
neuper@37991
   386
\   in (Rewrite_Set_Inst [(bdv,v_v)] integration False) t_)";
neuper@37906
   387
val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
neuper@37906
   388
atomty sc;
neuper@37906
   389
show_mets();
neuper@37906
   390
neuper@37906
   391
neuper@38013
   392
"----------- me method [diff,integration] ---------------";
neuper@38013
   393
"----------- me method [diff,integration] ---------------";
neuper@38013
   394
"----------- me method [diff,integration] ---------------";
neuper@37906
   395
(*exp_CalcInt_No-1.xml*)
neuper@37906
   396
val fmz = ["functionTerm (x^^^2 + 1)", 
neuper@37906
   397
	   "integrateBy x","antiDerivative FF"];
neuper@37906
   398
val (dI',pI',mI') =
neuper@37991
   399
  ("Integrate",["integrate","function"],
neuper@37906
   400
   ["diff","integration"]);
neuper@37906
   401
val p = e_pos'; val c = []; 
neuper@37906
   402
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@37906
   403
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   404
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   405
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   406
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   407
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   408
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   409
val (p,_,f,nxt,_,pt) = me nxt p c pt(*nxt <- Apply_Method*);
neuper@37906
   410
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   411
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   412
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   413
if f2str f = "c + x + 1 / 3 * x ^^^ 3" then ()
neuper@37906
   414
else raise error "integrate.sml: method [diff,integration]";
neuper@37906
   415
neuper@37906
   416
neuper@38013
   417
"----------- me method [diff,integration,named] ---------";
neuper@38013
   418
"----------- me method [diff,integration,named] ---------";
neuper@38013
   419
"----------- me method [diff,integration,named] ---------";
neuper@37906
   420
(*exp_CalcInt_No-2.xml*)
neuper@37906
   421
val fmz = ["functionTerm (x^^^2 + 1)", 
neuper@37906
   422
	   "integrateBy x","antiDerivativeName F"];
neuper@37906
   423
val (dI',pI',mI') =
neuper@37991
   424
  ("Integrate",["named","integrate","function"],
neuper@37906
   425
   ["diff","integration","named"]);
neuper@37906
   426
val p = e_pos'; val c = []; 
neuper@37906
   427
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@37906
   428
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   429
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   430
val (p,_,f,nxt,_,pt) = me nxt p c pt(*nxt <- Add_Find *);
neuper@37906
   431
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   432
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   433
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   434
val (p,_,f,nxt,_,pt) = me nxt p c pt(*nxt <- Apply_Method*);
neuper@37906
   435
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   436
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   437
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   438
if f2str f = "F x = c + x + 1 / 3 * x ^^^ 3" then() 
neuper@37906
   439
else raise error "integrate.sml: method [diff,integration,named]";
neuper@37906
   440
neuper@37906
   441
neuper@38013
   442
"----------- me met [diff,integration,named] Biegelinie.Q";
neuper@38013
   443
"----------- me met [diff,integration,named] Biegelinie.Q";
neuper@38013
   444
"----------- me met [diff,integration,named] Biegelinie.Q";
neuper@37906
   445
(*exp_CalcInt_No-3.xml*)
neuper@37906
   446
val fmz = ["functionTerm (- q_0)", 
neuper@37906
   447
	   "integrateBy x","antiDerivativeName Q"];
neuper@37906
   448
val (dI',pI',mI') =
neuper@37991
   449
  ("Biegelinie",["named","integrate","function"],
neuper@37906
   450
   ["diff","integration","named"]);
neuper@37906
   451
val p = e_pos'; val c = [];
neuper@37906
   452
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@37906
   453
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   454
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   455
(*Error Tac Q not in ...*)
neuper@37906
   456
val (p,_,f,nxt,_,pt) = me nxt p c pt(*nxt <- Add_Find *);
neuper@37906
   457
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   458
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   459
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   460
val (p,_,f,nxt,_,pt) = me nxt p c pt(*nxt <- Apply_Method*);
neuper@37906
   461
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   462
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   463
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   464
neuper@37906
   465
if f2str f = "Q x = c + -1 * q_0 * x" then() 
neuper@37906
   466
else raise error "integrate.sml: method [diff,integration,named] .Q";
neuper@37906
   467
neuper@37906
   468
neuper@38013
   469
"----------- interSteps [diff,integration] --------------";
neuper@38013
   470
"----------- interSteps [diff,integration] --------------";
neuper@38013
   471
"----------- interSteps [diff,integration] --------------";
neuper@37906
   472
states:=[];
neuper@37906
   473
CalcTree
neuper@37906
   474
[(["functionTerm (x^2 + 1)","integrateBy x","antiDerivative FF"], 
neuper@37991
   475
  ("Integrate",["integrate","function"],
neuper@37906
   476
  ["diff","integration"]))];
neuper@37906
   477
Iterator 1;
neuper@37906
   478
moveActiveRoot 1;
neuper@37906
   479
autoCalculate 1 CompleteCalc;
neuper@37906
   480
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   481
neuper@37906
   482
interSteps 1 ([1],Res);
neuper@37906
   483
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   484
if existpt' ([1,3], Res) pt then ()
neuper@37906
   485
else raise error "integrate.sml: interSteps on Rewrite_Set_Inst 1";
neuper@37906
   486
neuper@37906
   487
neuper@38013
   488
"----------- method analog to rls 'integration' ---------";
neuper@38013
   489
"----------- method analog to rls 'integration' ---------";
neuper@38013
   490
"----------- method analog to rls 'integration' ---------";
neuper@37906
   491
store_met
neuper@38013
   492
    (prep_met thy "met_testint" [] e_metID
neuper@37906
   493
	      (["diff","integration","test"],
neuper@37994
   494
	       [("#Given" ,["functionTerm f_f", "integrateBy v_v"]),
neuper@37906
   495
		("#Find"  ,["antiDerivative F_"])
neuper@37906
   496
		],
neuper@37906
   497
	       {rew_ord'="tless_true", rls'=Atools_erls, calc = [], 
neuper@37906
   498
		srls = e_rls, 
neuper@37906
   499
		prls=e_rls,
neuper@37906
   500
	     crls = Atools_erls, nrls = e_rls},
neuper@37994
   501
"Script IntegrationScript (f_f::real) (v_v::real) =             \
neuper@37991
   502
\  (((Rewrite_Set_Inst [(bdv,v_v)] integration_rules False) @@ \
neuper@37991
   503
\    (Rewrite_Set_Inst [(bdv,v_v)] add_new_c False)         @@ \
neuper@37994
   504
\    (Rewrite_Set_Inst [(bdv,v_v)] simplify_Integral False)) (f_f::real))"
neuper@37906
   505
));
neuper@37906
   506
neuper@37906
   507
states:=[];
neuper@37906
   508
CalcTree
neuper@37906
   509
[(["functionTerm (Integral x^2 + 1 D x)","integrateBy x",
neuper@37906
   510
   "antiDerivative FF"], 
neuper@37991
   511
  ("Integrate",["integrate","function"],
neuper@37906
   512
  ["diff","integration","test"]))];
neuper@37906
   513
Iterator 1;
neuper@37906
   514
moveActiveRoot 1;
neuper@37906
   515
autoCalculate 1 CompleteCalcHead;
neuper@37906
   516
neuper@37906
   517
fetchProposedTactic 1  (*..Apply_Method*);
neuper@37906
   518
autoCalculate 1 (Step 1);
neuper@37906
   519
getTactic 1 ([1], Frm)  (*still empty*);
neuper@37906
   520
neuper@37906
   521
fetchProposedTactic 1  (*Rewrite_Set_Inst integration_rules*);
neuper@37906
   522
autoCalculate 1 (Step 1);
neuper@37906
   523
neuper@37906
   524
fetchProposedTactic 1  (*Rewrite_Set_Inst add_new_c*);
neuper@37906
   525
autoCalculate 1 (Step 1);
neuper@37906
   526
neuper@37906
   527
fetchProposedTactic 1  (*Rewrite_Set_Inst simplify_Integral*);
neuper@37906
   528
autoCalculate 1 (Step 1);
neuper@37906
   529
neuper@37906
   530
autoCalculate 1 CompleteCalc;
neuper@37906
   531
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   532
if existpt' ([3], Res) pt then ()
neuper@37906
   533
else raise error  "integrate.sml: test-script doesnt work";
neuper@37906
   534
neuper@37906
   535
neuper@38013
   536
"----------- Ambiguous input: Integral ?u + ?v D ?bdv = .";
neuper@38013
   537
"----------- Ambiguous input: Integral ?u + ?v D ?bdv = .";
neuper@38013
   538
"----------- Ambiguous input: Integral ?u + ?v D ?bdv = .";
neuper@37906
   539
states:=[];
neuper@37906
   540
CalcTree
neuper@37906
   541
[(["functionTerm (x^2 + 1)","integrateBy x","antiDerivative FF"], 
neuper@37991
   542
  ("Integrate",["integrate","function"],
neuper@37906
   543
  ["diff","integration"]))];
neuper@37906
   544
Iterator 1;
neuper@37906
   545
moveActiveRoot 1;
neuper@37906
   546
autoCalculate 1 CompleteCalc;
neuper@37906
   547
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   548
neuper@37906
   549
interSteps 1 ([1],Res);
neuper@37906
   550
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   551
interSteps 1 ([1,1],Res);
neuper@37906
   552
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   553
getTactic 1 ([1,1,1],Frm);
neuper@37906
   554
neuper@37906
   555
val str = (unenclose o string_of_thm) integral_add;
neuper@37906
   556
writeln str;
neuper@37906
   557
(*
neuper@37906
   558
read_cterm (sign_of thy) (str,(TVar(("DUMMY",0),[])));
neuper@37906
   559
neuper@37906
   560
*** More than one term is type correct:
neuper@37906
   561
*** ((Integral (?u + ?v) D ?bdv) =
neuper@37906
   562
***  (Integral ?u D (?bdv + (Integral ?v D ?bdv))))
neuper@37906
   563
                ###^^^###
neuper@37906
   564
*** ((Integral (?u + ?v) D ?bdv) =
neuper@37906
   565
***  ((Integral ?u D ?bdv) + (Integral ?v D ?bdv)))
neuper@37906
   566
*)
neuper@37906
   567
neuper@37906
   568
if existpt' ([1,1,5], Res) pt then ()
neuper@37906
   569
else raise error "integrate.sml: interSteps on Rewrite_Set_Inst 2";
neuper@37906
   570
neuper@38013
   571
neuper@38013
   572
"----------- CAS input ----------------------------------";
neuper@38013
   573
"----------- CAS input ----------------------------------";
neuper@38013
   574
"----------- CAS input ----------------------------------";
neuper@37906
   575
val t = str2term "Integrate (x^^^2 + x + 1, x)";
neuper@37906
   576
case t of Const ("Integrate.Integrate", _) $ _ => ()
neuper@37906
   577
	| _ => raise error "diff.sml behav.changed for Integrate (..., x)";
neuper@37906
   578
atomty t;
neuper@37906
   579
neuper@37906
   580
states:=[];
neuper@37906
   581
CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
neuper@37906
   582
Iterator 1;
neuper@37906
   583
moveActiveRoot 1;
neuper@37906
   584
replaceFormula 1 "Integrate (x^2 + x + 1, x)";
neuper@37906
   585
autoCalculate 1 CompleteCalc;
neuper@37906
   586
val ((pt,p),_) = get_calc 1;
neuper@37906
   587
val Form res = (#1 o pt_extract) (pt, ([],Res));
neuper@37906
   588
show_pt pt;
neuper@37906
   589
(* WN070703 does not work like Diff due to error in next-pos
neuper@37906
   590
if p = ([], Res) andalso term2str res = "5 * a" then ()
neuper@37906
   591
else raise error "diff.sml behav.changed for Integrate (x^2 + x + 1, x)";
neuper@37934
   592
*)