Alphabeta Math
Pipeline-generated
How statement and proof provenance work

The first chip identifies the source of the statement or construction; the second identifies the source of its local proof or verification.

  • Literature-sourced: the exact statement appears in a cited source; only wording and notation differ.
  • AI-adapted: a semantically identical restatement of literature-sourced material, modulo indexing, notation, and boundary cases adopted by the library.
  • AI-generated: a genuinely novel statement formulated by AI, with no source for the claim itself.

These labels describe origin, not correctness: citations and verification chips remain separate evidence.

Shor’s Factoring Algorithm

1 · Prerequisites

2 · Summary

This page gives a bounded-error factoring procedure for a promised composite integer N≥4. It returns 2 immediately for even inputs. For odd inputs, it searches for exact perfect powers by integer roots and returns a proper factor when it finds one. In the remaining odd-composite case, it samples uniformly from 1,…,N−1 by exact rejection sampling. A nonunit sample yields its gcd factor immediately; a unit is passed to the order-finding procedure of quantum-order-finding-and-rational-reconstruction with internal failure target 1/4.

Every proposed period is checked directly: it must lie between 2 and N, be even, and satisfy aq≡1(modN). The reduction then computes z=aq/2 mod N and tests gcd⁡(z−1,N) and gcd⁡(z+1,N). It returns only a divisor checked to lie strictly between 1 and N. Minimality of a candidate period is not required for output correctness; a nonminimal candidate can only miss a factor and cause a retry.

For a true order, the CRT proof identifies success through the two-adic valuations of the local prime-power orders. Each possible local valuation has probability at most 1/2; with k distinct prime factors, the probability that all valuations agree is at most 2−(k−1). Thus the true-order reduction succeeds with probability at least 1/2 on every odd composite that remains after perfect-power preprocessing. The order finder is exact with probability at least 3/4 for each fixed unit, so each outer attempt succeeds with probability at least 3/8. With T=min⁡{t≥1:5tv≤8tu}=⌈ln⁡(1/δ)−ln⁡(5/8)⌉ for δ=u/v, the total failure probability is at most (5/8)T≤δ.

The random-bit sampler uses countable choice and dependent choice only to supply countably many independent fair bits; the CRT and number-theoretic success proofs use finite products and finite choices. Under supplied explicit reversible arithmetic and an ideal exact-angle QFT, the stated gate, multiplier-call and expected arithmetic/post-processing bit-operation bounds are kept separate. No circuit-description generation-time, finite-alphabet or uniform-family bound is asserted. The bare controlled-unitary query branch costs O(nT(Q−1)) queries and carries no polynomial query claim.

3 · Logical flowchart

4 · Definitions, theorems and proofs

AlgorithmAlgorithm: AI-adaptedProof: Not applicableOpen item page →

Exact uniform sampling from the nonzero residue representatives

Definition

Input. An integer N≥3. The random tape is a countable sequence of independent bits, each taking 0 and 1 with probability 1/2. Its countable product law is supplied by Assuming countable and dependent choice, countable products of arbitrary probability spaces under countable choice and dependent choice (The Axiom of Countable Choice (ACω), The axiom of dependent choice: a relation in which every element is related to something admits an N-indexed chain).

Set M=N−1 and let h be the binary length of M−1, equivalently the least integer with M≤2h. For each block, read its bits in order as β0,…,βh−1, with the first bit most significant, and set b=∑j=0h−12h−1−jβj∈{0,…,2h−1}. If b≥M, discard this block and read the next h bits. Otherwise output a=b+1 and halt.

Whenever it halts, the procedure returns an element of {1,…,N−1} because an accepted block has 0≤b<M=N−1 and the output is b+1.

LemmaStatement: AI-adaptedProof: AI-generatedOpen item page →

Mixed CRT signs yield proper gcd factors

Statement

Let N=∏i<kpiei, where k≥1, the pi are distinct odd primes, and every ei≥1. If z2≡1(modN) but z≢1,−1(modN), then both gcd⁡(z−1,N) and gcd⁡(z+1,N) are proper nontrivial divisors of N. When k=1, the hypotheses cannot hold, because the proof below shows the only roots are the two global signs.

Facts & Assumptions

Given: The stated factorization of odd N, an integer z with z2≡1(modN), and z≢±1(modN).

[F2]

For odd prime p and e≥1, (Z/pe)× is cyclic of even order pe−1(p−1) (For every odd prime p and k≥1, (Z/pkZ)× is cyclic of order pk−1(p−1)).

Proof

1.1givenF1F2F3F5F6choosealgebra

By [F1], z has components zi=[z]piei. Each satisfies zi2=1, hence is a unit. Choose a generator gi of its cyclic unit group of even order Mi by [F2], and write zi=giti. By [F3], zi2=1 exactly when Mi∣2ti. Among residues ti modulo even Mi, this gives only ti=0 or ti=Mi/2, so zi is one of the two roots 1,−1: the second is −1 because −1 is a root and it is distinct from 1 modulo piei>2 (otherwise piei∣2, contrary to [F5]). To see the two exponent classes explicitly, write Mi=2si; Mi∣2ti is equivalent to si∣ti, which has the two residue classes 0,si modulo 2si.

2.1givenstep 1.1F1choose

The signs cannot all be +1, since CRT injectivity would then give z≡1(modN), and they cannot all be −1, since it would give z≡−1(modN). Choose indices i+ and i− with signs +1 and −1, respectively. This also shows that when k=1 the hypotheses are impossible.

3.1givenstep 2.1F4F5F6algebra

Since pi+ei+∣z−1 and pi+ei+∣N, it is a common divisor, so gcd⁡(z−1,N)≥pi+ei+>1. Since z≡−1(modpi−ei−), that prime power divides z+1; it cannot divide z−1 because then it would divide 2=(z+1)−(z−1), whereas pi−ei−>2. Thus N∤z−1 and gcd⁡(z−1,N)<N.

4.1step 3.1step 2.1F4∎

Interchanging the two signs in step 3.1 gives 1<gcd⁡(z+1,N)<N. Hence both gcds are proper nontrivial divisors.

LemmaStatement: AI-adaptedProof: AI-generatedOpen item page →

Half an even order gives a square root of one

Statement

Let N≥2, let x be a unit modulo N, and let q≥2 be an even integer with xq≡1(modN). Then z=xq/2 mod N satisfies z2≡1(modN). If q=ord⁡N(x), then additionally z≢1(modN).

Facts & Assumptions

Proof

1.1givenF1algebra

Write q=2h with h=q/2≥1. Then z2=[xh]N[xh]N=[x2h]N=[xq]N=[1]N, so z is a square root of one.

2.1givenF1F2step 1.1algebra

If q=ord⁡N(x) and z=[1]N, then [x]Nh=[1]N in the unit group. By [F2], q∣h, which is impossible because 0<h<q. Thus z≠[1]N.

3.1step 1.1step 2.1∎

The square relation holds for every accepted even exponent, and step 2.1 supplies the additional nonidentity conclusion when it is the true order.

LemmaStatement: AI-adaptedProof: AI-generatedjudge pass (gpt-6-luna)Open item page →

Two-adic order distribution in odd prime-power unit groups

Statement

Let p be an odd prime and e≥1. If A is uniform in (Z/pe)×, then for every possible integer j,

P(v2(ord⁡pe(A))=j)≤12.

Here v2(r) is the greatest s∈N such that 2s∣r, for the positive integer order r.

Facts & Assumptions

Given: An odd prime p, an integer e≥1, and the uniform finite probability law on (Z/pe)×.

[F3]

For a positive integer r, v2(r) is the greatest s with 2s∣r (The p-adic valuation vp(a) of a nonzero integer: the greatest k∈N with pk∣a, with prime 2).

[F4]

A finite uniform probability space assigns each outcome equal weight (Finite probability spaces, outcome weights, events, and event probabilities).

[F6]

Integer multiplication is associative and cancellation by a nonzero factor is valid (The integers form a commutative ring, The integers have no zero divisors; multiplicative cancellation).

Proof

1.1givenF1F2choose

Since p is odd, M=pe−1(p−1) is even; write M=2su with s≥1 and u odd. Choose a generator g by [F1]. The map t↦gt for 0≤t<M is a bijection onto the unit group, by the order statement in [F2], so a uniform unit corresponds to a uniform such exponent t.

1.2givenF2F5F6algebra

Put d=gcd⁡(M,t). For t>0, write M=dM0 and t=dt0. Bézout's identity for M,t divides through by d to give M0x+t0y=1, so M0,t0 are coprime by [F5]. For every h≥1, [F2] gives (gt)h=1 exactly when M∣th, equivalently M0∣t0h; [F5] makes this equivalent to M0∣h. Hence the least such h is M0=M/d. If t=0, then d=M and gt=1 has order 1=M/d.

2.1step 1.1step 1.2F3F4F5algebra

The exponent of 2 in d=gcd⁡(M,t) is s exactly when 2s∣t: if 2s∣t, then 2s is a common divisor and hence divides d; if 2s divides d, it divides t. Since 2s is the full power of 2 dividing M, this is equivalent to v2(M/d)=0. There are M/2s=u such residues among 0,…,M−1, so this probability is u/M=2−s≤1/2.

3.1step 1.1step 1.2F3F4F5algebra

For 1≤j≤s, v2(M/d)=j exactly when the exponent of 2 in d is s−j. As in step 2.1, this is exactly when 2s−j∣t and 2s−j+1∤t. The number of such residues is M2s−j−M2s−j+1=2j−1u, so their probability is 2j−1u/M=2j−s−1≤1/2. No other valuation occurs because M/d divides M.

4.1step 2.1step 3.1∎

The cases j=0 and 1≤j≤s exhaust all possible valuations, and each has probability at most 1/2 by steps 2.1 and 3.1.

LemmaStatement: AI-adaptedProof: AI-generatedjudge pass (gpt-6-luna)Open item page →

Random residue gcd branch for factoring

Statement

Let N≥2 and choose a uniformly from the integers 1,…,N−1. If gcd⁡(a,N)>1, then gcd⁡(a,N) is a proper factor of N. Conditional on gcd⁡(a,N)=1, the residue class [a]N is uniformly distributed in the unit group (Z/N)×.

Facts & Assumptions

Given: An integer N≥2 and the uniform finite sample space ΩN={1,…,N−1}.

