# Evaluation of the second argument to NIntegrate

The expression

Integrate[x^2, Flatten[{{x},{1,2}}]]


evaluates properly, to $\frac{7}{3}$. However,

NIntegrate[x^2, Flatten[{{x},{1,2}}]]


returns

NIntegrate::vars: Integration range specification Flatten[{{x},{1,2}}] is not of the form {x, xmin, ..., xmax}. >>

An explicit Evaluate is required on the second parameter to make this work. So I assume that NIntegrate has a HoldAll on its second parameter.

Did I have any way of knowing this before hand? That is, is this behavior documented? And, if it is (or even if it is not), why do the two functions behave differently?

• Such information can be found at the end of the "Details and Options" section in the documentation for NIntegrate (and for other functions, too). Try also executing Attributes[NIntegrate]. Commented Nov 12, 2013 at 2:48
• @MichaelE2 Thanks. So do you also know why the two functions (should) behave differently? Also, if you want to post this as an answer, I'll accept it. Commented Nov 12, 2013 at 21:01
• "…NIntegrate has a HoldAll on its second parameter…" - well, HoldAll does mean what it says; all inputs given are held. Commented May 26, 2015 at 23:49

The reason that it works for Integrate and not for NIntegrate is that NIntegrate has the attribute HoldAll and Integrate does not. Attributes, if any, are listed at the end of the "Details and Options" section of the documentation page for a function. They may also be inspected with the Attributes command:

Attributes@Integrate

Attributes@NIntegrate
(* {HoldAll,Protected} *)


Aside from the difference point out by the OP, there is also this one if x has a value:

x = 4
(* 4 *)

NIntegrate[x^2, {x, 1, 2}]
(* 2.33333 *)

Integrate[x^2, {x, 1, 2}]


Integrate::ilim: Invalid integration variable or limit(s) in {4,1,2}. >>

I do not know why the developers have chosen to treat these similar functions differently.