I have a series expansion in $x$ and $a,b$ are constants which I want to type in $\LaTeX$. But the numbers/integers are pretty large (have a lot of digits) so it becomes a bit messy in $\LaTeX$. Therefore, I wanted to use prime factorization for the numbers within the expression. Is there a way of doing this in Mathematica? As an example (just an example), given the output

(23991 x^3)/(250000 a^5) + (87271/(5000000 a^6) + 31/(600 a^2) - b/2816) x^4 

I want to simplify it to

(3*11*727)/(2^4*5^6*a^5)x^3 + ((197*443)/(2^6*5^7*a^6) + 31/(2^3*3*5^2*a^2) - b/(2^8*11)) x^4

That is, I want to rewrite the expression

$$\frac{23991\, x^3}{250000 \,a^5}+x^4 \left(\frac{87271}{5000000 \,a^6}+\frac{31}{600 \,a^2}-\frac{b}{2816}\right)$$


$$\frac{3 \cdot 11 \cdot 727}{2^{4} \cdot 5^{6} \cdot a^{5}}x^{3} + \left(\frac{197 \cdot 443}{2^{6} \cdot 5^{7} \cdot a^{6}} + \frac{31}{2^{3} \cdot 3 \cdot 5^{2} \cdot a^{2}} - \frac{b}{2^{8} \cdot 11}\right)x^{4}$$

  • $\begingroup$ What you want to do is not simplification to Mathematica. $\endgroup$
    – m_goldberg
    Jan 29, 2016 at 15:54

1 Answer 1


This is as close as I could get for this expression, but I don't know what other types of expressions you would need to work with. The code is also ugly, so there has got to be something prettier, but here goes: if we set

exp = (23991 x^3)/(250000 a^5) + (87271/(5000000 a^6) + 31/(600 a^2) - b/2816) x^4 


  exp /. 
  {Rational[x_, y_]*rest_ :> 
  n_?NumberQ*rest_ :> dummyhead[FactorInteger[n]]*rest
  } /. 
  list_dummyhead :> Times @@ (HoldForm[#1^#2] & @@@ list[[1]])

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .