Skip to content

Commit

Permalink
Remove obsolete getindex methods for accessing generators (#3260)
Browse files Browse the repository at this point in the history
* Avoid R[0]
* Add some missing supertypes
* Remove obsolete getindex methods for accessing generators
  • Loading branch information
fingolfin authored Jan 30, 2024
1 parent e374ec6 commit 2e151d3
Show file tree
Hide file tree
Showing 19 changed files with 11 additions and 67 deletions.
1 change: 0 additions & 1 deletion experimental/GModule/Brueckner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ function brueckner(mQ::Map{<:Oscar.GAPGroup, PcGroup}; primes::Vector=[])
return allR
end

Base.getindex(M::AbstractAlgebra.FPModule, i::Int) = i==0 ? zero(M) : gens(M)[i]
Oscar.gen(M::AbstractAlgebra.FPModule, i::Int) = M[i]

Oscar.is_free(M::Generic.FreeModule) = true
Expand Down
1 change: 0 additions & 1 deletion src/Groups/GAPGroups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ function gen(G::GAPGroup, i::Int)
@assert length(L) >= i "The number of generators is lower than the given index"
return group_element(G, L[i]::GapObj)
end
Base.getindex(G::GAPGroup, i::Int) = gen(G, i)

"""
ngens(G::GAPGroup) -> Int
Expand Down
2 changes: 0 additions & 2 deletions src/Groups/matrices/matrix_manipulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ end
#
########################################################################

Base.getindex(V::AbstractAlgebra.Generic.FreeModule, i::Int) = gen(V, i)


Base.:*(v::AbstractAlgebra.Generic.FreeModuleElem{T},x::MatElem{T}) where T <: RingElem = v.parent(v.v*x)
Base.:*(x::MatElem{T},u::AbstractAlgebra.Generic.FreeModuleElem{T}) where T <: RingElem = x*transpose(u.v)
Expand Down
12 changes: 1 addition & 11 deletions src/Modules/FreeModules-graded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ function gen(F::FreeModule_dec, i::Int)
return FreeModuleElem_dec(s, F)
end

function Base.getindex(F::FreeModule_dec, i::Int)
i == 0 && return zero(F)
return gen(F, i)
end

base_ring(F::FreeModule_dec) = F.R

#TODO: Parent - checks everywhere!!!
Expand Down Expand Up @@ -705,11 +700,6 @@ function Base.iszero(F::SubquoDecModule)
return all(iszero, gens(F))
end

function Base.getindex(F::SubquoDecModule, i::Int)
i == 0 && return zero(F)
return gen(F, i)
end

function Base.iterate(F::BiModArray, i::Int = 1)
if i>length(F)
return nothing
Expand Down Expand Up @@ -1294,7 +1284,7 @@ function tensor_product(G::FreeModule_dec...; task::Symbol = :none)
return Tuple(gen(G[i], t[e.r.pos[1]][i]) for i = 1:length(G))
end

return F, MapFromFunc(Hecke.TupleParent(Tuple([g[0] for g = G])), F, pure, inv_pure)
return F, MapFromFunc(Hecke.TupleParent(Tuple([zero(g) for g = G])), F, pure, inv_pure)
end

(G::ModuleFP_dec...) = tensor_product(G..., task = :none)
Expand Down
8 changes: 4 additions & 4 deletions src/Modules/ModulesGraded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ function graded_map(F::FreeMod{T}, A::MatrixElem{T}) where {T <: RingElement}
source_degrees = Vector{eltype(G)}()
for i in 1:nrows(A)
for j in 1:ncols(A)
if A[i, j] != R[0]
if !is_zero(A[i, j])
push!(source_degrees, degree(A[i, j]) + degree(F[j]))
break
end
Expand All @@ -580,7 +580,7 @@ function graded_map(F::FreeMod{T}, V::Vector{<:AbstractFreeModElem{T}}) where {T
source_degrees = Vector{eltype(G)}()
for i in 1:nrows
for j in 1:ncols
if coordinates(V[i])[j] != R[0]
if !is_zero(coordinates(V[i])[j])
push!(source_degrees, degree(coordinates(V[i])[j]) + degree(F[j]))
break
end
Expand All @@ -599,7 +599,7 @@ function graded_map(F::SubquoModule{T}, V::Vector{<:ModuleFPElem{T}}) where {T <
source_degrees = Vector{eltype(G)}()
for i in 1:nrows
for (j, coord_val) in coordinates(V[i])
if coord_val != R[0]
if !is_zero(coord_val)
push!(source_degrees, degree(coord_val) + degree(F[j]))
break
end
Expand Down Expand Up @@ -2258,7 +2258,7 @@ function tensor_product(G::FreeMod_dec...; task::Symbol = :none)
if task == :none
return F
end
return F, MapFromFunc(Hecke.TupleParent(Tuple([g[0] for g = G])), F, pure, inv_pure)
return F, MapFromFunc(Hecke.TupleParent(Tuple([zero(g) for g = G])), F, pure, inv_pure)
end


Expand Down
5 changes: 0 additions & 5 deletions src/Modules/UngradedModules/FreeModElem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ function basis(F::AbstractFreeMod, i::Int)
end
gen(F::AbstractFreeMod, i::Int) = basis(F,i)

function getindex(F::AbstractFreeMod, i::Int)
i == 0 && return zero(F)
return gen(F, i)
end

@doc raw"""
base_ring(F::AbstractFreeMod)
Expand Down
10 changes: 0 additions & 10 deletions src/Modules/UngradedModules/SubquoModuleElem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -899,16 +899,6 @@ function is_zero(M::SubquoModule)
return all(iszero, gens(M))
end

@doc raw"""
getindex(F::SubquoModule, i::Int)
Return the `i`th generator of `F`.
"""
function getindex(F::SubquoModule, i::Int)
i == 0 && return zero(F)
return gen(F, i)
end

function iterate(F::ModuleGens, i::Int = 1)
if i>length(F)
return nothing
Expand Down
4 changes: 2 additions & 2 deletions src/Modules/UngradedModules/Tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function tensor_product(G::FreeMod...; task::Symbol = :none)
return F
end

return F, MapFromFunc(Hecke.TupleParent(Tuple([g[0] for g = G])), F, pure, inv_pure)
return F, MapFromFunc(Hecke.TupleParent(Tuple([zero(g) for g = G])), F, pure, inv_pure)
end

(G::ModuleFP...) = tensor_product(G..., task = :none)
Expand Down Expand Up @@ -163,7 +163,7 @@ function tensor_product(G::ModuleFP...; task::Symbol = :none)
return s
end

return s, MapFromFunc(Hecke.TupleParent(Tuple([g[0] for g = G])), s, pure)
return s, MapFromFunc(Hecke.TupleParent(Tuple([zero(g) for g = G])), s, pure)
end


4 changes: 2 additions & 2 deletions src/Rings/FreeAssAlgIdeal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
# necessarily be confined to a degree bound.

@doc raw"""
mutable struct FreeAssAlgIdeal{T} <: FreeAssAlgIdeal{T}
mutable struct FreeAssAlgIdeal{T}
Two-sided ideal of a free associative algebra with elements of type `T`.
"""
mutable struct FreeAssAlgIdeal{T}
mutable struct FreeAssAlgIdeal{T} <: Ideal{T}
gens::IdealGens{T}
gb::IdealGens{T}

Expand Down
2 changes: 1 addition & 1 deletion src/Rings/Laurent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import AbstractAlgebra: LaurentMPolyRing, LaurentMPolyRingElem
end
end

mutable struct LaurentMPolyIdeal{T}
mutable struct LaurentMPolyIdeal{T} <: Ideal{T}
R
gens::Vector{T}
data # ideal of of _polyringquo(R)
Expand Down
2 changes: 0 additions & 2 deletions src/Rings/MPolyQuo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ end
gens(Q::MPolyQuoRing) = [Q(x) for x = gens(base_ring(Q))]
ngens(Q::MPolyQuoRing) = ngens(base_ring(Q))
gen(Q::MPolyQuoRing, i::Int) = Q(gen(base_ring(Q), i))
Base.getindex(Q::MPolyQuoRing, i::Int) = Q(base_ring(Q)[i])::elem_type(Q)
base_ring(Q::MPolyQuoRing) = base_ring(Q.I)
coefficient_ring(Q::MPolyQuoRing) = coefficient_ring(base_ring(Q))
modulus(Q::MPolyQuoRing) = Q.I
Expand Down Expand Up @@ -348,7 +347,6 @@ function gens(a::MPolyQuoIdeal)
end

gen(a::MPolyQuoIdeal, i::Int) = a.gens.Ox(a.gens.O[i])
getindex(a::MPolyQuoIdeal, i::Int) = gen(a, i)

@doc raw"""
ngens(a::MPolyQuoIdeal)
Expand Down
8 changes: 1 addition & 7 deletions src/Rings/PBWAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mutable struct PBWAlgElem{T, S} <: NCRingElem
sdata::Singular.spluralg{S}
end

mutable struct PBWAlgIdeal{D, T, S}
mutable struct PBWAlgIdeal{D, T, S} <: Ideal{PBWAlgElem{T, S}}
basering::PBWAlgRing{T, S}
sdata::Singular.sideal{Singular.spluralg{S}} # the gens of this ideal, always defined
sopdata::Singular.sideal{Singular.spluralg{S}} # the gens mapped to the opposite
Expand Down Expand Up @@ -249,10 +249,6 @@ function gen(R::PBWAlgRing, i::Int)
return PBWAlgElem(R, gen(R.sring, i))
end

function Base.getindex(R::PBWAlgRing, i::Int)
return gen(R, i)
end

function var_index(a::PBWAlgElem)
return Singular.var_index(a.sdata)
end
Expand Down Expand Up @@ -617,8 +613,6 @@ function gen(a::PBWAlgIdeal, i::Int)
return PBWAlgElem(R, a.sdata[i])
end

getindex(I::PBWAlgIdeal, i::Int) = gen(I, i)

function expressify(a::PBWAlgIdeal{D}; context = nothing) where D
dir = D < 0 ? :left_ideal : D > 0 ? :right_ideal : :two_sided_ideal
return Expr(:call, dir, [expressify(g, context = context) for g in gens(a)]...)
Expand Down
4 changes: 0 additions & 4 deletions src/Rings/PBWAlgebraQuo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ function gen(Q::PBWAlgQuo, i::Int)
return PBWAlgQuoElem(Q, PBWAlgElem(Q.I.basering, gen(Q.sring, i)))
end

function Base.getindex(Q::PBWAlgQuo, i::Int)
return gen(Q, i)
end

function zero(Q::PBWAlgQuo)
return PBWAlgQuoElem(Q, PBWAlgElem(Q.I.basering, zero(Q.sring)))
end
Expand Down
1 change: 0 additions & 1 deletion src/Rings/mpoly-graded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,6 @@ base_ring(W::MPolyDecRing) = base_ring(forget_decoration(W))
Nemo.ngens(W::MPolyDecRing) = Nemo.ngens(forget_decoration(W))
Nemo.gens(W::MPolyDecRing) = map(W, gens(forget_decoration(W)))
Nemo.gen(W::MPolyDecRing, i::Int) = W(gen(forget_decoration(W), i))
Base.getindex(W::MPolyDecRing, i::Int) = W(forget_decoration(W)[i])

base_ring(f::MPolyDecRingElem) = base_ring(forget_decoration(f))

Expand Down
1 change: 0 additions & 1 deletion src/Rings/mpoly-ideals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,6 @@ function gens(I::MPolyIdeal)
end

gen(I::MPolyIdeal, i::Int) = I.gens[Val(:O), i]
getindex(I::MPolyIdeal, i::Int) = gen(I, i)

#######################################################
@doc raw"""
Expand Down
1 change: 0 additions & 1 deletion src/Rings/mpoly-localizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,6 @@ end
### required getter functions
gens(I::MPolyLocalizedIdeal) = copy(I.gens)
gen(I::MPolyLocalizedIdeal, i::Int) = I.gens[i]
getindex(I::MPolyLocalizedIdeal, i::Int) = I.gens[i]
base_ring(I::MPolyLocalizedIdeal) = I.W

### type getters
Expand Down
10 changes: 0 additions & 10 deletions src/Rings/mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ function _variables_for_singular(n::Int)
end
_variables_for_singular(S::Vector{Symbol}) = _variables_for_singular(length(S))

function Base.getindex(R::MPolyRing, i::Int)
i == 0 && return zero(R)
return gen(R, i)
end

ngens(F::AbstractAlgebra.Generic.FracField{T}) where {T <: MPolyRingElem} = ngens(base_ring(F))

function gen(F::AbstractAlgebra.Generic.FracField{T}) where {T <: PolyRingElem}
Expand All @@ -39,11 +34,6 @@ function gens(F::AbstractAlgebra.Generic.FracField{T}) where {T <: Union{PolyRin
return map(F, gens(base_ring(F)))
end

function Base.getindex(F::AbstractAlgebra.Generic.FracField{T}, i::Int) where {T <: MPolyRingElem}
i == 0 && return zero(F)
return gen(F, i)
end

######################################################################
# pretty printing for iJulia notebooks..
#
Expand Down
1 change: 0 additions & 1 deletion src/Rings/mpolyquo-localizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,6 @@ end
### required getter functions
gens(I::MPolyQuoLocalizedIdeal) = copy(I.gens)
gen(I::MPolyQuoLocalizedIdeal, i::Int) = I.gens[i]
getindex(I::MPolyQuoLocalizedIdeal, i::Int) = I.gens[i]
base_ring(I::MPolyQuoLocalizedIdeal) = I.W

### additional getter functions
Expand Down
1 change: 0 additions & 1 deletion test/Rings/mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ end
@test gen(F, 2) == F(y)
@test gens(F) == elem_type(F)[ F(x), F(y), F(z) ]
@test F[1] == F(x)
@test F[0] == zero(F)
end

@testset "Grassmann Plücker Relations" begin
Expand Down

0 comments on commit 2e151d3

Please sign in to comment.