-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtools.cc
More file actions
1409 lines (1296 loc) · 45.8 KB
/
tools.cc
File metadata and controls
1409 lines (1296 loc) · 45.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// QCDLoop 2016
//
// Authors: Stefano Carrazza: stefano.carrazza@cern.ch
// Keith Ellis: keith.ellis@durham.ac.uk
// Giulia Zanderighi: giulia.zanderighi@cern.ch
#include <iostream>
#include <cmath>
#include "qcdloop/tools.h"
#include "qcdloop/config.h"
#include "qcdloop/maths.h"
#include "qcdloop/exceptions.h"
using std::cout;
using std::endl;
using std::is_same;
namespace ql {
template<typename TOutput, typename TMass, typename TScale>
Tools<TOutput,TMass,TScale>::Tools():
_qlonshellcutoff(is_same<TScale,double>::value ? 1e-10 : 1e-20q),
#if defined(__x86_64__) || defined(__i386__) || defined(__PPC64__) || defined(__ppc64__) || defined(_ARCH_PPC64)
_pi(is_same<TScale,double>::value ? M_PI : M_PIq),
#endif
#if defined(__aarch64__)
_pi(is_same<TScale,double>::value ? M_PI : M_PIl),
#endif
_pi2 (_pi*_pi),
_pio3 (_pi/TScale(3)),
_pio6 (_pi/TScale(6)),
_pi2o3 (_pio3*_pi),
_pi2o6 (_pio6*_pi),
_pi2o12(_pi2/TScale(12)),
_zero (is_same<TScale,double>::value ? 0.0 : 0.0q),
_half (is_same<TScale,double>::value ? 0.5 : 0.5q),
_one (is_same<TScale,double>::value ? 1.0 : 1.0q),
_two (is_same<TScale,double>::value ? 2.0 : 2.0q),
_three(is_same<TScale,double>::value ? 3.0 : 3.0q),
_four (is_same<TScale,double>::value ? 4.0 : 4.0q),
_five (is_same<TScale,double>::value ? 5.0 : 5.0q),
_six (is_same<TScale,double>::value ? 6.0 : 6.0q),
_ten (is_same<TScale,double>::value ? 10.0 : 10.0q),
_eps (is_same<TScale,double>::value ? 1e-6 : 1e-12q),
_eps4 (is_same<TScale,double>::value ? 1e-4 : 1e-4q),
_eps7 (is_same<TScale,double>::value ? 1e-7 : 1e-7q),
_eps10(is_same<TScale,double>::value ? 1e-10 : 1e-10q),
_eps14(is_same<TScale,double>::value ? 1e-14 : 1e-14q),
_eps15(is_same<TScale,double>::value ? 1e-15 : 1e-15q),
_xloss(is_same<TScale,double>::value ? 0.125 : 0.125q),
_neglig(is_same<TScale,double>::value ? 1e-14 : 1e-28),
_reps (is_same<TScale,double>::value ? 1e-16 : 1e-32q),
_2ipi(TOutput{_zero,_two*_pi}),
_ipio2(TOutput{_zero, _pi*_half}),
_ipi(TOutput{_zero, _pi}),
_czero (is_same<TOutput,complex>::value ? TOutput(0.0) : TOutput(0.0q)),
_chalf (is_same<TOutput,complex>::value ? TOutput(0.5) : TOutput(0.5q)),
_cone (is_same<TOutput,complex>::value ? TOutput(1.0) : TOutput(1.0q)),
_ctwo (is_same<TOutput,complex>::value ? TOutput(2.0) : TOutput(2.0q)),
_cthree(is_same<TOutput,complex>::value ? TOutput(3.0) : TOutput(3.0q)),
_cfour (is_same<TOutput,complex>::value ? TOutput(4.0) : TOutput(4.0q)),
_ieps (TOutput{_zero, _reps}),
_ieps2(TOutput{_zero, _reps*_reps}),
_ieps50(is_same<TOutput,complex>::value ? TOutput{_zero, 1e-50} : TOutput{_zero, 1e-50q})
{
// Show splash boot logo
Splash::Show();
// Allocate bernoulli coefficients
if (is_same<TScale,double>::value)
{
_C = {
0.4299669356081370,
0.4097598753307711,
-0.0185884366501460,
0.0014575108406227,
-0.0001430418444234,
0.0000158841554188,
-0.0000019078495939,
0.0000002419518085,
-0.0000000319334127,
0.0000000043454506,
-0.0000000006057848,
0.0000000000861210,
-0.0000000000124433,
0.0000000000018226,
-0.0000000000002701,
0.0000000000000404,
-0.0000000000000061,
0.0000000000000009,
-0.0000000000000001
};
_B = {
0.02777777777777777777777777777777777777777778774E0,
-0.000277777777777777777777777777777777777777777778E0,
4.72411186696900982615268329554043839758125472E-6,
-9.18577307466196355085243974132863021751910641E-8,
1.89788699889709990720091730192740293750394761E-9,
-4.06476164514422552680590938629196667454705711E-11,
8.92169102045645255521798731675274885151428361E-13,
-1.993929586072107568723644347793789705630694749E-14,
4.51898002961991819165047655285559322839681901E-16,
-1.035651761218124701448341154221865666596091238E-17,
2.39521862102618674574028374300098038167894899E-19,
-5.58178587432500933628307450562541990556705462E-21,
1.309150755418321285812307399186592301749849833E-22,
-3.087419802426740293242279764866462431595565203E-24,
7.31597565270220342035790560925214859103339899E-26,
-1.740845657234000740989055147759702545340841422E-27,
4.15763564461389971961789962077522667348825413E-29,
-9.96214848828462210319400670245583884985485196E-31,
2.394034424896165300521167987893749562934279156E-32,
-5.76834735536739008429179316187765424407233225E-34,
1.393179479647007977827886603911548331732410612E-35,
-3.372121965485089470468473635254930958979742891E-37,
8.17820877756210262176477721487283426787618937E-39,
-1.987010831152385925564820669234786567541858996E-40,
4.83577851804055089628705937311537820769430091E-42
};
}
else
{
// Based on CERNlib implementation C332 DDILOG
// Cross-checked by Wojciech Bizon and SC on June 2018.
// SC thanks Emanuele Re for discussion.
// p.67 of Luke, Y.L. "Mathematical Functions and their Aproximations"
// Recipe: change t -> -x in t -> [-1, 0]
// C[n] = - Integrate[ ChebyshevT[n,x] * PolyLog[2,-x] / Sqrt[x*(1-x)]] / norm[n]
// where norm[0] = pi, norm[>0] = pi/2.
_C = {
+0.4299669356081369720370336786993879911681q, // 47
+0.4097598753307710584682637109252552780893q, // 28
-0.0185884366501459196476416491402122676020q, // 391
+0.0014575108406226785536739284164594926527q, // 2055
-0.0001430418444234004877488301200908765223q, // 11267
+0.0000158841554187955323619055047167739548q, // 391004
-0.0000019078495938658272271963211420884105q, // 8015588
+0.0000002419518085416474949946146434289843q, // 47407588
-0.0000000319334127425178346049601414286296q, // 365082445
+0.0000000043454506267691229879571784781516q, // 3020705163
-0.0000000006057848011840744442970533090714q, // 01310493274
+0.0000000000861209779935949824428368451935q, // 499015050068
-0.0000000000124433165993886798964242137051q, // 456159308256
+0.0000000000018225569623573633006554773579q, // 2903333133341
-0.0000000000002700676604911465180857222938q, // 07277348726616
+0.0000000000000404220926315266464883285777q, // 966819039605138
-0.0000000000000061032514526918795037782652q, // 6125857640983405
+0.0000000000000009286297533019575861302980q, // 12120905726364786
-0.0000000000000001422602085511244683974902q, // 77390005481676598
+0.0000000000000000219263171815395735398033q, // 409420375519846175
-0.0000000000000000033979732421589786339948q, // 7449166351657333035
+0.0000000000000000005291954244833147145510q, // 39155749919426092154
-0.0000000000000000000827858081427899765284q, // 374428975307431576970
+0.0000000000000000000130037173454556037430q, // 510286627563116086246
-0.0000000000000000000020502222425528249238q, // 9003899608272738595180
+0.0000000000000000000003243578549148930334q, // 49269968207481971234178
-0.0000000000000000000000514779990334320717q, // 855020023960694971647731
+0.0000000000000000000000081938774771715779q, // 3800068495056627245722365
-0.0000000000000000000000013077835405712667q, // 2290049437436409702417541
+0.0000000000000000000000002092562930579890q, // 91245949861835427981622465
-0.0000000000000000000000000335616615054383q, // 751790629092426343180650287
+0.0000000000000000000000000053946577714317q, // 5180550927103490540268384425
-0.0000000000000000000000000008689193208690q, // 9968479986614298596382685532
+0.0000000000000000000000000001402281686966q, // 58818398547877502045652862885
-0.0000000000000000000000000000226715578131q, // 8277249048765387314926406643
+0.0000000000000000000000000000036717416991q, // 368554683868436131912480666
-0.0000000000000000000000000000005956151695q, // 8775943870885460187487415
+0.0000000000000000000000000000000967662432q, // 50130423384987872105375089
-0.0000000000000000000000000000000157438595q, // 0010115002774284579478285
+0.0000000000000000000000000000000025650460q, // 002467956741653059479711
-0.0000000000000000000000000000000004184519q, // 8993748074077563959674
+0.0000000000000000000000000000000000683494q, // 09303501707906999012185
-0.0000000000000000000000000000000000111772q // 939575215366434467459690877448
};
_B = {
0.02777777777777777777777777777777777777777778774E0q,
-0.000277777777777777777777777777777777777777777778E0q,
4.72411186696900982615268329554043839758125472E-6q,
-9.18577307466196355085243974132863021751910641E-8q,
1.89788699889709990720091730192740293750394761E-9q,
-4.06476164514422552680590938629196667454705711E-11q,
8.92169102045645255521798731675274885151428361E-13q,
-1.993929586072107568723644347793789705630694749E-14q,
4.51898002961991819165047655285559322839681901E-16q,
-1.035651761218124701448341154221865666596091238E-17q,
2.39521862102618674574028374300098038167894899E-19q,
-5.58178587432500933628307450562541990556705462E-21q,
1.309150755418321285812307399186592301749849833E-22q,
-3.087419802426740293242279764866462431595565203E-24q,
7.31597565270220342035790560925214859103339899E-26q,
-1.740845657234000740989055147759702545340841422E-27q,
4.15763564461389971961789962077522667348825413E-29q,
-9.96214848828462210319400670245583884985485196E-31q,
2.394034424896165300521167987893749562934279156E-32q,
-5.76834735536739008429179316187765424407233225E-34q,
1.393179479647007977827886603911548331732410612E-35q,
-3.372121965485089470468473635254930958979742891E-37q,
8.17820877756210262176477721487283426787618937E-39q,
-1.987010831152385925564820669234786567541858996E-40q,
4.83577851804055089628705937311537820769430091E-42q
};
}
}
template<typename TOutput, typename TMass, typename TScale>
Tools<TOutput,TMass,TScale>::~Tools()
{
_C.clear();
_B.clear();
}
/*!
* Compares the Abs(psq) to the cutoff
* \param msq the input to be tested
* \return true if |psq| < onshell cut-off
*/
template<typename TOutput, typename TMass, typename TScale>
bool Tools<TOutput,TMass,TScale>::iszero(TMass const& psq) const
{
return (Abs(psq) < _qlonshellcutoff) ? true : false;
}
/*!
* Computes the log of a complex number z.
* If the imag(z)=0 and real(z)<0 and extra ipi term is included.
* \param z the complex argument of the logarithm
* \param isig the sign of the imaginary part
* \return the complex log(z)
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::cLn(TOutput const& z, TScale const& isig) const
{
TOutput cln;
if (Imag(z) == _zero && Real(z) <= _zero)
cln = Log(-z) + TOutput{_zero, _pi*Sign(isig)};
else
cln = Log(z);
return cln;
}
/*!
* Computes the log of a real number x.
* If the x<0 and extra ipi term is included.
* \param x the real argument of the logarithm
* \param isig the sign of the imaginary part
* \return the complex log(x)
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::cLn(TScale const& x, TScale const& isig) const
{
TOutput ln;
if (x > 0)
ln = TOutput(Log(x));
else
ln = TOutput(Log(-x)) + TOutput{_zero, _pi*Sign(isig)};
return ln;
}
/*!
* Implementation of the formulae of Denner and Dittmaier \cite Denner:2005nn.
* \f[
* f_{n}(x) = \ln \left( 1 - \frac{1}{x} \right) + \sum_{l=n+1}^{\infty} \frac{x^{n-l}}{l+1}
* \f]
*
* \param n the lower index of
* \param x the argument of the function
* \param iep the epsilon value
* \return function DD from Eq. 4.11 of \cite Denner:2005nn.
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::fndd(int const& n, TOutput const& x, TScale const& iep) const
{
const int infty = 16;
TOutput res = _czero;
if (Abs(x) < _ten)
{
if (!iszero(Abs(x-_cone)))
res = (_cone-Pow(x,n+1))*(cLn(x-_cone, iep) - cLn(x, iep));
for (int j = 0; j <= n; j++)
res -= Pow(x, n-j)/(j+_one);
}
else
{
res = cLn(_cone-_cone/x, iep);
for (int j = n+1; j <= n+infty; j++)
res += Pow(x, n-j)/(j+_one);
}
return res;
}
/*!
* Computes \f${\rm Lnrat}(x,y) = \log(x-i \epsilon)-\log(y-i \epsilon)\f$
* \param x TMass object for the numerator
* \param y TMass object for the denumerator
* \return returns the ratio of logs
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::Lnrat(TOutput const& x, TOutput const& y) const
{
const TOutput r = x/y;
if (iszero(Imag(r)))
return TOutput(Log(Abs(r))) - _ipio2*TOutput(Sign(-Real(x))-Sign(-Real(y)));
else
return Log(r);
}
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::Lnrat(TScale const& x, TScale const& y) const
{
return TOutput(Log(Abs(x/y))) - _ipio2*TOutput(Sign(-x)-Sign(-y));
}
/*!
* The dilog function for real argument
* \param x the argument of the dilog
* \return the dilog
*/
template<typename TOutput, typename TMass, typename TScale>
TMass Tools<TOutput,TMass,TScale>::ddilog(TMass const& x) const
{
if ( x == _one )
return _pi2o6;
else if (x == -_one)
return -_half*_pi2o6;
const TMass T = -x;
TMass Y, S, A;
if (Real(T) <= -_two)
{
Y = -_one / (_one+T);
S = _one;
A = TMass(-_pi2o3 + _half*Real(Pow(Log(-T),2) - Pow(Log(_one+_one/T),2)));
}
else if (Real(T) < -_one)
{
Y = -_one - T;
S = -_one;
A = Log(-T);
A = TMass(-_pi2o6 + A*(A+Log(_one+_one/T)));
}
else if (Real(T) <= -_half)
{
Y = (-_one-T)/T;
S = _one;
A = Log(-T);
A = TMass(-_pi2o6 + A*(-_half*A+Log(_one+T)));
}
else if (Real(T) < _zero)
{
Y = -T/(_one+T);
S = -_one;
A = TMass(_half*Real(Pow(Log(_one+T),2)));
}
else if (Real(T) <= _one)
{
Y = T;
S = _one;
A = TMass(_zero);
}
else
{
Y = _one/T;
S = -_one;
A = TMass(_pi2o6 + _half*Real(Pow(Log(T),2)));
}
const TMass H = Y+Y-_one;
const TMass ALFA = H+H;
TMass B1 = _zero, B2 = _zero, B0 = _zero;
for (int i = _C.size() - 1; i >= 0; i--)
{
B0 = _C[i]+ALFA*B1-B2;
B2 = B1;
B1 = B0;
}
return -(S*(B0-H*B2)+A);
}
/*!
* \param z the argument
* \param isig the sign of z
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::denspence(TOutput const& z, TScale const& isig) const
{
const TOutput z1 = _cone - z;
const TScale az1 = Abs(z1);
if (isig == _zero && Imag(z) == _zero && Abs(Real(z1)) < _qlonshellcutoff)
cout << "denspence: argument on cut" << endl;
if (az1 < _eps15)
return TOutput{_pi2o6, _zero};
else if (Real(z) < _half)
{
if (Abs(z) < _one)
return li2series(z, isig);
else
return -_pi2o6 - _half*Pow(cLn(-z, -isig),2) - li2series(_one/z, -isig);
}
else
{
if (az1 < _one)
return _pi2o6 - cLn(z, isig)*cLn(z1, -isig) - li2series(z1, -isig);
else
return _ctwo*_pi2o6 + _half*Pow(cLn(-z1, -isig),2) - cLn(z, isig)*cLn(z1, -isig) + li2series(_one/z1, isig);
}
}
/*!
* \param zrat1 first argument
* \param zrat2 second argument
* \param ieps1 sign for zrat1
* \param ieps2 sign for zrat2
* \return
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::spencer(TOutput const& zrat1, TOutput const& zrat2, TScale const&ieps1, TScale const&ieps2) const
{
const TScale x1 = Real(zrat1);
const TScale x2 = Real(zrat2);
const TScale y1 = Imag(zrat1);
const TScale y2 = Imag(zrat2);
TOutput res, prod;
if (iszero(y1) && iszero(y2))
res = Li2omx(x1,x2,ieps1,ieps2);
else
{
TOutput arg = zrat1*zrat2;
const TScale ieps = _zero;
if (Abs(arg) <= _one)
{
if (arg == _zero || arg == _one)
prod = _czero;
else
{
const TOutput lnarg = cLn(zrat1, ieps1) + cLn(zrat2, ieps2);
const TOutput lnomarg = Log(_cone-arg);
prod = lnarg*lnomarg;
}
res = TOutput(_pi2o6) - denspence(arg, ieps) - prod;
}
else if (Abs(arg) > _one)
{
arg = _cone/(zrat1*zrat2);
const TOutput lnarg = -cLn(zrat1, ieps1)-cLn(zrat2, ieps2);
const TOutput lnomarg = Log(_cone-arg);
res = -TOutput(_pi2o6)+denspence(arg, ieps)+lnarg*lnomarg-_chalf*Pow(lnarg,2);
}
}
return res;
}
/*!
* \param z2 input arguments
* \param im2 input signs.
* \return the difference of cspence functions
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::xspence(TOutput const (&z1)[2], TScale const (&im1)[2], TOutput const& z2, TScale const& im2) const
{
return cspence(z1[1],im1[1],z2,im2)-cspence(z1[0],im1[0],z2,im2);
}
/*!
* \param z1 input argument
* \param im1 sign of z1
* \param z2 input argument
* \param im2 sign of z2
* \return the complex Spence's function
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::cspence(TOutput const& z1, TScale const& im1, TOutput const& z2, TScale const& im2) const
{
TOutput cspence = _czero;
const TOutput z12 = z1*z2;
const TScale im12 = im2*Sign(Real(z1));
if (Real(z12) > _half)
{
cspence = ltspence(1, z12, _zero);
const int etas = eta(z1, im1, z2, im2, im12);
if (etas != 0) cspence += TOutput(etas)*cLn(_cone-z12, -im12)*_2ipi;
}
else if (Abs(z12) < _eps4)
{
cspence = TOutput(_pi2o6);
if (Abs(z12) > _eps14)
cspence += -ltspence(0, z12, _zero) + (cLn(z1,im1) + cLn(z2,im2))*z12*(_cone + z12*(_chalf + z12*(_cone/_cthree + z12/_cfour)));
}
else
cspence = TOutput(_pi2o6) - ltspence(0, z12, _zero) - (cLn(z1, im1) + cLn(z2, im2))*cLn(_cone-z12,_zero);
return cspence;
}
/*!
* \param x numerator
* \param y denominator
* \return the Li2 ratio
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::Li2omrat(TScale const& x, TScale const& y) const
{
const TScale omarg = x/y;
const TScale arg = _one-omarg;
if (arg > _one)
return TOutput(_pi2o6-ddilog(omarg)) - Log(arg)*Lnrat(x,y);
else
return TOutput(ddilog(arg));
}
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::Li2omrat(TOutput const& x, TOutput const& y,
TScale const& ieps1, TScale const& ieps2) const
{
const TOutput omarg = x/y;
const TOutput arg = _cone-omarg;
const TScale isarg = Sign(Real(x)*ieps2-Real(y)*ieps1);
if (Abs(arg) > _one)
{
const TScale isomarg = -isarg;
return TOutput(_pi2o6) - denspence(omarg, isomarg) - cLn(omarg, isomarg)*cLn(arg, isarg);
}
else
return denspence(arg, isarg);
}
/*!
* expression for dilog(1-(v-i*ep)*(w-i*ep)/(x-i*ep)/(y-i*ep)) for real v,w,x and y
* \param v numerator
* \param w numerator
* \param x denominator
* \param y denominator
* \return the dilog ratio
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::Li2omx2(TScale const& v, TScale const& w, TScale const& x, TScale const& y) const
{
const TScale arg = (v*w)/(x*y);
const TScale omarg = _one-arg;
TOutput prod, Li2omx2;
if (Abs(arg) <= _one)
{
if (Abs(arg) == _zero || Abs(arg) == _one)
prod = _zero;
else
prod = (Lnrat(v,x)+Lnrat(w,y))*TOutput(Log(omarg));
Li2omx2 = TOutput(_pi2o6-ddilog(arg))-prod;
}
else if (Abs(arg) > _one)
{
const TScale arg2 = (x*y)/(v*w);
const TOutput lnarg = TOutput(-Lnrat(v,x)-Lnrat(w,y));
const TOutput lnomarg = TOutput(Log(_one-arg2));
Li2omx2 = -TOutput(_pi2o6-ddilog(arg2))+lnarg*lnomarg-_chalf*lnarg*lnarg;
}
return Li2omx2;
}
/*!
* Calculates Li[2](1-(z1+ieps1)*(z2+ieps2)) for complex z1,z2
* Using +Li2(1-z1*z2) for z1*z2<1
* and -Li2(1-1/(z1*z2))-1/2*(ln(z1)+ln(z2))^2 for z1*z2>1
* \param z1 input argument
* \param z2 input argument
* \param ieps1 sign of z1
* \param ieps2 sign of z2
* \return Li2 of the 1-product
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::Li2omx2(TOutput const& v, TOutput const& w, TOutput const& x, TOutput const& y, TScale const& ieps1, TScale const& ieps2) const
{
return cLi2omx2(v/x, w/y, ieps1, ieps2);
}
/*!
* Calculates Li[2](1-(z1+ieps1)*(z2+ieps2)) for complex z1,z2
* Using +Li2(1-z1*z2) for z1*z2<1
* and -Li2(1-1/(z1*z2))-1/2*(ln(z1)+ln(z2))^2 for z1*z2>1
* \param z1 input argument
* \param z2 input argument
* \param ieps1 sign of z1
* \param ieps2 sign of z2
* \return Li2 of the 1-product
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::cLi2omx2(TOutput const& z1, TOutput const& z2, TScale const& ieps1, TScale const& ieps2) const
{
const TOutput arg = z1*z2;
const TScale ieps = Sign(Real(z2)*ieps1+Real(z1)*ieps2);
TOutput prod, res;
if (Abs(arg) <= _one)
{
if (arg == _czero || arg == _cone)
prod = _czero;
else
prod = (cLn(z1, ieps1)+cLn(z2, ieps2)) * cLn(_cone-arg, -ieps);
res = TOutput(_pi2o6) - denspence(arg, ieps) - prod;
}
else if (Abs(arg) > _one)
{
const TOutput arg2 = _cone/(z1*z2);
const TOutput lnomarg = cLn(_cone-arg2, -ieps);
const TOutput lnarg = -cLn(z1, ieps1) - cLn(z2, ieps2);
res = TOutput(-_pi2o6) + denspence(arg2, ieps) + lnarg*lnomarg - _chalf*lnarg*lnarg;
}
return res;
}
/*!
* Calculate Li[2](1-(x1+ieps1)*(x2+ieps2)) for real x1,x2
* Using +Li2(1-x1*x2) for x1*x2<1
* and -Li2(1-1/(x1*x2))-1/2*(ln(x1)+ln(x2))^2 for x1*x2>1
* \param x1 numerator
* \param x2 denominator
* \param ieps1 sign of x1
* \param ieps2 sign of x2
* \return the ratio Li2
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::Li2omx(TMass const& x1, TMass const& x2, TScale const& ieps1, TScale const& ieps2) const
{
TOutput prod, Li2omx;
TMass arg = x1*x2;
const TScale ieps = Sign(Real(x2)*ieps1+Real(x1)*ieps2);
if (Real(arg) <= _one)
{
if (Real(arg) == _one || Real(arg) == _zero)
prod = _czero;
else
{
const TOutput lnarg = cLn(Real(x1), ieps) + cLn(Real(x2), ieps2);
const TOutput lnomarg = TOutput(Log(_one-arg));
prod = lnarg*lnomarg;
}
Li2omx = TOutput(_pi2o6)-denspence(TOutput(arg), ieps)-prod;
}
else if (Real(arg) > _one)
{
arg = _one/(x1*x2);
const TOutput lnarg = -cLn(Real(x1), ieps1)-cLn(Real(x2), ieps2);
const TOutput lnomarg = TOutput(Log(_one-arg));
Li2omx = -TOutput(_pi2o6)+denspence(TOutput(arg), ieps) + lnarg*lnomarg - _chalf*lnarg*lnarg;
}
return Li2omx;
}
/*!
* Generalization of cLi2omx2 for 3 arguments.
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::cLi2omx3(TOutput const& z1, TOutput const& z2, TOutput const& z3, TScale const& ieps1, TScale const& ieps2, TScale const& ieps3) const
{
const TOutput arg = z1*z2*z3;
TScale ieps;
if (iszero(Imag(arg)))
ieps = Sign(Real(z2*z3)*ieps1+Real(z1*z3)*ieps2+Real(z1*z2)*ieps3);
TOutput res = _czero;
if (Abs(arg) <= _one)
{
TOutput prod;
if (arg == _czero || arg == _cone)
prod = _zero;
else
{
const TOutput lnarg = cLn(z1, ieps1) + cLn(z2, ieps2) + cLn(z3, ieps3);
const TOutput lnomarg = cLn(_cone-arg, _zero);
prod = lnarg*lnomarg;
}
res = TOutput(_pi2o6)-denspence(arg, ieps)-prod;
}
else
{
const TOutput arg2 = _cone/(z1*z2*z3);
const TOutput lnarg = -cLn(z1, ieps1) - cLn(z2,ieps2) - cLn(z3,ieps3);
const TOutput lnomarg = cLn(_cone-arg2, _zero);
res = - TOutput(_pi2o6) + denspence(arg2, ieps) + lnarg*lnomarg - _chalf*lnarg*lnarg;
}
return res;
}
/*!
* \param x input argument
* \param y input argument
* \return
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::L0(TMass const& x, TMass const& y) const
{
TOutput L0;
const TMass denom = _one - x/y;
if (Abs(denom) < _eps7)
L0 = -_cone - TOutput(denom*(_half+denom/_three));
else
L0 = Lnrat(x,y)/TOutput(denom);
return L0;
}
/*!
* \param x input argument
* \param y input argument
* \return
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::L1(TMass const& x, TMass const& y) const
{
TOutput L1;
const TMass denom = _one - x/y;
if (Abs(denom) < _eps7)
L1 = -_cone*_chalf - TOutput(denom/_three*(_one+_three*denom/_four));
else
L1 = (L0(x,y)+_cone)/TOutput(denom);
return L1;
}
/*!
* Finite Triangle Li2 sum.
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::R3int(TOutput const& a, TOutput const& s1, TOutput const& s2, TOutput const& t1, TOutput const& t2, TOutput const& t3, TOutput const& t4) const
{
const TOutput b = (s1+s2)*(s1-s2)-a;
const TOutput c = s2*s2;
const TOutput d = Sqrt((a-(s1+s2)*(s1+s2))*(a-(s1-s2)*(s1-s2)));
TOutput y[2], s[2], res;
solveabcd(a,b,c,d,y);
solveabcd(a,t2,t3,t4,s);
const TOutput y0 = -(t1+b*s[0])/t4;
const TOutput dq0 = (y0-y[0]);
const TOutput dq1 = (y0-y[1]);
const TOutput OneOdq0 = _cone/dq0;
const TOutput OneMy0 = _cone-y[0];
const TScale SignImagOneOdq0 = Sign(Imag(OneOdq0));
const TOutput OneOdq1 = _cone/dq1;
const TOutput OneMy1 = _cone-y[1];
const TScale SignImagOneOdq1 = Sign(Imag(OneOdq1));
res = cspence(-y[0], Sign(Imag(-y[0])), OneOdq0, SignImagOneOdq0)
-cspence(OneMy0, Sign(Imag(OneMy0)), OneOdq0, SignImagOneOdq0)
+cspence(-y[1], Sign(Imag(-y[1])), OneOdq1, SignImagOneOdq1)
-cspence(OneMy1, Sign(Imag(OneMy1)), OneOdq1, SignImagOneOdq1);
TOutput zz = y0*(a*y0+b);
if (Abs(Real(zz))*_reps*_reps <= Abs(Imag(zz))*_neglig && Abs(Imag(zz)) <= Abs(Real(zz))*_neglig)
zz = (TOutput(Real(zz))+c)/a;
else
zz = (zz+c)/a;
// ajust complex logs
TOutput extra = eta3(-y[0],-y[1],c/a) - eta3(dq0,dq1,zz);
if (Real(a) < _zero && Imag(zz) < _zero) extra -= _2ipi;
if (extra != _czero)
{
const TOutput arg4 = (y0-_cone)/y0;
res += extra*cLn(arg4, Sign(Imag(arg4)));
}
return res;
}
/*!
* Finite Triangle Li2 sum.
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::R3int(TOutput const& a, TOutput const& s1, TOutput const& s2, TOutput const& t1) const
{
const TOutput b = (s1+s2)*(s1-s2)-a;
const TOutput c = s2*s2;
const TOutput d = Sqrt((a-(s1+s2)*(s1+s2))*(a-(s1-s2)*(s1-s2)));
TOutput y[2], res;
solveabcd(a,b,c,d,y);
const TOutput y0 = t1;
const TOutput dq0 = (y0-y[0]);
const TOutput dq1 = (y0-y[1]);
const TOutput OneOdq0 = _cone/dq0;
const TOutput OneMy0 = _cone-y[0];
const TScale SignImagOneOdq0 = Sign(Imag(OneOdq0));
const TOutput OneOdq1 = _cone/dq1;
const TOutput OneMy1 = _cone-y[1];
const TScale SignImagOneOdq1 = Sign(Imag(OneOdq1));
res = cspence(-y[0], Sign(Imag(-y[0])), OneOdq0, SignImagOneOdq0)
-cspence(OneMy0, Sign(Imag(OneMy0)), OneOdq0, SignImagOneOdq0)
+cspence(-y[1], Sign(Imag(-y[1])), OneOdq1, SignImagOneOdq1)
-cspence(OneMy1, Sign(Imag(OneMy1)), OneOdq1, SignImagOneOdq1);
TOutput zz = y0*(a*y0+b);
if (Abs(Real(zz))*_reps*_reps <= Abs(Imag(zz))*_neglig && Abs(Imag(zz)) <= Abs(Real(zz))*_neglig)
zz = (TOutput(Real(zz))+c)/a;
else
zz = (zz+c)/a;
// ajust complex logs
TOutput extra = eta3(-y[0],-y[1],c/a) - eta3(dq0,dq1,zz);
if (Real(a) < _zero && Imag(zz) < _zero) extra -= _2ipi;
if (extra != _czero)
{
const TOutput arg4 = (y0-_cone)/y0;
res += extra*cLn(arg4, Sign(Imag(arg4)));
}
return res;
}
/*!
* Finite Triangle Li2 sum.
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::R2int(TOutput const& a, TOutput const& b, TOutput const& y0) const
{
const TOutput y1 = -b/a;
const TOutput dq0 = y0-y1;
const TOutput oneOdq0 = _cone/dq0;
const TScale SignImagOneOdq0 = Sign(Imag(oneOdq0));
const TOutput oneMy1 = _cone-y1;
TOutput res = cspence(-y1, Sign(Imag(-y1)), oneOdq0, SignImagOneOdq0)
-cspence(oneMy1, Sign(Imag(oneMy1)), oneOdq0, SignImagOneOdq0);
TOutput extra = eta5(a,-y1,b,dq0,a*dq0);
if (extra != _czero)
{
const TOutput arg4 = (y0-_cone)/y0;
res += extra*cLn(arg4, Sign(Imag(arg4)));
}
return res;
}
/*!
* \param y
* \param z
* \param ieps
* \return
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::Rint(TOutput const& y, TOutput const& z, TScale const& ieps) const
{
const TOutput omz = _cone-z;
const TOutput ymone = y-_cone;
const TOutput invymz = _cone/(y-z);
const TOutput c[2] = { y*invymz, ymone*invymz };
if (Imag(z) != _zero)
{
const TOutput c2ipi = TOutput{_zero, _two*_pi};
const TOutput a = -z;
const TOutput b = invymz;
const TOutput ab= -z*invymz;
const TOutput eta1 = c2ipi*TOutput( Htheta(-Imag(a))*Htheta(-Imag(b))*Htheta(Imag(ab))
-Htheta(Imag(a))*Htheta(Imag(b))*Htheta(-Imag(ab)) );
const TOutput a2 = omz;
const TOutput ab2= omz*invymz;
const TOutput eta2 = c2ipi*TOutput( Htheta(-Imag(a2))*Htheta(-Imag(b))*Htheta(Imag(ab2))
-Htheta(Imag(a2))*Htheta(Imag(b))*Htheta(-Imag(ab2)) );
TOutput logc1 = _czero, logc2 = _czero;
if (eta1 != _czero) logc1 = TOutput(Log(c[0]));
if (eta2 != _czero) logc2 = TOutput(Log(c[1]));
return denspence(c[0],_zero) - denspence(c[1],_zero) + eta1*logc1 - eta2*logc2;
}
else
{
const TScale ieps1 = -ieps*Sign(Real(y));
const TScale ieps2 = -ieps*Sign(Real(ymone));
return denspence(c[0], ieps1) - denspence(c[1], ieps2);
}
}
/*!
* \brief Tools<TOutput, TMass, TScale>::R
* \param q
* \return
*/
template<typename TOutput, typename TMass, typename TScale>
void Tools<TOutput,TMass,TScale>::R(TOutput &r, TOutput &d, TOutput const& q) const
{
d = Sqrt(q*q-_four);
r = q+d;
TOutput r2 = q-d;
TScale a = Abs(r), b = Abs(r2);
if (b > a) { r = r2; d = -d; }
a = Imag(q);
b = Imag(r);
if (a == _zero)
{
if (b <= _zero)
r /= _ctwo;
else
{
r = _ctwo/r;
d = -d;
}
}
else
{
const TScale ik = Sign(Real(a));
const TScale ir = Sign(Real(b));
if (ir == ik)
r /= _ctwo;
else
{
r = _ctwo/r;
d = -d;
}
}
return;
}
/*!
* \brief Tools<TOutput, TMass, TScale>::qlZlogint
* \param z
* \param ieps
* \return
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::Zlogint(TOutput const& z, TScale const& ieps) const
{
const TOutput omz = _cone-z;
return omz*(cLn(omz, ieps)-_cone)-(-z)*(cLn(-z, ieps)-_cone);
}
/*!
* \param i_in
* \param z_in
* \param s
* \return
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::ltspence(int const& i_in, TOutput const& z_in, TScale const& s) const
{
TOutput z[2];
z[i_in] = z_in;
z[1-i_in] = _cone-z_in;
TOutput ltspence;
if (Real(z[0]) < _half)
{
if (Abs(z[0]) < _one)
ltspence = ltli2series(z[1],s);
else
{
const TOutput clnz = cLn(-z[0], -s);
ltspence = TOutput(-_pi2o6) - _chalf*clnz*clnz - ltli2series(-z[1]/z[0], -s);
}
}
else
{
const TScale az1 = Abs(z[1]);
if (az1 < _eps15)
ltspence = TOutput(_pi2o6);
else if (az1 < _one)
ltspence = TOutput(_pi2o6) - cLn(z[0],s)*cLn(z[1],-s) - ltli2series(z[0],-s);
else
{
const TOutput clnz = cLn(-z[0], -s);
ltspence = TOutput(_two*_pi2o6) + _chalf*clnz*clnz - cLn(z[0],s)*cLn(z[1],-s) + ltli2series(-z[0]/z[1],s);
}
}
return ltspence;
}
/*!
* \param z
* \param isig
* \return
*/
template<typename TOutput, typename TMass, typename TScale>
TOutput Tools<TOutput,TMass,TScale>::li2series(TOutput const& z, TScale const& isig) const
{
TOutput xm = -cLn(_cone-z, -isig);