diff --git a/src/bases.jl b/src/bases.jl index 9153661..15751d4 100644 --- a/src/bases.jl +++ b/src/bases.jl @@ -111,7 +111,7 @@ function algebra_type(::Type{BT}) where {B,M,BT<:MonomialIndexedBasis{B,M}} return Algebra{BT,B,M} end -implicit_basis(basis::SubBasis) = parent(basis) +implicit_basis(basis::SA.SubBasis) = parent(basis) implicit_basis(basis::FullBasis) = basis function implicit(a::SA.AlgebraElement) diff --git a/src/scaled.jl b/src/scaled.jl index 4790379..7e02aa8 100644 --- a/src/scaled.jl +++ b/src/scaled.jl @@ -71,7 +71,7 @@ function Base.promote_rule( end function scaling(exp) - return √(factorial(sum(exp)) / prod(factorial, exp; init = 1),) + return √(factorial(sum(exp)) / prod(factorial, exp; init = 1)) end unscale_coef(t::MP.AbstractTerm) = MP.coefficient(t) / scaling(MP.monomial(t)) function SA.coeffs( diff --git a/test/lagrange.jl b/test/lagrange.jl index 56857d1..c84215d 100644 --- a/test/lagrange.jl +++ b/test/lagrange.jl @@ -11,14 +11,14 @@ function _test(B::Type) implicit = MB.ImplicitLagrangeBasis(x, MB.BoxSampling([-1, -1], UInt32[1, 1])) point = zeros(2) - poly = implicit[x=>point] + poly = implicit[x => point] @test poly isa MB.LagrangePolynomial @test poly.variables == x @test poly.point === point err = ErrorException( "Variables `$([x[1]])` do not match Lagrange basis variables `$x`", ) - @test_throws err implicit[[x[1]]=>[0.0]] + @test_throws err implicit[[x[1]] => [0.0]] monos = monomials(x, 0:2) coeffs = collect(eachindex(monos)) sub = MB.SubBasis{B}(monos) diff --git a/test/monomial.jl b/test/monomial.jl index 1781b7e..168e648 100644 --- a/test/monomial.jl +++ b/test/monomial.jl @@ -124,9 +124,9 @@ function test_monomial(x, y) # (Tuple for TypedPolynomials, Vector for DynamicPolynomials) full = MB.FullBasis{MB.Monomial}(x * y) # Get the exponent keys from the FullBasis directly - e_x = MB.sparse_coefficients(x + 0 * y).basis_elements[1] - e_y2 = MB.sparse_coefficients(y^2 + 0 * x).basis_elements[1] - e_00 = MB.sparse_coefficients(1 * one(x * y)).basis_elements[1] + e_x = MB.sparse_coefficients(x+0*y).basis_elements[1] + e_y2 = MB.sparse_coefficients(y^2+0*x).basis_elements[1] + e_00 = MB.sparse_coefficients(1*one(x*y)).basis_elements[1] @testset "sparse_coefficients ordering" begin p = x + y^2 # mixes degree 1 (x) and degree 2 (y²) diff --git a/test/subbasis.jl b/test/subbasis.jl new file mode 100644 index 0000000..89cbf07 --- /dev/null +++ b/test/subbasis.jl @@ -0,0 +1,21 @@ +using Test +import StarAlgebras as SA +import MutableArithmetics as MA +using MultivariateBases +const MB = MultivariateBases + +@testset "implicit_basis on generic SA.SubBasis" begin + # `MB.implicit_basis` was historically only defined on `MB.SubBasis` + # (= `SA.SubBasis{Polynomial}`). It is now defined on any `SA.SubBasis`, + # so that a `SubBasis` whose parent is a non-polynomial `SA.ImplicitBasis` + # (such as the `SA.DiracBasis` wrapping a custom algebra of monoid elements + # used by the CHSH tutorial) routes through the same fallback. + parent_basis = SA.DiracBasis(["a", "b", "c"]) + sub = SA.SubBasis(parent_basis, ["a", "b"]) + + @test sub isa SA.SubBasis + @test !(sub isa MB.SubBasis) # not a polynomial-typed SubBasis + @test MB.implicit_basis(sub) === parent_basis + @test MA.promote_operation(MB.implicit_basis, typeof(sub)) == + typeof(parent_basis) +end