diff --git a/src/InvariantTheory/invariant_rings.jl b/src/InvariantTheory/invariant_rings.jl index 4cdbb2986f30..44473d837d17 100644 --- a/src/InvariantTheory/invariant_rings.jl +++ b/src/InvariantTheory/invariant_rings.jl @@ -167,7 +167,7 @@ function right_action(R::MPolyRing{T}, M::MatrixElem{T}) where {T} if iszero(M[i, j]) continue end - vars[i] = addeq!(vars[i], M[i, j] * x[j]) + vars[i] = add!(vars[i], M[i, j] * x[j]) end end @@ -214,7 +214,7 @@ function reynolds_operator( function reynolds(f::PolyRingElemT) g = parent(f)() for action in actions - g = addeq!(g, action(f)) + g = add!(g, action(f)) end return g * base_ring(f)(1//order(group(IR))) end @@ -344,7 +344,7 @@ function reynolds_operator( function reynolds(f::PolyRingElemT) g = parent(f)() for (action, val) in actions_and_values - g = addeq!(g, action(f) * val) + g = add!(g, action(f) * val) end return g * base_ring(f)(1//order(group(IR))) end diff --git a/src/NumberTheory/GaloisGrp/GaloisGrp.jl b/src/NumberTheory/GaloisGrp/GaloisGrp.jl index 1c66df5d2cb0..4a69580c2716 100644 --- a/src/NumberTheory/GaloisGrp/GaloisGrp.jl +++ b/src/NumberTheory/GaloisGrp/GaloisGrp.jl @@ -209,9 +209,6 @@ function total_degree(I::SLPoly) return value(evaluate(I, [C(1) for i = 1:n])) end -Oscar.mul!(a::BoundRingElem, b::BoundRingElem, c::BoundRingElem) = b*c -Oscar.addeq!(a::BoundRingElem, b::BoundRingElem) = a+b - #my 1st invariant!!! @doc raw""" sqrt_disc(a::Vector) diff --git a/src/Rings/AbelianClosure.jl b/src/Rings/AbelianClosure.jl index 3d2ff2b3bc61..76507fd1d01f 100644 --- a/src/Rings/AbelianClosure.jl +++ b/src/Rings/AbelianClosure.jl @@ -34,8 +34,8 @@ import Base: +, *, -, //, ==, zero, one, ^, div, isone, iszero, #import ..Oscar.AbstractAlgebra: promote_rule -import ..Oscar: AbstractAlgebra, addeq!, base_ring, base_ring_type, characteristic, elem_type, divexact, gen, - has_preimage_with_preimage, is_root_of_unity, is_unit, mul!, parent, +import ..Oscar: AbstractAlgebra, add!, base_ring, base_ring_type, characteristic, elem_type, divexact, gen, + has_preimage_with_preimage, is_root_of_unity, is_unit, mul!, neg!, parent, parent_type, promote_rule, root, root_of_unity, roots using Hecke @@ -625,14 +625,22 @@ end # ################################################################################ -function addeq!(c::QQAbFieldElem, a::QQAbFieldElem) - _c, _a = make_compatible(c, a) - addeq!(_c.data, _a.data) - return _c +function add!(c::QQAbFieldElem, a::QQAbFieldElem, b::QQAbFieldElem) + a, b = make_compatible(a, b) + b, c = make_compatible(b, c) + a, b = make_compatible(a, b) + c.data = add!(c.data, a.data, b.data) + return c +end + +function add!(a::QQAbFieldElem, b::QQAbFieldElem) + a, b = make_compatible(a, b) + a.data = add!(a.data, b.data) + return a end function neg!(a::QQAbFieldElem) - mul!(a.data,a.data,-1) + a.data = mul!(a.data, -1) return a end @@ -640,10 +648,16 @@ function mul!(c::QQAbFieldElem, a::QQAbFieldElem, b::QQAbFieldElem) a, b = make_compatible(a, b) b, c = make_compatible(b, c) a, b = make_compatible(a, b) - mul!(c.data, a.data, b.data) + c.data = mul!(c.data, a.data, b.data) return c end +function mul!(a::QQAbFieldElem, b::QQAbFieldElem) + a, b = make_compatible(a, b) + a.data = mul!(a.data, b.data) + return a +end + ################################################################################ # # Ad hoc binary operations diff --git a/src/Rings/MPolyQuo.jl b/src/Rings/MPolyQuo.jl index 34567799f976..ea4f44c585af 100644 --- a/src/Rings/MPolyQuo.jl +++ b/src/Rings/MPolyQuo.jl @@ -714,13 +714,13 @@ end #^(a::MPolyQuoRingElem, b::Base.Integer) = MPolyQuoRingElem(Base.power_by_squaring(a.f, b), a.P) function Oscar.mul!(a::MPolyQuoRingElem, b::MPolyQuoRingElem, c::MPolyQuoRingElem) - a.f = b.f*c.f + a.f = b.f * c.f a.simplified = false return a end -function Oscar.addeq!(a::MPolyQuoRingElem, b::MPolyQuoRingElem) - a.f += b.f +function Oscar.add!(a::MPolyQuoRingElem, b::MPolyQuoRingElem, c::MPolyQuoRingElem) + a.f = b.f + c.f a.simplified = false return a end diff --git a/src/Rings/NumberField.jl b/src/Rings/NumberField.jl index 0d032c0d77b2..b7c283a83077 100644 --- a/src/Rings/NumberField.jl +++ b/src/Rings/NumberField.jl @@ -445,11 +445,6 @@ function Oscar.add!(a::NfNSGenElem, b::NfNSGenElem, c::NfNSGenElem) return a end -function Oscar.addeq!(a::NfNSGenElem, b::NfNSGenElem) - a.f += b.f - return a -end - ################################################################################ # # Comparison diff --git a/src/Rings/localization_interface.jl b/src/Rings/localization_interface.jl index ee1b5a1b2e5a..8e6bbba86a6f 100644 --- a/src/Rings/localization_interface.jl +++ b/src/Rings/localization_interface.jl @@ -423,26 +423,6 @@ function Base.show(io::IO, W::AbsLocalizedRing) end end -function zero!(a::AbsLocalizedRingElem) - a = zero(parent(a)) - return a -end - -function mul!(c::T, a::T, b::T) where {T<:AbsLocalizedRingElem} - c = a*b - return c -end - -function add!(c::T, a::T, b::T) where {T<:AbsLocalizedRingElem} - c = a+b - return c -end - -function addeq!(a::T, b::T) where {T<:AbsLocalizedRingElem} - a = a+b - return a -end - ### promotion rules AbstractAlgebra.promote_rule(::Type{S}, ::Type{S}) where {S<:AbsLocalizedRingElem} = S diff --git a/src/Rings/mpoly-graded.jl b/src/Rings/mpoly-graded.jl index 4e6432bf3184..1812f652f4af 100644 --- a/src/Rings/mpoly-graded.jl +++ b/src/Rings/mpoly-graded.jl @@ -719,14 +719,6 @@ end ^(a::MPolyDecRingElem, i::Int) = MPolyDecRingElem(forget_decoration(a)^i, parent(a)) -function mul!(a::MPolyDecRingElem, b::MPolyDecRingElem, c::MPolyDecRingElem) - return b*c -end - -function addeq!(a::MPolyDecRingElem, b::MPolyDecRingElem) - return a+b -end - length(a::MPolyDecRingElem) = length(forget_decoration(a)) @doc raw""" diff --git a/src/Rings/mpolyquo-localizations.jl b/src/Rings/mpolyquo-localizations.jl index fbefa3f5007c..2a4a6445283b 100644 --- a/src/Rings/mpolyquo-localizations.jl +++ b/src/Rings/mpolyquo-localizations.jl @@ -782,11 +782,6 @@ function +(a::T, b::T) where {T<:MPolyQuoLocRingElem} return (parent(a))(lifted_numerator(a)*q + lifted_numerator(b)*p, new_den, check=false) end -# TODO: improve this method. -function addeq!(a::T, b::T) where {T<:MPolyQuoLocRingElem} - a = a+b - return a -end function -(a::T, b::T) where {T<:MPolyQuoLocRingElem} return a + (-b) diff --git a/src/Rings/slpolys.jl b/src/Rings/slpolys.jl index e5163dcb44ce..d501fedfa565 100644 --- a/src/Rings/slpolys.jl +++ b/src/Rings/slpolys.jl @@ -238,26 +238,26 @@ function SLP.combine!(op::SLP.Op, p::SLPoly, q::SLPoly) p end -addeq!(p::SLPoly{T}, q::SLPoly{T}) where {T} = SLP.combine!(SLP.plus, p, q) +add!(p::SLPoly{T}, q::SLPoly{T}) where {T} = SLP.combine!(SLP.plus, p, q) function add!(r::SLPoly{T}, p::SLPoly{T}, q::SLPoly{T}) where {T} copy!(r.slprogram, p.slprogram) - addeq!(r, q) + add!(r, q) r end -SLP.subeq!(p::SLPoly{T}, q::SLPoly{T}) where {T} = SLP.combine!(SLP.minus, p, q) +sub!(p::SLPoly{T}, q::SLPoly{T}) where {T} = SLP.combine!(SLP.minus, p, q) -function SLP.subeq!(p::SLPoly) +function neg!(p::SLPoly) SLP.combine!(SLP.uniminus, p.slprogram) p end -SLP.muleq!(p::SLPoly{T}, q::SLPoly{T}) where {T} = SLP.combine!(SLP.times, p, q) +mul!(p::SLPoly{T}, q::SLPoly{T}) where {T} = SLP.combine!(SLP.times, p, q) function mul!(r::SLPoly{T}, p::SLPoly{T}, q::SLPoly{T}) where {T} copy!(r.slprogram, p.slprogram) - SLP.muleq!(r, q) + mul!(r, q) r end @@ -275,13 +275,13 @@ end ## unary/binary ops -+(p::SLPoly{T}, q::SLPoly{T}) where {T} = addeq!(copy(p), q) ++(p::SLPoly{T}, q::SLPoly{T}) where {T} = add!(copy(p), q) -*(p::SLPoly{T}, q::SLPoly{T}) where {T} = SLP.muleq!(copy(p), q) +*(p::SLPoly{T}, q::SLPoly{T}) where {T} = mul!(copy(p), q) --(p::SLPoly{T}, q::SLPoly{T}) where {T} = SLP.subeq!(copy(p), q) +-(p::SLPoly{T}, q::SLPoly{T}) where {T} = sub!(copy(p), q) --(p::SLPoly) = SLP.subeq!(copy(p)) +-(p::SLPoly) = SLP.neg!(copy(p)) ^(p::SLPoly, e::Base.Integer) = SLP.expeq!(copy(p), e) diff --git a/src/StraightLinePrograms/StraightLinePrograms.jl b/src/StraightLinePrograms/StraightLinePrograms.jl index e34d3157d844..01f7dc3b5b62 100644 --- a/src/StraightLinePrograms/StraightLinePrograms.jl +++ b/src/StraightLinePrograms/StraightLinePrograms.jl @@ -1,6 +1,6 @@ module StraightLinePrograms -import Base: +, -, *, ^, parent +import Base: +, -, *, ^, parent, add!, sub!, mul!, neg! import ..AbstractAlgebra: evaluate diff --git a/src/StraightLinePrograms/straightline.jl b/src/StraightLinePrograms/straightline.jl index d001eea832e4..d7119255fe21 100644 --- a/src/StraightLinePrograms/straightline.jl +++ b/src/StraightLinePrograms/straightline.jl @@ -536,16 +536,16 @@ end ## mutating ops -addeq!(p::SLProgram, q::SLProgram) = combine!(plus, p, q) +add!(p::SLProgram, q::SLProgram) = combine!(plus, p, q) -subeq!(p::SLProgram, q::SLProgram) = combine!(minus, p, q) +sub!(p::SLProgram, q::SLProgram) = combine!(minus, p, q) -function subeq!(p::SLProgram) +function neg!(p::SLProgram) combine!(uniminus, p) p end -muleq!(p::SLProgram, q::SLProgram) = combine!(times, p, q) +mul!(p::SLProgram, q::SLProgram) = combine!(times, p, q) function expeq!(p::SLProgram, e::Integer) combine!(exponentiate, p, e) @@ -564,13 +564,13 @@ end copy_jointype(p::SLProgram, q::SLProgram) = copy_oftype(p, typejoin(constantstype(p), constantstype(q))) -+(p::SLProgram, q::SLProgram) = addeq!(copy_jointype(p, q), q) ++(p::SLProgram, q::SLProgram) = add!(copy_jointype(p, q), q) -*(p::SLProgram, q::SLProgram) = muleq!(copy_jointype(p, q), q) +*(p::SLProgram, q::SLProgram) = mul!(copy_jointype(p, q), q) --(p::SLProgram, q::SLProgram) = subeq!(copy_jointype(p, q), q) +-(p::SLProgram, q::SLProgram) = sub!(copy_jointype(p, q), q) --(p::SLProgram) = subeq!(copy(p)) +-(p::SLProgram) = neg!(copy(p)) ^(p::SLProgram, e::Integer) = expeq!(copy(p), e) @@ -708,7 +708,7 @@ retrieve(ints, cs, xs, res, i, conv::F=identity) where {F} = function evaluate!(res::Vector{S}, p::SLProgram{T}, xs::Vector{S}, conv::F=identity) where {S,T,F} # TODO: handle isempty(lines(p)) - # TODO: use inplace (addeq!, mul!, ... ) when applicable + # TODO: use inplace (add!, mul!, ... ) when applicable # TODO: add permutation of input? empty!(res) @@ -825,13 +825,13 @@ function compile!(p::SLProgram; isPoly::Bool = false) mininput = max(mininput, idy) if isplus(op) if idx == 0 && isPoly - :($rk = Nemo.addeq!($x, $y)) + :($rk = Nemo.add!($x, $y)) else :($rk = $x + $y) end elseif isminus(op) if idx == 0 && isPoly - :($rk = Nemo.subeq!($x, $y)) + :($rk = Nemo.sub!($x, $y)) else :($rk = $x - $y) end diff --git a/src/TropicalGeometry/semiring.jl b/src/TropicalGeometry/semiring.jl index 6b31426f9009..426f7b7771bf 100644 --- a/src/TropicalGeometry/semiring.jl +++ b/src/TropicalGeometry/semiring.jl @@ -401,17 +401,6 @@ function Base.:(^)(a::TropicalSemiringElem, n::Integer) end - -################################################################################ -# -# Unsafe operations -# -################################################################################ - -Oscar.mul!(x::TropicalSemiringElem, y::TropicalSemiringElem, z::TropicalSemiringElem) = y * z -Oscar.addeq!(y::TropicalSemiringElem, z::TropicalSemiringElem) = y + z - - ################################################################################ # # helpers for polymake conversion diff --git a/src/imports.jl b/src/imports.jl index d7e8251a76f3..41769e0ab4bf 100644 --- a/src/imports.jl +++ b/src/imports.jl @@ -55,7 +55,6 @@ import AbstractAlgebra: @attributes, @show_name, @show_special, - addeq!, allow_unicode, base_ring, canonical_unit, diff --git a/test/Rings/AbelianClosure.jl b/test/Rings/AbelianClosure.jl index a39004494e52..26d65cab7cff 100644 --- a/test/Rings/AbelianClosure.jl +++ b/test/Rings/AbelianClosure.jl @@ -194,7 +194,7 @@ end c = rand_elem() aa = deepcopy(a) bb = deepcopy(b) - @test addeq!(a, b) == aa + bb + @test add!(a, b) == aa + bb @test b == bb aa = deepcopy(a) @test Oscar.AbelianClosure.neg!(a) == -aa diff --git a/test/Rings/MPolyQuo.jl b/test/Rings/MPolyQuo.jl index 051c92e99437..9616aceaa0f8 100644 --- a/test/Rings/MPolyQuo.jl +++ b/test/Rings/MPolyQuo.jl @@ -81,7 +81,7 @@ end z = zero(Q) simplify(z) - addeq!(z, Q(x)) + z = add!(z, Q(x)) @test iszero(z) end diff --git a/test/Rings/NumberField.jl b/test/Rings/NumberField.jl index 5e7c20b65c50..1a2e9289bc4f 100644 --- a/test/Rings/NumberField.jl +++ b/test/Rings/NumberField.jl @@ -145,7 +145,7 @@ @test e == b + c e = deepcopy(b) - @inferred addeq!(b, c) + b = @inferred add!(b, c) @test b == e + c end diff --git a/test/Rings/mpoly-graded.jl b/test/Rings/mpoly-graded.jl index af69a35e6189..188d3194d197 100644 --- a/test/Rings/mpoly-graded.jl +++ b/test/Rings/mpoly-graded.jl @@ -120,7 +120,7 @@ end @test (polys[1] + polys[2])^2 == polys[1]^2 + 2*polys[1]*polys[2] + polys[2]^2 @test (polys[3] - polys[4])^2 == polys[3]^2 + 2*(-polys[3])*polys[4] + polys[4]^2 - @test polys[2] * (polys[3] + polys[4]) == Oscar.addeq!(Oscar.mul!(polys[1], polys[2], polys[3]), Oscar.mul!(polys[1], polys[2], polys[4])) + @test polys[2] * (polys[3] + polys[4]) == Oscar.add!(Oscar.mul!(polys[1], polys[2], polys[3]), Oscar.mul!(polys[1], polys[2], polys[4])) @test parent(polys[1]) === RR for k in 1:length(polys[4]) diff --git a/test/Rings/slpolys.jl b/test/Rings/slpolys.jl index 8b923e0a393a..5592b6446d76 100644 --- a/test/Rings/slpolys.jl +++ b/test/Rings/slpolys.jl @@ -250,19 +250,19 @@ end # mutating ops X, Y = gens(S) p = S(x*y-16*y^2) - # SLP.addeq!(p, S(x)) # TODO: this bugs - @test p === addeq!(p, S(x*y)) + # SLP.add!(p, S(x)) # TODO: this bugs + @test p === add!(p, S(x*y)) @test convert(R, p) == 2*x1*y1-16y1^2 @test p == X*Y-16Y^2+X*Y - @test p === SLP.subeq!(p, S(-16y^2)) + @test p === sub!(p, S(-16y^2)) @test convert(R, p) == 2*x1*y1 @test p == X*Y-16Y^2+X*Y- (-16*Y^2) - @test p === SLP.subeq!(p) + @test p === neg!(p) @test convert(R, p) == -2*x1*y1 - # @test p === SLP.muleq!(p, p) # TODO: this bugs - @test p === SLP.muleq!(p, S(-2*x*y)) + # @test p === mul!(p, p) # TODO: this bugs + @test p === mul!(p, S(-2*x*y)) @test convert(R, p) == 4*(x1*y1)^2 @test p === SLP.expeq!(p, 3) @test convert(R, p) == 64*(x1*y1)^6 diff --git a/test/StraightLinePrograms/straightline.jl b/test/StraightLinePrograms/straightline.jl index 9689a066678a..918213117c02 100644 --- a/test/StraightLinePrograms/straightline.jl +++ b/test/StraightLinePrograms/straightline.jl @@ -419,19 +419,19 @@ end q = SLProgram(Const(6)) r = SLProgram(2) - @test p === SLP.addeq!(p, q) + @test p === add!(p, q) @test SLP.evaluate(p, [3]) == 9 @test SLP.aslazyrec(p) == x+6 - @test p === SLP.subeq!(p, r) + @test p === sub!(p, r) @test SLP.evaluate(p, [3, 2]) == 7 @test SLP.aslazyrec(p) == x+6-y - @test p === SLP.subeq!(p) + @test p === neg!(p) @test SLP.evaluate(p, [3, 2]) == -7 @test SLP.aslazyrec(p) == -(x+6-y) - @test p === SLP.muleq!(p, r) + @test p === mul!(p, r) @test SLP.evaluate(p, [3, 2]) == -14 @test SLP.aslazyrec(p) == -(x+6-y)*y @@ -445,19 +445,19 @@ end p = SLProgram{UInt8}(1) q = SLProgram(Const(2)) - SLP.addeq!(p, q) + p = add!(p, q) @test p.cs[1] === 0x2 @test SLP.aslazyrec(p) == x+2 - SLP.muleq!(p, SLProgram(Const(3.0))) + p = mul!(p, SLProgram(Const(3.0))) @test p.cs[2] === 0x3 @test SLP.aslazyrec(p) == (x+2)*3.0 - SLP.subeq!(p, SLProgram(Const(big(4)))) + p = sub!(p, SLProgram(Const(big(4)))) @test p.cs[3] === 0x4 @test SLP.aslazyrec(p) == (x+2)*3.0-big(4) - @test_throws InexactError SLP.addeq!(p, SLProgram(Const(1.2))) + @test_throws InexactError SLP.add!(p, SLProgram(Const(1.2))) # for julia 1.10 and older append! did resize before failing # https://github.com/JuliaLang/julia/pull/51903 VERSION < v"1.11.0-DEV.884" && pop!(p.cs) # set back consistent state @@ -469,7 +469,7 @@ end @test p2 == p @test p2.cs == p.cs @test p2.lines == p.lines - SLP.addeq!(p2, SLProgram(Const(1.2))) + SLP.add!(p2, SLProgram(Const(1.2))) @test p2.cs[4] == 1.2 @test SLP.aslazyrec(p2) == ((((x + 2.0)*3.0) - 4.0) + 1.2) @@ -477,7 +477,7 @@ end @test p3 == p @test p3.cs == p.cs @test p3.lines == p.lines - @test_throws InexactError SLP.addeq!(p3, SLProgram(Const(1.2))) + @test_throws InexactError SLP.add!(p3, SLProgram(Const(1.2))) # unary/binary ops p = SLProgram{BigInt}(1) @@ -529,7 +529,7 @@ end # conversion LazyRec -> SLProgram @test SLProgram(x^2+y) isa SLProgram{Union{}} - p = SLP.muleq!(SLProgram(Const(2)), SLProgram{Int}(x^2+y)) + p = mul!(SLProgram(Const(2)), SLProgram{Int}(x^2+y)) @test p isa SLProgram{Int} @test SLP.evaluate(p, [2, 3]) == 14 @test SLP.aslazyrec(p) == 2*(x^2 + y)