(* IBP by FIRE *)
Quit[];

SetDirectory[NotebookDirectory[]]

<<mathematicaM2`

<<"Baikov.m"

??Baikov

Propagators={(k[1])^2-m1,(k[1]+p[1])^2-m1,(k[1]+p[1]+p[2])^2-m1,(k[1]+p[1]+p[2]+p[3])^2,k[2]^2-m1,(k[2]-p[1])^2,(k[2]-p[1]-p[2])^2-m1,(k[2]-p[1]-p[2]-p[3])^2-m1,(k[1]+k[2])^2}/.m1->0

repl={s[3,3]->0,s[4,4]->0,s[5,5]->0,s[3,4]->S/2,s[4,5]->T/2,s[3,5]->(mh-S-T)/2}/.mh->0

Do[s[j,i]=s[i,j],{i,3,5},{j,i,5}]

ll={3,4,5}
Sum[s[i,j],{i,ll},{j,ll}]/.repl

ll={3,4}
Sum[s[i,j],{i,ll},{j,ll}]/.repl

ll={4,5}
Sum[s[i,j],{i,ll},{j,ll}]/.repl

b2L4P=Baikov[2,3,Propagators,repl]

tmp2L4P=b2L4P[[3]]b2L4P[[-1]]/.d->4-2ϵ//Simplify

kindep=Cases[tmp2L4P,a_^(ϵ)->a][[1]]^ϵ
xdep=Cases[tmp2L4P,a_^(-1-ϵ)->a][[1]]

vars=Table[x[i],{i,1,Length[Propagators]}]

(* building DE wrt S *)

mif={G[0, {1, 1, 1, -1, 1, 0, 1, 1, 1}], G[0, {1, 1, 1, 0, 1, 0, 1, 1, 1}], G[0, {1, 1, 1, 0, 0, 0, 0, 1, 1}], G[0, {0, 1, 1, 0, 1, 0, 0, 1, 1}], 
 G[0, {1, 0, 1, 0, 1, 0, 1, 0, 0}], G[0, {0, 1, 0, 0, 1, 0, 1, 0, 1}], G[0, {0, 1, 0, 0, 0, 0, 0, 1, 1}], G[0, {0, 0, 1, 0, 1, 0, 0, 0, 1}]}/.G->F

Clear[pol]
pol[i_]:=D[xdep,x[i]]

pList=Join[{D[xdep,S]},Table[pol[i],{i,1,Length[Propagators]}]];

syz1=M2Syzygy[pList,vars,OptionalInput->"Algorithm=>Sugarless,Strategy=>{}",MinimalGenerators->True]//Simplify
%//Length

Length[syz1]

Sum[pList[[i]]syz1[[i,1]],{i,1,Length[pList]}]//Simplify

Table[syz1[[1,k]],{k,1,Length[syz1]}]

Sum[pList[[i]]syz1[[i,5]],{i,1,Length[pList]}]//Simplify
Sum[pList[[i]]syz1[[i,6]],{i,1,Length[pList]}]//Simplify

pList//Length

res=.

isyz=5
DeleteFile["tmpfile.m"]
Do[
FE=Product[x[i]^(-mif[[ig,2,i]]),{i,1,Length[Propagators]}];
dop1=Sum[D[syz1[[i,isyz]]/syz1[[1,isyz]]FE,x[i-1]],{i,2,10}];
tmp=dop1+D[kindep,S]FE/kindep;
tmp=Collect[tofire[tmp,Length[Propagators]],F[__],Factor//Simplify];
res[ig]=tmp/.F[a___]:>F[0,a];
(*tmp=tmp//InputForm;*)
,{ig,1,Length[mif]}]
Save["tmpfile.m",res]

isyz=6
DeleteFile["tmpfile.m"]
Do[
FE=Product[x[i]^(-mif[[ig,2,i]]),{i,1,Length[Propagators]}];
dop1=Sum[D[syz1[[i,isyz]]/syz1[[1,isyz]]FE,x[i-1]],{i,2,10}];
tmp=dop1+D[kindep,S]FE/kindep;
tmp=Collect[tofire[tmp,Length[Propagators]],F[__],Factor//Simplify];
res[ig]=tmp/.F[a___]:>F[0,a];
(*tmp=tmp//InputForm;*)
,{ig,1,Length[mif]}]
Save["tmpfile.m",res]

(* building DE wrt T *)

mif={G[0, {1, 1, 1, -1, 1, 0, 1, 1, 1}], G[0, {1, 1, 1, 0, 1, 0, 1, 1, 1}], G[0, {1, 1, 1, 0, 0, 0, 0, 1, 1}], G[0, {0, 1, 1, 0, 1, 0, 0, 1, 1}], 
 G[0, {1, 0, 1, 0, 1, 0, 1, 0, 0}], G[0, {0, 1, 0, 0, 1, 0, 1, 0, 1}], G[0, {0, 1, 0, 0, 0, 0, 0, 1, 1}], G[0, {0, 0, 1, 0, 1, 0, 0, 0, 1}]}/.G->F

Clear[pol]
pol[i_]:=D[xdep,x[i]]

pList=Join[{D[xdep,T]},Table[pol[i],{i,1,Length[Propagators]}]];

syz1=M2Syzygy[pList,vars,OptionalInput->"Algorithm=>Sugarless,Strategy=>{}",MinimalGenerators->True]//Simplify
%//Length

Length[syz1]

Sum[pList[[i]]syz1[[i,1]],{i,1,Length[pList]}]//Simplify

Table[syz1[[1,k]],{k,1,Length[syz1]}]

Sum[pList[[i]]syz1[[i,5]],{i,1,Length[pList]}]//Simplify
Sum[pList[[i]]syz1[[i,6]],{i,1,Length[pList]}]//Simplify

pList//Length

res=.

isyz=5
DeleteFile["tmpfile.m"]
Do[
FE=Product[x[i]^(-mif[[ig,2,i]]),{i,1,Length[Propagators]}];
dop1=Sum[D[syz1[[i,isyz]]/syz1[[1,isyz]]FE,x[i-1]],{i,2,10}];
tmp=dop1+D[kindep,T]FE/kindep;
tmp=Collect[tofire[tmp,Length[Propagators]],F[__],Factor//Simplify];
res[ig]=tmp/.F[a___]:>F[0,a];
(*tmp=tmp//InputForm;*)
,{ig,1,Length[mif]}]
Save["tmpfile.m",res]

isyz=6
DeleteFile["tmpfile.m"]
Do[
FE=Product[x[i]^(-mif[[ig,2,i]]),{i,1,Length[Propagators]}];
dop1=Sum[D[syz1[[i,isyz]]/syz1[[1,isyz]]FE,x[i-1]],{i,2,10}];
tmp=dop1+D[kindep,T]FE/kindep;
tmp=Collect[tofire[tmp,Length[Propagators]],F[__],Factor//Simplify];
res[ig]=tmp/.F[a___]:>F[0,a];
(*tmp=tmp//InputForm;*)
,{ig,1,Length[mif]}]
Save["tmpfile.m",res]