Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

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 answeranswer 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))

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))

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))

added 290 characters in body
Source Link
garej
  • 5k
  • 2
  • 20
  • 44

Another approach is to replace n's with respective numbers from Range[3]Two approaches with Replacement.

 
z = Nest[1 + x^n (#) &, 1, 3] 

enter image description here

Use ReplacePart with Map(/@)

ReplacePart[z, Position[z, n][[#]] -> Defer@# & /@ Range[3]] 

enter image description here

 

If you do not want x^1 dropAlso inspired by the @Karsten7's Defer@.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))

Another approach is to replace n's with respective numbers from Range[3].

z = Nest[1 + x^n (#) &, 1, 3] 

enter image description here

Use ReplacePart with Map(/@)

ReplacePart[z, Position[z, n][[#]] -> Defer@# & /@ Range[3]] 

enter image description here

If you do not want x^1 drop Defer@.

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))

deleted 23 characters in body
Source Link
garej
  • 5k
  • 2
  • 20
  • 44

Another approach is to replace n's with respective indexnumbers from Range[3].

sz = Nest[1 + x^n (#) &, 1, 3] 

enter image description here

z = 1 + x^n (1 + x^n (1 + x^n)) 

Use ReplacePart with Map(/@)

ReplacePart[z, Position[z, n][[#]] -> Defer@# & /@ Range[3]] 

enter image description here

If you do not want x^1 drop DeferDefer@.

Another approach is to replace n's with respective index.

s = Nest[1 + x^n (#) &, 1, 3] 

enter image description here

z = 1 + x^n (1 + x^n (1 + x^n)) 

Use ReplacePart with Map(/@)

ReplacePart[z, Position[z, n][[#]] -> Defer@# & /@ Range[3]] 

enter image description here

If you do not want x^1 drop Defer.

Another approach is to replace n's with respective numbers from Range[3].

z = Nest[1 + x^n (#) &, 1, 3] 

enter image description here

Use ReplacePart with Map(/@)

ReplacePart[z, Position[z, n][[#]] -> Defer@# & /@ Range[3]] 

enter image description here

If you do not want x^1 drop Defer@.

deleted 61 characters in body
Source Link
garej
  • 5k
  • 2
  • 20
  • 44
Loading
Source Link
garej
  • 5k
  • 2
  • 20
  • 44
Loading