Possible Duplicate:
Non-commutative symbolic linear algebra
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
Inner[]
andNonCommutativeMultiply[]
. $\endgroup$ – J. M. will be back soon♦ Nov 7 '12 at 13:01Inner[NonCommutativeMultiply, A, B]
$\endgroup$ – chris Nov 7 '12 at 13:13Times2[a_,b_]:=Times[a,b]
doesn't work when as you expect whenTimes2
is not orderless, is that it only affects the left hand side. You are just passing onwards toTimes
which is still orderless. $\endgroup$ – jVincent Nov 7 '12 at 13:14Times
when applied to specific expressions, without having to remove it. $\endgroup$ – jVincent Nov 7 '12 at 13:33Unprotect[Times];ClearAttributes[Times, Orderless];Protect[Times]; A.B
Though it is typically ill advised to mess with the behaviour of low level functions like Times $\endgroup$ – chris Nov 7 '12 at 14:21