-
Notifications
You must be signed in to change notification settings - Fork 31
Add resultant methods to fmpz_poly and fmpq_poly #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fec8a10
86ffb15
658e502
8bac286
296c96a
4870eec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2834,6 +2834,42 @@ def setbad(obj, i, val): | |
if type(p) == flint.fq_default_poly: | ||
assert raises(lambda: p.integral(), NotImplementedError) | ||
|
||
# resultant checks. | ||
x = P([0, 1]) | ||
|
||
if composite_characteristic and type(x) in [flint.fmpz_mod_poly, flint.nmod_poly]: | ||
# Flint sometimes crashes in this case, even though the resultant | ||
# could be computed. | ||
divisor = characteristic.factor()[0][0] | ||
assert raises(lambda: x.resultant(x + divisor), ValueError) | ||
elif type(x) == flint.fq_default_poly: | ||
# Flint does not implement resultants over GF(q) for nonprime q, so | ||
# there's nothing for us to check. | ||
pass | ||
else: | ||
assert x.resultant(x) == 0 | ||
assert x.resultant(x**2 + x - x) == 0 | ||
assert x.resultant(x**10 - x**5 + 1) == S(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised that nmod_poly doesn't crash here. I guess it sometimes does and sometimes doesn't: In [3]: a = flint.nmod_poly([1, 2, 3], 12)
In [4]: b = flint.nmod_poly([1, 2, 3], 12)
In [5]: a.resultant(b)
Out[5]: 0
In [6]: b = flint.nmod_poly([1, 2, 3, 4], 12)
In [7]: a.resultant(b)
Flint exception (Impossible inverse):
Cannot invert modulo 3*4
Aborted (core dumped) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know! I added a similar check for nmod_poly that makes this example throw an exception. |
||
assert (x - 1).resultant(x**5 + 1) == S(2) | ||
|
||
for k in range(-10, 10): | ||
assert x.resultant(x + S(k)) == S(k) | ||
|
||
def test_poly_resultants(): | ||
# Check that the resultant of two cyclotomic polynomials is right. | ||
# See Dresden's 2012 "Resultants of Cyclotomic Polynomials" | ||
for m in range(1, 50): | ||
for n in range(m + 1, 50): | ||
a = flint.fmpz_poly.cyclotomic(m) | ||
b = flint.fmpz_poly.cyclotomic(n) | ||
q, r = divmod(flint.fmpz(n), flint.fmpz(m)) | ||
fs = q.factor() | ||
if r != 0 or len(fs) > 1: | ||
assert a.resultant(b) == 1 | ||
else: | ||
prime = fs[0][0] | ||
tot = flint.fmpz(m).euler_phi() | ||
assert a.resultant(b) == prime**tot | ||
|
||
def _all_mpolys(): | ||
return [ | ||
|
@@ -2869,7 +2905,6 @@ def _all_mpolys(): | |
), | ||
] | ||
|
||
|
||
def test_mpolys(): | ||
for P, get_context, S, is_field, characteristic in _all_mpolys(): | ||
|
||
|
@@ -4832,6 +4867,8 @@ def test_all_tests(): | |
test_polys, | ||
test_mpolys, | ||
|
||
test_poly_resultants, | ||
|
||
test_fmpz_mpoly_vec, | ||
|
||
test_matrices_eq, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you want to record a different name here.