Skip to content

Commit

Permalink
Adapt to addeq! deprecation and remove some now unnecessary mutable…
Browse files Browse the repository at this point in the history
… arith methods
  • Loading branch information
lgoettgens committed Sep 19, 2024
1 parent c544c2a commit 7c48143
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 110 deletions.
6 changes: 3 additions & 3 deletions src/InvariantTheory/invariant_rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/NumberTheory/GaloisGrp/GaloisGrp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 22 additions & 8 deletions src/Rings/AbelianClosure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -625,25 +625,39 @@ 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

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
Expand Down
6 changes: 3 additions & 3 deletions src/Rings/MPolyQuo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/Rings/NumberField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions src/Rings/localization_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 0 additions & 8 deletions src/Rings/mpoly-graded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
5 changes: 0 additions & 5 deletions src/Rings/mpolyquo-localizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions src/Rings/slpolys.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/StraightLinePrograms/StraightLinePrograms.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module StraightLinePrograms

import Base: +, -, *, ^, parent
import Base: +, -, *, ^, parent, add!, sub!, mul!, neg!

import ..AbstractAlgebra: evaluate

Expand Down
22 changes: 11 additions & 11 deletions src/StraightLinePrograms/straightline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/TropicalGeometry/semiring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/imports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import AbstractAlgebra:
@attributes,
@show_name,
@show_special,
addeq!,
allow_unicode,
base_ring,
canonical_unit,
Expand Down
2 changes: 1 addition & 1 deletion test/Rings/AbelianClosure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/Rings/MPolyQuo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ end

z = zero(Q)
simplify(z)
addeq!(z, Q(x))
z = add!(z, Q(x))
@test iszero(z)
end

Expand Down
2 changes: 1 addition & 1 deletion test/Rings/NumberField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/Rings/mpoly-graded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
12 changes: 6 additions & 6 deletions test/Rings/slpolys.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7c48143

Please sign in to comment.