Skip to content

Commit

Permalink
Merge pull request #199 from GiacomoPope/real_complex_root
Browse files Browse the repository at this point in the history
Add DomainError positive char univariate polynomial rings
  • Loading branch information
oscarbenjamin authored Aug 27, 2024
2 parents 53a1c3f + 4cb404f commit 9a0327f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
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 @@ -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):
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(), 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
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 @@ -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
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 @@ -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")

0 comments on commit 9a0327f

Please sign in to comment.