# Ticket #9466: 9466.2.patch

File 9466.2.patch, 3.9 KB (added by mstreng, 8 years ago)
• ## sage/rings/finite_rings/element_givaro.pyx

```# HG changeset patch
# User Marco Streng <marco.streng@gmail.com>
# Date 1374775673 -3600
# Node ID bcfe7162d96865647a260ec14450339d531b11b4
# Parent  5d8c13e7b81a1e152855073f97a4d48ee97255d1
9466 all square roots of non-square elements

diff --git a/sage/rings/finite_rings/element_givaro.pyx b/sage/rings/finite_rings/element_givaro.pyx```
 a sage: K = GF(8, 'a') sage: all([a.sqrt()*a.sqrt() == a for a in K if a.is_square()]) True sage: K.=FiniteField(9) sage: a.sqrt(extend = False, all = True) [] """ if all: a = self.sqrt() return [a, -a] if -a != a else [a] if self.is_square(): a = self.sqrt() return [a, -a] if -a != a else [a] return [] cdef Cache_givaro cache = self._cache if self.element == cache.objectptr.one: return make_FiniteField_givaroElement(cache, cache.objectptr.one)
• ## sage/rings/finite_rings/integer_mod.pyx

`diff --git a/sage/rings/finite_rings/integer_mod.pyx b/sage/rings/finite_rings/integer_mod.pyx`
 a 9 sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) 25 Finding all square roots works in some cases:: sage: t = FiniteField(next_prime(2^100))(4) sage: t.sqrt(extend = False, all = True) [2, 1267650600228229401496703205651] sage: t = FiniteField(next_prime(2^100))(2) sage: t.sqrt(extend = False, all = True) [] sage: mod(4, 75).sqrt(all=True) Traceback (most recent call last): ... NotImplementedError: all=True not yet implemented for finding roots modulo non-prime integers :: z = Q.gen() if all: # TODO raise NotImplementedError raise NotImplementedError, "all=True not yet implemented " \ "for finding roots modulo integers" return z if all: return [] raise ValueError, "self must be a square" F = self._parent.factored_order() if (i*i) % n == self.ivalue: return self._new_c(i) if not extend: raise ValueError, "self must be a square" if not all: raise ValueError, "self must be a square" else: return [] # Either it failed but extend was True, or the generic algorithm is better return IntegerMod_abstract.sqrt(self, extend=extend, all=all)
• ## sage/rings/integer.pyx

`diff --git a/sage/rings/integer.pyx b/sage/rings/integer.pyx`
 a sage: type(Integer(-5).sqrt(prec=53)) TESTS: Check that :trac:`9466` is fixed:: sage: 3.sqrt(extend=False, all=True) [] """ if mpz_sgn(self.value) == 0: return [self] if all else self if non_square: if not extend: raise ValueError, "square root of %s not an integer"%self if not all: raise ValueError, "square root of %s not an integer"%self else: return [] from sage.functions.other import _do_sqrt return _do_sqrt(self, prec=prec, all=all)