diff --git a/src/flint/flint_base/flint_base.pyx b/src/flint/flint_base/flint_base.pyx index e0b02fcf..dc93d250 100644 --- a/src/flint/flint_base/flint_base.pyx +++ b/src/flint/flint_base/flint_base.pyx @@ -254,8 +254,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 783a4084..403625c0 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(), NotImplementedError) assert raises(lambda: R_cmp([0,0,1]).factor_squarefree(), NotImplementedError) 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 @@ -4020,7 +4026,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) @@ -4053,6 +4058,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 328600de..3a421f08 100644 --- a/src/flint/types/fmpz_mod_poly.pyx +++ b/src/flint/types/fmpz_mod_poly.pyx @@ -1864,6 +1864,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 1ee8aabf..7e0184ba 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 65f11666..0b37be16 100644 --- a/src/flint/types/nmod_poly.pyx +++ b/src/flint/types/nmod_poly.pyx @@ -668,3 +668,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")