79 p = a.parent().characteristic()
86 exponent1 = (q - 9) // 16
87 exponent2 = (q - 9) // 8
88 b =
l2r(2 * a, exponent1)
93 constant3 =
l2r(root2_squared, exponent2)
95 c = 2 * u**2 * root2_squared**2 * a
96 s1 = u * root2_squared * a * (c - 1)
97 return (ZZ(1 - r) >> 1) * s0 + (ZZ(1 + r) >> 1) * s1
138 p = previous_prime(2**bits)
139 while (p % 4 != 3)
or (p**2 % 16 != 9) or( (p**2 - 1) % 9 == 0):
140 p = previous_prime(p)
146 print(
'\n+++++++ Setup')
147 print(f
'p: {hex(p)}')
148 print(f
'p % 4 = {p % 4}')
149 print(f
'p % 3 = {p % 3}\n')
150 f = {2:
'(p + 1)', 1:
'(p - 1)'}[p % 3]
151 g = {1:
'(p + 1)', 2:
'(p - 1)'}[p % 3]
152 print(f
'In particular, 3 divides {f} but not {g}\n')
156 Rx = PolynomialRing(Fp, name=
"x")
160 Fq = Fp.extension(X**2 + 1,
'i')
163 Rx = PolynomialRing(Fq, name=
"x")
166 rootq2_squared = rootq
170 def sqrt_fq(input, check=True):
171 return sqrt_fp2(input, rootq2_squared, check=check)
175 r3 = ZZ(3).inverse_mod(N3)
179 zeta3 = (-1 + sqrt_fq(Fq(-3))) / Fq(2)