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

Make GSets better inferreable #4052

Merged
merged 3 commits into from
Aug 29, 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
4 changes: 4 additions & 0 deletions src/Groups/group_characters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,8 @@ end

Base.iterate(tbl::GAPGroupCharacterTable, state = 1) = state > nrows(tbl) ? nothing : (tbl[state], state+1)

Base.eltype(::Type{GAPGroupCharacterTable}) = GAPGroupClassFunction

"""
mod(tbl::GAPGroupCharacterTable, p::T) where T <: IntegerUnion
rem(tbl::GAPGroupCharacterTable, p::T) where T <: IntegerUnion
Expand Down Expand Up @@ -2347,6 +2349,8 @@ Base.length(chi::GAPGroupClassFunction) = length(GapObj(chi))

Base.iterate(chi::GAPGroupClassFunction, state = 1) = state > length(GapObj(chi)) ? nothing : (chi[state], state+1)

Base.eltype(::Type{GAPGroupClassFunction}) = QQAbFieldElem{AbsSimpleNumFieldElem}

@doc raw"""
degree(::Type{T} = QQFieldElem, chi::GAPGroupClassFunction)
where T <: Union{IntegerUnion, QQFieldElem, QQAbFieldElem}
Expand Down
21 changes: 10 additions & 11 deletions src/Groups/gsets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Hecke.orbit


"""
GSetByElements{T} <: GSet{T}
GSetByElements{T,S} <: GSet{T}

Objects of this type represent G-sets that are willing to write down
orbits and elements lists as vectors.
Expand All @@ -33,17 +33,17 @@ These G-sets are created by default by [`gset`](@ref).
The fields are
- the group that acts, of type `T`,
- the Julia function (for example `on_tuples`) that describes the action,
- the seeds (something iterable) whose closure under the action is the G-set
- the seeds (something iterable of eltype `S`) whose closure under the action is the G-set
- the dictionary used to store attributes (orbits, elements, ...).
"""
@attributes mutable struct GSetByElements{T} <: GSet{T}
@attributes mutable struct GSetByElements{T,S} <: GSet{T}
group::T
action_function::Function
seeds

function GSetByElements(G::T, fun::Function, seeds; closed::Bool = false) where T<:Union{GAPGroup, FinGenAbGroup}
@assert ! isempty(seeds)
Omega = new{T}(G, fun, seeds, Dict{Symbol,Any}())
function GSetByElements(G::T, fun::Function, seeds; closed::Bool = false) where {T<:Union{GAPGroup, FinGenAbGroup}}
@assert !isempty(seeds)
Omega = new{T,eltype(seeds)}(G, fun, seeds, Dict{Symbol,Any}())
closed && set_attribute!(Omega, :elements => unique!(collect(seeds)))
return Omega
end
Expand Down Expand Up @@ -411,9 +411,8 @@ julia> map(collect, orbs)
[5, 6]
```
"""
@attr Vector{GSetByElements{TG}} function orbits(Omega::T) where T <: GSetByElements{TG} where TG <: Union{GAPGroup, FinGenAbGroup}
G = acting_group(Omega)
orbs = T[]
@attr Vector{GSetByElements{T,S}} function orbits(Omega::GSetByElements{T,S}) where {T <: Union{GAPGroup, FinGenAbGroup},S}
orbs = GSetByElements{T,S}[]
for p in Omega.seeds
if all(o -> !(p in o), orbs)
push!(orbs, orbit(Omega, p))
Expand All @@ -440,7 +439,7 @@ julia> map(length, orbs)
2
```
"""
@attr Vector{GSetByElements{PermGroup}} orbits(G::PermGroup) = orbits(gset(G))
@attr Vector{GSetByElements{PermGroup, Int}} orbits(G::PermGroup) = orbits(gset(G))


#############################################################################
Expand All @@ -449,7 +448,7 @@ julia> map(length, orbs)
## if `:seeds` is known to be closed under the action then
## keep its ordering of points

@attr Any function elements(Omega::GSetByElements)
@attr Vector{S} function elements(Omega::GSetByElements{T,S}) where {T,S}
orbs = orbits(Omega)
return union(map(collect, orbs)...)
end
Expand Down
12 changes: 6 additions & 6 deletions test/Groups/gsets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Omega = gset(G)
@test AbstractAlgebra.PrettyPrinting.repr_terse(Omega) == "G-set"
@test isa(Omega, GSet)
@test length(Omega) == 6
@test length(orbits(Omega)) == 1
@test (@inferred length(Omega)) == 6
@test (@inferred length(@inferred orbits(Omega))) == 1
@test is_transitive(Omega)
@test ! is_regular(Omega)
@test ! is_semiregular(Omega)
Expand Down Expand Up @@ -455,12 +455,12 @@ end
return galois_conjugate(chi, QQAbAutomorphism(Int(lift(mu(g)))))
end

orb = orbit(u, f, t[3])
orb = @inferred orbit(u, f, t[3])
@test length(collect(orb)) == 3

Omega = gset(u, f, t)
orbs = orbits(Omega)
@test length(orbs) == 5
Omega = @inferred gset(u, f, t)
orbs = @inferred orbits(Omega)
@test (@inferred length(orbs)) == 5
@test sort(map(length, orbs)) == [1, 1, 1, 3, 3]
@test all(o -> conductor(sum(collect(o))) == 1, orbs)
o = orbs[findfirst(o -> length(o) == 3, orbs)]
Expand Down
Loading