Re: Efficient use of coefficient--Efficient simplification
- To: mathgroup@smc.vnet.net
- Subject: [mg11195] Re: [mg11183] Efficient use of coefficient--Efficient simplification
- From: "C. Woll" <carlw@u.washington.edu>
- Date: Mon, 2 Mar 1998 23:10:50 -0500
Hi Joel, One way to do what you want is to use Collect: Collect[ expr , ket[_] ] where expr is the expression you want to simplify. However, I don't know if this works in Mathematica 2.2. Carl Woll Dept of Physics U of Washington On Wed, 25 Feb 1998, Joel Cannon wrote: > I wish to simplify expressions such as the following which possess terms > involving ket[n+i]. They involve a variable range of indices i. > > Out[164]= > -(Sqrt[n] (Sqrt[-1 + n] ket[-2 + n] - Sqrt[n] ket[n])) + > > Sqrt[1 + n] (Sqrt[1 + n] ket[n] - Sqrt[2 + n] ket[2 + n]) > > I can collect the various terms in ket[n+i] with the following > operation: > > In[176]:= > Out[164]//Expand// Table[ket[n+i] Coefficient[#,ket[n+i] ],{i,-2,2}]& > //Plus @@ #& > > Out[176]= > -(Sqrt[-1 + n] Sqrt[n] ket[-2 + n]) + (1 + 2 n) ket[n] - > > Sqrt[1 + n] Sqrt[2 + n] ket[2 + n] > > My problem is this, Since I do no know what the range of ket[n+i] will > be, I would like to write a general expression that will find what > ket[n+i] are present and collect the coefficients of each of these. The > inelegant wat is to run over a range of i's that will surely bracket > any ket[n+i] that I will possibly encounter, but that is distasteful. > I am using version 2.2 but will probably switch to 3.0 soon. > > Any other suggestions to that way I have done things are welcomed. If > possible, please copy me on email since I might otherwise miss posts to > the newsgroup. > > cannon@alpha.centenary.edu > > Thanks very much, > > ------------------------------------------------------------------------------ > Joel W. Cannon | (318)869-5160 Dept. of > Physics | (318)869-5026 FAX Centenary College of > Louisiana | P. O. Box 41188 | > Shreveport, LA 71134-1188 | > >