[F3]

In a finite uniform probability space, each outcome has equal weight; event probability is the sum of those weights (Finite probability spaces, outcome weights, events, and event probabilities), and P(A∣B)=P(A∩B)/P(B) when P(B)>0 (Conditional probability P(A∣B) for P(B)>0).

Proof

1.1givenF4F5algebra

If g=gcd⁡(a,N)>1, then g∣a and g∣N by [F4]. Since g is positive and divides the nonzero a, [F5] gives g≤a<N; hence 1<g<N and g is a proper factor.

1.2givenF1F2F4choose

The event U={a∈ΩN:gcd⁡(a,N)=1} is nonempty because a=1 belongs to it. By [F1] and [F2], the map a↦[a]N is a bijection from U to (Z/N)×: every unit has its unique standard representative, and the zero class is not a unit because [F2] and [F4] give gcd⁡(0,N)=N≠1.

2.1step 1.2F3algebra

Every a∈U has probability 1/(N−1), so P(U)=∣U∣/(N−1)>0. For any fixed unit representative a∈U, its conditional probability is (1/(N−1))/P(U)=1/∣U∣. By [F2], this is the uniform law on the unit group.

3.1step 1.1step 2.1∎

Step 1.1 proves the immediate proper-factor branch, and step 2.1 proves conditional uniformity of the unit branch.

TheoremStatement: AI-adaptedProof: AI-generatedjudge pass (gpt-6-luna)Open item page →

Classical randomized order-to-factor success bound

Statement

Let N be an odd composite that is not a perfect power, and write its prime-power factorization N=∏i<kpiei, where the pi are distinct odd primes, ei≥1, and k is their number. Choose a uniformly from (Z/N)× and let r=ord⁡N(a). The true-order reduction sets z=ar/2 mod N when r is even and succeeds when r is even and z≢±1(modN); on that event both gcds give proper factors. This event has probability at least 1−2−(k−1)≥12.

Facts & Assumptions

Given: The stated odd composite N, its prime-power factorization, a uniform unit a, and the true order r=ord⁡N(a).

[F2]

The CRT map restricts to an isomorphism from the unit group modulo N to the product of the unit groups modulo the pairwise-coprime prime powers (For pairwise coprime positive moduli, the Chinese remainder bijection restricts to an isomorphism of unit groups).

[F4]

For each odd prime power, every possible value of v2 of a uniform unit's order has probability at most 1/2 (Two-adic order distribution in odd prime-power unit groups).

[F5]

The half-power of a true even order is a nonidentity square root of one; in each odd prime-power component the only square roots are ±1, and mixed CRT signs give proper gcd factors (Half an even order gives a square root of one, Mixed CRT signs yield proper gcd factors).

Proof

1.1givenF1algebra

By [F1], N has a factorization into distinct prime powers. Since N is odd, every prime factor is odd. If there were only one distinct prime p, then N=pe; e=1 would make N prime, while e≥2 would make it a perfect power. Both contradict the hypotheses, so k≥2.

1.2givenF2F3algebra

Under the CRT isomorphism [F2], a uniform unit corresponds to a uniform tuple (ai)i<k in the product of the local unit groups: the map is a bijection and preserves equal weights. By [F3], the local components, and hence their orders ri=ord⁡piei(ai) and valuations ji=v2(ri), are independent. Each local unit group is finite, so only finitely many valuation values occur.

2.1step 1.2F2F6F7F8algebra

By [F8], r is finite and positive. Since ar=1 modulo N, CRT and [F6] give ri∣r for each i. Let J=max⁡iji and m=v2(r). Since 2ji∣ri∣r, the definition of m gives ji≤m for every i, so J≤m. If m>J, write r=2ms and ri=2jisi with s,si odd; here m≥1. From ri∣r, canceling the nonzero factor 2ji gives si∣2m−jis. Since si is odd, it is coprime to 2m−ji, so Euclid's lemma gives si∣s. Also ji≤J<m, so 2ji∣2m−1. Thus every ri∣r/2, so every local component and therefore ar/2 equals the identity by [F2,F6]. This contradicts the minimality of r, since 0<r/2<r. Therefore m=J.

2.2step 1.2F3F4algebra

Write pi(j)=P(ji=j). By independence [F3], the probability that all valuations agree is ∑j∏i<kpi(j). For every possible j, [F4] bounds each of p1(j),…,pk−1(j) by 1/2, so ∏i<kpi(j)≤2−(k−1)p0(j). Summing over the finite set of possible j gives probability at most 2−(k−1), since ∑jp0(j)=1.

3.1step 2.1F5F6F7choosealgebra

If the ji are not all equal, then J≥1; choose indices i,h with ji=J and jh<J. Write r=2Js and rh=2jhsh with s,sh odd. Since rh∣r, cancellation gives sh∣2J−jhs; because sh is odd, it is coprime to 2J−jh, so Euclid's lemma gives sh∣s. As jh<J, 2jh∣2J−1, hence rh∣2J−1s=r/2. By [F6], ahr/2=1. For the maximum index, ri∤r/2 because its two-adic valuation is J while v2(r/2)=J−1; hence [F6] gives air/2≠1. Its square is 1 because ri∣r. By [F5], this local root is −1, while the h component is +1. Thus the global square root is neither global sign, and [F5] gives proper gcd factors.

