[PYTHON] Complex vector considered as a real vector

As a starting point for complex vectors, we will investigate the correspondence with real vectors. A calculation by SymPy is attached.

It deals with the following contents.

This is the knowledge required for quantum computers and complex neural networks.

This is a series of articles.

  1. Complex vector considered as a real vector ← This article
  2. Bicomplex numbers considered by representation matrix
  3. Quaternion considered by representation matrix
  4. Pauli matrices and biquaternions in Clifford algebra

This article has related articles.

Real vector and complex number

The inner product of a two-dimensional real vector is calculated as follows. (For details, see Previous article)

>>> from sympy import *
>>> a1,a2,b1,b2=symbols("a1:3 b1:3",real=True)
>>> Matrix([a1,a2]).dot(Matrix([b1,b2]))
a1*b1 + a2*b2
>>> Matrix([a1,a2]).T * Matrix([b1,b2])
Matrix([[a1*b1 + a2*b2]])
>>> Matrix([[a1,a2]]) * Matrix([b1,b2])
Matrix([[a1*b1 + a2*b2]])
\begin{align}
\left(\begin{matrix}a_1 \\ a_2\end{matrix}\right)\cdot
\left(\begin{matrix}b_1 \\ b_2\end{matrix}\right)
&=\left(\begin{matrix}a_1 \\ a_2\end{matrix}\right)^{\top}
  \left(\begin{matrix}b_1 \\ b_2\end{matrix}\right) \\
&=\left(\begin{matrix}a_1 &  a_2\end{matrix}\right)
  \left(\begin{matrix}b_1 \\ b_2\end{matrix}\right) \\
&=a_1b_1+a_2b_2
\end{align}

Calculate a simple example.

>>> Matrix([1,2]).dot(Matrix([3,4]))
11
>>> Matrix([1,2]).T*Matrix([3,4])
Matrix([[11]])
\left(\begin{matrix}1 \\ 2\end{matrix}\right)\cdot
\left(\begin{matrix}3 \\ 4\end{matrix}\right)
=\left(\begin{matrix}1 \\ 2\end{matrix}\right)^{\top}
 \left(\begin{matrix}3 \\ 4\end{matrix}\right)
=11

Complex number

Consider calculating the dot product of real vectors as a complex number.

Complex numbers are made up of two real numbers, so a two-dimensional real vector is associated with a complex number.

\left(\begin{matrix}a \\ b\end{matrix}\right) \mapsto a+bi

