import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
def paperfolding_number(b, digits=100):
b = ZZ(b)
if b < 2:
raise ValueError("b must be an integer >= 2")
s, m = QQ(0), ZZ(1)
goal = QQ(1)/(ZZ(10)**(digits+30)*b)
tail = QQ(1)/(b**m-1)
while tail > goal:
s += QQ(b**(3*m))/(b**(4*m)-1)
m *= 2
tail = QQ(1)/(b**m-1)
R = RealBallField(numberdb.bits(digits, losing=120))
return R(s+tail/2).add_error(R(tail/2))
paperfolding_number(2)The generator sums the grouped series with exact Sage rationals. After $J$ terms it bounds the omitted part by $1/(b^{2^J}-1)$, stopping when this is at most $10^{-130}/b$ for the default $100$ significant digits. Conversion of the rational midpoint and half-width to a $453$-bit Arb ball includes rounding and truncation error. Every returned ball is finite and has positive radius. The default range uses $7$ to $9$ grouped terms.
A separate checker constructs the digits by recursive folding, evaluates exact rational digit sums and bounds their tails by $b^{-N}/(b-1)$. For every stored base, this narrower interval is contained in the interval encoded by the recorded decimal. It also checks the functional equation at $b$ and $b^2$, verifies $1023$ digits against the odd-part rule, and uses a known digit prefix and deliberately incorrect shifts, omitted terms, altered last places, nonfinite inputs and excessively wide intervals as controls. The attached evidence records the exact tail widths, precision, code and software versions. These are computational checks of the stated enclosures, not a proof of further arithmetic properties.