Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

Re: Working with Dot[..] or NonCommutativeMultiply[..]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6388] Re: Working with Dot[..] or NonCommutativeMultiply[..]
  • From: Dick Zacher <dick at loc3.tandem.com>
  • Date: Sat, 15 Mar 1997 01:21:27 -0500 (EST)
  • Organization: Tandem Computers
  • Sender: owner-wri-mathgroup at wolfram.com

Sergio Rojas wrote:
> 
> Hello guys,
> 
>    Given:
> 
> f = a*x1 + b*x2 ;
> g = c*y1 ;
> 
>   where x1, x2, and y1 have non commutative product. The mathematica
>   output for:
> 
> Distribute[Dot[f,g,f]] (* Distribute[NonCommutativeMultiply[f,g,f]] *)
>                         is:
> 
> Out[79]= (a x1) . (c y1) . (a x1) + (a x1) . (c y1) . (b x2) +
> 
> >    (b x2) . (c y1) . (a x1) + (b x2) . (c y1) . (b x2)
> 
>           How, using mathematica, Out[79] can be written in the form:
> 
> a^2*c*(x1.y1.x1) + a*b*c*((x1.y1.x2) + (x2.y1.x1)) + b^2*c(x2.y1.x2)
> 
> Regards,
> 
> Sergio
> 
> e-mail: sergio at scisun.sci.ccny.cuny.edu

Probably there are much more elegant ways than this, but--
First, you could distinguish commuting, or scalar, quantities:

In[1]:=
scalar[n_?NumericQ]:=True

In[2]:=
scalar[x_*y_]:=scalar[x]&&scalar[y]

In[3]:=
scalar[x_+y_]:=scalar[x]&&scalar[y]

In[4]:=
scalar[x_^y_]:=scalar[x]/;scalar[y]

And you could provide a way of defining quantities to be scalars:

In[5]:=
makeScalar[vars__]:=((scalar[#]^=True)&/@{vars};)

Then you could define some rules for non-commuting multiplication
(though you might prefer to use ** rather than Dot):

In[6]:=
ncrules={ x_ .(y_+z_):>x.y+x.z,
          (x_+y_).z_:>x.z+y.z,
          c_ .x_:>c*x/;scalar[c],
          x_ .(c_*y_):>c*(x.y)/;scalar[c],
          (c_*x_).y_:>c*(x.y)/;scalar[c] };
 
Then indicate which quantities are scalar and do the computation:

In[7]:=
makeScalar[a,b,c]

In[8]:=
f = a*x1 + b*x2 ;
g = c*y1 ;

In[9]:=
f.g.f//.ncrules//InputForm

Out[9]//InputForm=
a^2*c*x1 . y1 . x1 + a*b*c*x1 . y1 . x2 + 
  a*b*c*x2 . y1 . x1 + b^2*c*x2 . y1 . x2

The terms aren't collected in just the way you wanted, but you get the
idea.
-- 
-----------------------------
Dick Zacher                    
Performance Engineering Dept., Tandem Computers
zacher_dick at tandem.com     phone: 408-285-5746     fax:   408-285-7079


  • Prev by Date: Why does TimeUsed die?
  • Next by Date: system of equations
  • Previous by thread: Working with Dot[..] or NonCommutativeMultiply[..]
  • Next by thread: Re: Working with Dot[..] or NonCommutativeMultiply[..]