# How to create a symmetric symbolic tensor?

I would like to create symbolic tensor. For example a 2nd order symmetric tensor that would look like this in matrix representation:

$$\left( \begin{array}{ccc} a & d & f \\ d & b & e \\ f & e & c \\ \end{array} \right)$$

Is this possible for higher order tensors (order 4, for example)? I don't feel like typing out all 81 components. And more importantly, will further calculations with these tensors simplify due to symmetry (if applicable)?

My goal is to find zero elements of the following tensor: : $$(c_{n_1 m_1}+c_{n_2m_2}+...+c_{n{_\mu m_{\mu}}})D_{m_1 m_2 ... m_{\mu}}$$

($D_{m_1 m_2 ... m_{\mu}}$ symmetric in all its indices, $c_{ij}$ is antisymmetric and zero everywhere except $c_{12}=\theta$ and $c_{21}=-\theta$, working in 3 dimensions)

• What do you want to do with the tensor? Do you want the elements explicitly listed, or do you want to tell Mathematica that x represents a symmetric tensor, without any direct reference to its elements? What kind of symmetry do you need for the 4-index tensor? – Szabolcs Sep 29 '16 at 14:00

Perhaps use Array to construct the symbolic nested list that represents the tensor and then set all elements with the same set of indices to the same list. For example, if you have a 3 by 3 by 3, given by

ClearAll[d]
t = Array[d, {3, 3, 3}]; t // MatrixForm Then, we re-order the indices:

t = t /. x_d :> Sort[x]; t // MatrixForm Note, for instance, that

Equal @@ Extract[t, Permutations[{1, 2, 3}]]
(* True *)


Or, do it all at once:

t = Array[d @@ Sort[{##}] &, {3, 3, 3}];


Alternatively,

ClearAll[d]
SetAttributes[d, Orderless];
t = Array[d, {3, 3, 3}];


If you are only interested in fully symmetric arrays, then I think using SetAttributes[c, Orderless] and then Array[c, dims] is the simplest solution, as proposed by @march.

But let me give another solution that generalizes to other symmetries:

This is a 3x3 symmetric matrix:

In:= Normal@ SymmetrizedArray[{i_, j_} -> c[i, j], {3, 3}, Symmetric[{1, 2}]]
Out= {{c[1, 1], c[1, 2], c[1, 3]}, {c[1, 2], c[2, 2], c[2, 3]}, {c[1, 3], c[2, 3], c[3, 3]}}

In:= SymmetricMatrixQ[%]
Out= True


This is a 3x3 antisymmetric matrix:

In:= Normal@ SymmetrizedArray[{i_, j_} -> c[i, j], {3, 3}, Antisymmetric[{1, 2}]]
Out= {{0, c[1, 2], c[1, 3]}, {-c[1, 2], 0, c[2, 3]}, {-c[1, 3], -c[2, 3], 0}}

In:= AntisymmetricMatrixQ[%]
Out= True


This is a depth 3 antisymmetric array:

In:= Normal@ SymmetrizedArray[{i_, j_, k_} -> c[i, j, k], {3, 3, 3}, Antisymmetric[All]]
Out= {{{0, 0, 0}, {0, 0, c[1, 2, 3]}, {0, -c[1, 2, 3], 0}}, {{0, 0, -c[1, 2, 3]}, {0, 0, 0}, {c[1, 2, 3], 0, 0}}, {{0, c[1, 2, 3], 0}, {-c[1, 2, 3], 0, 0}, {0, 0, 0}}}

In:= TensorSymmetry[%]
Out= Antisymmetric[{1, 2, 3}]


In dimension 3 it has only one independent component, namely c[1, 2, 3].

It is possible to specify any slot symmetry and SymmetrizedArray will take care of finding the appropriate independent components, zeros, signs, etc. for you.