Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

K.2 Continued-fraction candidates and observation events

Passing from the distribution to postprocessing requires a number-theoretic bridge. The earlier example concerns only the marginal: , so it cannot instantiate the recovery results below. Now impose the resolution condition and ask a deterministic question: given the measured integer, which finite list is guaranteed to contain the required fraction?

Definition K.9 (Finite continued-fraction candidates from observable inputs)

For natural numbers , let be the finite list of continued-fraction convergents of a rational . Define

Its only inputs are the measured integer , counting capacity , and modulus . The unknown order and phase index are not inputs. Each rational is represented in lowest terms with positive denominator.

How is actually enumerated? Put and . If , return . Otherwise recursively enumerate , replace each entry by , and prepend . For example, starts with , then , yielding . The positive reduced denominator strictly decreases at every recursive call, making the list finite. Below we also bound its length, while distinguishing stage counts from actual work. The source definition convergents also accepts negative rationals, zero, and integers. Totalized rational division defines candidates even at , although the application below always has .

This is a list of genuine real continued-fraction convergents. The exact correspondence mem_convergents_iff says that, for any rationals , membership is equivalent to the existence of with . The real definition repeats the terminal value after a rational expansion terminates; the finite list only needs to retain that value. Write reduced for the rational . For , its denominator formula reduced_den is .

Beyond termination, the list’s length can be bounded. Write for the canonical positive reduced denominator of a rational , and read as ; here always.

Theorem K.10 (Logarithmic length of the rational convergent list)LEAN ✓

For every rational ,

This includes negative rationals, zero, and integers. An integer has denominator and a singleton list, attaining equality.

Proof

Use strong induction on the positive reduced denominator. An integer terminates immediately. If the reciprocal fractional part is still nonintegral, the denominators after two and one recursive steps sum to at most the original denominator, and the former is strictly smaller than the latter. Thus two steps at least halve the denominator. Monotonicity of the natural logarithm and its multiplication-by-two identity account for the two removed entries before applying the induction hypothesis. The full proof is checked by the Lean kernel.

For the observable candidates, only and are needed. Filtering cannot increase length, and

Applying Theorem K.10 and monotonicity of the natural logarithm gives

This application requires neither nor . At the bound is ; at the filtered list is empty. It counts entries or Euclidean recursive stages. It supplies no bound on all the repeated map work, arithmetic bit complexity, or gate complexity. A short list does not certify an exact selector or make every candidate denominator divide the true order. The recovery results below still require their actual parameters, resolution, nearestness, and coprimality hypotheses.

Theorem K.11 (Conditional candidate membership for a nearest sample)LEAN ✓

For every actual padded modular-multiplication record , write and , with . Its work width satisfies , and its true order satisfies . For every independently chosen counting width , put . For every and , assume

Then

Proof

Excluding wrap-around turns circular nearestness into ordinary absolute error at most . If is the reduced denominator, and give , so the error is strictly below . Legendre’s approximation theorem supplies a real-convergent index; the finite-list correspondence gives actual membership, and passes the candidate filter. The denominator formula gives . The full proof is checked by the Lean kernel.

The hypothesis is itself. As defined above, it asserts the existence of an integer such that

Why can no wrap occur here? Put and . Then and . The nearest nonzero integer shifts, and , give errors at least and , respectively, both strictly greater than ; more distant integers are also excluded. Thus . The non-strict nearest-grid hypothesis still admits either rounding tie. Strictness in Legendre’s radius comes from the denominator’s square:

Theorem K.12 (Conditional true-order membership for a coprime phase)LEAN ✓

For every actual record above (, , , and ), every independent counting width , , , and , assume

Then the true order occurs in the list of candidate denominators:

Proof

By Theorem K.11, the reduced phase belongs to the candidates. Coprimality makes its denominator equal to . The full proof is checked by the Lean kernel.

The latent parameters describe hypotheses about the measurement; they are unknown when computing the candidates. The second result places the true order in a finite list without certifying how to select it. The first result’s divisibility conclusion concerns only the distinguished reduced phase, never every candidate. The following are independent exact rational computations, without additional Lean badges for the examples:

