# Specific factoring of fourth degree polynomial

I have a pretty unspecific question about a really specific thing -- How would one use Mathematica to find values for an integer, m, such that this polynomial

p4 = x^4 −(2m + 4)x^2 + (m−2)^2


Can be factored into the product of two non-constant polynomials with integer coefficients.

I understand, or at least think, that this is much more than a two-step deal, but any help you might offer in relation to how to go about this would be highly appreciated.

• You could try at least to write your poly in Mathematica notation – Dr. belisarius Dec 30 '14 at 15:26
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Dec 30 '14 at 15:28
• @belisarius I'm not new to stackexchange, although I haven't used it a while. I do know how to vote (although I can't, since I just signed up for Mathematica SE and don't have enough rep). The other question hadn't been marked as answer yet by choice, though you're right, it's a closed issue and should be marked accordingly. In relation to the mathematica notation, I could've used p4[x_], but I'm not really using x for anything (no need to substitute x for anything in this question) and so I chose (maybe uncorrectly) to leave it as is. Sorry about any more problems with my question. – SilverShad0wz Dec 30 '14 at 15:32
• I'm sure that before asking you've searched the site for similar questions (you should always do it!). By browsing the site like that you'll inevitably find good questions and answers: upvote them! – Dr. belisarius Dec 30 '14 at 15:36
• @belisarius of course! But there's a 15 rep minimum until you can upvote questions and answers :( – SilverShad0wz Dec 30 '14 at 15:52

I'm not entirely sure what you are looking for. Do the factors need to have integer coefficients? If not, then you get a factorization into quadratics just by noting you have a polynomial in x^2 and hence can use the quadratic formula. The nonnegativity of both roots will follow, in this specific example, provided the discriminant is nonnegative.

[Note: Below is corrected from original response.]

Reduce[(2*m+4)^2 - 4 (m-2)^2 >= 0, m]

(* Out[39]= m >= 0 *)


From here you might want to investigate the linear factors, I'm not sure.

If you are looking for integer coefficients in the factors, could work with this.

Solve[(2*m+4)^2 - 4*(m-2)^2 == k^2 && m>=0, {m, k}, Integers]


The (parametrized) result is tricky to work with but it does seem to be usable.

--- edit ---

We are looking for integer coefficients in the factorization. This gives some ammunition, for example, to attack the linear factor case.

Suppose there is such a factorization, that is, at least one linear factor. Then it will have the form (x-k)*cubic (where the cubic might be further factorizable). So let's see what that would imply. Equating coefficients of linear times cubic with the given polynomial form yields the following.

ss =
SolveAlways[(x - k)*(x^3 + a*x^2 + b*x + c) ==
x^4 \[Minus] (2 m + 4) x^2 + (m \[Minus] 2)^2, x]

(* Out[34]= {{a -> k, b -> -8 - 4 Sqrt[2] k - k^2,
c -> -8 k - 4 Sqrt[2] k^2 - k^3,
m -> 2 + 2 Sqrt[2] k + k^2}, {a -> k, b -> -8 + 4 Sqrt[2] k - k^2,
c -> -8 k + 4 Sqrt[2] k^2 - k^3, m -> 2 - 2 Sqrt[2] k + k^2}} *)


Now let's see what the quartic polynomial becomes.

Collect[Expand[(x - k)*(x^3 + a*x^2 + b*x + c) /. ss], x]

(* {8 k^2 + 4 Sqrt[2] k^3 +
k^4 + (-8 - 4 Sqrt[2] k - 2 k^2) x^2 + x^4,
8 k^2 - 4 Sqrt[2] k^3 + k^4 + (-8 + 4 Sqrt[2] k - 2 k^2) x^2 + x^4} *)


Since m is restricted to be an integer, we cannot obtain integer coefficients unless k has a factor involving sqrt(2). So we cannot have a linear factor with an integer root (negative of the constant term). (2m + 4) Now let's return to the quadratic timesx quadratic scenario. This can be handled simply by substituting y for x^2, that is, making the polynomial explicitly quadratic. Find the roots, then substitute back to rewrite in terms of x^2. The roots of the newly formed quadratic are given by the quadratic formula:

((2*m + 4) +- Sqrt[(2*m + 4)^2-4*(m−2)^2]) / 2


Per specifications of the question, we require that these be integral and nonnegative. Note that my original formulation of the quadratic discriminant was missing a factor of 4 from the second term. Putting it in makes for an easier computation. I edited above to observe that the nonnegativity restriction simply implies that m>=0. So let's follow up from there. I remark that the k below is not related to the (nonexisting) one from the linear times cubic attempt.

qsols = Solve[(2*m + 4)^2 - 4*(m - 2)^2 == k^2 && m >= 0, {m,
k}, Integers]

