I know that if I use
CenterDot @@ (Superscript @@@ FactorInteger[x])
Mathematica will pretty print the output. However, is it possible to tell Mathematica to automatically format the output of FactorInteger with CenterDot and Superscript?
I know that if I use
CenterDot @@ (Superscript @@@ FactorInteger[x])
Mathematica will pretty print the output. However, is it possible to tell Mathematica to automatically format the output of FactorInteger with CenterDot and Superscript?
This is the best I can come up quickly. It can be used much in the same way that MatrixForm is.
SetAttributes[factorizationForm, HoldFirst];
factorizationForm[expr_] :=
If[Head[Unevaluated[expr]] === FactorInteger,
CenterDot @@ Superscript @@@ expr,
expr]
Then
FactorInteger[5!] // factorizationForm
but
{{2, 3}, {3, 1}, {5, 1}} // factorizationForm
{{2, 3}, {3, 1}, {5, 1}}
I think it satisfies the spirit of your question even if it's not what you asked for to the letter.
$PrePrint doesn't have the HoldFirst attribute and it doesn't return one of the formatted forms, but the evaluated, but unformatted, form of its argument.
– m_goldberg
Apr 05 '14 at 13:19
$Preprint (which can have strange side-effects unless you know exactly what you are doing) until you have a much better understanding of how Mathematica works. If you don't understand that HoldFirst is an attribute and not a function and what difference that makes, you are not ready to mess with $Preprint. I do recommend this download if you want to learn more.
– m_goldberg
Apr 05 '14 at 23:41
fi[x_]:=CenterDot @@ (Superscript @@@ FactorInteger[x])– ubpdqn Apr 05 '14 at 03:59