# How to define amazing Goodstein's sequence?

There is an amazing and counterintuitive theorem:

For all $n$, there exists a $k$ such that the $k$-th term of the Goodstein sequence $G_k(n)=0$. In other words, every Goodstein sequence converges to $0$.

I want to do something like this :

define Goodstein sequence G[k,n] then

DiscretePlot[G[k, n], {k, 1, N}]


and

How can I find $N$ such $G_{N}(n)=0$?

I tried first few steps:

following code is from wolfram demonstrations project.

h[list_] := Select[MapIndexed[{#1, Length[list] - First[#2]} &,list], #[[1]] > 0 &]

patrList[n_, b_] := Map[f[#, b] &, h[IntegerDigits[n, b]]]

rule[b_] := {a_Integer, c_} -> t[a, p[b, c]]

f[{a_, c_}, b_] := If[c > b, {a, patrList[c, b]}, {a, c}]

ruleHold = n_Integer -> HoldForm[n];

rules = {t[1, c_] -> c, p[n_, 0] -> 1, p[n_, 1] -> n, t[a_, 1] -> a};

patrForm[n_, b_] :=patrList[n, b] //. rule[b] //. rules /. ruleHold //.
t[x_, y_] -> Times[x, y] //. List -> Plus //.  p[x_, y_] -> Power[x, y] // TraditionalForm


then

$G_1(10)=$ patrForm[10, 2]

$G_2(10)=$ (patrForm[10, 2] /. {2 -> 3}) - 1

$\textbf{Definition}$ The Goodstein Function $g(n)$ is deﬁned to be the smallest number $k$ for which $G_{k}(n)=0$.

Here are the ﬁrst few values of the function $g(n)$.see here

$$g(0)=1$$ $$g(1)=2$$ $$g(2)=4$$ $$g(3)=6$$ $$g(4)=6.895\times10^{121210694}$$

• Your pressing problem is how to compute a "hereditary representation"; after that, getting a Goodstein sequence is not too hard. – J. M.'s ennui Jul 1 '16 at 10:09
• @J.M. see here – vito Jul 1 '16 at 10:22
• I already looked at that; my point was that you need to compute such a representation first, probably starting with the output of IntegerDigits[]. – J. M.'s ennui Jul 1 '16 at 10:26

The patrForm function from the Wolfram demonstrations example really produces the hereditary representation of a number, so now all we have to do is to apply it a given number of times, subtracting 1 in between:

nextGoodstein[{h_, nb_}] := {patrForm[ReleaseHold[h /. {nb - 1 -> nb}] - 1, nb], nb + 1};
goodsteinHeld[k_, n_] := First@Nest[nextGoodstein, {patrForm[n, 2], 3}, k];
goodstein[k_, n_] := ReleaseHold[goodsteinHeld[k, n]];
goodsteinListHeld[k_, n_] := First /@ NestList[nextGoodstein, {patrForm[n, 2], 3}, k];
goodsteinList[k_, n_] := ReleaseHold[goodsteinListHeld[k, n]];
goodsteinFunction[num_] := Last@NestWhile[nextGoodstein, {patrForm[num, 2], 3}, Positive[ReleaseHold[First[#]]] &] - 2;

Table[goodsteinFunction[num], {num, 0, 3}]
goodsteinListHeld[50, 4]
goodsteinList[50, 4]


However, this won't allow to compute goodsteinFunction[4], of course. Also, don't change num to n here: it can cause identifier conflict and wrong results.