Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Definitions for Block-encoding structured matrices for data input in quantum computing

Definition
QAlgorithms_Papers_Independent_Extend50_P44

by Gohan · Oct 29, 2026 · Mathlib 0df444a (Lean v4.33.1)

prove2quantum

The 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.
Definition code
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
Source
Block-encoding structured matrices for data input in quantum computing, arXiv:2302.10949v2, https://arxiv.org/abs/2302.10949v2
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 www, an arithmetic gate is data consisting of a target index t∈{0,…,w−1}t\in\{0,\ldots,w-1\}t∈{0,…,w−1} and a finite set of control indices C⊆{0,…,w−1}C\subseteq\{0,\ldots,w-1\}C⊆{0,…,w−1}, together with the requirements t∉Ct\notin Ct∈/C and ∣C∣≤2|C|\le2∣C∣≤2. The control set may be empty, have one element, or have two elements. For w=0w=0w=0, no such gate exists because there is no possible target index.

QAlgorithms.Papers.Independent.Extend50.P44.ArithmeticGate.run

For every natural number www, every arithmetic gate with target t∈{0,…,w−1}t\in\{0,\ldots,w-1\}t∈{0,…,w−1} and control set C⊆{0,…,w−1}C\subseteq\{0,\ldots,w-1\}C⊆{0,…,w−1} satisfying t∉Ct\notin Ct∈/C and ∣C∣≤2|C|\le2∣C∣≤2, and every Boolean string x:{0,…,w−1}→{false,true}x:\{0,\ldots,w-1\}\to\{\mathrm{false},\mathrm{true}\}x:{0,…,w−1}→{false,true}, this defines the output string yyy by

