K.3 Executable order recovery and factor certificates
Application: halve repeatedly while preserving the same base’s half-order power. The exponent above passed the modular-power test but turned the half-order power into . We can ask a smaller question: after halving the current exponent, does the same base still return to ? If it does, halve and ask again; otherwise stop. This step needs neither prior knowledge of the true order nor a complete prime factorization of the exponent. It removes excess factors of from a returning exponent. The odd multiple left behind can still exceed the true order.
State the rule in its full generality. Let be a monoid with decidable equality, expressed by Monoid G and DecidableEq G. For and a natural number , define
stripTwos x m =
if 0 < m ∧ m % 2 = 0 ∧ x ^ (m / 2) = 1
then stripTwos x (m / 2)
else m
Division here is natural-number quotient. All three conditions must hold for a recursive call; otherwise the current exponent is returned. The inputs are only , with no unknown supplied. A monoid needs associativity and an identity; it need not be a group, finite, commutative, or cancellative. Actual evaluation also requires computable multiplication, identity, and equality. Every recursive call has : a positive even number is at least , and division by strictly decreases a positive natural number. Thus the natural measure proves termination. At the first condition fails and the output is . Termination alone gives no bit or gate complexity bound.
Let be any monoid with decidable equality. For and , assume and . Put and . Then all of the following hold:
- ;
- ;
- ;
- there is a natural number such that ;
- is odd;
- if is even, then is even and ;
- if is odd, then is odd.
Here is automatically positive: the positive returning exponent and orderOf_dvd_iff_pow_eq_one give , and zero cannot divide a positive number. The third clause similarly gives , so the natural quotient in the fifth clause satisfies . This is not a claim about the floor of a nonintegral ratio. Zero has a defined output but lies outside the correctness statement: every element satisfies , including elements with no positive returning exponent, for which orderOf is defined to be . A zeroth power therefore cannot establish positive order.
Use strong induction on the current positive exponent , retaining four properties together: the output is positive, is a power of times the output, the output still returns to , and its quotient by is odd. A continuation passes the problem to the smaller , rather than assuming the same claim again at the original fixed . If recursion gives , the evenness test yields
Each successful halving increments the witness ; a terminal branch uses . This constructs the natural witness in the fourth clause and supplies the divisibility in the second. Positivity and return to the identity are retained through the recursive premises.
At a terminal branch the output is the current positive and . We have . If the quotient were even, write ; then
All three continuation conditions would hold, contradicting termination at that branch. The quotient must be odd. This uses the usual order-divisibility and parity argument; the corresponding terminal property also appears as div_orderOf_odd_of_pow_ne_one in SymbolicQuantum/Shor/ReductionLemmas.lean, with no claim that it is a new mathematical fact.
Finally write . If is even, is even, and natural division gives
If is odd, is a product of odd numbers and is odd. Every power belongs to the same element; no interchange of different elements or cancellation law is needed. The full proof is checked by the Lean kernel.
Keep the base fixed when connecting the selector. Fix the same actual parameter record as before, with , , and . A return select a N L = some m supplies and Nat.powMod a m N = 1. The earlier Nat.powMod_def, Nat.cast_pow, and residue conversion turn precisely this test into , so the seven clauses apply to this . The same guard can be evaluated using natural-number modular powers; for and , Python’s pow(a,e,N) computes :
def strip_twos_mod(a, m, N):
while 0 < m and m % 2 == 0 and pow(a, m // 2, N) == 1:
m = m // 2
return m
This simply expresses the same guard through modular exponentiation. A return none still means that the menu has no positive passing entry; it supplies no positive exponent to halve. The process always tests powers of the original base. It does not resample the base or change the controlled modular multiplication, native positive-exponent circuit, work input , or padded target carrier. For the positive-exponent experiment, both observed labels are still reflected before the original menu is formed.
If the selector returns the true order , halving leaves it fixed. For odd the evenness test fails. For even , we have , so minimality of the true order excludes and the guard again fails. Thus stripTwos x r = r. The earlier exact-selection event is consequently contained in the exact-output event after halving, whose probability remains at least . This uses the same independent-reset law as before and introduces no new joint sampling model. Halving may also recover the true order from a previously inexact return, but does not flag exactness on each output.
Return to . Starting at , the test first reduces the exponent to ; then , and the process stops. Starting at , it first reduces to , since ; then , so it stops. Hence
Both paths yield the half-power residue , whose representative gives and . Before halving, the half-power residue of was , giving and . The reduction retains the odd quotient , making clear that a correct half-power does not imply exact order. It also tests no complete set of prime factors and cannot replace the full prime-factor certificate above.
Preserving the half-power also preserves the need for Good. The new interface is only , under the even-order condition. Factor extraction still requires the same actual unit to satisfy
Here powers are written after projecting the unit to ; its order agrees with the order in the unit group. Minimality of the true order separately excludes half-order power . Under the conditions and in Example K.17, the existing true-order Good argument supplies two proper factors; equality of half-powers connects its certificate to the same residue of the halved output.
The halving theorem states equality of powers in a monoid. Connecting it to gcds of large natural-number powers additionally requires explicit congruence, positivity conditions for natural subtraction, and gcd invariance; a natural-number power must not be equated with its standard residue. The values and above are direct calculations on concrete residues. The halving module itself states no general natural-number gcd transport or factor probability.
Two boundaries make the scope concrete. For , the trace is ; the true order is , and the odd output supplies no even half-order extraction route. For , we have , so the output remains . Its order is even but the second Good condition fails; the gcds are and .
This same-base halving rule also differs from Ekerå, On completely factoring any integer efficiently in a single run of an order finding algorithm, arXiv:2007.10044, §3.2, which samples new random bases and processes a squaring chain. The reference distinguishes the algorithms; its performance conclusions are not transferred here. Termination and these deterministic properties provide no efficient method for obtaining the initial , complete factorization, exact-order certificate, bit or gate complexity bound, hardware success rate, guarantee for arbitrarily correlated repetitions, or Las Vegas conclusion, and no mathematical originality is claimed. The quantum product law at a fixed actual base and the Good law on uniformly sampled units remain different sampling models. Their probabilities cannot be multiplied without a common joint law and the corresponding conditional probabilities.
One step further: cover the original exponent’s prime factors and strip down to the order. Halving removes only excess factors of , so can still leave . If an additional finite list contains every prime divisor of the original returning exponent, we can repeatedly test division by each entry. This additional input differs from the menu computed solely from observations: the selector does not supply it.
For any monoid with decidable equality, an element , and natural numbers , define
stripFactor x p m =
if 1 < p ∧ 0 < m ∧ p ∣ m ∧ x ^ (m / p) = 1
then stripFactor x p (m / p)
else m
stripFactors x P m =
P.foldl (fun n p => stripFactor x p n) m
Each successful division strictly decreases the current positive exponent because . Otherwise the current value is returned and the fold moves to the next entry. The inputs are only , with no true order supplied. Entries are processed in their original order, without deduplication or a requirement that every entry be prime.
Let be any monoid with decidable equality. For , a finite list of natural numbers, and , assume
Put . Then
Coverage concerns the original input : each prime divisor must itself occur in . It is a correctness premise, not a proof supplied as an additional function argument. The list may repeat entries or include extra composites, , and . No group, finiteness, commutativity, or cancellation assumption is required. Entries and never trigger recursion; the exponent always returns but lies outside this correctness statement. The case is included.
Write . A positive returning exponent gives and . First apply strong induction to the actual recursion for a single supplied factor. If and , the output satisfies
When , it also satisfies . In a recursive branch, combine the induction hypothesis at with , increasing the witness by . At a terminal branch, would give . Hence and : all four recursion conditions would hold, contradicting termination at this state.
Next induct over the list. The output remains a positive returning divisor of the original input, and every processed entry greater than is excluded from dividing the current output’s quotient by . Later processing replaces a returning exponent by a returning divisor . Since and divides both, . A previously excluded factor therefore cannot reappear in the later quotient. This also handles repeated entries and extra composites.
Every prime divisor of the final output divides the original , so coverage places it in . If division of the final exponent by this prime still returned to , order divisibility would force the prime to divide , contradicting the list invariant. Direct application of the existing orderOf_eq_of_pow_and_pow_div_prime gives . The proof establishes invariants of the actual recursion and fold; the terminal order criterion retains its existing source. The complete proof is checked by the Lean kernel.
Continue from the same selector’s return. Suppose the preceding select a N L = some m holds. Keep the same actual parameters , , and . The return contract gives . A list covering this original therefore makes stripFactors x P m equal the same base’s true order, even if that order was absent from the original menu. A return none still means no positive entry passed; it supplies no positive exponent to this theorem. With the native positive circuit, continue to reflect both observed labels before constructing the original menu and selecting, then process the same base. This step does not replace the sampling law.
For , input gives ; input also gives , removing the odd excess factor left after halving. For the identity and , the list gives , whereas gives and gives . In the last case, both original prime divisors divide a listed entry , but neither occurs as an entry. Divisibility into some list member cannot replace the theorem’s coverage condition.
How many power tests does the program actually call? Keep the original input, guards, and output, and add a count component. First check the arithmetic conditions , , and . If any fails, no power-equality test is called and the count is . If all pass, call the interface once, counting whether it succeeds or fails. Only success recurses, at the same quotient . The corresponding computable pair is defined by
stripFactorCost x p m =
if 1 < p ∧ 0 < m ∧ p ∣ m then
if x ^ (m / p) = 1 then
let r := stripFactorCost x p (m / p)
(r.1, r.2 + 1)
else (m, 1)
else (m, 0)
stripFactorsCost x P m =
P.foldl (fun r p =>
let s := stripFactorCost x p r.1
(s.1, r.2 + s.2)) (m, 0)
The fold still processes the original list in its original order: the first component carries the current exponent, and the second accumulates calls. Write . For this equals ; Lean’s total-function convention is .
For every type equipped with a monoid structure and decidable equality, every element , every finite list of natural numbers, and every , put
Then both clauses hold:
This count bound requires neither nor . It also requires no prime-factor coverage, primality of entries, absence of duplicates, finiteness, group structure, or cancellation. For , every entry stops at the arithmetic guard and the result is ; an empty list returns . Entries and call no power test, while arbitrary other natural entries follow the original guards. The preceding exact-order theorem still requires its original positivity, returning, and coverage conditions.
Strong induction on the current exponent proves equality of the first components: both programs stop under exactly the same conditions or recurse at the same . Carry this equality through the list fold.
For one list entry, let be its input, its output, and its count. Prove the potential inequality
If the arithmetic guard fails, ; if the power test fails, . Both terminal branches satisfy the inequality. On success, , , and , so and
The decrease in logarithmic potential therefore pays the cost of this successful test; apply the induction hypothesis at the quotient. Sum the single-entry inequalities along the original list. Intermediate potentials cancel, giving . Dropping the nonnegative final potential gives the count bound. The full proof is checked by the Lean kernel.
For example, retain . The tested exponents are , with residues , respectively. The first and last tests succeed, and the two failed tests also count, so the returned pair is . Finally : only the arithmetic guard is checked, with no additional power test.
The classical repeated-division order algorithm appears in Andrew V. Sutherland, MIT 18.783, Spring 2015, Lecture 8, §8.3, Algorithm 8.2, printed page 3 (lecture notes). The notes start from a returning multiple in an additive group and its prime factorization. Here multiplication and the identity replace addition and zero; the statement permits arbitrary decidable monoids and extra list entries. No algorithmic originality is claimed. The count theorem above is derived in trureturing for that classical algorithm; no mathematical originality is claimed.
This conditional algorithm supplies no method for acquiring or efficiently factoring the exponent. With verified coverage, a positive returning exponent is indeed processed into the true order; obtaining the information needed for coverage remains a separate task. The logarithmic bound counts only calls to the power-equality interface. It excludes acquiring , evaluating arithmetic guards, and multiplications inside modular exponentiation, and supplies no running-time, bit-complexity, quantum-gate, or complete Shor complexity bound. No new quantum success probability, uniform-unit sampler, guarantee for arbitrarily correlated repetitions, hardware implementation, or complete recursive integer-factorization result follows here. Combining the classical Good law with fixed-base quantum observations still requires an explicit common joint law.
From the true order to factors: which bases fail? Start with and . The local orders modulo and are and , so the global true order is . The half-order power is locally and , respectively, and therefore is neither nor modulo . What matters is how many factors of occur in each local order: here, and . We first count failing tuples in an arbitrary finite family of cyclic groups, then transport the same event to the actual unit group.
For every nonempty finite index type and every family of groups , assume each is finite and cyclic, and specify with . Put
Here is the true group-element order (Lean’s orderOf), and is natural-number division. Then
The factor sizes may differ, and the product need not be cyclic. The count includes every tuple, including the identity and tuples of odd order, and allows .
Write and . For a positive integer , let be its exponent of the prime , namely d.factorization 2. The order in the product is the least common multiple of the local orders, so .
In one cyclic factor, take an element of order and a positive even multiple of . Since and the cyclic group has a unique element of order , this half-power is either or . Moreover,
For the last equivalence, all other prime-exponent inequalities already follow from . Thus exactly when . Apply this with in each coordinate. If is even, failure means that every local valuation reaches the same maximum; if is odd, every local valuation is and failure also occurs. Hence
Choose a full-order generator in each factor. With , the number is even and . Multiplication switches between and . The preceding criterion implies : equal valuations would agree on whether they equal , contradicting the switch.
Fix an anchor coordinate . Encode a failing tuple and Boolean bits on the other coordinates by retaining and setting when , or when . The anchor reveals the original common valuation . At every other coordinate the encoded valuation equals exactly when its bit is . Thus the encoding recovers every bit, and cancellation of the generators recovers . This is an injection from into ; comparing cardinalities proves the bound. For there are no bits, every tuple fails, and the bound is equality. The full proof is checked by the Lean kernel.
This common-valuation count is the classical argument in Shor (1997), Section 5, PDF page 16; no new mathematical priority is claimed. The application below follows the pinned Blueprint/D5/S3/FiniteGroups/Cyclic/HalfOrderSynchronization.md, Blueprint/D5/S3/Quantum/ShorContinuedFractions.md, and the attribution in Library/QuantumChannels/shor1997gateorbits.md. It derives consequences from the count and the order, congruence, and coprime-cancellation facts; the GID above does not certify an entire factoring procedure.
Full prime powers. Take any odd natural . Let be its set of distinct prime factors, , and put
The index set is nonempty, every , and every is an odd prime. Each full prime-power unit group is cyclic. Its literal unit squares to and differs from , so has order . Indeed, , whereas modulo is possible only for or .
The Chinese remainder ring equivalence lifts to a multiplicative equivalence
The pinned construction applies Units.mapEquiv to the multiplicative equivalence of ZMod.equivPi N hN, then composes with MulEquiv.piUnits, where proves . It preserves true orders and every natural power, and sends literal to coordinatewise literal . Consequently, for
we have . Restricting to the failure subtypes gives a bijection between actual failing units and failing tuples. Nat.card_congr transports their equal cardinalities together with equality of the full carrier cardinalities. In particular, if
then Theorem K.16 yields . Here because the carrier contains the identity, , and . Dividing by these positive quantities in the real or rational numbers gives
This probability uses uniform sampling of the full actual unit group. The identity remains sampled and has false Good, since its order is . If is not a prime power, its prime-factor set is nonempty and does not have cardinality (isPrimePow_iff_card_primeFactors_eq_one), so . The failure proportion is then at most and success at least . Prime powers with remain covered by the count, which gives only the lower bound for success. Every actual exponent is retained, with no squarefree restriction.
The same Good gives both proper factors. This deterministic step requires only natural and ; it also applies to even . Let be the unit represented by , put , and assume . Finiteness gives , and evenness gives with . Minimality of the true order excludes , Good excludes , and
An arbitrary even period cannot replace the true order here. Coprimality and exclude , so and the natural number . Coercing the unit power to identifies the residue of with . The bound permits Nat.cast_sub to identify natural subtraction with the ring difference. Therefore
The first line follows because has zero residue; the second follows from and , respectively. If , coprime cancellation in the product forces , a contradiction. Symmetrically, forces , also a contradiction. Each gcd is positive and at most ; equality to would force divisibility of the corresponding factor. Thus, simultaneously,
Changing representatives preserves the gcd pair. Keep . For an actual unit , put , let be the canonical natural representative of , and let be the canonical natural representative of . Both are coprime to , hence . Every natural representative satisfying is also coprime to and satisfies . Compatibility of powers with residues gives
These are congruences, not natural-number equalities. Since are all at least , Nat.ModEq.sub permits subtraction of on both sides; addition of preserves congruence directly. Applying Nat.ModEq.gcd_eq gives
The two certificates therefore hold for the original representative’s power, the canonical base’s power, and the canonical half-power representative. Write when each of and divides and lies strictly between and . The certified event is explicitly
The deterministic argument proves ; projection to the first conjunct proves the converse. The identity map thus restricts to a bijection of the success subtypes, so
Returning to uniform unit sampling for odd , the same event with both certificates has probability exactly . It inherits the bound , and at least when is not a prime power. Adjoining certificates changes neither the success event nor its sampling carrier.
Classical unit sampling and the preceding actual quantum measurement at a fixed base are different random choices. Their Good and candidate-list probabilities cannot simply be multiplied: a combination needs an explicit common sampling law and the appropriate conditional probabilities. The all-pairs least-common-multiple list-membership bound for exactly two actual observations has been derived above under an explicit independent-reset premise, and least-passing-entry selection gives the same bound for exact output. The argument still supplies no efficient uniform-unit sampler, certified exact-order selector from the full candidate least-common-multiple list, guarantee for arbitrary correlated repetitions, complete recursive prime-factorization implementation, or bit and gate complexity. Concentration of the conditional posterior comb retains its earlier literature boundary.