6
$\begingroup$

Trying to standard create prime factors presentation, but can't seem to remove the parentheses:

f[n_] := If[PrimeQ[Abs[n]] == True, n, Sign[n] CenterDot @@ 
Table[If[FactorInteger[Abs[n]][[m, 2]] < 2, FactorInteger[Abs[n]][[m, 1]], 
Superscript @@ (FactorInteger[Abs[n]][[m]])], {m, 1, Length@FactorInteger[Abs[n]]}]]

f[-96]

out:

$-(2^5\cdot 3)$

I'm sure I made a meal out of it, but as it it, it works. I tried to remove -1 output with Sign, but getting parentheses. Is there a neat way to do this without?

$\endgroup$

1 Answer 1

9
$\begingroup$
pf[n_] := PrecedenceForm[CenterDot @@ Table[If[FactorInteger[Abs[n]][[m, 2]] < 2, 
      FactorInteger[Abs[n]][[m, 1]], Superscript @@ (FactorInteger[Abs[n]][[m]])], {m, 1, 
      Length@FactorInteger[Abs[n]]}], 10000];

f2[n_] := If[PrimeQ[Abs[n]] == True, n, Sign[n] pf[n]]

f2[-96]

enter image description here

See also:

PrecedenceForm

tutorial / Operator Input Forms >> Operator Precedence

$\endgroup$
1
  • $\begingroup$ lovely! Thank you :) $\endgroup$
    – martin
    Commented Nov 1, 2014 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.