MathGroup Archive 2003

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

Search the Archive

Re: Dealing with sums

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41014] Re: Dealing with sums
  • From: "Carl K. Woll" <carl at woll2woll.com>
  • Date: Tue, 29 Apr 2003 05:22:15 -0400 (EDT)
  • References: <008c01c30d39$8ed38670$0d1f0944@Main> <160736318.20030428230704@ngs.ru>
  • Sender: owner-wri-mathgroup at wolfram.com

Stepan,

I originally considered this problem dealing with expressions like a[i]
instead of a_i, and my proposed solution worked fine when dealing with sums
with functions of the a[i]. I was hasty in proposing the same solution for
subscripted variables, since the Subscript head mucks things up when doing
the derivatives which need to use the chain rule. As you probably noticed,
Bob Hanlon's solution doesn't handle functions of a_i either. This is
because Mathematica doesn't automatically use the chain rule so that your
definitions for D can take effect. By including the NonConstants option in
D, you force Mathematica to use the chain rule so that your new definition
for D can have a chance to be excersized. Unfortunately, this mechanism
doesn't quite work when you have subscripted variables, as the head
Subscript gets differentiated.

I see two possibilities here. Either work with terms like a[i] instead of
subscripted variables, or delve into the mysterious underworld of MakeBoxes
and MakeExpression so that the internal form of the subscripted variables is
simply a[i]. Pursuing the second option, we make the following definitions:

MakeExpression[SubscriptBox["a", i_], f_] :=
    MakeExpression[RowBox[{"a", "[", i, "]"}]]

MakeBoxes[a[i_], f_] :=
    SubscriptBox[MakeBoxes[a, f], MakeBoxes[i, f]]

Now, whenever Mathematica encounters a subscripted variable a_i, it turns it
into a[i], and whenever Mathematica generates output with a[i], it converts
into a_i. Next, we need to add rules for D and Sum:

Unprotect[D];
D[a[m_], a[n_], NonConstants -> {a}] := DiscreteDelta[n - m]
D[HoldPattern[Sum[t_, x_]], y__] := Sum[D[t, y], x]
Protect[D];

We are ready to test things out:

In[12]:=
\!\(D[Sum[a\_i\^2, {i, 0, n}], a\_m, NonConstants \[Rule] {a}]\)
Out[12]=
\!\(2\ a\_m\ UnitStep[m]\ UnitStep[\(-m\) + n]\)

In the above I used StandardForm for both input and output to show that the
input as well as the output consisted of subscripted variables, and that the
use of the internal form a[i] was completely transparent to the user.

Finally, I want to point out that I still think it is preferable to create
new symbols d, sum and delta and create similar rules as the above. If you
try using D on more complicated sums of functions of a_i I think you will
see why.

Carl Woll
Physics Dept
U of Washington

----- Original Message ----- 
From: "Stepan Yakovenko" <yakovenko at ngs.ru>
To: mathgroup at smc.vnet.net
Subject: [mg41014] Re[2]: Dealing with sums


>
>
> Hello Carl !
>
> Thanks for you concern !
> I'm greatly busy now, so I've no time to get into the heart of the
> matter. Though I've got the natural question: would this work with
> Sum[f[a_i],{i,1,N}] ?




  • Prev by Date: Re: General::aofil-closing files after manual abort
  • Next by Date: Re: Re: Re: Condition/constraint problem
  • Previous by thread: Re: Dealing with sums
  • Next by thread: RE: Re: Dealing with sums