Get[NotebookDirectory[]<>"PolyLogToolsLite.m"];

(*Using a pattern to make a pattern not a pattern!?*)lhsRule[RuleDelayed[lhs_,rhs_]]:=lhs/.HoldPattern[w_Pattern]:>w[[1]]
rhsRule[RuleDelayed[lhs_,rhs_]]:=Expand[rhs]

ruleToIdentity[expr_]:=lhsRule[expr]-rhsRule[expr]//Expand;

cr[{a_,b_,c_,d_}] := Limit[(a - c)/(a - d) / ((b - c)/(b-d)), Inf->Infinity];
cr[l_List] := Sequence@@(cr[Join[l[[1;;3]], {#}]]&/@l[[4;;All]]);

II[indices_List,arguments_List]/;Length[indices]==Length[arguments]&&VectorQ[indices,IntegerQ[#]&&#≥1&]:=G@@Flatten[Join[Table[Join[Table[0,{indices[[j]]-1}],{arguments[[j]]}],{j,Length[indices],1,-1}],{1}]]

(* ---- check the I31 functional equations from Gangl ---- *)

Get[NotebookDirectory[]<>"wt4_fe_i31.m"];

I31ab[a,b,c,d,e]/.{a->Inf,b->0,c->1,cri->cr,IIi->II}//CreateTensor//sh//flatTensor//Expand

I31bc[a,b,c,d,e]/.{a->Inf,b->0,c->1,cri->cr,IIi->II}//CreateTensor//sh//flatTensor//Expand

I31de[a,b,c,d,e]/.{a->Inf,b->0,c->1,cri->cr,IIi->II}//CreateTensor//sh//flatTensor//Expand

I31cyc[a,b,c,d,e]/.{a->Inf,b->0,c->1,cri->cr,IIi->II}//CreateTensor//sh//flatTensor//Expand

(* check the cyclic symmetry of the reductions *)

Get[NotebookDirectory[]<>"wt4_dan_precomputed.m"];

wt4danStructuredLowerPrecomputed - (wt4danStructuredLowerPrecomputed/.{a->b,b->c,c->d,d->e,e->a})

(* The functions f and phi4 are not equal *)

wt4danStructuredLowerPrecomputed - wt4DanAllNLoweras31and4Precomputed/.{cri->cr,IIi->II}//CreateTensor//sh//flatTensor//Expand

wt4danStructuredLowerPrecomputed - wt4DanAllNLoweras31and4Precomputed/.{cri->cr,IIi->II}//CreateTensor//del//Expand

(* The function phi4 is not even cyclically symmetric *)

(wt4DanAllNLoweras31and4Precomputed - (wt4DanAllNLoweras31and4Precomputed/.{a->b,b->c,c->d,d->e,e->a}))/.{cri->cr,IIi->II}//CreateTensor//del//Expand

(wt4DanAllNLoweras31and4Precomputed - (wt4DanAllNLoweras31and4Precomputed/.{a->b,b->c,c->d,d->e,e->a}))/.{cri->cr,IIi->II}//CreateTensor//sh//flatTensor//Expand

(* Now decompose the I31 functional equation *)

i31fe = (wt4danStructuredLowerPrecomputed - (wt4danStructuredLowerPrecomputed/.{a->f})) - (wt4DanAllNLoweras31and4Precomputed - (wt4DanAllNLoweras31and4Precomputed/.a->f));

i31fe/.{cri->cr,IIi->II}//CreateTensor//sh//flatTensor//Expand

danI31feasGangl

danI31feasGangl//Length

canonicalI4[IIi[{4},{cri[{a_,b_,c_,d_}]}]] := #[[2]]IIi[{4},{cri[#[[1]]]}]&@SortBy[{{{a,b,c,d},1},{{b,a,d,c},1},{{c,d,a,b},1},{{d,c,b,a},1},{{b,a,c,d},-1},{{a,b,d,c},-1},{{d,c,a,b},-1},{{c,d,b,a},-1}}, #[[1]]&][[1]]

-20 i31fe + danI31feasGangl/.{I31abi->I31ab,I31bci->I31bc,I31dei->I31de,I31cyci->I31cyc}/.w:IIi[{4},{cri[{a_,b_,c_,d_}]}]:>canonicalI4[w]//Expand