Skip to content

Commit 9a0327f

Browse files
Merge pull request #199 from GiacomoPope/real_complex_root
Add DomainError positive char univariate polynomial rings
2 parents 53a1c3f + 4cb404f commit 9a0327f

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

src/flint/flint_base/flint_base.pyx

+4-1
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,11 @@ cdef class flint_poly(flint_elem):
258258
roots.append((v, m))
259259
return roots
260260

261+
def real_roots(self):
262+
raise NotImplementedError("Real roots are not supported for this polynomial")
263+
261264
def complex_roots(self):
262-
raise AttributeError("Complex roots are not supported for this polynomial")
265+
raise NotImplementedError("Complex roots are not supported for this polynomial")
263266

264267

265268
cdef class flint_mpoly_context(flint_elem):

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(), DomainError)
22332238
assert raises(lambda: R_cmp([0,0,1]).factor_squarefree(), DomainError)
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
@@ -4318,7 +4324,6 @@ def test_fq_default_poly():
43184324
assert raises(lambda: f / "AAA", TypeError)
43194325
assert raises(lambda: "AAA" / f, TypeError)
43204326

4321-
43224327
# ZeroDivisionError
43234328
assert raises(lambda: f / 0, ZeroDivisionError)
43244329
assert raises(lambda: f // 0, ZeroDivisionError)
@@ -4351,6 +4356,9 @@ def test_fq_default_poly():
43514356
# pow_mod
43524357
assert f.pow_mod(2, g) == (f*f) % g
43534358
assert raises(lambda: f.pow_mod(2, "AAA"), TypeError)
4359+
4360+
# roots
4361+
assert raises(lambda: f.real_roots(), DomainError)
43544362
assert raises(lambda: f.complex_roots(), DomainError)
43554363

43564364
# compose errors

src/flint/types/fmpz_mod_poly.pyx

+7
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,13 @@ cdef class fmpz_mod_poly(flint_poly):
18841884
res[i] = root
18851885
return res
18861886

1887+
def real_roots(self):
1888+
"""
1889+
This method is not implemented for polynomials in
1890+
:math:`(\mathbb{Z}/N\mathbb{Z})[X]`
1891+
"""
1892+
raise DomainError("Cannot compute real roots for polynomials over integers modulo N")
1893+
18871894
def complex_roots(self):
18881895
"""
18891896
This method is not implemented for polynomials in

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

src/flint/types/nmod_poly.pyx

+14
Original file line numberDiff line numberDiff line change
@@ -715,3 +715,17 @@ cdef class nmod_poly(flint_poly):
715715
nmod_poly_init(v.val, self.val.mod.n)
716716
nmod_poly_deflate(v.val, self.val, n)
717717
return v, int(n)
718+
719+
def real_roots(self):
720+
"""
721+
This method is not implemented for polynomials in
722+
:math:`(\mathbb{Z}/N\mathbb{Z})[X]`
723+
"""
724+
raise DomainError("Cannot compute real roots for polynomials over integers modulo N")
725+
726+
def complex_roots(self):
727+
"""
728+
This method is not implemented for polynomials in
729+
:math:`(\mathbb{Z}/N\mathbb{Z})[X]`
730+
"""
731+
raise DomainError("Cannot compute complex roots for polynomials over integers modulo N")

0 commit comments

Comments
 (0)