(* Out[40]= {{m ->
ConditionalExpression[32 C[1]^2, C[1] \[Element] Integers],
k -> ConditionalExpression[32 C[1],
C[1] \[Element] Integers]}, {m ->
ConditionalExpression[2 + 16 C[1] + 32 C[1]^2,
C[1] \[Element] Integers],
k -> ConditionalExpression[8 + 32 C[1],
C[1] \[Element] Integers]}, {m ->
ConditionalExpression[8 + 32 C[1] + 32 C[1]^2,
C[1] \[Element] Integers],
k -> ConditionalExpression[16 + 32 C[1],
C[1] \[Element] Integers]}, {m ->
ConditionalExpression[18 + 48 C[1] + 32 C[1]^2,
C[1] \[Element] Integers],
k -> ConditionalExpression[24 + 32 C[1], C[1] \[Element] Integers]}} *)


This just means that any integer value for the parametrized constant will give a viable solution. For example one can generate some as follows. Note that there is overlap from separate solution branches, hence the use of Union.

polys =
Union[Flatten[
Table[Expand[
x^4 \[Minus] (2 m + 4) x^2 + (m \[Minus] 2)^2 /. qsols /.
C[1] -> j], {j, -4, 4}]]]

(* Out[49]= {518400 - 1448 x^2 + x^4, 417316 - 1300 x^2 + x^4,
331776 - 1160 x^2 + x^4, 260100 - 1028 x^2 + x^4,
200704 - 904 x^2 + x^4, 152100 - 788 x^2 + x^4,
112896 - 680 x^2 + x^4, 81796 - 580 x^2 + x^4, 57600 - 488 x^2 + x^4,
39204 - 404 x^2 + x^4, 25600 - 328 x^2 + x^4, 15876 - 260 x^2 + x^4,
9216 - 200 x^2 + x^4, 4900 - 148 x^2 + x^4, 2304 - 104 x^2 + x^4,
900 - 68 x^2 + x^4, 256 - 40 x^2 + x^4,
36 - 20 x^2 + x^4, -8 x^2 + x^4, 4 - 4 x^2 + x^4} *)

Factor[polys]


Notice that these do factor as desired.

(* Out[50]= {(-800 + x^2) (-648 + x^2), (-722 + x^2) (-578 +
x^2), (-648 + x^2) (-512 + x^2), (-578 + x^2) (-450 +
x^2), (-512 + x^2) (-392 + x^2), (-450 + x^2) (-338 +
x^2), (-392 + x^2) (-288 + x^2), (-338 + x^2) (-242 +
x^2), (-288 + x^2) (-200 + x^2), (-242 + x^2) (-162 +
x^2), (-200 + x^2) (-128 + x^2), (-162 + x^2) (-98 + x^2), (-128 +
x^2) (-72 + x^2), (-98 + x^2) (-50 + x^2), (-72 + x^2) (-32 +
x^2), (-50 + x^2) (-18 + x^2), (-32 + x^2) (-8 + x^2), (-18 +
x^2) (-2 + x^2), x^2 (-8 + x^2), (-2 + x^2)^2} *)


--- end edit ---

• Sorry, I might've miswrote on the post -- you're correct, I'm looking for integer coeficients in the factors. I'll look into your method right now, I'd be fine with it as long as I could work with the output. Thanks a lot for the help! – SilverShad0wz Dec 30 '14 at 16:27
• I'm fairly new to mathematica and I'm sorry but I'm having a bit of trouble using the output of your last suggestion. I'd be really grateful if you could ellaborate on what is being outputed. Thanks! – SilverShad0wz Dec 30 '14 at 17:00
• See edit for corrections and further analysis and details. – Daniel Lichtblau Dec 30 '14 at 17:31
• Couldn't have hoped for a better, more detailed explanation -- thank you so much! – SilverShad0wz Dec 30 '14 at 18:39

This is an interesting question that is not solvable in one simple step. Let's take a look at the assumptions. Since we have a fourth-order polynomial with integer coefficients we expect that there might be only complex conjugate roots. Now we have:

Times @@ (x - (x /. Solve[ x^4 - (2 m + 4) x^2 + (m - 2)^2 == 0, x]))

(-Sqrt[2 - 2 Sqrt[2] Sqrt[m] + m] + x) (Sqrt[ 2 - 2 Sqrt[2] Sqrt[m] + m] + x)
(-Sqrt[2 + 2 Sqrt[2] Sqrt[m] + m] + x) (Sqrt[2 + 2 Sqrt[2] Sqrt[m] + m] + x)


We would like to find cases when products of two linear factors are second order polynomials with integer coefficients. Taking possible products of linear factors we get:

