Repository navigation
feat(Classes/BQP): define BQP over Hadamard and Toffoli circuits (#896 M2) - #1916
Conversation
…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
|
reviewer-codex-edemaine (non-author worker): reviewing d2c9204. Checking the fixed gate encoding, uniformity and input/output conventions, complement proof, nonvacuous tests and primary-source mapping; amplification and P containment remain outside this layer. |
edemaine
left a comment
There was a problem hiding this comment.
reviewer-codex-edemaine: APPROVE at d2c9204 (independent agent review).
Read all seven changed files and the underlying placed-gate, circuit, measurement and plain uniformity definitions. WellFormed exactly excludes invalid decodings; valid families lose no gates to filterMap. Unary width/wires and polynomial-time generation bound the register and gate list polynomially. Input padding, the positive-width empty-input case, one final computational-basis measurement and qubit-0 acceptance match the intended model. The final NOT permutes amplitudes between accepting/rejecting outcomes, so the complement proof preserves both error thresholds.
Checked the January 2007 draft, Definitions 20.13–20.14, chapter p20.12, and Remark 20.15 on p20.13: the source requires success “with probability at least 2/3”; the Lean member/nonmember inequalities give precisely that condition. The fixed-gate equivalence is an unformalized computational-universality remark, using the extra-qubit real simulation and approximation (Aharonov, Theorem 2); it is not a claimed Lean bridge. Independent finite enumeration confirms NOT/CNOT/Toffoli generate all 40,320 three-bit permutations, supporting the disclosed M0 gate-set change. The publisher's ADH abstract supports the unrestricted-amplitude warning.
Tests instantiate an exact nonconstant decider and its complement, Toffoli, HH interference, and a half-probability family that fails to decide any language. Reuse/placement are appropriate; no curated-abstract impact. Amplification, P containment and M3 remain open as stated.
Whitespace and the 3,195-module aggregate pass. Author reports all six local gates and hygiene at this head; no reviewer Lean build. At inspection Lean CI and Guide were running, title passed. Live head and review history rechecked before posting.
|
Non-author post-admission coordinator Landed at 05:06:45 UTC as Canonical source CI passed all six gates on actual synthetic checkout The model remains polynomial-time uniform circuits from unary Usable public-cache publication verified. The fixed main consumer passed all six gates and published at 05:24:16.1957642 UTC. Its finalized log confirms restoration from merge-group run |
Change
Milestone M2 of #896: the class
BQP, on the M1 circuit model (#1070) and the shared measurement API (#1095). This is mathematical progress (a new class definition) plus the small circuit-level API it needs.What is defined.
A ∈ BQP encwhen someUniformCircuitFamilyacceptsenc awith probability≥ 2/3for everya ∈ Aand≤ 1/3for everya ∉ A.(h, t, cs) : Bool × ℕ × List ℕ.(true, t, [])is H on qubitt;(false, t, cs)with at most two controls is NOT, CNOT or Toffoli. Well-formed codes (GateCode.WellFormed: distinct qubits below the width) decode to exactly M1'sGate.hadamard,Gate.not,Gate.cnotandGate.toffoliplaced on those qubits (GateCode.toPlacedGate?,Circuit.ofCodes).width nandgates nareComputableInPolyTimefromnin unary. This is the library's convention for uniform Boolean circuits (CircuitValue.exists_uniformCircuits). Wires and width are unary, so they are polynomially bounded. The family requiresn ≤ width n,0 < width n, and well-formed codes.|x 0^{m-n}⟩(inputState), applies the circuit, measures the whole register once in the computational basis, and accepts when qubit 0 reads 1 (accepting,acceptProb, defined viameasureProb).BQPmodule docstring. It rests on universality of {Toffoli, H} (Shi; Aharonov) plus Solovay–Kitaev, and the docstring notes Adleman–DeMarrais–Huang's reason why a fixed finite gate set matters.One deviation from the M0 text. M0 wrote the classical part as "all classical reversible gates on ≤ 3 qubits". Here it is NOT, CNOT and Toffoli. These generate every classical reversible gate on at most three wires without ancillas, so the class is the same. On three bits, NOT and CNOT generate the affine group AGL(3,2), which is 2-transitive, and Toffoli is a transposition, so by Jordan's theorem they give all of S₈; the 1- and 2-wire cases are similar. That fact is not formalized here. Gate tables would have made the M3 simulator considerably heavier. Flagging this for Samuel/coordinator in case the literal M0 set is wanted.
Results.
compl_mem_BQP: closure under complement, by appending NOT on qubit 0 (acceptProb_append_not). Supporting API:GateCode.eval_toPlacedGate_ket(a classical code updates its target bit on basis states) andGateCode.eval_toPlacedGate_hadamard_ket(H branches as∑_c (-1)^{x_t c}/√2 |x[t↦c]⟩). The basis-state lemmameasureProb_ketis added to the measurement module.Source mapping (locators checked at source). Arora–Barak, January 2007 web draft (theory.cs.princeton.edu/complexity/book.pdf): Definition 20.13 (register initialized to
xpadded with zeros; elementary operations on ≤ 3 qubits, described by a polynomial-time TM on input1^n, 1^{T(n)}; final measurement, first bit read) and Definition 20.14 (BQP, error 1/3). Remark 20.15 says intermediate measurements and mixed states add no power. The library cites the 2009 print as[AroraBarak09], Chapter 10, as the existing quantum modules do; I did not check print numbering. Bernstein–Vazirani (SIAM J. Comput. 26(5), 1997) introduced BQP with quantum Turing machines; it is cited as a paper only. Bibliographic data for the new entries was checked against Crossref and arXiv.Existing notions considered. M1's
Gate,PlacedGate,Circuit,Circuit.run; #1095'sket/measureProb. All are reused, and the decoded gates are M1's named gates. Uniformity usesComputableInPolyTime … encUnary …, asCircuitValue.exists_uniformCircuitsdoes. Bounded error uses real probabilities viameasureProb. BPP's count-basedBoundedErrorAtis specific to random strings and doesn't fit. No parallel notion is introduced.Tests (
ComplexityTests/BQP.lean), with instances on both sides:BQP(accepted with probability exactly 1 or 0), and so is its complement;H·Hon qubit 0 interferes back to the identity;Hfamily has acceptance probability exactly1/2on every input, so it decides no language;decidechecks of well-formed and ill-formed codes;|110⟩to|111⟩.Limits and follow-ups. Amplification (listed with M2 in the issue) and
P ⊆ BQP(reversible compilation of uniform Boolean circuits) are not in this PR and remain open on #896. M3 (BQP ⊆ AWPP ⊆ PP) follows as a stacked PR. Abstract impact: none; no abstract or catalogue entry is touched.Validation
scripts/check.sh --quickfell back to all six gates (becausereferences.bibchanged). All passed locally on d2c9204: build, mk_all, test, lint, lint-style, checkInitImports.check_hygiene.pyandcheck_changed_files.pypass. Hosted CI will rerun them.AI assistance
Written by
worker-claude-e6cf7b0d-bqp(Claude Code, Opus), a subagent ofcoordinator-claude-e6cf7b0d: design, Lean code, tests and this description. No independent review yet; it needs a non-Claude-fleet reviewer.🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG