Having -1 as part of the result when factoring a polynomial

3 views (last 30 days)
Hi,
I'm trying to find the factor from a polynomial and sometimes when I used the factor(x) function as shown below
factor(y^6 - x^6)
The array result would show
[ -1, x - y, x + y, x^2 + x*y + y^2, x^2 - x*y + y^2]
and I'm having trouble understanding what the "-1" means
What I've also noticed is that when I tried to calculate it outside of matlab the result seems to be somewhat different
for example, using the same polynomial from before I would instead get
(y + x)(y - x)(y^2 + x^2 + yx)(y^2 + x^2 - yx)
Where some of the plus and minus sign switch from the y to x
If anyone could explain this that would be very helpful
thank you

Answers (3)

Torsten
Torsten on 19 Mar 2024
Moved: Torsten on 19 Mar 2024
syms x y
f = expand(-1*(x-y)*(x+y)*(x^2+x*y+y^2)*(x^2-x*y+y^2))
f = 

Steven Lord
Steven Lord on 19 Mar 2024
What happens if you omit that factor when you multiply the rest of the factors together?
syms x y
P1 = y^6 - x^6
P1 = 
f = factor(P1)
f = 
P2 = simplify(prod(f(2:end)))
P2 = 
x^6-y^6 is not the same as y^6-x^6.
What happens if you were to multiply those first two terms together?
f(1)*f(2)
ans = 
That's the same as the second term in your "outside of matlab[sic]" result. That still doesn't give you the exact form you got outside MATLAB, but "x+y" (inside MATLAB) and "y+x" (outside MATLAB) are the same because addition is commutative, unlike subtraction.

John D'Errico
John D'Errico on 19 Mar 2024
Edited: John D'Errico on 19 Mar 2024
You should understand that a factorization is not unique when you get down to a factor of -1. Yes, it may seem strange, but even the simple polynomial
P = -x + y
could arbitrarily and ambiguously be factored into pairs of factors
{1, -x + y}
or
{1, y - x}
or even
{-1, x - y}
And that is essentially what happened here. MATLAB made a simple decision, for a totally arbitrary reason. Sometimes wanting to understand a subtle decision made by a complex software package is asking too much. :) The result is completely valid in any case. However, in this case, I think I know what happened.
At some point along the way, a form like (-x+y) was generated. And, yes. you miight just mentally rewrite that as (y-x). But what happens inside the symbolic toolbox?
syms x y
factor(-x + y)
ans = 
Indeed, it factors out a -1 term. But if we try this:
factor(x - y)
ans = 
it seems willing to leave it alone.
  4 Comments
John D'Errico
John D'Errico on 19 Mar 2024
Edited: John D'Errico on 19 Mar 2024
That is essentially my point, that there must be some sort of implicit preferences built into the code. I think any aesthetics were those of the author(s) of the toolbox. I might imagine some simple rules, perhaps
  1. All coefficients of a "factor" should be integers.
  2. The first coefficient of a fragment in a term should have a constant factor of 1, to the extent that is possible.
  3. Factor out -1, rather than look for a re-ordering of terms that might avoid needing to create a factor of -1.
Those are just wild guesses on my part of course. I can test those "rules". But there is no assurance I am correct in my guess as to the actual rules employed.
syms x y
factor(x/2 + y)
ans = 
factor(x + y/2)
ans = 
factor(x/2 + y/3)
ans = 
factor(x/4 + y/2)
ans = 
factor(x/2 + y/4)
ans = 
Clearly factor likes integer coefficients. But it is not wedded to the idea that the leading coefficient on the first fragment is unity, as that would sometimes require a re-ordering.
The problem with looking for a re-ordering to yield a unit leading coefficient is it is simpler to just factor out -1, than it is to look for a re-ordering. For example, suppose we consider the expression:
-x - y + z
We might automatically see that as
z - x - y
But it is surely simpler to write it as
-1*(x + y - z)
which requires no re-ordering.
Why do I feel as if I have been thrust into some sort of quasi-Asimovian universe, where the robots follow a set of laws, but where we have not been told the laws of robotics, and we can only infer them from the actions of the bots?
Walter Roberson
Walter Roberson on 19 Mar 2024
I recall (perhaps incorrectly) that it prefers things in asciibetical order:
Yes, it does.
All expressions are immediately rewritten in a cannonical order. This is done as an optimization: you can efficiently check if two expressions are the same by comparing the cannonical order of the expression.
Checking whether two expressions are the same is important because expressions that are the same are replaced by a pointer to the unique version of the expression. That in turn means that operations on the common expression can be performed just once instead of once for each time the expression repeats.

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!