flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
wrappers.hpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
19#ifndef WRAPPERS_H
20#define WRAPPERS_H
21
22#include <algorithm>
23#include <cmath>
24#include <complex>
25#include <limits>
26#include <numeric>
27#include <sstream>
28#include <string>
29#include <type_traits>
30#include <utility>
31#include <Eigen/Core>
32
33#include "eigen_tensor.hpp"
34#include "error.hpp"
35#include "logger.hpp"
36#include "if.hpp"
37#include "sum.hpp"
38#include "which.hpp"
39
40namespace flexiblesusy {
41
42// Constants ///////////////////////////////////////////////////////////
43
44static constexpr double Pi = 3.141592653589793;
45static constexpr double oneOver16Pi = 0.019894367886486917; // 1/(16 Pi)
46static constexpr double oneOver16PiSqr = 6.332573977646110963e-03;
47static constexpr double oneLoop = 6.332573977646110963e-03;
48static constexpr double twoLoop = 4.010149318236068752e-05;
49static constexpr double threeLoop = 2.539456721913701978e-07;
50static constexpr double fourLoop = 1.608129755454920543e-09;
51static constexpr double fiveLoop = 1.018360064207223307e-11;
52static constexpr bool True = true;
53static constexpr double zeta2 = 1.6449340668482264; // Zeta[2]
54static constexpr double zeta3 = 1.2020569031595943; // Zeta[3]
55static constexpr double zeta4 = 1.0823232337111382; // Zeta[4]
56static constexpr double zeta5 = 1.0369277551433699; // Zeta[5]
57static constexpr double ln2 = 0.69314718055994531;
58static constexpr double oneOverSqrt2 = 0.70710678118654752; // 1/Sqrt[2]
59
60// Abs /////////////////////////////////////////////////////////////////
61
62inline int Abs(int x) noexcept { return std::abs(x); }
63inline long Abs(long x) noexcept { return std::abs(x); }
64inline long long Abs(long long x) noexcept { return std::abs(x); }
65inline float Abs(float x) noexcept { return std::abs(x); }
66inline double Abs(double x) noexcept { return std::abs(x); }
67inline long double Abs(long double x) noexcept { return std::abs(x); }
68inline float Abs(const std::complex<float>& x) noexcept { return std::abs(x); }
69inline double Abs(const std::complex<double>& x) noexcept { return std::abs(x); }
70inline long double Abs(const std::complex<long double>& x) noexcept { return std::abs(x); }
71
72template <typename Derived>
73auto Abs(const Eigen::ArrayBase<Derived>& x) -> decltype(x.cwiseAbs().eval())
74{
75 return x.cwiseAbs();
76}
77
78template <typename Derived>
79auto Abs(const Eigen::MatrixBase<Derived>& x) -> decltype(x.cwiseAbs().eval())
80{
81 return x.cwiseAbs();
82}
83
84// AbsSqr //////////////////////////////////////////////////////////////
85
86inline int AbsSqr(int x) noexcept { return x*x; }
87inline long AbsSqr(long x) noexcept { return x*x; }
88inline long long AbsSqr(long long x) noexcept { return x*x; }
89inline float AbsSqr(float x) noexcept { return x*x; }
90inline double AbsSqr(double x) noexcept { return x*x; }
91inline long double AbsSqr(long double x) noexcept { return x*x; }
92inline float AbsSqr(const std::complex<float>& x) noexcept { return std::norm(x); }
93inline double AbsSqr(const std::complex<double>& x) noexcept { return std::norm(x); }
94inline long double AbsSqr(const std::complex<long double>& x) noexcept { return std::norm(x); }
95
96template <typename Derived>
97auto AbsSqr(const Eigen::ArrayBase<Derived>& x) -> decltype(x.cwiseAbs().eval().square().eval())
98{
99 return x.eval().cwiseAbs().square();
100}
101
102template <typename Derived>
103auto AbsSqr(const Eigen::MatrixBase<Derived>& x) -> decltype(AbsSqr(x.array()).matrix().eval())
104{
105 return AbsSqr(x.array()).matrix().eval();
106}
107
108// AbsSqrt /////////////////////////////////////////////////////////////
109
110inline double AbsSqrt(double x) noexcept { return std::sqrt(std::abs(x)); }
111
112inline double AbsSqrt(const std::complex<double>& x) noexcept { return std::sqrt(std::abs(x)); }
113
114template <typename Derived>
115auto AbsSqrt(const Eigen::ArrayBase<Derived>& x) -> decltype(x.cwiseAbs().cwiseSqrt())
116{
117 return x.cwiseAbs().cwiseSqrt();
118}
119
120template <typename Derived>
121auto AbsSqrt(const Eigen::MatrixBase<Derived>& x) -> decltype(x.cwiseAbs().cwiseSqrt())
122{
123 return x.cwiseAbs().cwiseSqrt();
124}
125
126// ArcCos //////////////////////////////////////////////////////////////
127
128inline double ArcCos(double x) noexcept { return std::acos(x); }
129inline std::complex<double> ArcCos(const std::complex<double>& x) noexcept { return std::acos(x); }
130
131// ArcSin //////////////////////////////////////////////////////////////
132
133inline double ArcSin(double x) noexcept { return std::asin(x); }
134inline std::complex<double> ArcSin(const std::complex<double>& x) noexcept { return std::asin(x); }
135
136// ArcTan //////////////////////////////////////////////////////////////
137
138inline double ArcTan(double x) noexcept { return std::atan(x); }
139inline std::complex<double> ArcTan(const std::complex<double>& x) noexcept { return std::atan(x); }
140
141// Arg /////////////////////////////////////////////////////////////////
142
143inline double Arg(double x) noexcept { return std::arg(x); }
144inline double Arg(const std::complex<double>& x) noexcept { return std::arg(x); }
145
146// Cbrt ////////////////////////////////////////////////////////////////
147
148inline double Cbrt(double x) noexcept { return std::cbrt(x); }
149
150// Conj ////////////////////////////////////////////////////////////////
151
152inline int Conj(int x) noexcept { return x; }
153inline long Conj(long x) noexcept { return x; }
154inline long long Conj(long long x) noexcept { return x; }
155inline float Conj(float x) noexcept { return x; }
156inline double Conj(double x) noexcept { return x; }
157inline long double Conj(long double x) noexcept { return x; }
158inline std::complex<float> Conj(const std::complex<float>& x) noexcept { return std::conj(x); }
159inline std::complex<double> Conj(const std::complex<double>& x) noexcept { return std::conj(x); }
160inline std::complex<long double> Conj(const std::complex<long double>& x) noexcept { return std::conj(x); }
161
162template <typename Derived>
163auto Conj(const Eigen::ArrayBase<Derived>& x) -> decltype(x.conjugate())
164{
165 return x.conjugate();
166}
167
168template <typename Derived>
169auto Conj(const Eigen::MatrixBase<Derived>& x) -> decltype(x.conjugate())
170{
171 return x.conjugate();
172}
173
174#define Conjugate(x) Conj(x)
175
176// Cube ////////////////////////////////////////////////////////////////
177
178template <typename T>
179constexpr T Cube(T a) noexcept
180{
181 return a * a * a;
182}
183
184// Exp /////////////////////////////////////////////////////////////////
185
186template <typename T>
187T Exp(T z) noexcept
188{
189 return std::exp(z);
190}
191
192// Trigonometric function //////////////////////////////////////////////
193
194double Tan(double a) noexcept;
195double Cot(double a) noexcept;
196double Cos(double x) noexcept;
197double Sin(double x) noexcept;
198double Sec(double x) noexcept;
199double Csc(double x) noexcept;
200
201// Delta ///////////////////////////////////////////////////////////////
202
203int Delta(int i, int j) noexcept;
204
205// Flag a pre-defined problem //////////////////////////////////////////
206
207#define FSFlagProblem(p) [&](){ (p); return 0.; }()
208
209// Flag a pre-defined warning //////////////////////////////////////////
210
211#define FSFlagWarning(p) [&](){ (p); return 0.; }()
212
213// IsClose /////////////////////////////////////////////////////////////
214
215bool IsClose(double, double, double eps = std::numeric_limits<double>::epsilon()) noexcept;
216
217// IsCloseRel //////////////////////////////////////////////////////////
218
219bool IsCloseRel(double, double, double eps = std::numeric_limits<double>::epsilon()) noexcept;
220
221// IsFinite ////////////////////////////////////////////////////////////
222
223bool IsFinite(double) noexcept;
224bool IsFinite(const std::complex<double>&) noexcept;
225
226template <class Derived>
227bool IsFinite(const Eigen::DenseBase<Derived>& m)
228{
229 // workaround for intel compiler / Eigen bug that causes unexpected
230 // behavior from allFinite()
231 const auto nr = m.rows();
232 const auto nc = m.cols();
233
234 for (int r = 0; r < nr; r++) {
235 for (int c = 0; c < nc; c++) {
236 if (!std::isfinite(m(r,c))) {
237 return false;
238 }
239 }
240 }
241
242 return true;
243}
244
245// KroneckerDelta //////////////////////////////////////////////////////
246
247int KroneckerDelta(int, int) noexcept;
248
249// Diag ////////////////////////////////////////////////////////////////
250
251template <class Derived>
252typename Eigen::MatrixBase<Derived>::PlainObject Diag(const Eigen::MatrixBase<Derived>& m)
253{
254 if (m.rows() != m.cols()) {
255 throw SetupError("Diag is only defined for squared matrices");
256 }
257
258 typename Eigen::MatrixBase<Derived>::PlainObject diag(m);
259
260 for (Eigen::Index i = 0; i < m.rows(); ++i) {
261 for (Eigen::Index k = i + 1; k < m.cols(); ++k) {
262 diag(i,k) = 0.0;
263 }
264 }
265
266 for (Eigen::Index i = 0; i < m.rows(); ++i) {
267 for (Eigen::Index k = 0; k < i; ++k) {
268 diag(i,k) = 0.0;
269 }
270 }
271
272 return diag;
273}
274
275// ComplexLog //////////////////////////////////////////////////////////
276
277std::complex<double> ComplexLog(double a) noexcept;
278std::complex<double> ComplexLog(const std::complex<double>& z) noexcept;
279
280// FiniteLog ///////////////////////////////////////////////////////////
281
282double FiniteLog(double a) noexcept;
283
284// Hermitianize ////////////////////////////////////////////////////////
285
292template <typename Derived>
293void Hermitianize(Eigen::PlainObjectBase<Derived>& m)
294{
295 if (m.rows() != m.cols()) {
296 throw SetupError("Hermitianize is only defined for squared matrices");
297 }
298
299 for (Eigen::Index i = 0; i < m.rows(); ++i) {
300 for (Eigen::Index k = 0; k < i; ++k) {
301 m(i,k) = Conj(m(k,i));
302 }
303 }
304}
305
307
308namespace {
309
310template <typename Printer>
311void PrintTo(std::stringstream& ostr, Printer&& printer)
312{
313 printer(ostr.str());
314}
315
316template <typename Printer, typename T0, typename... Ts>
317void PrintTo(std::stringstream& ostr, Printer&& printer, T0&& v, Ts&&... vs)
318{
319 ostr << v;
320 PrintTo(ostr, printer, std::forward<Ts>(vs)...);
321}
322
323} // anonymous namespace
324
326template<typename... Ts>
327double PrintDEBUG(Ts&&... vs)
328{
329 std::stringstream ss;
330 PrintTo(ss, [] (const std::string& s) { DEBUG_MSG(s); }, std::forward<Ts>(vs)...);
331 return 0.;
332}
333
335template<typename... Ts>
336double PrintERROR(Ts&&... vs)
337{
338 std::stringstream ss;
339 PrintTo(ss, [] (const std::string& s) { ERROR(s); }, std::forward<Ts>(vs)...);
340 return 0.;
341}
342
344template<typename... Ts>
345double PrintFATAL(Ts&&... vs)
346{
347 std::stringstream ss;
348 PrintTo(ss, [] (const std::string& s) { FATAL(s); }, std::forward<Ts>(vs)...);
349 return 0.;
350}
351
353template<typename... Ts>
354double PrintINFO(Ts&&... vs)
355{
356 std::stringstream ss;
357 PrintTo(ss, [] (const std::string& s) { INFO(s); }, std::forward<Ts>(vs)...);
358 return 0.;
359}
360
362template<typename... Ts>
363double PrintVERBOSE(Ts&&... vs)
364{
365 std::stringstream ss;
366 PrintTo(ss, [] (const std::string& s) { VERBOSE_MSG(s); }, std::forward<Ts>(vs)...);
367 return 0.;
368}
369
371template<typename... Ts>
372double PrintWARNING(Ts&&... vs)
373{
374 std::stringstream ss;
375 PrintTo(ss, [] (const std::string& s) { WARNING(s); }, std::forward<Ts>(vs)...);
376 return 0.;
377}
378
380
381double Log(double a) noexcept;
382
383// MaxRelDiff //////////////////////////////////////////////////////////
384
385double MaxRelDiff(double, double) noexcept;
386
387double MaxRelDiff(const std::complex<double>&, const std::complex<double>&) noexcept;
388
389template <class Derived>
390auto MaxRelDiff(const Eigen::PlainObjectBase<Derived>& a,
391 const Eigen::PlainObjectBase<Derived>& b)
392 -> decltype(MaxRelDiff(a.data()[0], b.data()[0]))
393{
394 if (a.rows() != b.rows() || a.cols() != b.cols()) {
395 throw SetupError("MaxRelDiff: Matrices/Vectors have different size!");
396 }
397
398 using Scalar_t = decltype(MaxRelDiff(a.data()[0], b.data()[0]));
399
400 Scalar_t max = 0;
401
402 for (Eigen::Index i = 0; i < a.size(); i++) {
403 max = std::max(max, MaxRelDiff(a.data()[i], b.data()[i]));
404 }
405
406 return max;
407}
408
409// MaxAbsValue /////////////////////////////////////////////////////////
410
411double MaxAbsValue(double x) noexcept;
412
413double MaxAbsValue(const std::complex<double>& x) noexcept;
414
415template <class Derived>
416auto MaxAbsValue(const Eigen::MatrixBase<Derived>& x) noexcept -> decltype(x.cwiseAbs().maxCoeff())
417{
418 return x.cwiseAbs().maxCoeff();
419}
420
421template <class Derived>
422auto MaxAbsValue(const Eigen::ArrayBase<Derived>& x) noexcept -> decltype(x.cwiseAbs().maxCoeff())
423{
424 return x.cwiseAbs().maxCoeff();
425}
426
427// Max /////////////////////////////////////////////////////////////////
428
429template<typename T>
430T Max(T&&t) noexcept
431{
432 return std::forward<T>(t);
433}
434
435template<typename T0, typename T1, typename... Ts>
436typename std::common_type<T0, T1, Ts...>::type Max(T0&& val1, T1&& val2, Ts&&... vs) noexcept
437{
438 if (val2 < val1)
439 return Max(val1, std::forward<Ts>(vs)...);
440 else
441 return Max(val2, std::forward<Ts>(vs)...);
442}
443
444template<typename T>
445T Min(T&&t) noexcept
446{
447 return std::forward<T>(t);
448}
449
450template<typename T0, typename T1, typename... Ts>
451typename std::common_type<T0, T1, Ts...>::type Min(T0&& val1, T1&& val2, Ts&&... vs) noexcept
452{
453 if (val2 < val1)
454 return Min(val2, std::forward<Ts>(vs)...);
455 else
456 return Min(val1, std::forward<Ts>(vs)...);
457}
458
459// Sign /////////////////////////////////////////////////////////////////
460
461int Sign(double x) noexcept;
462int Sign(int x) noexcept;
463
464// PolyLog /////////////////////////////////////////////////////////////
465
467double PolyLog(int, double) noexcept;
468
470std::complex<double> PolyLog(int, const std::complex<double>&) noexcept;
471
472// Power functions /////////////////////////////////////////////////////
473
474template <typename Base, typename Exponent>
475Base Power(Base base, Exponent exp) noexcept
476{
477 return std::pow(base, exp);
478}
479
480template <typename Base>
481constexpr Base Power2(Base b) noexcept
482{
483 return b * b;
484}
485
486template <typename Base>
487constexpr Base Power3(Base b) noexcept
488{
489 return b * b * b;
490}
491
492template <typename Base>
493constexpr Base Power4(Base b) noexcept
494{
495 return Power2(Power2(b));
496}
497
498template <typename Base>
499constexpr Base Power5(Base b) noexcept
500{
501 return Power4(b) * b;
502}
503
504template <typename Base>
505constexpr Base Power6(Base b) noexcept
506{
507 return Power2(Power2(b)*b);
508}
509
510template <typename Base>
511constexpr Base Power7(Base b) noexcept
512{
513 return Power6(b) * b;
514}
515
516template <typename Base>
517constexpr Base Power8(Base b) noexcept
518{
519 return Power2(Power4(b));
520}
521
522template <typename Base>
523constexpr Base Power9(Base b) noexcept
524{
525 return Power8(b) * b;
526}
527
528template <typename Base>
529constexpr Base Power10(Base b) noexcept
530{
531 return Power2(Power4(b)*b);
532}
533
534template <typename Base>
535constexpr Base Power11(Base b) noexcept
536{
537 return Power10(b) * b;
538}
539
540template <typename Base>
541constexpr Base Power12(Base b) noexcept
542{
543 return Power2(Power6(b));
544}
545
546template <typename T>
547constexpr T Quad(T a) noexcept
548{
549 return Power2(Power2(a));
550}
551
552// Re //////////////////////////////////////////////////////////////////
553
554double Re(double) noexcept;
555
556double Re(const std::complex<double>&) noexcept;
557
558template<class Derived>
559auto Re(const Eigen::MatrixBase<Derived>& x) noexcept -> decltype(x.real().eval())
560{
561 return x.real().eval();
562}
563
564// Im //////////////////////////////////////////////////////////////////
565
566double Im(double) noexcept;
567
568double Im(const std::complex<double>&) noexcept;
569
570template<class Derived>
571auto Im(const Eigen::MatrixBase<Derived>& x) noexcept -> decltype(x.imag().eval())
572{
573 return x.imag().eval();
574}
575
576// RelDiff /////////////////////////////////////////////////////////////
577
578template <typename T>
579T RelDiff(T a, T b, T eps = std::numeric_limits<T>::epsilon()) noexcept
580{
581 const T max = std::max(a, b);
582
583 if (std::abs(max) < eps)
584 return T();
585
586 return (a - b) / max;
587}
588
589// Round ///////////////////////////////////////////////////////////////
590
591int Round(double a) noexcept;
592
593// SignedAbsSqrt ///////////////////////////////////////////////////////
594
596double SignedAbsSqrt(double a) noexcept;
597
599template <typename Derived>
600auto SignedAbsSqrt(const Eigen::ArrayBase<Derived>& a) noexcept -> typename Derived::PlainObject
601{
602 using Scalar = typename Derived::PlainObject::Scalar;
603 return a.unaryExpr([](Scalar a) -> Scalar { return SignedAbsSqrt(a); });
604}
605
606// Sqrt ////////////////////////////////////////////////////////////////
607
608template <class T, typename = std::enable_if_t<std::is_floating_point<T>::value,T>>
609T Sqrt(T a) noexcept
610{
611 return std::sqrt(a);
612}
613
614template <class T, typename = std::enable_if_t<std::is_integral<T>::value,T>>
615double Sqrt(T a) noexcept
616{
617 return std::sqrt(static_cast<double>(a));
618}
619
621template <typename Derived>
622auto Sqrt(const Eigen::ArrayBase<Derived>& a) noexcept -> typename Derived::PlainObject
623{
624 using Scalar = typename Derived::PlainObject::Scalar;
625 return a.unaryExpr([](Scalar a) -> Scalar { return Sqrt(a); });
626}
627
628// Sqr /////////////////////////////////////////////////////////////////
629
630template <typename T>
631constexpr std::complex<T> Sqr(const std::complex<T>& a) noexcept
632{
633 return a * a;
634}
635
636template <typename T, class = std::enable_if_t<std::is_arithmetic<T>::value,T>>
637constexpr T Sqr(T a) noexcept
638{
639 return a * a;
640}
641
643template <typename Derived>
644auto Sqr(const Eigen::ArrayBase<Derived>& a) noexcept -> typename Derived::PlainObject
645{
646 using Scalar = typename Derived::PlainObject::Scalar;
647 return a.unaryExpr([](Scalar a) -> Scalar { return Sqr(a); });
648}
649
651template <typename Derived>
652auto Sqr(const Eigen::MatrixBase<Derived>& a) noexcept -> typename Derived::PlainObject
653{
654 return a * a;
655}
656
657// arithmetic operators for integer and complex numbers ////////////////
658
659#define DEFINE_COMMUTATIVE_OPERATOR_COMPLEX_INT(op) \
660 template <typename T> \
661 std::complex<T> operator op(const std::complex<T>& lhs, int rhs) \
662 { \
663 return lhs op static_cast<T>(rhs); \
664 } \
665 \
666 template <typename T> \
667 std::complex<T> operator op(int lhs, const std::complex<T>& rhs) \
668 { \
669 return static_cast<T>(lhs) op rhs; \
670 }
671
676
683template <typename Derived>
684void Symmetrize(Eigen::PlainObjectBase<Derived>& m)
685{
686 if (m.rows() != m.cols()) {
687 throw SetupError("Symmetrize is only defined for squared matrices");
688 }
689
690 for (Eigen::Index i = 0; i < m.rows(); ++i) {
691 for (Eigen::Index k = 0; k < i; ++k) {
692 m(i,k) = m(k,i);
693 }
694 }
695}
696
697#define UNITMATRIX(rows) Eigen::Matrix<double,rows,rows>::Identity()
698#define ZEROMATRIX(rows,cols) Eigen::Matrix<double,rows,cols>::Zero()
699#define ZEROTENSOR3(d1,d2,d3) ZeroTensor3<double,d1,d2,d3>()
700#define ZEROTENSOR4(d1,d2,d3,d4) ZeroTensor4<double,d1,d2,d3,d4>()
701#define ZEROVECTOR(rows) Eigen::Matrix<double,rows,1>::Zero()
702#define ZEROARRAY(rows) Eigen::Array<double,rows,1>::Zero()
703#define UNITMATRIXCOMPLEX(rows) Eigen::Matrix<std::complex<double>,rows,rows>::Identity()
704#define ZEROMATRIXCOMPLEX(rows,cols) Eigen::Matrix<std::complex<double>,rows,cols>::Zero()
705#define ZEROVECTORCOMPLEX(rows) Eigen::Matrix<std::complex<double>,rows,1>::Zero()
706#define ZEROTENSOR3COMPLEX(d1,d2,d3) ZeroTensor3<std::complex<double>,d1,d2,d3>()
707#define ZEROTENSOR4COMPLEX(d1,d2,d3,d4) ZeroTensor4<std::complex<double>,d1,d2,d3,d4>()
708#define ZEROARRAYCOMPLEX(rows) Eigen::Array<std::complex<double>,rows,1>::Zero()
709
710// MxN matrix projection operator, which projects on the (X,Y)
711// component
712#define PROJECTOR Proj
713#define DEFINE_PROJECTOR(M,N,X,Y) \
714 Eigen::Matrix<double,M,N> Proj(Eigen::Matrix<double,M,N>::Zero()); \
715 Proj((X)-1,(Y)-1) = 1;
716
717inline double FSThrow(const std::string& s)
718{
719 throw PhysicalError(s);
720 return 0.;
721}
722
723template<class Scalar, int M>
724Eigen::Matrix<Scalar,M,M> ToMatrix(const Eigen::Array<Scalar,M,1>& a) noexcept
725{
726 return Eigen::Matrix<Scalar,M,M>(a.matrix().asDiagonal());
727}
728
729template<class Scalar, int M, int N>
730Eigen::Matrix<Scalar,M,N> ToMatrix(const Eigen::Matrix<Scalar,M,N>& a) noexcept
731{
732 return a;
733}
734
735// ToString ////////////////////////////////////////////////////////////
736
737std::string ToString(char);
738
739std::string ToString(unsigned char);
740std::string ToString(unsigned short);
741std::string ToString(unsigned int);
742std::string ToString(unsigned long);
743std::string ToString(unsigned long long);
744
745std::string ToString(signed char);
746std::string ToString(signed short);
747std::string ToString(signed int);
748std::string ToString(signed long);
749std::string ToString(signed long long);
750
751std::string ToString(double);
752std::string ToString(const std::complex<double>&);
753
754// Total ///////////////////////////////////////////////////////////////
755
757double Total(double) noexcept;
758
760std::complex<double> Total(const std::complex<double>&) noexcept;
761
763template <typename Derived>
764auto Total(const Eigen::DenseBase<Derived>& a) noexcept -> typename Derived::Scalar
765{
766 return a.sum();
767}
768
769// UnitVector //////////////////////////////////////////////////////////
770
772template <int N, int i, typename Scalar = double>
773constexpr auto UnitVector() noexcept -> Eigen::Matrix<Scalar,N,1>
774{
775 return Eigen::Matrix<Scalar,N,1>::Unit(i);
776}
777
779template <int N, typename Scalar = double>
780constexpr auto UnitVector(int i) noexcept -> Eigen::Matrix<Scalar,N,1>
781{
782 return Eigen::Matrix<Scalar,N,1>::Unit(i);
783}
784
786Eigen::VectorXd UnitVector(int N, int i) noexcept;
787
788// MatrixProjector /////////////////////////////////////////////////////
789
791template <int M, int N, int i, int j, typename Scalar = double>
792auto MatrixProjector() noexcept -> Eigen::Matrix<Scalar,M,N>
793{
794 Eigen::Matrix<Scalar,M,N> proj(Eigen::Matrix<Scalar,M,N>::Zero());
795 proj(i,j) = 1;
796
797 return proj;
798}
799
801template <int M, int N, typename Scalar = double>
802auto MatrixProjector(int i, int j) noexcept -> Eigen::Matrix<Scalar,M,N>
803{
804 Eigen::Matrix<Scalar,M,N> proj(Eigen::Matrix<Scalar,M,N>::Zero());
805 proj(i,j) = 1;
806
807 return proj;
808}
809
811Eigen::MatrixXd MatrixProjector(int M, int N, int i, int j) noexcept;
812
813// UnitStep ////////////////////////////////////////////////////////////
814
816template <typename T>
817constexpr int UnitStep(T x) noexcept
818{
819 return x < T() ? 0 : 1;
820}
821
822// ZeroSqrt ////////////////////////////////////////////////////////////
823
825double ZeroSqrt(double x) noexcept;
826
828template <typename Derived>
829Derived ZeroSqrt(const Eigen::ArrayBase<Derived>& m) noexcept
830{
831 return m.unaryExpr([](double a){ return ZeroSqrt(a); });
832}
833
834template<typename T>
835T KallenLambda(T x, T y, T z) noexcept {
836 return Sqr(x-y-z) - 4*y*z;
837}
838
839} // namespace flexiblesusy
840
841#endif
Exception class to be used in the FlexibleSUSY model file.
Definition: error.hpp:226
Spectrum generator was not setup correctly.
Definition: error.hpp:46
#define M(i)
Definition: defs.h:629
#define DEBUG_MSG(msg)
Definition: logger.hpp:59
#define INFO(msg)
Definition: logger.hpp:61
#define ERROR(msg)
Definition: logger.hpp:65
#define WARNING(msg)
Definition: logger.hpp:63
#define FATAL(msg)
Definition: logger.hpp:67
#define VERBOSE_MSG(msg)
Definition: logger.hpp:57
void PrintTo(std::stringstream &ostr, Printer &&printer, T0 &&v, Ts &&... vs)
Definition: wrappers.hpp:317
constexpr T norm(const Complex< T > &z) noexcept
Definition: complex.hpp:66
double Re(double x) noexcept
Definition: wrappers.cpp:163
constexpr Base Power10(Base b) noexcept
Definition: wrappers.hpp:529
constexpr Base Power3(Base b) noexcept
Definition: wrappers.hpp:487
const Real epsilon
Definition: mathdefs.hpp:18
static constexpr bool True
Definition: wrappers.hpp:52
double PrintINFO(Ts &&... vs)
print an information message
Definition: wrappers.hpp:354
double ArcCos(double x) noexcept
Definition: wrappers.hpp:128
T Max(T &&t) noexcept
Definition: wrappers.hpp:430
double Cos(double x) noexcept
Definition: wrappers.cpp:42
constexpr Base Power6(Base b) noexcept
Definition: wrappers.hpp:505
static constexpr double oneOver16Pi
Definition: wrappers.hpp:45
static constexpr double zeta2
Definition: wrappers.hpp:53
static constexpr double ln2
Definition: wrappers.hpp:57
T RelDiff(T a, T b, T eps=std::numeric_limits< T >::epsilon()) noexcept
Definition: wrappers.hpp:579
static constexpr double oneOverSqrt2
Definition: wrappers.hpp:58
double Arg(double x) noexcept
Definition: wrappers.hpp:143
T Sqrt(T a) noexcept
Definition: wrappers.hpp:609
Eigen::Matrix< Scalar, M, M > ToMatrix(const Eigen::Array< Scalar, M, 1 > &a) noexcept
Definition: wrappers.hpp:724
int Sign(double x) noexcept
Definition: wrappers.cpp:188
double ArcSin(double x) noexcept
Definition: wrappers.hpp:133
constexpr T arg(const Complex< T > &z) noexcept
Definition: complex.hpp:42
static constexpr double oneLoop
Definition: wrappers.hpp:47
T Min(T &&t) noexcept
Definition: wrappers.hpp:445
double FSThrow(const std::string &s)
Definition: wrappers.hpp:717
double FiniteLog(double a) noexcept
Definition: wrappers.cpp:107
constexpr Base Power7(Base b) noexcept
Definition: wrappers.hpp:511
double PrintWARNING(Ts &&... vs)
print warning to cerr
Definition: wrappers.hpp:372
double AbsSqrt(double x) noexcept
Definition: wrappers.hpp:110
bool IsCloseRel(double a, double b, double eps) noexcept
Definition: wrappers.cpp:72
double ZeroSqrt(double x) noexcept
sqrt(x) for x >= 0; 0 for x < 0
Definition: wrappers.cpp:251
bool IsClose(double a, double b, double eps) noexcept
Definition: wrappers.cpp:67
double PolyLog(int n, double z) noexcept
real polylogarithm
Definition: wrappers.cpp:145
static constexpr double fiveLoop
Definition: wrappers.hpp:51
constexpr std::complex< T > Sqr(const std::complex< T > &a) noexcept
Definition: wrappers.hpp:631
constexpr int UnitStep(T x) noexcept
step function (0 for x < 0, 1 otherwise)
Definition: wrappers.hpp:817
int Delta(int i, int j) noexcept
Definition: wrappers.cpp:62
double Cbrt(double x) noexcept
Definition: wrappers.hpp:148
double Cot(double a) noexcept
Definition: wrappers.cpp:37
void Hermitianize(Eigen::PlainObjectBase< Derived > &m)
Definition: wrappers.hpp:293
double Sin(double x) noexcept
Definition: wrappers.cpp:47
double PrintDEBUG(Ts &&... vs)
print debug information to cerr
Definition: wrappers.hpp:327
Eigen::MatrixBase< Derived >::PlainObject Diag(const Eigen::MatrixBase< Derived > &m)
Definition: wrappers.hpp:252
static constexpr double zeta4
Definition: wrappers.hpp:55
double Log(double a) noexcept
Definition: wrappers.cpp:92
std::complex< double > ComplexLog(double a) noexcept
Definition: wrappers.cpp:97
constexpr Base Power9(Base b) noexcept
Definition: wrappers.hpp:523
double MaxRelDiff(double a, double b) noexcept
Definition: wrappers.cpp:123
double SignedAbsSqrt(double a) noexcept
signed square root of absolute
Definition: wrappers.cpp:198
double Total(double a) noexcept
sum of all arguments
Definition: wrappers.cpp:223
T KallenLambda(T x, T y, T z) noexcept
Definition: wrappers.hpp:835
double Im(double) noexcept
Definition: wrappers.cpp:178
void Symmetrize(Eigen::PlainObjectBase< Derived > &m)
Definition: wrappers.hpp:684
int Conj(int x) noexcept
Definition: wrappers.hpp:152
double ArcTan(double x) noexcept
Definition: wrappers.hpp:138
int AbsSqr(int x) noexcept
Definition: wrappers.hpp:86
int KroneckerDelta(int i, int j) noexcept
Definition: wrappers.cpp:87
double Csc(double x) noexcept
Definition: wrappers.cpp:57
constexpr Base Power12(Base b) noexcept
Definition: wrappers.hpp:541
static constexpr double threeLoop
Definition: wrappers.hpp:49
constexpr T Quad(T a) noexcept
Definition: wrappers.hpp:547
Base Power(Base base, Exponent exp) noexcept
Definition: wrappers.hpp:475
static constexpr double fourLoop
Definition: wrappers.hpp:50
static constexpr double zeta5
Definition: wrappers.hpp:56
constexpr Base Power5(Base b) noexcept
Definition: wrappers.hpp:499
double Sec(double x) noexcept
Definition: wrappers.cpp:52
int Round(double a) noexcept
Definition: wrappers.cpp:173
std::string ToString(char a)
Definition: wrappers.cpp:209
constexpr Base Power11(Base b) noexcept
Definition: wrappers.hpp:535
constexpr Base Power4(Base b) noexcept
Definition: wrappers.hpp:493
T Exp(T z) noexcept
Definition: wrappers.hpp:187
double PrintFATAL(Ts &&... vs)
print error to cerr and stop program
Definition: wrappers.hpp:345
Eigen::MatrixXd MatrixProjector(int M, int N, int i, int j) noexcept
unit matrix projector of size MxN into direction i, j
Definition: wrappers.cpp:243
constexpr Base Power8(Base b) noexcept
Definition: wrappers.hpp:517
static constexpr double twoLoop
Definition: wrappers.hpp:48
bool IsFinite(double x) noexcept
Definition: wrappers.cpp:77
static constexpr double Pi
Definition: wrappers.hpp:44
double Tan(double a) noexcept
Definition: wrappers.cpp:32
double PrintERROR(Ts &&... vs)
print error to cerr
Definition: wrappers.hpp:336
Eigen::VectorXd UnitVector(int N, int i) noexcept
unit vector of length N into direction i
Definition: wrappers.cpp:234
int Abs(int x) noexcept
Definition: wrappers.hpp:62
constexpr Base Power2(Base b) noexcept
Definition: wrappers.hpp:481
constexpr T Cube(T a) noexcept
Definition: wrappers.hpp:179
static constexpr double oneOver16PiSqr
Definition: wrappers.hpp:46
static constexpr double zeta3
Definition: wrappers.hpp:54
double PrintVERBOSE(Ts &&... vs)
print verbose information to cerr
Definition: wrappers.hpp:363
double MaxAbsValue(double x) noexcept
Definition: wrappers.cpp:113
constexpr Complex< T > conj(const Complex< T > &z) noexcept
Definition: complex.hpp:48
#define DEFINE_COMMUTATIVE_OPERATOR_COMPLEX_INT(op)
Definition: wrappers.hpp:659