QNLP  v1.0
mat_ops.hpp
Go to the documentation of this file.
1 
10 #ifndef QNLP_MAT_OPS
11 #define QNLP_MAT_OPS
12 
13 #include <complex>
14 #include <vector>
15 #include <iostream>
16 
17 namespace QNLP{
25  template <class Mat2x2Type>
26  const Mat2x2Type matrixSqrt(const Mat2x2Type& U){
27  Mat2x2Type V(U);
28  std::complex<double> delta = U(0,0)*U(1,1) - U(0,1)*U(1,0);
29  std::complex<double> tau = U(0,0) + U(1,1);
30  std::complex<double> s = sqrt(delta);
31  std::complex<double> t = sqrt(tau + 2.0*s);
32 
33  //must be a way to vectorise these; TinyMatrix have a scale/shift option?
34  V(0,0) += s;
35  V(1,1) += s;
36  std::complex<double> scale_factor(1.,0.);
37  scale_factor /= t;
38  V(0,0) *= scale_factor; //(std::complex<double>(1.,0.)/t);
39  V(0,1) *= scale_factor; //(1/t);
40  V(1,0) *= scale_factor; //(1/t);
41  V(1,1) *= scale_factor; //(1/t);
42 
43  return V;
44  }
45 
53  template <class Mat2x2Type>
54  Mat2x2Type adjointMatrix(const Mat2x2Type& U){
55  Mat2x2Type Uadjoint(U);
56  std::complex<double> tmp;
57  tmp = Uadjoint(0,1);
58  Uadjoint(0,1) = Uadjoint(1,0);
59  Uadjoint(1,0) = tmp;
60  Uadjoint(0,0) = std::conj(Uadjoint(0,0));
61  Uadjoint(0,1) = std::conj(Uadjoint(0,1));
62  Uadjoint(1,0) = std::conj(Uadjoint(1,0));
63  Uadjoint(1,1) = std::conj(Uadjoint(1,1));
64  return Uadjoint;
65  }
66 }
67 #endif
const Mat2x2Type matrixSqrt(const Mat2x2Type &U)
Calculates the unitary matrix square root (U == VV, where V is returned)
Definition: mat_ops.hpp:26
Mat2x2Type adjointMatrix(const Mat2x2Type &U)
Function to calculate the adjoint of an input matrix.
Definition: mat_ops.hpp:54