Suppose first that a simple continued fraction is eventually periodic. Its periodic tail is fixed by the Möbius transformation represented by the continued-fraction matrix of one full period:
Thus
The infinite tail is not rational, since a rational simple continued fraction terminates. Hence is a quadratic irrational, and the finite initial block expresses the original number as another rational Möbius transform of . Therefore every eventually periodic simple continued fraction represents a quadratic irrational.
For the purely periodic fraction ,
so . Positivity selects
Apply the continued-fraction algorithm to :
The complete quotient then repeats, giving
The convergents through one term before the final are
The last of these satisfies the Pell equation
so a positive solution is
Choose a power of two with
Since the multiplicative order is less than , this guarantees . Prepare two quantum registers in the state
and use quantum modular exponentiation to obtain
Measure the second register. The order as the exact period of modular exponentiation implies that, conditional on the measured value, the first register is a normalized truncated periodic coset
where is the largest integer for which .
Apply the quantum Fourier transform to the first register and measure it, obtaining . The supplied Fourier-transform theorem states that, with probability of order , is an integer nearest to for some coprime to . On that event,
The supplied continued-fraction theorem, applied through continued-fraction recovery in quantum order finding, therefore recovers the reduced fraction from . Because and are coprime, its denominator is the exact order . The candidate is checked classically by verifying .
The quantum Fourier transform, quantum modular exponentiation, continued-fraction algorithm, and final modular check all take polynomial time in . Since , the successful event has probability of order , as required.
Write the continued fraction as and define its convergents by
Induction using these recurrences gives
In particular, consecutive convergents have coprime numerator and denominator. The standard best-approximation consequence of the same determinant identity is that, for and ,
Dividing by gives
The contrapositive proves that any strictly better approximation has .
For , the continued-fraction algorithm gives
and the remainder then repeats. Hence
The convergent supplies a solution of the Pell equation:
The two registers start in . A quantum Fourier transform on the first and evaluation of give
The first measurement, on the function register, returns . The compatible inputs are , so the normalized state becomes
Apply to the first register and put . Its state is
The geometric sum vanishes unless . Thus this is
up to the unchanged second register. The outcomes each have probability , in accordance with the quantum Fourier transform of a periodic coset state.
For the stated second outcome,
The continued-fraction algorithm therefore returns denominator . Since the numerator is coprime to the true period, exact period recovery from a Fourier sample succeeds, and direct evaluation confirms that the least period is
All steps through the transformed state are the same as in part (c), but the second measurement now gives . The classical fraction is
so reduction or the continued-fraction algorithm proposes denominator . This is not a period, since for example
Equivalently, the sample has and true period , with , so it reveals only . The algorithm does not succeed from this sample and must be repeated.
Apply the continued-fraction algorithm. Since ,
The successive complete quotients are
and
Taking one more reciprocal returns to , so the continued fraction of the square root of eleven is
Write
The first convergents are and , whence
The continued fraction convergent recurrence is
where for even and for odd .
Set
If is even and , then
because . If is odd and , then
because . The base case and induction prove the alternating multiplier recurrence for convergents of the square root of eleven:
Starting with , the continued-fraction algorithm sets
unless is already an integer. This gives
Every finite continued fraction is rational, since it is built from integers by finitely many additions and reciprocals. Conversely, if is rational in lowest terms, then
When , the next complete quotient is . Thus each step is an application of the Euclidean algorithm and replaces the denominator by a smaller nonnegative remainder. The process must terminate. This proves the termination criterion for a simple continued fraction.
For ,
and
Finally,
so the complete quotients repeat. Hence the continued fraction of the square root of three is