6

Having $X,Y$ being symbols for matrices, I was wondering if there is a way to simplify expressions like

KroneckerProduct[X, X] + KroneckerProduct[-X, X] 

to give zero. Or

KroneckerProduct[2 X, 3 Y]

to produce something like:

6 KroneckerProduct[X, Y]

In general if $a,b$ are scalars, and $X,Y$ are matrices we have this mathematical identity:

KroneckerProduct[a X, b Y] == a*b KroneckerProduct[X, Y].
MarcoB
  • 67,153
  • 18
  • 91
  • 189
Milad
  • 147
  • 6
  • Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Aug 13 '15 at 00:46
  • You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful – Michael E2 Aug 13 '15 at 00:46
  • What sort of zero would you expect in the first example? – Michael E2 Aug 13 '15 at 00:49
  • Thanks for you comments :) I'll try to get familiar ASAP. KroneckerProduct[-X, X]=-KroneckerProduct[X, X], so the sum is just like adding a matrix to its negative, which results in a zero matrix. – Milad Aug 13 '15 at 01:16

3 Answers3

11

There is another option, using the relatively new tensor capabilities of Mathematica. This is pretty much copied from another answer by jose, but I don't need any assumptions here:

TensorExpand[KroneckerProduct[X, X] + KroneckerProduct[-X, X]]

(* ==> 0 *)

TensorExpand[KroneckerProduct[2 X, 3 Y]]

(* ==> 6 KroneckerProduct[X, Y] *)

There is a potential problem with this approach in that the first result is 0 rather than a matrix. However, Mathematica doesn't have a special symbol for the zero matrix of unspecified dimension. If you want to get a more "correct" output that keeps track of the product space in which the zero lives, it will be necessary to hand-craft the necessary algebraic rules and symbols.

Jens
  • 97,245
  • 7
  • 213
  • 499
  • Great, this is what I needed. Thank you very much @Jens.

    Also, do you know how can I have KroneckerProduct[x, z] + KroneckerProduct[y, z]=KroneckerProduct[x+y, z] ?

    I looked through TensorReduce, and the other suggestions in the Help, but couldn't figure it out. I couldn't find a good reference for these.

    Thank you anyway.

    – Milad Aug 13 '15 at 01:49
  • So I guess you tried TensorExpand[KroneckerProduct[x,z]+KroneckerProduct[y,z]==KroneckerProduct[x+y,z]] and got True, right? I guess what you want is a transformation rule that combines two products into one, i.e., a factorization. I think that will require defining a custom function. – Jens Aug 13 '15 at 06:21
  • Here is a function that does the factorization: kroneckerFactor[expr_]:=expr//.{Plus[KroneckerProduct[x_,y_],KroneckerProduct[z_,y_]]:>KroneckerProduct[x+z,y],Plus[KroneckerProduct[y_,x_],KroneckerProduct[y_,z_]]:>KroneckerProduct[y,x+z]} – Jens Aug 13 '15 at 06:25
  • I'd forgotten about the Tensor* family of MMA functions - +1 – ciao Aug 13 '15 at 06:31
  • Exactly, that's what I meant. Thanks @Jens – Milad Aug 14 '15 at 01:23
  • I guess I should go for these case by case, there is no routine Simplification built in for Tensors or Kronecker Product. I use NCAlgebra package which handles such a simplifications for non-commuting algebra properly, but as far as I see there is no Tensor/Kronecker handling. – Milad Aug 14 '15 at 01:31
  • I was wondering if someone can help with my new but related question here – Milad Oct 22 '15 at 19:24
3

How about:

av = Array[Subscript[a, ##] &, {2}];
bv = Array[Subscript[b, ##] &, {2}];
KroneckerProduct[av, bv] + KroneckerProduct[-av, bv]

{{0, 0}, {0, 0}}
bill s
  • 68,936
  • 4
  • 101
  • 191
  • I was wondering if its possible to do this without specifying the matrix's dimensions and properties. This is just a part of a project, and everything involve is unknown matrices with some general properties. It would be perfect if using something close to Simplify I could produce: KroneckerProduct[aX, bY] = a*b KroneckerProduct[X, Y] – Milad Aug 13 '15 at 01:27
0

Some people (see The ubiquitous Kronecker product by Van Loan) have worked on finding two matrices $A, B$ of specified size whose tensor product $A \otimes B$ is closest (in a norm) to a given (larger) matrix $C$. That is, find $A, B$ which minimize $||C-A \otimes B||$. The algorithm is based on the SVD. There is a matlab implementation somewhere. It would be nice to see this algorithm implemented in Mathematica.

If the error is zero then the algorithm factorises - but If I recollect the article doesn't go into this. Is this more simple, unique? Who knows?

pdmclean
  • 1,368
  • 10
  • 19
  • 1
    This could perhaps be reworked into a separate question, but it isn't an answer to the current question. – Jens Aug 13 '15 at 06:12
  • see http://mathematica.stackexchange.com/questions/91651/nearest-kronecker-product – pdmclean Aug 15 '15 at 13:15