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

Add components method to Abelian group #1632

Merged
merged 4 commits into from
Oct 18, 2024
Merged
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
1 change: 1 addition & 0 deletions docs/src/manual/abelian/elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ parent(x::FinGenAbGroupElem)
### Access

```@docs
getindex(x::FinGenAbGroupElem, v::AbstractVector{Int})
getindex(x::FinGenAbGroupElem, i::Int)
```

Expand Down
20 changes: 20 additions & 0 deletions src/GrpAb/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ function getindex(x::FinGenAbGroupElem, i::Int)
return x.coeff[1, i]
end

@doc raw"""
getindex(x::FinGenAbGroupElem, v::AbstractVector{Int}) -> Vector{ZZRingElem}

Returns the $i$-th components of the element $x$ where $i \in v$.

!!! note
This function is inefficient since the elements are internally stored using ZZMatrix but this function outputs a vector.
"""
function getindex(x::FinGenAbGroupElem, v::AbstractVector{Int})
return [x.coeff[1, i] for i in v]
end

function Base.firstindex(x::FinGenAbGroupElem)
return Int(1)
end

function Base.lastindex(x::FinGenAbGroupElem)
return ngens(parent(x))
end

################################################################################
#
# Comparison
Expand Down
3 changes: 3 additions & 0 deletions test/GrpAb/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
a = @inferred FinGenAbGroupElem(G, N)
@test parent(a) == G
@test a.coeff == N
@test a[begin:end] == [0, 0, 0]

G = @inferred abelian_group([3, 0])
N = FlintZZ[1 1]
a = @inferred FinGenAbGroupElem(G, N)
@test @inferred parent(a) == G
@test a.coeff == N
@test a[begin:end] == [1, 1]

N = matrix(FlintZZ, 1, 2, [ 1, 1 ])
a = @inferred G(N)
Expand All @@ -21,6 +23,7 @@
a = @inferred G(N)
@test @inferred parent(a) == G
@test a.coeff == transpose(N)
@test a[begin:end] == [1, 1]
end

@testset "Generators" begin
Expand Down
Loading