MathGroup Archive 1997

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7749] Re: [mg7658] nested * and ** (rules for commutative quantities)
  • From: "C. Woll" <carlw at u.washington.edu>
  • Date: Mon, 7 Jul 1997 04:41:21 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

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.

Unprotect[NonCommutativeMultiply];
Clear[NonCommutativeMultiply];
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)
Protect[NonCommutativeMultiply];

With this definition,

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

produces

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)