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
Dotexpressions likea.2. I've never been able to resolve an issue of this type without, in this situation, defining an upvalue forTimesor a downvalue forKroneckerProduct. – IPoiler Oct 22 '15 at 03:52x. (2 y) // TensorExpand )
– Milad Oct 22 '15 at 04:01=and:=. These definitions are associated with the outermostHeaddefined to the left of the operator and are checked when thatHeadis encountered. Upvalues are definitions associated with aHeadin a subexpression left of it's operators,^=,^:=and/:. For your purposes I'd use define something likeKroneckerProduct/:Dot[KroneckerProduct[x__],Times[a_?NumberQ,b_KroneckerProduct]:=a Dot[KroneckerProduct[x],b]to always pull out constant coefficients in theDot. – IPoiler Oct 22 '15 at 04:13KroneckerProduct/:Dot[x_KroneckerProduct, Times[a_?NumberQ, b_KroneckerProduct]] := a Dot[x, b]. Don't forget toUnprotect[KroneckerProduct]first. – IPoiler Oct 22 '15 at 04:35I have several functions defined using Kronecker, and also have expressions like :
– Milad Oct 22 '15 at 17:23KroneckerProduct[x, y].(2 KroneckerProduct[z, w]).KroneckerProduct[x, y] // TensorExpandor with more products in my calculation.KroneckerProduct /: Dot[x___KroneckerProduct, Times[a_?NumberQ, b_KroneckerProduct], y___KroneckerProduct] := a Dot[x, b, y]will work with both your most recent case and the previous one. – IPoiler Oct 22 '15 at 18:36(2 KroneckerProduct[x, y]).(2 KroneckerProduct[3 z, w]).KroneckerProduct[z, w] // TensorExpand– Milad Oct 22 '15 at 19:07Dot[x___, c_?NumberQ*y_, z___] := c Dot[x, y, z]. This time,Unprotect[Dot]since it will be associated withDotnow rather thanKroneckerProduct. – IPoiler Oct 22 '15 at 19:23