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