Core 1028 declarations in 19 modules
FormalRV.Core.ApproxQFT
FormalRV/Core/ApproxQFT.lean
FormalRV.Core.ApproxQFT — a CONSTRUCTIVE Clifford+T compilation of the
QFT via Coppersmith's approximate ("banded") QFT, with an exact,
elementary approximation-error bound. No existence axiom: the
compiler is an actual circuit transformation and the error is derived.
## The idea
The QFT's controlled phase rotations are `R_k = R_z(2π/2^k)`. Only
`R_1=Z, R_2=S, R_3=T` are exactly Clifford+T (proved in
`CliffordTRotations`). The approximate QFT with cutoff `m` simply
DROPS every `R_k` with `k > m` (replaces it by the identity). With
`m ≤ 3` the resulting circuit is *exactly* Clifford+T, and the error
of each drop is computed here from first principles:
error of dropping `R_z(θ)` = ‖R_z(θ) − I‖ = |e^{iθ} − 1| ≤ |θ|.
So the QFT→Clifford+T compilation error is a derived sum
`Σ_{dropped} 2π/2^k`, NOT an assumed bound.
theoremrotation_sub_one_diag
theorem rotation_sub_one_diag (θ : ℝ) :
rotation 0 0 θ - 1 = !![0, 0; 0, Complex.exp (θ * I) - 1]`R_z(θ) − I` is the diagonal matrix `diag(0, e^{iθ}−1)`: dropping a
z-rotation leaves only the `(1,1)` entry `e^{iθ}−1`.
theoremdropRotationError_le
theorem dropRotationError_le (θ : ℝ) :
‖Complex.exp ((θ : ℂ) * I) - 1‖ ≤ |θ|*The exact drop error (chord ≤ arc).** The magnitude of the only
non-zero entry of `R_z(θ) − I` is `|e^{iθ} − 1| ≤ |θ|` — the exact
operator-norm error of dropping the rotation `R_z(θ)`. Elementary,
no axiom.
theoremqftRot_drop_error_le
theorem qftRot_drop_error_le (k : ℕ) :
‖Complex.exp ((2 * Real.pi / 2 ^ k : ℝ) * I) - 1‖ ≤ 2 * Real.pi / 2 ^ kDropping the QFT rotation `R_k = R_z(2π/2^k)` costs at most
`2π/2^k` in operator norm — and `2π/2^k → 0`, so deep rotations are
nearly free to drop. This is the per-rotation term of the
approximate-QFT error budget, derived (not assumed).
theoremaqft_ladder_error_budget
theorem aqft_ladder_error_budget (c n : ℕ) (hcn : c ≤ n) :
∑ m ∈ Finset.Ico c n, (Real.pi / 2 ^ m) ≤ 2 * Real.pi / 2 ^ c*Closed-form AQFT error budget.** The total cost of dropping every
phase-ladder rotation `R_z(π/2^m)` from the cutoff `c` onward is at
most `2π/2^c` — a geometric tail. Derived from the per-rotation
`dropRotationError_le`, with no axiom.
theoremaqft_error_budget_antitone
theorem aqft_error_budget_antitone {c c' : ℕ} (h : c ≤ c') :
(2 * Real.pi / 2 ^ c' : ℝ) ≤ 2 * Real.pi / 2 ^ cThe error budget tends to `0` as the cutoff grows: choosing a larger
cutoff `c` drives the AQFT approximation error `≤ 2π/2^c` below any
target. (Trade-off: a larger cutoff keeps more rotations, and only
`m ≤ 1` (`Z, S†`) — or `m ≤ 2` with a controlled-`T` gadget — stay
exactly Clifford+T; finer kept rotations would need true synthesis.)
FormalRV.Core.Basic
FormalRV/Core/Basic.lean
FormalRV.Basic — shared primitives for the qianxu.pdf gap review.
Contains the surgery-cycle cost τ_s and a few foundational defs that
every gap module depends on. Lean 4 core only (no mathlib).
Per CLAUDE.md "Hard rules": every numerical claim in a gap module must
be a `lake build`-passing Lean lemma. This file is the foundation those
lemmas build on.
Refs: qianxu.pdf App. E §1, p. 21 (Eq. E1 surgery cycle cost).
deftau_s
def tau_s (d : Nat) : Nat
Surgery-cycle cost in stabilizer-measurement cycles, as a function of
the processor-code distance `d`. From qianxu p. 21: "τ_s ≈ 2d/3".
Integer division is fine here; the paper's `≈` already absorbs the
rounding.
example(example)
example : tau_s 12 = 8
For d = 12 (a plausible processor-code distance): τ_s = 8 cycles.
example(example)
example : tau_s 18 = 12
For d = 18: τ_s = 12 cycles.
example(example)
example : tau_s 12 ≤ tau_s 18
Sanity: τ_s is monotone in d (for the values we care about).
FormalRV.Core.Boolean
FormalRV/Core/Boolean.lean
FormalRV.Framework.Boolean — boolean helpers used in arithmetic
correctness proofs.
Centralizes the small set of Boolean operations BQ-Algo needs (majority,
half-add carry, full-add carry-out) so each correctness proof can refer to
a named function instead of an inlined expression.
defmajority
def majority (a b c : Bool) : Bool
Majority of three Boolean values: true iff at least two are true.
Equivalently: the carry-out of a full adder.
example(example)
example : majority false false false = false
Smoke checks: all 8 cases.
example(example)
example : majority true false false = false
example(example)
example : majority false true false = false
example(example)
example : majority false false true = false
example(example)
example : majority true true false = true
example(example)
example : majority true false true = true
example(example)
example : majority false true true = true
example(example)
example : majority true true true = true
theoremmajority_eq_cuccaro_form
theorem majority_eq_cuccaro_form (a b c : Bool) :
majority a b c = (xor c ((xor a c) && (xor b c)))The Cuccaro MAJ gate replaces qubit `c` with the majority of
its three inputs. Algebraically:
majority(a,b,c) = c ⊕ ((a ⊕ c) ∧ (b ⊕ c))
This is what makes MAJ implementable as 2 CX + 1 CCX.
FormalRV.Core.CliffordTRotations
FormalRV/Core/CliffordTRotations.lean
FormalRV.Core.CliffordTRotations — exact Clifford+T synthesis of the
`π/4`-multiple z-rotations, and the (cited) Solovay–Kitaev contract for
the rest. This is the rotation layer of "compile QPE to Clifford+T".
## The exact cases (proved here, sorry-free)
A z-rotation `R_z(λ) = diag(1, e^{iλ})` is exactly Clifford+T iff
`λ ∈ (π/4)·ℤ`, in which case it is a power of the `T` gate
(`T = R_z(π/4)`). We prove the phase-composition law and hence
T^k = R_z(k·π/4) (`tPow_eq_rotation`)
which covers `Z = T⁴`, `S = T²`, `T = T¹` — and so the QFT's exact
controlled rotations `R_1 = Z`, `R_2 = S`, `R_3 = T`
(`R_k := diag(1, e^{2πi/2^k})`).
## The approximate cases (the honest boundary)
The QFT rotations `R_k` for `k ≥ 4` are irrational-angle and provably
NOT exactly Clifford+T. Rather than ASSUME a decomposition exists
(Solovay–Kitaev as an axiom), we compile them constructively by the
standard approximate-QFT (Coppersmith) algorithm: DROP every rotation
below the cutoff. With cutoff `≤ 3` the kept rotations are exactly
`Z, S, T`, so the whole QFT becomes exactly Clifford+T, and the error
of each dropped rotation is DERIVED (`‖R_z(θ) − I‖ ≤ |θ|`), not
assumed. That construction and its error budget live in
`FormalRV.Core.ApproxQFT`.
theoremrotation_zz_diag
theorem rotation_zz_diag (lam : ℝ) :
rotation 0 0 lam = !![1, 0; 0, Complex.exp (lam * I)]theoremrotation_zz_mul
theorem rotation_zz_mul (a b : ℝ) :
rotation 0 0 a * rotation 0 0 b = rotation 0 0 (a + b)theoremrotation_zz_pow
theorem rotation_zz_pow (lam : ℝ) (k : ℕ) :
(rotation 0 0 lam) ^ k = rotation 0 0 (k * lam)theoremtPow_eq_rotation
theorem tPow_eq_rotation (k : ℕ) :
(rotation 0 0 (Real.pi / 4)) ^ k = rotation 0 0 (k * (Real.pi / 4))*Exact Clifford+T synthesis of a `π/4`-multiple z-rotation:** `k`
applications of the `T` gate (`R_z(π/4)`) realise `R_z(k·π/4)`
exactly.
defqftRot
noncomputable def qftRot (k : ℕ) : Matrix (Fin 2) (Fin 2) ℂ
The QFT phase rotation `R_k = diag(1, e^{2πi/2^k}) = R_z(2π/2^k)`.
theoremqftRot_three_eq_T
theorem qftRot_three_eq_T : qftRot 3 = rotation 0 0 (Real.pi / 4)
`R_3 = T` (one `T` gate).
theoremqftRot_two_eq_TSq
theorem qftRot_two_eq_TSq :
qftRot 2 = (rotation 0 0 (Real.pi / 4)) ^ 2`R_2 = S = T²`.
theoremqftRot_one_eq_TPow4
theorem qftRot_one_eq_TPow4 :
qftRot 1 = (rotation 0 0 (Real.pi / 4)) ^ 4`R_1 = Z = T⁴`.
inductiveIsCliffordT
inductive IsCliffordT : {dim : Nat} → BaseUCom dim → Prop
| seq {dim : Nat} {c₁ c₂ : BaseUCom dim} :
IsCliffordT c₁ → IsCliffordT c₂ → IsCliffordT (UCom.seq c₁ c₂)
| gate1 {dim : Nat} {u : BaseUnitary 1} {n : Nat}
(h : u = U_H ∨ u = U_S ∨ u = U_T ∨ u = U_SDAG ∨ u = U_TDAG ∨ u = U_I) :
IsCliffordT (UCom.app1 u n : BaseUCom dim)
| cnot {dim : Nat} {m n : Nat} :
IsCliffordT (UCom.app2 BaseUnitary.CNOT m n : BaseUCom dim)A `BaseUCom` is a Clifford+T circuit: composed from the single-qubit
Clifford+T gates `{H, S, T, S†, T†}` and `CNOT`.
theoremexact_rotation_no_approx
theorem exact_rotation_no_approx (k : ℕ) :
(rotation 0 0 (Real.pi / 4)) ^ k = rotation 0 0 (k * (Real.pi / 4))The exact rotations need no approximation at all: `R_z(k·π/4)` is
`T^k` exactly (`ε = 0`). Off the `(π/4)·ℤ` lattice the approximate-QFT
drop (`ApproxQFT`) supplies a constructive, error-bounded
Clifford+T circuit.
FormalRV.Core.DensitySem
FormalRV/Core/DensitySem.lean
FormalRV.Framework.DensitySem — density-matrix semantics for `Com`.
Lean translation of `SQIR/SQIR/DensitySem.v` (148 LOC of Coq).
Where `NDSem` gives operational/non-deterministic semantics, this gives
the deterministic density-matrix semantics: each `Com` is interpreted as
a `Superoperator` (a function on density matrices).
Status: scaffolding — types and signatures in place, key proofs sorried
for partial-trace / measurement reasoning.
abbrevDensityMat
abbrev DensityMat (dim : Nat)
A density matrix on a `dim`-qubit system: `2^dim × 2^dim` complex,
Hermitian, positive semi-definite, trace 1. We don't enforce the
physical constraints in the type; just use `Square dim`.
abbrevSuperoperator
abbrev Superoperator (dim : Nat)
A superoperator: a linear map between density matrices. We model it
as a plain function for now (not enforcing complete positivity in the
type).
defc_eval
noncomputable def c_eval {dim : Nat} : BaseCom dim → Superoperator dim
| Com.cskip => fun ρ => ρ
| Com.embedU u => fun ρ => uc_eval u * ρ * (uc_eval u).conjTranspose
| Com.useq c₁ c₂ => fun ρ => c_eval c₂ (c_eval c₁ ρ)
| Com.meas n c₁ c₂ => fun ρ =>
let p₀Density-matrix semantics for `Com`. Each program is a superoperator.
For unitary `u`: ρ ↦ U ρ U†.
For measurement: ρ ↦ P₀ ρ P₀† + P₁ ρ P₁† (sum over outcomes), with
each branch's program applied conditionally.
SQIR/DensitySem.v line ~22.
defc_equiv
def c_equiv {dim : Nat} (c₁ c₂ : BaseCom dim) : Prop`Com` equivalence under the density-matrix semantics.
theoremc_equiv_refl
theorem c_equiv_refl {dim : Nat} (c : BaseCom dim) : c_equiv c ctheoremc_equiv_sym
theorem c_equiv_sym {dim : Nat} {c₁ c₂ : BaseCom dim} :
c_equiv c₁ c₂ → c_equiv c₂ c₁theoremc_equiv_trans
theorem c_equiv_trans {dim : Nat} {c₁ c₂ c₃ : BaseCom dim} :
c_equiv c₁ c₂ → c_equiv c₂ c₃ → c_equiv c₁ c₃theoremc_useq_assoc
theorem c_useq_assoc {dim : Nat} (c₁ c₂ c₃ : BaseCom dim) :
c_equiv (Com.useq (Com.useq c₁ c₂) c₃) (Com.useq c₁ (Com.useq c₂ c₃))`useq` associativity for `Com` (density-matrix version).
theoremc_useq_assoc_l
theorem c_useq_assoc_l {dim : Nat} (c₁ c₂ c₃ : BaseCom dim) :
c_equiv (Com.useq c₁ (Com.useq c₂ c₃)) (Com.useq (Com.useq c₁ c₂) c₃)`useq` left-associativity (reverse direction): `c₁;(c₂;c₃) ≡ (c₁;c₂);c₃`.
Direct corollary of `c_useq_assoc` via `c_equiv_sym`.
theoremc_useq_congr
theorem c_useq_congr {dim : Nat} (c₁ c₁' c₂ c₂' : BaseCom dim)
(h₁ : c_equiv c₁ c₁') (h₂ : c_equiv c₂ c₂') :
c_equiv (Com.useq c₁ c₂) (Com.useq c₁' c₂')Sequential composition is congruent under `c_equiv`.
-- SQIR/SQIR/DensitySem.v line 60: seq_congruence.
theoremc_cskip_useq
theorem c_cskip_useq {dim : Nat} (c : BaseCom dim) :
c_equiv (Com.useq Com.cskip c) c`cskip ; c ≡ c` — left identity of useq under c_equiv.
theoremc_useq_cskip
theorem c_useq_cskip {dim : Nat} (c : BaseCom dim) :
c_equiv (Com.useq c Com.cskip) c`c ; cskip ≡ c` — right identity of useq under c_equiv.
theoremc_meas_congr
theorem c_meas_congr {dim : Nat} (n : Nat) {c₁ c₁' c₂ c₂' : BaseCom dim}
(h₁ : c_equiv c₁ c₁') (h₂ : c_equiv c₂ c₂') :
c_equiv (Com.meas n c₁ c₂) (Com.meas n c₁' c₂')Measurement is congruent under `c_equiv` on each branch.
-- SQIR/SQIR/DensitySem.v: `meas_congruence`.
theoremc_equiv_of_uc_equiv
theorem c_equiv_of_uc_equiv {dim : Nat} {u₁ u₂ : BaseUCom dim}
(h : UCom.equiv u₁ u₂) :
c_equiv (Com.embedU u₁) (Com.embedU u₂)Bridge from unitary semantics to density semantics: if two unitary
commands are `UCom.equiv` (have equal `uc_eval`), then their embeddings
into `Com` are `c_equiv`. The natural lifting of unitary equivalence
through the density-matrix evolution `ρ ↦ U ρ U†`.
theoremc_equiv_useq_embedU_left
theorem c_equiv_useq_embedU_left {dim : Nat} (c : BaseCom dim)
{u₁ u₂ : BaseUCom dim} (h : UCom.equiv u₁ u₂) :
c_equiv (Com.useq (Com.embedU u₁) c) (Com.useq (Com.embedU u₂) c)Left-position bridge composition: substituting an equivalent unitary
in the left position of a useq preserves `c_equiv`. 1-line combination
of `c_equiv_of_uc_equiv` with `c_useq_congr`.
theoremc_equiv_useq_embedU_right
theorem c_equiv_useq_embedU_right {dim : Nat} (c : BaseCom dim)
{u₁ u₂ : BaseUCom dim} (h : UCom.equiv u₁ u₂) :
c_equiv (Com.useq c (Com.embedU u₁)) (Com.useq c (Com.embedU u₂))Right-position bridge composition: symmetric to `c_equiv_useq_embedU_left`.
theoremc_equiv_embedU_invert_invert
theorem c_equiv_embedU_invert_invert {dim : Nat} (c : BaseUCom dim) :
c_equiv (Com.embedU (invert (invert c))) (Com.embedU c)Lifting `invert_invert` through `embedU`: `embedU(invert(invert c)) ⩮
embedU(c)`. Direct consequence of the syntactic equality
`invert (invert c) = c`.
theoremc_equiv_useq_embedU_ID_l
theorem c_equiv_useq_embedU_ID_l {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseCom dim) :
c_equiv (Com.useq (Com.embedU (BaseUCom.ID q)) c) c`embedU(ID q)` is a left-identity of `useq` at the density layer
(when `q < dim`). The identity unitary acts as the identity on
density matrices: `1 ρ 1† = ρ`.
theoremc_equiv_useq_embedU_ID_r
theorem c_equiv_useq_embedU_ID_r {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseCom dim) :
c_equiv (Com.useq c (Com.embedU (BaseUCom.ID q))) c`embedU(ID q)` is also a right-identity of `useq` at the density layer.
Symmetric companion of `c_equiv_useq_embedU_ID_l`.
theoremc_equiv_useq_embedU_embedU
theorem c_equiv_useq_embedU_embedU {dim : Nat} (u₁ u₂ : BaseUCom dim) :
c_equiv (Com.useq (Com.embedU u₁) (Com.embedU u₂))
(Com.embedU (UCom.seq u₁ u₂))Sequencing two embedded unitaries is the embedding of their sequence:
`useq (embedU u₁) (embedU u₂) ⩮ embedU (u₁ ; u₂)`. The fundamental
"merge" identity for the density layer, derived from matrix
associativity and `conjTranspose_mul`.
theoremc_equiv_useq_embedU_T_TDAG
theorem c_equiv_useq_embedU_T_TDAG {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.T q : BaseUCom dim))
(Com.embedU (BaseUCom.TDAG q)))
(Com.embedU (BaseUCom.ID q))Application of the seq-merge identity + bridge:
`useq (embedU(T q)) (embedU(TDAG q)) ⩮ embedU(ID q)`. Demonstrates the
seq-merge → bridge composition chain — converts a density-layer
seq of two embedUs into a unitary identity.
theoremc_equiv_useq_embedU_X_X
theorem c_equiv_useq_embedU_X_X {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.X q : BaseUCom dim))
(Com.embedU (BaseUCom.X q)))
(Com.embedU (BaseUCom.ID q))Pauli-X involution via seq-merge + bridge.
theoremc_equiv_useq_embedU_Y_Y
theorem c_equiv_useq_embedU_Y_Y {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.Y q : BaseUCom dim))
(Com.embedU (BaseUCom.Y q)))
(Com.embedU (BaseUCom.ID q))Pauli-Y involution via seq-merge + bridge.
theoremc_equiv_useq_embedU_Z_Z
theorem c_equiv_useq_embedU_Z_Z {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.Z q : BaseUCom dim))
(Com.embedU (BaseUCom.Z q)))
(Com.embedU (BaseUCom.ID q))Pauli-Z involution via seq-merge + bridge.
theoremc_equiv_useq_embedU_H_H
theorem c_equiv_useq_embedU_H_H {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.H q : BaseUCom dim))
(Com.embedU (BaseUCom.H q)))
(Com.embedU (BaseUCom.ID q))Hadamard involution via seq-merge + bridge.
theoremc_equiv_useq_embedU_CCX_CCX
theorem c_equiv_useq_embedU_CCX_CCX {dim : Nat} (a b c : Nat) (h0 : 0 < dim)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
c_equiv (Com.useq (Com.embedU (BaseUCom.CCX a b c : BaseUCom dim))
(Com.embedU (BaseUCom.CCX a b c)))
(Com.embedU (BaseUCom.ID 0))Toffoli involution via seq-merge + bridge: at the density layer,
`useq (embedU (CCX a b c)) (embedU (CCX a b c)) ⩮ embedU (ID 0)`
when `dim ≥ 1`. Mirrors `c_equiv_useq_embedU_X_X` for the 3-qubit
Toffoli case.
theoremc_equiv_useq_embedU_TDAG_T
theorem c_equiv_useq_embedU_TDAG_T {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.TDAG q : BaseUCom dim))
(Com.embedU (BaseUCom.T q)))
(Com.embedU (BaseUCom.ID q))T†·T inverse pair via seq-merge + bridge.
theoremc_equiv_useq_embedU_S_SDAG
theorem c_equiv_useq_embedU_S_SDAG {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.S q : BaseUCom dim))
(Com.embedU (BaseUCom.SDAG q)))
(Com.embedU (BaseUCom.ID q))S·S† inverse pair via seq-merge + bridge.
theoremc_equiv_useq_embedU_SDAG_S
theorem c_equiv_useq_embedU_SDAG_S {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.SDAG q : BaseUCom dim))
(Com.embedU (BaseUCom.S q)))
(Com.embedU (BaseUCom.ID q))S†·S inverse pair via seq-merge + bridge.
theoremc_equiv_useq_embedU_H_Z_eq_X_H
theorem c_equiv_useq_embedU_H_Z_eq_X_H {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.H q : BaseUCom dim))
(Com.embedU (BaseUCom.Z q)))
(Com.useq (Com.embedU (BaseUCom.X q))
(Com.embedU (BaseUCom.H q)))Hadamard interchange identity at the density layer:
`useq (embedU H) (embedU Z) ⩮ useq (embedU X) (embedU H)`. Lifts
`H_comm_Z` via the seq-merge → bridge → seq-merge⁻¹ chain.
theoremc_equiv_useq_embedU_H_X_eq_Z_H
theorem c_equiv_useq_embedU_H_X_eq_Z_H {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.H q : BaseUCom dim))
(Com.embedU (BaseUCom.X q)))
(Com.useq (Com.embedU (BaseUCom.Z q))
(Com.embedU (BaseUCom.H q)))Dual Hadamard interchange at the density layer:
`useq (embedU H) (embedU X) ⩮ useq (embedU Z) (embedU H)`. Lifts
`H_comm_X` via the same seq-merge chain.
theoremc_equiv_useq_embedU_Rz_Rz_add
theorem c_equiv_useq_embedU_Rz_Rz_add {dim : Nat} (θ θ' : ℝ) (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.Rz θ q : BaseUCom dim))
(Com.embedU (BaseUCom.Rz θ' q)))
(Com.embedU (BaseUCom.Rz (θ + θ') q))Z-rotation composition lifted to density semantics:
`useq (embedU(Rz θ)) (embedU(Rz θ')) ⩮ embedU(Rz (θ+θ'))`.
Lifts `Rz_Rz_add` via seq-merge + bridge.
theoremc_equiv_useq_embedU_Rz_neg_id
theorem c_equiv_useq_embedU_Rz_neg_id {dim : Nat} (θ : ℝ) (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.Rz θ q : BaseUCom dim))
(Com.embedU (BaseUCom.Rz (-θ) q)))
(Com.embedU (BaseUCom.ID q))Parametric Z-rotation cancellation lifted to density:
`useq (embedU(Rz θ)) (embedU(Rz (-θ))) ⩮ embedU(ID q)`. Generalizes
the T·T† and S·S† inverse-pair lifts to arbitrary θ.
theoremc_equiv_embedU_Rz_zero_eq_ID
theorem c_equiv_embedU_Rz_zero_eq_ID {dim : Nat} (q : Nat) :
c_equiv (Com.embedU (BaseUCom.Rz 0 q : BaseUCom dim))
(Com.embedU (BaseUCom.ID q))Trivial Z-rotation = ID at density: `embedU(Rz 0 q) ⩮ embedU(ID q)`.
Direct bridge lift of `Rz_0_id`. Useful for eliminating
zero-angle rotations from circuits.
theoremc_equiv_useq_embedU_T_T_eq_S
theorem c_equiv_useq_embedU_T_T_eq_S {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.T q : BaseUCom dim))
(Com.embedU (BaseUCom.T q)))
(Com.embedU (BaseUCom.S q))T·T = S lifted to density: `useq (embedU(T q)) (embedU(T q)) ⩮
embedU(S q)`. Useful T-count reduction primitive.
theoremc_equiv_useq_embedU_S_S_eq_Z
theorem c_equiv_useq_embedU_S_S_eq_Z {dim : Nat} (q : Nat) :
c_equiv (Com.useq (Com.embedU (BaseUCom.S q : BaseUCom dim))
(Com.embedU (BaseUCom.S q)))
(Com.embedU (BaseUCom.Z q))S·S = Z lifted to density. Same Rz-composition pattern with θ = π/2.
theoremc_equiv_useq_embedU_SKIP_l
theorem c_equiv_useq_embedU_SKIP_l {dim : Nat} (hd : 0 < dim) (c : BaseUCom dim) :
c_equiv (Com.useq (Com.embedU (BaseUCom.SKIP : BaseUCom dim)) (Com.embedU c))
(Com.embedU c)SKIP-as-left-identity lifted to density: `useq (embedU SKIP) (embedU c)
⩮ embedU c`. Lifts `useq_SKIP_l` via seq-merge + bridge.
theoremc_equiv_useq_embedU_SKIP_r
theorem c_equiv_useq_embedU_SKIP_r {dim : Nat} (hd : 0 < dim) (c : BaseUCom dim) :
c_equiv (Com.useq (Com.embedU c) (Com.embedU (BaseUCom.SKIP : BaseUCom dim)))
(Com.embedU c)SKIP-as-right-identity lifted to density.
theoremc_equiv_embedU_T_TDAG_id
theorem c_equiv_embedU_T_TDAG_id {dim : Nat} (q : Nat) :
c_equiv (Com.embedU (UCom.seq (BaseUCom.T q : BaseUCom dim) (BaseUCom.TDAG q)))
(Com.embedU (BaseUCom.ID q))Demo of the `c_equiv_of_uc_equiv` bridge: the embedded T·T† circuit
is density-equivalent to the embedded ID. 1-line application of
the bridge to `T_TDAG_id`. Same pattern works with any of the rich
UnitaryOps equivalences (involution-pair identities, niter periodics,
etc.).
theoremc_equiv_embedU_X_X_id
theorem c_equiv_embedU_X_X_id {dim : Nat} (q : Nat) :
c_equiv (Com.embedU (UCom.seq (BaseUCom.X q : BaseUCom dim) (BaseUCom.X q)))
(Com.embedU (BaseUCom.ID q))Pauli-X involution lifted to density semantics: `embedU(X q ; X q) ⩮
embedU(ID q)`. 1-line application of the bridge to `X_X_id`.
theoremc_equiv_embedU_Y_Y_id
theorem c_equiv_embedU_Y_Y_id {dim : Nat} (q : Nat) :
c_equiv (Com.embedU (UCom.seq (BaseUCom.Y q : BaseUCom dim) (BaseUCom.Y q)))
(Com.embedU (BaseUCom.ID q))Pauli-Y involution lifted to density semantics.
theoremc_equiv_embedU_Z_Z_id
theorem c_equiv_embedU_Z_Z_id {dim : Nat} (q : Nat) :
c_equiv (Com.embedU (UCom.seq (BaseUCom.Z q : BaseUCom dim) (BaseUCom.Z q)))
(Com.embedU (BaseUCom.ID q))Pauli-Z involution lifted to density semantics.
theoremc_equiv_embedU_H_H_id
theorem c_equiv_embedU_H_H_id {dim : Nat} (q : Nat) :
c_equiv (Com.embedU (UCom.seq (BaseUCom.H q : BaseUCom dim) (BaseUCom.H q)))
(Com.embedU (BaseUCom.ID q))Hadamard involution lifted to density semantics.
theoremc_equiv_embedU_CCX_CCX_id
theorem c_equiv_embedU_CCX_CCX_id {dim : Nat} (a b c : Nat) (h0 : 0 < dim)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
c_equiv (Com.embedU (UCom.seq (BaseUCom.CCX a b c : BaseUCom dim)
(BaseUCom.CCX a b c)))
(Com.embedU (BaseUCom.ID 0))Toffoli involution lifted to density semantics: at the density layer,
`embedU(CCX a b c ; CCX a b c) ⩮ embedU(ID 0)` for any `dim ≥ 1`.
1-line application of `c_equiv_of_uc_equiv` to the unitary-level
`CCX_CCX_id` in `Framework.PadAction`.
theoremc_equiv_embedU_CCX_control_symm
theorem c_equiv_embedU_CCX_control_symm {dim : Nat} (a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
c_equiv (Com.embedU (BaseUCom.CCX a b c : BaseUCom dim))
(Com.embedU (BaseUCom.CCX b a c))Toffoli control symmetry lifted to density semantics: at the
density layer, `embedU (CCX a b c) ⩮ embedU (CCX b a c)`. 1-line
application of `c_equiv_of_uc_equiv` to `CCX_control_symm_equiv`.
theoremc_equiv_embedU_TDAG_T_id
theorem c_equiv_embedU_TDAG_T_id {dim : Nat} (q : Nat) :
c_equiv (Com.embedU (UCom.seq (BaseUCom.TDAG q : BaseUCom dim) (BaseUCom.T q)))
(Com.embedU (BaseUCom.ID q))T†·T inverse-pair lifted to density semantics.
theoremc_equiv_embedU_S_SDAG_id
theorem c_equiv_embedU_S_SDAG_id {dim : Nat} (q : Nat) :
c_equiv (Com.embedU (UCom.seq (BaseUCom.S q : BaseUCom dim) (BaseUCom.SDAG q)))
(Com.embedU (BaseUCom.ID q))S·S† inverse-pair lifted to density semantics.
theoremc_equiv_embedU_SDAG_S_id
theorem c_equiv_embedU_SDAG_S_id {dim : Nat} (q : Nat) :
c_equiv (Com.embedU (UCom.seq (BaseUCom.SDAG q : BaseUCom dim) (BaseUCom.S q)))
(Com.embedU (BaseUCom.ID q))S†·S inverse-pair lifted to density semantics.
theoremc_equiv_embedU_niter_eight_T_eq_ID
theorem c_equiv_embedU_niter_eight_T_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
c_equiv (Com.embedU (niter 8 (BaseUCom.T q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter T period-8 lifted to density semantics: `embedU(T⁸) ⩮ embedU(ID)`.
1-line application of the bridge to `niter_eight_T_eq_ID`. Demonstrates
that the niter periodic identities (not just inverse-pair compositions)
also lift cleanly through the density bridge.
theoremc_equiv_embedU_niter_eight_TDAG_eq_ID
theorem c_equiv_embedU_niter_eight_TDAG_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
c_equiv (Com.embedU (niter 8 (BaseUCom.TDAG q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter T† period-8 lifted to density semantics: `embedU(T†⁸) ⩮ embedU(ID)`.
theoremc_equiv_embedU_niter_four_S_eq_ID
theorem c_equiv_embedU_niter_four_S_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
c_equiv (Com.embedU (niter 4 (BaseUCom.S q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter S period-4 lifted to density semantics: `embedU(S⁴) ⩮ embedU(ID)`.
theoremc_equiv_embedU_niter_four_SDAG_eq_ID
theorem c_equiv_embedU_niter_four_SDAG_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
c_equiv (Com.embedU (niter 4 (BaseUCom.SDAG q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter S† period-4 lifted to density semantics: `embedU(S†⁴) ⩮ embedU(ID)`.
theoremc_equiv_embedU_niter_two_X_eq_ID
theorem c_equiv_embedU_niter_two_X_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
c_equiv (Com.embedU (niter 2 (BaseUCom.X q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter X involution period-2 lifted to density semantics:
`embedU(X²) ⩮ embedU(ID)`. First Pauli niter lift.
theoremc_equiv_embedU_niter_two_Y_eq_ID
theorem c_equiv_embedU_niter_two_Y_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
c_equiv (Com.embedU (niter 2 (BaseUCom.Y q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter Y involution period-2 lifted to density semantics.
theoremc_equiv_embedU_niter_two_Z_eq_ID
theorem c_equiv_embedU_niter_two_Z_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
c_equiv (Com.embedU (niter 2 (BaseUCom.Z q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter Z involution period-2 lifted to density semantics.
theoremc_equiv_embedU_niter_two_H_eq_ID
theorem c_equiv_embedU_niter_two_H_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
c_equiv (Com.embedU (niter 2 (BaseUCom.H q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter H involution period-2 lifted to density semantics.
Completes the Pauli/H period-2 density lift set.
defmeasure
def measure {dim : Nat} (n : Nat) : BaseCom dimA simple measurement of qubit `n`: measure, discard outcome.
-- SQIR/SQIR/DensitySem.v: `Definition measure n := meas n SKIP SKIP`.
theoremc_eval_measure
theorem c_eval_measure {dim : Nat} (n : Nat) (ρ : DensityMat dim) :
c_eval (measure n : BaseCom dim) ρ
= proj n dim true * ρ * (proj n dim true).conjTranspose
+ proj n dim false * ρ * (proj n dim false).conjTransposeDensity-matrix semantics of measurement: ρ ↦ P₁ ρ P₁† + P₀ ρ P₀†.
-- SQIR/SQIR/DensitySem.v line 107: c_eval_measure.
theoremc_eval_add
theorem c_eval_add {dim : Nat} (c : BaseCom dim) (ρ₁ ρ₂ : DensityMat dim) :
c_eval c (ρ₁ + ρ₂) = c_eval c ρ₁ + c_eval c ρ₂Additivity of `c_eval` in the density matrix: applying c to (ρ₁+ρ₂)
gives c_eval c ρ₁ + c_eval c ρ₂. Companion to c_eval_smul; together
they establish c_eval is a linear functional in ρ.
theoremc_eval_smul
theorem c_eval_smul {dim : Nat} (c : BaseCom dim) (k : ℂ) (ρ : DensityMat dim) :
c_eval c (k • ρ) = k • c_eval c ρLinearity of `c_eval` in the density matrix: scaling ρ by k scales the
result by k. Holds for every BaseCom (induction over c).
-- SQIR/SQIR/DensitySem.v line 100: c_eval_scale.
theoremc_eval_neg
theorem c_eval_neg {dim : Nat} (c : BaseCom dim) (ρ : DensityMat dim) :
c_eval c (-ρ) = -c_eval c ρNegation passes through `c_eval` (corollary of c_eval_smul with k = -1).
theoremc_eval_sub
theorem c_eval_sub {dim : Nat} (c : BaseCom dim) (ρ₁ ρ₂ : DensityMat dim) :
c_eval c (ρ₁ - ρ₂) = c_eval c ρ₁ - c_eval c ρ₂Subtraction passes through `c_eval` (corollary of c_eval_add and c_eval_neg).
theoremc_eval_zero
theorem c_eval_zero {dim : Nat} (c : BaseCom dim) :
c_eval c (0 : DensityMat dim) = 0The zero density matrix is preserved by every program.
-- SQIR/SQIR/DensitySem.v line 93: c_eval_0.
theoremc_eval_finset_sum
theorem c_eval_finset_sum {dim : Nat} (c : BaseCom dim)
{α : Type*} (s : Finset α) (f : α → DensityMat dim) :
c_eval c (∑ i ∈ s, f i) = ∑ i ∈ s, c_eval c (f i)`c_eval` distributes over Finset sums. Generalizes `c_eval_add` to
arbitrary finite sums via Finset induction.
theoremc_eval_meas_same
theorem c_eval_meas_same {dim : Nat} (n : Nat) (c : BaseCom dim)
(ρ : DensityMat dim) :
c_eval (Com.meas n c c) ρ
= c_eval c (proj n dim true * ρ * (proj n dim true).conjTranspose
+ proj n dim false * ρ * (proj n dim false).conjTranspose)Measurement with identical branches: when both branches are the same
command `c`, the projections sum first inside, then `c_eval c` is
applied — i.e., `c` is unconditionally applied to the measure-and-
forget channel output. Direct application of `c_eval_add`.
theoremc_equiv_meas_same_eq_measure_useq
theorem c_equiv_meas_same_eq_measure_useq {dim : Nat} (n : Nat) (c : BaseCom dim) :
c_equiv (Com.meas n c c) (Com.useq (measure n) c)Operational refactoring: `meas n c c ⩮ measure n ; c`. When both
measurement branches are the same command, the measurement can be
extracted as a separate prefix and then `c` applied to the result.
Direct chain of `c_eval_meas_same` with the definitional unfolding
of useq.
FormalRV.Core.Gate
FormalRV/Core/Gate.lean
FormalRV.Framework.Gate — quantum circuit IR + resource accounting.
Mirrors SQIR's `bccom` (RCIR) and `ucom` (SQIR) deep embeddings, but
Lean-native and minimal: just the gate set BQ-Algo needs to express
Cuccaro / Gidney 2018 / windowed arithmetic / etc., plus tcount/gcount/depth.
This is the SQIR analogue layer 1 (gate IR). Layer 2 (semantics) is
`Framework.Semantics`. Layer 3 (full quantum / unitary matrices) is
deferred until BQ-Algo gets to QPE — at the RCIR level (bit-vector
semantics), arithmetic correctness can be proved without complex matrices.
inductiveGate
inductive Gate
Reversible classical / Clifford+Toffoli circuit IR.
Constructors:
- `I` — identity (no-op)
- `X q` — bit-flip on qubit `q`
- `CX c t` — controlled-NOT, control `c`, target `t`
- `CCX a b t` — Toffoli, controls `a` `b`, target `t`
(the only gate with nonzero T-count in this base IR)
- `seq g₁ g₂` — sequential composition (`g₁` first, then `g₂`)
Future quantum-only gates (`H`, `T`, `Rz`, ...) will go in
`Framework/QuantumGate.lean` when we need QPE-level reasoning.
deftcount
def tcount : Gate → Nat | I => 0 | X _ => 0 | CX _ _ => 0 | CCX _ _ _ => 7 | seq g₁ g₂ => tcount g₁ + tcount g₂
T-gate count under the textbook 7-T Toffoli decomposition.
Cliffords (X, CX) and identity are free. Optimizations like
Gidney 2018's logical-AND (4-T per Toffoli) appear as separate
Gate variants in `BQAlgo/Gidney2018.lean`, NOT by mutating tcount.
defgcount
def gcount : Gate → Nat | I => 0 | X _ => 1 | CX _ _ => 1 | CCX _ _ _ => 1 | seq g₁ g₂ => gcount g₁ + gcount g₂
Total gate count (each primitive = 1, identity = 0).
defdepth
def depth : Gate → Nat | I => 0 | X _ => 1 | CX _ _ => 1 | CCX _ _ _ => 1 | seq g₁ g₂ => depth g₁ + depth g₂
Sequential depth (sum of primitive depths).
True parallel depth would require a `par` constructor and a different
cost — a Cuccaro adder is sequential, so this suffices for now.
example(example)
example : tcount (CCX 0 1 2) = 7
example(example)
example : gcount (CCX 0 1 2) = 1
example(example)
example : depth (CCX 0 1 2) = 1
example(example)
example : tcount (seq (X 0) (CCX 0 1 2)) = 7
example(example)
example : gcount (seq (X 0) (CCX 0 1 2)) = 2
example(example)
example : depth (seq (X 0) (CCX 0 1 2)) = 2
FormalRV.Core.GateDecompositions
FormalRV/Core/GateDecompositions.lean
FormalRV.Framework.GateDecompositions — gate identity theorems.
Lean translation skeleton of `SQIR/SQIR/GateDecompositions.v` (1649 LOC
of Coq). The headline target is `CCX_correct`: the 7-T Toffoli decomposition
in `BaseUCom.CCX` has the same matrix semantics as the abstract Toffoli.
## Status (2026-05-05)
- PROVEN in Lean: `toffoliMatrix_mul_toffoliMatrix` (Toffoli is involution).
- DEFERRED to SQIR (G-T axioms): `f_to_vec_CCX`, `CCX_eq_toffoliMatrix`.
See per-axiom docstrings for the closure plan and SQIR proof refs.
deftoffoliMatrix
def toffoliMatrix : Matrix (Fin 8) (Fin 8) ℂ
The 8×8 Toffoli (CCX) matrix.
theoremtoffoliMatrix_mul_toffoliMatrix
theorem toffoliMatrix_mul_toffoliMatrix :
toffoliMatrix * toffoliMatrix = (1 : Matrix (Fin 8) (Fin 8) ℂ)Toffoli is its own inverse.
theoremf_to_vec_CCX
theorem f_to_vec_CCX (dim a b c : Nat) (f : Nat → Bool)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
uc_eval (BaseUCom.CCX a b c : BaseUCom dim) * f_to_vec dim f
= f_to_vec dim (update f c (xor (f c) (f a && f b)))`f_to_vec_CCX` from SQIR. Action of the 7-T Toffoli decomposition on a
basis state.
PROVEN as `Framework.PadAction.f_to_vec_CCX_proved` modulo the named
`CCX_PHASE_CANCEL` sorry (8-case Complex.exp algebra inside the
underlying `f_to_vec_CCX_left_proved`). Re-exported here as a theorem
matching SQIR's UnitaryOps.v signature.
theoremCCX_eq_toffoliMatrix
theorem CCX_eq_toffoliMatrix :
uc_eval (BaseUCom.CCX 0 1 2 : BaseUCom 3) = toffoliMatrixMatrix-equality form of CCX correctness. Not a SQIR theorem (SQIR uses
`f_to_vec_CCX`); kept for the review work.
Proof: matrix_eq_of_basis_action reduces to 8 column-equality cases.
Case k=0 discharged below; cases k ∈ {1..7} are named-sorried as
`CCX_TOFFOLI_BASIS_k`.
theoremniter_four_T_eq_Z
theorem niter_four_T_eq_Z {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 4 (T q : BaseUCom dim)) (Z q)`niter 4 (T q) ≡ Z q` — applying T four times via iteration equals Z.
Combines `uc_eval_niter` with the matrix-level `tMatrix_pow_four`.
Lives here because it needs both `niter` (UnitaryOps) and
`tMatrix_pow_four` (PadAction).
theoremniter_four_TDAG_eq_Z
theorem niter_four_TDAG_eq_Z {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 4 (TDAG q : BaseUCom dim)) (Z q)`niter 4 (TDAG q) ≡ Z q` — T†⁴ = Z (dagger version of `niter_four_T_eq_Z`).
theoremniter_four_S_eq_SKIP
theorem niter_four_S_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 4 (S q : BaseUCom dim)) SKIP`niter 4 (S q) ≡ SKIP` — S has order 4 (S⁴ = I).
theoremniter_four_SDAG_eq_SKIP
theorem niter_four_SDAG_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 4 (SDAG q : BaseUCom dim)) SKIP`niter 4 (SDAG q) ≡ SKIP` — S† has order 4 (S†⁴ = I).
theoremniter_two_T_eq_S
theorem niter_two_T_eq_S {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 2 (T q : BaseUCom dim)) (S q)`niter 2 (T q) ≡ S q` — T² = S.
theoremniter_two_TDAG_eq_SDAG
theorem niter_two_TDAG_eq_SDAG {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 2 (TDAG q : BaseUCom dim)) (SDAG q)`niter 2 (TDAG q) ≡ SDAG q` — T†² = S†.
theoremniter_two_S_eq_Z
theorem niter_two_S_eq_Z {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 2 (S q : BaseUCom dim)) (Z q)`niter 2 (S q) ≡ Z q` — S² = Z.
theoremniter_two_SDAG_eq_Z
theorem niter_two_SDAG_eq_Z {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 2 (SDAG q : BaseUCom dim)) (Z q)`niter 2 (SDAG q) ≡ Z q` — S†² = Z.
theoremniter_three_T_eq_TS
theorem niter_three_T_eq_TS {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 3 (T q : BaseUCom dim)) (UCom.seq (T q) (S q))`niter 3 (T q) ≡ T q ; S q` — T³ = T·S, since T² = S so T³ = (T²)·T = S·T,
which at uc_eval level is `pad_u sMatrix * pad_u tMatrix = uc_eval (T q ; S q)`.
theoremniter_three_TDAG_eq_TDAG_SDAG
theorem niter_three_TDAG_eq_TDAG_SDAG {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 3 (TDAG q : BaseUCom dim)) (UCom.seq (TDAG q) (SDAG q))`niter 3 (TDAG q) ≡ TDAG q ; SDAG q` — T†³ = T†·S†, since T†² = S†.
theoremniter_three_S_eq_SDAG
theorem niter_three_S_eq_SDAG {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 3 (S q : BaseUCom dim)) (SDAG q)`niter 3 (S q) ≡ S† q` — S³ = S† (S has order 4).
theoremniter_three_SDAG_eq_S
theorem niter_three_SDAG_eq_S {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 3 (SDAG q : BaseUCom dim)) (S q)`niter 3 (SDAG q) ≡ S q` — S†³ = S.
theoremniter_four_H_eq_SKIP
theorem niter_four_H_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 4 (H q : BaseUCom dim)) SKIP`niter 4 (H q) ≡ SKIP` — H is involutive so H⁴ = I.
theoremniter_four_X_eq_SKIP
theorem niter_four_X_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 4 (X q : BaseUCom dim)) SKIP`niter 4 (X q) ≡ SKIP` — X⁴ = (X²)² = I.
theoremniter_four_Y_eq_SKIP
theorem niter_four_Y_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 4 (Y q : BaseUCom dim)) SKIP`niter 4 (Y q) ≡ SKIP` — Y⁴ = I.
theoremproj_false_on_f_to_vec
theorem proj_false_on_f_to_vec (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
proj n dim false * f_to_vec dim f = if f n then 0 else f_to_vec dim f`proj q dim false` annihilates `f_to_vec dim f` when `f q = true`,
otherwise leaves it unchanged. Lift of `pad_u_proj0_on_f_to_vec`.
theoremproj_true_on_f_to_vec
theorem proj_true_on_f_to_vec (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
proj n dim true * f_to_vec dim f = if f n then f_to_vec dim f else 0`proj q dim true` annihilates `f_to_vec dim f` when `f q = false`,
otherwise leaves it unchanged.
theoremf_to_vec_proj_eq
theorem f_to_vec_proj_eq (dim n : Nat) (h : n < dim) (b : Bool) (f : Nat → Bool)
(hfn : f n = b) :
proj n dim b * f_to_vec dim f = f_to_vec dim f`proj q dim b * f_to_vec dim f = f_to_vec dim f` when `f q = b`.
Projection onto matching basis state acts as identity.
-- SQIR/SQIR/UnitaryOps.v line 272: f_to_vec_proj_eq.
theoremf_to_vec_proj_neq
theorem f_to_vec_proj_neq (dim n : Nat) (h : n < dim) (b : Bool) (f : Nat → Bool)
(hfn : f n ≠ b) :
proj n dim b * f_to_vec dim f = 0`proj q dim b * f_to_vec dim f = 0` when `f q ≠ b`. Projection onto
non-matching basis state annihilates.
-- SQIR/SQIR/UnitaryOps.v line 288: f_to_vec_proj_neq.
theoremf_to_vec_classical
theorem f_to_vec_classical (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
proj n dim (f n) * f_to_vec dim f = f_to_vec dim f`f_to_vec dim f` is the (f n)-eigenstate of `proj n dim`. Direct
corollary of `f_to_vec_proj_eq` with `b = f n`.
-- SQIR/SQIR/UnitaryOps.v line 306: f_to_vec_classical.
theoremf_to_vec_proj
theorem f_to_vec_proj (dim n : Nat) (h : n < dim) (b : Bool) (f : Nat → Bool) :
proj n dim b * f_to_vec dim f
= (if f n = b then (1 : ℂ) else 0) • f_to_vec dim fUnified projector-on-f_to_vec lemma: scales by 1 or 0 depending on
whether `f n` matches `b`.
-- SQIR/SQIR/UnitaryOps.v line 363: f_to_vec_proj.
theoremniter_four_Z_eq_SKIP
theorem niter_four_Z_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 4 (Z q : BaseUCom dim)) SKIP`niter 4 (Z q) ≡ SKIP` — Z⁴ = I.
theoremniter_five_T_eq_TZ
theorem niter_five_T_eq_TZ {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 5 (T q : BaseUCom dim)) (UCom.seq (T q) (Z q))`niter 5 (T q) ≡ T q ; Z q` — T⁵ = Z·T, since T⁴ = Z.
theoremniter_five_TDAG_eq_TDAG_Z
theorem niter_five_TDAG_eq_TDAG_Z {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 5 (TDAG q : BaseUCom dim)) (UCom.seq (TDAG q) (Z q))`niter 5 (TDAG q) ≡ TDAG q ; Z q` — T†⁵ = Z·T†, since T†⁴ = Z.
theoremniter_five_S_eq_S
theorem niter_five_S_eq_S {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 5 (S q : BaseUCom dim)) (S q)`niter 5 (S q) ≡ S q` — S⁵ = S, since S⁴ = I.
theoremniter_five_SDAG_eq_SDAG
theorem niter_five_SDAG_eq_SDAG {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 5 (SDAG q : BaseUCom dim)) (SDAG q)`niter 5 (SDAG q) ≡ SDAG q` — S†⁵ = S†, since S†⁴ = I.
theoremniter_five_X_eq_X
theorem niter_five_X_eq_X {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 5 (X q : BaseUCom dim)) (X q)`niter 5 (X q) ≡ X q` — X⁵ = X, since X² = I.
theoremniter_five_Y_eq_Y
theorem niter_five_Y_eq_Y {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 5 (Y q : BaseUCom dim)) (Y q)`niter 5 (Y q) ≡ Y q` — Y⁵ = Y, since Y² = I.
theoremniter_five_Z_eq_Z
theorem niter_five_Z_eq_Z {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 5 (Z q : BaseUCom dim)) (Z q)`niter 5 (Z q) ≡ Z q` — Z⁵ = Z, since Z² = I.
theoremniter_five_H_eq_H
theorem niter_five_H_eq_H {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 5 (H q : BaseUCom dim)) (H q)`niter 5 (H q) ≡ H q` — H⁵ = H, since H² = I.
theoremniter_four_X_eq_ID
theorem niter_four_X_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 4 (X q : BaseUCom dim)) (ID q)`niter 4 (X q) ≡ ID q`.
theoremniter_four_Y_eq_ID
theorem niter_four_Y_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 4 (Y q : BaseUCom dim)) (ID q)`niter 4 (Y q) ≡ ID q`.
theoremniter_four_Z_eq_ID
theorem niter_four_Z_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 4 (Z q : BaseUCom dim)) (ID q)`niter 4 (Z q) ≡ ID q`.
theoremniter_four_H_eq_ID
theorem niter_four_H_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 4 (H q : BaseUCom dim)) (ID q)`niter 4 (H q) ≡ ID q`.
theoremniter_eight_X_eq_ID
theorem niter_eight_X_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 8 (X q : BaseUCom dim)) (ID q)`niter 8 (X q) ≡ ID q` — direct 1-line application of the
`niter_two_mul_self_inv_eq_ID` template with k=4.
theoremniter_eight_Y_eq_ID
theorem niter_eight_Y_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 8 (Y q : BaseUCom dim)) (ID q)`niter 8 (Y q) ≡ ID q`.
theoremniter_eight_Z_eq_ID
theorem niter_eight_Z_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 8 (Z q : BaseUCom dim)) (ID q)`niter 8 (Z q) ≡ ID q`.
theoremniter_eight_H_eq_ID
theorem niter_eight_H_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 8 (H q : BaseUCom dim)) (ID q)`niter 8 (H q) ≡ ID q`.
FormalRV.Core.GateQASM
FormalRV/Core/GateQASM.lean
FormalRV.Core.GateQASM — emit a `Gate` IR circuit as OpenQASM, and tie the per-gate-type
counts to `tcount`. This lets an external tool (Qiskit) load the EMITTED circuit, count
its gates, and confirm the count equals the Lean-proved number — empirical justification
that the counting is correct (no Lean-only bookkeeping trick).
Proved consistency: `tcount g = 7 · numCCX g` (each Toffoli = 7 T) and
`gcount g = numX g + numCX g + numCCX g` (total = sum of per-type). So once Qiskit
confirms `#ccx` in the emitted QASM equals `numCCX g`, it has confirmed `tcount/7`.
defnumCCX
def numCCX : Gate → Nat | .CCX _ _ _ => 1 | .seq a b => numCCX a + numCCX b | _ => 0
defnumCX
def numCX : Gate → Nat | .CX _ _ => 1 | .seq a b => numCX a + numCX b | _ => 0
defnumX
def numX : Gate → Nat | .X _ => 1 | .seq a b => numX a + numX b | _ => 0
theoremtcount_eq_seven_numCCX
theorem tcount_eq_seven_numCCX (g : Gate) : tcount g = 7 * numCCX g
`tcount = 7 · (#Toffoli)`: ties the QASM `ccx` count to the proved T-count.
theoremgcount_eq_sum
theorem gcount_eq_sum (g : Gate) : gcount g = numX g + numCX g + numCCX g
`gcount = #X + #CX + #CCX`: the total gate count is the sum of the per-type counts.
defmaxQubit
def maxQubit : Gate → Nat | .I => 0 | .X q => q | .CX a b => max a b | .CCX a b c => max a (max b c) | .seq x y => max (maxQubit x) (maxQubit y)
Highest qubit index the circuit touches.
deftoQASMBody
def toQASMBody : Gate → List String
| .I => []
| .X q => [s!"x q[{q}];"]
| .CX a b => [s!"cx q[{a}], q[{b}];"]
| .CCX a b c => [s!"ccx q[{a}], q[{b}], q[{c}];"]
| .seq x y => toQASMBody x ++ toQASMBody ydeftoQASM
def toQASM (g : Gate) : String
Emit the circuit as an OpenQASM 2.0 program (Qiskit-loadable; `ccx` is native).
FormalRV.Core.NDSem
FormalRV/Core/NDSem.lean
FormalRV.Framework.NDSem — non-deterministic semantics for `Com`.
Lean translation of `SQIR/SQIR/NDSem.v` (138 LOC of Coq).
Defines the operational semantics of `Com` (programs with measurement)
as a relation `nd_eval c ψ ψ'` meaning "starting from state ψ, program c
can produce state ψ'". The relation is non-deterministic: measurement
branches.
Status: scaffolding. The inductive `nd_eval` is defined; key structural
lemmas (assoc, equiv refl/sym/trans, congruence) are sorried for the
pieces that need partial-trace / norm reasoning that mathlib's
matrix-norm API requires.
abbrevStateVec
abbrev StateVec (dim : Nat)
A `dim`-qubit pure state vector: a `2^dim`-dimensional complex column.
defbasisState
noncomputable def basisState {dim : Nat} (k : Fin (2^dim)) : StateVec dimThe k-th computational basis state |k⟩ for `k : Fin (2^dim)`.
defprob_outcome
noncomputable def prob_outcome {dim : Nat} (ψ : StateVec dim) (k : Fin (2^dim)) : ℝProbability of observing computational-basis outcome `k` when measuring
state `ψ`: `|⟨k | ψ⟩|² = |ψ k 0|²`.
defzeroState
noncomputable def zeroState (dim : Nat) : StateVec dim
The "all zeros" basis state |0...0⟩.
inductivend_eval
inductive nd_eval {dim : Nat} : BaseCom dim → StateVec dim → StateVec dim → Prop
| cskip {ψ : StateVec dim} : nd_eval Com.cskip ψ ψ
| embedU (u : BaseUCom dim) (ψ : StateVec dim) :
nd_eval (Com.embedU u) ψ (uc_eval u * ψ)
| meas_t {n : Nat} {c₁ c₂ : BaseCom dim} {ψ ψ'' : StateVec dim} :
nd_eval c₁ (BaseUCom.proj n dim true * ψ) ψ'' →
nd_eval (Com.meas n c₁ c₂) ψ ψ''
| meas_f {n : Nat} {c₁ c₂ : BaseCom dim} {ψ ψ'' : StateVec dim} :
nd_eval c₂ (BaseUCom.proj n dim false * ψ) ψ'' →
nd_eval (Com.meas n c₁ c₂) ψ ψ''
| useq {c₁ c₂ : BaseCom dim} {ψ ψ' ψ'' : StateVec dim} :
nd_eval c₁ ψ ψ' → nd_eval c₂ ψ' ψ'' →Operational semantics for `Com` (with measurement).
`nd_eval c ψ ψ'` ↔ "from input ψ, program c can output ψ'".
Non-deterministic on `meas` branches.
defnd_equiv
def nd_equiv {dim : Nat} (c₁ c₂ : BaseCom dim) : Prop`Com` equivalence under the non-deterministic semantics.
theoremnd_equiv_refl
theorem nd_equiv_refl {dim : Nat} (c : BaseCom dim) : nd_equiv c cReflexivity.
theoremnd_equiv_sym
theorem nd_equiv_sym {dim : Nat} {c₁ c₂ : BaseCom dim}
(h : nd_equiv c₁ c₂) : nd_equiv c₂ c₁Symmetry.
theoremnd_equiv_trans
theorem nd_equiv_trans {dim : Nat} {c₁ c₂ c₃ : BaseCom dim}
(h₁₂ : nd_equiv c₁ c₂) (h₂₃ : nd_equiv c₂ c₃) : nd_equiv c₁ c₃Transitivity.
theoremnd_useq_assoc
theorem nd_useq_assoc {dim : Nat} (c₁ c₂ c₃ : BaseCom dim) :
nd_equiv (Com.useq (Com.useq c₁ c₂) c₃) (Com.useq c₁ (Com.useq c₂ c₃))`useq` associativity for `Com`.
theoremnd_useq_assoc_l
theorem nd_useq_assoc_l {dim : Nat} (c₁ c₂ c₃ : BaseCom dim) :
nd_equiv (Com.useq c₁ (Com.useq c₂ c₃)) (Com.useq (Com.useq c₁ c₂) c₃)`useq` left-associativity (reverse direction): `c₁;(c₂;c₃) ≡ (c₁;c₂);c₃`.
Direct corollary of `nd_useq_assoc` via `nd_equiv_sym`.
theoremnd_useq_congr
theorem nd_useq_congr {dim : Nat} (c₁ c₁' c₂ c₂' : BaseCom dim)
(h₁ : nd_equiv c₁ c₁') (h₂ : nd_equiv c₂ c₂') :
nd_equiv (Com.useq c₁ c₂) (Com.useq c₁' c₂')Sequential composition is congruent under `nd_equiv`.
-- SQIR/SQIR/NDSem.v line 75: nd_seq_congruence.
theoremnd_cskip_useq
theorem nd_cskip_useq {dim : Nat} (c : BaseCom dim) :
nd_equiv (Com.useq Com.cskip c) c`cskip ; c ≡ c` — left identity of useq under nd_equiv.
theoremnd_useq_cskip
theorem nd_useq_cskip {dim : Nat} (c : BaseCom dim) :
nd_equiv (Com.useq c Com.cskip) c`c ; cskip ≡ c` — right identity of useq under nd_equiv.
theoremnd_eval_cskip_iff
theorem nd_eval_cskip_iff {dim : Nat} (ψ ψ' : StateVec dim) :
nd_eval (Com.cskip : BaseCom dim) ψ ψ' ↔ ψ = ψ'Inversion lemma: `nd_eval cskip ψ ψ'` iff `ψ = ψ'`.
theoremnd_eval_embedU_iff
theorem nd_eval_embedU_iff {dim : Nat} (u : BaseUCom dim) (ψ ψ' : StateVec dim) :
nd_eval (Com.embedU u) ψ ψ' ↔ ψ' = uc_eval u * ψInversion lemma: `nd_eval (embedU u) ψ ψ'` iff `ψ' = uc_eval u * ψ`.
Useful for reasoning about unitary commands inside non-deterministic
semantics — connects the unitary semantics to the operational.
theoremnd_equiv_of_uc_equiv
theorem nd_equiv_of_uc_equiv {dim : Nat} {u₁ u₂ : BaseUCom dim}
(h : UCom.equiv u₁ u₂) :
nd_equiv (Com.embedU u₁) (Com.embedU u₂)Bridge from unitary semantics to non-deterministic semantics: if two
unitary commands are `UCom.equiv` (have equal `uc_eval`), then their
embeddings into `Com` are `nd_equiv`. The natural lifting of unitary
equivalence through the operational `ψ ↦ U ψ` action.
theoremnd_equiv_useq_embedU_left
theorem nd_equiv_useq_embedU_left {dim : Nat} (c : BaseCom dim)
{u₁ u₂ : BaseUCom dim} (h : UCom.equiv u₁ u₂) :
nd_equiv (Com.useq (Com.embedU u₁) c) (Com.useq (Com.embedU u₂) c)Left-position bridge composition: substituting an equivalent unitary
in the LEFT position of a useq preserves `nd_equiv`. ND analog of
`c_equiv_useq_embedU_left`.
theoremnd_equiv_useq_embedU_right
theorem nd_equiv_useq_embedU_right {dim : Nat} (c : BaseCom dim)
{u₁ u₂ : BaseUCom dim} (h : UCom.equiv u₁ u₂) :
nd_equiv (Com.useq c (Com.embedU u₁)) (Com.useq c (Com.embedU u₂))Right-position bridge composition: symmetric companion.
theoremnd_equiv_embedU_invert_invert
theorem nd_equiv_embedU_invert_invert {dim : Nat} (c : BaseUCom dim) :
nd_equiv (Com.embedU (BaseUCom.invert (BaseUCom.invert c))) (Com.embedU c)Lifting `invert_invert` through `embedU`: `embedU(invert(invert c)) ≣
embedU(c)` at the ND layer. ND analog of
`c_equiv_embedU_invert_invert`.
theoremnd_equiv_embedU_T_TDAG_id
theorem nd_equiv_embedU_T_TDAG_id {dim : Nat} (q : Nat) :
nd_equiv (Com.embedU (UCom.seq (BaseUCom.T q : BaseUCom dim) (BaseUCom.TDAG q)))
(Com.embedU (BaseUCom.ID q))Demo of the `nd_equiv_of_uc_equiv` bridge: the embedded T·T† circuit
is ND-equivalent to the embedded ID. 1-line application of the bridge
to `T_TDAG_id`. Mirror of `c_equiv_embedU_T_TDAG_id` from DensitySem.
theoremnd_equiv_embedU_TDAG_T_id
theorem nd_equiv_embedU_TDAG_T_id {dim : Nat} (q : Nat) :
nd_equiv (Com.embedU (UCom.seq (BaseUCom.TDAG q : BaseUCom dim) (BaseUCom.T q)))
(Com.embedU (BaseUCom.ID q))T†·T inverse-pair lifted to ND semantics.
theoremnd_equiv_embedU_S_SDAG_id
theorem nd_equiv_embedU_S_SDAG_id {dim : Nat} (q : Nat) :
nd_equiv (Com.embedU (UCom.seq (BaseUCom.S q : BaseUCom dim) (BaseUCom.SDAG q)))
(Com.embedU (BaseUCom.ID q))S·S† inverse-pair lifted to ND semantics.
theoremnd_equiv_embedU_SDAG_S_id
theorem nd_equiv_embedU_SDAG_S_id {dim : Nat} (q : Nat) :
nd_equiv (Com.embedU (UCom.seq (BaseUCom.SDAG q : BaseUCom dim) (BaseUCom.S q)))
(Com.embedU (BaseUCom.ID q))S†·S inverse-pair lifted to ND semantics.
theoremnd_equiv_embedU_X_X_id
theorem nd_equiv_embedU_X_X_id {dim : Nat} (q : Nat) :
nd_equiv (Com.embedU (UCom.seq (BaseUCom.X q : BaseUCom dim) (BaseUCom.X q)))
(Com.embedU (BaseUCom.ID q))Pauli-X involution lifted to ND semantics.
theoremnd_equiv_embedU_Y_Y_id
theorem nd_equiv_embedU_Y_Y_id {dim : Nat} (q : Nat) :
nd_equiv (Com.embedU (UCom.seq (BaseUCom.Y q : BaseUCom dim) (BaseUCom.Y q)))
(Com.embedU (BaseUCom.ID q))Pauli-Y involution lifted to ND semantics.
theoremnd_equiv_embedU_Z_Z_id
theorem nd_equiv_embedU_Z_Z_id {dim : Nat} (q : Nat) :
nd_equiv (Com.embedU (UCom.seq (BaseUCom.Z q : BaseUCom dim) (BaseUCom.Z q)))
(Com.embedU (BaseUCom.ID q))Pauli-Z involution lifted to ND semantics.
theoremnd_equiv_embedU_H_H_id
theorem nd_equiv_embedU_H_H_id {dim : Nat} (q : Nat) :
nd_equiv (Com.embedU (UCom.seq (BaseUCom.H q : BaseUCom dim) (BaseUCom.H q)))
(Com.embedU (BaseUCom.ID q))Hadamard involution lifted to ND semantics.
theoremnd_equiv_embedU_CCX_CCX_id
theorem nd_equiv_embedU_CCX_CCX_id {dim : Nat} (a b c : Nat) (h0 : 0 < dim)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
nd_equiv (Com.embedU (UCom.seq (BaseUCom.CCX a b c : BaseUCom dim)
(BaseUCom.CCX a b c)))
(Com.embedU (BaseUCom.ID 0))Toffoli involution lifted to ND semantics: at the non-deterministic
layer, `embedU(CCX a b c ; CCX a b c) ⩮ embedU(ID 0)` for any
`dim ≥ 1`. 1-line application of `nd_equiv_of_uc_equiv` to the
unitary-level `CCX_CCX_id` in `Framework.PadAction`.
theoremnd_equiv_embedU_CCX_control_symm
theorem nd_equiv_embedU_CCX_control_symm {dim : Nat} (a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
nd_equiv (Com.embedU (BaseUCom.CCX a b c : BaseUCom dim))
(Com.embedU (BaseUCom.CCX b a c))Toffoli control symmetry lifted to ND semantics: at the ND layer,
`embedU (CCX a b c) ⩮ embedU (CCX b a c)`. 1-line application of
`nd_equiv_of_uc_equiv` to `CCX_control_symm_equiv`.
theoremnd_equiv_embedU_niter_eight_T_eq_ID
theorem nd_equiv_embedU_niter_eight_T_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
nd_equiv (Com.embedU (BaseUCom.niter 8 (BaseUCom.T q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter T period-8 lifted to ND semantics.
theoremnd_equiv_embedU_niter_eight_TDAG_eq_ID
theorem nd_equiv_embedU_niter_eight_TDAG_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
nd_equiv (Com.embedU (BaseUCom.niter 8 (BaseUCom.TDAG q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter T† period-8 lifted to ND semantics.
theoremnd_equiv_embedU_niter_four_S_eq_ID
theorem nd_equiv_embedU_niter_four_S_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
nd_equiv (Com.embedU (BaseUCom.niter 4 (BaseUCom.S q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter S period-4 lifted to ND semantics.
theoremnd_equiv_embedU_niter_four_SDAG_eq_ID
theorem nd_equiv_embedU_niter_four_SDAG_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
nd_equiv (Com.embedU (BaseUCom.niter 4 (BaseUCom.SDAG q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter S† period-4 lifted to ND semantics.
theoremnd_equiv_embedU_niter_two_X_eq_ID
theorem nd_equiv_embedU_niter_two_X_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
nd_equiv (Com.embedU (BaseUCom.niter 2 (BaseUCom.X q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter X involution period-2 lifted to ND semantics.
theoremnd_equiv_embedU_niter_two_Y_eq_ID
theorem nd_equiv_embedU_niter_two_Y_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
nd_equiv (Com.embedU (BaseUCom.niter 2 (BaseUCom.Y q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter Y involution period-2 lifted to ND semantics.
theoremnd_equiv_embedU_niter_two_Z_eq_ID
theorem nd_equiv_embedU_niter_two_Z_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
nd_equiv (Com.embedU (BaseUCom.niter 2 (BaseUCom.Z q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter Z involution period-2 lifted to ND semantics.
theoremnd_equiv_embedU_niter_two_H_eq_ID
theorem nd_equiv_embedU_niter_two_H_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
nd_equiv (Com.embedU (BaseUCom.niter 2 (BaseUCom.H q : BaseUCom dim)))
(Com.embedU (BaseUCom.ID q))niter H involution period-2 lifted to ND semantics.
Completes the ND-side niter periodic lift set.
theoremnd_eval_useq_iff
theorem nd_eval_useq_iff {dim : Nat} (c₁ c₂ : BaseCom dim)
(ψ ψ'' : StateVec dim) :
nd_eval (Com.useq c₁ c₂) ψ ψ''
↔ ∃ ψ' : StateVec dim, nd_eval c₁ ψ ψ' ∧ nd_eval c₂ ψ' ψ''Inversion lemma for sequence composition: `nd_eval (useq c₁ c₂) ψ ψ''`
iff there exists an intermediate state `ψ'` reachable from `ψ` via
`c₁` from which `ψ''` is reachable via `c₂`.
theoremnd_eval_meas_iff
theorem nd_eval_meas_iff {dim : Nat} (n : Nat) (c₁ c₂ : BaseCom dim)
(ψ ψ'' : StateVec dim) :
nd_eval (Com.meas n c₁ c₂) ψ ψ''
↔ nd_eval c₁ (BaseUCom.proj n dim true * ψ) ψ''
∨ nd_eval c₂ (BaseUCom.proj n dim false * ψ) ψ''Inversion lemma for measurement: `nd_eval (meas n c₁ c₂) ψ ψ''` iff
one of the two outcomes (true or false) leads to ψ'' via the
corresponding branch program.
theoremnd_equiv_useq_embedU_ID_l
theorem nd_equiv_useq_embedU_ID_l {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseCom dim) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.ID q)) c) c`embedU(ID q)` is a left-identity of `useq` at the ND layer
(when `q < dim`). ND analog of `c_equiv_useq_embedU_ID_l`.
theoremnd_equiv_useq_embedU_ID_r
theorem nd_equiv_useq_embedU_ID_r {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseCom dim) :
nd_equiv (Com.useq c (Com.embedU (BaseUCom.ID q))) c`embedU(ID q)` is also a right-identity of `useq` at the ND layer.
Symmetric companion of `nd_equiv_useq_embedU_ID_l`.
theoremnd_equiv_useq_embedU_embedU
theorem nd_equiv_useq_embedU_embedU {dim : Nat} (u₁ u₂ : BaseUCom dim) :
nd_equiv (Com.useq (Com.embedU u₁) (Com.embedU u₂))
(Com.embedU (UCom.seq u₁ u₂))Sequencing two embedded unitaries is the embedding of their sequence
at the ND layer. ND analog of `c_equiv_useq_embedU_embedU`.
theoremnd_equiv_useq_embedU_T_TDAG
theorem nd_equiv_useq_embedU_T_TDAG {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.T q : BaseUCom dim))
(Com.embedU (BaseUCom.TDAG q)))
(Com.embedU (BaseUCom.ID q))T·T† inverse pair via ND seq-merge + bridge.
theoremnd_equiv_useq_embedU_X_X
theorem nd_equiv_useq_embedU_X_X {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.X q : BaseUCom dim))
(Com.embedU (BaseUCom.X q)))
(Com.embedU (BaseUCom.ID q))Pauli-X involution via ND seq-merge + bridge.
theoremnd_equiv_useq_embedU_Y_Y
theorem nd_equiv_useq_embedU_Y_Y {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.Y q : BaseUCom dim))
(Com.embedU (BaseUCom.Y q)))
(Com.embedU (BaseUCom.ID q))Pauli-Y involution via ND seq-merge + bridge.
theoremnd_equiv_useq_embedU_Z_Z
theorem nd_equiv_useq_embedU_Z_Z {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.Z q : BaseUCom dim))
(Com.embedU (BaseUCom.Z q)))
(Com.embedU (BaseUCom.ID q))Pauli-Z involution via ND seq-merge + bridge.
theoremnd_equiv_useq_embedU_H_H
theorem nd_equiv_useq_embedU_H_H {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.H q : BaseUCom dim))
(Com.embedU (BaseUCom.H q)))
(Com.embedU (BaseUCom.ID q))Hadamard involution via ND seq-merge + bridge.
theoremnd_equiv_useq_embedU_CCX_CCX
theorem nd_equiv_useq_embedU_CCX_CCX {dim : Nat} (a b c : Nat) (h0 : 0 < dim)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.CCX a b c : BaseUCom dim))
(Com.embedU (BaseUCom.CCX a b c)))
(Com.embedU (BaseUCom.ID 0))Toffoli involution via ND seq-merge + bridge: at the ND layer,
`useq (embedU (CCX a b c)) (embedU (CCX a b c)) ⩮ embedU (ID 0)`
when `dim ≥ 1`. Mirror of `c_equiv_useq_embedU_CCX_CCX` from
DensitySem; same construction with `nd_equiv_*` primitives.
theoremnd_equiv_useq_embedU_TDAG_T
theorem nd_equiv_useq_embedU_TDAG_T {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.TDAG q : BaseUCom dim))
(Com.embedU (BaseUCom.T q)))
(Com.embedU (BaseUCom.ID q))T†·T inverse pair via ND seq-merge + bridge.
theoremnd_equiv_useq_embedU_S_SDAG
theorem nd_equiv_useq_embedU_S_SDAG {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.S q : BaseUCom dim))
(Com.embedU (BaseUCom.SDAG q)))
(Com.embedU (BaseUCom.ID q))S·S† inverse pair via ND seq-merge + bridge.
theoremnd_equiv_useq_embedU_SDAG_S
theorem nd_equiv_useq_embedU_SDAG_S {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.SDAG q : BaseUCom dim))
(Com.embedU (BaseUCom.S q)))
(Com.embedU (BaseUCom.ID q))S†·S inverse pair via ND seq-merge + bridge.
theoremnd_equiv_useq_embedU_H_Z_eq_X_H
theorem nd_equiv_useq_embedU_H_Z_eq_X_H {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.H q : BaseUCom dim))
(Com.embedU (BaseUCom.Z q)))
(Com.useq (Com.embedU (BaseUCom.X q))
(Com.embedU (BaseUCom.H q)))Hadamard interchange at the ND layer: lifts `H_comm_Z` via the
seq-merge → bridge → seq-merge⁻¹ chain. ND analog of
`c_equiv_useq_embedU_H_Z_eq_X_H`.
theoremnd_equiv_useq_embedU_H_X_eq_Z_H
theorem nd_equiv_useq_embedU_H_X_eq_Z_H {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.H q : BaseUCom dim))
(Com.embedU (BaseUCom.X q)))
(Com.useq (Com.embedU (BaseUCom.Z q))
(Com.embedU (BaseUCom.H q)))Dual Hadamard interchange at the ND layer.
theoremnd_equiv_useq_embedU_Rz_Rz_add
theorem nd_equiv_useq_embedU_Rz_Rz_add {dim : Nat} (θ θ' : ℝ) (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.Rz θ q : BaseUCom dim))
(Com.embedU (BaseUCom.Rz θ' q)))
(Com.embedU (BaseUCom.Rz (θ + θ') q))Z-rotation composition lifted to ND. ND analog of
`c_equiv_useq_embedU_Rz_Rz_add`.
theoremnd_equiv_useq_embedU_Rz_neg_id
theorem nd_equiv_useq_embedU_Rz_neg_id {dim : Nat} (θ : ℝ) (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.Rz θ q : BaseUCom dim))
(Com.embedU (BaseUCom.Rz (-θ) q)))
(Com.embedU (BaseUCom.ID q))Parametric Rz cancellation lifted to ND. ND analog of
`c_equiv_useq_embedU_Rz_neg_id`.
theoremnd_equiv_embedU_Rz_zero_eq_ID
theorem nd_equiv_embedU_Rz_zero_eq_ID {dim : Nat} (q : Nat) :
nd_equiv (Com.embedU (BaseUCom.Rz 0 q : BaseUCom dim))
(Com.embedU (BaseUCom.ID q))Trivial Z-rotation = ID at ND: `embedU(Rz 0 q) ≣ embedU(ID q)`.
ND analog of `c_equiv_embedU_Rz_zero_eq_ID`.
theoremnd_equiv_useq_embedU_T_T_eq_S
theorem nd_equiv_useq_embedU_T_T_eq_S {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.T q : BaseUCom dim))
(Com.embedU (BaseUCom.T q)))
(Com.embedU (BaseUCom.S q))T·T = S at ND: ND analog of `c_equiv_useq_embedU_T_T_eq_S`.
theoremnd_equiv_useq_embedU_S_S_eq_Z
theorem nd_equiv_useq_embedU_S_S_eq_Z {dim : Nat} (q : Nat) :
nd_equiv (Com.useq (Com.embedU (BaseUCom.S q : BaseUCom dim))
(Com.embedU (BaseUCom.S q)))
(Com.embedU (BaseUCom.Z q))S·S = Z at ND: ND analog of `c_equiv_useq_embedU_S_S_eq_Z`.
theoremnd_meas_congr
theorem nd_meas_congr {dim : Nat} (n : Nat) {c₁ c₁' c₂ c₂' : BaseCom dim}
(h₁ : nd_equiv c₁ c₁') (h₂ : nd_equiv c₂ c₂') :
nd_equiv (Com.meas n c₁ c₂) (Com.meas n c₁' c₂')Measurement is congruent under `nd_equiv` on each branch. ND analog of
`c_meas_congr` from DensitySem.
theoremnd_equiv_meas_same_eq_measure_useq
theorem nd_equiv_meas_same_eq_measure_useq {dim : Nat} (n : Nat) (c : BaseCom dim) :
nd_equiv (Com.meas n c c)
(Com.useq (Com.meas n Com.cskip Com.cskip) c)Operational refactoring: `meas n c c ≣ (measure n) ; c` at the ND
layer (where `measure n := meas n cskip cskip` per DensitySem). The
forward direction picks the same branch on the right; the reverse
direction destructures the cskip witnesses and case-splits on the
intermediate state. ND analog of `c_equiv_meas_same_eq_measure_useq`.
FormalRV.Core.PadAction
FormalRV/Core/PadAction.lean
(no documented top-level declarations)
FormalRV.Core.PadAction.CCXToffoliComplete
FormalRV/Core/PadAction/CCXToffoliComplete.lean
theoremf_to_vec_H_X_H
theorem f_to_vec_H_X_H (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.X n))
(BaseUCom.H n))
* f_to_vec dim f
= (if f n then (-1 : ℂ) else 1) • f_to_vec dim f`H q ; X q ; H q` acts as Z on `f_to_vec dim f` (Hadamard sandwich).
theoremf_to_vec_H_Z_H
theorem f_to_vec_H_Z_H (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.Z n))
(BaseUCom.H n))
* f_to_vec dim f
= f_to_vec dim (update f n (!f n))`H q ; Z q ; H q` acts as X (bit flip) on `f_to_vec dim f`.
theoremf_to_vec_H_comm_Z
theorem f_to_vec_H_comm_Z (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.Z n)) * f_to_vec dim f
= uc_eval (UCom.seq (BaseUCom.X n) (BaseUCom.H n)) * f_to_vec dim f`H q ; Z q` and `X q ; H q` agree on `f_to_vec dim f`. Hadamard
interchange at the f-coord level (lift of `H_comm_Z`).
theoremf_to_vec_H_comm_X
theorem f_to_vec_H_comm_X (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.X n)) * f_to_vec dim f
= uc_eval (UCom.seq (BaseUCom.Z n) (BaseUCom.H n)) * f_to_vec dim f`H q ; X q` and `Z q ; H q` agree on `f_to_vec dim f`. Dual interchange.
theoremf_to_vec_CCX_left_proved
theorem f_to_vec_CCX_left_proved (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.CNOT a b))
(BaseUCom.TDAG b))theoremuc_eval_CCX_eq_left_chain
theorem uc_eval_CCX_eq_left_chain (dim a b c : Nat) :
uc_eval (BaseUCom.CCX a b c : BaseUCom dim)
= uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.CNOT a b))
(BaseUCom.TDAG b))
(BaseUCom.CNOT a b))theoremf_to_vec_CCX_proved
theorem f_to_vec_CCX_proved (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (BaseUCom.CCX a b c : BaseUCom dim) * f_to_vec dim f
= f_to_vec dim (update f c (xor (f c) (f a && f b)))SQIR-faithful form of `f_to_vec_CCX`, derived from the left-chain
proof + right-association bridge. Matches the axiom statement in
`Framework.GateDecompositions`.
theoremf_to_vec_CCX_no_op
theorem f_to_vec_CCX_no_op (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool)
(h : (f a && f b) = false) :
uc_eval (BaseUCom.CCX a b c : BaseUCom dim) * f_to_vec dim f
= f_to_vec dim fCorollary: when at least one control bit is 0, CCX leaves the state
unchanged.
theoremf_to_vec_CCX_flip
theorem f_to_vec_CCX_flip (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool)
(hfa : f a = true) (hfb : f b = true) :
uc_eval (BaseUCom.CCX a b c : BaseUCom dim) * f_to_vec dim f
= f_to_vec dim (update f c (!f c))Corollary: when both control bits are 1, CCX flips the target bit.
theoremf_to_vec_CCX_involutive
theorem f_to_vec_CCX_involutive (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (BaseUCom.CCX a b c : BaseUCom dim) *
(uc_eval (BaseUCom.CCX a b c : BaseUCom dim) * f_to_vec dim f)
= f_to_vec dim fCCX is its own inverse on basis vectors: applying it twice returns the
original state. Follows from `f_to_vec_CCX_proved` plus the fact that
`update_neq` keeps the controls a, b unchanged across the inner update,
so the second xor flips back what the first xor flipped.
-- SQIR/SQIR/UnitaryOps.v analog: CCX is the Toffoli gate, an involution.
theoremmatrix_eq_of_basis_action
theorem matrix_eq_of_basis_action {n : Nat} (M N : Matrix (Fin n) (Fin n) ℂ)
(h : ∀ k : Fin n, M * basis_vector n k.val = N * basis_vector n k.val) :
M = NTwo square matrices are equal iff their actions on all basis vectors agree.
theoremfunbool_to_nat_nat_to_funbool
theorem funbool_to_nat_nat_to_funbool (n j : Nat) (h : j < 2^n) :
funbool_to_nat n (nat_to_funbool n j) = jInverse property: `funbool_to_nat n (nat_to_funbool n j) = j` for `j < 2^n`.
theorembasis_vector_eq_f_to_vec_nat
theorem basis_vector_eq_f_to_vec_nat (n j : Nat) (h : j < 2^n) :
basis_vector (2^n) j = f_to_vec n (nat_to_funbool n j)Bridge: every basis vector at index `j < 2^n` can be written as
`f_to_vec` of the inverse-funbool-to-nat function. Nat-indexed form,
avoids `Fin (2^n)` vs `Fin 8` unification friction.
theorembasis_vector_eq_f_to_vec_nat_to_funbool
theorem basis_vector_eq_f_to_vec_nat_to_funbool (n : Nat) (j : Fin (2^n)) :
basis_vector (2^n) j.val = f_to_vec n (nat_to_funbool n j.val)Fin-indexed version (legacy).
theoremnat_to_funbool_3_0_eq_false
theorem nat_to_funbool_3_0_eq_false (i : Nat) :
nat_to_funbool 3 0 i = falseFor k.val = 0: nat_to_funbool 3 0 i = false for all i.
theoremnat_to_funbool_3_1_zero
theorem nat_to_funbool_3_1_zero : nat_to_funbool 3 1 0 = false
For k.val = 1 = 001₂: bit pattern is (false, false, true) at indices (0, 1, 2).
theoremnat_to_funbool_3_1_one
theorem nat_to_funbool_3_1_one : nat_to_funbool 3 1 1 = false
theoremnat_to_funbool_3_1_two
theorem nat_to_funbool_3_1_two : nat_to_funbool 3 1 2 = true
theoremnat_to_funbool_3_2_zero
theorem nat_to_funbool_3_2_zero : nat_to_funbool 3 2 0 = false
For k.val = 2 = 010₂: bit pattern (false, true, false).
theoremnat_to_funbool_3_2_one
theorem nat_to_funbool_3_2_one : nat_to_funbool 3 2 1 = true
theoremnat_to_funbool_3_2_two
theorem nat_to_funbool_3_2_two : nat_to_funbool 3 2 2 = false
theoremnat_to_funbool_3_3_zero
theorem nat_to_funbool_3_3_zero : nat_to_funbool 3 3 0 = false
For k.val = 3 = 011₂: bit pattern (false, true, true).
theoremnat_to_funbool_3_3_one
theorem nat_to_funbool_3_3_one : nat_to_funbool 3 3 1 = true
theoremnat_to_funbool_3_3_two
theorem nat_to_funbool_3_3_two : nat_to_funbool 3 3 2 = true
theoremnat_to_funbool_3_4_zero
theorem nat_to_funbool_3_4_zero : nat_to_funbool 3 4 0 = true
For k.val = 4 = 100₂: bit pattern (true, false, false).
theoremnat_to_funbool_3_4_one
theorem nat_to_funbool_3_4_one : nat_to_funbool 3 4 1 = false
theoremnat_to_funbool_3_4_two
theorem nat_to_funbool_3_4_two : nat_to_funbool 3 4 2 = false
theoremnat_to_funbool_3_5_zero
theorem nat_to_funbool_3_5_zero : nat_to_funbool 3 5 0 = true
For k.val = 5 = 101₂: bit pattern (true, false, true).
theoremnat_to_funbool_3_5_one
theorem nat_to_funbool_3_5_one : nat_to_funbool 3 5 1 = false
theoremnat_to_funbool_3_5_two
theorem nat_to_funbool_3_5_two : nat_to_funbool 3 5 2 = true
theoremnat_to_funbool_3_6_zero
theorem nat_to_funbool_3_6_zero : nat_to_funbool 3 6 0 = true
For k.val = 6 = 110₂: bit pattern (true, true, false).
theoremnat_to_funbool_3_6_one
theorem nat_to_funbool_3_6_one : nat_to_funbool 3 6 1 = true
theoremnat_to_funbool_3_6_two
theorem nat_to_funbool_3_6_two : nat_to_funbool 3 6 2 = false
theoremnat_to_funbool_3_7_zero
theorem nat_to_funbool_3_7_zero : nat_to_funbool 3 7 0 = true
For k.val = 7 = 111₂: bit pattern (true, true, true).
theoremnat_to_funbool_3_7_one
theorem nat_to_funbool_3_7_one : nat_to_funbool 3 7 1 = true
theoremnat_to_funbool_3_7_two
theorem nat_to_funbool_3_7_two : nat_to_funbool 3 7 2 = true
theoremCCX_CCX_eq_one
theorem CCX_CCX_eq_one (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
uc_eval (BaseUCom.CCX a b c : BaseUCom dim) *
uc_eval (BaseUCom.CCX a b c : BaseUCom dim)
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level Toffoli involution: applying CCX twice is the identity matrix.
Lifted from `f_to_vec_CCX_involutive` via `matrix_eq_of_basis_action`.
-- SQIR/SQIR/UnitaryOps.v analog: CCX is self-inverse (involution).
theoremCCX_CCX_id
theorem CCX_CCX_id {dim : Nat} (a b c : Nat) (h0 : 0 < dim)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
UCom.equiv
(UCom.seq (BaseUCom.CCX a b c : BaseUCom dim) (BaseUCom.CCX a b c))
(BaseUCom.ID 0)UCom.equiv form of `CCX_CCX_eq_one`: at the circuit level,
`CCX a b c ; CCX a b c ≅ ID 0` whenever `dim ≥ 1`. Useful for
Toffoli-pair cancellation in circuit-level rewriting.
-- SQIR/SQIR/Equivalences.v analog: SKIP-style identity (X_X_id pattern).
theoremf_to_vec_CCX_CCX_CCX
theorem f_to_vec_CCX_CCX_CCX (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.CCX a b c : BaseUCom dim)
(BaseUCom.CCX a b c))
(BaseUCom.CCX a b c))
* f_to_vec dim f
= f_to_vec dim (update f c (xor (f c) (f a && f b)))`CCX a b c ; CCX a b c ; CCX a b c` acts as a single CCX on
`f_to_vec dim f` (CCX³ = CCX, since CCX² = ID). Direct corollary
of `CCX_CCX_eq_one` (matrix-level) + `f_to_vec_CCX_proved`.
Completes the 3-chain family on basis states: X³, Z³, CNOT³, CCX³.
-- SQIR/SQIR/UnitaryOps.v analog: Toffoli 3-chain identity.
theoremf_to_vec_X_X_X_X_X
theorem f_to_vec_X_X_X_X_X (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.X n : BaseUCom dim) (BaseUCom.X n))
(BaseUCom.X n)) (BaseUCom.X n)) (BaseUCom.X n))
* f_to_vec dim f
= f_to_vec dim (update f n (!f n))`X q ; X q ; X q ; X q ; X q` acts as a single X on `f_to_vec dim f`
(X⁵ = X, since X⁴ = ID). Iter 101 extension of the basis-state
Pauli-chain family. Useful for circuit-rewriting passes that
encounter X-gate odd-length chains.
theoremf_to_vec_Z_Z_Z_Z_Z
theorem f_to_vec_Z_Z_Z_Z_Z (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.Z n : BaseUCom dim) (BaseUCom.Z n))
(BaseUCom.Z n)) (BaseUCom.Z n)) (BaseUCom.Z n))
* f_to_vec dim f
= (if f n then (-1 : ℂ) else 1) • f_to_vec dim f`Z q ; Z q ; Z q ; Z q ; Z q` acts as a single Z on `f_to_vec dim f`
(Z⁵ = Z, since Z⁴ = ID). Mirrors `f_to_vec_X_X_X_X_X` (Iter 101)
for the Pauli Z gate's cyclic phase action. Useful for circuit-
rewriting passes that encounter Z-gate odd-length chains.
theoremCNOT_CNOT_eq_one
theorem CNOT_CNOT_eq_one (dim i j : Nat)
(hi : i < dim) (hj : j < dim) (hij : i ≠ j) :
uc_eval (UCom.seq (BaseUCom.CNOT i j : BaseUCom dim) (BaseUCom.CNOT i j))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level CNOT involution: applying CNOT twice is the identity matrix.
Lifted from `f_to_vec_CNOT_CNOT` via `matrix_eq_of_basis_action`.
theoremCNOT_CNOT_id
theorem CNOT_CNOT_id {dim : Nat} (i j : Nat) (h0 : 0 < dim)
(hi : i < dim) (hj : j < dim) (hij : i ≠ j) :
UCom.equiv
(UCom.seq (UCom.seq (BaseUCom.CNOT i j : BaseUCom dim) (BaseUCom.CNOT i j))
(BaseUCom.ID 0))
(BaseUCom.ID 0)UCom.equiv form of `CNOT_CNOT_eq_one`: at the circuit level,
`CNOT i j ; CNOT i j ≅ ID 0` whenever `dim ≥ 1`.
theoremf_to_vec_seq_CCX_CCX_eq_self
theorem f_to_vec_seq_CCX_CCX_eq_self (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.CCX a b c : BaseUCom dim) (BaseUCom.CCX a b c))
* f_to_vec dim f
= f_to_vec dim f*Seq-form basis-state lift** of `CCX_CCX_eq_one`. Cleaner
statement than `f_to_vec_CCX_involutive` (product form): uses
`UCom.seq` directly. Useful for chained rewrites at the seq
level. -- SQIR/SQIR/Equivalences.v: CCX_CCX_id at basis state.
theoremf_to_vec_seq_CNOT_CNOT_eq_self
theorem f_to_vec_seq_CNOT_CNOT_eq_self (dim i j : Nat)
(hi : i < dim) (hj : j < dim) (hij : i ≠ j) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.CNOT i j : BaseUCom dim) (BaseUCom.CNOT i j))
* f_to_vec dim f
= f_to_vec dim f*Seq-form basis-state lift** of `CNOT_CNOT_eq_one`. The matrix-
level theorem is ALREADY in seq form, so the `rw` applies
directly without a `show`.
theoremX_X_eq_one
theorem X_X_eq_one (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (BaseUCom.X n : BaseUCom dim) (BaseUCom.X n))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level X involution: applying X twice is the identity matrix.
Lifted from `f_to_vec_X_X` via `matrix_eq_of_basis_action`.
*Completes the X/CNOT/CCX matrix-level involution family** —
each is a single-line application of the basis-action lift, using
the existing per-gate basis-state involutions.
theoremY_Y_eq_one
theorem Y_Y_eq_one (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (BaseUCom.Y n : BaseUCom dim) (BaseUCom.Y n))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level Y involution: applying Y twice is the identity matrix.
Lifted from `f_to_vec_Y_Y` via `matrix_eq_of_basis_action`.
theoremZ_Z_eq_one
theorem Z_Z_eq_one (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (BaseUCom.Z n : BaseUCom dim) (BaseUCom.Z n))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level Z involution: applying Z twice is the identity matrix.
Lifted from `f_to_vec_Z_Z` via `matrix_eq_of_basis_action`.
theoremH_H_eq_one
theorem H_H_eq_one (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.H n))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level H involution: applying H twice is the identity matrix.
Lifted from `f_to_vec_H_H` via `matrix_eq_of_basis_action`.
*Extends the Pauli involution family** (X/Y/Z/H) to matrix-level.
theoremX_X_X_X_eq_one
theorem X_X_X_X_eq_one (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.X n : BaseUCom dim)
(BaseUCom.X n))
(BaseUCom.X n))
(BaseUCom.X n))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level X order-4 identity: `X⁴ = 1`. Lifted from
`f_to_vec_X_X_X_X` via `matrix_eq_of_basis_action`. Mirrors the
pattern of `X_X_eq_one` but for the 4-chain. Useful for cyclic
cancellation in circuits where X gates may appear an even number
of times on the same qubit.
theoremZ_Z_Z_Z_eq_one
theorem Z_Z_Z_Z_eq_one (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.Z n : BaseUCom dim)
(BaseUCom.Z n))
(BaseUCom.Z n))
(BaseUCom.Z n))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level Z order-4 identity: `Z⁴ = 1`. Lifted from
`f_to_vec_Z_Z_Z_Z` via `matrix_eq_of_basis_action`.
theoremS_S_S_S_eq_one
theorem S_S_S_S_eq_one (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.S n))
(BaseUCom.S n)) (BaseUCom.S n))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level S order-4 identity: `S⁴ = 1`. Derived from
existing `S_S_S_S_eq_ID` (RHS `uc_eval (BaseUCom.ID n)`) +
`uc_eval_ID_eq_one` (converts to matrix `1` when `n < dim`).
theoremH_H_H_H_eq_one
theorem H_H_H_H_eq_one (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.H n))
(BaseUCom.H n)) (BaseUCom.H n))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level H order-4 identity: `H⁴ = 1`. Direct lift of
`H_H_H_H_eq_ID` via `uc_eval_ID_eq_one`.
theoremY_Y_Y_Y_eq_one
theorem Y_Y_Y_Y_eq_one (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.Y n : BaseUCom dim)
(BaseUCom.Y n))
(BaseUCom.Y n))
(BaseUCom.Y n))
= (1 : Matrix (Fin (2^dim)) (Fin (2^dim)) ℂ)Matrix-level Y order-4 identity: `Y⁴ = 1`. **Derived via
composition** rather than f_to_vec lift (no
`f_to_vec_Y_Y_Y_Y` exists). Strategy: reassociate
`Y * (Y * (Y * Y))` to `(Y * Y) * (Y * Y)` via `Matrix.mul_assoc`,
then collapse each pair via `Y_Y_eq_one`.
theoremf_to_vec_Y_Y_Y_Y
theorem f_to_vec_Y_Y_Y_Y (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.Y n : BaseUCom dim)
(BaseUCom.Y n))
(BaseUCom.Y n))
(BaseUCom.Y n))
* f_to_vec dim f
= f_to_vec dim fBasis-state lift of `Y_Y_Y_Y_eq_one` (matrix-level Y⁴ = 1).
Useful for chaining at the f_to_vec layer (per-bit cascade
correctness proofs needing Y-gate involution in 4-chain form).
theoremf_to_vec_Y_Y_Y_Y_Y
theorem f_to_vec_Y_Y_Y_Y_Y (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.Y n : BaseUCom dim) (BaseUCom.Y n))
(BaseUCom.Y n)) (BaseUCom.Y n)) (BaseUCom.Y n))
* f_to_vec dim f
= uc_eval (BaseUCom.Y n : BaseUCom dim) * f_to_vec dim f`Y q ; Y q ; Y q ; Y q ; Y q` acts as a single `Y q` on `f_to_vec dim f`
(Y⁵ = Y, since Y⁴ = ID). **Relational form**: unlike X⁵ and Z⁵ which
have closed-form basis-state results (`update` for X, `±1 •` for Z),
Y introduces an `i·(-1)^b` phase that has no closed form on
`f_to_vec dim f` alone. So the cleanest statement is
`uc_eval(Y⁵) · v = uc_eval(Y) · v`. Completes the Pauli order-5
basis-state family (X⁵/Y⁵/Z⁵) mirroring Iter 101 and the Iter 132
SQIR-tick.
theoremY_Y_Y_Y_Y_eq_Y
theorem Y_Y_Y_Y_Y_eq_Y (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.Y n : BaseUCom dim) (BaseUCom.Y n))
(BaseUCom.Y n)) (BaseUCom.Y n)) (BaseUCom.Y n))
= uc_eval (BaseUCom.Y n : BaseUCom dim)*Matrix-level Y order-5 cyclic identity**: `Y⁵ = Y`. Direct
consequence of `Y_Y_Y_Y_eq_one` (Y⁴ = 1) plus `Matrix.mul_one`.
More useful than the f_to_vec form (Iter 133) when the input is
NOT a basis state — e.g., during circuit-equivalence rewriting
on arbitrary state vectors. Per Iter 132 reflection.
theoremZ_Z_Z_Z_Z_eq_Z
theorem Z_Z_Z_Z_Z_eq_Z (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.Z n : BaseUCom dim) (BaseUCom.Z n))
(BaseUCom.Z n)) (BaseUCom.Z n)) (BaseUCom.Z n))
= uc_eval (BaseUCom.Z n : BaseUCom dim)*Matrix-level Z order-5 cyclic identity**: `Z⁵ = Z`. Direct
consequence of `Z_Z_Z_Z_eq_one` (Z⁴ = 1) plus `Matrix.mul_one`.
Mirrors `Y_Y_Y_Y_Y_eq_Y` (Iter 137) — same proof structure.
Matrix-level form for circuit-equivalence proofs on arbitrary
state vectors.
theoremX_X_X_X_X_eq_X
theorem X_X_X_X_X_eq_X (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.X n : BaseUCom dim) (BaseUCom.X n))
(BaseUCom.X n)) (BaseUCom.X n)) (BaseUCom.X n))
= uc_eval (BaseUCom.X n : BaseUCom dim)*Matrix-level X order-5 cyclic identity**: `X⁵ = X`. Direct
consequence of `X_X_X_X_eq_one` (X⁴ = 1) plus `Matrix.mul_one`.
Completes the Pauli matrix-level order-5 family (X/Y/Z all done
after this — Y from Iter 137, Z from the Iter 144 SQIR-tick).
theoremH_H_H_H_H_eq_H
theorem H_H_H_H_H_eq_H (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H n : BaseUCom dim) (BaseUCom.H n))
(BaseUCom.H n)) (BaseUCom.H n)) (BaseUCom.H n))
= uc_eval (BaseUCom.H n : BaseUCom dim)*Matrix-level H order-5 cyclic identity**: `H⁵ = H`. Direct
consequence of `H_H_H_H_eq_one` (H⁴ = 1) plus `Matrix.mul_one`.
Mirrors `X_X_X_X_X_eq_X`/`Y_Y_Y_Y_Y_eq_Y`/`Z_Z_Z_Z_Z_eq_Z`,
same proof shape. Matrix-level form for circuit-equivalence
proofs on arbitrary state vectors (not just basis states).
theoremS_S_S_S_S_eq_S
theorem S_S_S_S_S_eq_S (dim n : Nat) (h : n < dim) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.S n : BaseUCom dim) (BaseUCom.S n))
(BaseUCom.S n)) (BaseUCom.S n)) (BaseUCom.S n))
= uc_eval (BaseUCom.S n : BaseUCom dim)*Matrix-level S order-5 cyclic identity**: `S⁵ = S`. Direct
consequence of `S_S_S_S_eq_one` (S⁴ = 1) plus `Matrix.mul_one`.
Same proof pattern as X/Y/Z/H matrix-level lifts. Completes
the Clifford matrix-level order-5 family (X, Y, Z, H, S all
done now).
theoremCCX_control_symm
theorem CCX_control_symm {dim : Nat} (a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
uc_eval (BaseUCom.CCX a b c : BaseUCom dim)
= uc_eval (BaseUCom.CCX b a c : BaseUCom dim)Toffoli control symmetry: swapping the two control qubits leaves
the gate's matrix unchanged. Follows from `f_to_vec_CCX_proved`,
which uses `f a && f b` — symmetric in `a, b` via `Bool.and_comm`.
-- SQIR/SQIR/UnitaryOps.v analog: CCX a b c ≡ CCX b a c.
theoremCCX_control_symm_equiv
theorem CCX_control_symm_equiv {dim : Nat} (a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
UCom.equiv (BaseUCom.CCX a b c : BaseUCom dim) (BaseUCom.CCX b a c)UCom.equiv form of `CCX_control_symm`: at the circuit level,
`CCX a b c ≅ CCX b a c`. Direct corollary since `UCom.equiv` is
just `uc_eval` equality.
-- SQIR/SQIR/Equivalences.v style.
theoremf_to_vec_CCX_control_symm
theorem f_to_vec_CCX_control_symm (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (BaseUCom.CCX a b c : BaseUCom dim) * f_to_vec dim f
= uc_eval (BaseUCom.CCX b a c : BaseUCom dim) * f_to_vec dim fBasis-state lift of `CCX_control_symm`: applying CCX with controls
`(a, b)` to `f_to_vec dim f` gives the same result as CCX with
controls swapped `(b, a)`. Direct corollary, useful when the
available rewriting form is on `f_to_vec`-applied form.
-- SQIR/SQIR/UnitaryOps.v: CCX-control-symmetry at the basis level.
FormalRV.Core.PadAction.PadActionComposite
FormalRV/Core/PadAction/PadActionComposite.lean
theorempad_u_
theorem pad_u_σz_mul_pad_u_sMatrix (dim n : Nat) :
pad_u dim n σz * pad_u dim n sMatrix = pad_u dim n sdagMatrixPadded version: `pad_u Z · pad_u S = pad_u S†`.
theorempad_u_
theorem pad_u_σz_mul_pad_u_sdagMatrix (dim n : Nat) :
pad_u dim n σz * pad_u dim n sdagMatrix = pad_u dim n sMatrixPadded version: `pad_u Z · pad_u S† = pad_u S`.
theoremS_Z_eq_SDAG
theorem S_Z_eq_SDAG {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.Z n))
= uc_eval (BaseUCom.SDAG n : BaseUCom dim)Circuit equivalence: `S q ; Z q ≡ S† q` — Z·S = S† via σz_mul_sMatrix.
theoremSDAG_Z_eq_S
theorem SDAG_Z_eq_S {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.Z n))
= uc_eval (BaseUCom.S n : BaseUCom dim)Circuit equivalence: `S† q ; Z q ≡ S q` — Z·S† = S via σz_mul_sdagMatrix.
theoremS_S_S_eq_SDAG
theorem S_S_S_eq_SDAG {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.S n))
(BaseUCom.S n))
= uc_eval (BaseUCom.SDAG n : BaseUCom dim)Circuit equivalence: `S q ; S q ; S q ≡ S† q`. Lift of `sMatrix_pow_three`
(S has order 4, so S³ = S^(-1) = S†).
theoremSDAG_SDAG_SDAG_eq_S
theorem SDAG_SDAG_SDAG_eq_S {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.SDAG n))
(BaseUCom.SDAG n))
= uc_eval (BaseUCom.S n : BaseUCom dim)Circuit equivalence: `S† q ; S† q ; S† q ≡ S q`. Dual of `S_S_S_eq_SDAG`.
theoremf_to_vec_S_S_S
theorem f_to_vec_S_S_S (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.S n))
(BaseUCom.S n))
* f_to_vec dim f
= (if f n then -Complex.I else 1) • f_to_vec dim f`S q ; S q ; S q` acts as S† phase on `f_to_vec dim f` (S³ ≡ S†).
theoremf_to_vec_SDAG_SDAG_SDAG
theorem f_to_vec_SDAG_SDAG_SDAG (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.SDAG n))
(BaseUCom.SDAG n))
* f_to_vec dim f
= (if f n then Complex.I else 1) • f_to_vec dim f`S† q ; S† q ; S† q` acts as S phase on `f_to_vec dim f` (S†³ ≡ S).
theoremH_H_H_eq_H
theorem H_H_H_eq_H {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.H n))
(BaseUCom.H n))
= uc_eval (BaseUCom.H n : BaseUCom dim)Circuit equivalence: `H q ; H q ; H q ≡ H q`. Lift of `hMatrix_pow_three`.
theoremf_to_vec_H_H_H
theorem f_to_vec_H_H_H (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.H n))
(BaseUCom.H n))
* f_to_vec dim f
= uc_eval (BaseUCom.H n : BaseUCom dim) * f_to_vec dim f`H q ; H q ; H q` acts as a single H on `f_to_vec dim f`.
theoremX_X_X_eq_X
theorem X_X_X_eq_X {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (BaseUCom.X n : BaseUCom dim) (BaseUCom.X n))
(BaseUCom.X n))
= uc_eval (BaseUCom.X n : BaseUCom dim)Circuit equivalence: `X q ; X q ; X q ≡ X q`. Lift of `σx_pow_three`.
theoremY_Y_Y_eq_Y
theorem Y_Y_Y_eq_Y {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (BaseUCom.Y n : BaseUCom dim) (BaseUCom.Y n))
(BaseUCom.Y n))
= uc_eval (BaseUCom.Y n : BaseUCom dim)Circuit equivalence: `Y q ; Y q ; Y q ≡ Y q`. Lift of `σy_pow_three`.
theoremZ_Z_Z_eq_Z
theorem Z_Z_Z_eq_Z {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (BaseUCom.Z n : BaseUCom dim) (BaseUCom.Z n))
(BaseUCom.Z n))
= uc_eval (BaseUCom.Z n : BaseUCom dim)Circuit equivalence: `Z q ; Z q ; Z q ≡ Z q`. Lift of `σz_pow_three`.
theoremf_to_vec_SDAG_SDAG
theorem f_to_vec_SDAG_SDAG (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.SDAG n))
* f_to_vec dim f
= (if f n then (-1 : ℂ) else 1) • f_to_vec dim f`S† q ; S† q` acts as Z on `f_to_vec dim f` (since (S†)² = Z).
theoremexp_pi4_sq_eq_I
theorem exp_pi4_sq_eq_I :
(Complex.exp (Complex.I * (Real.pi / 4)))^2 = Complex.I`(exp(iπ/4))² = I` (used for T² = S).
theoremtMatrix_mul_tMatrix
theorem tMatrix_mul_tMatrix : tMatrix * tMatrix = sMatrix
`tMatrix * tMatrix = sMatrix` (T² = S, since (exp(iπ/4))² = exp(iπ/2) = I).
theoremtMatrix_pow_four
theorem tMatrix_pow_four : tMatrix * tMatrix * tMatrix * tMatrix = σz
`T⁴ = Z` at the matrix level — chain of `T² = S` and `S² = Z`.
theoremsMatrix_pow_four
theorem sMatrix_pow_four : sMatrix * sMatrix * sMatrix * sMatrix = σi
`S⁴ = I` at the matrix level — chain of `S² = Z` and `Z² = I`.
theoremT_T_T_T_eq_Z
theorem T_T_T_T_eq_Z {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.T n : BaseUCom dim) (BaseUCom.T n))
(BaseUCom.T n)) (BaseUCom.T n))
= uc_eval (BaseUCom.Z n : BaseUCom dim)Circuit equivalence: `T q ; T q ; T q ; T q ≡ Z q`. Lifts `tMatrix_pow_four`
via three `pad_u_mul_pad_u` collapses.
theoremH_H_H_H_eq_ID
theorem H_H_H_H_eq_ID {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.H n))
(BaseUCom.H n)) (BaseUCom.H n))
= uc_eval (BaseUCom.ID n : BaseUCom dim)Circuit equivalence: `H q ; H q ; H q ; H q ≡ ID q`. Lifts
`hMatrix_pow_four`. Note: H² ≡ ID is stronger; this is included for
symmetry with the T⁴/S⁴/T†⁴/S†⁴ family.
theoremS_S_S_S_eq_ID
theorem S_S_S_S_eq_ID {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.S n))
(BaseUCom.S n)) (BaseUCom.S n))
= uc_eval (BaseUCom.ID n : BaseUCom dim)Circuit equivalence: `S q ; S q ; S q ; S q ≡ ID q`. Lifts `sMatrix_pow_four`.
theoremf_to_vec_T_T_T_T
theorem f_to_vec_T_T_T_T (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.T n : BaseUCom dim) (BaseUCom.T n))
(BaseUCom.T n)) (BaseUCom.T n))
* f_to_vec dim f
= (if f n then (-1 : ℂ) else 1) • f_to_vec dim f`T q ; T q ; T q ; T q` acts as Z phase on `f_to_vec dim f`.
theoremf_to_vec_H_H_H_H
theorem f_to_vec_H_H_H_H (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.H n))
(BaseUCom.H n)) (BaseUCom.H n))
* f_to_vec dim f
= f_to_vec dim f`H q ; H q ; H q ; H q` acts as identity on `f_to_vec dim f`.
theoremf_to_vec_H_H_H_H_H
theorem f_to_vec_H_H_H_H_H (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H n : BaseUCom dim) (BaseUCom.H n))
(BaseUCom.H n)) (BaseUCom.H n)) (BaseUCom.H n))
* f_to_vec dim f
= uc_eval (BaseUCom.H n : BaseUCom dim) * f_to_vec dim f`H q ; H q ; H q ; H q ; H q` acts as a single `H q` on `f_to_vec dim f`
(H⁵ = H, since H⁴ = ID). **Relational form**: H|b⟩ = (|0⟩ ± |1⟩)/√2 is not
a basis state, so the cleanest statement is `uc_eval(H⁵) · v = uc_eval(H) · v`.
Mirrors `f_to_vec_Y_Y_Y_Y_Y` (Iter 133) — same proof structure as Y⁵ since both
have order-4 = ID without a closed-form basis-state expression.
theoremf_to_vec_S_S_S_S
theorem f_to_vec_S_S_S_S (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.S n))
(BaseUCom.S n)) (BaseUCom.S n))
* f_to_vec dim f
= f_to_vec dim f`S q ; S q ; S q ; S q` acts as identity on `f_to_vec dim f`.
theoremf_to_vec_S_S_S_S_S
theorem f_to_vec_S_S_S_S_S (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.S n : BaseUCom dim) (BaseUCom.S n))
(BaseUCom.S n)) (BaseUCom.S n)) (BaseUCom.S n))
* f_to_vec dim f
= (if f n then Complex.I else 1) • f_to_vec dim f`S q ; S q ; S q ; S q ; S q` acts as a single `S q` on `f_to_vec dim f`
(S⁵ = S, since S⁴ = ID). **Closed-form** result via `f_to_vec_S_uc_eval`:
`(if f n then Complex.I else 1) • f_to_vec dim f`. Diagonal-phase variant
of Z⁵; S maps |b⟩ to i^b |b⟩, so the basis-state action is just a phase
factor. Completes the diagonal-phase order-5 family alongside `f_to_vec_Z_Z_Z_Z_Z`
(Iter 132 SQIR-tick).
theoremexp_neg_pi4_sq_eq_neg_I
theorem exp_neg_pi4_sq_eq_neg_I :
(Complex.exp (-(Complex.I * (Real.pi / 4))))^2 = -Complex.I`(exp(-iπ/4))² = -I`.
theoremtdagMatrix_mul_tdagMatrix
theorem tdagMatrix_mul_tdagMatrix : tdagMatrix * tdagMatrix = sdagMatrix
`tdagMatrix * tdagMatrix = sdagMatrix` (T†² = S†).
theoremTDAG_TDAG_eq_SDAG
theorem TDAG_TDAG_eq_SDAG {dim : Nat} (n : Nat) :
uc_eval (UCom.seq (BaseUCom.TDAG n : BaseUCom dim) (BaseUCom.TDAG n))
= uc_eval (BaseUCom.SDAG n : BaseUCom dim)Circuit equivalence: `T† q ; T† q ≡ S† q`.
theoremf_to_vec_TDAG_TDAG
theorem f_to_vec_TDAG_TDAG (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.TDAG n : BaseUCom dim) (BaseUCom.TDAG n))
* f_to_vec dim f
= (if f n then -Complex.I else 1) • f_to_vec dim f`T† q ; T† q` acts as S† phase on `f_to_vec dim f` (since (T†)² = S†).
theoremtdagMatrix_pow_four
theorem tdagMatrix_pow_four :
tdagMatrix * tdagMatrix * tdagMatrix * tdagMatrix = σz`T†⁴ = Z` at the matrix level — chain of `T†² = S†` and `S†² = Z`.
theoremtMatrix_pow_five
theorem tMatrix_pow_five :
tMatrix * tMatrix * tMatrix * tMatrix * tMatrix = σz * tMatrix`T⁵ = Z · T` — direct corollary of T⁴ = Z.
theoremtdagMatrix_pow_five
theorem tdagMatrix_pow_five :
tdagMatrix * tdagMatrix * tdagMatrix * tdagMatrix * tdagMatrix = σz * tdagMatrix`T†⁵ = Z · T†` — direct corollary of T†⁴ = Z.
theorempad_u_sMatrix_pow_four
theorem pad_u_sMatrix_pow_four {dim n : Nat} (h : n < dim) :
pad_u dim n sMatrix * pad_u dim n sMatrix * pad_u dim n sMatrix * pad_u dim n sMatrix
= (1 : Square dim)S has order 4 at the padded level: S · S · S · S = 1 (chain form).
theoremsdagMatrix_pow_four
theorem sdagMatrix_pow_four :
sdagMatrix * sdagMatrix * sdagMatrix * sdagMatrix = σi`S†⁴ = I` at the matrix level — chain of `S†² = Z` and `Z² = I`.
theorempad_u_sdagMatrix_pow_four
theorem pad_u_sdagMatrix_pow_four {dim n : Nat} (h : n < dim) :
pad_u dim n sdagMatrix * pad_u dim n sdagMatrix * pad_u dim n sdagMatrix * pad_u dim n sdagMatrix
= (1 : Square dim)S† has order 4 at the padded level: S† · S† · S† · S† = 1 (chain form).
theorempad_u_tMatrix_pow_four
theorem pad_u_tMatrix_pow_four (dim n : Nat) :
pad_u dim n tMatrix * pad_u dim n tMatrix * pad_u dim n tMatrix * pad_u dim n tMatrix
= pad_u dim n σzT's 4-chain at the padded level equals pad_u σz (the padded Z gate).
Reflects T⁴ = Z; no `n < dim` hypothesis needed.
theorempad_u_tdagMatrix_pow_four
theorem pad_u_tdagMatrix_pow_four (dim n : Nat) :
pad_u dim n tdagMatrix * pad_u dim n tdagMatrix * pad_u dim n tdagMatrix * pad_u dim n tdagMatrix
= pad_u dim n σzT†'s 4-chain at the padded level equals pad_u σz. Reflects T†⁴ = Z.
theorempad_u_tMatrix_mul_tMatrix
theorem pad_u_tMatrix_mul_tMatrix (dim n : Nat) :
pad_u dim n tMatrix * pad_u dim n tMatrix = pad_u dim n sMatrixT's 2-chain at the padded level equals pad_u sMatrix. Reflects T² = S.
theorempad_u_sMatrix_mul_sMatrix
theorem pad_u_sMatrix_mul_sMatrix (dim n : Nat) :
pad_u dim n sMatrix * pad_u dim n sMatrix = pad_u dim n σzS's 2-chain at the padded level equals pad_u σz. Reflects S² = Z.
theorempad_u_tdagMatrix_mul_tdagMatrix
theorem pad_u_tdagMatrix_mul_tdagMatrix (dim n : Nat) :
pad_u dim n tdagMatrix * pad_u dim n tdagMatrix = pad_u dim n sdagMatrixT†'s 2-chain at the padded level equals pad_u sdagMatrix. Reflects T†² = S†.
theorempad_u_sdagMatrix_mul_sdagMatrix
theorem pad_u_sdagMatrix_mul_sdagMatrix (dim n : Nat) :
pad_u dim n sdagMatrix * pad_u dim n sdagMatrix = pad_u dim n σzS†'s 2-chain at the padded level equals pad_u σz. Reflects S†² = Z.
theorempad_u_sMatrix_pow_three
theorem pad_u_sMatrix_pow_three (dim n : Nat) :
pad_u dim n sMatrix * pad_u dim n sMatrix * pad_u dim n sMatrix
= pad_u dim n sdagMatrixS's 3-chain at the padded level equals pad_u sdagMatrix. Reflects S³ = S†.
theorempad_u_sdagMatrix_pow_three
theorem pad_u_sdagMatrix_pow_three (dim n : Nat) :
pad_u dim n sdagMatrix * pad_u dim n sdagMatrix * pad_u dim n sdagMatrix
= pad_u dim n sMatrixS†'s 3-chain at the padded level equals pad_u sMatrix. Reflects S†³ = S.
theoremsMatrix_pow_five
theorem sMatrix_pow_five :
sMatrix * sMatrix * sMatrix * sMatrix * sMatrix = sMatrix`S⁵ = S`. Follows from S⁴ = I + Matrix.one_mul.
theoremsdagMatrix_pow_five
theorem sdagMatrix_pow_five :
sdagMatrix * sdagMatrix * sdagMatrix * sdagMatrix * sdagMatrix = sdagMatrix`S†⁵ = S†`.
theorempad_u_sMatrix_pow_five
theorem pad_u_sMatrix_pow_five (dim n : Nat) :
pad_u dim n sMatrix * pad_u dim n sMatrix * pad_u dim n sMatrix * pad_u dim n sMatrix * pad_u dim n sMatrix
= pad_u dim n sMatrixS's 5-chain at the padded level equals pad_u sMatrix. Reflects S⁵ = S.
theorempad_u_sdagMatrix_pow_five
theorem pad_u_sdagMatrix_pow_five (dim n : Nat) :
pad_u dim n sdagMatrix * pad_u dim n sdagMatrix * pad_u dim n sdagMatrix * pad_u dim n sdagMatrix * pad_u dim n sdagMatrix
= pad_u dim n sdagMatrixS†'s 5-chain at the padded level equals pad_u sdagMatrix. Reflects S†⁵ = S†.
theorempad_u_tMatrix_pow_five
theorem pad_u_tMatrix_pow_five (dim n : Nat) :
pad_u dim n tMatrix * pad_u dim n tMatrix * pad_u dim n tMatrix * pad_u dim n tMatrix * pad_u dim n tMatrix
= pad_u dim n (σz * tMatrix)T's 5-chain at the padded level equals pad_u (σz·T). Reflects T⁵ = Z·T.
theorempad_u_tdagMatrix_pow_five
theorem pad_u_tdagMatrix_pow_five (dim n : Nat) :
pad_u dim n tdagMatrix * pad_u dim n tdagMatrix * pad_u dim n tdagMatrix * pad_u dim n tdagMatrix * pad_u dim n tdagMatrix
= pad_u dim n (σz * tdagMatrix)T†'s 5-chain at the padded level equals pad_u (σz·T†). Reflects T†⁵ = Z·T†.
theoremTDAG_TDAG_TDAG_TDAG_eq_Z
theorem TDAG_TDAG_TDAG_TDAG_eq_Z {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.TDAG n : BaseUCom dim)
(BaseUCom.TDAG n)) (BaseUCom.TDAG n)) (BaseUCom.TDAG n))
= uc_eval (BaseUCom.Z n : BaseUCom dim)Circuit equivalence: `T† q ; T† q ; T† q ; T† q ≡ Z q`.
Lifts `tdagMatrix_pow_four`.
theoremSDAG_SDAG_SDAG_SDAG_eq_ID
theorem SDAG_SDAG_SDAG_SDAG_eq_ID {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.SDAG n : BaseUCom dim)
(BaseUCom.SDAG n)) (BaseUCom.SDAG n)) (BaseUCom.SDAG n))
= uc_eval (BaseUCom.ID n : BaseUCom dim)Circuit equivalence: `S† q ; S† q ; S† q ; S† q ≡ ID q`.
Lifts `sdagMatrix_pow_four`.
theoremf_to_vec_TDAG_TDAG_TDAG_TDAG
theorem f_to_vec_TDAG_TDAG_TDAG_TDAG (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.TDAG n : BaseUCom dim)
(BaseUCom.TDAG n)) (BaseUCom.TDAG n)) (BaseUCom.TDAG n))
* f_to_vec dim f
= (if f n then (-1 : ℂ) else 1) • f_to_vec dim f`T† q ; T† q ; T† q ; T† q` acts as Z phase on `f_to_vec dim f`.
theoremf_to_vec_SDAG_SDAG_SDAG_SDAG
theorem f_to_vec_SDAG_SDAG_SDAG_SDAG (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.SDAG n : BaseUCom dim)
(BaseUCom.SDAG n)) (BaseUCom.SDAG n)) (BaseUCom.SDAG n))
* f_to_vec dim f
= f_to_vec dim f`S† q ; S† q ; S† q ; S† q` acts as identity on `f_to_vec dim f`.
theoremS_SDAG_eq_id
theorem S_SDAG_eq_id {dim n : Nat} (h : n < dim) :
uc_eval (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.SDAG n))
= (1 : Square dim)Circuit equivalence: `S q ; S† q ≡ ID` (uc_eval = identity matrix).
theoremSDAG_S_eq_id
theorem SDAG_S_eq_id {dim n : Nat} (h : n < dim) :
uc_eval (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.S n))
= (1 : Square dim)Circuit equivalence: `S† q ; S q ≡ ID`.
theoremf_to_vec_TDAG_then_T
theorem f_to_vec_TDAG_then_T (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.TDAG n : BaseUCom dim) (BaseUCom.T n))
* f_to_vec dim f
= f_to_vec dim f`T† q ; T q` is identity (matrix-level proof).
theoremf_to_vec_Y_Y
theorem f_to_vec_Y_Y (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.Y n : BaseUCom dim) (BaseUCom.Y n))
* f_to_vec dim f
= f_to_vec dim f`Y q ; Y q` is identity (matrix-level proof).
σy is its own inverse (σy²=I), so the matrix-level shortcut applies.
theoremf_to_vec_H_H
theorem f_to_vec_H_H (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.H n))
* f_to_vec dim f
= f_to_vec dim f`H q ; H q` is identity. Cleanest proof via the matrix-level identity
`hMatrix_mul_hMatrix` (already proven in UnitarySem) — avoids the
superposition-cancellation route.
theoremf_to_vec_T_T
theorem f_to_vec_T_T (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.T n : BaseUCom dim) (BaseUCom.T n))
* f_to_vec dim f
= (if f n then Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (Complex.I * (Real.pi / 4))
else 1)
• f_to_vec dim fChaining check: applying T twice on `f_to_vec dim f` gives a `T²` phase factor.
Validates the `uc_eval_seq_mul` + `mul_smul_state` + `f_to_vec_T_uc_eval`
chain works as expected. This is the simplest non-trivial multi-gate
composition through `f_to_vec`.
theoremf_to_vec_TDAG_T
theorem f_to_vec_TDAG_T (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.T n : BaseUCom dim) (BaseUCom.TDAG n))
* f_to_vec dim f
= f_to_vec dim fChaining check: applying T then T† gives no phase change (T†T = id).
theoremf_to_vec_H_CNOT
theorem f_to_vec_H_CNOT (dim b c : Nat) (hb : b < dim) (hc : c < dim)
(hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c))
* f_to_vec dim f
= (Real.sqrt 2 / 2 : ℂ) • f_to_vec dim (update f c (f b))
+ ((if f c then (-1 : ℂ) else 1) * (Real.sqrt 2 / 2 : ℂ))
• f_to_vec dim (update f c (!f b))theoremf_to_vec_H_CNOT_TDAG
theorem f_to_vec_H_CNOT_TDAG (dim b c : Nat) (hb : b < dim) (hc : c < dim)
(hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
* f_to_vec dim f
= ((if f b then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)
* (Real.sqrt 2 / 2 : ℂ))
• f_to_vec dim (update f c (f b))
+ ((if f c then (-1 : ℂ) else 1)
* (if !f b then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)
* (Real.sqrt 2 / 2 : ℂ))
• f_to_vec dim (update f c (!f b))theoremf_to_vec_H_CNOT_TDAG_CNOT
theorem f_to_vec_H_CNOT_TDAG_CNOT (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
* f_to_vec dim f
= ((if f b then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)
* (Real.sqrt 2 / 2 : ℂ))
• f_to_vec dim (update f c (xor (f b) (f a)))
+ ((if f c then (-1 : ℂ) else 1)
* (if !f b then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)theoremf_to_vec_CCX_prefix_5
theorem f_to_vec_CCX_prefix_5 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
* f_to_vec dim f
= ((if xor (f b) (f a) then Complex.exp (Complex.I * (Real.pi / 4)) else 1)
* (if f b then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)
* (Real.sqrt 2 / 2 : ℂ))
• f_to_vec dim (update f c (xor (f b) (f a)))theoremf_to_vec_CCX_prefix_6
theorem f_to_vec_CCX_prefix_6 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
* f_to_vec dim f
= ((if xor (f b) (f a) then Complex.exp (Complex.I * (Real.pi / 4)) else 1)
* (if f b then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)
* (Real.sqrt 2 / 2 : ℂ))theoremf_to_vec_CCX_prefix_7
theorem f_to_vec_CCX_prefix_7 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
* f_to_vec dim f
= ((if f a then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)
* (if xor (f b) (f a) then Complex.exp (Complex.I * (Real.pi / 4)) else 1)theoremf_to_vec_CCX_prefix_8
theorem f_to_vec_CCX_prefix_8 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
* f_to_vec dim f
= ((if f a then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)theoremf_to_vec_CCX_prefix_9
theorem f_to_vec_CCX_prefix_9 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.CNOT a b))
* f_to_vec dim ftheoremf_to_vec_CCX_prefix_10
theorem f_to_vec_CCX_prefix_10 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.CNOT a b))
(BaseUCom.TDAG b))theoremf_to_vec_CCX_prefix_11
theorem f_to_vec_CCX_prefix_11 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.CNOT a b))
(BaseUCom.TDAG b))theoremf_to_vec_CCX_prefix_12
theorem f_to_vec_CCX_prefix_12 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.CNOT a b))
(BaseUCom.TDAG b))theoremf_to_vec_CCX_prefix_13
theorem f_to_vec_CCX_prefix_13 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.CNOT a b))
(BaseUCom.TDAG b))theoremf_to_vec_CCX_prefix_14
theorem f_to_vec_CCX_prefix_14 (dim a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq (UCom.seq
(BaseUCom.H c : BaseUCom dim) (BaseUCom.CNOT b c)) (BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.T c))
(BaseUCom.CNOT b c))
(BaseUCom.TDAG c))
(BaseUCom.CNOT a c))
(BaseUCom.CNOT a b))
(BaseUCom.TDAG b))theoremexp_pi4_mul_exp_neg_pi4
theorem exp_pi4_mul_exp_neg_pi4 :
Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (-(Complex.I * (Real.pi / 4))) = 1exp(iπ/4) · exp(-iπ/4) = 1.
theoremexp_neg_pi4_mul_exp_pi4
theorem exp_neg_pi4_mul_exp_pi4 :
Complex.exp (-(Complex.I * (Real.pi / 4)))
* Complex.exp (Complex.I * (Real.pi / 4)) = 1exp(-iπ/4) · exp(iπ/4) = 1.
theoremexp_pi4_sq_mul_exp_neg_pi4_sq
theorem exp_pi4_sq_mul_exp_neg_pi4_sq :
(Complex.exp (Complex.I * (Real.pi / 4)))^2
* (Complex.exp (-(Complex.I * (Real.pi / 4))))^2 = 1exp(iπ/4)^2 · exp(-iπ/4)^2 = 1.
theoremexp_pi4_pow_four
theorem exp_pi4_pow_four :
(Complex.exp (Complex.I * (Real.pi / 4)))^4 = -1exp(iπ/4)^4 = exp(iπ) = -1.
theoremexp_neg_pi4_pow_four
theorem exp_neg_pi4_pow_four :
(Complex.exp (-(Complex.I * (Real.pi / 4))))^4 = -1exp(-iπ/4)^4 = exp(-iπ) = -1. Dagger version of `exp_pi4_pow_four`.
theoremexp_pi4_pow_two_eq_I
theorem exp_pi4_pow_two_eq_I :
(Complex.exp (Complex.I * (Real.pi / 4)))^2 = Complex.Iexp(iπ/4)^2 = exp(iπ/2) = i. The basic π/4 → π/2 squaring identity.
Useful for further reducing 2-factor exp products inside the CCX
phase-cancellation cases.
theoremexp_neg_pi4_pow_two_eq_neg_I
theorem exp_neg_pi4_pow_two_eq_neg_I :
(Complex.exp (-(Complex.I * (Real.pi / 4))))^2 = -Complex.Iexp(-iπ/4)^2 = exp(-iπ/2) = -i. Dagger version.
theoremexp_pi4_alt_four
theorem exp_pi4_alt_four :
Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (-(Complex.I * (Real.pi / 4)))
* Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (-(Complex.I * (Real.pi / 4))) = 14-factor alternating pattern: `e * e⁻¹ * e * e⁻¹ = 1` where
`e = exp(iπ/4)`. This product appears in CCX_PHASE_CANCEL α₁
expressions for cases where (f a, f b) = (F, F). 1-line proof
via repeated `exp_pi4_mul_exp_neg_pi4` after associativity.
theoremexp_pi4_consec_four
theorem exp_pi4_consec_four :
Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (-(Complex.I * (Real.pi / 4)))
* Complex.exp (-(Complex.I * (Real.pi / 4))) = 14-factor consecutive-grouping pattern: `e * e * e⁻¹ * e⁻¹ = 1` where
`e = exp(iπ/4)`. Appears in CCX_PHASE_CANCEL α₁ for (F,T,*) and
(T,F,*) cases (2 positive π/4 factors then 2 negative).
theoremexp_pi4_palindrome_four
theorem exp_pi4_palindrome_four :
Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (-(Complex.I * (Real.pi / 4)))
* Complex.exp (-(Complex.I * (Real.pi / 4)))
* Complex.exp (Complex.I * (Real.pi / 4)) = 14-factor palindrome pattern: `e * e⁻¹ * e⁻¹ * e = 1` where
`e = exp(iπ/4)`. Appears in CCX_PHASE_CANCEL α₀ for (T,F,*) cases.
theoremexp_pi4_mul_four_eq_neg_one
theorem exp_pi4_mul_four_eq_neg_one :
Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (Complex.I * (Real.pi / 4)) = -14-factor uniform-product pattern: `e * e * e * e = -1` where
`e = exp(iπ/4)`. Appears in CCX_PHASE_CANCEL α₁ for (T,T,*) cases.
Equivalent to `exp_pi4_pow_four` but in mul-of-mul form.
theoremsqrt2_div2_sq
theorem sqrt2_div2_sq : ((Real.sqrt 2 : ℂ) / 2) * ((Real.sqrt 2 : ℂ) / 2) = 1/2
(√2/2)² = 1/2 in ℂ.
theoremhMatrix_
theorem hMatrix_σx_hMatrix : hMatrix * σx * hMatrix = σz
Hadamard sandwich: `H X H = Z`.
theoremhMatrix_
theorem hMatrix_σz_hMatrix : hMatrix * σz * hMatrix = σx
Hadamard sandwich: `H Z H = X`. Dual of `hMatrix_σx_hMatrix`.
theoremhMatrix_
theorem hMatrix_σy_hMatrix : hMatrix * σy * hMatrix = -σy
Hadamard sandwich: `H Y H = -Y`. The Y axis flips under Hadamard
conjugation (Y is anti-symmetric under the X↔Z basis swap).
theoremsMatrix_
theorem sMatrix_σx_sdagMatrix : sMatrix * σx * sdagMatrix = σy
S sandwich: `S X S† = Y`. The S gate maps X to Y under conjugation
(a 90° rotation in the X-Y plane).
theoremsMatrix_
theorem sMatrix_σy_sdagMatrix : sMatrix * σy * sdagMatrix = -σx
S sandwich: `S Y S† = -X`.
theoremsMatrix_
theorem sMatrix_σz_sdagMatrix : sMatrix * σz * sdagMatrix = σz
S sandwich: `S Z S† = Z`. The Z axis is fixed by S (since both are
Z-axis rotations and commute).
theoremsdagMatrix_
theorem sdagMatrix_σx_sMatrix : sdagMatrix * σx * sMatrix = -σy
Dual S†-sandwich: `S† X S = -Y`. Inverse rotation of `S X S† = Y`.
theoremsdagMatrix_
theorem sdagMatrix_σy_sMatrix : sdagMatrix * σy * sMatrix = σx
Dual S†-sandwich: `S† Y S = X`.
theoremsdagMatrix_
theorem sdagMatrix_σz_sMatrix : sdagMatrix * σz * sMatrix = σz
Dual S†-sandwich: `S† Z S = Z`.
theoremtMatrix_
theorem tMatrix_σz_tdagMatrix : tMatrix * σz * tdagMatrix = σz
T-sandwich: `T Z T† = Z`. T is a Z-axis rotation (by π/4) so it
commutes with σz; the sandwich therefore acts trivially.
theoremtdagMatrix_
theorem tdagMatrix_σz_tMatrix : tdagMatrix * σz * tMatrix = σz
T†-sandwich: `T† Z T = Z`. Dual of `tMatrix_σz_tdagMatrix`.
theoremH_X_H_eq_Z
theorem H_X_H_eq_Z {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.X n))
(BaseUCom.H n))
= uc_eval (BaseUCom.Z n : BaseUCom dim)Circuit equivalence: `H q ; X q ; H q ≡ Z q`. This is the
canonical Hadamard sandwich identity at the circuit level — lifts
the matrix identity `hMatrix * σx * hMatrix = σz` (theorem
`hMatrix_σx_hMatrix`) through `pad_u_mul_pad_u`.
theoremH_Z_H_eq_X
theorem H_Z_H_eq_X {dim n : Nat} :
uc_eval (UCom.seq (UCom.seq (BaseUCom.H n : BaseUCom dim) (BaseUCom.Z n))
(BaseUCom.H n))
= uc_eval (BaseUCom.X n : BaseUCom dim)Circuit equivalence: `H q ; Z q ; H q ≡ X q`. Dual sandwich.
FormalRV.Core.PadAction.PadActionDefinitions
FormalRV/Core/PadAction/PadActionDefinitions.lean
## The reindex equiv used by `pad_u`
defpadEquiv
noncomputable def padEquiv (dim n : Nat) (h : n < dim) :
(Fin (2^n) × Fin 2) × Fin (2^(dim-n-1)) ≃ Fin (2^dim)The reindex equiv embedded inside `pad_u dim n` (when `n < dim`).
Decomposes a `Fin (2^dim)` index into a triple `(high, middle, low)` with
`high : Fin (2^n)`, `middle : Fin 2`, `low : Fin (2^(dim-n-1))`.
defflipBit
def flipBit : Fin 2 → Fin 2 | ⟨0, _⟩ => 1 | ⟨1, _⟩ => 0 | ⟨_+2, h⟩ => absurd h (by omega)
Flip a `Fin 2` value: 0 ↔ 1.
defsdagMatrix
noncomputable def sdagMatrix : Matrix (Fin 2) (Fin 2) ℂ
The S†-gate matrix: `!![1, 0; 0, -I]`.
deftdagMatrix
noncomputable def tdagMatrix : Matrix (Fin 2) (Fin 2) ℂ
The T†-gate matrix: `!![1, 0; 0, exp(-i·π/4)]`.
defnat_to_funbool
def nat_to_funbool (n : Nat) (j : Nat) : Nat → Bool
The natural-number inverse of `funbool_to_nat`: extracts bit at position
`n-1-i` of `j`. For `j < 2^n`, `funbool_to_nat n (nat_to_funbool n j) = j`.
FormalRV.Core.PadAction.PadActionGateEntry
FormalRV/Core/PadAction/PadActionGateEntry.lean
## Entry formula for `pad_u`
The (r, c) entry of `pad_u dim n M` factorizes as
δ_high(r,c) · M[middle(r), middle(c)] · δ_low(r,c)
where the δ's enforce equality on the high and low parts of the index.
theorempad_u_apply_reindex
theorem pad_u_apply_reindex {dim n : Nat} (h : n < dim)
(M : Matrix (Fin 2) (Fin 2) ℂ)
(rH cH : Fin (2^n)) (rM cM : Fin 2) (rL cL : Fin (2^(dim-n-1))) :
pad_u dim n M (padEquiv dim n h ((rH, rM), rL)) (padEquiv dim n h ((cH, cM), cL))
= (if rH = cH then (1:ℂ) else 0)
* M rM cM
* (if rL = cL then (1:ℂ) else 0)Entry formula for `pad_u dim n M` with indices written via `padEquiv`.
This is the workhorse for proving how `pad_u` acts on basis vectors.
theoremmul_basis_vector_apply
theorem mul_basis_vector_apply {n : Nat} (A : Matrix (Fin n) (Fin n) ℂ)
(k : Nat) (h : k < n) (i : Fin n) :
(A * basis_vector n k) i 0 = A i ⟨k, h⟩`A * basis_vector n k` extracts column `k` of `A`.
theorempad_u_basis_vector_entry
theorem pad_u_basis_vector_entry {dim n : Nat} (h : n < dim)
(M : Matrix (Fin 2) (Fin 2) ℂ)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1)))
(rH : Fin (2^n)) (rM : Fin 2) (rL : Fin (2^(dim-n-1))) :
(pad_u dim n M * basis_vector (2^dim)
(padEquiv dim n h ((kH, kM), kL)).val)
(padEquiv dim n h ((rH, rM), rL)) 0
= (if rH = kH then (1:ℂ) else 0)
* M rM kM
* (if rL = kL then (1:ℂ) else 0)The (r, 0) entry of `pad_u dim n M * basis_vector(2^dim, K)` when both
`r` and `K` are written via `padEquiv`.
theoremflipBit_ne
theorem flipBit_ne (x : Fin 2) : flipBit x ≠ x
theoremne_iff_eq_flipBit
theorem ne_iff_eq_flipBit (x y : Fin 2) : x ≠ y ↔ x = flipBit y
theoremx_apply
theorem σx_apply (i j : Fin 2) :
σx i j = (if i = flipBit j then (1:ℂ) else 0)σx as a function on `Fin 2` indices: 1 iff `i ≠ j`, expressible as
`i = flipBit j`. Used to compute σx applied to basis indices.
theorempadEquiv_val_eq_iff
theorem padEquiv_val_eq_iff {dim n : Nat} (h : n < dim)
(a b : (Fin (2^n) × Fin 2) × Fin (2^(dim-n-1))) :
(padEquiv dim n h a).val = (padEquiv dim n h b).val ↔ a = bBridge lemma: equality of `padEquiv` values iff triple equality.
theorempad_u_
theorem pad_u_σx_on_basis_vector_padEquiv {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1))) :
pad_u dim n σx * basis_vector (2^dim)
(padEquiv dim n h ((kH, kM), kL)).val
= basis_vector (2^dim)
(padEquiv dim n h ((kH, flipBit kM), kL)).valtheoremproj0_apply
theorem proj0_apply (i j : Fin 2) :
proj0 i j = (if i = 0 ∧ j = 0 then (1:ℂ) else 0)theoremproj1_apply
theorem proj1_apply (i j : Fin 2) :
proj1 i j = (if i = 1 ∧ j = 1 then (1:ℂ) else 0)theorempad_u_proj0_on_basis_vector_zero
theorem pad_u_proj0_on_basis_vector_zero {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kL : Fin (2^(dim-n-1))) :
pad_u dim n proj0 * basis_vector (2^dim)
(padEquiv dim n h ((kH, (0 : Fin 2)), kL)).val
= basis_vector (2^dim)
(padEquiv dim n h ((kH, (0 : Fin 2)), kL)).val`pad_u dim n proj0` acting on a basis state with middle bit 0
leaves it unchanged.
theorempad_u_proj0_on_basis_vector_one
theorem pad_u_proj0_on_basis_vector_one {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kL : Fin (2^(dim-n-1))) :
pad_u dim n proj0 * basis_vector (2^dim)
(padEquiv dim n h ((kH, (1 : Fin 2)), kL)).val = 0`pad_u dim n proj0` acting on a basis state with middle bit 1
annihilates it.
theorempad_u_proj1_on_basis_vector_one
theorem pad_u_proj1_on_basis_vector_one {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kL : Fin (2^(dim-n-1))) :
pad_u dim n proj1 * basis_vector (2^dim)
(padEquiv dim n h ((kH, (1 : Fin 2)), kL)).val
= basis_vector (2^dim)
(padEquiv dim n h ((kH, (1 : Fin 2)), kL)).val`pad_u dim n proj1` acting on a basis state with middle bit 1
leaves it unchanged.
theorempad_u_proj1_on_basis_vector_zero
theorem pad_u_proj1_on_basis_vector_zero {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kL : Fin (2^(dim-n-1))) :
pad_u dim n proj1 * basis_vector (2^dim)
(padEquiv dim n h ((kH, (0 : Fin 2)), kL)).val = 0`pad_u dim n proj1` acting on a basis state with middle bit 0
annihilates it.
theoremfunbool_to_nat_split_aux
theorem funbool_to_nat_split_aux (n k : Nat) (f : Nat → Bool) :
funbool_to_nat (n + 1 + k) f
= funbool_to_nat n f * 2^(k+1)
+ (if f n then 1 else 0) * 2^k
+ funbool_to_nat k (fun p => f (p + n + 1))theoremfunbool_to_nat_split
theorem funbool_to_nat_split (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
funbool_to_nat dim f
= funbool_to_nat n f * 2^(dim - n)
+ (if f n then 1 else 0) * 2^(dim - n - 1)
+ funbool_to_nat (dim - n - 1) (fun p => f (p + n + 1))theorempadEquiv_val_formula
theorem padEquiv_val_formula {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1))) :
(padEquiv dim n h ((kH, kM), kL)).val
= kH.val * 2^(dim-n) + kM.val * 2^(dim-n-1) + kL.valThe natural-number value of `padEquiv((kH, kM), kL)` is the standard
base-2 packing: `kH * 2^(dim-n) + kM * 2^(dim-n-1) + kL`.
theoremf_to_vec_eq_basis_padEquiv
theorem f_to_vec_eq_basis_padEquiv (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
f_to_vec dim f
= basis_vector (2^dim)
(padEquiv dim n h
((⟨funbool_to_nat n f, funbool_to_nat_lt n f⟩,
⟨if f n then 1 else 0, by split_ifs <;> omega⟩),
⟨funbool_to_nat (dim - n - 1) (fun p => f (p + n + 1)),
funbool_to_nat_lt _ _⟩)).val`f_to_vec dim f` is the basis state at the `padEquiv` packing of
(top-bits-of-f, f-at-n, bottom-bits-of-f).
theoremfunbool_to_nat_update_eq
theorem funbool_to_nat_update_eq (dim n : Nat) (h : n < dim)
(f : Nat → Bool) (v : Bool) :
funbool_to_nat dim (update f n v)
= funbool_to_nat n f * 2^(dim - n)
+ (if v then 1 else 0) * 2^(dim - n - 1)
+ funbool_to_nat (dim - n - 1) (fun p => f (p + n + 1))After `update f n v`, the `funbool_to_nat` decomposition only changes
in the middle bit.
theoremflipBit_val_of_b
theorem flipBit_val_of_b (b : Bool) :
(flipBit ⟨if b then 1 else 0, by split_ifs <;> omega⟩).val
= (if !b then 1 else 0)`flipBit (⟨if b then 1 else 0⟩).val = if !b then 1 else 0`.
theorempad_u_
theorem pad_u_σx_on_f_to_vec (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
pad_u dim n σx * f_to_vec dim f = f_to_vec dim (update f n (!f n))`pad_u dim n σx` acting on `f_to_vec dim f` flips the bit at index `n`.
theorempad_u_proj0_on_f_to_vec
theorem pad_u_proj0_on_f_to_vec (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
pad_u dim n proj0 * f_to_vec dim f
= if f n then 0 else f_to_vec dim f`pad_u dim n proj0` acting on `f_to_vec dim f`: keeps the state if
`f n = false`, annihilates if `f n = true`.
theorempad_u_proj1_on_f_to_vec
theorem pad_u_proj1_on_f_to_vec (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
pad_u dim n proj1 * f_to_vec dim f
= if f n then f_to_vec dim f else 0`pad_u dim n proj1` acting on `f_to_vec dim f`: keeps the state if
`f n = true`, annihilates if `f n = false`.
theoremf_to_vec_CNOT_proved
theorem f_to_vec_CNOT_proved (n i j : Nat) (f : Nat → Bool)
(hi : i < n) (hj : j < n) (hij : i ≠ j) :
uc_eval (BaseUCom.CNOT i j : BaseUCom n) * f_to_vec n f
= f_to_vec n (update f j (xor (f j) (f i)))theoremtMatrix_apply
theorem tMatrix_apply (i j : Fin 2) :
tMatrix i j
= (if i = j then (if i = 1 then Complex.exp (Complex.I * (Real.pi / 4)) else 1) else 0)theorempad_u_T_on_basis_vector_padEquiv
theorem pad_u_T_on_basis_vector_padEquiv {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1))) :
pad_u dim n tMatrix * basis_vector (2^dim)
(padEquiv dim n h ((kH, kM), kL)).val
= (if kM = 1 then Complex.exp (Complex.I * (Real.pi / 4)) else 1)
• basis_vector (2^dim) (padEquiv dim n h ((kH, kM), kL)).val`pad_u dim n tMatrix` acting on a `padEquiv`-coordinated basis state:
leaves the state unchanged, multiplied by the T-phase factor at qubit `n`.
theoremf_to_vec_T_proved
theorem f_to_vec_T_proved (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
pad_u dim n tMatrix * f_to_vec dim f
= (if f n then Complex.exp (Complex.I * (Real.pi / 4)) else 1)
• f_to_vec dim f`pad_u dim n tMatrix` on `f_to_vec dim f`: phase-multiplies by `e^(iπ/4)`
if `f n` is true, else leaves unchanged.
Faithful translation of SQIR `f_to_vec_T` from `UnitaryOps.v`.
theoremrotation_Rz_apply
theorem rotation_Rz_apply (θ : ℝ) (i j : Fin 2) :
rotation 0 0 θ i j
= (if i = j then (if i = 1 then Complex.exp ((θ : ℂ) * Complex.I) else 1) else 0)Entry formula for `rotation 0 0 θ` (the Rz(θ) gate). Diagonal with
entries 1 (at |0⟩) and exp(θ·i) (at |1⟩). Generalizes T, S, Z, T†, S†
entry formulas.
theorempad_u_Rz_on_basis_vector_padEquiv
theorem pad_u_Rz_on_basis_vector_padEquiv {dim n : Nat} (h : n < dim) (θ : ℝ)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1))) :
pad_u dim n (rotation 0 0 θ) * basis_vector (2^dim)
(padEquiv dim n h ((kH, kM), kL)).val
= (if kM = 1 then Complex.exp ((θ : ℂ) * Complex.I) else 1)
• basis_vector (2^dim) (padEquiv dim n h ((kH, kM), kL)).val`pad_u dim n (rotation 0 0 θ)` acting on a `padEquiv`-coordinated basis state:
diagonal phase `exp(θ·i)` if middle bit is 1, else 1.
Generalizes pad_u_T/Z/S_on_basis_vector_padEquiv.
theoremf_to_vec_Rz_proved
theorem f_to_vec_Rz_proved (dim n : Nat) (h : n < dim) (θ : ℝ) (f : Nat → Bool) :
pad_u dim n (rotation 0 0 θ) * f_to_vec dim f
= (if f n then Complex.exp ((θ : ℂ) * Complex.I) else 1) • f_to_vec dim f`pad_u dim n (rotation 0 0 θ)` on `f_to_vec dim f`: phase-multiplies by
`exp(θ·i)` if `f n` is true, else leaves unchanged.
Unifies f_to_vec_T/Z/S/TDAG/SDAG_proved at arbitrary θ.
theoremf_to_vec_Rz_uc_eval
theorem f_to_vec_Rz_uc_eval (dim n : Nat) (h : n < dim) (θ : ℝ) (f : Nat → Bool) :
uc_eval (BaseUCom.Rz θ n : BaseUCom dim) * f_to_vec dim f
= (if f n then Complex.exp ((θ : ℂ) * Complex.I) else 1) • f_to_vec dim fSQIR-faithful uc_eval form of `f_to_vec_Rz`. Generalizes
f_to_vec_T/Z/S/TDAG/SDAG_uc_eval.
theoremf_to_vec_SKIP_uc_eval
theorem f_to_vec_SKIP_uc_eval {dim : Nat} (h : 0 < dim) (f : Nat → Bool) :
uc_eval (BaseUCom.SKIP : BaseUCom dim) * f_to_vec dim f = f_to_vec dim fSKIP applied to any state is the identity.
theoremID_uc_eval_eq_one
theorem ID_uc_eval_eq_one {dim n : Nat} (h : n < dim) :
uc_eval (BaseUCom.ID n : BaseUCom dim) = (1 : Square dim)The matrix semantics of `ID n` is the identity matrix when `n < dim`.
theoremf_to_vec_ID
theorem f_to_vec_ID {dim n : Nat} (h : n < dim) (f : Nat → Bool) :
uc_eval (BaseUCom.ID n : BaseUCom dim) * f_to_vec dim f = f_to_vec dim f`ID n` applied to any state is identity.
theoremz_apply
theorem σz_apply (i j : Fin 2) :
σz i j = (if i = j then (if i = 1 then (-1 : ℂ) else 1) else 0)Entry formula for `σz`.
theorempad_u_Z_on_basis_vector_padEquiv
theorem pad_u_Z_on_basis_vector_padEquiv {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1))) :
pad_u dim n σz * basis_vector (2^dim)
(padEquiv dim n h ((kH, kM), kL)).val
= (if kM = 1 then (-1 : ℂ) else 1)
• basis_vector (2^dim) (padEquiv dim n h ((kH, kM), kL)).valtheoremf_to_vec_Z_proved
theorem f_to_vec_Z_proved (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
pad_u dim n σz * f_to_vec dim f
= (if f n then (-1 : ℂ) else 1) • f_to_vec dim f`pad_u dim n σz` on `f_to_vec dim f`: sign flip if `f n` is true.
Faithful translation of SQIR `f_to_vec_Z` from `UnitaryOps.v`.
theoremf_to_vec_Z_uc_eval
theorem f_to_vec_Z_uc_eval (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (BaseUCom.Z n : BaseUCom dim) * f_to_vec dim f
= (if f n then (-1 : ℂ) else 1) • f_to_vec dim fSQIR-faithful form of `f_to_vec_Z`.
theoremsMatrix_apply
theorem sMatrix_apply (i j : Fin 2) :
sMatrix i j = (if i = j then (if i = 1 then Complex.I else 1) else 0)theorempad_u_S_on_basis_vector_padEquiv
theorem pad_u_S_on_basis_vector_padEquiv {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1))) :
pad_u dim n sMatrix * basis_vector (2^dim)
(padEquiv dim n h ((kH, kM), kL)).val
= (if kM = 1 then Complex.I else 1)
• basis_vector (2^dim) (padEquiv dim n h ((kH, kM), kL)).valtheoremf_to_vec_S_proved
theorem f_to_vec_S_proved (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
pad_u dim n sMatrix * f_to_vec dim f
= (if f n then Complex.I else 1) • f_to_vec dim f`pad_u dim n sMatrix` on `f_to_vec dim f`: phase factor `i` if `f n` is true.
Faithful translation of SQIR `f_to_vec_S`.
theoremf_to_vec_S_uc_eval
theorem f_to_vec_S_uc_eval (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (BaseUCom.S n : BaseUCom dim) * f_to_vec dim f
= (if f n then Complex.I else 1) • f_to_vec dim fSQIR-faithful form of `f_to_vec_S`.
theoremrotation_SDAG
theorem rotation_SDAG : rotation 0 0 (-(Real.pi / 2)) = sdagMatrix
`rotation 0 0 (-π/2) = sdagMatrix`.
theoremsdagMatrix_apply
theorem sdagMatrix_apply (i j : Fin 2) :
sdagMatrix i j = (if i = j then (if i = 1 then -Complex.I else 1) else 0)theorempad_u_SDAG_on_basis_vector_padEquiv
theorem pad_u_SDAG_on_basis_vector_padEquiv {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1))) :
pad_u dim n sdagMatrix * basis_vector (2^dim)
(padEquiv dim n h ((kH, kM), kL)).val
= (if kM = 1 then -Complex.I else 1)
• basis_vector (2^dim) (padEquiv dim n h ((kH, kM), kL)).valtheoremf_to_vec_SDAG_proved
theorem f_to_vec_SDAG_proved (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
pad_u dim n sdagMatrix * f_to_vec dim f
= (if f n then -Complex.I else 1) • f_to_vec dim ftheoremf_to_vec_SDAG_uc_eval
theorem f_to_vec_SDAG_uc_eval (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (BaseUCom.SDAG n : BaseUCom dim) * f_to_vec dim f
= (if f n then -Complex.I else 1) • f_to_vec dim ftheoremtdagMatrix_apply
theorem tdagMatrix_apply (i j : Fin 2) :
tdagMatrix i j
= (if i = j then (if i = 1 then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1) else 0)theorempad_u_TDAG_on_basis_vector_padEquiv
theorem pad_u_TDAG_on_basis_vector_padEquiv {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1))) :
pad_u dim n tdagMatrix * basis_vector (2^dim)
(padEquiv dim n h ((kH, kM), kL)).val
= (if kM = 1 then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)
• basis_vector (2^dim) (padEquiv dim n h ((kH, kM), kL)).valtheoremf_to_vec_TDAG_proved
theorem f_to_vec_TDAG_proved (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
pad_u dim n tdagMatrix * f_to_vec dim f
= (if f n then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)
• f_to_vec dim f`pad_u dim n tdagMatrix` on `f_to_vec dim f`: phase-multiplies by
`e^(-i·π/4)` if `f n` is true, else leaves unchanged.
Faithful translation of SQIR `f_to_vec_TDAG` from `UnitaryOps.v`.
theoremhMatrix_apply
theorem hMatrix_apply (i j : Fin 2) :
hMatrix i j
= (if i = 1 ∧ j = 1 then -(Real.sqrt 2 / 2 : ℂ) else (Real.sqrt 2 / 2 : ℂ))theorempad_u_H_on_basis_vector_padEquiv
theorem pad_u_H_on_basis_vector_padEquiv {dim n : Nat} (h : n < dim)
(kH : Fin (2^n)) (kM : Fin 2) (kL : Fin (2^(dim-n-1))) :
pad_u dim n hMatrix * basis_vector (2^dim)
(padEquiv dim n h ((kH, kM), kL)).val
= ((Real.sqrt 2 / 2 : ℂ))
• basis_vector (2^dim) (padEquiv dim n h ((kH, (0 : Fin 2)), kL)).val
+ ((if kM = 1 then (-1 : ℂ) else 1) * (Real.sqrt 2 / 2 : ℂ))
• basis_vector (2^dim) (padEquiv dim n h ((kH, (1 : Fin 2)), kL)).val`pad_u dim n hMatrix` acting on a `padEquiv`-coordinated basis state:
produces a sum of two basis states (`mid = 0` and `mid = 1`) with
Hadamard coefficients.
theoremf_to_vec_update_false_eq_padEquiv
theorem f_to_vec_update_false_eq_padEquiv (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
f_to_vec dim (update f n false) = basis_vector (2^dim)
(padEquiv dim n h ((⟨funbool_to_nat n f, funbool_to_nat_lt n f⟩,
(0 : Fin 2)),
⟨funbool_to_nat (dim-n-1) (fun p => f (p+n+1)),
funbool_to_nat_lt _ _⟩)).val`f_to_vec dim (update f n false)` in `padEquiv` form (middle bit = 0).
theoremf_to_vec_update_true_eq_padEquiv
theorem f_to_vec_update_true_eq_padEquiv (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
f_to_vec dim (update f n true) = basis_vector (2^dim)
(padEquiv dim n h ((⟨funbool_to_nat n f, funbool_to_nat_lt n f⟩,
(1 : Fin 2)),
⟨funbool_to_nat (dim-n-1) (fun p => f (p+n+1)),
funbool_to_nat_lt _ _⟩)).val`f_to_vec dim (update f n true)` in `padEquiv` form (middle bit = 1).
theoremf_to_vec_H_proved
theorem f_to_vec_H_proved (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
pad_u dim n hMatrix * f_to_vec dim f
= (Real.sqrt 2 / 2 : ℂ) • f_to_vec dim (update f n false)
+ ((if f n then (-1 : ℂ) else 1) * (Real.sqrt 2 / 2 : ℂ))
• f_to_vec dim (update f n true)`pad_u dim n hMatrix` on `f_to_vec dim f`: produces a sum of two basis
states (n flipped to false, n flipped to true) with Hadamard weights.
Faithful translation of SQIR `f_to_vec_H` from `UnitaryOps.v`.
theoremrotation_TDAG
theorem rotation_TDAG : rotation 0 0 (-(Real.pi / 4)) = tdagMatrix
`rotation 0 0 (-π/4) = tdagMatrix`. Mirrors `rotation_T`.
theoremtMatrix_commutes_
theorem tMatrix_commutes_σz : tMatrix * σz = σz * tMatrix
`T · σz = σz · T`. Phase commutes with Pauli Z.
theoremsMatrix_commutes_
theorem sMatrix_commutes_σz : sMatrix * σz = σz * sMatrix
`S · σz = σz · S`.
theoremtdagMatrix_commutes_
theorem tdagMatrix_commutes_σz : tdagMatrix * σz = σz * tdagMatrix
`T† · σz = σz · T†`.
theoremsdagMatrix_commutes_
theorem sdagMatrix_commutes_σz : sdagMatrix * σz = σz * sdagMatrix
`S† · σz = σz · S†`.
theoremtMatrix_commutes_sMatrix
theorem tMatrix_commutes_sMatrix : tMatrix * sMatrix = sMatrix * tMatrix
`T · S = S · T`. Phase gates commute with each other. Two-line corollary
of `rotation_Rz_commutes`.
theoremtMatrix_commutes_sdagMatrix
theorem tMatrix_commutes_sdagMatrix : tMatrix * sdagMatrix = sdagMatrix * tMatrix
`T · S† = S† · T`.
theoremtdagMatrix_commutes_sMatrix
theorem tdagMatrix_commutes_sMatrix : tdagMatrix * sMatrix = sMatrix * tdagMatrix
`T† · S = S · T†`.
theoremtdagMatrix_commutes_sdagMatrix
theorem tdagMatrix_commutes_sdagMatrix :
tdagMatrix * sdagMatrix = sdagMatrix * tdagMatrix`T† · S† = S† · T†`.
theoremT_S_eq_S_T
theorem T_S_eq_S_T {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.T n : BaseUCom dim) (BaseUCom.S n))
= uc_eval (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.T n))Circuit equivalence: `T q ; S q ≡ S q ; T q`. Phase gates commute.
theoremT_SDAG_eq_SDAG_T
theorem T_SDAG_eq_SDAG_T {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.T n : BaseUCom dim) (BaseUCom.SDAG n))
= uc_eval (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.T n))Circuit equivalence: `T q ; S† q ≡ S† q ; T q`.
theoremTDAG_S_eq_S_TDAG
theorem TDAG_S_eq_S_TDAG {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.TDAG n : BaseUCom dim) (BaseUCom.S n))
= uc_eval (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.TDAG n))Circuit equivalence: `T† q ; S q ≡ S q ; T† q`.
theoremTDAG_SDAG_eq_SDAG_TDAG
theorem TDAG_SDAG_eq_SDAG_TDAG {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.TDAG n : BaseUCom dim) (BaseUCom.SDAG n))
= uc_eval (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.TDAG n))Circuit equivalence: `T† q ; S† q ≡ S† q ; T† q`.
theoremZ_S_eq_S_Z
theorem Z_S_eq_S_Z {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.Z n : BaseUCom dim) (BaseUCom.S n))
= uc_eval (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.Z n))Circuit equivalence: `Z q ; S q ≡ S q ; Z q`. Z and S are both Z-axis
rotations and commute.
theoremZ_T_eq_T_Z
theorem Z_T_eq_T_Z {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.Z n : BaseUCom dim) (BaseUCom.T n))
= uc_eval (UCom.seq (BaseUCom.T n : BaseUCom dim) (BaseUCom.Z n))Circuit equivalence: `Z q ; T q ≡ T q ; Z q`. Z and T commute.
theoremZ_SDAG_eq_SDAG_Z
theorem Z_SDAG_eq_SDAG_Z {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.Z n : BaseUCom dim) (BaseUCom.SDAG n))
= uc_eval (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.Z n))Circuit equivalence: `Z q ; S† q ≡ S† q ; Z q`.
theoremZ_TDAG_eq_TDAG_Z
theorem Z_TDAG_eq_TDAG_Z {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.Z n : BaseUCom dim) (BaseUCom.TDAG n))
= uc_eval (UCom.seq (BaseUCom.TDAG n : BaseUCom dim) (BaseUCom.Z n))Circuit equivalence: `Z q ; T† q ≡ T† q ; Z q`.
theoremf_to_vec_X_uc_eval
theorem f_to_vec_X_uc_eval (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (BaseUCom.X n : BaseUCom dim) * f_to_vec dim f
= f_to_vec dim (update f n (!f n))SQIR-faithful form of `f_to_vec_X` (Pauli X = bit flip).
Translates SQIR `UnitaryOps.v f_to_vec_X`.
theoremf_to_vec_T_uc_eval
theorem f_to_vec_T_uc_eval (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (BaseUCom.T n : BaseUCom dim) * f_to_vec dim f
= (if f n then Complex.exp (Complex.I * (Real.pi / 4)) else 1)
• f_to_vec dim fSQIR-faithful form of `f_to_vec_T`.
theoremf_to_vec_TDAG_uc_eval
theorem f_to_vec_TDAG_uc_eval (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (BaseUCom.TDAG n : BaseUCom dim) * f_to_vec dim f
= (if f n then Complex.exp (-(Complex.I * (Real.pi / 4))) else 1)
• f_to_vec dim fSQIR-faithful form of `f_to_vec_TDAG`.
theoremf_to_vec_H_uc_eval
theorem f_to_vec_H_uc_eval (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (BaseUCom.H n : BaseUCom dim) * f_to_vec dim f
= (Real.sqrt 2 / 2 : ℂ) • f_to_vec dim (update f n false)
+ ((if f n then (-1 : ℂ) else 1) * (Real.sqrt 2 / 2 : ℂ))
• f_to_vec dim (update f n true)SQIR-faithful form of `f_to_vec_H`.
theoremuc_eval_seq_mul
theorem uc_eval_seq_mul {dim : Nat} (c₁ c₂ : BaseUCom dim)
(v : Matrix (Fin (2^dim)) (Fin 1) ℂ) :
uc_eval (UCom.seq c₁ c₂) * v = uc_eval c₂ * (uc_eval c₁ * v)Apply a `seq` to a state vector: c₁ first, then c₂.
Useful for unrolling `(uc_eval (seq c₁ c₂)) * v` to
`uc_eval c₂ * (uc_eval c₁ * v)` in proofs that step gate-by-gate.
theoremmul_add_state
theorem mul_add_state {dim : Nat} (A : Square dim)
(v w : Matrix (Fin (2^dim)) (Fin 1) ℂ) :
A * (v + w) = A * v + A * wDistribute a matrix product over a sum-of-state-vectors: `A * (v + w) = A*v + A*w`.
The Hadamard introduces a sum, so chaining through later gates needs this.
theoremmul_smul_state
theorem mul_smul_state {dim : Nat} (A : Square dim) (c : ℂ)
(v : Matrix (Fin (2^dim)) (Fin 1) ℂ) :
A * (c • v) = c • (A * v)Distribute a matrix product over a scalar-multiplied state vector:
`A * (c • v) = c • (A * v)`.
theoremf_to_vec_SWAP
theorem f_to_vec_SWAP (dim a b : Nat) (ha : a < dim) (hb : b < dim) (hab : a ≠ b)
(f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.CNOT a b : BaseUCom dim)
(UCom.seq (BaseUCom.CNOT b a) (BaseUCom.CNOT a b)))
* f_to_vec dim f
= f_to_vec dim (update (update f a (f b)) b (f a))`SWAP a b = CNOT a b; CNOT b a; CNOT a b` swaps the values at qubits a and b
in any basis state.
theoremf_to_vec_Rz_Rz
theorem f_to_vec_Rz_Rz (dim n : Nat) (h : n < dim) (θ θ' : ℝ) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.Rz θ n : BaseUCom dim) (BaseUCom.Rz θ' n))
* f_to_vec dim f
= (if f n then Complex.exp (((θ + θ') : ℂ) * Complex.I) else 1) • f_to_vec dim f`Rz θ ; Rz θ'` on `f_to_vec dim f` adds the angles in the phase factor.
f-coord version of SQIR's `Rz_Rz_add`.
theoremf_to_vec_X_X
theorem f_to_vec_X_X (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.X n : BaseUCom dim) (BaseUCom.X n))
* f_to_vec dim f
= f_to_vec dim f`X q ; X q` is identity on `f_to_vec dim f`.
Mirrors SQIR's `X_X_id` at the f-coordinate level.
theoremf_to_vec_X_X_X
theorem f_to_vec_X_X_X (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.X n : BaseUCom dim) (BaseUCom.X n))
(BaseUCom.X n))
* f_to_vec dim f
= f_to_vec dim (update f n (!f n))`X q ; X q ; X q` acts as a single X on `f_to_vec dim f` (X³ = X).
theoremf_to_vec_X_X_X_X
theorem f_to_vec_X_X_X_X (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.X n : BaseUCom dim) (BaseUCom.X n))
(BaseUCom.X n)) (BaseUCom.X n))
* f_to_vec dim f
= f_to_vec dim f`X q ; X q ; X q ; X q` is identity on `f_to_vec dim f` (X⁴ = ID).
theoremf_to_vec_Z_Z
theorem f_to_vec_Z_Z (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.Z n : BaseUCom dim) (BaseUCom.Z n))
* f_to_vec dim f
= f_to_vec dim f`Z q ; Z q` is identity on `f_to_vec dim f`.
Z's two phase factors `(if f n then -1 else 1)` multiply to 1.
theoremf_to_vec_S_S
theorem f_to_vec_S_S (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.S n))
* f_to_vec dim f
= (if f n then (-1 : ℂ) else 1) • f_to_vec dim f`S q ; S q` acts as Z on `f_to_vec dim f` (since S² = Z). Combines
`S_S_eq_Z` (UnitarySem.lean) with `f_to_vec_Z_uc_eval`.
theoremf_to_vec_Z_Z_Z
theorem f_to_vec_Z_Z_Z (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.Z n : BaseUCom dim) (BaseUCom.Z n))
(BaseUCom.Z n))
* f_to_vec dim f
= (if f n then (-1 : ℂ) else 1) • f_to_vec dim f`Z q ; Z q ; Z q` acts as Z on `f_to_vec dim f` (Z³ = Z).
theoremf_to_vec_Z_Z_Z_Z
theorem f_to_vec_Z_Z_Z_Z (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (UCom.seq (BaseUCom.Z n : BaseUCom dim) (BaseUCom.Z n))
(BaseUCom.Z n)) (BaseUCom.Z n))
* f_to_vec dim f
= f_to_vec dim f`Z q ; Z q ; Z q ; Z q` is identity on `f_to_vec dim f` (Z⁴ = ID).
theoremf_to_vec_CNOT_CNOT
theorem f_to_vec_CNOT_CNOT (dim i j : Nat) (hi : i < dim) (hj : j < dim) (hij : i ≠ j)
(f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.CNOT i j : BaseUCom dim) (BaseUCom.CNOT i j))
* f_to_vec dim f
= f_to_vec dim f`CNOT i j ; CNOT i j` is identity on `f_to_vec dim f` (CNOT is involutive).
-- SQIR/SQIR/Equivalences.v line 109: CNOT_CNOT_id.
theoremf_to_vec_CNOT_CNOT_CNOT
theorem f_to_vec_CNOT_CNOT_CNOT (dim i j : Nat) (hi : i < dim) (hj : j < dim)
(hij : i ≠ j) (f : Nat → Bool) :
uc_eval (UCom.seq (UCom.seq (BaseUCom.CNOT i j : BaseUCom dim) (BaseUCom.CNOT i j))
(BaseUCom.CNOT i j))
* f_to_vec dim f
= f_to_vec dim (update f j (xor (f j) (f i)))`CNOT i j ; CNOT i j ; CNOT i j` acts as a single CNOT on
`f_to_vec dim f` (CNOT³ = CNOT, since CNOT² = ID).
-- SQIR/SQIR/Equivalences.v line ~120: 3-chain CNOT identity.
theoremf_to_vec_S_SDAG
theorem f_to_vec_S_SDAG (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.S n : BaseUCom dim) (BaseUCom.SDAG n))
* f_to_vec dim f
= f_to_vec dim f`S q ; S† q` is identity on `f_to_vec dim f`.
Phase factors `i * -i = 1` on |1⟩.
theoremf_to_vec_SDAG_S
theorem f_to_vec_SDAG_S (dim n : Nat) (h : n < dim) (f : Nat → Bool) :
uc_eval (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.S n))
* f_to_vec dim f
= f_to_vec dim f`S† q ; S q` is identity (symmetric companion).
theoremexp_pi4_mul_exp_neg_pi4_aux
theorem exp_pi4_mul_exp_neg_pi4_aux :
Complex.exp (Complex.I * (Real.pi / 4))
* Complex.exp (-(Complex.I * (Real.pi / 4))) = 1`exp(iπ/4) * exp(-iπ/4) = 1` (inline version, used before exp_pi4_mul_exp_neg_pi4
is declared).
theoremtMatrix_mul_tdagMatrix
theorem tMatrix_mul_tdagMatrix : tMatrix * tdagMatrix = σi
`tMatrix * tdagMatrix = σi` (T and T† are inverses at the matrix level).
theoremtdagMatrix_mul_tMatrix
theorem tdagMatrix_mul_tMatrix : tdagMatrix * tMatrix = σi
`tdagMatrix * tMatrix = σi`.
theoremsMatrix_mul_sdagMatrix
theorem sMatrix_mul_sdagMatrix : sMatrix * sdagMatrix = σi
`sMatrix * sdagMatrix = σi` (S and S† are inverses at the matrix level).
theoremsdagMatrix_mul_sMatrix
theorem sdagMatrix_mul_sMatrix : sdagMatrix * sMatrix = σi
`sdagMatrix * sMatrix = σi`.
theoremsMatrix_mul_sMatrix
theorem sMatrix_mul_sMatrix : sMatrix * sMatrix = σz
`sMatrix * sMatrix = σz` (S² = Z, since I² = -1).
theorempad_u_tMatrix_tdagMatrix
theorem pad_u_tMatrix_tdagMatrix {dim n : Nat} (h : n < dim) :
pad_u dim n tMatrix * pad_u dim n tdagMatrix = (1 : Square dim)T followed by TDAG is the identity at the padded level.
theorempad_u_tdagMatrix_tMatrix
theorem pad_u_tdagMatrix_tMatrix {dim n : Nat} (h : n < dim) :
pad_u dim n tdagMatrix * pad_u dim n tMatrix = (1 : Square dim)TDAG followed by T is the identity at the padded level.
theorempad_u_sMatrix_sdagMatrix
theorem pad_u_sMatrix_sdagMatrix {dim n : Nat} (h : n < dim) :
pad_u dim n sMatrix * pad_u dim n sdagMatrix = (1 : Square dim)S followed by SDAG is the identity at the padded level.
theorempad_u_sdagMatrix_sMatrix
theorem pad_u_sdagMatrix_sMatrix {dim n : Nat} (h : n < dim) :
pad_u dim n sdagMatrix * pad_u dim n sMatrix = (1 : Square dim)SDAG followed by S is the identity at the padded level.
theoremsdagMatrix_mul_sdagMatrix
theorem sdagMatrix_mul_sdagMatrix : sdagMatrix * sdagMatrix = σz
`sdagMatrix * sdagMatrix = σz` (S†² = Z, since (-I)² = -1).
theoremsMatrix_pow_three
theorem sMatrix_pow_three : sMatrix * sMatrix * sMatrix = sdagMatrix
`S³ = S†`. The S gate has order 4: S² = Z, S³ = S† (its inverse).
theoremsdagMatrix_pow_three
theorem sdagMatrix_pow_three : sdagMatrix * sdagMatrix * sdagMatrix = sMatrix
`S†³ = S`.
theoremSDAG_SDAG_eq_Z
theorem SDAG_SDAG_eq_Z {dim n : Nat} :
uc_eval (UCom.seq (BaseUCom.SDAG n : BaseUCom dim) (BaseUCom.SDAG n))
= uc_eval (BaseUCom.Z n : BaseUCom dim)Circuit equivalence: `S† q ; S† q ≡ Z q`. Lift of `sdagMatrix_mul_sdagMatrix`.
theoremz_mul_sMatrix
theorem σz_mul_sMatrix : σz * sMatrix = sdagMatrix
`σz · S = S†` at the matrix level (since Z·diag(1,i) = diag(1,-i)).
theoremz_mul_sdagMatrix
theorem σz_mul_sdagMatrix : σz * sdagMatrix = sMatrix
`σz · S† = S` at the matrix level.
FormalRV.Core.QuantumGate
FormalRV/Core/QuantumGate.lean
FormalRV.Framework.QuantumGate — quantum unitary circuit IR.
Lean translation of SQIR/SQIR/SQIR.v, narrowed to the base gate set
used in the SQIR formalization of Shor's algorithm. Targets
Shor-correctness as the end goal.
Hierarchy of IRs in this project:
- `Framework.Gate` (already written): RCIR-level reversible classical
circuits (I/X/CX/CCX/seq). Used for adders, modular multipliers,
lookups. Bit-vector semantics in `Framework.Semantics`.
- `Framework.QuantumGate` (this file): general unitary circuits with
a parametric R(θ,ϕ,λ) rotation gate and CNOT. Matrix semantics in
`Framework.UnitarySem`.
- Future: density-matrix / measurement semantics (SQIR's NDSem.v,
DensitySem.v) when we model the full Shor algorithm with classical
post-processing.
Refs:
- SQIR/SQIR/SQIR.v (this file's source)
- Peng et al. 2022 (arXiv:2204.07112) §2 — formal methods overview
inductiveBaseUnitary
inductive BaseUnitary : Nat → Type | R : ℝ → ℝ → ℝ → BaseUnitary 1 -- general 1-qubit rotation | CNOT : BaseUnitary 2
The arity-indexed unitary primitive set.
`BaseUnitary 1` covers all single-qubit gates via R(θ,ϕ,λ).
`BaseUnitary 2` is just CNOT. We don't need a 3-qubit primitive —
Toffoli is built from H/T/CNOT (see `CCX` below).
inductiveUCom
inductive UCom (U : Nat → Type) (dim : Nat) : Type | seq : UCom U dim → UCom U dim → UCom U dim | app1 : U 1 → Nat → UCom U dim | app2 : U 2 → Nat → Nat → UCom U dim | app3 : U 3 → Nat → Nat → Nat → UCom U dim
Unitary circuit over gate set `U`, acting on `dim` qubits.
Constructors:
- `seq` : sequential composition
- `app1 u n` : apply 1-qubit unitary `u` to qubit `n`
- `app2 u m n` : apply 2-qubit unitary `u` to qubits `m`, `n`
- `app3 u m n p` : apply 3-qubit unitary `u` to qubits `m`, `n`, `p`
(no 3-qubit gates in BaseUnitary; reserved for
future extensions like Toffoli decomposition study)
abbrevBaseUCom
abbrev BaseUCom (dim : Nat)
A `UCom` over the base unitary set.
defU_H
def U_H : BaseUnitary 1
Hadamard: R(π/2, 0, π).
defU_X
def U_X : BaseUnitary 1
Pauli X: R(π, 0, π).
defU_Y
def U_Y : BaseUnitary 1
Pauli Y: R(π, π/2, π/2).
defU_Z
def U_Z : BaseUnitary 1
Pauli Z: R(0, 0, π).
defU_I
def U_I : BaseUnitary 1
Identity: R(0, 0, 0).
defU_T
def U_T : BaseUnitary 1
T gate (π/8 rotation): Rz(π/4) = R(0, 0, π/4).
defU_TDAG
def U_TDAG : BaseUnitary 1
T-dagger: Rz(-π/4).
defU_S
def U_S : BaseUnitary 1
S gate (phase): Rz(π/2).
defU_SDAG
def U_SDAG : BaseUnitary 1
S-dagger: Rz(-π/2).
defU_Rz
def U_Rz (lam : ℝ) : BaseUnitary 1
General Z-axis rotation by angle `λ`: R(0, 0, λ).
defU_Rx
def U_Rx (th : ℝ) : BaseUnitary 1
General X-axis rotation by angle `θ`: R(θ, -π/2, π/2).
defU_Ry
def U_Ry (th : ℝ) : BaseUnitary 1
General Y-axis rotation by angle `θ`: R(θ, 0, 0).
defH
def H {dim : Nat} (n : Nat) : BaseUCom dimApply Hadamard to qubit `n`.
defX
def X {dim : Nat} (n : Nat) : BaseUCom dimApply Pauli X to qubit `n`.
defY
def Y {dim : Nat} (n : Nat) : BaseUCom dimApply Pauli Y to qubit `n`.
defZ
def Z {dim : Nat} (n : Nat) : BaseUCom dimApply Pauli Z to qubit `n`.
defID
def ID {dim : Nat} (n : Nat) : BaseUCom dimIdentity on qubit `n`.
defSKIP
def SKIP {dim : Nat} : BaseUCom dimA no-op (`SKIP` in SQIR). Identity on qubit 0; well-typed iff dim ≥ 1.
defT
def T {dim : Nat} (n : Nat) : BaseUCom dimT gate on qubit `n`.
defTDAG
def TDAG {dim : Nat} (n : Nat) : BaseUCom dimT-dagger on qubit `n`.
defS
def S {dim : Nat} (n : Nat) : BaseUCom dimS gate (= P, phase) on qubit `n`.
defSDAG
def SDAG {dim : Nat} (n : Nat) : BaseUCom dimS-dagger on qubit `n`.
defRz
def Rz {dim : Nat} (lam : ℝ) (n : Nat) : BaseUCom dimRz(λ) on qubit `n`.
defRx
def Rx {dim : Nat} (th : ℝ) (n : Nat) : BaseUCom dimRx(θ) on qubit `n`.
defRy
def Ry {dim : Nat} (th : ℝ) (n : Nat) : BaseUCom dimRy(θ) on qubit `n`.
defCNOT
def CNOT {dim : Nat} (c t : Nat) : BaseUCom dimCNOT with control `c`, target `t`.
defCZ
def CZ {dim : Nat} (m n : Nat) : BaseUCom dimControlled-Z = H · CNOT · H on the target.
Mirrors SQIR.v: `Definition CZ m n := H n ; CNOT m n ; H n`.
defSWAP
def SWAP {dim : Nat} (m n : Nat) : BaseUCom dimSWAP via three CNOTs.
Mirrors SQIR.v: `Definition SWAP m n := CNOT m n; CNOT n m; CNOT m n`.
defCCX
def CCX {dim : Nat} (a b c : Nat) : BaseUCom dimToffoli via the standard 7-T decomposition (SQIR.v line 67).
This is the canonical Cliffords+T realization of CCX:
H c ; CNOT b c ; T† c ; CNOT a c ;
T c ; CNOT b c ; T† c ; CNOT a c ;
CNOT a b ; T† b ; CNOT a b ;
T a ; T b ; T c ; H c
Counted as 7 T gates (T†, T appear 4 + 3 times; the textbook
accounting that gives "7 T per Toffoli").
defCCZ
def CCZ {dim : Nat} (a b c : Nat) : BaseUCom dimCCZ = CCX without the framing Hadamards (SQIR.v line 75).
inductiveUCom.WellTyped
inductive UCom.WellTyped {U : Nat → Type} : (dim : Nat) → UCom U dim → Prop
| seq {dim c₁ c₂} :
WellTyped dim c₁ → WellTyped dim c₂ → WellTyped dim (UCom.seq c₁ c₂)
| app1 {dim u n} :
n < dim → WellTyped dim (UCom.app1 u n)
| app2 {dim u m n} :
m < dim → n < dim → m ≠ n → WellTyped dim (UCom.app2 u m n)
| app3 {dim u m n p} :
m < dim → n < dim → p < dim → m ≠ n → n ≠ p → m ≠ p →
WellTyped dim (UCom.app3 u m n p)inductiveCom
inductive Com (U : Nat → Type) (dim : Nat) : Type | cskip : Com U dim | useq : Com U dim → Com U dim → Com U dim | embedU : UCom U dim → Com U dim | meas : Nat → Com U dim → Com U dim → Com U dim
General programs with measurement, parameterized over gate set `U`.
abbrevBaseCom
abbrev BaseCom (dim : Nat)
instanceU
instance {U : Nat → Type} {dim : Nat} : Coe (UCom U dim) (Com U dim)Coerce any UCom to a Com (transparent).
FormalRV.Core.QuantumLib
FormalRV/Core/QuantumLib.lean
FormalRV.Framework.QuantumLib — Lean implementation of the QuantumLib
helpers SQIR depends on.
Originally axiomatized; now being converted to real definitions one by one.
Each axiom that gets discharged here lets a downstream sorry in QPE.lean,
GateDecompositions.lean, or Shor/Order.lean become attackable.
Status: PARTIAL. Core state-vector helpers are defined; some
Shor-specific helpers (modmult, probability_of_success) remain
axiomatized pending circuit-implementation work.
deffunbool_to_nat
def funbool_to_nat : Nat → (Nat → Bool) → Nat | 0, _ => 0 | k+1, f => 2 * funbool_to_nat k f + (if f k then 1 else 0)
Encode the first k values of `f` as a natural number, big-endian:
`funbool_to_nat (k+1) f = 2 * funbool_to_nat k f + (if f k then 1 else 0)`.
Bit `(k-1-i)` of the result is `f i` (so `f 0` is the MSB).
theoremfunbool_to_nat_lt
theorem funbool_to_nat_lt (k : Nat) (f : Nat → Bool) : funbool_to_nat k f < 2^k
Recurrence by definition (kept as a named lemma for downstream use).
defbasis_vector
def basis_vector (n k : Nat) : Matrix (Fin n) (Fin 1) ℂ
The k-th computational basis state in `n`-dim space.
theorembasis_vector_apply_eq
theorem basis_vector_apply_eq (n k : Nat) (i : Fin n) (j : Fin 1) (h : i.val = k) :
basis_vector n k i j = 1`basis_vector` value at the matching index is 1.
theorembasis_vector_apply_ne
theorem basis_vector_apply_ne (n k : Nat) (i : Fin n) (j : Fin 1) (h : i.val ≠ k) :
basis_vector n k i j = 0`basis_vector` value at a non-matching index is 0.
deff_to_vec
def f_to_vec (n : Nat) (f : Nat → Bool) : Matrix (Fin (2^n)) (Fin 1) ℂ
The basis state |f(n-1)...f(0)⟩, encoded little-endian via funbool_to_nat.
defkron_zeros
def kron_zeros (k : Nat) : Matrix (Fin (2^k)) (Fin 1) ℂ
The all-zeros basis state on k qubits. Equals `basis_vector (2^k) 0`.
theoremfunbool_to_nat_const_false_aux
private theorem funbool_to_nat_const_false_aux (k : Nat) :
funbool_to_nat k (fun _ => false) = 0`funbool_to_nat n (fun _ => false) = 0`. (Restated here so it's available
above `kron_zeros_eq_f_to_vec_false`; re-stated as a `@[simp]` lemma below
for ergonomics.)
theoremkron_zeros_eq_f_to_vec_false
theorem kron_zeros_eq_f_to_vec_false (k : Nat) :
kron_zeros k = f_to_vec k (fun _ => false)theoremfunbool_to_nat_const_true
theorem funbool_to_nat_const_true (k : Nat) :
funbool_to_nat k (fun _ => true) = 2^k - 1Encoding the all-true function gives `2^k - 1`.
theoremf_to_vec_const_true
theorem f_to_vec_const_true (n : Nat) :
f_to_vec n (fun _ => true) = basis_vector (2^n) (2^n - 1)The all-ones state |1...1⟩ as `f_to_vec` of the constant-true function.
theoremf_to_vec_apply
theorem f_to_vec_apply (n : Nat) (f : Nat → Bool) (i : Fin (2^n)) (j : Fin 1) :
f_to_vec n f i j = if i.val = funbool_to_nat n f then 1 else 0Entry-wise formula for `f_to_vec`: 1 at index `funbool_to_nat n f`, 0 elsewhere.
theoremf_to_vec_apply_eq
theorem f_to_vec_apply_eq (n : Nat) (f : Nat → Bool) (i : Fin (2^n)) (j : Fin 1)
(h : i.val = funbool_to_nat n f) : f_to_vec n f i j = 1`f_to_vec` value at the matching index is 1.
theoremf_to_vec_apply_ne
theorem f_to_vec_apply_ne (n : Nat) (f : Nat → Bool) (i : Fin (2^n)) (j : Fin 1)
(h : i.val ≠ funbool_to_nat n f) : f_to_vec n f i j = 0`f_to_vec` value at a non-matching index is 0.
theoremf_to_vec_zero_apply
theorem f_to_vec_zero_apply (f : Nat → Bool) (i : Fin (2^0)) (j : Fin 1) :
f_to_vec 0 f i j = 1`f_to_vec 0` has only one entry (the trivial 1×1 column), and it's 1.
theoremf_to_vec_ne_zero
theorem f_to_vec_ne_zero (n : Nat) (f : Nat → Bool) :
f_to_vec n f ≠ 0`f_to_vec n f` is never the zero matrix (it's always a basis vector).
theorembasis_vector_ne_zero
theorem basis_vector_ne_zero (n k : Nat) (h : k < n) :
basis_vector n k ≠ 0`basis_vector n k ≠ 0` when `k < n` (the standard basis is nonzero).
theoremkron_zeros_ne_zero
theorem kron_zeros_ne_zero (k : Nat) : kron_zeros k ≠ 0
`kron_zeros k ≠ 0` (the all-zeros basis state is non-zero).
defkron_vec
noncomputable def kron_vec {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
Matrix (Fin (2^(a+b))) (Fin 1) ℂTensor product of two qubit-register state vectors.
defkron_vec_high
def kron_vec_high {a b : Nat} (i : Fin (2^(a+b))) : Fin (2^a)High-bits projection: extract the upper qubits' index from a composite
`Fin (2^(a+b))` index. `kron_vec_high i = i.val / 2^b`.
defkron_vec_low
def kron_vec_low {a b : Nat} (i : Fin (2^(a+b))) : Fin (2^b)Low-bits projection: extract the lower qubits' index from a composite
`Fin (2^(a+b))` index. `kron_vec_low i = i.val % 2^b`.
theoremkron_vec_apply
theorem kron_vec_apply {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ)
(i : Fin (2^(a+b))) (j : Fin 1) :
kron_vec ψ φ i j = ψ (kron_vec_high i) 0 * φ (kron_vec_low i) 0Explicit unfolding: `kron_vec ψ φ` at composite index `i` equals the
product of `ψ` at the high-bits projection and `φ` at the low-bits
projection. Direct restatement of the definition with the let-bindings
pulled out as named helpers.
theoremkron_vec_high_low_unique
theorem kron_vec_high_low_unique {a b : Nat} (i : Fin (2^(a+b))) :
i.val = (kron_vec_high i).val * 2^b + (kron_vec_low i).valThe high/low decomposition recovers the original composite index:
`i.val = high.val * 2^b + low.val`. Standard division-with-remainder
identity, the key fact behind the eventual `Fin (2^(a+b)) ≃ Fin 2^a × Fin 2^b`
reindexing for `Pure_State_Vector_kron`.
theoremkron_vec_high_low_inj
theorem kron_vec_high_low_inj {a b : Nat} (i₁ i₂ : Fin (2^(a+b)))
(hh : kron_vec_high i₁ = kron_vec_high i₂)
(hl : kron_vec_low i₁ = kron_vec_low i₂) :
i₁ = i₂Injectivity of the high/low projection pair: two composite indices
with equal high and low projections must be equal. Direct corollary
of `kron_vec_high_low_unique` plus `Fin.ext`.
defkron_vec_combine
def kron_vec_combine {a b : Nat} (j : Fin (2^a)) (k : Fin (2^b)) : Fin (2^(a+b))Composite-index assembly: given a high-bits index `j : Fin (2^a)` and
a low-bits index `k : Fin (2^b)`, build the corresponding composite
index `Fin (2^(a+b))` via `j * 2^b + k`. The inverse of the
`(kron_vec_high, kron_vec_low)` projection pair.
theoremkron_vec_high_combine
theorem kron_vec_high_combine {a b : Nat} (j : Fin (2^a)) (k : Fin (2^b)) :
kron_vec_high (kron_vec_combine j k) = jRound-trip: extracting the high bits from an assembled composite index
recovers the original high index. `(j * 2^b + k) / 2^b = j` since
`k < 2^b` makes the `k / 2^b` term vanish.
theoremkron_vec_low_combine
theorem kron_vec_low_combine {a b : Nat} (j : Fin (2^a)) (k : Fin (2^b)) :
kron_vec_low (kron_vec_combine j k) = kRound-trip: extracting the low bits from an assembled composite index
recovers the original low index. `(j * 2^b + k) % 2^b = k` since
`j * 2^b` is a multiple of `2^b` and `k < 2^b`.
theoremkron_vec_combine_high_low
theorem kron_vec_combine_high_low {a b : Nat} (i : Fin (2^(a+b))) :
kron_vec_combine (kron_vec_high i) (kron_vec_low i) = iThe other round-trip direction: assembling the high/low projections of
`i` reconstructs `i`. Closes the bijection
`Fin (2^a) × Fin (2^b) ≃ Fin (2^(a+b))` via `kron_vec_high_low_inj`.
theoremkron_vec_apply_combine
theorem kron_vec_apply_combine {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ)
(j : Fin (2^a)) (k : Fin (2^b)) :
kron_vec ψ φ (kron_vec_combine j k) 0 = ψ j 0 * φ k 0Apply formula via assembly: evaluating `kron_vec ψ φ` at the composite
index `combine j k` gives the clean tensor-product formula
`ψ j 0 * φ k 0`. The most useful unfolding lemma for sums over
`(j, k)` rather than over the composite index.
defkronEquiv
def kronEquiv (a b : Nat) : Fin (2^a) × Fin (2^b) ≃ Fin (2^(a+b))
The full bijection `Fin (2^a) × Fin (2^b) ≃ Fin (2^(a+b))` packaged
as an `Equiv`, using `kron_vec_combine` as the forward map and
`(kron_vec_high, kron_vec_low)` as the inverse. The round-trip lemmas
`kron_vec_high_combine`, `kron_vec_low_combine`, and
`kron_vec_combine_high_low` discharge the `left_inv` / `right_inv`
obligations. Used downstream with `Finset.sum_equiv` to reindex
sums over `Fin (2^(a+b))` as iterated sums over `(j, k)`.
theoremkron_vec_normSq_apply_combine
theorem kron_vec_normSq_apply_combine {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ)
(j : Fin (2^a)) (k : Fin (2^b)) :
Complex.normSq ((kron_vec ψ φ) (kron_vec_combine j k) 0)
= Complex.normSq (ψ j 0) * Complex.normSq (φ k 0)Per-element norm-factorization: at any composite index `combine j k`,
the squared modulus of `kron_vec ψ φ` factors as the product of
squared moduli of `ψ` and `φ` at `j` and `k`. Direct chain of
`kron_vec_apply_combine` and `Complex.normSq_mul`. The pointwise
fact behind `kron_vec_normSq_sum`.
theoremkron_vec_normSq_sum
theorem kron_vec_normSq_sum {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
∑ i : Fin (2^(a+b)), Complex.normSq ((kron_vec ψ φ) i 0)
= (∑ j : Fin (2^a), Complex.normSq (ψ j 0))
* (∑ k : Fin (2^b), Complex.normSq (φ k 0))Sum-factorization: the total squared norm of the tensor product factors
as the product of total squared norms. The standard
`‖ψ ⊗ φ‖² = ‖ψ‖² · ‖φ‖²` identity, lifted to component sums via the
`kronEquiv` bijection + `Fintype.sum_prod_type` + `Finset.mul_sum`.
theoremkron_vec_zero_left
theorem kron_vec_zero_left {a b : Nat} (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec (0 : Matrix (Fin (2^a)) (Fin 1) ℂ) φ = 0Bilinearity (left zero): `0 ⊗ᵥ φ = 0`. The tensor product
annihilates when either factor is zero.
theoremkron_vec_zero_right
theorem kron_vec_zero_right {a b : Nat} (ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) :
kron_vec ψ (0 : Matrix (Fin (2^b)) (Fin 1) ℂ) = 0Bilinearity (right zero): `ψ ⊗ᵥ 0 = 0`.
theoremkron_vec_neg_left
theorem kron_vec_neg_left {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec (-ψ) φ = -(kron_vec ψ φ)Negation distributes through the left factor: `(-ψ) ⊗ᵥ φ = -(ψ ⊗ᵥ φ)`.
theoremkron_vec_neg_right
theorem kron_vec_neg_right {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec ψ (-φ) = -(kron_vec ψ φ)Negation distributes through the right factor: `ψ ⊗ᵥ (-φ) = -(ψ ⊗ᵥ φ)`.
theoremkron_vec_smul_left
theorem kron_vec_smul_left {a b : Nat} (c : ℂ)
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec (c • ψ) φ = c • (kron_vec ψ φ)Scalar multiplication on the left factor: `(c • ψ) ⊗ᵥ φ = c • (ψ ⊗ᵥ φ)`.
theoremkron_vec_smul_right
theorem kron_vec_smul_right {a b : Nat} (c : ℂ)
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec ψ (c • φ) = c • (kron_vec ψ φ)Scalar multiplication on the right factor: `ψ ⊗ᵥ (c • φ) = c • (ψ ⊗ᵥ φ)`.
theoremkron_vec_add_left
theorem kron_vec_add_left {a b : Nat}
(ψ₁ ψ₂ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec (ψ₁ + ψ₂) φ = kron_vec ψ₁ φ + kron_vec ψ₂ φDistributivity over addition on the left factor:
`(ψ₁ + ψ₂) ⊗ᵥ φ = ψ₁ ⊗ᵥ φ + ψ₂ ⊗ᵥ φ`.
theoremkron_vec_add_right
theorem kron_vec_add_right {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ₁ φ₂ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec ψ (φ₁ + φ₂) = kron_vec ψ φ₁ + kron_vec ψ φ₂Distributivity over addition on the right factor:
`ψ ⊗ᵥ (φ₁ + φ₂) = ψ ⊗ᵥ φ₁ + ψ ⊗ᵥ φ₂`.
theoremkron_vec_smul_smul
theorem kron_vec_smul_smul {a b : Nat} (c d : ℂ)
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec (c • ψ) (d • φ) = (c * d) • (kron_vec ψ φ)Combined two-sided scalar multiplication: scaling each factor multiplies
the result by the product of scalars. Direct chain of the
`kron_vec_smul_left` / `_right` pair with `smul_smul`.
theoremkron_vec_sub_left
theorem kron_vec_sub_left {a b : Nat}
(ψ₁ ψ₂ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec (ψ₁ - ψ₂) φ = kron_vec ψ₁ φ - kron_vec ψ₂ φSubtraction distributes through the left factor:
`(ψ₁ - ψ₂) ⊗ᵥ φ = ψ₁ ⊗ᵥ φ - ψ₂ ⊗ᵥ φ`. Direct chain of
`kron_vec_add_left` and `kron_vec_neg_left`.
theoremkron_vec_sub_right
theorem kron_vec_sub_right {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ₁ φ₂ : Matrix (Fin (2^b)) (Fin 1) ℂ) :
kron_vec ψ (φ₁ - φ₂) = kron_vec ψ φ₁ - kron_vec ψ φ₂Subtraction distributes through the right factor:
`ψ ⊗ᵥ (φ₁ - φ₂) = ψ ⊗ᵥ φ₁ - ψ ⊗ᵥ φ₂`.
defPure_State_Vector
noncomputable def Pure_State_Vector {n : Nat} (ψ : Matrix (Fin n) (Fin 1) ℂ) : PropA state vector is "pure" iff its squared L2-norm is 1.
defprobability_of_outcome
noncomputable def probability_of_outcome {n : Nat}
(φ ψ : Matrix (Fin n) (Fin 1) ℂ) : ℝThe Born-rule probability of measuring `φ` from state `ψ`:
`|⟨φ|ψ⟩|² = |φ⃰ · ψ|²`.
theoremprobability_of_outcome_zero_left
theorem probability_of_outcome_zero_left {n : Nat} (ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome (0 : Matrix (Fin n) (Fin 1) ℂ) ψ = 0Zero φ gives zero probability (no overlap).
theoremprobability_of_outcome_zero_right
theorem probability_of_outcome_zero_right {n : Nat} (φ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome φ (0 : Matrix (Fin n) (Fin 1) ℂ) = 0Zero ψ gives zero probability.
theoremprobability_of_outcome_nonneg
theorem probability_of_outcome_nonneg {n : Nat}
(φ ψ : Matrix (Fin n) (Fin 1) ℂ) :
0 ≤ probability_of_outcome φ ψBorn-rule probabilities are always non-negative (norm-squared of a complex number).
theoremprobability_of_outcome_smul_right
theorem probability_of_outcome_smul_right {n : Nat}
(c : ℂ) (φ ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome φ (c • ψ)
= Complex.normSq c * probability_of_outcome φ ψScaling the outcome state scales the probability by `|c|²`.
theoremprobability_of_outcome_smul_left
theorem probability_of_outcome_smul_left {n : Nat}
(c : ℂ) (φ ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome (c • φ) ψ
= Complex.normSq c * probability_of_outcome φ ψScaling the projector φ by `c` also scales the probability by `|c|²`.
theoremprobability_of_outcome_neg_right
theorem probability_of_outcome_neg_right {n : Nat}
(φ ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome φ (-ψ) = probability_of_outcome φ ψNegating the outcome state doesn't change the probability — global-sign
is a unit-modulus phase factor.
theoremprobability_of_outcome_neg_left
theorem probability_of_outcome_neg_left {n : Nat}
(φ ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome (-φ) ψ = probability_of_outcome φ ψNegating the projector also doesn't change the probability.
theoremprobability_of_outcome_smul_exp_I_right
theorem probability_of_outcome_smul_exp_I_right {n : Nat}
(θ : ℝ) (φ ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome φ (Complex.exp (↑θ * Complex.I) • ψ)
= probability_of_outcome φ ψScaling the outcome state ψ by `exp(iθ)` doesn't change the probability —
the exp(iθ) factor has unit modulus, so |exp(iθ)|² = 1 contributes
trivially. The canonical global-phase invariance for Born-rule probabilities.
theoremprobability_of_outcome_smul_exp_I_left
theorem probability_of_outcome_smul_exp_I_left {n : Nat}
(θ : ℝ) (φ ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome (Complex.exp (↑θ * Complex.I) • φ) ψ
= probability_of_outcome φ ψScaling the projection state φ by `exp(iθ)` doesn't change the probability —
symmetric companion of `probability_of_outcome_smul_exp_I_right`.
theoremprobability_of_outcome_comm
theorem probability_of_outcome_comm {n : Nat}
(φ ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome φ ψ = probability_of_outcome ψ φBorn-rule probability is symmetric: `|⟨φ|ψ⟩|² = |⟨ψ|φ⟩|²`. The two inner
products differ only by complex conjugation, and `normSq` is invariant
under conjugation.
theoremprobability_of_outcome_self
theorem probability_of_outcome_self {n : Nat}
(ψ : Matrix (Fin n) (Fin 1) ℂ) (h : Pure_State_Vector ψ) :
probability_of_outcome ψ ψ = 1For a pure state ψ, the Born-rule self-overlap is exactly 1:
`|⟨ψ|ψ⟩|² = 1`. This is the consistency condition that makes
`probability_of_outcome` interpretable as a probability over the
standard ψ-basis.
deford
noncomputable def ord (a N : Nat) : Nat
Multiplicative order of `a` mod `N`: smallest positive `r` with
`a^r ≡ 1 mod N`, or `0` if no such `r` exists (i.e., `a` is not a
unit mod `N`). Defined as Mathlib's `orderOf` on the multiplicative
monoid of `ZMod N`.
defmodinv
noncomputable def modinv (a N : Nat) : Nat
Modular inverse of `a` mod `N`. Returns the natural-number
representative of `(a : ZMod N)⁻¹`; `0` when no inverse exists.
defmodmult_rev_anc
def modmult_rev_anc (n : Nat) : Nat
Number of ancilla qubits used by the modular-mult subcircuit.
axiomf_modmult_circuit
axiom f_modmult_circuit (a a_inv N n : Nat) : Nat → BaseUCom (n + modmult_rev_anc n)
The reversible modular multiplication circuit family.
axiomprobability_of_success
axiom probability_of_success
(a r N m n : Nat) (anc : Nat) (f : Nat → BaseUCom (n + anc)) : ℝProbability that Shor's algorithm succeeds in recovering the order.
defkappa
noncomputable def kappa : ℝ
Shor's success-probability constant κ = 4 · e⁻² / π² ≈ 0.055.
theoremkron_zeros_apply_zero
theorem kron_zeros_apply_zero (k : Nat) (h : 0 < 2^k
theoremkron_zeros_apply_ne_zero
theorem kron_zeros_apply_ne_zero (k : Nat) (i : Fin (2^k)) (j : Fin 1)
(h : i.val ≠ 0) : kron_zeros k i j = 0`kron_zeros` is 0 at any non-zero index.
defupdate
def update (f : Nat → Bool) (c : Nat) (v : Bool) : Nat → Bool
Function update: `update f c v` is `f` except at index `c` where it
returns `v`. Matches SQIR's `update` from QuantumLib.
theoremupdate_apply
theorem update_apply (f : Nat → Bool) (c i : Nat) (v : Bool) :
update f c v i = if i = c then v else f iDefinitional unfolding of `update`: ite on the index.
theoremupdate_comm
theorem update_comm (f : Nat → Bool) (i j : Nat) (X Y : Bool) (h : i ≠ j) :
update (update f i X) j Y = update (update f j Y) i XUpdates at distinct indices commute.
theoremfunbool_to_nat_congr
theorem funbool_to_nat_congr (n : Nat) (f g : Nat → Bool)
(hfg : ∀ i, i < n → f i = g i) :
funbool_to_nat n f = funbool_to_nat n g`funbool_to_nat n f` only depends on `f` at indices `[0, n)`.
theoremPure_State_Vector_basis_vector
theorem Pure_State_Vector_basis_vector (n k : Nat) (h : k < n) :
Pure_State_Vector (basis_vector n k)Computational basis states are pure.
theoremPure_State_Vector_f_to_vec
theorem Pure_State_Vector_f_to_vec (n : Nat) (f : Nat → Bool) :
Pure_State_Vector (f_to_vec n f)`f_to_vec n f` is a pure state vector.
theoremPure_State_Vector_kron_zeros
theorem Pure_State_Vector_kron_zeros (k : Nat) :
Pure_State_Vector (kron_zeros k)The all-zeros basis state on `k` qubits is pure.
theoremprobability_of_outcome_basis_self
theorem probability_of_outcome_basis_self (n k : Nat) (h : k < n) :
probability_of_outcome (basis_vector n k) (basis_vector n k) = 1Specialization of `probability_of_outcome_self` to computational
basis vectors — `|⟨e_k|e_k⟩|² = 1`.
theoremprobability_of_outcome_f_to_vec_self
theorem probability_of_outcome_f_to_vec_self (n : Nat) (f : Nat → Bool) :
probability_of_outcome (f_to_vec n f) (f_to_vec n f) = 1Specialization of `probability_of_outcome_self` to `f_to_vec`
boolean-encoded basis states.
theoremprobability_of_outcome_basis_orth
theorem probability_of_outcome_basis_orth (n j k : Nat) (h : j ≠ k) :
probability_of_outcome (basis_vector n j) (basis_vector n k) = 0Distinct computational basis states are orthogonal under the Born rule:
`j ≠ k → |⟨e_j|e_k⟩|² = 0`. The inner product `(e_j)ᴴ · e_k` vanishes
termwise — every index `i` makes at most one of the two indicator
factors nonzero.
theoremprobability_of_outcome_basis
theorem probability_of_outcome_basis (n j k : Nat) (hj : j < n) (hk : k < n) :
probability_of_outcome (basis_vector n j) (basis_vector n k)
= if j = k then 1 else 0Combined Kronecker-delta form: for valid indices `j, k < n`, the
Born-rule overlap of two basis vectors is 1 if equal, 0 otherwise.
theoremprobability_of_outcome_apply
theorem probability_of_outcome_apply {n : Nat} (φ ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome φ ψ
= Complex.normSq (∑ i : Fin n, star (φ i 0) * ψ i 0)General Born-rule expansion: `prob φ ψ = |∑ i, conj(φ_i) · ψ_i|²` —
the inner-product form, with the matrix multiplication unfolded.
theoremprobability_of_outcome_basis_apply
theorem probability_of_outcome_basis_apply (n k : Nat) (hk : k < n)
(ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome (basis_vector n k) ψ
= Complex.normSq (ψ ⟨k, hk⟩ 0)The Born-rule probability of measuring the `k`-th basis state from a
state vector `ψ` is exactly `|ψ k 0|²` — the squared amplitude of `ψ`
at index `k`. This is the canonical "amplitude → probability" rule.
theoremprobability_of_outcome_basis_finset_sum
theorem probability_of_outcome_basis_finset_sum {n : Nat}
(ψ : Matrix (Fin n) (Fin 1) ℂ) :
∑ k : Fin n, probability_of_outcome (basis_vector n k.val) ψ
= ∑ k : Fin n, Complex.normSq (ψ k 0)Completeness of computational-basis measurement: summing the Born-rule
probabilities over all basis outcomes recovers the L2-norm-squared of `ψ`.
Combined with `Pure_State_Vector ψ`, this yields the standard "total
probability = 1" guarantee.
theoremprobability_of_outcome_total
theorem probability_of_outcome_total {n : Nat}
(ψ : Matrix (Fin n) (Fin 1) ℂ) (h : Pure_State_Vector ψ) :
∑ k : Fin n, probability_of_outcome (basis_vector n k.val) ψ = 1Total-probability theorem: for any pure state `ψ`, the sum of Born-rule
probabilities over all computational-basis outcomes is exactly 1.
Direct chain of `probability_of_outcome_basis_finset_sum` with the
`Pure_State_Vector` definition.
theoremprobability_of_outcome_basis_le_one
theorem probability_of_outcome_basis_le_one (n k : Nat) (hk : k < n)
(ψ : Matrix (Fin n) (Fin 1) ℂ) (h : Pure_State_Vector ψ) :
probability_of_outcome (basis_vector n k) ψ ≤ 1For a pure state, the Born-rule probability of any single
computational-basis outcome is at most 1. Each term `|ψ_k|²` is
non-negative and bounded by the total sum, which equals 1 by purity.
theoremprobability_of_outcome_basis_finset_sum_le_one
theorem probability_of_outcome_basis_finset_sum_le_one {n : Nat}
(S : Finset (Fin n)) (ψ : Matrix (Fin n) (Fin 1) ℂ) (h : Pure_State_Vector ψ) :
∑ k ∈ S, probability_of_outcome (basis_vector n k.val) ψ ≤ 1Subset bound: for any pure state and any subset of basis outcomes,
the sum of Born probabilities is at most 1. The standard "successful
outcomes" bound used in QPE/Shor measurement-success arguments.
theoremprobability_of_outcome_basis_eq_zero_iff
theorem probability_of_outcome_basis_eq_zero_iff (n k : Nat) (hk : k < n)
(ψ : Matrix (Fin n) (Fin 1) ℂ) :
probability_of_outcome (basis_vector n k) ψ = 0 ↔ ψ ⟨k, hk⟩ 0 = 0The Born-rule probability of a basis outcome vanishes iff the
corresponding amplitude vanishes — a direct consequence of
`Complex.normSq_eq_zero`. Useful for "this measurement outcome is
unreachable" arguments.
theoremprobability_of_outcome_basis_pos
theorem probability_of_outcome_basis_pos (n k : Nat) (hk : k < n)
(ψ : Matrix (Fin n) (Fin 1) ℂ) (h : ψ ⟨k, hk⟩ 0 ≠ 0) :
0 < probability_of_outcome (basis_vector n k) ψStrict positivity: a nonzero amplitude gives a strictly positive
measurement probability. Contrapositive of
`probability_of_outcome_basis_eq_zero_iff`, useful for "this outcome
is reachable" arguments.
theoremprobability_of_outcome_basis_pos_iff
theorem probability_of_outcome_basis_pos_iff (n k : Nat) (hk : k < n)
(ψ : Matrix (Fin n) (Fin 1) ℂ) :
0 < probability_of_outcome (basis_vector n k) ψ ↔ ψ ⟨k, hk⟩ 0 ≠ 0Combined iff form: Born-rule probability is strictly positive iff
the corresponding amplitude is nonzero. Packages
`probability_of_outcome_basis_pos` with its converse.
theoremPure_State_Vector_ne_zero
theorem Pure_State_Vector_ne_zero {n : Nat} (ψ : Matrix (Fin n) (Fin 1) ℂ)
(h : Pure_State_Vector ψ) : ψ ≠ 0Pure state vectors are nonzero — their squared L2-norm sums to 1, but
the zero vector has L2-norm 0 ≠ 1.
theoremPure_State_Vector_neg
theorem Pure_State_Vector_neg {n : Nat} (ψ : Matrix (Fin n) (Fin 1) ℂ)
(h : Pure_State_Vector ψ) : Pure_State_Vector (-ψ)Pure state vectors stay pure under negation (since |−x|² = |x|²).
theoremPure_State_Vector_smul_unit
theorem Pure_State_Vector_smul_unit {n : Nat} (c : ℂ)
(hc : Complex.normSq c = 1) (ψ : Matrix (Fin n) (Fin 1) ℂ)
(h : Pure_State_Vector ψ) : Pure_State_Vector (c • ψ)Pure state vectors stay pure under unit-modulus scalar multiplication
(since |c·x|² = |c|² · |x|² = 1 · |x|²). Used for global-phase factors.
theoremPure_State_Vector_smul_exp_I
theorem Pure_State_Vector_smul_exp_I {n : Nat} (θ : ℝ)
(ψ : Matrix (Fin n) (Fin 1) ℂ) (h : Pure_State_Vector ψ) :
Pure_State_Vector (Complex.exp (↑θ * Complex.I) • ψ)Specialization of `Pure_State_Vector_smul_unit` to `c = exp(iθ)`
(always unit modulus for real θ). The most useful instance — captures
the standard global-phase-factor case used throughout quantum computing.
theoremPure_State_Vector_kron
theorem Pure_State_Vector_kron {a b : Nat}
(ψ : Matrix (Fin (2^a)) (Fin 1) ℂ) (φ : Matrix (Fin (2^b)) (Fin 1) ℂ)
(hψ : Pure_State_Vector ψ) (hφ : Pure_State_Vector φ) :
Pure_State_Vector (kron_vec ψ φ)The tensor product of two pure states is a pure state. Direct
1-line corollary of `kron_vec_normSq_sum`: ‖ψ ⊗ φ‖² = ‖ψ‖² · ‖φ‖²
= 1 · 1 = 1. The capstone of the kron_vec layer.
theoremPure_State_Vector_kron_basis_vector
theorem Pure_State_Vector_kron_basis_vector {a b : Nat}
(j : Fin (2^a)) (k : Fin (2^b)) :
Pure_State_Vector
(kron_vec (basis_vector (2^a) j.val) (basis_vector (2^b) k.val))The tensor product of two computational basis states is a pure state.
Direct corollary of `Pure_State_Vector_kron` and
`Pure_State_Vector_basis_vector`.
theoremPure_State_Vector_kron_f_to_vec
theorem Pure_State_Vector_kron_f_to_vec {a b : Nat} (f g : Nat → Bool) :
Pure_State_Vector (kron_vec (f_to_vec a f) (f_to_vec b g))The tensor product of two boolean-encoded basis states is a pure state.
Symmetric companion of `Pure_State_Vector_kron_basis_vector` using
`f_to_vec`.
FormalRV.Core.Semantics
FormalRV/Core/Semantics.lean
FormalRV.Framework.Semantics — RCIR-level (bit-vector) semantics for
the `Gate` IR.
Mirrors SQIR's `bcexec : bccom -> nat -> bv -> bv` (RCIR.v). At this
semantic level we treat states as classical bit-vectors and gates as
reversible functions on them — sufficient for proving arithmetic
subroutines correct (adders, modular multipliers, lookups), which is
what BQ-Algo needs first.
The full quantum semantic (gate-as-unitary, state-as-complex-vector)
is deferred to `Framework/QuantumSemantics.lean` (not yet created) and
will only be needed once BQ-Algo reasons about QPE-level correctness.
Note on equality: bare `apply g s = f s` for `s : Fin n → Bool` requires
`funext` since function equality isn't `decide`-able in Lean core. We
state correctness pointwise (`∀ i, apply g s i = f s i`) which `decide`
can dispatch via `Fin n` being a Fintype.
abbrevState
abbrev State (n : Nat)
An n-qubit classical state: a function from qubit index to its
Boolean value.
defgetBit
def getBit (s : State n) (i : Nat) : Bool
Read bit `i` from state `s`; out-of-bounds reads return `false`
(matching SQIR's convention).
defflipBit
def flipBit (s : State n) (i : Nat) : State n
Flip bit `i` in state `s`; out-of-bounds writes are no-ops.
example(example)
example : getBit (n
Smoke checks.
example(example)
example : getBit (n
example(example)
example : getBit (n
defapply
def apply (g : Gate) (s : State n) : State n
Apply a `Gate` to a classical state, deterministically.
All gates here are classical-reversible, so this fully captures
their action (no superposition needed).
defmkState3
def mkState3 (b₀ b₁ b₂ : Bool) : State 3
Concrete 3-qubit state with bits `b₀ b₁ b₂`.
example(example)
example : ∀ i, apply (X 1) (mkState3 false true false) i
= mkState3 false false false iX on qubit 1 flips bit 1, leaves others alone.
example(example)
example : ∀ i, apply (CX 0 1) (mkState3 true false false) i
= mkState3 true true false iCX (control 0, target 1) with control set ⇒ target flips.
example(example)
example : ∀ i, apply (CX 0 1) (mkState3 false false false) i
= mkState3 false false false iCX with control unset ⇒ target unchanged.
example(example)
example : ∀ i, apply (CCX 0 1 2) (mkState3 true true false) i
= mkState3 true true true iCCX with both controls set ⇒ target flips.
example(example)
example : ∀ i, apply (CCX 0 1 2) (mkState3 true false false) i
= mkState3 true false false iCCX with one control unset ⇒ target unchanged.
defimplements
def implements (g : Gate) (f : State n → State n) : Prop
`g` implements `f` (as bit-vector functions) iff for every input state
and every bit index, `apply g s` and `f s` agree at that bit.
example(example)
example : implements (n
The identity gate implements the identity function.
FormalRV.Core.UnitaryOps
FormalRV/Core/UnitaryOps.lean
FormalRV.Framework.UnitaryOps — circuit operations beyond `useq`.
Lean translation of `SQIR/SQIR/UnitaryOps.v` (1482 LOC of Coq).
This file builds on `Framework.UnitarySem`. SQIR's UnitaryOps.v contains:
- inversion (`invert`)
- control / classical projection
- iteration (`niter`)
- parallel composition (`npar`)
- reversal of qubits
Many lemmas in this file depend on `pad_ctrl` (currently sorried) and
on per-gate matrix equivalences. Where dependencies aren't filled, we
state the theorem and `sorry` it with a clear note.
Status: scaffolding. Each translation goes in dependency order.
definvert
noncomputable def invert {dim : Nat} : BaseUCom dim → BaseUCom dim
| UCom.seq c₁ c₂ => UCom.seq (invert c₂) (invert c₁)
| UCom.app1 (R θ ϕ lam) n => UCom.app1 (R (-θ) (-lam) (-ϕ)) n
| UCom.app2 BaseUnitary.CNOT m n => UCom.app2 BaseUnitary.CNOT m n
| UCom.app3 _ _ _ _ => SKIP -- no 3-qubit primitives in BaseUnitaryInvert a `BaseUCom`, producing the unitary that undoes it.
theoremWellTyped_seq_iff
theorem WellTyped_seq_iff {dim : Nat} (c1 c2 : BaseUCom dim) :
UCom.WellTyped dim (UCom.seq c1 c2)
↔ UCom.WellTyped dim c1 ∧ UCom.WellTyped dim c2WellTyped of a sequence is iff WellTyped of both pieces. Useful as
a simp normalization: reduces structural WellTyped goals on seq
to component goals.
theoremWellTyped_app1_iff
theorem WellTyped_app1_iff {dim : Nat} (u : BaseUnitary 1) (n : Nat) :
UCom.WellTyped dim (UCom.app1 u n : BaseUCom dim) ↔ n < dimWellTyped of a 1-qubit application is iff the qubit index is in range.
theoremWellTyped_app2_iff
theorem WellTyped_app2_iff {dim : Nat} (u : BaseUnitary 2) (m n : Nat) :
UCom.WellTyped dim (UCom.app2 u m n : BaseUCom dim)
↔ m < dim ∧ n < dim ∧ m ≠ nWellTyped of a 2-qubit application is iff both indices are in range
and they are distinct.
theoremX_well_typed
theorem X_well_typed {dim : Nat} (n : Nat) (h : n < dim) :
UCom.WellTyped dim (X n : BaseUCom dim)`X n` is WellTyped when `n < dim`.
theoremY_well_typed
theorem Y_well_typed {dim : Nat} (n : Nat) (h : n < dim) :
UCom.WellTyped dim (Y n : BaseUCom dim)`Y n` is WellTyped when `n < dim`.
theoremZ_well_typed
theorem Z_well_typed {dim : Nat} (n : Nat) (h : n < dim) :
UCom.WellTyped dim (Z n : BaseUCom dim)`Z n` is WellTyped when `n < dim`.
theoremH_well_typed
theorem H_well_typed {dim : Nat} (n : Nat) (h : n < dim) :
UCom.WellTyped dim (H n : BaseUCom dim)`H n` is WellTyped when `n < dim`.
theoremT_well_typed
theorem T_well_typed {dim : Nat} (n : Nat) (h : n < dim) :
UCom.WellTyped dim (T n : BaseUCom dim)`T n` is WellTyped when `n < dim`.
theoremTDAG_well_typed
theorem TDAG_well_typed {dim : Nat} (n : Nat) (h : n < dim) :
UCom.WellTyped dim (TDAG n : BaseUCom dim)`TDAG n` is WellTyped when `n < dim`.
theoremS_well_typed
theorem S_well_typed {dim : Nat} (n : Nat) (h : n < dim) :
UCom.WellTyped dim (S n : BaseUCom dim)`S n` is WellTyped when `n < dim`.
theoremSDAG_well_typed
theorem SDAG_well_typed {dim : Nat} (n : Nat) (h : n < dim) :
UCom.WellTyped dim (SDAG n : BaseUCom dim)`SDAG n` is WellTyped when `n < dim`.
theoremID_well_typed
theorem ID_well_typed {dim : Nat} (n : Nat) (h : n < dim) :
UCom.WellTyped dim (ID n : BaseUCom dim)`ID n` is WellTyped when `n < dim`.
theoremRz_well_typed
theorem Rz_well_typed {dim : Nat} (θ : ℝ) (n : Nat) (h : n < dim) :
UCom.WellTyped dim (Rz θ n : BaseUCom dim)`Rz θ n` is WellTyped when `n < dim` (parametric).
theoremCNOT_well_typed
theorem CNOT_well_typed {dim : Nat} (m n : Nat)
(hm : m < dim) (hn : n < dim) (hmn : m ≠ n) :
UCom.WellTyped dim (CNOT m n : BaseUCom dim)`CNOT m n` is WellTyped when both qubits are in range and distinct.
theoremSWAP_well_typed
theorem SWAP_well_typed {dim : Nat} (m n : Nat)
(hm : m < dim) (hn : n < dim) (hmn : m ≠ n) :
UCom.WellTyped dim (SWAP m n : BaseUCom dim)`SWAP m n` is WellTyped when both qubits are in range and distinct.
SWAP unfolds to a 3-CNOT chain — apply WellTyped_seq_iff repeatedly
plus CNOT_well_typed for each piece.
theoremCCX_well_typed
theorem CCX_well_typed {dim : Nat} (a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
UCom.WellTyped dim (CCX a b c : BaseUCom dim)`CCX a b c` (Toffoli, 15-gate decomposition) is WellTyped when all
three qubits are in range and pairwise distinct.
theoremCCZ_well_typed
theorem CCZ_well_typed {dim : Nat} (a b c : Nat)
(ha : a < dim) (hb : b < dim) (hc : c < dim)
(hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) :
UCom.WellTyped dim (CCZ a b c : BaseUCom dim)`CCZ a b c` (controlled-controlled-Z, 13-gate decomposition: CCX
without the framing Hadamards) is WellTyped when all three qubits
are in range and pairwise distinct.
theoremWellTyped_invert
theorem WellTyped_invert {dim : Nat} (c : BaseUCom dim)
(h : UCom.WellTyped dim c) : UCom.WellTyped dim (invert c)`invert` preserves WellTyped: if c is WellTyped on dim qubits then so
is invert c. The app3 case (no 3-qubit primitives in BaseUnitary) maps
to SKIP which needs 0 < dim — derived from any of the qubit indices.
theoreminvert_Rz
theorem invert_Rz {dim : Nat} (θ : ℝ) (q : Nat) :
UCom.equiv (invert (Rz θ q : BaseUCom dim)) (Rz (-θ) q)Inverting a Z-rotation negates the angle. Matrix-level equivalence
since `invert (R 0 0 θ) = R (-0) (-θ) (-0)` syntactically while
`Rz (-θ) = R 0 0 (-θ)` — the two rotations agree pointwise (both
diag(1, exp(-iθ))). SQIR/UnitaryOps.v: `invert_Rz`.
theoreminvert_T
theorem invert_T {dim : Nat} (q : Nat) :
UCom.equiv (invert (T q : BaseUCom dim)) (TDAG q)Inverting T gives T† at the matrix level.
theoreminvert_S
theorem invert_S {dim : Nat} (q : Nat) :
UCom.equiv (invert (S q : BaseUCom dim)) (SDAG q)Inverting S gives S† at the matrix level.
theoreminvert_TDAG
theorem invert_TDAG {dim : Nat} (q : Nat) :
UCom.equiv (invert (TDAG q : BaseUCom dim)) (T q)Inverting T† gives T at the matrix level (the reverse direction).
theoreminvert_SDAG
theorem invert_SDAG {dim : Nat} (q : Nat) :
UCom.equiv (invert (SDAG q : BaseUCom dim)) (S q)Inverting S† gives S at the matrix level.
theoreminvert_ID
theorem invert_ID {dim : Nat} (q : Nat) :
UCom.equiv (invert (ID q : BaseUCom dim)) (ID q)`invert (ID q) ≡ ID q` — the identity gate is its own inverse at the
matrix level. ID q is just SKIP at qubit q (rotation 0 0 0), and
invert maps (R 0 0 0) → (R (-0) (-0) (-0)) which simp closes via neg_zero.
theoreminvert_Z
theorem invert_Z {dim : Nat} (q : Nat) :
UCom.equiv (invert (Z q : BaseUCom dim)) (Z q)`invert (Z q) ≡ Z q` — Z is its own inverse since Z² = I (involution).
At the matrix level, both sides reduce to σz: the LHS rotation
`(-0) (-π) (-0)` is diag(1, exp(-iπ)) = diag(1, -1), the RHS rotation
`0 0 π` is diag(1, exp(iπ)) = diag(1, -1).
theoreminvert_X
theorem invert_X {dim : Nat} (q : Nat) :
UCom.equiv (invert (X q : BaseUCom dim)) (X q)`invert (X q) ≡ X q` — X is its own inverse (involution: X² = I).
Both rotations evaluate to σx; the off-diagonal entries match via
`sin(-π/2) = -sin(π/2)` and the exp factors cancel via
`Complex.exp_pi_mul_I` / `Complex.exp_neg`.
theoreminvert_Y
theorem invert_Y {dim : Nat} (q : Nat) :
UCom.equiv (invert (Y q : BaseUCom dim)) (Y q)`invert (Y q) ≡ Y q` — Y is its own inverse (involution: Y² = I).
Both rotations evaluate to σy. The off-diagonal entries match
via `sin(-π/2) = -1` combined with `exp(-iπ/2) = -i`.
theoreminvert_H
theorem invert_H {dim : Nat} (q : Nat) :
UCom.equiv (invert (H q : BaseUCom dim)) (H q)`invert (H q) ≡ H q` — Hadamard is its own inverse (involution: H² = I).
Both rotations evaluate to hMatrix. Unlike X/Y/Z, all four matrix
entries are non-zero (±1/√2), so each cell needs `cos(π/4)` /
`sin(π/4)` reductions plus the exp factor cancellations.
theoreminvert_invert
theorem invert_invert {dim : Nat} (c : BaseUCom dim) :
invert (invert c) = cInvolutivity of `invert`: `invert (invert c) = c` syntactically.
`BaseUnitary 3` has no constructors, so the `app3` case is vacuous;
the other cases reduce by recursion (`seq` via the IH, `app1` via
`neg_neg`, `app2` via `cases u`).
defniter
def niter {dim : Nat} (n : Nat) (c : BaseUCom dim) : BaseUCom dim`niter n c` applies circuit `c` exactly `n` times in sequence.
Base case: `niter 0 c = SKIP`.
theoremuc_eval_niter_zero
theorem uc_eval_niter_zero {dim : Nat} (c : BaseUCom dim) :
uc_eval (niter 0 c) = uc_eval (SKIP : BaseUCom dim)Definitional unfolding of `uc_eval` on `niter 0`: equals SKIP's matrix.
theoremuc_eval_niter_succ
theorem uc_eval_niter_succ {dim : Nat} (n : Nat) (c : BaseUCom dim) :
uc_eval (niter (n + 1) c) = uc_eval (niter n c) * uc_eval cDefinitional unfolding of `uc_eval` on `niter (n+1)`.
theoremniter_one_eq
theorem niter_one_eq {dim : Nat} (c : BaseUCom dim) :
niter 1 c = UCom.seq c SKIP`niter 1 c ≡ c ; SKIP`. (And `c ; SKIP ≡ c` by `SKIP_id_r`.)
theoremniter_one
theorem niter_one {dim : Nat} (c : BaseUCom dim) (h : 0 < dim) :
UCom.equiv (niter 1 c) c`niter 1 c ≡ c` (under `UCom.equiv`). Combines `niter_one_eq` with
`SKIP_id_r` (the right-skip elimination).
theoremuc_eval_niter
theorem uc_eval_niter {dim : Nat} (h : 0 < dim) (n : Nat) (c : BaseUCom dim) :
uc_eval (niter n c) = (uc_eval c)^n`uc_eval (niter n c) = (uc_eval c)^n` — n-fold iteration is the
n-th matrix power. Note: at `n=0` returns the SKIP matrix
(`pad_u dim 0 σi`), which equals `(uc_eval c)^0 = 1` only when
`dim > 0`. For unrestricted `n`, this requires `0 < dim`.
theoremniter_add
theorem niter_add {dim : Nat} (k1 k2 : Nat) (c : BaseUCom dim) (hd : 0 < dim) :
UCom.equiv (UCom.seq (niter k2 c) (niter k1 c)) (niter (k1 + k2) c)`niter k1 c ; niter k2 c ≡ niter (k1 + k2) c` — niter is additive
in the iteration count, mirroring `pow_add` at the matrix level.
Requires `0 < dim` since the n=0 base of niter relies on `pad_u_id`.
theoremniter_mul
theorem niter_mul {dim : Nat} (k1 k2 : Nat) (c : BaseUCom dim) (hd : 0 < dim) :
UCom.equiv (niter (k1 * k2) c) (niter k2 (niter k1 c))`niter (k1 * k2) c ≡ niter k2 (niter k1 c)` — composing iterations
matches `pow_mul` at the matrix level: A^(k1*k2) = (A^k1)^k2.
theoremniter_congr
theorem niter_congr {dim : Nat} (k : Nat) (c c' : BaseUCom dim)
(h : UCom.equiv c c') (hd : 0 < dim) :
UCom.equiv (niter k c) (niter k c')`niter` preserves equivalence: if c ≡ c' then niter k c ≡ niter k c'.
Direct congruence — uc_eval (niter k c) = (uc_eval c)^k depends only
on uc_eval c, so equal evals give equal powers.
theoremniter_well_typed
theorem niter_well_typed {dim : Nat} (k : Nat) (c : BaseUCom dim)
(hc : UCom.WellTyped dim c) (hd : 0 < dim) :
UCom.WellTyped dim (niter k c)`niter k c` is WellTyped on dim qubits when `c` is WellTyped and `0 < dim`.
The 0 < dim is needed for the niter 0 = SKIP base case.
theoremniter_three_self_inv_eq_self
theorem niter_three_self_inv_eq_self {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseUCom dim) (h : UCom.equiv (niter 2 c) (ID q)) :
UCom.equiv (niter 3 c) cGeneric template: if `niter 2 c ≡ ID q`, then `niter 3 c ≡ c`.
Lifts X³=X, Y³=Y, Z³=Z, H³=H to a single parametric pattern.
Proof: niter 3 c = c ; niter 2 c, so uc_eval = uc_eval(niter 2 c) ·
uc_eval c = 1 · uc_eval c = uc_eval c (via the hypothesis).
theoremniter_Rz
theorem niter_Rz {dim : Nat} (q : Nat) (h : q < dim) (θ : ℝ) (k : Nat) :
UCom.equiv (niter k (Rz θ q : BaseUCom dim)) (Rz (k * θ) q)`niter k (Rz θ q) ≡ Rz (k·θ) q` — iterating a Z-rotation k times gives
a single Z-rotation by k·θ. Parametric BaseUCom-level lift of
`rotation_Rz_pow`. Requires `q < dim` (else pad_u_pow doesn't apply).
theoremniter_T_eq_Rz
theorem niter_T_eq_Rz {dim : Nat} (q : Nat) (h : q < dim) (k : Nat) :
UCom.equiv (niter k (T q : BaseUCom dim)) (Rz (k * (Real.pi/4)) q)`niter k (T q) ≡ Rz (k·π/4) q` — T iteration as a single Z-rotation.
theoremniter_TDAG_eq_Rz
theorem niter_TDAG_eq_Rz {dim : Nat} (q : Nat) (h : q < dim) (k : Nat) :
UCom.equiv (niter k (TDAG q : BaseUCom dim)) (Rz (k * (-(Real.pi/4))) q)`niter k (TDAG q) ≡ Rz (-k·π/4) q` — T† iteration as a single Z-rotation.
theoremniter_S_eq_Rz
theorem niter_S_eq_Rz {dim : Nat} (q : Nat) (h : q < dim) (k : Nat) :
UCom.equiv (niter k (S q : BaseUCom dim)) (Rz (k * (Real.pi/2)) q)`niter k (S q) ≡ Rz (k·π/2) q` — S iteration as a single Z-rotation.
theoremniter_SDAG_eq_Rz
theorem niter_SDAG_eq_Rz {dim : Nat} (q : Nat) (h : q < dim) (k : Nat) :
UCom.equiv (niter k (SDAG q : BaseUCom dim)) (Rz (k * (-(Real.pi/2))) q)`niter k (SDAG q) ≡ Rz (-k·π/2) q` — S† iteration as a single Z-rotation.
theoremniter_Z_eq_Rz
theorem niter_Z_eq_Rz {dim : Nat} (q : Nat) (h : q < dim) (k : Nat) :
UCom.equiv (niter k (Z q : BaseUCom dim)) (Rz (k * Real.pi) q)`niter k (Z q) ≡ Rz (k·π) q` — Z iteration as a single Z-rotation
(since Z = Rz π definitionally).
theoremniter_ID_eq_Rz
theorem niter_ID_eq_Rz {dim : Nat} (q : Nat) (h : q < dim) (k : Nat) :
UCom.equiv (niter k (ID q : BaseUCom dim)) (Rz (k * 0) q)`niter k (ID q) ≡ Rz (k·0) q ≡ Rz 0 q ≡ ID q` — ID iteration is just ID
(degenerate but consistent: ID q = Rz 0 q definitionally).
theoremniter_ID_eq_ID
theorem niter_ID_eq_ID {dim : Nat} (q : Nat) (h : q < dim) (k : Nat) :
UCom.equiv (niter k (ID q : BaseUCom dim)) (ID q)`niter k (ID q) ≡ ID q` for any k — ID iteration collapses back to ID.
Combines niter_ID_eq_Rz with the fact that k·0 = 0 and Rz 0 ≡ ID.
theoremniter_mul_eq_ID_of_eq_ID
theorem niter_mul_eq_ID_of_eq_ID {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseUCom dim) (m : Nat) (h : UCom.equiv (niter m c) (ID q)) (k : Nat) :
UCom.equiv (niter (m * k) c) (ID q)Most general template: if `niter m c ≡ ID q` (c has order dividing m),
then `niter (m*k) c ≡ ID q` for any k. Combines niter_mul, niter_congr,
and niter_ID_eq_ID. Generalizes both `niter_two_mul_self_inv_eq_ID`
(m=2) and order-4 lifts.
theoremniter_two_mul_self_inv_eq_ID
theorem niter_two_mul_self_inv_eq_ID {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseUCom dim) (h : UCom.equiv (niter 2 c) (ID q)) (k : Nat) :
UCom.equiv (niter (2 * k) c) (ID q)Specialization to order-2: if `niter 2 c ≡ ID q` (gate is involutive
at dim level), then `niter (2*k) c ≡ ID q` for any k.
theoremniter_eq_ID_of_dvd
theorem niter_eq_ID_of_dvd {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseUCom dim) (m : Nat) (h : UCom.equiv (niter m c) (ID q))
(n : Nat) (hdvd : m ∣ n) :
UCom.equiv (niter n c) (ID q)Divisibility version: if `niter m c ≡ ID q` and `m ∣ n`, then
`niter n c ≡ ID q`. The most ergonomic interface — destructures
the divisor witness and applies the multiplication template.
theoremniter_add_of_eq_ID
theorem niter_add_of_eq_ID {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseUCom dim) (m : Nat) (h : UCom.equiv (niter m c) (ID q)) (n : Nat) :
UCom.equiv (niter (m + n) c) (niter n c)Additive periodicity template: if `niter m c ≡ ID q`, then for any `n`,
`niter (m + n) c ≡ niter n c` — adding a full period to the iteration
count leaves the gate sequence unchanged. The dual to
`niter_eq_ID_of_dvd`: shifts iteration counts by multiples of the order.
theoremniter_succ_of_eq_ID
theorem niter_succ_of_eq_ID {dim : Nat} (q : Nat) (hq : q < dim)
(c : BaseUCom dim) (m : Nat) (h : UCom.equiv (niter m c) (ID q)) :
UCom.equiv (niter (m + 1) c) cSuccessor specialization: if `niter m c ≡ ID q`, then `niter (m+1) c ≡ c`.
The most common application — n = 1 case of `niter_add_of_eq_ID`,
composed with `niter_one`.
theoremniter_eight_T_eq_ID
theorem niter_eight_T_eq_ID {dim : Nat} (q : Nat) (h : q < dim) :
UCom.equiv (niter 8 (T q : BaseUCom dim)) (ID q)`niter 8 (T q) ≡ ID q` — T has order 8 (T⁸ = I), since 8·(π/4) = 2π
and Rz(2π) is the identity. The matrix-level T⁸ identity that's been
pending since we deferred the chain-form tMatrix_pow_eight.
theoremniter_eight_TDAG_eq_ID
theorem niter_eight_TDAG_eq_ID {dim : Nat} (q : Nat) (h : q < dim) :
UCom.equiv (niter 8 (TDAG q : BaseUCom dim)) (ID q)`niter 8 (TDAG q) ≡ ID q` — T† also has order 8 (T†⁸ = I), since
8·(-π/4) = -2π and Rz(-2π) is the identity. Symmetric companion to
niter_eight_T_eq_ID.
theoremniter_sixteen_T_eq_ID
theorem niter_sixteen_T_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 16 (T q : BaseUCom dim)) (ID q)`niter 16 (T q) ≡ ID q` — T has order 8, so order 16 = order 8 · 2.
theoremniter_sixteen_TDAG_eq_ID
theorem niter_sixteen_TDAG_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 16 (TDAG q : BaseUCom dim)) (ID q)`niter 16 (TDAG q) ≡ ID q` — symmetric companion.
theoremniter_nine_T_eq_T
theorem niter_nine_T_eq_T {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 9 (T q : BaseUCom dim)) (T q)`niter 9 (T q) ≡ T q` — T⁹ = T⁸·T = I·T = T. 1-line application of
`niter_succ_of_eq_ID` to `niter_eight_T_eq_ID`.
theoremniter_nine_TDAG_eq_TDAG
theorem niter_nine_TDAG_eq_TDAG {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 9 (TDAG q : BaseUCom dim)) (TDAG q)`niter 9 (TDAG q) ≡ TDAG q` — symmetric companion.
theoremniter_seventeen_T_eq_T
theorem niter_seventeen_T_eq_T {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 17 (T q : BaseUCom dim)) (T q)`niter 17 (T q) ≡ T q` — same template applied to the order-16 fact:
T¹⁷ = T¹⁶·T = I·T = T. 1-line application of `niter_succ_of_eq_ID`.
theoremniter_seventeen_TDAG_eq_TDAG
theorem niter_seventeen_TDAG_eq_TDAG {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 17 (TDAG q : BaseUCom dim)) (TDAG q)`niter 17 (TDAG q) ≡ TDAG q` — symmetric companion.
theoremniter_four_S_eq_ID
theorem niter_four_S_eq_ID {dim : Nat} (q : Nat) (h : q < dim) :
UCom.equiv (niter 4 (S q : BaseUCom dim)) (ID q)`niter 4 (S q) ≡ ID q` — S has order 4 (S⁴ = I), since 4·(π/2) = 2π.
Companion to niter_eight_T_eq_ID with k=4 instead of 8.
theoremniter_four_SDAG_eq_ID
theorem niter_four_SDAG_eq_ID {dim : Nat} (q : Nat) (h : q < dim) :
UCom.equiv (niter 4 (SDAG q : BaseUCom dim)) (ID q)`niter 4 (SDAG q) ≡ ID q` — S† also has order 4.
theoremniter_eight_S_eq_ID
theorem niter_eight_S_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 8 (S q : BaseUCom dim)) (ID q)`niter 8 (S q) ≡ ID q` — S has order 4, so order 8 = order 4 · 2.
1-line application of niter_mul_eq_ID_of_eq_ID with m=4, k=2.
theoremniter_eight_SDAG_eq_ID
theorem niter_eight_SDAG_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 8 (SDAG q : BaseUCom dim)) (ID q)`niter 8 (SDAG q) ≡ ID q` — symmetric companion.
theoremniter_nine_S_eq_S
theorem niter_nine_S_eq_S {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 9 (S q : BaseUCom dim)) (S q)`niter 9 (S q) ≡ S q` — S has order 4, S⁹ = S^(4·2+1) = (S⁴)²·S = I·S.
1-line application of `niter_succ_of_eq_ID` to `niter_eight_S_eq_ID`.
theoremniter_nine_SDAG_eq_SDAG
theorem niter_nine_SDAG_eq_SDAG {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 9 (SDAG q : BaseUCom dim)) (SDAG q)`niter 9 (SDAG q) ≡ SDAG q` — symmetric companion.
theoremniter_two_Z_eq_ID
theorem niter_two_Z_eq_ID {dim : Nat} (q : Nat) (h : q < dim) :
UCom.equiv (niter 2 (Z q : BaseUCom dim)) (ID q)`niter 2 (Z q) ≡ ID q` — Z has order 2 (Z² = I), since 2·π = 2π and
Rz(2π) is the identity. Companion to niter_two_Z_eq_SKIP but stated
with ID q on the RHS.
theoremniter_two_X_eq_SKIP
theorem niter_two_X_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 2 (X q : BaseUCom dim)) SKIP`niter 2 (X q) ≡ SKIP` — applying X twice via iteration is identity.
A demonstration of `uc_eval_niter` + the matrix-level σx² = σi.
theoremniter_two_Z_eq_SKIP
theorem niter_two_Z_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 2 (Z q : BaseUCom dim)) SKIP`niter 2 (Z q) ≡ SKIP` — Z is involutive.
theoremniter_two_H_eq_SKIP
theorem niter_two_H_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 2 (H q : BaseUCom dim)) SKIP`niter 2 (H q) ≡ SKIP` — H is involutive.
theoremniter_two_Y_eq_SKIP
theorem niter_two_Y_eq_SKIP {dim : Nat} (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter 2 (Y q : BaseUCom dim)) SKIP`niter 2 (Y q) ≡ SKIP` — Y is involutive.
theoremniter_two_X_eq_ID
theorem niter_two_X_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 2 (X q : BaseUCom dim)) (ID q)`niter 2 (X q) ≡ ID q`. Combines `niter_two_X_eq_SKIP` with
`ID_equiv_SKIP.symm` (no Z-rotation argument needed since X is on
a different axis).
theoremniter_two_Y_eq_ID
theorem niter_two_Y_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 2 (Y q : BaseUCom dim)) (ID q)`niter 2 (Y q) ≡ ID q`.
theoremniter_two_H_eq_ID
theorem niter_two_H_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 2 (H q : BaseUCom dim)) (ID q)`niter 2 (H q) ≡ ID q`.
theoremniter_three_X_eq_X
theorem niter_three_X_eq_X {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 3 (X q : BaseUCom dim)) (X q)`niter 3 (X q) ≡ X q` — X cubed equals X (involution).
theoremniter_three_Y_eq_Y
theorem niter_three_Y_eq_Y {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 3 (Y q : BaseUCom dim)) (Y q)`niter 3 (Y q) ≡ Y q` — Y cubed equals Y.
theoremniter_three_Z_eq_Z
theorem niter_three_Z_eq_Z {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 3 (Z q : BaseUCom dim)) (Z q)`niter 3 (Z q) ≡ Z q` — Z cubed equals Z.
theoremniter_three_H_eq_H
theorem niter_three_H_eq_H {dim : Nat} (q : Nat) (hd : 0 < dim) :
UCom.equiv (niter 3 (H q : BaseUCom dim)) (H q)`niter 3 (H q) ≡ H q` — H cubed equals H.
theoremniter_ID_eq_SKIP
theorem niter_ID_eq_SKIP {dim : Nat} (n : Nat) (q : Nat) (hq : q < dim) (hd : 0 < dim) :
UCom.equiv (niter n (ID q : BaseUCom dim)) SKIP`niter n (ID q) ≡ SKIP` for any `n` — iterating the identity gate is identity.
Parameterized over n: ID iterated any number of times is SKIP.
theoremniter_SKIP_eq_SKIP
theorem niter_SKIP_eq_SKIP {dim : Nat} (n : Nat) (hd : 0 < dim) :
UCom.equiv (niter n (SKIP : BaseUCom dim)) SKIP`niter n SKIP ≡ SKIP` for any `n` — iterating SKIP is SKIP.
defnpar
def npar {dim : Nat} (n : Nat) (g : Nat → BaseUCom dim) : BaseUCom dim`npar n g` applies the per-qubit gate `g k` to qubits 0, 1, ..., n−1
sequentially. Base case `npar 0 _ = SKIP`.
theoremuc_eval_npar_zero
theorem uc_eval_npar_zero {dim : Nat} (g : Nat → BaseUCom dim) :
uc_eval (npar 0 g) = uc_eval (SKIP : BaseUCom dim)Definitional unfolding of `uc_eval` on `npar 0`: equals SKIP's matrix.
theoremuc_eval_npar_succ
theorem uc_eval_npar_succ {dim : Nat} (n : Nat) (g : Nat → BaseUCom dim) :
uc_eval (npar (n + 1) g) = uc_eval (g n) * uc_eval (npar n g)Definitional unfolding of `uc_eval` on `npar (n+1)`: gate `g n` applied last.
theoremnpar_well_typed
theorem npar_well_typed {dim : Nat} (n : Nat) (g : Nat → BaseUCom dim) (hd : 0 < dim)
(hg : ∀ k, k < n → UCom.WellTyped dim (g k)) :
UCom.WellTyped dim (npar n g)`npar n g` is WellTyped on `dim` qubits when every `g k` for `k < n` is
WellTyped, plus `0 < dim` for the SKIP base case. Foundational lemma
for npar_H_well_typed and other npar-based circuits.
defnpar_H
noncomputable def npar_H {dim : Nat} (n : Nat) : BaseUCom dimA column of Hadamards: `H 0 ; H 1 ; ... ; H (n-1)`. The QFT pre-rotation.
theoremnpar_H_well_typed
theorem npar_H_well_typed {dim : Nat} (n : Nat) (h : n ≤ dim) (hd : 0 < dim) :
UCom.WellTyped dim (npar_H n : BaseUCom dim)`npar_H n` is WellTyped when `n ≤ dim` and `0 < dim`. Direct application
of `npar_well_typed` with `g k = H k` (each H k requires k < dim).
theoremuc_eval_npar_H_succ
theorem uc_eval_npar_H_succ {dim : Nat} (n : Nat) :
uc_eval (npar_H (n + 1) : BaseUCom dim)
= pad_u dim n hMatrix * uc_eval (npar_H n)Matrix form of npar_H's succ unfold: appending `H n` left-multiplies
by `pad_u dim n hMatrix`. Useful for inductive arguments on QFT.
theoremuc_eval_npar_H_zero
theorem uc_eval_npar_H_zero {dim : Nat} :
uc_eval (npar_H 0 : BaseUCom dim) = uc_eval (SKIP : BaseUCom dim)Matrix form of npar_H's zero unfold: equals SKIP's matrix. Trivial rfl.
theoremuc_eval_npar_H_zero_eq_one
theorem uc_eval_npar_H_zero_eq_one {dim : Nat} (h : 0 < dim) :
uc_eval (npar_H 0 : BaseUCom dim) = (1 : Square dim)npar_H 0 evaluates to the global identity matrix (when 0 < dim).
SKIP's matrix is `pad_u dim 0 σi = 1` via `rotation_I` + `pad_u_id`.
defbool_to_matrix
def bool_to_matrix (b : Bool) : Matrix (Fin 2) (Fin 2) ℂ
Map a bool to the corresponding 2×2 computational-basis projector.
defproj
noncomputable def proj (q dim : Nat) (b : Bool) : Square dim
Computational-basis projector at qubit `q` in a `dim`-qubit system.
theoremproj_mul_proj
theorem proj_mul_proj (q dim : Nat) (b : Bool) :
proj q dim b * proj q dim b = proj q dim b`proj q dim b` is idempotent: applying it twice gives the same projector.
Lift of `proj0_mul_proj0` / `proj1_mul_proj1` through `pad_u`.
theorembool_to_matrix_mul_ne
theorem bool_to_matrix_mul_ne (b b' : Bool) (h : b ≠ b') :
bool_to_matrix b * bool_to_matrix b' = 0Cross-product of basis-projector matrices vanishes when the bools differ.
theoremproj_mul_proj_ne
theorem proj_mul_proj_ne (q dim : Nat) (b b' : Bool) (h : b ≠ b') :
proj q dim b * proj q dim b' = 0`proj q dim b * proj q dim b' = 0` when `b ≠ b'`. Orthogonality of
computational-basis projectors at the n-qubit (padded) level.
theoremproj_true_add_proj_false
theorem proj_true_add_proj_false (q dim : Nat) (h : q < dim) :
proj q dim true + proj q dim false = (1 : Square dim)Completeness: `proj q dim true + proj q dim false = 1` (identity matrix)
when `q < dim`. The two basis projectors at the same qubit sum to identity.
defcontrolled_R
noncomputable def controlled_R {dim : Nat} (q t : Nat) (θ φ lam : ℝ) :
BaseUCom dim*Controlled-R(θ,φ,λ)** decomposition: 5-gate target-side circuit
`Rz · CNOT · R · CNOT · R` plus a control-side `Rz((φ+λ)/2)` to
absorb the global phase from the ABXBXC identity. Used by `control`
for the `app1 R` branch.
defcontrol
noncomputable def control {dim : Nat} (q : Nat) : BaseUCom dim → BaseUCom dim
| UCom.seq c₁ c₂ => UCom.seq (control q c₁) (control q c₂)
| UCom.app1 (BaseUnitary.R θ φ lam) t => controlled_R q t θ φ lam
| UCom.app2 BaseUnitary.CNOT m n => CCX q m n -- controlled-CNOT = Toffoli
| UCom.app3 _ _ _ _ => SKIP -- no 3-qubit primitivesControlled version of an arbitrary `BaseUCom`.
The control on `q` makes every gate in `c` conditional on |q⟩=|1⟩.
theoremcontrol_SKIP_eq
theorem control_SKIP_eq {dim : Nat} (q : Nat) :
control q (SKIP : BaseUCom dim) = controlled_R q 0 0 0 0Control of SKIP unfolds definitionally. SKIP = `ID 0 = app1 (R 0 0 0) 0`,
so `control q SKIP = controlled_R q 0 0 0 0`. Semantically this equals
`pad_ctrl dim q 0 (rotation 0 0 0) = pad_ctrl dim q 0 I = 1`; the
semantic equivalence is proved downstream once `pad_ctrl` of an
identity matrix is available (see `SQIRPort.ControlledGates`).
theoremcontrol_ID_eq
theorem control_ID_eq {dim : Nat} (q m : Nat) :
control q (ID m : BaseUCom dim) = controlled_R q m 0 0 0Control of any ID gate unfolds definitionally to `controlled_R q m 0 0 0`,
which is the matrix `pad_ctrl dim q m I = 1` semantically.
defis_fresh
def is_fresh {dim : Nat} (q : Nat) : BaseUCom dim → Prop
| UCom.seq c₁ c₂ => is_fresh q c₁ ∧ is_fresh q c₂
| UCom.app1 _ n => q ≠ n
| UCom.app2 _ m n => q ≠ m ∧ q ≠ n
| UCom.app3 _ a b c => q ≠ a ∧ q ≠ b ∧ q ≠ c`q` is "fresh" with respect to circuit `c` iff `c` doesn't act on qubit `q`.
This is the classical syntactic criterion for safe controlled-circuit
construction (control on a qubit not used by the body).
theoremfresh_X
theorem fresh_X {dim : Nat} (q₁ q₂ : Nat) :
q₁ ≠ q₂ ↔ is_fresh q₁ (X q₂ : BaseUCom dim)`is_fresh` characterization for X. -- SQIR/SQIR/UnitaryOps.v line 197: fresh_X.
theoremfresh_Z
theorem fresh_Z {dim : Nat} (q₁ q₂ : Nat) :
q₁ ≠ q₂ ↔ is_fresh q₁ (Z q₂ : BaseUCom dim)`is_fresh` characterization for Z.
theoremfresh_Y
theorem fresh_Y {dim : Nat} (q₁ q₂ : Nat) :
q₁ ≠ q₂ ↔ is_fresh q₁ (Y q₂ : BaseUCom dim)`is_fresh` characterization for Y.
theoremfresh_H
theorem fresh_H {dim : Nat} (q₁ q₂ : Nat) :
q₁ ≠ q₂ ↔ is_fresh q₁ (H q₂ : BaseUCom dim)`is_fresh` characterization for H. -- SQIR/SQIR/UnitaryOps.v line 205: fresh_H.
theoremfresh_T
theorem fresh_T {dim : Nat} (q₁ q₂ : Nat) :
q₁ ≠ q₂ ↔ is_fresh q₁ (T q₂ : BaseUCom dim)`is_fresh` characterization for T.
theoremfresh_S
theorem fresh_S {dim : Nat} (q₁ q₂ : Nat) :
q₁ ≠ q₂ ↔ is_fresh q₁ (S q₂ : BaseUCom dim)`is_fresh` characterization for S.
theoremfresh_TDAG
theorem fresh_TDAG {dim : Nat} (q₁ q₂ : Nat) :
q₁ ≠ q₂ ↔ is_fresh q₁ (TDAG q₂ : BaseUCom dim)`is_fresh` characterization for TDAG.
theoremfresh_SDAG
theorem fresh_SDAG {dim : Nat} (q₁ q₂ : Nat) :
q₁ ≠ q₂ ↔ is_fresh q₁ (SDAG q₂ : BaseUCom dim)`is_fresh` characterization for SDAG.
theoremfresh_CNOT
theorem fresh_CNOT {dim : Nat} (a b c : Nat) :
(a ≠ b ∧ a ≠ c) ↔ is_fresh a (CNOT b c : BaseUCom dim)`is_fresh` characterization for CNOT. Both qubits must differ from `a`.
-- SQIR/SQIR/UnitaryOps.v line 213: fresh_CNOT.
theoremfresh_seq
theorem fresh_seq {dim : Nat} (q : Nat) (c₁ c₂ : BaseUCom dim) :
is_fresh q (UCom.seq c₁ c₂) ↔ is_fresh q c₁ ∧ is_fresh q c₂`is_fresh` distributes over sequential composition: `q` is fresh in
`c1 ; c2` iff fresh in both. By definition.
theoremfresh_SKIP
theorem fresh_SKIP {dim : Nat} (q : Nat) :
q ≠ 0 ↔ is_fresh q (SKIP : BaseUCom dim)`is_fresh q SKIP` iff `q ≠ 0` (since `SKIP = ID 0`).
theoremfresh_CCX_mp
theorem fresh_CCX_mp {dim : Nat} (q a b c : Nat)
(ha : q ≠ a) (hb : q ≠ b) (hc : q ≠ c) :
is_fresh q (CCX a b c : BaseUCom dim)Forward direction of SQIR's `fresh_CCX`: if `q` differs from all three
target qubits, it's fresh in the 15-gate CCX decomposition.
-- SQIR/SQIR/UnitaryOps.v line 231 (forward direction).
theoremfresh_CCX_mpr
theorem fresh_CCX_mpr {dim : Nat} (q a b c : Nat)
(h : is_fresh q (CCX a b c : BaseUCom dim)) :
q ≠ a ∧ q ≠ b ∧ q ≠ cBackward direction of SQIR's `fresh_CCX`: extract the three inequalities.
-- SQIR/SQIR/UnitaryOps.v line 231 (backward direction).
theoremfresh_CCX
theorem fresh_CCX {dim : Nat} (q a b c : Nat) :
(q ≠ a ∧ q ≠ b ∧ q ≠ c) ↔ is_fresh q (CCX a b c : BaseUCom dim)SQIR's full `fresh_CCX` iff form.
theoremfresh_CCZ_mp
theorem fresh_CCZ_mp {dim : Nat} (q a b c : Nat)
(ha : q ≠ a) (hb : q ≠ b) (hc : q ≠ c) :
is_fresh q (CCZ a b c : BaseUCom dim)Forward direction: q ≠ a/b/c → fresh in CCZ (the 13-gate decomposition).
theoremfresh_CCZ_mpr
theorem fresh_CCZ_mpr {dim : Nat} (q a b c : Nat)
(h : is_fresh q (CCZ a b c : BaseUCom dim)) :
q ≠ a ∧ q ≠ b ∧ q ≠ cBackward direction for CCZ: extract the three inequalities from is_fresh.
theoremfresh_CCZ
theorem fresh_CCZ {dim : Nat} (q a b c : Nat) :
(q ≠ a ∧ q ≠ b ∧ q ≠ c) ↔ is_fresh q (CCZ a b c : BaseUCom dim)Full iff form for CCZ.
theoremfresh_SWAP
theorem fresh_SWAP {dim : Nat} (q m n : Nat) :
(q ≠ m ∧ q ≠ n) ↔ is_fresh q (SWAP m n : BaseUCom dim)`is_fresh` characterization for SWAP. SWAP = CNOT m n ; CNOT n m ; CNOT m n,
so q is fresh iff q ≠ m and q ≠ n.
theoremfresh_niter_succ
theorem fresh_niter_succ {dim : Nat} (q n : Nat) (c : BaseUCom dim) :
is_fresh q (niter (n + 1) c) ↔ is_fresh q c ∧ is_fresh q (niter n c)`is_fresh` distributes through `niter`'s successor: niter (n+1) c is
`c ; niter n c`, so q is fresh iff fresh in both.
theoremfresh_npar_succ
theorem fresh_npar_succ {dim : Nat} (q n : Nat) (g : Nat → BaseUCom dim) :
is_fresh q (npar (n + 1) g) ↔ is_fresh q (npar n g) ∧ is_fresh q (g n)`is_fresh` distributes through `npar`'s successor: npar (n+1) g is
`npar n g ; g n`, so q is fresh iff fresh in both.
theoremfresh_niter
theorem fresh_niter {dim : Nat} (q n : Nat) (c : BaseUCom dim)
(hc : is_fresh q c) (hq : q ≠ 0) :
is_fresh q (niter n c)If `q` is fresh in `c` (and q ≠ 0 for the SKIP base case), then `q` is
fresh in any iteration `niter n c`.
theoremfresh_npar
theorem fresh_npar {dim : Nat} (q n : Nat) (g : Nat → BaseUCom dim)
(hg : ∀ k, k < n → is_fresh q (g k)) (hq : q ≠ 0) :
is_fresh q (npar n g)If `q` is fresh in `g k` for every k < n (and q ≠ 0), then `q` is fresh
in `npar n g`.
theoremfresh_npar_H
theorem fresh_npar_H {dim : Nat} (q n : Nat) (hq : q ≥ n) (hq0 : q ≠ 0) :
is_fresh q (npar_H n : BaseUCom dim)`q ≥ n` and `q ≠ 0` is sufficient for `q` to be fresh in `npar_H n`
(the column of Hadamards on qubits 0, 1, …, n−1).
theoremfresh_controlled_R
theorem fresh_controlled_R {dim : Nat} (q1 q2 t : Nat) (θ φ lam : ℝ)
(h12 : q1 ≠ q2) (h1t : q1 ≠ t) :
is_fresh q1 (controlled_R q2 t θ φ lam : BaseUCom dim)Freshness for `controlled_R`: if `q1` is fresh from both the control
qubit `q2` and target `t`, it is fresh from the entire decomposition.
theoremfresh_control_mp
theorem fresh_control_mp {dim : Nat} (q1 q2 : Nat) (c : BaseUCom dim)
(h12 : q1 ≠ q2) (hc : is_fresh q1 c) (hq0 : q1 ≠ 0) :
is_fresh q1 (control q2 c)Forward direction of SQIR's `fresh_control`: q1 ≠ q2 and is_fresh q1 c
(and q1 ≠ 0 for the SKIP fallback in `control`'s app3 case) imply
is_fresh q1 (control q2 c).
-- SQIR/SQIR/UnitaryOps.v line 241: fresh_control (forward direction).
theoremniter_six_X_eq_ID
theorem niter_six_X_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 6 (X q : BaseUCom dim)) (ID q)Demo of niter_eq_ID_of_dvd: `niter 6 (X q) ≡ ID q` (X has order 2,
and 2 ∣ 6). Shows the ergonomic 1-line invocation with `decide` for
the divisibility witness.
theoremniter_twelve_S_eq_ID
theorem niter_twelve_S_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 12 (S q : BaseUCom dim)) (ID q)Demo of niter_eq_ID_of_dvd at order 4: `niter 12 (S q) ≡ ID q`
(S has order 4, and 4 ∣ 12).
theoremniter_thirteen_S_eq_S
theorem niter_thirteen_S_eq_S {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 13 (S q : BaseUCom dim)) (S q)Composed demo: `niter 13 (S q) ≡ S q` — combines the two parametric
templates `niter_eq_ID_of_dvd` (to reach order 12) and
`niter_succ_of_eq_ID` (to lift to 13). 1-line application showing how
multiple parametric templates compose.
theoremniter_twelve_SDAG_eq_ID
theorem niter_twelve_SDAG_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 12 (SDAG q : BaseUCom dim)) (ID q)Symmetric companion: `niter 12 (SDAG q) ≡ ID q` (SDAG also has
order 4, and 4 ∣ 12).
theoremniter_thirteen_SDAG_eq_SDAG
theorem niter_thirteen_SDAG_eq_SDAG {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 13 (SDAG q : BaseUCom dim)) (SDAG q)Symmetric companion: `niter 13 (SDAG q) ≡ SDAG q`.
theoremniter_seven_X_eq_X
theorem niter_seven_X_eq_X {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 7 (X q : BaseUCom dim)) (X q)Pauli-X period demo: `niter 7 (X q) ≡ X q` — X has order 2, so
X⁷ = (X²)³·X = I·X. 1-line composition of `niter_succ_of_eq_ID`
with `niter_six_X_eq_ID`. Demonstrates the templates work for
period-2 (involution) bases just as for the higher-period T/S families.
theoremniter_six_Z_eq_ID
theorem niter_six_Z_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 6 (Z q : BaseUCom dim)) (ID q)Pauli-Z analog of `niter_six_X_eq_ID`: `niter 6 (Z q) ≡ ID q`
(Z has order 2, 2 ∣ 6).
theoremniter_seven_Z_eq_Z
theorem niter_seven_Z_eq_Z {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 7 (Z q : BaseUCom dim)) (Z q)Pauli-Z period demo: `niter 7 (Z q) ≡ Z q`.
theoremniter_six_Y_eq_ID
theorem niter_six_Y_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 6 (Y q : BaseUCom dim)) (ID q)Pauli-Y analog: `niter 6 (Y q) ≡ ID q` (Y has order 2, 2 ∣ 6).
theoremniter_seven_Y_eq_Y
theorem niter_seven_Y_eq_Y {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 7 (Y q : BaseUCom dim)) (Y q)Pauli-Y period demo: `niter 7 (Y q) ≡ Y q`.
theoremniter_six_H_eq_ID
theorem niter_six_H_eq_ID {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 6 (H q : BaseUCom dim)) (ID q)Hadamard analog: `niter 6 (H q) ≡ ID q` (H has order 2, 2 ∣ 6).
theoremniter_seven_H_eq_H
theorem niter_seven_H_eq_H {dim : Nat} (q : Nat) (hq : q < dim) :
UCom.equiv (niter 7 (H q : BaseUCom dim)) (H q)Hadamard period demo: `niter 7 (H q) ≡ H q`. Completes the X/Y/Z/H
period-6 pair set.
FormalRV.Core.UnitarySem
FormalRV/Core/UnitarySem.lean
FormalRV.Framework.UnitarySem — matrix semantics for unitary circuits.
Lean translation of SQIR/SQIR/UnitarySem.v. This is the layer that maps
a syntactic `BaseUCom dim` to its denotational meaning as a 2^dim × 2^dim
complex unitary matrix.
## Status (2026-05-04, end of long grind)
*ZERO SORRIES.** This file now has the full unitary-matrix semantic
layer for SQIR-style circuits, with every theorem proven. Headlines:
- `pad_u` (embed 2×2 unitary at qubit n) — IMPLEMENTED via Kronecker
products + reindex
- `pad_ctrl` (controlled-version) — IMPLEMENTED via projector
decomposition `proj0_pad + proj1_pad · M_pad`
- `pad_u_mul_pad_u` — proven (matrix-mul + kron-mul + reindex)
- `pad_u_id` — proven (Iₙ_kron_Iₙ chain + reindex of identity)
All single-qubit gate-matrix theorems proven (rotation_X/Y/Z/I/T/S/H,
Pauli involutions σx² = σy² = σz², anti-commutation, hMatrix_mul_hMatrix,
CNOT² = I). All circuit-equivalence theorems for single-qubit gates
proven (X_X_id, Y_Y_id, Z_Z_id, Rz_Rz_add, T_TDAG_id, etc.). SKIP
identity laws proven.
## Strategic note: do we need this for the gap review?
For *resource* claims (T-count, gate count, qubit count) we do NOT need
matrix semantics — `Framework.Gate` (RCIR-level) suffices, and that's
what BQ-Algo uses for the Cuccaro / Gidney 2018 / windowed arithmetic
cost work. We only need this matrix layer to prove **algorithm
correctness** (e.g., that QPE applied to IMM actually finds the order),
which is the deepest part of the Shor formalization. The review can
produce results from `Framework.Gate` long before this file's sorries
are all filled.
defI
def Iₙ (n : Nat) : Matrix (Fin n) (Fin n) ℂ
The n×n identity matrix on `Fin n × Fin n`.
Reference: SQIR's `QuantumLib.Pad.I n` (used throughout pad_u/pad_ctrl).
example(example)
example : Iₙ 2 0 0 = 1
example(example)
example : Iₙ 2 1 1 = 1
example(example)
example : Iₙ 2 0 1 = 0
example(example)
example : Iₙ 2 1 0 = 0
example(example)
example : (2^0 : Nat) = 1
example(example)
example : (2^1 : Nat) = 2
example(example)
example : (2^2 : Nat) = 4
example(example)
example : (2^3 : Nat) = 8
abbrevSquare
abbrev Square (dim : Nat)
The 2^dim × 2^dim complex matrix space (mirrors SQIR's `Square (2^dim)`).
Tensoring a basis state with itself gives the canonical
computational-basis enumeration.
example(example)
example : Square 1 = Matrix (Fin 2) (Fin 2) ℂ
For dim = 1, `Square 1 = Matrix (Fin 2) (Fin 2) ℂ` definitionally
(since `2^1 = 2` reduces by rfl).
example(example)
example : Square 2 = Matrix (Fin 4) (Fin 4) ℂ
Same for dim = 2: `Square 2 = Matrix (Fin 4) (Fin 4) ℂ`.
example(example)
example (a b : Nat) : Fin a × Fin b ≃ Fin (a * b)
deffin22
def fin22 : Fin 2 × Fin 2 ≃ Fin 4
Specialization: `Fin 2 × Fin 2 ≃ Fin 4`. The smallest non-trivial case;
every `pad_u 2 0 M` and `pad_u 2 1 M` will use a reindex of this shape.
example(example)
example (a b c : Nat) : (Fin a × Fin b) × Fin c ≃ Fin (a * b * c)
For `pad_u dim n M`, the relevant reindex flattens
`Fin (2^n) × Fin 2 × Fin (2^(dim-n-1))` into `Fin (2^dim)`. We need
associativity of products: `(A × B) × C ≃ A × (B × C)` plus
`finProdFinEquiv` twice, plus that `2^n * 2 * 2^(dim-n-1) = 2^dim`.
theoremtwo_pow_split
theorem two_pow_split (dim n : Nat) (h : n < dim) :
2 ^ n * 2 * 2 ^ (dim - n - 1) = 2 ^ dimThe Nat fact: when `n < dim`, the dimension product `2^n · 2 · 2^(dim-n-1)`
equals `2^dim`. Required to type-cast `pad_u`'s Kronecker output to `Square dim`.
theoremI
theorem Iₙ_kron_Iₙ (a b : Nat) :
(Iₙ a ⊗ₖ Iₙ b : Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ) = 1`Iₙ a ⊗ₖ Iₙ b = 1`, where the result has type
`Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ`. Direct application of
`Matrix.one_kronecker_one`.
theoremI
theorem Iₙ_kron_Iₙ_reindex (a b : Nat) :
Matrix.reindex finProdFinEquiv finProdFinEquiv (Iₙ a ⊗ₖ Iₙ b) = Iₙ (a * b)The reindexed version: after flattening the product index `Fin a × Fin b`
to `Fin (a*b)` via `finProdFinEquiv`, the identity remains the identity.
defrotation
noncomputable def rotation (θ ϕ lam : ℝ) : Matrix (Fin 2) (Fin 2) ℂ
The universal R(θ, ϕ, λ) single-qubit rotation, in standard form:
R(θ, ϕ, λ) = ⎡ cos(θ/2) -e^(iλ) sin(θ/2) ⎤
⎣ e^(iϕ) sin(θ/2) e^(i(ϕ+λ)) cos(θ/2) ⎦
Mirrors `QuantumLib.Pad.rotation` (Coq) / `qiskit.U3` (Qiskit).
With this single matrix all base single-qubit gates are recovered:
H = R(π/2, 0, π), X = R(π, 0, π), Z = R(0, 0, π), T = R(0, 0, π/4), …
defx
def σx : Matrix (Fin 2) (Fin 2) ℂ
The Pauli X matrix. Used as the kernel of CNOT's pad_ctrl.
defy
noncomputable def σy : Matrix (Fin 2) (Fin 2) ℂ
The Pauli Y matrix.
defz
def σz : Matrix (Fin 2) (Fin 2) ℂ
The Pauli Z matrix.
defi
def σi : Matrix (Fin 2) (Fin 2) ℂ
The 2×2 identity (matches `Iₙ 2`, but kept as `σi` for SQIR parity).
defproj0
def proj0 : Matrix (Fin 2) (Fin 2) ℂ
Projector onto |0⟩: `|0⟩⟨0| = !![1, 0; 0, 0]`. Used in `pad_ctrl` to
express controlled gates: ctrl-`m`-target-`n`-of-M = `|0⟩⟨0|⊗I + |1⟩⟨1|⊗M`.
defproj1
def proj1 : Matrix (Fin 2) (Fin 2) ℂ
Projector onto |1⟩: `|1⟩⟨1| = !![0, 0; 0, 1]`.
theoremproj0_add_proj1_eq_id
theorem proj0_add_proj1_eq_id : proj0 + proj1 = σi
Sanity: `proj0 + proj1 = σi` (completeness of the {|0⟩, |1⟩} basis).
theoremproj0_mul_proj0
theorem proj0_mul_proj0 : proj0 * proj0 = proj0
Projector idempotence: `|0⟩⟨0| · |0⟩⟨0| = |0⟩⟨0|`.
theoremproj1_mul_proj1
theorem proj1_mul_proj1 : proj1 * proj1 = proj1
Projector idempotence: `|1⟩⟨1| · |1⟩⟨1| = |1⟩⟨1|`.
theoremproj0_mul_proj1
theorem proj0_mul_proj1 : proj0 * proj1 = 0
Projector orthogonality: `|0⟩⟨0| · |1⟩⟨1| = 0`.
theoremproj1_mul_proj0
theorem proj1_mul_proj0 : proj1 * proj0 = 0
Projector orthogonality (reverse): `|1⟩⟨1| · |0⟩⟨0| = 0`.
theoremx_proj0_
theorem σx_proj0_σx : σx * proj0 * σx = proj1
X conjugates `|0⟩⟨0|` to `|1⟩⟨1|`: `σx · |0⟩⟨0| · σx = |1⟩⟨1|`.
theoremx_proj1_
theorem σx_proj1_σx : σx * proj1 * σx = proj0
X conjugates `|1⟩⟨1|` to `|0⟩⟨0|`: `σx · |1⟩⟨1| · σx = |0⟩⟨0|`.
theoremz_mul_proj0
theorem σz_mul_proj0 : σz * proj0 = proj0
σz acts as +1 on `|0⟩⟨0|`: `σz · |0⟩⟨0| = |0⟩⟨0|`.
theoremz_mul_proj1
theorem σz_mul_proj1 : σz * proj1 = -proj1
σz acts as -1 on `|1⟩⟨1|`: `σz · |1⟩⟨1| = -|1⟩⟨1|`.
theoremproj0_mul_
theorem proj0_mul_σz : proj0 * σz = proj0
Right action: `|0⟩⟨0| · σz = |0⟩⟨0|`.
theoremproj1_mul_
theorem proj1_mul_σz : proj1 * σz = -proj1
Right action: `|1⟩⟨1| · σz = -|1⟩⟨1|`.
theoremx_mul_proj0
theorem σx_mul_proj0 : σx * proj0 = proj1 * σx
σx swaps the projectors: `σx · |0⟩⟨0| = |1⟩⟨1| · σx`.
theoremx_mul_proj1
theorem σx_mul_proj1 : σx * proj1 = proj0 * σx
σx swaps the projectors (dual): `σx · |1⟩⟨1| = |0⟩⟨0| · σx`.
theoremrotation_X
theorem rotation_X : rotation Real.pi 0 Real.pi = σx
`rotation π 0 π = σx`. Justifies SQIR.v's `Definition U_X := U_R π 0 π`.
theoremrotation_Z
theorem rotation_Z : rotation 0 0 Real.pi = σz
`rotation 0 0 π = σz`. Justifies SQIR.v's `Definition U_Z := U_R 0 0 π`.
theoremrotation_Y
theorem rotation_Y : rotation Real.pi (Real.pi / 2) (Real.pi / 2) = σy
`rotation π (π/2) (π/2) = σy`. Justifies SQIR.v's `Definition U_Y := U_R π (π/2) (π/2)`.
Uses `Complex.exp_pi_div_two_mul_I : exp (π/2 · I) = I` and
`exp_pi_mul_I : exp (π · I) = -1`.
theoremx_mul_
theorem σx_mul_σx : σx * σx = σi
σx² = I (the Pauli-X is its own inverse).
theoremz_mul_
theorem σz_mul_σz : σz * σz = σi
σz² = I.
theoremy_mul_
theorem σy_mul_σy : σy * σy = σi
σy² = I. The proof needs Complex.I_mul_I or equivalent (`I * I = -1`).
theoremx_mul_
theorem σx_mul_σz_eq_neg : σx * σz = -(σz * σx)
Pauli anti-commutation: σx · σz = −(σz · σx).
Equivalently: σx σz + σz σx = 0. The Pauli matrices anti-commute
pairwise.
theoremx_mul_
theorem σx_mul_σy : σx * σy = Complex.I • σz
σx · σy = i · σz.
theoremy_mul_
theorem σy_mul_σz : σy * σz = Complex.I • σx
σy · σz = i · σx.
theoremz_mul_
theorem σz_mul_σx : σz * σx = Complex.I • σy
σz · σx = i · σy.
theoremy_mul_
theorem σy_mul_σx : σy * σx = -Complex.I • σz
σy · σx = -i · σz.
theoremz_mul_
theorem σz_mul_σy : σz * σy = -Complex.I • σx
σz · σy = -i · σx.
theoremx_mul_
theorem σx_mul_σz : σx * σz = -Complex.I • σy
σx · σz = -i · σy.
theoremx_mul_
theorem σx_mul_σy_eq_neg : σx * σy = -(σy * σx)
σx · σy = -(σy · σx). Anti-commutation, derived from the cyclic
and anti-cyclic Pauli products.
theoremy_mul_
theorem σy_mul_σz_eq_neg : σy * σz = -(σz * σy)
σy · σz = -(σz · σy).
theoremx_mul_
theorem σx_mul_σy_mul_σz : σx * σy * σz = Complex.I • σi
The product of all three Pauli matrices in cyclic order is `i · I`.
Follows from `σx · σy = i · σz` and `σz · σz = I`.
theoremy_mul_
theorem σy_mul_σz_mul_σx : σy * σz * σx = Complex.I • σi
Cyclic shift: σy · σz · σx = i · I.
theoremz_mul_
theorem σz_mul_σx_mul_σy : σz * σx * σy = Complex.I • σi
Cyclic shift: σz · σx · σy = i · I.
theoremy_mul_
theorem σy_mul_σx_mul_σz : σy * σx * σz = -Complex.I • σi
Anti-cyclic: σy · σx · σz = -i · I.
theoremx_mul_
theorem σx_mul_σz_mul_σy : σx * σz * σy = -Complex.I • σi
Anti-cyclic: σx · σz · σy = -i · I.
theoremz_mul_
theorem σz_mul_σy_mul_σx : σz * σy * σx = -Complex.I • σi
Anti-cyclic: σz · σy · σx = -i · I.
theorempauli_squares_sum
theorem pauli_squares_sum :
σx * σx + σy * σy + σz * σz = (3 : ℂ) • σiSum of squared Pauli matrices: σx² + σy² + σz² = 3 · I.
deftMatrix
noncomputable def tMatrix : Matrix (Fin 2) (Fin 2) ℂ
The T-gate matrix: `!![1, 0; 0, exp(i·π/4)]`.
theoremrotation_T
theorem rotation_T : rotation 0 0 (Real.pi / 4) = tMatrix
`rotation 0 0 (π/4) = T`. Justifies SQIR.v's `Definition U_T := U_R 0 0 (π/4)`.
defsMatrix
noncomputable def sMatrix : Matrix (Fin 2) (Fin 2) ℂ
The S-gate matrix: `!![1, 0; 0, I]`.
defcnotMatrix
def cnotMatrix : Matrix (Fin 4) (Fin 4) ℂ
The 4×4 CNOT matrix in the computational basis (control = high bit).
Rows/cols enumerate `|00⟩, |01⟩, |10⟩, |11⟩`:
|00⟩ → |00⟩, |01⟩ → |01⟩, |10⟩ → |11⟩, |11⟩ → |10⟩
Equivalent to `proj0 ⊗ I₂ + proj1 ⊗ σx` after reindex via `finProdFinEquiv`.
theoremcnotMatrix_mul_cnotMatrix
theorem cnotMatrix_mul_cnotMatrix : cnotMatrix * cnotMatrix = (1 : Matrix (Fin 4) (Fin 4) ℂ)
CNOT applied twice is the identity.
theoremcnotMatrix_pow_four
theorem cnotMatrix_pow_four :
cnotMatrix * cnotMatrix * cnotMatrix * cnotMatrix = (1 : Matrix (Fin 4) (Fin 4) ℂ)CNOT⁴ = I. Trivial corollary of `cnotMatrix_mul_cnotMatrix` since
CNOT² = I implies CNOT⁴ = (CNOT²)² = I².
theoremcnotMatrix_pow_three
theorem cnotMatrix_pow_three :
cnotMatrix * cnotMatrix * cnotMatrix = cnotMatrixCNOT³ = CNOT. Trivial corollary of CNOT² = I.
theoremcnotMatrix_pow_five
theorem cnotMatrix_pow_five :
cnotMatrix * cnotMatrix * cnotMatrix * cnotMatrix * cnotMatrix = cnotMatrixCNOT⁵ = CNOT. Trivial corollary of CNOT⁴ = I.
theoremi_mul_
theorem σi_mul_σi : σi * σi = σi
`σi · σi = σi`. The 2×2 identity matrix is idempotent.
theoremi_eq_one
theorem σi_eq_one : σi = (1 : Matrix (Fin 2) (Fin 2) ℂ)
`σi = 1` as matrices: the explicit `!![1,0;0,1]` matches the typeclass identity.
theoremx_pow_four
theorem σx_pow_four : σx * σx * σx * σx = σi
`σx⁴ = I`. Pauli X is involutive, so its fourth power is identity.
theoremy_pow_four
theorem σy_pow_four : σy * σy * σy * σy = σi
`σy⁴ = I`.
theoremz_pow_four
theorem σz_pow_four : σz * σz * σz * σz = σi
`σz⁴ = I`.
theoremx_pow_five
theorem σx_pow_five : σx * σx * σx * σx * σx = σx
`σx⁵ = σx`. Follows from σx⁴ = I + Matrix.one_mul.
theoremy_pow_five
theorem σy_pow_five : σy * σy * σy * σy * σy = σy
`σy⁵ = σy`.
theoremz_pow_five
theorem σz_pow_five : σz * σz * σz * σz * σz = σz
`σz⁵ = σz`.
theoremx_pow_six
theorem σx_pow_six : σx * σx * σx * σx * σx * σx = σi
`σx⁶ = I`. Pauli X has order 2, so any even power is identity.
Useful for T-gate distillation cycle analysis.
theoremy_pow_six
theorem σy_pow_six : σy * σy * σy * σy * σy * σy = σi
`σy⁶ = I`.
theoremz_pow_six
theorem σz_pow_six : σz * σz * σz * σz * σz * σz = σi
`σz⁶ = I`.
theoremx_pow_seven
theorem σx_pow_seven : σx * σx * σx * σx * σx * σx * σx = σx
`σx⁷ = σx`. Cycle wraps to self (period 2). Proof: σx⁶ = σi, then
σi · σx = σx via σi_eq_one + Matrix.one_mul.
theoremy_pow_seven
theorem σy_pow_seven : σy * σy * σy * σy * σy * σy * σy = σy
`σy⁷ = σy`.
theoremz_pow_seven
theorem σz_pow_seven : σz * σz * σz * σz * σz * σz * σz = σz
`σz⁷ = σz`.
theoremx_pow_eight
theorem σx_pow_eight : σx * σx * σx * σx * σx * σx * σx * σx = σi
`σx⁸ = I`. Even power → identity (period 2).
theoremy_pow_eight
theorem σy_pow_eight : σy * σy * σy * σy * σy * σy * σy * σy = σi
`σy⁸ = I`.
theoremz_pow_eight
theorem σz_pow_eight : σz * σz * σz * σz * σz * σz * σz * σz = σi
`σz⁸ = I`.
theoremx_pow_three
theorem σx_pow_three : σx * σx * σx = σx
`σx³ = σx`. Follows from involutivity (σx² = σi).
theoremy_pow_three
theorem σy_pow_three : σy * σy * σy = σy
`σy³ = σy`.
theoremz_pow_three
theorem σz_pow_three : σz * σz * σz = σz
`σz³ = σz`.
theoremrotation_S
theorem rotation_S : rotation 0 0 (Real.pi / 2) = sMatrix
`rotation 0 0 (π/2) = S`. Justifies SQIR.v's `Definition U_S := U_R 0 0 (π/2)`.
Uses `Complex.exp_pi_div_two_mul_I : exp(π/2 · I) = I`.
theoremrotation_I
theorem rotation_I : rotation 0 0 0 = σi
`rotation 0 0 0 = σi` (identity rotation = identity matrix).
Justifies SQIR.v's `Definition U_I := U_R 0 0 0`.
defhMatrix
noncomputable def hMatrix : Matrix (Fin 2) (Fin 2) ℂ
The Hadamard matrix: `(√2/2) · !![1, 1; 1, -1]`, with all entries
cast to `ℂ`. Equivalent to the standard `1/√2 · ...` form.
theoremsqrt2_sq_C
private theorem sqrt2_sq_C : ((Real.sqrt 2 : ℂ))^2 = 2
`(√2 : ℂ)² = 2` — Real.sq_sqrt cast through ℂ.
theoremsqrt2_div2_sq_C
private theorem sqrt2_div2_sq_C : ((Real.sqrt 2 : ℂ) / 2) * ((Real.sqrt 2 : ℂ) / 2) = 1/2
`((√2 : ℂ) / 2) * ((√2 : ℂ) / 2) = 1/2`. The fundamental Hadamard fact.
theoremhMatrix_mul_hMatrix
theorem hMatrix_mul_hMatrix : hMatrix * hMatrix = σi
Hadamard involution: H · H = I.
theoremhMatrix_pow_four
theorem hMatrix_pow_four : hMatrix * hMatrix * hMatrix * hMatrix = σi
`H⁴ = I`. Hadamard is involutive (H² = I), so its fourth power is identity.
theoremhMatrix_pow_three
theorem hMatrix_pow_three : hMatrix * hMatrix * hMatrix = hMatrix
`H³ = H`. Follows from involutivity (H² = I).
theoremhMatrix_pow_five
theorem hMatrix_pow_five :
hMatrix * hMatrix * hMatrix * hMatrix * hMatrix = hMatrix`H⁵ = H`. Follows from H⁴ = I + Matrix.one_mul.
theoremz_mul_hMatrix
theorem σz_mul_hMatrix : σz * hMatrix = hMatrix * σx
`σz · H = H · σx`. The Hadamard interchange identity at the matrix level —
underlying SQIR's `H_comm_Z` circuit equivalence.
theoremx_mul_hMatrix
theorem σx_mul_hMatrix : σx * hMatrix = hMatrix * σz
`σx · H = H · σz`. The dual Hadamard interchange identity.
theorempi_div_two_div_two
private theorem pi_div_two_div_two : Real.pi / 2 / 2 = Real.pi / 4
`Real.pi / 2 / 2 = Real.pi / 4` — used to align rotation_H argument with cos_pi_div_four.
theoremrotation_H
theorem rotation_H : rotation (Real.pi / 2) 0 Real.pi = hMatrix
`rotation π/2 0 π = H` (Hadamard matrix).
Justifies SQIR.v's `Definition U_H := U_R (π/2) 0 π`.
defpad_u
noncomputable def pad_u (dim n : Nat) (M : Matrix (Fin 2) (Fin 2) ℂ) : Square dim
Embed a 2×2 unitary at qubit `n` in a `dim`-qubit system.
Construction (when `n < dim`): tensor `Iₙ (2^n) ⊗ M ⊗ Iₙ (2^(dim-n-1))`,
then reindex `(Fin (2^n) × Fin 2) × Fin (2^(dim-n-1)) ≃ Fin (2^dim)` via
two `finProdFinEquiv` chained with a Nat-equality cast (`two_pow_split`).
When `n ≥ dim`, returns the zero matrix (matching SQIR's convention).
theorempad_u_ill_typed
theorem pad_u_ill_typed {dim n : Nat} (M : Matrix (Fin 2) (Fin 2) ℂ)
(h : dim ≤ n) : pad_u dim n M = 0When the qubit index is out of dim range, `pad_u` returns the zero matrix.
Foundational lemma for the *_ill_typed family.
theorempad_u_zero
theorem pad_u_zero (dim n : Nat) : pad_u dim n (0 : Matrix (Fin 2) (Fin 2) ℂ) = 0
`pad_u dim n 0 = 0` (padding the zero matrix gives the zero matrix).
theorempad_u_add
theorem pad_u_add (dim n : Nat) (A B : Matrix (Fin 2) (Fin 2) ℂ) :
pad_u dim n (A + B) = pad_u dim n A + pad_u dim n B`pad_u` distributes over matrix addition: `pad_u dim n (A + B) = pad_u dim n A + pad_u dim n B`.
theorempad_u_smul
theorem pad_u_smul (dim n : Nat) (c : ℂ) (A : Matrix (Fin 2) (Fin 2) ℂ) :
pad_u dim n (c • A) = c • pad_u dim n A`pad_u` distributes over scalar multiplication.
theorempad_u_neg
theorem pad_u_neg (dim n : Nat) (A : Matrix (Fin 2) (Fin 2) ℂ) :
pad_u dim n (-A) = -pad_u dim n A`pad_u` distributes over negation.
theorempad_u_sub
theorem pad_u_sub (dim n : Nat) (A B : Matrix (Fin 2) (Fin 2) ℂ) :
pad_u dim n (A - B) = pad_u dim n A - pad_u dim n B`pad_u` distributes over subtraction.
defpad_ctrl
noncomputable def pad_ctrl (dim m n : Nat) (M : Matrix (Fin 2) (Fin 2) ℂ) : Square dim
Embed a controlled-M (control `m`, target `n`) in a `dim`-qubit system.
`M` is a 2×2 unitary; the controlled version applies `M` to qubit `n`
when qubit `m` is in state |1⟩, and identity otherwise.
Implementation via the projector decomposition:
ctrl-m-target-n-of-M = (proj0 at m) + (proj1 at m) · (M at n)
using our existing `pad_u`. Returns 0 when the qubits aren't valid.
theorempad_u_mul_pad_u
theorem pad_u_mul_pad_u (dim n : Nat) (A B : Matrix (Fin 2) (Fin 2) ℂ) :
pad_u dim n B * pad_u dim n A = pad_u dim n (B * A)pad_u commutes with matrix multiplication when applied at the same qubit.
The `n ≥ dim` case closes trivially (0 * 0 = 0). The `n < dim` case
uses Matrix.mul_kronecker_mul (twice) + submatrix_mul_equiv.
theoremnat_inner_m_of_lt
private theorem nat_inner_m_of_lt (dim m n : Nat) (hmn : m < n) (hn : n < dim) :
2^(n-m-1) * 2 * 2^(dim-n-1) = 2^(dim-m-1)theoremnat_inner_n_of_lt
private theorem nat_inner_n_of_lt (m n : Nat) (hmn : m < n) :
2^m * 2 * 2^(n - m - 1) = 2^ndefbridge_m_5to3
private def bridge_m_5to3 (a mid c : Nat) :
((((Fin a × Fin 2) × Fin mid) × Fin 2) × Fin c)
≃ ((Fin a × Fin 2) × Fin (mid * 2 * c))Bridge equiv collapsing the right 3 blocks of `5T` to a single Fin block
(for the pad_u m direction).
theorembridge_m_5to3_matrix
private theorem bridge_m_5to3_matrix (a mid c : Nat) (A : Matrix (Fin 2) (Fin 2) ℂ) :
Matrix.reindex (bridge_m_5to3 a mid c) (bridge_m_5to3 a mid c)
((((Iₙ a ⊗ₖ A) ⊗ₖ Iₙ mid) ⊗ₖ Iₙ 2) ⊗ₖ Iₙ c)
= (Iₙ a ⊗ₖ A) ⊗ₖ Iₙ (mid * 2 * c)defbridge_n_5to3
private def bridge_n_5to3 (a mid c : Nat) :
((((Fin a × Fin 2) × Fin mid) × Fin 2) × Fin c)
≃ ((Fin (a * 2 * mid) × Fin 2) × Fin c)Bridge equiv collapsing the left 3 blocks of `5T` to a single Fin block
(for the pad_u n direction).
theorembridge_n_5to3_matrix
private theorem bridge_n_5to3_matrix (a mid c : Nat) (B : Matrix (Fin 2) (Fin 2) ℂ) :
Matrix.reindex (bridge_n_5to3 a mid c) (bridge_n_5to3 a mid c)
((((Iₙ a ⊗ₖ Iₙ 2) ⊗ₖ Iₙ mid) ⊗ₖ B) ⊗ₖ Iₙ c)
= (Iₙ (a * 2 * mid) ⊗ₖ B) ⊗ₖ Iₙ ctheoremkron_5block_disjoint_comm_aux
private theorem kron_5block_disjoint_comm_aux (a mid c : Nat)
(A B : Matrix (Fin 2) (Fin 2) ℂ) :
((((Iₙ a ⊗ₖ A) ⊗ₖ Iₙ mid) ⊗ₖ Iₙ 2) ⊗ₖ Iₙ c)
* ((((Iₙ a ⊗ₖ Iₙ 2) ⊗ₖ Iₙ mid) ⊗ₖ B) ⊗ₖ Iₙ c)
= ((((Iₙ a ⊗ₖ Iₙ 2) ⊗ₖ Iₙ mid) ⊗ₖ B) ⊗ₖ Iₙ c)
* ((((Iₙ a ⊗ₖ A) ⊗ₖ Iₙ mid) ⊗ₖ Iₙ 2) ⊗ₖ Iₙ c)Core abstract 5-block commutation: A in slot 2 and B in slot 4
of a 5-factor kron tensor structure commute. Both products reduce
to `(((Iₙ a ⊗ A) ⊗ Iₙ mid) ⊗ B) ⊗ Iₙ c` via `mul_kronecker_mul` ×8.
theoremreindex_kron_prodCongr_aux
private theorem reindex_kron_prodCongr_aux {α α' β β' : Type*} [Fintype α] [Fintype β]
(e₁ : α ≃ α') (e₂ : β ≃ β')
(A : Matrix α α ℂ) (B : Matrix β β ℂ) :
Matrix.reindex (Equiv.prodCongr e₁ e₂) (Equiv.prodCongr e₁ e₂) (A ⊗ₖ B)
= Matrix.reindex e₁ e₁ A ⊗ₖ Matrix.reindex e₂ e₂ Btheoremcast_inner_I
private theorem cast_inner_Iₙ_aux {α : Type*} [Fintype α]
(X : Matrix α α ℂ) (K M : Nat) (h : K = M) :
Matrix.reindex (Equiv.prodCongr (Equiv.refl α) (Fin.castOrderIso h).toEquiv)
(Equiv.prodCongr (Equiv.refl α) (Fin.castOrderIso h).toEquiv)
(X ⊗ₖ Iₙ K)
= X ⊗ₖ Iₙ Mtheoremcast_outer_I
private theorem cast_outer_Iₙ_aux {β : Type*} [Fintype β]
(X : Matrix β β ℂ) (K M : Nat) (h : K = M) :
Matrix.reindex (Equiv.prodCongr (Fin.castOrderIso h).toEquiv (Equiv.refl β))
(Equiv.prodCongr (Fin.castOrderIso h).toEquiv (Equiv.refl β))
(Iₙ K ⊗ₖ X)
= Iₙ M ⊗ₖ Xtheoremreindex_trans_eq_aux
private theorem reindex_trans_eq_aux {α β γ : Type*} [Fintype α] [Fintype β]
(e : α ≃ β) (f : β ≃ γ) (M : Matrix α α ℂ) :
Matrix.reindex (e.trans f) (e.trans f) M
= Matrix.reindex f f (Matrix.reindex e e M)theoremcombined_bridge_m_aux
private theorem combined_bridge_m_aux (dim m n : Nat) (hmn : m < n) (hn : n < dim)
(A : Matrix (Fin 2) (Fin 2) ℂ) :
Matrix.reindex
((bridge_m_5to3 (2^m) (2^(n-m-1)) (2^(dim-n-1))).trans
(Equiv.prodCongr (Equiv.refl _)
(Fin.castOrderIso (nat_inner_m_of_lt dim m n hmn hn)).toEquiv))
((bridge_m_5to3 (2^m) (2^(n-m-1)) (2^(dim-n-1))).trans
(Equiv.prodCongr (Equiv.refl _)
(Fin.castOrderIso (nat_inner_m_of_lt dim m n hmn hn)).toEquiv))
((((Iₙ (2^m) ⊗ₖ A) ⊗ₖ Iₙ (2^(n-m-1))) ⊗ₖ Iₙ 2) ⊗ₖ Iₙ (2^(dim-n-1)))
= (Iₙ (2^m) ⊗ₖ A) ⊗ₖ Iₙ (2^(dim-m-1))Combined bridge: collapsing the right 3 blocks of 5block_A (with Iₙ cast)
yields the 3-block form `(Iₙ(2^m) ⊗ A) ⊗ Iₙ(2^(dim-m-1))`.
theoremcombined_bridge_n_aux
private theorem combined_bridge_n_aux (dim m n : Nat) (hmn : m < n) (hn : n < dim)
(B : Matrix (Fin 2) (Fin 2) ℂ) :
Matrix.reindex
((bridge_n_5to3 (2^m) (2^(n-m-1)) (2^(dim-n-1))).trans
(Equiv.prodCongr (Equiv.prodCongr
(Fin.castOrderIso (nat_inner_n_of_lt m n hmn)).toEquiv (Equiv.refl _))
(Equiv.refl _)))
((bridge_n_5to3 (2^m) (2^(n-m-1)) (2^(dim-n-1))).trans
(Equiv.prodCongr (Equiv.prodCongr
(Fin.castOrderIso (nat_inner_n_of_lt m n hmn)).toEquiv (Equiv.refl _))
(Equiv.refl _)))
((((Iₙ (2^m) ⊗ₖ Iₙ 2) ⊗ₖ Iₙ (2^(n-m-1))) ⊗ₖ B) ⊗ₖ Iₙ (2^(dim-n-1)))Combined bridge: collapsing the left 3 blocks of 5block_B (with Iₙ cast)
yields the 3-block form `(Iₙ(2^n) ⊗ B) ⊗ Iₙ(2^(dim-n-1))`.
defE_m_unified
private noncomputable def E_m_unified (dim m n : Nat) (hmn : m < n) (hn : n < dim) :
((((Fin (2^m) × Fin 2) × Fin (2^(n-m-1))) × Fin 2) × Fin (2^(dim-n-1)))
≃ Fin (2^dim)The unified reindex via the pad_u m direction (combining right 3 blocks).
defE_n_unified
private noncomputable def E_n_unified (dim m n : Nat) (hmn : m < n) (hn : n < dim) :
((((Fin (2^m) × Fin 2) × Fin (2^(n-m-1))) × Fin 2) × Fin (2^(dim-n-1)))
≃ Fin (2^dim)The unified reindex via the pad_u n direction (combining left 3 blocks).
theoremE_m_eq_E_n_unified
private theorem E_m_eq_E_n_unified (dim m n : Nat) (hmn : m < n) (hn : n < dim) :
E_m_unified dim m n hmn hn = E_n_unified dim m n hmn hnThe two unified reindexes are equal as Equivs (proven by Equiv.ext +
Fin.ext + Nat exponent identity `2^(dim-m-1) = 2^(dim-n-1) · 2^(n-m-1) · 2`).
theorempad_u_m_via_E_unified
private theorem pad_u_m_via_E_unified (dim m n : Nat) (hmn : m < n) (hn : n < dim)
(A : Matrix (Fin 2) (Fin 2) ℂ) :
pad_u dim m A = Matrix.reindex (E_m_unified dim m n hmn hn) (E_m_unified dim m n hmn hn)
((((Iₙ (2^m) ⊗ₖ A) ⊗ₖ Iₙ (2^(n-m-1))) ⊗ₖ Iₙ 2) ⊗ₖ Iₙ (2^(dim-n-1)))theorempad_u_n_via_E_unified
private theorem pad_u_n_via_E_unified (dim m n : Nat) (hmn : m < n) (hn : n < dim)
(B : Matrix (Fin 2) (Fin 2) ℂ) :
pad_u dim n B = Matrix.reindex (E_n_unified dim m n hmn hn) (E_n_unified dim m n hmn hn)
((((Iₙ (2^m) ⊗ₖ Iₙ 2) ⊗ₖ Iₙ (2^(n-m-1))) ⊗ₖ B) ⊗ₖ Iₙ (2^(dim-n-1)))theorempad_u_disjoint_comm_lt
private theorem pad_u_disjoint_comm_lt (dim m n : Nat)
(A B : Matrix (Fin 2) (Fin 2) ℂ) (hmn : m < n) (hn : n < dim) :
pad_u dim m A * pad_u dim n B = pad_u dim n B * pad_u dim m AThe `m < n < dim` case of `pad_u_disjoint_comm`.
theorempad_u_disjoint_comm
theorem pad_u_disjoint_comm (dim m n : Nat) (A B : Matrix (Fin 2) (Fin 2) ℂ)
(hm : m < dim) (hn : n < dim) (hmn : m ≠ n) :
pad_u dim m A * pad_u dim n B = pad_u dim n B * pad_u dim m ADisjoint single-qubit `pad_u`'s commute under matrix multiplication
(closed 2026-05-23 via the 5-block reindex strategy). For `m ≠ n`,
WLOG `m < n`; both pad_u's factor through the same unified 5-block
reindex `E_5 : T_5 ≃ Fin(2^dim)`, where the 5-block matrices commute
via `Matrix.mul_kronecker_mul` ×4 + identity collapses, and the
commutation lifts through `Matrix.submatrix_mul_equiv`. The unified
`E_5` is reached via two different bridge paths (combining right 3
blocks for pad_u m, left 3 blocks for pad_u n) that yield equal Equivs
by `Equiv.ext` + the Nat identity `2^(dim-m-1) = 2^(dim-n-1)·2^(n-m-1)·2`.
theorempad_u_disjoint_comm'
theorem pad_u_disjoint_comm' (dim m n : Nat) (A B : Matrix (Fin 2) (Fin 2) ℂ)
(hmn : m ≠ n) :
pad_u dim m A * pad_u dim n B = pad_u dim n B * pad_u dim m ADisjoint `pad_u`'s commute (totally unconstrained version: handles
out-of-range qubits via the `pad_u_ill_typed` zero collapse).
theorempad_u_pad_ctrl_disjoint_comm
theorem pad_u_pad_ctrl_disjoint_comm (dim q m n : Nat)
(U M : Matrix (Fin 2) (Fin 2) ℂ)
(hq_m : q ≠ m) (hq_n : q ≠ n) :
pad_u dim q U * pad_ctrl dim m n M
= pad_ctrl dim m n M * pad_u dim q UA `pad_u` and a `pad_ctrl` on pairwise-disjoint qubits commute.
Derived from `pad_u_disjoint_comm'` by unfolding `pad_ctrl`
(`= pad_u m proj0 + pad_u m proj1 * pad_u n M`) and propagating
the commutation through the projector decomposition.
theorempad_ctrl_disjoint_comm
theorem pad_ctrl_disjoint_comm (dim m n m' n' : Nat)
(M M' : Matrix (Fin 2) (Fin 2) ℂ)
(hmm : m ≠ m') (hmn : m ≠ n') (hnm : n ≠ m') (hnn : n ≠ n') :
pad_ctrl dim m n M * pad_ctrl dim m' n' M'
= pad_ctrl dim m' n' M' * pad_ctrl dim m n MTwo `pad_ctrl`'s on four pairwise-disjoint qubits commute.
Same derivation chain as `pad_u_pad_ctrl_disjoint_comm`.
defueval_r
noncomputable def ueval_r (dim n : Nat) (U : BaseUnitary 1) : Square dim
The matrix corresponding to a base 1-qubit unitary applied to qubit `n`.
defueval_cnot
noncomputable def ueval_cnot (dim m n : Nat) : Square dim
The matrix corresponding to CNOT with control `m`, target `n`.
defuc_eval
noncomputable def uc_eval {dim : Nat} : BaseUCom dim → Square dim
| UCom.seq c₁ c₂ => uc_eval c₂ * uc_eval c₁
| UCom.app1 U n => ueval_r dim n U
| UCom.app2 _ m n => ueval_cnot dim m n
| UCom.app3 _ _ _ _ => 0 -- no 3-qubit primitives in BaseUnitaryDenote a `BaseUCom dim` as its 2^dim × 2^dim complex matrix.
Mirrors SQIR's `uc_eval` (UnitarySem.v line 24).
defUCom.equiv
def UCom.equiv {dim : Nat} (c₁ c₂ : BaseUCom dim) : PropTwo unitary circuits are equivalent iff their matrix semantics agree.
We avoid `≡` because it collides with `Nat.ModEq` notation; use the
function name `UCom.equiv` directly, or the local `≅` alias below.
theoremUCom.equiv_refl
theorem UCom.equiv_refl {dim : Nat} (c : BaseUCom dim) : UCom.equiv c cEquivalence is reflexive.
theoremUCom.equiv_symm
theorem UCom.equiv_symm {dim : Nat} {c₁ c₂ : BaseUCom dim} :
UCom.equiv c₁ c₂ → UCom.equiv c₂ c₁Equivalence is symmetric.
theoremUCom.equiv_trans
theorem UCom.equiv_trans {dim : Nat} {c₁ c₂ c₃ : BaseUCom dim} :
UCom.equiv c₁ c₂ → UCom.equiv c₂ c₃ → UCom.equiv c₁ c₃Equivalence is transitive.
theoremuseq_assoc
theorem useq_assoc {dim : Nat} (c₁ c₂ c₃ : BaseUCom dim) :
UCom.equiv (UCom.seq (UCom.seq c₁ c₂) c₃) (UCom.seq c₁ (UCom.seq c₂ c₃))Sequential composition is associative.
The `uc_eval` of `seq c₁ c₂` is `uc_eval c₂ * uc_eval c₁` (right-to-left
matrix order), so this reduces to associativity of matrix multiplication.
theoremuseq_assoc_l
theorem useq_assoc_l {dim : Nat} (c₁ c₂ c₃ : BaseUCom dim) :
UCom.equiv (UCom.seq c₁ (UCom.seq c₂ c₃)) (UCom.seq (UCom.seq c₁ c₂) c₃)`useq` left-associativity (reverse direction): `c₁;(c₂;c₃) ≡ (c₁;c₂);c₃`.
Direct corollary of `useq_assoc` via `UCom.equiv_symm`.
theoremX_ill_typed
theorem X_ill_typed {dim q : Nat} (h : dim ≤ q) :
uc_eval (X q : BaseUCom dim) = 0`uc_eval (X q) = 0` when q is out of dim range. SQIR `X_ill_typed`.
theoremY_ill_typed
theorem Y_ill_typed {dim q : Nat} (h : dim ≤ q) :
uc_eval (Y q : BaseUCom dim) = 0`uc_eval (Y q) = 0` when q is out of dim range. SQIR `Y_ill_typed`.
theoremZ_ill_typed
theorem Z_ill_typed {dim q : Nat} (h : dim ≤ q) :
uc_eval (Z q : BaseUCom dim) = 0`uc_eval (Z q) = 0` when q is out of dim range. SQIR `Z_ill_typed`.
theoremH_ill_typed
theorem H_ill_typed {dim q : Nat} (h : dim ≤ q) :
uc_eval (H q : BaseUCom dim) = 0`uc_eval (H q) = 0` when q is out of dim range. SQIR `H_ill_typed`.
theoremT_ill_typed
theorem T_ill_typed {dim q : Nat} (h : dim ≤ q) :
uc_eval (T q : BaseUCom dim) = 0`uc_eval (T q) = 0` when q is out of dim range.
theoremTDAG_ill_typed
theorem TDAG_ill_typed {dim q : Nat} (h : dim ≤ q) :
uc_eval (TDAG q : BaseUCom dim) = 0`uc_eval (TDAG q) = 0` when q is out of dim range.
theoremS_ill_typed
theorem S_ill_typed {dim q : Nat} (h : dim ≤ q) :
uc_eval (S q : BaseUCom dim) = 0`uc_eval (S q) = 0` when q is out of dim range.
theoremSDAG_ill_typed
theorem SDAG_ill_typed {dim q : Nat} (h : dim ≤ q) :
uc_eval (SDAG q : BaseUCom dim) = 0`uc_eval (SDAG q) = 0` when q is out of dim range.
theoremID_ill_typed
theorem ID_ill_typed {dim q : Nat} (h : dim ≤ q) :
uc_eval (ID q : BaseUCom dim) = 0`uc_eval (ID q) = 0` when q is out of dim range. SQIR `ID_ill_typed`.
theoremRz_ill_typed
theorem Rz_ill_typed {dim q : Nat} (θ : ℝ) (h : dim ≤ q) :
uc_eval (Rz θ q : BaseUCom dim) = 0`uc_eval (Rz θ q) = 0` when q is out of dim range (parametric).
SQIR/SQIR/UnitaryOps.v: `Rz_ill_typed`.
theoremCNOT_ill_typed_control
theorem CNOT_ill_typed_control {dim m n : Nat} (h : dim ≤ m) :
uc_eval (CNOT m n : BaseUCom dim) = 0`uc_eval (CNOT m n) = 0` when control qubit m is out of dim range.
SQIR/SQIR/UnitaryOps.v: `CNOT_ill_typed` (control branch only — the
target-oob and same-qubit branches behave differently in our model
and need separate lemmas).
theoremSWAP_ill_typed_left
theorem SWAP_ill_typed_left {dim m n : Nat} (h : dim ≤ m) :
uc_eval (SWAP m n : BaseUCom dim) = 0`uc_eval (SWAP m n) = 0` when m is out of dim range. SWAP unfolds to
a 3-CNOT chain, all of which have m as control somewhere.
theoremSWAP_ill_typed_right
theorem SWAP_ill_typed_right {dim m n : Nat} (h : dim ≤ n) :
uc_eval (SWAP m n : BaseUCom dim) = 0`uc_eval (SWAP m n) = 0` when n is out of dim range. The middle CNOT
(CNOT n m) has n as control and vanishes by CNOT_ill_typed_control.
theoremX_X_id
theorem X_X_id {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (X q : BaseUCom dim) (X q)) (ID q)`X q ; X q ≡ ID q` — the X gate is its own inverse.
SQIR/Equivalences.v line 68.
theoremZ_Z_id
theorem Z_Z_id {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (Z q : BaseUCom dim) (Z q)) (ID q)`Z q ; Z q ≡ ID q` — the Z gate is its own inverse.
Analogous to SQIR's `X_X_id`.
theoremY_Y_id
theorem Y_Y_id {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (Y q : BaseUCom dim) (Y q)) (ID q)`Y q ; Y q ≡ ID q`.
theoremH_H_id
theorem H_H_id {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (H q : BaseUCom dim) (H q)) (ID q)`H q ; H q ≡ ID q` — the Hadamard gate is its own inverse.
-- SQIR/SQIR/Equivalences.v line 78: H_H_id.
theoremH_comm_Z
theorem H_comm_Z {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (H q : BaseUCom dim) (Z q))
(UCom.seq (X q) (H q))`H q ; Z q ≡ X q ; H q` — the Hadamard interchange identity.
-- SQIR/SQIR/Equivalences.v line 164: H_comm_Z.
theoremH_comm_X
theorem H_comm_X {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (H q : BaseUCom dim) (X q))
(UCom.seq (Z q) (H q))`H q ; X q ≡ Z q ; H q` — the dual Hadamard interchange identity.
theoremrotation_Rz_compose
theorem rotation_Rz_compose (θ θ' : ℝ) :
rotation 0 0 θ * rotation 0 0 θ' = rotation 0 0 (θ + θ')Helper: composition of `rotation 0 0 θ` and `rotation 0 0 θ'`.
Uses `Complex.exp_add`: `exp(iθ) · exp(iθ') = exp(i(θ+θ'))`.
theoremrotation_Rz_neg_inv
theorem rotation_Rz_neg_inv (θ : ℝ) :
rotation 0 0 θ * rotation 0 0 (-θ) = σiZ-rotation by θ followed by Z-rotation by -θ is the identity matrix.
Direct corollary of `rotation_Rz_compose` + `rotation_I`.
theoremrotation_Rz_neg_inv_l
theorem rotation_Rz_neg_inv_l (θ : ℝ) :
rotation 0 0 (-θ) * rotation 0 0 θ = σiZ-rotation by -θ followed by Z-rotation by θ is the identity matrix.
Symmetric companion to `rotation_Rz_neg_inv`.
theoremrotation_Rx_zero
theorem rotation_Rx_zero : rotation 0 (-(Real.pi/2)) (Real.pi/2) = σi
The X-axis rotation by 0 is the identity matrix.
`Rx 0 = R 0 (-π/2) (π/2)`; with cos(0) = 1, sin(0) = 0, the off-diagonal
terms vanish and the diagonal is (1, exp(0)) = (1, 1). Same shape as
`rotation_I` but with the Rx angle convention.
theoremrotation_Rz_pow
theorem rotation_Rz_pow (θ : ℝ) (k : Nat) :
(rotation 0 0 θ)^k = rotation 0 0 (k * θ)Z-rotation raised to the k-th power equals a Z-rotation by k·θ.
Generalizes `rotation_Rz_compose` to arbitrary powers via induction.
theoremrotation_Rz_commutes_
theorem rotation_Rz_commutes_σz (θ : ℝ) :
rotation 0 0 θ * σz = σz * rotation 0 0 θAny Z-rotation commutes with σz: `Rz(θ) · σz = σz · Rz(θ)`. Both
matrices are diagonal so this is the trivial commutation of two
diagonal 2×2 matrices. Subsumes T, T†, S, S† commutation with σz.
theoremrotation_Rz_commutes
theorem rotation_Rz_commutes (θ θ' : ℝ) :
rotation 0 0 θ * rotation 0 0 θ' = rotation 0 0 θ' * rotation 0 0 θZ-rotations commute with each other. Subsumes T·S = S·T, T·T† = T†·T,
S·S† = S†·S, etc. as instances. Follows from `rotation_Rz_compose` and
`add_comm`.
theoremRz_Rz_add
theorem Rz_Rz_add {dim : Nat} (q : Nat) (θ θ' : ℝ) :
UCom.equiv (UCom.seq (Rz θ q : BaseUCom dim) (Rz θ' q)) (Rz (θ + θ') q)`Rz θ q ; Rz θ' q ≡ Rz (θ + θ') q` — Z-rotations add their angles.
SQIR/Equivalences.v line 88.
theoremRz_0_id
theorem Rz_0_id {dim : Nat} (q : Nat) :
UCom.equiv (Rz 0 q : BaseUCom dim) (ID q)`Rz 0 q ≡ ID q` — zero rotation is identity.
theoremT_TDAG_id
theorem T_TDAG_id {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (T q : BaseUCom dim) (TDAG q)) (ID q)`T q ; TDAG q ≡ ID q` — T is inverted by T†.
T = Rz(π/4), TDAG = Rz(-π/4), product = Rz(0) = ID.
theoremTDAG_T_id
theorem TDAG_T_id {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (TDAG q : BaseUCom dim) (T q)) (ID q)`TDAG q ; T q ≡ ID q` — symmetric companion.
theoremS_SDAG_id
theorem S_SDAG_id {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (S q : BaseUCom dim) (SDAG q)) (ID q)`S q ; SDAG q ≡ ID q`.
theoremSDAG_S_id
theorem SDAG_S_id {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (SDAG q : BaseUCom dim) (S q)) (ID q)`SDAG q ; S q ≡ ID q` — symmetric companion of `S_SDAG_id`.
theoremRz_neg_id
theorem Rz_neg_id {dim : Nat} (q : Nat) (θ : ℝ) :
UCom.equiv (UCom.seq (Rz θ q : BaseUCom dim) (Rz (-θ) q)) (ID q)`Rz θ q ; Rz (-θ) q ≡ ID q` — every Z-rotation is invertible by its negation.
Generalizes `T_TDAG_id` (θ = π/4) and `S_SDAG_id` (θ = π/2).
theoremRz_neg_id_l
theorem Rz_neg_id_l {dim : Nat} (q : Nat) (θ : ℝ) :
UCom.equiv (UCom.seq (Rz (-θ) q : BaseUCom dim) (Rz θ q)) (ID q)`Rz (-θ) q ; Rz θ q ≡ ID q` — reverse direction of `Rz_neg_id`. Direct
corollary obtained by substituting θ ↦ -θ and folding the double-negation.
theoremrotation_2pi
theorem rotation_2pi : rotation 0 0 (2 * Real.pi) = σi
`rotation 0 0 (2π) = σi`. The 2π Z-rotation is identity (exp(2πi) = 1).
theoremrotation_Rz_periodic
theorem rotation_Rz_periodic (θ : ℝ) :
rotation 0 0 (θ + 2 * Real.pi) = rotation 0 0 θ2π-periodicity of Z-rotations: `rotation 0 0 (θ + 2π) = rotation 0 0 θ`.
theoremRz_2pi_id
theorem Rz_2pi_id {dim : Nat} (q : Nat) :
UCom.equiv (Rz (2 * Real.pi) q : BaseUCom dim) (ID q)`Rz (2π) q ≡ ID q` — full 2π rotation is the identity.
theoremRz_neg_2pi_id
theorem Rz_neg_2pi_id {dim : Nat} (q : Nat) :
UCom.equiv (Rz (-(2 * Real.pi)) q : BaseUCom dim) (ID q)`Rz (-2π) q ≡ ID q` — full -2π rotation is also the identity (Z-rotations
are 2π-periodic, so -2π and 0 give equivalent matrices).
theoremRz_pi_eq_Z
theorem Rz_pi_eq_Z {dim : Nat} (q : Nat) :
UCom.equiv (Rz Real.pi q : BaseUCom dim) (Z q)`Rz π q ≡ Z q` — π Z-rotation is the Pauli Z gate.
theoremRz_pi_div_two_eq_S
theorem Rz_pi_div_two_eq_S {dim : Nat} (q : Nat) :
UCom.equiv (Rz (Real.pi / 2) q : BaseUCom dim) (S q)`Rz (π/2) q ≡ S q` — π/2 Z-rotation is the S gate.
theoremRz_pi_div_four_eq_T
theorem Rz_pi_div_four_eq_T {dim : Nat} (q : Nat) :
UCom.equiv (Rz (Real.pi / 4) q : BaseUCom dim) (T q)`Rz (π/4) q ≡ T q` — π/4 Z-rotation is the T gate.
theoremRz_neg_pi_div_two_eq_SDAG
theorem Rz_neg_pi_div_two_eq_SDAG {dim : Nat} (q : Nat) :
UCom.equiv (Rz (-(Real.pi / 2)) q : BaseUCom dim) (SDAG q)`Rz (-π/2) q ≡ S† q`.
theoremRz_neg_pi_div_four_eq_TDAG
theorem Rz_neg_pi_div_four_eq_TDAG {dim : Nat} (q : Nat) :
UCom.equiv (Rz (-(Real.pi / 4)) q : BaseUCom dim) (TDAG q)`Rz (-π/4) q ≡ T† q`.
theoremRz_periodic
theorem Rz_periodic {dim : Nat} (q : Nat) (θ : ℝ) :
UCom.equiv (Rz (θ + 2 * Real.pi) q : BaseUCom dim) (Rz θ q)`Rz (θ + 2π) q ≡ Rz θ q` — Z-rotation is 2π-periodic at the circuit level.
theoremRz_4pi_id
theorem Rz_4pi_id {dim : Nat} (q : Nat) :
UCom.equiv (Rz (4 * Real.pi) q : BaseUCom dim) (ID q)`Rz (4π) q ≡ ID q` — 4π rotation is the identity (since 4π = 2π + 2π).
Direct corollary of Rz_periodic + Rz_2pi_id.
theoremRz_neg_4pi_id
theorem Rz_neg_4pi_id {dim : Nat} (q : Nat) :
UCom.equiv (Rz (-(4 * Real.pi)) q : BaseUCom dim) (ID q)`Rz (-4π) q ≡ ID q` — symmetric companion to Rz_4pi_id for negative angle.
theoremRz_2pi_smul_id
theorem Rz_2pi_smul_id {dim : Nat} (q : Nat) (k : Nat) :
UCom.equiv (Rz ((k : ℝ) * (2 * Real.pi)) q : BaseUCom dim) (ID q)`Rz (k·2π) q ≡ ID q` for any k : ℕ — parametric generalization of
Rz_2pi_id (k=1) and Rz_4pi_id (k=2). Proof by induction on k.
theoremRz_neg_2pi_smul_id
theorem Rz_neg_2pi_smul_id {dim : Nat} (q : Nat) (k : Nat) :
UCom.equiv (Rz (-((k : ℝ) * (2 * Real.pi))) q : BaseUCom dim) (ID q)`Rz (-(k·2π)) q ≡ ID q` for any k : ℕ — symmetric companion to
Rz_2pi_smul_id for negative multiples of 2π.
theoremT_T_eq_S
theorem T_T_eq_S {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (T q : BaseUCom dim) (T q)) (S q)`T q ; T q ≡ S q` — two T gates equal S (since Rz(π/4) twice = Rz(π/2) = S).
theoremS_S_eq_Z
theorem S_S_eq_Z {dim : Nat} (q : Nat) :
UCom.equiv (UCom.seq (S q : BaseUCom dim) (S q)) (Z q)`S q ; S q ≡ Z q` — two S gates equal Z (since Rz(π/2) twice = Rz(π) = Z).
theoremi_eq_I
theorem σi_eq_Iₙ_two : σi = Iₙ 2
σi (the explicit `!![1,0;0,1]` matrix) equals `Iₙ 2` (mathlib's identity).
theorempad_u_id
theorem pad_u_id {dim n : Nat} (h : n < dim) :
pad_u dim n σi = (1 : Square dim)pad_u of the identity matrix at any qubit gives the global identity.
Proof sketch: substitute σi = Iₙ 2, apply Iₙ_kron_Iₙ twice
(Iₙ a ⊗ₖ Iₙ b = 1 as a Matrix on (Fin a × Fin b)), then reindex
of identity is identity.
theorempad_u_one
theorem pad_u_one {dim n : Nat} (h : n < dim) :
pad_u dim n (1 : Matrix (Fin 2) (Fin 2) ℂ) = (1 : Square dim)`pad_u` of the identity 2×2 matrix (the canonical `1`) gives the
global identity. Trivial corollary of `σi_eq_one` and `pad_u_id`.
theorempad_u_dim_eq_one
theorem pad_u_dim_eq_one (M : Matrix (Fin 2) (Fin 2) ℂ) :
pad_u 1 0 M = M`pad_u 1 0 M = M`: padding a 2×2 unitary at qubit 0 of a 1-qubit system
is the identity operation. Since `2^1 = 2` definitionally, both sides
inhabit `Matrix (Fin 2) (Fin 2) ℂ` without any explicit cast.
Both inner kron multipliers `Iₙ (2^0) = Iₙ 1` and `Iₙ (2^(1-0-1)) = Iₙ 1`
are the 1×1 identity, so the kron entry at `((0, b), 0) ((0, b'), 0)`
equals `1 · M b b' · 1 = M b b'`. The reindex `e` from
`(Fin 1 × Fin 2) × Fin 1 ≃ Fin 2` then identifies `i ↔ ((0, i), 0)`.
Proof currently sorried: requires unwinding the explicit `Fin`
arithmetic of `finProdFinEquiv` and `Fin.castOrderIso` at the
concrete `dim=1, n=0` instance. Sorry name: `TODO_pad_u_dim_eq_one`.
theoremuc_eval_ID_eq_one
theorem uc_eval_ID_eq_one {dim q : Nat} (h : q < dim) :
uc_eval (ID q : BaseUCom dim) = 1Well-typed counterpart of `ID_ill_typed`: `uc_eval (ID q) = 1`
when `q < dim`. The semantics of `ID q` is the identity matrix on
`dim` qubits — `rotation 0 0 0` is the 2×2 identity, and padding it
via `pad_u_id` preserves identity.
theoremuseq_ID_l
theorem useq_ID_l {dim q : Nat} (hq : q < dim) (c : BaseUCom dim) :
UCom.equiv (UCom.seq (ID q) c) c`useq (ID q) c ≡ c` — `ID q` is a left-identity of useq at the UCom
level (when `q < dim`). 2-line proof via `uc_eval_ID_eq_one`.
theoremuseq_ID_r
theorem useq_ID_r {dim q : Nat} (hq : q < dim) (c : BaseUCom dim) :
UCom.equiv (UCom.seq c (ID q)) c`useq c (ID q) ≡ c` — `ID q` is a right-identity of useq.
theoremuc_eval_SKIP_eq_one
theorem uc_eval_SKIP_eq_one {dim : Nat} (h : 0 < dim) :
uc_eval (SKIP : BaseUCom dim) = (1 : Square dim)`uc_eval (SKIP) = 1` when `0 < dim`. SKIP is `ID 0` definitionally,
so this is `uc_eval_ID_eq_one` with q = 0.
theoremuseq_SKIP_l
theorem useq_SKIP_l {dim : Nat} (hd : 0 < dim) (c : BaseUCom dim) :
UCom.equiv (UCom.seq SKIP c) c`useq SKIP c ≡ c` — SKIP is a left-identity of useq (when `0 < dim`).
Direct corollary of `useq_ID_l` with q = 0.
theoremuseq_SKIP_r
theorem useq_SKIP_r {dim : Nat} (hd : 0 < dim) (c : BaseUCom dim) :
UCom.equiv (UCom.seq c SKIP) c`useq c SKIP ≡ c` — SKIP is a right-identity of useq.
theorempad_u_pow
theorem pad_u_pow {dim n : Nat} (h : n < dim) (A : Matrix (Fin 2) (Fin 2) ℂ) :
∀ k, pad_u dim n (A ^ k) = (pad_u dim n A) ^ k
| 0 => by rw [pow_zero, pow_zero]; exact pad_u_one h
| k + 1 => by rw [pow_succ, pow_succ, ← pad_u_pow h A k, pad_u_mul_pad_u]`pad_u` distributes over matrix powers (when `n < dim`). Iterates
`pad_u_mul_pad_u` and bases out at `pad_u_one`.
theorempad_u_rotation_Rz_pow
theorem pad_u_rotation_Rz_pow {dim n : Nat} (h : n < dim) (θ : ℝ) (k : Nat) :
(pad_u dim n (rotation 0 0 θ))^k = pad_u dim n (rotation 0 0 (k * θ))Padded version: `(pad_u (Rz θ))^k = pad_u (Rz (k·θ))` (when n < dim).
Direct corollary of `pad_u_pow` + `rotation_Rz_pow`.
theorempad_u_rotation_I
theorem pad_u_rotation_I {dim n : Nat} (h : n < dim) :
pad_u dim n (rotation 0 0 0) = (1 : Square dim)Padded zero-rotation collapses to the global identity (when n < dim).
Direct corollary of `rotation_I` + `pad_u_id`.
theorempad_u_rotation_Rz_compose
theorem pad_u_rotation_Rz_compose (dim n : Nat) (θ θ' : ℝ) :
pad_u dim n (rotation 0 0 θ) * pad_u dim n (rotation 0 0 θ')
= pad_u dim n (rotation 0 0 (θ + θ'))Padded version: `pad_u (Rz θ) * pad_u (Rz θ') = pad_u (Rz (θ+θ'))`.
No `n < dim` hypothesis needed; both sides vanish to 0 when n ≥ dim.
theorempad_u_rotation_Rz_neg_inv
theorem pad_u_rotation_Rz_neg_inv {dim n : Nat} (h : n < dim) (θ : ℝ) :
pad_u dim n (rotation 0 0 θ) * pad_u dim n (rotation 0 0 (-θ))
= (1 : Square dim)Padded version: `pad_u (Rz θ) * pad_u (Rz (-θ)) = 1` (when n < dim).
Direct corollary of `pad_u_mul_pad_u` + `rotation_Rz_neg_inv` + `pad_u_id`.
theorempad_u_rotation_Rz_neg_inv_l
theorem pad_u_rotation_Rz_neg_inv_l {dim n : Nat} (h : n < dim) (θ : ℝ) :
pad_u dim n (rotation 0 0 (-θ)) * pad_u dim n (rotation 0 0 θ)
= (1 : Square dim)Symmetric direction: `pad_u (Rz (-θ)) * pad_u (Rz θ) = 1` (when n < dim).
Companion to `pad_u_rotation_Rz_neg_inv`.
theorempad_u_self_inv
theorem pad_u_self_inv {dim n : Nat} (h : n < dim) (A : Matrix (Fin 2) (Fin 2) ℂ)
(hA : A * A = σi) :
pad_u dim n A * pad_u dim n A = (1 : Square dim)Generic self-inverse lift: any 2×2 matrix that squares to σi (the
identity) gives a self-inverse pad_u at the matrix level. Recipe:
pad_u_mul_pad_u to fold the product, hA to collapse A*A to σi,
pad_u_id to land on the global identity.
theorempad_u_
theorem pad_u_σx_sq {dim n : Nat} (h : n < dim) :
pad_u dim n σx * pad_u dim n σx = (1 : Square dim)σx is self-inverse at the padded level.
theorempad_u_
theorem pad_u_σy_sq {dim n : Nat} (h : n < dim) :
pad_u dim n σy * pad_u dim n σy = (1 : Square dim)σy is self-inverse at the padded level.
theorempad_u_
theorem pad_u_σz_sq {dim n : Nat} (h : n < dim) :
pad_u dim n σz * pad_u dim n σz = (1 : Square dim)σz is self-inverse at the padded level.
theorempad_u_hMatrix_sq
theorem pad_u_hMatrix_sq {dim n : Nat} (h : n < dim) :
pad_u dim n hMatrix * pad_u dim n hMatrix = (1 : Square dim)The Hadamard is self-inverse at the padded level.
theorempad_u_mul_inv
theorem pad_u_mul_inv {dim n : Nat} (h : n < dim) (A B : Matrix (Fin 2) (Fin 2) ℂ)
(hBA : B * A = σi) :
pad_u dim n B * pad_u dim n A = (1 : Square dim)Generic mutual-inverse lift: if B * A = σi (i.e., A is a left-inverse
of B in the 2×2 ring), then their padded versions are mutual inverses
at the matrix level. Generalizes `pad_u_self_inv`. Use cases include
T*TDAG, S*SDAG, and any other unitary-with-its-adjoint pair.
theorempad_u_pow_two_eq
theorem pad_u_pow_two_eq (dim n : Nat)
(A B : Matrix (Fin 2) (Fin 2) ℂ) (hA : A * A = B) :
pad_u dim n A * pad_u dim n A = pad_u dim n BGeneric order-2 chain lift: A*A = B → pad_u A * pad_u A = pad_u B.
No `n < dim` hypothesis. The `B = σi` case lets `pad_u_id` finish
to the global identity (see `pad_u_self_inv`).
theorempad_u_pow_three_eq
theorem pad_u_pow_three_eq (dim n : Nat)
(A B : Matrix (Fin 2) (Fin 2) ℂ) (hA : A * A * A = B) :
pad_u dim n A * pad_u dim n A * pad_u dim n A = pad_u dim n BGeneric order-3 chain lift: A*A*A = B → 3× chain product of pad_u A
= pad_u B. No `n < dim` hypothesis. Use cases include S³=S†, S†³=S,
σx/σy/σz³=themselves, hMatrix³=hMatrix.
theorempad_u_pow_four_eq
theorem pad_u_pow_four_eq (dim n : Nat)
(A B : Matrix (Fin 2) (Fin 2) ℂ) (hA : A * A * A * A = B) :
pad_u dim n A * pad_u dim n A * pad_u dim n A * pad_u dim n A
= pad_u dim n BGeneric order-4 chain lift: A*A*A*A = B → the chain product of
four pad_u A's equals pad_u B. No `n < dim` hypothesis required;
both sides are 0 when n ≥ dim (since pad_u dim n returns 0 there
and a 4-chain of 0's is 0). The `B = σi` case lets `pad_u_id`
finish to the global identity (see `pad_u_pow_four_eq_one`).
theorempad_u_pow_five_eq
theorem pad_u_pow_five_eq (dim n : Nat)
(A B : Matrix (Fin 2) (Fin 2) ℂ) (hA : A * A * A * A * A = B) :
pad_u dim n A * pad_u dim n A * pad_u dim n A * pad_u dim n A * pad_u dim n A
= pad_u dim n BGeneric order-5 chain lift: A*A*A*A*A = B → 5× chain product of
pad_u A = pad_u B. No `n < dim` hypothesis. Use cases include
σx/σy/σz⁵=themselves (Pauli order-5 by σ²=I × σ), hMatrix⁵=hMatrix,
sMatrix⁵=sMatrix, sdagMatrix⁵=sdagMatrix.
theorempad_u_pow_six_eq
theorem pad_u_pow_six_eq (dim n : Nat)
(A B : Matrix (Fin 2) (Fin 2) ℂ) (hA : A * A * A * A * A * A = B) :
pad_u dim n A * pad_u dim n A * pad_u dim n A * pad_u dim n A
* pad_u dim n A * pad_u dim n A
= pad_u dim n BGeneric order-6 chain lift: A^6 = B → 6× chain product of pad_u A
equals pad_u B. No `n < dim` hypothesis. Use cases include the
Pauli order-6 case (σx⁶ = (σx²)³ = σi³ = σi), used in T-gate
distillation cycle analysis.
theorempad_u_pow_four_eq_one
theorem pad_u_pow_four_eq_one {dim n : Nat} (h : n < dim)
(A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A * A * A * A = σi) :
pad_u dim n A * pad_u dim n A * pad_u dim n A * pad_u dim n A
= (1 : Square dim)Generic order-4 lift (chain form): if A * A * A * A = σi, then the
chain product of four pad_u A's is the identity. Use cases include
hMatrix (H⁴=I), sMatrix (S⁴=I), sdagMatrix, and the Paulis (their
chain product happens to be σi by σ²=σi twice).
theorempad_u_hMatrix_pow_four
theorem pad_u_hMatrix_pow_four {dim n : Nat} (h : n < dim) :
pad_u dim n hMatrix * pad_u dim n hMatrix * pad_u dim n hMatrix * pad_u dim n hMatrix
= (1 : Square dim)Hadamard has order 4 at the padded level: H · H · H · H = 1.
theorempad_u_
theorem pad_u_σx_pow_four {dim n : Nat} (h : n < dim) :
pad_u dim n σx * pad_u dim n σx * pad_u dim n σx * pad_u dim n σx
= (1 : Square dim)σx has order 4 at the padded level (chain form).
theorempad_u_
theorem pad_u_σy_pow_four {dim n : Nat} (h : n < dim) :
pad_u dim n σy * pad_u dim n σy * pad_u dim n σy * pad_u dim n σy
= (1 : Square dim)σy has order 4 at the padded level (chain form).
theorempad_u_
theorem pad_u_σz_pow_four {dim n : Nat} (h : n < dim) :
pad_u dim n σz * pad_u dim n σz * pad_u dim n σz * pad_u dim n σz
= (1 : Square dim)σz has order 4 at the padded level (chain form).
theorempad_u_
theorem pad_u_σx_pow_five (dim n : Nat) :
pad_u dim n σx * pad_u dim n σx * pad_u dim n σx * pad_u dim n σx * pad_u dim n σx
= pad_u dim n σxσx's 5-chain at the padded level equals pad_u σx (cycle wraps to self).
theorempad_u_
theorem pad_u_σy_pow_five (dim n : Nat) :
pad_u dim n σy * pad_u dim n σy * pad_u dim n σy * pad_u dim n σy * pad_u dim n σy
= pad_u dim n σyσy's 5-chain at the padded level equals pad_u σy.
theorempad_u_
theorem pad_u_σz_pow_five (dim n : Nat) :
pad_u dim n σz * pad_u dim n σz * pad_u dim n σz * pad_u dim n σz * pad_u dim n σz
= pad_u dim n σzσz's 5-chain at the padded level equals pad_u σz.
theorempad_u_hMatrix_pow_five
theorem pad_u_hMatrix_pow_five (dim n : Nat) :
pad_u dim n hMatrix * pad_u dim n hMatrix * pad_u dim n hMatrix * pad_u dim n hMatrix * pad_u dim n hMatrix
= pad_u dim n hMatrixHadamard's 5-chain at the padded level equals pad_u hMatrix.
theorempad_u_
theorem pad_u_σx_pow_six (dim n : Nat) :
pad_u dim n σx * pad_u dim n σx * pad_u dim n σx * pad_u dim n σx
* pad_u dim n σx * pad_u dim n σx
= pad_u dim n σiσx's 6-chain at the padded level equals pad_u σi (= identity if n < dim).
theorempad_u_
theorem pad_u_σy_pow_six (dim n : Nat) :
pad_u dim n σy * pad_u dim n σy * pad_u dim n σy * pad_u dim n σy
* pad_u dim n σy * pad_u dim n σy
= pad_u dim n σiσy's 6-chain at the padded level equals pad_u σi.
theorempad_u_
theorem pad_u_σz_pow_six (dim n : Nat) :
pad_u dim n σz * pad_u dim n σz * pad_u dim n σz * pad_u dim n σz
* pad_u dim n σz * pad_u dim n σz
= pad_u dim n σiσz's 6-chain at the padded level equals pad_u σi.
theorempad_u_pow_six_eq_one
theorem pad_u_pow_six_eq_one {dim n : Nat} (h : n < dim)
(A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A * A * A * A * A * A = σi) :
pad_u dim n A * pad_u dim n A * pad_u dim n A * pad_u dim n A
* pad_u dim n A * pad_u dim n A
= (1 : Square dim)Generic order-6 lift (chain form): if A^6 = σi, then the chain
product of six pad_u A's is the global identity (under n < dim).
Mirrors `pad_u_pow_four_eq_one` for the order-6 case.
theorempad_u_
theorem pad_u_σx_pow_six_eq_one {dim n : Nat} (h : n < dim) :
pad_u dim n σx * pad_u dim n σx * pad_u dim n σx * pad_u dim n σx
* pad_u dim n σx * pad_u dim n σx
= (1 : Square dim)σx has order 6 at the padded level: 6-chain = global identity
(when n < dim). Combines `pad_u_pow_six_eq_one` with `σx_pow_six`.
theorempad_u_
theorem pad_u_σy_pow_six_eq_one {dim n : Nat} (h : n < dim) :
pad_u dim n σy * pad_u dim n σy * pad_u dim n σy * pad_u dim n σy
* pad_u dim n σy * pad_u dim n σy
= (1 : Square dim)σy has order 6 at the padded level: 6-chain = global identity.
theorempad_u_
theorem pad_u_σz_pow_six_eq_one {dim n : Nat} (h : n < dim) :
pad_u dim n σz * pad_u dim n σz * pad_u dim n σz * pad_u dim n σz
* pad_u dim n σz * pad_u dim n σz
= (1 : Square dim)σz has order 6 at the padded level: 6-chain = global identity.
theorempad_ctrl_id
theorem pad_ctrl_id {dim m n : Nat} (hm : m < dim) (hn : n < dim) :
pad_ctrl dim m n σi = (1 : Square dim)A controlled-identity gate is the global identity (both qubits valid).
Whether the control fires or not, applying I has no effect, so the
sum (proj0 + proj1·I) collapses to (proj0 + proj1) = σi → identity.
theorempad_ctrl_zero
theorem pad_ctrl_zero (dim m n : Nat) :
pad_ctrl dim m n (0 : Matrix (Fin 2) (Fin 2) ℂ) = pad_u dim m proj0A controlled-zero "gate" is just the projection on the control qubit at
state |0⟩: when the control fires there's nothing to apply (target term
vanishes). Mathematically `pad_ctrl _ _ _ 0 = pad_u _ _ proj0`. Useful
as infrastructure for splitting pad_ctrl proofs additively.
theorempad_ctrl_smul
theorem pad_ctrl_smul (dim m n : Nat) (c : ℂ) (A : Matrix (Fin 2) (Fin 2) ℂ) :
pad_ctrl dim m n (c • A)
= pad_u dim m proj0 + c • (pad_u dim m proj1 * pad_u dim n A)Scalar multiplication in the target argument: only the |1⟩ branch
sees the scaling, since the |0⟩ branch (proj0) doesn't depend on the
target operator.
theorempad_ctrl_neg
theorem pad_ctrl_neg (dim m n : Nat) (A : Matrix (Fin 2) (Fin 2) ℂ) :
pad_ctrl dim m n (-A)
= pad_u dim m proj0 - pad_u dim m proj1 * pad_u dim n ANegation in the target argument: only the |1⟩ branch flips sign.
theorempad_ctrl_add
theorem pad_ctrl_add (dim m n : Nat) (A B : Matrix (Fin 2) (Fin 2) ℂ) :
pad_ctrl dim m n (A + B)
= pad_ctrl dim m n A + pad_u dim m proj1 * pad_u dim n BAsymmetric additivity in the target: adding a second operator to the
target produces the original pad_ctrl plus an extra |1⟩-branch term —
the proj0 contribution doesn't double, since proj0 is target-independent.
theorempad_ctrl_sub
theorem pad_ctrl_sub (dim m n : Nat) (A B : Matrix (Fin 2) (Fin 2) ℂ) :
pad_ctrl dim m n (A - B)
= pad_ctrl dim m n A - pad_u dim m proj1 * pad_u dim n BAsymmetric subtractivity in the target: subtracting a second operator
from the target subtracts only an extra |1⟩-branch term. Corollary
of `pad_ctrl_add` + `pad_u_neg` via `sub_eq_add_neg`.
theorempad_ctrl_target_oob
theorem pad_ctrl_target_oob (dim m n : Nat) (A : Matrix (Fin 2) (Fin 2) ℂ)
(hn : ¬n < dim) :
pad_ctrl dim m n A = pad_u dim m proj0Boundary case: when the target qubit is out of dim range, the |1⟩-branch
term vanishes and pad_ctrl reduces to just the proj0 padding.
theorempad_ctrl_control_oob
theorem pad_ctrl_control_oob (dim m n : Nat) (A : Matrix (Fin 2) (Fin 2) ℂ)
(hm : ¬m < dim) :
pad_ctrl dim m n A = 0Boundary case: when the control qubit is out of dim range, both
projector paddings vanish and pad_ctrl is just zero.
theorempad_ctrl_same_qubit
theorem pad_ctrl_same_qubit (dim n : Nat) (A : Matrix (Fin 2) (Fin 2) ℂ) :
pad_ctrl dim n n A = pad_u dim n (proj0 + proj1 * A)Edge case: when control and target are the same qubit, pad_ctrl
collapses to a single pad_u of the kernel `proj0 + proj1·A`.
theorempad_u_
theorem pad_u_σx_pow_three (dim n : Nat) :
pad_u dim n σx * pad_u dim n σx * pad_u dim n σx = pad_u dim n σxσx's 3-chain at the padded level equals pad_u σx (cubes back to self).
theorempad_u_
theorem pad_u_σy_pow_three (dim n : Nat) :
pad_u dim n σy * pad_u dim n σy * pad_u dim n σy = pad_u dim n σyσy's 3-chain at the padded level equals pad_u σy.
theorempad_u_
theorem pad_u_σz_pow_three (dim n : Nat) :
pad_u dim n σz * pad_u dim n σz * pad_u dim n σz = pad_u dim n σzσz's 3-chain at the padded level equals pad_u σz.
theorempad_u_hMatrix_pow_three
theorem pad_u_hMatrix_pow_three (dim n : Nat) :
pad_u dim n hMatrix * pad_u dim n hMatrix * pad_u dim n hMatrix = pad_u dim n hMatrixHadamard's 3-chain at the padded level equals pad_u hMatrix.
theoremID_equiv_SKIP
theorem ID_equiv_SKIP {dim : Nat} {n : Nat} (h : n < dim) (h0 : 0 < dim) :
UCom.equiv (ID n : BaseUCom dim) (SKIP)`ID n ≡ SKIP` for any well-typed `n < dim`.
SQIR/Equivalences.v line 11.
theoremSKIP_id_l
theorem SKIP_id_l {dim : Nat} (c : BaseUCom dim) (h : 0 < dim) :
UCom.equiv (UCom.seq (SKIP : BaseUCom dim) c) c`SKIP ; c ≡ c` — left identity. Follows from `pad_u_id` and `Matrix.one_mul`.
theoremSKIP_id_r
theorem SKIP_id_r {dim : Nat} (c : BaseUCom dim) (h : 0 < dim) :
UCom.equiv (UCom.seq c (SKIP : BaseUCom dim)) c`c ; SKIP ≡ c` — right identity.
theoremuseq_congruence
theorem useq_congruence {dim : Nat} {c₁ c₁' c₂ c₂' : BaseUCom dim}
(h₁ : UCom.equiv c₁ c₁') (h₂ : UCom.equiv c₂ c₂') :
UCom.equiv (UCom.seq c₁ c₂) (UCom.seq c₁' c₂')`useq_congruence`: if `c₁ ≡ c₁'` and `c₂ ≡ c₂'`, then `c₁;c₂ ≡ c₁';c₂'`.
SQIR/UnitarySem.v line 78.
theoremuseq_congruence_l
theorem useq_congruence_l {dim : Nat} {c₂ c₂' : BaseUCom dim} (c₁ : BaseUCom dim)
(h₂ : UCom.equiv c₂ c₂') :
UCom.equiv (UCom.seq c₁ c₂) (UCom.seq c₁ c₂')Left congruence: if `c₂ ≡ c₂'`, then `c₁;c₂ ≡ c₁;c₂'`.
theoremuseq_congruence_r
theorem useq_congruence_r {dim : Nat} {c₁ c₁' : BaseUCom dim} (c₂ : BaseUCom dim)
(h₁ : UCom.equiv c₁ c₁') :
UCom.equiv (UCom.seq c₁ c₂) (UCom.seq c₁' c₂)Right congruence: if `c₁ ≡ c₁'`, then `c₁;c₂ ≡ c₁';c₂`.