Nearest error and bound

The first row’s full list was computed by Euclidean recursion above; is removed because its denominator is not below . The second row’s full list is . Filtering retains both the correct denominator and the denominator , which does not divide . Thus neither “take the last candidate” nor “pass one modular-exponentiation test” is an exact-order selection algorithm certified here. Even a passing test alone establishes only : the tested exponent is a multiple of the order, and need not equal it.

The rational zero has denominator , so the first theorem includes . When , the sole phase is and , so the second theorem applies too. The recovery conditions and already exclude , whereas the preceding marginal permits these widths. Neither candidate theorem requires or identifies work width with counting width . With this chapter’s positive-exponent final transform , first reflect the observed label to , then use nearestness for the same phase and compute these candidates. Keeping the label unchanged would change the phase being approximated.

One actual measurement: the probability that the candidate list contains the true order. We can now connect conditional recovery to the actual marginal. Fix any actual parameter record as above, with , , , , and . Use exactly and : modular multiplication fixes the padding, the work input is , and the work and counting widths are independent. Define the finite measurement event

The event is exactly the source predicate r ∈ (candidates y.val Q N).map Rat.den. The unknown defines success; the candidate computation still takes only . All quotients are real after casting natural numbers. By Theorem K.4, is the event probability of this actual counting measurement. We will obtain

This bound follows by combining the cited results with finite counting.

First find an admissible nearest label for each phase. For , round the real number to an integer . The nearest-integer estimate abs_sub_round gives . Since and imply , we have

Since is an integer, . Thus we may take with . Dividing by gives

This satisfies with integer shift . Only existence is needed; at a midpoint tie, either non-strict nearest choice satisfies the same estimate. Phase is included.

Next bound the same event within each component. Let

For each , Theorem K.12 places the chosen in , and Theorem K.6 gives . Every is a squared complex modulus and hence nonnegative, so

We have first summed the event within each component. We have neither added possibly coinciding as distinct measurement outcomes nor needed to prove the chosen labels distinct.

Finally combine the actual mixture with the coprime count. By Theorem K.3, . Interchanging finite sums and applying the component event bounds with the positive weight gives

The last step is finite counting: Fin.sum_univ_eq_sum_range rewrites the sum over as a sum over , and Nat.coprime_comm aligns the coprimality predicate with the definition of Nat.totient. Thus . This ratio comes from the spectral weights and number of coprime phases for the same actual input; it assumes no additional experiment that samples a latent phase uniformly. For , and ; the sole phase and the only measurement outcome with nonzero probability are zero, and the zero candidate has denominator . The actual event probability is , so the bound still holds. The derivation needs no and adds no width restriction beyond the existing resolution condition.

Positive-exponent outputs use a reflected event. If the final transform is and is the observed label, use the involution defined above. The event is then

The equality uses and . Both nearestness and candidate computation apply to the reflected label , so the list is candidates (rho b).val Q N. This does not replace the unreflected positive-exponent candidate event by .

This lower bound concerns the probability that the finite candidate list from one actual measurement contains the true order. It does not certify exact-order selection from the list, nor that every candidate denominator divides the true order. It specifies no joint law for two measurements; the next application adds an explicit independent-reset sampling premise. An exact least-common-multiple product law for ideal phase sampling, factor extraction, full bit or gate complexity, hardware realization, and empirical performance remain outside this single-run derivation. Concentration of a conditioned posterior comb has not been established by bounding the actual marginal event.

Application: two independent resets let two denominators recover the true order. Reduction can remove prime factors from one recovered denominator; a second denominator can supply the missing factors. Following the two-reset application in the owning ShorContinuedFractions exposition, we ask whether the all-pairs least-common-multiple list computed from two observed integers contains the true order.

Fix the same actual parameter record throughout, with

We still have . Each run starts afresh with the original counting state and the original work input , uses the same , and ends with the inverse Fourier transform. The base, modulus, work width, and counting width are identical in the two runs. Write

