As the CDF file from my video can't be viewed in current browsers anymore and the CDF Player doesn't seem to be used a lot anyway, I have programmed the generation of Goodstein sequences once again, this time in Python. The HTML was generated in Jupyter.
def normalForm (x, b):
if x < b:
return x
L = []
e = 0
while x > 0:
m = x % b
if m > 0:
L.append([normalForm(e, b), m])
x //= b
e += 1
return L
def fromNormalForm (L, b):
if type(L) is int:
return L
return sum(f * b**fromNormalForm(e, b) for e, f in L)
from re import match
def maybeAddParens (s):
return s if match(r"^[0-9]+$", s) else "(" + s +")"
def beautify (f, b, e):
if e == 0:
return str(f)
if e == 1:
if f == 1:
return str(b)
else:
return "{}*{}".format(f, b)
if f == 1:
return "{}^{}".format(b, maybeAddParens(normalFormToString(e, b)))
return "{}*{}^{}".format(f, b, maybeAddParens(normalFormToString(e, b)))
def normalFormToString (L, b):
if type(L) is int:
return str(L)
return "+".join(beautify(f, b, e) for e, f in L)
def goodstein (x, n):
b = 2
while b <= n + 1:
if x == 0:
break
N = normalForm(x, b)
print("{} = {}".format(x, normalFormToString(N, b)))
b += 1
x = fromNormalForm(N, b) - 1
goodstein(13, 7)
goodstein(7, 13)