MathGroup Archive 1997

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

Search the Archive

Re: nested * and ** (rules for commutative quantities)

On Thu, 26 Jun 1997, Marlies Brinksma wrote:

> ...
> I have a set of operators (let's call them Op[index_,arg2_]).
> Two of these operators commute when their indices are different and they are 
> noncommutative otherwise. All operators commute with any scalar quantity.
> I would like to define some rules such that expressions like:
> Op[3,a] ** Op[2,v] ** 4 ** Op[6,s] ** Op[2,x] ** Op[1,t]
> will be automatically changed to:
> Times[4, Op[1,t],NonCommutativeMultiply[Op[2,v],Op[2,x]],Op[3,a],Op[6,s]]
> ...

Hi Marlies,

I'm not sure of all the rules that you want to impose, since you don't
explain why Op[1,t] is not within NonCommutativeMultiply. Also, you don't
mention what kinds of objects other than numbers might occur in addition
to your Op functions. At any rate, here is a short definition which might
do what you want.

Op[n_,a_]**Op[m_,b_]:=Op[m,b]**Op[n,a] /; n>m
Op[n_,a_]**b_?NumberQ:=b Op[n,a]
a_**(b_?NumberQ c_):=b (a**c)
(b_?NumberQ c_)**d_:=b (c**d)

With this definition,

Op[3,a] ** Op[2,v] ** 4 ** Op[6,s] ** Op[2,x] ** Op[1,t]


4 Op[1,t]**Op[2,v]**Op[2,x]**Op[3,a]**Op[6,s]

Instead of NumberQ, you can use a more complex condition if you have other
objects besides numbers and Op functions. For example, if Op[1,_] objects
commute with each other, then you could add the definitions

Op[1,b_]**Op[n_,a]:=Op[1,b] Op[n,a]
a_**(Op[1,b_] c_):=Op[1,b] (a**c)
(Op[1,b_] c_)**d_:=Op[1,b] (c**d)

Is this what you're looking for?

Carl Woll

  • Prev by Date: Bug in FullSimplify[] confirmed by Wolfram Research
  • Next by Date: 2-D Graphics Options
  • Previous by thread: Re: nested * and ** (rules for commutative quantities)
  • Next by thread: Re: nested * and ** (rules for commutative quantities)