This is the actual marginal, summing over the full work register, including padding. Independent resets are an explicit modeling and sampling premise of this application: the outputs of the two complete preparations and measurements have joint law

Equal marginals alone do not imply this law. For example, always copying the first outcome into the second can preserve both marginals while usually changing the joint law. Retaining an unreset work register or allowing arbitrary correlated repetitions does not justify the product law either. Nonnegative squared norms and Theorem K.4 give

The decoder sees only the two observed integers. Define the denominator lists and their all-pairs list by

The source expressions are (candidates y.val Q N).map Rat.den and (D y).flatMap (fun d => (D z).map (fun e => Nat.lcm d e)). For each in the first list, form its least common multiple with every in the second, then concatenate those smaller lists. The computation uses only , with neither the unknown nor a latent phase index as input. Define success by

The indicator is one when membership holds and zero otherwise. Each observed pair is counted once, even if candidate entries repeat or several denominator pairs produce . The true order defines mathematical success without entering the list computation. We will derive

Conditional recovery: what does each denominator lose? For every , the preceding nearest-integer construction supplies labels satisfying for and , respectively. Explicitly, round to an integer with error at most ; ensures . Only existence is needed, including phase zero and either non-strict nearest choice at a midpoint tie.

By Theorem K.11, both reduced phases belong to their respective candidate lists. The existing reduced_den formula identifies the two distinguished denominators:

Both gcds divide . Applying Nat.div_lcm_eq_div_gcd and Nat.gcd_gcd_gcd_right gives the exact identity

Thus whenever the phase pair is jointly primitive, meaning . Neither numerator needs to be individually coprime to . This makes no divisibility claim about the other candidate denominators.

For example, take the actual modulus , base , work width , and , with true order . For phase numerators , nearest observations are , with errors and , respectively. Computing directly from the observable inputs gives

Here and . The recovered denominators and are both smaller than the true order, but their least common multiple is . The phases and true order explain why this observed pair succeeds; they were not used to enumerate its lists. This is a deterministic hand calculation, not a substitution of one observed pair’s probability for the probability of the whole event.

At least half of all phase pairs are jointly primitive. Let

Every failing pair has some prime dividing both numerators. For each such , send a label with to . This is an injection into ; since , the division of is exact. Zero is included among the divisible numerators. At most ordered pairs therefore have both coordinates divisible by . A union bound over the distinct prime factors gives

Repeated prime factors appear only once in this sum, and overlaps among bad sets merely weaken the upper bound. Ratios are taken after casting to the reals.

Separate . Every remaining prime divisor is odd, at least , and at most , hence belongs to . Use the original finite-tail estimate reciprocal_square_shifted_finite_tail_le: for every real and every ,

This retains the full positivity hypothesis and the whole reciprocal-square sequence. The proof keeps the first term and bounds subsequent terms using

The resulting finite sum telescopes; dropping its nonnegative reciprocal endpoint gives the stated bound. For the left side is an empty sum. With and ,

Good and bad pairs partition the phase pairs, giving the sufficient bound . Only this half-density estimate is needed. The exact density in an ideal model of independent uniform phases is a distinct literature quantity. The union estimate above neither proves that exact product formula nor identifies it with the actual finite-clock candidate-event probability. Combining these standard counting and tail arguments makes no claim of mathematical novelty.

First fix a phase pair and bound the whole event within that component. Retain and . For a fixed , define

If is jointly primitive, conditional recovery gives . The specialization to actual modular phases of Theorem K.6 gives and . Every other summand is nonnegative, so

This bounds the mass of the entire membership event in one fixed component. It does not repeatedly add actual observed-point probabilities indexed by different latent phases.

Then expand the actual product law and combine with weight . By Theorem K.3, each actual marginal is . Under the explicitly assumed independent-reset law,

