# 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

b


688  688  return self 
689  689  cdef nmod_poly_t numer 
690  690  cdef nmod_poly_t denom 
 691  cdef long a 
691  692  cdef FpTElement res 
692  693  
693  694  nmod_poly_init(denom, self.p) 
694  695  nmod_poly_init(numer, self.p) 
695  696  
696  697  if nmod_poly_sqrt(numer, self._numer) and nmod_poly_sqrt(denom, self._denom): 
 698  # Make denominator monic 
 699  a = nmod_poly_leading(denom) 
 700  if a != 1: 
 701  a = mod_inverse_int(a, self.p) 
 702  nmod_poly_scalar_mul_nmod(numer, numer, a) 
 703  nmod_poly_scalar_mul_nmod(denom, denom, a) 
 704  # Choose numerator with smaller leading coefficient 
 705  a = nmod_poly_leading(numer) 
 706  if a > self.p  a: 
 707  nmod_poly_neg(numer, numer) 
697  708  res = self._new_c() 
698  709  nmod_poly_swap(numer, res._numer) 
699  710  nmod_poly_swap(denom, res._denom) 
… 
… 

736  747  
737  748  sage: from sage.rings.fraction_field_FpT import * 
738  749  sage: K = GF(7)['t'].fraction_field(); t = K.gen(0) 
739   sage: ((t + 2)^2/(3*t^3 + 1)^4).sqrt() 
 750  sage: p = (t + 2)^2/(3*t^3 + 1)^4 
 751  sage: p.sqrt() 
740  752  (3*t + 6)/(t^6 + 3*t^3 + 4) 
 753  sage: p.sqrt()^2 == p 
 754  True 
 755  
741  756  """ 
742  757  s = self._sqrt_or_None() 
743  758  if s is None: 