softsusy is hosted by Hepforge, IPPP Durham
SOFTSUSY  4.1
numerics.h
Go to the documentation of this file.
1 
12 #ifndef NUMERICS_H
13 #define NUMERICS_H
14 
17 
18 #include "utils.h"
19 #include "mycomplex.h"
20 #include "def.h"
21 #include <iostream>
22 #include <cmath>
23 #include <cfloat>
24 #include <limits>
25 #include "linalg.h"
26 #include "dilogwrap.h"
27 using namespace softsusy;
28 
33 int cubicRoots(double a, double b, double c, double d,
34  DoubleVector & ans);
35 
37 int cubicRootsInside(double a, double b, double c, DoubleVector & ans);
38 
41 double dgauss(double (*f)(double x), double a, double b, double eps);
42 
45 double dgauss(double (*f)(double x, const DoubleVector & v),
46  const DoubleVector & v, double a, double b, double eps);
47 
49 double accurateSqrt1Plusx(double x);
50 
54 void rungeKuttaStep(const DoubleVector & y, const DoubleVector & dydx,
55  double x, double h, DoubleVector & yout, DoubleVector & yerr,
56  DoubleVector (*derivs)(double, const DoubleVector &));
57 
59 int odeStepper(DoubleVector & y, const DoubleVector & dydx, double *x, double
60  htry, double eps, DoubleVector & yscal, double *hdid,
61  double *hnext,
62  DoubleVector (*derivs)(double, const DoubleVector &));
63 
66 double lnLPoisson(unsigned k, double lambda);
67 
70 double LPoisson(unsigned k, double lambda);
71 
73 int integrateOdes(DoubleVector & ystart, double x1, double x2, double eps,
74  double h1, double hmin,
75  DoubleVector (*derivs)(double, const DoubleVector &),
76  int (*rkqs)
77  (DoubleVector & y, const DoubleVector & dydx, double *x,
78  double htry, double eps, DoubleVector & yscal, double
79  *hdid, double *hnext,
80  DoubleVector (*derivs)(double, const DoubleVector &)));
81 
84 double calcDerivative(double (*func)(double),
85  double x, double h, double *err);
86 
89 double calcDerivative(double (*func)(double, void*),
90  double x, double h, double* err, void* params = NULL);
91 
94 double findMinimum(double ax, double bx, double cx, double (*f)(double),
95  double tol, double & xmin);
96 
97 void shft2(double & a, double & b, double & c);
99 void shft3(double & a, double & b, double & c, double & d);
100 
102 double integrandThreshbn(double x);
104 double bIntegral(int n, double p, double m1, double m2, double mt);
105 DoubleVector dd(double x, const DoubleVector & y);
106 
108 double b0(double p, double m1, double m2, double q);
110 double b1(double p, double m1, double m2, double q);
112 double b22(double p, double m1, double m2, double q);
114 double c0(double m1, double m2, double m3);
116 double d27(double m1, double m2, double m3, double m4);
118 double d0(double m1, double m2, double m3, double m4);
120 inline double a0(double m, double q) {
121  if (fabs(m) < EPSTOL) return 0.;
122  return sqr(m) * (1.0 - 2. * log(abs(m / q)));
123 }
125 inline double ffn(double p, double m1, double m2, double q) {
126  return a0(m1, q) - 2.0 * a0(m2, q) -
127  (2.0 * sqr(p) + 2.0 * sqr(m1) - sqr(m2)) *
128  b0(p, m1, m2, q);
129 }
131 inline double gfn(double p, double m1, double m2, double q) {
132  return (sqr(p) - sqr(m1) - sqr(m2)) * b0(p, m1, m2, q) - a0(m1, q)
133  - a0(m2, q);
134 }
136 inline double hfn(double p, double m1, double m2, double q) {
137  return 4.0 * b22(p, m1, m2, q) + gfn(p, m1, m2, q);
138 }
140 inline double b22bar(double p, double m1, double m2, double q) {
141  return b22(p, m1, m2, q) - 0.25 * a0(m1, q) - 0.25 * a0(m2, q);
142 }
143 
144 Complex b0c(double p, double m1, double m2, double q);
146 Complex b1c(double p, double m1, double m2, double q);
148 Complex b22c(double p, double m1, double m2, double q);
151 inline Complex ffnc(double p, double m1, double m2, double q) {
152  return a0(m1, q) - 2.0 * a0(m2, q) -
153  (2.0 * sqr(p) + 2.0 * sqr(m1) - sqr(m2)) *
154  b0c(p, m1, m2, q);
155 }
157 inline Complex gfnc(double p, double m1, double m2, double q) {
158  return (sqr(p) - sqr(m1) - sqr(m2)) * b0c(p, m1, m2, q) - a0(m1, q)
159  - a0(m2, q);
160 }
162 inline Complex hfnc(double p, double m1, double m2, double q) {
163  return 4.0 * b22c(p, m1, m2, q) + gfnc(p, m1, m2, q);
164 }
166 inline Complex b22barc(double p, double m1, double m2, double q) {
167  return b22c(p, m1, m2, q) - 0.25 * a0(m1, q) - 0.25 * a0(m2, q);
168 }
169 
170 /*inline double fB(const Complex & x) {
172  // if (x.real() < EPSTOL * 10. && x.imag() < EPSTOL * 10.) return -1.;
173  return (log(Complex(1.0 - x)) - x * log(Complex(1.0 - 1.0 / x))
174  - Complex(1.0)).real();
175  } */
176 double fB(const Complex & x);
177 
178 Complex fBc(const Complex & x);
179 double dilogarg(double t);
180 double dilog(double x);
181 
182 double integrandThreshbnr(double x);
183 Complex fnfn(double x);
184 
187 double gasdev(long & idum);
190 double truncGaussWidthHalf(long & idum);
193 double ran1(long & idum);
196 double cauchyRan(long & idum);
197 
201 int bin(double data, double start, double end, int numBins);
202 
204 double logOfSum(double a, double b);
205 
207 DoubleVector getRandomDirection(int n, int & numChanged, long & idum);
208 
212 double calcCL(double cl, const DoubleVector & l);
213 
217 double calc1dFraction(double y, const DoubleVector & l);
218 
221 double fps(double z);
222 double fs(double z);
223 double ffbar(double z);
224 
225 Complex dilog(const Complex & x);
226 std::complex<long double> dilogcl(const std::complex<long double>&);
227 
229 double trapzd(double (*func)(double), double a, double b, int n,
230  double tol = 1.0e-3);
232 double qtrap(double (*func)(double), double a, double b, double tol);
234 double midpnt(double (*func)(double), double a, double b, int n);
237 double qromb(double (*func)(double), double a, double b, double EPS);
239 double qromb2(double (*func)(double), double a, double b, double EPS);
240 
243 double sumOfExp(double a, double b);
244 
247 void polint(const DoubleVector& xa, const DoubleVector & ya, double x,
248  double & y, double & dy);
249 
254 DoubleMatrix display3x3RealMixing(double theta12, double theta13,
255  double theta23, double d);
256 
258 void getAngles(const DoubleMatrix & v, double & t12, double & t13,
259  double & t23, double & d);
262 bool midPtStep(DoubleVector & xi,
263  DoubleVector (*derivs)(double t, const DoubleVector & v),
264  double tInitial, double tStep);
268  DoubleVector (*derivs)(double t,
269  const DoubleVector & v),
270  double tInitial, double tFinal, int numSteps);
271 
273 double fin(double mm1, double mm2);
274 double den(double a, int b);
276 double log1minusx(double x);
278 #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
281 double zriddr(double (*func)(double), double x1, double x2, double xacc);
285 void fdjac(int n, DoubleVector x, const DoubleVector & fvec, DoubleMatrix & df,
286  int (*vecfunc)(const DoubleVector &, void*, DoubleVector &),
287  void* params = NULL);
290 bool lnsrch(const DoubleVector & xold, double fold, const DoubleVector & g,
291  DoubleVector & p,
292  DoubleVector & x, double & f, double stpmax,
293  int (*vecfunc)(const DoubleVector &, void*, DoubleVector &),
294  DoubleVector & fvec, void* params = NULL);
295 /* allocate an int vector with subscript range v[nl..nh] */
296 int *ivector(long nl, long nh);
297 /* free an int vector allocated with ivector() */
298 void free_ivector(int *v, long nl, long nh);
299 void lubksb(const DoubleMatrix & a, int n, int *indx, DoubleVector & b);
306 bool newt(DoubleVector & x,
307  int (*vecfunc)(const DoubleVector &, void*, DoubleVector &),
308  void* params = NULL);
310 void load(float x, const DoubleVector & v, DoubleVector & y);
313 void score(float x, const DoubleVector & y, DoubleVector & f);
319 //void shoot(const DoubleVector & v, DoubleVector & f);
326 void qrdcmp(DoubleMatrix & a, int n, DoubleVector & c, DoubleVector & d,
327  int & sing);
328 void qrupdt(DoubleMatrix & r, DoubleMatrix & qt, int n,
329  DoubleVector & u, DoubleVector & v);
333 void rotate(DoubleMatrix & r, DoubleMatrix & qt, int n, int i, float a,
334  float b);
335 void rsolv(const DoubleMatrix & a, int n, const DoubleVector & d,
336  DoubleVector & b);
337 
339  // returns sqrt(f) for f>0
340  double ccbSqrt(double f);
342  // returns sqrt(f) for f>0 or -sqrt(|f|) for f<0
343  double signedSqrt(double f);
345  double signedSqr(double f);
346 
350 double kinFn(double m1, double m2, double m3);
351 double lambda(double a, double b, double c);
352 #endif
353 
drop-in replacement for the original home-grown Complex class
Definition: mycomplex.h:17
Matrix from 1..rows, 1..cols of double values.
Definition: linalg.h:214
DoubleVector is of variable length, and contains double precision.
Definition: linalg.h:35
double m1
decay global variable declarations
Definition: decays.cpp:14
switches (options) and parameters such as default fermion masses, required accuracy etc
Dilog function.
DoubleVector and DoubleMatrix classes of doubles and operations between them, complexified copies als...
complex numbers and operators between them
Complex log(const Complex &a)
Principal log.
Definition: mycomplex.h:67
global variable declaration
Definition: def.cpp:13
const double EPSTOL
underflow accuracy
Definition: def.h:37
double log1minusx(double x)
This function DOESNT WORK YET!!!
Definition: numerics.cpp:230
double accurateSqrt1Plusx(double x)
calculate root(1+x), where x<<1 accurately
Definition: numerics.cpp:209
double qtrap(double(*func)(double), double a, double b, double tol)
Driver for integration.
Definition: numerics.cpp:1488
double gasdev(long &idum)
Definition: numerics.cpp:1111
Complex b1c(double p, double m1, double m2, double q)
Passarino-Veltman function definition: complex answer.
Definition: numerics.cpp:815
Complex gfnc(double p, double m1, double m2, double q)
inlined PV functions: complex answer
Definition: numerics.h:157
void load(float x, const DoubleVector &v, DoubleVector &y)
calculates the n-vector y, given freely specifiable values v(1..n2) at x1
Complex fBc(const Complex &x)
Definition: numerics.cpp:573
double fps(double z)
Definition: numerics.cpp:1439
DoubleVector getRandomDirection(int n, int &numChanged, long &idum)
returns a random direction: total number of dimensions=n
Definition: numerics.cpp:1376
bool midPtStep(DoubleVector &xi, DoubleVector(*derivs)(double t, const DoubleVector &v), double tInitial, double tStep)
Definition: numerics.cpp:1750
double signedSqrt(double f)
returns the square root of the absolute value of the argument
Definition: numerics.cpp:2396
double hfn(double p, double m1, double m2, double q)
inlined PV functions: real part
Definition: numerics.h:136
double fin(double mm1, double mm2)
useful for 2-loop mb/mt corrections
Definition: numerics.cpp:1803
double dgauss(double(*f)(double x), double a, double b, double eps)
Definition: numerics.cpp:83
double fB(const Complex &x)
Definition: numerics.cpp:559
double b22bar(double p, double m1, double m2, double q)
inlined PV functions: real part
Definition: numerics.h:140
double cauchyRan(long &idum)
Definition: numerics.cpp:1163
double logOfSum(double a, double b)
Adds logs of two numbers in a more careful way that avoids underflow.
Definition: numerics.cpp:1175
int cubicRootsInside(double a, double b, double c, DoubleVector &ans)
cubic roots for x^3 + a*x + b*x^2 + c*x^4 = 0
Definition: numerics.cpp:53
double bIntegral(int n, double p, double m1, double m2, double mt)
Returns real part of b function, less accurate than analytic expressions.
Definition: numerics.cpp:550
int cubicRoots(double a, double b, double c, double d, DoubleVector &ans)
Definition: numerics.cpp:20
Complex ffnc(double p, double m1, double m2, double q)
Definition: numerics.h:151
std::complex< long double > dilogcl(const std::complex< long double > &)
Complex dilogarithm .
Definition: numerics.cpp:1287
void lubksb(const DoubleMatrix &a, int n, int *indx, DoubleVector &b)
Get rid of int n.
Definition: numerics.cpp:1963
double findMinimum(double ax, double bx, double cx, double(*f)(double), double tol, double &xmin)
Definition: numerics.cpp:488
double zriddr(double(*func)(double), double x1, double x2, double xacc)
Definition: numerics.cpp:1829
double kinFn(double m1, double m2, double m3)
Definition: numerics.cpp:2410
Complex b22c(double p, double m1, double m2, double q)
Passarino-Veltman function definition: complex answer.
Definition: numerics.cpp:918
double a0(double m, double q)
inlined PV functions: real part
Definition: numerics.h:120
double ffn(double p, double m1, double m2, double q)
inlined PV functions: real part
Definition: numerics.h:125
double lnLPoisson(unsigned k, double lambda)
Definition: numerics.cpp:311
void score(float x, const DoubleVector &y, DoubleVector &f)
DoubleMatrix display3x3RealMixing(double theta12, double theta13, double theta23, double d)
Definition: numerics.cpp:1705
void qrdcmp(DoubleMatrix &a, int n, DoubleVector &c, DoubleVector &d, int &sing)
Definition: numerics.cpp:2299
double ccbSqrt(double f)
returns the square root of the absolute value of the argument
Definition: numerics.cpp:2394
double signedSqr(double f)
returns f * f * sign(f)
Definition: numerics.cpp:2398
double calcCL(double cl, const DoubleVector &l)
Definition: numerics.cpp:1398
void rungeKuttaStep(const DoubleVector &y, const DoubleVector &dydx, double x, double h, DoubleVector &yout, DoubleVector &yerr, DoubleVector(*derivs)(double, const DoubleVector &))
Definition: numerics.cpp:365
void rotate(DoubleMatrix &r, DoubleMatrix &qt, int n, int i, float a, float b)
Definition: numerics.cpp:2351
double d0(double m1, double m2, double m3, double m4)
Passarino-Veltman function definition: real part.
Definition: numerics.cpp:982
int bin(double data, double start, double end, int numBins)
Definition: numerics.cpp:1169
double c0(double m1, double m2, double m3)
Passarino-Veltman function definition: real part.
Definition: numerics.cpp:1029
int odeStepper(DoubleVector &y, const DoubleVector &dydx, double *x, double htry, double eps, DoubleVector &yscal, double *hdid, double *hnext, DoubleVector(*derivs)(double, const DoubleVector &))
organises the variable step-size for Runge-Kutta evolution
Definition: numerics.cpp:327
Complex b22barc(double p, double m1, double m2, double q)
inlined PV functions: complex answer
Definition: numerics.h:166
Complex hfnc(double p, double m1, double m2, double q)
inlined PV functions: complex answer
Definition: numerics.h:162
void polint(const DoubleVector &xa, const DoubleVector &ya, double x, double &y, double &dy)
Definition: numerics.cpp:1672
double ran1(long &idum)
Definition: numerics.cpp:1132
double calcDerivative(double(*func)(double), double x, double h, double *err)
Definition: numerics.cpp:412
int integrateOdes(DoubleVector &ystart, double x1, double x2, double eps, double h1, double hmin, DoubleVector(*derivs)(double, const DoubleVector &), int(*rkqs)(DoubleVector &y, const DoubleVector &dydx, double *x, double htry, double eps, DoubleVector &yscal, double *hdid, double *hnext, DoubleVector(*derivs)(double, const DoubleVector &)))
Organises integration of 1st order system of ODEs.
Definition: numerics.cpp:252
double gfn(double p, double m1, double m2, double q)
inlined PV functions: real part
Definition: numerics.h:131
double qromb(double(*func)(double), double a, double b, double EPS)
Definition: numerics.cpp:1621
double b0(double p, double m1, double m2, double q)
Passarino-Veltman function definition: real part.
Definition: numerics.cpp:592
double b22(double p, double m1, double m2, double q)
Passarino-Veltman function definition: real part.
Definition: numerics.cpp:860
double LPoisson(unsigned k, double lambda)
Definition: numerics.cpp:319
void fdjac(int n, DoubleVector x, const DoubleVector &fvec, DoubleMatrix &df, int(*vecfunc)(const DoubleVector &, void *, DoubleVector &), void *params=NULL)
double truncGaussWidthHalf(long &idum)
Definition: numerics.cpp:1103
void getAngles(const DoubleMatrix &v, double &t12, double &t13, double &t23, double &d)
Given a matrix v, determines which angles gave it.
Definition: numerics.cpp:1737
double b1(double p, double m1, double m2, double q)
Passarino-Veltman function definition: real part.
Definition: numerics.cpp:754
void shft3(double &a, double &b, double &c, double &d)
a=b, b=c and c=d
bool integrateReversibly(DoubleVector &xi, DoubleVector(*derivs)(double t, const DoubleVector &v), double tInitial, double tFinal, int numSteps)
Definition: numerics.cpp:1781
bool newt(DoubleVector &x, int(*vecfunc)(const DoubleVector &, void *, DoubleVector &), void *params=NULL)
More work can be done on this: get rid of int n and in subfunctions too.
Definition: numerics.cpp:2042
double sumOfExp(double a, double b)
Definition: numerics.cpp:1186
void shft2(double &a, double &b, double &c)
double trapzd(double(*func)(double), double a, double b, int n, double tol=1.0e-3)
Trapezoidal function integration to accuracy tol.
Definition: numerics.cpp:1470
double qromb2(double(*func)(double), double a, double b, double EPS)
Identical copy to facilitate double integral.
Definition: numerics.cpp:1645
double integrandThreshbn(double x)
For calculation of PV functions.
bool lnsrch(const DoubleVector &xold, double fold, const DoubleVector &g, DoubleVector &p, DoubleVector &x, double &f, double stpmax, int(*vecfunc)(const DoubleVector &, void *, DoubleVector &), DoubleVector &fvec, void *params=NULL)
Definition: numerics.cpp:1901
double calc1dFraction(double y, const DoubleVector &l)
Definition: numerics.cpp:1428
double d27(double m1, double m2, double m3, double m4)
Passarino-Veltman function definition: real part.
Definition: numerics.cpp:1017
Complex b0c(double p, double m1, double m2, double q)
Definition: numerics.cpp:673
double midpnt(double(*func)(double), double a, double b, int n)
Mid point function integration.
Definition: numerics.cpp:1507
A few handy bits and pieces - little mathematical functions and the like.
double sqr(double a)
square of a number
Definition: utils.h:49