a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
Expanded.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 HEPfit Collaboration
3  *
4  *
5  * For the licensing terms see doc/COPYING.
6  */
7 
8 #include "Expanded.h"
9 
10 template <class T>
12  minord1 = 0;
13  minord2 = 0;
14  n1 = 0;
15 }
16 
23 
24 template <class T>
25 Expanded<T>::Expanded(std::vector<T> & dinp, int minord2_i)
26 {
27  minord1 = 0;
28  n1 = 1;
29  minord2 = minord2_i;
30  n2.push_back(dinp.size());
31  data.push_back(dinp);
32 }
33 
34 template Expanded<double>::Expanded(std::vector<double> & dinp, int minord2_i);
35 template Expanded<complex>::Expanded(std::vector<complex> & dinp, int minord2_i);
36 template Expanded<vector<double> >::Expanded(std::vector<vector<double> > & dinp, int minord2_i);
37 template Expanded<vector<complex> >::Expanded(std::vector<vector<complex> > & dinp, int minord2_i);
38 template Expanded<matrix<double> >::Expanded(std::vector<matrix<double> > & dinp, int minord2_i);
39 template Expanded<matrix<complex> >::Expanded(std::vector<matrix<complex> > & dinp, int minord2_i);
40 
41 template <class T>
42 Expanded<T>::Expanded(std::vector<std::vector<T> > & dinp, int minord2_i, int minord1_i) {
43  minord1 = minord1_i;
44  minord2 = minord2_i;
45  n1 = dinp.size();
46  for (int i = 0; i < n1; i++)
47  n2.push_back(dinp[i].size());
48  data = dinp;
49  }
50 
51 template Expanded<double>::Expanded(std::vector<std::vector<double> >& dinp, int minord2_i, int minord1_i);
52 template Expanded<complex>::Expanded(std::vector<std::vector<complex> >& dinp, int minord2_i, int minord1_i);
53 template Expanded<vector<double> >::Expanded(std::vector<std::vector<vector<double> > >& dinp, int minord2_i, int minord1_i);
54 template Expanded<vector<complex> >::Expanded(std::vector<std::vector<vector<complex> > >& dinp, int minord2_i, int minord1_i);
55 template Expanded<matrix<double> >::Expanded(std::vector<std::vector<matrix<double> > >& dinp, int minord2_i, int minord1_i);
56 template Expanded<matrix<complex> >::Expanded(std::vector<std::vector<matrix<complex> > >& dinp, int minord2_i, int minord1_i);
57 
59 {
60  std::vector<std::vector<complex> > res;
61  for (int i = 0; i < n1; i++)
62  {
63  res.push_back(std::vector<complex>(n2.at(i)));
64  for (int j = 0; j < n2.at(i); j++)
65  res[i][j] = data[i][j].conjugate();
66  }
67  return Expanded<complex>(res, minord2, minord1);
68 }
69 
70 template <> Expanded<matrix<double> > Expanded<matrix<double> >::transpose() const
71 {
72  std::vector<std::vector<matrix<double> > > res;
73  for (int i1 = 0; i1 < n1; i1++)
74  {
75  res.push_back(std::vector<matrix<double> >(n2.at(i1), matrix<double>(data[0][0].size_i(), data[0][0].size_j(), 0.)));
76  for (int i2 = 0; i2 < n2.at(i1); i2++)
77  res[i1][i2] = data[i1][i2].transpose();
78  }
79  return Expanded<matrix<double>>(res, minord2, minord1);
80 }
81 
82 template <> Expanded<matrix<complex> > Expanded<matrix<complex> >::transpose() const
83 {
84  std::vector<std::vector<matrix<complex> > > res;
85  for (int i1 = 0; i1 < n1; i1++)
86  {
87  res.push_back(std::vector<matrix<complex> >(n2.at(i1), matrix<complex>(data[0][0].size_i(), data[0][0].size_j(), 0.)));
88  for (int i2 = 0; i2 < n2.at(i1); i2++)
89  res[i1][i2] = data[i1][i2].transpose();
90  }
91  return Expanded<matrix < complex >> (res, minord2, minord1);
92 }
93 
95 {
96  std::vector<std::vector<double> > res;
97  for (int i = 0; i < n1; i++)
98  {
99  res.push_back(std::vector<double>(n2.at(i), 0.));
100  for (int j = 0; j < n2.at(i); j++)
101  res[i][j] = data[i][j].real();
102  }
103  return Expanded<double>(res, minord2, minord1);
104 }
105 
107 {
108  return ((*this) * ((*this).conjugate())).real();
109 }
110 
111 template <>
112 matrix<double> Expanded<matrix<double> >::Zero() const
113 {
114  int id, jd;
115  id = data[0][0].size_i();
116  jd = data[0][0].size_j();
117  return matrix<double>(id, jd, 0.);
118 }
119 
120 template <>
121 matrix<complex> Expanded<matrix<complex> >::Zero() const
122 {
123  int id, jd;
124  id = data[0][0].size_i();
125  jd = data[0][0].size_j();
126  return matrix<complex>(id, jd, 0.);
127 }
128 
129 template<>
130 vector<double> Expanded<vector<double> >::Zero() const
131 {
132  int id;
133  id = data[0][0].size();
134  return vector<double>(id, 0.);
135 }
136 
137 template<>
138 vector<complex> Expanded<vector<complex> >::Zero() const
139 {
140  int id;
141  id = data[0][0].size();
142  return vector<complex>(id, 0.);
143 }
144 
145 template<>
146 double Expanded<double>::invCoeff(int i, int j) const {
147  if(i == 0 && j == 0) return (1. / data[0][0]);
148  double res = 0.;
149  for(int n = 0; n <= i; n++)
150  for(int m = 0; m <= j; m++) {
151  if(n == i && m == j) continue;
152  res -= invCoeff(n, m) * data[i - n][j - m];
153  }
154  return (res / data[0][0]);
155 }
156 
157 template<>
158 complex Expanded<complex>::invCoeff(int i, int j) const {
159  if(i == 0 && j == 0) return (1. / data[0][0]);
160  complex res = 0.;
161  for(int n = 0; n <= i; n++)
162  for(int m = 0; m <= j; m++) {
163  if(n == i && m == j) continue;
164  res -= invCoeff(n, m) * data[i - n][j - m];
165  }
166  return (res / data[0][0]);
167 }
168 
169 template <>
171 {
172  std::vector<std::vector<double> > res;
173  for (int i1 = 0; i1 < n1; i1++)
174  {
175  res.push_back(std::vector<double> (n2.at(i1), 0.));
176  for (int i2 = 0; i2 < n2.at(i1); i2++)
177  res[i1][i2] = invCoeff(i1, i2);
178  }
179  return Expanded<double>(res, -minord2, -minord1);
180 }
181 
182 template <>
184 {
185  std::vector<std::vector<complex> > res;
186  for (int i1 = 0; i1 < n1; i1++)
187  {
188  res.push_back(std::vector<complex> (n2.at(i1), 0.));
189  for (int i2 = 0; i2 < n2.at(i1); i2++)
190  res[i1][i2] = invCoeff(i1, i2);
191  }
192  return Expanded<complex>(res, -minord2, -minord1);
193 }
194 
195 /***************** Begin UnExpanded * Expanded *****************/
196 
197 // scalar * X -> commute
198 
199 Expanded<complex> operator*(const complex& ue, const Expanded<double>& ex)
200 {
201  return (ex * ue);
202 }
203 
204 Expanded<vector<complex> > operator*(const complex& ue, const Expanded<vector<double> >& ex)
205 {
206  return (ex * ue);
207 }
208 
209 Expanded<matrix<complex> > operator*(const complex& ue, const Expanded<matrix<double> >& ex)
210 {
211  return (ex * ue);
212 }
213 
214 // X * scalar -> commute
215 
216 Expanded<vector<double> > operator*(const vector<double>& ue, const Expanded<double>& ex)
217 {
218  return (ex * ue);
219 }
220 
221 Expanded<vector<complex> > operator*(const vector<double>& ue, const Expanded<complex>& ex)
222 {
223  return (ex * ue);
224 }
225 
226 Expanded<matrix<double> > operator*(const matrix<double>& ue, const Expanded<double>& ex)
227 {
228  return (ex * ue);
229 }
230 
231 Expanded<matrix<complex> > operator*(const matrix<double>& ue, const Expanded<complex>& ex)
232 {
233  return (ex * ue);
234 }
235 
236 // both vector -> commute
237 
238 Expanded<double> operator*(const vector<double>& ue, const Expanded<vector<double> >& ex)
239 {
240  return (ex * ue);
241 }
242 
243 // vector * matrix
244 
245 Expanded<vector<double> > operator*(const vector<double>& ue, const Expanded<matrix<double> >& ex)
246 {
247  return (ex.transpose() * ue);
248 }
249 
250 // matrix * vector
251 
252 Expanded<vector<double> > operator*(const matrix<double>& ue, const Expanded<vector<double> >& ex)
253 {
254  return (ex * ue.transpose());
255 }
256 
257 // matrix * matrix
258 
259 Expanded<matrix<double> > operator*(const matrix<double>& ue, const Expanded<matrix<double> >& ex)
260 {
261  return ((ex.transpose() * ue.transpose()).transpose());
262 }
263 
264 /***************** End UnExpanded * Expanded *****************/
Expanded::real
Expanded< double > real() const
Method to return the real part of a complex Expanded.
Expanded::conjugate
Expanded< T > conjugate() const
Method to return the conjugate value of a Expanded<complex>.
Expanded::abs2
Expanded< double > abs2() const
Method to return the squared absolute value of a Expanded<complex>.
operator*
Expanded< complex > operator*(const complex &ue, const Expanded< double > &ex)
Definition: Expanded.cpp:199
Expanded.h
Expanded
A template class for Taylor double expansion of several objects.
Definition: Expanded.h:55
Expanded::inverse
Expanded< T > inverse() const
Definition: Expanded.h:322
Expanded::invCoeff
T invCoeff(int i, int j) const
Return the (i-th, j-th) coefficient of the expansion of 1/Expanded.
Definition: Expanded.h:832
Expanded::Expanded
Expanded()
Empty constructor. All data initialized to zero.
Definition: Expanded.cpp:11