How to Calculate Continued Fraction of Radical 7
Generate continued fraction terms of √7, inspect convergents, and visualize approximation error with Chart.js.
Expert Guide: How to Calculate Continued Fraction of Radical 7
Calculating the continued fraction of radical 7 means finding the simple continued fraction representation of √7. This is one of the most useful examples in number theory because it shows every core idea at once: irrationality, periodic structure, convergents, and fast approximation quality. The short answer is that √7 has continued fraction form [2; 1, 1, 1, 4, 1, 1, 1, 4, …]. The repeating block is (1, 1, 1, 4). If you are learning the method for exams, coding, or deeper research in Diophantine approximation, this walkthrough will help you compute it by hand and verify it computationally.
Why continued fractions matter for √7
Decimals are familiar, but they do not expose hidden structure. Continued fractions do. For irrational numbers like √7, convergents from continued fractions are the best possible rational approximations for a given denominator size. This is not just a computational curiosity. It appears in algorithm design, Pell-type equations, cryptography, and approximation theory. In practical terms, if you need a fraction close to √7 and you want very high accuracy with small numerator and denominator, convergents are usually the smartest choice.
A second reason is theoretical: Lagrange proved that the continued fraction expansion of every quadratic irrational is eventually periodic, and for square roots of non-square integers, it is purely periodic after the initial integer part. So when you compute √7, you are seeing a classic theorem in action, not just a numeric trick.
Core definitions you need before calculation
- Simple continued fraction: an expression of the form a0 + 1/(a1 + 1/(a2 + …)) where each ai for i ≥ 1 is a positive integer.
- Partial quotient: each integer ai in the expansion.
- Convergent: the rational fraction you get by truncating after a finite number of terms.
- Period: repeating block of partial quotients for periodic expansions.
For √7, the integer part is 2, so a0 = 2. Everything that follows comes from a recurrence based on integer arithmetic.
Step by step algorithm for the continued fraction of √7
The most reliable manual algorithm for √N uses three sequences: m, d, and a. For N = 7, initialize:
- a0 = floor(√7) = 2
- m0 = 0
- d0 = 1
- a0 = 2 is already the first term
Then iterate for n = 0, 1, 2, … using:
- m(n+1) = d(n)·a(n) – m(n)
- d(n+1) = (N – m(n+1)^2) / d(n)
- a(n+1) = floor((a0 + m(n+1)) / d(n+1))
Now compute:
- Start: m0 = 0, d0 = 1, a0 = 2
- n=0: m1 = 1·2 – 0 = 2; d1 = (7 – 4)/1 = 3; a1 = floor((2+2)/3) = 1
- n=1: m2 = 3·1 – 2 = 1; d2 = (7 – 1)/3 = 2; a2 = floor((2+1)/2) = 1
- n=2: m3 = 2·1 – 1 = 1; d3 = (7 – 1)/2 = 3; a3 = floor((2+1)/3) = 1
- n=3: m4 = 3·1 – 1 = 2; d4 = (7 – 4)/3 = 1; a4 = floor((2+2)/1) = 4
At this point the state loops, giving repeating terms 1, 1, 1, 4. Therefore:
√7 = [2; (1,1,1,4)].
How to build convergents from the terms
Once you have partial quotients, compute convergents using recurrences:
- p(-2)=0, p(-1)=1, p(n)=a(n)·p(n-1)+p(n-2)
- q(-2)=1, q(-1)=0, q(n)=a(n)·q(n-1)+q(n-2)
- Convergent Cn = p(n)/q(n)
For √7 with terms [2;1,1,1,4,…], first convergents are 2/1, 3/1, 5/2, 8/3, 37/14, 45/17, and so on. Each convergent jumps close to √7 quickly.
Comparison table: first convergents and real error
The table below uses √7 ≈ 2.6457513110645907 and lists absolute error values. These are standard numeric values and are useful for understanding how rapidly continued fractions improve approximation quality.
| n | Convergent p/q | Decimal value | Absolute error |p/q – √7| |
|---|---|---|---|
| 0 | 2/1 | 2.0000000000 | 0.6457513111 |
| 1 | 3/1 | 3.0000000000 | 0.3542486889 |
| 2 | 5/2 | 2.5000000000 | 0.1457513111 |
| 3 | 8/3 | 2.6666666667 | 0.0209153556 |
| 4 | 37/14 | 2.6428571429 | 0.0028941682 |
| 5 | 45/17 | 2.6470588235 | 0.0013075125 |
| 6 | 82/31 | 2.6451612903 | 0.0005900207 |
| 7 | 127/48 | 2.6458333333 | 0.0000820223 |
| 8 | 590/223 | 2.6457399103 | 0.0000114008 |
| 9 | 717/271 | 2.6457564576 | 0.0000051465 |
What this error trend tells you
The improvement is not perfectly monotonic at every index, but overall it drops dramatically. You move from tenths-level error to millionths-level error with relatively small denominators. This is exactly why convergents are prized in practical approximation tasks. For fixed denominator limits, random fractions rarely compete with convergents from the continued fraction expansion.
Comparison table: periodic structure of square root continued fractions
It is useful to compare √7 with nearby radicals. The period length can vary a lot even for small integers.
| Radical | Continued fraction form | Period block | Period length |
|---|---|---|---|
| √2 | [1; (2)] | (2) | 1 |
| √3 | [1; (1,2)] | (1,2) | 2 |
| √5 | [2; (4)] | (4) | 1 |
| √6 | [2; (2,4)] | (2,4) | 2 |
| √7 | [2; (1,1,1,4)] | (1,1,1,4) | 4 |
Common mistakes when calculating √7 continued fraction
- Using rounded decimals too early: always use exact integer recurrence for m, d, and a.
- Forgetting floor operation: a(n+1) is floor((a0+m(n+1))/d(n+1)), not a rounded value.
- Mixing index shifts: keep a clear notation for n, n+1 at each update.
- Incorrect stopping rule: for square root expansions, period often recognized when d returns to 1 and next a is 2a0.
Exam ready workflow
- Write a0 = floor(√7) = 2.
- Set m0 = 0, d0 = 1.
- Iterate recurrence carefully in a small table with columns n, m, d, a.
- Extract repeating block once state cycles.
- Compute at least three convergents to verify plausibility.
- Cross check against decimal √7 for sanity.
Why this links to Pell equations
Periodic continued fractions of square roots are tightly connected to Pell equations x² – Ny² = 1. For N = 7, convergents generated from [2; (1,1,1,4)] produce excellent candidates for integer solutions. In fact, the fundamental solution of x² – 7y² = 1 is x = 8, y = 3, and you can see 8/3 as one of the early convergents. This is a classic bridge between approximation and algebraic number theory. If you continue terms, larger convergents give larger Pell solutions through recurrence behavior.
Practical coding tips for robust implementations
If you are implementing this in JavaScript, Python, or C++, keep arithmetic integer as long as possible. You only need floating point for final error evaluation against Math.sqrt(7). For high term counts, numerator and denominator can grow large quickly. In JavaScript, Number works for moderate length, but if you push terms high, BigInt is safer for exact rational values. For educational calculators like the one above, 30 to 60 terms is more than enough to show pattern and error decay.
A good UI pattern is to let users choose term count, decimal formatting, and error metric. Absolute error is intuitive, while relative error (as percent) is useful for comparing approximation quality across different scales. A chart that plots error versus convergent index gives immediate visual feedback of convergence behavior.
Authoritative references for deeper study
If you want rigorous definitions and reference formulas, review these high quality sources:
- NIST Digital Library of Mathematical Functions (Continued Fractions)
- Stanford University notes on continued fractions
- Cornell mathematics lecture notes on continued fractions
Final takeaway
To calculate the continued fraction of radical 7, use integer recurrences for m, d, and a starting from a0 = 2. The expansion is periodic with repeating block (1,1,1,4), so √7 = [2; (1,1,1,4)]. From these terms, build convergents using p and q recurrences, then evaluate error if needed. This method is mathematically rigorous, computationally efficient, and foundational for advanced topics in number theory. Once you understand √7, you can generalize the exact same workflow to any √N where N is not a perfect square.