diff --git a/src/expectation.jl b/src/expectation.jl index 06e0c11..31881e7 100644 --- a/src/expectation.jl +++ b/src/expectation.jl @@ -21,6 +21,15 @@ function _expectation( return s end +function _expectation( + μ::MomentVector{S,<:MB.SubBasis{B}}, + p::SA.AlgebraElement{<:MB.Algebra}, + f, +) where {S,B} + basis = MB.FullBasis{B,MP.monomial_type(typeof(p))}() + return _expectation(μ, MB.algebra_element(SA.coeffs(p, basis), basis), f) +end + function _expectation(μ::MomentVector, p::MP.AbstractPolynomialLike, f) return _expectation( μ, diff --git a/test/expectation.jl b/test/expectation.jl index 33d397d..cba3964 100644 --- a/test/expectation.jl +++ b/test/expectation.jl @@ -17,5 +17,10 @@ @test (@inferred dot(0.5 * x[1] * x[2]^2, m)) == 2.0 a = MB.algebra_element([0.5], MB.SubBasis{MB.Monomial}([x[1] * x[2]^2])) @test (@inferred dot(a, m)) == 2.0 + a = MB.algebra_element( + [0.5], + MB.SubBasis{MB.ScaledMonomial}([x[1] * x[2]^2]), + ) + @test (@inferred dot(a, m)) == 2 * √3 @test (@inferred dot(m, x[1] * x[3])) == 3 end