Skip to content
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

Add DomainError positive char univariate polynomial rings #199

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/flint/flint_base/flint_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 9 additions & 1 deletion src/flint/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/flint/types/fmpz_mod_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/flint/types/fq_default_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/flint/types/nmod_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Loading