A matrix-vector cross product

I want to do a cross product involving a vector of Pauli matrices $\vec \sigma = \left( {{\sigma _1},{\sigma _2},{\sigma _3}} \right)$; for example, $\vec \sigma \times \left( {1,2,3} \right)$.

s:= Table[PauliMatrix[i], {i, 1, 3}];
Cross[s,{1,2,3}]


The code above will not work.

The only way I can think of is to use the method which I have just learned from Mr. Wizard:

ReleaseHold @ Block[{PauliMatrix}, Hold @@ {Cross[s,{1, 2, 3}]}]


But I feel uncomfortable writing such long code to realize such a simple cross product.

Is there any better way or not?

Update J.M. give the method

Cross[Unevaluated /@ PauliMatrix[Range[3]], {a,b,c}]


But it turns out that when one of the a,b,c is zero, the code will give error. a Remedy is given by J.M in his comment.

But I am asking here why it gives right answer when a b c are all nonzero while failed with a zero component?

-
add comment

4 Answers

Taking a page from kptnw's fine answer, here's one possibility:

Cross[Unevaluated /@ PauliMatrix[Range[3]], Range[3]]

-
I finally choose your answer. easier and won't have to worry about the order and negtive sign when using LeviCivitaTensor –  matheorem May 5 at 8:09
OhOh, Sorry J.M. I found peculier things. Your solution is flawed. Try Cross[Unevaluated/@PauliMatrix[Range[3]],{0,1,0}] –  matheorem May 5 at 8:55
Yes, I see what you mean. In that case, Cross[Unevaluated /@ PauliMatrix[Range[3]], {\[FormalP], \[FormalQ], \[FormalR]}] /. Thread[{\[FormalP], \[FormalQ], \[FormalR]} -> {0, 1, 0}] –  Ｊ. Ｍ. May 5 at 11:37
Ok, rule replacement works. But I still don't know where does it gone wrong? I looked into the Trace result, but it is unexpectedly long! I can't figure out why. –  matheorem May 5 at 12:23
FWIW the referenced question is a duplicate. –  Mr.Wizard Jun 5 at 6:21
show 1 more comment

Another idea to shorten the notation for the cross product in the special case where you have a Pauli matrix vector as the first argument is this:

ClearAll[OverVector];
OverVector /: Cross[OverVector[σ], x_?VectorQ] :=
x.LeviCivitaTensor[3].PauliMatrix[Range[3]]

Cross[OverVector[σ], {x, y, z}]

(*
==> {{{-y, -I z}, {I z, y}}, {{x, -z}, {-z, -x}}, {{0,
I x + y}, {-I x + y, 0}}}
*)


You can also literally enter $\vec{\sigma}$ instead of OverVector[σ].

If you want to make the definition of the cross product more visible in your notation, you could also introduce the LeviCivitaTensor in the form of an abbreviation $\varepsilon$ and use it instead of Cross directly:

ε = LeviCivitaTensor[3];

OverVector[σ] = PauliMatrix[Range[3]];

{x, y, z}.ε.OverVector[σ]

(*
==> {{{-y, -I z}, {I z, y}}, {{x, -z}, {-z, -x}}, {{0,
I x + y}, {-I x + y, 0}}}
*)


I've defined an abbreviation for the vector of Pauli matrices here. Because of this, the two approaches (this one and the first alternative) don't mix - so one should settle on or the other.

Edit in response to updated question

The Unevaluated trick in J.M.'s answer works without error in version 8 (that's where I tested it first, and upvoted that method initially). But it produces divide-by-zero errors in version 9. This seems like a bug to me because there are no documented changes in Cross or Unevaluated in recent versions. My LeviCivitaTensor approach works in all versions.

-
For people like me who've forgotten their identities: {p, q, r}.LeviCivitaTensor[3].{u, v, w} === Cross[{u, v, w}, {p, q, r}]. Note the order! –  Ｊ. Ｍ. May 4 at 17:36
@J.M. BTW, a related answer where I used this is: Is it possible to do vector calculus in Mathematica?. Hope you don't get into an identity crisis... –  Jens May 4 at 17:41
add comment

Directly define a cross function should be the easiest.

cross3[{x_, y_, z_}, {a_, b_, c_}] := {c y - b z, -c x + a z, b x - a y}


then no matter

cross3[PauliMatrix[Range[3]],{1,2,3}]


or

cross3[{1,2,3},PauliMatrix[Range[3]]]


will be OK. No ordering problem in Jens' LeviCivitaTensor method.

-
add comment

Since I'm being credited with the method (which I do appreciate), let me point out that your use of Block is being needlessly complicated with Hold and ReleaseHold. The same behavior can be had with:

Block[{PauliMatrix}, Cross[s, {1, 2, 3}]]

{{{-2, -3 I}, {3 I, 2}}, {{1, -3}, {-3, -1}}, {{0, 2 + I}, {2 - I, 0}}}


We can make the Unevaluated method, similar to what I showed here and what J. M. posted above, work even with vectors containing zero by applying it to all elements. I would write it thus:

heldCross[vec__] := Cross @@ Map[Unevaluated, {vec}, {2}]


Now:

heldCross[PauliMatrix @ Range @ 3, {1, 2, 3}]

{{{-2, -3 I}, {3 I, 2}}, {{1, -3}, {-3, -1}}, {{0, 2 + I}, {2 - I, 0}}}

heldCross[PauliMatrix @ Range @ 3, {0, 1, 2}]

{{{-1, -2 I}, {2 I, 1}}, {{0, -2}, {-2, 0}}, {{0, 1}, {1, 0}}}

-
Happy to see you! Thank you very much! you're right, I realized how stupid I am at that time. But this method only works in the situation when s is setdeleyed as Table[PauliMatrix[i],{3}], it will not gonna work if s is not setdeleyed or PauliMatix[Range[3]]. So let me just stick with my answer below, it is quite straightforward which makes it seems a little "silly", but to my experience, it is quite robust. –  matheorem Jun 5 at 5:59
@matheorem Hardly stupid; a mere mistake. :-) Normally I would have recommended Unevaluated as J. M. did, but I see that method breaks with zeros. I am looking into that now. (The Trace` is indeed long.) –  Mr.Wizard Jun 5 at 6:11
Awesome. But can you explain why J.M.'s solution is flawed when there is zero. By the way, J.M. changed his name to 0x4A4D??!!! –  matheorem Jun 5 at 7:52
@matheorem I didn't see anything obvious and I didn't feel like working on it right now. Yes, he did; I guess he's feeling pallid. –  Mr.Wizard Jun 5 at 8:00
So it is a chinese character. Wow, that's interesting. I know a lot of chinese characters, actually I am a chinese. But I can bet, this character is not known by 99.99% chinese people. –  matheorem Jun 5 at 8:16
add comment