Re: sum of binomials .. bug ?
- To: mathgroup at smc.vnet.net
- Subject: [mg70527] Re: sum of binomials .. bug ?
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 18 Oct 2006 04:18:32 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <eh20si$2ms$1@smc.vnet.net>
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