Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bool coefficient_type for monomials #280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 2 deletions src/MultivariatePolynomials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract type AbstractPolynomialLike{T} <: MA.AbstractMutable end
"""
AbstractTermLike{T}

Abstract type for a value that can act like a term. For instance, an `AbstractMonomial` is an `AbstractTermLike{Int}` since it can act as a term with coefficient `1`.
Abstract type for a value that can act like a term. For instance, an `AbstractMonomial` is an `AbstractTermLike{Bool}` since it can act as a term with coefficient `1`.
"""
abstract type AbstractTermLike{T} <: AbstractPolynomialLike{T} end

Expand All @@ -27,7 +27,7 @@ abstract type AbstractTermLike{T} <: AbstractPolynomialLike{T} end

Abstract type for a value that can act like a monomial. For instance, an `AbstractVariable` is an `AbstractMonomialLike` since it can act as a monomial of one variable with degree `1`.
"""
abstract type AbstractMonomialLike <: AbstractTermLike{Int} end
abstract type AbstractMonomialLike <: AbstractTermLike{Bool} end

"""
AbstractVariable <: AbstractMonomialLike
Expand Down
6 changes: 3 additions & 3 deletions src/term.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ difference between this and `coef * mono`:
Converts the polynomial `p` to a term.
When applied on a polynomial, it throws an `InexactError` if it has more than one term.
When applied to a term, it is the identity and does not copy it.
When applied to a monomial, it create a term of type `AbstractTerm{Int}`.
When applied to a monomial, it create a term of type `AbstractTerm{Bool}`.
"""
function term end
term(coef, var::AbstractVariable) = term(coef, monomial(var))
Expand Down Expand Up @@ -45,7 +45,7 @@ Returns the type of the terms of a polynomial of type `PT` but with coefficient
"""
term_type(::Type{T}) where {T<:AbstractTerm} = T
term_type(p::Type{<:_APL}, ::Type{T}) where {T} = term_type(term_type(p), T)
term_type(::Type{M}) where {M<:AbstractMonomialLike} = term_type(M, Int)
term_type(::Type{M}) where {M<:AbstractMonomialLike} = term_type(M, Bool)
term_type(v::Type{<:AbstractVariable}) = term_type(monomial_type(v))
function term_type(v::Type{<:AbstractVariable}, ::Type{T}) where {T}
return term_type(monomial_type(v), T)
Expand Down Expand Up @@ -134,7 +134,7 @@ Returns the coefficient type of a polynomial of type `PT`.

Calling `coefficient_type` on ``(4//5)x^2y`` should return `Rational{Int}`,
calling `coefficient_type` on ``1.0x^2y + 2.0x`` should return `Float64` and
calling `coefficient_type` on ``xy`` should return `Int`.
calling `coefficient_type` on ``xy`` should return `Bool`.
"""
function coefficient_type(
::Union{PT,Type{PT},AbstractVector{PT},Type{<:AbstractVector{PT}}},
Expand Down
Loading