       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= (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 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:=
scalar[n_?NumericQ]:=True

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

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

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

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

In:=
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:=
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:=
makeScalar[a,b,c]

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

In:=
f.g.f//.ncrules//InputForm

Out//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[..]