# Integrate - Why is the integration variable not local

I have noticed something odd: Let

f[t_]:=Integrate[x, {x, 0, t}]
h[t_]:=Sum[x, {x, 0, t}]


Now, enter

Table[f[x], {x, 0, 5}]
Table[h[x], {x, 0, 5}]


The first one fails, the second one does not. Consulting the documentation shows that the summation variable for Sum is local, but the integration variable for Integrate is not. There's even an article that mentions this fact.

My question is now: Is there any reason for this, i.e. any case where this 'not-scoping' is useful and not annoying? (Especially since they seem to have omitted this 'feature' for Sum or even NIntegrate)

• Also, Table, Do and Plot scope, Fit does not. I always wanted to ask this myself. Dec 21, 2015 at 23:41
• Try Array instead of Table, like here Array[ f[#]&, {5}] and you'll see what may be the reason. Dec 21, 2015 at 23:43
• @Artes I already know why it is happening if that is what you're trying to explain. I am asking why it was implemented like this Dec 22, 2015 at 9:10
• I actually think this is in part a vagary of different development histories. But there is at least one important difference between the functions: Sum has both symbolic and procedural aspects to it (made more transparent by Method settings added several eyars ago). The procedural form really is akin to Table  and that argues strongly for scoping the variabler(s) of summation. Integrate does not have any analogous behavior, hence does not really warrant such scoping. It is akin to Solve in that respect. Dec 22, 2015 at 15:50
• Interesting, Sum admits such nonsense.. Sum[ i , {i, i}] -> i (1 + i)/2 .. I expect if they started from scratch the way to resolve all this would be to insist on using formal parameters for integration variables and sum indices. Dec 23, 2015 at 15:28

I don't see this primarily as an issue of localization but rather of assignment. In a construct like Table the variables are assigned values in some way. This could potentially be done in several different ways, but a method like Block was chosen. So we see:

Dynamic[x]
Table[Pause[1], {x, 10}];

(* changing Dynamic value *)


(I think this was probably chosen for its compatibility with standard For loop code. Manipulate also changes the value of a variable, but uses something akin to Module.)

Sum also assigns a value to a variable and a Block-like method was chosen for it as well:

Dynamic[x]
Sum[Pause[1], {x, 0, 10}];

(* changing Dynamic value *)


But what does Integrate do? It does not assign anything; there is no variable.

If nothing is assigned, no assignment needs to be localized.

Dynamic[x]
Integrate[Print[x]; Pause[1]; x, {x, 0, 5}]


x

x

25/2

There is no need to choose whether to use Block, or Module, or something else (With?) as nothing is iteratively changed. Rather x is merely a specification, not a variable.

• Expecting a scoping construct here would be like expecting one
on x in Collect[a x + b y + c x, x] as that too is a specification.

There is a related construct that does use variables: NIntegrate. And guess what? It works like Table and Sum do:

Dynamic[x]
fn[_?NumericQ] := Pause[1]
NIntegrate[fn[x], {x, 0, 15}];

(* changing Dynamic value *)