Continued fractions and quadratic surds

I became interested in the nearest square (NSCF), nearest integer (NICF) and optimal continued fraction (OCF) through Jim White of the ANU, around October 2007. Coincidentally John Robertson had also been studying the NSCF and NICF and joined the discussion. NICF refers here to a half-regular continued fraction where the partial numerators are allowed to be ±1, in contrast to the nearest integer continued fraction of Adolf Hurwitz and B. Minnegerode, where the partial numerators are all -1. I should also mention Selenius' ideal relative approximation continued fraction (IACF or SK) which is the same as the OCF, but somewhat harder to describe. Selenius first obtains the regular continued fraction (RCF) and replaces all 1's by a process of singularisation. For quadratic surds, the period-lengths of OCF and SK are sometimes double that of the period-length of the corresponding NSCF. Contrary to a disparaging review by D.H. Lehmer of A.A.K. Ayyangar's paper below, NSCF has some nice properties. For example, the period-length of the NSCF expansion for √D is no greater than and can be much shorter than the RCF period-length. Also there are three mid-point criteria for solving Pell's equation - see paper 12 below.


  1. BCMATH continued fraction programs
  2. On the regular continued fraction (RCF) expansion of √22n+1 (pdf)
  3. T.H. Jackson and K.R. Matthews, On Shanks' algorithm for computing the continued fraction of logba, Journal of Integer Sequences 5 (2002) article 02.2.7. We give a more practical variant of Shanks' 1954 algorithm for computing the continued fraction of logba for integers a > b > 1, using the floor and ceiling functions and an integer parameter c > 1. The variant, when repeated for a few values of c = 10r, enables one to guess if logba is rational and otherwise find approximately r partial quotients. Also see the online BCMath program.
    Here are the first 1000 partial quotients of the continued fraction expansion of log23.
  4. Some continued fraction identities (pdf)
  5. Primitive Pythagorean triples and the negative Pell equation (pdf) - see BCMATH program
  6. A unimodular matrix and Pell's equation (pdf)
  7. Reduced quadratic irrationals and Pell's equation (pdf)
  8. Solving Ax2 - By2 = N in integers, where A > 0, B > 0 and D = AB is not a perfect square and gcd(A,B) = gcd(A,N) = 1 (pdf)
  9. Latexed version of Theory of the nearest square continued fraction, A.A. Krishnaswami Ayyangar, J. Mysore Univ. Sect. A. 1, (1941) 97-117, which was indistinct in many places. Also I have expanded and changed the author's proofs in some places when they were hard to follow.
  10. The nearest square continued fraction expansion of (p+q+√{p2+q2})/p, where p > 2q > 0, gcd(p,q)=1
  11. On the definition of nearest integer reduced quadratic surd (with John Robertson)
  12. Keith R. Matthews, John P. Robertson and Jim White, Midpoint criteria for solving Pell's equation using the nearest square continued fraction, Math. Comp. 79 January (2010), 485-499
  13. John P. Robertson and Keith R. Matthews, A continued fractions approach to a result of Feit, The American Mathematical Monthly 115 April (2008), 346-349
  14. Keith R. Matthews, John P. Robertson, Jim White, Corrigenda to `Calculation of the regulator of Q(√D) by use of the nearest integer continued fraction algorithm', Mathematics of Computation 78, Number 265, January (2009), 615-616
  15. Keith R. Matthews, Unisequences and nearest integer continued fraction midpoint criteria for Pell's equation, Journal of Integer Sequences, 12 (2009), Article 09.6.7
  16. Period 2 NSCF and NICF expansions of √D (23rd April 2009)
  17. Continuants and half-regular continued fractions (updated 2nd August 2010)
  18. Testing a quadratic surd for being NSCF reduced
  19. Period length equality for the nearest integer and nearest square continued fraction expansions of a quadratic surd (submitted)
  20. On Purely Periodic Nearest Square Continued Fractions (draft manuscript)
  21. On the optimal continued fraction expansion of a quadratic surd (draft manuscript)
  22. On the convergents of semi--regular continued fractions (2nd August 2010)
Page layout: Alan Offer
Keith Matthews Last modified 2nd August 2010