From 609b98906dd28edff8e738c59a349ac5b8c42433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 31 Aug 2019 18:27:14 +0200 Subject: [PATCH] Implement variable_union_type --- Project.toml | 2 +- src/DynamicPolynomials.jl | 1 + test/mono.jl | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index fde1223..3192c2a 100644 --- a/Project.toml +++ b/Project.toml @@ -11,6 +11,6 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -MultivariatePolynomials = "~0.3" +MultivariatePolynomials = "~0.3.2" Reexport = ">= 0.2" julia = "1" diff --git a/src/DynamicPolynomials.jl b/src/DynamicPolynomials.jl index 24af9e5..8eb96ee 100644 --- a/src/DynamicPolynomials.jl +++ b/src/DynamicPolynomials.jl @@ -13,6 +13,7 @@ include("monovec.jl") include("poly.jl") const TermPoly{C, T} = Union{Term{C, T}, Polynomial{C, T}} const PolyType{C} = Union{Polynomial{C}, Term{C}, Monomial{C}, PolyVar{C}} +MP.variable_union_type(::Union{PolyType{C}, Type{<:PolyType{C}}}) where {C} = PolyVar{C} MP.constantmonomial(::Type{<:PolyType{C}}) where {C} = Monomial{C}() MP.constantmonomial(p::PolyType) = Monomial(_vars(p), zeros(Int, nvariables(p))) MP.monomialtype(::Type{<:PolyType{C}}) where C = Monomial{C} diff --git a/test/mono.jl b/test/mono.jl index 1d16296..a7f7d01 100644 --- a/test/mono.jl +++ b/test/mono.jl @@ -25,6 +25,18 @@ @test vars == (x, y, z) end + @testset "variable_union_type" begin + @polyvar x + @test DynamicPolynomials.MP.variable_union_type(x) == PolyVar{true} + @test DynamicPolynomials.MP.variable_union_type(x^2) == PolyVar{true} + @test DynamicPolynomials.MP.variable_union_type(2x) == PolyVar{true} + @test DynamicPolynomials.MP.variable_union_type(x + 1) == PolyVar{true} + @ncpolyvar y + @test DynamicPolynomials.MP.variable_union_type(y) == PolyVar{false} + @test DynamicPolynomials.MP.variable_union_type(y^2) == PolyVar{false} + @test DynamicPolynomials.MP.variable_union_type(2y) == PolyVar{false} + @test DynamicPolynomials.MP.variable_union_type(y + 1) == PolyVar{false} + end @testset "PolyVar" begin @test zeroterm(PolyVar{true}) == 0 @test zero(PolyVar{true}) == 0