17
$\begingroup$

The Documentation tells us that there are two ways to disable symbolic processing of the integrand by the NIntegrate function when it is known that it just slows down the computation. One way is documented and heavily used on the Documentation page "NIntegrate Integration Strategies" and some other Documentation pages:

Method -> {Automatic, "SymbolicProcessing" -> 0}

Another approach is to define the integrand as a "black-box" function and this way is recommended in the "Possible Issues" section of the NIntegrate documentation page.

Let us compare:

f[x_] := Nest[Sin[# + Sin[2 #]] &, x, 20]
NIntegrate[f[x], {x, 0, 1}, 
  Method -> {Automatic, "SymbolicProcessing" -> 0}] // Timing

(* => {2.797, 0.947747} *)

g[x_?NumericQ] := Nest[Sin[# + Sin[2 #]] &, x, 20]
NIntegrate[g[x], {x, 0, 1}] // Timing

(* => {0.032, 0.947747} *)

One can see the two-order speedup of the "black-box" over the Method option. What is the reason? Are there cases when the Method option have advantages over the "black-box" approach? In which cases it is recommended to use one or another?

$\endgroup$
1

1 Answer 1

8
$\begingroup$

The first case still symbolically expands nest, substituting each numerical value into that nasty big expression, while the second expands it numerically for each x val.

Try this

f[x_] := (Print[x]; Nest[Sin[# + Sin[2 #]] &, x, 2])

You will see it is only called once with the symbolic argument. "SymbolicProcessing" only turns off attenpts at symbolic integration

$\endgroup$
2
  • 8
    $\begingroup$ "SymbolicProcessing" doesn't affect whether or not symbolic integration is tried (AFAICT, with NIntegrate, it never is). Rather, preprocessing is aimed at making certain classes of integral easier to deal with numerically. For example, it checks for and tries to remove oscillatory behaviour, splits integrands piecewise and selects a method for each section, transforms integrals over infinite intervals into ones over the unit (hyper)cube, etc. $\endgroup$ Aug 29, 2012 at 10:14
  • 1
    $\begingroup$ thanks, I puzzled over that after posting the answer. $\endgroup$
    – george2079
    Aug 29, 2012 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.