Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12280 > unrolled thread

Non Commutative Multiply

Started byRodrigo AP <digorna@gmail.com>
First post2012-11-08 07:14 +0000
Last post2012-11-09 00:02 +0000
Articles 6 — 6 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Non Commutative Multiply Rodrigo AP <digorna@gmail.com> - 2012-11-08 07:14 +0000
    Re: Non Commutative Multiply Ray Koopman <koopman@sfu.ca> - 2012-11-09 00:00 +0000
    Re: Non Commutative Multiply mstankus@gmail.com - 2012-11-09 00:01 +0000
    Re: Non Commutative Multiply Roland Franzius <roland.franzius@uos.de> - 2012-11-09 00:01 +0000
    Re: Non Commutative Multiply David Bailey <dave@removedbailey.co.uk> - 2012-11-09 00:01 +0000
    Re: Non Commutative Multiply daniel.lichtblau0@gmail.com - 2012-11-09 00:02 +0000

#12280 — Non Commutative Multiply

FromRodrigo AP <digorna@gmail.com>
Date2012-11-08 07:14 +0000
SubjectNon Commutative Multiply
Message-ID<k7fm4l$jko$1@smc.vnet.net>
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

[toc] | [next] | [standalone]


#12281

FromRay Koopman <koopman@sfu.ca>
Date2012-11-09 00:00 +0000
Message-ID<k7hh2k$nud$1@smc.vnet.net>
In reply to#12280
On Nov 7, 11:16 pm, Rodrigo AP <digo...@gmail.com> 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

Inner[NonCommutativeMultiply,A,B,Plus]

{{e ** a + f ** c, e ** b + f ** d},
 {g ** a + h ** c, g ** b + h ** d}}

[toc] | [prev] | [next] | [standalone]


#12286

Frommstankus@gmail.com
Date2012-11-09 00:01 +0000
Message-ID<k7hh47$nvb$1@smc.vnet.net>
In reply to#12280
On Wednesday, November 7, 2012 11:16:35 PM UTC-8, digo 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

You can use NCAlgebrq. See http://www.math.ucsd.edu/~ncalg/

Mark Stankus

[toc] | [prev] | [next] | [standalone]


#12287

FromRoland Franzius <roland.franzius@uos.de>
Date2012-11-09 00:01 +0000
Message-ID<k7hh4i$nvd$1@smc.vnet.net>
In reply to#12280
Am 08.11.2012 08:14, schrieb Rodrigo AP:
> 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?


Changing fundamental operators like Times is not a solution. It will 
cause a breakdown of the algebra machine.

Use operator  Inner  and

a multiplicative oprator symbol from

http://reference.wolfram.com/mathematica/tutorial/OperatorsWithoutBuiltInMeanings.html

like

CircleTimes, SmallCircle.


SmallCircle[A_?MatrixQ, B_?MatrixQ]:=Inner[SmallCircle[#1,#2]&,A,B,Plus]
SmallCircle[A_,B_, C___]:=SmallCircle[SmallCircle[A,B], C]

Now you can enrich procedures like Simplify, Factor and Expand by the 
typical set of rules for the linear expressions with head Plus und Times, eg

Unprotect[Simplify]

Simplify[expression_]:=
expression//.
{SmallCircle[a___,b_?NumericQ,c___]:>b*SmallCircle[a,c],
  SmallCircle[a___,b_+c__,d___]:> SmallCircle[a,b,d]+SmallCircle[a,c,d],
SmallCircle[a___,b_?NumericQ c__:1,d___]:>b*SmallCircle[a,b,d]}


Probably it is better to give the class of noncommutative objects an 
identity by naming them explicitely in a logical statement as


operators = {P,Q, d_Q, d_P}

(OperatorQ[#]=True&)/@operators

or

OperatorQ[x_]:= MemberQ	[ operators, x]

and formulate the rules in such a way that only products and powers of 
operators remain inside the noncommutative operator product.

This makes it easier to extract the typical scalar functions, starting 
with Power and in principle has to be applied to the body of all special 
complex functions.

-- 

Roland Franzius

[toc] | [prev] | [next] | [standalone]


#12289

FromDavid Bailey <dave@removedbailey.co.uk>
Date2012-11-09 00:01 +0000
Message-ID<k7hh56$nvm$1@smc.vnet.net>
In reply to#12280
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

[toc] | [prev] | [next] | [standalone]


#12294

Fromdaniel.lichtblau0@gmail.com
Date2012-11-09 00:02 +0000
Message-ID<k7hh6q$o0l$1@smc.vnet.net>
In reply to#12280
On Thursday, November 8, 2012 1:16:35 AM UTC-6, digo 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

Could use NonCommutativeMultiply inside Inner.

In[430]:= aA = {{e, f}, {g, h}};
bB = {{a, b}, {c, d}};

In[434]:= Inner[NonCommutativeMultiply, aA, bB, Plus]

Out[434]= {{e ** a + f ** c, e ** b + f ** d}, {g ** a + h ** c, 
  g ** b + h ** d}}

Daniel Lichtblau
Wolfram Research

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web