Unexpected outputs from TensorSymmetry

I have encountered what looks like a bug relating to tensor symmetry computations (or maybe I am missing something?)

Take the following example:

Table[E^(-(((i - j)/2 - p + q)^2/2)), {i, 5}, {j, 5}, {p, 3}, {q, 3}]

This array is symmetric if you swap slots 1 with 2 and 3 with 4. TensorSymmetry should give {{Cycles[{{1, 2}, {3, 4}}], 1}}. However, it doesn’t detect any symmetries at all. Checking

\[Element] Arrays[{5, 5, 3, 3}, Reals, {{Cycles[{{1, 2}, {3, 4}}], 1}}]

Also returns false. Passing to SymmetrizedArray also returns an array with no symmetries. Note that if you explicitly specify the symmetry it will work.

SymmetrizedArray[{i_, j_, p_, q_} :> E^(-(((i - j)/2 - p + q)^2/2)), {5, 5, 3, 3}, {{{2, 1, 4, 3}, 1}}]

The array you get will be symmetric and works with \[Element] and TensorSymmetry. In fact, it will pass an equality check with the non-symmetrized version, proving the array is indeed symmetric.

SymmetrizedArray[{i_, j_, p_, q_} :> E^(-(((i - j)/2 - p + q)^2/2)), 
 {5, 5, 3, 3}, {{{2, 1, 4, 3}, 1}}] == 
 Table[E^(-(((i - j)/2 - p + q)^2/2)), {i, 5}, {j, 5}, {p, 3}, {q, 3}]

Gives True, and

Symmetrize[
  Table[E^(-(((i - j)/2 - p + q)^2/2)), {i, 5}, {j, 5}, {p, 3}, {q, 3}], {{{2, 1, 4, 3}, 1}}] == 
 Table[E^(-(((i - j)/2 - p + q)^2/2)), {i, 5}, {j, 5}, {p, 3}, {q, 3}]

also gives True.

I suspect there is a bug in the symmetry finding or checking code. Here I am using exact numbers, so there shouldn’t be any tolerance issues. But if you use approximate numbers you get the same issue. This is on Wolfram Desktop 13.2.1.0 on MacOS ARM.

Hi Nicholas,

the tensor is definitely not symmetric

In[151]:= ((i - j)/2 - p + q)^2/2 - ((j - i)/2 - p + q)^2/2 // Simplify

Out[151]= (i - j) (-1 + q)

Regards Roland

It’s true that it’s not symmetric exchanging only i with j, but it is symmetric exchanging both i with j and p with q. This is what the symmetry {{2,1,4,3},1} indicates–equivalently {Cycles[{{1,2},{3,4}],1}. The symmetry you are checking for is {Cycles[{{1,2}}],1} or {{2,1,3,4},1}.

((i - j)/2 - p + q)^2/2 == ((j - i)/2 - q + p)^2/2 // Simplify

gives True

T is transpose-symmetric {1->2, 3->4}

In:=(T = 
   Table[ ((i - j) - p + q)^2 , {i, 4}, {j, 5}, {p, 3}, {q, 2}]) ==  
        Table[ ((j - i) - q + p)^2 , {i, 4}, {j, 5}, {p, 3}, {q, 2}] 

Out:= True

Tensorsymmetry[] seems to detect a symmetry of the simultaneous transpositions in groups only if the Rank is uniform.

In:= TensorSymmetry[T]

Out:= {}

In:= T = Table[ ((i - j) - p + q)^2 , {i, 4}, {j, 4}, {p, 4}, {q, 4}] ;

In In[294]:= TensorSymmetry[T]

Out= {{Cycles[{{2, 3}}], 1}, {Cycles[{{1, 2}, {3, 4}}],  1}, {Cycles[{{1, 2, 4, 3}}], 1}}

Yoe example reduced to the index function tensor

T = Table[ ((i - j) - p + q)^2 , {i, 4}, {j, 4}, {p, 3}, {q, 3}] 

In:= TensorSymmetry[T]

Out[296]= {}

Regards Roland