Skip to content

About

Cellular substrate algebra extended with quantum operators — the substrate is measurement

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

substrate-quantum

Classical simulation of small quantum systems. Up to ~14 qubits is feasible (16,384 complex amplitudes).

import { QuantumState, Gates, bellPhiPlus, bellPhiMinus, bellPsiPlus, bellPsiMinus,
  ghzState, wState, qft, grover, deutschJozsa, entanglementEntropy } from 'substrate-quantum';

// Bell state |Φ+⟩ = (|00⟩ + |11⟩) / √2
const bell = bellPhiPlus();
bell.measure();                  // collapses to 00 or 11, each with prob 1/2
const hist = bell.sampleHistogram(10000); // distribution

// GHZ state — all 3 qubits maximally entangled
const ghz = ghzState(3);          // (|000⟩ + |111⟩) / √2

// Entanglement entropy
entanglementEntropy(bell, 0);    // 1 bit
entanglementEntropy(ghz, 0);     // 1 bit (1 qubit reduced out)

// Algorithms
grover(state, markedItem);       // Grover search
qft(state);                      // Quantum Fourier Transform
deutschJozsa(f, n);              // Returns 'constant' or 'balanced'

The math

Quantum states

A quantum state on n qubits is a vector in C^(2^n). Each amplitude αᵢ is complex.

|ψ⟩ = Σᵢ αᵢ |i⟩

Born rule: probability of measuring basis state |i⟩ is |αᵢ|².

Normalize so Σ|αᵢ|² = 1.

Gates

Single-qubit gates are 2×2 unitary matrices. Apply to qubit q by tensor product with identity on all others.

Gate Matrix Effect
I [[1,0],[0,1]] identity
X [[0,1],[1,0]] NOT (bit flip)
Y [[0,-i],[i,0]] bit + phase flip
Z [[1,0],[0,-1]] phase flip
H 1/√2 · [[1,1],[1,-1]] Hadamard (superposition)
S [[1,0],[0,i]] π/2 phase
T [[1,0],[0,e^{iπ/4}]] π/4 phase
Rx(θ) rotation around X exp(-iθX/2)
Ry(θ) rotation around Y exp(-iθY/2)
Rz(θ) rotation around Z exp(-iθZ/2)

Entanglement

Bell states — maximally entangled 2-qubit states:

|Φ+⟩ = (|00⟩ + |11⟩) / √2   (H on q0, then CNOT 0→1)
|Φ-⟩ = (|00⟩ - |11⟩) / √2
|Ψ+⟩ = (|01⟩ + |10⟩) / √2
|Ψ-⟩ = (|01⟩ - |10⟩) / √2

Measuring one qubit instantly determines the other. This isn't classical correlation — it violates Bell inequalities.

GHZ state (n qubits): ( |00...0⟩ + |11...1⟩ ) / √2. Constructed by H on qubit 0, then CNOT chain 0→1→2→...→n-1.

Von Neumann entropy

S(ρ) = -tr(ρ log ρ) = -Σᵢ λᵢ log λᵢ

where λᵢ are eigenvalues of the density matrix ρ = |ψ⟩⟨ψ|.

For a pure state, S = 0 (one eigenvalue is 1, rest are 0). For a maximally mixed state on d levels, S = log d. For a Bell state reduced to one qubit, S = 1 bit (maximally entangled).

Quantum algorithms

Grover search: Given an oracle that marks one item in N, find it in O(√N) queries (vs O(N) classically). Optimal iteration count: ⌊π/4 · √N⌋.

Algorithm: start in uniform superposition, repeat: (1) flip marked amplitude, (2) reflect about mean amplitude.

Quantum Fourier Transform: QFT applied to a state computes the DFT in superposition. Used in Shor's algorithm, phase estimation. Cost: O(n²) gates for n qubits. Inverse: QFT applied twice is identity (up to endianness).

Deutsch-Jozsa: Given f: {0,1}^n → {0,1} that is either constant or balanced, determine which in 1 query. Quantum advantage is exponential vs classical worst case (2^(n-1)+1 queries).

Why simulate?

Real quantum computers are noisy (NISQ era — Noisy Intermediate-Scale Quantum). 100 qubits is the practical ceiling for state-vector simulation (2^100 ≈ 10^30 complex amplitudes).

For algorithm research on small instances (< 14 qubits), classical simulation is exact and fast. Use this for:

  • Testing oracle implementations
  • Verifying small Grover/Shor circuits
  • Building intuition about entanglement
  • Teaching quantum computing

For larger systems, use tensor network simulators (quimb, ITensor) or stabilizer simulators (stim) depending on structure.

Limitations

  • 2^n memory: 14 qubits = 16 KiB, 20 qubits = 16 MiB, 24 qubits = 256 MiB, 28 qubits = 4 GiB
  • No noise model (no decoherence, gate errors, readout errors)
  • No measurement in the middle (only final Born-rule sampling)
  • Real implementations of QFT, Grover should use decomposition to 1- and 2-qubit gates

License

MIT.

About

Cellular substrate algebra extended with quantum operators — the substrate is measurement

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages