# Ticket #7931: 7931_fix3.patch

File 7931_fix3.patch, 4.8 KB (added by roed, 9 years ago)

Apply on top of previous patches

• ## sage/rings/finite_rings/element_base.pyx

```# HG changeset patch
# User David Roe <roed@math.harvard.edu>
# Date 1285943222 14400
# Node ID 5eb432d59dc6f2cf6296a8729b25ee895e0d8ded
# Parent  74423238ccd88ebd93604185c5d82d3d2cf285af
[mq]: 7931_fix3.patch

diff -r 74423238ccd8 -r 5eb432d59dc6 sage/rings/finite_rings/element_base.pyx```
 a ...               if (y^41).nth_root(41*r)**(41*r) != y^41: raise RuntimeError ...               if (y^307).nth_root(307*r)**(307*r) != y^307: raise RuntimeError sage: k. = GF(4) sage: a.nth_root(0,all=True) [] sage: k(1).nth_root(0,all=True) [a, a + 1, 1] ALGORITHMS: - The default is currently an algorithm described in the following paper: - David Roe (2010-02-13) """ if self.is_zero(): if n < 0: raise ZeroDivisionError if n <= 0: if all: return [] else: raise ValueError if all: return [self] else: return self if n < 0: self = ~self n = -n elif n == 0: if self == 1: if all: return [a for a in self.parent().list() if a != 0] else: return self else: if all: return [] else: raise ValueError if extend: raise NotImplementedError from sage.rings.integer import Integer
• ## sage/rings/finite_rings/integer_mod.pyx

`diff -r 74423238ccd8 -r 5eb432d59dc6 sage/rings/finite_rings/integer_mod.pyx`
 a .. warning:: The 'extend' option is not implemented (yet). NOTES: - If `n = 0` - ``all=True`` - ``self=1``; all nonzero elements of the parent are returned in a list. Note that this could be very expensive for large parents. - otherwise; an empty list is returned - ``all=False`` - ``self=1``; ``self`` is returned - otherwise; a ``ValueError`` is raised - If `n < 0` - if self is invertible, the `(-n)`\th root of the inverse of self is returned - otherwise a ValueError is raised or empty list returned. EXAMPLES:: sage: mod(3,6).nth_root(0) Traceback (most recent call last): ... ZeroDivisionError ValueError sage: mod(1,6).nth_root(0,all=True) [1, 2, 3, 4, 5] TESTS:: sage: for p in [1009,2003,10007,100003]: # long time sage: for p in [1009,2003,10007,100003]: ...       K = GF(p) ...       for r in (p-1).divisors(): ...           if r == 1: continue ...           if (y^41).nth_root(41*r)**(41*r) != y^41: raise RuntimeError ...           if (y^307).nth_root(307*r)**(307*r) != y^307: raise RuntimeError sage: for t in xrange(200): ...       n = randint(1,2^63) ...       K = Integers(n) ...       b = K.random_element() ...       e = randint(-2^62, 2^63) ...       try: ...           a = b.nth_root(e) ...           if a^e != b: ...               print n, b, e, a ...               raise NotImplementedError ...       except ValueError: ...           pass ALGORITHMS: - The default for prime modulus is currently an algorithm described in the following paper: else: return self else: if all: return [] else: raise ZeroDivisionError else: raise ValueError F = K.factored_order() if len(F) == 0: if all: if self.is_zero(): if n < 0: if all: return [] else: raise ZeroDivisionError else: raise ValueError if all: if k == 1: return [self] else: return self if n < 0: self = ~self try: self = ~self except ZeroDivisionError: if all: return [] else: raise ValueError n = -n if p == 2 and k == 1: if all: return [self]