Skip to content

Commit e78a3d4

Browse files
authored
Merge pull request #51 from JuliaAlgebra/bl/variable_union_type
Implement variable_union_type
2 parents 765201f + 609b989 commit e78a3d4

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1111
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1212

1313
[compat]
14-
MultivariatePolynomials = "~0.3"
14+
MultivariatePolynomials = "~0.3.2"
1515
Reexport = ">= 0.2"
1616
julia = "1"

src/DynamicPolynomials.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ include("monovec.jl")
1313
include("poly.jl")
1414
const TermPoly{C, T} = Union{Term{C, T}, Polynomial{C, T}}
1515
const PolyType{C} = Union{Polynomial{C}, Term{C}, Monomial{C}, PolyVar{C}}
16+
MP.variable_union_type(::Union{PolyType{C}, Type{<:PolyType{C}}}) where {C} = PolyVar{C}
1617
MP.constantmonomial(::Type{<:PolyType{C}}) where {C} = Monomial{C}()
1718
MP.constantmonomial(p::PolyType) = Monomial(_vars(p), zeros(Int, nvariables(p)))
1819
MP.monomialtype(::Type{<:PolyType{C}}) where C = Monomial{C}

test/mono.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
@test vars == (x, y, z)
2626
end
2727

28+
@testset "variable_union_type" begin
29+
@polyvar x
30+
@test DynamicPolynomials.MP.variable_union_type(x) == PolyVar{true}
31+
@test DynamicPolynomials.MP.variable_union_type(x^2) == PolyVar{true}
32+
@test DynamicPolynomials.MP.variable_union_type(2x) == PolyVar{true}
33+
@test DynamicPolynomials.MP.variable_union_type(x + 1) == PolyVar{true}
34+
@ncpolyvar y
35+
@test DynamicPolynomials.MP.variable_union_type(y) == PolyVar{false}
36+
@test DynamicPolynomials.MP.variable_union_type(y^2) == PolyVar{false}
37+
@test DynamicPolynomials.MP.variable_union_type(2y) == PolyVar{false}
38+
@test DynamicPolynomials.MP.variable_union_type(y + 1) == PolyVar{false}
39+
end
2840
@testset "PolyVar" begin
2941
@test zeroterm(PolyVar{true}) == 0
3042
@test zero(PolyVar{true}) == 0

0 commit comments

Comments
 (0)