@@ -1179,40 +1179,47 @@ cdef class fq_default_poly(flint_poly):
11791179 """
11801180 cdef fq_default_poly res
11811181
1182- # FLINT requires the constant term is one
1183- if not self .constant_coefficient().is_one():
1184- raise ValueError (" constant coefficient of the polynomial must be one" )
1182+ # FLINT requires the constant term is one, so we need to normalise
1183+ c = self .constant_coefficient()
1184+ if not c.is_square():
1185+ raise ValueError (" constant coefficient of the polynomial must be a square" )
1186+ self = self / c
11851187
11861188 res = self .ctx.new_ctype_poly()
11871189 fq_default_poly_sqrt_series(
11881190 res.val, self .val, n, res.ctx.field.val
11891191 )
1190- return res
1192+ return res * c.sqrt()
11911193
11921194 def inv_sqrt_trunc (self , slong n ):
11931195 """
11941196 Returns the inverse of the square root of ``self`` modulo `x^n`.
11951197
11961198 Requires that the constant coefficient of the polynomial is one.
11971199
1198- >>> R = fq_default_poly_ctx(163, 3 )
1200+ >>> R = fq_default_poly_ctx(65537, 2 )
11991201 >>> x = R.gen()
12001202 >>> z = R.base_field().gen()
1201- >>> f = (37*z + 54)*x**3 + (8*z + 94)*x**2 + (52*z + 142)*x + 1
1202- >>> f.sqrt_trunc(5)
1203- (60*z^2 + 17*z + 158)*x^4 + (7*z^2 + 17*z + 148)*x^3 + (151*z^2 + 114*z + 53)*x^2 + (26*z + 71)*x + 1
1203+ >>> f = 28902*x**3 + (49416*z + 58229)*x**2 + 9441*z*x + (7944*z + 57534)
1204+ >>> h = f.inv_sqrt_trunc(3)
1205+ >>> h
1206+ (23030*z + 8965)*x^2 + (43656*z + 7173)*x + (27935*z + 28199)
1207+ >>> (h*h).mul_low(f, 3).is_one()
1208+ True
12041209 """
12051210 cdef fq_default_poly res
12061211
1207- # FLINT requires the constant term is one
1208- if not self .constant_coefficient().is_one():
1209- raise ValueError (" constant coefficient of the polynomial must be one" )
1212+ # FLINT requires the constant term is one, so we need to normalise
1213+ c = self .constant_coefficient()
1214+ if not c.is_square():
1215+ raise ValueError (" constant coefficient of the polynomial must be a square" )
1216+ self = self / c
12101217
12111218 res = self .ctx.new_ctype_poly()
12121219 fq_default_poly_invsqrt_series(
12131220 res.val, self .val, n, res.ctx.field.val
12141221 )
1215- return res
1222+ return res / c.sqrt()
12161223
12171224 def inverse_series_trunc (self , slong n ):
12181225 """
@@ -1228,6 +1235,9 @@ cdef class fq_default_poly(flint_poly):
12281235 (96*z^2 + 90*z + 21)*x^2 + (111*z + 21)*x + 1
12291236 >>> f.inverse_series_trunc(4)
12301237 (34*z^2 + z + 2)*x^3 + (96*z^2 + 90*z + 21)*x^2 + (111*z + 21)*x + 1
1238+ >>> h = f.inverse_series_trunc(4)
1239+ >>> f.mul_low(h, 4).is_one()
1240+ True
12311241 """
12321242 cdef fmpz_t f
12331243 cdef fq_default_poly res
0 commit comments