4.1step 1.1step 2.2step 3.1algebra∎

By step 2.2, the valuations differ with probability at least 1−2−(k−1); step 3.1 shows that every such outcome gives a proper factor. Since k≥2 by step 1.1, this probability is at least 1/2.

AlgorithmAlgorithm: AI-adaptedProof: Not applicablejudge pass (gpt-6-luna)Open item page →

Shor factoring with verified output and bounded outer retries

Definition

Inputs. A composite integer N≥4, encoded in binary, and a rational target failure probability δ=u/v with coprime integers 0<u<v. Use the modular-order-finding procedure on the earlier A page with its explicit reversible modular-multiplication circuit. Output is a verified proper divisor of N or FAIL.

Arithmetic subroutines. For c≥1 and exponent e≥0, CappedPower(c,e) returns min⁡{ce,N+1}: initialize (r,d,k)=(1,c,e); while k>0, replace r by min⁡{rd,N+1} if k is odd, then replace k by ⌊k/2⌋ and, if the new k>0, replace d by min⁡{d2,N+1}. For any integer c and exponent e≥0, ModPower(c,e) returns ce mod N: initialize (r,d,k)=(1,c mod N,e); while k>0, replace r by rd mod N if k is odd, then replace k by ⌊k/2⌋ and, if the new k>0, replace d by d2 mod N. In both routines, parity, quotient, product, comparison, and remainder operations are exact integer operations.

  1. Set n=⌈log⁡2N⌉. If N is even, set d=2, check 1<d<N and N mod d=0, and return d if both checks pass.

  2. For each integer exponent e=2,3,…,n, initialize L=2 and R=N. While L≤R, set b=⌊(L+R)/2⌋ and y=CappedPower(b,e). If y<N, set L=b+1. If y>N, set R=b−1. If y=N, verify 1<b<N and N mod b=0; return b if both checks pass, and otherwise set R=b−1. If the loop ends without a return, continue to the next exponent.

  3. Initialize T=1, A=5, and B=8. While Av>Bu, replace (T,A,B) by (T+1,5A,8B). Continue to instruction 4 with this T; it is the least positive integer satisfying 5Tv≤8Tu, equivalently T=⌈ln⁡(1/δ)/(−ln⁡(5/8))⌉.

  4. For attempts i=1,…,T, obtain a fresh independent sample a by running Exact uniform sampling from the nonzero residue representatives on N with a fresh independent countable fair-bit tape. Compute g=gcd⁡(a,N). If 1<g<N and N mod g=0, return g. If g≠1, start the next attempt; the case g=N is rejected as an invalid sample and also starts the next attempt.

  5. When g=1, run modular order finding on (N,a) with target parameter b=2, so its target failure is 2−2=1/4. Use fresh measurement randomness independent of the sampler tape and all previous attempts. If it returns FAIL, start the next attempt. Otherwise let q be its candidate. Reject the candidate unless 2≤q≤N, q is even, and ModPower(a,q)=1. Set z=ModPower(a,q/2), the standard representative of aq/2 mod N. Compute d−=gcd⁡(z−1,N) and d+=gcd⁡(z+1,N). Return the first of these satisfying 1<d±<N and N mod d±=0; if neither passes, start the next attempt.

  6. If all T attempts finish without returning a divisor, return FAIL.

The residue sampler's exact uniformity, almost-sure termination, and expected-bit bound are proved separately. The outer attempt count, root search, modular exponentiation, and divisor checks have the finite bounds stated above. Correctness, success probability, and costs are separate claims.

Remarks

The odd-composite branch reaches order finding only after the gcd test establishes gcd⁡(a,N)=1, so the residue class of a is a unit by For n≥1, [a]n is a unit if and only if gcd⁡(a,n)=1. A returned candidate period is rechecked even though the order-finding contract also verifies candidates. Its fair-bit tapes use countable choice and dependent choice through the sampler's countable product model; the number-theoretic and output-verification branches use finite arguments. Order-finding success and cost are separate claims.

DefinitionDefinition: AI-adaptedProof: Not applicableOpen item page →

Shor factoring cost-accounting branches

Definition

Fix a promised input integer N≥4, set n=⌈log⁡2N⌉, and let an order-finding phase register have width m≥1 and size Q=2m. A work wire is an auxiliary circuit wire outside the stated input and output registers; its presence and use are charged as part of the supplied circuit. Classical bit transitions use the convention of Classical bit-operation cost. The cost report for Shor factoring keeps the following branches separate.

  • Explicit reversible arithmetic. A supplied reversible circuit for multiplication by a fixed residue modulo N is charged by its actual gate occurrences and work wires. Each use of that circuit is also counted in a separate modular-multiplier-call coordinate. The circuit, its inverse, and any controlled version must be supplied; this definition assigns none of them zero cost. It asserts no finite circuit-description generator or generation-time bound.
  • Ideal exact-angle QFT. In this named ideal submodel, each Hadamard, exact controlled-phase rotation, and swap in the supplied m-bit QFT circuit counts as one ideal gate. The standard exact cyclic QFT has m Hadamards, m(m−1)/2 controlled-phase rotations, and ⌊m/2⌋ swaps, hence O(m2) ideal gates. This submodel permits exact real angles as unit-cost gates. It supplies no finite gate alphabet, finite binary description, approximation, compiler, or uniform-family claim.
  • Bare controlled-unitary access. If only a controlled call to Ux:∣z⟩↦∣xz mod N⟩ is supplied, implementing the controlled power Ux2j by repetition costs 2j oracle calls. Across j=0,…,m−1 this is ∑j2j=Q−1 calls per phase-estimation sample. These oracle-query counts are separate from gate counts.
  • Classical bit work. Integer inputs are binary, elementary arithmetic is charged in bit operations, and schoolbook multiplication of two b-bit integers costs O(b2). A rejection sampler's random-bit cost is reported in expectation separately from deterministic bit operations.

