test/Tools/isac/Knowledge/integrate.sml
author Walther Neuper <neuper@ist.tugraz.at>
Sun, 10 Oct 2010 14:15:43 +0200
branchisac-update-Isa09-2
changeset 38056 98ebf8c25a28
parent 38055 e9ee52ea1454
child 38064 b9b19b631413
permissions -rw-r--r--
update finished for test/../integrate.sml

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