1
$\begingroup$

I noticed that the definition of KroneckerProduct and

For example

TensorProduct[({
   {0, 1},
   {1, 0}
  }), ({
   {0, 1},
   {1, 0}
  })]

Output: {{{{0,0},{0,0}},{{0,1},{1,0}}},{{{0,1},{1,0}},{{0,0},{0,0}}}}

KroneckerProduct[({
   {0, 1},
   {1, 0}
  }), ({
   {0, 1},
   {1, 0}
  })]

Output: {{0, 0, 0, 1}, {0, 0, 1, 0}, {0, 1, 0, 0}, {1, 0, 0, 0}}

Mathematically, what we really want for a tensor product between two matrices is indeed the KroneckerProduct, NOT TensorProduct.

I would like to define such a function:

a_\[TensorProduct]b_ := KroneckerProduct[a, b]

But it outputs a failure:

Outputs: SetDelayed::write: Tag TensorProduct in a_[TensorProduct]b_ is Protected.

Is there a way to use the $\otimes$ namely [TensorProduct] notation to define the function a_[TensorProduct]b_ := KroneckerProduct[a, b]?

See:enter image description here

$\endgroup$
2
$\begingroup$

This works for me

CircleTimes[x_, y_] := KroneckerProduct[x, y] 

or, as @CarlWoll suggested, simply

CircleTimes = KroneckerProduct 

Now

a = {{0, 1}, {1, 0}};
a\[CircleTimes]a
(* {{0, 0, 0, 1}, {0, 0, 1, 0}, {0, 1, 0, 0}, {1, 0, 0, 0}} *)

Notice that it is entered as is entered as \esc c* \esc and not as \esc t* \esc. The latter is indeed reserved.

$\endgroup$
6
  • $\begingroup$ thanks but the reason to use the ⊗ symbol is to simplify the notation when we have $$ a ⊗ b ⊗ c ⊗d ⊗ e ⊗ f ⊗ ... $$ a long list. Othewise, how would we not just use the $$ \text{KroneckerProduct[a, KroneckerProduct[b,KroneckerProduct[c,...] } $$ that is also equally long as your new function.... $\endgroup$
    – wonderich
    Aug 20 at 18:44
  • $\begingroup$ @wonderich See the documentation for CircleTimes, the very first example demonstrates exactly what you want. You may also need to use parenthesis. $\endgroup$
    – yarchik
    Aug 20 at 18:45
  • $\begingroup$ thanks for the comment +1, but I really hope to use a symbol ⊗ or something else very short not like CircleTimes. But it is good to know CircleTimes[x,y, ...] displays as x[CircleTimes]y[CircleTimes].... $\endgroup$
    – wonderich
    Aug 20 at 18:47
  • $\begingroup$ @wonderich As I understood, you would like to handle multiple arguments. Then you have to define corresponding rules or use parenthesis as (a\[CircleTimes]a)\[CircleTimes]a $\endgroup$
    – yarchik
    Aug 20 at 18:49
  • 1
    $\begingroup$ Could also do CircleTimes = KroneckerProduct $\endgroup$
    – Carl Woll
    Aug 20 at 18:58
1
$\begingroup$

For display purposes we can define a new display format for KroneckerProduct like this

Unprotect[KroneckerProduct];
Format[x_KroneckerProduct] := Row[List @@ x,
  Subscript["\[CircleTimes]", Style["k", Tiny]]]
Protect[KroneckerProduct];

KroneckerProduct[a, b, c, d]

$$a\otimes _{\text{k}}b\otimes _{\text{k}}c\otimes _{\text{k}}d$$

The little "k" subscript on the $\otimes$ is there to make it a unique symbol, so there can be no question about its meaning. It is not a required feature.

To save a few keystrokes and to make our input fit the language of tensor products we could define an abbreviation, tensor, as

ClearAll[tensor]
tensor = KroneckerProduct;
expr = tensor[a, b, c, d]

We might read this as "a tensored with b tensored with c tensored with d", or "tensor product of a, b, c and d". expr displays with $\otimes_k$ symbols, but is only a KroneckerProduct expression, as can be seen with FullForm.

To remove the unique symbol definition and return KroneckerProduct to its usual display form, evaluate this

Unprotect[KroneckerProduct];
Format[_KroneckerProduct] = Null;
Format[_KroneckerProduct] =.
Protect[KroneckerProduct];

The assignment of Null in the second line ensures there is a value to unset in the third line.

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