The product of complex numbers is calculated as follows. In SymPy, the imaginary number is ʻI`.

>>> expand((a1+a2*I)*(b1+b2*I)).collect(I)
a1*b1 - a2*b2 + I*(a1*b2 + a2*b1)
(a_1+a_2i)(b_1+b_2i)=(a_1b_1-a_2b_2)+(a_1b_2+a_2b_1)i

Comparing this with the inner product $ a_1b_1 + a_2b_2 $ of the real vector, we find that:

If one of the complex numbers is conjugate, the real part of the product is the inner product and the imaginary part is the outer product. The sign of the outer product changes depending on which is conjugate (anticommutative).

>>> expand((a1+a2*I).conjugate()*(b1+b2*I)).collect(I)
a1*b1 + a2*b2 + I*(a1*b2 - a2*b1)
>>> expand((a1+a2*I)*(b1+b2*I).conjugate()).collect(I)
a1*b1 + a2*b2 + I*(-a1*b2 + a2*b1)
\begin{align}
\underbrace{(a_1+a_2i)^*}_{Conjugated}(b_1+b_2i)&=(\underbrace{a_1b_1+a_2b_2}_{inner product})+(\underbrace{a_1b_2-a_2b_1}_{Cross product})i \tag{1}\\
(a_1+a_2i)\underbrace{(b_1+b_2i)^*}_{Conjugated}&=(a_1b_1+a_2b_2)\underbrace{-(a_1b_2-a_2b_1)}_{Sign inversion}i \tag{2}
\end{align}

(1) is the standard when finding the inner product and outer product with complex numbers. We will discuss the details later, but transpose in matrix calculation and complex conjugate correspond.

(a_1\mathbf{e}_1+a_2\mathbf{e}_2)(b_1\mathbf{e}_1+b_2\mathbf{e}_2)=(a_1b_1+a_2b_2)+(a_1b_2-a_2b_1)\mathbf{e}_1\mathbf{e}_2

This time, only the inner product value is required, so the outer product (imaginary part) is ignored.

>>> Matrix([a1,a2]).row_join(Matrix([b1,b2]))
Matrix([
[a1, b1],
[a2, b2]])
>>> Matrix([a1,a2]).row_join(Matrix([b1,b2])).det()
a1*b2 - a2*b1
\det\left(\begin{array}{c|c}a_1 & b_1 \\ a_2 & b_2\end{array}\right)=a_1b_2-a_2b_1

Compute a simple example with SymPy and Python built-in features. In the latter, the complex number is j, the conjugate is.conjugate (), and the real part is .real.

SymPy


>>> re(expand(((1+2*I).conjugate()*(3+4*I))))
11

Built-in


>>> ((1+2j).conjugate()*(3+4j)).real
11.0
\Re\{(1+2i)^*(3+4i)\}=11

I was able to calculate the same as the inner product of real vectors. If you look side by side, you can see that the complex conjugate ($ ^ * ) works in the same way as the transpose ( ^ {\ top} $).

>>> Matrix([1,2]).T*Matrix([3,4])
Matrix([[11]])
>>> expand((1+2*I).conjugate()*(3+4*I))
11 - 2*I
>>> (1+2j).conjugate()*(3+4j)
(11-2j)
\left(\begin{matrix}1 \\ 2\end{matrix}\right)^{\top}
\left(\begin{matrix}3 \\ 4\end{matrix}\right)
=11 \\
(1+2i)^*(3+4i)=11-2i
>>> Matrix([1,2]).row_join(Matrix([3,4])).det()
-2
\det\left(\begin{array}{c|c}1 & 3 \\ 2 & 4\end{array}\right)=4-6=-2

Representation matrix

Consider why complex conjugates correspond to transpose.

The complex number is represented by a two-dimensional real vector, and the inner product is compared with the calculation result.

>>> (a1+a2*I).conjugate()*(b1+b2*I)
(a1 - I*a2)*(b1 + I*b2)
>>> expand((a1+a2*I).conjugate()*(b1+b2*I)).collect(I)
a1*b1 + a2*b2 + I*(a1*b2 - a2*b1)
>>> Matrix([a1,a2]).T*Matrix([b1,b2])
Matrix([[a1*b1 + a2*b2]])
\begin{align}
(a_1+a_2i)^*(b_1+b_2i)
&=(a_1-a_2i)(b_1+b_2i) \\
&=(a_1b_1+a_2b_2)+(a_1b_2-a_2b_1)i \\
\left(\begin{matrix}a_1 \\ a_2\end{matrix}\right)^{\top}
\left(\begin{matrix}b_1 \\ b_2\end{matrix}\right)
&=a_1b_1+a_2b_2
\end{align}

The inner product of a real vector does not include the imaginary part (although it is natural to say that the imaginary part is the outer product). Try increasing the number of columns to include the imaginary part.

Imaginary unit

First consider the imaginary unit $ i $. The incremented column is unknown $ x, y $.

>>> x,y=symbols("x y")
>>> i=Matrix([0,1]).row_join(Matrix([x,y]))
>>> i
Matrix([
[0, x],
[1, y]])
i \mapsto
\left(\begin{matrix}0 \\ 1 \end{matrix}\right)
\xrightarrow{Add more columns}
\left(\begin{matrix}0 & x \\ 1 & y\end{matrix}\right)

Determine $ x, y $ so that $ i ^ 2 = -1 $. The second column after square is determined automatically, so the calculation is omitted.

>>> i**2
Matrix([
[x,      x*y],
[y, x + y**2]])
i^2 \mapsto
\left(\begin{matrix}0 & x \\ 1 & y\end{matrix}\right)^2
=\left(\begin{matrix}x & * \\ y & *\end{matrix}\right)
=\left(\begin{matrix}-1 & * \\0 & *\end{matrix}\right) \\
∴(x,y)=(-1,0)

Now we have a quadratic square matrix corresponding to $ i $ that satisfies $ i ^ 2 = -1 $. This is called the ** representation matrix ** of $ i $.

>>> i=Matrix([[0,-1],[1,0]])
i \mapsto \left(\begin{matrix}0 & -1 \\ 1 & 0\end{matrix}\right)
i \mapsto
\left(\begin{array}{c|c}
\underbrace{\begin{matrix} 0 \\ 1 \end{matrix}}_{i} &
\underbrace{\begin{matrix}-1 \\ 0 \end{matrix}}_{-1}
\end{array}\right)

Complex number

The $ 1 $ representation matrix is an identity matrix because it is an identity element whose value does not change when multiplied.

>>> _1=eye(2)
>>> _1
Matrix([
[1, 0],
[0, 1]])
1 \mapsto
I=\left(\begin{matrix}1 & 0 \\ 0 & 1\end{matrix}\right)

Combining the representation matrices of $ 1 $ and $ i $ gives a complex representation matrix.

>>> a,b=symbols("a b",real=True)
>>> a*_1+b*i
Matrix([
[a, -b],
[b,  a]])
a+bi \mapsto
 a\underbrace{\left(\begin{matrix}1 &  0 \\ 0 & 1\end{matrix}\right)}_{1}
+b\underbrace{\left(\begin{matrix}0 & -1 \\ 1 & 0\end{matrix}\right)}_{i}
=\left(\begin{matrix}a & -b \\ b & a\end{matrix}\right)

The summary is as follows.

a+bi \mapsto
\left(\begin{matrix}a \\ b \end{matrix}\right)
\xrightarrow{Add more columns}
\left(\begin{matrix}a & -b \\ b & a\end{matrix}\right)
>>> Matrix([[a,-b],[b,a]]).det()
a**2 + b**2
>>> Matrix([a,b]).T*Matrix([a,b])
Matrix([[a**2 + b**2]])
>>> abs(a+b*I)**2
a**2 + b**2
\det\left(\begin{array}{c|c}a & -b \\ b & a\end{array}\right)
=\left(\begin{matrix}a \\ b\end{matrix}\right)^{\top}
 \left(\begin{matrix}a \\ b\end{matrix}\right)
=a^2+b^2=|a+bi|^2

Verification

Let's calculate the product by replacing the complex number with the representation matrix.

>>> (a1+a2*I).conjugate()*(b1+b2*I)
(a1 - I*a2)*(b1 + I*b2)
>>> a1*_1-a2*i
Matrix([
[ a1, a2],
[-a2, a1]])
>>> b1*_1+b2*i
Matrix([
[b1, -b2],
[b2,  b1]])
>>> (a1*_1-a2*i)*(b1*_1+b2*i)
Matrix([
[a1*b1 + a2*b2, -a1*b2 + a2*b1],
[a1*b2 - a2*b1,  a1*b1 + a2*b2]])
>>> expand((a1+a2*I).conjugate()*(b1+b2*I)).collect(I)
a1*b1 + a2*b2 + I*(a1*b2 - a2*b1)
\begin{align}
(a_1+a_2i)^*(b_1+b_2i)
=&(a_1-a_2i)(b_1+b_2i) \\
\mapsto
&\left(\begin{matrix}a_1 &  a_2 \\ -a_2 & a_1\end{matrix}\right)
 \left(\begin{matrix}b_1 & -b_2 \\  b_2 & b_1\end{matrix}\right) \\
=&\left(\begin{matrix}
    a_1b_1+a_2b_2 & -(a_1b_2-a_2b_1) \\
    a_1b_2-a_2b_1 &   a_1b_1+a_2b_2
  \end{matrix}\right) \\
\mapsto
&(a_1b_1+a_2b_2)+(a_1b_2-a_2b_1)i
\end{align}

The result matched the calculation as it was a complex number. The behavior of complex numbers can be represented by ** matrices **.

Complex conjugate

If you transpose the representation matrix, the complex numbers represented will be conjugate. This is why transpose corresponds to conjugates in complex numbers.

>>> (a*_1+b*i).T
Matrix([
[ a, b],
[-b, a]])
\left(\begin{matrix}a & -b \\ b & a\end{matrix}\right)^{\top}
=\left(\begin{matrix}a & b \\ -b & a\end{matrix}\right)
\mapsto a-bi=(a+bi)^*

The calculation example confirmed earlier gives the same result even if the complex conjugate is replaced with transpose.

>>> (a1*_1+a2*i).T*(b1*_1+b2*i)
Matrix([
[a1*b1 + a2*b2, -a1*b2 + a2*b1],
[a1*b2 - a2*b1,  a1*b1 + a2*b2]])
\begin{align}
(a_1+a_2i)^*(b_1+b_2i)
\mapsto
&\left(\begin{matrix}a_1 & -a_2 \\ a_2 & a_1\end{matrix}\right)^{\top}
 \left(\begin{matrix}b_1 & -b_2 \\ b_2 & b_1\end{matrix}\right) \\
=&\left(\begin{matrix}
    a_1b_1+a_2b_2 & -(a_1b_2-a_2b_1) \\
    a_1b_2-a_2b_1 &   a_1b_1+a_2b_2
  \end{matrix}\right) \\
\end{align}

Real vector and complex vector

A 4-dimensional real vector is associated with a 2-dimensional complex vector, assuming that the imaginary part of the calculation result is ignored.

\left(\begin{matrix}a \\ b \\ c \\ d\end{matrix}\right) \mapsto
\left(\begin{matrix}a+bi \\ c+di\end{matrix}\right)

Check the vector containing the complex number in the component (complex vector) because it requires special attention for transposition.

Hermitian conjugate

Replace each complex number contained in the complex vector with a representation matrix.

\left(\begin{matrix}a+bi \\ \hline c+di\end{matrix}\right) \mapsto
\left(\begin{matrix}a & -b \\ b & a \\ \hline c & -d \\ d & c\end{matrix}\right)

If you transpose the representation matrix back to a complex number, you can see that the complex conjugate appears at the same time as the transpose.

\begin{align}
\left(\begin{matrix}a & -b \\ b & a \\ \hline c & -d \\ d & c\end{matrix}\right)^{\top}
=&\left(\begin{array}{cc|cc}a & b & c & d \\ -b & a & -d & c\end{array}\right) \\
\mapsto &\left(\begin{array}{c|c}a-bi & c-di\end{array}\right) \\
=&\left(\begin{array}{c|c}a+bi & c+di\end{array}\right)^* \\
=&\left\{\left(\begin{matrix}a+bi \\ \hline c+di\end{matrix}\right)^{\top}\right\}^*
\end{align}

In this way, in complex vectors and complex matrices, transpose and complex conjugate are linked. The matrix that takes both the transpose and the complex conjugate is the Elmeat conjugate ([Conjugate transpose](https://ja.wikipedia.org/wiki/%E9%9A%8F%E4%BC%B4%E8%A1%8C%] It is called E5% 88% 97)) and is represented by the dagger ($ ^ {\ dagger} $) in this article. In SymPy, the acronym for Hermite is .H (H is not pronounced in French). The result is the same even if the order of operations is reversed (conjugate → transpose).

>>> a,b,c,d=symbols("a b c d",real=True)
>>> Matrix([a+b*I,c+d*I]).H
Matrix([[a - I*b, c - I*d]])
>>> Matrix([a+b*I,c+d*I]).T.conjugate()
Matrix([[a - I*b, c - I*d]])
>>> Matrix([a+b*I,c+d*I]).conjugate().T
Matrix([[a - I*b, c - I*d]])
\left(\begin{matrix}a+bi \\ c+di\end{matrix}\right)^{\dagger}
:=\left\{\left(\begin{matrix}a+bi \\ c+di\end{matrix}\right)^{\top}\right\}^*
=\left\{\left(\begin{matrix}a+bi \\ c+di\end{matrix}\right)^*\right\}^{\top}
=\left(\begin{matrix}a-bi & c-di\end{matrix}\right)

Verification

A simple calculation confirms the transpose of the real vector and the Hermitian conjugate of the complex vector.

>>> Matrix([1,2,3,4]).T*Matrix([5,6,7,8])
Matrix([[70]])
>>> expand(Matrix([1+2j,3+4j]).H*Matrix([5+6j,7+8j]))
Matrix([[70.0 - 8.0*I]])
\left(\begin{matrix}1 \\ 2 \\ 3 \\ 4\end{matrix}\right)^{\top}
\left(\begin{matrix}5 \\ 6 \\ 7 \\ 8\end{matrix}\right)
=70 \\
\left(\begin{matrix}1+2i \\ 3+4i\end{matrix}\right)^{\dagger}
\left(\begin{matrix}5+6i \\ 7+8i\end{matrix}\right)
=70-8i

The same result was obtained by ignoring the imaginary part.

Quaternion / bicomplex number

A four-dimensional real vector is associated with a quaternion.

\left(\begin{matrix}a \\ b \\ c \\ d\end{matrix}\right) \mapsto a+bi+cj+dk

If you calculate the product with the conjugate, you get the inner product from the real part.

[Quaternion]\ (1-2i-3j-4k)(5+6i+7j+8k)=70-16j-8k

If you want to discard the imaginary part, you have the option of using bicomplex numbers instead of quaternions. Unlike quaternions, bicomplex numbers are commutative products, so they may be more convenient than quaternions for some applications (sometimes called commutative quaternions). Note that due to the structure of bicomplex numbers, the shape of the conjugate is different from that of quaternions.

[Bicomplex number]\ (1-2i-3j+4k)(5+6i+7j+8k)=70-8i-16j-4k

Here, quaternions and bicomplex numbers are only introduced, but details will be explained in the sequel article.

Execution columns and complex matrices

As we have seen, associating a real vector with a complex vector halves the number of rows. If you associate the execution column with a complex matrix, the number of rows will be halved as well.

Execution column (2 x 2)

Second-order real square matrices are associated with two-dimensional complex horizontal vectors (1x2 matrices).

\left(\begin{matrix}a & c \\ b & d\end{matrix}\right) \mapsto
\left(\begin{matrix}a+bi & c+di\end{matrix}\right)

A calculation example is shown below.

>>> Matrix([[1,3],[2,4]]).T*Matrix([[5,7],[6,8]])
Matrix([
[17, 23],
[39, 53]])
>>> expand(Matrix([[1+2j,3+4j]]).H*Matrix([[5+6j,7+8j]]))
Matrix([
[17.0 - 4.0*I, 23.0 - 6.0*I],
[39.0 - 2.0*I, 53.0 - 4.0*I]])
\left(\begin{matrix}1 & 3 \\ 2 & 4\end{matrix}\right)^{\top}
\left(\begin{matrix}5 & 7 \\ 6 & 8\end{matrix}\right)
=\left(\begin{matrix}17 & 23 \\ 39 & 53\end{matrix}\right) \\
\left(\begin{matrix}1+2i & 3+4i\end{matrix}\right)^{\dagger}
\left(\begin{matrix}5+6i & 7+8i\end{matrix}\right)
=\left(\begin{matrix}17-4i & 23-6i \\ 39-2i & 53-4i\end{matrix}\right)

The same result can be obtained by ignoring the imaginary part. Notice that the resulting matrix will be the same size as the execution column. Intuitively, it can be interpreted that two lines cannot be combined into one line because it contains an imaginary part.

Execution column (4 x 2)

A 4x2 execution column is associated with a quadratic complex square matrix.

\left(\begin{matrix}a & e \\ b & f \\ c & g \\ d & h\end{matrix}\right) \mapsto
\left(\begin{matrix}a+bi & e+fi \\ c+di & g+hi\end{matrix}\right)

A calculation example is shown below.

>>> Matrix([[1,5],[2,6],[3,7],[4,8]]).T*Matrix([[9,13],[10,14],[11,15],[12,16]])
Matrix([
[110, 150],
[278, 382]])
>>> expand(Matrix([[1+2j,5+6j],[3+4j,7+8j]]).H*Matrix([[9+10j,13+14j],[11+12j,15+16j]]))
Matrix([
[110.0 - 16.0*I, 150.0 - 24.0*I],
[ 278.0 - 8.0*I, 382.0 - 16.0*I]])
\left(\begin{matrix}1 & 5 \\ 2 & 6 \\ 3 & 7 \\ 4 & 8\end{matrix}\right)^{\top}
\left(\begin{matrix}9 & 13 \\ 10 & 14 \\ 11 & 15 \\ 12 & 16\end{matrix}\right)
=\left(\begin{matrix}110 & 150 \\ 278 & 382\end{matrix}\right) \\
\left(\begin{matrix}1+2i & 5+6i \\ 3+4i & 7+8i\end{matrix}\right)^{\dagger}
\left(\begin{matrix}9+10i & 13+14i \\ 11+12i & 15+16i\end{matrix}\right)
=\left(\begin{matrix}110-16i & 150-24i \\ 278-8i & 382-16i\end{matrix}\right)

For reference, the calculation result using the quaternion matrix is shown.

\begin{align}
&\left(\begin{matrix}1+2i+3j+4k & 5+6i+7j+8k\end{matrix}\right)^{\dagger}
 \left(\begin{matrix}9+10i+11j+12k & 13+14i+15j+16k\end{matrix}\right) \\
&=\left(\begin{matrix}
    110-32j-16k & 150-48j-24k \\
    278-16j- 8k & 382-32j-16k
  \end{matrix}\right)
\end{align}

This is the end of the comparison.

Related article

This time, we focused on the inner product, so we didn't mention the outer product very much. See the following articles for cross products and Clifford algebra.

Bicomplex numbers and quaternions are explained in the following articles from the perspective of how to make them.

If you treat the coefficients of the quaternion differently from the representation matrix and calculate, you will see the image that the inner product and the outer product are called "inside" and "outside".

reference

I referred to the Hermitian conjugate.

I used it as a reference for SymPy.

Recommended Posts

Complex vector considered as a real vector
Use Remotte as a user