(* ::Package:: *)

(* ::Title:: *)
(*Exercise 4.15*)


(* ::Subtitle:: *)
(*Computing leading singularities with the package DlogBasis*)


(* ::Text:: *)
(*This notebook was tested with Wolfram Mathematica 12.3.1.*)
(*Get DlogBasis at https://github.com/pascalwasser/DlogBasis .*)


(* ::Text:: *)
(*We start off by setting the working directory and loading DlogBasis.*)


$Directory = If[$FrontEnd=!=Null,NotebookDirectory[],DirectoryName[$InputFileName]];
SetDirectory[$Directory];


<<DlogBasis`;


(* ::Text:: *)
(*If you have issues loading DlogBasis, make sure that it is visible in Mathematica's search path ($Path). If not, add the following line to the file $UserBaseDirectory/Kernel/init.m:*)
(**)
(*$Path = Append[$Path, directory];*)
(**)
(*where the string directory specifies the folder where the file "DlogBasis.wl" is located. Then quit and restart.*)


(* ::Chapter:: *)
(*a) Massive tadpole and bubble integrals, D=2*)


(* ::Text:: *)
(*We use the parametrisation of the integrands derived in the text and in the solution to exercise 4.13. We neglect the constant prefactors.*)


\[Omega]10 = s/(msq-s*\[Beta]1*\[Beta]2);
\[Omega]11 = 1/s/(\[Beta]1*\[Beta]2-msq/s)/((1+\[Beta]1)*(1+\[Beta]2)-msq/s);
integrandvariables = {\[Beta]1,\[Beta]2};


(* ::Text:: *)
(*The function LeadingSingularities[func, vars] computes the leading singularities of the function "func" treating the variables in the list "vars" as integrand variables. The other variables in "func" are viewed as parameters.*)


lsing["\[Omega]10"] = LeadingSingularities[\[Omega]10,integrandvariables];
lsing["\[Omega]11"] = LeadingSingularities[\[Omega]11,integrandvariables];

Print["leading singularities: "];
Print["\[Omega]10 -> ", lsing["\[Omega]10"]];
Print["\[Omega]11 -> ", lsing["\[Omega]11"]];


Clear[lsing,\[Omega]10,\[Omega]11,integrandvariables];


(* ::Chapter:: *)
(*b) Two-loop kite integral, D=4*)


(* ::Text:: *)
(*We use the parametrisation of the integrand derived in the solution to exercise 4.14. The inverse propagators are given by*)


D1 = (a3*a4-a1*a2)*s;
D2 = (a3*a4-a1*a2+a1+a2-1)*s;
D3 = (b3*b4-b1*b2)*s;
D4 = (b3*b4-b1*b2-b1-b2-1)*s;
D5 = (a3*a4-a1*a2+b3*b4-b1*b2+a3*b4+a4*b3-a1*b2-a2*b1)*s;
jacobian = s^4;

integrand = jacobian/D1/D2/D3/D4/D5;
integrandvariables = {a1,a2,a3,a4,b1,b2,b3,b4};


(* ::Text:: *)
(*The function LeadingSingularities returns Fail[DoublePole]. This means that the integrand has double poles, and hence cannot be written in a dlog form.*)


lsing = LeadingSingularities[integrand,integrandvariables];
Print[lsing];


Clear[D1,D2,D3,D4,D5,jacobian,integrand,integrandvariables,lsing];


(* ::Chapter:: *)
(*c) Massless box and triangle integrals, D=4*)


(* ::Text:: *)
(*We initialize loop momenta, external momenta, propagators and kinematic replacements in order to use DlogBasis' parametrisation tools.*)


Internal={k};
External={p1,p2,p3};
Propagators={-k^2,-(k+p1)^2,-(k+p1+p2)^2,-(k+p1+p2+p3)^2};
Replacements={p1^2->0,p2^2->0,p3^2->0,p1*p2->s/2,p2*p3->t/2,p1*p3->-1/2*(s+t)};

InitializeDlogbasis[];


(* ::Text:: *)
(*We choose the standard four-dimensional spinor-helicity parametrisation with p1 and p2 as basis vectors. p3 serves for an internal normalization. a labels the parametrisation variables. The loop momentum k is then parametrised as*)
(**)
(*k = a[1]*p1 + a[2]*p2 + a[3]*q3*m+ a[4]*q4/m ,*)
(**)
(*where*)
(**)
(*q3 = <1|gamma|2] / 2 ,*)
(*q4 = <2|gamma|1] / 2 ,*)
(*m = <23>/<13> .*)
(**)
(*m is an arbitrary phase normalisation factor which makes the variables a[i] phase free.*)
(*We set this parametrisation, and print the parametrisation of the propagators.*)


SetParametrization[SpinorHelicityParametrization[Internal,{a},{p1,p2,p3}]];

Print["parameterisation of the propagators: "];
Do[
  Print["D_"<>ToString[i], " = ", Simplify[Parametrize[Propagators[[i]]]]], 
{i,Length[Propagators]}]


(* ::Text:: *)
(*We compute the leading singularities of all box and triangle integrals of this family.*)


integrals = {G[1,{1,1,1,1}], G[1,{1,1,1,0}], G[1,{1,1,0,1}], G[1,{1,0,1,1}], G[1,{0,1,1,1}]};

Do[
  Module[{integral,integralparam,leadingsing},
    integral = integrals[[i]];
    integralparam = Parametrize[integral];
    leadingsing = LeadingSingularities[integralparam,IntegrandVariables[]];
    Print[integral, " -> ", leadingsing];
  ],
{i,Length[integrals]}];


Clear[Internal,External,Propagators,Replacements,integrals];
