Skip to content

Commit 6652b19

Browse files
authored
Fix variables with FullBasis (#32)
* Fix variables with FullBasis * Fix * Fixes
1 parent ff443e4 commit 6652b19

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/MultivariateBases.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,13 @@ function MA.promote_operation(
7272
return Algebra{BT,B,M}
7373
end
7474

75+
const _APL = MP.AbstractPolynomialLike
76+
# We don't define it for all `AlgebraElement` as this would be type piracy
77+
const _AE = SA.AlgebraElement{<:Algebra}
78+
79+
Base.:(+)(p::_APL, q::_AE) = +(p, MP.polynomial(q))
80+
Base.:(+)(p::_AE, q::_APL) = +(MP.polynomial(p), q)
81+
Base.:(-)(p::_APL, q::_AE) = -(p, MP.polynomial(q))
82+
Base.:(-)(p::_AE, q::_APL) = -(MP.polynomial(p), q)
83+
7584
end # module

src/monomial.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ function SubBasis{B}(
112112
)
113113
end
114114

115+
SubBasis{B}(monos::Tuple) where {B} = SubBasis{B}([monos...])
116+
115117
function Base.copy(basis::SubBasis)
116118
return typeof(basis)(copy(basis.monomials))
117119
end

src/polynomial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# TODO Add to MultivariatePolynomials
2-
MP.variables(p::SA.AlgebraElement) = MP.variables(SA.basis(p))
2+
MP.variables(p::SA.AlgebraElement) = MP.variables(explicit_basis(p))
33
Base.keytype(p::MP.AbstractPolynomialLike) = MP.monomial_type(p)
44
Base.valtype(p::MP.AbstractPolynomialLike) = MP.coefficient_type(p)
55
#Base.keys(p::MP.AbstractPolynomial) = MP.monomials(p)

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
5454
@test full_basis[mono] == p
5555
@test polynomial_type(mono, String) == polynomial_type(typeof(p), String)
5656
a = MB.algebra_element(p)
57+
@test variables(a) == x
5758
@test typeof(polynomial(a)) == polynomial_type(typeof(a))
5859
@test typeof(polynomial(a)) == polynomial_type(typeof(p), Int)
5960
@test a a
@@ -72,6 +73,11 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
7273
"\$\$ " *
7374
_wrap(MB.SA.trim_LaTeX(mime, sprint(show, mime, p.monomial))) *
7475
" \$\$"
76+
const_mono = constant_monomial(prod(x))
77+
@test const_mono + MB.algebra_element(MB.Polynomial{B}(const_mono)) == 2
78+
@test MB.algebra_element(MB.Polynomial{B}(const_mono)) + const_mono == 2
79+
@test iszero(const_mono - MB.algebra_element(MB.Polynomial{B}(const_mono)))
80+
@test iszero(MB.algebra_element(MB.Polynomial{B}(const_mono)) - const_mono)
7581
end
7682

7783
function univ_orthogonal_test(

0 commit comments

Comments
 (0)