# "Symmetrize" shall symmetrize only tensor values $\ne 0$

Using Symmetrize I want to transform a tensor to be symmetric under all index permutations for all original entries $$\ne 0$$. However each entry is normalized by the number of index permutations. How to tell MMA to consider for symmetrizing only values $$\ne0$$?

a = ConstantArray[0, {3, 3, 3}];
a[[1, 1, 1]] = 1; (* 1 index permutation *)
a[[1, 1, 2]] = 2; (* 3 index permutations *)
a[[1, 2, 3]] = 5; (* 6 index permutations *)
asym = Normal[Symmetrize[a, Symmetric[All]]];
MatrixForm[asym]


To get the desired symmetrized tensor I have to multiply each entry by the number of its index permutations:

Table[asym[[i1,i2,i3]] *= Length[Permutations[{i1,i2,i3}]],{i1,1,3},{i2,1,3},{i3,1,3}];
MatrixForm[asym]


The same I would achieve if I define the symmetric tensor from scratch.

Normal[SymmetrizedArray[{{1,1,1}->1,{1,1,2}->2,{1,2,3}->5},{3,3,3},Symmetric[All]]]


However this method does not apply as there is already a tensor given where only nonzero values shall be symmetrized.

MMA 13

• Did you try to apply Ceiling[]? Commented Oct 10, 2022 at 16:13

I think what you want is to specify a symmetric array giving only its independent components:

SymmetrizedArray[{{1, 1, 1} -> 1, {1, 1, 2} -> 2, {1, 2, 3} -> 5}, {3, 3, 3}, Symmetric[All]] // Normal
(* {{{1, 2, 0}, {2, 0, 5}, {0, 5, 0}}, {{2, 0, 5}, {0, 0, 0}, {5, 0, 0}}, {{0, 5, 0}, {5, 0, 0}, {0, 0, 0}}} *)

• Given is a tensor with a few entries and I want to symmetrize the tensor. For demonstration I filled in my small example an empty tensor with some values, but in practice I start from a tensor that has already some vales. Your method is only useful if I construct a tensor from zero. My method of multiplication with permutation numbers is more suitable. But I thought there is an option to avoid the normalization by the number of permutations. Why at all this normalization happens? Commented Oct 11, 2022 at 10:18
• With the normalization by the number of permutations we guarantee that Symmetrize[A] is equal to A for an array A that is already symmetric. Note that if you already have an array then you can extract its non-zero values with ArrayRules for example.
– jose
Commented Oct 11, 2022 at 14:59

The answer from the comments is to define the tensor by ArrayRules. The correct coding is then:

a = ConstantArray[0, {3, 3, 3}];
a[[1, 1, 1]] = 1;
a[[1, 1, 2]] = 2;
a[[1, 2, 3]] = 5;
asym = Normal[SymmetrizedArray[ArrayRules[a],{3,3,3},Symmetric[All]]];
MatrixForm[asym]