Skip to content

Commit

Permalink
Resolve multivariate ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
joschmitt committed Oct 7, 2024
1 parent c640c2e commit 58323e7
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/generic/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2060,30 +2060,24 @@ end
#
###############################################################################

function ==(a::MPoly, n::Union{Integer, Rational, AbstractFloat})
N = size(a.exps, 1)
if n == 0
return a.length == 0
elseif a.length == 1
return a.coeffs[1] == n && monomial_iszero(a.exps, 1, N)
end
return false
# Check whether a is constant and a == n
function _cmp_constant(a::MPoly, n)
return is_constant(a) && (is_zero(a) ? is_zero(n) : coeff(a, 1) == n)
end

==(a::MPoly, n::Union{Integer, Rational, AbstractFloat}) = _cmp_constant(a, n)

==(n::Union{Integer, Rational, AbstractFloat}, a::MPoly) = a == n

function ==(a::MPoly{T}, n::T) where {T <: RingElem}
N = size(a.exps, 1)
if n == 0
return a.length == 0
elseif a.length == 1
return a.coeffs[1] == n && monomial_iszero(a.exps, 1, N)
end
return false
end
==(a::MPoly{T}, n::T) where {T <: RingElem} = _cmp_constant(a, n)

==(n::T, a::MPoly{T}) where {T <: RingElem} = a == n

# To avoid ambiguity with ==(::MPolyRingElem, ::MPolyRingElem)
==(a::MPoly{T}, n::T) where {T <: MPolyRingElem} = _cmp_constant(a, n)

Check warning on line 2077 in src/generic/MPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/MPoly.jl#L2077

Added line #L2077 was not covered by tests

==(n::T, a::MPoly{T}) where {T <: MPolyRingElem} = a == n

Check warning on line 2079 in src/generic/MPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/MPoly.jl#L2079

Added line #L2079 was not covered by tests

###############################################################################
#
# Powering
Expand Down

0 comments on commit 58323e7

Please sign in to comment.