Skip to content

Commit

Permalink
avoid calling conductor
Browse files Browse the repository at this point in the history
Instead, call `Hecke.force_coerce_cyclo(Kg, data(x), Val(false))`,
which finds out whether the conversion works.
  • Loading branch information
ThomasBreuer committed Oct 25, 2024
1 parent 24c8f63 commit 06796c3
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions src/Rings/AbelianClosure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -933,25 +933,22 @@ end

# Construct the map from `F` to an abelian closure `K` such that `gen(F)`
# is mapped to `x`.
# If `F` is a cyclotomic field with conductor `N` then assume that `gen(F)`
# is mapped to `QQAbFieldElem(gen(F), N)`.
# If `F` has conductor `N` then assume that `x.c == N` holds.
# If `F` is a cyclotomic field with conductor `N` then assume that
# `x == QQAbFieldElem(gen(F), N)`.
# (Use that the powers of this element form a basis of the field.)
function _embedding(F::QQField, K::QQAbField{AbsSimpleNumField},
x::QQAbFieldElem{AbsSimpleNumFieldElem})
C1, z = cyclotomic_field(1)
C1, _ = cyclotomic_field(1)

f = function(x::QQFieldElem)
return QQAbFieldElem(C1(x), 1)
end

finv = function(x::QQAbFieldElem; check::Bool = false)
if conductor(x) == 1
return Hecke.force_coerce_cyclo(C1, data(x))
elseif check
return
else
error("element has no preimage")
end
res = Hecke.force_coerce_cyclo(C1, data(x), Val(false))
!check && res === nothing && error("element has no preimage")
return res

Check warning on line 951 in src/Rings/AbelianClosure.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings/AbelianClosure.jl#L949-L951

Added lines #L949 - L951 were not covered by tests
end

return MapFromFunc(F, K, f, finv)
Expand All @@ -967,17 +964,13 @@ function _embedding(F::AbsSimpleNumField, K::QQAbField{AbsSimpleNumField},
end

finv = function(x::QQAbFieldElem; check::Bool = false)
if n % conductor(x) == 0
return Hecke.force_coerce_cyclo(F, data(x))
elseif check
return
else
error("element has no preimage")
end
res = Hecke.force_coerce_cyclo(F, data(x), Val(false))
!check && res === nothing && error("element has no preimage")
return res
end
else
# `F` is expected to be a proper subfield of a cyclotomic field.
n = conductor(x)
n = x.c
x = data(x)
Kn, = AbelianClosure.cyclotomic_field(K, n)
powers = [Hecke.coefficients(Hecke.force_coerce_cyclo(Kn, x^i))
Expand All @@ -990,24 +983,25 @@ function _embedding(F::AbsSimpleNumField, K::QQAbField{AbsSimpleNumField},
end

finv = function(x::QQAbFieldElem; check::Bool = false)
n % conductor(x) == 0 || return false, zero(F)
# Write `x` w.r.t. the n-th cyclotomic field ...
g = gcd(x.c, n)
Kg, = AbelianClosure.cyclotomic_field(K, g)
x = Hecke.force_coerce_cyclo(Kg, data(x))
x = Hecke.force_coerce_cyclo(Kg, data(x), Val(false))
if x === nothing
!check && error("element has no preimage")
return

Check warning on line 992 in src/Rings/AbelianClosure.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings/AbelianClosure.jl#L991-L992

Added lines #L991 - L992 were not covered by tests
end
x = Hecke.force_coerce_cyclo(Kn, x)
# ... and then w.r.t. `F`
a = Hecke.coefficients(x)
fl, sol = can_solve_with_solution(c, matrix(QQ, length(a), 1, a); side = :right)
if fl
b = transpose(sol)
b = [b[i] for i in 1:length(b)]
return F(b)
elseif check
if !fl
!check && error("element has no preimage")
return
else
error("element has no preimage")
end
b = transpose(sol)
b = [b[i] for i in 1:length(b)]
return F(b)
end
end
return MapFromFunc(F, K, f, finv)
Expand Down

0 comments on commit 06796c3

Please sign in to comment.