YAP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PhaseSpaceUtilities.h
Go to the documentation of this file.
1 /* YAP - Yet another PWA toolkit
2  Copyright 2015, Technische Universitaet Muenchen,
3  Authors: Daniel Greenwald, Johannes Rauch
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
20 
21 #ifndef yap_PhaseSpaceUtilities_h
22 #define yap_PhaseSpaceUtilities_h
23 
24 #include "Exceptions.h"
25 #include "Matrix.h"
26 
27 #include <vector>
28 
29 namespace yap {
30 
33 std::vector<std::vector<size_t> > combinations(size_t N, size_t n, const std::vector<std::vector<size_t> >& C = std::vector<std::vector<size_t> >())
34 {
35  if (n > N)
36  throw exceptions::Exception("n must be less than N", "combinations");
37 
38  if (n == 0)
39  return C;
40 
41  std::vector<std::vector<size_t> > CC;
42 
43  if (C.empty()) {
44 
45  for (size_t i = 0; i <= N - n; ++i)
46  CC.push_back(std::vector<size_t>(1, i));
47 
48  } else {
49 
50  for (auto& c : C)
51  for (size_t i = c.back() + 1; i <= N - n; ++i) {
52  CC.push_back(c);
53  CC.back().push_back(i);
54  }
55  }
56 
57  return combinations(N, n - 1, CC);
58 }
59 
61 template <typename T, size_t N>
62 T delta(const SquareMatrix<T, N>& M, size_t l)
63 {
64  if (l == 0)
65  throw exceptions::Exception("l must be greater than 0", "delta");
66 
67  if (l > N)
68  throw exceptions::Exception("l must be less than or equal to N", "delta");
69 
70  if (l == 1)
71  return trace(M);
72 
73  if (l == N)
74  return det(M) * pow_negative_one(1 - 1);
75 
76  auto C = combinations(N, l);
77  T d = 0;
78  for (const auto& c : C)
79  d += det(diagonal_minor(M, c));
80  return d * pow_negative_one(l - 1);
81 }
82 
92 template <typename T, size_t N>
93 bool check_deltas(const SquareMatrix<T, N>& M)
94 {
95  // check that first four Delta's are greater than zero
96  for (size_t i = 1; i < M.size() and i <= 4; ++i)
97  if (delta(M, i) < 0)
98  return false;
99  // check that remaining Delta's are zero
100  for (size_t i = 5; i < M.size(); ++i)
101  if (delta(M, i) != 0)
102  return false;
103 }
104 
105 }
106 
107 #endif
108 
const T det(SquareMatrix< T, N > M)
Definition: Matrix.h:300
std::vector< std::vector< size_t > > combinations(size_t N, size_t n, const std::vector< std::vector< size_t > > &C=std::vector< std::vector< size_t > >())
Definition: PhaseSpaceUtilities.h:33
bool check_deltas(const SquareMatrix< T, N > &M)
Definition: PhaseSpaceUtilities.h:93
Base class for handling YAP exceptions.
Definition: Exceptions.h:39
const SquareMatrix< T, M > diagonal_minor(const SquareMatrix< T, N > m, std::vector< size_t > indices)
diagonal minor matrix
Definition: Matrix.h:326
T delta(const SquareMatrix< T, N > &M, size_t l)
Definition: PhaseSpaceUtilities.h:62
const T trace(const SquareMatrix< T, N > &M)
trace
Definition: Matrix.h:340
constexpr int pow_negative_one(int exponent)
optimized function for (-1)^n
Definition: MathUtilities.h:44