The four coordinates used by the factoring cost theorem are ideal or explicit quantum gates, modular-multiplier calls, bare controlled-unitary oracle queries, and classical bit operations. An inapplicable branch is not reported as a zero-cost implementation.

Remarks

This is a cost convention for the stated algorithmic comparison. In particular, the ideal exact-angle QFT count is not a finite-alphabet or uniform-circuit theorem.

LemmaStatement: AI-adaptedProof: AI-generatedjudge pass (gpt-6-luna)Open item page →

Even and perfect-power preprocessing returns a proper factor

Statement

For a promised composite N≥4, the even branch and the finite integer-root precheck in Shor factoring with verified output and bounded outer retries return a proper factor whenever they return. If N is even, the even branch returns 2. If N=be for integers b≥2 and e≥2 and N is odd, the root-search branch is reached, detects an exact-power representation N=cf with c≥2 and f≥2, and returns its base c as a proper factor. Writing n=⌈log⁡2N⌉, its schoolbook bit cost is O(n5).

Facts & Assumptions

Given: A composite integer N≥4, n=⌈log⁡2N⌉, and the even/perfect-power preprocessing instructions in Shor factoring with verified output and bounded outer retries.

[F1]

Divisibility means d∣N exactly when N=dq for an integer q (Divisibility in Z: d∣a when a=dq for some integer q); integer powers are natural monoid powers with b0=1 and be+1=beb (Powers gn: natural exponents in a monoid and integer exponents in a group, with g0=e).

[F2]

Integer order is translation invariant, products of positive integers are positive, and the natural embedding preserves order (The integers form a totally ordered ring, The integers form a commutative ring, The naturals embed in the integers).

[F3]

The binary search and exponent range are those in Shor factoring with verified output and bounded outer retries; its capped repeated-squaring powers use integers at most N+1. Schoolbook multiplication of two n-bit integers costs O(n2) bit operations (Shor factoring cost-accounting branches).

Proof

1.1givenF1F2algebra

If N is even, 2∣N. Since N≥4, 1<2<N, so the returned integer is a proper factor.

1.2givenF1F2algebra

Suppose the precheck finds N=be with 2≤b≤N and e≥2. Then N=b be−1, so b∣N by [F1]. The power be−1≥2, so N=b be−1≥2b>b; hence 1<b<N and its explicit divisibility verification returns a proper factor.

2.1givenF1F2algebra

Conversely, suppose N=be with b≥2 and e≥2. If N is even, step 1.1 shows that the earlier even branch returns 2, so the root search is not reached. Now suppose N is odd. Then the root-search branch is reached, and 2e≤be=N≤2n, so e≤n and the loop includes this exponent. If the algorithm has not already returned on an earlier exact-power match in this root search, then for this fixed e, if 2≤x<y, ye−xe=(y−x)∑j=0e−1ye−1−jxj>0, because the factor and every summand are positive by [F2]. Hence x↦xe is strictly increasing, so binary search on [2,N] finds b; capping values above N at N+1 preserves each comparison with N. If the algorithm already returned on an earlier root-search match, that match was itself an exact-power representation of N, and step 1.2 shows that its returned base is a proper factor. Thus the odd perfect-power input returns a proper factor through the root search, while the even case is handled by step 1.1.

3.1givenF3algebra∎

There are at most n exponents and at most n binary-search comparisons per exponent because N≤2n. Each comparison uses at most O(log⁡n) capped multiplications of O(n)-bit integers, hence O(n2log⁡n) bit operations by [F3]. The total is O(n4log⁡n)=O(n5) for n≥2, proving the claimed bound.

TheoremStatement: AI-adaptedProof: AI-generatedOpen item page →

Rejection sampling is uniform, almost surely terminating, and has expected linear bit cost

Statement

For every N≥3, the procedure in Exact uniform sampling from the nonzero residue representatives halts almost surely and returns each a∈{1,…,N−1} with probability exactly 1/(N−1). If h=⌈log⁡2(N−1)⌉, its expected random-bit use is at most 2h and its expected total classical bit transitions are O(h).

Facts & Assumptions

Given: N≥3, M=N−1, h=⌈log⁡2M⌉, and the rejection procedure in Exact uniform sampling from the nonzero residue representatives.

[A1]

Countable choice and dependent choice are assumed only to form the countable product of fair-bit probability spaces used by the random tape (The Axiom of Countable Choice (ACω), The axiom of dependent choice: a relation in which every element is related to something admits an N-indexed chain, Assuming countable and dependent choice, countable products of arbitrary probability spaces). The finite probability branches of the number-theoretic proofs do not use this axiom branch.

