Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
bernoulli.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef BERNOULLI_H_INCLUDED
24 #define BERNOULLI_H_INCLUDED
25 
26 #include <csl.h>
27 #include "mrtError.h"
28 
29 namespace mty {
30 
31 inline csl::Expr bernoulliCombinatorial(size_t i, size_t j)
32 {
33  if (j < i - j)
34  return bernoulliCombinatorial(i, i - j);
35  csl::Expr rational = CSL_1;
36  size_t denom_j = i - j;
37  for (size_t num_i = i; num_i > j; --num_i) {
38  rational *= num_i;
39  if (denom_j > 0)
40  rational /= denom_j--;
41  }
42  return rational;
43 }
44 
45 inline csl::Expr bernoulliRecursion(
46  std::vector<csl::Expr> const &B,
47  size_t n
48  )
49 {
50  std::vector<csl::Expr> terms(n);
51  for (size_t i = 0; i != n; ++i)
52  terms[i] = bernoulliCombinatorial(n, i) * B[i] / (n - i + 1);
53  return -csl::sum_s(terms);
54 }
55 
56 // Definition of B- found in
57 // https://en.wikipedia.org/wiki/Bernoulli_number
58 inline csl::Expr bernoulliNumber(size_t i)
59 {
60  static constexpr size_t maxBernouilli = 25;
61  HEPAssert(i <= maxBernouilli,
62  mty::error::ValueError,
63  "Asking Bernouilli number " + toString(i) + ", but cannot go "
64  "beyond " + toString(maxBernouilli))
65  static std::vector<csl::Expr> B = {1};
66  if (i < B.size())
67  return B[i];
68  for (size_t j = B.size(); j <= i; ++j)
69  B.push_back(bernoulliRecursion(B, j));
70 
71  return B.back();
72 }
73 
74 }
75 
76 #endif
Namespace of MARTY.
Definition: 2HDM.h:31