Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ MP.nvariables(::Type{<:Monomial{V}}) where {V} = length(V)
MP.nvariables(m::Monomial) = nvariables(typeof(m))
MP.monomial_type(::Type{V}) where V<:Variable = monomial_type(V())
MP.monomial_type(v::Variable) = Monomial{(v,), 1}
function MP.monomial(vars::Tuple, exps::NTuple{N,Int}) where {N}
@assert length(vars) == length(exps)
return Monomial{vars,N}(exps)
end

MP.exponents(m::Monomial) = m.exponents
MP.exponent(m::Monomial, i::Integer) = m.exponents[i]
Expand Down
4 changes: 4 additions & 0 deletions test/polynomials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ end
@test @inferred(Monomial{tuple(), 0}()) == @inferred(x^0)

@test @inferred(Monomial{(x, y)}([1, 2])) == Monomial{(x, y)}((1, 2))
@test @inferred(monomial((x, y), (1, 2))) == Monomial{(x, y)}((1, 2))
@test_throws AssertionError monomial((x,), (1, 2))
@test_throws AssertionError monomial((y, x), (1, 2))
@test_throws AssertionError monomial((x, x), (1, 2))
end

@testset "terms" begin
Expand Down