RE: Re: Dealing with sums
- To: mathgroup at smc.vnet.net
- Subject: [mg41045] RE: [mg41014] Re: Dealing with sums
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 30 Apr 2003 04:21:36 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Carl, Have you tried out Ted Ersek's SubscriptSymbols package? It should solve the problem. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Carl K. Woll [mailto:carl at woll2woll.com] To: mathgroup at smc.vnet.net 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: [mg41045] [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}] ?