Skip to content

Convergents ​

The successive convergents pk/qkp_k/q_k of a continued fraction, given as its list of terms or as the number itself.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageConvergents✓
Convergents(list)the convergents of a term list, such as one ContinuedFraction returns
Convergents(x)every convergent of a rational xx — the last one is xx itself
Convergents(x, n)the first nn convergents of xx, via ContinuedFraction(x, n)
Typed signatures
TypePackageApplies
(value, integer?) -> list<number>modularalways

Domain: The modular group

Details
  • The two-term recurrence pk=akpk−1+pk−2p_k = a_k p_{k-1} + p_{k-2}, qk=akqk−1+qk−2q_k = a_k q_{k-1} + q_{k-2}, seeded p−1=1,p−2=0,q−1=0,q−2=1p_{-1}=1, p_{-2}=0, q_{-1}=0, q_{-2}=1 — the same recurrence ModularMatrix multiplication runs, one TakST^{a_k}S at a time
  • Every convergent is in lowest terms, and each is a better rational approximation of xx than any fraction with a smaller denominator
  • Convergents(x) (no n) needs a RATIONAL xx, since ContinuedFraction(x) alone does; an irrational needs Convergents(x, n)

Examples

Basic #

from a list of terms

live ↗
InConvergents([3,7,15,1])\mathrm{Convergents}(\bigl\lbrack3, 7, 15, 1\bigr\rbrack)Out[3,227,333106,355113]\bigl\lbrack3, \frac{22}{7}, \frac{333}{106}, \frac{355}{113}\bigr\rbrack

the first five convergents of π\pi

live ↗
InConvergents(π,5)\mathrm{Convergents}(π, 5)Out[3,227,333106,355113,103 99333 102]\bigl\lbrack3, \frac{22}{7}, \frac{333}{106}, \frac{355}{113}, \frac{103\,993}{33\,102}\bigr\rbrack

Ratios of consecutive Fibonacci numbers, since every quotient is 11

live ↗
InConvergents(φ,10)\mathrm{Convergents}(\varphi, 10)Out[1,2,32,53,85,138,2113,3421,5534,8955]\bigl\lbrack1, 2, \frac{3}{2}, \frac{5}{3}, \frac{8}{5}, \frac{13}{8}, \frac{21}{13}, \frac{34}{21}, \frac{55}{34}, \frac{89}{55}\bigr\rbrack

Convergents from a list of quotients directly

live ↗
InConvergents([1,1,1,1,1])\mathrm{Convergents}(\bigl\lbrack1, 1, 1, 1, 1\bigr\rbrack)Out[1,2,32,53,85]\bigl\lbrack1, 2, \frac{3}{2}, \frac{5}{3}, \frac{8}{5}\bigr\rbrack
Scope #

a rational: the last convergent is the number itself

live ↗
InConvergents(4717)\mathrm{Convergents}(\frac{47}{17})Out[2,3,114,4717]\bigl\lbrack2, 3, \frac{11}{4}, \frac{47}{17}\bigr\rbrack

The classic approximations of π\pi: 22/722/7, 355/113355/113, 103993/33102103993/33102

live ↗
InConvergents(π,10)\mathrm{Convergents}(π, 10)Out[3,227,333106,355113,103 99333 102,104 34833 215,208 34166 317,312 68999 532,833 719265 381,1 146 408364 913]\bigl\lbrack3, \frac{22}{7}, \frac{333}{106}, \frac{355}{113}, \frac{103\,993}{33\,102}, \frac{104\,348}{33\,215}, \frac{208\,341}{66\,317}, \frac{312\,689}{99\,532}, \frac{833\,719}{265\,381}, \frac{1\,146\,408}{364\,913}\bigr\rbrack

Convergents to 7=[2;1,1,1,4,1,1,1,4,…]\sqrt7 = [2; 1,1,1,4,1,1,1,4,\ldots]

live ↗
InConvergents(7,10)\mathrm{Convergents}(\sqrt{7}, 10)Out[2,3,52,83,3714,4517,8231,12748,590223,717271]\bigl\lbrack2, 3, \frac{5}{2}, \frac{8}{3}, \frac{37}{14}, \frac{45}{17}, \frac{82}{31}, \frac{127}{48}, \frac{590}{223}, \frac{717}{271}\bigr\rbrack

A rational's convergents end exactly at the number itself

live ↗
InConvergents(717)\mathrm{Convergents}(\frac{7}{17})Out[0,12,25,717]\bigl\lbrack0, \frac{1}{2}, \frac{2}{5}, \frac{7}{17}\bigr\rbrack
Applications #

convergents of 2\sqrt2 solve Pell's equations p2−2q2=±1p^2 - 2q^2 = \pm1

live ↗
InConvergents(2,5)\mathrm{Convergents}(\sqrt{2}, 5)Out[1,32,75,1712,4129]\bigl\lbrack1, \frac{3}{2}, \frac{7}{5}, \frac{17}{12}, \frac{41}{29}\bigr\rbrack
Properties #

Errors against π\pi alternate in sign and shrink rapidly

live ↗
InConvergents(π,10)−N(π)\mathrm{Convergents}(π, 10)-N(π)Out[−0.141 592 653 589 793 238 462 643,0.001 264 489 267 349 618 677 357,−0.000 083 219 627 529 087 522 643,0.000 000 266 764 189 062 417 357,−5.778 906 343 926 43⋅10−10,3.316 278 062 473 57⋅10−10,−1.223 565 329 426 43⋅10−10,2.914 338 493 735 7⋅10−11,−8.715 467 262 643⋅10−12,1.610 740 017 357⋅10−12]\bigl\lbrack-0.141\,592\,653\,589\,793\,238\,462\,643, 0.001\,264\,489\,267\,349\,618\,677\,357, -0.000\,083\,219\,627\,529\,087\,522\,643, 0.000\,000\,266\,764\,189\,062\,417\,357, -5.778\,906\,343\,926\,43\cdot10^{-10}, 3.316\,278\,062\,473\,57\cdot10^{-10}, -1.223\,565\,329\,426\,43\cdot10^{-10}, 2.914\,338\,493\,735\,7\cdot10^{-11}, -8.715\,467\,262\,643\cdot10^{-12}, 1.610\,740\,017\,357\cdot10^{-12}\bigr\rbrack
About
Examples10
Checked againstWolfram Language 10 agree
CrosswalkWolfram Language

See also: ContinuedFraction, ContinuedFractionK