qcheatsheet

QBit - \(\left| \psi \right>\)

  • Linear combination of 2 basis states:

    $$ \left| \psi \right> = \alpha \left| 0 \right> + \beta \left| 1 \right> = \begin{bmatrix} \alpha \\ \beta \end{bmatrix} $$

  • When measuring \(\psi\), probability to have \(0\) is: \(|| \alpha ||^2\)

  • Bloch Sphere representation: \(\left| \psi \right> = cos(\frac{\theta}{2}) \left| 0 \right> + e^{i\phi} sin(\frac{\theta}{2}) \left| 1 \right>\)

  • Remarquable values:

    $$ \left| + \right> = \frac{1}{\sqrt{2}} (\left| 0 \right> + \left| 1 \right>) \\ \left| - \right> = \frac{1}{\sqrt{2}} (\left| 0 \right> - \left| 1 \right>) $$

QRegister - \(\left| \Psi \right>\)

  • Multiple Qbits form a register. Which is the tensor product of QBits:

    $$ \left| \Psi \right> = \left| \psi_2 \psi_1 \psi_0 \right> = \left| \psi_2 \right> \otimes \left| \psi_1 \right> \otimes \left| \psi_0 \right> $$

  • Can be represented as linear combination of basis states:

$$ \left| \Psi \right> = a \left| 000 \right> + b \left| 001 \right> + c \left| 010 \right> + d \left| 011 \right> + e \left| 100 \right> + f \left| 101 \right> + g \left| 110 \right> + h \left| 111 \right> = \begin{bmatrix} a \\ b \\ c \\ d \\ e \\ f \\ g \\ h \end{bmatrix} $$

Entanglement

Two or more qubits can be entangled, meaning that the state cannot be factorized as a product of states:

$$ \frac{1}{\sqrt{2}} \left| 00 \right> + \frac{1}{\sqrt{2}} \left| 11 \right> \neq (a \left| 0 \right> + b \left| 1 \right>) \otimes (c \left| 0 \right> + d \left| 1 \right>) $$

Matrix product - \(\times\)

$$ \begin{bmatrix} 1 & 2 \\ 3 & 4 \\ \end{bmatrix} \times \begin{bmatrix} 0 & 5\\ 6 & 7\\ \end{bmatrix} = \begin{bmatrix} 1 \times 0 + 2 \times 6 & 1 \times 5 + 2 \times 7 \\ 3 \times 0 + 4 \times 6 & 3 \times 5 + 4 \times 7 \\ \end{bmatrix} $$
  • Matrix product is linear:
$$ \begin{align} \lambda (A \times B) &= (\lambda A) \times B = A \times (\lambda B) \\ (A + B) \times C &= (A \times C) + (B \times C) \end{align} $$
  • Matrix product is not commutative:
    $$ A \times B \neq B \times A $$

Tensor product - \(\otimes\)

Sometime called Kronecker product.

$$ \begin{bmatrix} 1 & 2 \\ 3 & 4 \\ \end{bmatrix} \otimes \begin{bmatrix} 0 & 5\\ 6 & 7\\ \end{bmatrix} = \begin{bmatrix} 1{\begin{bmatrix}0&5\\6&7\\\end{bmatrix}} & 2{\begin{bmatrix}0&5\\6&7\\\end{bmatrix}} \\ 3{\begin{bmatrix}0&5\\6&7\\\end{bmatrix}} & 4{\begin{bmatrix}0&5\\6&7\\\end{bmatrix}} \\ \end{bmatrix} $$
  • Tensor product is linear:
$$ \begin{align} \lambda (A \otimes B) &= (\lambda A) \otimes B = A \otimes (\lambda B) \\ (A + B) \otimes C &= (A \otimes C) + (B \otimes C) \end{align} $$
  • Tensor product is not commutative:
    $$ A \otimes B \neq B \otimes A $$

Apply QGate to QBit

  • Single QBit: Qgate has matrix \(M\) of size \(2*2\), applied to a QBit \(\left| \psi \right> = \alpha \left| 0 \right> + \beta \left| 1 \right>\):
$$ Q(\left| \psi \right>) = M \times \left| \psi \right> = \begin{bmatrix} a & b \\ c & d \end{bmatrix} \times \begin{bmatrix} \alpha \\ \beta \end{bmatrix} $$
  • Multi QBits: Qgate has matrix \(M\) of size \(2^n * 2^n\) applied to a \(n\) QBit register:
$$ Q(\left| \Psi \right>) = M \times \left| \Psi \right> $$

QGates

PauliX - NOT - \(\sigma_x\)

  • Apply a 180º rotation around X axis
  • swap α and β probabilities and keep the same phase ϕ.
  • Effect on base:
$$ \left< \sigma_x | 0 \right> = \left| 1 \right> \\ \left< \sigma_x | 1 \right> = \left| 0 \right> $$
  • Matrix:
$$ \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} $$

PauliY - \(\sigma_y\)

  • Apply a 180º rotation around Y axis
  • Swap α and β probabilities and shift the phase ϕ.
  • Effect on base
$$ \begin{align} &\left< \sigma_y | 0 \right> = i\left| 1 \right> \\ &\left< \sigma_y | 1 \right> = -i\left| 0 \right> \end{align} $$
  • Matrix
$$ \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} $$

PauliZ - \(\sigma_z\)

  • Apply a 180º rotation around Z axis
  • Keep α and β probabilities and flip the phase ϕ.
  • Effect on base:
$$ \begin{align} &\left< \sigma_z | 0 \right> = \left| 0 \right> \\ &\left< \sigma_z | 1 \right> = -\left| 1 \right> \end{align} $$
  • Matrix
$$ \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} $$

Hadamard - \(H\)

  • Apply a 90º rotation around the Y-axis, followed by a 180º rotation around the X-axis
  • Effect on base:
$$ \begin{align} &\left< H | 0 \right> = \left| + \right>\\ &\left< H | 1 \right> = \left| - \right>\\ &\left< H | + \right> = \left| 0 \right>\\ &\left< H | - \right> = \left| 1 \right>\\ \end{align} $$
  • Matrix:
$$ \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} $$

Quantum Circuit

  • Single QBit
      ┌───┐  ┌───┐  ┌───┐   
q_0: ─┤ A ├──┤ B ├──┤ C ├─  
      └───┘  └───┘  └───┘    

Input state: \(\left| q_0 \right>\)

Output state: \(M \times \left| q_0 \right> = C \times B \times A \times \left| q_0 \right>\)

  • Multiple QBits
                          ┌───┐
q_0: ───────        q_0: ─┤ I ├─  
      ┌───┐               ├───┤  
q_1: ─┤ Q ├─        q_1: ─┤ Q ├─ 
      └───┘    <=>        ├───┤   
q_2: ───────        q_2: ─┤ I ├─  
                          ├───┤  
q_3: ───────        q_3: ─┤ I ├─  
                          └───┘

Input state: \(\left| \Psi \right> = \left| q_3 q_2 q_1 q_0 \right>\). 1st Qbit on the right.

Output state: \(M \times \left| \Psi \right> = (I \otimes I \otimes Q \otimes I) \times \left| \Psi \right>\)

Use Tensor product \(\otimes\). \(Q\) is single QBit QGate, \(I\) is Identity. \(Q, I\) have size \(2*2\). \(M\) has size \(2^n * 2^n\).

XOR / CNOT / bitwise addition - \(\oplus\)

  • \(0 \oplus x = x\)
  • \(1 \oplus x = !x\)
  • /!\ \((a \oplus b) \otimes c \ne (a \otimes c) \oplus (b \otimes c)\)