MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: sum of binomials .. bug ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70563] Re: sum of binomials .. bug ?
  • From: Peter Pein <petsie at dordos.net>
  • Date: Thu, 19 Oct 2006 03:23:38 -0400 (EDT)
  • References: <eh20si$2ms$1@smc.vnet.net> <eh4q2f$8rd$1@smc.vnet.net>

Jean-Marc Gulliet schrieb:
> yann_che2 at yahoo.fr wrote:
>> Hi everyone,
>>
>> on Mathematica 5.2 (mac os x), experimenting sums of binomials, i tried
>> the following:
>>
>> In[6]:=   f[k_] := Sum[Binomial[21 - k, i], {i, 0, 10 - k}]
>> In[7]:=   x = 3; f[x]
>> Out[7]:= 63004
>> In[8]:=   Clear[x] ; f[x] /. x -> 3
>> Out[8]:= 262144
>> In[9]:=   Clear[x] ; f[x]
>> Out[9]:= 2^(21-x)
>>
>>
>> does anyone know why Out[7] and Out[8] give different results ? do you
>> think it is a bug ? i searched everywhere in the forums but couldn't
>> find anything that helped.
>> do you have a clue ?
>>
>> yann
>>
> No bug here. You are not evaluating the same function. In the first 
> case, k is replaced by the value 3, then the sum/binomial is evaluated. 
> In the second case, the sum/binomial is evaluated first, then the value 
> 3 is substituted to k. You can get a consistent result using an 
> immediate assignment rather than a delayed one.
> 
> In[1]:=
> f[k_] := Sum[Binomial[21 - k, i], {i, 0, 10 - k}]
> 
> In[2]:=
> Trace[f[3]]
> 
> In[3]:=
> Trace[f[x] /. x -> 3]
> 
> In[4]:=
> Clear[f]
> f[k_] = Sum[Binomial[21 - k, i], {i, 0, 10 - k}]
> 
> Out[5]=
> 2^(21 - k)
> 
> In[6]:=
> f[3]
> 
> Out[6]=
> 262144
> 
> In[7]:=
> f[x] /. x -> 3
> 
> Out[7]=
> 262144
> 
> Regards,
> Jean-Marc
> 
Hi Jean-Marc,

do not trust any CAS without getting a second opinion. The bugs are not always
as obvious as in the following example:


In[1]:=
hilDet[n_] := Product[(n^2 - k^2)^(k - n)*k!^2, {k, 1, n - 1}]/n^n;

Testing for some n:

In[2]:=
And @@ Table[hilDet[k] == Det[Array[1/(#1 + #2 - 1) & , {k, k}]], {k, 10}]
Out[2]=
True

split n^2-k^2:

In[3]:=
bug[n_] := (Product[(n + k)^(k - n)*k!^2, {k, 1, n - 1}]*Product[(n - k)^(k -
n), {k, 1, n - 1}])/n^n
In[4]:=
bug[10] == hilDet[10]
Out[4]=
True

well, but:

In[5]:=
bug[n]
Out[5]=
(E^((1/12)*(1 - 6*n + 6*n^2 - 12*Derivative[1, 0][Zeta][-1, 1 - n]))*
   Product[(k + n)^(k - n)*k!^2, {k, 1, -1 + n}])/(n^n*Glaisher)
In[6]:=
% /. n -> 10
Out[6]=
(20155392*E^((1/12)*(541 - 12*Derivative[1, 0][Zeta][-1,
-9])))/(43160654253356787452215625*Glaisher)
In[7]:=
hilDet[n]
Out[7]=
Product[(-k^2 + n^2)^(k - n)*k!^2, {k, 1, -1 + n}]/n^n

P²


  • Prev by Date: Re: damped oscilations data fit
  • Next by Date: RE: Re: Graphics/PlotRange/LaTeX/Psfrag
  • Previous by thread: Re: sum of binomials .. bug ?
  • Next by thread: Re: sum of binomials .. bug ?