MathGroup Archive 2003

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

Search the Archive

Re: Dealing with sums

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41006] Re: Dealing with sums
  • From: "Carl K. Woll" <carlw at u.washington.edu>
  • Date: Mon, 28 Apr 2003 02:31:51 -0400 (EDT)
  • Organization: University of Washington
  • References: <b8g114$pg5$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Stepan,

In my opinion, the best way to handle these types of derivatives is to use
the NonConstants option of D. For example, we could do the following:

Unprotect[D];
D[Subscript[a,i_],Subscript[a,j_],NonConstants->{a}]:=DiscreteDelta[i-j]
Protect[D];

I used the DiscreteDelta function instead of the Kronecker delta because
Mathematica seems to be better at simplifying sums with DiscreteDeltas
instead of KroneckerDeltas. Also, I  use Subscript[a,i] instead of the
equivalent form with all of the extra \s to aid in readability. Then, we can
differentiate things and get what you expect:

In[12]:=
D[Subscript[a,i],Subscript[a,j],NonConstants->{a}]
Out[12]=
DiscreteDelta[i - j]

Unfortunately, when the NonConstants option is used, Mathematica doesn't
commute the derivative and sum. To see what I mean, note what happens in
your example, where you had (when translated into slightly more
comprehensible InputForm)

D[Sum[Subscript[a,i],{i,0,N}],Subscript[a,3]]

and Mathematica commuted the D and the Sum to arrive at

Sum[D[Subscript[a,i],Subscript[a,3]],{i,0,N}]

and of course not knowing any better Mathematica thought that the derivative
was zero. If you use the NonConstants options, then you would have

D[Sum[Subscript[a,i],{i,0,N}],Subscript[a,3],NonConstants->{a}]

and Mathematica does not commute the D and Sum, so nothing further happens.
You could add a rule to D to automatically commute D and Sum as follows:

Unprotect[D];
D[HoldPattern[Sum[t_,x_]],y_,nc_]:=Sum[D[t,y,nc],x]
Protect[D];

and then when you try taking the derivative everything works.

In[17]:=
D[Sum[Subscript[a,i],{i,0,N}],Subscript[a,3],NonConstants->{a}]
Out[17]=
UnitStep[-3 + N]

However, I think it's better not to use the Sum symbol for these sums, as
Sum will not typically be able to find the closed form sum of the summand,
and also you may want to avoid adding rules to a protected symbol like D.
Furthermore, you may prefer to have an output of 1 instead of
UnitStep[-3+N], as you may know that N is bigger than 3. Instead, I
recommend that you introduce new symbols, such as d, sum and delta, and add
similar rules for these symbols, as I suggested in the following post:

http://forums.wolfram.com/mathgroup/archive/2003/Mar/msg00140.html

You will have to modify my suggestions a bit to accomodate subscripts.

Carl Woll
Physics Dept
U of Washington

"Stepan Yakovenko" <yakovenko at ngs.ru> wrote in message
news:b8g114$pg5$1 at smc.vnet.net...
> HI!
>
>   I want to get a derivative in terms of KroneckerDelta function:
>
>   \!\(\[PartialD]\_\(a\_3\)\(\[Sum]\+\(i = 0\)\%N a\_i\)\)
>
>   But I get 0.
>
>   Is there a way to do it in Mathematica ?
>
>
> -- 
> Best regards,
>  Stepan                          mailto:yakovenko at ngs.ru
>
>




  • Prev by Date: RE: slant lines (and pasted forms of Mathematica expressions)
  • Next by Date: Calling abbreviated functions nested within other functions
  • Previous by thread: Re: Dealing with sums
  • Next by thread: Re: Dealing with sums