Skip to content

Commit 381df60

Browse files
committed
add DomainError for real_roots and complex_roots for positive characteristic univariate polys
1 parent 464a276 commit 381df60

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

Diff for: src/flint/flint_base/flint_base.pyx

+3
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ cdef class flint_poly(flint_elem):
254254
roots.append((v, m))
255255
return roots
256256

257+
def real_roots(self):
258+
raise AttributeError("Complex roots are not supported for this polynomial")
259+
257260
def complex_roots(self):
258261
raise AttributeError("Complex roots are not supported for this polynomial")
259262

Diff for: src/flint/test/test_all.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,9 @@ def set_bad2():
14651465
assert P([1], 11).roots() == []
14661466
assert P([1, 2, 3], 11).roots() == [(8, 1), (6, 1)]
14671467
assert P([1, 6, 1, 8], 11).roots() == [(5, 3)]
1468+
assert raises(lambda: P([1, 2, 3], 11).real_roots(), DomainError)
1469+
assert raises(lambda: P([1, 2, 3], 11).complex_roots(), DomainError)
1470+
14681471

14691472
def test_nmod_mat():
14701473
M = flint.nmod_mat
@@ -2226,12 +2229,15 @@ def test_fmpz_mod_poly():
22262229
assert set(ff.factor()[1]) == set(ff.factor(algorithm="kaltofen_shoup")[1])
22272230
assert set(ff.factor()[1]) == set(ff.factor(algorithm="berlekamp")[1])
22282231
assert raises(lambda: R_test([0,0,1]).factor(algorithm="AAA"), ValueError)
2232+
assert raises(lambda: R_test([0,0,1]).real_roots(), DomainError)
22292233
assert raises(lambda: R_test([0,0,1]).complex_roots(), DomainError)
22302234

2235+
22312236
# composite moduli not supported
22322237
assert raises(lambda: R_cmp([0,0,1]).factor(), NotImplementedError)
22332238
assert raises(lambda: R_cmp([0,0,1]).factor_squarefree(), NotImplementedError)
22342239
assert raises(lambda: R_cmp([0,0,1]).roots(), NotImplementedError)
2240+
assert raises(lambda: R_cmp([0,0,1]).real_roots(), DomainError)
22352241
assert raises(lambda: R_cmp([0,0,1]).complex_roots(), DomainError)
22362242

22372243
# minpoly
@@ -4020,7 +4026,6 @@ def test_fq_default_poly():
40204026
assert raises(lambda: f / "AAA", TypeError)
40214027
assert raises(lambda: "AAA" / f, TypeError)
40224028

4023-
40244029
# ZeroDivisionError
40254030
assert raises(lambda: f / 0, ZeroDivisionError)
40264031
assert raises(lambda: f // 0, ZeroDivisionError)
@@ -4053,6 +4058,9 @@ def test_fq_default_poly():
40534058
# pow_mod
40544059
assert f.pow_mod(2, g) == (f*f) % g
40554060
assert raises(lambda: f.pow_mod(2, "AAA"), TypeError)
4061+
4062+
# roots
4063+
assert raises(lambda: f.real_roots(), DomainError)
40564064
assert raises(lambda: f.complex_roots(), DomainError)
40574065

40584066
# compose errors

Diff for: src/flint/types/fmpz_mod_poly.pyx

+7
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,13 @@ cdef class fmpz_mod_poly(flint_poly):
18641864
res[i] = root
18651865
return res
18661866

1867+
def real_roots(self):
1868+
"""
1869+
This method is not implemented for polynomials in
1870+
:math:`(\mathbb{Z}/N\mathbb{Z})[X]`
1871+
"""
1872+
raise DomainError("Cannot compute real roots for polynomials over integers modulo N")
1873+
18671874
def complex_roots(self):
18681875
"""
18691876
This method is not implemented for polynomials in

Diff for: src/flint/types/fq_default_poly.pyx

+6
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,12 @@ cdef class fq_default_poly(flint_poly):
15881588
res[i] = root
15891589
return res
15901590

1591+
def real_roots(self):
1592+
"""
1593+
This method is not implemented for polynomials in finite fields
1594+
"""
1595+
raise DomainError("Cannot compute real roots for polynomials over finite fields")
1596+
15911597
def complex_roots(self):
15921598
"""
15931599
This method is not implemented for polynomials in finite fields

Diff for: src/flint/types/nmod_poly.pyx

+14
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,17 @@ cdef class nmod_poly(flint_poly):
668668
nmod_poly_init(v.val, self.val.mod.n)
669669
nmod_poly_deflate(v.val, self.val, n)
670670
return v, int(n)
671+
672+
def real_roots(self):
673+
"""
674+
This method is not implemented for polynomials in
675+
:math:`(\mathbb{Z}/N\mathbb{Z})[X]`
676+
"""
677+
raise DomainError("Cannot compute real roots for polynomials over integers modulo N")
678+
679+
def complex_roots(self):
680+
"""
681+
This method is not implemented for polynomials in
682+
:math:`(\mathbb{Z}/N\mathbb{Z})[X]`
683+
"""
684+
raise DomainError("Cannot compute complex roots for polynomials over integers modulo N")

0 commit comments

Comments
 (0)