The second line simply interchanges finite sums. Latent phase pairs index the spectral expansion of the actual product distribution; they are neither decoder inputs nor additional measured random variables. Even if several phase pairs choose the same observed pair, that observed pair has a single indicator, and the expansion decomposes its own actual mass. Neither duplicate candidates nor colliding nearest labels overcount the event.

Positive Fourier transforms and the native positive circuit: reflect both labels on the same controlled state. Keep the identical actual state before the Fourier transform,

For each work coordinate , put , where is the chapter’s positive-exponent . Write for the same label reflection previously denoted by :

The zero branch is essential: zero reflects to zero, not to the integer outside . On each column of this same , the positive kernel equals the negative kernel at the reflected label. In the nonzero branch their phases differ by the integral frequency ; at zero they agree directly. Applying the existing phase_conj and phase_shift_int identities gives exact equality of the full work vectors:

This compares all work amplitudes, not just one orbit coordinate. Defining and summing squared moduli over the full work carrier gives

The final equality reindexes by the involution . For any predicate on observed pairs, reindexing by the product permutation on both coordinates yields

Thus, when the two positive-Fourier experiments explicitly assume independent resets with joint mass , the correct success event and bound are

This positive product law is also nonnegative and normalized. Both observed labels must be reflected before candidate computation. No such bound is asserted here for the raw, unreflected positive event . The argument reflects actual observations and assumes no equivariance of a nearest-label selection rule.

Theorem 15.3 connects the same conclusion to the actual native positive circuit. For every OracleModel and its Interpretation, let be the onBinaryLabels matrix of Source.circuit oracles n under that interpretation. The cited statement identifies its action with on every vector. Applying it to each column of the same actual controlled state gives

Summing squared moduli over all gives exactly the same . Its normalization, the event identity reflecting both coordinates, and the bound under two independent resets therefore apply. The controlled modular multiplication, work input, and joint state before the Fourier transform have not been replaced.

Edge cases and scope. Recovery needs only the stated resolution , without . When , the only phase pair is ; it is jointly primitive, , and the prime-factor set is empty. Both actual outcomes are zero, , , and the actual success probability is . For every , the definitions retain zero numerators, one or two zero observed labels, and repeated prime factors. In particular, phase has distinguished reduced denominator . Both midpoint ties are allowed, with no uniqueness requirement for nearest labels. Reflection and native circuit equality themselves include ; recovery with already excludes . The finite-tail estimate also applies when its summation range is empty.

The combined application establishes precisely that the full all-pairs list computed from two observations contains their common true order with probability at least , under independent resets of the same actual modular-multiplication experiment. It gives no certified exact-order selector from the full candidate least-common-multiple list. It also does not certify that taking the least common multiple of every entry in that list equals the true order: other candidates can introduce extra factors. Guarantees for arbitrary correlated repetitions, efficient uniform-unit sampling, recursive prime factorization, bit or gate complexity, and hardware performance remain outside this application. The uniform-unit Good bound and simultaneous gcd extraction below concern another sampling law. Without an explicit common joint law, their probabilities cannot simply be multiplied by this quantum event probability.

The candidate-membership and list-length results come from ShorContinuedFractions, FiniteRationalConvergents, and FiniteRationalConvergentsLength at the pinned source. The rational-list and length proofs are supplied by aicyberg; the modules retain the provenance and Apache 2.0 license of Finite-register phase estimation and spectral Shor order finding (solanaqubits/leanbook, fixed revision). Source audit #30614 still has three validated items and one unfinished item: the broader clock statement and independent ideal-sampling product law are not settled by this specialization to the modular bound. The separate earlier marginal-source audit #30521 still has three validated and fifty-nine unfinished items. These statuses describe coverage, not a refutation of the mathematical proofs above. The single-run list-membership bound above combines conditional membership, the actual mixture, and finite coprime counting. The two-run all-pairs list event instead uses a sufficient half-density bound for jointly primitive phase pairs under an explicit independent-reset premise. Below, a separate finite cyclic-family count yields the Good proportion for uniformly sampled units and both factor certificates on the same event. Independence remains a sampling premise; arbitrary correlated repetitions, certification of each individual return, classical bit complexity, full quantum gate complexity, and hardware performance retain the boundaries in Remark 15.7.

