test/Tools/isac/Knowledge/integrate.sml
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 28 Sep 2010 09:06:56 +0200
branchisac-update-Isa09-2
changeset 38031 460c24a6a6ba
parent 38030 95d956108461
child 38048 377d9061ec3e
permissions -rw-r--r--
tuned error and writeln

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