Skip to content

Commit

Permalink
Fix variables with FullBasis (#32)
Browse files Browse the repository at this point in the history
* Fix variables with FullBasis

* Fix

* Fixes
  • Loading branch information
blegat authored Jun 18, 2024
1 parent ff443e4 commit 6652b19
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
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

0 comments on commit 6652b19

Please sign in to comment.