diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 2f347d9..b4c57ca 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -301,7 +301,7 @@ end # ############################################################################### -function addeq!(X::GroupRingElem{T}, Y::GroupRingElem{T}) where T +function addeq!(X::GroupRingElem, Y::GroupRingElem) X.coeffs += Y.coeffs return X end @@ -310,12 +310,17 @@ function +(X::GroupRingElem{T}, Y::GroupRingElem{T}) where T return GroupRingElem(X.coeffs+Y.coeffs, parent(X)) end -function +(X::GroupRingElem{T}, Y::GroupRingElem{S}) where {T,S} +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, Y::GroupRingElem) = addeq!((-Y), X) +-(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 doc""" mul!(result::AbstractArray{T}, diff --git a/test/runtests.jl b/test/runtests.jl index 49e6459..4377e5c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -165,6 +165,15 @@ using GroupRings a = RG(ones(Int, order(G))) b = sum((-1)^parity(g)*RG(g) for g in elements(G)) @test 1/2*(a+b).coeffs == [1.0, 0.0, 1.0, 0.0, 1.0, 0.0] + + a = RG(1) + RG(perm"(2,3)") + RG(perm"(1,2,3)") + b = RG(1) - RG(perm"(1,2)(3)") - RG(perm"(1,2,3)") + + @test a - b == RG(perm"(2,3)") + RG(perm"(1,2)(3)") + 2RG(perm"(1,2,3)") + + @test 1//2*2a == a + @test a + 2a == (3//1)*a + @test 2a - (1//1)*a == a end @testset "Multiplicative structure" begin