# Ticket #12173: sqrt_normalization_fix.patch

File sqrt_normalization_fix.patch, 1.7 KB (added by Jean-Pierre Flori, 10 years ago)

Fredrik's patch for sqrt normalization

• ## sage/rings/fraction_field_FpT.pyx

```# HG changeset patch
# User Fredrik Johansson
# Date 1338990348 -7200
# Node ID 9ee606715e2b619c6ea5e175fcff595692bc194b
# Parent  3c8a4bd85ae10a56ea140512af874e0100bfb563
#12173: Fix normalization of sqrt for fraction field elements

diff --git a/sage/rings/fraction_field_FpT.pyx b/sage/rings/fraction_field_FpT.pyx```
 a return self cdef nmod_poly_t numer cdef nmod_poly_t denom cdef long a cdef FpTElement res nmod_poly_init(denom, self.p) nmod_poly_init(numer, self.p) if nmod_poly_sqrt(numer, self._numer) and nmod_poly_sqrt(denom, self._denom): # Make denominator monic a = nmod_poly_leading(denom) if a != 1: a = mod_inverse_int(a, self.p) nmod_poly_scalar_mul_nmod(numer, numer, a) nmod_poly_scalar_mul_nmod(denom, denom, a) # Choose numerator with smaller leading coefficient a = nmod_poly_leading(numer) if a > self.p - a: nmod_poly_neg(numer, numer) res = self._new_c() nmod_poly_swap(numer, res._numer) nmod_poly_swap(denom, res._denom) sage: from sage.rings.fraction_field_FpT import * sage: K = GF(7)['t'].fraction_field(); t = K.gen(0) sage: ((t + 2)^2/(3*t^3 + 1)^4).sqrt() sage: p = (t + 2)^2/(3*t^3 + 1)^4 sage: p.sqrt() (3*t + 6)/(t^6 + 3*t^3 + 4) sage: p.sqrt()^2 == p True """ s = self._sqrt_or_None() if s is None: