# Lecture 011 - Linear Algebra of One Qubit

## Linear Algebra of 1 Qubit

|+\rangle = \begin{bmatrix} +\sqrt{1/2}\\ +\sqrt{1/2}\\ \end{bmatrix}, -|+\rangle = \begin{bmatrix} -\sqrt{1/2}\\ -\sqrt{1/2}\\ \end{bmatrix}, |-\rangle = \begin{bmatrix} +\sqrt{1/2}\\ -\sqrt{1/2}\\ \end{bmatrix}, -|-\rangle = \begin{bmatrix} -\sqrt{1/2}\\ +\sqrt{1/2}\\ \end{bmatrix},

$NOT$: reflection accross $\pi/4$

$HAD$: reflection accross $\pi/8$

Since both instruction cancels out if they are applied sequentially, so we only need to consider two matrix act on one qubit.

def R(A):
NOT A

R = \begin{bmatrix} \sqrt{1/2}, \sqrt{1/2}\\ -\sqrt{1/2}, \sqrt{1/2}\\ \end{bmatrix}

$R$: rotation by $-\pi/4$

def R-1(A):
NOT A

R^\dagger = \begin{bmatrix} \sqrt{1/2}, -\sqrt{1/2}\\ \sqrt{1/2}, \sqrt{1/2}\\ \end{bmatrix}

$R^\dagger$: rotation by $\pi/4$

Note that the matrix $R$ is not its self inverse/reverse. $R$ is unitrary because the reverse is its inverse.

### General Rotation

Any rotation by $\theta$ is unitrary, and therefore allowed

R_{\theta}^{(x,y)} = \begin{bmatrix} x & -y\\ y & x\\ \end{bmatrix}, R_{-\theta}^{(x,y)} = \begin{bmatrix} x & y\\ -y & x\\ \end{bmatrix}

where $(x, y)$ is the vector you end up after applying rotation to $(0, 0)$.

Every unitary matrix is a rotation or reflection.

Two reflections generates a rotation for $\geq 1$ dimension reflecting point.

If higher dimension is allowed, reflection can be simulated by rotation.

If we first apply reflection against $\alpha$ degree and then against $\beta$ degree, the final rotation angle is $2(\beta - \alpha)$.

Note that reflection is not commutative.

### Dirac Bra-Ket

Bra: $\langle \cdot |$ column vector

Ket: $|\cdot \rangle$ row vector

We also define:

|\cdot\rangle^\dagger = |\cdot\rangle^T = \langle\cdot |
\langle 0 | = \begin{bmatrix} 1 & 0\\ \end{bmatrix}, \langle 1 | = \begin{bmatrix} 0 & 1\\ \end{bmatrix}

You can use these vectors to get coordinates:

$ Notice when the matrix multiplication type-check, the notation forms a nice bracket.

For vectors, dot product is equivalent as matrix multiplication.

We also have the following property: for $L, R$ matrix

(L \cdot R)^\dagger = R^\dagger \cdot L^\dagger

Therefore:

\langle f | v \rangle^\dagger = |v\rangle^\dagger \cdot \langle f|^\dagger = \langle v | f \rangle

Most importantly, dot product with complex number is not commutative, this is because the row vector of a complex vector doesn't look the same as the column vector of a complex vector. This is because we defined "transformation between row and column" as $\dagger$. But $\dagger$ need swapping $i$ with $-i$. Therefore, daggering a $1\times1$ matrix isn't necessary the identity when you have complex numbers.

If $M$ is a complex matrix, $M^\dagger$ is formed by swaping rows and column (transpose) and then swapping $i$ with $-i$ ("complex conjugate") for each entry.

Printing (in standard basis $|0\rangle$, $|1\rangle$) qubit in state $|v\rangle$ will output "0" with probability $|\langle 0 | v \rangle |^2$ and "1" with probability $|\langle 1 | v \rangle |^2$

If we only care about the probability of printing "0" after some transformation $T$, we can do the following:

1. apply $T^\dagger$ with $|0\rangle$: $|t\rangle = T^\dagger|0\rangle$
2. apply $T^\dagger|0\rangle$ to the state we care about: $\langle t | v \rangle = |t\rangle^\dagger |v\rangle = (T^\dagger|0\rangle)^\dagger |v\rangle = \langle 0 | T |v \rangle$

There are three interpolation to notation $\langle f | v \rangle$:

• $|v\rangle$'s coordinate in $|f\rangle$'s basis (let $|v\rangle$ undo $|f\rangle$'s transformation and take the coordinate)

• length of $|v\rangle$ projection to $|f\rangle$ (dot product of unit vector)

• $\cos(\text{angle of } |v\rangle \text{ from } |f\rangle)$ ($\||f\rangle\| \cdot \||q\rangle\| \cdot \cos(\text{angle of } |v\rangle \text{ from } |f\rangle)$)

### Measuring

The pseudo code of measuring look like this:

def measure(A):
if rand(A) == "0":
A = |0>
print("0")
elif rand(A) == "1":
A = |1>
print("1")


For fun, digital pregnant test is a powerful computer who's only job is to translate two bars on the test strip to readable characters. Juncheng Zhan: I saw a video on a very similar device, but it's a "digital" covid test (Ellume), with a more powerful chip (a 64 MHz nRF52810) that supports bluetooth!

We can also measure in different basis.

def measure(A, theta):
rotate(A, -theta)
measure(A) # interpret 0 as theta direction, and 1 as theta+\pi/2 direction
rotate(A, theta) # mimic stay in deterministic with respect to measuring basis


The above function is: when $\vec{i}, \vec{j}$ forms a orthornormal basis in $\mathbb{R}^2$

• $Pr\{v \to \vec{i}\} = |\langle \vec{i} | v \rangle|^2$

• $Pr\{v \to \vec{j}\} = |\langle \vec{j} | v \rangle|^2$

"deterministic" only make sense if you specify basis

If a state $|v\rangle$ is $\theta_i$ angle with respect to its basis $|\vec{i}\rangle$, then:

• $Pr\{\vec{i}\} = \cos^2 \theta_i$

• $Pr\{\vec{j}\} = \sin^2 \theta_i$

The cosine and sine comes from projection. Basically taking the $\vec{i}$ component (for $\cos$) or taking the $\vec{j}$ component (for $\sin$) of $|v\rangle$. Below $|f\rangle, |g\rangle$ is the standard basis rotated by $\theta$:

|f\rangle = (\cos \theta) |0\rangle + (\sin \theta) |1\rangle|g\rangle = (-\sin \theta) |0\rangle + (\cos \theta) |0\rangle

### Filters

More fun facts:  I forgot to mention that your laptop screen also emits photons with special polarization!  It's literally how LCD screens work: the light first goes through a Horizontal Polarizing Filter, and then it goes through another filter that can controllably be turned to be either an HPF or a VPF. Set it HPF to get light, set it to HPF to get black.  (They have 3 of these per pixel, for Red, Green, Blue.)

Polarized filters are extremely useful in photography: to get rid of reflections from non-metallic surfaces such as sky, glass, water, vegetation,

We define the filter to have the following property:

• Horizontal Filter: $|0\rangle$ pass, $|1\rangle$ blocks

• Vertical Filter: $|1\rangle$ pass, $|0\rangle$ blocks

• $\theta$-Filter: horizontal filter rotated by $\theta$

$\pi/4$ radian filter has basis $|+\rangle$ and $-|-\rangle$. Therefore the pass through (output $+$)'s probability is $\cos ^2(45^\circ) = (\sqrt{1/2})^2 = \frac{1}{2}$

The probability of going through is $|\langle \vec{\theta} | v \rangle|^2$. When assume real:

Pr\{\text{going through}\} = |(\cos \theta)(\cos (\theta+\delta)) + (\sin \theta)(\sin (\theta + \delta))|^2

If you want turn the amplitude by $\delta$ degree with $n$ filters, the intensity of light getting through is:

\prod_{i=1}^{n}\left(\left(\cos\theta\right)\cos\left(\theta+\frac{\delta}{n}\right)+\left(\sin\theta\right)\sin\left(\theta+\frac{\delta}{n}\right)\right)^{2} = \left(\cos\frac{\delta}{n}\right)^{2n}

We choose to evenly distribute the angles because the function $\cos$ and $\sin$ is about linear near small angle. If the difference of angle is too big, the error will accumulate, meaning more intensity of light will be lost.

Here is one simple explanation why measurement behaves the way it is:

• Assume:

• there exists minimum indivisible energy, what we called a photon
• filters will block a portion of the energy in some rotation
• Therefore: since energy can't exist if it is less than the anergy of a photon, it either choose to completely pass through or completely blocked

Table of Content