[Date Index]
[Thread Index]
[Author Index]
Re: Bug in Sum causes index variable to remain set?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg33897] Re: [mg33838] Bug in Sum causes index variable to remain set?
*From*: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
*Date*: Sun, 21 Apr 2002 06:14:48 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
I forgot a couple of things. First, your second example seems to be
wrong. At least with Mathematica 4.1 for MacOS X I get:
In[1]:=
Sum[1, {f[x, n], 1, 3}]
Out[1]=
3
In[2]:=
?f
Global`f
So only when you actually perform an evaluation within f that you get
the behaviour you observed, e.g.
In[3]:=
Sum[1, {f[x*1, n], 1, 3}]
Out[3]=
3
In[4]:=
Information["f", LongForm -> False]
Global`f
f[x, n] = 3
Also, it seems to me that the simplest solution to your problem (which I
am not prepared to call a bug) is to wrap Block around Sum as follows:
In[8]:=
Clear[f]
In[9]:=
Block[{f}, Sum[1, {f[x, n*1], 1, 3}]]
Out[9]=
3
In[10]:=
Information["f",LongForm -> False]
Global`f
On Sunday, April 21, 2002, at 03:46 PM, Andrzej Kozlowski wrote:
> I don't know whether this is a bug or not, and it seems to me that this
> is just the sort of situation where we lack a clear definition of what
> constitutes a bug (Behaviour undesirable to some users? Unintended
> undesirable behaviour? Easily avoidable undesirable behaviour?).
> However, I can point out that this behaviour is a universal feature of
> Mathematica design in analogous cases. The same thing will happen if
> you replace Sum by Product, Table or Do. Integrate is not a good
> example because it does not assign values to the variable of
> integration (it just finds the antiderivative and evaluate limits).
> NIntegrate would have been a better example, but it actually also does
> not make assignments to an iterator. So bug or not it seems to be a
> feature (feature!) of Mathematica"s design, more precisely of the way
> Matheamtica uses iterators.
>
> Andrzej Kozlowski
Toyama International University
JAPAN
http://platon.c.u-tokyo.ac.jp/andrzej/
>
>
>
>
>
> On Friday, April 19, 2002, at 03:28 PM, Martin Jenkins wrote:
>
>>
>> Hello, I have found what appears to be a bug in Sum in Mathematica 4.0.
>> I stumbled across is trying to sum an expression with subscripts.
>> Anyway:
>>
>> In[1]:= n = 1;
>>
>> In[2]:= Sum[1, {f[x, 1], 1, 3}]
>> Out[2]= 3
>> In[3]:= ?f
>> In[4]:= Sum[1, {f[x, n], 1, 3}]
>> Out[4]= 3
>> In[5]:= ?f
>>
>> In[6]:= Clear[f];
>> In[7]:= Sum[1, {f[x, 1*1], 1, 3}]
>> Out[7]= 3
>> In[8]:= ?f
>>
>> The way that f gets set by the Sum to the final value is a bug is it
>> not? I would guess that Sum unsets the literal expression f[x, n] or
>> f[x, 1*1], rather than exactly what it set in the first place. I can
>> get around this by f[x,n]=. whenever I use it... but I would rather
>> not have a line with a comment saying "Mathematica bug work-around".
>> Integrate works fine under similar circumstances.
>>
>> Thanks,
>> Martin
>>
>>
>>
>>
>
Prev by Date:
**RE: Need a algorithm**
Next by Date:
**Re: Integrate malfunction?**
Previous by thread:
**Re: Bug in Sum causes index variable to remain set?**
Next by thread:
**Re: Bug in Sum causes index variable to remain set?**
| |