diff --git a/Project.toml b/Project.toml index 90de204..1002b26 100644 --- a/Project.toml +++ b/Project.toml @@ -1,13 +1,17 @@ name = "StarAlgebras" uuid = "0c0c59c1-dc5f-42e9-9a8b-b5dc384a6cd1" authors = ["Marek Kaluba "] -version = "0.2.0" +version = "0.2.1" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] +Groups = "0.8" +GroupsCore = "0.5" +PermutationGroups = "0.6" +SparseArrays = "1" julia = "1.6" [extras] diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 376638a..40c1450 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -1,6 +1,10 @@ # module structure: -Base.:*(a::Number, X::AlgebraElement) = - mul!(similar(X, promote_type(eltype(X), typeof(a))), X, a) + +function Base.:*(a::Number, X::AlgebraElement) + T = Base._return_type(*, Tuple{eltype(X),typeof(a)}) + return mul!(similar(X, T), X, a) +end + Base.:*(X::AlgebraElement, a::Number) = a * X Base.:(/)(X::AlgebraElement, a::Number) = inv(a) * X diff --git a/src/show.jl b/src/show.jl index 1ae427e..82301ed 100644 --- a/src/show.jl +++ b/src/show.jl @@ -1,7 +1,7 @@ -Base.show(io::IO, A::AbstractStarAlgebra) = - print(io, "*-algebra of $(object(A))") -Base.show(io::IO, ::Type{<:StarAlgebra{O,T}}) where {O,T} = - print(io, "StarAlgebra{$O, $T, …}") +function Base.show(io::IO, A::AbstractStarAlgebra) + ioc = IOContext(io, :limit => true, :compact => true) + return print(ioc, "*-algebra of ", object(A)) +end __prints_with_minus(::Any) = false __prints_with_minus(x::Real) = x < 0 diff --git a/test/arithmetic.jl b/test/arithmetic.jl index 24fe89e..19b71e9 100644 --- a/test/arithmetic.jl +++ b/test/arithmetic.jl @@ -1,21 +1,10 @@ -using GroupsCore -using PermutationGroups -import Random - -StarAlgebras.star(g::PermutationGroups.GroupElement) = inv(g) - -using SparseArrays -if VERSION < v"1.9" - Base.sum(v::SparseVector) = sum(nonzeros(v)) -end - @testset "Arithmetic" begin G = PermGroup(perm"(1,2,3)", perm"(1,2)") b = StarAlgebras.Basis{UInt8}(collect(G)) l = length(b) RG = StarAlgebra(G, b, (l, l)) - @test contains(sprint(show, RG), "*-algebra of Permutation group") + @test contains(sprint(show, RG), "*-algebra of") @testset "Module structure" begin a = AlgebraElement(ones(Int, order(G)), RG) @@ -114,7 +103,7 @@ end @test supp(z) == StarAlgebras.basis(parent(z)) @test supp(RG(1) + RG(g)) == [one(G), g] - @test supp(a) == [one(G), h, g] + @test supp(a) == [one(G), g, h] @testset "Projections in star algebras" begin b = StarAlgebras.basis(RG) diff --git a/test/runtests.jl b/test/runtests.jl index 01cb81c..4781da1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,7 +8,18 @@ include("test_example_words.jl") @testset "StarAlgebras" begin include("mtables.jl") include("constructors.jl") + + using GroupsCore + StarAlgebras.star(g::GroupsCore.GroupElement) = inv(g) + + using SparseArrays + if VERSION < v"1.9" + Base.sum(v::SparseVector) = sum(nonzeros(v)) + end + + using PermutationGroups include("arithmetic.jl") + using Groups include("sum_of_squares.jl") end diff --git a/test/sum_of_squares.jl b/test/sum_of_squares.jl index 80ef114..bfba90e 100644 --- a/test/sum_of_squares.jl +++ b/test/sum_of_squares.jl @@ -1,7 +1,4 @@ -using Groups - @testset "sum of squares in FreeGroup *-algebra" begin - StarAlgebras.star(g::Groups.GroupElement) = inv(g) F = Groups.FreeGroup(4) S = [Groups.gens(F); inv.(Groups.gens(F))] diff --git a/test/test_example_words.jl b/test/test_example_words.jl index fc327ce..276a20e 100644 --- a/test/test_example_words.jl +++ b/test/test_example_words.jl @@ -29,18 +29,13 @@ function Base.:*(w::Word, z::Word) end function StarAlgebras.star(w::Word) - newletters = similar(w.letters) - # star(:a) = :b # star(:b) = :a # star(:c) = :c star_d = Dict(1 => 2, 2 => 1) - for (i, l) in enumerate(Iterators.reverse(w.letters)) - k = haskey(star_d, l) ? star_d[l] : l - newletters[i] = k - end + newletters = [get(star_d, l, l) for l in Iterators.reverse(w.letters)] return Word(w.alphabet, newletters) end