Following my previous question I have this issue using TensorExpand:

KroneckerProduct[x, y].(KroneckerProduct[2 z, w]) // TensorExpand

results in:

2KroneckerProduct[x.z, y.w]

as expected. But why doesn't the following:

KroneckerProduct[x, y].(2 KroneckerProduct[z, w]) // TensorExpand

produce the same answer, and how should I get it to work?

Again this is a just a small step in my program, so I'm looking for a neat solution (minimum amount of modifying internal functions...)

It works for x. (2 y) // TensorExpand

  • $\begingroup$ I suspect it has to do with the fact that Mathematica doesn't reduce Dot expressions like a.2. I've never been able to resolve an issue of this type without, in this situation, defining an upvalue for Times or a downvalue for KroneckerProduct. $\endgroup$
    – IPoiler
    Oct 22 '15 at 3:52
  • $\begingroup$ I see. Could you please elaborate on this? I'm not familiar with upvalue/downvalue. (I just realized that it works for x. (2 y) // TensorExpand ) $\endgroup$
    – Milad
    Oct 22 '15 at 4:01
  • $\begingroup$ Sure. Downvalues are the type of definitions you probably already use pretty regularly, = and :=. These definitions are associated with the outermost Head defined to the left of the operator and are checked when that Head is encountered. Upvalues are definitions associated with a Head in a subexpression left of it's operators, ^=, ^:= and /:. For your purposes I'd use define something like KroneckerProduct/:Dot[KroneckerProduct[x__],Times[a_?NumberQ,b_KroneckerProduct]:=a Dot[KroneckerProduct[x],b] to always pull out constant coefficients in the Dot. $\endgroup$
    – IPoiler
    Oct 22 '15 at 4:13
  • $\begingroup$ Thanks. I get error using this (even after fixing the missing bracket.) I'll play with it. $\endgroup$
    – Milad
    Oct 22 '15 at 4:27
  • $\begingroup$ For whatever reason I am unable to edit my previous comment, but try KroneckerProduct/:Dot[x_KroneckerProduct, Times[a_?NumberQ, b_KroneckerProduct]] := a Dot[x, b]. Don't forget to Unprotect[KroneckerProduct] first. $\endgroup$
    – IPoiler
    Oct 22 '15 at 4:35

It looks like TensorExpand acquired support for this kind of expansion in M11.2 or M11.3:

KroneckerProduct[x, y].(2 KroneckerProduct[z, w]) // TensorExpand

2 KroneckerProduct[x.z, y.w]


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.