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

image_basis fails over finite fields #63

Closed
laurentbartholdi opened this issue Nov 10, 2023 · 2 comments
Closed

image_basis fails over finite fields #63

laurentbartholdi opened this issue Nov 10, 2023 · 2 comments

Comments

@laurentbartholdi
Copy link

I tried the following, based on the example in action_permutation.jl:

julia> G = PermGroup(perm"(1,2,3)", perm"(1,2)")
julia> F = SymbolicWedderburn.Characters.FiniteFields.GF{42013}
julia> struct Word{T}
           alphabet::Vector{T}
           letters::Vector{Int}

           function Word(a::AbstractVector{T}, l::AbstractVector{<:Integer}) where {T}
               all(i -> 1 <= i <= length(a), l) ||
                   throw(ArgumentError("Invalid word over alphabet $a: $w"))
               return new{T}(a, l)
           end
       end

julia> Base.show(io::IO, w::Word) = join(io, w.alphabet[w.letters], "·")

julia> function Base.:(==)(w::Word, v::Word)
           return w.alphabet == v.alphabet && w.letters == v.letters
       end

julia> function Base.hash(w::Word, h::UInt = UInt(0))
           return hash(w.alphabet, hash(w.letters, hash(Word, h)))
       end

julia> struct OnLetters <: SymbolicWedderburn.ByPermutations end

julia> function SymbolicWedderburn.action(
           ::OnLetters,
           p::PermutationGroups.AbstractPermutation,
           w::Word,
       )
           return Word(w.alphabet, [w.letters[i]^p for i in eachindex(w.letters)])
       end

julia> action = OnLetters()

julia> function allwords(A, radius)
           words = [Word(A, [i]) for i in 1:length(A)]
           for r in 2:radius
               append!(
                   words,
                   [Word(A, collect(w)) for w in Iterators.product(fill(1:3, r)...)],
               )
           end
           return words
       end
allwords (generic function with 1 method)

julia> words = let A = [:a, :b, :c], radius = 4
               w = Word(A, [1, 2, 3, 2, 1])

               # (a·b·c·b·a)^(2,3) == a·c·b·c·a
               @test SymbolicWedderburn.action(OnLetters(), perm"(2,3)", w) ==
                     Word(A, [1, 3, 2, 3, 1])

               words = allwords(A, radius)
           end

julia> tbl = SymbolicWedderburn.CharacterTable(F, G)

julia> ehom = SymbolicWedderburn.CachedExtensionHomomorphism(
               G,
               action,
               words;
               precompute = true,
           )

julia> all(g  keys(ehom.cache) for g in G)

julia> ψ = SymbolicWedderburn.action_character(ehom, tbl)

julia> SymbolicWedderburn.image_basis(ehom,SymbolicWedderburn.irreducible_characters(tbl)[1])
ERROR: promotion of types Rational{Int64} and SymbolicWedderburn.Characters.FiniteFields.GF{42013} failed to change any arguments
Stacktrace:
  [1] error(::String, ::String, ::String)
    @ Base ./error.jl:44
  [2] sametype_error(input::Tuple{Rational{Int64}, SymbolicWedderburn.Characters.FiniteFields.GF{42013}})
    @ Base ./promotion.jl:420
  [3] not_sametype(x::Tuple{…}, y::Tuple{…})
    @ Base ./promotion.jl:414
  [4] promote
    @ ./promotion.jl:397 [inlined]
  [5] *(x::Rational{Int64}, y::SymbolicWedderburn.Characters.FiniteFields.GF{42013})
    @ Base ./promotion.jl:426
  [6] matrix_projection_irr_acc!(result::SparseArrays.SparseMatrixCSC{…}, hom::SymbolicWedderburn.CachedExtensionHomomorphism{…}, class_values::Vector{…}, conjugacy_cls::Vector{…}, weight::Rational{…})
    @ SymbolicWedderburn ~/.julia/packages/SymbolicWedderburn/hBhTJ/src/matrix_projections.jl:234
  [7] matrix_projection_irr_acc!(result::SparseArrays.SparseMatrixCSC{…}, hom::SymbolicWedderburn.CachedExtensionHomomorphism{…}, χ::SymbolicWedderburn.Characters.Character{…}, weight::Int64)
    @ SymbolicWedderburn ~/.julia/packages/SymbolicWedderburn/hBhTJ/src/matrix_projections.jl:217
  [8] matrix_projection_irr
    @ ~/.julia/packages/SymbolicWedderburn/hBhTJ/src/matrix_projections.jl:145 [inlined]
  [9] matrix_representation(hom::SymbolicWedderburn.CachedExtensionHomomorphism{…}, χ::SymbolicWedderburn.Characters.Character{…})
    @ SymbolicWedderburn ~/.julia/packages/SymbolicWedderburn/hBhTJ/src/matrix_projections.jl:360
 [10] image_basis
    @ SymbolicWedderburn ~/.julia/packages/SymbolicWedderburn/hBhTJ/src/matrix_projections.jl:419 [inlined]
 [11] image_basis(hom::SymbolicWedderburn.CachedExtensionHomomorphism{…}, α::SymbolicWedderburn.Characters.Character{…})
    @ SymbolicWedderburn ~/.julia/packages/SymbolicWedderburn/hBhTJ/src/matrix_projections.jl:419
 [12] top-level scope
    @ REPL[41]:1
Some type information was truncated. Use `show(err)` to see complete types.
@kalmarek
Copy link
Owner

as already observed the immediate error could be fixed by defining

Base.promote_rule(::Type{<:GF{p}}, ::Type{<:Rational}) where p = GF{p}
GF{p}(q::Rational, check=false) where p = GF{p}(numerator(q), check)/
numerator(q)

but runs into problems deeper down the chain

@kalmarek kalmarek changed the title Error with finite fields image_basis fails over finite fields Feb 8, 2024
@kalmarek
Copy link
Owner

kalmarek commented Feb 8, 2024

as of today master defining the following two methods:

import SymbolicWedderburn.Characters.FiniteFields as FF
Base.promote_rule(::Type{<:FF.GF{p}}, ::Type{<:Rational}) where p = FF.GF{p}
FF.GF{p}(q::Rational, check=false) where p = FF.GF{p}(numerator(q), check)/numerator(q)

makes the call to image_basis return what it should (well, hopefully, I didn't check the values):

julia> SymbolicWedderburn.image_basis(ehom,SymbolicWedderburn.irreducible_characters(tbl)[1])

22×120 SparseArrays.SparseMatrixCSC{SymbolicWedderburn.Characters.FiniteFields.GF{42013}, Int64} with 42 stored entries:
⎡⠉⠁⠀⠀⠐⠒⠀⠀⠀⠒⠂⠀⠀⠀⠒⠀⠀⠤⢀⠀⠀⠀⡀⠀⠀⠀⠀⡀⠀⠠⠀⠄⠀⢀⠀⠀⠀⠀⢀⠀⠀⠀⡀⠤⠀⠀⎤
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠂⠀⠁⠀⠁⠊⠀⠁⠀⠀⠀⠀⠀⠈⠀⠓⠈⠀⠁⠀⠐⠉⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎦

I'm not convinced that I want to support here the GF{p} & Rational promotion, but if there are more requests for the feature the path is open ;)

@kalmarek kalmarek closed this as completed Feb 8, 2024
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

No branches or pull requests

2 participants