From 3345a1719de15db228a6fec2723dd7ee165a257f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 17 Jun 2024 15:50:34 +0200 Subject: [PATCH] Fixes --- src/quotient.jl | 66 +++++++++++++++++++++++++----------------------- test/quotient.jl | 9 ++++++- test/runtests.jl | 1 + 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/quotient.jl b/src/quotient.jl index 881cc33..cc933ad 100644 --- a/src/quotient.jl +++ b/src/quotient.jl @@ -23,35 +23,37 @@ function SA.coeffs(coeffs, sub::SubBasis{Monomial}, basis::QuotientBasis) return SA.coeffs(MP.polynomial(coeffs, sub.monomials), parent(sub), basis) end -function MA.operate!( - op::SA.UnsafeAddMul{typeof(*)}, - a::SA.AlgebraElement{<:Algebra{<:QuotientBasis,Monomial}}, - α, - p::Polynomial{Monomial}, -) - _assert_constant(α) - for t in MP.terms(rem(p.monomial, SA.basis(a).divisor)) - MA.operate!( - op, - algebra_element(SA.coeffs(a), SA.basis(a).basis), - α * MP.coefficient(t), - Polynomial{Monomial}(MP.monomial(t)), - ) - #SA.unsafe_push!(SA.coeffs(a), SA.basis(a).basis[Polynomial{Monomial}(MP.monomial(k))], α * MP.coefficient(t)) - end - return a -end - -function SA.adjoint_coeffs( - coeffs, - src::SubBasis{Monomial}, - dest::QuotientBasis{<:Polynomial{Monomial}}, -) - return map(src.monomials) do mono - return sum( - MP.coefficient(t) * - coeffs[dest.basis[Polynomial{Monomial}(MP.monomial(t))]] for - t in MP.terms(rem(mono, dest.divisor)) - ) - end -end +# Needed ? +#function MA.operate!( +# op::SA.UnsafeAddMul{typeof(*)}, +# a::SA.AlgebraElement{<:Algebra{<:QuotientBasis,Monomial}}, +# α, +# p::Polynomial{Monomial}, +#) +# _assert_constant(α) +# for t in MP.terms(rem(p.monomial, SA.basis(a).divisor)) +# MA.operate!( +# op, +# algebra_element(SA.coeffs(a), SA.basis(a).basis), +# α * MP.coefficient(t), +# Polynomial{Monomial}(MP.monomial(t)), +# ) +# #SA.unsafe_push!(SA.coeffs(a), SA.basis(a).basis[Polynomial{Monomial}(MP.monomial(k))], α * MP.coefficient(t)) +# end +# return a +#end + +#function SA.adjoint_coeffs( +# coeffs, +# src::SubBasis{Monomial}, +# dest::QuotientBasis{<:Polynomial{Monomial}}, +#) +# @show @__LINE__ +# return map(src.monomials) do mono +# return sum( +# MP.coefficient(t) * +# coeffs[dest.basis[Polynomial{Monomial}(MP.monomial(t))]] for +# t in MP.terms(rem(mono, dest.divisor)) +# ) +# end +#end diff --git a/test/quotient.jl b/test/quotient.jl index 417edf3..705765d 100644 --- a/test/quotient.jl +++ b/test/quotient.jl @@ -15,5 +15,12 @@ end basis = MB.QuotientBasis(MB.SubBasis{MB.Monomial}([1, y, x]), PlusMinusOne()) @test length(basis) == 3 - @test coefficients(x^3 - 2x^2 * y + 3x^2, basis) == [3, -2, 1] + p = x^3 - 2x^2 * y + 3x^2 + coeffs = [3, -2, 1] + @test coefficients(p, basis) == coeffs + a = MB.algebra_element(p) + @test StarAlgebras.coeffs(a, basis) == coeffs + explicit = MB.explicit_basis(a) + exp = MB.algebra_element(SA.coeffs(a, explicit), explicit) + @test SA.coeffs(exp, basis) == coeffs end diff --git a/test/runtests.jl b/test/runtests.jl index a13c7c7..2898428 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using Test +import StarAlgebras as SA using MultivariateBases const MB = MultivariateBases using LinearAlgebra