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

Move obvious type piracy from Hecke to Nemo #1143

Merged
merged 11 commits into from
Jul 6, 2023
Merged
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
AbstractAlgebra = "^0.30.4"
Nemo = "^0.34.1"
Nemo = "^0.35.0"
RandomExtensions = "0.4.3"
Requires = "^0.5.2, 1.0"
julia = "1.6"
2 changes: 1 addition & 1 deletion examples/Round2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ end

function Hecke.powermod(a::OrderElem, n::ZZRingElem, p::RingElem)
c = parent(a)(1)
for i = Hecke.BitsMod.bits(n)
for i = Hecke.bits(n)
c *= c
if i
c *= a
Expand Down
2 changes: 0 additions & 2 deletions src/AlgAss/ChangeRing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ mutable struct AlgAssResMor{S, T, U, V} <: Map{S, T, HeckeMap, AlgAssResMor}
end
end

degree(::QQField) = 1

domain(f::AlgAssResMor) = f.domain

codomain(f::AlgAssResMor) = f.codomain
Expand Down
2 changes: 0 additions & 2 deletions src/AlgAssAbsOrd/Conjugacy/Husert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ function _explode(x::Generic.MatSpaceElem{nf_elem})
return z
end

Base.:(*)(x::QQFieldElem, y::AbstractAlgebra.Generic.MatSpaceElem{nf_elem}) = base_ring(y)(x) * y

function _to_absolute_basis(v, m, ns, Ks)
w = Vector{QQFieldElem}(undef, m)
k = 1
Expand Down
12 changes: 0 additions & 12 deletions src/AlgAssRelOrd/Eichler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ function _eichler_find_transforming_unit(I::AlgAssRelOrdIdl, J::AlgAssRelOrdIdl)
return t
end

degree(F::Union{ fpField, Generic.ResidueField{ZZRingElem} }) = 1

function get_coeff_fmpz!(x::fqPolyRepFieldElem, n::Int, z::ZZRingElem)
ccall((:fmpz_set_ui, libflint), Nothing, (Ref{ZZRingElem}, UInt), z, ccall((:nmod_poly_get_coeff_ui, libflint), UInt, (Ref{fqPolyRepFieldElem}, Int), x, n))
return z
Expand All @@ -218,16 +216,6 @@ function get_coeff_fmpz!(x::FqPolyRepFieldElem, n::Int, z::ZZRingElem)
return z
end

function lift!(x::fpFieldElem, z::ZZRingElem)
ccall((:fmpz_set_ui, libflint), Nothing, (Ref{ZZRingElem}, UInt), z, x.data)
return z
end

function lift!(x::Generic.ResidueFieldElem{ZZRingElem}, z::ZZRingElem)
ccall((:fmpz_set, libflint), Nothing, (Ref{ZZRingElem}, Ref{ZZRingElem}), z, x.data)
return z
end

# Let v and w be non-zero k \times 1-matrices over a finite field and let
# generators be a vector of invertible k \times k-matrices over this field.
# This functions finds a matrix g in the group generated by the elements in
Expand Down
4 changes: 0 additions & 4 deletions src/Aliases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
@alias isdefining_polynomial_nice is_defining_polynomial_nice
@alias isdefinite is_definite
@alias isdegenerate is_degenerate
@alias isdiagonal is_diagonal
@alias isdiagonalisable is_diagonalisable
@alias isdiscriminant is_discriminant
@alias isdivisible is_divisible
Expand Down Expand Up @@ -116,15 +115,13 @@
@alias islocally_isomorphic is_locally_isomorphic
@alias islocally_isomorphic_with_isomophism is_locally_isomorphic_with_isomophism
@alias islocally_represented_by is_locally_represented_by
@alias islower_triangular is_lower_triangular
@alias ismaximal is_maximal
@alias ismaximal_integral is_maximal_integral
@alias ismaximal_known is_maximal_known
@alias ismaximal_known_and_maximal is_maximal_known_and_maximal
@alias ismaximal_order_known is_maximal_order_known
@alias ismodular is_modular
@alias isnegative_definite is_negative_definite
@alias isnilpotent is_nilpotent
@alias isnorm is_norm
@alias isnorm_divisible is_norm_divisible
@alias isnorm_divisible_pp is_norm_divisible_pp
Expand All @@ -137,7 +134,6 @@
@alias isone_sided is_one_sided
@alias ispairwise_coprime is_pairwise_coprime
@alias ispositive_definite is_positive_definite
@alias ispositive_entry is_positive_entry
@alias ispower_trager is_power_trager
@alias ispower_unram is_power_unram
@alias isprimary is_primary
Expand Down
4 changes: 0 additions & 4 deletions src/EllCrv/EllCrv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1086,10 +1086,6 @@ end
#
################################################################################

function log(a::ZZRingElem, b::ZZRingElem)
log(b)/log(a)
end

function replace_all_squares_modulo(f, g, F)
# assumes that f is in Z[x,y^2] and g in Z[x]. Replaces y^2 with g.
# the result will be in Z[x]
Expand Down
11 changes: 0 additions & 11 deletions src/EllCrv/Heights.jl
Original file line number Diff line number Diff line change
Expand Up @@ -960,14 +960,3 @@ function refine_beta_bound(P::PolyElem, Q::PolyElem, E, mu::arb, a::arb, b::arb

return beta_bound
end

#This should probably go somewhere else. (Taking the nth derivative)
function derivative(x::acb_poly, n::Int64)
for i in (1:n)
x = derivative(x)
end
return x
end



23 changes: 0 additions & 23 deletions src/EllCrv/Misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ end
#
################################################################################

@doc raw"""
zeros(f::ZZPolyRingElem) -> Vector{ZZRingElem}

Computes the integer zeros of a given polynomial $f$.
"""
function zeros(f::ZZPolyRingElem)

fac = factor(f)
zeros = Nemo.ZZRingElem[]

# check if there are monic linear factors <-> zeros
for i in fac
if degree(i[1]) == 1 && leading_coefficient(i[1]) == 1
push!(zeros, -coeff(i[1],0))
end
end

return zeros
end


# @doc raw"""
# quadroots(a::ZZRingElem, b::ZZRingElem, c::ZZRingElem, p::ZZRingElem) -> Bool
Expand Down Expand Up @@ -234,9 +214,6 @@ function normal_basis(K::T, L::T) where T<:FinField
end


jacobi_symbol(x::Integer, y::ZZRingElem) = jacobi_symbol(ZZRingElem(x), y)


function mod(a::nf_elem, I::NfOrdIdl)
R = order(I)
k, phi = residue_field(R, I)
Expand Down
64 changes: 0 additions & 64 deletions src/GenOrd/Auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,6 @@ function hnf_modular(M::MatElem{T}, d::T, is_prime::Bool = false) where {T}
return H[1:ncols(M), :]
end

function Base.divrem(a::ZZModRingElem, b::ZZModRingElem)
R = parent(a)
r = rem(a, b)
return divexact(a-r, b), r
end

function Base.div(a::ZZModRingElem, b::ZZModRingElem)
R = parent(a)
r = rem(a, b)
return divexact(a-r, b)
end

function Base.rem(a::ZZModRingElem, b::ZZModRingElem)
R = parent(a)
r = R(rem(lift(a), gcd(modulus(R), lift(b))))
return r
end

function function_field(f::PolyElem{<:Generic.RationalFunctionFieldElem}, s::String = "_a"; check::Bool = true, cached::Bool = false)
return FunctionField(f, s, cached = cached)
end
Expand Down Expand Up @@ -153,21 +135,12 @@ function Hecke.discriminant(F::Generic.FunctionField)
return discriminant(defining_polynomial(F))
end

function (R::QQPolyRing)(a::Generic.RationalFunctionFieldElem{QQFieldElem})
@assert isone(denominator(a))
return R(numerator(a))
end

#######################################################################
#
# support for ZZ
#
#######################################################################

denominator(a::QQFieldElem, ::ZZRing) = denominator(a)

numerator(a::QQFieldElem, ::ZZRing) = numerator(a)

integral_split(a::QQFieldElem, ::ZZRing) = (numerator(a), denominator(a))

integral_split(a::Rational, R::ZZRing) = integral_split(QQFieldElem(a), R)
Expand Down Expand Up @@ -235,42 +208,6 @@ end

(R::Generic.RationalFunctionField{T})(x::KInftyElem{T}) where {T <: FieldElem} = x.d

base_ring_type(::Type{AbstractAlgebra.Generic.PolyRing{T}}) where {T} = parent_type(T)

base_ring_type(::Type{AcbPolyRing}) = AcbField

base_ring_type(::Type{ArbPolyRing}) = ArbField

base_ring_type(::Type{QQPolyRing}) = QQField

base_ring_type(::Type{ZZModPolyRing}) = Nemo.ZZModRing

base_ring_type(::Type{ZZPolyRing}) = ZZRing

base_ring_type(::Type{FqPolyRing}) = FqField

base_ring_type(::Type{fqPolyRepPolyRing}) = fqPolyRepField

base_ring_type(::Type{FqPolyRepPolyRing}) = FqPolyRepField

base_ring_type(::Type{FpPolyRing}) = Nemo.FpField

base_ring_type(::Type{fpPolyRing}) = Nemo.fpField

base_ring_type(::Type{zzModPolyRing}) = Nemo.zzModRing

function (R::Generic.PolyRing{T})(x::AbstractAlgebra.Generic.RationalFunctionFieldElem{T, U}) where {T <: RingElem, U}
@assert isone(denominator(x))
@assert parent(numerator(x)) === R
return numerator(x)
end

function (R::PolyRing{T})(x::AbstractAlgebra.Generic.RationalFunctionFieldElem{T, U}) where {T <: RingElem, U}
@assert isone(denominator(x))
@assert parent(numerator(x)) === R
return numerator(x)
end

# RationalFunctionFieldElem{T}, PolyRing{T}
function Hecke.numerator(a::Generic.RationalFunctionFieldElem{T}, S::PolyRing{T}) where {T}
return numerator(a)
Expand Down Expand Up @@ -339,7 +276,6 @@ function Hecke.integral_split(M::MatElem{<:AbstractAlgebra.FieldElem}, S::Generi
return m, den
end

Nemo.ngens(R::MPolyRing) = Nemo.nvars(R)
#TODO: move elsewhere?
function Hecke.lcm(a::Vector{<:RingElem})
if length(a) == 0
Expand Down
2 changes: 1 addition & 1 deletion src/GenOrd/GenOrd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ end

function powermod(a::GenOrdElem, n::ZZRingElem, p::RingElem)
c = one(parent(a))
for i = BitsMod.bits(n)
for i = bits(n)
c *= c
if i
c *= a
Expand Down
6 changes: 0 additions & 6 deletions src/GrpAb/SubgroupEnum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,6 @@ end
return true
end

#(::Colon)(x::Int, y::Nothing) = 1:0

Base.:(:)(x::Int, y::Nothing) = 1:0

Base.:(:)(x::Int, y::ZZRingElem) = ZZRingElem(x):y

function SigmaIteratorGivenY(s, x, y)
t = something(findlast(!iszero, y), 0)
SigmaIteratorGivenY(Iterators.filter(sigma -> _isvalid(s, t, x, y, sigma),
Expand Down
25 changes: 0 additions & 25 deletions src/GrpAb/stable_sub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,6 @@ function show(io::IO, M::ZpnGModule)
print(io, "Module over Z/", M.R.n, "Z with structure ", M.V)
end

#
# Lifts a matrix from F_p to Z/p^nZ
#

function lift(M::fqPolyRepMatrix, R::Nemo.zzModRing)
@hassert :StabSub 1 is_prime_power(modulus(R))
N=zero_matrix(R,nrows(M),ncols(M))
for i=1:nrows(M)
for j=1:ncols(M)
N[i,j]=FlintZZ(coeff(M[i,j],0))
end
end
return N
end

function lift(M::fpMatrix, R::Nemo.zzModRing)
@hassert :StabSub 1 is_prime_power(modulus(R))
N=zero_matrix(R, nrows(M), ncols(M))
for i=1:nrows(M)
for j=1:ncols(M)
N[i,j] = R(lift(M[i,j]))
end
end
return N
end

# Action of a matrix on an element of the group
function *(x::GrpAbFinGenElem, M::zzModMatrix)
Expand Down
5 changes: 2 additions & 3 deletions src/Hecke.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ import Nemo: acb_struct, Ring, Group, Field, zzModRing, zzModRingElem, arf_struc
elem_to_mat_row!, elem_from_mat_row, fpFieldElem, fpMatrix,
FpFieldElem, Zmodn_poly, Zmodn_mat, fpField,
FpField, acb_vec, array, acb_vec_clear, force_coerce,
force_op, fmpz_mod_ctx_struct, divisors, is_zero_entry, IntegerUnion
force_op, fmpz_mod_ctx_struct, divisors, is_zero_entry, IntegerUnion, remove!,
valuation!

export show, StepRange, domain, codomain, image, preimage, modord, resultant,
next_prime, is_power, number_field, factor, @vtime, RationalUnion
Expand Down Expand Up @@ -674,8 +675,6 @@ end

elem_type(::Type{FacElemMon{T}}) where {T} = FacElem{elem_type(T), T}

elem_type(::Type{Generic.ResidueRing{T}}) where {T} = Generic.ResidueRingElem{T}

################################################################################
#
# Aliases
Expand Down
6 changes: 0 additions & 6 deletions src/LinearAlgebra/FakeFmpqMat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,6 @@ function QQMatrix(x::FakeFmpqMat)
return z
end

function QQMatrix(x::ZZMatrix)
z = zero_matrix(FlintQQ, nrows(x), ncols(x))
ccall((:fmpq_mat_set_fmpz_mat, libflint), Nothing, (Ref{QQMatrix}, Ref{ZZMatrix}), z, x)
return z
end

function _fmpq_mat_to_fmpz_mat_den(x::QQMatrix)
z = zero_matrix(FlintZZ, nrows(x), ncols(x))
d = ZZRingElem()
Expand Down
36 changes: 0 additions & 36 deletions src/LinearAlgebra/Solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,7 @@ function modular_lift(ap::Vector{fqPolyRepMatrix}, me::modular_env)
return A
end

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

Inplace: reduce all entries of $A$ modulo $m$, into the positive residue system.
"""
function mod!(A::Generic.Mat{nf_elem}, m::ZZRingElem)
for i=1:nrows(A)
for j=1:ncols(A)
mod!(A[i, j], m)
end
end
end

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

Inplace: reduce all entries of $A$ modulo $m$, into the symmetric residue system.
"""
function mod_sym!(A::Generic.Mat{nf_elem}, m::ZZRingElem)
for i = 1:nrows(A)
for j = 1:ncols(A)
mod_sym!(A[i, j], m)
end
end
end

function small_coeff(a::nf_elem, B::ZZRingElem, i::Int)
z = ZZRingElem()
Expand Down Expand Up @@ -221,18 +197,6 @@ function denominator_ideal(M::Vector{nf_elem}, den::nf_elem)
return d
end

@doc raw"""
divexact!(A::Generic.Mat{nf_elem}, p::ZZRingElem)

Inplace: divide each entry of $A$ by $p$.
"""
function divexact!(A::Generic.Mat{nf_elem}, p::ZZRingElem)
for i=1:nrows(A)
for j=1:ncols(A)
A[i,j] = A[i,j]//p
end
end
end

#TODO/ To experiment:
# - vector reconstruction ala Storjohan
Expand Down
Loading