<<PolylogTools`

I41[x_,y_] := G[y, 0, 0, 0, x, 1];
I41m[x_,y_] := (I41[x,y] - I41[x,1/y])/2;

L5[x_] := -G[0, 0, 0, 0, 1/x, 1];

SetAttributes[L5sym,HoldAll];
Options[L5sym]={oneMinusOneOverX->False, oneOverP->False, sumOverP->False};
L5sym[coeff_,arg_,opts:OptionsPattern[]]:=Module[{oneOverPTF,oneMinusOneOverXTF,sumOverPTF,coeffs,args},(
oneOverPTF=OptionValue[oneOverP]==True;
sumOverPTF=OptionValue[sumOverP]==True;
oneMinusOneOverXTF = OptionValue[oneMinusOneOverX] == True;

coeffs={Hold[coeff]};
args={Hold[arg]};

If[oneOverPTF,coeffs=Join[coeffs,-coeffs/.{HoldPattern[a]->d,HoldPattern[d]->a}];
args=Join[args,args/.{p->1/p}];];

If[oneMinusOneOverXTF,
coeffs = Join[coeffs, coeffs, coeffs];
args = Join[args, args/.x->1-1/x, args/.x->1/(1-x)];
];

If[sumOverPTF,
Return[Plus@@Release[MapThread[#1 Lip[#2]&,{coeffs,args}]]];
];

Return[Plus@@Release[MapThread[#1 L5i[#2]&,{coeffs,args}]]];
)];

leadingsimpt[expr_] := expr//.{(-1+(1/q))^exp_:>(1-q)^exp/q^exp,(1-(1/q))^exp_:>(-1)^exp(1-q)^exp/(q)^exp,(1/q)^exp_:>q^-exp,(-1/q)^exp_:>(-1)^exp q^-exp,(-1+(1/(1-q)))^exp_:>q^exp/(1-q)^exp,(1-(1/(1-q)))^exp_:>(((-1)^exp(q)^exp)/((1-q)^exp)),(-(1/(1-q)))^exp_:>(-1)^exp(1-q)^-exp,((1/(1-q)))^exp_:>(1-q)^-exp,(-1+q)^exp_:>(-1)^exp(1-q)^exp, (-1)^-exp_:>(-1)^exp,(-q)^exp_:>(-1)^exp q^exp};Lleadt[expr_] := expr/.Liq[arg_]:>Liq[leadingsimpt[arg/.{d->-a-b}]];

sumrules={
Sum[f_Plus,it:{x_Symbol,__}]:>(Sum[#,it]&)/@f,
Sum[c_ f_,it:{x_Symbol,__}]:>c Sum[f,it]/;FreeQ[c,x],
Sum[c_,it:{x_Symbol,__}]:>c Sum[1,it]/;FreeQ[c,x]
};

L5iinv[arg_]:=If[Sort[Factor@Expand[{arg,1/arg}]][[1]]===Factor[arg],L5i[Factor[arg]],L5i[Factor[1/arg]]];
L5can[expr_]:=expr/.L5i[arg_]:>L5iinv[arg]

L5piinv[arg_]:=If[Sort[Factor@Expand[{arg,1/arg}]][[1]]===Factor[arg],Lip[Factor[arg]],Lip[Factor[1/arg]]];
L5pcan[expr_]:=expr/.Lip[arg_]:>L5piinv[arg]

leadingsimpt[expr_] := expr//.{(-1+(1/x))^exp_:>(1-x)^exp/q^exp,(1-(1/x))^exp_:>(-1)^exp(1-x)^exp/(x)^exp,(1/x)^exp_:>x^-exp,(-1/x)^exp_:>(-1)^exp x^-exp,(-1+(1/(1-x)))^exp_:>x^exp/(1-x)^exp,(1-(1/(1-x)))^exp_:>(((-1)^exp(x)^exp)/((1-x)^exp)),(-(1/(1-x)))^exp_:>(-1)^exp(1-x)^-exp,((1/(1-x)))^exp_:>(1-x)^-exp,(-1+x)^exp_:>(-1)^exp(1-x)^exp, (-1)^-exp_:>(-1)^exp,(-x)^exp_:>(-1)^exp x^exp};Lleadt[expr_] := expr/.L5i[arg_]:>L5i[leadingsimpt[arg/.{d->-a-b}]];

coeffsimp[expr_] := Plus@@(#[[1]]#[[2]]&/@(({Factor[Plus@@#[[All,1]]],#[[1,2]]})&/@(expr//Cases[#,a_ b_L5i | a_ b_Liq|a_ b_Lipq| a_ b_Lip:>{a,b}]&//GatherBy[#, #[[2]]&]&)))

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

(* I41m[x, y] + I41m[1/(1-x), y] + I41m[1-1/x, y];

li6termsFullXslot[y_] := I41i[1,y] +(1/2) L5i[1-y]-(1/4) L5i[(1/((-1+x) (-1+y)))]-(1/4) L5i[((-1+x)/(-1+y))]-(1/4) L5i[-(1/(x (-1+y)))]-(1/4) L5i[-((-1+x)/(x (-1+y)))]-(1/4) L5i[-(x/(-1+y))]-(1/4) L5i[-(x/((-1+x) (-1+y)))]-(1/12) L5i[-((-1+y)/((-1+x) x (y^2)))]-(1/12) L5i[-(((((-1+x))^2) (-1+y))/(x (y^2)))]-(1/12) L5i[(((x^2) (-1+y))/((-1+x) (y^2)))]+(5/2) L5i[(1/y)]-L5i[-(1/((-1+x) y))]+L5i[-((-1+x)/y)]+L5i[(1/(x y))]-L5i[((-1+x)/(x y))]-L5i[(x/y)]+L5i[(x/((-1+x) y))]+(1/12) L5i[-((-1+x)/((x^2) (-1+y) y))]+(1/12) L5i[(x/((((-1+x))^2) (-1+y) y))]+(1/12) L5i[(((-1+x) x)/((-1+y) y))]-(1/2) L5i[((-1+y)/y)]+(1/4) L5i[-((-1+y)/((-1+x) y))]+(1/4) L5i[-(((-1+x) (-1+y))/y)]+(1/4) L5i[((-1+y)/(x y))]+(1/4) L5i[(((-1+x) (-1+y))/(x y))]+(1/4) L5i[((x (-1+y))/y)]+(1/4) L5i[((x (-1+y))/((-1+x) y))];

li6termsFullQYslot[x_] := (1/(a b d (d-a))) L5i[(t/(x^a (1-x)^b))] +
+(1/(a b d (d-a)))L5i[(t/(x^d(x-1)^b))]+

 -(d/2) L5i[x] + b L5i[1-x] + b L5i[1-(1/x)] +

+ -(b/(4(d-a))) Lip[(((((1-x))^2) p)/(x (((1-p))^2)))]+

+ (((d-a)/(4 b))+1) Lip[x p] +
+ (((d-a)/(4 b))-1) Lip[(x/p)] +

+(b/a)( Lip[ (1/(1-p))] -  Lip[ ((1-x)/(1-p))]- Lip[ ((1-1/x)/(1-p))])+
-(b/d)( Lip[(1/(1-1/p))] -  Lip[((1-x)/(1-1/p))]- Lip[((1-1/x)/(1-1/p))]);

(* -- *)

(* i41m[[x] + [1/(1-x)] + [1-1/x], [p]]

i41id = -I41roots[1,p]+(b)/a Lip[1-p]-(a+3 b)/b Lip[1/p]+b/(a+b) Lip[(-1+p)/p];

result = -i41id + (li6termsFullQYslot[x] +li6termsFullQYslot[1/(1-x)] + li6termsFullQYslot[1-1/x]) - (li6termsFullXslot[p]/.{L5i->Lip,I41i->I41roots})/.{d->-a-b}//L5can//L5pcan//Lleadt//Expand//coeffsimp

g[p,y_] := (1-y)^b y^a;
g[1/(p),y_]:=(y-1)^b y^d;

result - (
L5sym[((-1)/(a b d (a-d))), (t/(g[p,x])), {oneMinusOneOverX->True,oneOverP->True}]+
-L5sym[1/12, (((-1+p) p)/((-1+x) x)), {oneMinusOneOverX->True,oneOverP->True, sumOverP->True}]+
+L5sym[(b/(8(a-d))),(((((-1+p))^2) x)/(p (((-1+x))^2))), {oneMinusOneOverX->True,oneOverP->True, sumOverP->True}]+
+L5sym[(((5a + 4d))/(4a)),(1-p )x, {oneMinusOneOverX->True,oneOverP->True, sumOverP->True}]+
-L5sym[(((a - d))/(4 b)),p x, {oneMinusOneOverX->True,oneOverP->True, sumOverP->True}]+
+L5sym[((5a + 4d)/(4 a)),(x/((1-p) )), {oneMinusOneOverX->True,oneOverP->True, sumOverP->True}]+
+L5sym[(((a - d))/(12b)),p, {oneMinusOneOverX->True,oneOverP->True, sumOverP->True}]+
-L5sym[((5a + 4d)/(6a)),1-p, {oneMinusOneOverX->True,oneOverP->True, sumOverP->True}]+
-L5sym[(1/2) (5d + 4a),x, {oneMinusOneOverX->True}]
)/.{d->-a-b}//Lleadt//L5can//L5pcan//coeffsimp

L5sym[(1/4) (5d + 4a),x, {oneMinusOneOverX->True, oneOverP->True}]//L5can//coeffsimp

(* ------ *)

case1 = result/.{a->1,b->2};

LipX[arg_] := Sum[L5i[arg]/.{p->px[i]},{i, 1, 3}];

px[1]=1/(1-y+y^2);
px[2]=px[1]/.y->1-1/y//Factor;
px[3]=px[2]/.y->1-1/y//Factor;

tx = px[3](1-px[3])^2//Factor;

case1/.{u->ux,t->tx}/.{Lip->LipX,Liq->LiqX,Lipq->LipqX}//L5can//Expand