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

Replace some setprecision!(::ParentObject) #1522

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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 examples/NFDB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ function _p_adic_regulator_coates(K::AbsSimpleNumField, p::IntegerUnion)
while true
(prec > 2^12 || working_prec > 2^12) && error("Something wrong")
imK =[LocalFieldValuationRingElem{PadicField, PadicFieldElem}[] for i in 1:degK]
Qp = PadicField(p, prec, cached = false)
Qp = padic_field(p, precision = prec, cached = false)
Zp = ring_of_integers(Qp)
dK = discriminant(OK)
r = maximum([ramification_index(P) for P in dp])
Expand Down
2 changes: 1 addition & 1 deletion examples/Plesken.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function primitive_root_r_div_qm1(R, r::Int)
end

function get_f(r::Int, p::ZZRingElem, s::Int)
R = PadicField(r, s)
R = padic_field(r, precision = s)
return lift(teichmuller(R(p)))
end
# plan
Expand Down
2 changes: 1 addition & 1 deletion examples/Tropics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ lp[1].gen_two*lp[2].gen_two^2
ma = representation_matrix(a)
mb = representation_matrix(k(ans))
@assert iszero(ma*mb - mb*ma)
Qp = PadicField(7, 10)
Qp = padic_field(7, precision = 10)
Main.TropicalModule.simultaneous_diagonalization([map_entries(Qp, ma), map_entries(Qp, mb)])

=#
Expand Down
7 changes: 7 additions & 0 deletions src/Deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,10 @@ end
# Deprecated in 0.33.0

@deprecate rres reduced_resultant

# Deprecated in 0.34.0

@deprecate lift(a::LocalFieldValuationRingElem) lift(ZZ, a)
@deprecate prime_field(L::Union{QadicField, LocalField}) absolute_base_field(L)
@deprecate coefficient_ring(k::LocalField) base_field(k)
@deprecate coefficient_field(k::QadicField) base_field(k)
4 changes: 2 additions & 2 deletions src/HeckeTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2240,11 +2240,11 @@ mutable struct qAdicRootCtx
lf = Hecke.factor_mod_pk(Array, H, 1)
if splitting_field
d = lcm([degree(y[1]) for y = lf])
R = QadicField(p, d, 1)[1]
R = qadic_field(p, d, precision = 1)[1]
Q = [R]
r.is_splitting = true
else
Q = [QadicField(p, x, 1)[1] for x = Set(degree(y[1]) for y = lf)]
Q = [qadic_field(p, x, precision = 1)[1] for x = Set(degree(y[1]) for y = lf)]
r.is_splitting = false
end
@assert all(x->isone(x[2]), lf)
Expand Down
107 changes: 53 additions & 54 deletions src/LocalField/Completions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ The map giving the embedding of $K$ into the completion, admits a pointwise
preimage to obtain a lift. Note, that the map is not well defined by this
data: $K$ will have $\deg P$ many embeddings.

The map is guaranteed to yield a relative precision of at least `preciscion`.
The map is guaranteed to yield a relative precision of at least `precision`.
"""
function completion(K::AbsSimpleNumField, P::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}, precision::Int = 64)
function completion(K::AbsSimpleNumField, P::AbsNumFieldOrderIdeal{AbsSimpleNumField, AbsSimpleNumFieldElem}, precision::Int = 64, Qp::Union{PadicField,Nothing} = nothing)
#to guarantee a rel_prec we need to account for the index (or the
#elementary divisor of the trace mat): the map
#is for the field (equation order), the precision is measured in the
Expand All @@ -189,9 +189,11 @@ function completion(K::AbsSimpleNumField, P::AbsNumFieldOrderIdeal{AbsSimpleNumF
f = degree(P)
e = ramification_index(P)
prec_padics = div(precision+e-1, e)
Qp = PadicField(minimum(P), prec_padics, cached = false)
if isnothing(Qp)
Qp = padic_field(minimum(P), precision = prec_padics, cached = false)
end
Zp = maximal_order(Qp)
Qq, gQq = QadicField(minimum(P), f, prec_padics, cached = false)
Qq, gQq = unramified_extension(Qp, f, precision = prec_padics, cached = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

I have no detail about the maths in here, so I just trust this change (which unlike the others seems not completely "obvious") is correct

Qqx, gQqx = polynomial_ring(Qq, "x")
q, mq = residue_field(Qq)
#F, mF = ResidueFieldSmall(OK, P)
Expand Down Expand Up @@ -264,54 +266,51 @@ function _solve_internal(gq_in_K, P, precision, Zp, Qq)
mul!(bK.num, bK.num, divexact(d, denominator(bK, copy = false)))
end

setprecision!(Zp, Hecke.precision(Zp) + valuation(Zp(denominator(MK))))

if true
#snf is slower (possibly) but has optimal precision loss.
#bad example is completion at prime over 2 in
# x^8 - 12*x^7 + 44*x^6 - 24*x^5 - 132*x^4 + 120*x^3 + 208*x^2 - 528*x + 724
# the can_solve... returns a precision of just 6 p-adic digits
# the snf gets 16 (both for the default precision)
# the det(M) has valuation 12, but the elem. divisors only 3
#TODO: rewrite can_solve? look at Avi's stuff?
# x M = b
# u*M*v = s
# x inv(u) u M v = b v
# x inv(u) s = b v
# x = b v inv(s) u
#lets try:
s, _u, v = snf_with_transform(MK.num)
bv = bK.num * v
bv = map_entries(Zp, bv)
for i=1:ncols(s)
bv[1, i] = divexact(bv[1, i], Zp(s[i,i]))
bv[2, i] = divexact(bv[2, i], Zp(s[i,i]))
end
xZp = bv * map_entries(Zp, _u[1:ncols(s), 1:ncols(s)])
else
MZp = map_entries(Zp, MK.num)
bZp = map_entries(Zp, bK.num)
fl, xZp = can_solve_with_solution(MZp, bZp, side = :left)
@assert fl
end
coeffs_eisenstein = Vector{QadicFieldElem}(undef, e+1)
gQq = gen(Qq)
for i = 1:e
coeff = zero(Qq)
for j = 0:f-1
coeff += (gQq^j)*xZp[1, j+1+(i-1)*f].x
return with_precision(Zp, Hecke.precision(Zp) + valuation(Zp(denominator(MK)))) do
if true
#snf is slower (possibly) but has optimal precision loss.
#bad example is completion at prime over 2 in
# x^8 - 12*x^7 + 44*x^6 - 24*x^5 - 132*x^4 + 120*x^3 + 208*x^2 - 528*x + 724
# the can_solve... returns a precision of just 6 p-adic digits
# the snf gets 16 (both for the default precision)
# the det(M) has valuation 12, but the elem. divisors only 3
#TODO: rewrite can_solve? look at Avi's stuff?
# x M = b
# u*M*v = s
# x inv(u) u M v = b v
# x inv(u) s = b v
# x = b v inv(s) u
#lets try:
s, _u, v = snf_with_transform(MK.num)
bv = bK.num * v
bv = map_entries(Zp, bv)
for i=1:ncols(s)
bv[1, i] = divexact(bv[1, i], Zp(s[i,i]))
bv[2, i] = divexact(bv[2, i], Zp(s[i,i]))
end
xZp = bv * map_entries(Zp, _u[1:ncols(s), 1:ncols(s)])
else
MZp = map_entries(Zp, MK.num)
bZp = map_entries(Zp, bK.num)
xZp = solve(MZp, bZp, side = :left)
end
coeffs_eisenstein[i] = -coeff
end
coeffs_eisenstein[e+1] = one(Qq)
if iszero(coeffs_eisenstein[1])
error("precision not high enough to obtain Esenstein polynomial")
end
return coeffs_eisenstein, xZp
coeffs_eisenstein = Vector{QadicFieldElem}(undef, e+1)
gQq = gen(Qq)
for i = 1:e
coeff = zero(Qq)
for j = 0:f-1
coeff += (gQq^j)*xZp[1, j+1+(i-1)*f].x
end
coeffs_eisenstein[i] = -coeff
end
coeffs_eisenstein[e+1] = one(Qq)
if iszero(coeffs_eisenstein[1])
error("precision not high enough to obtain Esenstein polynomial")
end
return coeffs_eisenstein, xZp
end # with_precision
end



function setprecision!(f::CompletionMap{LocalField{QadicFieldElem, EisensteinLocalField}, LocalFieldElem{QadicFieldElem, EisensteinLocalField}}, new_prec::Int)
P = prime(f)
OK = order(P)
Expand All @@ -336,7 +335,7 @@ function setprecision!(f::CompletionMap{LocalField{QadicFieldElem, EisensteinLoc
gq = _increase_precision(gq, pol_gq, div(f.precision+e-1, e), ex, P)
f.inv_img = (gq, f.inv_img[2])

Zp = maximal_order(prime_field(Kp))
Zp = maximal_order(absolute_base_field(Kp))
Qq = base_field(Kp)

setprecision!(Qq, ex)
Expand Down Expand Up @@ -384,7 +383,7 @@ function totally_ramified_completion(K::AbsSimpleNumField, P::AbsNumFieldOrderId
@assert nf(OK) == K
@assert isone(degree(P))
e = ramification_index(P)
Qp = PadicField(minimum(P), precision)
Qp = padic_field(minimum(P), precision = precision)
Zp = maximal_order(Qp)
Zx = FlintZZ["x"][1]
Qpx = polynomial_ring(Qp, "x")[1]
Expand Down Expand Up @@ -443,7 +442,7 @@ function setprecision!(f::CompletionMap{LocalField{PadicFieldElem, EisensteinLoc
if r > 0
ex += 1
end
Qp = PadicField(prime(Kp), div(new_prec, e)+1)
Qp = padic_field(prime(Kp), precision = div(new_prec, e) + 1)
Zp = maximal_order(Qp)
Qpx, _ = polynomial_ring(Qp, "x")
pows_u = powers(u, e-1)
Expand Down Expand Up @@ -495,8 +494,8 @@ function unramified_completion(K::AbsSimpleNumField, P::AbsNumFieldOrderIdeal{Ab
@assert isone(ramification_index(P))
f = degree(P)
p = minimum(P)
Qq, gQq = QadicField(p, f, precision)
Qp = PadicField(p, precision)
Qq, gQq = qadic_field(p, f, precision = precision)
Qp = padic_field(p, precision = precision)
Zp = maximal_order(Qp)
q, mq = residue_field(Qq)
F, mF = residue_field(OK, P)
Expand Down
Loading
Loading