MathGroup Archive 2012

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

Search the Archive

Re: Non Commutative Multiply

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128609] Re: Non Commutative Multiply
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Thu, 8 Nov 2012 19:02:30 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <k7fm4l$jko$1@smc.vnet.net>

On 08/11/2012 07:14, Rodrigo AP wrote:
> Dear group,
>
> I want to multiply two matrices, for example,
>
> A = {{e, f}, {g, h}}
> B = {{a, b}, {c, d}}
>
> Using A.B, Mathematica returns
>
> {{a e + b g, a f + b h}, {c e + d g, c f + d h}}
>
> I would like to get, however, the following result:
>
> {{e a + f c, e b + f d}, {g a + h c, g b + h d}}
>
> since, for me, the entries {a,b,c,d,e,f,g,h} are operators, i.e., they
> are non-commutative.
>
> I could solve this problem clearing the attribute "Orderless" in the
> built-in function Times:
>
> ClearAttributes[Times, Orderless]
>
> I know, however, this can be dangerous. I tried to define a function
> Times2[a_,b_]:=Times[a,b]
> and then use ClearAttributes[Times2, Orderless] but it doesn't work.
>
> How could I solve this problem?
>
> Thanks in advance
>
> Rodrigo
>
>
First, avoid using names that start with capital letters - unless 
perhaps they are long names not likely to get used within Mathematica, 
such as MyHorses (or indeed probably anything of the form My....)!

To represent non commutative multiplications, you really have to use 
another operator which doesn't have the Orderless attribute. Times is 
built too far down in Mathematica, to make it useful to change its 
properties.

m1 = {{e, f}, {g, h}}
m2 = {{a, b}, {c, d}}

In[5]:= Inner[CircleTimes,m1,m2,Plus]

Out[5]= {{e\[CircleTimes]a + f\[CircleTimes]c,
   e\[CircleTimes]b + f\[CircleTimes]d}, {g\[CircleTimes]a +
    h\[CircleTimes]c, g\[CircleTimes]b + h\[CircleTimes]d}}

(Note that \[CircleTimes] will display nicely inside Mathematica).


Since only you are using CircleTimes, you can sensibly change its 
attributes, for example by giving the operator associativity with the 
Flat attribute.

David Bailey
http://www.dbaileyconsultancy.co.uk




  • Prev by Date: Re: Help with map /@
  • Next by Date: Re: Error Code: 616
  • Previous by thread: Re: Non Commutative Multiply
  • Next by thread: Re: Non Commutative Multiply