Homepage Solution manuals Ivan Niven An Introduction to the Theory of Numbers Exercise 7.7.3 (Expansion of $\sqrt{15}$ into continued fraction)

Exercise 7.7.3 (Expansion of $\sqrt{15}$ into continued fraction)

Expand 15 into an infinite simple continued fraction.

Answers

Note: By using (7.16) and the formula from Theorem 4.1.6:

a n = a n ( n , a )

we obtain

a i = ξ i = m i + d q i = m i + d q i .

So we can use only arithmetical operations to compute a i .

Proof. Starting from ξ 0 = 15 + 15 = 3 + 15 = m 0 + d q 0 , we repeat (7.13), using the preceding note, until q i = 1 (by Theorem 7.21). We obtain

m 0 = 3 , q 0 = 1 , a 0 = ξ = 6 , m 1 = a 0 q 0 m 0 = 3 , q 1 = d m 1 2 q 0 = 6 , a 1 = m 1 + d q 1 = 1 , m 2 = a 1 q 1 m 1 = 3 , q 2 = d m 2 2 q 1 = 1 .

Since q 2 = 1 , there is no other computing, and 3 + 15 = 6 , 1 ¯ = 6 , 1 , 6 ¯ , so

15 = 3 , 1 , 6 ¯ = 3 , 1 , 6 , 1 , 6 , 1 , 6 , 1 , 6 , .

The following program in pure Python computes the continued fraction expansion of n :

from math import sqrt

def continued_fraction(d):
    """ input : d > 1 , not a perfect square
        output: continued fraction expansion of sqrt(d),
          (up to the end of the period)
    """
    Vd = int(sqrt(d))
    expansion = [Vd]
    m = Vd
    q = d - m * m
    while q != 1:
        a = (m + Vd) // q
        expansion.append(a)
        m = a * q - m; q = (d - m * m) // q
    expansion.append(m + Vd)
    return expansion

if __name__ == ’__main__’:
    for i in range(100):
        if int(round(sqrt(i))) ** 2 != i:
         print(i, ’=>’, continued_fraction(i))

2 => [1, 2]
3 => [1, 1, 2]
5 => [2, 4]
6 => [2, 2, 4]
7 => [2, 1, 1, 1, 4]
...
15 => [3, 1, 6]
...
98 => [9, 1, 8, 1, 18]
99 => [9, 1, 18]

This confirms

15 = 3 , 1 , 6 ¯ .

User profile picture
2025-08-13 08:45
Comments