5
$\begingroup$

If yy and zz are 2x2 Hermitian matrices, is there a way that I can mark them (with a property?) as Hermitian so that Mathematica can assume that it can factor out and simplify scalar multipliers from a dot product expression? In this example, we have -1 * -1 as the multiplier:

ClearAll[a, yy, zz]
a = -(-yy.zz).zz
FullForm[a]

This gives:

-(-yy.zz).zz
Times[-1,Dot[Times[-1,Dot[yy,zz]],zz]]

Can it be made to simplify to just:

yy.zz.zz
$\endgroup$
  • $\begingroup$ Dave, just a gentle reminder that, if one of the answers provided below solve your problem, you might want to accept it by clicking on the gray check mark next to it. $\endgroup$ – MarcoB Jul 27 '15 at 19:44
5
$\begingroup$

To factor out numeric factors in any argument of Dot:

(2 yy.(3 zz)).(4 zz) //. Dot[a___, d_?NumericQ b_, c___] :> d Dot[a, b, c]

24 yy.zz.zz


Edit: If you want this to happen automatically, you can add the rule as a new definition for Dot:

Unprotect[Dot];
Dot[a___, d_?NumericQ b_, c___] := d Dot[a, b, c]
Protect[Dot];

Now the factoring happens by itself:

(2 yy.(3 zz)).(4 zz)

24 yy.zz.zz

$\endgroup$
  • $\begingroup$ Thanks; this is a nice and straightforward replacement that will do the job. I must say, though, that I was hoping that Mathematica could just "figure it out". $\endgroup$ – David B Jul 27 '15 at 20:28
  • $\begingroup$ @daveboden You can make it automatic, if you like -- see the edit. $\endgroup$ – Simon Rochester Jul 27 '15 at 21:21
3
$\begingroup$

Is the following sufficiently general?

t[e_] := e /. Dot[Times[z1_ /;!ArrayQ[z1], Dot[z2__]], z3__] :> z1 Dot[z2, z3]    
Simplify[a, TransformationFunctions -> {Automatic, t}]
(* yy.zz.zz *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.