Simplifying polynomials [closed]

I have noticed a strange behaviour in Mathematica regarding simplifying polynomial expressions. Take the following polynomials

pol1=3-8s+4s^2
pol2=(2s-1)(2s-3)


these two polynomials are equals. However, If I try to simplify the pol1 I do not get pol2

pol1//FullSimplify
(*Output: 3 - 8 s + 4 s^2*)


Why does this happen? I have always used FullSimplify for this kind of expressions. For example,

pol3=-15 + 41 s - 24 s^2 + 4 s^3;
pol3//FullSimplify
(*Output: (-3 + s) (-5 + 2 s) (-1 + 2 s) *)

• You could use Factor. – b.gates.you.know.what Jan 22 '19 at 9:43
• @b.gatessucks this is the answer! Thanks ;) – apt45 Jan 22 '19 at 10:07
• By default FullSimplify uses LeafCount as the ComplexityFunction. This means that the expression which has more leaves is considered more complex. With this understanding we can reconcile the results that you get. – Lotus Jan 22 '19 at 10:12
• @Lotus thanks! So, is it always better to use Factor, right? – apt45 Jan 22 '19 at 10:13
• – Bob Hanlon Jan 22 '19 at 15:28

You can use Factor as stated in the comments:

pol1 // Factor


(-3 + 2 s) (-1 + 2 s)

Comparing the polynomials reveals:

(pol1 // Factor) === (pol2 // Factor) (* factoring pol2 just equalizes sorting of terms *)


True

ComplexityFunction is used by FullSimplify to judge whether an expression is simpler than another. We may tweak this (maybe naively) by trying to maximize the number of expressions with the head Times:

f[e_] := -Count[ e, _Times, {0, Infinity} ]

FullSimplify[ pol1, ComplexityFunction -> f ]


(-3 + 2 s) (-1 + 2 s)

You can see that they are equal by using FullSimplify on both polynomials.

FullSimplify@pol1


3 + 4 (-2 + s) s

FullSimplify@pol2


3 + 4 (-2 + s) s

Furthermore, you can Reduce the expression of equality with regard to s:

Reduce[pol1 == pol2, s]


True

• I know they are equal... I was just wondering why Mathematica is not simplifying properly pol1. – apt45 Jan 22 '19 at 10:05
• Ah, my apologies, I misread your question! I'll leave this here for posterity ðŸ˜… – Carl Lange Jan 22 '19 at 10:09