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

Conversation

paemurru
Copy link
Contributor

@simonbrandhorst suggested that instead of accessing the property using the dot notation, a proper getter would be useful. I named the method components since this is how it is referred to in the docs.

@thofma
Copy link
Owner

thofma commented Sep 27, 2024

Yes and no, see #1466

@simonbrandhorst
Copy link
Collaborator

I see. Maybe we just make an arbitrary default decision and go for it? Throw a dice?
We can also add
coefficients(::Type{ZZMatrix}, x)
coefficients(::Type{Vector{ZZRingElem}, x)

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.80%. Comparing base (a024dc6) to head (af3e7cd).
Report is 18 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1632      +/-   ##
==========================================
- Coverage   75.85%   75.80%   -0.06%     
==========================================
  Files         361      361              
  Lines      113702   113695       -7     
==========================================
- Hits        86249    86184      -65     
- Misses      27453    27511      +58     
Files with missing lines Coverage Δ
src/GrpAb/Elem.jl 96.75% <100.00%> (+0.10%) ⬆️

... and 42 files with indirect coverage changes

@fingolfin
Copy link
Contributor

What do you want to do? Knowing your usecase would help decide how to best address this. Maybe a more mathematical interface would be possible.

Note that you already can do x[1] to get the first, second, etc. entry.

If we really want this, we could also allow something like Vector{ZZRingElem}(x) ...

@paemurru
Copy link
Contributor Author

paemurru commented Oct 9, 2024

A toric geometry function outputs an algebra graded by a finitely generated abelian group. I want to make a new algebra with a slightly different grading. Namely, the last "column" replaced by ones.

Ideally I would want to be able to write x[1:end] to get the vector of entries. So I can construct the vector [x[1:end-1]; 1].

@fieker
Copy link
Collaborator

fieker commented Oct 9, 2024 via email

@paemurru
Copy link
Contributor Author

paemurru commented Oct 9, 2024

Is this math - or developing/ testing to get examples.
Math.

I think it would be rather nice if we could write g[1:end] to get the vector of entries, considering g[i] already gives an entry. Is there an easy way to add this functionality?

@simonbrandhorst
Copy link
Collaborator

It is just about the interface. We know how to achieve what we want. But do others know it as well?
I find both of the following not optimal. The first because one has to go back to the parent and the second because it is not using the interface .

julia> A = abelian_group([0,1,2,3]);

julia> x = A[1]
Abelian group element [1, 0, 0, 0]

julia> [x[i] for i in 1:ngens(A)]
4-element Vector{ZZRingElem}:
 1
 0
 0
 0

julia> x.coeff
[1   0   0   0]

@fieker
Copy link
Collaborator

fieker commented Oct 9, 2024 via email

@fieker
Copy link
Collaborator

fieker commented Oct 10, 2024 via email

@simonbrandhorst
Copy link
Collaborator

I can see your point. As a mathematician I would do the following:

julia> B = abelian_group([2 2 0; 2 2 0; 1 2 3])
Finitely generated abelian group
  with 3 generators and 3 relations and relation matrix
  [2   2   0]
  [2   2   0]
  [1   2   3]

julia> b = B([7,5,31])
Abelian group element [0, 1, 40]

Now the goal is to express b as a Z-linear combination of the generators.
As a mathematician I am well aware that this combination is in general not unique,
because the presentation
$$\mathbb{Z}^3 \to A$$
has a kernel.
Hence I would do the following.

julia> phi = hom(A,B,gens(B))
Map
  from Z^3
  to finitely generated abelian group with 3 generators and 3 relations

julia> a = preimage(phi,b)
Abelian group element [0, 1, 40]

And now I would wonder, how I get the coefficients [0,1,40].
Then I would try a bunch of things coming to mind e.g.
collect(a) , coefficients(a), coordinates(a), maybe matrix(a) .. then
I would probably give up and type a.coeff.
Possibly someone would try

julia> F = free_module(ZZ,3)
Free module of rank 3 over ZZ

julia> hom(F,B,gens(B))
ERROR: MethodError: 

To be able to call `x[begin:end]`.
@paemurru
Copy link
Contributor Author

Added

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

with a note that it is inefficient.

Now the function components (or whatever it should be called) is not needed since we can call x[begin:end] instead.

src/GrpAb/Elem.jl Outdated Show resolved Hide resolved
src/GrpAb/Elem.jl Outdated Show resolved Hide resolved
src/GrpAb/Elem.jl Outdated Show resolved Hide resolved
src/exports.jl Outdated Show resolved Hide resolved
@thofma thofma enabled auto-merge (squash) October 18, 2024 14:26
@thofma thofma merged commit 542c23e into thofma:master Oct 18, 2024
17 checks passed
@paemurru paemurru deleted the ep/abelian_group_components branch October 18, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants