test/Tools/isac/Knowledge/integrate.sml
author Walther Neuper <neuper@ist.tugraz.at>
Wed, 06 Oct 2010 14:52:12 +0200
branchisac-update-Isa09-2
changeset 38049 02a1cce684a7
parent 38048 377d9061ec3e
child 38050 4c52ad406c20
permissions -rw-r--r--
intermed. test/../integrate.sml, pbl, met, scr seem to work

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