Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jun 17, 2024
1 parent 6495ff3 commit 3345a17
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
66 changes: 34 additions & 32 deletions src/quotient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion test/quotient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Test

import StarAlgebras as SA
using MultivariateBases
const MB = MultivariateBases
using LinearAlgebra
Expand Down

0 comments on commit 3345a17

Please sign in to comment.