1
1
# We reverse the order of comparisons here so that the result
2
2
# of x < y is equal to the result of Monomial(x) < Monomial(y)
3
- @pure isless (v1:: AbstractVariable , v2:: AbstractVariable ) = name (v1) > name (v2)
4
- isless (m1:: AbstractTermLike , m2:: AbstractTermLike ) = isless (promote (m1, m2)... )
3
+ Base . @pure Base . isless (v1:: AbstractVariable , v2:: AbstractVariable ) = name (v1) > name (v2)
4
+ Base . isless (m1:: AbstractTermLike , m2:: AbstractTermLike ) = isless (promote (m1, m2)... )
5
5
6
- function isless (t1:: AbstractTerm , t2:: AbstractTerm )
6
+ function Base . isless (t1:: AbstractTerm , t2:: AbstractTerm )
7
7
if monomial (t1) < monomial (t2)
8
8
true
9
9
elseif monomial (t1) == monomial (t2)
18
18
# is a polynomial of JuMP affine expression but if we promote it would be a
19
19
# polynomial of quadratic expression
20
20
for op in [:+ , :- , :(== )]
21
- @eval $ op (p1:: APL , p2:: APL ) = $ op (promote (p1, p2)... )
21
+ @eval Base. $ op (p1:: APL , p2:: APL ) = $ op (promote (p1, p2)... )
22
22
end
23
- isapprox (p1:: APL , p2:: APL ; kwargs... ) = isapprox (promote (p1, p2)... ; kwargs... )
23
+ Base . isapprox (p1:: APL , p2:: APL ; kwargs... ) = isapprox (promote (p1, p2)... ; kwargs... )
24
24
25
25
# @eval $op(p::APL, α) = $op(promote(p, α)...) would be less efficient
26
26
for (op, fun) in [(:+ , :plusconstant ), (:- , :minusconstant ), (:* , :multconstant ), (:(== ), :eqconstant )]
27
- @eval $ op (p:: APL , α) = $ fun (p, α)
28
- @eval $ op (α, p:: APL ) = $ fun (α, p)
27
+ @eval Base. $ op (p:: APL , α) = $ fun (p, α)
28
+ @eval Base. $ op (α, p:: APL ) = $ fun (α, p)
29
29
end
30
- isapprox (p:: APL , α; kwargs... ) = isapprox (promote (p, α)... ; kwargs... )
31
- isapprox (α, p:: APL ; kwargs... ) = isapprox (promote (p, α)... ; kwargs... )
30
+ Base . isapprox (p:: APL , α; kwargs... ) = isapprox (promote (p, α)... ; kwargs... )
31
+ Base . isapprox (α, p:: APL ; kwargs... ) = isapprox (promote (p, α)... ; kwargs... )
32
32
33
- ( - ) (m:: AbstractMonomialLike ) = (- 1 ) * m
34
- ( - ) (t:: AbstractTermLike ) = (- coefficient (t)) * monomial (t)
35
- ( - ) (p:: APL ) = polynomial ((- ). (terms (p)))
36
- ( + ) (p:: Union{APL, RationalPoly} ) = p
33
+ Base.: - (m:: AbstractMonomialLike ) = (- 1 ) * m
34
+ Base.: - (t:: AbstractTermLike ) = (- coefficient (t)) * monomial (t)
35
+ Base.: - (p:: APL ) = polynomial ((- ). (terms (p)))
36
+ Base.: + (p:: Union{APL, RationalPoly} ) = p
37
37
38
38
# Avoid adding a zero constant that might artificially increase the Newton polytope
39
39
# Need to add polynomial conversion for type stability
@@ -59,16 +59,16 @@ _multconstant(α, f, p::AbstractPolynomialLike) = _multconstant(α, f, polynomia
59
59
multconstant (α, p:: AbstractPolynomialLike ) = _multconstant (α, β -> α* β, p)
60
60
multconstant (p:: AbstractPolynomialLike , α) = _multconstant (α, β -> β* α, p)
61
61
62
- ( * ) (m1:: AbstractMonomialLike , m2:: AbstractMonomialLike ) = mapexponents (+ , m1, m2)
63
- # (*) (m1::AbstractMonomialLike, m2::AbstractMonomialLike) = *(monomial(m1), monomial(m2))
62
+ Base.: * (m1:: AbstractMonomialLike , m2:: AbstractMonomialLike ) = mapexponents (+ , m1, m2)
63
+ # Base.:* (m1::AbstractMonomialLike, m2::AbstractMonomialLike) = *(monomial(m1), monomial(m2))
64
64
65
- ( * ) (m:: AbstractMonomialLike , t:: AbstractTermLike ) = coefficient (t) * (m * monomial (t))
66
- ( * ) (t:: AbstractTermLike , m:: AbstractMonomialLike ) = coefficient (t) * (monomial (t) * m)
67
- ( * ) (t1:: AbstractTermLike , t2:: AbstractTermLike ) = (coefficient (t1) * coefficient (t2)) * (monomial (t1) * monomial (t2))
65
+ Base.: * (m:: AbstractMonomialLike , t:: AbstractTermLike ) = coefficient (t) * (m * monomial (t))
66
+ Base.: * (t:: AbstractTermLike , m:: AbstractMonomialLike ) = coefficient (t) * (monomial (t) * m)
67
+ Base.: * (t1:: AbstractTermLike , t2:: AbstractTermLike ) = (coefficient (t1) * coefficient (t2)) * (monomial (t1) * monomial (t2))
68
68
69
- ( * ) (t:: AbstractTermLike , p:: APL ) = polynomial (map (te -> t * te, terms (p)))
70
- ( * ) (p:: APL , t:: AbstractTermLike ) = polynomial (map (te -> te * t, terms (p)))
71
- ( * ) (p:: APL , q:: APL ) = polynomial (p) * polynomial (q)
69
+ Base.: * (t:: AbstractTermLike , p:: APL ) = polynomial (map (te -> t * te, terms (p)))
70
+ Base.: * (p:: APL , t:: AbstractTermLike ) = polynomial (map (te -> te * t, terms (p)))
71
+ Base.: * (p:: APL , q:: APL ) = polynomial (p) * polynomial (q)
72
72
73
73
# guaranteed that monomial(t1) > monomial(t2)
74
74
function _polynomial_2terms (t1:: TT , t2:: TT , :: Type{T} ) where {TT<: AbstractTerm , T}
@@ -82,9 +82,9 @@ function _polynomial_2terms(t1::TT, t2::TT, ::Type{T}) where {TT<:AbstractTerm,
82
82
end
83
83
for op in [:+ , :- ]
84
84
@eval begin
85
- $ op (t1:: AbstractTermLike , t2:: AbstractTermLike ) = $ op (term (t1), term (t2))
86
- $ op (t1:: AbstractTerm , t2:: AbstractTerm ) = $ op (promote (t1, t2)... )
87
- function $op (t1:: TT , t2:: TT ) where {T, TT <: AbstractTerm{T} }
85
+ Base. $ op (t1:: AbstractTermLike , t2:: AbstractTermLike ) = $ op (term (t1), term (t2))
86
+ Base. $ op (t1:: AbstractTerm , t2:: AbstractTerm ) = $ op (promote (t1, t2)... )
87
+ function Base . $op (t1:: TT , t2:: TT ) where {T, TT <: AbstractTerm{T} }
88
88
S = Base. promote_op ($ op, T, T)
89
89
# t1 > t2 would compare the coefficient in case the monomials are equal
90
90
# and it will throw a MethodError in case the coefficients are not comparable
@@ -104,9 +104,9 @@ adjoint_operator(m::AbstractMonomial) = m
104
104
adjoint_operator (t:: T ) where {T <: AbstractTerm } = adjoint_operator (coefficient (t)) * monomial (t)
105
105
adjoint_operator (p:: AbstractPolynomialLike ) = polynomial (map (adjoint_operator, terms (p)))
106
106
107
- dot (p1:: AbstractPolynomialLike , p2:: AbstractPolynomialLike ) = p1' * p2
108
- dot (x, p:: AbstractPolynomialLike ) = x' * p
109
- dot (p:: AbstractPolynomialLike , x) = p' * x
107
+ Base . dot (p1:: AbstractPolynomialLike , p2:: AbstractPolynomialLike ) = p1' * p2
108
+ Base . dot (x, p:: AbstractPolynomialLike ) = x' * p
109
+ Base . dot (p:: AbstractPolynomialLike , x) = p' * x
110
110
111
111
# Amazingly, this works! Thanks, StaticArrays.jl!
112
112
"""
@@ -117,4 +117,4 @@ Base.vec(vars::Tuple{Vararg{AbstractVariable}}) = [vars...]
117
117
# vec(vars::Tuple{Vararg{<:TypedVariable}}) = SVector(vars)
118
118
119
119
# https://github.com/JuliaLang/julia/pull/23332
120
- ^ (x:: AbstractPolynomialLike , p:: Integer ) = Base. power_by_squaring (x, p)
120
+ Base.: ^ (x:: AbstractPolynomialLike , p:: Integer ) = Base. power_by_squaring (x, p)
0 commit comments