# Scalar product operator of complex vectors

What is the scalar product operator for complex vectors (or matrices) in Mathematica? The usual $Dot[]$ doesn't work. E.g. here is what the Mathematica gives $$\{1,0\}.\{I,0\}=I$$ but the answer should be $-I$, since the scalar product of complex vectors is defined as follows: let $$a,b∈C^n \,\,\, then \,\,(a,b)= ∑_{i=1}^na_i \bar b_i$$ where $\bar b_i$ is the complex conjugate of $b_i$.

-

You can define your own scalar product as

Scalar[a_, b_] := Dot[a, Conjugate[b]]


so that Scalar[{1,0},{I,0}] = -I. The issue is that vectors and dual vectors in Mathematica are written the same way---they are both lists---so the system has no way to keep track of whether you are passing it b or Conjugate[b], for example. Thus Mathematica does the least surprising thing, which is to assume Dot[a,b]==Dot[b,a], and not Dot[a,b]==Conjugate[Dot[b,a]].

Edit: if you need the canonical scalar matrix product, you can use these definitions instead:

Scalar[a_, b_] :=  Dot[a, Conjugate[b]] /; Length[Dimensions[a]] == Length[Dimensions[b]] == 1
Scalar[a_, b_] :=  Tr[Dot[a, ConjugateTranspose[b]]] /; And[
Length[Dimensions[a]] == Length[Dimensions[b]] == 2,
Dimensions[b] == Dimensions[a]
]


so that the example above still holds, but you can, for example, do

Outer[Scalar, PauliMatrix /@ Range[0, 3], PauliMatrix /@ Range[0, 3],1]


which gives 2 IdentityMatrix[4] as expected.

-
You can, of course, invent your own mathematics. With Mathematica it's also easy to overload the Plus-operator to get any desired result (like 1 + 1 = 3). – eldo Jun 18 '14 at 18:17
@eldo I don't know if a link to Wikipedia is good enough, but please know that the dot product on complex vectors can be so defined. en.wikipedia.org/wiki/Dot_product#Complex_vectors – evanb Jun 18 '14 at 18:20
And I don't understand the downvote, either. – evanb Jun 18 '14 at 18:21
Note that the definition there reduces to the familiar definition if a and b are real. When someone says they have a complex number, they typically mean that they have a number that lives in the complex plane. That number might accidentally be real, in which case the complex conjugate doesn't do anything. But for not-accidentally-real complex numbers, the conjugate matters. – evanb Jun 18 '14 at 18:34
the downvote was because of the slightly arrogant "People are simply talking past one another in the other answers." Now you know the reason and I upvote again :) – eldo Jun 18 '14 at 18:34

That is how you do a dot product in Mathematica.You have the wrong symbol but in this case Mathematica still gave you correct answer:

{1,0}.{I,0}=1*I+0*0=I

-
your answer works in this simple case, but it is not the definition of the dot product for complex vectors. – eldo Jun 18 '14 at 17:39