1
0
mirror of https://github.com/kalmarek/GroupRings.jl.git synced 2024-10-31 18:15:34 +01:00

fix addition/subtraction for different coeff types

This commit is contained in:
kalmarek 2018-08-14 09:47:15 +02:00
parent 6b2cd781c7
commit 2fee695b51
2 changed files with 17 additions and 3 deletions

View File

@ -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},

View File

@ -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