Textbook / teaching anchor
Quantum circuits
Visual circuit-model reference.
Beginner layer · the circuit model
A wire tells you where the state lives; a box tells you which operation happens next. Read time from left to right, but remember that matrix products act on state vectors from the right.
Textbook / teaching anchor
Visual circuit-model reference.
Textbook / teaching anchor
“Computers are physical objects, and computations are physical processes.”
Standard textbook reference for quantum mechanics, qubits, gates, and the circuit model.
Strict mathematics, after the picture
Every symbol used here is connected below to a compiled declaration or a clearly marked research-source formula.
Textbook / teaching anchor
Visual circuit-model reference.
Textbook / teaching anchor
“Computers are physical objects, and computations are physical processes.”
Standard textbook reference for quantum mechanics, qubits, gates, and the circuit model.
Learn Lean while learning quantum computing
evalGateMatrices [G₁, G₂, …, Gₘ] = Gₘ ⬝ … ⬝ G₂ ⬝ G₁
The evaluator is a definition, and later theorems prove that circuit syntax and matrix meaning use the same order.
The full proof-backed declarations for this chapter are shown immediately below.
Shared foundations · Chapter 2 of 9
Separate gate syntax from matrix evaluation and make register order an explicit part of the semantic boundary.
QuantumBlockEncoding/Circuit.leanQuantumBlockEncoding/CircuitSemantics.leanQuantumBlockEncoding/ConcreteSemantics.leanTextbook lesson
A circuit is an ordered program; its denotation is one unitary matrix. The list order and multiplication order must be stated once and then reused everywhere.
A gate preserves norm. ASPBE's concrete certificates use Mathlib's unitary group, while symbolic paper models keep unproved oracle unitarity as an explicit contract.
The rightmost matrix acts first. Reversing this convention can preserve dimensions while changing the algorithm, so the evaluator is a named library definition.
Flattening ancilla and system registers requires one fixed order. Projection lemmas prove that the flat index and product-register views select the same entries.
Given gates G then V, write the final state and the combined matrix without reversing their order.
Mathematical order and conventions adapted from Lin, Lecture Notes on Quantum Algorithms for Scientific Computation. The formal checkpoints and ASPBE status distinctions are specific to this library.
Route at a glance
flowchart LR
C["Fixed mathematical<br/>contract"] --> O["Named proof<br/>obligations"]
O --> P["Candidate routes<br/>with provenance"]
P --> L{"Lean gate"}
L -- "proof fails" --> F["Classified failure<br/>and next local lemma"]
F --> P
L -- "certificate compiles" --> X["Finite export<br/>and circuit check"]
X --> D["Documented result<br/>with stated scope"]
classDef contract fill:#f8f5ee,stroke:#826a32,color:#222222,stroke-width:1.5px;
classDef process fill:#ffffff,stroke:#64747a,color:#222222,stroke-width:1.25px;
classDef gate fill:#edf5f1,stroke:#2f7355,color:#18382b,stroke-width:1.5px;
classDef feedback fill:#fff2ef,stroke:#a44b3f,color:#4a2520,stroke-width:1.25px;
class C contract;
class O,P,X,D process;
class L gate;
class F feedback;
Selected declarations
A compiled route means that the reusable theorem or constructor and at least one finite witness compile. Hardware- and problem-specific downstream instantiations are out of scope, not universal claims made by these cards.
Lean result
QuantumBlockEncoding.evalGateMatrices
A list of gate matrices is folded into one matrix in the library's declared application order.
The list is executable syntax; its fold is the matrix used by proofs. Without one order convention, circuit diagrams and matrix products can silently disagree.
Recursively multiply the next gate matrix on the side fixed by the semantics.
QuantumBlockEncoding.GateMatrix; QuantumBlockEncoding.Matrix| Mathematical step | Lean object or step |
|---|---|
| Empty circuit is identity. | evalGateMatrices [] |
| Compose the next gate. | evalGateMatrices (g :: gs) |
def evalGateMatrices {α : Type u} [OfNat α 0] [OfNat α 1]
[HAdd α α α] [HMul α α α] {qubits : Nat}
(gates : List (GateMatrix α qubits)) :
Matrix (qubitDim qubits) (qubitDim qubits) α :=
gates.foldl (fun acc gateMatrix => Matrix.mul gateMatrix.matrix acc)
(Matrix.identity (qubitDim qubits) α)
Local declaration · Verso Blueprint · commit-pinned GitHub source
Lean result
QuantumBlockEncoding.ConcreteSemantics.signalSystemBlockProjection_eq_cleanBlockProduct
The two ASPBE block-projection views are pointwise equal under the shared register order.
A circuit-semantics proof can be consumed by classic block-encoding arithmetic without index reconstruction. Register-shape mismatches were a repeated historical failure class.
Both definitions use the same signal-major flattened index, so the pointwise proof is definitional.
QuantumBlockEncoding.signalSystemBlockProjection; QuantumBlockEncoding.BlockEncodingClassics.cleanBlockProductQuantumBlockEncoding.ConcreteSemantics.exactCleanBlockOfSignalProjectionQuantumBlockEncoding.ConcreteSemantics.exactCleanBlockOfSignalProjection_correct| Mathematical step | Lean object or step |
|---|---|
| Fix system row and column. | intro row col |
| Unfold the shared index. | rfl |
theorem signalSystemBlockProjection_eq_cleanBlockProduct
{signalDim systemDim : Nat}
(operator : Matrix (signalDim * systemDim) (signalDim * systemDim) Rat)
(signalIndex : Fin signalDim) :
Matrix.PointwiseEq
(signalSystemBlockProjection
signalDim systemDim systemDim operator signalIndex)
(BlockEncodingClassics.cleanBlockProduct signalIndex operator) := by
Local declaration · Verso Blueprint · commit-pinned GitHub source
Lean result
QuantumBlockEncoding.CircuitMatrixSemantics.blockExtractionTarget
Circuit semantics selects the signal-system block that must match the scaled target operator.
Ancillas are fixed to zero on both sides; the remaining indices are the signal system. It connects an executable gate list to the mathematical block-encoding contract.
Evaluate the gate list, project the ancilla-zero rows and columns, then compare the signal entries.
QuantumBlockEncoding.CircuitMatrixSemantics; QuantumBlockEncoding.signalSystemBlockProjectionQuantumBlockEncoding.CertifiedCircuitBlockExtraction.extractionTargetQuantumBlockEncoding.CertifiedCircuitBlockExtraction.exactCleanBlockQuantumBlockEncoding.CertifiedCircuitBlockExtraction.exactCleanBlock_correct| Mathematical step | Lean object or step |
|---|---|
| Evaluate syntax. | CircuitMatrixSemantics.ofGateMatrices |
| Extract the selected block. | signalSystemBlockProjection |
def CircuitMatrixSemantics.blockExtractionTarget
{α : Type u} [OfNat α 0] [OfNat α 1]
[HAdd α α α] [HMul α α α]
{qubits : Nat}
(sem : CircuitMatrixSemantics α qubits)
(dim signalDim : Nat)
(hDim : qubitDim qubits = signalDim * dim)
(targetMatrix : Matrix dim dim α)
(normalizer : α)
(signalIdx : Fin signalDim) :
BlockExtractionTarget α dim dim signalDim where
Local declaration · Verso Blueprint · commit-pinned GitHub source
Lean result
QuantumBlockEncoding.ConcreteSemantics.pointwiseProjection_iff_cleanBasisAction
Checking every clean projected entry is equivalent to checking the clean output amplitude after acting on every clean basis input.
This is the finite-matrix bridge between the projected-block definition and the action-on-a-state proof style used in circuit derivations. Readers can follow a paper's state evolution without changing the mathematical acceptance contract.
Apply the matrix to a basis ket, use column selection, and identify the clean signal-system row.
QuantumBlockEncoding.ConcreteSemantics.cleanBasisActionAmplitude; QuantumBlockEncoding.ConcreteSemantics.applyVec_basisKetQuantumBlockEncoding.ConcreteSemantics.cleanBasisActionAmplitude_eq_signalSystemBlockProjectionQuantumBlockEncoding.ConcreteSemantics.pointwiseProjection_iff_cleanBasisAction| Mathematical step | Lean object or step |
|---|---|
| Select one clean basis input. | applyVec_basisKet |
| Read one clean output amplitude. | cleanBasisActionAmplitude_eq_signalSystemBlockProjection |
| Quantify over both system indices. | pointwiseProjection_iff_cleanBasisAction |
theorem pointwiseProjection_iff_cleanBasisAction
{signalDim systemDim : Nat} {α : Type u} [NonAssocSemiring α]
(operator : FiniteMatrix (signalDim * systemDim) (signalDim * systemDim) α)
(signalIndex : Fin signalDim) (target : Matrix systemDim systemDim α) :
Matrix.PointwiseEq
(signalSystemBlockProjection signalDim systemDim systemDim
operator signalIndex)
target ↔
∀ output input,
cleanBasisActionAmplitude operator signalIndex output input =
target output input := by
Local declaration · Verso Blueprint · commit-pinned GitHub source