<<PolylogTools`

GatherCiTiList[expr_]:=Block[{temp=flatTensor[Expand[expr]]},temp=GatherBy[List@@CollectCiTi[temp,1],Last];
temp=CleanUp/@temp;
Return[temp];];
CleanUp[list_List]:={list[[1,2]],Total[list[[All,1]]]}
CollectCiTi[sum_Plus,a_]:=CollectCiTi[#,a]&/@sum;
CollectCiTi[a_. ct_CiTi,b_]:=CollectCiTi[a,ct b];
CollectCiTi[sum_Plus,a_]:=CollectCiTi[#,a]&/@sum;
CollectCiTi[a_. ct_CiTi,b_]:=CollectCiTi[a,ct b];
CleanUp[list_List]:={list[[1,2]],Total[list[[All,1]]]}
GatherCiTiList[expr_]:=Block[{temp=flatTensor[Expand[expr]]},temp=GatherBy[List@@CollectCiTi[temp,1],Last];
temp=CleanUp/@temp;
Return[temp];];

(* -------- *)

cr[a_,b_,c_,Inf]:=(a-c)/(b-c);
cr[a_,b_,Inf,d_]:=(b-d)/(a-d);
cr[a_,Inf,c_,d_]:=(a-c)/(a-d);
cr[Inf,b_,c_,d_]:=(b-d)/(b-c);

cr[a_,b_,c_,d_]:=(a-c) (b-d)/((a-d) (b-c));
cr[a_,b_,c_,d_,e_]:={cr[a,b,c,d],cr[a,b,c,e]};
cr[a_,b_,c_,d_,e_,f_]:={cr[a,b,c,d],cr[a,b,c,e],cr[a,b,c,f]};

crorbit[{a_,b_,c_,d_}] := {{a,b,c,d},{b,a,d,c},{c,d,a,b},{d,c,b,a},{b,a,c,d},{a,b,d,c},{d,c,a,b}, {c,d,b,a}}//Sort;

I311[x_,y_,z_] := G[z, y, 0, 0, x, 1];
I32[x_,y_] := G[0, y, 0, 0, x, 1];
L5[x_] := -G[0, 0, 0, 0, 1/x, 1];

I41[x_,y_] := G[y, 0, 0, 0, x, 1];
N5[x_] := G[0, 0, 0, 1, 1, x];

N5old[x_] := I41[1,x];

tocr[expr_] := expr/.{I311[a_,b_,c_,d_,e_,f_] :> I311@@cr[a,b,c,d,e,f], I32[a_,b_,c_,d_,e_] :> I32@@cr[a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