Skip to content

Commit

Permalink
Bool coefficient_type for monomials
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Nov 23, 2023
1 parent d1f41c5 commit 50a36c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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

0 comments on commit 50a36c3

Please sign in to comment.