Column[
Collect[
Expand[{
(Sqrt[2 - 2 Sqrt[2] Sqrt[m] + m] + x) (-Sqrt[2 - 2 Sqrt[2] Sqrt[m] + m] + x),
(Sqrt[2 - 2 Sqrt[2] Sqrt[m] + m] + x) (Sqrt[2 + 2 Sqrt[2] Sqrt[m] + m] + x),
(Sqrt[2 - 2 Sqrt[2] Sqrt[m] + m] + x) (-Sqrt[2 + 2 Sqrt[2] Sqrt[m] + m] + x)}],
x,
FullSimplify[ #, m > 2] &]]

-2 + 2 Sqrt[2] Sqrt[m] - m + x^2
-2 + m + (Sqrt[2 - 2 Sqrt[2] Sqrt[m] + m] + Sqrt[2 + 2 Sqrt[2] Sqrt[m] + m]) x + x^2
2 - m + (Sqrt[2 - 2 Sqrt[2] Sqrt[m] + m] - Sqrt[2 + 2 Sqrt[2] Sqrt[m] + m]) x + x^2


We don't have to worry about another factor since if one is with integer coefficients the other one is so.

Now we have to analize when the above three factors have integer coefficients.

## I

We don't know a priori how many solutions there might be therefore I recommend to examine this answer: Solving/Reducing equations in Z/pZ

If one is to search extensively then extension of "DiscreteSolutionBound" might be helpful:

SetSystemOptions["ReduceOptions" -> {"DiscreteSolutionBound" -> 100}];


We introduce another parameter k to restrict our search to integers, moreover since there might be infinitely many solutions we should somehow set bounds for m and k.

m /. {ToRules @ Reduce[-2 + 2 Sqrt[2] Sqrt[m] - m == k &&
m >= 0 && -100 <= k <= 100, {m}, Integers]}

{128, 98, 72, 50, 32, 18, 0, 8, 2}


## II

Taking another factors we find many more solutions

m /. {ToRules @ Reduce[(Sqrt[ 2 - 2 Sqrt[2] Sqrt[m] + m] +
Sqrt[2 + 2 Sqrt[2] Sqrt[m] + m]) == k &&
m >= 0 && -50 <= k <= 50, {m}, Integers]}

{ 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256,
289, 324, 361, 400, 441, 484, 529, 576, 625}


## III

m /. { ToRules @ Reduce[( Sqrt[2 - 2 Sqrt[2] Sqrt[m] + m] -
Sqrt[2 + 2 Sqrt[2] Sqrt[m] + m]) == k &&
m >= 0 && -50 <= k <= 50, {m}, Integers]}

{1, 0}


We have found many solutions assuming certain bounds for k however we are interested in m only. It is not difficult to observe that a general solution is of the form m == 2 n^2 in case I and m == n^2 in case II for integer n. The case case III doesn't change that the general solution is m == n^2 || m == 2 n^2 for integer n.

One simple approach is to try different values of m using the Factor function and check if the polynomials factor in the desired way. For example, contrast what happens when you have a polynomial that is simply factorizable such as

Factor[x^4 - (2 m + 4) x^2 + (m - 2)^2 //. m -> 8]


and what happens when you don't

Factor[x^4 - (2 m + 4) x^2 + (m - 2)^2 //. m -> 7]


In the first case, when the polynomial factors nicely into two pieces, the FullForm starts with Times. In the second case, when the polynomial does not factor, the FullForm starts with Plus. Thus you can search for the desired m values by looking at the Head

vals = Position[Head[Factor[x^4 - (2 m + 4) x^2 + (m - 2)^2 //. m -> #]] & /@ Range[100], Times]

{1, 2, 4, 8, 9, 16, 18, 25, 32, 36, 49, 50, 64, 72, 81, 98, 100}


These values of m give polynomials of the desired form. The corresponding factored polynomials are:

(Factor[x^4 - (2 m + 4) x^2 + (m - 2)^2 //. m -> #] & /@ Range[100])[[vals]]

{(-1 - 2 x + x^2) (-1 + 2 x + x^2),  x^2 (-8 + x^2),
(2 - 4 x + x^2) (2 + 4 x + x^2),(-18 + x^2) (-2 + x^2),
(7 - 6 x + x^2) (7 + 6 x + x^2), (14 - 8 x + x^2) (14 + 8 x + x^2),
(-32 + x^2) (-8 + x^2), (23 - 10 x + x^2) (23 + 10 x + x^2),
(-50 + x^2) (-18 + x^2), (34 - 12 x + x^2) (34 + 12 x + x^2),
(47 - 14 x + x^2) (47 + 14 x + x^2), (-72 + x^2) (-32 + x^2),
(62 - 16 x + x^2) (62 + 16 x + x^2), (-98 + x^2) (-50 + x^2),
(79 - 18 x + x^2) (79 + 18 x + x^2), (-128 + x^2) (-72 + x^2),
(98 - 20 x + x^2) (98 + 20 x + x^2)}