Skip to content

Commit

Permalink
Remove more obvious piracy from different places now in Nemo
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Jul 2, 2023
1 parent d13daa2 commit 6a89741
Show file tree
Hide file tree
Showing 28 changed files with 27 additions and 331 deletions.
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
37 changes: 0 additions & 37 deletions src/GenOrd/Auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,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 @@ -312,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
4 changes: 0 additions & 4 deletions src/LocalField/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ function Base.setprecision(a::LocalFieldElem, n::Int)
return setprecision!(b, n)
end

function setprecision!(a::padic, n::Int)
return setprecision(a, n)
end

function setprecision!(a::LocalFieldElem, n::Int)
K = parent(a)
e = ramification_index(K)
Expand Down
12 changes: 0 additions & 12 deletions src/LocalField/LocalField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,6 @@ function setprecision(f::Function, K::Union{LocalField, FlintPadicField, FlintQa
return v
end

function setprecision(f::Function, K::Union{FlintPadicField, FlintQadicField}, n::Int)
old = precision(K)
# @assert n>=0
setprecision!(K, n)
v = try
f()
finally
setprecision!(K, old)
end
return v
end


################################################################################
#
Expand Down
14 changes: 1 addition & 13 deletions src/LocalField/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ add_assertion_scope(:padic_poly)
#
################################################################################

function setprecision!(f::Generic.Poly{qadic}, N::Int)
for i=1:length(f)
setprecision!(f.coeffs[i], N)
end
set_length!(f, normalise(f, length(f)))
return f
end

function Base.setprecision(f::Generic.Poly{qadic}, N::Int)
g = map_coefficients(x->setprecision(x, N), f, parent = parent(f))
return g
end

function setprecision_fixed_precision(f::Generic.Poly{qadic}, N::Int)
f = setprecision(f, N)
Expand Down Expand Up @@ -158,7 +146,7 @@ function _content(f::Generic.Poly{T}) where T <: Union{padic, qadic, LocalFieldE
return uniformizer(K)^numerator(e)
end

function rem!(x::AbstractAlgebra.Generic.Poly{T}, y::AbstractAlgebra.Generic.Poly{T}, z::AbstractAlgebra.Generic.Poly{T}) where T <:Union{padic, qadic, LocalFieldElem}
function rem!(x::AbstractAlgebra.Generic.Poly{T}, y::AbstractAlgebra.Generic.Poly{T}, z::AbstractAlgebra.Generic.Poly{T}) where {T<:LocalFieldElem}
x = rem(y, z)
return x
end
Expand Down
14 changes: 7 additions & 7 deletions src/Map/NfOrd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ function image(mF::NfToFqNmodMor_easy, a::FacElem{nf_elem, AnticNumberField}, D:

if !((quo != 0 && vv != 0) || !iszero(v))
if !cached
nf_elem_to_gfp_poly!(t, k)
Nemo.nf_elem_to_gfp_poly!(t, k)
D[i] = zero(parent(t))
set!(D[i], t)
end
Expand All @@ -996,7 +996,7 @@ function image(mF::NfToFqNmodMor_easy, a::FacElem{nf_elem, AnticNumberField}, D:
(Ref{fqPolyRepFieldElem}, Ref{fpPolyRingElem}, Ref{fqPolyRepField}), s, D[i], Fq)
_reduce(s)
else
nf_elem_to_gfp_poly!(t, k)
Nemo.nf_elem_to_gfp_poly!(t, k)
#tt = deepcopy(t)
if isassigned(D, i)
y = D[i]
Expand Down Expand Up @@ -1055,13 +1055,13 @@ function image(mF::NfToFqNmodMor_easy, a::nf_elem, n_quo::Int = 0)
end

function _nf_to_gfp_elem(b::nf_elem, a_tmp::fpPolyRingElem, def_pol::fpPolyRingElem)
nf_elem_to_gfp_poly!(a_tmp, b)
Nemo.nf_elem_to_gfp_poly!(a_tmp, b)
rem!(a_tmp, a_tmp, def_pol)
return coeff(a_tmp, 0)
end

function _nf_to_gfp_elem(b::nf_elem, a_tmp::FpPolyRingElem, def_pol::FpPolyRingElem)
nf_elem_to_gfp_fmpz_poly!(a_tmp, b)
Nemo.nf_elem_to_gfp_fmpz_poly!(a_tmp, b)
rem!(a_tmp, a_tmp, def_pol)
return coeff(a_tmp, 0)
end
Expand Down Expand Up @@ -1145,15 +1145,15 @@ function image(mF::NfToGFMor_easy, a::FacElem{nf_elem, AnticNumberField}, D::Vec

if iszero(vv) && !cached
D[i] = zero(parent(t))
nf_elem_to_gfp_poly!(t, k)
Nemo.nf_elem_to_gfp_poly!(t, k)
set!(D[i], t)
end

if !iszero(vv)
if cached
s = evaluate_raw(D[i], evaluateat)
else
nf_elem_to_gfp_poly!(t, k)
Nemo.nf_elem_to_gfp_poly!(t, k)
#tt = deepcopy(t)
if isassigned(D, i)
y = D[i]
Expand Down Expand Up @@ -1215,7 +1215,7 @@ function image(mF::NfToGFMor_easy, a::nf_elem, D::Vector, cached::Bool, n_quo::I
#rem!(t, D[1], p)
#s = coeff(t, 0)
else
nf_elem_to_gfp_poly!(t, a)
Nemo.nf_elem_to_gfp_poly!(t, a)
D[1] = deepcopy(t)
#rem!(t, t, p)
#s = coeff(t, 0)
Expand Down
19 changes: 2 additions & 17 deletions src/Misc/CRT.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import Nemo.crt, Nemo.zero, Nemo.iszero, Nemo.isone, Nemo.sub!
export crt_env, crt, crt_inv, modular_init, crt_signed

@inline function rem!(a::ZZRingElem, b::ZZRingElem, c::ZZRingElem)
ccall((:fmpz_mod, libflint), Nothing, (Ref{ZZRingElem}, Ref{ZZRingElem}, Ref{ZZRingElem}), a, b, c)
return a
end

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

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

mutable struct crt_env{T}
pr::Vector{T}
id::Vector{T}
Expand Down Expand Up @@ -778,7 +763,7 @@ end
@inbounds function inner_eval(z::Vector{Tuple{fqPolyRepFieldElem, ZZRingElem, Int}})
sort!(z, lt = (a,b) -> isless(b[2], a[2]))
t = z[1][3] #should be largest...
it = [BitsMod.bits(i[2]) for i=z]
it = [bits(i[2]) for i=z]
is = map(iterate, it)
u = one(z[1][1])
K = parent(u)
Expand Down Expand Up @@ -860,7 +845,7 @@ function modular_proj(a::Generic.Poly{nf_elem}, me::modular_env)
if iszero(mod(denominator(c), me.p))
throw(BadPrime(me.p))
end
nf_elem_to_nmod_poly!(r, c, true)
Nemo.nf_elem_to_nmod_poly!(r, c, true)
crt_inv!(me.rp, r, me.ce)
for j=1:me.ce.n
u = coeff(me.Rp[j], i)
Expand Down
19 changes: 3 additions & 16 deletions src/Misc/FiniteField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ function _reduce(a::FqPolyRepFieldElem)
#end
end

function (R::FqPolyRepField)(x::ZZModPolyRingElem)
z = R()
ccall((:fq_set_fmpz_mod_poly, libflint), Nothing, (Ref{Nemo.FqPolyRepFieldElem}, Ref{Nemo.ZZModPolyRingElem}, Ref{Nemo.FqPolyRepField}), z, x, R)
#ccall((:fq_reduce, libflint), Nothing, (Ref{Nemo.FqPolyRepFieldElem}, Ref{Nemo.FqPolyRepField}), z, R)
return z
end

function (R::FqPolyRepField)(x::FpPolyRingElem)
z = R()
ccall((:fq_set_fmpz_mod_poly, libflint), Nothing, (Ref{Nemo.FqPolyRepFieldElem}, Ref{Nemo.FpPolyRingElem}, Ref{Nemo.FqPolyRepField}), z, x, R)
ccall((:fq_reduce, libflint), Nothing, (Ref{Nemo.FqPolyRepFieldElem}, Ref{Nemo.FqPolyRepField}), z, R)
return z
end

#TODO: move elsewhere - and use. There are more calls to nmod_set/reduce
function (A::fqPolyRepField)(x::zzModPolyRingElem)
Expand All @@ -51,23 +38,23 @@ function (A::fqPolyRepField)(x::fpPolyRingElem)
end

function _nf_to_fq!(a::fqPolyRepFieldElem, b::nf_elem, K::fqPolyRepField, a_tmp::zzModPolyRingElem)
nf_elem_to_nmod_poly!(a_tmp, b)
Nemo.nf_elem_to_nmod_poly!(a_tmp, b)
ccall((:fq_nmod_set, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{zzModPolyRingElem}, Ref{fqPolyRepField}),
a, a_tmp, K)
_reduce(a)
end

function _nf_to_fq!(a::fqPolyRepFieldElem, b::nf_elem, K::fqPolyRepField, a_tmp::fpPolyRingElem)
nf_elem_to_gfp_poly!(a_tmp, b)
Nemo.nf_elem_to_gfp_poly!(a_tmp, b)
ccall((:fq_nmod_set, libflint), Nothing,
(Ref{fqPolyRepFieldElem}, Ref{fpPolyRingElem}, Ref{fqPolyRepField}),
a, a_tmp, K)
_reduce(a)
end

function _nf_to_fq!(a::FqPolyRepFieldElem, b::nf_elem, K::FqPolyRepField, a_tmp::FpPolyRingElem)
nf_elem_to_gfp_fmpz_poly!(a_tmp, b)
Nemo.nf_elem_to_gfp_fmpz_poly!(a_tmp, b)
ccall((:fq_set, libflint), Nothing,
(Ref{FqPolyRepFieldElem}, Ref{FpPolyRingElem}, Ref{FqPolyRepField}),
a, a_tmp, K)
Expand Down
24 changes: 0 additions & 24 deletions src/Misc/Integer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,6 @@ function fdiv_qr_with_preinvn!(q::ZZRingElem, r::ZZRingElem, g::ZZRingElem, h::Z
ccall((:fmpz_fdiv_qr_preinvn, libflint), Nothing, (Ref{ZZRingElem}, Ref{ZZRingElem}, Ref{ZZRingElem}, Ref{ZZRingElem}, Ref{fmpz_preinvn_struct}), q, r, g, h, hinv)
end

function submul!(z::ZZRingElem, x::ZZRingElem, y::ZZRingElem)
ccall((:fmpz_submul, libflint), Nothing, (Ref{ZZRingElem}, Ref{ZZRingElem}, Ref{ZZRingElem}), z, x, y)
end


################################################################################
#
# Modular reduction with symmetric residue system
#
################################################################################

function mod_sym(a::ZZRingElem, b::ZZRingElem)
c = mod(a, b)
@assert c >= 0
if b > 0 && 2 * c > b
return c - b
elseif b < 0 && 2 * c > -b
return c + b
else
return c
end
end


################################################################################
#
# sunit group
Expand Down
21 changes: 1 addition & 20 deletions src/Misc/RelFiniteField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,13 @@ function (F::fpField)(a::RelFinFieldElem)
return F(coeff(a, 0))
end

function (F::fpField)(a::fqPolyRepFieldElem)
for i = 1:degree(parent(a))-1
@assert iszero(coeff(a, i))
end
return F(coeff(a, 0))
end

function (F::FpField)(a::RelFinFieldElem)
for i = 1:degree(parent(a))-1
@assert iszero(coeff(a, i))
end
return F(coeff(a, 0))
end

function (F::FpField)(a::FqPolyRepFieldElem)
for i = 1:degree(parent(a))-1
@assert iszero(coeff(a, i))
end
return F(coeff(a, 0))
end

################################################################################
#
Expand Down Expand Up @@ -765,13 +752,7 @@ function is_irreducible(f::PolyElem{T}) where T <: RelFinFieldElem
return length(l.fac) == 1
end

function (Rx::fpPolyRing)(a::fqPolyRepFieldElem)
el = Rx()
for i = 0:degree(parent(a))
setcoeff!(el, i, base_ring(Rx)(coeff(a, i)))
end
return el
end


function norm(f::PolyElem{fqPolyRepFieldElem})
Fx = parent(f)
Expand Down
9 changes: 0 additions & 9 deletions src/Misc/Series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,6 @@ function Hecke.residue_field(S::SeriesRing{T}) where {T <: Nemo.RingElem} #darn
return k, MapFromFunc(x -> coeff(x, 0), y -> set_precision(S(y), 1), S, k)
end

#TODO: in Nemo, rename to setprecision
# fix/report series add for different length
function set_precision(a::SeriesElem, i::Int)
b = deepcopy(a)
set_precision!(b, i)
return b
end


function rational_reconstruction(a::SeriesElem; parent::PolyRing = polynomial_ring(base_ring(a), cached = false)[1])
C = base_ring(a)
Ct = parent
Expand Down
4 changes: 0 additions & 4 deletions src/Misc/acb_root_ctx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ function set!(z::arb, x::arb)
return z
end

function bits(x::acb)
return ccall((:acb_bits, libarb), Int, (Ref{Nemo.acb}, ), x)
end

function rel_error_bits(x::acb)
return ccall((:acb_rel_error_bits, libarb), Int, (Ref{Nemo.acb}, ), x)
end
Expand Down
Loading

0 comments on commit 6a89741

Please sign in to comment.