yi={xixor1{∀j∈C, xj=true},i=t,xi,i≠t,y_i= \begin{cases} x_i\mathbin{\mathrm{xor}}\mathbf1_{\{\forall j\in C,\ x_j=\mathrm{true}\}},&i=t,\\ x_i,&i\ne t, \end{cases}yi​={xi​xor1{∀j∈C, xj​=true}​,xi​,​i=t,i=t,​

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 w=0w=0w=0, there is no gate to supply as an argument.

QAlgorithms.Papers.Independent.Extend50.P44.CheckerLabels

For a natural number nnn and a scheme BBB with parameters (n,n,1,2n−1)(n,n,1,2n-1)(n,n,1,2n−1), where natural-number subtraction is truncated at zero, this predicate requires every label ℓ=(a,b)\ell=(a,b)ℓ=(a,b), with a∈{0,1}a\in\{0,1\}a∈{0,1} and 0≤b<22n−10\le b<2^{2n-1}0≤b<22n−1, to be valid, both slot sets to be the entire set {0,…,2n−1}\{0,\ldots,2^n-1\}{0,…,2n−1}, and the second coordinates of its row and column images to satisfy

(Brow(a,b))2=⌊b 2n/2 ⌋,(Bcolumn(a,b))2=2(b mod (2n/2))+(a+⌊b 2n/2 ⌋) mod 2.(B_{\mathrm{row}}(a,b))_2=\left\lfloor\frac{b}{\,2^n/2\,}\right\rfloor, \qquad (B_{\mathrm{column}}(a,b))_2 =2\bigl(b\bmod(2^n/2)\bigr) +\left(a+\left\lfloor\frac{b}{\,2^n/2\,}\right\rfloor\right)\bmod2.(Brow​(a,b))2​=⌊2n/2b​⌋,(Bcolumn​(a,b))2​=2(bmod(2n/2))+(a+⌊2n/2b​⌋)mod2.

Here 2n/22^n/22n/2 is natural-number division. Being a scheme additionally means that 1+(2n−1)=n+n1+(2n-1)=n+n1+(2n−1)=n+n; the row and column maps are bijections from the label set onto {0,…,2n−1}2\{0,\ldots,2^n-1\}^2{0,…,2n−1}2; 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 2n×2n2^n\times2^n2n×2n matrices Hc,HrH_c,H_rHc​,Hr​ 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 2−n/22^{-n/2}2−n/2. The displayed coordinate requirements impose no additional formula for the first coordinates. Although n=0n=0n=0 is syntactically included, no such scheme exists then, since its required bit balance would be 1=01=01=0.

QAlgorithms.Papers.Independent.Extend50.P44.LaplacianLabels

Let nx,nyn_x,n_ynx​,ny​ be arbitrary natural numbers, including zero, and put N=2nx+nyN=2^{n_x+n_y}N=2nx​+ny​ and h=2nxh=2^{n_x}h=2nx​. Write [r]={0,…,r−1}[r]=\{0,\ldots,r-1\}[r]={0,…,r−1}. The argument BBB is a scheme with label set [4]×[2N][4]\times[2N][4]×[2N], two bijections c,r:[4]×[2N]→[8]×[N]c,r:[4]\times[2N]\to[8]\times[N]c,r:[4]×[2N]→[8]×[N], a Boolean validity function vvv, nonempty column and row slot sets C,R⊆[8]C,R\subseteq[8]C,R⊆[8], and unitary matrices Hc,HrH_c,H_rHc​,Hr​ on C[8]\mathbb C^{[8]}C[8]. Its parameters satisfy 2+(nx+ny+1)=3+(nx+ny)2+(n_x+n_y+1)=3+(n_x+n_y)2+(nx​+ny​+1)=3+(nx​+ny​); every valid label has its column slot in CCC and row slot in RRR; two valid labels with the same column output coordinate and the same row output coordinate must be equal; and the zeroth columns of Hc,HrH_c,H_rHc​,Hr​ equal ∣C∣−1/2|C|^{-1/2}∣C∣−1/2 on CCC and ∣R∣−1/2|R|^{-1/2}∣R∣−1/2 on RRR, respectively, and zero elsewhere. This definition is the proposition that C={0,2,3,4,5}C=\{0,2,3,4,5\}C={0,2,3,4,5}, R=CR=CR=C, and every label (u,t)∈[4]×[2N](u,t)\in[4]\times[2N](u,t)∈[4]×[2N], including invalid labels, satisfies

v(u,t)=true⟺(u=0∧t<N) ∨ (u=1∧t mod h≠0) ∨ (u=2∧t mod N≥h),c(u,t)1=2u+⌊t/N⌋,\begin{aligned} v(u,t)=\mathrm{true}\quad&\Longleftrightarrow\quad (u=0\land t<N)\ \lor\ (u=1\land t\bmod h\ne0)\ \lor\ (u=2\land t\bmod N\ge h),\\ c(u,t)_1&=2u+\left\lfloor t/N\right\rfloor, \end{aligned}v(u,t)=truec(u,t)1​​⟺(u=0∧t<N) ∨ (u=1∧tmodh=0) ∨ (u=2∧tmodN≥h),=2u+⌊t/N⌋,​

and, whenever that label is valid, its column output coordinate satisfies the following equality in the integers:

c(u,t)2=(t mod N)−{1,t<N and u=1,h,t<N and u=2,0,otherwise.c(u,t)_2=(t\bmod N)- \begin{cases} 1,&t<N\text{ and }u=1,\\ h,&t<N\text{ and }u=2,\\ 0,&\text{otherwise}. \end{cases}c(u,t)2​=(tmodN)−⎩⎨⎧​1,h,0,​t<N and u=1,t<N and u=2,otherwise.​

There is no additional row-coordinate formula in this predicate. The powers used as divisors are always positive; when nx=0n_x=0nx​=0, the u=1u=1u=1 validity alternative never holds, and when ny=0n_y=0ny​=0, the u=2u=2u=2 alternative never holds.

QAlgorithms.Papers.Independent.Extend50.P44.PrepLayout.alpha

Let n,s,d,mn,s,d,mn,s,d,m be natural numbers and [r]={0,…,r−1}[r]=\{0,\ldots,r-1\}[r]={0,…,r−1}. The parameter BBB is scheme data consisting of d+m=s+nd+m=s+nd+m=s+n, bijections C,R:[2d]×[2m]→[2s]×[2n]C,R:[2^d]\times[2^m]\to[2^s]\times[2^n]C,R:[2d]×[2m]→[2s]×[2n], a Boolean validity function vvv, nonempty sets Jc,Jr⊆[2s]J_c,J_r\subseteq[2^s]Jc​,Jr​⊆[2s], and unitary matrices Hc,HrH_c,H_rHc​,Hr​ on [2s][2^s][2s]. Valid labels map into the corresponding slot sets; a valid label is determined by the pair (C(ℓ)2,R(ℓ)2)(C(\ell)_2,R(\ell)_2)(C(ℓ)2​,R(ℓ)2​); and the zeroth columns of Hc,HrH_c,H_rHc​,Hr​ are respectively uniform on Jc,JrJ_c,J_rJc​,Jr​ and zero elsewhere. The parameter LLL supplies a nonempty active set S⊆[2d]S\subseteq[2^d]S⊆[2d], natural numbers kc,krk_c,k_rkc​,kr​, zero-preserving bijections fc:[2s]→[2d]×[2kc]f_c:[2^s]\to[2^d]\times[2^{k_c}]fc​:[2s]→[2d]×[2kc​], fr:[2s]→[2d]×[2kr]f_r:[2^s]\to[2^d]\times[2^{k_r}]fr​:[2s]→[2d]×[2kr​], nonempty residual sets Tc,TrT_c,T_rTc​,Tr​, and unitary residual matrices Kc,KrK_c,K_rKc​,Kr​ with zeroth columns uniform on those sets and zero elsewhere; it requires Jc=fc−1(S×Tc)J_c=f_c^{-1}(S\times T_c)Jc​=fc−1​(S×Tc​), Jr=fr−1(S×Tr)J_r=f_r^{-1}(S\times T_r)Jr​=fr−1​(S×Tr​), and fc(C(ℓ)1)1=fr(R(ℓ)1)1=ℓ1f_c(C(\ell)_1)_1=f_r(R(\ell)_1)_1=\ell_1fc​(C(ℓ)1​)1​=fr​(R(ℓ)1​)1​=ℓ1​ for every label. For every real-valued table a:[2d]→Ra:[2^d]\to\mathbb Ra:[2d]→R and every real ppp, this defines

αL(a,p)=∣Jc∣ ∣Jr∣∣S∣(∑j∈Sr2p(aj))(∑j∈Sr2−2p(aj)),rt(x)={0,x=0,∣x∣t,x≠0.\alpha_L(a,p)= \frac{\sqrt{|J_c|\,|J_r|}}{|S|} \sqrt{ \left(\sum_{j\in S}r_{2p}(a_j)\right) \left(\sum_{j\in S}r_{2-2p}(a_j)\right) }, \qquad r_t(x)= \begin{cases} 0,&x=0,\\ |x|^t,&x\ne0. \end{cases}αL​(a,p)=∣S∣∣Jc​∣∣Jr​∣​​​j∈S∑​r2p​(aj​)​​j∈S∑​r2−2p​(aj​)​​,rt​(x)={0,∣x∣t,​x=0,x=0.​

There is no restriction on ppp, no nonvanishing requirement on aaa, and no requirement that aaa vanish outside SSS; entries outside SSS 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 n,s,d,mn,s,d,mn,s,d,m be natural numbers and [r]={0,…,r−1}[r]=\{0,\ldots,r-1\}[r]={0,…,r−1}. Let BBB supply d+m=s+nd+m=s+nd+m=s+n, bijections C,R:[2d]×[2m]→[2s]×[2n]C,R:[2^d]\times[2^m]\to[2^s]\times[2^n]C,R:[2d]×[2m]→[2s]×[2n], a Boolean validity function vvv, nonempty slot sets Jc,JrJ_c,J_rJc​,Jr​, and unitary matrices Hc,HrH_c,H_rHc​,Hr​ 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 (C(ℓ)2,R(ℓ)2)(C(\ell)_2,R(\ell)_2)(C(ℓ)2​,R(ℓ)2​). Let LLL supply a nonempty active set SSS, natural numbers kc,krk_c,k_rkc​,kr​, zero-preserving bijections fc:[2s]→[2d]×[2kc]f_c:[2^s]\to[2^d]\times[2^{k_c}]fc​:[2s]→[2d]×[2kc​], fr:[2s]→[2d]×[2kr]f_r:[2^s]\to[2^d]\times[2^{k_r}]fr​:[2s]→[2d]×[2kr​], nonempty residual sets Tc,TrT_c,T_rTc​,Tr​, and unitary matrices Kc,KrK_c,K_rKc​,Kr​ whose zeroth columns are uniform on those residual sets and zero elsewhere, with Jc=fc−1(S×Tc)J_c=f_c^{-1}(S\times T_c)Jc​=fc−1​(S×Tc​), Jr=fr−1(S×Tr)J_r=f_r^{-1}(S\times T_r)Jr​=fr−1​(S×Tr​), and fc(C(ℓ)1)1=fr(R(ℓ)1)1=ℓ1f_c(C(\ell)_1)_1=f_r(R(\ell)_1)_1=\ell_1fc​(C(ℓ)1​)1​=fr​(R(ℓ)1​)1​=ℓ1​ for every label. For any real table a:[2d]→Ra:[2^d]\to\mathbb Ra:[2d]→R, real ppp, and supplied preparation pair P,QP,QP,Q, the matrices P,QP,QP,Q are unitary and have zeroth column and zeroth row, respectively, equal on SSS to

Pj,0=sign⁡(aj)rp(aj)∑h∈Sr2p(ah),Q0,j=r1−p(aj)∑h∈Sr2−2p(ah),P_{j,0}=\frac{\operatorname{sign}(a_j)r_p(a_j)} {\sqrt{\sum_{h\in S}r_{2p}(a_h)}}, \qquad Q_{0,j}=\frac{r_{1-p}(a_j)} {\sqrt{\sum_{h\in S}r_{2-2p}(a_h)}},Pj,0​=∑h∈S​r2p​(ah​)​sign(aj​)rp​(aj​)​,Q0,j​=∑h∈S​r2−2p​(ah​)​r1−p​(aj​)​,

and zero outside SSS, where rt(0)=0r_t(0)=0rt​(0)=0 and rt(x)=∣x∣tr_t(x)=|x|^trt​(x)=∣x∣t otherwise. Define Tf(A,H)x,y=Af(x)1,f(y)1Hf(x)2,f(y)2T_f(A,H)_{x,y}=A_{f(x)_1,f(y)_1}H_{f(x)_2,f(y)_2}Tf​(A,H)x,y​=Af(x)1​,f(y)1​​Hf(x)2​,f(y)2​​; define D(H)(b,(t,i)),(c,(u,j))=1b=c1i=jHt,uD(H)_{(b,(t,i)),(c,(u,j))}=\mathbf1_{b=c}\mathbf1_{i=j}H_{t,u}D(H)(b,(t,i)),(c,(u,j))​=1b=c​1i=j​Ht,u​; and, for e=C,Re=C,Re=C,R, define (We)(b,y),(c,ℓ)=1b=c1y=e(ℓ)(W_e)_{(b,y),(c,\ell)}=\mathbf1_{b=c}\mathbf1_{y=e(\ell)}(We​)(b,y),(c,ℓ)​=1b=c​1y=e(ℓ)​. On Boolean-flagged labels define

G(b,ℓ),(c,h)={1,ℓ=h and b={c,v(h)=true,¬c,v(h)=false,0,otherwise.G_{(b,\ell),(c,h)} = \begin{cases} 1,&\ell=h\ \text{and }b= \begin{cases}c,&v(h)=\mathrm{true},\\ \neg c,&v(h)=\mathrm{false},\end{cases}\\ 0,&\text{otherwise}. \end{cases}G(b,ℓ),(c,h)​=⎩⎨⎧​1,0,​ℓ=h and b={c,¬c,​v(h)=true,v(h)=false,​otherwise.​

The declaration defines a matrix C\mathcal CC indexed by ({false,true}×[2s])×[2n](\{\mathrm{false},\mathrm{true}\}\times[2^s])\times[2^n]({false,true}×[2s])×[2n] by reassociating the indices of

V=D ⁣(Tfr(Q,Kr†))WR G WC†D ⁣(Tfc(P,Kc)),C((b,t),i),((c,u),j)=V(b,(t,i)),(c,(u,j)).V=D\!\left(T_{f_r}(Q,K_r^\dagger)\right) W_R\,G\,W_C^\dagger D\!\left(T_{f_c}(P,K_c)\right), \qquad \mathcal C_{((b,t),i),((c,u),j)} =V_{(b,(t,i)),(c,(u,j))}.V=D(Tfr​​(Q,Kr†​))WR​GWC†​D(Tfc​​(P,Kc​)),C((b,t),i),((c,u),j)​=V(b,(t,i)),(c,(u,j))​.

Here †\dagger† 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 n,s,d,mn,s,d,mn,s,d,m be natural numbers, write [r]={0,…,r−1}[r]=\{0,\ldots,r-1\}[r]={0,…,r−1}, and let BBB consist of the following scheme data: d+m=s+nd+m=s+nd+m=s+n; bijections C,R:[2d]×[2m]→[2s]×[2n]C,R:[2^d]\times[2^m]\to[2^s]\times[2^n]C,R:[2d]×[2m]→[2s]×[2n]; a Boolean function vvv on their domain; nonempty sets Jc,Jr⊆[2s]J_c,J_r\subseteq[2^s]Jc​,Jr​⊆[2s]; and unitary matrices Hc,HrH_c,H_rHc​,Hr​ on [2s][2^s][2s]. These data satisfy v(ℓ)=true⇒C(ℓ)1∈Jcv(\ell)=\mathrm{true}\Rightarrow C(\ell)_1\in J_cv(ℓ)=true⇒C(ℓ)1​∈Jc​ and R(ℓ)1∈JrR(\ell)_1\in J_rR(ℓ)1​∈Jr​; any two valid labels having both the same second component under CCC and the same second component under RRR are equal; and (Hc)t,0=∣Jc∣−1/2(H_c)_{t,0}=|J_c|^{-1/2}(Hc​)t,0​=∣Jc​∣−1/2 for t∈Jct\in J_ct∈Jc​, zero otherwise, with the analogous requirement for Hr,JrH_r,J_rHr​,Jr​. A preparation layout for BBB is additional data comprising a nonempty set S⊆[2d]S\subseteq[2^d]S⊆[2d], natural numbers kc,krk_c,k_rkc​,kr​, bijections

fc:[2s]⟶[2d]×[2kc],fr:[2s]⟶[2d]×[2kr],f_c:[2^s]\longrightarrow[2^d]\times[2^{k_c}], \qquad f_r:[2^s]\longrightarrow[2^d]\times[2^{k_r}],fc​:[2s]⟶[2d]×[2kc​],fr​:[2s]⟶[2d]×[2kr​],

nonempty sets Tc⊆[2kc]T_c\subseteq[2^{k_c}]Tc​⊆[2kc​], Tr⊆[2kr]T_r\subseteq[2^{k_r}]Tr​⊆[2kr​], and unitary matrices Kc,KrK_c,K_rKc​,Kr​ on these respective residual index spaces. They must satisfy fc(0)=fr(0)=(0,0)f_c(0)=f_r(0)=(0,0)fc​(0)=fr​(0)=(0,0),

t∈Jc  ⟺  fc(t)1∈S and fc(t)2∈Tc,t∈Jr  ⟺  fr(t)1∈S and fr(t)2∈Tr,fc(C(ℓ)1)1=ℓ1,fr(R(ℓ)1)1=ℓ1\begin{aligned} t\in J_c&\iff f_c(t)_1\in S\ \text{and }f_c(t)_2\in T_c,\\ t\in J_r&\iff f_r(t)_1\in S\ \text{and }f_r(t)_2\in T_r,\\ f_c(C(\ell)_1)_1&=\ell_1,\qquad f_r(R(\ell)_1)_1=\ell_1 \end{aligned}t∈Jc​t∈Jr​fc​(C(ℓ)1​)1​​⟺fc​(t)1​∈S and fc​(t)2​∈Tc​,⟺fr​(t)1​∈S and fr​(t)2​∈Tr​,=ℓ1​,fr​(R(ℓ)1​)1​=ℓ1​​

for every ttt and every label ℓ\ellℓ, including invalid labels. Finally, (Kc)t,0=∣Tc∣−1/2(K_c)_{t,0}=|T_c|^{-1/2}(Kc​)t,0​=∣Tc​∣−1/2 on TcT_cTc​ and zero elsewhere, and (Kr)t,0=∣Tr∣−1/2(K_r)_{t,0}=|T_r|^{-1/2}(Kr​)t,0​=∣Tr​∣−1/2 on TrT_rTr​ and zero elsewhere. None of n,s,d,m,kc,krn,s,d,m,k_c,k_rn,s,d,m,kc​,kr​ is required to be positive; their powers of two are always positive.

QAlgorithms.Papers.Independent.Extend50.P44.PrepLayout.noDeleteCircuit

Let n,s,d,mn,s,d,mn,s,d,m be arbitrary natural numbers, write [r]={0,…,r−1}[r]=\{0,\ldots,r-1\}[r]={0,…,r−1}, and set N=2nN=2^nN=2n, S=2sS=2^sS=2s, D=2dD=2^dD=2d, M=2mM=2^mM=2m. The implicit argument BBB consists of the equality d+m=s+nd+m=s+nd+m=s+n, column and row bijections c,r:[D]×[M]→[S]×[N]c,r:[D]\times[M]\to[S]\times[N]c,r:[D]×[M]→[S]×[N], a Boolean validity function vvv, nonempty slot sets C,R⊆[S]C,R\subseteq[S]C,R⊆[S], and unitary slot matrices Hc,HrH_c,H_rHc​,Hr​. 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 Hc,HrH_c,H_rHc​,Hr​ are the normalized indicators of C,RC,RC,R. The layout LLL supplies a nonempty active set A⊆[D]A\subseteq[D]A⊆[D], natural numbers kc,krk_c,k_rkc​,kr​, bijections fc:[S]→[D]×[2kc]f_c:[S]\to[D]\times[2^{k_c}]fc​:[S]→[D]×[2kc​] and fr:[S]→[D]×[2kr]f_r:[S]\to[D]\times[2^{k_r}]fr​:[S]→[D]×[2kr​] sending 000 to (0,0)(0,0)(0,0), and nonempty residual sets C0,R0C_0,R_0C0​,R0​, such that membership in C,RC,RC,R is respectively equivalent to the first factor belonging to AAA and the second belonging to C0,R0C_0,R_0C0​,R0​. Moreover, the first factor of fc(c(ℓ)1)f_c(c(\ell)_1)fc​(c(ℓ)1​) and of fr(r(ℓ)1)f_r(r(\ell)_1)fr​(r(ℓ)1​) equals the data index ℓ1\ell_1ℓ1​ for every label ℓ\ellℓ. The layout also supplies unitary matrices Kc,KrK_c,K_rKc​,Kr​ whose zeroth columns are the normalized indicators of C0,R0C_0,R_0C0​,R0​. For arbitrary real data a:[D]→Ra:[D]\to\mathbb Ra:[D]→R and arbitrary real ppp, put w(x,t)=0w(x,t)=0w(x,t)=0 if x=0x=0x=0, and w(x,t)=∣x∣tw(x,t)=|x|^tw(x,t)=∣x∣t otherwise. The argument PPP supplies two unitary matrices Pc,PrP_c,P_rPc​,Pr​ on C[D]\mathbb C^{[D]}C[D], with

(Pc)j0={sign⁡(aj)w(aj,p)∑k∈Aw(ak,2p),j∈A,0,j∉A,(Pr)0j={w(aj,1−p)∑k∈Aw(ak,2−2p),j∈A,0,j∉A.(P_c)_{j0}= \begin{cases} \dfrac{\operatorname{sign}(a_j)w(a_j,p)} {\sqrt{\sum_{k\in A}w(a_k,2p)}},&j\in A,\\ 0,&j\notin A, \end{cases} \qquad (P_r)_{0j}= \begin{cases} \dfrac{w(a_j,1-p)} {\sqrt{\sum_{k\in A}w(a_k,2-2p)}},&j\in A,\\ 0,&j\notin A. \end{cases}(Pc​)j0​=⎩⎨⎧​∑k∈A​w(ak​,2p)​sign(aj​)w(aj​,p)​,0,​j∈A,j∈/A,​(Pr​)0j​=⎩⎨⎧​∑k∈A​w(ak​,2−2p)​w(aj​,1−p)​,0,​j∈A,j∈/A.​

To describe the defined matrix, reindex Pc⊗KcP_c\otimes K_cPc​⊗Kc​ through fcf_cfc​ to obtain a slot matrix FcF_cFc​, and reindex Pr⊗Kr†P_r\otimes K_r^\daggerPr​⊗Kr†​ through frf_rfr​ to obtain FrF_rFr​. On registers consisting of a Boolean flag, a slot, and an output index, apply FcF_cFc​ to the slot, apply c−1c^{-1}c−1 to replace the slot/output pair by its label, flip the flag exactly when that label is invalid, apply rrr to replace the label by its row slot/output pair, and apply FrF_rFr​ to the slot. If UUU is the resulting matrix, this definition returns the matrix indexed by [S]×[N][S]\times[N][S]×[N] whose (x,y)(x,y)(x,y)-entry is

U(false,x1,x2),(false,y1,y2).U_{(\mathrm{false},x_1,x_2),(\mathrm{false},y_1,y_2)}.U(false,x1​,x2​),(false,y1​,y2​)​.

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 ppp are included. Reciprocals at zero are zero; if all active data vanish, the required zeroth column of PcP_cPc​ is zero, so no such unitary preparation pair exists.

QAlgorithms.Papers.Independent.Extend50.P44.PreparationPair

Let n,s,d,mn,s,d,mn,s,d,m be natural numbers and [r]={0,…,r−1}[r]=\{0,\ldots,r-1\}[r]={0,…,r−1}. Let BBB contain d+m=s+nd+m=s+nd+m=s+n, bijections C,R:[2d]×[2m]→[2s]×[2n]C,R:[2^d]\times[2^m]\to[2^s]\times[2^n]C,R:[2d]×[2m]→[2s]×[2n], Boolean validity data vvv, nonempty slot sets Jc,JrJ_c,J_rJc​,Jr​, and unitary matrices Hc,HrH_c,H_rHc​,Hr​ whose zeroth columns are uniform on the corresponding slot sets and zero elsewhere; valid labels map into those sets and are uniquely determined by (C(ℓ)2,R(ℓ)2)(C(\ell)_2,R(\ell)_2)(C(ℓ)2​,R(ℓ)2​). Let LLL contain a nonempty active set S⊆[2d]S\subseteq[2^d]S⊆[2d], natural numbers kc,krk_c,k_rkc​,kr​, bijections fc,frf_c,f_rfc​,fr​ from [2s][2^s][2s] onto [2d]×[2kc][2^d]\times[2^{k_c}][2d]×[2kc​] and [2d]×[2kr][2^d]\times[2^{k_r}][2d]×[2kr​], respectively, both sending zero to (0,0)(0,0)(0,0), nonempty residual sets Tc,TrT_c,T_rTc​,Tr​, and unitary residual matrices Kc,KrK_c,K_rKc​,Kr​ with zeroth columns uniform on those sets. Its requirements are Jc=fc−1(S×Tc)J_c=f_c^{-1}(S\times T_c)Jc​=fc−1​(S×Tc​), Jr=fr−1(S×Tr)J_r=f_r^{-1}(S\times T_r)Jr​=fr−1​(S×Tr​), and fc(C(ℓ)1)1=fr(R(ℓ)1)1=ℓ1f_c(C(\ell)_1)_1=f_r(R(\ell)_1)_1=\ell_1fc​(C(ℓ)1​)1​=fr​(R(ℓ)1​)1​=ℓ1​ for every label. For an arbitrary real table a:[2d]→Ra:[2^d]\to\mathbb Ra:[2d]→R and arbitrary real ppp, a preparation pair is a pair of unitary complex matrices P,QP,QP,Q on [2d][2^d][2d] satisfying

Pj,0={sign⁡(aj) rp(aj)∑k∈Sr2p(ak),j∈S,0,j∉S,Q0,j={r1−p(aj)∑k∈Sr2−2p(ak),j∈S,0,j∉S,P_{j,0}= \begin{cases} \displaystyle\frac{\operatorname{sign}(a_j)\,r_p(a_j)} {\sqrt{\sum_{k\in S}r_{2p}(a_k)}},&j\in S,\\ 0,&j\notin S, \end{cases} \qquad Q_{0,j}= \begin{cases} \displaystyle\frac{r_{1-p}(a_j)} {\sqrt{\sum_{k\in S}r_{2-2p}(a_k)}},&j\in S,\\ 0,&j\notin S, \end{cases}Pj,0​=⎩⎨⎧​∑k∈S​r2p​(ak​)​sign(aj​)rp​(aj​)​,0,​j∈S,j∈/S,​Q0,j​=⎩⎨⎧​∑k∈S​r2−2p​(ak​)​r1−p​(aj​)​,0,​j∈S,j∈/S,​

where rt(0)=0r_t(0)=0rt​(0)=0 and rt(x)=∣x∣tr_t(x)=|x|^trt​(x)=∣x∣t for x≠0x\ne0x=0, and all displayed real entries are regarded as complex numbers. The prescribed part of PPP is its zeroth column, whereas the prescribed part of QQQ 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 PPP, 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 X,YX,YX,Y, encoding functions input:X→N→{false,true}\mathrm{input}:X\to\mathbb N\to\{\mathrm{false},\mathrm{true}\}input:X→N→{false,true} and output:Y→N→{false,true}\mathrm{output}:Y\to\mathbb N\to\{\mathrm{false},\mathrm{true}\}output:Y→N→{false,true}, a function f:X→Yf:X\to Yf:X→Y, natural numbers w,workw,\mathrm{work}w,work, and a finite list ccc of arithmetic gates on w+workw+\mathrm{work}w+work bits, this predicate means that for every x∈Xx\in Xx∈X, applying ccc in list order to the string whose first www bits are input(x,0),…,input(x,w−1)\mathrm{input}(x,0),\ldots,\mathrm{input}(x,w-1)input(x,0),…,input(x,w−1) and whose final work\mathrm{work}work bits are false produces exactly the string whose first www bits encode f(x)f(x)f(x) using output\mathrm{output}output and whose final work\mathrm{work}work 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 XXX is empty.

QAlgorithms.Papers.Independent.Extend50.P44.Scheme.ArithmeticCost

For natural numbers n,s,d,mn,s,d,mn,s,d,m, a scheme BBB, a real number bound\mathrm{bound}bound, and a natural number work\mathrm{work}work, this predicate asserts the existence of three finite arithmetic-gate lists c,r,gc,r,gc,r,g on 2+d+m+work2+d+m+\mathrm{work}2+d+m+work bits with the following exact actions. Here the scheme includes d+m=s+nd+m=s+nd+m=s+n; bijections Bcolumn,Brow:{0,…,2d−1}×{0,…,2m−1}→{0,…,2s−1}×{0,…,2n−1}B_{\mathrm{column}},B_{\mathrm{row}}:\{0,\ldots,2^d-1\}\times\{0,\ldots,2^m-1\}\to\{0,\ldots,2^s-1\}\times\{0,\ldots,2^n-1\}Bcolumn​,Brow​:{0,…,2d−1}×{0,…,2m−1}→{0,…,2s−1}×{0,…,2n−1}; a Boolean validity function; nonempty column and row slot sets in {0,…,2s−1}\{0,\ldots,2^s-1\}{0,…,2s−1} 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 2s×2s2^s\times2^s2s×2s matrices Hc,HrH_c,H_rHc​,Hr​, 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 work\mathrm{work}work false bits. For every pair of flags and every label ℓ\ellℓ, the list ccc maps this encoding to that of the same flags and Bcolumn(ℓ)B_{\mathrm{column}}(\ell)Bcolumn​(ℓ), using output widths s,ns,ns,n; the list rrr does the same with Brow(ℓ)B_{\mathrm{row}}(\ell)Brow​(ℓ); and ggg retains ℓ\ellℓ and the first flag, retaining the second flag when ℓ\ellℓ 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 c,r,gc,r,gc,r,g, regarded as a real number, must be at most bound\mathrm{bound}bound. 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 n,s,d,mn,s,d,mn,s,d,m, a scheme BBB, a real number bound\mathrm{bound}bound, and a natural number work\mathrm{work}work, this predicate asserts the existence of three finite arithmetic-gate lists c,r,gc,r,gc,r,g on 2+d+m+work2+d+m+\mathrm{work}2+d+m+work bits whose combined lengths are at most bound\mathrm{bound}bound, after converting the lengths to real numbers. The scheme includes d+m=s+nd+m=s+nd+m=s+n; column and row bijections from pairs of integers of widths d,md,md,m to pairs of widths s,ns,ns,n; 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 2s×2s2^s\times2^s2s×2s matrices Hc,HrH_c,H_rHc​,Hr​, with their columns indexed by zero equal to the respective slot indicators divided by the square roots of the slot cardinalities. For every label ℓ\ellℓ and both possible values of each of two flags, encode the flags first, then ℓ\ellℓ's components in fixed-width binary, most significant bit first, and append work\mathrm{work}work false bits. Applying ccc in list order must produce the same flags and the column-bijection image of ℓ\ellℓ, encoded with widths s,ns,ns,n; applying rrr must instead produce its row-bijection image; and applying ggg 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 n,s,d,mn,s,d,mn,s,d,m, let BBB contain d+m=s+nd+m=s+nd+m=s+n, bijections C,R:L→T×JC,R:L\to T\times JC,R:L→T×J, a Boolean validity function vvv, nonempty subsets Sc,Sr⊆TS_c,S_r\subseteq TSc​,Sr​⊆T, and complex unitary matrices Hc,HrH_c,H_rHc​,Hr​, where L={0,…,2d−1}×{0,…,2m−1}L=\{0,\ldots,2^d-1\}\times\{0,\ldots,2^m-1\}L={0,…,2d−1}×{0,…,2m−1}, T={0,…,2s−1}T=\{0,\ldots,2^s-1\}T={0,…,2s−1}, and J={0,…,2n−1}J=\{0,\ldots,2^n-1\}J={0,…,2n−1}. Valid labels must map into the specified subsets in their first coordinates and be uniquely determined by their two second coordinates; Hc,HrH_c,H_rHc​,Hr​ have first columns equal to ∣Sc∣−1/2,∣Sr∣−1/2|S_c|^{-1/2},|S_r|^{-1/2}∣Sc​∣−1/2,∣Sr​∣−1/2 on those subsets and zero elsewhere. For any real table a:{0,…,2d−1}→Ra:\{0,\ldots,2^d-1\}\to\mathbb Ra:{0,…,2d−1}→R, this defines

αbase(B,a)=∣Sc∣ ∣Sr∣max⁡({0}∪{∣aj∣:0≤j<2d}).\alpha_{\mathrm{base}}(B,a)= \sqrt{|S_c|\,|S_r|} \max\bigl(\{0\}\cup\{|a_j|:0\le j<2^d\}\bigr).αbase​(B,a)=∣Sc​∣∣Sr​∣​max({0}∪{∣aj​∣:0≤j<2d}).

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 n,s,d,mn,s,d,mn,s,d,m, let BBB consist of d+m=s+nd+m=s+nd+m=s+n, bijections C,R:L→T×JC,R:L\to T\times JC,R:L→T×J, a Boolean validity function vvv, nonempty subsets Sc,Sr⊆TS_c,S_r\subseteq TSc​,Sr​⊆T, and complex unitary matrices Hc,HrH_c,H_rHc​,Hr​, where L={0,…,2d−1}×{0,…,2m−1}L=\{0,\ldots,2^d-1\}\times\{0,\ldots,2^m-1\}L={0,…,2d−1}×{0,…,2m−1}, T={0,…,2s−1}T=\{0,\ldots,2^s-1\}T={0,…,2s−1}, and J={0,…,2n−1}J=\{0,\ldots,2^n-1\}J={0,…,2n−1}; valid labels have first coordinates in the corresponding subsets and are uniquely determined by their pair of second coordinates, and the first columns of Hc,HrH_c,H_rHc​,Hr​ are uniform with amplitudes ∣Sc∣−1/2,∣Sr∣−1/2|S_c|^{-1/2},|S_r|^{-1/2}∣Sc​∣−1/2,∣Sr​∣−1/2 on those subsets and zero elsewhere. Given a real table a:{0,…,2d−1}→Ra:\{0,\ldots,2^d-1\}\to\mathbb Ra:{0,…,2d−1}→R and a Boolean parameter hhh, defaulting to false, let M=max⁡({0}∪{∣aj∣:j<2d})M=\max(\{0\}\cup\{|a_j|:j<2^d\})M=max({0}∪{∣aj​∣:j<2d}), define We(f,y),(g,ℓ)=1W_e{}_{(f,y),(g,\ell)}=1We​(f,y),(g,ℓ)​=1 exactly when f=gf=gf=g and y=e(ℓ)y=e(\ell)y=e(ℓ), and zero otherwise, for e=C,Re=C,Re=C,R and two-bit flags f,gf,gf,g; define D(H)(f,(t,i)),(g,(u,j))=HtuD(H)_{(f,(t,i)),(g,(u,j))}=H_{tu}D(H)(f,(t,i)),(g,(u,j))​=Htu​ when f=gf=gf=g and i=ji=ji=j, and zero otherwise; and define K((b,f),ℓ),((c,g),k)K_{((b,f),\ell),((c,g),k)}K((b,f),ℓ),((c,g),k)​ to be zero unless ℓ=k\ell=kℓ=k and f=gf=gf=g for valid kkk, or f=¬gf=\neg gf=¬g for invalid kkk, in which case it equals R(ak1/M)bcR(a_{k_1}/M)_{bc}R(ak1​​/M)bc​ multiplied by −1-1−1 if hhh and ccc are both true and by 111 otherwise, where R(q)R(q)R(q) has diagonal qqq and off-diagonal −i1−q2-\mathrm i\sqrt{1-q^2}−i1−q2​. This defines

V=D(Hr)†WRKWC†D(Hc),U((f,t),i),((g,u),j)=V(f,(t,i)),(g,(u,j)),V=D(H_r)^\dagger W_R K W_C^\dagger D(H_c), \qquad U_{((f,t),i),((g,u),j)} =V_{(f,(t,i)),(g,(u,j))},V=D(Hr​)†WR​KWC†​D(Hc​),U((f,t),i),((g,u),j)​=V(f,(t,i)),(g,(u,j))​,

where †\dagger† 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 0/0=00/0=00/0=0.

QAlgorithms.Papers.Independent.Extend50.P44.Scheme.baseMiddle

For natural numbers n,s,d,mn,s,d,mn,s,d,m, let BBB contain d+m=s+nd+m=s+nd+m=s+n, bijections C,R:L→T×JC,R:L\to T\times JC,R:L→T×J, a Boolean validity function vvv, nonempty subsets Sc,Sr⊆TS_c,S_r\subseteq TSc​,Sr​⊆T, and unitary matrices Hc,HrH_c,H_rHc​,Hr​, where L={0,…,2d−1}×{0,…,2m−1}L=\{0,\ldots,2^d-1\}\times\{0,\ldots,2^m-1\}L={0,…,2d−1}×{0,…,2m−1}, T={0,…,2s−1}T=\{0,\ldots,2^s-1\}T={0,…,2s−1}, and J={0,…,2n−1}J=\{0,\ldots,2^n-1\}J={0,…,2n−1}; 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 ∣Sc∣−1/2,∣Sr∣−1/2|S_c|^{-1/2},|S_r|^{-1/2}∣Sc​∣−1/2,∣Sr​∣−1/2 on those subsets and zero elsewhere. Given a real table a:{0,…,2d−1}→Ra:\{0,\ldots,2^d-1\}\to\mathbb Ra:{0,…,2d−1}→R and a Boolean parameter hhh, put M=max⁡({0}∪{∣aj∣:j<2d})M=\max(\{0\}\cup\{|a_j|:j<2^d\})M=max({0}∪{∣aj​∣:j<2d}). This defines a complex matrix on pairs of Boolean flags and a label by

K((b,f),ℓ),((c,g),k)={R(ak1/M)bc εh(c),ℓ=k,f={g,v(k)=true,¬g,v(k)=false,0,otherwise,K_{((b,f),\ell),((c,g),k)}= \begin{cases} R(a_{k_1}/M)_{bc}\,\varepsilon_h(c), &\ell=k,\quad f= \begin{cases}g,&v(k)=\mathrm{true},\\\neg g,&v(k)=\mathrm{false},\end{cases}\\ 0,&\text{otherwise}, \end{cases}K((b,f),ℓ),((c,g),k)​=⎩⎨⎧​R(ak1​​/M)bc​εh​(c),0,​ℓ=k,f={g,¬g,​v(k)=true,v(k)=false,​otherwise,​

where εh(c)=−1\varepsilon_h(c)=-1εh​(c)=−1 if both hhh and ccc are true and is 111 otherwise, and R(q)R(q)R(q) has diagonal entries qqq and off-diagonal entries −i1−q2-\mathrm i\sqrt{1-q^2}−i1−q2​. The parameter hhh imposes no additional hypothesis. If aaa is identically zero, then M=0M=0M=0 and every quotient aj/Ma_j/Maj​/M is defined as zero, so the corresponding first-flag matrix has zero diagonal and off-diagonal entries −i-\mathrm i−i. All natural parameters may be zero.

QAlgorithms.Papers.Independent.Extend50.P44.Scheme.matrix

For natural numbers n,s,d,mn,s,d,mn,s,d,m, let BBB consist of d+m=s+nd+m=s+nd+m=s+n, bijections C,R:L→T×JC,R:L\to T\times JC,R:L→T×J, a Boolean validity function vvv, nonempty subsets Sc,Sr⊆TS_c,S_r\subseteq TSc​,Sr​⊆T, and unitary matrices Hc,HrH_c,H_rHc​,Hr​, where L={0,…,2d−1}×{0,…,2m−1}L=\{0,\ldots,2^d-1\}\times\{0,\ldots,2^m-1\}L={0,…,2d−1}×{0,…,2m−1}, T={0,…,2s−1}T=\{0,\ldots,2^s-1\}T={0,…,2s−1}, and J={0,…,2n−1}J=\{0,\ldots,2^n-1\}J={0,…,2n−1}; valid labels have their first CCC- and RRR-coordinates in Sc,SrS_c,S_rSc​,Sr​, respectively, and their pair of second coordinates uniquely determines the label; the first columns of Hc,HrH_c,H_rHc​,Hr​ are respectively ∣Sc∣−1/2|S_c|^{-1/2}∣Sc​∣−1/2 on ScS_cSc​ and ∣Sr∣−1/2|S_r|^{-1/2}∣Sr​∣−1/2 on SrS_rSr​, and zero elsewhere. For every real table a:{0,…,2d−1}→Ra:\{0,\ldots,2^d-1\}\to\mathbb Ra:{0,…,2d−1}→R, this defines the complex matrix

Aij=∑ℓ∈Lv(ℓ)=trueR(ℓ)2=i, C(ℓ)2=jaℓ1(i,j∈J).A_{ij}=\sum_{\substack{\ell\in L\\v(\ell)=\mathrm{true}\\R(\ell)_2=i,\ C(\ell)_2=j}}a_{\ell_1} \qquad(i,j\in J).Aij​=ℓ∈Lv(ℓ)=trueR(ℓ)2​=i, C(ℓ)2​=j​∑​aℓ1​​(i,j∈J).

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 n,s,d,mn,s,d,mn,s,d,m, this structure consists of a proof that d+m=s+nd+m=s+nd+m=s+n; two bijections C,R:L→T×JC,R:L\to T\times JC,R:L→T×J, where L={0,…,2d−1}×{0,…,2m−1}L=\{0,\ldots,2^d-1\}\times\{0,\ldots,2^m-1\}L={0,…,2d−1}×{0,…,2m−1}, T={0,…,2s−1}T=\{0,\ldots,2^s-1\}T={0,…,2s−1}, and J={0,…,2n−1}J=\{0,\ldots,2^n-1\}J={0,…,2n−1}; a Boolean function v:L→{false,true}v:L\to\{\mathrm{false},\mathrm{true}\}v:L→{false,true}; nonempty finite subsets Sc,Sr⊆TS_c,S_r\subseteq TSc​,Sr​⊆T; and two complex unitary matrices Hc,HrH_c,H_rHc​,Hr​ indexed by TTT. These data must satisfy, for every ℓ∈L\ell\in Lℓ∈L, v(ℓ)=true⇒C(ℓ)1∈Scv(\ell)=\mathrm{true}\Rightarrow C(\ell)_1\in S_cv(ℓ)=true⇒C(ℓ)1​∈Sc​ and v(ℓ)=true⇒R(ℓ)1∈Srv(\ell)=\mathrm{true}\Rightarrow R(\ell)_1\in S_rv(ℓ)=true⇒R(ℓ)1​∈Sr​; for every valid pair ℓ,k\ell,kℓ,k, equality of both C(ℓ)2=C(k)2C(\ell)_2=C(k)_2C(ℓ)2​=C(k)2​ and R(ℓ)2=R(k)2R(\ell)_2=R(k)_2R(ℓ)2​=R(k)2​ must imply ℓ=k\ell=kℓ=k; and for every t∈Tt\in Tt∈T,

(Hc)t0={∣Sc∣−1/2,t∈Sc,0,t∉Sc,(Hr)t0={∣Sr∣−1/2,t∈Sr,0,t∉Sr.(H_c)_{t0}= \begin{cases}|S_c|^{-1/2},&t\in S_c,\\0,&t\notin S_c,\end{cases} \qquad (H_r)_{t0}= \begin{cases}|S_r|^{-1/2},&t\in S_r,\\0,&t\notin S_r.\end{cases}(Hc​)t0​={∣Sc​∣−1/2,0,​t∈Sc​,t∈/Sc​,​(Hr​)t0​={∣Sr​∣−1/2,0,​t∈Sr​,t∈/Sr​.​

All four natural parameters may be zero, with 20=12^0=120=1. No label is required to be valid, so vvv may be identically false.

QAlgorithms.Papers.Independent.Extend50.P44.Scheme.simpleCircuit

For natural numbers n,s,d,mn,s,d,mn,s,d,m, write Jt={0,…,2t−1}J_t=\{0,\ldots,2^t-1\}Jt​={0,…,2t−1} and L=Jd×JmL=J_d\times J_mL=Jd​×Jm​. A scheme BBB supplies d+m=s+nd+m=s+nd+m=s+n, bijections C,R:L→Js×JnC,R:L\to J_s\times J_nC,R:L→Js​×Jn​, a Boolean function v:L→{false,true}v:L\to\{\mathrm{false},\mathrm{true}\}v:L→{false,true}, nonempty slot sets Sc,Sr⊆JsS_c,S_r\subseteq J_sSc​,Sr​⊆Js​, and unitary matrices Hc,HrH_c,H_rHc​,Hr​ on JsJ_sJs​. Every valid label ℓ\ellℓ, meaning v(ℓ)=truev(\ell)=\mathrm{true}v(ℓ)=true, has C(ℓ)1∈ScC(\ell)_1\in S_cC(ℓ)1​∈Sc​ and R(ℓ)1∈SrR(\ell)_1\in S_rR(ℓ)1​∈Sr​; the map ℓ↦(C(ℓ)2,R(ℓ)2)\ell\mapsto(C(\ell)_2,R(\ell)_2)ℓ↦(C(ℓ)2​,R(ℓ)2​) is injective on valid labels; and the first columns of Hc,HrH_c,H_rHc​,Hr​ are respectively 1/∣Sc∣1/\sqrt{|S_c|}1/∣Sc​∣​ and 1/∣Sr∣1/\sqrt{|S_r|}1/∣Sr​∣​ on their slot sets and zero elsewhere. Given any real table a:Jd→Ra:J_d\to\mathbb Ra:Jd​→R and Boolean parameter hhh, defaulting to false, put M=max⁡j∈Jd∣aj∣M=\max_{j\in J_d}|a_j|M=maxj∈Jd​​∣aj​∣ and define the Boolean-indexed matrix

D(q)b,c={q,b=c,−i1−q2,b≠c.D(q)_{b,c}= \begin{cases} q,&b=c,\\ -\mathrm i\sqrt{1-q^2},&b\ne c. \end{cases}D(q)b,c​={q,−i1−q2​,​b=c,b=c.​

Define KKK on {false,true}×L\{\mathrm{false},\mathrm{true}\}\times L{false,true}×L by

K(b,ℓ),(c,k)=1ℓ=k D(ak1/M)b,c{−1,h=true and c=true,1,otherwise.K_{(b,\ell),(c,k)} =\mathbf1_{\ell=k}\,D(a_{k_1}/M)_{b,c} \begin{cases}-1,&h=\mathrm{true}\text{ and }c=\mathrm{true},\\1,&\text{otherwise}.\end{cases}K(b,ℓ),(c,k)​=1ℓ=k​D(ak1​​/M)b,c​{−1,1,​h=true and c=true,otherwise.​

For a flag set FFF, let PCP_CPC​ and PRP_RPR​ send (f,ℓ)(f,\ell)(f,ℓ) respectively to (f,C(ℓ))(f,C(\ell))(f,C(ℓ)) and (f,R(ℓ))(f,R(\ell))(f,R(ℓ)), with matrix entries one at these images and zero otherwise, and let DF(H)(f,t,i),(g,u,j)=1f=g1i=jHt,u\mathcal D_F(H)_{(f,t,i),(g,u,j)}=\mathbf1_{f=g}\mathbf1_{i=j}H_{t,u}DF​(H)(f,t,i),(g,u,j)​=1f=g​1i=j​Ht,u​. The definition returns

DF(Hr)†PRKPC†DF(Hc),F={false,true},\mathcal D_F(H_r)^\dagger P_R K P_C^\dagger\mathcal D_F(H_c), \qquad F=\{\mathrm{false},\mathrm{true}\},DF​(Hr​)†PR​KPC†​DF​(Hc​),F={false,true},

with indices regrouped as ((f,t),i)((f,t),i)((f,t),i). It imposes no nonzero-table hypothesis: if aaa is identically zero, division by M=0M=0M=0 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 n,s,d,mn,s,d,mn,s,d,m, let Jt={0,…,2t−1}J_t=\{0,\ldots,2^t-1\}Jt​={0,…,2t−1} and L=Jd×JmL=J_d\times J_mL=Jd​×Jm​. A scheme BBB consists of d+m=s+nd+m=s+nd+m=s+n, bijections C,R:L→Js×JnC,R:L\to J_s\times J_nC,R:L→Js​×Jn​, a Boolean validity function vvv, nonempty slot sets Sc,Sr⊆JsS_c,S_r\subseteq J_sSc​,Sr​⊆Js​, and unitary matrices Hc,HrH_c,H_rHc​,Hr​. Valid labels map into the corresponding slot sets, ℓ↦(C(ℓ)2,R(ℓ)2)\ell\mapsto(C(\ell)_2,R(\ell)_2)ℓ↦(C(ℓ)2​,R(ℓ)2​) is injective on valid labels, and the first columns of Hc,HrH_c,H_rHc​,Hr​ are uniform positive amplitudes on their respective slot sets and zero elsewhere. For any a:Jd→Ra:J_d\to\mathbb Ra:Jd​→R and any real ppp, set M=max⁡j∣aj∣M=\max_j|a_j|M=maxj​∣aj​∣, define s(x,t)=0s(x,t)=0s(x,t)=0 when x=0x=0x=0 and s(x,t)=∣x∣ts(x,t)=|x|^ts(x,t)=∣x∣t otherwise, and put

qj=sign⁡(aj)s(aj,p)Mp,rj=s(aj,1−p)M1−p.q_j=\frac{\operatorname{sign}(a_j)s(a_j,p)}{M^p}, \qquad r_j=\frac{s(a_j,1-p)}{M^{1-p}}.qj​=Mpsign(aj​)s(aj​,p)​,rj​=M1−ps(aj​,1−p)​.

Here sign⁡(0)=0\operatorname{sign}(0)=0sign(0)=0, and real powers and division use their total definitions, including division by zero giving zero. With D(q)b,c=qD(q)_{b,c}=qD(q)b,c​=q for b=cb=cb=c and D(q)b,c=−i1−q2D(q)_{b,c}=-\mathrm i\sqrt{1-q^2}D(q)b,c​=−i1−q2​ otherwise, define a matrix KKK on three Boolean flags and LLL by

K((b1,b2,b3),ℓ),((c1,c2,c3),k)={D(qk1)b1,c1D(rk1)b2,c2,ℓ=k,b3={c3,v(k)=true,¬c3,v(k)=false,0,otherwise.K_{((b_1,b_2,b_3),\ell),((c_1,c_2,c_3),k)} = \begin{cases} D(q_{k_1})_{b_1,c_1}D(r_{k_1})_{b_2,c_2}, &\ell=k,\quad b_3=\begin{cases}c_3,&v(k)=\mathrm{true},\\\neg c_3,&v(k)=\mathrm{false},\end{cases}\\ 0,&\text{otherwise}. \end{cases}K((b1​,b2​,b3​),ℓ),((c1​,c2​,c3​),k)​=⎩⎨⎧​D(qk1​​)b1​,c1​​D(rk1​​)b2​,c2​​,0,​ℓ=k,b3​={c3​,¬c3​,​v(k)=true,v(k)=false,​otherwise.​

Let PC,PRP_C,P_RPC​,PR​ be the matrices of (f,ℓ)↦(f,C(ℓ))(f,\ell)\mapsto(f,C(\ell))(f,ℓ)↦(f,C(ℓ)) and (f,ℓ)↦(f,R(ℓ))(f,\ell)\mapsto(f,R(\ell))(f,ℓ)↦(f,R(ℓ)), and let DF(H)(f,t,i),(g,u,j)=1f=g1i=jHt,u\mathcal D_F(H)_{(f,t,i),(g,u,j)}=\mathbf1_{f=g}\mathbf1_{i=j}H_{t,u}DF​(H)(f,t,i),(g,u,j)​=1f=g​1i=j​Ht,u​, where FFF is the set of three Boolean flags. The returned matrix is DF(Hr)†PRKPC†DF(Hc)\mathcal D_F(H_r)^\dagger P_RKP_C^\dagger\mathcal D_F(H_c)DF​(Hr​)†PR​KPC†​DF​(Hc​), regrouped onto indices ((f,t),i)((f,t),i)((f,t),i). This definition places no restriction on ppp, allows zero table entries and the identically zero table, and asserts no unitarity.

QAlgorithms.Papers.Independent.Extend50.P44.ToeplitzLabels

For arbitrary natural numbers n,dn,dn,d, put N=2nN=2^nN=2n and D=2dD=2^dD=2d, and fix 0≤k<D0\le k<D0≤k<D. Let BBB consist of column and row bijections c,r:{0,…,D−1}×{0,…,N−1}→{0,…,D−1}×{0,…,N−1}c,r:\{0,\ldots,D-1\}\times\{0,\ldots,N-1\}\to\{0,\ldots,D-1\}\times\{0,\ldots,N-1\}c,r:{0,…,D−1}×{0,…,N−1}→{0,…,D−1}×{0,…,N−1}, a Boolean validity function vvv, nonempty slot sets C,R⊆{0,…,D−1}C,R\subseteq\{0,\ldots,D-1\}C,R⊆{0,…,D−1}, and unitary D×DD\times DD×D matrices Hc,HrH_c,H_rHc​,Hr​; their first columns are respectively ∣C∣−1/2|C|^{-1/2}∣C∣−1/2 on CCC and zero elsewhere, and ∣R∣−1/2|R|^{-1/2}∣R∣−1/2 on RRR 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 d+n=d+nd+n=d+nd+n=d+n. This predicate means that C=R={0,…,D−1}C=R=\{0,\ldots,D-1\}C=R={0,…,D−1} and, for every label (t,h)(t,h)(t,h),

c(t,h)=(t,h),r(t,h)1=t,r(t,h)2=(t−k+h) mod N,v(t,h)=true ⟺ 0≤t−k+h<N.c(t,h)=(t,h),\qquad r(t,h)_1=t,\qquad r(t,h)_2=(t-k+h)\bmod N,\qquad v(t,h)=\text{true}\ \Longleftrightarrow\ 0\le t-k+h<N.c(t,h)=(t,h),r(t,h)1​=t,r(t,h)2​=(t−k+h)modN,v(t,h)=true ⟺ 0≤t−k+h<N.

The expression t−k+ht-k+ht−k+h and its remainder are computed in the integers, with remainder in {0,…,N−1}\{0,\ldots,N-1\}{0,…,N−1}. The conditions apply also when n=0n=0n=0 or d=0d=0d=0.

QAlgorithms.Papers.Independent.Extend50.P44.TransposeOracle

For natural numbers n,s,d,mn,s,d,mn,s,d,m, put Jt={0,…,2t−1}J_t=\{0,\ldots,2^t-1\}Jt​={0,…,2t−1} and L=Jd×JmL=J_d\times J_mL=Jd​×Jm​. Let BBB be scheme data consisting of d+m=s+nd+m=s+nd+m=s+n, bijections C,R:L→Js×JnC,R:L\to J_s\times J_nC,R:L→Js​×Jn​, a Boolean validity function vvv, nonempty slot sets Sc,Sr⊆JsS_c,S_r\subseteq J_sSc​,Sr​⊆Js​, and unitary matrices Hc,HrH_c,H_rHc​,Hr​. Valid labels map into the respective slot sets, their pairs of column and row system positions determine them uniquely, and the first columns of Hc,HrH_c,H_rHc​,Hr​ are uniform positive amplitudes on their slot sets and zero elsewhere. A transpose oracle for BBB consists of a permutation τ:L→L\tau:L\to Lτ:L→L satisfying, for every label ℓ\ellℓ,

τ(τ(ℓ))=ℓ,τ(ℓ)1=ℓ1,v(τ(ℓ))=v(ℓ),R(ℓ)=C(τ(ℓ)),\tau(\tau(\ell))=\ell,\qquad \tau(\ell)_1=\ell_1,\qquad v(\tau(\ell))=v(\ell),\qquad R(\ell)=C(\tau(\ell)),τ(τ(ℓ))=ℓ,τ(ℓ)1​=ℓ1​,v(τ(ℓ))=v(ℓ),R(ℓ)=C(τ(ℓ)),

together with the equality Hr=HcH_r=H_cHr​=Hc​. These requirements apply to invalid labels as well as valid ones.

QAlgorithms.Papers.Independent.Extend50.P44.TreeLabels

For any natural number nnn, put N=2nN=2^nN=2n. Let BBB consist of column and row bijections c,r:{0,1,2,3}×{0,…,2N−1}→{0,…,7}×{0,…,N−1}c,r:\{0,1,2,3\}\times\{0,\ldots,2N-1\}\to\{0,\ldots,7\}\times\{0,\ldots,N-1\}c,r:{0,1,2,3}×{0,…,2N−1}→{0,…,7}×{0,…,N−1}, a Boolean validity function vvv, nonempty slot sets C,R⊆{0,…,7}C,R\subseteq\{0,\ldots,7\}C,R⊆{0,…,7}, and unitary 8×88\times88×8 matrices Hc,HrH_c,H_rHc​,Hr​. Their first columns are respectively ∣C∣−1/2|C|^{-1/2}∣C∣−1/2 on CCC and zero elsewhere, and ∣R∣−1/2|R|^{-1/2}∣R∣−1/2 on RRR 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 2+(n+1)=3+n2+(n+1)=3+n2+(n+1)=3+n. This predicate means C=R={0,1,2,3}C=R=\{0,1,2,3\}C=R={0,1,2,3} and that a label (t,h)(t,h)(t,h) is valid exactly when

(t=0∧(h=0∨(⌊N/2⌋≤h<N))) ∨ (t=1∧0<h<⌊N/2⌋) ∨ (t=2∧h≠0∧h≠N).\bigl(t=0\land(h=0\lor(\lfloor N/2\rfloor\le h<N))\bigr) \ \lor\ \bigl(t=1\land0<h<\lfloor N/2\rfloor\bigr) \ \lor\ \bigl(t=2\land h\ne0\land h\ne N\bigr).(t=0∧(h=0∨(⌊N/2⌋≤h<N))) ∨ (t=1∧0<h<⌊N/2⌋) ∨ (t=2∧h=0∧h=N).

For every valid label it additionally requires

r(t,h)2={h,t<2,⌊h/2⌋,t≥2 and h<N,h−N,t≥2 and N≤h.r(t,h)_2= \begin{cases} h,&t<2,\\ \lfloor h/2\rfloor,&t\ge2\ \text{and}\ h<N,\\ h-N,&t\ge2\ \text{and}\ N\le h. \end{cases}r(t,h)2​=⎩⎨⎧​h,⌊h/2⌋,h−N,​t<2,t≥2 and h<N,t≥2 and N≤h.​

All arithmetic here is natural-number arithmetic, and n=0n=0n=0 is included.

QAlgorithms.Papers.Independent.Extend50.P44.TridiagonalLabels

For any natural number nnn, put N=2nN=2^nN=2n. Let BBB consist of column and row bijections c,r:{0,…,2N−1}×{0,1}→{0,1,2,3}×{0,…,N−1}c,r:\{0,\ldots,2N-1\}\times\{0,1\}\to\{0,1,2,3\}\times\{0,\ldots,N-1\}c,r:{0,…,2N−1}×{0,1}→{0,1,2,3}×{0,…,N−1}, a Boolean validity function vvv, nonempty slot sets C,R⊆{0,1,2,3}C,R\subseteq\{0,1,2,3\}C,R⊆{0,1,2,3}, and unitary 4×44\times44×4 matrices Hc,HrH_c,H_rHc​,Hr​. Their first columns are respectively ∣C∣−1/2|C|^{-1/2}∣C∣−1/2 on CCC and zero elsewhere, and ∣R∣−1/2|R|^{-1/2}∣R∣−1/2 on RRR 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 (n+1)+1=2+n(n+1)+1=2+n(n+1)+1=2+n. This predicate asserts C=R={0,1,3}C=R=\{0,1,3\}C=R={0,1,3} and, for every label (t,h)(t,h)(t,h),

v(t,h)=true ⟺ ¬((t mod 2=0∧h=1)∨t=2N−1),v(t,h)=\text{true} \ \Longleftrightarrow\ \neg\bigl((t\bmod2=0\land h=1)\lor t=2N-1\bigr),v(t,h)=true ⟺ ¬((tmod2=0∧h=1)∨t=2N−1),

and, whenever that label is valid,

r(t,h)2=(⌊t/2⌋+h) mod N,c(t,h)2=(⌊t/2⌋+{t mod 2,h=0,0,h=1) mod N.r(t,h)_2=(\lfloor t/2\rfloor+h)\bmod N,\qquad c(t,h)_2= \left(\lfloor t/2\rfloor+ \begin{cases}t\bmod2,&h=0,\\0,&h=1\end{cases}\right)\bmod N.r(t,h)2​=(⌊t/2⌋+h)modN,c(t,h)2​=(⌊t/2⌋+{tmod2,0,​h=0,h=1​)modN.

All divisions, remainders, and indices in these formulas are natural-number operations. The definition allows n=0n=0n=0.

QAlgorithms.Papers.Independent.Extend50.P44.bandedToeplitz

For arbitrary natural numbers n,dn,dn,d, an integer 0≤k<2d0\le k<2^d0≤k<2d, and real coefficients a0,…,a2d−1a_0,\ldots,a_{2^d-1}a0​,…,a2d−1​, this defines a complex 2n×2n2^n\times2^n2n×2n matrix. For 0≤i,j<2n0\le i,j<2^n0≤i,j<2n, its entry is the seed value at index i+(2n−1−j)i+(2^n-1-j)i+(2n−1−j), where the seed at uuu is the sum of ata_tat​ over indices satisfying u−(2n−1)=t−ku-(2^n-1)=t-ku−(2n−1)=t−k. Thus, using integer arithmetic for the coefficient index,

Mij={ak+i−j,0≤k+i−j<2d,0,otherwise.M_{ij}= \begin{cases} a_{k+i-j},&0\le k+i-j<2^d,\\ 0,&\text{otherwise}. \end{cases}Mij​={ak+i−j​,0,​0≤k+i−j<2d,otherwise.​

Real coefficients are regarded as complex numbers. There is no restriction relating nnn and ddd; for n=0n=0n=0 the matrix is [ak][a_k][ak​], and for d=0d=0d=0 it is a0a_0a0​ times the identity.

QAlgorithms.Papers.Independent.Extend50.P44.bandedToeplitzSeed

For arbitrary natural numbers n,dn,dn,d, an integer kkk with 0≤k<2d0\le k<2^d0≤k<2d, and real coefficients ata_tat​ indexed by 0≤t<2d0\le t<2^d0≤t<2d, this defines a complex-valued sequence indexed by 0≤u<2n+1−10\le u<2^{n+1}-10≤u<2n+1−1:

su=∑t=02d−1{at,u−(2n−1)=t−k,0,otherwise.s_u=\sum_{t=0}^{2^d-1} \begin{cases} a_t,&u-(2^n-1)=t-k,\\ 0,&\text{otherwise}. \end{cases}su​=t=0∑2d−1​{at​,0,​u−(2n−1)=t−k,otherwise.​

The subtraction in the equality is integer subtraction. Equivalently, su=ak+u−(2n−1)s_u=a_{k+u-(2^n-1)}su​=ak+u−(2n−1)​ when that integer index lies between 000 and 2d−12^d-12d−1, and su=0s_u=0su​=0 otherwise; real values are embedded in C\mathbb CC. Both n=0n=0n=0 and d=0d=0d=0 are allowed.

QAlgorithms.Papers.Independent.Extend50.P44.baseLoadingSchedule

For every natural number DDD, the base loading schedule is the one-entry list [D][D][D], including the list [0][0][0] when D=0D=0D=0.

QAlgorithms.Papers.Independent.Extend50.P44.basisMatrix

For every type XXX equipped with decidable equality and every function f:X→Xf:X\to Xf:X→X, this defines the complex matrix

Bx,y={1,x=f(y),0,x≠f(y).B_{x,y}= \begin{cases} 1,&x=f(y),\\ 0,&x\ne f(y). \end{cases}Bx,y​={1,0,​x=f(y),x=f(y).​

There is no assumption that XXX is finite or nonempty, or that fff is injective or surjective.

QAlgorithms.Papers.Independent.Extend50.P44.bitAt

For all natural numbers w,value,kw,\mathrm{value},kw,value,k, this defines a Boolean that, when k<wk<wk<w, is position kkk, counting from the most significant end starting at zero, of the length-www binary representation of value mod 2w\mathrm{value}\bmod 2^wvaluemod2w, including leading zeros. When k≥wk\ge wk≥w, it is false. In particular, for w=0w=0w=0 it is false for every value and position.

QAlgorithms.Papers.Independent.Extend50.P44.checkerboard

For every natural number nnn and every pair of real numbers a0,a1a_0,a_1a0​,a1​, this defines a complex 2n×2n2^n\times2^n2n×2n matrix whose entry at row iii and column jjj, indexed from zero, is a(i+j) mod 2a_{(i+j)\bmod2}a(i+j)mod2​, embedded in C\mathbb CC. Thus entries with even i+ji+ji+j equal a0a_0a0​, and entries with odd i+ji+ji+j equal a1a_1a1​. No restrictions are placed on either real number. When n=0n=0n=0, the matrix has one entry, equal to a0a_0a0​.

QAlgorithms.Papers.Independent.Extend50.P44.cleanBits

For any type XXX, arbitrary encoding function encode:X→N→{false,true}\mathrm{encode}:X\to\mathbb N\to\{\mathrm{false},\mathrm{true}\}encode:X→N→{false,true}, natural numbers w,workw,\mathrm{work}w,work, and x∈Xx\in Xx∈X, this defines a bit string of length w+workw+\mathrm{work}w+work. At position i<wi<wi<w it equals encode(x,i)\mathrm{encode}(x,i)encode(x,i), and at every remaining position it is false. Only the first www values of the encoding are used. Both lengths may be zero: w=0w=0w=0 gives an all-false string, and w+work=0w+\mathrm{work}=0w+work=0 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

H=12(111−1),T=(100eiπ/4),T†=(100e−iπ/4),X=(0110),H=\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix},\qquad T=\begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix},\qquad T^\dagger=\begin{pmatrix}1&0\\0&e^{-i\pi/4}\end{pmatrix},\qquad X=\begin{pmatrix}0&1\\1&0\end{pmatrix},H=2​1​(11​1−1​),T=(10​0eiπ/4​),T†=(10​0e−iπ/4​),X=(01​10​),

and the two-qubit controlled-NOT gate whose matrix entry from (c,t)(c,t)(c,t) to (c′,t′)(c',t')(c′,t′) is one exactly when c′=cc'=cc′=c and t′=t⊕ct'=t\mathbin{\oplus}ct′=t⊕c, 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 qqq, this defines the complex matrix indexed by the two Boolean values, in the order false, true, as

R(q)=(q−i1−q2−i1−q2q).R(q)= \begin{pmatrix} q&-\mathrm i\sqrt{1-q^2}\\ -\mathrm i\sqrt{1-q^2}&q \end{pmatrix}.R(q)=(q−i1−q2​​−i1−q2​q​).

There is no assumption that ∣q∣≤1|q|\le1∣q∣≤1; the real square root is 000 on negative inputs, so when ∣q∣>1|q|>1∣q∣>1 this definition gives R(q)=qIR(q)=qIR(q)=qI.

QAlgorithms.Papers.Independent.Extend50.P44.deleteCheckerCorners

For a natural number nnn, let BBB be the following data: the equality 1+(2n−1)=2n1+(2n-1)=2n1+(2n−1)=2n, where natural-number subtraction is truncated at zero; two bijections c,rc,rc,r from labels (t,h)(t,h)(t,h), with 0≤t<20\le t<20≤t<2 and 0≤h<22n−10\le h<2^{2n-1}0≤h<22n−1, to pairs of integers in {0,…,2n−1}2\{0,\ldots,2^n-1\}^2{0,…,2n−1}2; a Boolean validity function v(t,h)v(t,h)v(t,h); nonempty column and row slot sets C,R⊆{0,…,2n−1}C,R\subseteq\{0,\ldots,2^n-1\}C,R⊆{0,…,2n−1}; and unitary matrices Hc,HrH_c,H_rHc​,Hr​ of size 2n2^n2n. These data satisfy c(t,h)1∈Cc(t,h)_1\in Cc(t,h)1​∈C and r(t,h)1∈Rr(t,h)_1\in Rr(t,h)1​∈R whenever v(t,h)v(t,h)v(t,h) is true; two valid labels with the same column second coordinate and the same row second coordinate are equal; and the first columns of Hc,HrH_c,H_rHc​,Hr​ are respectively ∣C∣−1/2|C|^{-1/2}∣C∣−1/2 on CCC and zero elsewhere, and ∣R∣−1/2|R|^{-1/2}∣R∣−1/2 on RRR and zero elsewhere. This definition returns the same data with validity replaced by

v′(t,h)=true⟺v(t,h)=true ∧ ¬(t=0∧(h=0∨h=22n−1−1)).v'(t,h)=\text{true} \quad\Longleftrightarrow\quad v(t,h)=\text{true}\ \land\ \neg\bigl(t=0\land(h=0\lor h=2^{2n-1}-1)\bigr).v′(t,h)=true⟺v(t,h)=true ∧ ¬(t=0∧(h=0∨h=22n−1−1)).

All other data are retained, with the slot-membership and injectivity conditions restricted to the remaining valid labels. The required balance equality rules out n=0n=0n=0.

QAlgorithms.Papers.Independent.Extend50.P44.deletedCheckerboard

For every natural number nnn and pair of real numbers a0,a1a_0,a_1a0​,a1​, this defines a complex 2n×2n2^n\times2^n2n×2n matrix, indexed by integers 0≤i,j<2n0\le i,j<2^n0≤i,j<2n, whose entries are

Mij={0,(i=j=0) or (i=j=2n−1),a(i+j) mod 2,otherwise.M_{ij}= \begin{cases} 0,&(i=j=0)\ \text{or}\ (i=j=2^n-1),\\ a_{(i+j)\bmod 2},&\text{otherwise}. \end{cases}Mij​={0,a(i+j)mod2​,​(i=j=0) or (i=j=2n−1),otherwise.​

The real coefficients are regarded as complex numbers. The definition includes n=0n=0n=0, when the two specified corners coincide and the resulting 1×11\times11×1 matrix is zero.

QAlgorithms.Papers.Independent.Extend50.P44.diffusion

For arbitrary natural numbers s,ns,ns,n, any type FFF with decidable equality, and any complex matrix HHH indexed by T={0,…,2s−1}T=\{0,\ldots,2^s-1\}T={0,…,2s−1}, this defines a complex matrix indexed by F×(T×J)F\times(T\times J)F×(T×J), where J={0,…,2n−1}J=\{0,\ldots,2^n-1\}J={0,…,2n−1}, by

D(H)(f,(t,i)),(g,(u,j))={Htu,f=g and i=j,0,otherwise.D(H)_{(f,(t,i)),(g,(u,j))}= \begin{cases} H_{tu},&f=g\ \text{and }i=j,\\ 0,&\text{otherwise}. \end{cases}D(H)(f,(t,i)),(g,(u,j))​={Htu​,0,​f=g and i=j,otherwise.​

No unitarity assumption is imposed on HHH, and FFF need not be finite or nonempty. The cases s=0s=0s=0 and n=0n=0n=0 are included, giving singleton sets TTT and JJJ, respectively.

QAlgorithms.Papers.Independent.Extend50.P44.doubleFlaggedPairBits

For all natural numbers u,vu,vu,v, Booleans β1,β2\beta_1,\beta_2β1​,β2​, integers a,ba,ba,b satisfying 0≤a<2u0\le a<2^u0≤a<2u and 0≤b<2v0\le b<2^v0≤b<2v, and a natural number kkk, this defines the Boolean at position kkk of the sequence consisting of β1,β2\beta_1,\beta_2β1​,β2​, the length-uuu binary representation of aaa, and the length-vvv binary representation of bbb. Both representations have leading zeros and are ordered most significant bit first. Positions zero and one return the respective flags, the next uuu positions contain aaa, the following vvv positions contain bbb, and all positions k≥2+u+vk\ge2+u+vk≥2+u+v return false. Either binary block may be empty.

QAlgorithms.Papers.Independent.Extend50.P44.doubleLoadingSchedule

For every natural number DDD, the double loading schedule is the two-entry list [D,D][D,D][D,D], including [0,0][0,0][0,0] when D=0D=0D=0.

QAlgorithms.Papers.Independent.Extend50.P44.entryArithmeticCost

For every natural number www and every finite list ccc of arithmetic gates on www 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 ccc followed by its reversal. Consequently, it equals twice the number of gates in ccc with exactly two controls. Gates with zero or one control contribute zero. Empty lists are allowed and have cost zero; when w=0w=0w=0, no gate can have a target, so the list must be empty.

QAlgorithms.Papers.Independent.Extend50.P44.entryCircuit

For arbitrary natural numbers n,d,m,bn,d,m,bn,d,m,b, an arbitrary function rrr from pairs (i,j)(i,j)(i,j) with 0≤i,j<2n0\le i,j<2^n0≤i,j<2n to optional pairs (t,u)(t,u)(t,u) with 0≤t<2d0\le t<2^d0≤t<2d, 0≤u<2m0\le u<2^m0≤u<2m, and an arbitrary table code\mathrm{code}code assigning a bbb-bit string to each t<2dt<2^dt<2d, this defines a square complex matrix on basis labels ((v,(i,j)),z)((v,(i,j)),z)((v,(i,j)),z), where vvv has bbb bits and zzz has 1+d+m1+d+m1+d+m bits. Define R(i,j)R(i,j)R(i,j) to be all false when r(i,j)r(i,j)r(i,j) is absent, and otherwise to be a true flag followed by the most significant first ddd-bit encoding of ttt and mmm-bit encoding of uuu. Define L(z)L(z)L(z) to be all false if the flag of zzz is false, and otherwise to be code(t)\mathrm{code}(t)code(t), where ttt is the integer represented by the next ddd bits; the final mmm bits are ignored. Let CCC have entry one exactly from ((v,(i,j)),z)((v,(i,j)),z)((v,(i,j)),z) to ((v,(i,j)),z⊕R(i,j))((v,(i,j)),z\oplus R(i,j))((v,(i,j)),z⊕R(i,j)), and let VVV have entry one exactly from that label to ((v⊕L(z),(i,j)),z)((v\oplus L(z),(i,j)),z)((v⊕L(z),(i,j)),z), with all other entries zero; ⊕\oplus⊕ means componentwise Boolean exclusive-or. The defined matrix is CVCCVCCVC, so its entry is one exactly for the basis transformation

((v,(i,j)),z)⟼((v⊕L(z⊕R(i,j)),(i,j)),z),((v,(i,j)),z)\longmapsto \bigl((v\oplus L(z\oplus R(i,j)),(i,j)),z\bigr),((v,(i,j)),z)⟼((v⊕L(z⊕R(i,j)),(i,j)),z),

and zero otherwise. This definition applies to every initial scratch string zzz, including nonzero strings, and permits zero-length numerical and value registers.

QAlgorithms.Papers.Independent.Extend50.P44.extendedTree

For every natural number nnn, put N=2nN=2^nN=2n, and let a0,a1,a2a_0,a_1,a_2a0​,a1​,a2​ be arbitrary real numbers. This defines a complex N×NN\times NN×N matrix with indices 0≤i,j<N0\le i,j<N0≤i,j<N:

Mij={a0,i=j and (i=0 or ⌊N/2⌋≤i),a1,i=j and neither of those conditions holds,a2,i≠j and((i>0∧⌊i/2⌋=j)∨(j>0∧⌊j/2⌋=i)),0,otherwise.M_{ij}= \begin{cases} a_0,&i=j\ \text{and}\ (i=0\ \text{or}\ \lfloor N/2\rfloor\le i),\\ a_1,&i=j\ \text{and neither of those conditions holds},\\ a_2,&i\ne j\ \text{and}\bigl((i>0\land\lfloor i/2\rfloor=j) \lor(j>0\land\lfloor j/2\rfloor=i)\bigr),\\ 0,&\text{otherwise}. \end{cases}Mij​=⎩⎨⎧​a0​,a1​,a2​,0,​i=j and (i=0 or ⌊N/2⌋≤i),i=j and neither of those conditions holds,i=j and((i>0∧⌊i/2⌋=j)∨(j>0∧⌊j/2⌋=i)),otherwise.​

Real coefficients are embedded in C\mathbb CC, and division is natural-number division. For n=0n=0n=0, the matrix is [a0][a_0][a0​].

QAlgorithms.Papers.Independent.Extend50.P44.flaggedPairBits

For all natural numbers u,vu,vu,v, a Boolean β\betaβ, integers a,ba,ba,b satisfying 0≤a<2u0\le a<2^u0≤a<2u and 0≤b<2v0\le b<2^v0≤b<2v, and a natural number kkk, this defines the Boolean at position kkk of the sequence consisting of β\betaβ, followed by the length-uuu binary representation of aaa, followed by the length-vvv binary representation of bbb. The binary representations use leading zeros and run from most significant to least significant bit. Position zero returns β\betaβ; positions 1,…,u1,\ldots,u1,…,u contain aaa; positions u+1,…,u+vu+1,\ldots,u+vu+1,…,u+v contain bbb; every position k≥1+u+vk\ge1+u+vk≥1+u+v returns false. Zero widths contribute empty blocks.

QAlgorithms.Papers.Independent.Extend50.P44.idealLoader

For every natural number dbd_bdb​ and every real table a=(aj)0≤j<2dba=(a_j)_{0\le j<2^{d_b}}a=(aj​)0≤j<2db​​, let M=max⁡({0}∪{∣aj∣:0≤j<2db})M=\max(\{0\}\cup\{|a_j|:0\le j<2^{d_b}\})M=max({0}∪{∣aj​∣:0≤j<2db​}). This defines a complex matrix indexed by a Boolean flag and a table index:

V(f,j),(g,k)={ak/M,j=k and f=g,−i1−(ak/M)2,j=k and f≠g,0,j≠k.V_{(f,j),(g,k)} = \begin{cases} a_k/M,&j=k\text{ and }f=g,\\ -i\sqrt{1-(a_k/M)^2},&j=k\text{ and }f\ne g,\\ 0,&j\ne k. \end{cases}V(f,j),(g,k)​=⎩⎨⎧​ak​/M,−i1−(ak​/M)2​,0,​j=k and f=g,j=k and f=g,j=k.​

Division is the total real division operation, so if the table is identically zero, M=0M=0M=0 and every ratio ak/Ma_k/Mak​/M is zero; in that case each fixed-index flag block has zero diagonal and off-diagonal entries −i-i−i. The case db=0d_b=0db​=0 has one table index and is included.

QAlgorithms.Papers.Independent.Extend50.P44.laplacian

For arbitrary natural numbers nx,nyn_x,n_ynx​,ny​ and arbitrary real numbers dx,dyd_x,d_ydx​,dy​, put Nx=2nxN_x=2^{n_x}Nx​=2nx​ and Ny=2nyN_y=2^{n_y}Ny​=2ny​. This defines a complex NxNy×NxNyN_xN_y\times N_xN_yNx​Ny​×Nx​Ny​ matrix. For each index iii, set xi=i mod Nxx_i=i\bmod N_xxi​=imodNx​ and yi=⌊i/Nx⌋y_i=\lfloor i/N_x\rflooryi​=⌊i/Nx​⌋; then

Lij={−2(dx−2+dy−2),i=j,dx−2,i≠j, yi=yj, ∣xi−xj∣=1,dy−2,i≠j, xi=xj, ∣yi−yj∣=1,0,otherwise.L_{ij}= \begin{cases} -2(d_x^{-2}+d_y^{-2}),&i=j,\\ d_x^{-2},&i\ne j,\ y_i=y_j,\ |x_i-x_j|=1,\\ d_y^{-2},&i\ne j,\ x_i=x_j,\ |y_i-y_j|=1,\\ 0,&\text{otherwise}. \end{cases}Lij​=⎩⎨⎧​−2(dx−2​+dy−2​),dx−2​,dy−2​,0,​i=j,i=j, yi​=yj​, ∣xi​−xj​∣=1,i=j, xi​=xj​, ∣yi​−yj​∣=1,otherwise.​

Coordinate differences inside absolute values are taken in the integers, and all displayed real entries are embedded in C\mathbb CC. There are no positivity or nonzero assumptions on dx,dyd_x,d_ydx​,dy​; 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 dx,dyd_x,d_ydx​,dy​, this defines the four-entry real table

(−2(1dx2+1dy2), 1dx2, 1dy2, 0),\left(-2\left(\frac1{d_x^2}+\frac1{d_y^2}\right),\ \frac1{d_x^2},\ \frac1{d_y^2},\ 0\right),(−2(dx2​1​+dy2​1​), dx2​1​, dy2​1​, 0),

with entries indexed by 0,1,2,30,1,2,30,1,2,3, respectively. There are no positivity or nonzero assumptions on dx,dyd_x,d_ydx​,dy​; 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 db,b,workd_b,b,\mathrm{work}db​,b,work, this defines a rectangular complex matrix JJJ with rows indexed by Boolean strings of length 1+db+b+work1+d_b+b+\mathrm{work}1+db​+b+work and columns indexed by pairs (f,j)(f,j)(f,j), where fff is Boolean and 0≤j<2db0\le j<2^{d_b}0≤j<2db​. Split a row string into a first flag f′f'f′, a dbd_bdb​-bit address zzz, a bbb-bit string qqq, and work\mathrm{work}work work bits. Then

J(f′,z,q,anc),(f,j)={2−b/2exp⁡ ⁣(−2πi val⁡(q)/2b),f′=f, z=bin⁡db(j), anc=0,0,otherwise,J_{(f',z,q,\mathrm{anc}),(f,j)} = \begin{cases} 2^{-b/2}\exp\!\left(-2\pi i\,\operatorname{val}(q)/2^b\right), &f'=f,\ z=\operatorname{bin}_{d_b}(j),\ \mathrm{anc}=0,\\ 0,&\text{otherwise}, \end{cases}J(f′,z,q,anc),(f,j)​={2−b/2exp(−2πival(q)/2b),0,​f′=f, z=bindb​​(j), anc=0,otherwise,​

where bin⁡db(j)\operatorname{bin}_{d_b}(j)bindb​​(j) is the most significant first binary encoding of jjj, and val⁡(q)=∑i=0b−11{qi=true}2b−1−i\operatorname{val}(q)=\sum_{i=0}^{b-1}\mathbf1_{\{q_i=\mathrm{true}\}}2^{b-1-i}val(q)=∑i=0b−1​1{qi​=true}​2b−1−i. Registers of length zero are permitted, and their bit conditions are vacuous; when b=0b=0b=0, the displayed nonzero entry is one.

QAlgorithms.Papers.Independent.Extend50.P44.loaderTWord

For every natural number www and every circuit ccc that is a finite list of applications of H,T,T†,XH,T,T^\dagger,XH,T,T†,X, and controlled-NOT to injectively selected ordered wires among www wires, this defines a list of letters of the same length and in the same order. An application is replaced by the letter ttt exactly when its gate equals the one-qubit gate T=diag⁡(1,eiπ/4)T=\operatorname{diag}(1,e^{i\pi/4})T=diag(1,eiπ/4) or T†=diag⁡(1,e−iπ/4)T^\dagger=\operatorname{diag}(1,e^{-i\pi/4})T†=diag(1,e−iπ/4); every other application is replaced by the letter hhh. Thus applications of the Hadamard gate, bit flip, and controlled-NOT all produce hhh, independently of their wire placements. The empty circuit produces the empty list; w=0w=0w=0 is allowed.

QAlgorithms.Papers.Independent.Extend50.P44.loadingCost

For every finite list of natural numbers schedule=[k1,…,kr]\mathrm{schedule}=[k_1,\ldots,k_r]schedule=[k1​,…,kr​], its loading cost is the natural-number sum ∑j=1rkj\sum_{j=1}^r k_j∑j=1r​kj​. The empty list has cost zero, and zero entries contribute zero.

QAlgorithms.Papers.Independent.Extend50.P44.matrixMax

For every natural number NNN and real N×NN\times NN×N matrix AAA, this defines

matrixMax⁡(A)=max⁡({0}∪{∣Aij∣:0≤i,j<N}),\operatorname{matrixMax}(A)= \max\bigl(\{0\}\cup\{|A_{ij}|:0\le i,j<N\}\bigr),matrixMax(A)=max({0}∪{∣Aij​∣:0≤i,j<N}),

by taking each row’s maximum with initial value 000, and then taking the maximum of those results with initial value 000. In particular, the value is 000 when N=0N=0N=0.

QAlgorithms.Papers.Independent.Extend50.P44.paddedTable

For every natural number DDD and every real table a=(a0,…,aD−1)a=(a_0,\ldots,a_{D-1})a=(a0​,…,aD−1​), this defines a table indexed by 0≤j<2clog⁡2D0\le j<2^{\operatorname{clog}_2D}0≤j<2clog2​D, with value aja_jaj​ when j<Dj<Dj<D and zero otherwise. Here clog⁡2D\operatorname{clog}_2Dclog2​D is the natural-number ceiling logarithm to base two; for D≥1D\ge1D≥1, it is the least natural number qqq with D≤2qD\le2^qD≤2q. The definition also includes D=0D=0D=0, when the ceiling logarithm is zero and the resulting one-entry table is zero.

QAlgorithms.Papers.Independent.Extend50.P44.pairBits

For all natural numbers u,vu,vu,v, a pair x=(a,b)x=(a,b)x=(a,b) with 0≤a<2u0\le a<2^u0≤a<2u and 0≤b<2v0\le b<2^v0≤b<2v, and a natural number kkk, this defines position kkk of the concatenation of the length-uuu binary representation of aaa and the length-vvv binary representation of bbb, both written most significant bit first with leading zeros. Explicitly, it returns position kkk of the first representation if k<uk<uk<u, position k−uk-uk−u of the second if u≤k<u+vu\le k<u+vu≤k<u+v, and false if k≥u+vk\ge u+vk≥u+v. Either width may be zero, in which case that representation contributes no bits.

QAlgorithms.Papers.Independent.Extend50.P44.phaseGradient

For every natural number bbb and every Boolean string z=(z0,…,zb−1)z=(z_0,\ldots,z_{b-1})z=(z0​,…,zb−1​), this defines the complex number

2−b/2exp⁡ ⁣(−2πi2b∑j=0b−11{zj=true} 2b−1−j).2^{-b/2}\exp\!\left(-\frac{2\pi i}{2^b} \sum_{j=0}^{b-1}\mathbf1_{\{z_j=\mathrm{true}\}}\,2^{b-1-j}\right).2−b/2exp(−2b2πi​j=0∑b−1​1{zj​=true}​2b−1−j).

The sum interprets the bits in most significant first order. When b=0b=0b=0, the string is empty, the sum is zero, and the value is one.

QAlgorithms.Papers.Independent.Extend50.P44.prepAlpha

For every natural number DDD, real table a:{0,…,D−1}→Ra:\{0,\ldots,D-1\}\to\mathbb Ra:{0,…,D−1}→R, natural numbers Sc,SrS_c,S_rSc​,Sr​, and real number ppp, this defines

α(a,Sc,Sr,p)=ScSrD(∑j=0D−1h(aj,2p))(∑j=0D−1h(aj,2−2p)),h(x,t)={0,x=0,∣x∣t,x≠0.\alpha(a,S_c,S_r,p)= \frac{\sqrt{S_cS_r}}{D} \sqrt{ \left(\sum_{j=0}^{D-1}h(a_j,2p)\right) \left(\sum_{j=0}^{D-1}h(a_j,2-2p)\right)}, \qquad h(x,t)= \begin{cases}0,&x=0,\\|x|^t,&x\ne0.\end{cases}α(a,Sc​,Sr​,p)=DSc​Sr​​​(j=0∑D−1​h(aj​,2p))(j=0∑D−1​h(aj​,2−2p))​,h(x,t)={0,∣x∣t,​x=0,x=0.​

There is no restriction on ppp. Empty sums are 000, and real division by zero is defined to be 000, so the result is 000 when D=0D=0D=0; it is also 000 if Sc=0S_c=0Sc​=0, Sr=0S_r=0Sr​=0, or every entry of aaa is zero.

QAlgorithms.Papers.Independent.Extend50.P44.reverseCode

For every pair of natural numbers d,md,md,m, every type XXX, every function r:X→Option⁡({0,…,2d−1}×{0,…,2m−1})r:X\to\operatorname{Option}(\{0,\ldots,2^d-1\}\times\{0,\ldots,2^m-1\})r:X→Option({0,…,2d−1}×{0,…,2m−1}), and every x∈Xx\in Xx∈X, this defines a Boolean string of length 1+d+m1+d+m1+d+m. If r(x)r(x)r(x) is absent, every bit is false. If r(x)r(x)r(x) is present with value (j,k)(j,k)(j,k), the string is the concatenation of a true flag, the ddd-bit most significant first binary encoding of jjj, and the mmm-bit most significant first binary encoding of kkk. 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 n,tn,tn,t, a pair u,v∈{0,…,2n−1}u,v\in\{0,\ldots,2^n-1\}u,v∈{0,…,2n−1}, a Boolean string zzz of length ttt, and a natural-number position iii, this Boolean-valued function returns position iii of the concatenation of the nnn-bit binary representations of uuu and vvv, followed by zzz, using most significant bit first and positions starting at zero. Explicitly, it returns bit iii of uuu if i<ni<ni<n, bit i−ni-ni−n of vvv if n≤i<2nn\le i<2nn≤i<2n, and zi−2nz_{i-2n}zi−2n​ if 2n≤i<2n+t2n\le i<2n+t2n≤i<2n+t; it returns false when i≥2n+ti\ge2n+ti≥2n+t. The binary encoding reduces an integer modulo 2w2^w2w when encoding it in www bits; here the two integers already lie within range, and encoding the integer represented by zzz recovers zzz. Zero lengths are allowed, so the corresponding segments may be empty.

QAlgorithms.Papers.Independent.Extend50.P44.runArithmetic

For every natural number www, finite list ccc of arithmetic gates on www bits, and bit string x:{0,…,w−1}→{false,true}x:\{0,\ldots,w-1\}\to\{\mathrm{false},\mathrm{true}\}x:{0,…,w−1}→{false,true}, this defines the bit string obtained by applying the gates of ccc to xxx 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 xxx. The definition includes w=0w=0w=0, 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 ddd and every real table a:{0,…,2d−1}→Ra:\{0,\ldots,2^d-1\}\to\mathbb Ra:{0,…,2d−1}→R, this defines the complex diagonal matrix

(Sa)i,j={−1,i=j and ai<0,1,i=j and 0≤ai,0,i≠j.(S_a)_{i,j} = \begin{cases} -1,&i=j\ \text{and }a_i<0,\\ 1,&i=j\ \text{and }0\le a_i,\\ 0,&i\ne j. \end{cases}(Sa​)i,j​=⎩⎨⎧​−1,1,0,​i=j and ai​<0,i=j and 0≤ai​,i=j.​

In particular, a zero table entry receives diagonal value +1+1+1. The definition includes d=0d=0d=0, when the matrix has one row and one column.

QAlgorithms.Papers.Independent.Extend50.P44.supportedPower

For arbitrary real numbers xxx and ppp, this defines

supportedPower⁡(x,p)={0,x=0,∣x∣p,x≠0.\operatorname{supportedPower}(x,p)= \begin{cases} 0,&x=0,\\ |x|^p,&x\ne0. \end{cases}supportedPower(x,p)={0,∣x∣p,​x=0,x=0.​

The exponent ppp may be positive, zero, or negative; in particular, the value at x=0x=0x=0 is always 000, including when p=0p=0p=0 or p<0p<0p<0.

QAlgorithms.Papers.Independent.Extend50.P44.tableMax

For every natural number DDD and real table a:{0,…,D−1}→Ra:\{0,\ldots,D-1\}\to\mathbb Ra:{0,…,D−1}→R, this defines

tableMax⁡(a)=max⁡({0}∪{∣aj∣:0≤j<D}).\operatorname{tableMax}(a)=\max\bigl(\{0\}\cup\{|a_j|:0\le j<D\}\bigr).tableMax(a)=max({0}∪{∣aj​∣:0≤j<D}).

Thus the value is the largest absolute table entry when D>0D>0D>0, and is 000 when D=0D=0D=0.

QAlgorithms.Papers.Independent.Extend50.P44.tensorPreparation

For all natural numbers s,d,ks,d,ks,d,k, every bijection f:[2s]→[2d]×[2k]f:[2^s]\to[2^d]\times[2^k]f:[2s]→[2d]×[2k], where [r]={0,…,r−1}[r]=\{0,\ldots,r-1\}[r]={0,…,r−1}, every complex matrix PPP on [2d][2^d][2d], and every complex matrix HHH on [2k][2^k][2k], this defines the complex matrix Tf(P,H)T_f(P,H)Tf​(P,H) on [2s][2^s][2s] by

Tf(P,H)x,y=Pf(x)1,f(y)1 Hf(x)2,f(y)2.T_f(P,H)_{x,y} = P_{f(x)_1,f(y)_1}\,H_{f(x)_2,f(y)_2}.Tf​(P,H)x,y​=Pf(x)1​,f(y)1​​Hf(x)2​,f(y)2​​.

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 2s=2d2k2^s=2^d2^k2s=2d2k.

QAlgorithms.Papers.Independent.Extend50.P44.toffoliCount

For every natural number www and finite list ccc of arithmetic gates on www bits, this defines the natural number of occurrences in ccc 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 w=0w=0w=0.

QAlgorithms.Papers.Independent.Extend50.P44.treeTable

For any real table a0,a1,a2a_0,a_1,a_2a0​,a1​,a2​, this defines the four-entry real table (a0,a1,a2,0)(a_0,a_1,a_2,0)(a0​,a1​,a2​,0): the value at an index j∈{0,1,2,3}j\in\{0,1,2,3\}j∈{0,1,2,3} is aja_jaj​ when j<3j<3j<3, and zero when j=3j=3j=3.

QAlgorithms.Papers.Independent.Extend50.P44.triTable

For every natural number nnn and real table aja_jaj​ indexed by 0≤j<2n+1−10\le j<2^{n+1}-10≤j<2n+1−1, this defines a real table indexed by 0≤j<2n+10\le j<2^{n+1}0≤j<2n+1, preserving the supplied entries and assigning zero to the one additional index:

a~j={aj,j<2n+1−1,0,j=2n+1−1.\widetilde a_j= \begin{cases} a_j,&j<2^{n+1}-1,\\ 0,&j=2^{n+1}-1. \end{cases}aj​={aj​,0,​j<2n+1−1,j=2n+1−1.​

For n=0n=0n=0, the input has one entry and the output is (a0,0)(a_0,0)(a0​,0).

QAlgorithms.Papers.Independent.Extend50.P44.tridiagonal

For every natural number nnn, write N=2nN=2^nN=2n, and let a0,…,a2N−2a_0,\ldots,a_{2N-2}a0​,…,a2N−2​ be arbitrary real numbers. This defines the complex N×NN\times NN×N matrix

Mij={a2i,i=j,a2min⁡(i,j)+1,i+1=j or j+1=i,0,otherwise,0≤i,j<N.M_{ij}= \begin{cases} a_{2i},&i=j,\\ a_{2\min(i,j)+1},&i+1=j\ \text{or}\ j+1=i,\\ 0,&\text{otherwise}, \end{cases} \qquad 0\le i,j<N.Mij​=⎩⎨⎧​a2i​,a2min(i,j)+1​,0,​i=j,i+1=j or j+1=i,otherwise,​0≤i,j<N.

The code obtains these coefficients from the table extended by a zero at index 2N−12N-12N−1; every coefficient used in the displayed cases is within the original table. Real coefficients are embedded in C\mathbb CC. The case n=0n=0n=0 gives the 1×11\times11×1 matrix [a0][a_0][a0​].

QAlgorithms.Papers.Independent.Extend50.P44.valueAtLabel

For arbitrary natural numbers d,m,bd,m,bd,m,b, a function code:{0,…,2d−1}→{false,true}b\mathrm{code}:\{0,\ldots,2^d-1\}\to\{\mathrm{false},\mathrm{true}\}^bcode:{0,…,2d−1}→{false,true}b, and a Boolean string zzz of length 1+d+m1+d+m1+d+m, this defines a bbb-bit string. If the first bit of zzz is false, the result is the all-false string. If it is true, the next ddd bits are interpreted as the index

j=∑i=0d−11{z1+i=true} 2d−1−i,j=\sum_{i=0}^{d-1}\mathbf1_{\{z_{1+i}=\mathrm{true}\}}\,2^{d-1-i},j=i=0∑d−1​1{z1+i​=true}​2d−1−i,

and the result is code(j)\mathrm{code}(j)code(j). The final mmm bits do not enter this value. When d=0d=0d=0, the selected index is zero; when b=0b=0b=0, the result is the unique empty string.

QAlgorithms.Papers.Independent.Extend50.P44.withFlags

For arbitrary types F,X,YF,X,YF,X,Y, with decidable equality on FFF and YYY, and any bijection e:X→Ye:X\to Ye:X→Y, this defines a complex matrix with rows indexed by F×YF\times YF×Y and columns indexed by F×XF\times XF×X, whose entries are

W(f,y),(g,x)={1,f=g and y=e(x),0,otherwise.W_{(f,y),(g,x)}= \begin{cases} 1,&f=g\ \text{and }y=e(x),\\ 0,&\text{otherwise}. \end{cases}W(f,y),(g,x)​={1,0,​f=g and y=e(x),otherwise.​

Thus it preserves the flag and applies eee to the other index. No finiteness or nonemptiness assumption is imposed on these types.

QAlgorithms.Papers.Independent.Extend50.P44.zeroEncoding

For every natural number NNN, this defines a complex matrix ZNZ_NZN​ whose rows and columns are indexed by {false,true}×{0,…,N−1}\{\mathrm{false},\mathrm{true}\}\times\{0,\ldots,N-1\}{false,true}×{0,…,N−1}, with entries

(ZN)(b,i),(c,j)={1,b=¬c and i=j,0,otherwise.(Z_N)_{(b,i),(c,j)} = \begin{cases} 1,&b=\neg c\ \text{and }i=j,\\ 0,&\text{otherwise}. \end{cases}(ZN​)(b,i),(c,j)​={1,0,​b=¬c and i=j,otherwise.​

Thus its nonzero entries connect each Boolean value to its complement while preserving the second index. For N=0N=0N=0, the index set is empty and this is the empty matrix.

Human review
  • Endorsed by Shuze Chen · Oct 30, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Gohan · Oct 30, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me