[F1]

Each bit has probability 1/2 for both values, finite blocks have their product law under the countable product measure, and disjoint blocks are independent (Assuming countable and dependent choice, countable products of arbitrary probability spaces, Finite probability spaces, outcome weights, events, and event probabilities, Coordinate random elements of a countable product are independent).

[F2]

For a decreasing sequence of events in a probability space, the probability of the intersection is the limit of the probabilities (Continuity from above when one set has finite measure).

[F3]

For a nonnegative random variable, expectation is the tail integral (Expectation of a nonnegative or integrable random variable, Layer-cake formulas for random variables).

[F4]

The multitape bit-cost convention charges random-bit generation, binary arithmetic, comparisons and output writing (Classical bit-operation cost, Shor factoring cost-accounting branches).

Proof

1.1givenA1F1algebra

A block is accepted with probability p=M/2h. By the definition of h, M≤2h, and either M=2h or M>2h−1; hence p≥1/2. If p=1, every block is accepted and each valid b is output with probability 2−h=1/M. If p<1, for a fixed valid b<M the probability that the algorithm outputs b+1 on block t is (1−p)t−12−h by [F1], and summing gives 2−h∑t≥0(1−p)t=2−h/p=1/M.

2.1givenA1step 1.1F1F2algebra

The events that the first j blocks are all rejected decrease with j and have probability (1−p)j≤2−j by [F1]. Their intersection is the event that the algorithm never halts, and [F2] gives that event probability lim⁡j→∞(1−p)j=0. Thus the procedure halts almost surely.

3.1givenA1step 1.1F1F3F4algebra∎

Let K be the number of blocks read before the first acceptance. For integer j≥0, P(K>j)=(1−p)j. The tail function is constant on each interval [j,j+1), so [F3] gives E[K]=∑j≥0(1−p)j=1/p≤2, with the p=1 case interpreted as K=1. Computing h as the binary length of M−1 takes O(h) transitions. Each block reads and stores h bits in O(h) transitions; comparing that h-bit integer with M takes O(h) transitions, and incrementing an accepted value and writing the output use at most h+1 bits. Since h≥1, these operations also take O(h) transitions, so the nonrandom work per block is O(h). By [F4], these transitions and the h random-bit generations are charged. Thus expected random-bit use is at most 2h and expected total bit transitions are O(h).

TheoremStatement: AI-adaptedProof: AI-generatedjudge pass (gpt-6-luna)Open item page →

Order-to-factor output correctness

Statement

For every promised composite N≥4, every non-FAIL output of Shor factoring with verified output and bounded outer retries is a proper divisor of N. In its odd-unit branch, any candidate q that passes the algorithm's checks and is even has aq≡1(modN); with z=aq/2 mod N, if z≢±1(modN), both gcd⁡(z−1,N) and gcd⁡(z+1,N) are proper nontrivial divisors. No minimality of q is needed for this output-correctness claim.

Facts & Assumptions

Given: The input/output instructions in Shor factoring with verified output and bounded outer retries, a promised composite N≥4, and an execution that returns rather than FAIL.

[F1]

The even and perfect-power preprocessing return only a divisor d satisfying 1<d<N (Even and perfect-power preprocessing returns a proper factor).

[F2]

For a uniform residue a∈{1,…,N−1}, if gcd⁡(a,N)>1 it is a proper factor; if the gcd is one then a is a unit (Random residue gcd branch for factoring, For n≥1, [a]n is a unit if and only if gcd⁡(a,n)=1).

[F3]

For a unit a and an accepted even exponent q with aq≡1, z=aq/2 satisfies z2≡1 (Half an even order gives a square root of one).

Proof

1.1givenF1algebra

The even branch returns 2 only after checking 1<2<N and N mod 2=0. The perfect-power branch returns only after the exact checks 1<b<N and N mod b=0, and [F1] proves its candidate is proper.

1.2givenF2algebra

In a random-residue branch, a returned gcd candidate is checked to satisfy 1<d<N and N mod d=0; [F2] also shows that a nonunit gcd cannot equal N because the sampled representative satisfies a<N. Thus any returned candidate in this branch is proper.

1.3givenF3F4algebra

The order-finding branch is reached only after the even and perfect-power branches, so N is odd. It first verifies gcd⁡(a,N)=1 and aq≡1(modN). If q is even it sets z=aq/2; [F3] gives z2≡1(modN). If z≢±1, [F4] gives a prime-power factorization and the CRT sign lemma shows that both computed gcds lie strictly between 1 and N and divide N, so the explicit verification accepts a proper factor.

2.1step 1.1step 1.2step 1.3∎

Every return branch is one of steps 1.1, 1.2 or 1.3, and each branch verifies the strict divisor conditions before returning. Therefore every non-FAIL output is a proper divisor.

Remarks

This theorem proves output correctness conditional on the outer algorithm's exact period and gcd checks. It does not rely on a candidate being the minimal order, and it makes no probability claim about whether the order-finding branch is reached.

TheoremStatement: AI-adaptedProof: AI-generatedOpen item page →

Separate Shor factoring bit, gate, and query costs

