17 #include <boost/numeric/ublas/matrix_sparse.hpp>
18 #include <boost/numeric/ublas/matrix.hpp>
19 #include <boost/numeric/ublas/vector.hpp>
26 template<
typename Value_type,
typename Size_type>
35 typedef boost::numeric::ublas::compressed_matrix<value_type,boost::numeric::ublas::row_major>
sparse_matrix_type;
37 typedef boost::numeric::ublas::matrix<value_type>
matrix_type;
39 typedef boost::numeric::ublas::vector<value_type>
vector_type;
103 template<
typename Value_type,
typename Size_type>
106 template<
typename Value_type,
typename Size_type>
110 case 0: rdm(0,1) = rdm(2,3) = 1; rdm(1,0) = rdm(3,2) = -1;
break;
111 case 1: rdm(0,1) = rdm(1,0) = -1; rdm(2,3) = rdm(3,2) = 1;
break;
112 case 2: rdm(0,3) = rdm(1,2) = rdm(2,1) = rdm(3,0) = 1;
break;
113 case 3: rdm(0,0) = rdm(2,2) = -1; rdm(1,1) = rdm(3,3) = 1;
break;
114 case 4: rdm(0,0) = rdm(3,3) = -1; rdm(1,1) = rdm(2,2) = 1;
break;
115 case 5: rdm(0,2) = rdm(2,0) = 1; rdm(1,3) = rdm(3,1) = -1;
break;
116 case 6: rdm(0,1) = rdm(1,0) = rdm(2,3) = rdm(3,2) = 1;
break;
117 case 7: rdm(0,3) = rdm(2,1) = 1; rdm(1,2) = rdm(3,0) = -1;
break;
118 case 8: rdm(0,1) = rdm(3,2) = 1; rdm(1,0) = rdm(2,3) = -1;
break;
119 case 9: rdm(0,2) = rdm(1,3) = -1; rdm(2,0) = rdm(3,1) = 1;
break;
120 case 10: rdm(0,2) = rdm(3,1) = 1; rdm(1,3) = rdm(2,0) = -1;
break;
121 case 11: rdm(0,2) = rdm(1,3) = rdm(2,0) = rdm(3,1) = -1;
break;
122 case 12: rdm(0,0) = rdm(1,1) = -1; rdm(2,2) = rdm(3,3) = 1;
break;
123 case 13: rdm(0,3) = rdm(3,0) = -1; rdm(1,2) = rdm(2,1) = 1;
break;
124 case 14: rdm(0,3) = rdm(1,2) = -1; rdm(2,1) = rdm(3,0) = 1;
break;
125 case 15: rdm(0,0) = rdm(1,1) = rdm(2,2) = rdm(3,3) = 1;
break;
126 default:
throw std::out_of_range(
"Error in RDM::generate: 0 <= i <= 15");
break;
131 template<
typename Value_type,
typename Size_type>
137 if (M.size1() != 4 && M.size1() != M.size2())
138 throw std::length_error(
"Error in RDM::decompose: Wrong matrix dimensions.");
147 for (
short i = 0; i < 16; ++i) {
160 template<
typename Value_type,
typename Size_type>
162 if (coeffs.size() > 16)
163 throw std::length_error(
"Error in RDM::combine: Wrong size of coefficient vector.");
166 matrix_type M = boost::numeric::ublas::zero_matrix<value_type>(4,4);
169 for (
short i = 0; i < 16; ++i)
170 M += coeffs(i)*getRDM(i);
175 template<
typename Value_type,
typename Size_type>
179 R = boost::numeric::ublas::identity_matrix<value_type>(4);
186 auto mult = [&](
short i) {
196 P(0) = mult(1); P(1) = mult(2); P(2) = mult(3);
197 E(0) = mult(4); E(1) = mult(5); E(2) = mult(6);
198 B(0) = -mult(7); B(1) = -mult(8); B(2) = -mult(9);
199 mr = boost::numeric::ublas::inner_prod(E,B);
200 mg = boost::numeric::ublas::inner_prod(B,P);
202 transform(Ms,
short(0),0.5 *
std::atan2(mg,mr),R,invR);
206 P(0) = mult(1); P(1) = mult(2); P(2) = mult(3);
207 E(0) = mult(4); E(1) = mult(5); E(2) = mult(6);
208 B(0) = -mult(7); B(1) = -mult(8); B(2) = -mult(9);
211 transform(Ms,
short(7),0.5 *
std::atan2(b(2),b(1)),R,invR);
215 P(0) = mult(1); P(1) = mult(2); P(2) = mult(3);
216 E(0) = mult(4); E(1) = mult(5); E(2) = mult(6);
217 B(0) = -mult(7); B(1) = -mult(8); B(2) = -mult(9);
220 transform(Ms,
short(9),-0.5 *
std::atan2(b(0),b(1)),R,invR);
224 P(0) = mult(1); P(1) = mult(2); P(2) = mult(3);
225 E(0) = mult(4); E(1) = mult(5); E(2) = mult(6);
226 B(0) = -mult(7); B(1) = -mult(8); B(2) = -mult(9);
227 mr = boost::numeric::ublas::inner_prod(E,B);
233 transform(Ms,
short(2),0.5 * std::atanh(mr / b(1)),R,invR);
235 transform(Ms,
short(2),0.5 * std::atanh(b(1) / mr),R,invR);
239 P(0) = mult(1); P(1) = mult(2); P(2) = mult(3);
240 E(0) = mult(4); E(1) = mult(5); E(2) = mult(6);
241 B(0) = -mult(7); B(1) = -mult(8); B(2) = -mult(9);
244 mr = boost::numeric::ublas::inner_prod(E,B);
245 mg = boost::numeric::ublas::inner_prod(B,P);
246 mb = boost::numeric::ublas::inner_prod(E,P);
248 value_type P2 = boost::numeric::ublas::inner_prod(P,P);
249 value_type E2 = boost::numeric::ublas::inner_prod(E,E);
252 transform(Ms,
short(0),0.25 *
std::atan2(mb,0.5 * (E2 - P2)),R,invR);
255 P(0) = mult(1); P(2) = mult(3);
257 transform(Ms,
short(8),-0.5 *
std::atan2(P(2),P(0)),R,invR);
260 template<
typename Value_type,
typename Size_type>
266 return 0.5 * (M + matt_boost::gemmm<matrix_type>(rdm0,boost::numeric::ublas::trans(M),rdm0));
270 template<
typename Value_type,
typename Size_type>
276 return 0.5 * (M - matt_boost::gemmm<matrix_type>(rdm0,boost::numeric::ublas::trans(M),rdm0));
283 template<
typename Value_type,
typename Size_type>
290 if (i < 7 && i != 0 && i < 11 && i != 14) {
298 M = matt_boost::gemmm<matrix_type>(
R,M,invR);
Size_type size_type
Type for specifying sizes.
void transform(matrix_type &, short, value_type, sparse_matrix_type &, sparse_matrix_type &)
Applies a rotation to the matrix M by a given angle.
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
Tps< T > sin(const Tps< T > &x)
Sine.
short DimOfRDMs
The matrix dimension (4x4)
matrix_type symplex(const matrix_type &)
Returns the symplex part of a 4x4 real-valued matrix.
Tps< T > cosh(const Tps< T > &x)
Hyperbolic cosine.
matrix_type combine(const vector_type &)
Takes a vector of coefficients, evaluates the linear combination of RDMs with these coefficients and ...
boost::numeric::ublas::vector< value_type > vector_type
Dense vector type definition.
void diagonalize(matrix_type &, sparse_matrix_type &, sparse_matrix_type &)
Brings a 4x4 symplex matrix into Hamilton form and computes the transformation matrix and its inverse...
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
boost::numeric::ublas::matrix< value_type > matrix_type
Dense matrix type definition.
boost::numeric::ublas::compressed_matrix< value_type, boost::numeric::ublas::row_major > sparse_matrix_type
Sparse matrix type definition.
BOOST_UBLAS_INLINE V trace(ublas::matrix< V > &e)
Computes the trace of a square matrix.
Tps< T > cos(const Tps< T > &x)
Cosine.
T::PETE_Expr_t::PETE_Return_t prod(const PETE_Expr< T > &expr)
vector_type decompose(const matrix_type &)
Decomposes a real-valued 4x4 matrix into a linear combination and returns a vector containing the coe...
Value_type value_type
Type of variables.
short NumOfRDMs
The number of real Dirac matrices.
sparse_matrix_type getRDM(short)
Returns the i-th Real Dirac matrix.
BOOST_UBLAS_INLINE ublas::vector< V > cross_prod(ublas::vector< V > &v1, ublas::vector< V > &v2)
Computes the cross product of two vectors in .
Tps< T > sinh(const Tps< T > &x)
Hyperbolic sine.
matrix_type cosymplex(const matrix_type &)
Returns the cosymplex part of a 4x4 real-valued matrix.
RDM()
Default constructor (sets only NumOfRDMs and DimOfRDMs)