variable of integration not localized in Integrate and Sum?
- To: mathgroup at smc.vnet.net
- Subject: [mg63827] variable of integration not localized in Integrate and Sum?
- From: Don Hatch <hatch at plunk.org>
- Date: Tue, 17 Jan 2006 04:33:23 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Apparently I need to explicitly localize t in the following,
otherwise it messes up when I pass in t as the second argument.
In:
F[f_, x_] := Integrate[f[x + t], {t, -1/2, 1/2}]
F[Sin, x]
F[Sin, t]
Out:
2 Sin[1/2] Sin[x] <---- correct
0 <---- ?!?!
This is surprising to me-- I thought that
the fact that t is the integration variable
would cause it to be automatically localized, but apparently not.
To get the right answer, I can say:
In:
F[f_, x_] := Module[{t}, Integrate[f[x + t], {t, -1/2, 1/2}]]
F[Sin, x]
F[Sin, t]
Out:
2 Sin[1/2] Sin[x] <---- correct
2 Sin[1/2] Sin[t] <---- correct
(note, I really have to use Module, not Block-- it still messes up using
Block).
The documentation for Integrate doesn't seem to support my hope that t gets
localized, as far as I could see;
however, note that exactly the same problem
occurs for Sum, whose documentation does explicitly state:
The iteration variable i is treated as local.
So here is an example that seems to clearly contradict the documentation
of Sum:
In:
F[f_, x_] := Sum[f[x + t], {t, -1/2, 1/2, 1/10}]/11
F[Identity, x]
F[Identity, t]
Out:
x <---- correct
0 <---- ?!?!
Just as for Integrate, it works properly when I explicitly
localize using Module (but not Block):
In:
F[f_, x_] := Module[{t}, Sum[f[x + t], {t, -1/2, 1/2, 1/10}]/11]
F[Identity, x]
F[Identity, t]
Out:
x <---- correct
t <---- correct
Is this a bug in Sum and/or Integrate?
I'm using Mathematica version 5.2.0.0, on Linux/X.
Don Hatch
- Follow-Ups:
- Re: variable of integration not localized in Integrate and Sum?
- From: Pratik Desai <pdesai1@umbc.edu>
- Getting identifier names from content MathML of equation
- From: Pradeep Suresh <pradeep@purdue.edu>
- Re: variable of integration not localized in Integrate and Sum?