Skip to content

tBuLi/kroneckerproduct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

(this is a work in progress, nothing works yet)

Kronecker Product

This plugin is made to make working with direct products very easy and efficient.

>>> unit, x, y, z = pauli_matrices()
>>> x << unit
sigma_{x} ⊗ 1

Direct product are done using the bitshift operator <<, since we are essentially pushing the matrix on the right hand side of the operator into what's on the left hand side.

The normal multiplication operator still does matrix multiplication:

>>> unit, x, y, z = pauli_matrices()
>>> x * y
i sigma_{z}

The usecase I'm developing this for is doing matrix multiplication with block matrices build up by taking the Kronecker product of many 2 x 2 matrices. If we take the Kronecker product of k such matrices, the dimension of the final matrix will therefore be 2^k x 2^k. For large k this will become impossible very quickly. However, by our knowledge that the final matrix is in fact a kronecker product, we only have to multiply the k 2 x 2 matrices to arrive at the result.

So roughly speaking,

(2^k * 2^k) * (2^k * 2^k) -> k * (2 * 2) * (2 * 2)

This is a huge decrease in computational complexity!

Obviously, because of the OOP implementation the overhead will be far greater but I expect that for large k this will start to pay of. Furthermore, the k multiplications of 2 * 2 matrices could even be done in parallel.

Lazy Evaluation FTW

No matrix multiplication is performed when calculating kronecker products. In fact, the objects do not have to be matrices at all. This package only cares whether the object have multiplication defined.

Matrix multiplication of the irreducable blocks is performed when you actually perform a matrix multiplication using * since

Matrix Product

Properties

Bilinearity and Associativity

A << (B + C) == (A << B) + (A << C)
(A + B) << C == (A << C) + (B << C)
(k*A) << B == k(A << B)
(A << B) << C == A << (B << C)

Matrix Product

(A << B) * (C << D) == (A * C) << (B * D)

Inverse

1/(A << B) == 1/A << 1/B

This might be a slight abuse of notation, but I think it is a good one in the context of coding with matrices. The division operator is out of a job anyway.

Transpose and Conjugation

(A << B).T == A.T << B.T
~(A << B) == ~A << ~B

Conjugation uses the binary not operator, since we flip the imaginary 'bit'.

Determinant

det(A << B) == det(A)**len(B) * det(B)**len(A)

Exponentiation

Not defined yet.

More Examples

>>> unit, x, y, z = pauli_matrices()
>>> (x + y) << unit
sigma_{x} + sigma{y}
>>> a = x << x
>>> b = y << y
>>> a * b
(i sigma_z) ⊗ (i sigma_z)
>>> a = x << x
>>> 1/a
(sigma_x)^{-1} ⊗ (sigma_x)^{-1}

About

Package to perform Kronecker Products lazily.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages