|
23 | 23 | RubiStats::usage = "RubiStats is a symbolic wrapper that contains statistical information about an integration." <>
|
24 | 24 | "It consists of (a) the number of steps used to integrate, (b) the number of distinct rules used, (c) is the leaf count size of the input," <>
|
25 | 25 | "(d) the leaf count size of the antiderivative, and (e) the rule-to-size ratio of the integration (i.e. the quotient of (b) and (c)).";
|
26 |
| - |
| 26 | +RubiPrintInformation::usage = "RubiPrintInformation is an option to Steps and Stats that prints information if set to True and returns as a list otherwise."; |
27 | 27 | Unintegrable::usage = "Unintegrable[expn,var] indicates <expn> is not integrable with respect to <var> in closed-form.";
|
28 | 28 | CannotIntegrate::usage = "CannotIntegrate[expn,var] indicates Rubi is unable to integrate <expn> with respect to <var>.";
|
29 | 29 |
|
|
287 | 287 | ];
|
288 | 288 |
|
289 | 289 | Int::argFlag = "The `` routine can only be used with the form Int[expr, x] where x is a symbol.";
|
290 |
| -Int::noShowSteps = "To use this function, you need to define $LoadShowSteps=True before loading the Rubi package" |
| 290 | +Int::noShowSteps = "To use this function, you need to define $LoadShowSteps=True before loading the Rubi package"; |
291 | 291 | SetAttributes[Steps, {HoldAllComplete}];
|
292 |
| -Steps[Int[expr_, x_], n_Integer : Infinity] := Module[{result, steps}, |
| 292 | +Options[Steps] = { |
| 293 | + RubiPrintInformation -> True |
| 294 | +}; |
| 295 | +Steps[Int[expr_, x_], n_Integer : Infinity, OptionsPattern[]] /; n > 0 := Module[{result, steps}, |
293 | 296 | {result, steps} = Reap@Block[{$ShowSteps = True},
|
294 | 297 | FixedPoint[
|
295 | 298 | Function[int,
|
|
298 | 301 | ReleaseHold[held]
|
299 | 302 | ]
|
300 | 303 | ], Int[expr, x],
|
301 |
| - n |
| 304 | + n - 1 |
302 | 305 | ]
|
303 | 306 | ];
|
304 |
| - PrintRubiSteps[steps]; |
305 |
| - result |
| 307 | + If[OptionValue[RubiPrintInformation] === True, |
| 308 | + PrintRubiSteps[steps]; |
| 309 | + result, |
| 310 | + {steps, result} |
| 311 | + ] |
306 | 312 | ] /; TrueQ[$LoadShowSteps] && Head[x] === Symbol && n > 0;
|
307 | 313 | Steps[int : Int[__]] := (Message[Int::noShowSteps]; int);
|
308 | 314 | Steps[___] := Null /; Message[Int::argFlag, "Steps"];
|
309 | 315 |
|
310 | 316 | SetAttributes[Step, {HoldAllComplete}];
|
311 |
| -Step[Int[expr_, x_]] := Module[{result, step}, |
| 317 | +Options[Step] = { |
| 318 | + RubiPrintInformation -> True |
| 319 | +}; |
| 320 | +Step[Int[expr_, x_], OptionsPattern[]] := Module[{result, step}, |
312 | 321 | {result, step} = Reap@Block[{$ShowSteps = True}, Int[expr, x]];
|
313 |
| - PrintRubiSteps[step]; |
314 |
| - result |
| 322 | + If[OptionValue[RubiPrintInformation] === True, |
| 323 | + PrintRubiSteps[step]; |
| 324 | + result, |
| 325 | + {step, result} |
| 326 | + ] |
315 | 327 | ] /; TrueQ[$LoadShowSteps && Head[x] === Symbol];
|
316 | 328 | Step[int : Int[__]] := (Message[Int::noShowSteps]; int);
|
317 | 329 | Step[___] := Null /; Message[Int::argFlag, "Step"];
|
318 | 330 |
|
319 | 331 | SetAttributes[Stats, {HoldAllComplete}];
|
320 |
| -Stats[Int[expr_, x_]] := Block[{$ShowSteps = False, $StepCounter = 0, $RuleList = {}}, |
| 332 | +Options[Stats] = { |
| 333 | + RubiPrintInformation -> True |
| 334 | +}; |
| 335 | +Stats[Int[expr_, x_], OptionsPattern[]] := Block[{$ShowSteps = False, $StepCounter = 0, $RuleList = {}}, |
321 | 336 | With[{result = Int[expr, x]},
|
322 |
| - { |
323 |
| - RubiStats@{$StepCounter, Length[$RuleList], LeafCount[expr], LeafCount[result], N[Length[$RuleList] / LeafCount[expr], 4], $RuleList}, |
324 |
| - result |
325 |
| - }]] /; TrueQ[$LoadShowSteps] && Head[x] === Symbol; |
| 337 | + If[OptionValue[RubiPrintInformation] === True, |
| 338 | + Print@RubiStats@{$StepCounter, Length[$RuleList], LeafCount[expr], LeafCount[result], N[Length[$RuleList] / LeafCount[expr], 4], $RuleList}; |
| 339 | + result, |
| 340 | + { |
| 341 | + RubiStats@{$StepCounter, Length[$RuleList], LeafCount[expr], LeafCount[result], N[Length[$RuleList] / LeafCount[expr], 4], $RuleList}, |
| 342 | + result |
| 343 | + } |
| 344 | + ] |
| 345 | +]] /; TrueQ[$LoadShowSteps] && Head[x] === Symbol; |
326 | 346 | Stats[int : Int[_, _Symbol]] := (Message[Int::noShowSteps]; int);
|
327 | 347 | Stats[___] := Null /; Message[Int::argFlag, "Stats"];
|
328 | 348 |
|
|
332 | 352 | Int[_, _, flag : (Stats | Step | Steps)] := Null /; Message[Int::oldFlag, flag];
|
333 | 353 |
|
334 | 354 |
|
335 |
| -Int[u_, {x_Symbol, a_, b_}] := |
336 |
| - With[{result = Int[u, x]}, |
337 |
| - Limit[result, x -> b] - Limit[result, x -> a]] |
338 |
| - |
339 |
| - |
340 |
| -Int[{u__}, x_Symbol] := |
341 |
| - Map[Function[Int[#, x]], {u}] |
342 |
| - |
| 355 | +Int[u_, {x_Symbol, a_, b_}] := With[{result = Int[u, x]}, Limit[result, x -> b] - Limit[result, x -> a]]; |
| 356 | +Int[{u__}, x_Symbol] := Map[Function[Int[#, x]], {u}]; |
343 | 357 |
|
344 | 358 | Protect[Int];
|
345 | 359 |
|
346 |
| - |
347 | 360 | $Unintegrable = False;
|
348 |
| - |
349 |
| - |
350 | 361 | Unintegrable[u_, x_] :=
|
351 | 362 | If[$Unintegrable === True,
|
352 | 363 | Defer[Unintegrable][u, x],
|
353 |
| - Defer[Int][u, x]]; |
| 364 | + Defer[Int][u, x] |
| 365 | + ]; |
354 | 366 |
|
355 | 367 | CannotIntegrate[u_, x_] := Defer[Int][u, x];
|
356 | 368 | LoadRules[$ruleFormatting];
|
|
0 commit comments