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

Fix variables with FullBasis #32

Merged
merged 3 commits into from
Jun 18, 2024
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
9 changes: 9 additions & 0 deletions src/MultivariateBases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,13 @@ function MA.promote_operation(
return Algebra{BT,B,M}
end

const _APL = MP.AbstractPolynomialLike
# We don't define it for all `AlgebraElement` as this would be type piracy
const _AE = SA.AlgebraElement{<:Algebra}

Base.:(+)(p::_APL, q::_AE) = +(p, MP.polynomial(q))
Base.:(+)(p::_AE, q::_APL) = +(MP.polynomial(p), q)
Base.:(-)(p::_APL, q::_AE) = -(p, MP.polynomial(q))
Base.:(-)(p::_AE, q::_APL) = -(MP.polynomial(p), q)

end # module
2 changes: 2 additions & 0 deletions src/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ function SubBasis{B}(
)
end

SubBasis{B}(monos::Tuple) where {B} = SubBasis{B}([monos...])

function Base.copy(basis::SubBasis)
return typeof(basis)(copy(basis.monomials))
end
Expand Down
2 changes: 1 addition & 1 deletion src/polynomial.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# TODO Add to MultivariatePolynomials
MP.variables(p::SA.AlgebraElement) = MP.variables(SA.basis(p))
MP.variables(p::SA.AlgebraElement) = MP.variables(explicit_basis(p))
Base.keytype(p::MP.AbstractPolynomialLike) = MP.monomial_type(p)
Base.valtype(p::MP.AbstractPolynomialLike) = MP.coefficient_type(p)
#Base.keys(p::MP.AbstractPolynomial) = MP.monomials(p)
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
@test full_basis[mono] == p
@test polynomial_type(mono, String) == polynomial_type(typeof(p), String)
a = MB.algebra_element(p)
@test variables(a) == x
@test typeof(polynomial(a)) == polynomial_type(typeof(a))
@test typeof(polynomial(a)) == polynomial_type(typeof(p), Int)
@test a ≈ a
Expand All @@ -72,6 +73,11 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
"\$\$ " *
_wrap(MB.SA.trim_LaTeX(mime, sprint(show, mime, p.monomial))) *
" \$\$"
const_mono = constant_monomial(prod(x))
@test const_mono + MB.algebra_element(MB.Polynomial{B}(const_mono)) == 2
@test MB.algebra_element(MB.Polynomial{B}(const_mono)) + const_mono == 2
@test iszero(const_mono - MB.algebra_element(MB.Polynomial{B}(const_mono)))
@test iszero(MB.algebra_element(MB.Polynomial{B}(const_mono)) - const_mono)
end

function univ_orthogonal_test(
Expand Down
Loading