Skip to content

Commit 9646c61

Browse files
authored
Merge pull request #126 from JuliaAlgebra/bl/effective_variables
Add effective_variables
2 parents c23eac6 + 0a13a44 commit 9646c61

File tree

9 files changed

+70
-10
lines changed

9 files changed

+70
-10
lines changed

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
MultivariatePolynomials = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3"
44

55
[compat]
6-
Documenter = "^0.19.6"
6+
Documenter = "^0.24.3"

docs/make.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
using Documenter, MultivariatePolynomials
22

33
makedocs(
4-
format = :html,
54
sitename = "MultivariatePolynomials",
5+
6+
format = Documenter.HTML(
7+
# See https://github.com/JuliaDocs/Documenter.jl/issues/868
8+
prettyurls = get(ENV, "CI", nothing) == "true"
9+
),
10+
# See https://github.com/JuliaOpt/JuMP.jl/issues/1576
11+
strict = true,
12+
613
pages = [
714
"Introduction" => "index.md",
815
"Types" => "types.md",
@@ -14,9 +21,4 @@ makedocs(
1421

1522
deploydocs(
1623
repo = "github.com/JuliaAlgebra/MultivariatePolynomials.jl.git",
17-
target = "build",
18-
osname = "linux",
19-
julia = "1.0",
20-
deps = nothing,
21-
make = nothing,
2224
)

docs/src/types.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ AbstractMonomialLike
2323
AbstractMonomial
2424
monomialtype
2525
variables
26+
effective_variables
2627
nvariables
2728
exponents
2829
degree
@@ -56,7 +57,7 @@ polynomialtype
5657
terms
5758
nterms
5859
coefficients
59-
coefficient(p::AbstractPolynomialLike, vars, m::AbstractMonomialLike)
60+
coefficient(p::AbstractPolynomialLike, m::AbstractMonomialLike, vars)
6061
monomials
6162
mindegree
6263
maxdegree

src/polynomial.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export polynomial, polynomial!, polynomialtype, terms, nterms, coefficients, monomials
22
export coefficienttype, monomialtype
3-
export mindegree, maxdegree, extdegree
3+
export mindegree, maxdegree, extdegree, effective_variables
44
export leadingterm, leadingcoefficient, leadingmonomial
55
export removeleadingterm, removemonomials, monic
66

@@ -258,6 +258,18 @@ function extdegree(p::Union{AbstractPolynomialLike, AbstractVector{<:AbstractTer
258258
(mindegree(p, args...), maxdegree(p, args...))
259259
end
260260

261+
"""
262+
effective_variables(p::AbstractPolynomialLike)
263+
264+
Return a vector of `eltype` `variable_union_type(p)` (see [`variable_union_type`](@ref)),
265+
containing all the variables that has nonzero degree in at least one term.
266+
That is, return all the variables `v` such that `maxdegree(p, v)` is not zero.
267+
"""
268+
function effective_variables(p::AbstractPolynomialLike)
269+
VT = variable_union_type(p)
270+
return VT[v for v in variables(p) if !iszero(maxdegree(p, v))]
271+
end
272+
261273
"""
262274
leadingterm(p::AbstractPolynomialLike)
263275

src/variable.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export name, name_base_indices, similarvariable, @similarvariable
1+
export name, name_base_indices, similarvariable, @similarvariable, variable_union_type
22

33
Base.copy(x::AbstractVariable) = x
44

test/monomial.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,19 @@ const MP = MultivariatePolynomials
5151
@test adjoint(x) == x
5252
@test transpose(x^2) == x^2
5353
@test adjoint(x^2) == x^2
54+
55+
@testset "Effective variables" begin
56+
T = variable_union_type(x)
57+
@test x isa T
58+
@test y[2] isa T
59+
@test T[x, y[2]] == @inferred effective_variables(x * y[2])
60+
@test T[x, y[2]] == @inferred effective_variables(y[2] * x)
61+
@test T[x] == @inferred effective_variables(x * y[2]^0)
62+
@test T[x] == @inferred effective_variables(y[2]^0 * x)
63+
@test T[y[2]] == @inferred effective_variables(x^0 * y[2])
64+
@test T[y[2]] == @inferred effective_variables(y[2] * x^0)
65+
@test T[x, y[2]] == @inferred effective_variables(y[3]^0 * x * y[2])
66+
@test T[x, y[2]] == @inferred effective_variables(y[2] * y[3]^0 * x)
67+
@test T[x, y[2]] == @inferred effective_variables(y[2] * x * y[3]^0)
68+
end
5469
end

test/polynomial.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,16 @@ const MP = MultivariatePolynomials
154154
@test variables(v)[1] == x
155155
@test variables(v)[2] == y
156156
end
157+
158+
@testset "Effective variables" begin
159+
Mod.@polyvar x y z
160+
T = variable_union_type(x)
161+
@test x isa T
162+
@test y isa T
163+
@test z isa T
164+
@test T[x] == @inferred effective_variables(x + y - y)
165+
@test T[x, y] == @inferred effective_variables(z + x + y - z)
166+
@test T[y, z] == @inferred effective_variables(z + 0 * x + y)
167+
@test T[z] == @inferred effective_variables(z + 0 * x + y^0)
168+
end
157169
end

test/term.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,17 @@
4848

4949
@test_throws InexactError push!([1], 2x)
5050
@test_throws ErrorException push!([x^2], 2x)
51+
52+
53+
@testset "Effective variables" begin
54+
T = variable_union_type(x)
55+
@test x isa T
56+
@test y isa T
57+
@test T[x, y] == @inferred effective_variables(x * y)
58+
@test T[x, y] == @inferred effective_variables(y * x)
59+
@test T[x] == @inferred effective_variables(x * y^0)
60+
@test T[x] == @inferred effective_variables(y^0 * x)
61+
@test T[y] == @inferred effective_variables(x^0 * y)
62+
@test T[y] == @inferred effective_variables(y * x^0)
63+
end
5164
end

test/variable.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ import MultivariatePolynomials: AbstractVariable, similarvariable, @similarvaria
4949
end
5050
end
5151
end
52+
53+
@testset "Effective variables" begin
54+
@test [x] == @inferred effective_variables(x)
55+
@test [y] == @inferred effective_variables(y)
56+
end
5257
end
5358
@testset "Create similar variable" begin
5459
Mod.@polyvar x y

0 commit comments

Comments
 (0)