MathGroup Archive 1998

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

Search the Archive

Re: Efficient use of coefficient--Efficient simplification


  • To: mathgroup@smc.vnet.net
  • Subject: [mg11250] Re: Efficient use of coefficient--Efficient simplification
  • From: Paul Abbott <paul@physics.uwa.edu.au>
  • Date: Wed, 4 Mar 1998 01:39:12 -0500
  • Organization: University of Western Australia
  • References: <6d0c3l$2mt@smc.vnet.net>

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.

In Version 3.0 Collect has been modified to work with patterns:

In[1]:= -(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]);

E.g.,

In[2]:= Collect[%,ket(_),Factor]
Out[2]=
-Sqrt[n - 1] Sqrt[n] ket[n - 2] + (2 n + 1) ket[n] - 
 
  Sqrt[n + 1] Sqrt[n + 2] ket[n + 2]

Cheers,
	Paul 

____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907       
mailto:paul@physics.uwa.edu.au  AUSTRALIA                            
http://www.pd.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________



  • Prev by Date: Re: combine two vectors to form matrix
  • Next by Date: Re: Change viewpoints in real time
  • Prev by thread: Re: Efficient use of coefficient--Efficient simplification
  • Next by thread: Mathematica graphics to AutoCad?