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

feat: group algebras with sparse representation #1655

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

thofma
Copy link
Owner

@thofma thofma commented Oct 18, 2024

Due to popular demand, group algebras with sparse representation (aka "don't crash with large groups"). Needs some work/clean up:

julia> G = SymmetricGroup(10)
Full symmetric group over 10 elements

julia> QG = group_algebra(QQ, G; sparse = true)
Group algebra
  of full symmetric group over 10 elements
  over rational field

julia> a = QG(rand(G)); b = QG(rand(G));

julia> c = (a + b) * (a - b)
(1,2,4,8,7)(3,9,10,5,6) - (1,4,9)(2,10,3,6,7,5,8) + (1,7,3,8,6,10,4)(2,9,5) - (1,2,6)(3,9)(4,5)

@royess this might interest you. It is similar to your approach.

Small todo:

  • Add a FG(::Dict) constructor.
  • Add tests.
  • Add documentation.

@thofma thofma marked this pull request as draft October 18, 2024 19:41
@thofma thofma force-pushed the th/grpalg branch 2 times, most recently from 032ba33 to d4cbc4f Compare October 21, 2024 20:17
@thofma thofma marked this pull request as ready for review October 21, 2024 21:11
Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 91.08280% with 14 lines in your changes missing coverage. Please review.

Project coverage is 75.82%. Comparing base (2af99ca) to head (2c131f3).

Files with missing lines Patch % Lines
src/AlgAss/Elem.jl 83.33% 13 Missing ⚠️
src/AlgAss/AlgGrp.jl 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1655      +/-   ##
==========================================
- Coverage   75.85%   75.82%   -0.04%     
==========================================
  Files         361      361              
  Lines      113719   113797      +78     
==========================================
+ Hits        86262    86284      +22     
- Misses      27457    27513      +56     
Files with missing lines Coverage Δ
src/AlgAss/AbsAlgAss.jl 88.26% <100.00%> (+0.06%) ⬆️
src/AlgAss/Types.jl 85.79% <100.00%> (+2.89%) ⬆️
src/Grp/GenGrp.jl 70.11% <100.00%> (+0.11%) ⬆️
src/GrpAb/GrpAbFinGen.jl 75.92% <100.00%> (-0.07%) ⬇️
src/AlgAss/AlgGrp.jl 74.28% <85.71%> (+1.21%) ⬆️
src/AlgAss/Elem.jl 88.29% <83.33%> (-0.32%) ⬇️

... and 26 files with indirect coverage changes

@lgoettgens
Copy link
Contributor

Does this change allow me to work with group algebras of infinite groups as well?

@thofma
Copy link
Owner Author

thofma commented Oct 22, 2024

Yes:

julia> F = free_group(2)
Free group of rank 2

julia> x, y = gens(F);

julia> QF = group_algebra(QQ, F; sparse = true)
Group algebra
  of free group of rank 2
  over rational field

julia> (QF(x) + QF(y))^2
f1^2 + f1*f2 + f2*f1 + f2^2

@Fe-r-oz
Copy link

Fe-r-oz commented Oct 22, 2024

This is wonderful! I will shift to sparse = true as soon as this is merged! Thank you.

Copy link
Contributor

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Some quick comments and questions (all nitpicks, not meant to block anything)

Comment on lines +36 to +44
```jldoctest
julia> G = abelian_group([2, 2]); a = G([0, 1]);
julia> QG = group_algebra(QQ, G);
julia> x = QG(a)
[0, 0, 1, 0]
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit redundant to me given the example right afterwards. But perhaps that just me (definitely is a matter of taste anyway).

Suggested change
```jldoctest
julia> G = abelian_group([2, 2]); a = G([0, 1]);
julia> QG = group_algebra(QQ, G);
julia> x = QG(a)
[0, 0, 1, 0]
```

Alternatively, how about turning this into a "running" example, with the codeblocks connected with help of a label? I.e. using the ```jldoctest mylabel syntax. Then the definitions of G and QG don't have to be repeated three times.

julia> QG = group_algebra(QQ, G);
julia> QG(Dict(a => 2, zero(G) => 1)) == 2 * QG(a) + 1 * QG(zero(G))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about also supporting this syntax?

Suggested change
julia> QG(Dict(a => 2, zero(G) => 1)) == 2 * QG(a) + 1 * QG(zero(G))
julia> QG(a => 2, zero(G) => 1) == 2 * QG(a) + 1 * QG(zero(G))

@@ -59,17 +59,25 @@ end
################################################################################

@doc raw"""
group_algebra(K::Ring, G; op = *) -> GroupAlgebra
group_algebra(K::Ring, G::Group; sparse::Bool = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is op omitted on purpose (just wondering, as it is still there in the implementation)

@@ -130,6 +130,13 @@ end
@attributes mutable struct GroupAlgebra{T, S, R} <: AbstractAssociativeAlgebra{T}
base_ring::Ring
group::S
# We represent elements using a coefficient vector,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# We represent elements using a coefficient vector,
# If `sparse` is false we represent elements using a coefficient vector,

Comment on lines +285 to +288
A.ind += 1
resize!(A.base_to_group, max(A.ind, length(A.base_to_group)))
A.base_to_group[A.ind] = g
return A.ind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when would length(A.base_to_group) ever exceed A.ind? Right now I am wondering why you even need A.ind and can't just do this:

Suggested change
A.ind += 1
resize!(A.base_to_group, max(A.ind, length(A.base_to_group)))
A.base_to_group[A.ind] = g
return A.ind
push!(A.base_to_group, g)
return length(A.base_to_group)


A.one = v
if !A.sparse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge this with preceding end into an else?

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.

4 participants