# Outputting numbers symbolically

Suppose I want Mathematica to output

Table[2^n, {n, 1, 5}]


Mathematica gives

{2, 4, 8, 16, 32}


but how can I get Mathematica to output

{2, 2^2, 2^3, 2^4, 2^5}


?

EDIT

What about more complicated expressions like:

Table[n^2, {n, 1, 5}]


Mathematica gives

{1, 4, 9, 16, 25}.


If I try

Table[HoldForm@n^2, {n, 1, 5}]


I get the unexpected (to me)

{n^2, n^2, n^2, n^2, n^2}

• Table[HoldForm@2^n, {n, 1, 5}] !Mathematica graphics – Nasser Oct 1 '14 at 20:44
• Inactivate[Table[2^n, {n, 1, 5}], Power] (I am not obsessed with Inactive I promise) – chuy Oct 1 '14 at 20:53
• @chuy That's an elegant answer - much more than a comment. – eldo Oct 1 '14 at 21:00
• To output Table[2^n, {n, 1, 5}] simply type "Table[2^n, {n, 1, 5}]" and hit <shift>+<return> – DavidC Oct 2 '14 at 0:04
• Thank you @ Nasser, @ chuy, @ David Carraher, @kguler. Your comments and answers have helped me a lot, and I was not able to find the answer contrary to the "closers". Looking through the Help files did not help me in the slightest. – Pixel Oct 2 '14 at 6:00

Try this:

 Table[x^n, {n, 1, 5}] /. x -> "2"

• I like this way indeed - much simpler for me than HoldForm, and I can do things like: Table[x^n*n^y, {n, 1, 5}] /. {x -> "2", y -> "3"} Thanks. – Pixel Oct 8 '14 at 15:56
Table[With[{n = n}, HoldForm[2^n]], {n, 1, 5}]
(* or Table[With[{n = n}, Defer[2^n]], {n, 1, 5}] *)


Table[With[{n = n}, HoldForm@n^2], {n, 1, 5}]
(* or Table[With[{n = n}, Defer@n^2], {n, 1, 5}] *)


Update: If 1 and 1^2 (similarly, 2 and 2^1) are both acceptable, then you can use a simpler variant of Alexey's answer without the need for ReplaceAll:

{Array["2"^# &, {5}], Array[#^"2" &, {5}]}


or

{Table["2"^n, {n, 1, 5}], Table[n^"2", {n, 1, 5}]}


As Nasser suggested, the following works for the first part of the post:

Table[HoldForm@2^n, {n, 1, 5}]


I found the answer for EDIT1: to be:

Table[(HoldForm[2^#1] &)[i], {i, 1, 5}]

• You might find Table[(Defer[2^#1] &)[i], {i, 1, 5}] sometimes more suitable. If you copy and paste it, it can be evaluated without using ReleaseHold. – Michael E2 Oct 1 '14 at 21:14