diff --git a/src/GenericCyclotomics.jl b/src/GenericCyclotomics.jl index 6c963ef..7293179 100644 --- a/src/GenericCyclotomics.jl +++ b/src/GenericCyclotomics.jl @@ -2,7 +2,7 @@ using Oscar.Random: Random, SamplerTrivial, GLOBAL_RNG using Oscar.RandomExtensions: RandomExtensions, Make2, AbstractRNG import Oscar.AbstractAlgebra: parent_type, elem_type, base_ring, base_ring_type, parent, is_domain_type, - is_exact_type, canonical_unit, isequal, divexact, zero!, mul!, add!, addeq!, get_cached!, is_unit, + is_exact_type, canonical_unit, isequal, divexact, zero!, mul!, add!, get_cached!, is_unit, characteristic, Ring, RingElem, expressify, evaluate, normal_form, divexact import Oscar: pretty, Indent, Dedent, terse, is_terse import Base: show, +, -, *, ^, ==, inv, isone, iszero, one, zero, rand, deepcopy_internal, hash, conj, promote_rule @@ -367,10 +367,13 @@ end mul!(x::GenericCyclo, y::GenericCyclo, z::GenericCyclo) = y*z -add!(x::GenericCyclo, y::GenericCyclo, z::GenericCyclo) = y+z - -function addeq!(x::GenericCyclo, y::GenericCyclo) - mergewith!(+, x.f, y.f) +function add!(x::GenericCyclo, y::GenericCyclo, z::GenericCyclo) + if x === z + y,z=z,y + elseif x !== y + x.f = deepcopy(y.f) + end + mergewith!(+, x.f, z.f) strip_zeros!(x.f) return x end diff --git a/test/runtests.jl b/test/runtests.jl index 4beeb4f..6881a10 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -60,6 +60,24 @@ test_Ring_interface(S) @test isone((S(1)//S(2))*2) @test conj(a//c) == conj(a)//conj(c) + + x=deepcopy(a) + y=deepcopy(b) + ab=a+b + @test add!(y, a, y) == ab + @test y == ab + @test a == x + + add!(a, a, a) + @test a == 2*x + + y=deepcopy(b) + z=deepcopy(c) + cb=c+b + add!(a, c, b) + @test a == cb + @test b == y + @test c == z end @testset "Shifts" begin