Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The QFT circuit (4.4) maps |a⟩ to q^{-1/2} ∑_b exp(2πiac/q)|b⟩, c = bit reversal of b

Proved
ShorAlgorithms.QFT.qft_circuit_eq

by mikedeng1 · Sep 29, 2026 · Mathlib 0df444a (Lean v4.33.1)

p2o-batch-p200bp2o-gran-per-chapterp2o-plan-paperp2o-v1quantum-algorithmsquantum-circuitsquantum-fourier-transform

Let l≥0l \ge 0l≥0 and q=2lq = 2^lq=2l. Run Shor's gate sequence (4.4),

Rl−1 Sl−2,l−1 Rl−2 Sl−3,l−1 Sl−3,l−2 Rl−3⋯R1 S0,l−1⋯S0,2 S0,1 R0R_{l-1}\, S_{l-2,l-1}\, R_{l-2}\, S_{l-3,l-1}\, S_{l-3,l-2}\, R_{l-3} \cdots R_1\, S_{0,l-1} \cdots S_{0,2}\, S_{0,1}\, R_0Rl−1​Sl−2,l−1​Rl−2​Sl−3,l−1​Sl−3,l−2​Rl−3​⋯R1​S0,l−1​⋯S0,2​S0,1​R0​

(applied from left to right; RjR_jRj​ the one-bit gate (4.2) on bit jjj, Sj,kS_{j,k}Sj,k​ the two-bit phase gate (4.3) with angle π/2k−j\pi/2^{k-j}π/2k−j), on the basis state ∣a⟩=∣al−1…a0⟩|a\rangle = |a_{l-1} \dots a_0\rangle∣a⟩=∣al−1​…a0​⟩, where a=∑j2jaja = \sum_j 2^j a_ja=∑j​2jaj​. The result is the state

1q1/2∑bexp⁡(2πi ac/q) ∣b⟩,\frac{1}{q^{1/2}} \sum_{b} \exp(2\pi i\, a c / q)\, |b\rangle,q1/21​b∑​exp(2πiac/q)∣b⟩,

the sum over all lll-bit strings bbb, where c=∑k2kckc = \sum_k 2^k c_kc=∑k​2kck​ with ck=bl−1−kc_k = b_{l-1-k}ck​=bl−1−k​ is the bit reversal of bbb.

Since the (a,c)(a, c)(a,c) entry of Shor's Fourier matrix AqA_qAq​ (eq. (4.1)) is q−1/2exp⁡(2πiac/q)q^{-1/2}\exp(2\pi i ac/q)q−1/2exp(2πiac/q), the circuit computes AqA_qAq​ followed by a reversal of the order of the output bits. The circuit consists of lll one-bit gates and l(l−1)/2l(l-1)/2l(l−1)/2 two-bit gates, which is what makes the Fourier sampling steps of Shor's factoring and discrete logarithm algorithms efficient.

Formalization Note The statement is made on basis states ∣a⟩|a\rangle∣a⟩, as in the paper; by linearity of the circuit it determines the action on every state. The conclusion is an equality of functions: the output amplitude at every bit string bbb is (2l)−1exp⁡(2πi ac/2l)(\sqrt{2^l})^{-1}\exp(2\pi i\, a c/2^l)(2l​)−1exp(2πiac/2l). The case l=0l = 0l=0 (q=1q = 1q=1, empty circuit) is included.

Preamble
import Mathlib
import Definitions.Def_ShorAlgorithms_QFT_BitStrings
import Definitions.Def_ShorAlgorithms_QFT_Circuit
Formal statement
namespace ShorAlgorithms.QFT

/-- Shor 1997, §4, p. 1496: with `q = 2^l`, the gate sequence (4.4) takes the basis state `|a⟩`
to `q^{-1/2} ∑_b exp(2π i a c / q) |b⟩`, where `c` is the bit reversal of `b`. That is, the
circuit computes the Fourier transform `A_q` of eq. (4.1) followed by a reversal of the output
bits. -/
theorem qft_circuit_eq (l : ℕ) (a : Fin l → Fin 2) :
    runCircuit (qftGates l) (basisState a) =
      fun b => ((Real.sqrt (2 ^ l) : ℝ) : ℂ)⁻¹ *
        Complex.exp (2 * Real.pi * Complex.I * (bitsVal a : ℂ) * (bitsVal (bitRev b) : ℂ) /
          2 ^ l) := by sorry

end ShorAlgorithms.QFT
Source
Shor, Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer, SIAM J. Comput. 26(5) (1997), p. 1496, §4 ("Applying this sequence of transformations will result in a quantum state …"); A_q from p. 1495, eq. (4.1)
Human review
  • Endorsed by Shuze Chen · Oct 1, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 1, 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 paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me