diff --git a/Project.toml b/Project.toml index 95ebfc01b..80d6b85b6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "AbstractAlgebra" uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" -version = "0.42.5" +version = "0.42.6" [deps] InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" diff --git a/docs/src/ring.md b/docs/src/ring.md index f2d05df1a..ba7c3c2b9 100644 --- a/docs/src/ring.md +++ b/docs/src/ring.md @@ -167,22 +167,21 @@ right, respectively, of `a`. ## Unsafe ring operators -To speed up polynomial arithmetic, various unsafe operators are provided, which +To speed up polynomial arithmetic, various unsafe operators are provided, which may mutate the output rather than create a new object. ```julia zero!(a::NCRingElement) mul!(a::T, b::T, c::T) where T <: NCRingElement add!(a::T, b::T, c::T) where T <: NCRingElement -addeq!(a::T, b::T) where T <: NCRingElement addmul!(a::T, b::T, c::T, t::T) where T <: NCRingElement ``` In each case the mutated object is the leftmost parameter. -The `addeq!(a, b)` operation does the same thing as `add!(a, a, b)`. The +The `add!(a, b)` operation does the same thing as `add!(a, a, b)`. The optional `addmul!(a, b, c, t)` operation does the same thing as -`mul!(t, b, c); addeq!(a, t)` where `t` is a temporary which can be mutated so +`mul!(t, b, c); add!(a, t)` where `t` is a temporary which can be mutated so that an addition allocation is not needed. ## Random generation diff --git a/docs/src/ring_interface.md b/docs/src/ring_interface.md index b555d6841..a83078f50 100644 --- a/docs/src/ring_interface.md +++ b/docs/src/ring_interface.md @@ -562,12 +562,6 @@ add!(c::MyElem, a::MyElem, b::MyElem) Set $c$ to the value $a + b$ in place. Return the mutated value. Aliasing is permitted. -```julia -addeq!(a::MyElem, b::MyElem) -``` - -Set $a$ to $a + b$ in place. Return the mutated value. Aliasing is permitted. - ### Random generation The random functions are only used for test code to generate test data. They therefore @@ -813,7 +807,7 @@ using Random: Random, SamplerTrivial, GLOBAL_RNG using RandomExtensions: RandomExtensions, Make2, AbstractRNG import 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!, + is_exact_type, canonical_unit, isequal, divexact, zero!, mul!, add!, get_cached!, is_unit, characteristic, Ring, RingElem, expressify import Base: show, +, -, *, ^, ==, inv, isone, iszero, one, zero, rand, @@ -980,11 +974,6 @@ function add!(f::ConstPoly{T}, g::ConstPoly{T}, h::ConstPoly{T}) where T <: Ring return f end -function addeq!(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement - f.c += g.c - return f -end - # Random generation RandomExtensions.maketype(R::ConstPolyRing, _) = elem_type(R) diff --git a/src/AbsSeries.jl b/src/AbsSeries.jl index 0f750ed24..259da759a 100644 --- a/src/AbsSeries.jl +++ b/src/AbsSeries.jl @@ -299,7 +299,7 @@ function *(a::AbsPowerSeriesRingElem{T}, b::AbsPowerSeriesRingElem{T}) where T < if lenz > i for j = 2:min(lenb, lenz - i + 1) t = mul!(t, coeff(a, i - 1), coeff(b, j - 1)) - d[i + j - 1] = addeq!(d[i + j - 1], t) + d[i + j - 1] = add!(d[i + j - 1], t) end end end @@ -740,7 +740,7 @@ function Base.inv(a::AbsPowerSeriesRingElem{T}) where T <: FieldElement x = set_precision!(x, la[n]) y = set_precision!(y, la[n]) y = mul!(y, minus_a, x) - y = addeq!(y, two) + y = add!(y, two) x = mul!(x, x, y) n -= 1 end @@ -886,13 +886,13 @@ function sqrt_classical(a::AbsPowerSeriesRingElem; check::Bool=true) for i = 1:div(n - 1, 2) j = n - i p = mul!(p, coeff(asqrt, aval2 + i), coeff(asqrt, aval2 + j)) - c = addeq!(c, p) + c = add!(c, p) end c *= 2 if (n % 2) == 0 i = div(n, 2) p = mul!(p, coeff(asqrt, aval2 + i), coeff(asqrt, aval2 + i)) - c = addeq!(c, p) + c = add!(c, p) end c = coeff(a, n + aval) - c if check @@ -1039,8 +1039,8 @@ function Base.exp(a::AbsPowerSeriesRingElem{T}) where T <: FieldElement x = set_precision!(x, la[n]) one1 = set_precision!(one1, la[n]) t = -log(x) - t = addeq!(t, one1) - t = addeq!(t, a) + t = add!(t, one1) + t = add!(t, a) x = mul!(x, x, t) n -= 1 end diff --git a/src/Deprecations.jl b/src/Deprecations.jl index dc88f5230..8d9546d15 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -13,6 +13,9 @@ @alias FreeAssAlgebra FreeAssociativeAlgebra @alias FreeAssAlgElem FreeAssociativeAlgebraElem +# renamed in 0.42.6 +@alias addeq! add! + ############################################################################### # # Deprecated bindings diff --git a/src/Fraction.jl b/src/Fraction.jl index 04f69335a..da316e507 100644 --- a/src/Fraction.jl +++ b/src/Fraction.jl @@ -831,13 +831,13 @@ function mul!(c::FracElem{T}, a::FracElem{T}, b::FracElem{T}) where {T <: RingEl return c end -function addeq!(a::FracElem{T}, b::FracElem{T}) where {T <: RingElem} +function add!(a::FracElem{T}, b::FracElem{T}) where {T <: RingElem} d1 = denominator(a, false) d2 = denominator(b, false) n1 = numerator(a, false) n2 = numerator(b, false) if d1 == d2 - a.num = addeq!(a.num, b.num) + a.num = add!(a.num, b.num) if !isone(d1) gd = gcd(a.num, d1) if !isone(gd) @@ -848,20 +848,20 @@ function addeq!(a::FracElem{T}, b::FracElem{T}) where {T <: RingElem} elseif isone(d1) if n1 !== n2 a.num = mul!(a.num, a.num, d2) - a.num = addeq!(a.num, n2) + a.num = add!(a.num, n2) else a.num = n1*d2 + n2 end a.den = deepcopy(d2) elseif isone(d2) - a.num = addeq!(a.num, n2*d1) + a.num = add!(a.num, n2*d1) a.den = deepcopy(d1) else gd = gcd(d1, d2) if isone(gd) if n1 !== n2 a.num = mul!(a.num, a.num, d2) - a.num = addeq!(a.num, n2*d1) + a.num = add!(a.num, n2*d1) else a.num = n1*d2 + n2*d1 end diff --git a/src/FreeAssociativeAlgebra.jl b/src/FreeAssociativeAlgebra.jl index 076b40160..01a8f42b8 100644 --- a/src/FreeAssociativeAlgebra.jl +++ b/src/FreeAssociativeAlgebra.jl @@ -199,7 +199,7 @@ function evaluate(a::FreeAssociativeAlgebraElem{T}, vals::Vector{U}) where {T <: r = zero(S) o = one(S) for (c, v) in zip(coefficients(a), exponent_words(a)) - r = addeq!(r, c*prod((vals[i] for i in v), init = o)) + r = add!(r, c*prod((vals[i] for i in v), init = o)) end return r end diff --git a/src/Groups.jl b/src/Groups.jl index f46d784d2..f903aa702 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -236,6 +236,10 @@ end # Mutable API where modifications are recommended for performance reasons ################################################################################ +# further mutable functions in fundamental_interface.jl: +# mul!(out::T, g::T, h::T) where {T<:GroupElem} = g * h +# inv!(out::T, g::T) where {T<:GroupElem} = inv(g) + """ one!(g::GroupElem) @@ -243,22 +247,6 @@ Return `one(g)`, possibly modifying `g`. """ one!(g::GroupElem) = one(parent(g)) -""" - inv!(out::T, g::T) where {GEl <: GroupElem} - -Return `inv(g)`, possibly modifying `out`. Aliasing of `g` with `out` is -allowed. -""" -inv!(out::T, g::T) where {T<:GroupElem} = inv(g) - -""" - mul!(out::T, g::T, h::T) where {GEl <: GroupElem} - -Return `g*h`, possibly modifying `out`. Aliasing of `g` or `h` with `out` is -allowed. -""" -mul!(out::T, g::T, h::T) where {T<:GroupElem} = g * h - """ div_right!(out::T, g::T, h::T) where {GEl <: GroupElem} diff --git a/src/MPoly.jl b/src/MPoly.jl index b580e48c7..7887aeedc 100644 --- a/src/MPoly.jl +++ b/src/MPoly.jl @@ -905,13 +905,13 @@ function evaluate(a::MPolyRingElem{T}, vals::Vector{U}) where {T <: RingElement, j = i = i + 1 while iseven(j) && length(r) > 1 top = pop!(r) - r[end] = addeq!(r[end], top) + r[end] = add!(r[end], top) j >>= 1 end end while length(r) > 1 top = pop!(r) - r[end] = addeq!(r[end], top) + r[end] = add!(r[end], top) end return r[1] end @@ -1037,7 +1037,7 @@ function __evaluate(a, vars, vals, powers) end M = Generic.MPolyBuildCtx(S) push_term!(M, c, v) - addeq!(r, t*finish(M)) + add!(r, t*finish(M)) end return r end diff --git a/src/MatRing.jl b/src/MatRing.jl index 30a6bcc17..a0a1fab9b 100644 --- a/src/MatRing.jl +++ b/src/MatRing.jl @@ -186,7 +186,7 @@ function *(x::MatRingElem{T}, y::MatRingElem{T}) where {T <: NCRingElement} A[i, j] = base_ring(x)() for k = 1:ncols(x) C = mul!(C, x[i, k], y[k, j]) - A[i, j] = addeq!(A[i, j], C) + A[i, j] = add!(A[i, j], C) end end end diff --git a/src/Matrix-Strassen.jl b/src/Matrix-Strassen.jl index 1072cf5a1..f282948c4 100644 --- a/src/Matrix-Strassen.jl +++ b/src/Matrix-Strassen.jl @@ -10,19 +10,18 @@ argument "cutoff" to indicate when the base case should be used. The speedup depends on the ring and the entry sizes. -#Examples: +# Examples ```jldoctest; setup = :(using AbstractAlgebra) julia> m = matrix(ZZ, rand(-10:10, 1000, 1000)); julia> n = similar(m); -julia> mul!(n, m, m); +julia> n = mul!(n, m, m); -julia> Strassen.mul!(n, m, m); - -julia> Strassen.mul!(n, m, m; cutoff = 100); +julia> n = Strassen.mul!(n, m, m); +julia> n = Strassen.mul!(n, m, m; cutoff = 100); ``` """ module Strassen @@ -49,8 +48,7 @@ function mul!(C::MatElem{T}, A::MatElem{T}, B::MatElem{T}; cutoff::Int = cutoff) @assert a == sC[1] && b == sB[1] && c == sC[2] if (a <= cutoff || b <= cutoff || c <= cutoff) - AbstractAlgebra.mul!(C, A, B) - return + return AbstractAlgebra.mul!(C, A, B) end anr = div(a, 2) @@ -142,7 +140,7 @@ function mul!(C::MatElem{T}, A::MatElem{T}, B::MatElem{T}; cutoff::Int = cutoff) #nmod_mat_window_init(Cc, C, 0, 2*bnc, a, c); Cc = view(C, 1:a, 2*bnc+1:c) #nmod_mat_mul(Cc, A, Bc); - AbstractAlgebra.mul!(Cc, A, Bc) + Cc = AbstractAlgebra.mul!(Cc, A, Bc) end if a > 2*anr #last row of A by B -> last row of C @@ -151,7 +149,7 @@ function mul!(C::MatElem{T}, A::MatElem{T}, B::MatElem{T}; cutoff::Int = cutoff) #nmod_mat_window_init(Cr, C, 2*anr, 0, a, c); Cr = view(C, 2*anr+1:a, 1:c) #nmod_mat_mul(Cr, Ar, B); - AbstractAlgebra.mul!(Cr, Ar, B) + Cr = AbstractAlgebra.mul!(Cr, Ar, B) end if b > 2*anc # last col of A by last row of B -> C @@ -162,8 +160,10 @@ function mul!(C::MatElem{T}, A::MatElem{T}, B::MatElem{T}; cutoff::Int = cutoff) #nmod_mat_window_init(Cb, C, 0, 0, 2*anr, 2*bnc); Cb = view(C, 1:2*anr, 1:2*bnc) #nmod_mat_addmul(Cb, Cb, Ac, Br); - AbstractAlgebra.mul!(Cb, Ac, Br, true) + Cb = AbstractAlgebra.mul!(Cb, Ac, Br) end + + return C end #solve_tril fast, recursive diff --git a/src/Matrix.jl b/src/Matrix.jl index bf9d47840..a66d9c0bb 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -1549,7 +1549,7 @@ function tr(x::MatrixElem{T}) where T <: NCRingElement !is_square(x) && error("Not a square matrix in trace") d = zero(base_ring(x)) for i = 1:nrows(x) - d = addeq!(d, x[i, i]) + d = add!(d, x[i, i]) end return d end @@ -1745,7 +1745,7 @@ function lu!(P::Perm, A::MatrixElem{T}) where {T <: FieldElement} q = A[i, c]*d for j = c + 1:n t = mul_red!(t, A[r, j], q, false) - A[i, j] = addeq!(A[i, j], t) + A[i, j] = add!(A[i, j], t) end A[i, c] = R() A[i, rank] = -q @@ -1753,7 +1753,7 @@ function lu!(P::Perm, A::MatrixElem{T}) where {T <: FieldElement} r += 1 c += 1 end - inv!(P) + P = inv!(P) return rank end @@ -1834,7 +1834,7 @@ function fflu!(P::Perm, A::MatrixElem{T}) where {T <: RingElement} for j = c + 1:n A[i, j] = mul_red!(A[i, j], A[i, j], q, false) t = mul_red!(t, A[i, c], A[r, j], false) - A[i, j] = addeq!(A[i, j], t) + A[i, j] = add!(A[i, j], t) A[i, j] = reduce!(A[i, j]) if r > 1 A[i, j] = divexact(A[i, j], d) @@ -1848,7 +1848,7 @@ function fflu!(P::Perm, A::MatrixElem{T}) where {T <: RingElement} r += 1 c += 1 end - inv!(P) + P = inv!(P) return rank, d2 end @@ -1889,7 +1889,7 @@ function fflu!(P::Perm, A::MatrixElem{T}) where {T <: Union{FieldElement, ResEle for j = c + 1:n A[i, j] = mul_red!(A[i, j], A[i, j], q, false) t = mul_red!(t, A[i, c], A[r, j], false) - A[i, j] = addeq!(A[i, j], t) + A[i, j] = add!(A[i, j], t) A[i, j] = reduce!(A[i, j]) if r > 1 A[i, j] = mul!(A[i, j], A[i, j], d) @@ -1903,7 +1903,7 @@ function fflu!(P::Perm, A::MatrixElem{T}) where {T <: Union{FieldElement, ResEle r += 1 c += 1 end - inv!(P) + P = inv!(P) return rank, d2 end @@ -2201,7 +2201,7 @@ function reduce_row!(A::MatrixElem{T}, P::Vector{Int}, L::Vector{Int}, m::Int) w A[m, i] = R() for j = i + 1:L[r] t = mul_red!(t, A[r, j], h, false) - A[m, j] = addeq!(A[m, j], t) + A[m, j] = add!(A[m, j], t) end else # reduce remainder of row for return @@ -2237,7 +2237,7 @@ function reduce_row!(A::MatrixElem{T}, P::Vector{Int}, L::Vector{Int}, m::Int) w for j = i + 1:L[r] t = mul_red!(t, A[r, j], h, false) A[m, j] = mul_red!(A[m, j], A[m, j], d, false) - A[m, j] = addeq!(A[m, j], t) + A[m, j] = add!(A[m, j], t) A[m, j] = reduce!(A[m, j]) end for j = L[r] + 1:L[m] @@ -2293,11 +2293,11 @@ function det_clow(M::MatrixElem{T}) where {T <: RingElement} if !iszero(A[i, j]) for m = j + 1:n C = mul!(C, A[i, j], M[i, m]) - B[m, j] = addeq!(B[m, j], C) + B[m, j] = add!(B[m, j], C) end for m = j + 1:n C = mul!(C, A[i, j], M[i, j]) - B[m, m] = addeq!(B[m, m], -C) + B[m, m] = add!(B[m, m], -C) end end end @@ -2833,7 +2833,7 @@ function _solve_fflu_precomp(p::Perm, FFLU::MatElem{T}, b::MatElem{T}) where {T end if i <= c && piv[i] <= c s = mul_red!(s, FFLU[j, piv[i]], t, false) - x[j, k] = addeq!(x[j, k], s) + x[j, k] = add!(x[j, k], s) end x[j, k] = reduce!(x[j, k]) if i > 1 @@ -2858,7 +2858,7 @@ function _solve_fflu_precomp(p::Perm, FFLU::MatElem{T}, b::MatElem{T}) where {T for j in (piv[l] + 1):c t = mul!(t, y[j, k], FFLU[l, j]) t = mul!(t, t, minus_one) - y[i, k] = addeq!(y[i, k], t) + y[i, k] = add!(y[i, k], t) end flag, y[i, k] = divides(y[i, k], diag[l]) @@ -2956,7 +2956,7 @@ function _solve_lu_precomp(p::Perm, LU::MatElem{T}, b::MatElem{T}) where {T <: F if j == 1 x[i, k] = x[i, k] + t # LU[i, j] * x[j, k] else - x[i, k] = addeq!(x[i, k], t) + x[i, k] = add!(x[i, k], t) end else x[i, k] = deepcopy(x[i, k]) @@ -2976,7 +2976,7 @@ function _solve_lu_precomp(p::Perm, LU::MatElem{T}, b::MatElem{T}) where {T <: F for j in (piv[l] + 1):c # x[i, k] = x[i, k] - x[j, k] * LU[l, j] t = mul_red!(t, y[j, k], -LU[l, j], false) - y[i, k] = addeq!(y[i, k], t) + y[i, k] = add!(y[i, k], t) end y[i, k] = reduce!(y[i, k]) @@ -3749,12 +3749,12 @@ function hessenberg!(A::MatrixElem{T}) where {T <: RingElement} u = mul!(u, A[i, m - 1], h) for j = m:n t = mul!(t, u, A[m, j]) - A[i, j] = addeq!(A[i, j], t) + A[i, j] = add!(A[i, j], t) end u = -u for j = 1:n t = mul!(t, u, A[j, i]) - A[j, m] = addeq!(A[j, m], t) + A[j, m] = add!(A[j, m], t) end A[i, m - 1] = R() end @@ -3886,13 +3886,13 @@ function charpoly_danilevsky_ff!(S::Ring, A::MatrixElem{T}) where {T <: RingElem for kk = 1:n - i - 1 t = mul_red!(t, A[j, n - i], V[kk], false) A[j, kk] = mul_red!(A[j, kk], A[j, kk], h, false) - A[j, kk] = addeq!(A[j, kk], t) + A[j, kk] = add!(A[j, kk], t) A[j, kk] = reduce!(A[j, kk]) end for kk = n - i + 1:n t = mul_red!(t, A[j, n - i], V[kk], false) A[j, kk] = mul_red!(A[j, kk], A[j, kk], h, false) - A[j, kk] = addeq!(A[j, kk], t) + A[j, kk] = add!(A[j, kk], t) A[j, kk] = reduce!(A[j, kk]) end end @@ -4004,11 +4004,11 @@ function charpoly_danilevsky!(S::Ring, A::MatrixElem{T}) where {T <: RingElement for j = 1:n - i for k = 1:n - i - 1 t = mul!(t, A[j, n - i], V[k]) - A[j, k] = addeq!(A[j, k], t) + A[j, k] = add!(A[j, k], t) end for k = n - i + 1:n t = mul!(t, A[j, n - i], V[k]) - A[j, k] = addeq!(A[j, k], t) + A[j, k] = add!(A[j, k], t) end A[j, n - i] = mul!(A[j, n - i], A[j, n - i], h) end @@ -4025,7 +4025,7 @@ function charpoly_danilevsky!(S::Ring, A::MatrixElem{T}) where {T <: RingElement for k = 1:n - i s = addmul_delayed_reduction!(s, A[k, j], W[k], t) end - s = addeq!(s, W[j + 1]) + s = add!(s, W[j + 1]) s = reduce!(s) A[n - i, j] = s end @@ -4464,11 +4464,11 @@ function hnf_cohen!(H::MatrixElem{T}, U::MatrixElem{T}) where {T <: RingElement} q = -div(H[j,i], H[k, i]) for c = i:n t = mul!(t, q, H[k, c]) - H[j, c] = addeq!(H[j, c], t) + H[j, c] = add!(H[j, c], t) end for c = 1:m t = mul!(t, q, U[k, c]) - U[j, c] = addeq!(U[j, c], t) + U[j, c] = add!(U[j, c], t) end end k += 1 @@ -5432,17 +5432,17 @@ function weak_popov_with_pivots!(P::MatElem{T}, W::MatElem{T}, U::MatElem{T}, pi q = -div(P[pivots[i][j], i], P[pivot, i]) for c = 1:n t = mul!(t, q, P[pivot, c]) - P[pivots[i][j], c] = addeq!(P[pivots[i][j], c], t) + P[pivots[i][j], c] = add!(P[pivots[i][j], c], t) end if with_trafo for c = 1:ncols(U) t = mul!(t, q, U[pivot, c]) - U[pivots[i][j], c] = addeq!(U[pivots[i][j], c], t) + U[pivots[i][j], c] = add!(U[pivots[i][j], c], t) end end if extended t = mul!(t, q, W[pivot,1]) - W[pivots[i][j], 1] = addeq!(W[pivots[i][j], 1], t) + W[pivots[i][j], 1] = add!(W[pivots[i][j], 1], t) end end old_pivots = pivots[i] @@ -5539,7 +5539,7 @@ function det_popov(A::MatElem{T}) where {T <: PolyRingElem} q = -div(B[r1, c], B[r2, c]) for j = 1:i + 1 t = mul!(t, q, B[r2, j]) - B[r1, j] = addeq!(B[r1, j], t) + B[r1, j] = add!(B[r1, j], t) end c = find_pivot_popov(B, r1, i) end @@ -5682,12 +5682,12 @@ function popov!(P::MatElem{T}, U::MatElem{T}, with_trafo::Bool = false) where {T q = -div(P[r, c2], P[r2, c2]) for c = 1:n t = mul!(t, q, P[r2, c]) - P[r, c] = addeq!(P[r, c], t) + P[r, c] = add!(P[r, c], t) end if with_trafo for c = 1:ncols(U) t = mul!(t, q, U[r2, c]) - U[r, c] = addeq!(U[r, c], t) + U[r, c] = add!(U[r, c], t) end end end @@ -5746,12 +5746,12 @@ function hnf_via_popov_reduce_row!(H::MatElem{T}, U::MatElem{T}, pivots_hermite: q = -div(H[r, c], H[pivot, c]) for j = c:n t = mul!(t, q, H[pivot, j]) - H[r, j] = addeq!(H[r, j], t) + H[r, j] = add!(H[r, j], t) end if with_trafo for j = 1:ncols(U) t = mul!(t, q, U[pivot, j]) - U[r, j] = addeq!(U[r, j], t) + U[r, j] = add!(U[r, j], t) end end end @@ -5773,12 +5773,12 @@ function hnf_via_popov_reduce_column!(H::MatElem{T}, U::MatElem{T}, pivots_hermi q = -div(H[i, c], H[r, c]) for j = 1:n t = mul!(t, q, H[r, j]) - H[i, j] = addeq!(H[i, j], t) + H[i, j] = add!(H[i, j], t) end if with_trafo for j = 1:ncols(U) t = mul!(t, q, U[r, j]) - U[i, j] = addeq!(U[i, j], t) + U[i, j] = add!(U[i, j], t) end end end @@ -5818,12 +5818,12 @@ function hnf_via_popov!(H::MatElem{T}, U::MatElem{T}, with_trafo::Bool = false) q = -div(H[r1, c], H[r2, c]) for j = 1:n t = mul!(t, q, H[r2, j]) - H[r1, j] = addeq!(H[r1, j], t) + H[r1, j] = add!(H[r1, j], t) end if with_trafo for j = 1:ncols(U) t = mul!(t, q, U[r2, j]) - U[r1, j] = addeq!(U[r1, j], t) + U[r1, j] = add!(U[r1, j], t) end end hnf_via_popov_reduce_row!(H, U, pivots_hermite, r1, with_trafo) @@ -5884,11 +5884,11 @@ function similarity!(A::MatrixElem{T}, r::Int, d::T) where {T <: RingElement} for i = 1:n for j = 1:r - 1 t = mul!(t, A[i, r], d) - A[i, j] = addeq!(A[i, j], t) + A[i, j] = add!(A[i, j], t) end for j = r + 1:n t = mul!(t, A[i, r], d) - A[i, j] = addeq!(A[i, j], t) + A[i, j] = add!(A[i, j], t) end end d = -d diff --git a/src/NCPoly.jl b/src/NCPoly.jl index ba6954693..5e45040a2 100644 --- a/src/NCPoly.jl +++ b/src/NCPoly.jl @@ -222,7 +222,7 @@ function *(a::NCPolyRingElem{T}, b::NCPolyRingElem{T}) where T <: NCRingElem for i = 1:lena - 1 for j = 2:lenb t = mul!(t, coeff(a, i - 1), coeff(b, j - 1)) - d[i + j - 1] = addeq!(d[i + j - 1], t) + d[i + j - 1] = add!(d[i + j - 1], t) end end z = parent(a)(d) @@ -441,7 +441,7 @@ function mullow(a::NCPolyRingElem{T}, b::NCPolyRingElem{T}, n::Int) where T <: N if lenz > i for j = 2:min(lenb, lenz - i + 1) t = mul!(t, coeff(a, i - 1), coeff(b, j - 1)) - d[i + j - 1] = addeq!(d[i + j - 1], t) + d[i + j - 1] = add!(d[i + j - 1], t) end end end @@ -684,7 +684,7 @@ end function addmul!(z::NCPolyRingElem{T}, x::NCPolyRingElem{T}, y::NCPolyRingElem{T}, c::NCPolyRingElem{T}) where T <: NCRingElem c = mul!(c, x, y) - z = addeq!(z, c) + z = add!(z, c) return z end diff --git a/src/NCRings.jl b/src/NCRings.jl index c41d6d08e..7736960d5 100644 --- a/src/NCRings.jl +++ b/src/NCRings.jl @@ -130,25 +130,9 @@ Base.:\(y::Union{Integer, Rational, AbstractFloat}, x::NCRingElem) = divexact_le Base.literal_pow(::typeof(^), x::NCRingElem, ::Val{p}) where {p} = x^p -function zero!(z::NCRingElem) - return zero(parent(z)) -end - -function add!(z::T, x::T, y::T) where T <: NCRingElem - return x + y -end - -function sub!(z::T, x::T, y::T) where T <: NCRingElem - return x - y -end - -function mul!(z::T, x::T, y::T) where T <: NCRingElem - return x*y -end - function addmul!(z::T, x::T, y::T, c::T) where T <: NCRingElem c = mul!(c, x, y) - z = addeq!(z, c) + z = add!(z, c) return z end @@ -213,7 +197,7 @@ end # Define addmul_delayed_reduction! for all ring elem types function addmul_delayed_reduction!(a::T, b::T, c::T, d::T) where T <: NCRingElement d = mul_red!(d, b, c, false) - return addeq!(a, d) + return add!(a, d) end # Fall back to nop diff --git a/src/Poly.jl b/src/Poly.jl index 8386cd7bb..2587e2b17 100644 --- a/src/Poly.jl +++ b/src/Poly.jl @@ -592,7 +592,7 @@ function mul_karatsuba(a::PolyRingElem{T}, b::PolyRingElem{T}) where T <: RingEl end for i = 1:length(z1) u = coeff(r, i + m - 1) - u = addeq!(u, coeff(z1, i - 1)) + u = add!(u, coeff(z1, i - 1)) setcoeff!(r, i + m - 1, u) end # necessary for finite characteristic @@ -691,7 +691,7 @@ function mul_classical(a::PolyRingElem{T}, b::PolyRingElem{T}) where T <: RingEl for i = 1:lena - 1 for j = 2:lenb t = mul_red!(t, coeff(a, i - 1), coeff(b, j - 1), false) - d[i + j - 1] = addeq!(d[i + j - 1], t) + d[i + j - 1] = add!(d[i + j - 1], t) end end for i = 1:lenz @@ -770,9 +770,9 @@ function pow_multinomial(a::PolyRingElem{T}, e::Int) where T <: RingElement for i = 1 : min(k, lena - 1) t = coeff(a, i) * res[(k - i) + 1] u += e + 1 - res[k + 1] = addeq!(res[k + 1], t * u) + res[k + 1] = add!(res[k + 1], t * u) end - d = addeq!(d, first) + d = add!(d, first) res[k + 1] = divexact(res[k + 1], d) end z = parent(a)(res) @@ -1016,7 +1016,7 @@ function mullow(a::PolyRingElem{T}, b::PolyRingElem{T}, n::Int) where T <: RingE if lenz > i for j = 2:min(lenb, lenz - i + 1) t = mul_red!(t, coeff(a, i - 1), coeff(b, j - 1), false) - d[i + j - 1] = addeq!(d[i + j - 1], t) + d[i + j - 1] = add!(d[i + j - 1], t) end end end @@ -1087,7 +1087,7 @@ function divhigh(a::PolyRingElem{T}, b::PolyRingElem{T}, n0::Int) where T <: Rin if da < degree(b) break end - # negate quotient so we can use addeq! below + # negate quotient so we can use add! below q = -divexact(coeff(a, da), leading_coefficient(b)) r = setcoeff!(r, da - degree(b), q) da -= 1 @@ -1096,7 +1096,7 @@ function divhigh(a::PolyRingElem{T}, b::PolyRingElem{T}, n0::Int) where T <: Rin for j = 0:min(degree(b) - 1, i) t = mul!(t, coeff(r, da - degree(b) + j + 1), coeff(b, degree(b) - j - 1)) - c = addeq!(c, t) + c = add!(c, t) end a = setcoeff!(a, da, c) end @@ -1436,7 +1436,7 @@ function mod(f::PolyRingElem{T}, g::PolyRingElem{T}) where T <: RingElement for i = 1:length(g) - 1 c = mul!(c, coeff(g, i - 1), l) u = coeff(f, i + length(f) - length(g) - 1) - u = addeq!(u, c) + u = add!(u, c) f = setcoeff!(f, i + length(f) - length(g) - 1, u) end f = set_length!(f, normalise(f, length(f) - 1)) @@ -1471,7 +1471,7 @@ function Base.divrem(f::PolyRingElem{T}, g::PolyRingElem{T}) where T <: RingElem for i = 1:length(g) - 1 c = mul!(c, coeff(g, i - 1), l) u = coeff(f, i + length(f) - length(g) - 1) - u = addeq!(u, c) + u = add!(u, c) f = setcoeff!(f, i + length(f) - length(g) - 1, u) end f = set_length!(f, normalise(f, length(f) - 1)) @@ -1631,7 +1631,7 @@ function divides(f::PolyRingElem{T}, g::PolyRingElem{T}) where T <: RingElement for i = 1:length(g) c = mul!(c, coeff(g, i - 1), d) u = coeff(f, i + length(f) - length(g) - 1) - u = addeq!(u, c) + u = add!(u, c) f = setcoeff!(f, i + length(f) - length(g) - 1, u) end f = set_length!(f, normalise(f, length(f))) @@ -1720,9 +1720,9 @@ function sqrt_classical(f::PolyRingElem{T}; check::Bool=true) where T <: RingEle for j = lenq - k + 1:lenq if i - j + 2 >= j && j > 0 c = mul_red!(c, d[j], d[i - j + 2], false) - qc = addeq!(qc, c) + qc = add!(qc, c) if (j != i - j + 2) - qc = addeq!(qc, c) + qc = add!(qc, c) end end end @@ -3012,7 +3012,7 @@ function monomial_to_newton!(P::Vector{T}, roots::Vector{T}) where T <: RingElem for i = 1:n - 1 for j = n - 1:-1:i t = mul!(t, P[j + 1], roots[i]) - P[j] = addeq!(P[j], t) + P[j] = add!(P[j], t) end end end @@ -3038,7 +3038,7 @@ function newton_to_monomial!(P::Vector{T}, roots::Vector{T}) where T <: RingElem d = -roots[i] for j = i:n - 1 t = mul!(t, P[j + 1], d) - P[j] = addeq!(P[j], t) + P[j] = add!(P[j], t) end end end @@ -3285,7 +3285,7 @@ end function addmul!(z::PolyRingElem{T}, x::PolyRingElem{T}, y::PolyRingElem{T}, c::PolyRingElem{T}) where T <: RingElement c = mul!(c, x, y) - z = addeq!(z, c) + z = add!(z, c) return z end diff --git a/src/RelSeries.jl b/src/RelSeries.jl index cb1265b2d..7b47e81c5 100644 --- a/src/RelSeries.jl +++ b/src/RelSeries.jl @@ -490,7 +490,7 @@ function *(a::RelPowerSeriesRingElem{T}, b::RelPowerSeriesRingElem{T}) where T < if lenz > i for j = 2:min(lenb, lenz - i + 1) t = mul!(t, polcoeff(a, i - 1), polcoeff(b, j - 1)) - d[i + j - 1] = addeq!(d[i + j - 1], t) + d[i + j - 1] = add!(d[i + j - 1], t) end end end @@ -656,7 +656,7 @@ function mullow(a::RelPowerSeriesRingElem{T}, b::RelPowerSeriesRingElem{T}, n::I if lenz > i for j = 2:min(lenb, lenz - i + 1) t = mul!(t, coeff(a, i - 1), coeff(b, j - 1)) - d[i + j - 1] = addeq!(d[i + j - 1], t) + d[i + j - 1] = add!(d[i + j - 1], t) end end end @@ -996,7 +996,7 @@ function Base.inv(a::RelPowerSeriesRingElem{T}) where T <: FieldElement x = set_precision!(x, la[n]) y = set_precision!(y, la[n]) y = mul!(y, minus_a, x) - y = addeq!(y, two) + y = add!(y, two) x = mul!(x, x, y) n -= 1 end @@ -1164,13 +1164,13 @@ function sqrt_classical(a::RelPowerSeriesRingElem; check::Bool=true) for i = 1:div(n - 1, 2) j = n - i p = mul!(p, polcoeff(asqrt, i), polcoeff(asqrt, j)) - c = addeq!(c, p) + c = add!(c, p) end c *= 2 if (n % 2) == 0 i = div(n, 2) p = mul!(p, polcoeff(asqrt, i), polcoeff(asqrt, i)) - c = addeq!(c, p) + c = add!(c, p) end c = polcoeff(a, n) - c if check @@ -1375,8 +1375,8 @@ function Base.exp(a::RelPowerSeriesRingElem{T}) where T <: FieldElement x = set_precision!(x, la[n]) one1 = set_precision!(one1, la[n]) t = -log(x) - t = addeq!(t, one1) - t = addeq!(t, a) + t = add!(t, one1) + t = add!(t, a) x = mul!(x, x, t) n -= 1 end diff --git a/src/Residue.jl b/src/Residue.jl index 707730885..69e7c8c35 100644 --- a/src/Residue.jl +++ b/src/Residue.jl @@ -420,11 +420,6 @@ function mul!(c::ResElem{T}, a::ResElem{T}, b::ResElem{T}) where {T <: RingEleme return c end -function addeq!(c::ResElem{T}, a::ResElem{T}) where {T <: RingElement} - c.data = mod(data(c) + data(a), modulus(a)) - return c -end - function add!(c::ResElem{T}, a::ResElem{T}, b::ResElem{T}) where {T <: RingElement} c.data = mod(data(a) + data(b), modulus(a)) return c diff --git a/src/ResidueField.jl b/src/ResidueField.jl index fc45c5cfb..0bea99802 100644 --- a/src/ResidueField.jl +++ b/src/ResidueField.jl @@ -441,11 +441,6 @@ function mul!(c::ResFieldElem{T}, a::ResFieldElem{T}, b::ResFieldElem{T}) where return c end -function addeq!(c::ResFieldElem{T}, a::ResFieldElem{T}) where {T <: RingElement} - c.data = mod(data(c) + data(a), modulus(a)) - return c -end - function add!(c::ResFieldElem{T}, a::ResFieldElem{T}, b::ResFieldElem{T}) where {T <: RingElement} c.data = mod(data(a) + data(b), modulus(a)) return c diff --git a/src/algorithms/DensePoly.jl b/src/algorithms/DensePoly.jl index 8ce83b459..a51259fee 100644 --- a/src/algorithms/DensePoly.jl +++ b/src/algorithms/DensePoly.jl @@ -11,7 +11,7 @@ import AbstractAlgebra: Ring import AbstractAlgebra: elem_type import AbstractAlgebra: mul_red! import AbstractAlgebra: reduce! -import AbstractAlgebra: addeq! +import AbstractAlgebra: add! # usual polynomial mullow with the "fast" techniques depending on cutoffs # write the lower Alen coefficients of @@ -72,13 +72,13 @@ function macc_classical( if dr > 0 for j in jstart : jstop t = mul_red!(t, B[Boff + j], C[Coff + i - j], false) - A[Aoff + i] = addeq!(A[Aoff + i], t) + A[Aoff + i] = add!(A[Aoff + i], t) end elseif dr < 0 z = zero(R) for j in jstart : jstop t = mul_red!(t, B[Boff + j], C[Coff + i - j], false) - z = addeq!(z, t) + z = add!(z, t) end A[Aoff + i] -= z else @@ -89,7 +89,7 @@ function macc_classical( end while (j = j + 1) <= jstop t = mul_red!(t, B[Boff + j], C[Coff + i - j], false) - A[Aoff + i] = addeq!(A[Aoff + i], t) + A[Aoff + i] = add!(A[Aoff + i], t) end end reduce!(A[Aoff + i]) @@ -206,7 +206,7 @@ function acc( end else for i in 0 : Blen - 1 - A[Aoff + i] = addeq!(A[Aoff + i], B[Boff + i]) + A[Aoff + i] = add!(A[Aoff + i], B[Boff + i]) end end end diff --git a/src/algorithms/MPolyEvaluate.jl b/src/algorithms/MPolyEvaluate.jl index b8aadead4..a547541c6 100644 --- a/src/algorithms/MPolyEvaluate.jl +++ b/src/algorithms/MPolyEvaluate.jl @@ -4,14 +4,6 @@ # ############################################################################### -function add!(z::T, a, b)::T where T - return a + b -end - -function mul!(z::T, a, b)::T where T - return a*b -end - function pow!(z::T, a, b)::T where T return a^b end @@ -96,7 +88,7 @@ function _horner_lex_rec( end (ta, tc) = _horner_lex_rec(res, ctxA, Bcoeffs, Bexps, Bstart, i-1, var+1, C, ctxC, ta, tc) - res[var] = addeq!(res[var], res[var+1]) + res[var] = add!(res[var], res[var+1]) res[var], ta, tc = mulpow!(res[var], C[var], e - nexte, ta, tc) if i > Bstop @@ -559,13 +551,13 @@ function evaluate_log(f::MPolyRingElem, p::Vector{T}; power_cache = PowerCache{T j = i = i + 1 while iseven(j) && length(r) > 1 top = pop!(r) - r[end] = addeq!(r[end], top) + r[end] = add!(r[end], top) j >>= 1 end end while length(r) > 1 top = pop!(r) - r[end] = addeq!(r[end], top) + r[end] = add!(r[end], top) end return isempty(r) ? zero(S) : r[1] end diff --git a/src/exports.jl b/src/exports.jl index f28d97f04..0ae79e4c1 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -109,7 +109,6 @@ export add_column export add_column! export add_row export add_row! -export addeq! export addmul! export addmul_delayed_reduction! export allow_unicode @@ -174,6 +173,7 @@ export dim export direct_sum export disable_cache! export discriminant +export div! export div_left export div_left! export div_right @@ -212,6 +212,7 @@ export free_associative_algebra export free_module export function_field export gcd +export gcd! export gcd_with_cofactors export gcdinv export gcdx @@ -373,6 +374,7 @@ export max_precision export minors export minpoly export mod +export mod! export module_homomorphism export module_isomorphism export modulus @@ -459,6 +461,7 @@ export reduce! export rel_series export rel_series_type export rels +export rem! export remove export renest export renormalize! diff --git a/src/fundamental_interface.jl b/src/fundamental_interface.jl index 90d1f3c9e..26fa8a502 100644 --- a/src/fundamental_interface.jl +++ b/src/fundamental_interface.jl @@ -50,7 +50,7 @@ julia> elem_type(S) == typeof(x) true ``` """ -elem_type(x) = elem_type(typeof(x)) +elem_type(x) = elem_type(typeof(x)) elem_type(T::DataType) = throw(MethodError(elem_type, (T,))) @doc raw""" @@ -304,35 +304,154 @@ const VarName = Union{Symbol, AbstractString, Char} Return the zero of `parent(a)`, possibly modifying the object `a` in the process. """ -function zero! end +function zero!(a) + return zero(parent(a)) +end @doc raw""" add!(a, b, c) Return `b + c`, possibly modifying the object `a` in the process. """ -function add! end +function add!(a, b, c) + return b + c +end @doc raw""" - addeq!(a, b) + add!(a, b) Return `a + b`, possibly modifying the object `a` in the process. +This is a shorthand for `add!(a, a, b)`. """ -addeq!(a, b) = add!(a, a, b) +add!(a, b) = add!(a, a, b) @doc raw""" sub!(a, b, c) Return `b - c`, possibly modifying the object `a` in the process. """ -function sub! end +function sub!(a, b, c) + return b - c +end + +@doc raw""" + sub!(a, b) + +Return `a - b`, possibly modifying the object `a` in the process. +This is a shorthand for `sub!(a, a, b)`. +""" +sub!(a, b) = sub!(a, a, b) + +@doc raw""" + neg!(a, b) + +Return `-b`, possibly modifying the object `a` in the process. +""" +function neg!(a, b) + return -b +end + +@doc raw""" + neg!(a) + +Return `-a`, possibly modifying the object `a` in the process. +This is a shorthand for `neg!(a, a)`. +""" +neg!(a) = neg!(a, a) @doc raw""" mul!(a, b, c) -Return `b*c`, possibly modifying the object `a` in the process. +Return `b * c`, possibly modifying the object `a` in the process. """ -function mul! end +function mul!(a, b, c) + return b * c +end + +@doc raw""" + mul!(a, b) + +Return `a * b`, possibly modifying the object `a` in the process. +This is a shorthand for `mul!(a, a, b)`. +""" +mul!(a, b) = mul!(a, a, b) + +@doc raw""" + div!(a, b, c) + +Return `div(b, c)`, possibly modifying the object `a` in the process. +""" +function div!(a, b, c) + return div(b, c) +end + +@doc raw""" + div!(a, b) + +Return `div(a, b)`, possibly modifying the object `a` in the process. +This is a shorthand for `div!(a, a, b)`. +""" +div!(a, b) = div!(a, a, b) + +@doc raw""" + rem!(a, b, c) + +Return `rem(b, c)`, possibly modifying the object `a` in the process. +""" +function rem!(a, b, c) + return rem(b, c) +end + +@doc raw""" + rem!(a, b) + +Return `rem(a, b)`, possibly modifying the object `a` in the process. +This is a shorthand for `rem!(a, a, b)`. +""" +rem!(a, b) = rem!(a, a, b) + +@doc raw""" + mod!(a, b, c) + +Return `mod(b, c)`, possibly modifying the object `a` in the process. +""" +function mod!(a, b, c) + return mod(b, c) +end + +@doc raw""" + mod!(a, b) + +Return `mod(a, b)`, possibly modifying the object `a` in the process. +This is a shorthand for `mod!(a, a, b)`. +""" +mod!(a, b) = mod!(a, a, b) + +@doc raw""" + inv!(a, b) + +Return `inv(b)`, possibly modifying the object `a` in the process. +""" +function inv!(a, b) + return inv(b) +end + +@doc raw""" + inv!(a) + +Return `inv(a)`, possibly modifying the object `a` in the process. +This is a shorthand for `inv!(a, a)`. +""" +inv!(a) = inv!(a, a) + +@doc raw""" + gcd!(a, b, c) + +Return `gcd(b, c)`, possibly modifying the object `a` in the process. +""" +function gcd!(a, b, c) + return gcd(b, c) +end @doc raw""" canonical_injection(D, i) @@ -361,4 +480,3 @@ function _number_of_direct_product_factors end Return the homomorphism from the domain `D` into the codomain `C` defined by the data. """ function hom end - diff --git a/src/generic/AbsMSeries.jl b/src/generic/AbsMSeries.jl index 005e331ca..004f97cb5 100644 --- a/src/generic/AbsMSeries.jl +++ b/src/generic/AbsMSeries.jl @@ -619,10 +619,10 @@ end # ############################################################################### -function addeq!(a::AbsMSeries{T}, b::AbsMSeries{T}) where T <: RingElement +function add!(a::AbsMSeries{T}, b::AbsMSeries{T}) where T <: RingElement R = parent(a) prec = min.(precision(a), precision(b)) - a.poly = addeq!(a.poly, b.poly) + a.poly = add!(a.poly, b.poly) if R.weighted_prec == -1 a.poly = truncate_poly(a.poly, prec) a.prec = prec diff --git a/src/generic/AbsSeries.jl b/src/generic/AbsSeries.jl index d81020e58..aa9e4eede 100644 --- a/src/generic/AbsSeries.jl +++ b/src/generic/AbsSeries.jl @@ -246,7 +246,7 @@ function mul!(c::AbsSeries{T}, a::AbsSeries{T}, b::AbsSeries{T}) where T <: Ring return c end -function addeq!(c::AbsSeries{T}, a::AbsSeries{T}) where T <: RingElement +function add!(c::AbsSeries{T}, a::AbsSeries{T}) where T <: RingElement lenc = length(c) lena = length(a) @@ -258,7 +258,7 @@ function addeq!(c::AbsSeries{T}, a::AbsSeries{T}) where T <: RingElement len = max(lenc, lena) fit!(c, len) for i = 1:lena - c.coeffs[i] = addeq!(c.coeffs[i], coeff(a, i - 1)) + c.coeffs[i] = add!(c.coeffs[i], coeff(a, i - 1)) end c.length = normalise(c, len) c.prec = prec @@ -267,9 +267,9 @@ end function add!(c::AbsSeries{T}, a::AbsSeries{T}, b::AbsSeries{T}) where T <: RingElement if c === a - return addeq!(c, b) + return add!(c, b) elseif c === b - return addeq!(c, a) + return add!(c, a) end lena = length(a) lenb = length(b) diff --git a/src/generic/FactoredFraction.jl b/src/generic/FactoredFraction.jl index 29ae0d775..987aff946 100644 --- a/src/generic/FactoredFraction.jl +++ b/src/generic/FactoredFraction.jl @@ -476,16 +476,19 @@ function zero!(c::FactoredFracFieldElem) return c end -function mul!(c::FactoredFracFieldElem{T}, a::FactoredFracFieldElem{T}, b::FactoredFracFieldElem{T}) where T <: RingElement - return a*b +# needed as add!(c::FracElem{T}, a::FracElem{T}, b::FracElem{T}) is incompatible +function add!(c::FactoredFracFieldElem{T}, a::FactoredFracFieldElem{T}, b::FactoredFracFieldElem{T}) where T <: RingElement + return a + b end -function addeq!(a::FactoredFracFieldElem{T}, b::FactoredFracFieldElem{T}) where T <: RingElement - return a + b +# needed as add!(a::FracElem{T}, b::FracElem{T}) is incompatible +function add!(a::FactoredFracFieldElem{T}, b::FactoredFracFieldElem{T}) where T <: RingElement + return a + b end -function add!(c::FactoredFracFieldElem{T}, a::FactoredFracFieldElem{T}, b::FactoredFracFieldElem{T}) where T <: RingElement - return a + b +# needed as mul!(c::FracElem{T}, a::FracElem{T}, b::FracElem{T}) is incompatible +function mul!(c::FactoredFracFieldElem{T}, a::FactoredFracFieldElem{T}, b::FactoredFracFieldElem{T}) where T <: RingElement + return a*b end ############################################################################### diff --git a/src/generic/FunctionField.jl b/src/generic/FunctionField.jl index 029bb3e6e..12a7f697c 100644 --- a/src/generic/FunctionField.jl +++ b/src/generic/FunctionField.jl @@ -191,7 +191,7 @@ function _rat_poly_add(poly1::Poly{S}, den1::S, if isone(d) rpoly = poly1*den2 t = poly2*den1 - rpoly = addeq!(rpoly, t) + rpoly = add!(rpoly, t) rden = den1*den2 else den11 = divexact(den1, d) @@ -199,7 +199,7 @@ function _rat_poly_add(poly1::Poly{S}, den1::S, rpoly = poly1*den22 t = poly2*den11 - rpoly = addeq!(rpoly, t) + rpoly = add!(rpoly, t) if iszero(rpoly) rden = one(R) @@ -1180,7 +1180,7 @@ function add!(c::FunctionFieldElem{T}, return c end -function addeq!(c::FunctionFieldElem{T}, a::FunctionFieldElem{T}) where +function add!(c::FunctionFieldElem{T}, a::FunctionFieldElem{T}) where T <: FieldElement n1, d1 = _rat_poly(c) n2, d2 = _rat_poly(a) diff --git a/src/generic/LaurentPoly.jl b/src/generic/LaurentPoly.jl index f3416594a..f50c7d858 100644 --- a/src/generic/LaurentPoly.jl +++ b/src/generic/LaurentPoly.jl @@ -378,14 +378,6 @@ function mul!(z::LaurentPolyWrap{T}, a::LaurentPolyWrap{T}, b::LaurentPolyWrap{T return z end -function addeq!(c::LaurentPolyWrap{T}, a::LaurentPolyWrap{T}) where T - # TODO: optimize (together with +) - d = c + a - c.poly = d.poly - c.mindeg = d.mindeg - c -end - function add!(c::LaurentPolyWrap{T}, a::LaurentPolyWrap{T}, b::LaurentPolyWrap{T}) where T # TODO: optimize d = a + b diff --git a/src/generic/LaurentSeries.jl b/src/generic/LaurentSeries.jl index 6fc92e900..9f5bb1e56 100644 --- a/src/generic/LaurentSeries.jl +++ b/src/generic/LaurentSeries.jl @@ -768,7 +768,7 @@ function *(a::LaurentSeriesElem{T}, b::LaurentSeriesElem{T}) where {T <: RingEle if ai != 0 for j = 2:min(lenb, lenz - i + 1) t = mul!(t, ai, polcoeff(b, j - 1)) - d[i + j - 1] = addeq!(d[i + j - 1], t) + d[i + j - 1] = add!(d[i + j - 1], t) end end end @@ -924,7 +924,7 @@ function mullow(a::LaurentSeriesElem{T}, b::LaurentSeriesElem{T}, n::Int) where if lenz > i for j = 2:min(lenb, lenz - i + 1) t = mul!(t, polcoeff(a, i - 1), polcoeff(b, j - 1)) - d[i + j - 1] = addeq!(d[i + j - 1], t) + d[i + j - 1] = add!(d[i + j - 1], t) end end end @@ -1370,13 +1370,13 @@ function sqrt_classical(a::LaurentSeriesElem; check::Bool=true) for i = 1:div(n - 1, 2) j = n - i p = mul!(p, polcoeff(asqrt, i), polcoeff(asqrt, j)) - c = addeq!(c, p) + c = add!(c, p) end c *= 2 if (n % 2) == 0 i = div(n, 2) p = mul!(p, polcoeff(asqrt, i), polcoeff(asqrt, i)) - c = addeq!(c, p) + c = add!(c, p) end c = polcoeff(a, n) - c if check @@ -1563,8 +1563,8 @@ function Base.exp(a::LaurentSeriesElem{T}) where T <: FieldElement z = set_precision!(z, la[n]) one1 = set_precision!(one1, la[n]) t = -log(z) - t = addeq!(t, one1) - t = addeq!(t, a) + t = add!(t, one1) + t = add!(t, a) z = mul!(z, z, t) n -= 1 end @@ -1662,7 +1662,7 @@ function mul!(c::LaurentSeriesElem{T}, a::LaurentSeriesElem{T}, b::LaurentSeries if ai != 0 for j = 2:min(lenb, lenc - i + 1) t = mul!(t, polcoeff(a, i - 1), polcoeff(b, j - 1)) - c.coeffs[i + j - 1] = addeq!(c.coeffs[i + j - 1], t) + c.coeffs[i + j - 1] = add!(c.coeffs[i + j - 1], t) end end end @@ -1676,7 +1676,7 @@ function mul!(c::LaurentSeriesElem{T}, a::LaurentSeriesElem{T}, b::LaurentSeries return c end -function addeq!(c::LaurentSeriesElem{T}, a::LaurentSeriesElem{T}) where {T <: RingElement} +function add!(c::LaurentSeriesElem{T}, a::LaurentSeriesElem{T}) where {T <: RingElement} # TODO: write a version which doesn't make a copy b = deepcopy(c) return add!(c, b, a) @@ -1684,9 +1684,9 @@ end function add!(c::LaurentSeriesElem{T}, a::LaurentSeriesElem{T}, b::LaurentSeriesElem{T}) where {T <: RingElement} if c === a - return addeq!(c, b) + return add!(c, b) elseif c === b - return addeq!(c, a) + return add!(c, a) end lena = pol_length(a) lenb = pol_length(b) diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index 2d9b0c8b0..94e91a5f5 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -972,10 +972,10 @@ function Base.push!(G::geobucket{T}, p::T) where T G.buckets[j] = zero(R) end end - G.buckets[i] = addeq!(G.buckets[i], p) + G.buckets[i] = add!(G.buckets[i], p) while i <= G.len if length(G.buckets[i]) >= 4^i - G.buckets[i + 1] = addeq!(G.buckets[i + 1], G.buckets[i]) + G.buckets[i + 1] = add!(G.buckets[i + 1], G.buckets[i]) G.buckets[i] = R() i += 1 end @@ -990,7 +990,7 @@ end function finish(G::geobucket{T}) where T p = G.buckets[1] for i = 2:length(G.buckets) - p = addeq!(p, G.buckets[i]) + p = add!(p, G.buckets[i]) end return p::T end @@ -1132,7 +1132,7 @@ function do_merge(Ac::Vector{T}, Bc::Vector{T}, monomial_set!(Be, r + k, Ae, s1 + i, N) i += 1 elseif cmpexp == 0 - Ac[s1 + i] = addeq!(Ac[s1 + i], Ac[s2 + j]) + Ac[s1 + i] = add!(Ac[s1 + i], Ac[s2 + j]) if !iszero(Ac[s1 + i]) Bc[r + k] = Ac[s1 + i] monomial_set!(Be, r + k, Ae, s1 + i, N) @@ -1775,8 +1775,8 @@ function sqrt_heap(a::MPoly{T}, bits::Int; check::Bool=true) where {T <: RingEle qc = addmul_delayed_reduction!(qc, Qc[v.i], Qc[v.j], c) else c = mul_red!(c, Qc[v.i], Qc[v.j], false) # qc += 2*Q[i]*Q[j] - qc = addeq!(qc, c) - qc = addeq!(qc, c) + qc = add!(qc, c) + qc = add!(qc, c) end end # decide whether node needs processing or reusing @@ -1795,8 +1795,8 @@ function sqrt_heap(a::MPoly{T}, bits::Int; check::Bool=true) where {T <: RingEle qc = addmul_delayed_reduction!(qc, Qc[v.i], Qc[v.j], c) else c = mul_red!(c, Qc[v.i], Qc[v.j], false) # qc += 2*Q[i]*Q[j] - qc = addeq!(qc, c) - qc = addeq!(qc, c) + qc = add!(qc, c) + qc = add!(qc, c) end end # decide whether node needs processing or reusing @@ -2194,7 +2194,7 @@ function pow_fps(f::MPoly{T}, k::Int, bits::Int) where {T <: RingElement} v = I[x.n] largest[v.i] |= topbit t1 = mul!(t1, f.coeffs[v.i], gc[v.j]) - SS = addeq!(SS, t1) + SS = add!(SS, t1) if !monomial_isless(Exps, exp, final_exp, 1, N, par, drmask) temp2 = add!(temp2, fik[v.i], gi[v.j]) C = addmul_delayed_reduction!(C, temp2, t1, temp) @@ -2208,7 +2208,7 @@ function pow_fps(f::MPoly{T}, k::Int, bits::Int) where {T <: RingElement} v = I[xn] largest[v.i] |= topbit t1 = mul!(t1, f.coeffs[v.i], gc[v.j]) - SS = addeq!(SS, t1) + SS = add!(SS, t1) if !monomial_isless(Exps, exp, final_exp, 1, N, par, drmask) temp2 = add!(temp2, fik[v.i], gi[v.j]) C = addmul_delayed_reduction!(C, temp2, t1, temp) @@ -2254,7 +2254,7 @@ function pow_fps(f::MPoly{T}, k::Int, bits::Int) where {T <: RingElement} end if !iszero(C) temp = divexact(C, from_exp(R, exp_copy, 1, N) - kp1f1) - SS = addeq!(SS, temp) + SS = add!(SS, temp) gc[gnext] = divexact(temp, f.coeffs[1]) push!(gi, -from_exp(R, ge, gnext, N)) if (largest[2] & topbit) != 0 @@ -3902,7 +3902,7 @@ function mul!(a::MPoly{T}, b::MPoly{T}, c::MPoly{T}) where {T <: RingElement} return a end -function addeq!(a::MPoly{T}, b::MPoly{T}) where {T <: RingElement} +function add!(a::MPoly{T}, b::MPoly{T}) where {T <: RingElement} t = a + b a.coeffs = t.coeffs a.exps = t.exps diff --git a/src/generic/MatRing.jl b/src/generic/MatRing.jl index fc343d0b2..67c68142a 100644 --- a/src/generic/MatRing.jl +++ b/src/generic/MatRing.jl @@ -94,40 +94,8 @@ end # ############################################################################### -function zero!(M::MatRingElem{T}) where T <: NCRingElement - n = degree(M) - R = base_ring(M) - for i = 1:n - for j = 1:n - M[i, j] = zero(R) - end - end - return M -end - -function mul!(A::MatRingElem{T}, B::MatRingElem{T}, - C::MatRingElem{T}) where T <: NCRingElement - return B*C -end - -function add!(A::MatRingElem{T}, B::MatRingElem{T}, - C::MatRingElem{T}) where T <: NCRingElement - n = degree(A) - for i = 1:n - for j = 1:n - A.entries[i, j] = B.entries[i, j] + C.entries[i, j] - end - end - return A -end - -function addeq!(A::MatRingElem{T}, B::MatRingElem{T}) where T <: NCRingElement - n = degree(A) - for i = 1:n - for j = 1:n - A.entries[i, j] += B.entries[i, j] - end - end +function add!(A::MatRingElem{T}, B::MatRingElem{T}) where T <: NCRingElement + A.entries .+= B.entries return A end diff --git a/src/generic/Matrix.jl b/src/generic/Matrix.jl index d4ab9bd1d..800564ea2 100644 --- a/src/generic/Matrix.jl +++ b/src/generic/Matrix.jl @@ -202,19 +202,18 @@ function matrix_space(R::AbstractAlgebra.NCRing, r::Int, c::Int; cached::Bool = return Generic.MatSpace{T}(R, r, c) end +function AbstractAlgebra.add!(A::Mat{T}, B::Mat{T}, C::Mat{T}) where T + A.entries .= B.entries .+ C.entries + return A +end + function AbstractAlgebra.sub!(A::Mat{T}, B::Mat{T}, C::Mat{T}) where T - A.entries.= B.entries .- C.entries + A.entries .= B.entries .- C.entries return A end -#since type(view(MatElem{T})) != MatElem{T} which breaks -# sub!(A::T, B::T, C::T) where T in AA -function AbstractAlgebra.mul!(A::Mat{T}, B::Mat{T}, C::Mat{T}, f::Bool = false) where T - if f - A.entries .+= (B * C).entries - else - A.entries .= (B * C).entries - end +function AbstractAlgebra.mul!(A::Mat{T}, B::Mat{T}, C::Mat{T}) where T + A.entries .= (B * C).entries return A end diff --git a/src/generic/Misc/Localization.jl b/src/generic/Misc/Localization.jl index 8c8288e67..1f7c27a46 100644 --- a/src/generic/Misc/Localization.jl +++ b/src/generic/Misc/Localization.jl @@ -96,17 +96,6 @@ Poly: deg(N(a/b)), rest the same =========================================== =# -############################################################################### -# -# Unsafe operators and functions -# -############################################################################### - -add!(c::LocalizedEuclideanRingElem, a::LocalizedEuclideanRingElem, b::LocalizedEuclideanRingElem) = a + b - -mul!(c::LocalizedEuclideanRingElem, a::LocalizedEuclideanRingElem, b::LocalizedEuclideanRingElem) = a * b - -addeq!(a::LocalizedEuclideanRingElem, b::LocalizedEuclideanRingElem) = a + b ############################################################################### # diff --git a/src/generic/NCPoly.jl b/src/generic/NCPoly.jl index bebb7bae3..064720981 100644 --- a/src/generic/NCPoly.jl +++ b/src/generic/NCPoly.jl @@ -116,7 +116,7 @@ function mul!(c::NCPoly{T}, a::NCPoly{T}, b::NCPoly{T}) where T <: NCRingElem for i = 1:lena - 1 for j = 2:lenb t = mul!(t, coeff(a, i - 1), coeff(b, j - 1)) - c.coeffs[i + j - 1] = addeq!(c.coeffs[i + j - 1], t) + c.coeffs[i + j - 1] = add!(c.coeffs[i + j - 1], t) end end @@ -125,13 +125,13 @@ function mul!(c::NCPoly{T}, a::NCPoly{T}, b::NCPoly{T}) where T <: NCRingElem return c end -function addeq!(c::NCPoly{T}, a::NCPoly{T}) where T <: NCRingElem +function add!(c::NCPoly{T}, a::NCPoly{T}) where T <: NCRingElem lenc = length(c) lena = length(a) len = max(lenc, lena) fit!(c, len) for i = 1:lena - c.coeffs[i] = addeq!(c.coeffs[i], coeff(a, i - 1)) + c.coeffs[i] = add!(c.coeffs[i], coeff(a, i - 1)) end c = set_length!(c, normalise(c, len)) return c diff --git a/src/generic/Poly.jl b/src/generic/Poly.jl index 3e805287f..af747c598 100644 --- a/src/generic/Poly.jl +++ b/src/generic/Poly.jl @@ -228,7 +228,7 @@ function mul!(c::Poly{T}, a::Poly{T}, b::Poly{T}) where T <: RingElement for i = 1:lena - 1 for j = 2:lenb t = mul!(t, coeff(a, i - 1), coeff(b, j - 1)) - c.coeffs[i + j - 1] = addeq!(c.coeffs[i + j - 1], t) + c.coeffs[i + j - 1] = add!(c.coeffs[i + j - 1], t) end end @@ -237,13 +237,13 @@ function mul!(c::Poly{T}, a::Poly{T}, b::Poly{T}) where T <: RingElement return c end -function addeq!(c::Poly{T}, a::Poly{T}) where T <: RingElement +function add!(c::Poly{T}, a::Poly{T}) where T <: RingElement lenc = length(c) lena = length(a) len = max(lenc, lena) fit!(c, len) for i = 1:lena - c.coeffs[i] = addeq!(c.coeffs[i], coeff(a, i - 1)) + c.coeffs[i] = add!(c.coeffs[i], coeff(a, i - 1)) end c = set_length!(c, normalise(c, len)) return c diff --git a/src/generic/PuiseuxSeries.jl b/src/generic/PuiseuxSeries.jl index f5cace1cf..c8dda9b95 100644 --- a/src/generic/PuiseuxSeries.jl +++ b/src/generic/PuiseuxSeries.jl @@ -764,18 +764,6 @@ function add!(c::PuiseuxSeriesElem{T}, a::PuiseuxSeriesElem{T}, b::PuiseuxSeries return c end -function addeq!(c::PuiseuxSeriesElem{T}, a::PuiseuxSeriesElem{T}) where T <: RingElement - s = gcd(c.scale, a.scale) - zscale = div(c.scale*a.scale, s) - ainf = div(a.scale, s) - cinf = div(c.scale, s) - cnew = inflate(c.data, ainf) - c.data = addeq!(cnew, inflate(a.data, cinf)) - c.scale = zscale - c = rescale!(c) - return c -end - ############################################################################### # # Promotion rules diff --git a/src/generic/QuotientModule.jl b/src/generic/QuotientModule.jl index 9af70039c..502506518 100644 --- a/src/generic/QuotientModule.jl +++ b/src/generic/QuotientModule.jl @@ -124,7 +124,7 @@ function reduce_mod_rels(v::AbstractAlgebra.MatElem{T}, vrels::Vector{<:Abstract q = -q for j = i + 1:ncols(rel) t1 = mul!(t1, q, rel[1, j]) - v[1, start + j - 1] = addeq!(v[1, start + j - 1], t1) + v[1, start + j - 1] = add!(v[1, start + j - 1], t1) end i += 1 end diff --git a/src/generic/RationalFunctionField.jl b/src/generic/RationalFunctionField.jl index a97513e68..70e4118b0 100644 --- a/src/generic/RationalFunctionField.jl +++ b/src/generic/RationalFunctionField.jl @@ -484,11 +484,6 @@ function mul!(c::RationalFunctionFieldElem{T, U}, a::RationalFunctionFieldElem{T return c end -function addeq!(a::RationalFunctionFieldElem{T, U}, b::RationalFunctionFieldElem{T, U}) where {T <: FieldElement, U <: Union{PolyRingElem, MPolyRingElem}} - a.d = addeq!(data(a), data(b)) - return a -end - function add!(c::RationalFunctionFieldElem{T}, a::RationalFunctionFieldElem{T, U}, b::RationalFunctionFieldElem{T, U}) where {T <: FieldElement, U <: Union{PolyRingElem, MPolyRingElem}} c.d = add!(data(c), data(a), data(b)) return c diff --git a/src/generic/RelSeries.jl b/src/generic/RelSeries.jl index 40bfda5fe..859748910 100644 --- a/src/generic/RelSeries.jl +++ b/src/generic/RelSeries.jl @@ -237,7 +237,7 @@ function mul!(c::RelSeries{T}, a::RelSeries{T}, b::RelSeries{T}) where T <: Ring return c end -function addeq!(c::RelSeries{T}, a::RelSeries{T}) where T <: RingElement +function add!(c::RelSeries{T}, a::RelSeries{T}) where T <: RingElement lenc = pol_length(c) lena = pol_length(a) valc = valuation(c) @@ -274,7 +274,7 @@ function addeq!(c::RelSeries{T}, a::RelSeries{T}) where T <: RingElement c.coeffs[i] = R() end for i = vala - valc + 1:min(lenc, lenr, lena + vala - valc) - c.coeffs[i] = addeq!(c.coeffs[i], a.coeffs[i - vala + valc]) + c.coeffs[i] = add!(c.coeffs[i], a.coeffs[i - vala + valc]) end for i = max(lenc, vala - valc) + 1:min(lena + vala - valc, lenr) c.coeffs[i] = deepcopy(a.coeffs[i - vala + valc]) @@ -289,9 +289,9 @@ end function add!(c::RelSeries{T}, a::RelSeries{T}, b::RelSeries{T}) where T <: RingElement if c === a - return addeq!(c, b) + return add!(c, b) elseif c === b - return addeq!(c, a) + return add!(c, a) end lena = pol_length(a) lenb = pol_length(b) diff --git a/src/generic/SparsePoly.jl b/src/generic/SparsePoly.jl index c2e977321..ff0e5f5b1 100644 --- a/src/generic/SparsePoly.jl +++ b/src/generic/SparsePoly.jl @@ -738,14 +738,6 @@ function mul!(a::SparsePoly{T}, b::SparsePoly{T}, c::SparsePoly{T}) where {T <: return a end -function addeq!(a::SparsePoly{T}, b::SparsePoly{T}) where {T <: RingElement} - t = a + b - a.coeffs = t.coeffs - a.exps = t.exps - a.length = t.length - return a -end - function add!(a::SparsePoly{T}, b::SparsePoly{T}, c::SparsePoly{T}) where {T <: RingElement} t = b + c a.coeffs = t.coeffs diff --git a/src/generic/TotalFraction.jl b/src/generic/TotalFraction.jl index 08789b84f..175063101 100644 --- a/src/generic/TotalFraction.jl +++ b/src/generic/TotalFraction.jl @@ -429,24 +429,24 @@ function mul!(c::TotFrac{T}, a::TotFrac{T}, b::TotFrac{T}) where {T <: RingElem} return c end -function addeq!(a::TotFrac{T}, b::TotFrac{T}) where {T <: RingElem} +function add!(a::TotFrac{T}, b::TotFrac{T}) where {T <: RingElem} R = base_ring(b) d1 = denominator(a, false) d2 = denominator(b, false) n1 = numerator(a, false) n2 = numerator(b, false) if d1 == d2 - a.num = addeq!(a.num, b.num) + a.num = add!(a.num, b.num) elseif isone(d1) if n1 !== n2 a.num = mul!(a.num, a.num, d2) - a.num = addeq!(a.num, n2) + a.num = add!(a.num, n2) else a.num = n1*d2 + n2 end a.den = deepcopy(d2) elseif isone(d2) - a.num = addeq!(a.num, n2*d1) + a.num = add!(a.num, n2*d1) a.den = deepcopy(d1) else a.num = d1*n2 + d2*n1 diff --git a/src/generic/UnivPoly.jl b/src/generic/UnivPoly.jl index 8d5238396..7aa884d6e 100644 --- a/src/generic/UnivPoly.jl +++ b/src/generic/UnivPoly.jl @@ -1007,12 +1007,12 @@ function fit!(a::UnivPoly, n::Int) end function add!(a::UnivPoly{T}, b::UnivPoly{T}, c::UnivPoly{T}) where {T <: RingElement} - a.p = (b + c).p + a.p = add!(a.p, b.p, c.p) return a end function mul!(a::UnivPoly{T}, b::UnivPoly{T}, c::UnivPoly{T}) where {T <: RingElement} - a.p = (b*c).p + a.p = mul!(a.p, b.p, c.p) return a end diff --git a/src/generic/imports.jl b/src/generic/imports.jl index 3e3820f85..1943eb985 100644 --- a/src/generic/imports.jl +++ b/src/generic/imports.jl @@ -96,7 +96,6 @@ import ..AbstractAlgebra: RingElement import ..AbstractAlgebra: _can_solve_with_solution_fflu import ..AbstractAlgebra: _can_solve_with_solution_lu import ..AbstractAlgebra: add! -import ..AbstractAlgebra: addeq! import ..AbstractAlgebra: addmul! import ..AbstractAlgebra: base_ring import ..AbstractAlgebra: base_ring_type diff --git a/src/julia/Float.jl b/src/julia/Float.jl index 61648a777..c11f6688a 100644 --- a/src/julia/Float.jl +++ b/src/julia/Float.jl @@ -161,17 +161,6 @@ end # No actual mutation is permitted for Julia types # See #1077 -function zero!(a::T) where T <: AbstractFloat - return T(0) -end - -function mul!(a::T, b::T, c::T) where T <: AbstractFloat - return b*c -end - -function add!(a::T, b::T, c::T) where T <: AbstractFloat - return b + c -end function addmul!(a::T, b::T, c::T, d::T) where T <: AbstractFloat return a + b*c diff --git a/src/julia/GF.jl b/src/julia/GF.jl index 1e03f3648..a1d9cba76 100644 --- a/src/julia/GF.jl +++ b/src/julia/GF.jl @@ -360,10 +360,6 @@ function zero!(z::GFElem{T}) where T <: Integer return GFElem{T}(d, R) end -function mul!(z::GFElem{T}, x::GFElem{T}, y::GFElem{T}) where T <: Integer - return x*y -end - function mul!(z::GFElem{BigInt}, x::GFElem{BigInt}, y::GFElem{BigInt}) R = parent(x) p = R.p::BigInt @@ -375,14 +371,10 @@ function mul!(z::GFElem{BigInt}, x::GFElem{BigInt}, y::GFElem{BigInt}) end end -function addeq!(z::GFElem{T}, x::GFElem{T}) where T <: Integer - return z + x -end - -function addeq!(z::GFElem{BigInt}, x::GFElem{BigInt}) +function add!(z::GFElem{BigInt}, x::GFElem{BigInt}) R = parent(x) p = R.p::BigInt - d = addeq!(z.d, x.d) + d = add!(z.d, x.d) if d < p return GFElem{BigInt}(d, R) else @@ -390,10 +382,6 @@ function addeq!(z::GFElem{BigInt}, x::GFElem{BigInt}) end end -function add!(z::GFElem{T}, x::GFElem{T}, y::GFElem{T}) where T <: Integer - return x + y -end - function add!(z::GFElem{BigInt}, x::GFElem{BigInt}, y::GFElem{BigInt}) R = parent(x) p = R.p::BigInt diff --git a/src/julia/Integer.jl b/src/julia/Integer.jl index f629aff4c..598e248ac 100644 --- a/src/julia/Integer.jl +++ b/src/julia/Integer.jl @@ -539,17 +539,6 @@ end # No actual mutation is permitted for Julia types # See #1077 -function zero!(a::T) where T <: Integer - return T(0) -end - -function mul!(a::T, b::T, c::T) where T <: Integer - return b*c -end - -function add!(a::T, b::T, c::T) where T <: Integer - return b + c -end function addmul!(a::T, b::T, c::T, d::T) where T <: Integer return a + b*c diff --git a/src/julia/Rational.jl b/src/julia/Rational.jl index caef7d85a..27aeb18d2 100644 --- a/src/julia/Rational.jl +++ b/src/julia/Rational.jl @@ -231,9 +231,9 @@ end function add!(a::Rational{T}, b::Rational{T}, c::Rational{T}) where T <: Integer if a === b - return addeq!(a, c) + return add!(a, c) elseif a == c - return addeq!(a, b) + return add!(a, b) else # no aliasing n = a.num d = a.den @@ -253,7 +253,7 @@ function add!(a::Rational{T}, b::Rational{T}, c::Rational{T}) where T <: Integer end end -function addeq!(a::Rational{T}, b::Rational{T}) where T <: Integer +function add!(a::Rational{T}, b::Rational{T}) where T <: Integer if a === b if iseven(a.den) return Rational{T}(a.num, div(b.den, 2)) @@ -281,18 +281,10 @@ end function addmul!(a::Rational{T}, b::Rational{T}, c::Rational{T}, d::Rational{T}) where T <: Integer d = mul!(d, b, c) - a = addeq!(a, d) + a = add!(a, d) return a end -sub!(z::Rational{T}, x::Rational{T}, y::T) where T <: Integer = x - y - -neg!(z::Rational{T}, x::Rational{T}) where T <: Integer = -x - -add!(z::Rational{T}, x::Rational{T}, y::T) where T <: Integer = x + y - -mul!(z::Rational{T}, x::Rational{T}, y::T) where T <: Integer = x * y - ############################################################################### # # Random generation diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index ffe2541cd..7fc245873 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -198,7 +198,7 @@ function test_NCRing_interface(R::AbstractAlgebra.NCRing; reps = 50) x = deepcopy(b) @test add!(x, a, x) == ab x = deepcopy(a) - @test addeq!(x, b) == ab + @test add!(x, b) == ab # isapprox as BigFloat may fuse # matrices don't implement addmul! diff --git a/test/algorithms/GenericFunctions-test.jl b/test/algorithms/GenericFunctions-test.jl index 5d797298d..be844b28b 100644 --- a/test/algorithms/GenericFunctions-test.jl +++ b/test/algorithms/GenericFunctions-test.jl @@ -11,7 +11,6 @@ using ..RandomExtensions: RandomExtensions, Make2, AbstractRNG import AbstractAlgebra: Ring import AbstractAlgebra: RingElem import AbstractAlgebra: add! -import AbstractAlgebra: addeq! import AbstractAlgebra: base_ring import AbstractAlgebra: base_ring_type import AbstractAlgebra: canonical_unit @@ -209,11 +208,6 @@ function add!(f::ConstPoly{T}, g::ConstPoly{T}, h::ConstPoly{T}) where T <: Ring return f end -function addeq!(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement - f.c += g.c - return f -end - # Random generation RandomExtensions.maketype(R::ConstPolyRing, _) = elem_type(R) diff --git a/test/generic/AbsSeries-test.jl b/test/generic/AbsSeries-test.jl index 6088f9ac8..fc019eb42 100644 --- a/test/generic/AbsSeries-test.jl +++ b/test/generic/AbsSeries-test.jl @@ -1244,7 +1244,7 @@ end @test isequal(f, f0) f1 = deepcopy(f) - f1 = addeq!(f1, g) + f1 = add!(f1, g) @test isequal(h, k) @test isequal(g, g0) diff --git a/test/generic/FreeAssociativeAlgebra-test.jl b/test/generic/FreeAssociativeAlgebra-test.jl index 2782469b2..c1f8c713b 100644 --- a/test/generic/FreeAssociativeAlgebra-test.jl +++ b/test/generic/FreeAssociativeAlgebra-test.jl @@ -73,7 +73,7 @@ f4 = zero(S) for t in terms(f1) - f4 = addeq!(f4, t) + f4 = add!(f4, t) end @test f1 == f4 diff --git a/test/generic/FunctionField-test.jl b/test/generic/FunctionField-test.jl index 008de4ab2..c533c788b 100644 --- a/test/generic/FunctionField-test.jl +++ b/test/generic/FunctionField-test.jl @@ -781,7 +781,7 @@ end @test isequal(f, f0) f1 = deepcopy(f) - f1 = addeq!(f1, g) + f1 = add!(f1, g) @test isequal(h, k) @test isequal(g, g0) @@ -833,7 +833,7 @@ end @test isequal(f, f0) f1 = deepcopy(f) - f1 = addeq!(f1, g) + f1 = add!(f1, g) @test isequal(h, k) @test isequal(g, g0) diff --git a/test/generic/LaurentPoly-test.jl b/test/generic/LaurentPoly-test.jl index f62607c43..6ff96c1df 100644 --- a/test/generic/LaurentPoly-test.jl +++ b/test/generic/LaurentPoly-test.jl @@ -421,11 +421,11 @@ end @test t == s # TODO: add a test for when s.poly is immutable - # addeq! + # add! p = rand(L, -10:10, -10:10) q = rand(L, -10:10, -10:10) t = p + q - s = addeq!(p, q) + s = add!(p, q) @test s === p == t # TODO: add a test for when p.poly is immutable diff --git a/test/generic/LaurentSeries-test.jl b/test/generic/LaurentSeries-test.jl index 89d1c6e84..350085775 100644 --- a/test/generic/LaurentSeries-test.jl +++ b/test/generic/LaurentSeries-test.jl @@ -397,7 +397,7 @@ end b = 83 + 43*x^10 + O(x^20) c = a + b ccp = deepcopy(c) - addeq!(a, b) + a = add!(a, b) @test c - a == 0 @test c - ccp == 0 end diff --git a/test/generic/Matrix-test.jl b/test/generic/Matrix-test.jl index 487aa6397..b647a3f58 100644 --- a/test/generic/Matrix-test.jl +++ b/test/generic/Matrix-test.jl @@ -59,7 +59,7 @@ AbstractAlgebra.parent_type(::Type{F2Elem}) = F2 AbstractAlgebra.elem_type(::Type{F2}) = F2Elem AbstractAlgebra.parent(x::F2Elem) = F2() AbstractAlgebra.mul!(x::F2Elem, y::F2Elem, z::F2Elem) = y * z -AbstractAlgebra.addeq!(x::F2Elem, y::F2Elem) = x + y +AbstractAlgebra.add!(x::F2Elem, y::F2Elem) = x + y AbstractAlgebra.divexact(x::F2Elem, y::F2Elem) = y.x ? x : throw(DivideError()) Random.rand(rng::AbstractRNG, sp::Random.SamplerTrivial{F2}) = F2Elem(rand(rng, Bool)) diff --git a/test/generic/RelSeries-test.jl b/test/generic/RelSeries-test.jl index 245a4a958..f25a1a999 100644 --- a/test/generic/RelSeries-test.jl +++ b/test/generic/RelSeries-test.jl @@ -1282,7 +1282,7 @@ end @test isequal(f, f0) f1 = deepcopy(f) - f1 = addeq!(f1, g) + f1 = add!(f1, g) @test isequal(h, k) @test isequal(g, g0) diff --git a/test/generic/TotalFraction-test.jl b/test/generic/TotalFraction-test.jl index fdaeebcf4..3156b4661 100644 --- a/test/generic/TotalFraction-test.jl +++ b/test/generic/TotalFraction-test.jl @@ -241,34 +241,34 @@ end a = S(5, 7) b = S(1, 7) - a = addeq!(a, b) + a = add!(a, b) @test a == S(6, 7) a = S(3, 1) - a = addeq!(a, a) + a = add!(a, a) @test a == S(6, 1) a = S(3, 1) b = S(5, 7) - a = addeq!(a, b) + a = add!(a, b) @test a == S(2, 7) a = S(5, 7) b = S(3, 1) - a = addeq!(a, b) + a = add!(a, b) @test a == S(2, 7) a = S(3, 5) b = S(1, 7) - a = addeq!(a, b) + a = add!(a, b) @test a == S(2, 11) diff --git a/test/generic/UnivPoly-test.jl b/test/generic/UnivPoly-test.jl index 1438f0f30..b3104697e 100644 --- a/test/generic/UnivPoly-test.jl +++ b/test/generic/UnivPoly-test.jl @@ -1106,7 +1106,7 @@ end @test f1 == g + h f2 = deepcopy(f) - f2 = addeq!(f2, g) + f2 = add!(f2, g) @test f2 == f + g diff --git a/test/julia/GFElem-test.jl b/test/julia/GFElem-test.jl index 93c65626d..6f6ff497e 100644 --- a/test/julia/GFElem-test.jl +++ b/test/julia/GFElem-test.jl @@ -130,12 +130,12 @@ end if Int == Int32 F = GF(2147483659) a = F(2147483659 - 1) - @test addeq!(a, a) == F(2147483657) + @test add!(a, a) == F(2147483657) @test add!(a, a, a) == F(2147483657) else F = GF(4611686018427388039) a = F(4611686018427388039 - 1) - @test addeq!(a, a) == F(4611686018427388037) + @test add!(a, a) == F(4611686018427388037) @test add!(a, a, a) == F(4611686018427388037) end end