From a7712bb4690d2aa0804e88f557996ef06d78835c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 3 Jul 2024 19:24:01 +0200 Subject: [PATCH] Allow multiplication with different algebras --- src/arithmetic.jl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 9645323..b6c1e8d 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -127,6 +127,24 @@ function MA.operate_to!( return res end +function mstructure(args::AbstractStarAlgebra...) + for arg in args + @assert arg == first(args) + end + return mstructure(basis(args[1])) +end + +function MA.operate!( + ::UnsafeAddMul{typeof(*)}, + res::AlgebraElement, + A::BasisTransformation, + args::Vararg{AlgebraElement,N}, +) where {N} + mstr = mstructure(algebra(res), algebra.(args)...) + MA.operate!(UnsafeAddMul(mstr), coeffs(res), coeffs.(args)...) + return res +end + function MA.operate!( ::UnsafeAddMul{typeof(*)}, res::AlgebraElement, @@ -137,7 +155,7 @@ function MA.operate!( @assert parent(res) == parent(arg) end end - mstr = mstructure(basis(res)) + mstr = mstructure(basis(res), basis.(args)...) MA.operate!(UnsafeAddMul(mstr), coeffs(res), coeffs.(args)...) return res end