Skip to content

Commit

Permalink
Change residue_field for local fields
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Nov 2, 2023
1 parent 159ba41 commit 0324987
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LazyArtifacts = "1.6"
Libdl = "1.6"
LinearAlgebra = "1.6"
Markdown = "1.6"
Nemo = "^0.37.0"
Nemo = "^0.37.3"
Pkg = "1.6"
Polymake = "0.10, 0.11"
Printf = "1.6"
Expand Down
5 changes: 3 additions & 2 deletions src/LocalField/Completions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ function completion(K::AnticNumberField, P::NfOrdIdl, precision::Int = 64)
Qq, gQq = QadicField(minimum(P), f, prec_padics, cached = false)
Qqx, gQqx = polynomial_ring(Qq, "x")
q, mq = residue_field(Qq)
F, mF = ResidueFieldSmall(OK, P)
#F, mF = ResidueFieldSmall(OK, P)
F, mF = residue_field(OK, P)
mp = find_morphism(q, F)
g = gen(q)
gq_in_K = (mF\(mp(g))).elem_in_nf
Expand Down Expand Up @@ -444,7 +445,7 @@ function unramified_completion(K::AnticNumberField, P::NfOrdIdl, precision::Int
Qp = PadicField(p, precision)
Zp = maximal_order(Qp)
q, mq = residue_field(Qq)
F, mF = ResidueFieldSmall(OK, P)
F, mF = residue_field(OK, P)
mp = find_morphism(q, F)
g = gen(q)
gq_in_K = (mF\(mp(g))).elem_in_nf
Expand Down
10 changes: 5 additions & 5 deletions src/LocalField/Conjugates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,21 +558,21 @@ function completion(K::AnticNumberField, ca::qadic)
while length(pa) < d
push!(pa, pa[end]*pa[2])
end
m = matrix(Native.GF(p), d, d, [coeff(pa[i], j-1) for j=1:d for i=1:d])
o = matrix(Native.GF(p), d, 1, [coeff(gen(R), j-1) for j=1:d])
m = matrix(Nemo._GF(p), d, d, [lift(ZZ, coeff(pa[i], j-1)) for j=1:d for i=1:d])
o = matrix(Nemo._GF(p), d, 1, [lift(ZZ, coeff(gen(R), j-1)) for j=1:d])
s = solve(m, o)
@hassert :qAdic 1 m*s == o
a = K()
for i=1:d
_num_setcoeff!(a, i-1, lift(s[i,1]))
_num_setcoeff!(a, i-1, lift(ZZ, s[i, 1]))
end
f = defining_polynomial(parent(ca), FlintZZ)
fso = inv(derivative(f)(gen(R)))
o = matrix(Native.GF(p), d, 1, [coeff(fso, j-1) for j=1:d])
o = matrix(Nemo._GF(p), d, 1, [lift(ZZ, coeff(fso, j-1)) for j=1:d])
s = solve(m, o)
b = K()
for i=1:d
_num_setcoeff!(b, i-1, lift(s[i,1]))
_num_setcoeff!(b, i-1, lift(ZZ, s[i,1]))
end

#TODO: don't use f, use the factors i the HenselCtx
Expand Down
7 changes: 4 additions & 3 deletions src/LocalField/LocalField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ function residue_field(K::LocalField{S, UnramifiedLocalField}) where {S <: Field
Fpt = polynomial_ring(ks, cached = false)[1]
g = defining_polynomial(K)
f = Fpt([ks(mks(coeff(g, i))) for i=0:degree(K)])
kk = Native.finite_field(f)[1]
kk, = Nemo._residue_field(f)
bas = basis(K)
u = gen(kk)
function proj(a::Hecke.LocalFieldElem)
Expand Down Expand Up @@ -494,9 +494,10 @@ end

function unramified_extension(L::Union{FlintPadicField, FlintQadicField, LocalField}, n::Int)
R, mR = residue_field(L)
f = polynomial(R, push!([rand(R) for i = 0:n-1], one(R)))
Rt, t = polynomial_ring(R, "t", cached = false)
f = Rt(push!([rand(R) for i = 0:n-1], one(R)))
while !is_irreducible(f)
f = polynomial(R, push!([rand(R) for i = 0:n-1], one(R)))
f = Rt(push!([rand(R) for i = 0:n-1], one(R)))
end
f_L = polynomial(L, [mR\(coeff(f, i)) for i = 0:degree(f)])
return unramified_extension(f_L)
Expand Down
12 changes: 9 additions & 3 deletions src/LocalField/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function lift(a::T, K::PadicField) where T <: Union{Nemo.zzModRingElem, Nemo.ZZM
return Hecke.lift(a) + O(K, p^v)
end

function lift(a::FqFieldElem, K::PadicField)
return Hecke.lift(ZZ, a) + O(K, prime(K))
end

function lift(a::FinFieldElem, K::LocalField)
k, mk = residue_field(K)
@assert k === parent(a)
Expand Down Expand Up @@ -883,6 +887,8 @@ mutable struct HenselCtxdr{S}
# @assert sum(map(degree, lfp)) == degree(f)
Q = base_ring(f)
Qx = parent(f)
@assert residue_field(Q)[1] === coefficient_ring(lfp[1])
k, Qtok = residue_field(Q)
i = 1
la = Vector{typeof(f)}()
n = length(lfp)
Expand All @@ -891,12 +897,12 @@ mutable struct HenselCtxdr{S}
f2 = lfp[i+1]
g, a, b = gcdx(f1, f2)
@assert isone(g)
push!(la, map_coefficients(x -> setprecision(lift(x, Q), 1), a, parent = Qx))
push!(la, map_coefficients(x -> setprecision(lift(x, Q), 1), b, parent = Qx))
push!(la, map_coefficients(x -> setprecision(Qtok\x, 1), a, parent = Qx))
push!(la, map_coefficients(x -> setprecision(Qtok\x, 1), b, parent = Qx))
push!(lfp, f1*f2)
i += 2
end
return new(f, map(x -> map_coefficients(y -> setprecision(lift(y, Q), 1), x, parent = Qx), lfp), la, uniformizer(Q), n)
return new(f, map(x -> map_coefficients(y -> setprecision(Qtok\y, 1), x, parent = Qx), lfp), la, uniformizer(Q), n)
end

function HenselCtxdr{S}(f::PolyRingElem{S}) where S
Expand Down
23 changes: 13 additions & 10 deletions src/LocalField/neq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ end
########### any_root computes a single root in the finite field extensions####

import Nemo: any_root
function any_root(F::Union{fqPolyRepField, Hecke.RelFinField}, f::Union{fpPolyRingElem, fqPolyRepPolyRingElem})
g = polynomial(F, [coeff(f,i) for i = 0:degree(f) ] )
function any_root(F::Union{fqPolyRepField, Hecke.RelFinField, FqField}, f::PolyElem)
g = change_base_ring(F, f; cached = false)
return any_root(g)
end

Expand Down Expand Up @@ -83,11 +83,12 @@ end

function Nemo.basis(K::FinField, k::FinField)
b = basis(K)
K = base_ring(K)
K = base_field(K)
while absolute_degree(K) > absolute_degree(k)
b = [x*y for x = basis(K) for y = b]
K = base_ring(K)
K = base_field(K)
end
@show K, k
if K != k
error("subfield not in tower")
end
Expand Down Expand Up @@ -139,7 +140,7 @@ function _unit_group_gens_case2(K::Union{FlintQadicField, Hecke.LocalField})

k, mk = residue_field(K)
@assert absolute_degree(k) == f
omega = basis(k, prime_field(k))
omega = absolute_basis(k)
@assert isone(omega[1]) #this has to change...
mu_0 = valuation(e, p)+1
e_0 = divexact(e, (p-1)*p^(mu_0-1))
Expand Down Expand Up @@ -192,7 +193,7 @@ function _unit_group_gens_case1(K::Union{FlintQadicField, Hecke.LocalField})
k, mk = residue_field(K)
@assert absolute_degree(k) == f

b = [preimage(mk, x) for x = basis(k, prime_field(k))]
b = [preimage(mk, x) for x = absolute_basis(k)]
F_K = [ lambda for lambda = 1:ceil(Int, p*e//(p-1))-1 if lambda % p != 0]
@assert length(F_K) == e

Expand Down Expand Up @@ -412,15 +413,16 @@ end
Find an element `x` in `F` such that the norm from `F` down to the parent of
`b` is exactly `b`.
"""
function norm_equation(F::Union{fqPolyRepField, Hecke.RelFinField}, b::Union{fpFieldElem, fqPolyRepFieldElem})
function norm_equation(F::Union{fqPolyRepField, Hecke.RelFinField, FqField}, b::Union{fpFieldElem, fqPolyRepFieldElem, FqFieldElem})
if iszero(b)
return zero(F)
end
k = parent(b)
n = degree(F,k)
f = polynomial(k,vcat([b],[rand(k) for i = 1:n-1],[1]))
n = degree(F, k)
kt, = polynomial_ring(k, "t", cached = false)
f = kt(vcat([b],[rand(k) for i = 1:n-1],[one(k)]))
while !is_irreducible(f)
f = polynomial(k,vcat([b],[rand(k) for i = 1:n-1],[1]))
f = kt(vcat([b],[rand(k) for i = 1:n-1],[one(k)]))
end
return (-1)^(n)*any_root(F, f)
end
Expand Down Expand Up @@ -796,6 +798,7 @@ function local_fundamental_class_serre(mKL::LocalFieldMor)
rE, mE = residue_field(E)
rL, mL = residue_field(L)
rK, mK = residue_field(K)
# how is this supposed to work?
mrKL = hom(rK, rL, mL(mKL(preimage(mK, gen(rK)))))
q = order(rK)

Expand Down
68 changes: 58 additions & 10 deletions src/LocalField/qAdic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ function residue_field(Q::FlintQadicField)
if z !== nothing
return codomain(z), z
end
Fp = Native.GF(Int(prime(Q)))
Fp = Nemo._GF(prime(Q))
Fpt = polynomial_ring(Fp, cached = false)[1]
g = defining_polynomial(Q) #no Conway if parameters are too large!
f = Fpt([Fp(lift(coeff(g, i))) for i=0:degree(Q)])
k = Native.finite_field(f, "o", cached = false)[1]
k, = Nemo._residue_field(f, "o")
pro = function(x::qadic)
v = valuation(x)
v < 0 && error("elt non integral")
v > 0 && return k(0)
z = k()
_z = Fpt()
for i=0:degree(Q)
setcoeff!(z, i, UInt(lift(coeff(x, i))%prime(Q)))
setcoeff!(_z, i, Fp(lift(coeff(x, i))))
end
return z
return k(_z)
end
lif = function(x::fqPolyRepFieldElem)
lif = function(x::FqFieldElem)
z = Q()
for i=0:degree(Q)-1
setcoeff!(z, i, coeff(x, i))
setcoeff!(z, i, lift(ZZ, coeff(x, i)))
end
return z
end
Expand All @@ -37,22 +37,70 @@ function residue_field(Q::FlintQadicField)
return k, mk
end

#function residue_field(Q::FlintQadicField)
# z = get_attribute(Q, :ResidueFieldMap)
# if z !== nothing
# return codomain(z), z
# end
# Fp = Native.GF(Int(prime(Q)))
# Fpt = polynomial_ring(Fp, cached = false)[1]
# g = defining_polynomial(Q) #no Conway if parameters are too large!
# f = Fpt([Fp(lift(coeff(g, i))) for i=0:degree(Q)])
# k = Native.finite_field(f, "o", cached = false)[1]
# pro = function(x::qadic)
# v = valuation(x)
# v < 0 && error("elt non integral")
# v > 0 && return k(0)
# z = k()
# for i=0:degree(Q)
# setcoeff!(z, i, UInt(lift(coeff(x, i))%prime(Q)))
# end
# return z
# end
# lif = function(x::fqPolyRepFieldElem)
# z = Q()
# for i=0:degree(Q)-1
# setcoeff!(z, i, coeff(x, i))
# end
# return z
# end
# mk = MapFromFunc(Q, k, pro, lif)
# set_attribute!(Q, :ResidueFieldMap => mk)
# return k, mk
#end

function residue_field(Q::FlintPadicField)
k = Native.GF(Int(prime(Q)))
k = Nemo._GF(prime(Q))
pro = function(x::padic)
v = valuation(x)
v < 0 && error("elt non integral")
v > 0 && return k(0)
z = k(lift(x))
return z
end
lif = function(x::fpFieldElem)
z = Q(lift(x))
lif = function(x::FqFieldElem)
z = Q(lift(ZZ, x))
return z
end
return k, MapFromFunc(Q, k, pro, lif)
end

#function residue_field(Q::FlintPadicField)
# k = Native.GF(Int(prime(Q)))
# pro = function(x::padic)
# v = valuation(x)
# v < 0 && error("elt non integral")
# v > 0 && return k(0)
# z = k(lift(x))
# return z
# end
# lif = function(x::fpFieldElem)
# z = Q(lift(x))
# return z
# end
# return k, MapFromFunc(Q, k, pro, lif)
#end

coefficient_field(Q::FlintQadicField) = coefficient_ring(Q)

function getUnit(a::padic)
Expand Down
10 changes: 8 additions & 2 deletions src/Map/FiniteField.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
function hom(F::FinField, K::FinField, a::FinFieldElem; check::Bool = true)
@assert parent(a) == K

# I will be jumping through a lot of hoops to make
# base_field(F) == F_p work
if check
@assert iszero(defining_polynomial(F)(a))
if absolute_degree(base_field(F)) == 1 && base_field(F) !== base_field(K)
@assert iszero(map_coefficients(x -> base_field(K)(lift(ZZ, x)), defining_polynomial(F), cached = false)(a))
else
@assert iszero(defining_polynomial(F)(a))
end
end

if F isa FqField
@assert K isa FqField
@assert base_field(F) === base_field(K)
@assert absolute_degree(F) == 1 || base_field(F) === base_field(K)
k = base_field(F)
kx = parent(defining_polynomial(F))

Expand Down
9 changes: 9 additions & 0 deletions src/Misc/FiniteField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ function find_morphism(k::fqPolyRepField, K::fqPolyRepField)
return phi
end

function find_morphism(k::FqField, K::FqField)
if degree(k) > 1
phi = Nemo.find_morphism(k, K) #avoids embed - which stores the info
else
phi = MapFromFunc(k, K, x -> K(lift(ZZ, x)), y -> k(lift(ZZ, y)))
end
return phi
end


mutable struct VeryBad
entries::Ptr{Nothing}
Expand Down
2 changes: 1 addition & 1 deletion src/NumFieldOrd/NfOrd/Clgp/Proof.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function _prime_partition(do_it, nt)
end
@assert first(do_it) == 1
ub = last(do_it)
np = ceil(Int, logarithmic_integral(1.0*ub))
np = ceil(Int, max(10.0, logarithmic_integral(1.0*ub)))
primes_per_thread = ceil(Int, np//nt)
intervals = collect(Iterators.partition(1:np, primes_per_thread))
res = UnitRange{Int}[]
Expand Down

0 comments on commit 0324987

Please sign in to comment.