Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Convert an expression involving Dot, Tr and MatrixPower into an equivalent expression using TensorContract
ResourceFunction["ToTensor"][expr] converts Dot,Tr and MatrixPower subexpressions into equivalent forms using TensorContract. |
Specify the properties of symbolic arrays:
In[1]:= |
A tensor built using Tr and Dot:
In[2]:= |
Out[2]= |
Convert to an equivalent form using TensorContract:
In[3]:= |
Out[3]= |
Check:
In[4]:= |
Out[5]= |
Check equivalence of forms, assuming the two matrices A and B are square:
In[6]:= |
Out[6]= |
A tensor consisting of Dot, Tr and MatrixPower:
In[7]:= |
Out[7]= |
Evaluate, assuming the two matrices are square:
In[8]:= |
Out[8]= |
TensorReduce is unable to reduce some mixed expressions consisting of both TensorContract and Dot:
In[9]:= |
Out[11]= |
Using ToTensor trivially simplifies the expression:
In[12]:= |
Out[12]= |
Rank information for symbolic tensors must be specified using the Assumptions option or using $Assumptions:
In[13]:= |
Out[14]= |
Here the assumptions are added correctly:
In[15]:= |
Out[15]= |
Only Tr expression representing traces of the first two levels of an array have equivalent TensorContract representations:
In[16]:= |
Out[16]= |
This work is licensed under a Creative Commons Attribution 4.0 International License