# Reducing large polynomial expression to product of simplar polynominals

A beginner to Mathematica.

I am trying to express a large symbolic polynomial expression as a product of factors of simpler polynomials:

For example I was able to factor this expression:

256. ptz (1. ptx^4 + 1. ptx^2 pty^2 - 2. ptx^3 ptz -
2. ptx pty^2 ptz + 1. ptx^2 ptz^2 + 1. pty^2 ptz^2 + 2. ptx^3 px +
2. ptx pty^2 px - 2. ptx^2 ptz px - 2. pty^2 ptz px +
1. ptx^2 px^2 + 1. pty^2 px^2 - 2. ptx^3 pz - 2. ptx pty^2 pz +
2. ptx^2 ptz pz + 2. pty^2 ptz pz - 2. ptx^2 px pz -
2. pty^2 px pz + 1. ptx^2 pz^2 + 1. pty^2 pz^2)


into

256 ptz (ptx^2 + pty^2)(ptx - ptz + px - pz)^2


manually. How do I accomplish the same in Mathematica ? I do realize that the factors are not "standard terms". Any hints would be much appreciated.

• Rationalize the coefficients: Factor[Rationalize[expr]]. Jun 12, 2020 at 17:56

It is generally good practice to work with exact integers, rationals, roots, etc. when trying to manipulate things in Mathematica. Your question illustrates why.

foo = 256. ptz (1. ptx^4 + 1. ptx^2 pty^2 - 2. ptx^3 ptz -
2. ptx pty^2 ptz + 1. ptx^2 ptz^2 + 1. pty^2 ptz^2 +
2. ptx^3 px + 2. ptx pty^2 px - 2. ptx^2 ptz px -
2. pty^2 ptz px + 1. ptx^2 px^2 + 1. pty^2 px^2 - 2. ptx^3 pz -
2. ptx pty^2 pz + 2. ptx^2 ptz pz + 2. pty^2 ptz pz -
2. ptx^2 px pz - 2. pty^2 px pz + 1. ptx^2 pz^2 +
1. pty^2 pz^2);
bar = Rationalize[foo]

(* 256 ptz (ptx^4 + ptx^2 pty^2 - 2 ptx^3 ptz - 2 ptx pty^2 ptz +
ptx^2 ptz^2 + pty^2 ptz^2 + 2 ptx^3 px + 2 ptx pty^2 px -
2 ptx^2 ptz px - 2 pty^2 ptz px + ptx^2 px^2 + pty^2 px^2 -
2 ptx^3 pz - 2 ptx pty^2 pz + 2 ptx^2 ptz pz + 2 pty^2 ptz pz -
2 ptx^2 px pz - 2 pty^2 px pz + ptx^2 pz^2 + pty^2 pz^2) *)

Simplify[bar]

(* 256 (ptx^2 + pty^2) ptz (ptx - ptz + px - pz)^2 *)


The Rationalize command replaces all expressions involving machine-precision numbers (such as 1. and 2.) with exact integers (such as 1 and 2.) The Simplify function is then able to do much more if it knows that these are exact integer coefficients and not approximate real numbers. In contrast, simply asking Mathematica to

Simplify[foo]


does not change the output much (try it!)

For more information on why Mathematica works the way it does, you may find the Wolfram tutorial on How to Control the Precision and Accuracy of Numerical Results helpful.

• This is one of those questions where the real problem is not what's being directly asked about. Jun 12, 2020 at 17:56
• Thank you Michael for the quick response and also the solution. It does exactly what I was looking for. I used Simplify[foo] without paying attention to the significance of integers. Thank you again. Jun 12, 2020 at 18:22