Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Compute the hypertrace of a given hypermatrix
| ResourceFunction["HyperTr"][h] gives the hypertrace of the cubical hypermatrix h. | 
 such that
 such that  where 1≤i≤n. Their sum is the hypertrace, thus generalizing the ordinary matrix trace to tensors of arbitrary rank.
 where 1≤i≤n. Their sum is the hypertrace, thus generalizing the ordinary matrix trace to tensors of arbitrary rank.Calculate the hypertrace of a cubical hypermatrix with d=4 and n=2:
| In[1]:= | ![ResourceFunction["HyperTr"][
 Array[Subscript[W, #1, #2, #3, #4] &, {2, 2, 2, 2}]]](https://www.wolframcloud.com/obj/resourcesystem/images/966/9667507e-df3d-479a-a600-3358a8f98429/7f8caa13a75bb197.png) | 
| Out[1]= |  | 
Numeric values:
| In[2]:= | ![ResourceFunction["HyperTr"][{\!\(\*
TagBox[
RowBox[{"(", "", GridBox[{
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"0"},
{"3"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"1"},
{"4"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
Column], "", ")"}]},
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"7"},
{"6"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"1"},
{"7"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
Column], "", ")"}]}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}], "", ")"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\), \!\(\*
TagBox[
RowBox[{"(", "", GridBox[{
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"4"},
{"7"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"0"},
{"5"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
Column], "", ")"}]},
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"9"},
{"7"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"8"},
{"7"}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
Column], "", ")"}]}
},
GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}], "", ")"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\)}]](https://www.wolframcloud.com/obj/resourcesystem/images/966/9667507e-df3d-479a-a600-3358a8f98429/3870347406e65861.png) | 
| Out[2]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License