Skip to content

Commit

Permalink
Remove obvious piracy from different places now in Nemo
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Jun 29, 2023
1 parent d2a55de commit 531a41d
Show file tree
Hide file tree
Showing 30 changed files with 3 additions and 553 deletions.
20 changes: 0 additions & 20 deletions src/Misc/ResidueRingPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,3 @@ function gcd!(f::Nemo.fpPolyRingElem, g::Nemo.fpPolyRingElem, h::Nemo.fpPolyRing
ccall((:nmod_poly_gcd, libflint), Nothing, (Ref{Nemo.fpPolyRingElem}, Ref{Nemo.fpPolyRingElem}, Ref{Nemo.fpPolyRingElem}), f, g, h)
return f
end

function (R::Nemo.zzModPolyRing)(g::QQPolyRingElem)
return fmpq_poly_to_nmod_poly(R, g)
end

function (R::Nemo.fpPolyRing)(g::QQPolyRingElem)
return fmpq_poly_to_gfp_poly(R, g)
end

function (R::Nemo.ZZModPolyRing)(g::QQPolyRingElem)
return fmpq_poly_to_fmpz_mod_poly(R, g)
end

function (R::Nemo.FpPolyRing)(g::QQPolyRingElem)
return fmpq_poly_to_gfp_fmpz_poly(R, g)
end

function (R::Nemo.FqPolyRing)(g::QQPolyRingElem)
return fmpq_poly_to_fq_default_poly(R, g)
end
25 changes: 0 additions & 25 deletions src/NumField/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,6 @@ export coordinates, absolute_coordinates, absolute_norm, absolute_tr,
#
################################################################################

is_unit(a::NumFieldElem) = !iszero(a)

canonical_unit(a::NumFieldElem) = a

################################################################################
#
# Base case for dot products
#
################################################################################

dot(x::ZZRingElem, y::NumFieldElem) = x * y

dot(x::Integer, y::NumFieldElem) = x * y

dot(x::NumFieldElem, y::Integer) = x * y

function dot(a::Vector{<: NumFieldElem}, b::Vector{ZZRingElem})
d = zero(parent(a[1]))
t = zero(d)
for i=1:length(a)
mul!(t, a[i], b[i])
add!(d, d, t)
end
return d
end

function dot(a::Vector{NfAbsNSElem}, b::Vector{ZZRingElem})
Qxy = parent(a[1].data)
Expand Down
21 changes: 0 additions & 21 deletions src/NumField/Field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,29 +205,8 @@ function is_normal_basis_generator(a::NumFieldElem)
return rank(A) == n
end

#trivia to make life easier

gens(L::SimpleNumField{T}) where {T} = [gen(L)]

function gen(L::SimpleNumField{T}, i::Int) where {T}
i == 1 || error("index must be 1")
return gen(L)
end

gen(L::NonSimpleNumField{T}, i::Int) where {T} = L(gen(parent(L.pol[1]), i))

function Base.getindex(L::SimpleNumField{T}, i::Int) where {T}
if i == 0
return one(L)
elseif i == 1
return gen(L)
else
error("index has to be 0 or 1")
end
end

ngens(L::SimpleNumField{T}) where {T} = 1

function Base.getindex(L::NonSimpleNumField{T}, i::Int) where {T}
i == 0 && return one(L)
return gen(L, i)
Expand Down
69 changes: 0 additions & 69 deletions src/NumField/NfAbs/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,75 +53,6 @@ function basis_matrix(A::Vector{nf_elem})
return M
end

################################################################################
#
# Characteristic polynomial
#
################################################################################

function charpoly(Qx::QQPolyRing, a::nf_elem)
f = charpoly(Qx, representation_matrix(a))
return f
end

function charpoly(a::nf_elem)
f = charpoly(parent(parent(a).pol), a)
return f
end

function charpoly(a::nf_elem, ::QQField)
return charpoly(a)
end

function charpoly(Zx::ZZPolyRing, a::nf_elem)
f = charpoly(a)
if !isone(denominator(f))
error("Element is not integral")
end
return Zx(f)
end

function charpoly(a::nf_elem, Z::ZZRing)
return charpoly(polynomial_ring(Z, cached = false)[1], a)
end

################################################################################
#
# Minimal polynomial
#
################################################################################

@doc raw"""
minpoly(a::nf_elem) -> QQPolyRingElem
The minimal polynomial of $a$.
"""
function minpoly(Qx::QQPolyRing, a::nf_elem)
f = minpoly(Qx, representation_matrix(a))
return f
end

function minpoly(a::nf_elem)
f = minpoly(parent(parent(a).pol), a)
return f
end

function minpoly(a::nf_elem, ::QQField)
return minpoly(a)
end

function minpoly(a::nf_elem, ZZ::ZZRing)
return minpoly(polynomial_ring(ZZ, cached = false)[1], a)
end

function minpoly(Zx::ZZPolyRing, a::nf_elem)
f = minpoly(a)
if !isone(denominator(f))
error("Element is not integral")
end
return Zx(f)
end

################################################################################
#
# Unsafe operations
Expand Down
49 changes: 0 additions & 49 deletions src/NumField/NfAbs/NfAbs.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
export splitting_field, is_subfield, is_defining_polynomial_nice,
quadratic_field, is_linearly_disjoint, rationals_as_number_field

################################################################################
#
# Base field
#
################################################################################

base_field(K::AnticNumberField) = FlintQQ

################################################################################
#
# Order type
Expand Down Expand Up @@ -244,24 +236,6 @@ function relative_class_number(K::AnticNumberField)
return divexact(h, hp)
end

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

function basis(K::AnticNumberField)
n = degree(K)
g = gen(K);
d = Array{typeof(g)}(undef, n)
b = K(1)
for i = 1:n-1
d[i] = b
b *= g
end
d[n] = b
return d
end

################################################################################
#
Expand Down Expand Up @@ -797,8 +771,6 @@ function splitting_field(fl::Vector{QQPolyRingElem}; coprime::Bool = false, do_r
end
end


copy(f::QQPolyRingElem) = parent(f)(f)
gcd_into!(a::QQPolyRingElem, b::QQPolyRingElem, c::QQPolyRingElem) = gcd(b, c)

@doc raw"""
Expand Down Expand Up @@ -895,14 +867,6 @@ function _splitting_field(fl::Vector{<:PolyElem{<:NumFieldElem}}; do_roots::Type
end
end

function Base.:(^)(a::nf_elem, e::UInt)
b = parent(a)()
ccall((:nf_elem_pow, libantic), Nothing,
(Ref{nf_elem}, Ref{nf_elem}, UInt, Ref{AnticNumberField}),
b, a, e, parent(a))
return b
end


@doc raw"""
normal_closure(K::AnticNumberField) -> AnticNumberField, NfToNfMor
Expand All @@ -915,15 +879,6 @@ function normal_closure(K::AnticNumberField)
return s, hom(K, s, r, check = false)
end

function set_name!(K::AnticNumberField, s::String)
set_attribute!(K, :name => s)
end

function set_name!(K::AnticNumberField)
s = find_name(K)
s === nothing || set_name!(K, string(s))
end

################################################################################
#
# Is linearly disjoint
Expand Down Expand Up @@ -1318,7 +1273,3 @@ function force_coerce_cyclo(a::AnticNumberField, b::nf_elem, throw_error::Type{V
# now ff is a polynomial for b w.r.t. the fa-th cyclotomic field
return a(ff)
end

(::QQField)(a::nf_elem) = (is_rational(a) && return coeff(a, 0)) || error("not a rational")
(::ZZRing)(a::nf_elem) = (isinteger(a) && return numerator(coeff(a, 0))) || error("not an integer")

10 changes: 0 additions & 10 deletions src/NumField/NfAbs/NonSimple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ function Nemo.one!(a::NfAbsNSElem)
return a
end

function Nemo.one!(a::QQMPolyRingElem)
ccall((:fmpq_mpoly_one, libflint), Nothing,
(Ref{QQMPolyRingElem}, Ref{QQMPolyRing}), a, parent(a))
return a
end

################################################################################
#
# Random
Expand Down Expand Up @@ -1136,10 +1130,6 @@ function degree(a::NfAbsNSElem)
return degree(minpoly(a))
end

function degree(a::nf_elem)
return degree(minpoly(a))
end

#TODO: Improve the algorithm
function primitive_element(K::NfAbsNS)
g = gens(K)
Expand Down
10 changes: 0 additions & 10 deletions src/NumField/NfAbs/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -431,16 +431,6 @@ function eq_mod(a::Generic.Poly{nf_elem}, b::Generic.Poly{nf_elem}, d::ZZRingEle
return e
end

################################################################################
#
# Predicates
#
################################################################################

function is_squarefree(x::Generic.Poly{nf_elem})
return isone(gcd(x, derivative(x), true))
end

################################################################################
#
# Some weird conversion
Expand Down
26 changes: 1 addition & 25 deletions src/NumField/NfAbs/PolyFact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,6 @@ function Base.round(::Type{ZZRingElem}, a::ZZRingElem, b::ZZRingElem, bi::fmpz_p
return r
end

@doc raw"""
round(::ZZRingElem, a::ZZRingElem, b::ZZRingElem) -> ZZRingElem
Computes `round(a//b)`.
"""
function Base.round(::Type{ZZRingElem}, a::ZZRingElem, b::ZZRingElem)
s = sign(a)*sign(b)
bs = abs(b)
as = abs(a)
r = s*div(2*as+bs, 2*bs)
# @assert r == round(ZZRingElem, a//b)
return r
end

#TODO: think about computing pM[1][1,:]//pM[2] as a "float" approximation
# to save on multiplications
function reco(a::ZZRingElem, M, pM::Tuple{ZZMatrix, ZZRingElem, fmpz_preinvn_struct}, O)
Expand Down Expand Up @@ -521,16 +507,6 @@ function lll_with_removal_knapsack(x::ZZMatrix, b::ZZRingElem, ctx::lll_ctx = ll
return d, z
end

function tdivpow2!(B::ZZMatrix, t::Int)
ccall((:fmpz_mat_scalar_tdiv_q_2exp, libflint), Nothing, (Ref{ZZMatrix}, Ref{ZZMatrix}, Cint), B, B, t)
end

function Nemo.tdivpow2(B::ZZMatrix, t::Int)
C = similar(B)
ccall((:fmpz_mat_scalar_tdiv_q_2exp, libflint), Nothing, (Ref{ZZMatrix}, Ref{ZZMatrix}, Cint), C, B, t)
return C
end

function gradual_feed_lll(M::ZZMatrix, sm::ZZRingElem, B::ZZMatrix, d::ZZRingElem, bnd::ZZRingElem)
b = maximum(nbits, B)
sc = max(0, b-55)
Expand Down Expand Up @@ -767,7 +743,7 @@ function van_hoeij(f::PolyElem{nf_elem}, P::NfOrdIdl; prec_scale = 1)
sz = nbits(vH.pM[2]) - div(r, 1) - prec_scale
end
push!(really_used, n)
tdivpow2!(B, sz+prec_scale)
Nemo.tdivpow2!(B, sz+prec_scale)
d = tdivpow2(vH.pM[2], sz)

bnd = r*ZZRingElem(2)^(2*prec_scale) + degree(K)*(ncols(M)-r)*div(r, 2)^2
Expand Down
18 changes: 0 additions & 18 deletions src/NumField/NfAbs/Simplify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,6 @@ function _block(el::NfAbsNSElem, rt::Vector{Vector{fqPolyRepFieldElem}}, R::fpFi
return b
end

function AbstractAlgebra.map_coefficients(F::fpField, f::QQMPolyRingElem; parent = polynomial_ring(F, nvars(parent(f)), cached = false)[1])
dF = denominator(f)
d = F(dF)
if iszero(d)
error("Denominator divisible by p!")
end
m = inv(d)
ctx = MPolyBuildCtx(parent)
for x in zip(coefficients(f), exponent_vectors(f))
el = numerator(x[1]*dF)
push_term!(ctx, F(el)*m, x[2])
end
return finish(ctx)
end




function _sieve_primitive_elements(B::Vector{nf_elem})
K = parent(B[1])
Zx = polynomial_ring(FlintZZ, "x", cached = false)[1]
Expand Down
9 changes: 0 additions & 9 deletions src/NumField/NfRel/NfRelNS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ mS(gen(S))
mS\gens(K)[2]
=#

#to make the MPoly module happy, divrem needs it...
function Base.div(a::nf_elem, b::nf_elem)
return a//b
end

function Nemo.rem(a::nf_elem, b::nf_elem)
return parent(a)(0)
end

#non-simple fields are quotients by multivariate polynomials
#this could be extended to arbitrary zero-dimensional quotients, but
#I don't need this here.
Expand Down
Loading

0 comments on commit 531a41d

Please sign in to comment.