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$

closed as off-topic by gwr, Michael E2, Bob Hanlon, Bill Watts, Henrik Schumacher Jan 22 at 22:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – gwr, Michael E2, Bob Hanlon, Bill Watts, Henrik Schumacher
If this question can be reworded to fit the rules in the help center, please edit the question.

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

$\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

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

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