# Simplifying expression using pattern matching inside Assuming[]

I want to simplify a sum of terms that look like so:

1/96 (-48 I λ ℏ^2 G[1, 1] G[1, t1] G[1, t2] -
12 λ^2 ℏ^3 G[1, 2]^2 G[1, t1] G[1, t2] G[2, 2] -
3 λ^2 ℏ^3 G[1, 1] G[1, t1] G[1, t2] G[2, 2]^2 -
8 λ^2 ℏ^3 G[1, 2]^3 G[1, t2] G[2, t1] -
12 λ^2 ℏ^3 G[1, 1] G[1, 2] G[1, t2] G[2, 2] G[2,
t1] - 8 λ^2 ℏ^3 G[1, 2]^3 G[1, t1] G[2, t2] -
12 λ^2 ℏ^3 G[1, 1] G[1, 2] G[1, t1] G[2, 2] G[2,
t2] - 12 λ^2 ℏ^3 G[1, 1] G[1, 2]^2 G[2, t1] G[2,
t2] + 24 I λ ℏ^2 G[2, 2] G[2, t1] G[2, t2])


Simplification should be acheived by using the fact that product of G's terms that differ only by exchange of 1 and 2 are equal as well as each G is symmetric in its two arguments i.e. $G[1,2]=G[2,1]$

So, $G[t1,1]G[1,2]^3G[t1,2]=G[t1,2]G[1,2]^3G[t1,1]$

Edit 1:

I scraped off my earlier code as I just realized it was completely wrong. Also, I am sorry for not being clearer. Exchange symmetry has to be checked for each term of the sum as a whole.

Edit 2:

Another try with no luck:

Assuming[s : _Times == (s /. {1 -> 2, 2 -> 1 }),
Simplify@(G[1, 1] G[1, t1] G[1, t2] + G[2, 2] G[2, t1] G[2, t2])]

• SetAttributes[G,Orderless]. – AccidentalFourierTransform Apr 1 '18 at 14:50
• @AccidentalFourierTransform Thanks for the nifty code for symmetry of G. What about the symmetry of each product expression as in interchange of 1 and 2? – Subho Apr 1 '18 at 14:53
• That is much more complicated. You have to brute-force all permutations. This grows as a factorial, so don't expect any efficient approach. Why don't you use FeynArts? – AccidentalFourierTransform Apr 1 '18 at 14:56

I think you should canonicalize each product of G's. For example:

SetAttributes[G, Orderless]

canon[term_Plus] := canon /@ term
canon[term_Times] := First @ Sort[{term, term /. G->switchG}]

switchG[a_,b_]:=G @@ ({a,b} /. {1->2, 2->1})


expr = 1/96 (-48 I λ ℏ^2 G[1,1] G[1,t1] G[1,t2] -
12 λ^2 ℏ^3 G[1,2]^2 G[1,t1] G[1,t2] G[2,2] -
3 λ^2 ℏ^3 G[1,1] G[1,t1] G[1,t2] G[2,2]^2 -
8 λ^2 ℏ^3 G[1,2]^3 G[1,t2] G[2,t1] -
12 λ^2 ℏ^3 G[1,1] G[1,2] G[1,t2] G[2,2] G[2,t1] -
8 λ^2 ℏ^3 G[1,2]^3 G[1,t1] G[2,t2] -
12 λ^2 ℏ^3 G[1,1] G[1,2] G[1,t1] G[2,2] G[2,t2] -
12 λ^2 ℏ^3 G[1,1] G[1,2]^2 G[2,t1] G[2,t2] +
24 I λ ℏ^2 G[2,2] G[2,t1] G[2,t2]
);

canon @ Expand @ expr


-(1/4) I λ ℏ^2 G[1, 1] G[1, t1] G[1, t2] - 1/4 λ^2 ℏ^3 G[1, 2]^2 G[1, t1] G[1, t2] G[2, 2] - 1/32 λ^2 ℏ^3 G[1, 1] G[1, t1] G[1, t2] G[2, 2]^2 - 1/6 λ^2 ℏ^3 G[1, 2]^3 G[1, t2] G[2, t1] - 1/4 λ^2 ℏ^3 G[1, 1] G[1, 2] G[1, t2] G[2, 2] G[2, t1]

• Thanks! This works just fine. Can you explain how the sorting happens in Sort[{term, term /. G->switchG}], given that it is not one of the common ordering functions like Less, Greater or lexicographical ordering? – Subho Apr 2 '18 at 11:42