I am looking to simplify an output that I have from previous calculations in Mathematica:

```
-2 Sin[\[Theta]/2]^2 ((-1+Cos[\[Theta]]) g[P,P,T,U]-(1+Cos[\[Theta]]) g[Q,Q,T,U]-(g[P,Q,T,U]+g[Q,P,T,U]) Sin[\[Theta]])
```

However, in this specific problem, we know that `g[Q, P, T, U] == g[P, Q, T, U]`

, in the sense that `g`

can be looked at as a tensor with the custom symmetries `g[P,Q,R,S] == g[P,Q,S,R] == g[Q,P,R,S] == g[Q,P,S,R] == g[R,S,P,Q] == g[R,S,Q,P] == g[S,R,P,Q] == g[S,R,Q,P]`

. (They are the two-electron integrals occurring in quantum chemistry.)

I know that I could use the replacement rule `/.{g[Q, P, T, U] -> g[P, Q, T, U]}`

, but I have many similar terms, for example I have

```
-2 Sin[\[Theta]/2]^2 ((-1+Cos[\[Theta]]) g[R,S,P,P]-(1+Cos[\[Theta]]) g[R,S,Q,Q]-(g[R,S,P,Q]+g[R,S,Q,P]) Sin[\[Theta]])
```

as well, so I would need to use the replacement rule `/.{g[R, S, Q, P}->g[R, S, P, Q]}`

as well.

This list of different and similar terms is huge, so my question is if there is there a way to tell mathematica that the given symmetry of the arguments of `g`

exists, in order to simplify the above expression.

Ultimately, I would like to simplify the expressions of the type

```
2 Sin[\[Theta]/2]^4 (8 Cos[\[Theta]/2]^4 g[Q,P,P,Q]+8 g[P,Q,Q,P] Sin[\[Theta]/2]^4+2 Sin[\[Theta]] ((1+Cos[\[Theta]]) g[P,P,P,Q]+(-1+Cos[\[Theta]]) g[P,P,Q,P]-g[P,Q,P,P]+Cos[\[Theta]] g[P,Q,P,P]+g[P,Q,Q,Q]-Cos[\[Theta]] g[P,Q,Q,Q]+g[Q,P,P,P]+Cos[\[Theta]] g[Q,P,P,P]-g[Q,P,Q,Q]-Cos[\[Theta]] g[Q,P,Q,Q]-g[Q,Q,P,Q]-Cos[\[Theta]] g[Q,Q,P,Q]+g[Q,Q,Q,P]-Cos[\[Theta]] g[Q,Q,Q,P]+g[P,P,P,P] Sin[\[Theta]]-g[P,P,Q,Q] Sin[\[Theta]]-g[P,Q,P,Q] Sin[\[Theta]]-g[Q,P,Q,P] Sin[\[Theta]]-g[Q,Q,P,P] Sin[\[Theta]]+g[Q,Q,Q,Q] Sin[\[Theta]]))
```