Application: choose the least passing exponent from the observed list. The preceding application combines two denominator lists into a finite menu and bounds the probability that the true order belongs to it. We now add a definite selection rule: test each exponent by modular exponentiation, then take the least value that passes. Following the selector application in the ShorContinuedFractions source exposition, we derive the result here from existing list and multiplicative-order properties.

For arbitrary natural numbers and any finite list of natural numbers, write

select a N L =
  List.argmin id
    (L.filter (fun d => decide (0 < d ∧ Nat.powMod a d N = 1)))

This composes existing functions. The filter keeps positive exponents that pass the modular-power test; List.argmin id returns their least natural value as some m, or none if the filtered list is empty. Its only inputs are . There is no unknown true-order input , latent phase, or flag saying whether this attempt is exact. The domain retains list order, duplicates, and empty lists. We do not first replace the list by a set or assume that every entry divides the order.

Connect the executable test to the actual multiplicative order. To interpret the output in terms of order, fix any actual parameter record and put

The record also supplies and a work width large enough for the modulus. Thus is the actual order for this same base and modulus. The following list argument is independent of counting width, resolution, and how was obtained. By Nat.powMod_def, the test computes the natural residue . Since , the literal residue is its canonical representative. ZMod.natCast_eq_natCast_iff' and Nat.cast_pow therefore give

Call the filtered list . If , then List.argmin_mem puts in , yielding

The last clause follows from orderOf_dvd_of_pow_eq_one. Every that is positive and passes the modular-power test belongs to , so List.le_of_mem_argmin gives

This is minimality among passing entries of the supplied list. Every positive passing exponent is a positive multiple of , hence ; orderOf_le_of_pow_eq_one also gives that inequality directly. Nonpassing entries do not enter the comparison, and missing exponents are not searched. A return therefore certifies positivity, a passing test, list membership, minimality within the list, and . It carries no flag certifying and performs no search for smaller positive exponents outside the list that give residue one.

The selector returns the true order if and only if the menu contains it. For every actual above and every finite , the exact correspondence is

For the forward direction, the returned belongs to the filtered list and therefore to the original list .

For the reverse direction, suppose . Since and , it passes the modular-power test and belongs to . By List.argmin_eq_none, a return of none would require . Here is nonempty, so the return is some m. This is a positive passing exponent, which gives by the order property. Meanwhile, itself is a passing entry in the list, so minimality gives . The two inequalities force . They connect two minima: is the least positive exponent giving residue one, while is the least such exponent present in the menu. Membership of makes them coincide.

The failure return has a complete equivalence as well:

Indeed, argmin returns none exactly when is empty, and the filter is empty exactly when the original list has no positive passing entry. Thus none reports failure of this menu; the actual parameter record still has a true order. An empty list returns none, zero exponents fail the positivity condition, and repeated passing entries remain repeated entries. On ties, argmin retains the first occurrence. Its score here is id on natural numbers, so tied scores are the same exponent and do not affect the contract. The case is included.

Rewrite membership probability as exact-output probability, one summand at a time. Return to the same actual and counting width as in the preceding application, retaining and . Both runs still use the same , the same , and the same full work carrier, including padded coordinates. To make the selector’s input explicit, recall the list definitions:

The latter is (D y).flatMap (fun d => (D z).map (Nat.lcm d)), retaining all pairs and duplicates. Define the exact-output event by

The generic list contract gives pointwise, where still means . Selection builds the menu from observed integers and runs the tests; the unknown appears only in the mathematical success predicate.

Write . Continue to assume explicitly that the two complete preparations and measurements have independent resets, with joint mass . This product is nonnegative and sums to . For any event , define its probability by

The indicators of and agree at every observed pair, so every summand remains unchanged. Consequently,

The bound still comes from the actual phase mixture, the mass of the whole event within each jointly primitive component, and . No additional experiment independently sampling latent phases is assumed, and no injective choice of nearest-label witnesses is needed. An observed pair has a single exact-output indicator, however many occurrences of or successful denominator pairs its menu contains. Resolution, target padding, and actual input are the same, and is still unnecessary. One or two zero observed labels are included.

Native positive Fourier circuit: reflect both observations before selection. Use the same

as above, together with and . Reflection remains the negation involution transported through , including and . The full work-vector identity on this same controlled state gives

The appropriate event is therefore

Reflect both labels first; a zero label still maps to zero. The two positive-Fourier experiments explicitly use the independent-reset law . Reindexing the finite sum by the involution gives

For every OracleModel and its Interpretation, Theorem 15.3 identifies the action of the native positive circuit’s onBinaryLabels matrix with on the same column . Thus, coordinate by coordinate,

Summing squared moduli over the full carrier gives the same , so the reflected selection event applies to this same native circuit. The probability equality relies on involutive reindexing of both coordinates. It supplies no such bound for the unreflected positive-label menu . An unreset target, dependent repetitions, or an unspecified correlated state also cannot use this product law.

Minimization cannot supply an order missing from the menu. Consider a finite deterministic calculation with

Here . The Euclidean expansion of successively uses

ending with . Its full list is . Filtering for denominators strictly below gives

The last line concatenates the rows , , and , with no deduplication. The first six positive powers of modulo have residues

so the true order is . For the distinct menu values , the modular-power residues are respectively . The least positive passing value is , hence

The true order is absent from this menu, and the return is twice that order. This example establishes candidate computation and selection for the given integers. No positive probability for the observed pair in the actual quantum experiment is asserted here.

Using the returned as though it were the true order would give the half exponent , whereas the actual half order is . Their residues differ:

The former yields gcds and ; the latter yields and . Passing the modular-power test cannot replace the true-order premise in the classical factor extraction below. Nor does the all-pairs construction guarantee that a missing order appears. List-relative minimization is exact when the true order is present; it does not make every menu complete.

Probability guarantee and certificates for individual returns. Under the stated actual input, resolution, and independent-reset law, the probability that the returned value equals the true order is at least . This is a bounded-error guarantee for exact output. A return some m carries no flag identifying whether this attempt was exact: it may be a larger positive multiple. A return none means only that no positive menu entry passed. This is not a Las Vegas procedure that certifies every returned order and recognizes every unsuccessful attempt. Repeating these returns alone supplies no exactness certificate; this application makes no probability-amplification claim.

Exactness can be tested with additional resources. The existing orderOf_eq_of_pow_and_pow_div_prime says that a positive passing exponent is the order if every prime divisor satisfies

The mechanism is direct. Since , write . If , choose a prime divisor . Then , so this prime-division test must give residue , a contradiction. Thus . To use these tests as a finite certificate, a complete verified prime factorization of is needed to cover all its distinct prime divisors; testing a few primes is insufficient. For , the prime tests are empty, and positive passing already forces order . Obtaining a complete factorization and verifying supplied factors are separate tasks. The selector does not supply the factors, and no efficient method for obtaining them is asserted here.

The minimum-of-order-multiples idea appears explicitly in Ekerå, On the success probability of quantum order finding, arXiv:2201.07791v2, §4.1.7: when processed values are all positive multiples of the order and at least one is the order, their minimum is the order. The citation concerns this minimum argument. The paper’s offset search and smoothness-based processing differ from the all-pairs menu here; their algorithms and performance estimates do not transfer with that argument.

Finite lists and executable modular exponentiation specify a computation. The logarithmic length bound above counts convergents or Euclidean stages; it does not automatically cover every recursive list operation or the bit cost of rational arithmetic. This application supplies no end-to-end bit cost, quantum gate bound, efficient acquisition of complete factors, recursive factoring algorithm, or hardware-performance conclusion. Its exact-output event concerns counting observations for a fixed actual base, whereas the classical Good event below uses a separate unit-group sampling law. Combining their probabilities still requires an explicit common joint sampling construction.