Finite quantum algorithms, query oracles, and simulation #
Ported from the corresponding upstream modules listed by the source sections below.
References beginning with Source name these retained sections.
Finite-dimensional complex Hilbert space for the query model #
A quantum state on a finite basis type H is a function ψ : H → ℂ, an operator
is a Matrix H H ℂ, and the action of an operator on a state is U *ᵥ ψ. We
keep this raw, in the same spirit as the adversary side of the project: the
inner product is a plain finite sum
qInner ψ φ = ∑ h, star (ψ h) * φ h,
conjugate-linear in the first argument, and the squared norm is
qNormSq ψ = ∑ h, ‖ψ h‖².
Why not EuclideanSpace ℂ H? Because most arguments downstream — the query
decomposition of a state by its index register, the progress measure of the
adversary lower bound, the oracle's action on a product basis — are
manipulations of finite sums over the basis, and WithLp/PiLp coercions get
in the way of exactly those. So the raw form is the default.
It is not a quarantine, though: qInner_eq_euclidean and qNormSq_eq_euclidean
below are public, and SourceQuantumProjector crosses by them deliberately,
building subspaces and orthogonal projectors in EuclideanSpace where Mathlib's
theory lives and carrying the results back as matrices. Raw by default, Euclidean
where Mathlib is stronger.
Main definitions #
qInner,qNormSq,IsQState(a unit vector).qBasis h— the computational basis state|h⟩.Matrix.unitaryGroup H ℂis Mathlib's;qPerm eis the unitary that sends|b⟩to|e b⟩, which is how every permutation oracle enters.IsQProjector Pand the reflectionqRefl P = 2P - 1.
Main results #
qInner_mulVec_mulVec,qNormSq_mulVec,IsQState.mulVec— a unitary preserves inner products, squared norms, and unit states.qInner_norm_le— Cauchy–Schwarz.qInner_mulVec_left— moving an operator across the inner product.qPerm_mem_unitaryGroup,qPerm_mulVec,qPerm_involutive.qRefl_mem_unitaryGroup,qRefl_mul_self.
The inner product #
The Hermitian inner product on H → ℂ, conjugate-linear in the first
argument (the physicists' convention, and Mathlib's).
Equations
- QuantumQueryComplexity.qInner ψ φ = star ψ ⬝ᵥ φ
Instances For
The squared norm of a state, as a real number.
Equations
- QuantumQueryComplexity.qNormSq ψ = ∑ h : H, Complex.normSq (ψ h)
Instances For
A (pure) quantum state: a unit vector.
Equations
Instances For
The Euclidean bridge #
The sanctioned crossing between the raw representation used everywhere here and
Mathlib's inner-product-space library. These two lemmas are public on
purpose: the reflection constructors of the upper bound build a subspace in
EuclideanSpace ℂ H, take Mathlib's Submodule.starProjection, transport it
back through WithLp.linearEquiv, and turn it into a matrix with
LinearMap.toMatrix'. That route needs to state its correctness in raw terms,
and these are the lemmas that let it.
Everything else in this section stays raw: the bridge is a door, not a move.
Basis states #
The computational basis state |h⟩.
Equations
Instances For
Unitaries #
A unitary preserves the squared norm.
A unitary maps states to states.
Permutation unitaries #
Every oracle in this development is a permutation of the computational basis, so
this is the workhorse. Note the inverse in the definition: Mathlib's
Equiv.Perm.permMatrix σ acts on coordinates by v ∘ σ, i.e. it sends the
basis state |b⟩ to |σ⁻¹ b⟩; qPerm e is normalized so that it sends |b⟩ to
|e b⟩.
The unitary that sends the basis state |b⟩ to |e b⟩.
Equations
Instances For
A permutation unitary sends basis states to basis states.
An involutive permutation gives a self-inverse unitary: query = unquery.
Projectors and reflections #
An orthogonal projector.
Equations
- QuantumQueryComplexity.IsQProjector P = (P.conjTranspose = P ∧ P * P = P)
Instances For
The reflection about the range of a projector, 2P - 1.
Equations
- QuantumQueryComplexity.qRefl P = 2 • P - 1
Instances For
A reflection is involutive.
Conjugating a projector by a unitary gives a projector.
A reflection is unitary.
The two counting bounds of the independent-run analysis #
Pure finite probability, stated over an arbitrary weight; no quantum imports.
sum_filter_ne_le_sum_coord— the union bound over coordinates: any weight of the patterns different from a target is at most the sum over coordinates of the weight of the patterns wrong at that coordinate. (A standalone utility, currently unused: the tuple join ended up using Weierstrass on the diagonal instead, and plurality amplification (SourceQuantumPlurality) uses the sharper exponential-moment argumentsum_prod_tail_lerather than a union bound.)sum_prod_majority_le— the majority tail: if each coordinate's wrong value carries probability at mostε ≤ 1, the product weight of the patterns with at leasttwrong coordinates is at most2^k·εᵗ. With per-run error1/16andt = ⌈k/2⌉this is≤ 2^{-k}— no Chernoff bound and no independence formalism: the product structure is supplied exactly by the bank-swap compiler, and the tail is one count over patterns.sum_prod_tail_le— the exponential-moment tail (moved here fromSourceQuantumPlurality, so that circuit utilities can use it without the lower-bound development): the weight of the records with at leasttwrong coordinates is at most(1 + ε)^k / 2^t. Unlike the majority tail it decays at base error1/3:(4/3)^k / 2^{k/2} = (8/9)^{k/2}.
The majority tail: patterns with at least t wrong coordinates carry
product weight at most 2^k·εᵗ.
The exponential-moment tail #
The exponential-moment tail. If each coordinate's wrong values carry
probability at most ε, the product weight of the records with at least t
wrong coordinates, times 2^t, is at most (1 + ε)^k: the weight of
2^{wrong} factorizes coordinatewise as ∏ (1 + Pr[wrong]) ≤ (1 + ε)^k,
and 2^t ≤ 2^{wrong} on the tail.
Fidelity bounds for a unitary, against a fixed vector and against a far pair #
The two generic Hilbert-space estimates behind the state-conversion
measurement. The quantity a Hadamard test reads out is Re⟪ψ, Uψ⟫, and the
detector U of SourceQuantumInputDetector is designed to make it large on one kind
of input and small on the other. This section proves the two sides in the
abstract, for an arbitrary unitary U on an arbitrary finite space:
- the positive side (
le_mul_re_qInner_mulVec_of_fixed): ifUfixesφ, thenRe⟪ψ, Uψ⟫ ≥ 2|⟪φ,ψ⟫|²/‖φ‖² − ‖ψ‖²— stated multiplied out by‖φ‖⁴, soφ = 0needs no special case and no division appears; - the negative side (
re_qInner_mulVec_le_of_perp): ifψ = ψN + ψForthogonally and‖UψF + ψF‖is small —Uis close to−1on the far part — thenRe⟪ψ, Uψ⟫ ≤ ‖ψ‖‖ψN‖ + ‖ψ‖‖UψF + ψF‖ − ‖ψF‖².
No spectral decomposition of U occurs. The positive bound is one
Cauchy–Schwarz application to the auxiliary vector χ = ‖φ‖²ψ − ⟪φ,ψ⟫φ, the
component of ‖φ‖²ψ orthogonal to φ: since U and Uᴴ both fix φ, the
plane spanned by φ and the pair χ, Uχ splits the form ⟪ψ, Uψ⟫ exactly,
and Cauchy–Schwarz on the χ-part is the only estimate. The negative bound
is Cauchy–Schwarz three times, with the orthogonality supplying the exact
−‖ψF‖² term.
Also here: qInner_mulVec_one_sub_mulVec, the orthogonality of a projector's
range and its complement's range on the same vector — the form in which the
chord windows enter the negative side downstream.
A unitary that fixes a vector: so does its adjoint.
The fidelity lower bound. A unitary that fixes φ satisfies, on every
ψ, Re⟪ψ, Uψ⟫ ≥ 2|⟪φ,ψ⟫|²/‖φ‖² − ‖ψ‖² — multiplied out by ‖φ‖⁴, so no
positivity of ‖φ‖ is assumed and no division appears.
The fidelity upper bound. If ψ splits orthogonally into a near part
ψN and a far part ψF on which the unitary is close to −1, then
Re⟪ψ, Uψ⟫ ≤ ‖ψ‖‖ψN‖ + ‖ψ‖‖UψF + ψF‖ − ‖ψF‖².
A projector's range is orthogonal to its complement's range, on the same vector. The form in which the chord-window decomposition enters the fidelity bound.
Computational-basis measurement #
A measurement of the final state of a query algorithm is a projective
measurement in the computational basis, coarse-grained by a readout map
p : H → O that says which output each basis state announces. So the only
definition needed is
qProb p ψ o = ∑ h with p h = o, ‖ψ h‖²,
the probability of announcing o. Deferring all measurements to the end is
without loss of generality in the query model, and general POVMs are not needed
for the characterization (see the plan, §"Design Decisions").
The companion definition qRestrict p o ψ is the unnormalized post-measurement
state; it is what turns statements about probabilities into statements about
inner products, which is how the adversary lower bound consumes the output
condition (∑ o, qRestrict p o ψ = ψ, and distinct outcomes are orthogonal).
The unnormalized part of ψ that announces the outcome o.
Instances For
The probability that measuring ψ announces the outcome o.
Equations
- QuantumQueryComplexity.qProb p ψ o = ∑ h : H, if p h = o then Complex.normSq (ψ h) else 0
Instances For
Measuring a basis state announces its readout with certainty.
The distance-to-success bridge #
None of this needs [Fintype O] — the sums range over H alone — and the
cardinality-free extraction depends on exactly that: the bridge from a
conversion-distance bound to a success probability must not reintroduce an
output-cardinality assumption.
Restriction is the best sector approximation: against any φ
supported on the o-sector, the unannounced mass of ψ is dominated.
The distance-to-success bridge, output-cardinality-free: a state
within squared distance δ of one supported on the o-sector announces
o with probability at least qNormSq ψ − δ.
The outcomes partition the norm #
Two distinct outcomes cannot both be likely. This is what forbids a single state from answering two different questions, and hence what makes the query model unable to compute an unobservable distinction.
The probability of announcing anything other than o is 1 - qProb p ψ o.
The post-measurement decomposition #
The inner product decomposes over the outcomes. This is the form the adversary lower bound uses, with the readout map taken to be the query-index register: it splits a state into the sectors the oracle acts on independently.
The value oracle #
The basis of a query algorithm is
QBasis ι σ W = Option ι × Option σ × W
— a query-index register (none = idle, no query is made), an answer register
(none = blank), and a workspace. On input a : ι → σ the oracle acts as the
identity on the idle sector and, on the index some i, swaps the blank answer
with the answer some (a i):
|i⟩|⊥⟩|w⟩ ↦ |i⟩|a i⟩|w⟩, |i⟩|a i⟩|w⟩ ↦ |i⟩|⊥⟩|w⟩,
leaving |i⟩|s⟩|w⟩ alone for every other answer s.
Why this oracle rather than |i⟩|s⟩ ↦ |i⟩|s ⊕ a i⟩:
- it is defined for any finite alphabet, with no group structure on
σ; - it is a permutation of the basis, hence unitary for free, and an involution, so query and unquery are literally the same matrix;
- the idle index gives controlled queries at no extra cost, which is what the phase-detection circuit of the upper bound will need;
- on a blank answer register it returns the value coherently, which is all the lower bound's query decomposition uses.
It is equivalent to the Boolean XOR oracle at two queries per query, in both
directions: SourceQuantumXorOracle defines that oracle (with explicit idle-index
and blank-answer sectors) and SourceQuantumSimulation proves the equivalence.
The two lemmas that carry the whole development are oracleMap_none and
oracleMap_some: the oracle's action at a basis state with index some i
depends on the input only through a i. That is the source of the
adversary lower bound's query decomposition.
The basis of a query algorithm: query index (none = idle), answer register
(none = blank), and workspace.
Instances For
Equations
Equations
- QuantumQueryComplexity.instQBasisFintype = { elems := Finset.univ ×ˢ Finset.univ, complete := ⋯ }
The oracle's action on the computational basis.
Equations
Instances For
The oracle never moves the index register.
The oracle as a permutation of the basis.
Equations
Instances For
The oracle unitary.
Equations
Instances For
Query = unquery.
On the idle sector the oracle does nothing: this is what makes a query controlled.
The query decomposition. At a basis state with query index some i the
queried state depends on the input only through a i.
Two inputs that agree at the index i give the same amplitude at every
basis state querying i; two inputs always agree on the idle sector.
Quantum query algorithms #
A quantum query algorithm is an initial unit state on QBasis ι σ Work, a
sequence of input-independent unitaries, and a readout map for the final
computational-basis measurement. On input a : ι → σ it evolves as
ψ₀ = U₀ |init⟩, ψ_{t+1} = U_{t+1} O_a ψ_t,
so A.state a t is the state after t queries; A.prob a t o is the
probability that measuring it announces o. This is the standard
deferred-measurement form of the model.
Design notes #
- The unitaries are indexed by all of
ℕ. An algorithm is not tied to a query count: the query count is the timetat which one reads off the answer. This removes everyFin (q+1)cast from the development, and makes "the same algorithm run longer" a statement aboutt, not a new structure. - The workspace
Wis a parameter, not a field. Bundling it inside the structure makesA.Workappear in the index type of every matrix, and thenrwand instance search fail on goals that are true byrfl(the typeQBasis ι σ A.Workis only definitionally the concrete workspace a construction used). Quantifying overWis deferred toQueryCountsinSourceQuantumComplexity, which is the one place it costs anything. Everything lives inType(universe 0): every index type, alphabet and workspace in this project is concrete. - Correctness is stated promise-natively, through
read : X → ι → σ. The total case isX = (ι → σ)withread = id.
Main results #
QAlg.state_isQState— the algorithm's state is a unit vector at all times.computesWithErrorOn_const— a constant function needs no queries.computesWithErrorOn_proj— one query reads one coordinate exactly.
A quantum query algorithm with output type O and workspace W.
The initial state.
The initial state is a unit vector.
Each step is unitary.
- readout : QBasis ι σ W → O
The final measurement's readout map.
Instances For
The state of A on input a after t queries.
Equations
Instances For
The state stays a unit vector.
The probability that A, run for t queries on input a, announces o.
Equations
- A.prob a t o = QuantumQueryComplexity.qProb A.readout (A.state a t) o
Instances For
Bounded-error correctness #
A computes f on the promise read with error at most ε in q
queries.
Equations
- QuantumQueryComplexity.ComputesWithErrorOn A q read f ε = ∀ (x : X), 1 - ε ≤ A.prob (read x) q (f x)
Instances For
Two sanity constructions #
These are the smallest end-to-end uses of the model: they exercise the oracle's action on a basis state and the measurement rule, and they are the base cases of every later construction.
The zero-query algorithm that always announces c.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A constant function needs no queries.
The one-query algorithm that queries the coordinate i and announces the
answer register.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One query reads one coordinate, exactly.
Workspace extension and register-indexed families #
Extending a workspace by a register V and acting block-diagonally on it is
the single primitive behind two things the circuit layer needs: lifting an
operator to a larger workspace (a constant family) and controlling it on a
register value (a family that is the identity elsewhere).
blockFam fam applies fam v on the sector where the extra register holds v.
It is defined as Mathlib's Matrix.blockDiagonal read through the reindexing
regEquiv : QBasis ι σ (V × W) ≃ QBasis ι σ W × V, so the algebra —
multiplicativity, unit, adjoint — is inherited rather than re-proved.
Acceptance contracts #
blockFam_mul,blockFam_one,blockFam_conjTranspose,blockFam_mem_unitaryGroup— it is a monoid map into the unitaries.blockFam_mulVec_embed— its action on the encoded subspaceembedReg v ψ, the sector where the register holdsv. This is the only form in whichblockFamgets used: statements about a controlled operator are statements about encoded states, never global matrix identities.blockFam_oracle— the oracle ignores the workspace, so on an extended workspace it is a constant block family. This is what lets a query pass through a workspace extension unchanged.
A register-indexed family of operators, acting block-diagonally on the extra register.
Equations
Instances For
Lift an operator to an extended workspace: the constant family.
Equations
- QuantumQueryComplexity.liftReg V U = QuantumQueryComplexity.blockFam fun (x : V) => U
Instances For
The algebra #
The encoded subspace #
The encoded subspace: ψ, placed in the sector where the extra register
holds v.
Instances For
The sectors are orthogonal #
The embedding is linear and isometric onto its own sector, and distinct register values give orthogonal sectors. Everything a superposition over the register needs — Pythagoras for a packed family, in particular — comes from these.
Split a sum over the extended basis as (rest, extra register).
Distinct register values give orthogonal sectors, and the embedding preserves the inner product on its own.
Operators on the extra register itself #
blockFam acts on the workspace, indexed by the register. Its transpose —
acting on the register, trivially on the workspace — is the other primitive a
clocked construction needs, and it is Mathlib's Kronecker product with the
identity, so again the algebra is inherited rather than re-proved.
An operator acting on the extra register alone, as the identity elsewhere.
Equations
- QuantumQueryComplexity.regOp A = (Matrix.kroneckerMap (fun (x1 x2 : ℂ) => x1 * x2) 1 A).submatrix ⇑QuantumQueryComplexity.regEquiv ⇑QuantumQueryComplexity.regEquiv
Instances For
The action on the encoded subspace: A moves the register, leaving the
workspace vector alone.
The oracle passes through a workspace extension #
The oracle leaves the extra register alone.
The oracle ignores the workspace, so on an extended workspace it is a constant block family.
Bounded-error quantum query complexity #
qQueryOn read f ε is the least number of queries with which some algorithm
computes f on the promise read with error at most ε, and
boundedErrorQQueryOn fixes the conventional ε = 1/3.
Two API shapes matter downstream and they are not symmetric:
- Upper bounds (
qQueryOn_le) are unconditional: exhibiting one algorithm bounds the infimum. - Lower bounds (
le_qQueryOn) need the achievable set to be nonempty, becausesInf ∅ = 0inℕ. The hypothesis is discharged once and for all by an exact algorithm for every observationally determined problem; until that is in place every lower bound carrieshneexplicitly rather than hiding the gap.
The set of query counts at which f is computable with error ≤ ε. The
workspace is existentially quantified here — this is the one place where that
costs anything, and it keeps QAlg free of a bundled type field.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bounded-error quantum query complexity on a promise.
Equations
- QuantumQueryComplexity.qQueryOn read f ε = sInf (QuantumQueryComplexity.QueryCounts read f ε)
Instances For
The conventional error convention.
Equations
- QuantumQueryComplexity.boundedErrorQQueryOn read f = QuantumQueryComplexity.qQueryOn read f (1 / 3)
Instances For
Quantum query complexity of a total function.
Equations
Instances For
The conventional error convention, for a total function.
Equations
Instances For
Upper bounds #
Trap: in the existential above the two instance components must be supplied
with inferInstance. Writing ⟨W, _, _, A, h⟩ and letting unification solve
them from A's type sends isDefEq into a loop (it does not terminate even at
2·10⁶ heartbeats).
One algorithm bounds the complexity.
Lower bounds and the optimal witness #
The infimum is attained: an optimal algorithm exists as soon as any algorithm does.
A bound valid for every algorithm bounds the complexity from below.
The real-valued form, which is what the adversary lower bound produces.
Monotonicity in the error #
Restriction to a promise #
A promise problem whose output is a function of the observations is no
harder than the total problem: run the total algorithm on the promised
observations. No injectivity and no structure on read are needed.
A total algorithm, run on the promised observations.
The restriction bound: Q_ε(f ∘ read on the promise) ≤ Q_ε(f). This
is what turns a promise lower bound into a lower bound on the honest total
function.
The constant case #
A constant function has quantum query complexity zero.
Query routines: a composable layer above QAlg #
QAlg is a whole algorithm — an initial state, a schedule, and a readout — and
its schedule has an exact length. Circuit constructions need something smaller
and composable: an operator built from queries, which can be sequenced,
inverted, and controlled, and whose query count is tracked exactly. That is a
QRoutine:
R.run a = U_len · O_a · U_{len-1} · ⋯ · O_a · U_0, exactly R.len queries.
A routine carries no initial state and no readout, so it composes; R.toAlg
turns one into a QAlg at the end, and toAlg_state says the algorithm's state
after R.len queries is R.run a applied to the initial state. So everything
proved about QAlg — in particular the operational lower bound — applies to
whatever the routine layer builds, with no change to the pinned statements.
Main results #
run_mem_unitaryGroup— a routine is a unitary for every input.toAlg_state— the bridge toQAlg.comp_run— sequencing:(R.comp S).run a = S.run a * R.run awith(R.comp S).len = R.len + S.len. Query counts add exactly; the boundary unitariesS.step 0andR.step R.lenare merged into one, which is why no query is wasted at the junction.exists_inv— inversion: every routine has an inverse routine of the same length. This is where the oracle being an involution pays:Oᴴ = O, so reversing a schedule costs no extra queries.runUpto_congr— routines agreeing on steps0 … lenhave the same run, which is what lets constructions specify a schedule only where it matters.
A query routine: len oracle calls interleaved with input-independent
unitaries.
- len : ℕ
The number of queries.
Each step is unitary.
Instances For
The adjoint of a unitary is unitary.
The operator implemented by the first t queries of R, with the opaque
oracle matrix Q in place of the transposition oracle.
Equations
- QuantumQueryComplexity.QRoutine.runWith Q R 0 = R.step 0
- QuantumQueryComplexity.QRoutine.runWith Q R t.succ = R.step (t + 1) * (Q * QuantumQueryComplexity.QRoutine.runWith Q R t)
Instances For
Only the steps up to t matter.
The operator implemented by the first t queries of R.
Equations
Instances For
The operator implemented by R, using exactly R.len queries.
Instances For
Only the steps up to t matter for the first t queries.
Turn a routine into an algorithm by supplying an initial state and a readout.
Equations
Instances For
The bridge. The algorithm's state after t queries is the routine's
operator applied to the initial state.
Sequencing #
Sequencing: run R, then S. The two boundary unitaries are merged,
so the query count is exactly R.len + S.len.
Equations
Instances For
The standard semantics is the transposition-oracle instance.
Sequencing, parametrically #
Sequencing against any oracle: the mirror of comp_run.
Sequencing, at the level of operators.
Padding by two #
Padding by an even number of queries is free and needs no extra workspace: the
oracle is an involution, so a query immediately followed by a query is the
identity. Padding by one is a different matter — it needs somewhere to park
the query index so that the extra query idles — and lives in SourceQuantumControl.
Append two queries that cancel.
Equations
Instances For
Padding by two changes nothing.
Inversion #
The oracle is an involution with real entries, so it is self-adjoint; reversing
a schedule therefore costs no extra queries. That is the content of the
Oᴴ = O step below, and it is the reason the value oracle was chosen to be a
transposition in the first place.
Inversion. Every routine has an inverse routine of the same length.
Zero-query constructors, and an explicit inverse #
A zero-query routine: just a unitary.
Equations
- QuantumQueryComplexity.QRoutine.ofUnitary U hU = { len := 0, step := fun (x : ℕ) => U, step_unitary := ⋯ }
Instances For
The zero-query identity routine.
Instances For
The one-query routine: a single bare oracle call.
Equations
- QuantumQueryComplexity.QRoutine.query = { len := 1, step := fun (x : ℕ) => 1, step_unitary := ⋯ }
Instances For
An explicit inverse routine, chosen once from exists_inv.
Instances For
Conjugation and iteration #
Conjugate a fixed unitary by a routine: run R, apply U, run R
backwards. Costs 2 · R.len queries — no more, because inversion is free.
Instances For
Run R n times in sequence.
Equations
Instances For
The same bridge read backwards: an algorithm's state is the run of the routine formed from its own steps.
The controlled query, and idling #
The value oracle has an idle index none, and SourceQuantumOracle records that it
does nothing there. That is only half of what a circuit needs: to use the
idle sector one must be able to move the query index into it and back, and
"assign none to the index register" is not injective, hence not unitary.
The fix is the same one SourceQuantumReadAll used for copying: swap, don't assign.
Extend the workspace with a control bit and a parking slot,
CtrlWork ι W = Bool × Option ι × W,
and let parkMat swap the index register with the parking slot exactly when the
control bit is false. Then
ctrlQuery a = parkMat · O_a · parkMat
contains exactly one oracle factor and satisfies
ctrlQuery_qBasis_true— on controltrueit is the query;ctrlQuery_qBasis_false— on controlfalsewith a blank slot it is the identity: the physical query is spent on the idle index.
So one physical query implements the controlled logical query, which is what
phase detection will need, and what makes an idle query available for padding a
schedule by one (padOne; padding by two needs no workspace at all, see
QRoutine.padTwo).
IsParked names the sector this all happens in — control false, slot blank —
and ctrlQuery_mulVec_of_parked upgrades the basis-state statement to states
supported there, which is the form a padding argument consumes.
The workspace of a controlled routine: a control bit, a parking slot for the query index, and the original workspace.
Instances For
Equations
Equations
- QuantumQueryComplexity.instCtrlWorkFintype = { elems := Finset.univ ×ˢ Finset.univ, complete := ⋯ }
Parking #
Swap the query-index register with the parking slot, unless the control bit says otherwise.
Equations
Instances For
Parking, as a permutation of the basis.
Equations
Instances For
Parking, as a unitary.
Equations
Instances For
The controlled query #
The controlled query: park, query, unpark. Note the single oracleMat
factor — this costs exactly one physical query.
Equations
Instances For
The basis action of the controlled query.
Equations
Instances For
On the control-true sector the controlled query is the query.
On the control-false sector with a blank slot the controlled query is the identity: the physical query is spent on the idle index.
The parked sector #
A state is parked if it lives where the control bit is false and the
parking slot is blank — the sector on which a query idles.
Equations
- QuantumQueryComplexity.IsParked ψ = ∀ (p : QuantumQueryComplexity.QBasis ι σ (QuantumQueryComplexity.CtrlWork ι W)), ψ p ≠ 0 → p.2.2.1 = false ∧ p.2.2.2.1 = none
Instances For
A parked state does not notice a query. This is the form a padding argument consumes.
Idling and padding by one #
The controlled query as a one-query routine.
Equations
- QuantumQueryComplexity.ctrlQueryRoutine = { len := 1, step := fun (x : ℕ) => QuantumQueryComplexity.parkMat, step_unitary := ⋯ }
Instances For
Padding by one query.
Instances For
Padding by one is free on the parked sector.
Controlled execution of a whole routine #
A fixed step is controlled by lifting it to the parked workspace and
conditioning on the control bit — both instances of blockFam. A query is
controlled by ctrlQuery. Neither adds a query, so control_len is an
equality.
The statements are about the encoded subspace embedCtrl b ψ — control bit
b, parking slot blank — and not global matrix identities, which would be
false: off that subspace ctrlQuery swaps a parked index back in and queries
it.
The blank-slot embedding: ψ in the sector with control bit b and an
empty parking slot.
Equations
Instances For
A fixed step, lifted to the parked workspace and conditioned on the control bit.
Equations
- QuantumQueryComplexity.ctrlStep U = QuantumQueryComplexity.blockFam fun (b : Bool) => bif b then QuantumQueryComplexity.liftReg (Option ι) U else 1
Instances For
The controlled routine, built one query at a time.
Equations
- One or more equations did not get rendered due to their size.
- QuantumQueryComplexity.controlUpto R 0 = QuantumQueryComplexity.QRoutine.ofUnitary (QuantumQueryComplexity.ctrlStep (R.step 0)) ⋯
Instances For
Controlled execution of a routine.
Equations
Instances For
Controlling a routine costs no extra queries.
On the control-true sector the controlled routine runs.
On the control-false sector it does nothing — and still spends exactly
R.len physical queries.
Lifting an operator along a factorizing equivalence #
The generic tool of the independent-run compiler. A basis equivalence
e : β ≃ γ × δ splits a space into a system and an environment;
kronLift e M is M ⊗ 1 read through e, so its algebra is inherited from
Mathlib's Kronecker product exactly as blockFam's came from
blockDiagonal. The two working lemmas:
kronLift_mulVec_splitVec— on a split statesplitVec e φ ξ = φ((e·).1)·ξ((e·).2)the lift acts on the system factor alone;kronLiftRoutine_runUpto_splitVec— a routine's steps lifted along an oracle-compatible equivalence (one that carries the global query registers into the system factor:e (oracleMap a p) = (oracleMap a (e p).1, (e p).2)) run, against the real oracle, as the original routine on the system factor. The compatibility is stated at the map level, so no matrix identity for the oracle is ever needed.
M ⊗ 1, read through the factorizing equivalence e.
Equations
- QuantumQueryComplexity.kronLift e M = (Matrix.kroneckerMap (fun (x1 x2 : ℂ) => x1 * x2) M 1).submatrix ⇑e ⇑e
Instances For
The lifted routine #
e is oracle-compatible when it carries the global query registers
into the system factor and the environment rides along.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The oracle preserves split states along an oracle-compatible equivalence, acting on the system factor.
A routine's steps, lifted along e.
Equations
- QuantumQueryComplexity.QRoutine.kronLift e R = { len := R.len, step := fun (t : ℕ) => QuantumQueryComplexity.kronLift e (R.step t), step_unitary := ⋯ }
Instances For
The lifted routine runs as the original on the system factor.
Classical postprocessing of the readout #
Relabelling an algorithm's measurement outcome costs nothing: QAlg.postcomp
changes only the readout field, so the state — which is built from init
and step alone — is literally unchanged, and the fibre sum can only grow
the correct outcome's probability (qProb_comp_ge).
At the complexity level this is qQueryOn_postcomp_le : Q_ε(g ∘ f) ≤ Q_ε(f),
the workhorse for reading a Boolean test off a large-valued output: it is how
a lower bound proved for a Boolean postprocessing transfers to the function
itself, and it is what makes lower bounds available for outputs whose type is
too big (or infinite) for the Fintype-output machinery.
Post-composing the readout can only increase the probability of the image outcome.
Relabelling the readout: same initial state, same steps, composed output map.
Equations
Instances For
Post-composition at the algorithm level: same cost, same error, the composed function.
The workspace-existential form, for callers that quantify it away.
Every achievable query count survives postprocessing — the mirror of
queryCounts_subset_of_read.
Classical postprocessing of the readout is free: post-composing the output function can only lower the quantum query complexity.
Reading the whole input exactly #
Every observationally determined problem has an exact algorithm making
|ι| queries. This is the theorem that makes qQueryOn a genuine minimum
rather than sInf ∅ = 0, and it is the base case of the query model: it says
the model can do at least what a classical algorithm can.
The construction records the answers in a workspace QRec ι σ = ι → Option σ
and never leaves the computational basis. Two families of basis permutations
do all the work:
idxSwapPerm u v— transpose the two index-register valuesuandv. Since the index register's content is known at each time (it isidxAt t), a transposition suffices to move it to the next index; "assign the index register" would not be unitary, but "transpose the value it holds with the one it should hold next" is.slotSwapPerm j— swap the answer register with the workspace slotj. A swap, not a copy: copying is not injective, but the slot is blank when the swap happens, so the swap has the effect of a copy and clears the answer register for the next query.
The step unitary at time t is idxSwapPerm (prevIdx t) (idxAt t) after
slotSwapPerm (prevIdx t), and the invariant carried by the induction is
state a t = |idxAt t⟩ |⊥⟩ |recAt a t⟩,
with recAt a t the record holding the answers of the first t indices. It
holds for every t, with no side condition: past |ι| the index register is
idle, the oracle acts trivially and the state stops moving, so the algorithm
pads for free.
Two families of basis permutations #
Transpose two values of the query-index register.
Equations
- QuantumQueryComplexity.idxSwapMap u v p = ((Equiv.swap u v) p.1, p.2)
Instances For
The index-register transposition, as a permutation of the basis.
Equations
Instances For
The workspace of the exact algorithm: a record of the answers seen so far.
Equations
- QuantumQueryComplexity.QRec ι σ = (ι → Option σ)
Instances For
Swap the answer register with the workspace slot j.
Equations
- QuantumQueryComplexity.slotSwapMap j p = (p.1, p.2.2 j, Function.update p.2.2 j p.2.1)
Instances For
The slot swap at an optional index: at none there is nothing to store, so
the algorithm idles. This is what lets one formula describe every step.
Equations
Instances For
The schedule #
The index queried at time t; none once every index has been read.
Equations
- QuantumQueryComplexity.idxAt ι t = if h : t < Fintype.card ι then some ((Fintype.equivFin ι).symm ⟨t, h⟩) else none
Instances For
The index queried at time t - 1, i.e. the one whose answer the step at time
t has to store.
Equations
Instances For
The record #
The workspace after t queries: the answers at the first t indices.
Equations
- QuantumQueryComplexity.recAt a t i = if ↑((Fintype.equivFin ι) i) < t then some (a i) else none
Instances For
Once every index has been read the record is complete.
Storing the answer at the index read at time t advances the record.
The slot the algorithm is about to write to is blank.
The algorithm #
The algorithm that reads every coordinate, announcing dec of the
completed record.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant. After t queries the algorithm holds the record of the
first t answers, with the index register pointing at the next index and the
answer register blank.
The algorithm announces dec of the full input after |ι| queries.
Every observationally determined problem is exactly solvable #
The readout: decode a completed record into the value of f. Well defined
by observational determinacy — two promise inputs with the same record are
indistinguishable, hence have the same f-value.
Equations
- QuantumQueryComplexity.recDecode read f w = if h : ∃ (x : X), ∀ (i : ι), w i = some (read x i) then f h.choose else Classical.arbitrary O
Instances For
Every observationally determined problem has an exact |ι|-query
algorithm. In particular the set of achievable query counts is nonempty, so
qQueryOn is a genuine minimum.
The achievable set is nonempty, which is the hypothesis every lower
bound in SourceQuantumComplexity carries.
Reading everything is enough: qQueryOn ≤ |ι|.
Running a routine against an arbitrary oracle matrix #
The QRoutine.runWith semantics and composition laws are proved alongside
QRoutine in SourceQuantumRoutine. The standard runUpto semantics is their
transposition-oracle specialization. Both the standard and XOR simulation
compilers use the shared arbitrary-oracle implementation.
The uniform alphabet factorization #
This alphabet factorization removes the √|σ| loss in uniform extraction.
A dual solution has to realise the inequality indicator [a ≠ b] as an
inner product of vectors attached to the two letters. The construction used
so far copies a value onto every letter that differs, so its norms grow like
√|σ|. The uniform replacement lives on Option σ — one extra "constant"
coordinate beside the σ-indexed ones. The vectors live in an ambient space
of dimension |σ| + 1, but each is supported on exactly two coordinates;
they are two-sparse independently of the alphabet size:
μ a = (1, e a) ν b = (1, − e b)
⟨μ a, ν b⟩ = 1 − δ_{ab} = [a ≠ b]
‖μ a‖² = ‖ν b‖² = 2
The constant coordinate contributes 1 to every pairing; the letter
coordinates contribute −1 exactly when the letters agree, cancelling it.
Both squared norms are 2 — equivalently both norms are √2 —
independently of the alphabet size, which is the whole point.
The left vector of the factorization: 1 on the constant coordinate and
1 at its own letter.
Equations
- QuantumQueryComplexity.uniformLeft a none = 1
- QuantumQueryComplexity.uniformLeft a (some j) = if j = a then 1 else 0
Instances For
The right vector: 1 on the constant coordinate and −1 at its own
letter.
Equations
- QuantumQueryComplexity.uniformRight b none = 1
- QuantumQueryComplexity.uniformRight b (some j) = if j = b then -1 else 0
Instances For
The factorization: the pairing is the inequality indicator.
Both squared norms are 2 — equivalently both norms are √2 —
independently of the alphabet size.
The factorization in the form the dual constraint consumes: the pairing vanishes exactly when the letters agree, i.e. when the query does not distinguish the two inputs.
The Hadamard test, compiled #
The generic measurement layer of the algorithm extraction: given a routine R
and a unit vector u, the Hadamard test prepares
(|0⟩ + |1⟩)/√2 ⊗ u, runs R controlled on the first qubit, applies a
Hadamard to it, and measures it. The whole point:
P(announce true) = (1 + Re⟪u, R.run a · u⟫)/2
P(announce false) = (1 − Re⟪u, R.run a · u⟫)/2
(hadTest_prob_true / hadTest_prob_false) — the test turns the real part of
the expectation ⟪u, R_a u⟫, which the fidelity bounds of SourceQuantumFidelity
control, into an outcome probability, at exactly R.len queries
(QRoutine.control costs R.len, the Hadamards are free).
The compilation reuses the existing plumbing wholesale: QRoutine.control
for the controlled run, regOp for the Hadamard on the control register,
comp/ofUnitary for the final gate, and toAlg for the bridge to QAlg.
The announcement convention is true on control 0: the detector this test
will be applied to is ≈ +1 on the accepting side, so acceptance is
constructive interference back onto |0⟩.
hadMat is real symmetric, and everything about it is decided entrywise over
Bool — no 2 × 2 matrix theory is imported.
The Hadamard gate, on the control register #
1/√2, as a complex scalar.
Equations
Instances For
The Hadamard gate on one qubit: (1/√2)·(−1)^{b·b'}.
Equations
- QuantumQueryComplexity.hadMat = Matrix.of fun (b b' : Bool) => if (b && b') = true then -QuantumQueryComplexity.hadS else QuantumQueryComplexity.hadS
Instances For
The Hadamard on the control register of CtrlWork.
Equations
Instances For
The Hadamard acts on the control sectors as its column says.
Sector algebra #
The test #
The Hadamard-test initial state: (|0⟩ + |1⟩)/√2 ⊗ u.
Equations
Instances For
The Hadamard test of R on u: controlled-R between two Hadamards
on a control qubit, measuring the control. Announces true on control 0.
Costs exactly R.len queries.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The final state of the test, exactly: interference between u and
R_a u, sorted by the control bit.
The measurement rule of the sorted state.
The acceptance probability of the Hadamard test.
The rejection probability of the Hadamard test.
The independent-run compiler: exact product statistics #
Two algorithms, compiled into one whose outcome distribution is the exact product of theirs — the engine of amplification and of the finite-output construction.
Banks, not uncompute. The compiled workspace holds a full
QBasis ι σ Wⱼ-valued bank for each algorithm; the global initial state is
the tensor product of the two initial states parked in their banks, with
blank global query registers. Phase j swaps bank j into the active
position (a basis permutation exchanging the global query/answer registers
with the bank's stored pair), runs algorithm j's schedule lifted along the
oracle-compatible equivalence pairEquivⱼ (SourceQuantumKronLift), and swaps back.
Each phase therefore acts on a pristine tensor factor: no uncompute, no
factor two in the cost, and the final state is literally
prodState blank (A₁.state a q₁) (A₂.state a q₂),
so the joint measurement factorizes exactly (qProb_pairReadout).
Realizes read q P packages "some algorithm has outcome distribution P
after q queries"; Realizes.pair is the compiler, Realizes.map reshapes
outcomes through the readout for free, and Realizes.fold iterates the pair
into a k-tuple with product statistics at cost ∑ qⱼ.
The two factorizing equivalences and the two swaps #
Phase 1's view: system = (global registers, bank 1's workspace), environment = (bank 1's parked registers, bank 2).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Swap the global query/answer registers with bank 1's parked pair.
Equations
Instances For
Swap the global query/answer registers with bank 2's parked pair.
Equations
Instances For
The swap-in unitary for bank 1.
Equations
Instances For
The swap-in unitary for bank 2.
Equations
Instances For
Product states #
Blank global registers.
Instances For
The phase actions #
The compiled routine #
The pair compiler: swap in bank 1, run schedule 1 lifted, swap out;
swap in bank 2, run schedule 2 lifted, swap out. R₁.len + R₂.len
queries.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The compiled run is the product of the runs.
The joint measurement factorizes #
Some algorithm has outcome distribution P after q queries.
Equations
- QuantumQueryComplexity.Realizes read q P = ∃ (W : Type) (x : Fintype W) (x_1 : DecidableEq W) (A : QuantumQueryComplexity.QAlg ι σ O W), ∀ (x_2 : X) (o : O), A.prob (read x_2) q o = P x_2 o
Instances For
Every distribution an algorithm realizes is one the model measures: values are probabilities of the final state.
The pair compiler, packaged: two realizable distributions have a jointly realizable product, at the sum of the costs.
Reshaping the outcome through the readout is free.
The bijective special case: relabel the outcomes.
The standard Boolean XOR oracle, and its query model #
The conventional oracle for Boolean inputs: on the answer register,
|i⟩|b⟩|w⟩ ↦ |i⟩|b ⊕ a i⟩|w⟩,
with an idle index (none, no query) and a fixed blank answer — on this
model's basis QBasis ι Bool W the answer register is Option Bool, the XOR
acts on the some-part, and both none sectors are fixed. Boolean
specifically: for an arbitrary alphabet there is no canonical XOR directly
on σ without choosing a group structure, so the simulation theorems start
here. The upstream construction (upstream OneHot.lean) instead XORs an encoding of the letter
— its one-hot code in Hot σ := σ → Bool — which needs no structure on σ.
Like the transposition oracle it is a basis permutation and an involution, so unitarity and query = unquery are free.
The model: QAlg is oracle-agnostic data (initial state, steps, readout);
only the state semantics names the oracle. xorState is QAlg.state with
xorOracleMat in place of oracleMat, and XorComputesWithErrorOn,
XorQueryCounts, xorQQueryOn mirror the standard model's definitions
verbatim. SourceQuantumSimulation proves the two models equivalent within a factor
of two in the query count.
The XOR on an optional Boolean #
The oracle #
The XOR oracle's action on the computational basis.
Equations
Instances For
The XOR oracle as a permutation of the basis.
Equations
Instances For
The XOR oracle unitary.
Equations
Instances For
Query = unquery, here too.
The XOR query model #
QAlg carries no oracle; the state semantics does. These definitions mirror
QAlg.state, ComputesWithErrorOn, QueryCounts, and qQueryOn with the
XOR oracle substituted.
The state of A on input a after t XOR queries.
Equations
- QuantumQueryComplexity.xorState A a 0 = (A.step 0).mulVec A.init
- QuantumQueryComplexity.xorState A a t.succ = (A.step (t + 1)).mulVec ((QuantumQueryComplexity.xorOracleMat a).mulVec (QuantumQueryComplexity.xorState A a t))
Instances For
The bridge to the parametric run: the XOR state is runWith of the
algorithm's step schedule, packaged with any length.
A computes f on the promise read with error at most ε in q
XOR queries.
Equations
- QuantumQueryComplexity.XorComputesWithErrorOn A q read f ε = ∀ (x : X), 1 - ε ≤ QuantumQueryComplexity.qProb A.readout (QuantumQueryComplexity.xorState A (read x) q) (f x)
Instances For
The achievable XOR-query counts.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Quantum query complexity in the XOR-oracle model.
Equations
- QuantumQueryComplexity.xorQQueryOn read f ε = sInf (QuantumQueryComplexity.XorQueryCounts read f ε)
Instances For
Folding the pair compiler: tuples, majority, and joint correctness #
The k-fold iteration of Realizes.pair, and its two consumers:
amplify— majority overkindependent runs of a Boolean algorithm. The record statistics are an exact product, so the failure probability is the pattern countsum_prod_majority_le: at per-run errorεthe amplified error is2^k·ε^{⌈k/2⌉}; at the nativeε = 1/16this is≤ 2^{-k}.exists_tuple_computes—BBoolean algorithms joined into one computing the tuple, with error∑ εᵢ(the product of the diagonal probabilities, bounded by Weierstrass).
Costs add exactly throughout — the bank-swap compiler has no uncompute overhead.
The k-fold product realization over any decidable output type #
The trivial realization: no runs, the constant distribution 1 on the
empty record.
The k-fold product realization over any decidable output type: costs
add, distributions multiply.
The base and the cons step #
Prepending a coordinate to a Boolean tuple.
Instances For
The trivial realization: no runs, the constant distribution 1 on the
empty tuple.
The k-fold product realization: costs add, distributions
multiply.
Probabilities sum to one.
Majority amplification #
Majority amplification. k independent runs of a Boolean algorithm
with error ε ≤ 1 compute the same function with error 2^k·ε^{⌈k/2⌉}, at
k times the cost.
Joining Boolean algorithms into a tuple #
The tuple compiler: B Boolean algorithms joined into one computing
the tuple function, at the sum of the costs and the sum of the errors.
Oracle simulation: transposition ↔ XOR, at two queries per query #
The model-equivalence theorem for Boolean input
alphabets. Each direction is one two-query gadget on a clean-ancilla
encoded subspace (embedReg with an Option Bool ancilla register), compiled
over whole routines at exactly 2·R.len queries, and exported as a
QueryCounts translation:
q ∈ XorQueryCounts read f ε → 2q ∈ QueryCounts read f ε
q ∈ QueryCounts read f ε → 2q ∈ XorQueryCounts read f ε
with the complexity inequalities
qQueryOn read f ε ≤ 2 · xorQQueryOn read f ε
xorQQueryOn read f ε ≤ 2 · qQueryOn read f ε.
The gadgets. With ancilla v, answer t:
- transposition simulates XOR (
xorGadget, clean value⊥): swapt ↔ v, query (⊥ ↦ a i), XOR the answer into the ancilla, unquery, swap back —swap · O · xorInto · O · swap; - XOR simulates transposition (
transGadget, clean valuesome false): swap, query (some false ↦ some (a i)), controlled-swap⊥ ↔ some von the ancilla wherevis the answer's value, unquery, swap back —swap · Oˣ · ctrlSwap · Oˣ · swap.
Both middle unitaries are input-independent basis permutations; the controlled swap is additionally controlled on the index register being active, which is what keeps the idle sector exactly fixed. Off the clean sector each gadget moves the ancilla away from the clean value, so the encoded-subspace statements hold with no side condition.
The compilers are compositional (QRoutine.comp + ofUnitary of lifted
steps, exactly like selectPowers), with comp_run sequencing the standard
side and comp_runWith/xorRun (from SourceQuantumRunWith) the XOR side.
Boolean specifically: for an arbitrary alphabet there is no canonical XOR
directly on σ without choosing a group structure on σ; the transposition
oracle is the alphabet-free primitive, which is why it is this development's
native model. The upstream construction (upstream OneHotSimulation.lean) handles arbitrary finite
alphabets by XORing the letter's one-hot encoding into a Hot σ register,
with the same two-queries-per-query gadget pattern as here.
The run in the XOR model, packaged #
The operator implemented by R against the XOR oracle.
Equations
Instances For
On an active index with answer some v: swap ⊥ ↔ some v in the
ancilla. Controlled on the index being active, so the idle sector is exactly
fixed.
Equations
Instances For
The gadget unitaries #
The answer–ancilla swap.
Equations
Instances For
The XOR-into-the-ancilla unitary.
Equations
Instances For
The controlled-swap unitary.
Equations
Instances For
The two gadgets #
Transposition simulates XOR: two physical queries.
Equations
- QuantumQueryComplexity.xorGadget = { len := 2, step := fun (t : ℕ) => if t = 1 then QuantumQueryComplexity.xorIntoMat else QuantumQueryComplexity.swapAncMat, step_unitary := ⋯ }
Instances For
XOR simulates transposition: two physical queries.
Equations
- QuantumQueryComplexity.transGadget = { len := 2, step := fun (t : ℕ) => if t = 1 then QuantumQueryComplexity.ctrlSwapMat else QuantumQueryComplexity.swapAncMat, step_unitary := ⋯ }
Instances For
The XOR gadget's action on the clean-ancilla sector is exactly one XOR query.
The transposition gadget's action on the clean-ancilla sector is exactly one transposition query, under XOR semantics.
The compilers #
Compile the first t XOR queries of a schedule into the transposition
model: lifted steps, one xorGadget per query.
Equations
- One or more equations did not get rendered due to their size.
- QuantumQueryComplexity.simXorUpto R 0 = QuantumQueryComplexity.QRoutine.ofUnitary (QuantumQueryComplexity.liftReg (Option Bool) (R.step 0)) ⋯
Instances For
The compiled XOR schedule: 2·R.len transposition queries.
Equations
Instances For
Compile the first t transposition queries of a schedule into the XOR
model: lifted steps, one transGadget per query.
Equations
- One or more equations did not get rendered due to their size.
- QuantumQueryComplexity.simTransUpto R 0 = QuantumQueryComplexity.QRoutine.ofUnitary (QuantumQueryComplexity.liftReg (Option Bool) (R.step 0)) ⋯
Instances For
The compiled transposition schedule: 2·R.len XOR queries.
Equations
Instances For
Transporting states, readouts, and probabilities #
Measuring through the ancilla changes nothing.
The state bridges #
The standard state is the run of the algorithm's own schedule.
The XOR state of a packaged routine is its parametric run.
The QueryCounts translations #
The transposition model simulates the XOR model at a factor of two: every achievable XOR query count doubles into the native model.
The XOR model simulates the transposition model at a factor of two.
The complexity comparison #
Model equivalence, one direction: standard complexity is at most twice the XOR complexity.
Model equivalence, the other direction: XOR complexity is at most twice the standard complexity.
Finite outputs by bit encoding #
A finite output type O with m values is encoded in
B = ⌈log₂ m⌉ = Nat.clog 2 m Boolean bits through Fintype.equivFin; each
bit of f is a post-composition of f, so on the adversary side it costs
nothing (advPMOn_comp_le). Given a 1/16-algorithm for each bit, the
assembly is:
- amplify each bit to error
(1/4)ᵗwith2tmajority rounds (amplify; the exponent arithmetic is2^{2t}·(1/16)^t = (1/4)^t); - join the
Bamplified bits into the tuple (exists_tuple_computes), errorB·(1/4)ᵗ, cost∑ᵢ 2t·qᵢ; - decode by post-composing the readout with the inverse encoding
(
ComputesWithErrorOn.postcompfromSourceQuantumPostcomp— the fibre sum only grows the correct outcome's probability).
exists_decode_computes is the generic assembly; the final theorem against
advPMOn lives in SourceQuantumCharacterization, which supplies the
per-bit algorithms from the promise-Boolean characterization.
The bit encoding #
The number of encoding bits: ⌈log₂ |O|⌉.
Equations
Instances For
Bit i of the encoded value.
Equations
- QuantumQueryComplexity.encBit o i = (↑((Fintype.equivFin O) o)).testBit ↑i
Instances For
The decoder: the (unique) value with the given bits, if any.
Equations
- QuantumQueryComplexity.encDecode y = if h : ∃ (o : O), (fun (i : Fin (QuantumQueryComplexity.encBits O)) => QuantumQueryComplexity.encBit o i) = y then h.choose else Classical.arbitrary O
Instances For
The assembly #
The finite-output assembly: given a 1/16-algorithm for each
encoding bit of f, there is an algorithm for f itself with error
B·(1/4)ᵗ at cost ∑ᵢ 2t·qᵢ.