Statement

Let N≥4, n=⌈log⁡2N⌉, and let δ=u/v∈(0,1) be a reduced rational encoded in binary, with B the bit length of v. Let T be the attempt cap in Shor factoring with verified output and bounded outer retries, and put Q=22n+3. For the arithmetic, control, sampler and post-processing work after the declared circuits are supplied, under the explicit reversible-arithmetic branch and ideal exact-angle QFT branch of Shor factoring cost-accounting branches, the procedure uses

  • O(n4T)=O(n4(1+ln⁡(1/δ))) quantum gates;
  • O(n2T) controlled modular-multiplier calls and zero external black-box queries;
  • O(n5+n4T+B3) expected classical bit operations, including sampler bits and exact computation of T.

For the same order-finding control flow with only bare controlled access to Ux, one phase-estimation sample costs Q−1 controlled-Ux queries, so the outer algorithm uses O(nT(Q−1)) such queries. No polynomial-in-n query bound, finite-alphabet compilation, uniform-family gate claim, or circuit-description generation-time bound is asserted.

Facts & Assumptions

Given: The algorithm Shor factoring with verified output and bounded outer retries on binary input N,δ, with its declared outer cap T and phase width m=2n+3.

[F1]

For m=2n+3, Q=2m, and internal failure target 2−b, the order finder uses t=4(n+1)b independent samples. Its cost theorem gives O(n2b) controlled modular-multiplier calls, O(n4b) gates and O(n4b) classical bit transitions in the explicit-arithmetic/ideal-QFT model; with bare controlled-Ux access, one sample costs Q−1 queries (Modular order finding with rational reconstruction, Separate order-finding query, gate, and bit costs).

[F2]

A known controlled modular multiplication uses O(n2) gates, and the repeated-squaring constants and inverses can be computed in O(n3) classical bit transitions (Gate and bit cost of modular multiplication and powering).

[F3]

The ideal exact-angle inverse QFT has O(m2) gates, while the named cost convention keeps this ideal count separate from the explicit arithmetic circuits, multiplier calls, bare-unitary queries and classical bit operations; it asserts no finite gate alphabet or uniform family (Shor factoring cost-accounting branches).

[F4]

The even/perfect-power preprocessing takes O(n5) schoolbook bit operations (Even and perfect-power preprocessing returns a proper factor).

[F5]

For h=⌈log⁡2(N−1)⌉, one rejection-sampler call halts almost surely, returns a uniform element of {1,…,N−1}, and uses at most 2h expected random bits and O(h) expected total bit transitions (Rejection sampling is uniform, almost surely terminating, and has expected linear bit cost).

[F6]

Classical bit cost counts machine transitions, including random-bit generation, arithmetic, comparisons, preprocessing and output writing (Classical bit-operation cost).

[F7]

The resource model records gate occurrences, work wires, oracle queries, description length, generator time, and classical bit costs as distinct coordinates; separate theorems must establish each bound (Circuit-family and computation cost model).

Proof

1.1givenF1algebra

The Shor algorithm fixes b=2, so [F1] gives O(n2) multiplier calls, O(n4) gates and O(n4) classical bit transitions for each order-finding invocation. There are at most T such invocations, so their totals are O(n2T) calls, O(n4T) gates and O(n4T) bit transitions. The definition of T gives T=O(1+ln⁡(1/δ)) because −ln⁡(5/8) is a positive constant.

1.2givenF1algebra

In the bare controlled-Ux branch, one phase sample applies controlled powers Ux2j for j=0,…,m−1. Repeating the bare call 2j times implements the jth power, so one sample uses ∑j=0m−12j=2m−1=Q−1 queries. For fixed b=2, [F1] gives t=8(n+1)=O(n) samples per order call. At most T calls therefore use O(nT(Q−1)) queries.

1.3F1F4F5F6algebra

The perfect-power check costs O(n5) by [F4]. Each order call costs O(n4) classical bit transitions by [F1]. The outer verification adds at most O(n3) transitions per attempt: binary modular exponentiation uses O(n) products of n-bit integers. Schoolbook multiplication takes O(n2) transitions, and binary long division has at most n quotient positions, each requiring an O(n)-bit comparison/subtraction, so product remainders also take O(n2) transitions. The Euclidean gcd algorithm has O(n) remainder steps because in each pair of successive divisions the positive remainder at least halves; each division takes O(n2) transitions by the same long-division count. Divisor comparisons and remainder checks fit this bound. By [F5], each sampler call uses O(n) expected total transitions. Thus all these per-attempt work is O(n4T) in total.

1.4givenF6algebra

The exact cap is computed by increasing t until 5tv≤8tu. Since v<2B and u≥1, δ>2−B; also (5/8)2B=(25/64)B<2−B. Hence T≤2B. Throughout this loop, the exact powers have O(B) bits, and each of at most 2B multiply/compare iterations costs O(B2) schoolbook bit transitions. Computing T therefore costs O(B3).

2.1F1F2F3F7step 1.1algebra

In the explicit-arithmetic branch, each multiplier call is charged to the supplied reversible circuit; it is not a black-box query. [F2] supplies its O(n2) gate count and [F3] supplies the separate ideal QFT count. The resulting gate count is the O(n4T) bound in step 1.1; the distinct coordinates are those of [F7].

