Re: Re: Uniform design
- To: mathgroup at smc.vnet.net
- Subject: [mg48310] Re: [mg48304] Re: Uniform design
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 23 May 2004 06:15:37 -0400 (EDT)
- References: <c8kd99$msp$1@smc.vnet.net> <200405220704.DAA08884@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
One way to view the history of mathematics, and along with it the
history of "mathematical tools"(of which Mathematica is just one) is as
an unending struggle between two view points. There are various ways to
look at it, but one that particularly appeals to me, is through the
personalities of two of the greatest figures in the history of all
human thought: Newton and Leibniz. Leibniz, as is well known, had a
great interest in logic and abstract ideas. He also wished to create
perfect and universal tools that would enable the most ignorant and
stupid persons to solve the most difficult problems. In the works of V.
I. Arnold:
"On the basis of Pascal's studies and his own arguments Leibniz quite
rapidly developed formal analysis in the form in which we know it. That
is, in a form particularly suitable to teach analysis by people who do
not understand it to people who will never understand it. Leibniz wrote
'A poor head, having subsidiary advantages,... can beat the best, just
as a child can draw with a ruler better than the greatest master by
hand."
Newton, was of course the opposite. He did not care for generality and
even at first did not wish to study Euclid because (in Arnold's words):
"he thought it was foolish to prove things that were quite obvious".
But Barrow persuaded Newton to master geometry and this proved useful
when Newton on purpose decided to make his Principia as difficult as
possible, since he did not wish any "poor heads" to be able to make any
sense of it.
While I do not think the designers of Mathematica had exactly the same
intention as Newton, I am sure they also never intended it to be used
the way Leibniz wished his "universal method" to be used. I am also
pretty sure that Newton would have liked Mathematica and Leibniz most
likely not. All of us are in some degree on one side and the other, as
one can tell from the frequency that issues like those in this posting
are raised on this list.
Andrzej Kozlowski
On 22 May 2004, at 16:04, Maxim wrote:
> Bill Rowe <readnewsciv at earthlink.net> wrote in message
> news:<c8kd99$msp$1 at smc.vnet.net>...
>> On 5/20/04 at 4:03 AM, ab_def at prontomail.com (Maxim) wrote:
>>
>>> Besides, there's a matter of 'optimizations' that Mathematica uses
>>> for Sum (an issue which was discussed in this newsgroup a while
>>> ago):
>>
>>> In[1]:= Module[{cnt = 0}, Sum[cnt += 1, {i, 10^6}] ]
>>> Module[{cnt =0}, Sum[cnt += 1, {i, 10^6 + 1}] ]
>>
>>> Out[1]= 500000500000
>>
>>> Out[2]= 1000001
>>
>> Clearly, this is a bug. But consider
>>
>> In[1]:=
>> Timing[Module[{cnt = 0}, Sum[cnt += 1, {n, 10^6}]]]
>>
>> Out[1]=
>> {8.69*Second, 500000500000}
>>
>> In[2]:=
>> Timing[Sum[n, {n, 10^6}]]
>>
>> Out[2]=
>> {2.549999999999999*Second, 500000500000}
>>
>> In[3]:=
>> Timing[Sum[n, {n, k}] /. k -> 10^6]
>>
>> Out[3]=
>> {0.019999999999999574*Second, 500000500000}
>>
>> It seems to me far more natural to due either Sum[n, {n, 10^6}] or
>> Sum[n,
>> {n,k}]/.k->10^6 then what you've shown. Not only are these more
>> natural,
>> they are faster and avoid the bug.
>
> I'm not so sure about it being a bug; what is happening here is that
> for values not greater than 10^6 Sum works as an iterator should
> (chapter A.4.2 of the Book), but for larger values Sum calls
> SymbolicSum`SymbolicSum, which pre-evaluates the first argument; so
> cnt+=1 evaluates to 1 and we're summing 10^6+1 ones. The documentation
> says that it is done only for symbolic sums (that is, when there are
> non-numerical quantities in the iterator), but my guess is that
> Mathematica tries to speed up the computations in this way when the
> number of terms is too large. Nobody would want to sum more than 10^6
> terms, right?
>
> SymbolicSum`SymbolicSum adds its share of confusion too, because it is
> also HoldAll and performs some preliminary operations on the arguments
> before evaluating them; in particular, it looks for Out in the first
> argument. As a result, we get the following:
>
> In[1]:=
> a=k;
> Sum[a,{k,n}]
>
> Out[2]=
> k*n
>
> In[3]:=
> a=k;
> Sum[%,{k,n}]
>
> Out[4]=
> n*(n+1)/2
>
> That is, there is an incosistency in deciding when the first argument
> depends on the iterator variable. And here's another pitfall: we know
> that Module[{a=k},Sum[a,{k,n}]] evaluates to k*n, but what if the Sum
> remains unevaluated? Mathematica will just return the Sum expression,
> but with a already evaluated. So Module[{a=k},Sum[a*f[k],{k,n}]] will
> give Sum[k*f[k],{k,n}], not k*Sum[f[k],{k,n}] as in the previous case.
> Here's an example:
>
> In[5]:=
> Module[{a = 1/k}, Sum[a/k, {k, 1, Infinity}]]
> Module[{a = 1/k}, Sum[a/k^2, {k, 1, Infinity}]]
>
> Sum::div: Sum does not converge.
>
> Out[5]=
> Pi^2/6
>
> Out[6]=
> Pi^2/(6*k)
>
> What's more, Sum[1/k,{k,1,Infinity}] won't necessarily return
> unevaluated -- just as well it might evaluate to Infinity, because
> there are no clear rules for that either: sometimes Mathematica says
> that a sum diverges, sometimes that it converges to Infinity. That
> gives yet another possibility for Out[5]: it might return Infinity/k.
> So it's anybody's guess what the result will be in such cases.
>
> Maxim Rytin
> m.r at prontomail.com
>
>
- References:
- Re: Uniform design
- From: ab_def@prontomail.com (Maxim)
- Re: Uniform design