I want to create a table of factorization of certain numbers $f(n)$ with traditional pretty printing output (more or less same as what is used to display in textbooks). For example consider
FactorInteger[Table[n!, {n, 0, 5}]]
standard output is
{{{1, 1}}, {{1, 1}}, {{2, 1}}, {{2, 1}, {3, 1}}, {{2, 3}, {3, 1}}, {{2, 3}, {3, 1}, {5, 1}}}
and the so-called traditional output is some kind of matrix-looking format, with first column the base and the second column the exponent.
How do I create a suitable display output as in
$$\begin{array}{cc} \text{N} & \text{factorization of N!} \\ \hline 0 & 1 \\ \hline 1 & 1 \\ \hline 2 & 2 \\ \hline 3 & 2, 3 \\ \hline 4 & 2^3, 3 \\ \hline 5 & 2^3, 3,5 \\ \hline \end{array}$$
The lines and heading etc. are not the important aspects, the easily readable output is.
Answer
data = FactorInteger[Table[n!, {n, 0, 5}]];
leftCol = Prepend[Range[0, Length[data] - 1], "N"];
rigthCol = Prepend[
Row[HoldForm[#]^#2 & @@@ {##}, ","] & @@@ data,
"factorization of N!"
];
Grid[
Transpose[{leftCol, rigthCol}],
Alignment -> {{Right, Center}},
Dividers -> {False, {False, {True}}},
BaseStyle -> 25
] // TraditionalForm
Comments
Post a Comment