Skip to content

Commit

Permalink
feat: adjust to finite field changes in Nemo (#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma authored Jan 5, 2024
1 parent cef82d1 commit cb99cfd
Show file tree
Hide file tree
Showing 31 changed files with 75 additions and 101 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ GAPExt = "GAP"
PolymakeExt = "Polymake"

[compat]
AbstractAlgebra = "^0.34.4"
AbstractAlgebra = "^0.35.2"
Dates = "1.6"
Distributed = "1.6"
GAP = "0.9.6, 0.10"
Expand All @@ -37,7 +37,7 @@ LazyArtifacts = "1.6"
Libdl = "1.6"
LinearAlgebra = "1.6"
Markdown = "1.6"
Nemo = "^0.38.2"
Nemo = "^0.39.1"
Pkg = "1.6"
Polymake = "0.10, 0.11"
Printf = "1.6"
Expand Down
2 changes: 1 addition & 1 deletion examples/Plesken.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function plesken_kummer(p::ZZRingElem, r::Int, s::Int)
end
descent = true
ord = degree(opt)
R = FlintFiniteField(opt, "a")[1]
R = Native.finite_field(opt, "a")[1]
T = residue_ring(FlintZZ, p)
J = CoerceMap(T, R)
end
Expand Down
24 changes: 12 additions & 12 deletions ext/GAPExt/brauer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,12 @@ function _obstruction_prime_no_extend(x::FieldsTower, cocycles, p::Int)
GC = automorphism_list(K, copy = false)
D = x.isomorphism
Pcomp = 2
R = GF(Pcomp, cached = false)
R = Native.GF(Pcomp, cached = false)
Rx = polynomial_ring(R, "x", cached = false)[1]
ff = Rx(K.pol)
while iszero(mod(p, Pcomp)) || iszero(discriminant(ff))
Pcomp = next_prime(Pcomp)
R = GF(Pcomp, cached = false)
R = Native.GF(Pcomp, cached = false)
Rx = polynomial_ring(R, "x", cached = false)[1]
ff = Rx(K.pol)
end
Expand Down Expand Up @@ -738,13 +738,13 @@ function _obstruction_prime(x::FieldsTower, cocycles::Vector{cocycle_ctx}, p)
permGC = _from_autos_to_perm(autsK)
Gperm = _perm_to_gap_grp(permGC)
Pcomp = 2
R = GF(Pcomp, cached = false)
R = Native.GF(Pcomp, cached = false)
Rx = polynomial_ring(R, "x", cached = false)[1]
ff1 = Rx(K.pol)
ff2 = Rx(K1.pol)
while iszero(mod(p, Pcomp)) || iszero(discriminant(ff1)) || iszero(discriminant(ff2))
Pcomp = next_prime(Pcomp)
R = GF(Pcomp, cached = false)
R = Native.GF(Pcomp, cached = false)
Rx = polynomial_ring(R, "x", cached = false)[1]
ff1 = Rx(K.pol)
ff2 = Rx(K1.pol)
Expand Down Expand Up @@ -801,12 +801,12 @@ function action_on_roots(G::Vector{NfToNfMor}, zeta::nf_elem, pv::Int)
p = 11
K = domain(G[1])
Qx = parent(K.pol)
R = GF(p, cached = false)
R = Native.GF(p, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
fmod = Rx(K.pol)
while iszero(discriminant(fmod)) || iszero(mod(pv, p))
p = next_prime(p)
R = GF(p, cached = false)
R = Native.GF(p, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
fmod = Rx(K.pol)
end
Expand All @@ -833,13 +833,13 @@ function restriction(autsK1::Vector{NfToNfMor}, autsK::Vector{NfToNfMor}, mp::Nf
K = domain(mp)
K1 = codomain(mp)
p = 11
R = GF(p, cached = false)
R = Native.GF(p, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
ff1 = Rx(K.pol)
fmod = Rx(K1.pol)
while iszero(discriminant(ff1)) || iszero(discriminant(fmod))
p = next_prime(p)
R = GF(p, cached = false)
R = Native.GF(p, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
ff1 = Rx(K.pol)
fmod = Rx(K1.pol)
Expand Down Expand Up @@ -914,13 +914,13 @@ function _obstruction_pp(F::FieldsTower, cocycles::Vector{cocycle_ctx}, pv::Int)
permGC = _from_autos_to_perm(autsK)
Gperm = _perm_to_gap_grp(permGC)
Pcomp = 7
R = GF(Pcomp, cached = false)
R = Native.GF(Pcomp, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
ff1 = Rx(K.pol)
ff2 = Rx(K1.pol)
while iszero(discriminant(ff1)) || iszero(discriminant(ff2))
Pcomp = next_prime(Pcomp)
R = GF(Pcomp, cached = false)
R = Native.GF(Pcomp, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
ff1 = Rx(K.pol)
ff2 = Rx(K1.pol)
Expand Down Expand Up @@ -1006,12 +1006,12 @@ function _obstruction_pp_no_extend(F::FieldsTower, cocycles::Vector{cocycle_ctx}
permGC = _from_autos_to_perm(autsK)
Gperm = _perm_to_gap_grp(permGC)
Pcomp = 7
R = GF(Pcomp, cached = false)
R = Native.GF(Pcomp, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
ff1 = Rx(K.pol)
while iszero(discriminant(ff1))
Pcomp = next_prime(Pcomp)
R = GF(Pcomp, cached = false)
R = Native.GF(Pcomp, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
ff1 = Rx(K.pol)
end
Expand Down
8 changes: 4 additions & 4 deletions ext/GAPExt/fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ function permutations(G::Vector{Hecke.NfToNfMor})
dK = degree(K)
d = numerator(discriminant(K.pol))
p = 11
R = GF(p, cached = false)
R = Native.GF(p, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
fmod = Rx(K.pol)
while iszero(discriminant(fmod))
p = next_prime(p)
R = GF(p, cached = false)
R = Native.GF(p, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
fmod = Rx(K.pol)
end
Expand Down Expand Up @@ -264,12 +264,12 @@ function _from_autos_to_perm(G::Vector{Hecke.NfToNfMor})
n = length(G)
#First, find a good prime
p = 3
R = GF(p, cached = false)
R = Native.GF(p, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
fmod = Rx(K.pol)
while iszero(discriminant(fmod))
p = next_prime(p)
R = GF(p, cached = false)
R = Native.GF(p, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
fmod = Rx(K.pol)
end
Expand Down
2 changes: 1 addition & 1 deletion ext/GAPExt/maximal_abelian_subextension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function check_abelian_extensions(class_fields::Vector{Tuple{ClassField{MapRayCl
while iszero(mod(d1, p)) || iszero(mod(d2, p))
p = next_prime(p)
end
R = GF(p, cached = false)
R = Native.GF(p, cached = false)
Rx, x = polynomial_ring(R, "x", cached = false)
fmod = Rx(K.pol)
mp_pol = Rx(image_primitive_element(emb_sub))
Expand Down
2 changes: 1 addition & 1 deletion src/AlgAss/AbsAlgAss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ function _radical(A::AbsAlgAss{T}) where { T <: Union{ fqPolyRepFieldElem, FqPol
if T <: fqPolyRepFieldElem
Fp = Native.GF(Int(p))
elseif T === FqFieldElem
Fp = Nemo._GF(p)
Fp = GF(p)
else
Fp = Native.GF(p)
end
Expand Down
2 changes: 1 addition & 1 deletion src/AlgAss/AlgAss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function AlgAss(O::Union{NfAbsOrd, AlgAssAbsOrd}, I::Union{NfAbsOrdIdl, AlgAssAb
end

r = length(basis_elts)
Fp = Nemo._GF(p, cached = false)
Fp = GF(p, cached = false)

if r == 0
A = _zero_algebra(Fp)
Expand Down
2 changes: 1 addition & 1 deletion src/EllCrv/EllCrv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ Return an elliptic curve with the given $j$-invariant.
```jldoctest
julia> K = GF(3)
Finite field of characteristic 3
Finite field of degree 1 over GF(3)
julia> elliptic_curve_from_j_invariant(K(2))
Elliptic curve with equation
Expand Down
24 changes: 12 additions & 12 deletions src/EllCrv/Finite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1050,16 +1050,16 @@ Return the polynomial whose roots correspond to j-invariants
of supersingular elliptic curves of characteristic p.
"""
function supersingular_polynomial(p::IntegerUnion)
p = ZZRingElem(p)
K = GF(p)
KJ, J = polynomial_ring(GF(p), "J")
if p < 3
_p = ZZRingElem(p)
K = GF(_p)
KJ, J = polynomial_ring(K, "J")
if _p < 3
return J
end

m = divexact((p-1), 2)
KXT, (X, T) = polynomial_ring(K, ["X", "T"])
H = sum([binomial(m, i)^2 *T^i for i in (0:m)])
m = divexact((_p -1 ), 2)
KXT, (X, T) = polynomial_ring(K, ["X", "T"], cached = false)
H = sum(elem_type(KXT)[binomial(m, i)^2 *T^i for i in 0:m])
F = T^2 * (T - 1)^2 * X - 256 * (T^2 - T + 1)^3
R = resultant(F, H, 2)
factors = factor(evaluate(R, [J, zero(KJ)]))
Expand Down Expand Up @@ -1144,17 +1144,17 @@ Return a list of generators of the group of rational points on $E$.
julia> E = elliptic_curve(GF(101, 2), [1, 2]);
julia> gens(E)
2-element Vector{EllCrvPt{fqPolyRepFieldElem}}:
Point (93*o + 10 : 22*o + 69 : 1) of Elliptic curve with equation
2-element Vector{EllCrvPt{FqFieldElem}}:
Point (16*o + 42 : 88*o + 97 : 1) of Elliptic curve with equation
y^2 = x^3 + x + 2
Point (89*o + 62 : 14*o + 26 : 1) of Elliptic curve with equation
Point (88*o + 23 : 94*o + 22 : 1) of Elliptic curve with equation
y^2 = x^3 + x + 2
julia> E = elliptic_curve(GF(101), [1, 2]);
julia> gens(E)
1-element Vector{EllCrvPt{fpFieldElem}}:
Point (50 : 69 : 1) of Elliptic curve with equation
1-element Vector{EllCrvPt{FqFieldElem}}:
Point (85 : 58 : 1) of Elliptic curve with equation
y^2 = x^3 + x + 2
```
"""
Expand Down
2 changes: 1 addition & 1 deletion src/EllCrv/LocalData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ end
function _tates_algorithm(E::EllCrv{QQFieldElem}, _p::IntegerUnion)
p = ZZ(_p)
F = GF(p, cached = false)
_invmod = x -> QQ(lift(inv(F(x))))
_invmod = x -> QQ(lift(ZZ, inv(F(x))))
_uni = p
return __tates_algorithm_generic(E, ZZ, x -> is_zero(x) ? inf : valuation(x, p), x -> smod(x, p), x -> F(x), x -> QQ(lift(x)), _invmod, p)
end
Expand Down
6 changes: 3 additions & 3 deletions src/LocalField/Conjugates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ function completion(K::AnticNumberField, ca::qadic)
while length(pa) < d
push!(pa, pa[end]*pa[2])
end
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])
m = matrix(GF(p), d, d, [lift(ZZ, coeff(pa[i], j-1)) for j=1:d for i=1:d])
o = matrix(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()
Expand All @@ -566,7 +566,7 @@ function completion(K::AnticNumberField, ca::qadic)
end
f = defining_polynomial(parent(ca), FlintZZ)
fso = inv(derivative(f)(gen(R)))
o = matrix(Nemo._GF(p), d, 1, [lift(ZZ, coeff(fso, j-1)) for j=1:d])
o = matrix(GF(p), d, 1, [lift(ZZ, coeff(fso, j-1)) for j=1:d])
s = solve(m, o)
b = K()
for i=1:d
Expand Down
5 changes: 3 additions & 2 deletions src/LocalField/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ function fun_factor(g::Generic.Poly{padic})
Rt = polynomial_ring(R, "t", cached = false)[1]
fR = Rt([R(Hecke.lift(coeff(g, i))) for i = 0:degree(g)])
u, g1 = Hecke.fun_factor(fR)
fun = x -> lift(x, K)
return map_coefficients(fun, u, parent = Kt), map_coefficients(fun, g1, parent = Kt)
liftu = Kt(elem_type(K)[lift(coeff(u, i), K) for i in 0:degree(u)])
liftg1 = Kt(elem_type(K)[lift(coeff(g1, i), K) for i in 0:degree(g1)])
return (liftu, liftg1)::Tuple{typeof(g), typeof(g)}
end

function fun_factor(f::Generic.Poly{S}) where S <: Union{qadic, LocalFieldElem}
Expand Down
4 changes: 2 additions & 2 deletions src/LocalField/qAdic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function residue_field(Q::FlintQadicField)
if z !== nothing
return codomain(z), z
end
Fp = Nemo._GF(prime(Q))
Fp = 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)])
Expand Down Expand Up @@ -36,7 +36,7 @@ function residue_field(Q::FlintQadicField)
end

function residue_field(Q::FlintPadicField)
k = Nemo._GF(prime(Q))
k = GF(prime(Q))
pro = function(x::padic)
v = valuation(x)
v < 0 && error("elt non integral")
Expand Down
6 changes: 3 additions & 3 deletions src/Map/MapType.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,18 @@ julia> F = GF(2);
julia> f = MapFromFunc(QQ, F, x -> F(numerator(x)) * inv(F(denominator(x))))
Map defined by a julia-function
from rational field
to finite field of characteristic 2
to finite field of degree 1 over GF(2)
julia> f(QQ(1//3))
1
julia> println(f)
Map: QQ -> GF(2)
julia> f = MapFromFunc(QQ, F, x -> F(numerator(x)) * inv(F(denominator(x))), y -> QQ(lift(y)),)
julia> f = MapFromFunc(QQ, F, x -> F(numerator(x)) * inv(F(denominator(x))), y -> QQ(lift(ZZ, y)),)
Map defined by a julia-function with inverse
from rational field
to finite field of characteristic 2
to finite field of degree 1 over GF(2)
julia> preimage(f, F(1))
1
Expand Down
2 changes: 1 addition & 1 deletion src/Map/NfOrd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ function NfOrdToFqFieldMor(O::NfOrd, P::NfOrdIdl)
z.P = P
a, g, b = get_residue_field_data(P)
p = minimum(P)
R = Nemo._GF(p, cached = false)
R = GF(p, cached = false)
Rx, x = polynomial_ring(R, "_\$", cached = false)
F, = Nemo._residue_field(Rx(g), "_\$", check = false)
d = degree(g)
Expand Down
2 changes: 1 addition & 1 deletion src/Misc/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ specified, return the `n`-th cyclotomic polynomial over the integers.
```jldoctest
julia> F, _ = finite_field(5)
(Finite field of characteristic 5, 1)
(Finite field of degree 1 over GF(5), 0)
julia> Ft, _ = F["t"]
(Univariate polynomial ring in t over GF(5), t)
Expand Down
6 changes: 3 additions & 3 deletions src/Misc/RatRecon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function _modp_results(g::QQPolyRingElem,f::QQPolyRingElem, p::ZZRingElem, M::In
l1 = fpPolyRingElem[]; l2 = fpPolyRingElem[];l3 = ZZRingElem[]
L = listprimes([f,g], p, M)
for j in 1:length(L)
Rp, t = polynomial_ring(GF(Int(L[j]), cached=false), cached=false)
Rp, t = polynomial_ring(Native.GF(Int(L[j]), cached=false), cached=false)
gp = Rp(g)
fp = Rp(f)
fl, nu_p, de_p = rational_reconstruction_subres(gp, fp, -1, ErrorTolerant = ErrorTolerant)
Expand Down Expand Up @@ -424,13 +424,13 @@ function _modpResults(f, p::ZZRingElem, M::Int)
Np = listprimes([f], p, M)
Zx, Y = polynomial_ring(FlintZZ, "Y", cached=false)
for j in 1:length(Np)
RNp = GF(Int(Np[j]), cached=false)
RNp = Native.GF(Int(Np[j]), cached=false)
Rp, t = polynomial_ring(RNp, "t", cached=false)
fp = Rp(f)
if degree(fp) != degree(f)
continue #bad prime...
end
L1 = Nemo.fpFieldElem[]
L1 = fpFieldElem[]
for i in 0:degree(fp)
push!(L1, coeff(fp, i))
end
Expand Down
14 changes: 0 additions & 14 deletions src/Misc/nmod_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1265,20 +1265,6 @@ function unit_group_1_part(f::fqPolyRepPolyRingElem, k::Int)
return gens, rels
end

#=
function FlintFiniteField(f::fqPolyRepPolyRingElem, s::AbstractString = "o"; cached::Bool = true, check::Bool = true)
if check && !is_irreducible(f)
error("poly not irreducible")
end
k = base_ring(f)
p = characteristic(k)
K, o = FlintFiniteField(p, degree(k)*degree(f), s, cached = cached)
r = roots(K, f)[1] # not working, embeddings are missing
fl || error("s.th. went wrong")
return K, r
end
=#

function euler_phi(f::T) where {T <: Union{fpPolyRingElem, fqPolyRepPolyRingElem, FpPolyRingElem}}
lf = factor(f)
q = size(base_ring(f))
Expand Down
4 changes: 2 additions & 2 deletions src/NumField/NfAbs/Simplify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function _sieve_primitive_elements(B::Vector{nf_elem})

p, d = _find_prime(ZZPolyRingElem[f])

F = FlintFiniteField(p, d, "w", cached = false)[1]
F = Nemo.Native.finite_field(p, d, "w", cached = false)[1]
Ft = polynomial_ring(F, "t", cached = false)[1]
ap = zero(Ft)
fit!(ap, degree(K)+1)
Expand Down Expand Up @@ -352,7 +352,7 @@ function polredabs(K::AnticNumberField)
f = Zx(K.pol)
p, d = _find_prime(ZZPolyRingElem[f])

F = FlintFiniteField(p, d, "w", cached = false)[1]
F = Native.finite_field(p, d, "w", cached = false)[1]
Ft = polynomial_ring(F, "t", cached = false)[1]
ap = zero(Ft)
fit!(ap, degree(K)+1)
Expand Down
Loading

0 comments on commit cb99cfd

Please sign in to comment.