Convergents of $e$¶
Easy one-liner in SageMath.
In [1]:
sum(continued_fraction(e).convergent(99).numerator().digits())
Out[1]:
272
To compute the convergents ourselves, we'll first make a generator for the partial denominators of the continued fraction of $e$.
In [2]:
from itertools import count, chain
def partial_denominators_e():
yield 2
yield from chain.from_iterable((1, 2 * k, 1) for k in count(1))
Then we'll apply a simple algorithm for computing convergents using the partial denominators (outside of SageMath, you might want to use a fraction type).
In [3]:
def convergents(partial_denoms):
h, hprev = 1, 0
k, kprev = 0, 1
for b in partial_denoms:
h, hprev = b * h + hprev, h
k, kprev = b * k + kprev, k
yield h/k
Now just iterate until we reach the 100th convergent.
In [4]:
for (i, c) in enumerate(convergents(partial_denominators_e())):
if i == 99:
break
sum(c.numerator().digits())
Out[4]:
272
Relevant sequences¶
- Numerators of convergents of $e$: A007676
Copyright (C) 2025 filifa¶
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license and the BSD Zero Clause license.