fix leading coefficient bug in fmpz_mpoly_factor #2000
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #1998
short description: ZZ is not a field
long description
fmpz_mpoly_factor_irred_wang is called on A = 3*x1^3*x2^3*x3^3*x4^3+9*x1^3*x2^3*x3^3*x4^2+9*x1^3*x2^3*x3^3*x4+3*x1^3*x2^3*x3^3+x1^3*x2^3*x3^2*x4^4+5*x1^3*x2^3*x3^2*x4^3+9*x1^3*x2^3*x3^2*x4^2+7*x1^3*x2^3*x3^2*x4+2*x1^3*x2^3*x3^2-4*x1^3*x2^2*x3^3*x4^3-4*x1^3*x2^2*x3^3*x4^2+4*x1^3*x2^2*x3^3*x4+4*x1^3*x2^2*x3^3-4*x1^3*x2^2*x3^2*x4^3-2*x1^3*x2^2*x3^2*x4^2+8*x1^3*x2^2*x3^2*x4+6*x1^3*x2^2*x3^2+2*x1^3*x2^2*x3*x4^2+4*x1^3*x2^2*x3*x4+2*x1^3*x2^2*x3-6*x1^3*x2*x3^3*x4^2-5*x1^3*x2*x3^3*x4+x1^3*x2*x3^3-13*x1^3*x2*x3^2*x4^2-11*x1^3*x2*x3^2*x4+2*x1^3*x2*x3^2-8*x1^3*x2*x3*x4^2-7*x1^3*x2*x3*x4+x1^3*x2*x3-x1^3*x2*x4^2-x1^3*x2*x4-2*x1^3*x3^3*x4-6*x1^3*x3^2*x4-6*x1^3*x3*x4-2*x1^3*x4-x1^2*x2^3*x3^2*x4^4-5*x1^2*x2^3*x3^2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A = ((x2x3x4+x2x3+x3+1)x1 + ...)
((3x2^2x3^2x4^2+6x2^2x3^2x4+3x2^2x3^2+x2^2x3x4^3+4x2^2x3x4^2+5x2^2x3x4+2x2^2x3-4x2x3^2x4^2-3x2x3^2x4+x2x3^2-5x2x3x4^2-4x2x3x4+x2x3-x2x4^2-x2x4-2x3^2x4-4x3x4-2x4)*x1^2 + ...)
evaluation is tried at
x2 = 1
x3 = 2
x4 = 1
which produces
A = 4*(3x1 - 1)(x1 - 1)(7x1 - 3) modulo (x2 - 1, x3 - 2, x4 - 1)
Since the number of factor is wrong, we already known lifting will not succeed,
but let's see what else goes wrong first.
Lifting does not alter the leading coefficients, so they have to be - in some
sense - correct before lifting proceeds. The point of lcc is to find divisors
of the leading coefficients of the factors of A assuming that the univariate
factorization lifts (aka no extraneous factors). Since we had three univariate
factors, assume that they lift to corresponding multivariate factors F1, F2, F3.
lcc returns with (lc := lc_x1)
lc(F1) is divisible by 1
lc(F2) is divisible by 3x2^2x3^2x4^2+6x2^2x3^2x4+3x2^2x3^2+x2^2x3x4^3+4x2^2x3x4^2+5x2^2x3x4+2x2^2x3-4x2x3^2x4^2-3x2x3^2x4+x2x3^2-5x2x3x4^2-4x2x3x4+x2x3-x2x4^2-x2x4-2x3^2x4-4x3x4-2x4
lc(F3) is divisible by x2x3x4+x2x3+x3+1
Since the product of these three divisors is exactly lc(A), there is nothing
left over, m in the code is 1, and we will simply impose exactly these leading
coefficients, i.e.
lc(F1) = 1
lc(F2) = 3x2^2x3^2x4^2+6x2^2x3^2x4+3x2^2x3^2+x2^2x3x4^3+4x2^2x3x4^2+5x2^2x3x4+2x2^2x3-4x2x3^2x4^2-3x2x3^2x4+x2x3^2-5x2x3x4^2-4x2x3x4+x2x3-x2x4^2-x2x4-2x3^2x4-4x3x4-2x4
lc(F3) = x2x3x4+x2x3+x3+1
when lifting against A. The contradiction is already clear: the factor 3*x1 - 1
cannot possibly lift to an F1 with lc(F1) = 1 and the code tries to
divexact(1,3). More specifically, evaluation at x2 = 1, x3 = 2, x4 = 1, produces
lc(F1) = 1 modulo (x2 - 1, x3 - 2, x4 - 1)
lc(F2) = 12 ""
lc(F3) = 7 ""
Therefore, the leading coefficients of the univariate factorizations are coerced to these as
1x1 - 1/3
12x1 - 12
7*x1 - 3
which isn't so good over ZZ.
This would be fine to do over QQ, where the lifting would eventually just fail.
**** Why lcc returns what it does ****
lcc is the hairiest part of mpoly factor.
Kaltofen is used here which looks at bivariate factorizations of
A(x1, x2, 2, 1) = (288x2^3+48x2^2-198x2-54)x1^3 + (-96x2^3-352x2^2+174x2+126)x1^2 + (112x2^2+54x2-90)x1^1 + (-30x2+18)x1^0
A(x1, 1, x3, 1) = (12x3^3+4x3^2-12x3-4)x1^3 + (-16x3^3-20x3^2+24x3+12)x1^2 + (4x3^3+20x3^2-12x3-12)x1^1 + (-4x3^2+4)x1^0
A(x1, 1, 2, x4) = (4x4^4-4x4^3-45x4^2+19x4+110)x1^3 + (-4x4^4-4x4^3+75x4^2+11x4-226)x1^2 + (8x4^3-27x4^2-51x4+146)x1^1 + (-3x4^2+21*x4-30)*x1^0
The last two have content as polys in x1, so they are thrown away.
Everything is deduced from the factorization
A(x1, x2, 2, 1) = ( (3)x1^1 + (-1)x1^0 )
( (12x2^2-7x2-3)x1^1 + (-5x2+3)x1^0 )
( (4x2+3)*x1^1 + (-3)*x1^0 )
Note the leading coefficient of the first factor is a constant.
What we have is a factorization of lc(A) modulo (x3 - 2, x4 - 1):
lc(A) = (3)(12x2^2-7x2-3)(4*x2+3) modulo (x3 - 2, x4 - 1)
This factorization happens to lift [only trivial lcc is applied recursively :)]
and so the lifted factors can be safely assumed to be divisors of the lc(Fi)