3
$\begingroup$

I would like Mathematica to use the property that the TensorProduct is distributive to simplify expressions like

$A\otimes B+A\otimes C = A\otimes(B+C)$

Unfortunately neither Collect nor Simplify do the job

Collect[A \[TensorProduct] B + A \[TensorProduct] C, A]

and

Simplify[A \[TensorProduct] B + A \[TensorProduct] C]

both just return their argument. Is there a way to make Mathematica simplify such expressions?

$\endgroup$
1
  • $\begingroup$ Block[{TensorProduct = Times}, Collect[A\[TensorProduct]B + A\[TensorProduct]C, A]] /. Times -> TensorProduct? $\endgroup$
    – kglr
    Sep 7 '18 at 20:08
2
$\begingroup$

This is an experimental implementation of such a function:

tensorCollect[input_] := ReplaceRepeated[
  input,
  {
   Plus[
     summands___,
     Times[x___, TensorProduct[a___, R_, b___, S_, c___]],
     Times[y___, TensorProduct[a___, R_, b___, T_, c___]]
     ] :> Plus[summands, TensorProduct[a, R, b, Times[x, S] + Times[y, T], c]],
   Plus[
     summands___,
     Times[x___, TensorProduct[a___, R_, b___, T_, c___]],
     Times[y___, TensorProduct[a___, S_, b___, T_, c___]]
     ] :> 
    Plus[summands, TensorProduct[a, Times[x, R] + Times[y, S], b, T, c]]
   }
  ]

A simple test:

input = 2 A\[TensorProduct]B\[TensorProduct]R\[TensorProduct]S + 2 T\[TensorProduct]S + 3 A\[TensorProduct]B\[TensorProduct]T\[TensorProduct]S;
output = tensorCollect[input]
TensorExpand[output] == input

2 T \[TensorProduct] S + A \[TensorProduct] B \[TensorProduct] (2 R + 3 T) \[TensorProduct] S

True

But it probably contains some bugs. This does also not attempt to collect as many terms as possible.

$\endgroup$
5
  • $\begingroup$ Thanks a lot, so far this seems to work. I will do some more testing before accepting your answer $\endgroup$
    – lennart
    Sep 10 '18 at 7:31
  • $\begingroup$ I find that your function only works if there are coefficients in front of the Tensorproducts. For example tensorCollect[A \[TensorProduct] B + A \[TensorProduct] D] does not work $\endgroup$
    – lennart
    Sep 12 '18 at 13:38
  • 1
    $\begingroup$ @lennart Yeah, I know that it is not perfect. Yet, it might give you an idea how to proceed: You can add more and more transformation rules to improve upon tensorCollect. $\endgroup$ Sep 12 '18 at 13:42
  • $\begingroup$ What is the meaning of the a___, b___, c___ in the tensorproduct? Everything seems to work just fine without them. $\endgroup$
    – lennart
    Sep 12 '18 at 14:50
  • 1
    $\begingroup$ The triple underscore stand for a sequence of zero or more elements. TensorProduct does not have the attribute Flat, so we have to account for the possibility that there are other factors around and between there relevant factors R, S, and T. And most importantly, these factors have to correspond to each other. That will only take effect with long TensorProducts. $\endgroup$ Sep 12 '18 at 15:09
1
$\begingroup$

This command will make it to move the left argument out of brackets if to execute it twice:

Unprotect[TensorProduct];
TensorProduct /: TensorProduct [a_ , b_] + TensorProduct[ a_ , c_] := 
 TensorProduct[a, b + c] 
Protect[TensorProduct];

Idk why it produces an error message

TagSetDelayed::write: Tag TensorProduct in a_[TensorProduct]b_+a_[TensorProduct]c_ is Protected.

after the first execution.

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