1
$\begingroup$

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) *)
$\endgroup$
  • 2
    $\begingroup$ You could use Factor. $\endgroup$ – b.gates.you.know.what Jan 22 '19 at 9:43
  • $\begingroup$ @b.gatessucks this is the answer! Thanks ;) $\endgroup$ – apt45 Jan 22 '19 at 10:07
  • 4
    $\begingroup$ 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. $\endgroup$ – Lotus Jan 22 '19 at 10:12
  • $\begingroup$ @Lotus thanks! So, is it always better to use Factor, right? $\endgroup$ – apt45 Jan 22 '19 at 10:13
  • 1
    $\begingroup$ See Structural Operations on Polynomials $\endgroup$ – Bob Hanlon Jan 22 '19 at 15:28
5
$\begingroup$

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)

| improve this answer | |
$\endgroup$
2
$\begingroup$

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

| improve this answer | |
$\endgroup$
  • $\begingroup$ I know they are equal... I was just wondering why Mathematica is not simplifying properly pol1. $\endgroup$ – apt45 Jan 22 '19 at 10:05
  • $\begingroup$ Ah, my apologies, I misread your question! I'll leave this here for posterity 😅 $\endgroup$ – Carl Lange Jan 22 '19 at 10:09

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