Let [θ] denote the nearest integer to θ. i.e. [θ] = ⌊θ + 1/2⌋.
Define a sequence of complete convergents by x0 = (u+√d) / v, xn = bn + an+1 / xn+1, where bn = [xn], n ≥ 0; also an = ±1, where sign(an+1) = sign(xn - bn).
This gives a continued fraction x0 = b0 + a1 / b1+ ···, where bi ≥ 2 for all i ≥ 1 and ai = ±1.
Write xk = (Pk + √d) / Qk, so that P0 = u and Q0 = v. Then
bk = [(Pk + √d) / Qk],
Pk+1 = bkQk - Pk,
Qk+1 = ak+1(d - P2k+1) / Qk > 0.
(We use a nearest-integer formula for [x/m], m a non-zero integer.)
We then find the least k ≥ 1 such that Pn+k = Pn and Qn+k = Qn and this leads to a period of length k.
The convergents An / Bn are defined by A-2 = 0, A-1 = 1, B-2 = 1, B-1 = 0 and for k ≥ -1,
Ak+1 = bk+1Ak + ak+1Ak-1
Bk+1 = bk+1Bk + ak+1Bk-1.
If xn = (Pn + √d)/Qn and yn = (Pn - √d)/Qn and r = (3 - √5)/2, then
xn > 2 and -1 + r < yn < r or
xn = 3 - r = (3 + √5)/2.
We then find the least k ≥ 1 such that Pn+k = Pn and Qn+k = Qn and this leads to a period of length k.
The period is printed in bold font.
(11th January 2008. It is not hard to prove that a reduced NICF complete quotient gives a purely periodic NICF and conversely.
Last modified 12th January 2008
Return to main page