5
$\begingroup$

I have a polynomial in two variables, e.g.

16384 k^4 - 20480 k^2 + x^4 - 320 k^2 x^2 - 128 x^2 + 4096

I'd like Mathematica to factor it as $$(x^2 - f(k))(x^2 - g(k))$$ but Factor does nothing. I assume that's because it's treating $k$ on an equal footing with $x$, but I'd like it to consider $k$ as a constant and just factor with respect to $x$.

I'm sure this has been asked before, but all related-looking questions seemed to have much more complicated answers, including things like the Root function, the quartic formula, long Modules using Solve, or Groebner bases. Surely there's a simple, one-line solution for my problem?

$\endgroup$
2
  • $\begingroup$ I guess it might be possible with Simplify and the option ComplexityFunction. $\endgroup$
    – ivbc
    Jun 20, 2017 at 14:50
  • $\begingroup$ poly2 = (x^2 - a) (x^2 - b) /. Solve[And @@ Thread[CoefficientList[poly, x] == CoefficientList[(x^2 - a) (x^2 - b), x]], {a, b}] $\endgroup$
    – Bob Hanlon
    Jun 20, 2017 at 18:02

2 Answers 2

11
$\begingroup$

Although there might be various approaches, it seems that proceeding the most obvious one should be good enough

We have

Collect[(x^2 - f[k]) (x^2 - g[k]) // Expand, x]
x^4 + x^2 (-f[k] - g[k]) + f[k] g[k]

on the other hand it should be identically equal to

Collect[4096 - 20480 k^2 + 16384 k^4 - 128 x^2 - 320 k^2 x^2 + x^4, x]
4096 - 20480 k^2 + 16384 k^4 + (-128 - 320 k^2) x^2 + x^4

Therefore equating appropriate coefficients in the both polynomials we get a simple system and solving it yields solutions

Solve[{-128 - 320 k^2 == -f[k] - g[k], 
       4096 - 20480 k^2 + 16384 k^4 == f[k] g[k]}, {f[k], g[k]}]
 {{f[k] -> 32 (2 + 5 k^2 - Sqrt[40 k^2 + 9 k^4]), 
   g[k] -> 32 (2 + 5 k^2 + Sqrt[k^2 (40 + 9 k^2)])}, 
  {f[k] -> 32 (2 + 5 k^2 + Sqrt[40 k^2 + 9 k^4]), 
   g[k] -> 32 (2 + 5 k^2 - Sqrt[k^2 (40 + 9 k^2)])}}

Another, and a slightly simpler approach would be:

Solve[ 
  PolynomialQuotientRemainder[
    4096 - 20480 k^2 + 16384 k^4 - 128 x^2 - 320 k^2 x^2 + x^4, 
     x^2 - f[k], x] == {x^2 - g[k], 0}, 
  {f[k], g[k]}]
$\endgroup$
2
  • $\begingroup$ You could use CoefficientList and Thread to get the coefficients out, rather than copying the coefficients from each. Something like Solve[Thread[ CoefficientList[ 4096 - 20480 k^2 + 16384 k^4 - 128 x^2 - 320 k^2 x^2 + x^4, x] == CoefficientList[(x^2 - f[k]) (x^2 - g[k]), x]], {f[k], g[k]}] $\endgroup$
    – SPPearce
    Jun 20, 2017 at 14:50
  • 1
    $\begingroup$ However, this might be simpler Solve[PolynomialQuotientRemainder[ 4096 - 20480 k^2 + 16384 k^4 - 128 x^2 - 320 k^2 x^2 + x^4, x^2 - f[k], x] == {x^2 - g[k], 0}, {f[k], g[k]}] $\endgroup$
    – Artes
    Jun 20, 2017 at 15:28
3
$\begingroup$

Surely there's a simple, one-line solution for my problem?

Of course.

SolveAlways[16384 k^4 - 20480 k^2 + x^4 - 320 k^2 x^2 - 128 x^2 + 4096 ==
            (x^2 - f) (x^2 - g), x]
   {{f -> 32 (2 + 5 k^2 - Sqrt[k^2 (40 + 9 k^2)]), 
     g -> 32 (2 + 5 k^2 + Sqrt[40 k^2 + 9 k^4])},
    {f -> 32 (2 + 5 k^2 + Sqrt[k^2 (40 + 9 k^2)]), 
     g -> 32 (2 + 5 k^2 - Sqrt[40 k^2 + 9 k^4])}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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