3.1step 1.3step 1.4algebra∎

Combining steps 1.3 and 1.4 gives O(n5+n4T+B3) expected classical bit operations.

Remarks

The current cost-model definition and the QA08 arithmetic and order-finding cost theorems provide the stated separate resource coordinates. The supplied-circuit and ideal-QFT conventions above determine which bounds are asserted; they provide no circuit-description generation-time bound.

TheoremStatement: AI-adaptedProof: AI-generatedOpen item page →

Bounded-error success of Shor factoring

Statement

For a promised composite N≥4 and rational 0<δ<1, the procedure Shor factoring with verified output and bounded outer retries returns a proper divisor with probability at least 1−δ after its declared T=⌈ln⁡(1/δ)/(−ln⁡(5/8))⌉ outer attempts. Its exact even and perfect-power preprocessing branches succeed with probability one.

Facts & Assumptions

Given: The algorithm Shor factoring with verified output and bounded outer retries on N,δ, with T the least positive integer satisfying (5/8)T≤δ.

[F1]

The even and perfect-power preprocessing branches return proper factors whenever they apply (Even and perfect-power preprocessing returns a proper factor).

[F2]

A sampled nonunit residue immediately yields a proper gcd factor, and conditional on gcd one the residue is uniform in the unit group (Random residue gcd branch for factoring).

[F3]

For an odd composite that is not a perfect power, the true-order reduction succeeds on a uniform unit with probability at least 1/2 (Classical randomized order-to-factor success bound).

[F4]

The rejection sampler halts almost surely and returns a uniform representative (Rejection sampling is uniform, almost surely terminating, and has expected linear bit cost).

[F5]

Every returned output is a proper divisor (Order-to-factor output correctness).

[F6]

The algorithm uses fresh independent sampler tapes and fresh order-finding randomness across attempts (Shor factoring with verified output and bounded outer retries). For each fixed unit input, order finding uses finitely many measurements of finite registers (Success probability and repetition for modular order finding). Finite terminal outcome laws can therefore be combined by the finite product law, whose coordinate events are independent (The finite product of finite probability spaces, Product weights normalize, and coordinate events are mutually independent).

[F7]

In a finite probability space, conditional probability is P(A∣B)=P(A∩B)/P(B) when P(B)>0 (Conditional probability P(A∣B) for P(B)>0).

[A2]

The current body of Success probability and repetition for modular order finding states that for every fixed unit input and integer parameter b≥1, the exact-order output probability is at least 1−2−b. Setting b=2 gives at least 3/4 for each fixed unit input. The actual algorithm and theorem bodies and the proof route supporting this statement were inspected; this records the current carrier, not independent acceptance.

Proof

1.1givenF1F3algebra

If N is even or a perfect power, preprocessing returns a proper factor by [F1], so the theorem holds with probability one. Otherwise N is odd, composite, and not a perfect power, so [F3] applies.

1.2F2F3F4F6F7A1A2algebra

By [F4], the sampler halts almost surely and has uniform finite output law. For each unit representative a, let Ya be the finite set of order-finding measurement transcripts and μa its probability mass function; for a nonunit use a singleton Ya of mass one. One attempt has finite terminal outcome space ΩN={(a,y):1≤a<N, y∈Ya} with weights wN(a,y)=μa(y)/(N−1): the sampler marginal is [F4], the subsequent fresh measurement law is μa, and these weights sum to one. All conditioning here is on this finite space as in [F7]. Conditional on the unit event U, [F2] makes [a]N uniform in the unit group. Let G⊆U be the representatives whose true-order reduction succeeds, so [F3] gives P(G∣U)≥1/2. For each a∈G, [A2] gives exact-order probability at least 3/4; summing its transcript weights gives P(G and exact order∣U)≥(3/4)P(G∣U)≥3/8. On that event the algorithm returns a proper factor. This uses a pointwise order-finding bound, without assuming independence between the unit and its measurement outcome.

2.1step 1.2F5algebra

Let p be the probability that a sampled residue is a unit. The attempt succeeds with probability at least (1−p)+p(3/8)=1−5p/8≥3/8. Any output is correct by [F5]; a nonminimal or otherwise unsuccessful order candidate can only cause this attempt to continue.

3.1givenstep 1.2step 2.1F4F6algebra∎

Preassign T independent terminal records with the finite product law wN⊗T. By the fresh randomness in [F6], this is the joint terminal law of the actual attempts; stopping at the first success simply leaves subsequent records unused. The event that any of these finitely many samplers does not halt has probability zero by [F4]. Let Bi be the coordinate event that attempt i returns no factor. Step 2.1 gives P(Bi)≤5/8, and finite coordinate independence [F6] gives P(⋂i=1TBi)=∏i=1TP(Bi)≤(5/8)T≤δ. Thus the probability of returning a proper factor is at least 1−δ.

Remarks

The exact-order probability premise [A2] is taken from the current batch-32 carrier and checked against its stated fixed-unit hypotheses; the cited carrier remains a draft and this record is not independent acceptance. Countable choice and dependent choice are used only to supply the sampler's independent fair-bit tapes [A1].

5 · Examples, counterexamples and false statements

None yet.

Sources