Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change residue_field for local fields #1268

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4"
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 @@
########### 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 @@

function Nemo.basis(K::FinField, k::FinField)
b = basis(K)
K = base_ring(K)
K = base_field(K)

Check warning on line 86 in src/LocalField/neq.jl

View check run for this annotation

Codecov / codecov/patch

src/LocalField/neq.jl#L86

Added line #L86 was not covered by tests
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)

Check warning on line 89 in src/LocalField/neq.jl

View check run for this annotation

Codecov / codecov/patch

src/LocalField/neq.jl#L89

Added line #L89 was not covered by tests
end
@show K, k

Check warning on line 91 in src/LocalField/neq.jl

View check run for this annotation

Codecov / codecov/patch

src/LocalField/neq.jl#L91

Added line #L91 was not covered by tests
if K != k
error("subfield not in tower")
end
Expand Down Expand Up @@ -139,7 +140,7 @@

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 @@
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 @@
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 @@
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)))))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without promotion magic, this only works if base_field(rK) === base_field(rL), but this is not the case here.

q = order(rK)

Expand Down
20 changes: 10 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 @@ -38,16 +38,16 @@ function residue_field(Q::FlintQadicField)
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)
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))

Check warning on line 10 in src/Map/FiniteField.jl

View check run for this annotation

Codecov / codecov/patch

src/Map/FiniteField.jl#L10

Added line #L10 was not covered by tests
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
38 changes: 38 additions & 0 deletions src/Misc/FiniteField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,44 @@
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

function find_morphism(k::FqField, K::fqPolyRepField)
# This is no fun
if absolute_degree(k) == 1
#@assert degree(K) == 1
pre = function(x)
@assert all(is_zero(coeff(x, i)) for i in 1:(degree(K) - 1))
return k(coeff(x, 0))
end
return MapFromFunc(k, K, x -> K(lift(ZZ, x)), pre)
end

# build K as FqField, then find isomorphism, then go back

f = modulus(K)
a = gen(K)
F = prime_field(k)
Ft, t = polynomial_ring(F, "t", cached = false)
fF = map_coefficients(x -> F(lift(x)), f, parent = Ft)
KK, polytoKK = Nemo._residue_field(fF)

Check warning on line 244 in src/Misc/FiniteField.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/FiniteField.jl#L239-L244

Added lines #L239 - L244 were not covered by tests

KtoKK = x -> polytoKK(map_coefficients(x -> F(lift(x)), parent(f)(x), parent = Ft))

Check warning on line 246 in src/Misc/FiniteField.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/FiniteField.jl#L246

Added line #L246 was not covered by tests

KKtoK = x -> K(map_coefficients(x -> coefficient_ring(parent(f))(lift(ZZ, x)), polytoKK\x, parent = parent(f)))

Check warning on line 248 in src/Misc/FiniteField.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/FiniteField.jl#L248

Added line #L248 was not covered by tests

phi_k_to_KK = Nemo.embed_any(k, KK)

Check warning on line 250 in src/Misc/FiniteField.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/FiniteField.jl#L250

Added line #L250 was not covered by tests

phi = MapFromFunc(k, K, x -> KKtoK(phi_k_to_KK(x)), x -> phi_k_to_KK\(KtoKK(x)))

Check warning on line 252 in src/Misc/FiniteField.jl

View check run for this annotation

Codecov / codecov/patch

src/Misc/FiniteField.jl#L252

Added line #L252 was not covered by tests
end


mutable struct VeryBad
entries::Ptr{Nothing}
Expand Down
2 changes: 1 addition & 1 deletion src/NumField/NfAbs/PolyFact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mutable struct HenselCtxQadic <: Hensel
n::Int
#TODO: lift over subfields first iff poly is defined over subfield
#TODO: use flint if qadic = padic!!
function HenselCtxQadic(f::PolyRingElem{qadic}, lfp::Vector{fqPolyRepPolyRingElem})
function HenselCtxQadic(f::PolyRingElem{qadic}, lfp::Vector{FqPolyRingElem})
@assert sum(map(degree, lfp)) == degree(f)
Q = base_ring(f)
Qx = parent(f)
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
Loading