TITLE: Evaluating a binary quadratic form at convergents
QUESTION [5 upvotes]: We use the notation
$$\displaystyle [a_0; a_1, \cdots, a_n] = a_0 + \cfrac{1}{a_1 + \cfrac{1}{\ddots + \cfrac{1}{a_n}}}$$
to denote a finite continued fraction, and for a given real number $\alpha$, we attach the (possibly infinite) sequence of partial quotients $[a_0; a_1, a_2, \cdots] = \alpha$. 
It is well-known by classic theorems of Euler and Lagrange that a real number has eventually periodic continued fraction expansion if and only if $\alpha$ is a quadratic irrational. Moreover, it is known that if $\alpha$ is an irrational number and $p/q$ is a reduced fraction with $q > 0$ such that $|\alpha - p/q| < 1/(2q^2)$, then $p/q$ is in fact a convergent of $\alpha$; i.e., there is a positive integer $k$ such that $p/q = [a_0; a_1, \cdots, a_k]$. 
Suppose that $\theta$ is a purely periodic quadratic irrational, so that its continued fraction is of the form $[\overline{a_0; a_1, \cdots, a_n}]$. Let $f(x) = ax^2 + bx + c$ be the minimal polynomial of $\theta$. What do we know about the evaluation of the quadratic form $F(x,y) = y^2 f(x/y)$ at the pairs $(p_0, q_0), \cdots, (p_n, q_n)$ corresponding to the convergents? In particular, what are the sizes of these values compared to the discriminant $\Delta(F)$ of $F$?

REPLY [4 votes]: The item you want is the neighbor method, a version of continued fractions. I learned this from Buell, Binary Quadratic Forms. It is also in a 1929 Introduction by Dickson, and a book by Matthews I've never seen. For a positive but not square discriminant, all primitively represented numbers with absolute value below $\frac{1}{2} \sqrt \Delta$ appear as coefficients (first or third) in the chain. There are usually a few more coefficients with slightly larger absolute values. Each triple in a cycle is a "reduced" indefinite form.  A form $ax^2 + b xy + c y^2$ is reduced if and only if $ac<0$ and $b > |a+c| \; .$

jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$ ./indefCycle 1 3 -2

  0  form              1           3          -2


           1           0
           0           1

To Return  
           1           0
           0           1

0  form   1 3 -2   delta  -1     ambiguous  
1  form   -2 1 2   delta  1
2  form   2 3 -1   delta  -3
3  form   -1 3 2   delta  1     ambiguous            -1 composed with form zero  
4  form   2 1 -2   delta  -1
5  form   -2 3 1   delta  3
6  form   1 3 -2


  form   1 x^2  + 3 x y  -2 y^2 

minimum was   1rep   x = 1   y = 0 disc 17 dSqrt 4  M_Ratio  16
Automorph, written on right of Gram matrix:  
-9  -32
-16  -57
=========================================
jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$ 



jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$ ./indefCycle 1 13 -13

  0  form              1          13         -13


           1           0
           0           1

To Return  
           1           0
           0           1

0  form   1 13 -13   delta  -1     ambiguous  
1  form   -13 13 1   delta  13     ambiguous  
2  form   1 13 -13


  form   1 x^2  + 13 x y  -13 y^2 

minimum was   1rep   x = 1   y = 0 disc 221 dSqrt 14  M_Ratio  196
Automorph, written on right of Gram matrix:  
-1  -13
-1  -14
=========================================


jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$ ./indefCycle 1 7 -3

  0  form              1           7          -3


           1           0
           0           1

To Return  
           1           0
           0           1

0  form   1 7 -3   delta  -2     ambiguous  
1  form   -3 5 3   delta  2
2  form   3 7 -1   delta  -7
3  form   -1 7 3   delta  2     ambiguous            -1 composed with form zero  
4  form   3 5 -3   delta  -2
5  form   -3 7 1   delta  7
6  form   1 7 -3


  form   1 x^2  + 7 x y  -3 y^2 

minimum was   1rep   x = 1   y = 0 disc 61 dSqrt 7  M_Ratio  49
Automorph, written on right of Gram matrix:  
-79  -585
-195  -1444
=========================================
jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$