Iterations with Table?

Is the following code efficient? Has it any advantages?

s = Sqrt;
Table[s[t + 1] = s[t]^2, {t, 0, 4}]

{2, 4, 16, 256, 65536}

Should be efficient in the following case?

s = Sqrt;
Table[s[t + 1] = (1 + t)*s[t]^2, {t, 0, 4}]

{2, 8, 192, 147456, 108716359680}

How could a "stopping rule" alla NestWhileList be implemented?

Thanks!

• Hi Dennis! The only accepted language here is English. If you need help translating your questions or answers, other users can help you. Just ask for help in chat!. Suerte, causa! Oct 24 '14 at 2:00
• This question appears to be off-topic because it is not formulated in English. Oct 24 '14 at 3:45
• @m_goldberg Voted to close too. Then I thought again :) Oct 24 '14 at 4:31

I don't think you need iterations to accomplish what you are looking for.

For example:

s=Sqrt;
s[t_] := s[t] = s[t - 1]^2  (* Use memoization *)
Map[s, Range[1,5] ]
(* {2, 4, 16, 256, 65536} *)

and in the second case:

ss = Sqrt;
ss[t_] := ss[t] = t ss[t - 1]^2
Map[ss, Range[1,5] ]
(* {2, 8, 192, 147456, 108716359680} *)

If efficiency is important and you are going to generate more and more elements of your series then you might consider using RSolve to find an expression for all terms.

RSolve[{s[t + 1] == s[t]^2, s == Sqrt}, s[t], t]

and

RSolve[{s[t + 1] == (1 + t)*s[t]^2, s == Sqrt}, s[t], t]

Just to illustrate some alternatives:

f[n_] := Nest[#^2 &, 2, n]
fl[n_] := NestList[#^2 &, 2, n]

Then

Table[f[j], {j, 0, 4}]
f /@ Range[0, 4]
fl

all yield: {2, 4, 16, 256, 65536}