Definitions for Block-encoding structured matrices for data input in quantum computing
DefinitionQAlgorithms_Papers_Independent_Extend50_P44The objects the formalized statements of Block-encoding structured matrices for data input in quantum computing (arXiv:2302.10949) are stated in. Each was checked against the paper by a blind read-back and a moderator.
tableMax: PDF pp.5,7: the maximum magnitude of a supplied table (zero for an empty table).supportedPower: PDF p.8: supported powers, with zero padding excluded even at exponent zero.prepAlpha: PDF p.10, (32): PREP normalization, using the actual supported data count D.matrixMax: PDF p.8, (18): maximum entry magnitude, with a defined empty-matrix value.withFlags: PDF pp.5-7: an oracle acts trivially on the flag register. The accepted square permutation matrix is evaluated at the relabelled input, which also covers distinct source and target register types.dataRotation: PDF p.5, (7)-(8): RX(2 arccos q), with its negative imaginary off-diagonal.Scheme: PDF pp.5-7: full reversible oracle data, uniform preparation completions, actual supported sparsity states, and injective enumeration of structural entries. Dimensions are physical powers of two; equality of total bit counts is explicit. No block-encoding identity or circuit-cost bound is assumed here.Scheme.matrix: PDF pp.5-7: the matrix specified by the label pattern and supplied data. The injectivity in Scheme rules out counting a structural entry more than once.Scheme.baseAlpha: PDF pp.6-7: the base normalization uses supported sparsities, not padded S.diffusion: PDF pp.6-7: lift a sparsity diffusion, preserving flags and matrix indices.Scheme.baseMiddle: PDF p.7, (14)-(16): the middle multiplexed rotation and range-controlled NOT. When hermitian=true, the Z of (36) acts first on the input data flag.Scheme.baseCircuit: PDF p.7, (16), and p.11, (36): the actual five-stage base circuit, reassociated so that all flags precede the matrix register.Scheme.simpleCircuit: PDF p.6, (11): the introductory circuit has no deletion flag.Scheme.splitCircuit: PDF p.8, (19): two separate data flags, with the same middle range test.loadingCost: PDF pp.7,10: a loading schedule lists the table slots read at each loading stage. The base word contains one table rotation; the split and PREP words contain two. This metric does not count arithmetic gates or synthesis precision.baseLoadingSchedule: PDF pp.5,7: the base circuit's single table oracle.doubleLoadingSchedule: PDF pp.8,10: two separately loaded data tables.TransposeOracle: PDF p.11, (35): transpose is an involution on every label and preserves the data index and the range predicate, including on invalid labels.zeroEncoding: PDF pp.2,5: for the zero matrix use a flag X and alpha=1, rather than normalizing a zero data table. This definition is independent of all divisions.PrepLayout: PDF p.10, (31): compatible physical tensor factors. The active D labels need not fill their binary register. Supports factor as D times the supported residual sparsity. Data labels are preserved by both full arithmetic oracles; this is the source's commutativity prerequisite, including all padding.PrepLayout.alpha: PDF pp.10-11, (32): supported physical data register with its actual D.PreparationPair: PDF p.10, (29)-(30): PREP column and UNPREP row, with normalized states and full unitary completions. This does not assume block-encoding correctness.tensorPreparation: PDF p.10, (31): a preparation acting on the data factor and residual factor.PrepLayout.circuit: PDF p.10, (31): PREP, the column/range/row oracles, then UNPREP. Only the range-deletion qubit is left besides the physical sparsity register.signOracle: PDF p.12, (38): the full Hermitian sign oracle. Zero/unused labels have sign +1, so that the completion is unitary and Hermitian on every label.ArithmeticGate: PDF pp.5,13-21: elementary reversible arithmetic gates X, CNOT, CCNOT. Controls and target are distinct. Swaps can be three CNOT gates.ArithmeticGate.run: Basis action of an elementary reversible arithmetic gate.runArithmetic: Arithmetic gates are performed in list order.toffoliCount: PDF pp.13-21: CCNOT count in the actual elementary arithmetic list.bitAt: Canonical most-significant-first bit, returning zero beyond the register.pairBits: Canonical binary encoding of two source registers, in their displayed order.flaggedPairBits: A leading Boolean flag followed by the two source registers.doubleFlaggedPairBits: Source-order encoding of the existing data and deletion flags followed by the label registers. They may be borrowed by arithmetic but must be restored on every basis input; they are not further clean work ancillas.cleanBits: Append clean work wires after a fixed physical binary encoding.RealizesMap: A cost-bearing reversible circuit implements a map on every basis input, returning every work wire to zero. Encodings are fixed, rather than chosen to make the map artificially cheap.Scheme.ArithmeticCost: PDF pp.7,14-21: implementations of the two label oracles and the range NOT. The bound is on their summed CCNOT count. Work is clean and not a flag.Scheme.ArithmeticSize: PDF p.21: all-gates count for the Laplacian arithmetic. Existing flags may be borrowed but are restored on all basis inputs, including junk inputs.checkerboard: PDF p.13, (40)-(44): the checkerboard entries, allowing signed data.CheckerLabels: PDF p.13, (41)-(42): the paper's checkerboard labels.deletedCheckerboard: PDF pp.13-14, (49): replace only the two specified corner entries by zero.deleteCheckerCorners: PDF p.14, (49): the same arithmetic permutations with two invalid labels.bandedToeplitzSeed: PDF p.14, (50)-(52): the diagonal seed for the accepted Toeplitz matrix. Seed address u represents signed offset u-(N-1); out-of-band diagonals are zero.bandedToeplitz: PDF p.14, (50): specialize the accepted full Toeplitz matrix to the paper's banded signed-offset data; no periodic wrap-around is introduced.ToeplitzLabels: PDF pp.14-15: the actual Toeplitz arithmetic and its overflow deletion.triTable: PDF pp.15-16, (57),(63): diagonal/off-diagonal data with the last table slot fixed to zero, rather than loaded as an independent real parameter.tridiagonal: PDF p.15, (57): symmetric tridiagonal matrix, including N=1 and N=2.TridiagonalLabels: PDF p.16, (58)-(62): the supported three labels are 00,01,11, not H4.extendedTree: PDF pp.17-18, (67): tree adjacency with the source's extra root edge 0--1, root/leaf diagonal a0, internal diagonal a1, and every edge a2.treeTable: PDF p.17: fourth physical data slot is a structural zero.TreeLabels: PDF pp.17-18, (69)-(74): range and row formulas. The two invalid edge labels m=0,N have reversible completions instead of undefined arithmetic.laplacian: PDF pp.19-20, (78): nonperiodic finite-difference Laplacian. The integer coordinate differences avoid truncated natural subtraction.laplacianTable: PDF p.19, (78): the three actual values and a fourth zero sentinel.LaplacianLabels: PDF pp.19-20, (80)-(84): five supported states and off-grid deletion.PrepLayout.noDeleteCircuit: PDF p.13, (45): when no range deletion is needed, remove that untouched flag from the PREP circuit, rather than counting an extra physical flag.cliffordTSet: PDF pp.25-26: the elementary Clifford+T gate set used for T counts. Arbitrary rotations are targets of approximation, not free gates in this set.loaderTWord: PDF pp.25-26: extract the T-cost instruction trace from a concrete Clifford+T circuit for the accepted single-qubit word counter. Each T or inverse-T instruction contributes one t; other gates contribute h and hence zero T count. This trace records cost only; Circuit.unitary retains the full gate semantics.phaseGradient: PDF p.26: a normalized reusable phase-gradient resource. Its preparation is separate from each invocation of the lookup/rotate/uncompute procedure.loaderEmbedding: PDF pp.25-26, (91): embed data flag and table index with the reusable gradient state and clean work. This specifies full output accuracy, including return of the resource and work, not only the selected data amplitude.idealLoader: PDF p.25, (89): the ideal multiplexed RX data loader on every data-flag input.paddedTable: PDF p.25: a non-power-of-two supplied data table is padded with known zeros in its minimal physical binary register. No new unknown item is loaded.reverseCode: PDF p.26, (94): the reverse map supplies an occurrence label, or the fixed zero sentinel for structural zeros. It is not inferred from forward maps.valueAtLabel: PDF p.26: finite b-bit data lookup, with no additional loaded zero value.basisMatrix: A basis-action matrix used for the reversible XOR compute/load steps.entryCircuit: PDF p.26, (94): compute the occurrence label, XOR the corresponding finite entry value, then uncompute the occurrence label. Buffer input is general.rowColumnLabelBits: PDF p.26: binary encoding for the reverse-map implementation; rows, columns, and occurrence workspace use the fixed displayed register order.entryArithmeticCost: PDF p.26: the arithmetic part of the three-stage word consists exactly of the given reverse-map circuit and its inverse, with no repetition of data.
import Definitions.Def_QAlgorithms_Defs_BlockEncoding
import Definitions.Def_QAlgorithms_Defs_Circuit
import Definitions.Def_QAlgorithms_Papers_Independent_Frontier18_P11
import Definitions.Def_QAlgorithms_Papers_Independent_Information100_P34
import Definitions.Def_QAlgorithms_Papers_Independent_Advance50_P23
import Definitions.Def_QAlgorithms_Papers_Independent_Next46_P21
/-!
Statements from Sunderhauf, Campbell and Camps, arXiv:2302.10949v2.
All page numbers below are PDF page numbers. Rotations are ideal; arithmetic
oracles are reversible on the whole physical register, including padding.
Data loading counts table items, rather than elementary gates.
-/
noncomputable section
namespace QAlgorithms.Papers.Independent.Extend50.P44
open scoped BigOperators ComplexConjugate Matrix
open QAlgorithms.Papers.Independent.Frontier18.P11 (complexMatrix)
open QAlgorithms.Papers.Independent.Information100.P34 (permutationMatrix)
open QAlgorithms.Papers.Independent.Next46.P21 (tCount)
/-- PDF pp.5,7: the maximum magnitude of a supplied table (zero for an empty table). -/
def tableMax {D : ℕ} (a : Fin D → ℝ) : ℝ :=
(List.ofFn fun d => |a d|).foldr max 0
/-- PDF p.8: supported powers, with zero padding excluded even at exponent zero. -/
def supportedPower (x p : ℝ) : ℝ :=
if x = 0 then 0 else |x| ^ p
/-- PDF p.10, (32): PREP normalization, using the actual supported data count D. -/
def prepAlpha {D : ℕ} (a : Fin D → ℝ) (Sc Sr : ℕ) (p : ℝ) : ℝ :=
Real.sqrt ((Sc : ℝ) * Sr) / D *
Real.sqrt ((∑ d, supportedPower (a d) (2 * p)) *
∑ d, supportedPower (a d) (2 - 2 * p))
/-- PDF p.8, (18): maximum entry magnitude, with a defined empty-matrix value. -/
def matrixMax {N : ℕ} (A : Matrix (Fin N) (Fin N) ℝ) : ℝ :=
(List.ofFn fun i => (List.ofFn fun j => |A i j|).foldr max 0).foldr max 0
/-- PDF pp.5-7: an oracle acts trivially on the flag register.
The accepted square permutation matrix is evaluated at the relabelled input,
which also covers distinct source and target register types. -/
def withFlags {F X Y : Type*} [DecidableEq F] [DecidableEq Y]
(e : X ≃ Y) : Matrix (F × Y) (F × X) ℂ :=
fun y x => if y.1 = x.1 then permutationMatrix (Equiv.refl Y) y.2 (e x.2) else 0
/-- Sanity check: the accepted permutation helper retains the relabelled basis entry. -/
example {X Y : Type*} [DecidableEq Y] (e : X ≃ Y) (x : X) :
withFlags (F := Bool) e (false, e x) (false, x) = 1 := by
simp [withFlags, QAlgorithms.Papers.Independent.Information100.P34.permutationMatrix]
/-- PDF p.5, (7)-(8): RX(2 arccos q), with its negative imaginary off-diagonal. -/
def dataRotation (q : ℝ) : Matrix Bool Bool ℂ :=
fun b c => if b = c then (q : ℂ) else -Complex.I * (Real.sqrt (1 - q ^ 2) : ℂ)
/-- PDF pp.5-7: full reversible oracle data, uniform preparation completions,
actual supported sparsity states, and injective enumeration of structural entries.
Dimensions are physical powers of two; equality of total bit counts is explicit.
No block-encoding identity or circuit-cost bound is assumed here. -/
structure Scheme (n s d m : ℕ) where
bit_balance : d + m = s + n
column : (Fin (2 ^ d) × Fin (2 ^ m)) ≃ (Fin (2 ^ s) × Fin (2 ^ n))
row : (Fin (2 ^ d) × Fin (2 ^ m)) ≃ (Fin (2 ^ s) × Fin (2 ^ n))
valid : (Fin (2 ^ d) × Fin (2 ^ m)) → Bool
columnSlots : Finset (Fin (2 ^ s))
rowSlots : Finset (Fin (2 ^ s))
column_nonempty : columnSlots.Nonempty
row_nonempty : rowSlots.Nonempty
column_range : ∀ l, valid l = true → (column l).1 ∈ columnSlots
row_range : ∀ l, valid l = true → (row l).1 ∈ rowSlots
positions_injective : ∀ l k, valid l = true → valid k = true →
(column l).2 = (column k).2 → (row l).2 = (row k).2 → l = k
Hc : Matrix (Fin (2 ^ s)) (Fin (2 ^ s)) ℂ
Hr : Matrix (Fin (2 ^ s)) (Fin (2 ^ s)) ℂ
Hc_unitary : Hc ∈ Matrix.unitaryGroup _ ℂ
Hr_unitary : Hr ∈ Matrix.unitaryGroup _ ℂ
Hc_zero : ∀ t, Hc t 0 = if t ∈ columnSlots then
((Real.sqrt (columnSlots.card : ℝ))⁻¹ : ℂ) else 0
Hr_zero : ∀ t, Hr t 0 = if t ∈ rowSlots then
((Real.sqrt (rowSlots.card : ℝ))⁻¹ : ℂ) else 0
variable {n s d m : ℕ}
/-- PDF pp.5-7: the matrix specified by the label pattern and supplied data.
The injectivity in Scheme rules out counting a structural entry more than once. -/
def Scheme.matrix (B : Scheme n s d m) (a : Fin (2 ^ d) → ℝ) :
Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ :=
fun i j => ∑ l : Fin (2 ^ d) × Fin (2 ^ m),
if B.valid l = true ∧ (B.row l).2 = i ∧ (B.column l).2 = j then (a l.1 : ℂ) else 0
/-- PDF pp.6-7: the base normalization uses supported sparsities, not padded S. -/
def Scheme.baseAlpha (B : Scheme n s d m) (a : Fin (2 ^ d) → ℝ) : ℝ :=
Real.sqrt ((B.columnSlots.card : ℝ) * B.rowSlots.card) * tableMax a
/-- PDF pp.6-7: lift a sparsity diffusion, preserving flags and matrix indices. -/
def diffusion {F : Type*} [DecidableEq F]
(H : Matrix (Fin (2 ^ s)) (Fin (2 ^ s)) ℂ) :
Matrix (F × (Fin (2 ^ s) × Fin (2 ^ n)))
(F × (Fin (2 ^ s) × Fin (2 ^ n))) ℂ :=
fun x y => if x.1 = y.1 ∧ x.2.2 = y.2.2 then H x.2.1 y.2.1 else 0
/-- PDF p.7, (14)-(16): the middle multiplexed rotation and range-controlled NOT.
When hermitian=true, the Z of (36) acts first on the input data flag. -/
def Scheme.baseMiddle (B : Scheme n s d m) (a : Fin (2 ^ d) → ℝ)
(hermitian : Bool) :
Matrix ((Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m)))
((Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m))) ℂ :=
fun x y => if x.2 = y.2 ∧
x.1.2 = (if B.valid y.2 then y.1.2 else !y.1.2) then
dataRotation (a y.2.1 / tableMax a) x.1.1 y.1.1 *
(if hermitian && y.1.1 then -1 else 1) else 0
/-- PDF p.7, (16), and p.11, (36): the actual five-stage base circuit,
reassociated so that all flags precede the matrix register. -/
def Scheme.baseCircuit (B : Scheme n s d m) (a : Fin (2 ^ d) → ℝ)
(hermitian : Bool := false) :
Matrix (((Bool × Bool) × Fin (2 ^ s)) × Fin (2 ^ n))
(((Bool × Bool) × Fin (2 ^ s)) × Fin (2 ^ n)) ℂ :=
let V := (diffusion (n := n) (F := Bool × Bool) B.Hr)ᴴ * withFlags (F := Bool × Bool) B.row *
B.baseMiddle a hermitian * (withFlags (F := Bool × Bool) B.column)ᴴ * diffusion (n := n) (F := Bool × Bool) B.Hc
fun x y => V (x.1.1, (x.1.2, x.2)) (y.1.1, (y.1.2, y.2))
/-- PDF p.6, (11): the introductory circuit has no deletion flag. -/
def Scheme.simpleCircuit (B : Scheme n s d m) (a : Fin (2 ^ d) → ℝ)
(hermitian : Bool := false) :
Matrix ((Bool × Fin (2 ^ s)) × Fin (2 ^ n))
((Bool × Fin (2 ^ s)) × Fin (2 ^ n)) ℂ :=
let R : Matrix (Bool × (Fin (2 ^ d) × Fin (2 ^ m)))
(Bool × (Fin (2 ^ d) × Fin (2 ^ m))) ℂ := fun x y =>
if x.2 = y.2 then dataRotation (a y.2.1 / tableMax a) x.1 y.1 *
(if hermitian && y.1 then -1 else 1) else 0
let V := (diffusion (n := n) (F := Bool) B.Hr)ᴴ * withFlags (F := Bool) B.row * R *
(withFlags (F := Bool) B.column)ᴴ * diffusion (n := n) (F := Bool) B.Hc
fun x y => V (x.1.1, (x.1.2, x.2)) (y.1.1, (y.1.2, y.2))
/-- PDF p.8, (19): two separate data flags, with the same middle range test. -/
def Scheme.splitCircuit (B : Scheme n s d m) (a : Fin (2 ^ d) → ℝ) (p : ℝ) :
Matrix (((Bool × Bool × Bool) × Fin (2 ^ s)) × Fin (2 ^ n))
(((Bool × Bool × Bool) × Fin (2 ^ s)) × Fin (2 ^ n)) ℂ :=
let R : Matrix ((Bool × Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m)))
((Bool × Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m))) ℂ := fun x y =>
if x.2 = y.2 ∧ x.1.2.2 = (if B.valid y.2 then y.1.2.2 else !y.1.2.2) then
dataRotation (Real.sign (a y.2.1) * supportedPower (a y.2.1) p /
(tableMax a) ^ p) x.1.1 y.1.1 *
dataRotation (supportedPower (a y.2.1) (1 - p) /
(tableMax a) ^ (1 - p)) x.1.2.1 y.1.2.1 else 0
let V := (diffusion (n := n) (F := Bool × Bool × Bool) B.Hr)ᴴ * withFlags (F := Bool × Bool × Bool) B.row * R *
(withFlags (F := Bool × Bool × Bool) B.column)ᴴ * diffusion (n := n) (F := Bool × Bool × Bool) B.Hc
fun x y => V (x.1.1, (x.1.2, x.2)) (y.1.1, (y.1.2, y.2))
/-- PDF pp.7,10: a loading schedule lists the table slots read at each loading stage.
The base word contains one table rotation; the split and PREP words contain two.
This metric does not count arithmetic gates or synthesis precision. -/
def loadingCost (schedule : List ℕ) : ℕ := schedule.sum
/-- PDF pp.5,7: the base circuit's single table oracle. -/
def baseLoadingSchedule (D : ℕ) : List ℕ := [D]
/-- PDF pp.8,10: two separately loaded data tables. -/
def doubleLoadingSchedule (D : ℕ) : List ℕ := [D, D]
/-- PDF p.11, (35): transpose is an involution on every label and preserves
the data index and the range predicate, including on invalid labels. -/
structure TransposeOracle (B : Scheme n s d m) where
transpose : Equiv.Perm (Fin (2 ^ d) × Fin (2 ^ m))
involutive : ∀ l, transpose (transpose l) = l
data_preserved : ∀ l, (transpose l).1 = l.1
valid_preserved : ∀ l, B.valid (transpose l) = B.valid l
row_eq : ∀ l, B.row l = B.column (transpose l)
diffusion_eq : B.Hr = B.Hc
/-- PDF pp.2,5: for the zero matrix use a flag X and alpha=1, rather than
normalizing a zero data table. This definition is independent of all divisions. -/
def zeroEncoding (N : ℕ) : Matrix (Bool × Fin N) (Bool × Fin N) ℂ :=
fun x y => if x.1 = !y.1 ∧ x.2 = y.2 then 1 else 0
/-- The separate zero encoding has exactly zero selected block, even for N=0. -/
example (N : ℕ) (i j : Fin N) : zeroEncoding N (false, i) (false, j) = 0 := by
simp [zeroEncoding]
/-- Small supported endpoint: a structural zero contributes no zeroth power. -/
example : supportedPower 0 0 = 0 := by simp [supportedPower]
/-- Small sign check for the ideal data rotation. -/
example : dataRotation (-1) false false = (-1 : ℂ) := by simp [dataRotation]
/-- Single table loading and two loading stages count their supplied items. -/
example : loadingCost (baseLoadingSchedule 3) = 3 ∧
loadingCost (doubleLoadingSchedule 3) = 6 := by decide
/-- PDF p.10, (31): compatible physical tensor factors. The active D labels
need not fill their binary register. Supports factor as D times the supported
residual sparsity. Data labels are preserved by both full arithmetic oracles;
this is the source's commutativity prerequisite, including all padding. -/
structure PrepLayout (B : Scheme n s d m) where
active : Finset (Fin (2 ^ d))
active_nonempty : active.Nonempty
kc : ℕ
kr : ℕ
factorColumn : Fin (2 ^ s) ≃ (Fin (2 ^ d) × Fin (2 ^ kc))
factorRow : Fin (2 ^ s) ≃ (Fin (2 ^ d) × Fin (2 ^ kr))
factorColumn_zero : factorColumn 0 = (0, 0)
factorRow_zero : factorRow 0 = (0, 0)
residualColumn : Finset (Fin (2 ^ kc))
residualRow : Finset (Fin (2 ^ kr))
residualColumn_nonempty : residualColumn.Nonempty
residualRow_nonempty : residualRow.Nonempty
column_support : ∀ t, t ∈ B.columnSlots ↔
(factorColumn t).1 ∈ active ∧ (factorColumn t).2 ∈ residualColumn
row_support : ∀ t, t ∈ B.rowSlots ↔
(factorRow t).1 ∈ active ∧ (factorRow t).2 ∈ residualRow
column_data : ∀ l, (factorColumn (B.column l).1).1 = l.1
row_data : ∀ l, (factorRow (B.row l).1).1 = l.1
Hcolumn : Matrix (Fin (2 ^ kc)) (Fin (2 ^ kc)) ℂ
Hrow : Matrix (Fin (2 ^ kr)) (Fin (2 ^ kr)) ℂ
Hcolumn_unitary : Hcolumn ∈ Matrix.unitaryGroup _ ℂ
Hrow_unitary : Hrow ∈ Matrix.unitaryGroup _ ℂ
Hcolumn_zero : ∀ t, Hcolumn t 0 = if t ∈ residualColumn then
((Real.sqrt (residualColumn.card : ℝ))⁻¹ : ℂ) else 0
Hrow_zero : ∀ t, Hrow t 0 = if t ∈ residualRow then
((Real.sqrt (residualRow.card : ℝ))⁻¹ : ℂ) else 0
/-- PDF pp.10-11, (32): supported physical data register with its actual D. -/
def PrepLayout.alpha {B : Scheme n s d m} (L : PrepLayout B)
(a : Fin (2 ^ d) → ℝ) (p : ℝ) : ℝ :=
Real.sqrt ((B.columnSlots.card : ℝ) * B.rowSlots.card) / L.active.card *
Real.sqrt ((∑ j ∈ L.active, supportedPower (a j) (2 * p)) *
∑ j ∈ L.active, supportedPower (a j) (2 - 2 * p))
/-- PDF p.10, (29)-(30): PREP column and UNPREP row, with normalized states
and full unitary completions. This does not assume block-encoding correctness. -/
structure PreparationPair {B : Scheme n s d m} (L : PrepLayout B)
(a : Fin (2 ^ d) → ℝ) (p : ℝ) where
prep : Matrix (Fin (2 ^ d)) (Fin (2 ^ d)) ℂ
unprep : Matrix (Fin (2 ^ d)) (Fin (2 ^ d)) ℂ
prep_unitary : prep ∈ Matrix.unitaryGroup _ ℂ
unprep_unitary : unprep ∈ Matrix.unitaryGroup _ ℂ
prep_zero : ∀ j, prep j 0 = if j ∈ L.active then
((Real.sign (a j) * supportedPower (a j) p /
Real.sqrt (∑ k ∈ L.active, supportedPower (a k) (2 * p)) : ℝ) : ℂ) else 0
unprep_zero : ∀ j, unprep 0 j = if j ∈ L.active then
((supportedPower (a j) (1 - p) /
Real.sqrt (∑ k ∈ L.active, supportedPower (a k) (2 - 2 * p)) : ℝ) : ℂ) else 0
/-- PDF p.10, (31): a preparation acting on the data factor and residual factor. -/
def tensorPreparation {k : ℕ}
(factor : Fin (2 ^ s) ≃ (Fin (2 ^ d) × Fin (2 ^ k)))
(P : Matrix (Fin (2 ^ d)) (Fin (2 ^ d)) ℂ)
(H : Matrix (Fin (2 ^ k)) (Fin (2 ^ k)) ℂ) :
Matrix (Fin (2 ^ s)) (Fin (2 ^ s)) ℂ :=
fun x y => P (factor x).1 (factor y).1 * H (factor x).2 (factor y).2
/-- PDF p.10, (31): PREP, the column/range/row oracles, then UNPREP.
Only the range-deletion qubit is left besides the physical sparsity register. -/
def PrepLayout.circuit {B : Scheme n s d m} (L : PrepLayout B)
{a : Fin (2 ^ d) → ℝ} {p : ℝ} (P : PreparationPair L a p) :
Matrix ((Bool × Fin (2 ^ s)) × Fin (2 ^ n))
((Bool × Fin (2 ^ s)) × Fin (2 ^ n)) ℂ :=
let G : Matrix (Bool × (Fin (2 ^ d) × Fin (2 ^ m)))
(Bool × (Fin (2 ^ d) × Fin (2 ^ m))) ℂ := fun x y =>
if x.2 = y.2 ∧ x.1 = (if B.valid y.2 then y.1 else !y.1) then 1 else 0
let V := diffusion (n := n) (F := Bool) (tensorPreparation L.factorRow P.unprep L.Hrowᴴ) *
withFlags (F := Bool) B.row * G * (withFlags (F := Bool) B.column)ᴴ *
diffusion (n := n) (F := Bool) (tensorPreparation L.factorColumn P.prep L.Hcolumn)
fun x y => V (x.1.1, (x.1.2, x.2)) (y.1.1, (y.1.2, y.2))
/-- PDF p.12, (38): the full Hermitian sign oracle. Zero/unused labels
have sign +1, so that the completion is unitary and Hermitian on every label. -/
def signOracle (a : Fin (2 ^ d) → ℝ) : Matrix (Fin (2 ^ d)) (Fin (2 ^ d)) ℂ :=
fun i j => if i = j then (if a i < 0 then -1 else 1) else 0
/-- One supported data item has normalization |a| independent of p. -/
example (a : Fin 1 → ℝ) (Sc Sr : ℕ) (p : ℝ) :
prepAlpha a Sc Sr p = Real.sqrt ((Sc : ℝ) * Sr) *
Real.sqrt (supportedPower (a 0) (2 * p) * supportedPower (a 0) (2 - 2 * p)) := by
simp [prepAlpha]
/-- PDF pp.5,13-21: elementary reversible arithmetic gates X, CNOT, CCNOT.
Controls and target are distinct. Swaps can be three CNOT gates. -/
structure ArithmeticGate (w : ℕ) where
target : Fin w
controls : Finset (Fin w)
target_not_control : target ∉ controls
at_most_two : controls.card ≤ 2
/-- Basis action of an elementary reversible arithmetic gate. -/
def ArithmeticGate.run {w : ℕ} (g : ArithmeticGate w) (x : QAlgorithms.Qubits w) :
QAlgorithms.Qubits w :=
fun i => if i = g.target then Bool.xor (x i) (decide (∀ j ∈ g.controls, x j = true)) else x i
/-- Arithmetic gates are performed in list order. -/
def runArithmetic {w : ℕ} (c : List (ArithmeticGate w)) (x : QAlgorithms.Qubits w) :
QAlgorithms.Qubits w := c.foldl (fun y g => g.run y) x
/-- PDF pp.13-21: CCNOT count in the actual elementary arithmetic list. -/
def toffoliCount {w : ℕ} (c : List (ArithmeticGate w)) : ℕ :=
(c.map fun g => if g.controls.card = 2 then 1 else 0).sum
/-- Canonical most-significant-first bit, returning zero beyond the register. -/
def bitAt (w value k : ℕ) : Bool :=
if h : k < w then QAlgorithms.natToBits w value ⟨k, h⟩ else false
/-- Canonical binary encoding of two source registers, in their displayed order. -/
def pairBits {u v : ℕ} (x : Fin (2 ^ u) × Fin (2 ^ v)) (k : ℕ) : Bool :=
if k < u then bitAt u x.1 k else bitAt v x.2 (k - u)
/-- A leading Boolean flag followed by the two source registers. -/
def flaggedPairBits {u v : ℕ} (x : Bool × (Fin (2 ^ u) × Fin (2 ^ v))) (k : ℕ) : Bool :=
if k = 0 then x.1 else pairBits x.2 (k - 1)
/-- Source-order encoding of the existing data and deletion flags followed
by the label registers. They may be borrowed by arithmetic but must be restored
on every basis input; they are not further clean work ancillas. -/
def doubleFlaggedPairBits {u v : ℕ}
(x : (Bool × Bool) × (Fin (2 ^ u) × Fin (2 ^ v))) (k : ℕ) : Bool :=
if k = 0 then x.1.1 else if k = 1 then x.1.2 else pairBits x.2 (k - 2)
/-- Append clean work wires after a fixed physical binary encoding. -/
def cleanBits {X : Type*} (encode : X → ℕ → Bool) (w work : ℕ) (x : X) :
QAlgorithms.Qubits (w + work) :=
fun i => if i.val < w then encode x i.val else false
/-- A cost-bearing reversible circuit implements a map on every basis input,
returning every work wire to zero. Encodings are fixed, rather than chosen to
make the map artificially cheap. -/
def RealizesMap {X Y : Type*} (input : X → ℕ → Bool) (output : Y → ℕ → Bool)
(f : X → Y) (w work : ℕ) (c : List (ArithmeticGate (w + work))) : Prop :=
∀ x, runArithmetic c (cleanBits input w work x) = cleanBits output w work (f x)
/-- PDF pp.7,14-21: implementations of the two label oracles and the range
NOT. The bound is on their summed CCNOT count. Work is clean and not a flag. -/
def Scheme.ArithmeticCost (B : Scheme n s d m) (bound : ℝ) (work : ℕ) : Prop :=
∃ c r g : List (ArithmeticGate ((2 + (d + m)) + work)),
RealizesMap doubleFlaggedPairBits doubleFlaggedPairBits
(fun x : (Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m)) => (x.1, B.column x.2))
(2 + (d + m)) work c ∧
RealizesMap doubleFlaggedPairBits doubleFlaggedPairBits
(fun x : (Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m)) => (x.1, B.row x.2))
(2 + (d + m)) work r ∧
RealizesMap doubleFlaggedPairBits doubleFlaggedPairBits
(fun x : (Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m)) =>
((x.1.1, if B.valid x.2 then x.1.2 else !x.1.2), x.2))
(2 + (d + m)) work g ∧
((toffoliCount c + toffoliCount r + toffoliCount g : ℕ) : ℝ) ≤ bound
/-- PDF p.21: all-gates count for the Laplacian arithmetic. Existing flags
may be borrowed but are restored on all basis inputs, including junk inputs. -/
def Scheme.ArithmeticSize (B : Scheme n s d m) (bound : ℝ) (work : ℕ) : Prop :=
∃ c r g : List (ArithmeticGate ((2 + (d + m)) + work)),
RealizesMap doubleFlaggedPairBits doubleFlaggedPairBits
(fun x : (Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m)) => (x.1, B.column x.2))
(2 + (d + m)) work c ∧
RealizesMap doubleFlaggedPairBits doubleFlaggedPairBits
(fun x : (Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m)) => (x.1, B.row x.2))
(2 + (d + m)) work r ∧
RealizesMap doubleFlaggedPairBits doubleFlaggedPairBits
(fun x : (Bool × Bool) × (Fin (2 ^ d) × Fin (2 ^ m)) =>
((x.1.1, if B.valid x.2 then x.1.2 else !x.1.2), x.2))
(2 + (d + m)) work g ∧
((c.length + r.length + g.length : ℕ) : ℝ) ≤ bound
/-- PDF p.13, (40)-(44): the checkerboard entries, allowing signed data. -/
def checkerboard (n : ℕ) (a : Fin 2 → ℝ) : Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ :=
fun i j => (a ⟨(i.val + j.val) % 2, Nat.mod_lt _ (by decide)⟩ : ℂ)
/-- PDF p.13, (41)-(42): the paper's checkerboard labels. -/
def CheckerLabels (B : Scheme n n 1 (2 * n - 1)) : Prop :=
(∀ l, B.valid l = true) ∧ B.columnSlots = Finset.univ ∧ B.rowSlots = Finset.univ ∧
∀ l, (B.row l).2.val = l.2.val / (2 ^ n / 2) ∧
(B.column l).2.val = 2 * (l.2.val % (2 ^ n / 2)) +
(l.1.val + l.2.val / (2 ^ n / 2)) % 2
/-- PDF pp.13-14, (49): replace only the two specified corner entries by zero. -/
def deletedCheckerboard (n : ℕ) (a : Fin 2 → ℝ) : Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ :=
fun i j => if (i.val = 0 ∧ j.val = 0) ∨
(i.val + 1 = 2 ^ n ∧ j.val + 1 = 2 ^ n) then 0 else checkerboard n a i j
/-- PDF p.14, (49): the same arithmetic permutations with two invalid labels. -/
def deleteCheckerCorners (B : Scheme n n 1 (2 * n - 1)) : Scheme n n 1 (2 * n - 1) :=
{ B with
valid := fun l => B.valid l && !(decide (l.1.val = 0 ∧
(l.2.val = 0 ∨ l.2.val + 1 = 2 ^ (2 * n - 1))))
column_range := by
intro l h
simp only [Bool.and_eq_true_eq_eq_true_and_eq_true] at h
exact B.column_range l h.1
row_range := by
intro l h
simp only [Bool.and_eq_true_eq_eq_true_and_eq_true] at h
exact B.row_range l h.1
positions_injective := by
intro l k hl hk hc hr
simp only [Bool.and_eq_true_eq_eq_true_and_eq_true] at hl hk
exact B.positions_injective l k hl.1 hk.1 hc hr }
/-- PDF p.14, (50)-(52): the diagonal seed for the accepted Toeplitz matrix.
Seed address u represents signed offset u-(N-1); out-of-band diagonals are zero. -/
def bandedToeplitzSeed (n d : ℕ) (k : Fin (2 ^ d)) (a : Fin (2 ^ d) → ℝ) :
Fin (2 ^ n + 2 ^ n - 1) → ℂ :=
fun u => ∑ t : Fin (2 ^ d),
if (u.val : ℤ) - ((2 ^ n - 1 : ℕ) : ℤ) = (t.val : ℤ) - k.val
then (a t : ℂ) else 0
/-- PDF p.14, (50): specialize the accepted full Toeplitz matrix to the
paper's banded signed-offset data; no periodic wrap-around is introduced. -/
def bandedToeplitz (n d : ℕ) (k : Fin (2 ^ d)) (a : Fin (2 ^ d) → ℝ) :
Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ :=
QAlgorithms.Papers.Independent.Advance50.P23.toeplitz (2 ^ n) (2 ^ n)
(bandedToeplitzSeed n d k a)
/-- Sanity check: the one-entry banded Toeplitz adapter selects its sole datum. -/
example (a : Fin 1 → ℝ) : bandedToeplitz 0 0 0 a 0 0 = (a 0 : ℂ) := by
simp [bandedToeplitz, QAlgorithms.Papers.Independent.Advance50.P23.toeplitz,
bandedToeplitzSeed]
/-- PDF pp.14-15: the actual Toeplitz arithmetic and its overflow deletion. -/
def ToeplitzLabels (B : Scheme n d d n) (k : Fin (2 ^ d)) : Prop :=
B.columnSlots = Finset.univ ∧ B.rowSlots = Finset.univ ∧
∀ l, B.column l = (l.1, l.2) ∧ (B.row l).1 = l.1 ∧
((B.row l).2.val : ℤ) = ((l.1.val : ℤ) - k.val + l.2.val) % (2 ^ n : ℕ) ∧
(B.valid l = true ↔ 0 ≤ (l.1.val : ℤ) - k.val + l.2.val ∧
(l.1.val : ℤ) - k.val + l.2.val < (2 ^ n : ℕ))
/-- PDF pp.15-16, (57),(63): diagonal/off-diagonal data with the last table
slot fixed to zero, rather than loaded as an independent real parameter. -/
def triTable (n : ℕ) (a : Fin (2 * 2 ^ n - 1) → ℝ) : Fin (2 ^ (n + 1)) → ℝ :=
fun j => if h : j.val < 2 * 2 ^ n - 1 then a ⟨j.val, h⟩ else 0
/-- PDF p.15, (57): symmetric tridiagonal matrix, including N=1 and N=2. -/
def tridiagonal (n : ℕ) (a : Fin (2 * 2 ^ n - 1) → ℝ) :
Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ :=
fun i j => if i = j then (triTable n a ⟨2 * i.val, by simp only [pow_succ]; omega⟩ : ℂ)
else if i.val + 1 = j.val ∨ j.val + 1 = i.val then
(triTable n a ⟨2 * min i.val j.val + 1, by
have hi := i.isLt
have hm := Nat.min_le_left i.val j.val
simp only [pow_succ]
omega⟩ : ℂ) else 0
/-- PDF p.16, (58)-(62): the supported three labels are 00,01,11, not H4. -/
def TridiagonalLabels (B : Scheme n 2 (n + 1) 1) : Prop :=
B.columnSlots = (Finset.univ.filter fun j => j.val ≠ 2) ∧
B.rowSlots = (Finset.univ.filter fun j => j.val ≠ 2) ∧
∀ l, (B.valid l = true ↔ ¬((l.1.val % 2 = 0 ∧ l.2.val = 1) ∨
l.1.val + 1 = 2 ^ (n + 1))) ∧
(B.valid l = true → (B.row l).2.val = (l.1.val / 2 + l.2.val) % 2 ^ n ∧
(B.column l).2.val = (l.1.val / 2 + (if l.2.val = 0 then l.1.val % 2 else 0)) % 2 ^ n)
/-- PDF pp.17-18, (67): tree adjacency with the source's extra root edge
0--1, root/leaf diagonal a0, internal diagonal a1, and every edge a2. -/
def extendedTree (n : ℕ) (a : Fin 3 → ℝ) : Matrix (Fin (2 ^ n)) (Fin (2 ^ n)) ℂ :=
fun i j => if i = j then (a (if i.val = 0 ∨ 2 ^ n / 2 ≤ i.val then 0 else 1) : ℂ)
else if (i.val > 0 ∧ i.val / 2 = j.val) ∨ (j.val > 0 ∧ j.val / 2 = i.val)
then (a 2 : ℂ) else 0
/-- PDF p.17: fourth physical data slot is a structural zero. -/
def treeTable (a : Fin 3 → ℝ) : Fin 4 → ℝ :=
fun j => if h : j.val < 3 then a ⟨j.val, h⟩ else 0
/-- PDF pp.17-18, (69)-(74): range and row formulas. The two invalid edge
labels m=0,N have reversible completions instead of undefined arithmetic. -/
def TreeLabels (B : Scheme n 3 2 (n + 1)) : Prop :=
B.columnSlots = (Finset.univ.filter fun j => j.val < 4) ∧
B.rowSlots = (Finset.univ.filter fun j => j.val < 4) ∧
∀ l, (B.valid l = true ↔
(l.1.val = 0 ∧ (l.2.val = 0 ∨ (2 ^ n / 2 ≤ l.2.val ∧ l.2.val < 2 ^ n))) ∨
(l.1.val = 1 ∧ 0 < l.2.val ∧ l.2.val < 2 ^ n / 2) ∨
(l.1.val = 2 ∧ l.2.val ≠ 0 ∧ l.2.val ≠ 2 ^ n)) ∧
(B.valid l = true → (B.row l).2.val =
if l.1.val < 2 then l.2.val else
if l.2.val < 2 ^ n then l.2.val / 2 else l.2.val - 2 ^ n)
/-- PDF pp.19-20, (78): nonperiodic finite-difference Laplacian.
The integer coordinate differences avoid truncated natural subtraction. -/
def laplacian (nx ny : ℕ) (dx dy : ℝ) :
Matrix (Fin (2 ^ (nx + ny))) (Fin (2 ^ (nx + ny))) ℂ :=
fun i j =>
if i = j then (-2 * (1 / dx ^ 2 + 1 / dy ^ 2) : ℝ)
else if (i.val / 2 ^ nx = j.val / 2 ^ nx) ∧
|((i.val % 2 ^ nx : ℕ) : ℤ) - (j.val % 2 ^ nx : ℕ)| = 1 then (1 / dx ^ 2 : ℝ)
else if (i.val % 2 ^ nx = j.val % 2 ^ nx) ∧
|((i.val / 2 ^ nx : ℕ) : ℤ) - (j.val / 2 ^ nx : ℕ)| = 1 then (1 / dy ^ 2 : ℝ)
else 0
/-- PDF p.19, (78): the three actual values and a fourth zero sentinel. -/
def laplacianTable (dx dy : ℝ) : Fin 4 → ℝ :=
fun j => if j.val = 0 then -2 * (1 / dx ^ 2 + 1 / dy ^ 2)
else if j.val = 1 then 1 / dx ^ 2 else if j.val = 2 then 1 / dy ^ 2 else 0
/-- PDF pp.19-20, (80)-(84): five supported states and off-grid deletion. -/
def LaplacianLabels (nx ny : ℕ) (B : Scheme (nx + ny) 3 2 (nx + ny + 1)) : Prop :=
B.columnSlots = (Finset.univ.filter fun j => j.val = 0 ∨ j.val = 2 ∨
j.val = 3 ∨ j.val = 4 ∨ j.val = 5) ∧
B.rowSlots = B.columnSlots ∧
∀ l, (B.valid l = true ↔
(l.1.val = 0 ∧ l.2.val < 2 ^ (nx + ny)) ∨
(l.1.val = 1 ∧ l.2.val % 2 ^ nx ≠ 0) ∨
(l.1.val = 2 ∧ l.2.val % 2 ^ (nx + ny) ≥ 2 ^ nx)) ∧
(B.column l).1.val = 2 * l.1.val + l.2.val / 2 ^ (nx + ny) ∧
(B.valid l = true → ((B.column l).2.val : ℤ) =
((l.2.val % 2 ^ (nx + ny) : ℕ) : ℤ) -
(if l.2.val < 2 ^ (nx + ny) ∧ l.1.val = 1 then 1
else if l.2.val < 2 ^ (nx + ny) ∧ l.1.val = 2 then (2 ^ nx : ℕ) else 0))
/-- PDF p.13, (45): when no range deletion is needed, remove that untouched
flag from the PREP circuit, rather than counting an extra physical flag. -/
def PrepLayout.noDeleteCircuit {B : Scheme n s d m} (L : PrepLayout B)
{a : Fin (2 ^ d) → ℝ} {p : ℝ} (P : PreparationPair L a p) :
Matrix (Fin (2 ^ s) × Fin (2 ^ n)) (Fin (2 ^ s) × Fin (2 ^ n)) ℂ :=
fun x y => L.circuit P ((false, x.1), x.2) ((false, y.1), y.2)
/-- Reversible arithmetic with zero gates ignores no input and preserves all bits. -/
example (w : ℕ) (x : QAlgorithms.Qubits w) : runArithmetic [] x = x := rfl
/-- PDF p.16: the last tridiagonal table slot is a fixed zero sentinel. -/
example : triTable 1 (fun _ => (1 : ℝ)) 3 = 0 := by simp [triTable]
/-- N=2 checkerboard sign/parity and corner-deletion checks. -/
example (a : Fin 2 → ℝ) : checkerboard 1 a 0 1 = (a 1 : ℂ) ∧
deletedCheckerboard 1 a 0 0 = 0 := by simp [checkerboard, deletedCheckerboard]
/-- PDF pp.25-26: the elementary Clifford+T gate set used for T counts.
Arbitrary rotations are targets of approximation, not free gates in this set. -/
def cliffordTSet : Set QAlgorithms.Gate :=
{g | g = QAlgorithms.Gate.ofMatrix1 QAlgorithms.hadamard ∨
g = QAlgorithms.Gate.ofMatrix1 QAlgorithms.gateT ∨
g = QAlgorithms.Gate.ofMatrix1 QAlgorithms.gateTᴴ ∨
g = QAlgorithms.Gate.ofMatrix1 QAlgorithms.pauliX ∨
g = QAlgorithms.Gate.ofMatrix2 QAlgorithms.cnot}
local instance : DecidableEq QAlgorithms.Gate := Classical.decEq _
/-- PDF pp.25-26: extract the T-cost instruction trace from a concrete
Clifford+T circuit for the accepted single-qubit word counter. Each T or inverse-T
instruction contributes one t; other gates contribute h and hence zero T count.
This trace records cost only; Circuit.unitary retains the full gate semantics. -/
def loaderTWord {w : ℕ} (c : QAlgorithms.Circuit cliffordTSet w) :
List QAlgorithms.Papers.Independent.Next46.P21.Letter :=
c.map fun g => if g.gate = QAlgorithms.Gate.ofMatrix1 QAlgorithms.gateT ∨
g.gate = QAlgorithms.Gate.ofMatrix1 QAlgorithms.gateTᴴ then .t else .h
/-- PDF p.26: a normalized reusable phase-gradient resource. Its preparation
is separate from each invocation of the lookup/rotate/uncompute procedure. -/
def phaseGradient (b : ℕ) (z : QAlgorithms.Qubits b) : ℂ :=
(Real.sqrt (2 ^ b : ℕ))⁻¹ * Complex.exp
(-2 * (Real.pi : ℂ) * Complex.I * (QAlgorithms.bitsToNat z : ℂ) / (2 ^ b : ℕ))
/-- PDF pp.25-26, (91): embed data flag and table index with the reusable
gradient state and clean work. This specifies full output accuracy, including
return of the resource and work, not only the selected data amplitude. -/
def loaderEmbedding (db b work : ℕ) :
Matrix (QAlgorithms.Qubits (1 + db + b + work)) (Bool × Fin (2 ^ db)) ℂ :=
fun y x => if y ⟨0, by omega⟩ = x.1 ∧
(∀ i : Fin db, y ⟨1 + i.val, by omega⟩ = QAlgorithms.natToBits db x.2 i) ∧
(∀ i : Fin work, y ⟨1 + db + b + i.val, by omega⟩ = false) then
phaseGradient b (fun i => y ⟨1 + db + i.val, by omega⟩) else 0
/-- PDF p.25, (89): the ideal multiplexed RX data loader on every data-flag input. -/
def idealLoader {db : ℕ} (a : Fin (2 ^ db) → ℝ) :
Matrix (Bool × Fin (2 ^ db)) (Bool × Fin (2 ^ db)) ℂ :=
fun x y => if x.2 = y.2 then dataRotation (a y.2 / tableMax a) x.1 y.1 else 0
/-- PDF p.25: a non-power-of-two supplied data table is padded with known zeros
in its minimal physical binary register. No new unknown item is loaded. -/
def paddedTable {D : ℕ} (a : Fin D → ℝ) : Fin (2 ^ (Nat.clog 2 D)) → ℝ :=
fun j => if h : j.val < D then a ⟨j.val, h⟩ else 0
/-- PDF p.26, (94): the reverse map supplies an occurrence label, or the
fixed zero sentinel for structural zeros. It is not inferred from forward maps. -/
def reverseCode {d m : ℕ} {X : Type*}
(r : X → Option (Fin (2 ^ d) × Fin (2 ^ m))) (x : X) :
QAlgorithms.Qubits (1 + d + m) :=
fun i => match r x with
| none => false
| some l => flaggedPairBits (true, l) i.val
/-- PDF p.26: finite b-bit data lookup, with no additional loaded zero value. -/
def valueAtLabel {d m b : ℕ} (code : Fin (2 ^ d) → QAlgorithms.Qubits b)
(z : QAlgorithms.Qubits (1 + d + m)) : QAlgorithms.Qubits b :=
if z ⟨0, by omega⟩ then code (QAlgorithms.bitsEquivFin d
(fun i => z ⟨1 + i.val, by omega⟩)) else 0
/-- A basis-action matrix used for the reversible XOR compute/load steps. -/
def basisMatrix {X : Type*} [DecidableEq X] (f : X → X) : Matrix X X ℂ :=
fun x y => if x = f y then 1 else 0
/-- PDF p.26, (94): compute the occurrence label, XOR the corresponding
finite entry value, then uncompute the occurrence label. Buffer input is general. -/
def entryCircuit {n d m b : ℕ}
(r : (Fin (2 ^ n) × Fin (2 ^ n)) → Option (Fin (2 ^ d) × Fin (2 ^ m)))
(code : Fin (2 ^ d) → QAlgorithms.Qubits b) :
Matrix ((QAlgorithms.Qubits b × (Fin (2 ^ n) × Fin (2 ^ n))) ×
QAlgorithms.Qubits (1 + d + m))
((QAlgorithms.Qubits b × (Fin (2 ^ n) × Fin (2 ^ n))) ×
QAlgorithms.Qubits (1 + d + m)) ℂ :=
let C := basisMatrix fun x => (x.1, x.2 + reverseCode r x.1.2)
let V := basisMatrix fun x => ((x.1.1 + valueAtLabel code x.2, x.1.2), x.2)
C * V * C
/-- PDF p.26: binary encoding for the reverse-map implementation; rows,
columns, and occurrence workspace use the fixed displayed register order. -/
def rowColumnLabelBits {n t : ℕ}
(x : (Fin (2 ^ n) × Fin (2 ^ n)) × QAlgorithms.Qubits t) (i : ℕ) : Bool :=
if i < n + n then pairBits x.1 i else bitAt t (QAlgorithms.bitsToNat x.2) (i - (n + n))
/-- PDF p.26: the arithmetic part of the three-stage word consists exactly
of the given reverse-map circuit and its inverse, with no repetition of data. -/
def entryArithmeticCost {w : ℕ} (c : List (ArithmeticGate w)) : ℕ :=
toffoliCount (c ++ c.reverse)
/-- A zero sentinel yields the zero b-bit word, including b=0. -/
example (b d m : ℕ) (code : Fin (2 ^ d) → QAlgorithms.Qubits b) :
valueAtLabel (m := m) code 0 = 0 := by simp [valueAtLabel]
/-- The empty Clifford+T circuit has zero T count. -/
example (w : ℕ) : tCount (loaderTWord ([] : QAlgorithms.Circuit cliffordTSet w)) = 0 := rfl
end QAlgorithms.Papers.Independent.Extend50.P44
Read-back
What the Lean code literally says, in plain math · gpt-6.1-sol
QAlgorithms.Papers.Independent.Extend50.P44.ArithmeticGate
For every natural number , an arithmetic gate is data consisting of a target index and a finite set of control indices , together with the requirements and . The control set may be empty, have one element, or have two elements. For , no such gate exists because there is no possible target index.
QAlgorithms.Papers.Independent.Extend50.P44.ArithmeticGate.run
For every natural number , every arithmetic gate with target and control set satisfying and , and every Boolean string , this defines the output string by
where the indicator is Boolean true exactly when every control bit is true. Thus the target is flipped exactly under that condition, and every other bit is retained. For the empty control set the condition is vacuously true, so the target is always flipped; when , there is no gate to supply as an argument.
QAlgorithms.Papers.Independent.Extend50.P44.CheckerLabels
For a natural number and a scheme with parameters , where natural-number subtraction is truncated at zero, this predicate requires every label , with and , to be valid, both slot sets to be the entire set , and the second coordinates of its row and column images to satisfy
Here is natural-number division. Being a scheme additionally means that ; the row and column maps are bijections from the label set onto ; their first coordinates on valid labels belong to their respective nonempty slot sets; and equality of both second coordinates for valid labels forces equality of labels. The scheme also supplies unitary matrices whose columns indexed by zero are the respective slot indicators divided by the square roots of the slot cardinalities, so under this predicate both columns are constantly . The displayed coordinate requirements impose no additional formula for the first coordinates. Although is syntactically included, no such scheme exists then, since its required bit balance would be .
QAlgorithms.Papers.Independent.Extend50.P44.LaplacianLabels
Let be arbitrary natural numbers, including zero, and put and . Write . The argument is a scheme with label set , two bijections , a Boolean validity function , nonempty column and row slot sets , and unitary matrices on . Its parameters satisfy ; every valid label has its column slot in and row slot in ; two valid labels with the same column output coordinate and the same row output coordinate must be equal; and the zeroth columns of equal on and on , respectively, and zero elsewhere. This definition is the proposition that , , and every label , including invalid labels, satisfies
and, whenever that label is valid, its column output coordinate satisfies the following equality in the integers:
There is no additional row-coordinate formula in this predicate. The powers used as divisors are always positive; when , the validity alternative never holds, and when , the alternative never holds.
QAlgorithms.Papers.Independent.Extend50.P44.PrepLayout.alpha
Let be natural numbers and . The parameter is scheme data consisting of , bijections , a Boolean validity function , nonempty sets , and unitary matrices on . Valid labels map into the corresponding slot sets; a valid label is determined by the pair ; and the zeroth columns of are respectively uniform on and zero elsewhere. The parameter supplies a nonempty active set , natural numbers , zero-preserving bijections , , nonempty residual sets , and unitary residual matrices with zeroth columns uniform on those sets and zero elsewhere; it requires , , and for every label. For every real-valued table and every real , this defines
There is no restriction on , no nonvanishing requirement on , and no requirement that vanish outside ; entries outside do not enter this expression. In particular, the supported-power convention assigns zero to a zero entry even when its exponent is zero or negative, and the expression is zero if all active entries vanish.
QAlgorithms.Papers.Independent.Extend50.P44.PrepLayout.circuit
Let be natural numbers and . Let supply , bijections , a Boolean validity function , nonempty slot sets , and unitary matrices with zeroth columns uniform on those sets and zero elsewhere; valid labels map into the corresponding sets and are determined uniquely by their pair of system positions . Let supply a nonempty active set , natural numbers , zero-preserving bijections , , nonempty residual sets , and unitary matrices whose zeroth columns are uniform on those residual sets and zero elsewhere, with , , and for every label. For any real table , real , and supplied preparation pair , the matrices are unitary and have zeroth column and zeroth row, respectively, equal on to
and zero outside , where and otherwise. Define ; define ; and, for , define . On Boolean-flagged labels define
The declaration defines a matrix indexed by by reassociating the indices of
Here denotes conjugate transpose. This is a definition of the matrix; it makes no additional assertion about its block or its Hermitian property.
QAlgorithms.Papers.Independent.Extend50.P44.PrepLayout
Let be natural numbers, write , and let consist of the following scheme data: ; bijections ; a Boolean function on their domain; nonempty sets ; and unitary matrices on . These data satisfy and ; any two valid labels having both the same second component under and the same second component under are equal; and for , zero otherwise, with the analogous requirement for . A preparation layout for is additional data comprising a nonempty set , natural numbers , bijections
nonempty sets , , and unitary matrices on these respective residual index spaces. They must satisfy ,
for every and every label , including invalid labels. Finally, on and zero elsewhere, and on and zero elsewhere. None of is required to be positive; their powers of two are always positive.
QAlgorithms.Papers.Independent.Extend50.P44.PrepLayout.noDeleteCircuit
Let be arbitrary natural numbers, write , and set , , , . The implicit argument consists of the equality , column and row bijections , a Boolean validity function , nonempty slot sets , and unitary slot matrices . Valid labels map into their respective slot sets, valid labels are uniquely determined by their column and row output coordinates together, and the zeroth columns of are the normalized indicators of . The layout supplies a nonempty active set , natural numbers , bijections and sending to , and nonempty residual sets , such that membership in is respectively equivalent to the first factor belonging to and the second belonging to . Moreover, the first factor of and of equals the data index for every label . The layout also supplies unitary matrices whose zeroth columns are the normalized indicators of . For arbitrary real data and arbitrary real , put if , and otherwise. The argument supplies two unitary matrices on , with
To describe the defined matrix, reindex through to obtain a slot matrix , and reindex through to obtain . On registers consisting of a Boolean flag, a slot, and an output index, apply to the slot, apply to replace the slot/output pair by its label, flip the flag exactly when that label is invalid, apply to replace the label by its row slot/output pair, and apply to the slot. If is the resulting matrix, this definition returns the matrix indexed by whose -entry is
Thus it selects the false-to-false flag block; the definition alone asserts no unitarity of that selected block. All zero parameter values and all real are included. Reciprocals at zero are zero; if all active data vanish, the required zeroth column of is zero, so no such unitary preparation pair exists.
QAlgorithms.Papers.Independent.Extend50.P44.PreparationPair
Let be natural numbers and . Let contain , bijections , Boolean validity data , nonempty slot sets , and unitary matrices whose zeroth columns are uniform on the corresponding slot sets and zero elsewhere; valid labels map into those sets and are uniquely determined by . Let contain a nonempty active set , natural numbers , bijections from onto and , respectively, both sending zero to , nonempty residual sets , and unitary residual matrices with zeroth columns uniform on those sets. Its requirements are , , and for every label. For an arbitrary real table and arbitrary real , a preparation pair is a pair of unitary complex matrices on satisfying
where and for , and all displayed real entries are regarded as complex numbers. The prescribed part of is its zeroth column, whereas the prescribed part of is its zeroth row. Division by zero is defined to give zero; consequently, if all active table entries vanish, these requirements would give a zero zeroth column for , so no preparation pair exists in that case. The structure itself does not assert existence for every table and exponent.
QAlgorithms.Papers.Independent.Extend50.P44.RealizesMap
For arbitrary types , encoding functions and , a function , natural numbers , and a finite list of arithmetic gates on bits, this predicate means that for every , applying in list order to the string whose first bits are and whose final bits are false produces exactly the string whose first bits encode using and whose final bits are again false. Each gate toggles its target when all of its at most two controls are true, with the target excluded from the controls; an empty control set always triggers the toggle. The list and either length may be zero, neither encoding is assumed injective, and the predicate is vacuously true if is empty.
QAlgorithms.Papers.Independent.Extend50.P44.Scheme.ArithmeticCost
For natural numbers , a scheme , a real number , and a natural number , this predicate asserts the existence of three finite arithmetic-gate lists on bits with the following exact actions. Here the scheme includes ; bijections ; a Boolean validity function; nonempty column and row slot sets in containing the respective first coordinates of every valid label; and the requirement that two valid labels having equal column second coordinates and equal row second coordinates are equal. It also includes unitary matrices , whose columns indexed by zero equal the indicator functions of the respective slot sets divided by the square roots of their cardinalities. Encode a flagged pair by its two Boolean flags, followed by the fixed-width, most significant bit first binary representations of its two integer components, and append false bits. For every pair of flags and every label , the list maps this encoding to that of the same flags and , using output widths ; the list does the same with ; and retains and the first flag, retaining the second flag when is valid and negating it otherwise. Each list must return all appended work bits to false. Gates are applied in list order and toggle their target exactly when all their at most two controls are true, with the target excluded from the controls and an empty control set always triggering. The total number of gate occurrences with exactly two controls across , regarded as a real number, must be at most . The lists and work register may be empty; a negative bound cannot satisfy this predicate.
QAlgorithms.Papers.Independent.Extend50.P44.Scheme.ArithmeticSize
For natural numbers , a scheme , a real number , and a natural number , this predicate asserts the existence of three finite arithmetic-gate lists on bits whose combined lengths are at most , after converting the lengths to real numbers. The scheme includes ; column and row bijections from pairs of integers of widths to pairs of widths ; a Boolean validity function; nonempty column and row slot sets containing the respective first coordinates of valid labels; and injectivity of the pair consisting of the column second coordinate and row second coordinate on valid labels. It also includes unitary matrices , with their columns indexed by zero equal to the respective slot indicators divided by the square roots of the slot cardinalities. For every label and both possible values of each of two flags, encode the flags first, then 's components in fixed-width binary, most significant bit first, and append false bits. Applying in list order must produce the same flags and the column-bijection image of , encoded with widths ; applying must instead produce its row-bijection image; and applying must retain the label and first flag and toggle the second flag exactly when the label is invalid. Every list must restore all work bits to false. Each gate has a target outside its set of at most two controls and toggles that target exactly when every control is true, including unconditional toggling for an empty control set. Empty lists and zero work length are allowed; a negative bound cannot satisfy the predicate.
QAlgorithms.Papers.Independent.Extend50.P44.Scheme.baseAlpha
For natural numbers , let contain , bijections , a Boolean validity function , nonempty subsets , and complex unitary matrices , where , , and . Valid labels must map into the specified subsets in their first coordinates and be uniquely determined by their two second coordinates; have first columns equal to on those subsets and zero elsewhere. For any real table , this defines
The table includes all indices, including labels that never occur as valid; an identically zero table gives value zero. All natural parameters may be zero.
QAlgorithms.Papers.Independent.Extend50.P44.Scheme.baseCircuit
For natural numbers , let consist of , bijections , a Boolean validity function , nonempty subsets , and complex unitary matrices , where , , and ; valid labels have first coordinates in the corresponding subsets and are uniquely determined by their pair of second coordinates, and the first columns of are uniform with amplitudes on those subsets and zero elsewhere. Given a real table and a Boolean parameter , defaulting to false, let , define exactly when and , and zero otherwise, for and two-bit flags ; define when and , and zero otherwise; and define to be zero unless and for valid , or for invalid , in which case it equals multiplied by if and are both true and by otherwise, where has diagonal and off-diagonal . This defines
where denotes conjugate transpose. Thus the output matrix uses the same entries after regrouping the flag, slot, and data indices. Zero natural parameters are allowed, and an identically zero table uses the totalized quotient .
QAlgorithms.Papers.Independent.Extend50.P44.Scheme.baseMiddle
For natural numbers , let contain , bijections , a Boolean validity function , nonempty subsets , and unitary matrices , where , , and ; valid labels have first coordinates in the corresponding subsets and are uniquely determined by their two second coordinates, while the first columns of the unitaries are uniform with amplitudes on those subsets and zero elsewhere. Given a real table and a Boolean parameter , put . This defines a complex matrix on pairs of Boolean flags and a label by
where if both and are true and is otherwise, and has diagonal entries and off-diagonal entries . The parameter imposes no additional hypothesis. If is identically zero, then and every quotient is defined as zero, so the corresponding first-flag matrix has zero diagonal and off-diagonal entries . All natural parameters may be zero.
QAlgorithms.Papers.Independent.Extend50.P44.Scheme.matrix
For natural numbers , let consist of , bijections , a Boolean validity function , nonempty subsets , and unitary matrices , where , , and ; valid labels have their first - and -coordinates in , respectively, and their pair of second coordinates uniquely determines the label; the first columns of are respectively on and on , and zero elsewhere. For every real table , this defines the complex matrix
The uniqueness condition permits at most one contributing label per entry; an entry with no contributing label is zero, and the entire matrix is zero if no label is valid. Zero values of the natural parameters are allowed.
QAlgorithms.Papers.Independent.Extend50.P44.Scheme
For arbitrary natural numbers , this structure consists of a proof that ; two bijections , where , , and ; a Boolean function ; nonempty finite subsets ; and two complex unitary matrices indexed by . These data must satisfy, for every , and ; for every valid pair , equality of both and must imply ; and for every ,
All four natural parameters may be zero, with . No label is required to be valid, so may be identically false.
QAlgorithms.Papers.Independent.Extend50.P44.Scheme.simpleCircuit
For natural numbers , write and . A scheme supplies , bijections , a Boolean function , nonempty slot sets , and unitary matrices on . Every valid label , meaning , has and ; the map is injective on valid labels; and the first columns of are respectively and on their slot sets and zero elsewhere. Given any real table and Boolean parameter , defaulting to false, put and define the Boolean-indexed matrix
Define on by
For a flag set , let and send respectively to and , with matrix entries one at these images and zero otherwise, and let . The definition returns
with indices regrouped as . It imposes no nonzero-table hypothesis: if is identically zero, division by is defined to give zero. Zero values of the natural parameters are included whenever such scheme data exist.
QAlgorithms.Papers.Independent.Extend50.P44.Scheme.splitCircuit
For natural numbers , let and . A scheme consists of , bijections , a Boolean validity function , nonempty slot sets , and unitary matrices . Valid labels map into the corresponding slot sets, is injective on valid labels, and the first columns of are uniform positive amplitudes on their respective slot sets and zero elsewhere. For any and any real , set , define when and otherwise, and put
Here , and real powers and division use their total definitions, including division by zero giving zero. With for and otherwise, define a matrix on three Boolean flags and by
Let be the matrices of and , and let , where is the set of three Boolean flags. The returned matrix is , regrouped onto indices . This definition places no restriction on , allows zero table entries and the identically zero table, and asserts no unitarity.
QAlgorithms.Papers.Independent.Extend50.P44.ToeplitzLabels
For arbitrary natural numbers , put and , and fix . Let consist of column and row bijections , a Boolean validity function , nonempty slot sets , and unitary matrices ; their first columns are respectively on and zero elsewhere, and on and zero elsewhere. Valid labels must map to their respective slot sets, and two valid labels with equal column second coordinates and equal row second coordinates must coincide; the scheme’s bit-balance equality here is . This predicate means that and, for every label ,
The expression and its remainder are computed in the integers, with remainder in . The conditions apply also when or .
QAlgorithms.Papers.Independent.Extend50.P44.TransposeOracle
For natural numbers , put and . Let be scheme data consisting of , bijections , a Boolean validity function , nonempty slot sets , and unitary matrices . Valid labels map into the respective slot sets, their pairs of column and row system positions determine them uniquely, and the first columns of are uniform positive amplitudes on their slot sets and zero elsewhere. A transpose oracle for consists of a permutation satisfying, for every label ,
together with the equality . These requirements apply to invalid labels as well as valid ones.
QAlgorithms.Papers.Independent.Extend50.P44.TreeLabels
For any natural number , put . Let consist of column and row bijections , a Boolean validity function , nonempty slot sets , and unitary matrices . Their first columns are respectively on and zero elsewhere, and on and zero elsewhere; valid labels map to their respective slot sets, and two valid labels with equal column and row second coordinates coincide. The scheme also carries the balance equality . This predicate means and that a label is valid exactly when
For every valid label it additionally requires
All arithmetic here is natural-number arithmetic, and is included.
QAlgorithms.Papers.Independent.Extend50.P44.TridiagonalLabels
For any natural number , put . Let consist of column and row bijections , a Boolean validity function , nonempty slot sets , and unitary matrices . Their first columns are respectively on and zero elsewhere, and on and zero elsewhere; valid labels map to the respective slot sets, and equal column and row second coordinates determine a valid label uniquely. The scheme also carries the balance equality . This predicate asserts and, for every label ,
and, whenever that label is valid,
All divisions, remainders, and indices in these formulas are natural-number operations. The definition allows .
QAlgorithms.Papers.Independent.Extend50.P44.bandedToeplitz
For arbitrary natural numbers , an integer , and real coefficients , this defines a complex matrix. For , its entry is the seed value at index , where the seed at is the sum of over indices satisfying . Thus, using integer arithmetic for the coefficient index,
Real coefficients are regarded as complex numbers. There is no restriction relating and ; for the matrix is , and for it is times the identity.
QAlgorithms.Papers.Independent.Extend50.P44.bandedToeplitzSeed
For arbitrary natural numbers , an integer with , and real coefficients indexed by , this defines a complex-valued sequence indexed by :
The subtraction in the equality is integer subtraction. Equivalently, when that integer index lies between and , and otherwise; real values are embedded in . Both and are allowed.
QAlgorithms.Papers.Independent.Extend50.P44.baseLoadingSchedule
For every natural number , the base loading schedule is the one-entry list , including the list when .
QAlgorithms.Papers.Independent.Extend50.P44.basisMatrix
For every type equipped with decidable equality and every function , this defines the complex matrix
There is no assumption that is finite or nonempty, or that is injective or surjective.
QAlgorithms.Papers.Independent.Extend50.P44.bitAt
For all natural numbers , this defines a Boolean that, when , is position , counting from the most significant end starting at zero, of the length- binary representation of , including leading zeros. When , it is false. In particular, for it is false for every value and position.
QAlgorithms.Papers.Independent.Extend50.P44.checkerboard
For every natural number and every pair of real numbers , this defines a complex matrix whose entry at row and column , indexed from zero, is , embedded in . Thus entries with even equal , and entries with odd equal . No restrictions are placed on either real number. When , the matrix has one entry, equal to .
QAlgorithms.Papers.Independent.Extend50.P44.cleanBits
For any type , arbitrary encoding function , natural numbers , and , this defines a bit string of length . At position it equals , and at every remaining position it is false. Only the first values of the encoding are used. Both lengths may be zero: gives an all-false string, and gives the empty string.
QAlgorithms.Papers.Independent.Extend50.P44.cliffordTSet
This defines a set of gates consisting exactly of the one-qubit gates with matrices
and the two-qubit controlled-NOT gate whose matrix entry from to is one exactly when and , and zero otherwise. Each gate includes its specified arity; one-qubit matrix indices are identified with the sole bit of a one-bit string, and two-qubit indices with the ordered pair of bits.
QAlgorithms.Papers.Independent.Extend50.P44.dataRotation
For every real number , this defines the complex matrix indexed by the two Boolean values, in the order false, true, as
There is no assumption that ; the real square root is on negative inputs, so when this definition gives .
QAlgorithms.Papers.Independent.Extend50.P44.deleteCheckerCorners
For a natural number , let be the following data: the equality , where natural-number subtraction is truncated at zero; two bijections from labels , with and , to pairs of integers in ; a Boolean validity function ; nonempty column and row slot sets ; and unitary matrices of size . These data satisfy and whenever is true; two valid labels with the same column second coordinate and the same row second coordinate are equal; and the first columns of are respectively on and zero elsewhere, and on and zero elsewhere. This definition returns the same data with validity replaced by
All other data are retained, with the slot-membership and injectivity conditions restricted to the remaining valid labels. The required balance equality rules out .
QAlgorithms.Papers.Independent.Extend50.P44.deletedCheckerboard
For every natural number and pair of real numbers , this defines a complex matrix, indexed by integers , whose entries are
The real coefficients are regarded as complex numbers. The definition includes , when the two specified corners coincide and the resulting matrix is zero.
QAlgorithms.Papers.Independent.Extend50.P44.diffusion
For arbitrary natural numbers , any type with decidable equality, and any complex matrix indexed by , this defines a complex matrix indexed by , where , by
No unitarity assumption is imposed on , and need not be finite or nonempty. The cases and are included, giving singleton sets and , respectively.
QAlgorithms.Papers.Independent.Extend50.P44.doubleFlaggedPairBits
For all natural numbers , Booleans , integers satisfying and , and a natural number , this defines the Boolean at position of the sequence consisting of , the length- binary representation of , and the length- binary representation of . Both representations have leading zeros and are ordered most significant bit first. Positions zero and one return the respective flags, the next positions contain , the following positions contain , and all positions return false. Either binary block may be empty.
QAlgorithms.Papers.Independent.Extend50.P44.doubleLoadingSchedule
For every natural number , the double loading schedule is the two-entry list , including when .
QAlgorithms.Papers.Independent.Extend50.P44.entryArithmeticCost
For every natural number and every finite list of arithmetic gates on Boolean wires, each gate having a target wire and at most two distinct control wires, with the target excluded from the controls, the entry arithmetic cost is the number of gates with exactly two controls in the concatenated list consisting of followed by its reversal. Consequently, it equals twice the number of gates in with exactly two controls. Gates with zero or one control contribute zero. Empty lists are allowed and have cost zero; when , no gate can have a target, so the list must be empty.
QAlgorithms.Papers.Independent.Extend50.P44.entryCircuit
For arbitrary natural numbers , an arbitrary function from pairs with to optional pairs with , , and an arbitrary table assigning a -bit string to each , this defines a square complex matrix on basis labels , where has bits and has bits. Define to be all false when is absent, and otherwise to be a true flag followed by the most significant first -bit encoding of and -bit encoding of . Define to be all false if the flag of is false, and otherwise to be , where is the integer represented by the next bits; the final bits are ignored. Let have entry one exactly from to , and let have entry one exactly from that label to , with all other entries zero; means componentwise Boolean exclusive-or. The defined matrix is , so its entry is one exactly for the basis transformation
and zero otherwise. This definition applies to every initial scratch string , including nonzero strings, and permits zero-length numerical and value registers.
QAlgorithms.Papers.Independent.Extend50.P44.extendedTree
For every natural number , put , and let be arbitrary real numbers. This defines a complex matrix with indices :
Real coefficients are embedded in , and division is natural-number division. For , the matrix is .
QAlgorithms.Papers.Independent.Extend50.P44.flaggedPairBits
For all natural numbers , a Boolean , integers satisfying and , and a natural number , this defines the Boolean at position of the sequence consisting of , followed by the length- binary representation of , followed by the length- binary representation of . The binary representations use leading zeros and run from most significant to least significant bit. Position zero returns ; positions contain ; positions contain ; every position returns false. Zero widths contribute empty blocks.
QAlgorithms.Papers.Independent.Extend50.P44.idealLoader
For every natural number and every real table , let . This defines a complex matrix indexed by a Boolean flag and a table index:
Division is the total real division operation, so if the table is identically zero, and every ratio is zero; in that case each fixed-index flag block has zero diagonal and off-diagonal entries . The case has one table index and is included.
QAlgorithms.Papers.Independent.Extend50.P44.laplacian
For arbitrary natural numbers and arbitrary real numbers , put and . This defines a complex matrix. For each index , set and ; then
Coordinate differences inside absolute values are taken in the integers, and all displayed real entries are embedded in . There are no positivity or nonzero assumptions on ; a reciprocal-square term is zero when its denominator is zero. Either exponent may be zero, giving a coordinate with only one value; when both are zero, only the single diagonal entry remains.
QAlgorithms.Papers.Independent.Extend50.P44.laplacianTable
For arbitrary real numbers , this defines the four-entry real table
with entries indexed by , respectively. There are no positivity or nonzero assumptions on ; division by zero has value zero, so, for example, the entire table is zero when both are zero.
QAlgorithms.Papers.Independent.Extend50.P44.loaderEmbedding
For arbitrary natural numbers , this defines a rectangular complex matrix with rows indexed by Boolean strings of length and columns indexed by pairs , where is Boolean and . Split a row string into a first flag , a -bit address , a -bit string , and work bits. Then
where is the most significant first binary encoding of , and . Registers of length zero are permitted, and their bit conditions are vacuous; when , the displayed nonzero entry is one.
QAlgorithms.Papers.Independent.Extend50.P44.loaderTWord
For every natural number and every circuit that is a finite list of applications of , and controlled-NOT to injectively selected ordered wires among wires, this defines a list of letters of the same length and in the same order. An application is replaced by the letter exactly when its gate equals the one-qubit gate or ; every other application is replaced by the letter . Thus applications of the Hadamard gate, bit flip, and controlled-NOT all produce , independently of their wire placements. The empty circuit produces the empty list; is allowed.
QAlgorithms.Papers.Independent.Extend50.P44.loadingCost
For every finite list of natural numbers , its loading cost is the natural-number sum . The empty list has cost zero, and zero entries contribute zero.
QAlgorithms.Papers.Independent.Extend50.P44.matrixMax
For every natural number and real matrix , this defines
by taking each row’s maximum with initial value , and then taking the maximum of those results with initial value . In particular, the value is when .
QAlgorithms.Papers.Independent.Extend50.P44.paddedTable
For every natural number and every real table , this defines a table indexed by , with value when and zero otherwise. Here is the natural-number ceiling logarithm to base two; for , it is the least natural number with . The definition also includes , when the ceiling logarithm is zero and the resulting one-entry table is zero.
QAlgorithms.Papers.Independent.Extend50.P44.pairBits
For all natural numbers , a pair with and , and a natural number , this defines position of the concatenation of the length- binary representation of and the length- binary representation of , both written most significant bit first with leading zeros. Explicitly, it returns position of the first representation if , position of the second if , and false if . Either width may be zero, in which case that representation contributes no bits.
QAlgorithms.Papers.Independent.Extend50.P44.phaseGradient
For every natural number and every Boolean string , this defines the complex number
The sum interprets the bits in most significant first order. When , the string is empty, the sum is zero, and the value is one.
QAlgorithms.Papers.Independent.Extend50.P44.prepAlpha
For every natural number , real table , natural numbers , and real number , this defines
There is no restriction on . Empty sums are , and real division by zero is defined to be , so the result is when ; it is also if , , or every entry of is zero.
QAlgorithms.Papers.Independent.Extend50.P44.reverseCode
For every pair of natural numbers , every type , every function , and every , this defines a Boolean string of length . If is absent, every bit is false. If is present with value , the string is the concatenation of a true flag, the -bit most significant first binary encoding of , and the -bit most significant first binary encoding of . Either numerical register may have length zero; even when both do, a present value is distinguished from an absent value by the flag.
QAlgorithms.Papers.Independent.Extend50.P44.rowColumnLabelBits
For arbitrary natural numbers , a pair , a Boolean string of length , and a natural-number position , this Boolean-valued function returns position of the concatenation of the -bit binary representations of and , followed by , using most significant bit first and positions starting at zero. Explicitly, it returns bit of if , bit of if , and if ; it returns false when . The binary encoding reduces an integer modulo when encoding it in bits; here the two integers already lie within range, and encoding the integer represented by recovers . Zero lengths are allowed, so the corresponding segments may be empty.
QAlgorithms.Papers.Independent.Extend50.P44.runArithmetic
For every natural number , finite list of arithmetic gates on bits, and bit string , this defines the bit string obtained by applying the gates of to in list order. Each gate has a target bit and a set of at most two control bits, excluding the target; it toggles the target exactly when all its control bits are true and leaves every other bit unchanged. With no controls, the target is always toggled. The empty list returns . The definition includes , when no arithmetic gate can have a target and the only possible gate list is empty.
QAlgorithms.Papers.Independent.Extend50.P44.signOracle
For every natural number and every real table , this defines the complex diagonal matrix
In particular, a zero table entry receives diagonal value . The definition includes , when the matrix has one row and one column.
QAlgorithms.Papers.Independent.Extend50.P44.supportedPower
For arbitrary real numbers and , this defines
The exponent may be positive, zero, or negative; in particular, the value at is always , including when or .
QAlgorithms.Papers.Independent.Extend50.P44.tableMax
For every natural number and real table , this defines
Thus the value is the largest absolute table entry when , and is when .
QAlgorithms.Papers.Independent.Extend50.P44.tensorPreparation
For all natural numbers , every bijection , where , every complex matrix on , and every complex matrix on , this defines the complex matrix on by
Neither matrix is assumed unitary, and the bijection is not required to preserve zero. Zero values of any of the natural-number parameters are included; the existence of the supplied bijection requires .
QAlgorithms.Papers.Independent.Extend50.P44.toffoliCount
For every natural number and finite list of arithmetic gates on bits, this defines the natural number of occurrences in whose control set has cardinality exactly two. An arithmetic gate consists of a target bit and a set of at most two control bits that excludes the target. Gates with zero or one control contribute zero; repeated occurrences are counted separately. The empty list has count zero, including when .
QAlgorithms.Papers.Independent.Extend50.P44.treeTable
For any real table , this defines the four-entry real table : the value at an index is when , and zero when .
QAlgorithms.Papers.Independent.Extend50.P44.triTable
For every natural number and real table indexed by , this defines a real table indexed by , preserving the supplied entries and assigning zero to the one additional index:
For , the input has one entry and the output is .
QAlgorithms.Papers.Independent.Extend50.P44.tridiagonal
For every natural number , write , and let be arbitrary real numbers. This defines the complex matrix
The code obtains these coefficients from the table extended by a zero at index ; every coefficient used in the displayed cases is within the original table. Real coefficients are embedded in . The case gives the matrix .
QAlgorithms.Papers.Independent.Extend50.P44.valueAtLabel
For arbitrary natural numbers , a function , and a Boolean string of length , this defines a -bit string. If the first bit of is false, the result is the all-false string. If it is true, the next bits are interpreted as the index
and the result is . The final bits do not enter this value. When , the selected index is zero; when , the result is the unique empty string.
QAlgorithms.Papers.Independent.Extend50.P44.withFlags
For arbitrary types , with decidable equality on and , and any bijection , this defines a complex matrix with rows indexed by and columns indexed by , whose entries are
Thus it preserves the flag and applies to the other index. No finiteness or nonemptiness assumption is imposed on these types.
QAlgorithms.Papers.Independent.Extend50.P44.zeroEncoding
For every natural number , this defines a complex matrix whose rows and columns are indexed by , with entries
Thus its nonzero entries connect each Boolean value to its complement while preserving the second index. For , the index set is empty and this is the empty matrix.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.