# Display 10^n as power

How can I tell MMA to display input of the form 10^n as $10^n$ and not e.g. as 1000 for $n = 3$ or the rational $\frac{1}{1000}$ for $n = -3$.

This would help to keep tables compact when some parameters sweep across a large range of magnitudes, e.g.

TableForm[Table[x y, {x, Table[10^n, {n, -3, 3}]}, {y, Table[10^n, {n, -3, 3}]}],
TableHeadings -> {Table[10^n, {n, -3, 3}], Table[10^n, {n, -3, 3}]}]


• A nice extension to this question would be to have a way to display exact integer (or rational) multiple of 10^n, such as 12000000, represented by 12 10^6 – andre314 Jun 21 '17 at 8:17
• @andre If you don't mind the trailing dot on the mantissa, you can do EngineeringForm@N[12000000] to get 12.*10^6 (or ScientificForm@N[12000000] for 1.2*10^7)... but I do mind. – Casimir Jun 21 '17 at 8:27
• I do mind too, because I want to recognise exact values from approximative values. – andre314 Jun 21 '17 at 11:36
• Another possibility for your table would be to use logarithms. – ivbc Jun 21 '17 at 13:51
• @ivbc You mean as in Alexei's answer? – Casimir Jun 21 '17 at 14:03

An alternative would be to define your own number form:

ClearAll[form]
SetAttributes[form, Listable]

form[x_] := ScientificForm[N@x, NumberFormat -> (Superscript[10, #3] &)]
form[1] := Superscript[10, 0]

10^Partition[Range[-6, 6], 7, 1] // form //
TableForm[#, TableHeadings -> {#[[4]], #[[4]]}] &


• Interesting solution. Unlike the other answers where the scope is obvious, however, defining a custom number format might lead someone who did not write the code himself to expect that form works with all numbers. Instead, it ignores the mantissa (including sign) and acts like a floor function to the exponent, e.g. form[999] = 10^2 or form[-3456] = 10^3. Also, form[10^-\[Infinity]] = 10 but that could be fixed by form[10^-\[Infinity]] := 0. Still, this could lead to trouble when used carelessly. – Casimir Jun 21 '17 at 14:33
• hey @eldo, I came up with a very similar answer before seeing yours. I am not sure if i should edit yours or post mine as a new one, or something else... I posted for now so that someone can tell me what to do. – ivbc Jun 21 '17 at 15:30

I hadnt seen Eldos answer before now, but I did copy the SetAttributes and ClearAll from him.

Define:

ClearAll[newForm]
SetAttributes[newForm, Listable]

newForm[x_] :=
If[IntegerQ@x == True && Divisible[x, 10],
ScientificForm[x // N,
NumberFormat -> (
If[Length@Characters@#3 != 0,
If[ToExpression@#1 == 1,
Row[{Superscript[10,
ToString[ToExpression@#3 - Length@Characters@#1 + 2]]}],
Row[{x/10^(ToExpression@#3 - Length@Characters@#1 + 2),
"\[Times]",
Superscript[10,
ToString[ToExpression@#3 - Length@Characters@#1 + 2]]}]],
#1] &)],
ScientificForm[x]];


So the following comand gives a nice result

v = {1, 8^5, 130, 130., 15400000, 11.^7, 10^3};
newForm[v]


• OP wanted 10^3 without an integer multiplying it. Your answer gives 1 x 10^3. – Jack LaVigne Jun 28 '17 at 0:04
• Does it? O hadn't tested for this case, thanks for letting me know. I will find a solution latter. – ivbc Jun 28 '17 at 0:12
• @JackLaVigne, error corrected! – ivbc Jun 30 '17 at 18:02
• You got my vote – Jack LaVigne Jun 30 '17 at 18:49
TableForm[
Table[
Superscript[10, x + y],
{x, -3, 3},
{y, -3, 3}
Table[Superscript[10, n], {n, -3, 3}],
Table[Superscript[10, n], {n, -3, 3}]}
]


Try this:

  TableForm[
Table[10^ToString[Log[10, x y]], {x, Table[10^n, {n, -3, 3}]}, {y,
Table[10^n, {n, -3, 3}]}],
TableHeadings -> {Table[10^ToString[n], {n, -3, 3}],
Table[10^ToString[n], {n, -3, 3}]}]


Have fun!

a = Range[-3, 3];


HoldForm:

TableForm[Replace[Outer[Plus, a, a], x_ :> 10 ^ HoldForm @ x, {2}],
TableHeadings -> Replace[{a, a}, x_ :> 10 ^ HoldForm @ x, {2}] ]


Get back to initial form, if needed:

% // ReleaseHold


An example using Format:

Format[h[x_]] :=
With[{p = Log10[x]},
If[p == 0, Style[1, 20], Style[10^HoldForm[p], 20]]]
r = PowerRange[1/1000, 1000, 10];
tu = Tuples[r, 2];
TableForm[Partition[h@*Times @@@ tu, 7],
TableHeadings -> Map[h, {r, r}, {2}], TableAlignments -> Center]