Skip to content

feat(Classes/BQP): define BQP over Hadamard and Toffoli circuits (#896 M2) - #1916

Merged
SamuelSchlesinger merged 1 commit into
mainfrom
claude/bqp-896
Oct 31, 2026
Merged

SamuelSchlesinger merged 1 commit into
mainfrom
claude/bqp-896

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

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 enc when some UniformCircuitFamily accepts enc a with probability ≥ 2/3 for every a ∈ A and ≤ 1/3 for every a ∉ A.

  • Gate set (Samuel's 2026-10-30 decision on Frontier track: quantum computation foundations, BQP ⊆ PP and the Grover/BBBV bounds #896): Hadamard plus the classical reversible gates NOT, CNOT and Toffoli. A gate is written as a code (h, t, cs) : Bool × ℕ × List ℕ. (true, t, []) is H on qubit t; (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's Gate.hadamard, Gate.not, Gate.cnot and Gate.toffoli placed on those qubits (GateCode.toPlacedGate?, Circuit.ofCodes).
  • Uniformity: width n and gates n are ComputableInPolyTime from n in 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 requires n ≤ width n, 0 < width n, and well-formed codes.
  • Run and acceptance: the run starts in |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 via measureProb).
  • Equivalence with the textbook definition (arbitrary elementary gates on ≤ 3 qubits) is a cited, unformalized remark in the BQP module 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) and GateCode.eval_toPlacedGate_hadamard_ket (H branches as ∑_c (-1)^{x_t c}/√2 |x[t↦c]⟩). The basis-state lemma measureProb_ket is 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 x padded with zeros; elementary operations on ≤ 3 qubits, described by a polynomial-time TM on input 1^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's ket/measureProb. All are reused, and the decoded gates are M1's named gates. Uniformity uses ComputableInPolyTime … encUnary …, as CircuitValue.exists_uniformCircuits does. Bounded error uses real probabilities via measureProb. BPP's count-based BoundedErrorAt is specific to random strings and doesn't fit. No parallel notion is introduced.

Tests (ComplexityTests/BQP.lean), with instances on both sides:

  • the first-input-bit language is in BQP (accepted with probability exactly 1 or 0), and so is its complement;
  • H·H on qubit 0 interferes back to the identity;
  • the one-H family has acceptance probability exactly 1/2 on every input, so it decides no language;
  • the same exact decider is shown to fail the bounds for the complement;
  • decide checks of well-formed and ill-formed codes;
  • a Toffoli code maps |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 --quick fell back to all six gates (because references.bib changed). All passed locally on d2c9204: build, mk_all, test, lint, lint-style, checkInitImports. check_hygiene.py and check_changed_files.py pass. Hosted CI will rerun them.

AI assistance

Written by worker-claude-e6cf7b0d-bqp (Claude Code, Opus), a subagent of coordinator-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

…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

Copy link
Copy Markdown
Collaborator

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 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: 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.

SamuelSchlesinger commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator Author

Non-author post-admission coordinator roadmap_crypto verified #1916 through its external admission and actual landing. The source and credit of worker-claude-e6cf7b0d-bqp are preserved; reviewed head d2c9204ca736ebd1e173a0e46799dab5da8d292b was never edited. This reuses the exact-head outside correctness/API agent approval and the worker's handoff. No new admission, source/workflow change, local build or mathematics review was needed.

Landed at 05:06:45 UTC as aab202fc9fe99170ba70548f4371cbcfd2f0e6ef. Sole parent 5ecc83fb and tree 8ee240bc543d5d39b65cafff288133989d2a16fd match a strict neutral merge with no conflicts: 3,250 canonical imports, all five approved Lean/test blobs and modes exact, the three reviewed bibliography additions exact, dependency pins unchanged, and the complete unrelated parent prefix retained. #1070 and #1095 are actual ancestors, with unchanged prerequisite quantum files preserved.

Canonical source CI passed all six gates on actual synthetic checkout 2e74f428 (c24a5fa9 main plus reviewed d2c9204c), with all approved payloads and pins exact. Required merge-group CI also passed all six at the actual landed commit. The first actually started qualifying main consumer is fixed to run 41171687127, job 124450954672, attempt 1, checkout f6f42a1bbd32beb33b8bf622ac7273e75dbd2473 (external #1931, directly after #1916), started 05:13:51 UTC and pinned before any main log/map retrieval. All five reviewed payloads, prerequisites and pins remain exact; its 3,251-import aggregate is canonical. This checkout excludes #1792/#1794; BPL owns their next distinct publication boundary.

The model remains polynomial-time uniform circuits from unary n, over H/NOT/CNOT/Toffoli, with unary wires/width, zero-padded inputs, one final computational-basis measurement and qubit-0 acceptance at thresholds 2/3 and 1/3. The textbook gate-set equivalence is an unformalized remark. This delivers the BQP definition and complement closure, while amplification (#1930), P containment (#1936) and BQP containment (#1924) remain separate milestones under #896. No headline or curated-abstract expansion.

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 41171322767, attempt 1, whose exact f6f42a1b checkout and all-six success were also checked; zero Built/Building Complexity lines occurred while normal checks ran. The public revision map returns HTTP 200: 4,344 unique mappings, 195,493 bytes, SHA256 581e17dcf76c1b081d7baa7b13dbfab231398b91a1095100fbeb9a22224ea982. All 14 new artifact references versus the saved 6d572096 baseline return HEAD 200 with positive lengths. One finalized main-log retrieval and one map GET, with no baseline GET or artifact-body downloads. BPL receives the saved map for the next distinct #1792-containing consumer; the fixed checkout was never retargeted.

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