4
$\begingroup$

Any suggestion on how to bring a nested KroneckerProduct form into just one? I mean some way of converting:

KroneckerProduct[w,KroneckerProduct[KroneckerProduct[x, y], z]]

to:

KroneckerProduct[w,x,y,z]

The reason I want to do this is that TensorExpand cannot simplify the following expression:

KroneckerProduct[KroneckerProduct[x, y], z] - KroneckerProduct[x, KroneckerProduct[y, z]] // TensorExpand

to zero, but by using the following form:

KroneckerProduct[x, 2 y, -z] + KroneckerProduct[2 x, y, z] // TensorExpand

it outputs zero as it should.

$\endgroup$
4
$\begingroup$

My naive attempt:

flatf[f_, exp_] := Apply[f, Flatten@ReplaceAll[exp, f -> List]]

Example

flatf[KroneckerProduct, 
 KroneckerProduct[w, KroneckerProduct[KroneckerProduct[x, y], z]]
 ]
KroneckerProduct[w, x, y, z]

EDIT

But, Ahh... it was already implemented.

Flatten[
KroneckerProduct[w, KroneckerProduct[KroneckerProduct[x, y], z]]
, Infinity
, KroneckerProduct
]
KroneckerProduct[w, x, y, z]
$\endgroup$
0
1
$\begingroup$

I think your equivalence is only true for matrices. For example, consider 3 2-element vectors:

{x, y, z} = RandomInteger[1, {3, 2}];
KroneckerProduct[x, KroneckerProduct[y, z]] //Dimensions
KroneckerProduct[x, y, z] //Dimensions

{4, 2}

{2, 4}

On the other hand, TensorExpand already knows about this equivalence for matrices:

Clear[x, y, z];
TensorExpand[
    KroneckerProduct[KroneckerProduct[x, y], z] - KroneckerProduct[x, KroneckerProduct[y, z]],
    Assumptions->(x|y|z) \[Element] Matrices[{d,d}]
]

0

$\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.