diff --git a/src/flint/flint_base/flint_base.pyx b/src/flint/flint_base/flint_base.pyx index e93e69ba..7c3c2292 100644 --- a/src/flint/flint_base/flint_base.pyx +++ b/src/flint/flint_base/flint_base.pyx @@ -258,8 +258,11 @@ cdef class flint_poly(flint_elem): roots.append((v, m)) return roots + def real_roots(self): + raise NotImplementedError("Real roots are not supported for this polynomial") + def complex_roots(self): - raise AttributeError("Complex roots are not supported for this polynomial") + raise NotImplementedError("Complex roots are not supported for this polynomial") cdef class flint_mpoly_context(flint_elem): diff --git a/src/flint/test/test_all.py b/src/flint/test/test_all.py index 60ccdc02..3a174fbe 100644 --- a/src/flint/test/test_all.py +++ b/src/flint/test/test_all.py @@ -1465,6 +1465,9 @@ def set_bad2(): assert P([1], 11).roots() == [] assert P([1, 2, 3], 11).roots() == [(8, 1), (6, 1)] assert P([1, 6, 1, 8], 11).roots() == [(5, 3)] + assert raises(lambda: P([1, 2, 3], 11).real_roots(), DomainError) + assert raises(lambda: P([1, 2, 3], 11).complex_roots(), DomainError) + def test_nmod_mat(): M = flint.nmod_mat @@ -2226,12 +2229,15 @@ def test_fmpz_mod_poly(): assert set(ff.factor()[1]) == set(ff.factor(algorithm="kaltofen_shoup")[1]) assert set(ff.factor()[1]) == set(ff.factor(algorithm="berlekamp")[1]) assert raises(lambda: R_test([0,0,1]).factor(algorithm="AAA"), ValueError) + assert raises(lambda: R_test([0,0,1]).real_roots(), DomainError) assert raises(lambda: R_test([0,0,1]).complex_roots(), DomainError) + # composite moduli not supported assert raises(lambda: R_cmp([0,0,1]).factor(), DomainError) assert raises(lambda: R_cmp([0,0,1]).factor_squarefree(), DomainError) assert raises(lambda: R_cmp([0,0,1]).roots(), NotImplementedError) + assert raises(lambda: R_cmp([0,0,1]).real_roots(), DomainError) assert raises(lambda: R_cmp([0,0,1]).complex_roots(), DomainError) # minpoly @@ -4318,7 +4324,6 @@ def test_fq_default_poly(): assert raises(lambda: f / "AAA", TypeError) assert raises(lambda: "AAA" / f, TypeError) - # ZeroDivisionError assert raises(lambda: f / 0, ZeroDivisionError) assert raises(lambda: f // 0, ZeroDivisionError) @@ -4351,6 +4356,9 @@ def test_fq_default_poly(): # pow_mod assert f.pow_mod(2, g) == (f*f) % g assert raises(lambda: f.pow_mod(2, "AAA"), TypeError) + + # roots + assert raises(lambda: f.real_roots(), DomainError) assert raises(lambda: f.complex_roots(), DomainError) # compose errors diff --git a/src/flint/types/fmpz_mod_poly.pyx b/src/flint/types/fmpz_mod_poly.pyx index ce9cba76..7d6f088e 100644 --- a/src/flint/types/fmpz_mod_poly.pyx +++ b/src/flint/types/fmpz_mod_poly.pyx @@ -1884,6 +1884,13 @@ cdef class fmpz_mod_poly(flint_poly): res[i] = root return res + def real_roots(self): + """ + This method is not implemented for polynomials in + :math:`(\mathbb{Z}/N\mathbb{Z})[X]` + """ + raise DomainError("Cannot compute real roots for polynomials over integers modulo N") + def complex_roots(self): """ This method is not implemented for polynomials in diff --git a/src/flint/types/fq_default_poly.pyx b/src/flint/types/fq_default_poly.pyx index 16fda36d..9e86c015 100644 --- a/src/flint/types/fq_default_poly.pyx +++ b/src/flint/types/fq_default_poly.pyx @@ -1588,6 +1588,12 @@ cdef class fq_default_poly(flint_poly): res[i] = root return res + def real_roots(self): + """ + This method is not implemented for polynomials in finite fields + """ + raise DomainError("Cannot compute real roots for polynomials over finite fields") + def complex_roots(self): """ This method is not implemented for polynomials in finite fields diff --git a/src/flint/types/nmod_poly.pyx b/src/flint/types/nmod_poly.pyx index aef9dfb0..d0856b20 100644 --- a/src/flint/types/nmod_poly.pyx +++ b/src/flint/types/nmod_poly.pyx @@ -715,3 +715,17 @@ cdef class nmod_poly(flint_poly): nmod_poly_init(v.val, self.val.mod.n) nmod_poly_deflate(v.val, self.val, n) return v, int(n) + + def real_roots(self): + """ + This method is not implemented for polynomials in + :math:`(\mathbb{Z}/N\mathbb{Z})[X]` + """ + raise DomainError("Cannot compute real roots for polynomials over integers modulo N") + + def complex_roots(self): + """ + This method is not implemented for polynomials in + :math:`(\mathbb{Z}/N\mathbb{Z})[X]` + """ + raise DomainError("Cannot compute complex roots for polynomials over integers modulo N")