Re: Order of terms
- To: mathgroup at smc.vnet.net
- Subject: [mg77767] Re: Order of terms
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Sat, 16 Jun 2007 03:31:01 -0400 (EDT)
- References: <f4r3ic$980$1@smc.vnet.net>
Thomas Madden wrote: > Given > > > In[1]:= c[p_] := Sum[Subscript[a, k]* Subscript[b, n - k], {n, 0, p}, {k, 0, > n}] > > > > How can I get the output in the same order that the double sum is written? > For example I would like to have the output from c[2] be > > > > In[3]:= Hold[Subscript[a, 0]Subscript[b, 0]+Subscript[a, 0]Subscript[b, > 1]+Subscript[a, 1]Subscript[b, 0]+Subscript[a, 0]Subscript[b, > 2]+Subscript[a, 1]Subscript[b, 1]+Subscript[a, 2]Subscript[b, 0]] > > > rather than the default > > > c[2] > > Thanks in advance for any and all replies. > > Thomas > First, as dh has pointed out, Plus re-orders its arguments, so it is necessary to replace Sum by Table to preserve the desired order in the first place: c[p_]:=Table[Subscript[a,k]*Subscript[b,n-k],{n,0,p},{k,0,n}] Now it is possible to display the expression thus: Flatten[c[3]] /. List[s__] :> HoldForm[Plus[s]] Note that this expression is wrapped in the invisible HoldForm - which is required in order to preserve the ordering. If you need to paste it into another expression it is important to remove this wrapper - e.g. by applying the rule HoldForm->Identity David Bailey http://www.dbaileyconsultancy.co.uk