# Factorization of a fractional multivariate polynomial

Suppose I have given a fractional multivariate polynomial

F2[x1, y1, x2 , y2, x3 , y3, x4] = -((2 x1 x2 x3 x4 y1 y2^2 y3 (x2 y1 + (x3 + x4) (y1 + y2) + x4 y3) (x3 y3 + x2 (y2 + y3) + x1 (y1 + y2 + y3)))/((x2 y2 + x1 (y1 + y2))^2 (x2 y1 + x3 (y1 + y2)) (x3 y3 + x2 (y2 + y3)) (x3 y2 + x4 (y2 + y3))^2));


and some other fractional multivariate polynomials

K1[x1, y1, x2, y2, x3, y3] = (x2 y2 (x3 y3 + x2 (y2 + y3) + x1 (y1 + y2 + y3)))/((x2 y2 + x1 (y1 + y2)) (x3 y3 + x2 (y2 + y3)));


and

K2[y1, x2, y2, x3, y3, x4] = (x3 y2 (x2 y1 + (x3 + x4) (y1 + y2) + x4 y3))/((x2 y1 + x3 (y1 + y2)) (x3 y2 + x4 (y2 + y3)));


If I know that it is possible to factorize $F2$ in terms of $K1$ and $K2$ as follows

F2[x1, y1, x2, y2, x3, y3, x4] = -2 (K1[x1, y1, x2, y2, x3, y3] K2[y1, x2, y2, x3, y3, x4] ) (1 - K1[x1, y1, x2, y2, x3, y3]) (1 - K2[y1, x2, y2, x3, y3, x4]);


then how can I formulate this factorization in Mathematica?

How could I write a program for to do it? Which tools should I use?

• Why not give a concrete example of a factorable "fractional multivariate polynomial"? Commented Oct 5, 2016 at 7:14
• I couldn't understand your point?! @J.M. Commented Oct 5, 2016 at 7:26
• Something like "an example of a factorable univariate polynomial is $x^2-1=(x-1)(x+1)$"... you might want to talk about what a "fractional multivariate polynomial" is supposed to be for non-experts who might want to try things out anyway. Commented Oct 5, 2016 at 7:32
• Here I have asked a same question with more details. But somehow I think more details is not so useful! mathematica.stackexchange.com/questions/121921/… @J.M. Commented Oct 5, 2016 at 7:38
• I'll raise the same question I did on Wolfram Community: What do you find in the documentation when you enter either "factor" or "Factor"? Commented Oct 5, 2016 at 15:20

I interpret the question to be, given

f2 = -((2 x1 x2 x3 x4 y1 y2^2 y3 (x2 y1 + (x3 + x4) (y1 + y2) + x4 y3)
(x3 y3 + x2 (y2 + y3) + x1 (y1 + y2 + y3)))/((x2 y2 + x1 (y1 + y2))^2
(x2 y1 + x3 (y1 + y2)) (x3 y3 + x2 (y2 + y3)) (x3 y2 + x4 (y2 + y3))^2));
k1 = (x2 y2 (x3 y3 + x2 (y2 + y3) + x1 (y1 + y2 + y3)))/((x2 y2 + x1 (y1 + y2))
(x3 y3 + x2 (y2 + y3)));
k2 = (x3 y2 (x2 y1 + (x3 + x4) (y1 + y2) + x4 y3))/((x2 y1 + x3 (y1 + y2))
(x3 y2 + x4 (y2 + y3)));


express f2 as a low-order polynomial in k1 and k2. This can be done as follows. First, generate a generic low order polynomial.

Map[t1^First@# t2^Last@# &, Tuples[Range[0, 3], 2]].Table[Unique["c"], 16]
(* c3 + c7 t1 + c11 t1^2 + c15 t1^3 + c4 t2 + c8 t1 t2 + c12 t1^2 t2 +
c16 t1^3 t2 + c5 t2^2 + c9 t1 t2^2 + c13 t1^2 t2^2 + c17 t1^3 t2^2 +
c6 t2^3 + c10 t1 t2^3 + c14 t1^2 t2^3 + c18 t1^3 t2^3 *)


and then use SolveAlways. After about twenty seconds,

Flatten@SolveAlways[f2 == (% /. {t1 -> k1, t2 -> k2}), {x1, x2, x3, x4, y1, y2, y3}]
(* {c3 -> 0, c4 -> 0, c5 -> 0, c6 -> 0, c11 -> 0, c15 -> 0, c7 -> 0, c12 -> 2, c16 -> 0,
c8 -> -2, c10 -> 0, c13 -> -2, c14 -> 0, c17 -> 0, c18 -> 0, c9 -> 2} *)
Factor[%% /. %]
(* -2 (-1 + t1) t1 (-1 + t2) t2 *)


which is the desired result. For completeness,

Simplify[f2 == % /. {t1 -> k1, t2 -> k2}]
(* True *)


Much Faster Alternative

Because SolveAlways determines the coefficients c for any {x1, x2, x3, x4, y1, y2, y3}, Solve must be able to obtain the same values for the coefficients c for specific values of {x1, x2, x3, x4, y1, y2, y3}, and much faster.

tp = Tuples[Range[0, 3], 2]; tp // Length
(* 16 *)
gp = Map[t1^#[[1]] t2^#[[2]] &, tp].Table[Unique["c"], tp // Length];
Flatten@Solve[Table[(f2 == (gp /. {t1 -> k1, t2 -> k2})) /.
Thread[{x1, x2, x3, x4, y1, y2, y3} -> RandomInteger[{1, 7}, 7]], {n, tp // Length}],
List @@ (First@# & /@ (gp /. gp[[1]] -> gp[[1]] z))] /. Rule[_, 0] -> Nothing
(* {c12 -> 2, c13 -> -2, c8 -> -2, c9 -> 2} *)


as before but three orders of magnitude faster. Note, however, that this alternative always returns results for c, but they are visibly meaningless (random numbers in effect), if the corresponding result from SolveAlways is an empty List.

• I cannot believe it!! It really works! I don't know how to appreciate what you did for me! It means a lot for me! You again did a great job! It was a long time that neither me nor any other person was able to produce this program! Now I can extend it! You saved my project again!! It says that after 14 hours I can give +50, I will do it after 14 hours!! Thank you very much! @bbgodfrey Commented Oct 7, 2016 at 19:40
• Can you please let me know if we want to decompose our function, say $f3$ to $k1, k2, k3$; then what should I write in "Map" for $t2^?$ and what can be in my "Range" and also instead of "2" and instead of "16"? I still am not used to "Map"! Thank you very much for your time and your help! @bbgodfrey Commented Oct 8, 2016 at 0:37
• @farrokh For three functions use Map[t1^#[[1]] t2^#[[2]] t^#[[3]] &, Tuples[Range[0, 3], 3]].Table[Unique["c"], 64] However, note that the number of elements has grown from 16 to 64, so the calculation will be somewhat slower. As you go to bigger and bigger problems, the calculation could become prohibitively slow. To avoid this, use whatever other knowledge you have of the problem to reduce the number of elements in the generic polynomial. By the way, 64 is obtained by Tuples[Range[0, 3], 3] // Length. Commented Oct 8, 2016 at 0:49