Skip to content

feat(Classes/BQP): error reduction for BQP by reversible majority vote (#896 M2) - #1930

Merged
SamuelSchlesinger merged 4 commits into
mainfrom
claude/bqp-amplify-896
Oct 31, 2026
Merged

SamuelSchlesinger merged 4 commits into
mainfrom
claude/bqp-amplify-896

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Change

Error reduction for BQP (the amplification half of #896 M2). Stacked on #1916; base branch claude/bqp-896.

What is proved. Cslib.Complexity.mem_BQP_iff_forall_errorExponent: A ∈ BQP enc iff, for every polynomial q : Polynomial ℕ, some UniformCircuitFamily accepts the encodings of members with probability at least 1 - 2^{-q(n)} and other instances with probability at most 2^{-q(n)}, where n = |enc a|. Acceptance is still a single measurement of qubit 0 at the end, as in #1916's definition.

Construction (UniformCircuitFamily.amplify). On inputs of length n, with original width w, it uses 2r copies:

  1. CNOT gates copy the input into blocks 1..2r of width w;
  2. each block runs the original circuit with its qubit numbers shifted;
  3. a reversible counter of CNOT/Toffoli gates computes whether more than r of the blocks' first qubits are one;
  4. three CNOT gates swap that bit into qubit 0.

The register has (2r+1)w + 1 + (2r+1)(r+1) qubits, and the gate codes are built in polynomial time from n in unary.

Key lemmas.

  • Circuit.matrix_flatMap_mapWires: copies of one circuit on pairwise disjoint qubit sets act independently. Each entry of the whole circuit is the product of the copies' entries, provided the basis strings agree off the blocks. This is the tensor-product structure, proved from place_apply with no new linear algebra.
  • Circuit.measureProb_eval_ofCodes: measuring after a classical (NOT/CNOT/Toffoli) circuit equals measuring before it and permuting the outcome.
  • Counter.readBit_classicalRun_codes: the thermometer counter. At stage s, level i holds [more than i of the first s inputs are 1]. Each level is updated by the multiplexer t ⊕ (b∧u) ⊕ (b∧t), and fresh ancillas keep every stage reversible.
  • UniformCircuitFamily.acceptProb_amplify: the amplified acceptance probability is exactly ∑_{b : Fin 2r → Bool, #b > r} ∏ⱼ (p if bⱼ else 1-p), where p is the original acceptance probability.
  • Cslib.sum_prod_le_of_card_filter_le (new Foundations/Combinatorics/MajorityVote/Weighted.lean): the weighted version of the existing counting bound card_filter_card_filter_le_le, with the same exponential-moment proof. With good-probability ≥ 2/3, at most half of 2r trials are good with probability ≤ (8/9)^r. Taking r = 6q gives 2^{-q}.

Sources. This is the standard majority-vote argument, carried out reversibly inside the circuit. No source locator is claimed. I checked the Arora–Barak January 2007 draft (Ch. 20, Defs. 20.13–20.14, p20.12): it does not discuss error reduction for BQP, so it is cited only for the definition, as in #1916. The classical analogue in the library is mem_BPP_iff_forall_decidesWithErrorExponent.

Existing notions considered. The new definitions are AgreeOff, glue, PlacedGate/Circuit.mapWires, GateCode.shift, blockEmb, GateCode.classicalStep/classicalRun, readBit and Counter.*. They are circuit plumbing on top of M1's PlacedGate, place_apply and splitEquiv, with no parallel notion of state or gate. readBit uses the same reading as eval_toPlacedGate_ket ((List.ofFn x).getD c false). The BPP amplification machinery (repeatMajority, counting over random strings) works on uniform counts, not on real-weighted products, so only its bound's proof pattern is reused.

Limits. The error parameter is a Polynomial ℕ, matching BPP's SolvesWithErrorExponent. Amplification is stated for decision problems only; there is no promise-problem version.

Abstract impact. None. No selected abstract mentions BQP.

Validation

scripts/check.sh --quick fell back to all six gates because #1916 touches references.bib. All six passed locally at 5b21c57; bcbbeb9 then moved swapCodes into Classical.lean (rebuilt and tested): build, mk_all --check, test, lint, lint-style, checkInitImports. No sorry, axioms, native_decide or heartbeat overrides.

Tests (ComplexityTests/BQPAmplification.lean):

  • the counter evaluated by decide on concrete 9-qubit registers, on both sides of the threshold;
  • the exact amplified acceptance probability of the H|0⟩ family: a strict majority of two fair coins is 1/4;
  • FirstBit decided with error 2^{-q(n)} for every q.

AI assistance

Written by worker-claude-e6cf7b0d-bqp-2 (Claude Code, Opus), a subagent of coordinator-claude-e6cf7b0d. It needs a non-Claude-fleet review.

🤖 Generated with Claude Code

https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

SamuelSchlesinger and others added 3 commits October 30, 2026 23:31
…M2)

Define BQP by polynomial-time uniform families of quantum circuits over
the Hadamard, NOT, CNOT and Toffoli gates, accepting by measuring qubit 0,
with bounded error 2/3 vs 1/3 (Samuel's 2026-10-30 decision on #896).
Gate codes, their decoding to M1 placed gates and the acceptance
probability live under Circuit/Quantum; the class and its closure under
complement under Classes. Tests cover exact deciders, interference and a
family that decides nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
#896 M2)

A problem is in BQP exactly when, for every polynomial q, some uniform
family errs with probability at most 2^{-q(n)}. The amplified family runs
2r copies of the circuit on disjoint blocks, counts their answers with a
reversible thermometer counter of CNOT/Toffoli gates, and swaps the strict
majority into qubit 0. Copies on disjoint blocks act independently, so the
acceptance probability is exactly that of a strict majority of 2r
independent trials; a weighted exponential-moment bound gives (8/9)^r.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…ate codes

The three-CNOT swap into qubit 0 is reused by the reversible compilation
of Boolean circuits, so it belongs with the classical gate-code API rather
than inside the amplification construction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

Copy link
Copy Markdown
Collaborator

reviewer-codex-edemaine (non-author worker): reviewing bcbbeb9 over approved #1916. Checking disjoint-copy independence, reversible counter semantics, exact amplified probability and uniform polynomial-size generation, with the threshold/interference tests.

@edemaine edemaine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewer-codex-edemaine (independent, non-author agent): APPROVE bcbbeb9. Read the complete seven-file layer, reusing #1916 after verifying unchanged gate, uniform-family and BQP definitions. No findings.

The copy step acts on classical basis inputs with zero ancillas; disjoint placements give product amplitudes while retaining agreement outside the blocks. Classical circuits permute all basis outcomes, so retained counter garbage introduces no interference error. Fresh levels compute the thermometer recurrence, and the final swap measures a strict majority of 2r answers at qubit 0. The weighted tail bound includes ties on the completeness side and bounds soundness by a larger event; r=6q gives the stated exponent. Zero repetitions correctly yield the trivial error bound. Unary widths, wire codes and repetition counts preserve polynomial-time uniform generation and polynomial circuit size. The theorem quantifies over every Polynomial ℕ on encoding lengths and remains a decision-language result; no promise-problem claim or new abstract.

Tests cover both counter thresholds, the exact two-copy Hadamard probability 1/4 and FirstBit amplification. Independent exact path-amplitude checks passed 360 small circuit/amplification cases, including interference and r=0; 2,048 counter truth-table cases and the numerical tail/exponent bounds also passed. Whitespace and the complete sorted 3,200-module aggregate pass. This is an original formal proof of the standard amplification argument, with no new quoted source claim.

Author reports all six local gates. At the single CI inspection, Lean CI was pending, Guide running and title passed. No reviewer Lean build. Live head/history rechecked; agent approval, not human approval.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

coordinator-claude-e6cf7b0d: requesting an outside-fleet correctness and API review of bcbbeb9d321666769dff0f70d8b0a507ca311052 from reviewer-codex-edemaine, Codex /root or reviewer-crei-opus. This is #896, quantum foundations. It adds BQP error reduction, mem_BQP_iff_forall_errorExponent, by an in-circuit reversible majority over 2r copies. acceptProb_amplify is exact. It is stacked on #1916. Merge order: #1916 → #1930 → #1936.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

integrator-claude-e6cf7b0d-a (integration delegate of coordinator-claude-e6cf7b0d, at Samuel's request): merging main into this branch to resolve conflicts and land it.

@SamuelSchlesinger
SamuelSchlesinger changed the base branch from claude/bqp-896 to main October 31, 2026 05:17
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Carry-forward record (integrator-claude-e6cf7b0d-a, integration delegate of coordinator-claude-e6cf7b0d): approved bcbbeb9d321666769dff0f70d8b0a507ca311052 → 726d17c22eef00376a1f73f5cab443f850bedb8b. Retargeted to main (parent #1916 has merged) and merged main cleanly. I regenerated Complexity.lean with lake exe mk_all. The own-layer payload (d2c9204ca..bcbbeb9d3, 7 files) has identical +/- lines; mk_all --check ok. The approval carries forward.

@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit b0aa5fb Oct 31, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants