Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Convert TensorContract expressions into an equivalent form using Dot and Tr
ResourceFunction["FromTensor"][expr] converts TensorContract expressions in expr into equivalent forms using Dot and Tr. |
Specify the properties of symbolic arrays:
In[1]:= | ![]() |
Create a TensorContract expression:
In[2]:= | ![]() |
Convert to an equivalent form using Tr and Dot:
In[3]:= | ![]() |
Out[3]= | ![]() |
Check:
In[4]:= | ![]() |
Out[5]= | ![]() |
Create a tensor with disconnected components:
In[6]:= | ![]() |
Convert to an equivalent form using Tr and Dot:
In[7]:= | ![]() |
Out[7]= | ![]() |
Check equivalence of forms:
In[8]:= | ![]() |
Out[9]= | ![]() |
Tensor forms using Dot and Tr evaluate much more quickly than forms using TensorContract. Consider the following TensorContract expression:
In[10]:= | ![]() |
Out[10]= | ![]() |
The equivalent form using Dot and Tr:
In[11]:= | ![]() |
Out[11]= | ![]() |
Evaluate the two forms of the tensor using numerical arrays as the tensors:
In[12]:= | ![]() |
Out[13]= | ![]() |
The slowness of the TensorContract version can be ameliorated by judicious use of Inactivate and Activate:
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[16]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License