6
$\begingroup$

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].
$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – Michael E2 Aug 13 '15 at 0:46
  • $\begingroup$ 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 $\endgroup$ – Michael E2 Aug 13 '15 at 0:46
  • $\begingroup$ What sort of zero would you expect in the first example? $\endgroup$ – Michael E2 Aug 13 '15 at 0:49
  • $\begingroup$ 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. $\endgroup$ – Milad Aug 13 '15 at 1:16
10
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Milad Aug 13 '15 at 1:49
  • $\begingroup$ 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. $\endgroup$ – Jens Aug 13 '15 at 6:21
  • $\begingroup$ 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]} $\endgroup$ – Jens Aug 13 '15 at 6:25
  • $\begingroup$ I'd forgotten about the Tensor* family of MMA functions - +1 $\endgroup$ – ciao Aug 13 '15 at 6:31
  • $\begingroup$ Exactly, that's what I meant. Thanks @Jens $\endgroup$ – Milad Aug 14 '15 at 1:23
3
$\begingroup$

How about:

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

{{0, 0}, {0, 0}}
| improve this answer | |
$\endgroup$
  • $\begingroup$ 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] $\endgroup$ – Milad Aug 13 '15 at 1:27
0
$\begingroup$

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?

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.