Skip to content
Open
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
104 changes: 7 additions & 97 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ function prime_field(F::FqPolyRepField; cached::Bool=true)
return Native.GF(characteristic(F), cached=cached)
end

function prime_field(F::T; cached::Bool=true) where {T<:Union{fpField,FpField}}
return F
end
prime_field(F::FpField; cached::Bool=true) = F

function evaluate(f::ZZPolyRingElem, r::fqPolyRepFieldElem)
#Horner - stolen from Claus
Expand Down Expand Up @@ -94,6 +92,7 @@ function roots(f::ZZModPolyRingElem, p::ZZRingElem, e::Int)
F[p] = e
return roots(f, F)
end

function roots(f::ZZModPolyRingElem, fac::Fac{ZZRingElem})
res = fmpz_mod_poly_factor(base_ring(f))
_fac = fmpz_factor()
Expand Down Expand Up @@ -231,27 +230,6 @@ function evaluate(f::QQPolyRingElem, r::T) where {T<:RingElem}
return s
end

function mod!(f::ZZPolyRingElem, p::ZZRingElem)
for i = 0:degree(f)
setcoeff!(f, i, mod(coeff(f, i), p))
end
end

function mod(f::ZZPolyRingElem, p::ZZRingElem)
g = parent(f)()
for i = 0:degree(f)
setcoeff!(g, i, mod(coeff(f, i), p))
end
return g
end

#Assuming that the denominator of a is one, reduces all the coefficients modulo p
# non-symmetric (positive) residue system
function mod!(a::AbsSimpleNumFieldElem, b::ZZRingElem)
@ccall libflint.nf_elem_mod_fmpz(a::Ref{AbsSimpleNumFieldElem}, a::Ref{AbsSimpleNumFieldElem}, b::Ref{ZZRingElem}, parent(a)::Ref{AbsSimpleNumField})::Nothing
return a
end

@doc raw"""
numerator(a::AbsSimpleNumFieldElem) -> AbsSimpleNumFieldElem

Expand All @@ -266,14 +244,6 @@ function numerator(a::AbsSimpleNumFieldElem)
return z
end

function lift(R::ZZAbsPowerSeriesRing, f::ZZModAbsPowerSeriesRingElem)
r = R()
for i = 0:length(f)-1
setcoeff!(r, i, lift(coeff(f, i)))
end
return r
end

function evaluate(f::fpPolyRingElem, v::Vector{fpFieldElem})
F = base_ring(f)
v1 = UInt[x.data for x in v]
Expand Down Expand Up @@ -324,35 +294,11 @@ function inv(f::T) where {T<:Union{ZZModPolyRingElem,zzModPolyRingElem}}
return g
end

function invmod(f::ZZModPolyRingElem, M::ZZModPolyRingElem)
if !is_unit(f)
r = parent(f)()
ff = ZZ()
i = @ccall libflint.fmpz_mod_poly_invmod_f(ff::Ref{ZZRingElem}, r::Ref{ZZModPolyRingElem}, f::Ref{ZZModPolyRingElem}, M::Ref{ZZModPolyRingElem}, f.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Int
if iszero(i)
error("not yet implemented")
else
return r
end
end
if !is_unit(leading_coefficient(M))
error("not yet implemented")
end
g = parent(f)(inv(constant_coefficient(f)))
#lifting: to invert a, start with an inverse b mod m, then
# then b -> b*(2-ab) is an inverse mod m^2
# starting with this g, and using the fact that all coeffs are nilpotent
# we have an inverse modulo s.th. nilpotent. Hence it works
c = f * g
rem!(c, c, M)
while !isone(c)
mul!(g, g, 2 - c)
rem!(g, g, M)
mul!(c, f, g)
rem!(c, c, M)
end
return g
end
################################################################################
#
#
#
################################################################################

function round!(z::ArbFieldElem, x::ArbFieldElem, p::Int)
@ccall libflint.arb_set_round(z::Ref{ArbFieldElem}, x::Ref{ArbFieldElem}, p::Int)::Nothing
Expand Down Expand Up @@ -438,10 +384,6 @@ function size(F::FqField)
return order(F)
end

function order(R::zzModRing)
return ZZRingElem(R.n)
end

#################################################
# in triplicate.... and probably cases missing...
function elem_to_mat_row!(M::MatElem, i::Int, a::ResElem{T}) where {T<:PolyRingElem}
Expand Down Expand Up @@ -640,19 +582,6 @@ function image(M::Map{D,C}, a) where {D,C}
end
end

function setcoeff!(x::fqPolyRepFieldElem, n::Int, u::UInt)
@ccall libflint.nmod_poly_set_coeff_ui(x::Ref{fqPolyRepFieldElem}, n::Int, u::UInt)::Nothing
end

function basis(k::fpField)
return [k(1)]
end

function basis(k::fpField, l::fpField)
@assert k == l
return [k(1)]
end

function basis(K::fqPolyRepField, k::fpField)
@assert characteristic(K) == characteristic(k)
return basis(K)
Expand All @@ -673,15 +602,6 @@ function base_field(K::fqPolyRepField)
return Native.GF(Int(characteristic(K)))
end

function gen(k::fpField)
return k(1)
end

function defining_polynomial(k::fpField)
kx, x = polynomial_ring(k, cached=false)
return x - k(1)
end

@doc raw"""
mod!(A::Generic.Mat{AbsSimpleNumFieldElem}, m::ZZRingElem)

