/
ResidueField.jl
285 lines (249 loc) · 9.26 KB
/
ResidueField.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
################################################################################
#
# Residue field construction for arbitrary prime ideals
#
################################################################################
# Assume that m is a surjective morphism pi: O -> A, where A is a simple algebra
# over the prime field Z/pZ.
# This functions returns - a in O, such that pi(a) is a primitive element
# - f in Z[X], such that f is the minimal polynomial of
# pi(a)
# - a vector of ZZMatrix B, such that
# pi(basis(O)[i]) = sum_j B[i][1, j] * pi(a)^j
function compute_residue_field_data(m)
O = domain(m)
basisO = basis(O, copy = false)
B = codomain(m)
primB, minprimB, getcoordpowerbasis = _as_field(B)
f = degree(minprimB)
prim_elem = m\(primB)
min_poly_prim_elem = ZZPolyRingElem(ZZRingElem[lift(ZZ, coeff(minprimB, i)) for i in 0:degree(minprimB)])
min_poly_prim_elem.parent = ZZPolyRing(FlintZZ, :$, false)
basis_in_prim = Vector{ZZMatrix}(undef, degree(O))
for i in 1:degree(O)
basis_in_prim[i] = zero_matrix(FlintZZ, 1, f)
t = getcoordpowerbasis(m(basisO[i]))
for j in 1:f
basis_in_prim[i][1, j] = lift(ZZ, t[1, j])
end
end
return prim_elem, min_poly_prim_elem, basis_in_prim
end
# Compute the residue field data and store it in the prime P given the map m
function compute_residue_field_data!(P, m)
P.prim_elem, P.min_poly_prim_elem, P.basis_in_prim = compute_residue_field_data(m)
return nothing
end
# Compute the residue field data given the prime P
function compute_residue_field_data!(P)
p = minimum(P)
if fits(Int, p)
smallp = Int(p)
A, m = StructureConstantAlgebra(order(P), P, smallp)
compute_residue_field_data!(P, m)
else
AA, mm = StructureConstantAlgebra(order(P), P, p)
compute_residue_field_data!(P, mm)
end
return nothing
end
# Get the residue field data. This is the function one should use, since the
# data is often cached.
function get_residue_field_data(P)
if isdefined(P, :prim_elem)
return P.prim_elem, P.min_poly_prim_elem, P.basis_in_prim
else
compute_residue_field_data!(P)
get_residue_field_data(P)
end
end
################################################################################
#
# Residue field construction for nonindex divisors
#
################################################################################
function _residue_field_nonindex_divisor_helper_fq_default(f::QQPolyRingElem, g::QQPolyRingElem, p)
R = finite_field(p, 1, :o, cached = false, check = false)[1]
Zy, y = polynomial_ring(ZZ, "y", cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
gmodp = Rx(g)
fmodp = Rx(f)
h = gcd(gmodp, fmodp)
return Nemo._residue_field(h, check = false)[1], h
end
# It is assumed that p is not an index divisor
function _residue_field_nonindex_divisor_helper(f::QQPolyRingElem, g::QQPolyRingElem, p, ::Val{degree_one} = Val(false)) where degree_one
R = Native.GF(p, cached = false, check = false)
Zy, y = polynomial_ring(FlintZZ, "y", cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
gmodp = Rx(g)
fmodp = Rx(f)
h = gcd(gmodp,fmodp)
if degree_one
return R, h
else
if isa(p, Int)
F3 = fqPolyRepField(h, :$, false)
return F3, h
elseif isa(p, ZZRingElem)
F4 = FqPolyRepField(h, :$, false)
return F4, h
end
end
end
function _residue_field_nonindex_divisor_fq_default(O, P)
@assert has_2_elem(P) && is_prime_known(P) && is_prime(P)
gtwo = P.gen_two
f = nf(O).pol
g = parent(f)(elem_in_nf(gtwo))
F, h = _residue_field_nonindex_divisor_helper_fq_default(f, g, minimum(P))
mF = Mor(O, F, h)
mF.P = P
end
function _residue_field_nonindex_divisor(O, P, ::Val{small} = Val(false), degree_one_val::Val{degree_one} = Val(false)) where {small, degree_one}
# This code assumes that P comes from prime_decomposition
@assert has_2_elem(P) && is_prime_known(P) && is_prime(P)
gtwo = P.gen_two
f = nf(O).pol
g = parent(f)(elem_in_nf(gtwo))
if small
@assert fits(Int, minimum(P, copy = false))
F, h = _residue_field_nonindex_divisor_helper(f, g, Int(minimum(P)), degree_one_val)
mF = Mor(O, F, h)
mF.P = P
return F, mF
else
F, h = _residue_field_nonindex_divisor_helper_fq_default(f, g, minimum(P))
mF = Mor(O, F, h)
mF.P = P
return F, mF
#F, h = _residue_field_nonindex_divisor_helper(f, g, minimum(P), degree_one_val)
#mF = Mor(O, F, h)
#mF.P = P
#return F, mF
end
end
################################################################################
#
# Residue field construction for index divisors
#
################################################################################
function _residue_field_generic_fq_default(O, P)
f = NfOrdToFqFieldMor(O, P)
return codomain(f), f
end
function _residue_field_generic(O, P, ::Val{small} = Val(false), ::Val{degree_one} = Val(false)) where {small, degree_one}
if small
@assert fits(Int, minimum(P, copy = false))
if degree_one
f1 = NfOrdToGFMor(O, P)
return codomain(f1), f1
else
f = NfOrdToFqNmodMor(O, P)
return codomain(f), f
end
else
if degree_one
f3 = NfOrdToGFFmpzMor(O, P)
return codomain(f3), f3
else
f2 = NfOrdToFqMor(O, P)
return codomain(f2), f2
end
end
end
################################################################################
#
# High level functions
#
################################################################################
@doc raw"""
residue_field(O::AbsSimpleNumFieldOrder, P::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}, check::Bool = true) -> Field, Map
Returns the residue field of the prime ideal $P$ together with the
projection map. If ```check``` is true, the ideal is checked for
being prime.
"""
function residue_field(O::AbsSimpleNumFieldOrder, P::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}, check::Bool = true)
if check
!is_prime(P) && error("Ideal must be prime")
end
if !is_maximal_known(O) || !is_maximal(O) || !is_defining_polynomial_nice(nf(O))
return _residue_field_generic_fq_default(O, P)
end
if !is_index_divisor(O, minimum(P)) && has_2_elem(P)
return _residue_field_nonindex_divisor(O, P)
else
return _residue_field_generic_fq_default(O, P)
end
end
function ResidueFieldSmall(O::AbsSimpleNumFieldOrder, P::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem})
p = minimum(P)
!fits(Int, p) && error("Minimum of prime ideal must be small (< 64 bits)")
if !is_maximal_known(O) || !is_maximal(O) || !is_defining_polynomial_nice(nf(O))
return _residue_field_generic(O, P, Val(true))
end
if !is_index_divisor(O, minimum(P))
return _residue_field_nonindex_divisor(O, P, Val(true))
else
return _residue_field_generic(O, P, Val(true))
end
end
function ResidueFieldDegree1(O::AbsSimpleNumFieldOrder, P::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem})
@assert degree(P) == 1
if !is_maximal_known(O) || !is_maximal(O)
return _residue_field_generic(O, P, Val(false), Val(true))
end
if !is_index_divisor(O, minimum(P)) && has_2_elem(P)
return _residue_field_nonindex_divisor(O, P, Val(false), Val(true))
else
return _residue_field_generic(O, P, Val(false), Val(true))
end
end
function ResidueFieldSmallDegree1(O::AbsSimpleNumFieldOrder, P::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem})
p = minimum(P)
!fits(Int, p) && error("Minimum of prime ideal must be small (< 64 bits)")
@assert degree(P) == 1
if !is_maximal_known(O) || !is_maximal(O) || !is_defining_polynomial_nice(nf(O))
return _residue_field_generic(O, P, Val(true), Val(true))
end
if !is_index_divisor(O, minimum(P))
return _residue_field_nonindex_divisor(O, P, Val(true), Val(true))
else
return _residue_field_generic(O, P, Val(true), Val(true))
end
end
@doc raw"""
relative_residue_field(O::RelNumFieldOrder, P::RelNumFieldOrderIdeal) -> RelFinField, Map
Given a maximal order `O` in a relative number field $E/K$ and a prime ideal
`P` of `O`, return the residue field $O/P$ seen as an extension of the (relative)
residue field of a maximal order in `K` at $minimum(P)$.
Note that if `K` is a relative number field, the latter will also be seen as a
relative residue field.
"""
function relative_residue_field(O::RelNumFieldOrder{S, T, U}, P::RelNumFieldOrderIdeal{S, T, U}) where {S, T, U}
@req is_maximal(O) "O must be maximal"
@req order(P) === O "P must be an ideal of O"
E = nf(O)
K = base_field(E)
p = minimum(P)
projK = get_attribute(p, :rel_residue_field_map)
if projK === nothing
OK = maximal_order(K)
if !(K isa Hecke.RelSimpleNumField)
_, projK = residue_field(OK, p)
set_attribute!(p, :rel_residue_field_map, projK)
else
_, projK = relative_residue_field(OK, p)
set_attribute!(p, :rel_residue_field_map, projK)
end
end
FK = codomain(projK)
projE = NfRelOrdToFqFieldRelMor{typeof(O)}(O, P, projK)
#if base_field(K) isa QQField
# projE = NfRelOrdToRelFinFieldMor{typeof(O), FqFieldElem}(O, P, projK)
#else
# projE = NfRelOrdToRelFinFieldMor{typeof(O), Hecke.RelFinFieldElem{typeof(FK), typeof(FK.defining_polynomial)}}(O, P, projK)
#end
set_attribute!(P, :rel_residue_field_map, projE)
return codomain(projE), projE
end