Skip to content

Commit

Permalink
Merge pull request #68 from kalmarek/mk/edge_cases
Browse files Browse the repository at this point in the history
edge cases
  • Loading branch information
Marek Kaluba authored Nov 18, 2023
2 parents 5ef402d + 7b20d50 commit 15ddfeb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
38 changes: 12 additions & 26 deletions src/Characters/class_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ The following functionality is required for an `AbstractClassFunction`:
* `getindex(χ, i::Integer)`: the value on `i`-th conjugacy class.
Note: Indexing with negative integers should return values on the class which
contains inverses of the `i`-th class.
* `χ(g::GroupElement)`: value of `χ` on a group element (only for julia < 1.3)
"""
abstract type AbstractClassFunction{T} end # <:AbstractVector{T}?

Base.eltype(::AbstractClassFunction{T}) where {T} = T

function LinearAlgebra.dot::AbstractClassFunction, ψ::AbstractClassFunction)
@assert conjugacy_classes(χ) === conjugacy_classes(ψ)
val = sum(
length(cc) * χ[i] * ψ[-i] for
(i, cc) in enumerate(conjugacy_classes(χ))
)
CC = conjugacy_classes(χ)
val = sum(length(cc) * χ[i] * ψ[-i] for (i, cc) in enumerate(CC))
orderG = sum(length, conjugacy_classes(χ))
val = _div(val, orderG)
return val
Expand Down Expand Up @@ -57,15 +54,6 @@ Base.@propagate_inbounds function Base.getindex(χ::ClassFunction, i::Integer)
return values(χ)[i]
end

# TODO: move to AbstractClassFunction when we drop julia-1.0
# adding call methods to abstract types was not supported before julia-1.3
function::ClassFunction)(g::GroupElement)
for (i, cc) in enumerate(conjugacy_classes(χ))
g cc && return χ[i]
end
throw(DomainError(g, "element does not belong to conjugacy classes of "))
end

"""
Character <: AbstractClassFunction
Struct representing (possibly virtual) character of a group.
Expand Down Expand Up @@ -130,18 +118,14 @@ Base.@propagate_inbounds function Base.getindex(
i = i < 0 ? table(χ).inv_of[abs(i)] : i
@boundscheck 1 i nconjugacy_classes(table(χ))

if isirreducible(χ)
k = findfirst(!iszero, constituents(χ))::Int
return convert(T, table(χ)[k, i])
else
return convert(
T,
sum(
c * table(χ)[idx, i] for
(idx, c) in enumerate(constituents(χ)) if !iszero(c)
),
)
end
return convert(
T,
sum(
c * table(χ)[idx, i] for
(idx, c) in enumerate(constituents(χ)) if !iszero(c);
init = zero(T),
),
)
end

## Basic functionality
Expand Down Expand Up @@ -170,6 +154,8 @@ Base.:*(χ::Character, c::Number) = Character(table(χ), c .* constituents(χ))
Base.:*(c::Number, χ::Character) = χ * c
Base.:/::Character, c::Number) = Character(table(χ), constituents(χ) ./ c)

Base.zero::Character) = 0 * χ

## Group-theoretic functions:

PermutationGroups.degree::Character) = Int(χ(one(parent(χ))))
Expand Down
5 changes: 5 additions & 0 deletions src/Characters/dixon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ function dixon_prime(ordG::Integer, exponent::Integer)
# computations of this function over `BigInt` if `ordG` is so we convert
# to `Int`.
p = 2 * convert(Int, isqrt(ordG))
if isone(ordG)
@assert isone(exponent)
return 3one(p)
end

while true
p = nextprime(p + 1)
isone(p % exponent) && break # we need -1 to be in the field
Expand Down
4 changes: 3 additions & 1 deletion src/Characters/powermap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ struct PowerMap{T<:AbstractOrbit} <: AbstractMatrix{Int}
id = one(first(first(ccG)))
idx = findfirst(cc -> id cc, ccG)
cache[:, 1] .= idx
cache[:, 2] .= 1:length(ccG)
if size(cache, 2) > 1
cache[:, 2] .= 1:length(ccG)
end
return new{T}(ccG, cache)
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/characters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
@test sum(
length(cc) * a(first(cc)^2) for cc in Characters.conjugacy_classes(a)
) // order(G) == 2ι(χ)

# zero character
@test zero(χ) == Characters.Character(Characters.table(χ), zeros(5))
@test dot(χ, zero(χ)) == 0
@test dot(zero(χ), zero(χ)) == 0
end

@testset "Characters io" begin
Expand Down

0 comments on commit 15ddfeb

Please sign in to comment.