Expand Down Expand Up @@ -928,16 +848,6 @@ function (R::FqPolyRepField)(x::FpPolyRingElem)
return z
end

function rem!(a::ZZModPolyRingElem, b::ZZModPolyRingElem, c::ZZModPolyRingElem)
@ccall libflint.fmpz_mod_poly_rem(a::Ref{ZZModPolyRingElem}, b::Ref{ZZModPolyRingElem}, c::Ref{ZZModPolyRingElem}, a.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Nothing
return a
end

function rem!(a::FpPolyRingElem, b::FpPolyRingElem, c::FpPolyRingElem)
@ccall libflint.fmpz_mod_poly_rem(a::Ref{FpPolyRingElem}, b::Ref{FpPolyRingElem}, c::Ref{FpPolyRingElem}, a.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Nothing
return a
end

########################################
#
# misc infinity changes that need to stay in Nemo (after moving the rest to AA) # TODO: move somewhere sensible
Expand Down
7 changes: 7 additions & 0 deletions src/antic/nf_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,13 @@ base_field(::AbsSimpleNumField) = QQ
#
###############################################################################

#Assuming that the denominator of a is one, reduces all the coefficients modulo p
# non-symmetric (positive) residue system
function mod!(a::AbsSimpleNumFieldElem, b::ZZRingElem)
@ccall libflint.nf_elem_mod_fmpz(a::Ref{AbsSimpleNumFieldElem}, a::Ref{AbsSimpleNumFieldElem}, b::Ref{ZZRingElem}, parent(a)::Ref{AbsSimpleNumField})::Nothing
return a
end

function mod_sym!(a::AbsSimpleNumFieldElem, b::ZZRingElem)
@ccall libflint.nf_elem_smod_fmpz(a::Ref{AbsSimpleNumFieldElem}, a::Ref{AbsSimpleNumFieldElem}, b::Ref{ZZRingElem}, parent(a)::Ref{AbsSimpleNumField})::Nothing
return a
Expand Down
14 changes: 14 additions & 0 deletions src/flint/fmpz_mod_abs_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,20 @@ for (etype, rtype, ctype, mtype, brtype) in (
end # eval
end # for

################################################################################
#
# Lifting
#
################################################################################

function lift(R::ZZAbsPowerSeriesRing, f::ZZModAbsPowerSeriesRingElem)
r = R()
for i = 0:length(f)-1
setcoeff!(r, i, lift(coeff(f, i)))
end
return r
end

###############################################################################
#
# Square root
Expand Down
40 changes: 40 additions & 0 deletions src/flint/fmpz_mod_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,16 @@ end

mod(x::T, y::T) where {T <: Zmodn_fmpz_poly} = rem(x, y)

function rem!(a::ZZModPolyRingElem, b::ZZModPolyRingElem, c::ZZModPolyRingElem)
@ccall libflint.fmpz_mod_poly_rem(a::Ref{ZZModPolyRingElem}, b::Ref{ZZModPolyRingElem}, c::Ref{ZZModPolyRingElem}, a.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Nothing
return a
end

function rem!(a::FpPolyRingElem, b::FpPolyRingElem, c::FpPolyRingElem)
@ccall libflint.fmpz_mod_poly_rem(a::Ref{FpPolyRingElem}, b::Ref{FpPolyRingElem}, c::Ref{FpPolyRingElem}, a.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Nothing
return a
end

################################################################################
#
# Removal and valuation
Expand Down Expand Up @@ -506,6 +516,36 @@ function invmod(x::T, y::T) where {T <: Zmodn_fmpz_poly}
r == 0 ? error("Impossible inverse in invmod") : return z
end

function invmod(f::ZZModPolyRingElem, M::ZZModPolyRingElem)
if !is_unit(f)
r = parent(f)()
ff = ZZ()
i = @ccall libflint.fmpz_mod_poly_invmod_f(ff::Ref{ZZRingElem}, r::Ref{ZZModPolyRingElem}, f::Ref{ZZModPolyRingElem}, M::Ref{ZZModPolyRingElem}, f.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Int
if iszero(i)
error("not yet implemented")
else
return r
end
end
if !is_unit(leading_coefficient(M))
error("not yet implemented")
end
g = parent(f)(inv(constant_coefficient(f)))
#lifting: to invert a, start with an inverse b mod m, then
# then b -> b*(2-ab) is an inverse mod m^2
# starting with this g, and using the fact that all coeffs are nilpotent
# we have an inverse modulo s.th. nilpotent. Hence it works
c = f * g
rem!(c, c, M)
while !isone(c)
mul!(g, g, 2 - c)
rem!(g, g, M)
mul!(c, f, g)
rem!(c, c, M)
end
return g
end

function mulmod(x::T, y::T, z::T) where {T <: Zmodn_fmpz_poly}
check_parent(x, y)
check_parent(y, z)
Expand Down
14 changes: 14 additions & 0 deletions src/flint/fmpz_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,20 @@ end

divexact(x::ZZPolyRingElem, y::Integer; check::Bool=true) = divexact(x, flintify(y); check=check)

function mod!(f::ZZPolyRingElem, p::ZZRingElem)
for i = 0:degree(f)
setcoeff!(f, i, mod(coeff(f, i), p))
end
end

function mod(f::ZZPolyRingElem, p::ZZRingElem)
g = parent(f)()
for i = 0:degree(f)
setcoeff!(g, i, mod(coeff(f, i), p))
end
return g
end

###############################################################################
#
# Pseudodivision
Expand Down
15 changes: 10 additions & 5 deletions src/flint/fq_nmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,33 @@ function coeffs_raw(x::fqPolyRepFieldElem)
return Vcopy
end

function setcoeff!(x::fqPolyRepFieldElem, n::Int, u::UInt)
@ccall libflint.nmod_poly_set_coeff_ui(x::Ref{fqPolyRepFieldElem}, n::Int, u::UInt)::Nothing
return x
end

# set the i-th coeff of x to c, internal use only
function setindex_raw!(x::fqPolyRepFieldElem, c::UInt, i::Int)
len = degree(parent(x))
i > len - 1 && error("Index out of range")
@ccall libflint.nmod_poly_set_coeff_ui(x::Ref{fqPolyRepFieldElem}, i::Int, c::UInt)::Nothing
setcoeff!(x, i, c)
return x
end

zero(a::fqPolyRepField) = zero!(a())

one(a::fqPolyRepField) = one!(a())

iszero(a::fqPolyRepFieldElem) = @ccall libflint.fq_nmod_is_zero(a::Ref{fqPolyRepFieldElem}, a.parent::Ref{fqPolyRepField})::Bool

isone(a::fqPolyRepFieldElem) = @ccall libflint.fq_nmod_is_one(a::Ref{fqPolyRepFieldElem}, a.parent::Ref{fqPolyRepField})::Bool

function gen(a::fqPolyRepField)
d = a()
@ccall libflint.fq_nmod_gen(d::Ref{fqPolyRepFieldElem}, a::Ref{fqPolyRepField})::Nothing
return d
end

iszero(a::fqPolyRepFieldElem) = @ccall libflint.fq_nmod_is_zero(a::Ref{fqPolyRepFieldElem}, a.parent::Ref{fqPolyRepField})::Bool

isone(a::fqPolyRepFieldElem) = @ccall libflint.fq_nmod_is_one(a::Ref{fqPolyRepFieldElem}, a.parent::Ref{fqPolyRepField})::Bool

is_gen(a::fqPolyRepFieldElem) = a == gen(parent(a)) # there is no is_gen in flint

function characteristic(a::fqPolyRepField)
Expand Down
26 changes: 26 additions & 0 deletions src/flint/gfp_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ characteristic(R::fpField) = ZZRingElem(R.n)

degree(::fpField) = 1

function gen(k::fpField)
return k(1)
end

prime_field(F::fpField; cached::Bool=true) = F

function defining_polynomial(k::fpField)
kx, x = polynomial_ring(k, cached=false)
return x - k(1)
end

################################################################################
#
# Basis
#
################################################################################

function basis(k::fpField)
return [k(1)]
end

function basis(k::fpField, l::fpField)
@assert k == l
return [k(1)]
end

###############################################################################
#
# AbstractString I/O
Expand Down
2 changes: 2 additions & 0 deletions src/flint/nmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ isone(a::zzModRingElem) = (a.parent.n == 1) || (a.data == 1)

modulus(R::zzModRing) = R.n

order(R::zzModRing) = ZZRingElem(R.n)

function krull_dim(R::zzModRing)
is_trivial(R) && return -inf
return 0
Expand Down
Loading