Skip to main content
4 of 5
added 290 characters in body
garej
  • 5k
  • 2
  • 20
  • 44

Two approaches with Replacement.


z = Nest[1 + x^n (#) &, 1, 3] ReplacePart[z, Position[z, n][[#]] -> Defer@# & /@ Range[3]] 

enter image description here


Also inspired by the @Karsten7's answer and @Eldo's Module version:

Module[{r = 3, i = 1}, Quiet@ReplaceRepeated[(1 + x^n), (1 + x^n) -> 1 + x^n (1 + x^n), MaxIterations -> r - 1] /. n :> i++] 

1 + x (1 + x^2 (1 + x^3))

garej
  • 5k
  • 2
  • 20
  • 44