fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),mainPanel(
plotOutput("distPlot")
)
) )
---
title: "Quantum Study Guide"
author: "Jessica McPhaul"
date: "2025-02-06"
format:
html:
theme: cosmo
code-fold: true
html-math-method: katex
server: shiny
execute:
echo: true
---
## Shiny Interactive Component
::: {.cell}
```{.r .cell-code}
library(shiny)
:::
function(input, output, session) {
$distPlot <- renderPlot({
output<- faithful[, 2]
x <- seq(min(x), max(x), length.out = input$bins + 1)
bins
hist(x, breaks = bins,
col = 'darkgray',
border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')
}) }
function (input, output, session)
{
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins +
1)
hist(x, breaks = bins, col = "darkgray", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")
})
}
Quantum Computing: Math & Theory Study Guide
1. Complex Numbers & Linear Algebra
Complex Numbers:
- Form: \(z = a + bi\), where \(i^2 = -1\)
- Magnitude: \(|z| = \sqrt{a^2 + b^2}\)
- Conjugate: \(\overline{z} = a - bi\)
- Multiplication Rule: \((a+bi)(c+di) = (ac - bd) + (ad + bc)i\)
Linear Algebra Basics:
- Vector Notation (Dirac bra-ket):
- Column (Ket): \(|\psi\rangle = \begin{pmatrix} a \\ b \end{pmatrix}\)
- Row (Bra): \(\langle\psi| = \begin{pmatrix} a & b \end{pmatrix}\)
- Inner Product: \(\langle\phi | \psi \rangle\) = dot product
- Outer Product: \(|\psi\rangle \langle\phi|\) = matrix multiplication
- Matrices:
- Identity: \(I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\)
- Transpose: Switch rows & columns
- Conjugate Transpose: Conjugate each entry and transpose
- Matrix Multiplication: Row-column multiplication
Mnemonic for Matrix Multiplication:
“Row times Column gives the Sum”
2. Qubits & Quantum States
A qubit is a 2D vector in a complex Hilbert space:
\[ |\psi\rangle = \alpha|0\rangle + \beta|1\rangle, \quad \text{where } |\alpha|^2 + |\beta|^2 = 1 \]
- Computational Basis: \(|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, |1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix}\)
Bloch Sphere Representation:
\[ |\psi\rangle = \cos{\frac{\theta}{2}} |0\rangle + e^{i\phi} \sin{\frac{\theta}{2}} |1\rangle \]
Mnemonic:
- Latitude (θ) controls probability distribution - Longitude (φ) controls phase difference - “Theta tilts, Phi spins”
3. Quantum Gates & Transformations
Basic Quantum Gates:
Gate | Matrix Representation | Effect |
---|---|---|
Pauli-X (NOT) | \(\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\) | Flips \(|0\rangle \leftrightarrow |1\rangle\) |
Pauli-Y | \(\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}\) | Phase + Flip |
Pauli-Z | \(\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\) | Phase shift |
Hadamard (H) | \(\frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\) | Superposition |
Phase Gate (S) | \(\begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}\) | Phase shift |
T Gate | \(\begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}\) | Phase shift |
Mnemonic for Hadamard Gate:
“Halfway between 0 and 1” (Splits \(|0\rangle\) and \(|1\rangle\) into an equal mix)
4. Superposition & Entanglement
Superposition:
\[ H |0\rangle = \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) \]
Bell Pairs (Entanglement):
\[ |\Phi^+\rangle = \frac{1}{\sqrt{2}} (|00\rangle + |11\rangle) \]
Mnemonic for Bell States:
“Entangled twins” (They behave as a single unit)
5. Quantum Measurement & Probability
- Measurement collapses a qubit into \(|0\rangle\) or \(|1\rangle\)
- Probability of getting \(|0\rangle\): \(P(0) = |\alpha|^2\)
- Probability of getting \(|1\rangle\): \(P(1) = |\beta|^2\)
6. Quantum Algorithms
Deutsch’s Algorithm:
- Determines if a function is constant or balanced in one query
- Uses Hadamard & X gates
from qiskit import QuantumCircuit, Aer, execute
= QuantumCircuit(2, 1)
qc 0,1]) # Create superposition
qc.h([0,1) # Apply function
qc.cx(0) # Interference step
qc.h(0,0)
qc.measure(
= Aer.get_backend('qasm_simulator')
sim = execute(qc, sim, shots=1000).result()
result print(result.get_counts())
Quantum Fourier Transform (QFT):
- Generalization of the Fourier Transform to quantum states
- Key in Shor’s Algorithm for factorization
import numpy as np
from qiskit import QuantumCircuit
def qft(n):
= QuantumCircuit(n)
qc for i in range(n):
for j in range(i):
/ 2**(i-j), j, i) # Controlled phase gates
qc.cp(np.pi
qc.h(i)return qc
= qft(3)
qc 'mpl') # Visualize QFT circuit qc.draw(
Mnemonic for QFT:
“Interference creates frequency magic”
7. Shortcuts & Tips
- Use Hadamard gates to create superposition
- Apply controlled gates (CNOT) for entanglement
- Use phase gates (S, T) for controlled rotations
- QFT is a quantum version of the FFT—useful for factoring numbers
- Shor’s Algorithm breaks RSA encryption using QFT
Final Cheat Sheet
Concept | Formula / Mnemonic |
---|---|
Qubit State | \(|\psi\rangle = \alpha|0\rangle + \beta|1\rangle\) |
Hadamard Gate | \(H = \frac{1}{\sqrt{2}} (|0\rangle + |1\rangle)\) |
Entanglement | \(|\Phi^+\rangle = \frac{1}{\sqrt{2}} (|00\rangle + |11\rangle)\) |
Measurement Probability | \(P(0) = |\alpha|^2, P(1) = |\beta|^2\) |
Deutsch’s Algorithm | Uses Hadamard, CNOT, Hadamard |
QFT | Phase shift + Hadamard |
---