JuliaLinearAlgebra / LinearMaps.jl

A Julia package for defining and working with linear maps, also known as linear transformations or linear operators acting on vectors. The only requirement for a LinearMap is that it can act on a vector (by multiplication) efficiently.
Other
303 stars 42 forks source link

Multiplication of kronecker products is reversed #230

Closed apmypb closed 3 months ago

apmypb commented 3 months ago

It seems that the product $(A_1 \otimes B_1) \cdot \dots\cdot (A_n \otimes B_n)$ is falsely computed as $(A_n\cdot\dots\cdot A_1) \otimes (B_n\cdot\dots\cdot B_1)$ and not like $(A_1\cdot\dots\cdot A_n) \otimes (B_1\cdot\dots\cdot B_n)$ (the order of maps reversed) One can check the following minimal working example:

using LinearAlgebra
using LinearMaps

A = [0 1; 0 0]
B = [0 0; 1 0]
J = LinearMap(I, 1)
Matrix(kron(J, A*B)) == Matrix(kron(J, A) * kron(J, B)) # should be true

Applying reverse() on the tuples before the product should do the trick https://github.com/JuliaLinearAlgebra/LinearMaps.jl/blob/ee91b4f119e036aa403e3fb0d7c9094e51f46f70/src/kronecker.jl#L275

dkarrasch commented 3 months ago

Thanks for catching this! It had a test, which used the same linear maps, so didn't see the missing reverse. :facepalm: