From f5f173fdb8feea14f035e536906c17bbe24bbf37 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Thu, 27 Aug 2020 10:09:17 +0200 Subject: [PATCH 1/7] use star() instead of inv() when creating pm_matrix --- src/GroupRings.jl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 2ab4286..ee1f4cf 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -501,13 +501,16 @@ function star(X::GroupRingElem{T}) where T result = RG(T) for (i,c) in enumerate(X.coeffs) if c != zero(T) - g = inv(RG.basis[i]) + g = star(RG.basis[i]) result[g] = c end end return result end +star(g::GroupElem) = inv(g) +star(r::NCRingElem) = inv(r) + ############################################################################### # # Misc @@ -535,7 +538,7 @@ function create_pm(basis::AbstractVector{T}, basis_dict::Dict{T, Int}, Threads.@threads for i in 1:limit x = basis[i] if twisted - x = inv(x) + x = star(x) end for j in 1:limit product_matrix[i,j] = get(basis_dict, x*basis[j], 0) @@ -554,7 +557,7 @@ function check_pm(product_matrix, basis, twisted=false) if idx != nothing @warn("Product is not supported on basis") i,j = Tuple(idx) - x = (twisted ? inv(basis[i]) : basis[i]) + x = (twisted ? star(basis[i]) : basis[i]) throw(KeyError(x*basis[j])) end return true @@ -568,9 +571,9 @@ function complete!(RG::GroupRing, twisted::Bool=false) end warning = false - for idx in findall(RG.pm .== 0) + for idx in findall(iszero, RG.pm) i,j = Tuple(idx) - g = (twisted ? inv(RG.basis[i]) : RG.basis[i])*RG.basis[j] + g = (twisted ? star(RG.basis[i]) : RG.basis[i])*RG.basis[j] if haskey(RG.basis_dict, g) RG.pm[i,j] = RG.basis_dict[g] else From 31cf3b552db93da00509e665ac2303a4bfa967bc Mon Sep 17 00:00:00 2001 From: kalmarek Date: Thu, 27 Aug 2020 10:18:46 +0200 Subject: [PATCH 2/7] use === for checking parent in Base.:* --- src/GroupRings.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index ee1f4cf..bb5e5cd 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -457,7 +457,7 @@ end function *(X::GroupRingElem{T}, Y::GroupRingElem{T}, check::Bool=true) where T if check - parent(X) == parent(Y) || throw("Elements don't seem to belong to the same Group Ring!") + parent(X) === parent(Y) || throw("Elements don't seem to belong to the same Group Ring!") end if hasbasis(parent(X)) result = parent(X)(similar(X.coeffs)) @@ -471,7 +471,7 @@ end function *(X::GroupRingElem{T}, Y::GroupRingElem{S}, check::Bool=true) where {T,S} if check - parent(X) == parent(Y) || throw("Elements don't seem to belong to the same Group Ring!") + parent(X) === parent(Y) || throw("Elements don't seem to belong to the same Group Ring!") end TT = typeof(first(X.coeffs)*first(Y.coeffs)) From 002954f5ded105aeff431bcbdb7e2d008f86a81c Mon Sep 17 00:00:00 2001 From: kalmarek Date: Thu, 27 Aug 2020 10:19:11 +0200 Subject: [PATCH 3/7] minor changes --- src/GroupRings.jl | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index bb5e5cd..be4aa6a 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -21,7 +21,7 @@ mutable struct GroupRing{Gr<:GroupOrNCRing, T<:GroupOrNCRingElem} <: NCRing group::Gr basis::Vector{T} basis_dict::Dict{T, Int} - pm::Array{Int,2} + pm::Matrix{Int} function GroupRing(G::Gr, basis::Vector{T}; cachedmul::Bool=false) where {Gr, T} @@ -75,7 +75,7 @@ function GroupRing(G::Generic.SymmetricGroup; cachedmul::Bool=false) return GroupRing(G, vec(collect(G)), cachedmul=cachedmul) end -function GroupRing(G::Group, basis::Vector, pm::Array{Int,2}) +function GroupRing(G::Group, basis::AbstractVector, pm::AbstractMatrix{<:Integer}) size(pm,1) == size(pm,2) || throw("pm must be square, got $(size(pm))") eltype(basis) == elem_type(G) || throw("Basis must consist of elements of $G") return GroupRing(G, basis, reverse_dict(basis), pm) @@ -95,9 +95,7 @@ parent(g::GroupRingElem) = g.parent parent_type(X::GroupRingElem) = typeof(parent(X)) -import Base.promote_rule - -promote_rule(::Type{GroupRingElem{T}}, ::Type{GroupRingElem{S}}) where {T,S} = +Base.promote_rule(::Type{GroupRingElem{T}}, ::Type{GroupRingElem{S}}) where {T,S} = GroupRingElem{promote_type(T,S)} function convert(::Type{T}, X::GroupRingElem) where T<:Number @@ -297,16 +295,8 @@ function mul!(a::T, X::GroupRingElem{T}) where T return X end -mul(a::T, X::GroupRingElem{T}) where T = GroupRingElem(a*X.coeffs, parent(X)) - -function mul(a::T, X::GroupRingElem{S}) where {T<:Number, S} - TT = promote_type(T,S) - TT == S || @warn("Scalar and coeffs are in different rings! Promoting result to $(TT)") - return GroupRingElem(a.*X.coeffs, parent(X)) -end - -(*)(a::Number, X::GroupRingElem) = mul(a, X) -(*)(X::GroupRingElem, a::Number) = mul(a, X) +Base.:*(a::Number, X::GroupRingElem) = GroupRingElem(a*X.coeffs, parent(X)) +Base.:*(X::GroupRingElem, a::Number) = a*X # disallow Rings to hijack *(::, ::GroupRingElem) *(a::Union{AbstractFloat, Integer, RingElem, Rational}, X::GroupRingElem) = mul(a, X) @@ -425,7 +415,7 @@ function mul!(result::GroupRingElem, X::GroupRingElem, Y::GroupRingElem) if isdefined(RG, :pm) s = size(RG.pm) k = findprev(!iszero, X.coeffs, lX) - (k == nothing ? 0 : k) <= s[1] || throw("Element in X outside of support of parents product") + (k == nothing ? 0 : k) <= s[1] || throw("Element in X outside of support of parents product: $k $(RG.basis[k])") k = findprev(!iszero, Y.coeffs, lY) (k == nothing ? 0 : k) <= s[2] || throw("Element in Y outside of support of parents product") From 1718a6ce263be53956cd7bafe9c2f948ff39aa78 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 4 Oct 2020 21:08:50 +0200 Subject: [PATCH 4/7] rm REQUIRE --- REQUIRE | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 REQUIRE diff --git a/REQUIRE b/REQUIRE deleted file mode 100644 index 186790a..0000000 --- a/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.0 -AbstractAlgebra From 8178af653050b4b35250c577c2e9899a51f71266 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 4 Oct 2020 21:09:08 +0200 Subject: [PATCH 5/7] update travix to newest versions of julia --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index fd27633..b9c3a6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,8 @@ os: - osx julia: - 1.0 - - 1.1 - - 1.2 - - 1.3 + - 1.4 + - 1.5 - nightly notifications: email: true From 3054fa40d10fcde3227dad3f5c27a2ddd76fbec0 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 4 Oct 2020 21:12:18 +0200 Subject: [PATCH 6/7] remove warnings --- src/GroupRings.jl | 51 +++++++++++------------------------------------ test/runtests.jl | 6 +++--- 2 files changed, 15 insertions(+), 42 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index be4aa6a..9a02e2c 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -257,9 +257,6 @@ end ############################################################################### function (==)(X::GroupRingElem, Y::GroupRingElem) - if eltype(X.coeffs) != eltype(Y.coeffs) - @warn("Comparing elements with different coeffs Rings!") - end suppX = supp(X) suppX == supp(Y) || return false @@ -282,6 +279,9 @@ end hasbasis(A::GroupRing) = isdefined(A, :basis) +Base.deepcopy_internal(x::GroupRingElem, dict::IdDict) = + parent(x)(deepcopy(x.coeffs)) + ############################################################################### # # Scalar operators @@ -295,11 +295,13 @@ function mul!(a::T, X::GroupRingElem{T}) where T return X end -Base.:*(a::Number, X::GroupRingElem) = GroupRingElem(a*X.coeffs, parent(X)) +_mul(a::Number, X::GroupRingElem) = GroupRingElem(a*X.coeffs, parent(X)) + +Base.:*(a::Number, X::GroupRingElem) = _mul(a, X) Base.:*(X::GroupRingElem, a::Number) = a*X # disallow Rings to hijack *(::, ::GroupRingElem) -*(a::Union{AbstractFloat, Integer, RingElem, Rational}, X::GroupRingElem) = mul(a, X) +*(a::Union{AbstractFloat, Integer, RingElem, Rational}, X::GroupRingElem) = _mul(a, X) (/)(X::GroupRingElem, a) = 1/a*X (//)(X::GroupRingElem, a::Union{Integer, Rational}) = 1//a*X @@ -317,21 +319,8 @@ function addeq!(X::GroupRingElem, Y::GroupRingElem) return X end -function +(X::GroupRingElem{T}, Y::GroupRingElem{T}) where T - return GroupRingElem(X.coeffs+Y.coeffs, parent(X)) -end - -function +(X::GroupRingElem{S}, Y::GroupRingElem{T}) where {S, T} - @warn("Adding elements with different coefficient rings, Promoting result to $(promote_type(T,S))") - return GroupRingElem(X.coeffs+Y.coeffs, parent(X)) -end - --(X::GroupRingElem{T}, Y::GroupRingElem{T}) where T = addeq!((-Y), X) - -function -(X::GroupRingElem{S}, Y::GroupRingElem{T}) where {S, T} - @warn("Adding elements with different coefficient rings, Promoting result to $(promote_type(T,S))") - addeq!((-Y), X) -end +Base.:+(X::GroupRingElem, Y::GroupRingElem) = addeq!(deepcopy(X), Y) +-(X::GroupRingElem, Y::GroupRingElem) where T = addeq!((-Y), X) """ fmac!(result::AbstractVector{T}, @@ -445,34 +434,18 @@ function mul!(result::GroupRingElem, X::GroupRingElem, Y::GroupRingElem) return result end -function *(X::GroupRingElem{T}, Y::GroupRingElem{T}, check::Bool=true) where T - if check - parent(X) === parent(Y) || throw("Elements don't seem to belong to the same Group Ring!") - end - if hasbasis(parent(X)) - result = parent(X)(similar(X.coeffs)) - result = mul!(result, X, Y) - else - result = GRmul!(similar(X.coeffs), X.coeffs, Y.coeffs, parent(X).pm) - result = GroupRingElem(result, parent(X)) - end - return result -end - function *(X::GroupRingElem{T}, Y::GroupRingElem{S}, check::Bool=true) where {T,S} if check parent(X) === parent(Y) || throw("Elements don't seem to belong to the same Group Ring!") end - TT = typeof(first(X.coeffs)*first(Y.coeffs)) - @warn("Multiplying elements with different base rings! Promoting the result to $TT.") + TT = promote_type(T,S) if hasbasis(parent(X)) - result = parent(X)(similar(X.coeffs)) - result = convert(TT, result) + result = parent(X)(similar(X.coeffs, TT)) result = mul!(result, X, Y) else - result = convert(TT, similar(X.coeffs)) + result = similar(X.coeffs, TT) result = RGmul!(result, X.coeffs, Y.coeffs, parent(X).pm) result = GroupRingElem(result, parent(X)) end diff --git a/test/runtests.jl b/test/runtests.jl index 0b0065b..5bc76ac 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -145,10 +145,10 @@ using SparseArrays ww = "Scalar and coeffs are in different rings! Promoting result to Float64" @test isa(2.0*a, GroupRingElem) - @test_logs (:warn, ww) eltype(2.0*a) == typeof(2.0) - @test_logs (:warn, ww) (2.0*a).coeffs == 2.0.*(a.coeffs) + @test eltype(2.0*a) == typeof(2.0) + @test (2.0*a).coeffs == 2.0.*(a.coeffs) - @test_logs (:warn, ww) (a/2).coeffs == a.coeffs./2 + @test (a/2).coeffs == a.coeffs./2 b = a/2 @test isa(b, GroupRingElem) @test eltype(b) == typeof(1/2) From f4b73c29a30b267645f75b6786375c22c5f0c164 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 4 Oct 2020 21:12:47 +0200 Subject: [PATCH 7/7] bump to 0.3.3 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e1cfcc2..f37d5b5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GroupRings" uuid = "0befed6a-bd73-11e8-1e41-a1190947c2f5" authors = ["Marek Kaluba "] -version = "0.3.2" +version = "0.3.3" [deps] AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"