back to table · edit · history · where entries came from · files · download
605 bytes, as of the version from 2026-12-01 18:15 (current). Recorded here, not run.
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)