Quantum++  v0.8.8.2
C++11 quantum computing library
qpp Namespace Reference

Quantum++ main namespace. More...

Namespaces

 experimental
 Experimental/test functions/classes, do not use or modify.
 
 internal
 Internal utility functions, do not use/modify.
 

Classes

class  Codes
 const Singleton class that defines quantum error correcting codes More...
 
class  Exception
 Generates custom exceptions, used when validating function parameters. More...
 
class  Gates
 const Singleton class that implements most commonly used gates More...
 
class  IDisplay
 Abstract class (interface) that mandates the definition of virtual std::ostream& display(std::ostream& os) const. More...
 
class  Init
 const Singleton class that performs additional initializations/cleanups More...
 
struct  is_complex
 Checks whether the type is a complex type. More...
 
struct  is_complex< std::complex< T > >
 Checks whether the type is a complex number type, specialization for complex types. More...
 
struct  is_iterable
 Checks whether T is compatible with an STL-like iterable container. More...
 
struct  is_iterable< T, to_void< decltype(std::declval< T >().begin()), decltype(std::declval< T >().end()), typename T::value_type > >
 Checks whether T is compatible with an STL-like iterable container, specialization for STL-like iterable containers. More...
 
struct  is_matrix_expression
 Checks whether the type is an Eigen matrix expression. More...
 
struct  is_matrix_expression< typename Eigen::MatrixBase< Derived > >
 Checks whether the type is an Eigen matrix expression, specialization for Eigen matrix expressions. More...
 
class  RandomDevices
 Singeleton class that manages the source of randomness in the library. More...
 
class  States
 const Singleton class that implements most commonly used states More...
 
class  Timer
 Chronometer. More...
 

Typedefs

template<typename... >
using to_void = void
 Alias template that implements the proposal for void_t. More...
 
using idx = std::size_t
 Non-negative integer index. More...
 
using bigint = long long int
 Big integer. More...
 
using ubigint = unsigned long long int
 Non-negative big integer. More...
 
using cplx = std::complex< double >
 Complex number in double precision. More...
 
using ket = Eigen::VectorXcd
 Complex (double precision) dynamic Eigen column vector. More...
 
using bra = Eigen::RowVectorXcd
 Complex (double precision) dynamic Eigen row vector. More...
 
using cmat = Eigen::MatrixXcd
 Complex (double precision) dynamic Eigen matrix. More...
 
using dmat = Eigen::MatrixXd
 Real (double precision) dynamic Eigen matrix. More...
 
template<typename Scalar >
using dyn_mat = Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic >
 Dynamic Eigen matrix over the field specified by Scalar. More...
 
template<typename Scalar >
using dyn_col_vect = Eigen::Matrix< Scalar, Eigen::Dynamic, 1 >
 Dynamic Eigen column vector over the field specified by Scalar. More...
 
template<typename Scalar >
using dyn_row_vect = Eigen::Matrix< Scalar, 1, Eigen::Dynamic >
 Dynamic Eigen row vector over the field specified by Scalar. More...
 

Functions

constexpr cplx operator""_i (unsigned long long int x) noexcept
 User-defined literal for complex $i=\sqrt{-1}$ (integer overload) More...
 
constexpr cplx operator""_i (long double x) noexcept
 User-defined literal for complex $i=\sqrt{-1}$ (real overload) More...
 
cplx omega (idx D)
 D-th root of unity. More...
 
template<typename Derived >
dyn_col_vect< double > schmidtcoeffs (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &dims)
 Schmidt coefficients of the bi-partite pure state A. More...
 
template<typename Derived >
cmat schmidtA (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &dims)
 Schmidt basis on Alice side. More...
 
template<typename Derived >
cmat schmidtB (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &dims)
 Schmidt basis on Bob side. More...
 
template<typename Derived >
std::vector< double > schmidtprobs (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &dims)
 Schmidt probabilities of the bi-partite pure state A. More...
 
template<typename Derived >
double entanglement (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &dims)
 Entanglement of the bi-partite pure state A. More...
 
template<typename Derived >
double gconcurrence (const Eigen::MatrixBase< Derived > &A)
 G-concurrence of the bi-partite pure state A. More...
 
template<typename Derived >
double negativity (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &dims)
 Negativity of the bi-partite mixed state A. More...
 
template<typename Derived >
double lognegativity (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &dims)
 Logarithmic negativity of the bi-partite mixed state A. More...
 
template<typename Derived >
double concurrence (const Eigen::MatrixBase< Derived > &A)
 Wootters concurrence of the bi-partite qubit mixed state A. More...
 
template<typename Derived >
double entropy (const Eigen::MatrixBase< Derived > &A)
 von-Neumann entropy of the density matrix A More...
 
double entropy (const std::vector< double > &prob)
 Shannon entropy of the probability distribution prob. More...
 
template<typename Derived >
double renyi (const Eigen::MatrixBase< Derived > &A, double alpha)
 Renyi- $\alpha$ entropy of the density matrix A, for $\alpha\geq 0$. More...
 
double renyi (const std::vector< double > &prob, double alpha)
 Renyi- $\alpha$ entropy of the probability distribution prob, for $\alpha\geq 0$. More...
 
template<typename Derived >
double tsallis (const Eigen::MatrixBase< Derived > &A, double q)
 Tsallis- $q$ entropy of the density matrix A, for $q\geq 0$. More...
 
double tsallis (const std::vector< double > &prob, double q)
 Tsallis- $q$ entropy of the probability distribution prob, for $q\geq 0$. More...
 
template<typename Derived >
double qmutualinfo (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &subsysA, const std::vector< idx > &subsysB, const std::vector< idx > &dims)
 Quantum mutual information between 2 subsystems of a composite system. More...
 
template<typename Derived >
double qmutualinfo (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &subsysA, const std::vector< idx > &subsysB, idx d=2)
 Quantum mutual information between 2 subsystems of a composite system. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > transpose (const Eigen::MatrixBase< Derived > &A)
 Transpose. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > conjugate (const Eigen::MatrixBase< Derived > &A)
 Complex conjugate. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > adjoint (const Eigen::MatrixBase< Derived > &A)
 Adjoint. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > inverse (const Eigen::MatrixBase< Derived > &A)
 Inverse. More...
 
template<typename Derived >
Derived::Scalar trace (const Eigen::MatrixBase< Derived > &A)
 Trace. More...
 
template<typename Derived >
Derived::Scalar det (const Eigen::MatrixBase< Derived > &A)
 Determinant. More...
 
template<typename Derived >
Derived::Scalar logdet (const Eigen::MatrixBase< Derived > &A)
 Logarithm of the determinant. More...
 
template<typename Derived >
Derived::Scalar sum (const Eigen::MatrixBase< Derived > &A)
 Element-wise sum of A. More...
 
template<typename Derived >
Derived::Scalar prod (const Eigen::MatrixBase< Derived > &A)
 Element-wise product of A. More...
 
template<typename Derived >
double norm (const Eigen::MatrixBase< Derived > &A)
 Frobenius norm. More...
 
template<typename Derived >
std::pair< dyn_col_vect< cplx >, cmateig (const Eigen::MatrixBase< Derived > &A)
 Full eigen decomposition. More...
 
template<typename Derived >
dyn_col_vect< cplxevals (const Eigen::MatrixBase< Derived > &A)
 Eigenvalues. More...
 
template<typename Derived >
cmat evects (const Eigen::MatrixBase< Derived > &A)
 Eigenvectors. More...
 
template<typename Derived >
std::pair< dyn_col_vect< double >, cmatheig (const Eigen::MatrixBase< Derived > &A)
 Full eigen decomposition of Hermitian expression. More...
 
template<typename Derived >
dyn_col_vect< double > hevals (const Eigen::MatrixBase< Derived > &A)
 Hermitian eigenvalues. More...
 
template<typename Derived >
cmat hevects (const Eigen::MatrixBase< Derived > &A)
 Hermitian eigenvectors. More...
 
template<typename Derived >
std::tuple< cmat, dyn_col_vect< double >, cmatsvd (const Eigen::MatrixBase< Derived > &A)
 Full singular value decomposition. More...
 
template<typename Derived >
dyn_col_vect< double > svals (const Eigen::MatrixBase< Derived > &A)
 Singular values. More...
 
template<typename Derived >
cmat svdU (const Eigen::MatrixBase< Derived > &A)
 Left singular vectors. More...
 
template<typename Derived >
cmat svdV (const Eigen::MatrixBase< Derived > &A)
 Right singular vectors. More...
 
template<typename Derived >
cmat funm (const Eigen::MatrixBase< Derived > &A, cplx(*f)(const cplx &))
 Functional calculus f(A) More...
 
template<typename Derived >
cmat sqrtm (const Eigen::MatrixBase< Derived > &A)
 Matrix square root. More...
 
template<typename Derived >
cmat absm (const Eigen::MatrixBase< Derived > &A)
 Matrix absolut value. More...
 
template<typename Derived >
cmat expm (const Eigen::MatrixBase< Derived > &A)
 Matrix exponential. More...
 
template<typename Derived >
cmat logm (const Eigen::MatrixBase< Derived > &A)
 Matrix logarithm. More...
 
template<typename Derived >
cmat sinm (const Eigen::MatrixBase< Derived > &A)
 Matrix sin. More...
 
template<typename Derived >
cmat cosm (const Eigen::MatrixBase< Derived > &A)
 Matrix cos. More...
 
template<typename Derived >
cmat spectralpowm (const Eigen::MatrixBase< Derived > &A, const cplx z)
 Matrix power. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > powm (const Eigen::MatrixBase< Derived > &A, idx n)
 Matrix power. More...
 
template<typename Derived >
double schatten (const Eigen::MatrixBase< Derived > &A, double p)
 Schatten matrix norm. More...
 
template<typename OutputScalar , typename Derived >
dyn_mat< OutputScalar > cwise (const Eigen::MatrixBase< Derived > &A, OutputScalar(*f)( const typename Derived::Scalar &))
 Functor. More...
 
template<typename T >
dyn_mat< typename T::Scalar > kron (const T &head)
 Kronecker product. More...
 
template<typename T , typename... Args>
dyn_mat< typename T::Scalar > kron (const T &head, const Args &...tail)
 Kronecker product. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > kron (const std::vector< Derived > &As)
 Kronecker product. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > kron (const std::initializer_list< Derived > &As)
 Kronecker product. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > kronpow (const Eigen::MatrixBase< Derived > &A, idx n)
 Kronecker power. More...
 
template<typename T >
dyn_mat< typename T::Scalar > dirsum (const T &head)
 Direct sum. More...
 
template<typename T , typename... Args>
dyn_mat< typename T::Scalar > dirsum (const T &head, const Args &...tail)
 Direct sum. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > dirsum (const std::vector< Derived > &As)
 Direct sum. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > dirsum (const std::initializer_list< Derived > &As)
 Direct sum. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > dirsumpow (const Eigen::MatrixBase< Derived > &A, idx n)
 Direct sum power. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > reshape (const Eigen::MatrixBase< Derived > &A, idx rows, idx cols)
 Reshape. More...
 
template<typename Derived1 , typename Derived2 >
dyn_mat< typename Derived1::Scalar > comm (const Eigen::MatrixBase< Derived1 > &A, const Eigen::MatrixBase< Derived2 > &B)
 Commutator. More...
 
template<typename Derived1 , typename Derived2 >
dyn_mat< typename Derived1::Scalar > anticomm (const Eigen::MatrixBase< Derived1 > &A, const Eigen::MatrixBase< Derived2 > &B)
 Anti-commutator. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > prj (const Eigen::MatrixBase< Derived > &V)
 Projector. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > grams (const std::vector< Derived > &Vs)
 Gram-Schmidt orthogonalization. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > grams (const std::initializer_list< Derived > &Vs)
 Gram-Schmidt orthogonalization. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > grams (const Eigen::MatrixBase< Derived > &A)
 Gram-Schmidt orthogonalization. More...
 
std::vector< idxn2multiidx (idx n, const std::vector< idx > &dims)
 Non-negative integer index to multi-index. More...
 
idx multiidx2n (const std::vector< idx > &midx, const std::vector< idx > &dims)
 Multi-index to non-negative integer index. More...
 
ket mket (const std::vector< idx > &mask, const std::vector< idx > &dims)
 Multi-partite qudit ket. More...
 
ket mket (const std::vector< idx > &mask, idx d=2)
 Multi-partite qudit ket. More...
 
cmat mprj (const std::vector< idx > &mask, const std::vector< idx > &dims)
 Projector onto multi-partite qudit ket. More...
 
cmat mprj (const std::vector< idx > &mask, idx d=2)
 Projector onto multi-partite qudit ket. More...
 
template<typename InputIterator >
std::vector< double > abssq (InputIterator first, InputIterator last)
 Computes the absolute values squared of an STL-like range of complex numbers. More...
 
template<typename Container >
std::vector< double > abssq (const Container &c, typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
 Computes the absolute values squared of an STL-like container. More...
 
template<typename Derived >
std::vector< double > abssq (const Eigen::MatrixBase< Derived > &A)
 Computes the absolute values squared of an Eigen expression. More...
 
template<typename InputIterator >
std::iterator_traits< InputIterator >::value_type sum (InputIterator first, InputIterator last)
 Element-wise sum of an STL-like range. More...
 
template<typename Container >
Container::value_type sum (const Container &c, typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
 Element-wise sum of the elements of an STL-like container. More...
 
template<typename InputIterator >
std::iterator_traits< InputIterator >::value_type prod (InputIterator first, InputIterator last)
 Element-wise product of an STL-like range. More...
 
template<typename Container >
Container::value_type prod (const Container &c, typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
 Element-wise product of the elements of an STL-like container. More...
 
template<typename Derived >
dyn_col_vect< typename Derived::Scalar > rho2pure (const Eigen::MatrixBase< Derived > &A)
 Finds the pure state representation of a matrix proportional to a projector onto a pure state. More...
 
template<typename T >
std::vector< T > complement (std::vector< T > subsys, idx N)
 Constructs the complement of a subsystem vector. More...
 
template<typename Derived >
std::vector< double > rho2bloch (const Eigen::MatrixBase< Derived > &A)
 Computes the 3-dimensional real Bloch vector corresponding to the qubit density matrix A. More...
 
cmat bloch2rho (const std::vector< double > &r)
 Computes the density matrix corresponding to the 3-dimensional real Bloch vector r. More...
 
template<typename Derived >
internal::IOManipEigen disp (const Eigen::MatrixBase< Derived > &A, double chop=qpp::chop)
 Eigen expression ostream manipulator. More...
 
internal::IOManipEigen disp (cplx z, double chop=qpp::chop)
 Complex number ostream manipulator. More...
 
template<typename InputIterator >
internal::IOManipRange< InputIterator > disp (InputIterator first, InputIterator last, const std::string &separator, const std::string &start="[", const std::string &end="]")
 Range ostream manipulator. More...
 
template<typename Container >
internal::IOManipRange< typename Container::const_iterator > disp (const Container &c, const std::string &separator, const std::string &start="[", const std::string &end="]", typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
 Standard container ostream manipulator. The container must support std::begin(), std::end() and forward iteration. More...
 
template<typename PointerType >
internal::IOManipPointer< PointerType > disp (const PointerType *p, idx n, const std::string &separator, const std::string &start="[", const std::string &end="]")
 C-style pointer ostream manipulator. More...
 
template<typename Derived >
void save (const Eigen::MatrixBase< Derived > &A, const std::string &fname)
 Saves Eigen expression to a binary file (internal format) in double precision. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > load (const std::string &fname)
 Loads Eigen matrix from a binary file (internal format) in double precision. More...
 
template<typename Derived >
dyn_col_vect< typename Derived::Scalar > ip (const Eigen::MatrixBase< Derived > &phi, const Eigen::MatrixBase< Derived > &psi, const std::vector< idx > &subsys, const std::vector< idx > &dims)
 Generalized inner product. More...
 
template<typename Derived >
dyn_col_vect< typename Derived::Scalar > ip (const Eigen::MatrixBase< Derived > &phi, const Eigen::MatrixBase< Derived > &psi, const std::vector< idx > &subsys, idx d=2)
 Generalized inner product. More...
 
template<typename Derived >
std::tuple< idx, std::vector< double >, std::vector< cmat > > measure (const Eigen::MatrixBase< Derived > &A, const std::vector< cmat > &Ks)
 Measures the state A using the set of Kraus operators Ks. More...
 
template<typename Derived >
std::tuple< idx, std::vector< double >, std::vector< cmat > > measure (const Eigen::MatrixBase< Derived > &A, const std::initializer_list< cmat > &Ks)
 Measures the state A using the set of Kraus operators Ks. More...
 
template<typename Derived >
std::tuple< idx, std::vector< double >, std::vector< cmat > > measure (const Eigen::MatrixBase< Derived > &A, const cmat &U)
 Measures the state A in the orthonormal basis specified by the unitary matrix U. More...
 
template<typename Derived >
std::tuple< idx, std::vector< double >, std::vector< cmat > > measure (const Eigen::MatrixBase< Derived > &A, const std::vector< cmat > &Ks, const std::vector< idx > &subsys, const std::vector< idx > &dims)
 Measures the part subsys of the multi-partite state vector or density matrix A using the set of Kraus operators Ks. More...
 
template<typename Derived >
std::tuple< idx, std::vector< double >, std::vector< cmat > > measure (const Eigen::MatrixBase< Derived > &A, const std::initializer_list< cmat > &Ks, const std::vector< idx > &subsys, const std::vector< idx > &dims)
 Measures the part subsys of the multi-partite state vector or density matrix A using the set of Kraus operators Ks. More...
 
template<typename Derived >
std::tuple< idx, std::vector< double >, std::vector< cmat > > measure (const Eigen::MatrixBase< Derived > &A, const std::vector< cmat > &Ks, const std::vector< idx > &subsys, idx d=2)
 Measures the part subsys of the multi-partite state vector or density matrix A using the set of Kraus operators Ks. More...
 
template<typename Derived >
std::tuple< idx, std::vector< double >, std::vector< cmat > > measure (const Eigen::MatrixBase< Derived > &A, const std::initializer_list< cmat > &Ks, const std::vector< idx > &subsys, idx d=2)
 Measures the part subsys of the multi-partite state vector or density matrix A using the set of Kraus operators Ks. More...
 
template<typename Derived >
std::tuple< idx, std::vector< double >, std::vector< cmat > > measure (const Eigen::MatrixBase< Derived > &A, const cmat &V, const std::vector< idx > &subsys, const std::vector< idx > &dims)
 Measures the part subsys of the multi-partite state vector or density matrix A in the orthonormal basis or rank-1 POVM specified by the matrix V. More...
 
template<typename Derived >
std::tuple< idx, std::vector< double >, std::vector< cmat > > measure (const Eigen::MatrixBase< Derived > &A, const cmat &V, const std::vector< idx > &subsys, idx d=2)
 Measures the part subsys of the multi-partite state vector or density matrix A in the orthonormal basis or rank-1 POVM specified by the matrix V. More...
 
template<typename Derived >
std::tuple< std::vector< idx >, double, cmatmeasure_seq (const Eigen::MatrixBase< Derived > &A, std::vector< idx > subsys, std::vector< idx > dims)
 Sequentially measures the part subsys of the multi-partite state vector or density matrix A in the computational basis. More...
 
template<typename Derived >
std::tuple< std::vector< idx >, double, cmatmeasure_seq (const Eigen::MatrixBase< Derived > &A, std::vector< idx > subsys, idx d=2)
 Sequentially measures the part subsys of the multi-partite state vector or density matrix A in the computational basis. More...
 
template<typename Derived >
Derived loadMATLABmatrix (const std::string &, const std::string &)
 Loads an Eigen dynamic matrix from a MATLAB .mat file, generic version. More...
 
template<>
dmat loadMATLABmatrix (const std::string &mat_file, const std::string &var_name)
 Loads an Eigen dynamic matrix from a MATLAB .mat file, specialization for double matrices (qpp::dmat) More...
 
template<>
cmat loadMATLABmatrix (const std::string &mat_file, const std::string &var_name)
 Loads an Eigen dynamic matrix from a MATLAB .mat file, specialization for complex matrices (qpp::cmat) More...
 
template<typename Derived >
void saveMATLABmatrix (const Eigen::MatrixBase< Derived > &, const std::string &, const std::string &, const std::string &)
 Saves an Eigen dynamic matrix to a MATLAB .mat file, generic version. More...
 
template<>
void saveMATLABmatrix (const Eigen::MatrixBase< dmat > &A, const std::string &mat_file, const std::string &var_name, const std::string &mode)
 Saves an Eigen dynamic matrix to a MATLAB .mat file, specialization for double matrices (qpp::dmat) More...
 
template<>
void saveMATLABmatrix (const Eigen::MatrixBase< cmat > &A, const std::string &mat_file, const std::string &var_name, const std::string &mode)
 Saves an Eigen dynamic matrix to a MATLAB .mat file, specialization for complex matrices (qpp::cmat) More...
 
std::vector< int > x2contfrac (double x, idx n, idx cut=1e5)
 Simple continued fraction expansion. More...
 
double contfrac2x (const std::vector< int > &cf, idx n)
 Real representation of a simple continued fraction. More...
 
double contfrac2x (const std::vector< int > &cf)
 Real representation of a simple continued fraction. More...
 
bigint gcd (bigint m, bigint n)
 Greatest common divisor of two integers. More...
 
bigint gcd (const std::vector< bigint > &ns)
 Greatest common divisor of a list of integers. More...
 
bigint lcm (bigint m, bigint n)
 Least common multiple of two integers. More...
 
bigint lcm (const std::vector< bigint > &ns)
 Least common multiple of a list of integers. More...
 
std::vector< idxinvperm (const std::vector< idx > &perm)
 Inverse permutation. More...
 
std::vector< idxcompperm (const std::vector< idx > &perm, const std::vector< idx > &sigma)
 Compose permutations. More...
 
std::vector< bigintfactors (bigint n)
 Prime factor decomposition. More...
 
bool isprime (bigint n)
 Primality test. More...
 
bigint modpow (bigint a, bigint n, bigint p)
 Fast integer power modulo p based on the SQUARE-AND-MULTIPLY algorithm. More...
 
std::tuple< bigint, bigint, bigintegcd (bigint m, bigint n)
 Extended greatest common divisor of two integers. More...
 
bigint modinv (bigint a, bigint p)
 Modular inverse of a mod p. More...
 
template<typename Derived1 , typename Derived2 >
dyn_mat< typename Derived1::Scalar > applyCTRL (const Eigen::MatrixBase< Derived1 > &state, const Eigen::MatrixBase< Derived2 > &A, const std::vector< idx > &ctrl, const std::vector< idx > &subsys, const std::vector< idx > &dims)
 Applies the controlled-gate A to the part subsys of the multi-partite state vector or density matrix state. More...
 
template<typename Derived1 , typename Derived2 >
dyn_mat< typename Derived1::Scalar > applyCTRL (const Eigen::MatrixBase< Derived1 > &state, const Eigen::MatrixBase< Derived2 > &A, const std::vector< idx > &ctrl, const std::vector< idx > &subsys, idx d=2)
 Applies the controlled-gate A to the part subsys of the multi-partite state vector or density matrix state. More...
 
template<typename Derived1 , typename Derived2 >
dyn_mat< typename Derived1::Scalar > apply (const Eigen::MatrixBase< Derived1 > &state, const Eigen::MatrixBase< Derived2 > &A, const std::vector< idx > &subsys, const std::vector< idx > &dims)
 Applies the gate A to the part subsys of the multi-partite state vector or density matrix state. More...
 
template<typename Derived1 , typename Derived2 >
dyn_mat< typename Derived1::Scalar > apply (const Eigen::MatrixBase< Derived1 > &state, const Eigen::MatrixBase< Derived2 > &A, const std::vector< idx > &subsys, idx d=2)
 Applies the gate A to the part subsys of the multi-partite state vector or density matrix state. More...
 
template<typename Derived >
cmat apply (const Eigen::MatrixBase< Derived > &rho, const std::vector< cmat > &Ks)
 Applies the channel specified by the set of Kraus operators Ks to the density matrix rho. More...
 
template<typename Derived >
cmat apply (const Eigen::MatrixBase< Derived > &rho, const std::vector< cmat > &Ks, const std::vector< idx > &subsys, const std::vector< idx > &dims)
 Applies the channel specified by the set of Kraus operators Ks to the part subsys of the multi-partite density matrix rho. More...
 
template<typename Derived >
cmat apply (const Eigen::MatrixBase< Derived > &rho, const std::vector< cmat > &Ks, const std::vector< idx > &subsys, idx d=2)
 Applies the channel specified by the set of Kraus operators Ks to the part subsys of the multi-partite density matrix rho. More...
 
cmat kraus2super (const std::vector< cmat > &Ks)
 Superoperator matrix. More...
 
cmat kraus2choi (const std::vector< cmat > &Ks)
 Choi matrix. More...
 
std::vector< cmatchoi2kraus (const cmat &A)
 Orthogonal Kraus operators from Choi matrix. More...
 
cmat choi2super (const cmat &A)
 Converts Choi matrix to superoperator matrix. More...
 
cmat super2choi (const cmat &A)
 Converts superoperator matrix to Choi matrix. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > ptrace1 (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &dims)
 Partial trace. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > ptrace2 (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &dims)
 Partial trace. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > ptrace (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &subsys, const std::vector< idx > &dims)
 Partial trace. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > ptrace (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &subsys, idx d=2)
 Partial trace. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > ptranspose (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &subsys, const std::vector< idx > &dims)
 Partial transpose. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > ptranspose (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &subsys, idx d=2)
 Partial transpose. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > syspermute (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &perm, const std::vector< idx > &dims)
 Subsystem permutation. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > syspermute (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &perm, idx d=2)
 Subsystem permutation. More...
 
double rand (double a=0, double b=1)
 Generates a random real number uniformly distributed in the interval [a, b) More...
 
bigint rand (bigint a=std::numeric_limits< bigint >::min(), bigint b=std::numeric_limits< bigint >::max())
 Generates a random big integer uniformly distributed in the interval [a, b]. More...
 
ubigint rand (ubigint a=std::numeric_limits< ubigint >::min(), ubigint b=std::numeric_limits< ubigint >::max())
 Generates a random non-negative big integer uniformly distributed in the interval [a, b]. More...
 
idx randidx (idx a=std::numeric_limits< idx >::min(), idx b=std::numeric_limits< idx >::max())
 Generates a random index (idx) uniformly distributed in the interval [a, b]. More...
 
template<typename Derived >
Derived rand (idx rows, idx cols, double a=0, double b=1)
 Generates a random matrix with entries uniformly distributed in the interval [a, b) More...
 
template<>
dmat rand (idx rows, idx cols, double a, double b)
 Generates a random real matrix with entries uniformly distributed in the interval [a, b), specialization for double matrices (qpp::dmat) More...
 
template<>
cmat rand (idx rows, idx cols, double a, double b)
 Generates a random complex matrix with entries (both real and imaginary) uniformly distributed in the interval [a, b), specialization for complex matrices (qpp::cmat) More...
 
template<typename Derived >
Derived randn (idx rows, idx cols, double mean=0, double sigma=1)
 Generates a random matrix with entries normally distributed in N(mean, sigma) More...
 
template<>
dmat randn (idx rows, idx cols, double mean, double sigma)
 Generates a random real matrix with entries normally distributed in N(mean, sigma), specialization for double matrices (qpp::dmat) More...
 
template<>
cmat randn (idx rows, idx cols, double mean, double sigma)
 Generates a random complex matrix with entries (both real and imaginary) normally distributed in N(mean, sigma), specialization for complex matrices (qpp::cmat) More...
 
double randn (double mean=0, double sigma=1)
 Generates a random real number (double) normally distributed in N(mean, sigma) More...
 
cmat randU (idx D)
 Generates a random unitary matrix. More...
 
cmat randV (idx Din, idx Dout)
 Generates a random isometry matrix. More...
 
std::vector< cmatrandkraus (idx N, idx D)
 Generates a set of random Kraus operators. More...
 
cmat randH (idx D)
 Generates a random Hermitian matrix. More...
 
ket randket (idx D)
 Generates a random normalized ket (pure state vector) More...
 
cmat randrho (idx D)
 Generates a random density matrix. More...
 
std::vector< idxrandperm (idx n)
 Generates a random uniformly distributed permutation. More...
 
std::vector< double > uniform (idx N)
 Uniform probability distribution vector. More...
 
std::vector< double > marginalX (const dmat &probXY)
 Marginal distribution. More...
 
std::vector< double > marginalY (const dmat &probXY)
 Marginal distribution. More...
 
template<typename Container >
double avg (const std::vector< double > &prob, const Container &X, typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
 Average. More...
 
template<typename Container >
double cov (const dmat &probXY, const Container &X, const Container &Y, typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
 Covariance. More...
 
template<typename Container >
double var (const std::vector< double > &prob, const Container &X, typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
 Variance. More...
 
template<typename Container >
double sigma (const std::vector< double > &prob, const Container &X, typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
 Standard deviation. More...
 
template<typename Container >
double cor (const dmat &probXY, const Container &X, const Container &Y, typename std::enable_if< is_iterable< Container >::value >::type *=nullptr)
 Correlation. More...
 

Variables

constexpr double chop = 1e-10
 Used in qpp::disp() for setting to zero numbers that have their absolute value smaller than qpp::chop. More...
 
constexpr double eps = 1e-12
 Used to decide whether a number or expression in double precision is zero or not. More...
 
constexpr idx maxn = 64
 Maximum number of allowed qu(d)its (subsystems) More...
 
constexpr double pi = 3.141592653589793238462643383279502884
 $ \pi $ More...
 
constexpr double ee = 2.718281828459045235360287471352662497
 Base of natural logarithm, $e$. More...
 
constexpr double infty = std::numeric_limits<double>::infinity()
 Used to denote infinity in double precision. More...
 

Detailed Description

Quantum++ main namespace.

Typedef Documentation

using qpp::bigint = typedef long long int

Big integer.

using qpp::bra = typedef Eigen::RowVectorXcd

Complex (double precision) dynamic Eigen row vector.

using qpp::cmat = typedef Eigen::MatrixXcd

Complex (double precision) dynamic Eigen matrix.

using qpp::cplx = typedef std::complex<double>

Complex number in double precision.

using qpp::dmat = typedef Eigen::MatrixXd

Real (double precision) dynamic Eigen matrix.

template<typename Scalar >
using qpp::dyn_col_vect = typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1>

Dynamic Eigen column vector over the field specified by Scalar.

Example:

// type of colvect is Eigen::Matrix<float, Eigen::Dynamic, 1>
auto colvect = dyn_col_vect<float>(2);
template<typename Scalar >
using qpp::dyn_mat = typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>

Dynamic Eigen matrix over the field specified by Scalar.

Example:

// type of mat is Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic>
auto mat = dyn_mat<float>(2,3);
template<typename Scalar >
using qpp::dyn_row_vect = typedef Eigen::Matrix<Scalar, 1, Eigen::Dynamic>

Dynamic Eigen row vector over the field specified by Scalar.

Example:

// type of rowvect is Eigen::Matrix<float, 1, Eigen::Dynamic>
auto rowvect = dyn_row_vect<float>(3);
using qpp::idx = typedef std::size_t

Non-negative integer index.

using qpp::ket = typedef Eigen::VectorXcd

Complex (double precision) dynamic Eigen column vector.

template<typename... >
using qpp::to_void = typedef void

Alias template that implements the proposal for void_t.

See also
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3911
using qpp::ubigint = typedef unsigned long long int

Non-negative big integer.

Function Documentation

template<typename Derived >
cmat qpp::absm ( const Eigen::MatrixBase< Derived > &  A)

Matrix absolut value.

Parameters
AEigen expression
Returns
Matrix absolut value of A
template<typename InputIterator >
std::vector<double> qpp::abssq ( InputIterator  first,
InputIterator  last 
)

Computes the absolute values squared of an STL-like range of complex numbers.

Parameters
firstIterator to the first element of the range
lastIterator to the last element of the range
Returns
Real vector consisting of the range absolut values squared
template<typename Container >
std::vector<double> qpp::abssq ( const Container &  c,
typename std::enable_if< is_iterable< Container >::value >::type *  = nullptr 
)

Computes the absolute values squared of an STL-like container.

Parameters
cSTL-like container
Returns
Real vector consisting of the container's absolut values squared
template<typename Derived >
std::vector<double> qpp::abssq ( const Eigen::MatrixBase< Derived > &  A)

Computes the absolute values squared of an Eigen expression.

Parameters
AEigen expression
Returns
Real vector consisting of the absolut values squared
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::adjoint ( const Eigen::MatrixBase< Derived > &  A)

Adjoint.

Parameters
AEigen expression
Returns
Adjoint (Hermitian conjugate) of A, as a dynamic matrix over the same scalar field as A
template<typename Derived1 , typename Derived2 >
dyn_mat<typename Derived1::Scalar> qpp::anticomm ( const Eigen::MatrixBase< Derived1 > &  A,
const Eigen::MatrixBase< Derived2 > &  B 
)

Anti-commutator.

See also
qpp::comm()

Anti-commutator $ \{A,B\} = AB + BA $. Both A and B must be Eigen expressions over the same scalar field.

Parameters
AEigen expression
BEigen expression
Returns
Anti-commutator $AB +BA$, as a dynamic matrix over the same scalar field as A
template<typename Derived1 , typename Derived2 >
dyn_mat<typename Derived1::Scalar> qpp::apply ( const Eigen::MatrixBase< Derived1 > &  state,
const Eigen::MatrixBase< Derived2 > &  A,
const std::vector< idx > &  subsys,
const std::vector< idx > &  dims 
)

Applies the gate A to the part subsys of the multi-partite state vector or density matrix state.

Note
The dimension of the gate A must match the dimension of subsys
Parameters
stateEigen expression
AEigen expression
subsysSubsystem indexes where the gate A is applied
dimsDimensions of the multi-partite system
Returns
Gate A applied to the part subsys of state
template<typename Derived1 , typename Derived2 >
dyn_mat<typename Derived1::Scalar> qpp::apply ( const Eigen::MatrixBase< Derived1 > &  state,
const Eigen::MatrixBase< Derived2 > &  A,
const std::vector< idx > &  subsys,
idx  d = 2 
)

Applies the gate A to the part subsys of the multi-partite state vector or density matrix state.

Note
The dimension of the gate A must match the dimension of subsys
Parameters
stateEigen expression
AEigen expression
subsysSubsystem indexes where the gate A is applied
dSubsystem dimensions
Returns
Gate A applied to the part subsys of state
template<typename Derived >
cmat qpp::apply ( const Eigen::MatrixBase< Derived > &  rho,
const std::vector< cmat > &  Ks 
)

Applies the channel specified by the set of Kraus operators Ks to the density matrix rho.

Parameters
rhoEigen expression
KsSet of Kraus operators
Returns
Output density matrix after the action of the channel
template<typename Derived >
cmat qpp::apply ( const Eigen::MatrixBase< Derived > &  rho,
const std::vector< cmat > &  Ks,
const std::vector< idx > &  subsys,
const std::vector< idx > &  dims 
)

Applies the channel specified by the set of Kraus operators Ks to the part subsys of the multi-partite density matrix rho.

Parameters
rhoEigen expression
KsSet of Kraus operators
subsysSubsystem indexes where the Kraus operators Ks are applied
dimsDimensions of the multi-partite system
Returns
Output density matrix after the action of the channel
template<typename Derived >
cmat qpp::apply ( const Eigen::MatrixBase< Derived > &  rho,
const std::vector< cmat > &  Ks,
const std::vector< idx > &  subsys,
idx  d = 2 
)

Applies the channel specified by the set of Kraus operators Ks to the part subsys of the multi-partite density matrix rho.

Parameters
rhoEigen expression
KsSet of Kraus operators
subsysSubsystem indexes where the Kraus operators Ks are applied
dSubsystem dimensions
Returns
Output density matrix after the action of the channel
template<typename Derived1 , typename Derived2 >
dyn_mat<typename Derived1::Scalar> qpp::applyCTRL ( const Eigen::MatrixBase< Derived1 > &  state,
const Eigen::MatrixBase< Derived2 > &  A,
const std::vector< idx > &  ctrl,
const std::vector< idx > &  subsys,
const std::vector< idx > &  dims 
)

Applies the controlled-gate A to the part subsys of the multi-partite state vector or density matrix state.

See also
qpp::Gates::CTRL()
Note
The dimension of the gate A must match the dimension of subsys. Also, all control subsystems in ctrl must have the same dimension.
Parameters
stateEigen expression
AEigen expression
ctrlControl subsystem indexes
subsysSubsystem indexes where the gate A is applied
dimsDimensions of the multi-partite system
Returns
CTRL-A gate applied to the part subsys of state
template<typename Derived1 , typename Derived2 >
dyn_mat<typename Derived1::Scalar> qpp::applyCTRL ( const Eigen::MatrixBase< Derived1 > &  state,
const Eigen::MatrixBase< Derived2 > &  A,
const std::vector< idx > &  ctrl,
const std::vector< idx > &  subsys,
idx  d = 2 
)

Applies the controlled-gate A to the part subsys of the multi-partite state vector or density matrix state.

See also
qpp::Gates::CTRL()
Note
The dimension of the gate A must match the dimension of subsys
Parameters
stateEigen expression
AEigen expression
ctrlControl subsystem indexes
subsysSubsystem indexes where the gate A is applied
dSubsystem dimensions
Returns
CTRL-A gate applied to the part subsys of state
template<typename Container >
double qpp::avg ( const std::vector< double > &  prob,
const Container &  X,
typename std::enable_if< is_iterable< Container >::value >::type *  = nullptr 
)

Average.

Parameters
probReal probability vector representing the probability distribution of X
XRandom variable values represented by an STL-like container
Returns
Average of X
cmat qpp::bloch2rho ( const std::vector< double > &  r)
inline

Computes the density matrix corresponding to the 3-dimensional real Bloch vector r.

See also
qpp::rho2bloch()
Parameters
r3-dimensional real vector
Returns
Qubit density matrix
std::vector<cmat> qpp::choi2kraus ( const cmat A)
inline

Orthogonal Kraus operators from Choi matrix.

See also
qpp::kraus2choi()

Extracts a set of orthogonal (under Hilbert-Schmidt operator norm) Kraus operators from the Choi matrix A

Note
The Kraus operators satisfy $Tr(K_i^\dagger K_j)=\delta_{ij}$ for all $i\neq j$
Parameters
AChoi matrix
Returns
Set of orthogonal Kraus operators
cmat qpp::choi2super ( const cmat A)
inline

Converts Choi matrix to superoperator matrix.

See also
qpp::super2choi()
Parameters
AChoi matrix
Returns
Superoperator matrix
template<typename Derived1 , typename Derived2 >
dyn_mat<typename Derived1::Scalar> qpp::comm ( const Eigen::MatrixBase< Derived1 > &  A,
const Eigen::MatrixBase< Derived2 > &  B 
)

Commutator.

See also
qpp::anticomm()

Commutator $ [A,B] = AB - BA $. Both A and B must be Eigen expressions over the same scalar field.

Parameters
AEigen expression
BEigen expression
Returns
Commutator $AB -BA$, as a dynamic matrix over the same scalar field as A
template<typename T >
std::vector<T> qpp::complement ( std::vector< T >  subsys,
idx  N 
)

Constructs the complement of a subsystem vector.

Parameters
subsysSubsystem vector
NTotal number of systems
Returns
The complement of subsys with respect to the set $\{0, 1, \ldots, N - 1\}$
std::vector<idx> qpp::compperm ( const std::vector< idx > &  perm,
const std::vector< idx > &  sigma 
)
inline

Compose permutations.

Parameters
permPermutation
sigmaPermutation
Returns
Composition of the permutations perm $\circ$ sigma = perm(sigma)
template<typename Derived >
double qpp::concurrence ( const Eigen::MatrixBase< Derived > &  A)

Wootters concurrence of the bi-partite qubit mixed state A.

Parameters
AEigen expression
Returns
Wootters concurrence
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::conjugate ( const Eigen::MatrixBase< Derived > &  A)

Complex conjugate.

Parameters
AEigen expression
Returns
Complex conjugate of A, as a dynamic matrix over the same scalar field as A
double qpp::contfrac2x ( const std::vector< int > &  cf,
idx  n 
)
inline

Real representation of a simple continued fraction.

See also
qpp::x2contfrac()
Parameters
cfInteger vector containing the simple continued fraction expansion
nNumber of terms considered in the continued fraction expansion. If n is greater than the size of cf,then all terms in cf are considered.
Returns
Real representation of the simple continued fraction
double qpp::contfrac2x ( const std::vector< int > &  cf)
inline

Real representation of a simple continued fraction.

See also
qpp::x2contfrac()
Parameters
cfInteger vector containing the simple continued fraction expansion
Returns
Real representation of the simple continued fraction
template<typename Container >
double qpp::cor ( const dmat probXY,
const Container &  X,
const Container &  Y,
typename std::enable_if< is_iterable< Container >::value >::type *  = nullptr 
)

Correlation.

Parameters
probXYReal matrix representing the joint probability distribution of X and Y in lexicographical order (X labels the rows, Y labels the columns)
XRandom variable values represented by an STL-like container
YRandom variable values represented by an STL-like container
Returns
Correlation of X and Y
template<typename Derived >
cmat qpp::cosm ( const Eigen::MatrixBase< Derived > &  A)

Matrix cos.

Parameters
AEigen expression
Returns
Matrix cosine of A
template<typename Container >
double qpp::cov ( const dmat probXY,
const Container &  X,
const Container &  Y,
typename std::enable_if< is_iterable< Container >::value >::type *  = nullptr 
)

Covariance.

Parameters
probXYReal matrix representing the joint probability distribution of X and Y in lexicographical order (X labels the rows, Y labels the columns)
XRandom variable values represented by an STL-like container
YRandom variable values represented by an STL-like container
Returns
Covariance of X and Y
template<typename OutputScalar , typename Derived >
dyn_mat<OutputScalar> qpp::cwise ( const Eigen::MatrixBase< Derived > &  A,
OutputScalar(*)( const typename Derived::Scalar &)  f 
)

Functor.

Parameters
AEigen expression
fPointer-to-function from scalars of A to OutputScalar
Returns
Component-wise $f(A)$, as a dynamic matrix over the OutputScalar scalar field
template<typename Derived >
Derived::Scalar qpp::det ( const Eigen::MatrixBase< Derived > &  A)

Determinant.

Parameters
AEigen expression
Returns
Determinant of A, as a scalar over the same scalar field as A. Returns $\pm \infty$ when the determinant overflows/underflows.
template<typename T >
dyn_mat<typename T::Scalar> qpp::dirsum ( const T &  head)

Direct sum.

See also
qpp::dirsumpow()

Used to stop the recursion for the variadic template version of qpp::dirsum()

Parameters
headEigen expression
Returns
Its argument head
template<typename T , typename... Args>
dyn_mat<typename T::Scalar> qpp::dirsum ( const T &  head,
const Args &...  tail 
)

Direct sum.

See also
qpp::dirsumpow()
Parameters
headEigen expression
tailVariadic Eigen expression (zero or more parameters)
Returns
Direct sum of all input parameters, evaluated from left to right, as a dynamic matrix over the same scalar field as its arguments
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::dirsum ( const std::vector< Derived > &  As)

Direct sum.

See also
qpp::dirsumpow()
Parameters
Asstd::vector of Eigen expressions
Returns
Direct sum of all elements in As, evaluated from left to right, as a dynamic matrix over the same scalar field as its arguments
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::dirsum ( const std::initializer_list< Derived > &  As)

Direct sum.

See also
qpp::dirsumpow()
Parameters
Asstd::initializer_list of Eigen expressions, such as {A1, A2, ... ,Ak}
Returns
Direct sum of all elements in As, evaluated from left to right, as a dynamic matrix over the same scalar field as its arguments
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::dirsumpow ( const Eigen::MatrixBase< Derived > &  A,
idx  n 
)

Direct sum power.

See also
qpp::dirsum()
Parameters
AEigen expression
nNon-negative integer
Returns
Direct sum of A with itself n times $A^{\oplus n}$, as a dynamic matrix over the same scalar field as A
template<typename Derived >
internal::IOManipEigen qpp::disp ( const Eigen::MatrixBase< Derived > &  A,
double  chop = qpp::chop 
)

Eigen expression ostream manipulator.

Parameters
AEigen expression
chopSet to zero the elements smaller in absolute value than chop
Returns
Instance of qpp::internal::internal::IOManipEigen
internal::IOManipEigen qpp::disp ( cplx  z,
double  chop = qpp::chop 
)
inline

Complex number ostream manipulator.

Parameters
zComplex number (or any other type implicitly cast-able to std::complex<double>)
chopSet to zero the elements smaller in absolute value than chop
Returns
Instance of qpp::internal::internal::IOManipEigen
template<typename InputIterator >
internal::IOManipRange<InputIterator> qpp::disp ( InputIterator  first,
InputIterator  last,
const std::string &  separator,
const std::string &  start = "[",
const std::string &  end = "]" 
)

Range ostream manipulator.

Parameters
firstIterator to the first element of the range
lastIterator to the last element of the range
separatorSeparator
startLeft marking
endRight marking
Returns
Instance of qpp::internal::internal::IOManipRange
template<typename Container >
internal::IOManipRange<typename Container::const_iterator> qpp::disp ( const Container &  c,
const std::string &  separator,
const std::string &  start = "[",
const std::string &  end = "]",
typename std::enable_if< is_iterable< Container >::value >::type *  = nullptr 
)

Standard container ostream manipulator. The container must support std::begin(), std::end() and forward iteration.

Parameters
cContainer
separatorSeparator
startLeft marking
endRight marking
Returns
Instance of qpp::internal::internal::IOManipRange
template<typename PointerType >
internal::IOManipPointer<PointerType> qpp::disp ( const PointerType *  p,
idx  n,
const std::string &  separator,
const std::string &  start = "[",
const std::string &  end = "]" 
)

C-style pointer ostream manipulator.

Parameters
pPointer to the first element
nNumber of elements to be displayed
separatorSeparator
startLeft marking
endRight marking
Returns
Instance of qpp::internal::internal::IOManipPointer
std::tuple<bigint, bigint, bigint> qpp::egcd ( bigint  m,
bigint  n 
)
inline

Extended greatest common divisor of two integers.

See also
qpp::gcd()
Parameters
mInteger
nInteger
Returns
Tuple of: 1. Integer $a$, 2. Integer $b$, and 3. Non-negative integer $gcd(a, b)$ such that $am + bn = gcd(a, b)$
template<typename Derived >
std::pair<dyn_col_vect < cplx>, cmat> qpp::eig ( const Eigen::MatrixBase< Derived > &  A)

Full eigen decomposition.

See also
qpp::heig()
Parameters
AEigen expression
Returns
Pair of: 1. Eigenvalues of A, as a complex dynamic column vector, and 2. Eigenvectors of A, as columns of a complex dynamic matrix
template<typename Derived >
double qpp::entanglement ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  dims 
)

Entanglement of the bi-partite pure state A.

Defined as the von-Neumann entropy of the reduced density matrix of one of the subsystems

See also
qpp::entropy()
Parameters
AEigen expression
dimsDimensions of the bi-partite system
Returns
Entanglement, with the logarithm in base 2
template<typename Derived >
double qpp::entropy ( const Eigen::MatrixBase< Derived > &  A)

von-Neumann entropy of the density matrix A

Parameters
AEigen expression
Returns
von-Neumann entropy, with the logarithm in base 2
double qpp::entropy ( const std::vector< double > &  prob)
inline

Shannon entropy of the probability distribution prob.

Parameters
probReal probability vector
Returns
Shannon entropy, with the logarithm in base 2
template<typename Derived >
dyn_col_vect<cplx> qpp::evals ( const Eigen::MatrixBase< Derived > &  A)

Eigenvalues.

See also
qpp::hevals()
Parameters
AEigen expression
Returns
Eigenvalues of A, as a complex dynamic column vector
template<typename Derived >
cmat qpp::evects ( const Eigen::MatrixBase< Derived > &  A)

Eigenvectors.

See also
qpp::hevects()
Parameters
AEigen expression
Returns
Eigenvectors of A, as columns of a complex dynamic matrix
template<typename Derived >
cmat qpp::expm ( const Eigen::MatrixBase< Derived > &  A)

Matrix exponential.

Parameters
AEigen expression
Returns
Matrix exponential of A
std::vector<bigint> qpp::factors ( bigint  n)
inline

Prime factor decomposition.

Note
Runs in $\mathcal{O}(\sqrt{n})$ time complexity
Parameters
nInteger different from 0, 1 or -1
Returns
Integer vector containing the factors
template<typename Derived >
cmat qpp::funm ( const Eigen::MatrixBase< Derived > &  A,
cplx(*)(const cplx &)  f 
)

Functional calculus f(A)

Parameters
AEigen expression
fPointer-to-function from complex to complex
Returns
$f(A)$
bigint qpp::gcd ( bigint  m,
bigint  n 
)
inline

Greatest common divisor of two integers.

See also
qpp::lcm()
Parameters
mInteger
nInteger
Returns
Greatest common divisor of m and n
bigint qpp::gcd ( const std::vector< bigint > &  ns)
inline

Greatest common divisor of a list of integers.

See also
qpp::lcm()
Parameters
nsList of integers
Returns
Greatest common divisor of all numbers in ns
template<typename Derived >
double qpp::gconcurrence ( const Eigen::MatrixBase< Derived > &  A)

G-concurrence of the bi-partite pure state A.

Note
Both local dimensions must be equal

Uses qpp::logdet() to avoid overflows

See also
qpp::logdet()
Parameters
AEigen expression
Returns
G-concurrence
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::grams ( const std::vector< Derived > &  Vs)

Gram-Schmidt orthogonalization.

Parameters
Vsstd::vector of Eigen expressions as column vectors
Returns
Gram-Schmidt vectors of Vs as columns of a dynamic matrix over the same scalar field as its arguments
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::grams ( const std::initializer_list< Derived > &  Vs)

Gram-Schmidt orthogonalization.

Parameters
Vsstd::initializer_list of Eigen expressions as column vectors
Returns
Gram-Schmidt vectors of Vs as columns of a dynamic matrix over the same scalar field as its arguments
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::grams ( const Eigen::MatrixBase< Derived > &  A)

Gram-Schmidt orthogonalization.

Parameters
AEigen expression, the input vectors are the columns of A
Returns
Gram-Schmidt vectors of the columns of A, as columns of a dynamic matrix over the same scalar field as A
template<typename Derived >
std::pair<dyn_col_vect < double>, cmat> qpp::heig ( const Eigen::MatrixBase< Derived > &  A)

Full eigen decomposition of Hermitian expression.

See also
qpp::eig()
Parameters
AEigen expression
Returns
Pair of: 1. Eigenvalues of A, as a real dynamic column vector, and 2. Eigenvectors of A, as columns of a complex dynamic matrix
template<typename Derived >
dyn_col_vect<double> qpp::hevals ( const Eigen::MatrixBase< Derived > &  A)

Hermitian eigenvalues.

See also
qpp::evals()
Parameters
AEigen expression
Returns
Eigenvalues of Hermitian A, as a real dynamic column vector
template<typename Derived >
cmat qpp::hevects ( const Eigen::MatrixBase< Derived > &  A)

Hermitian eigenvectors.

See also
qpp::evects()
Parameters
AEigen expression
Returns
Eigenvectors of Hermitian A, as columns of a complex matrix
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::inverse ( const Eigen::MatrixBase< Derived > &  A)

Inverse.

Parameters
AEigen expression
Returns
Inverse of A, as a dynamic matrix over the same scalar field as A
std::vector<idx> qpp::invperm ( const std::vector< idx > &  perm)
inline

Inverse permutation.

Parameters
permPermutation
Returns
Inverse of the permutation perm
template<typename Derived >
dyn_col_vect<typename Derived::Scalar> qpp::ip ( const Eigen::MatrixBase< Derived > &  phi,
const Eigen::MatrixBase< Derived > &  psi,
const std::vector< idx > &  subsys,
const std::vector< idx > &  dims 
)

Generalized inner product.

Parameters
phiColumn vector Eigen expression
psiColumn vector Eigen expression
subsysSubsystem indexes over which phi is defined
dimsDimensions of the multi-partite system
Returns
The inner product $\langle \phi_{subsys}|\psi\rangle$, as a scalar or column vector over the remaining Hilbert space
template<typename Derived >
dyn_col_vect<typename Derived::Scalar> qpp::ip ( const Eigen::MatrixBase< Derived > &  phi,
const Eigen::MatrixBase< Derived > &  psi,
const std::vector< idx > &  subsys,
idx  d = 2 
)

Generalized inner product.

Parameters
phiColumn vector Eigen expression
psiColumn vector Eigen expression
subsysSubsystem indexes over which phi is defined
dSubsystem dimensions
Returns
The inner product $\langle \phi_{subsys}|\psi\rangle$, as a scalar or column vector over the remaining Hilbert space
bool qpp::isprime ( bigint  n)
inline

Primality test.

Note
Runs in $\mathcal{O}(\sqrt{n})$ time complexity. Use Miller-Rabin or something similar if you need high performance.
Parameters
nInteger different for 0, 1 or -1
Returns
True if the number is prime, false otherwise
cmat qpp::kraus2choi ( const std::vector< cmat > &  Ks)
inline

Choi matrix.

See also
qpp::choi2kraus()

Constructs the Choi matrix of the channel specified by the set of Kraus operators Ks in the standard operator basis $\{|i\rangle\langle j|\}$ ordered in lexicographical order, i.e. $|0\rangle\langle 0|$, $|0\rangle\langle 1|$ etc.

Note
The superoperator matrix $S$ and the Choi matrix $ C$ are related by $ S_{ab,mn} = C_{ma,nb}$
Parameters
KsSet of Kraus operators
Returns
Choi matrix
cmat qpp::kraus2super ( const std::vector< cmat > &  Ks)
inline

Superoperator matrix.

Constructs the superoperator matrix of the channel specified by the set of Kraus operators Ks in the standard operator basis $\{|i\rangle\langle j|\}$ ordered in lexicographical order, i.e. $|0\rangle\langle 0|$, $|0\rangle\langle 1|$ etc.

Parameters
KsSet of Kraus operators
Returns
Superoperator matrix
template<typename T >
dyn_mat<typename T::Scalar> qpp::kron ( const T &  head)

Kronecker product.

See also
qpp::kronpow()

Used to stop the recursion for the variadic template version of qpp::kron()

Parameters
headEigen expression
Returns
Its argument head
template<typename T , typename... Args>
dyn_mat<typename T::Scalar> qpp::kron ( const T &  head,
const Args &...  tail 
)

Kronecker product.

See also
qpp::kronpow()
Parameters
headEigen expression
tailVariadic Eigen expression (zero or more parameters)
Returns
Kronecker product of all input parameters, evaluated from left to right, as a dynamic matrix over the same scalar field as its arguments
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::kron ( const std::vector< Derived > &  As)

Kronecker product.

See also
qpp::kronpow()
Parameters
Asstd::vector of Eigen expressions
Returns
Kronecker product of all elements in As, evaluated from left to right, as a dynamic matrix over the same scalar field as its arguments
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::kron ( const std::initializer_list< Derived > &  As)

Kronecker product.

See also
qpp::kronpow()
Parameters
Asstd::initializer_list of Eigen expressions, such as {A1, A2, ... ,Ak}
Returns
Kronecker product of all elements in As, evaluated from left to right, as a dynamic matrix over the same scalar field as its arguments
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::kronpow ( const Eigen::MatrixBase< Derived > &  A,
idx  n 
)

Kronecker power.

See also
qpp::kron()
Parameters
AEigen expression
nNon-negative integer
Returns
Kronecker product of A with itself n times $A^{\otimes n}$, as a dynamic matrix over the same scalar field as A
bigint qpp::lcm ( bigint  m,
bigint  n 
)
inline

Least common multiple of two integers.

See also
qpp::gcd()
Parameters
mInteger
nInteger
Returns
Least common multiple of m and n
bigint qpp::lcm ( const std::vector< bigint > &  ns)
inline

Least common multiple of a list of integers.

See also
qpp::gcd()
Parameters
nsList of integers
Returns
Least common multiple of all numbers in ns
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::load ( const std::string &  fname)

Loads Eigen matrix from a binary file (internal format) in double precision.

See also
qpp::save()

The template parameter cannot be automatically deduced and must be explicitly provided, depending on the scalar field of the matrix that is being loaded.

Example:

// loads a previously saved Eigen dynamic complex matrix from "input.bin"
auto mat = load<cmat>("input.bin");
Parameters
AEigen expression
fnameOutput file name
template<typename Derived >
Derived qpp::loadMATLABmatrix ( const std::string &  ,
const std::string &   
)

Loads an Eigen dynamic matrix from a MATLAB .mat file, generic version.

See also
qpp::saveMATLABmatrix()

This is the generic version that always throws qpp::Exception::Type::UNDEFINED_TYPE. It is specialized only for qpp::dmat and qpp::cmat (the only matrix types that can be loaded)

template<>
dmat qpp::loadMATLABmatrix ( const std::string &  mat_file,
const std::string &  var_name 
)
inline

Loads an Eigen dynamic matrix from a MATLAB .mat file, specialization for double matrices (qpp::dmat)

See also
qpp::saveMATLABmatrix()

The template parameter cannot be automatically deduced and must be explicitly provided

Example:

// loads a previously saved Eigen dynamic double matrix
// from the MATLAB file "input.mat"
auto mat = loadMATLABmatrix<dmat>("input.mat");
Note
If var_name is a complex matrix, only the real part is loaded
Parameters
mat_fileMATALB .mat file
var_nameVariable name in the .mat file representing the matrix to be loaded
Returns
Eigen double dynamic matrix (qpp::dmat)
template<>
cmat qpp::loadMATLABmatrix ( const std::string &  mat_file,
const std::string &  var_name 
)
inline

Loads an Eigen dynamic matrix from a MATLAB .mat file, specialization for complex matrices (qpp::cmat)

See also
qpp::saveMATLABmatrix()

The template parameter cannot be automatically deduced and must be explicitly provided

Example:

// loads a previously saved Eigen dynamic complex matrix
// from the MATLAB file "input.mat"
auto mat = loadMATLABmatrix<cmat>("input.mat");
Parameters
mat_fileMATALB .mat file
var_nameVariable name in the .mat file representing the matrix to be loaded
Returns
Eigen complex dynamic matrix (qpp::cmat)
template<typename Derived >
Derived::Scalar qpp::logdet ( const Eigen::MatrixBase< Derived > &  A)

Logarithm of the determinant.

Useful when the determinant overflows/underflows

Parameters
AEigen expression
Returns
Logarithm of the determinant of A, as a scalar over the same scalar field as A
template<typename Derived >
cmat qpp::logm ( const Eigen::MatrixBase< Derived > &  A)

Matrix logarithm.

Parameters
AEigen expression
Returns
Matrix logarithm of A
template<typename Derived >
double qpp::lognegativity ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  dims 
)

Logarithmic negativity of the bi-partite mixed state A.

Parameters
AEigen expression
dimsDimensions of the bi-partite system
Returns
Logarithmic negativity, with the logarithm in base 2
std::vector<double> qpp::marginalX ( const dmat probXY)
inline

Marginal distribution.

Parameters
probXYReal matrix representing the joint probability distribution of X and Y in lexicographical order (X labels the rows, Y labels the columns)
Returns
Real vector consisting of the marginal distribution of X
std::vector<double> qpp::marginalY ( const dmat probXY)
inline

Marginal distribution.

Parameters
probXYReal matrix representing the joint probability distribution of X and Y in lexicographical order (X labels the rows, Y labels the columns)
Returns
Real vector consisting of the marginal distribution of Y
template<typename Derived >
std::tuple<idx, std::vector<double>, std::vector<cmat> > qpp::measure ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< cmat > &  Ks 
)

Measures the state A using the set of Kraus operators Ks.

Parameters
AEigen expression
KsSet of Kraus operators
Returns
Tuple of: 1. Result of the measurement, 2. Vector of outcome probabilities, and 3. Vector of post-measurement normalized states
template<typename Derived >
std::tuple<idx, std::vector<double>, std::vector<cmat> > qpp::measure ( const Eigen::MatrixBase< Derived > &  A,
const std::initializer_list< cmat > &  Ks 
)

Measures the state A using the set of Kraus operators Ks.

Parameters
AEigen expression
KsSet of Kraus operators
Returns
Tuple of: 1. Result of the measurement, 2. Vector of outcome probabilities, and 3. Vector of post-measurement normalized states
template<typename Derived >
std::tuple<idx, std::vector<double>, std::vector<cmat> > qpp::measure ( const Eigen::MatrixBase< Derived > &  A,
const cmat U 
)

Measures the state A in the orthonormal basis specified by the unitary matrix U.

Parameters
AEigen expression
UUnitary matrix whose columns represent the measurement basis vectors
Returns
Tuple of: 1. Result of the measurement, 2. Vector of outcome probabilities, and 3. Vector of post-measurement normalized states
template<typename Derived >
std::tuple<idx, std::vector<double>, std::vector<cmat> > qpp::measure ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< cmat > &  Ks,
const std::vector< idx > &  subsys,
const std::vector< idx > &  dims 
)

Measures the part subsys of the multi-partite state vector or density matrix A using the set of Kraus operators Ks.

See also
qpp::measure_seq()
Note
The dimension of all Ks must match the dimension of subsys. The measurement is destructive, i.e. the measured subsystems are traced away.
Parameters
AEigen expression
KsSet of Kraus operators
subsysSubsystem indexes that are measured
dimsDimensions of the multi-partite system
Returns
Tuple of: 1. Result of the measurement, 2. Vector of outcome probabilities, and 3. Vector of post-measurement normalized states
template<typename Derived >
std::tuple<idx, std::vector<double>, std::vector<cmat> > qpp::measure ( const Eigen::MatrixBase< Derived > &  A,
const std::initializer_list< cmat > &  Ks,
const std::vector< idx > &  subsys,
const std::vector< idx > &  dims 
)

Measures the part subsys of the multi-partite state vector or density matrix A using the set of Kraus operators Ks.

See also
qpp::measure_seq()
Note
The dimension of all Ks must match the dimension of subsys. The measurement is destructive, i.e. the measured subsystems are traced away.
Parameters
AEigen expression
KsSet of Kraus operators
subsysSubsystem indexes that are measured
dimsDimensions of the multi-partite system
Returns
Tuple of: 1. Result of the measurement, 2. Vector of outcome probabilities, and 3. Vector of post-measurement normalized states
template<typename Derived >
std::tuple<idx, std::vector<double>, std::vector<cmat> > qpp::measure ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< cmat > &  Ks,
const std::vector< idx > &  subsys,
idx  d = 2 
)

Measures the part subsys of the multi-partite state vector or density matrix A using the set of Kraus operators Ks.

See also
qpp::measure_seq()
Note
The dimension of all Ks must match the dimension of subsys. The measurement is destructive, i.e. the measured subsystems are traced away.
Parameters
AEigen expression
KsSet of Kraus operators
subsysSubsystem indexes that are measured
dSubsystem dimensions
Returns
Tuple of: 1. Result of the measurement, 2. Vector of outcome probabilities, and 3. Vector of post-measurement normalized states
template<typename Derived >
std::tuple<idx, std::vector<double>, std::vector<cmat> > qpp::measure ( const Eigen::MatrixBase< Derived > &  A,
const std::initializer_list< cmat > &  Ks,
const std::vector< idx > &  subsys,
idx  d = 2 
)

Measures the part subsys of the multi-partite state vector or density matrix A using the set of Kraus operators Ks.

See also
qpp::measure_seq()
Note
The dimension of all Ks must match the dimension of subsys. The measurement is destructive, i.e. the measured subsystems are traced away.
Parameters
AEigen expression
KsSet of Kraus operators
subsysSubsystem indexes that are measured
dSubsystem dimensions
Returns
Tuple of: 1. Result of the measurement, 2. Vector of outcome probabilities, and 3. Vector of post-measurement normalized states
template<typename Derived >
std::tuple<idx, std::vector<double>, std::vector<cmat> > qpp::measure ( const Eigen::MatrixBase< Derived > &  A,
const cmat V,
const std::vector< idx > &  subsys,
const std::vector< idx > &  dims 
)

Measures the part subsys of the multi-partite state vector or density matrix A in the orthonormal basis or rank-1 POVM specified by the matrix V.

See also
qpp::measure_seq()
Note
The dimension of V must match the dimension of subsys. The measurement is destructive, i.e. the measured subsystems are traced away.
Parameters
AEigen expression
VMatrix whose columns represent the measurement basis vectors or the bra parts of the rank-1 POVM
subsysSubsystem indexes that are measured
dimsDimensions of the multi-partite system
Returns
Tuple of: 1. Result of the measurement, 2. Vector of outcome probabilities, and 3. Vector of post-measurement normalized states
template<typename Derived >
std::tuple<idx, std::vector<double>, std::vector<cmat> > qpp::measure ( const Eigen::MatrixBase< Derived > &  A,
const cmat V,
const std::vector< idx > &  subsys,
idx  d = 2 
)

Measures the part subsys of the multi-partite state vector or density matrix A in the orthonormal basis or rank-1 POVM specified by the matrix V.

See also
qpp::measure_seq()
Note
The dimension of V must match the dimension of subsys. The measurement is destructive, i.e. the measured subsystems are traced away.
Parameters
AEigen expression
VMatrix whose columns represent the measurement basis vectors or the bra parts of the rank-1 POVM
subsysSubsystem indexes that are measured
dSubsystem dimensions
Returns
Tuple of: 1. Result of the measurement, 2. Vector of outcome probabilities, and 3. Vector of post-measurement normalized states
template<typename Derived >
std::tuple<std::vector<idx>, double, cmat> qpp::measure_seq ( const Eigen::MatrixBase< Derived > &  A,
std::vector< idx subsys,
std::vector< idx dims 
)

Sequentially measures the part subsys of the multi-partite state vector or density matrix A in the computational basis.

See also
qpp::measure()
Parameters
AEigen expression
subsysSubsystem indexes that are measured
dimsDimensions of the multi-partite system
Returns
Tuple of: 1. Vector of outcome results of the measurement (ordered in increasing order with respect to subsys, i.e. first measurement result corresponds to the subsystem with the smallest index), 2. Outcome probability, and 3. Post-measurement normalized state
template<typename Derived >
std::tuple<std::vector<idx>, double, cmat> qpp::measure_seq ( const Eigen::MatrixBase< Derived > &  A,
std::vector< idx subsys,
idx  d = 2 
)

Sequentially measures the part subsys of the multi-partite state vector or density matrix A in the computational basis.

See also
qpp::measure()
Parameters
AEigen expression
subsysSubsystem indexes that are measured
dSubsystem dimensions
Returns
Tuple of: 1. Vector of outcome results of the measurement (ordered in increasing order with respect to subsys, i.e. first measurement result corresponds to the subsystem with the smallest index), 2. Outcome probability, and 3. Post-measurement normalized state
ket qpp::mket ( const std::vector< idx > &  mask,
const std::vector< idx > &  dims 
)
inline

Multi-partite qudit ket.

Constructs the multi-partite qudit ket $|\mathrm{mask}\rangle$, where mask is a std::vector of non-negative integers. Each element in mask has to be smaller than the corresponding element in dims.

Parameters
maskstd::vector of non-negative integers
dimsDimensions of the multi-partite system
Returns
Multi-partite qudit state vector, as a complex dynamic column vector
ket qpp::mket ( const std::vector< idx > &  mask,
idx  d = 2 
)
inline

Multi-partite qudit ket.

Constructs the multi-partite qudit ket $|\mathrm{mask}\rangle$, all subsystem having equal dimension d. mask is a std::vector of non-negative integers, and each element in mask has to be strictly smaller than d.

Parameters
maskstd::vector of non-negative integers
dSubsystem dimensions
Returns
Multi-partite qudit state vector, as a complex dynamic column vector
bigint qpp::modinv ( bigint  a,
bigint  p 
)
inline

Modular inverse of a mod p.

See also
qpp::egcd()
Note
a and p must be co-prime
Parameters
mNon-negative integer
pNon-negative integer
Returns
Modular inverse $a^{-1}$ of a mod p
bigint qpp::modpow ( bigint  a,
bigint  n,
bigint  p 
)
inline

Fast integer power modulo p based on the SQUARE-AND-MULTIPLY algorithm.

Computes $a^n \mathrm{ mod } p$

Parameters
aNon-negative integer
nNon-negative integer
pStrictly positive integer
Returns
$a^n\mathrm{ mod }p$
cmat qpp::mprj ( const std::vector< idx > &  mask,
const std::vector< idx > &  dims 
)
inline

Projector onto multi-partite qudit ket.

Constructs the projector onto the multi-partite qudit ket $|\mathrm{mask}\rangle$, where mask is a std::vector of non-negative integers. Each element in mask has to be smaller than the corresponding element in dims.

Parameters
maskstd::vector of non-negative integers
dimsDimensions of the multi-partite system
Returns
Projector onto multi-partite qudit state vector, as a complex dynamic matrix
cmat qpp::mprj ( const std::vector< idx > &  mask,
idx  d = 2 
)
inline

Projector onto multi-partite qudit ket.

Constructs the projector onto the multi-partite qudit ket $|\mathrm{mask}\rangle$, all subsystem having equal dimension d. mask is a std::vector of non-negative integers, and each element in mask has to be strictly smaller than d.

Parameters
maskstd::vector of non-negative integers
dSubsystem dimensions
Returns
Projector onto multi-partite qudit state vector, as a complex dynamic matrix
idx qpp::multiidx2n ( const std::vector< idx > &  midx,
const std::vector< idx > &  dims 
)
inline

Multi-index to non-negative integer index.

See also
qpp::n2multiidx()

Uses standard lexicographical order, i.e. 00...0, 00...1 etc.

Parameters
midxMulti-index
dimsDimensions of the multi-partite system
Returns
Non-negative integer index
std::vector<idx> qpp::n2multiidx ( idx  n,
const std::vector< idx > &  dims 
)
inline

Non-negative integer index to multi-index.

See also
qpp::multiidx2n()

Uses standard lexicographical order, i.e. 00...0, 00...1 etc.

Parameters
nNon-negative integer index
dimsDimensions of the multi-partite system
Returns
Multi-index of the same size as dims
template<typename Derived >
double qpp::negativity ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  dims 
)

Negativity of the bi-partite mixed state A.

Parameters
AEigen expression
dimsDimensions of the bi-partite system
Returns
Negativity
template<typename Derived >
double qpp::norm ( const Eigen::MatrixBase< Derived > &  A)

Frobenius norm.

Parameters
AEigen expression
Returns
Frobenius norm of A
cplx qpp::omega ( idx  D)
inline

D-th root of unity.

Parameters
DNon-negative integer
Returns
D-th root of unity $\exp(2\pi i/D)$
constexpr cplx qpp::operator""_i ( unsigned long long int  x)
inlinenoexcept

User-defined literal for complex $i=\sqrt{-1}$ (integer overload)

Example:

auto z = 4_i; // type of z is std::complex<double>
constexpr cplx qpp::operator""_i ( long double  x)
inlinenoexcept

User-defined literal for complex $i=\sqrt{-1}$ (real overload)

Example:

auto z = 4.5_i; // type of z is std::complex<double>
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::powm ( const Eigen::MatrixBase< Derived > &  A,
idx  n 
)

Matrix power.

See also
qpp::spectralpowm()

Explicitly multiplies the matrix A with itself n times. By convention $A^0 = I$.

Parameters
AEigen expression
nNon-negative integer
Returns
Matrix power $A^n$, as a dynamic matrix over the same scalar field as A
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::prj ( const Eigen::MatrixBase< Derived > &  V)

Projector.

Normalized projector onto state vector

Parameters
VEigen expression
Returns
Projector onto the state vector V, or the matrix Zero if V has norm zero (i.e. smaller than qpp::eps), as a dynamic matrix over the same scalar field as A
template<typename Derived >
Derived::Scalar qpp::prod ( const Eigen::MatrixBase< Derived > &  A)

Element-wise product of A.

Parameters
AEigen expression
Returns
Element-wise product of A, as a scalar over the same scalar field as A
template<typename InputIterator >
std::iterator_traits<InputIterator>::value_type qpp::prod ( InputIterator  first,
InputIterator  last 
)

Element-wise product of an STL-like range.

Parameters
firstIterator to the first element of the range
lastIterator to the last element of the range
Returns
Element-wise product of the range, as a scalar over the same scalar field as the range
template<typename Container >
Container::value_type qpp::prod ( const Container &  c,
typename std::enable_if< is_iterable< Container >::value >::type *  = nullptr 
)

Element-wise product of the elements of an STL-like container.

Parameters
cSTL-like container
Returns
Element-wise product of the elements of the container, as a scalar over the same scalar field as the container
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::ptrace ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  subsys,
const std::vector< idx > &  dims 
)

Partial trace.

See also
qpp::ptrace1(), qpp::ptrace2()

Partial trace of the multi-partite state vector or density matrix over a list of subsystems

Parameters
AEigen expression
subsysSubsystem indexes
dimsDimensions of the multi-partite system
Returns
Partial trace $Tr_{subsys}(\cdot)$ over the subsytems subsys in a multi-partite system, as a dynamic matrix over the same scalar field as A
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::ptrace ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  subsys,
idx  d = 2 
)

Partial trace.

See also
qpp::ptrace1(), qpp::ptrace2()

Partial trace of the multi-partite state vector or density matrix over a list of subsystems

Parameters
AEigen expression
subsysSubsystem indexes
dSubsystem dimensions
Returns
Partial trace $Tr_{subsys}(\cdot)$ over the subsytems subsys in a multi-partite system, as a dynamic matrix over the same scalar field as A
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::ptrace1 ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  dims 
)

Partial trace.

See also
qpp::ptrace2()

Partial trace over the first subsystem of bi-partite state vector or density matrix

Parameters
AEigen expression
dimsDimensions of the bi-partite system (must be a std::vector with 2 elements)
Returns
Partial trace $Tr_{A}(\cdot)$ over the first subsytem $A$ in a bi-partite system $A\otimes B$, as a dynamic matrix over the same scalar field as A
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::ptrace2 ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  dims 
)

Partial trace.

See also
qpp::ptrace1()

Partial trace over the second subsystem of bi-partite state vector or density matrix

Parameters
AEigen expression
dimsDimensions of the bi-partite system (must be a std::vector with 2 elements)
Returns
Partial trace $Tr_{B}(\cdot)$ over the second subsytem $B$ in a bi-partite system $A\otimes B$, as a dynamic matrix over the same scalar field as A
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::ptranspose ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  subsys,
const std::vector< idx > &  dims 
)

Partial transpose.

Partial transpose of the multi-partite state vector or density matrix over a list of subsystems

Parameters
AEigen expression
subsysSubsystem indexes
dimsDimensions of the multi-partite system
Returns
Partial transpose $(\cdot)^{T_{subsys}}$ over the subsytems subsys in a multi-partite system, as a dynamic matrix over the same scalar field as A
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::ptranspose ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  subsys,
idx  d = 2 
)

Partial transpose.

Partial transpose of the multi-partite state vector or density matrix over a list of subsystems

Parameters
AEigen expression
subsysSubsystem indexes
dSubsystem dimensions
Returns
Partial transpose $(\cdot)^{T_{subsys}}$ over the subsytems subsys in a multi-partite system, as a dynamic matrix over the same scalar field as A
template<typename Derived >
double qpp::qmutualinfo ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  subsysA,
const std::vector< idx > &  subsysB,
const std::vector< idx > &  dims 
)

Quantum mutual information between 2 subsystems of a composite system.

Parameters
AEigen expression
subsysAIndexes of the first subsystem
subsysBIndexes of the second subsystem
dimsDimensions of the multi-partite system
Returns
Mutual information between the 2 subsystems
template<typename Derived >
double qpp::qmutualinfo ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  subsysA,
const std::vector< idx > &  subsysB,
idx  d = 2 
)

Quantum mutual information between 2 subsystems of a composite system.

Parameters
AEigen expression
subsysAIndexes of the first subsystem
subsysBIndexes of the second subsystem
dSubsystem dimensions
Returns
Mutual information between the 2 subsystems
double qpp::rand ( double  a = 0,
double  b = 1 
)
inline

Generates a random real number uniformly distributed in the interval [a, b)

Parameters
aBeginning of the interval, belongs to it
bEnd of the interval, does not belong to it
Returns
Random real number (double) uniformly distributed in the interval [a, b)
bigint qpp::rand ( bigint  a = std::numeric_limits<bigint>::min(),
bigint  b = std::numeric_limits<bigint>::max() 
)
inline

Generates a random big integer uniformly distributed in the interval [a, b].

Parameters
aBeginning of the interval, belongs to it
bEnd of the interval, belongs to it
Returns
Random big integer uniformly distributed in the interval [a, b]
ubigint qpp::rand ( ubigint  a = std::numeric_limits<ubigint>::min(),
ubigint  b = std::numeric_limits<ubigint>::max() 
)
inline

Generates a random non-negative big integer uniformly distributed in the interval [a, b].

Parameters
aBeginning of the interval, belongs to it
bEnd of the interval, belongs to it
Returns
Random non-negative big integer uniformly distributed in the interval [a, b]
template<typename Derived >
Derived qpp::rand ( idx  rows,
idx  cols,
double  a = 0,
double  b = 1 
)

Generates a random matrix with entries uniformly distributed in the interval [a, b)

If complex, then both real and imaginary parts are uniformly distributed in [a, b)

This is the generic version that always throws qpp::Exception::Type::UNDEFINED_TYPE. It is specialized only for qpp::dmat and qpp::cmat

template<>
dmat qpp::rand ( idx  rows,
idx  cols,
double  a,
double  b 
)
inline

Generates a random real matrix with entries uniformly distributed in the interval [a, b), specialization for double matrices (qpp::dmat)

The template parameter cannot be automatically deduced and must be explicitly provided

Example:

// generates a 3 x 3 random Eigen::MatrixXd,
// with entries uniformly distributed in [-1,1)
auto mat = rand<dmat>(3, 3, -1, 1);
Parameters
rowsNumber of rows of the random generated matrix
colsNumber of columns of the random generated matrix
aBeginning of the interval, belongs to it
bEnd of the interval, does not belong to it
Returns
Random real matrix
template<>
cmat qpp::rand ( idx  rows,
idx  cols,
double  a,
double  b 
)
inline

Generates a random complex matrix with entries (both real and imaginary) uniformly distributed in the interval [a, b), specialization for complex matrices (qpp::cmat)

The template parameter cannot be automatically deduced and must be explicitly provided

Example:

// generates a 3 x 3 random Eigen::MatrixXcd,
// with entries (both real and imaginary) uniformly distributed in [-1,1)
auto mat = rand<cmat>(3, 3, -1, 1);
Parameters
rowsNumber of rows of the random generated matrix
colsNumber of columns of the random generated matrix
aBeginning of the interval, belongs to it
bEnd of the interval, does not belong to it
Returns
Random complex matrix
cmat qpp::randH ( idx  D)
inline

Generates a random Hermitian matrix.

Parameters
DDimension of the Hilbert space
Returns
Random Hermitian matrix
idx qpp::randidx ( idx  a = std::numeric_limits<idx>::min(),
idx  b = std::numeric_limits<idx>::max() 
)
inline

Generates a random index (idx) uniformly distributed in the interval [a, b].

Parameters
aBeginning of the interval, belongs to it
bEnd of the interval, belongs to it
Returns
Random index (idx) uniformly distributed in the interval [a, b]
ket qpp::randket ( idx  D)
inline

Generates a random normalized ket (pure state vector)

Parameters
DDimension of the Hilbert space
Returns
Random normalized ket
std::vector<cmat> qpp::randkraus ( idx  N,
idx  D 
)
inline

Generates a set of random Kraus operators.

Note
The set of Kraus operators satisfy the closure condition $ \sum_i K_i^\dagger K_i = I$
Parameters
NNumber of Kraus operators
DDimension of the Hilbert space
Returns
Set of N Kraus operators satisfying the closure condition
template<typename Derived >
Derived qpp::randn ( idx  rows,
idx  cols,
double  mean = 0,
double  sigma = 1 
)

Generates a random matrix with entries normally distributed in N(mean, sigma)

If complex, then both real and imaginary parts are normally distributed in N(mean, sigma)

This is the generic version that always throws qpp::Exception::Type::UNDEFINED_TYPE. It is specialized only for qpp::dmat and qpp::cmat

template<>
dmat qpp::randn ( idx  rows,
idx  cols,
double  mean,
double  sigma 
)
inline

Generates a random real matrix with entries normally distributed in N(mean, sigma), specialization for double matrices (qpp::dmat)

The template parameter cannot be automatically deduced and must be explicitly provided

Example:

// generates a 3 x 3 random Eigen::MatrixXd,
// with entries normally distributed in N(0,2)
auto mat = randn<dmat>(3, 3, 0, 2);
Parameters
rowsNumber of rows of the random generated matrix
colsNumber of columns of the random generated matrix
meanMean
sigmaStandard deviation
Returns
Random real matrix
template<>
cmat qpp::randn ( idx  rows,
idx  cols,
double  mean,
double  sigma 
)
inline

Generates a random complex matrix with entries (both real and imaginary) normally distributed in N(mean, sigma), specialization for complex matrices (qpp::cmat)

The template parameter cannot be automatically deduced and must be explicitly provided

Example:

// generates a 3 x 3 random Eigen::MatrixXcd,
// with entries (both real and imaginary) normally distributed in N(0,2)
auto mat = randn<cmat>(3, 3, 0, 2);
Parameters
rowsNumber of rows of the random generated matrix
colsNumber of columns of the random generated matrix
meanMean
sigmaStandard deviation
Returns
Random complex matrix
double qpp::randn ( double  mean = 0,
double  sigma = 1 
)
inline

Generates a random real number (double) normally distributed in N(mean, sigma)

Parameters
meanMean
sigmaStandard deviation
Returns
Random real number normally distributed in N(mean, sigma)
std::vector<idx> qpp::randperm ( idx  n)
inline

Generates a random uniformly distributed permutation.

Uses Knuth shuffle method (as implemented by std::shuffle), so that all permutations are equally probable

Parameters
nSize of the permutation
Returns
Random permutation of size n
cmat qpp::randrho ( idx  D)
inline

Generates a random density matrix.

Parameters
DDimension of the Hilbert space
Returns
Random density matrix
cmat qpp::randU ( idx  D)
inline

Generates a random unitary matrix.

Parameters
DDimension of the Hilbert space
Returns
Random unitary
cmat qpp::randV ( idx  Din,
idx  Dout 
)
inline

Generates a random isometry matrix.

Parameters
DinSize of the input Hilbert space
DoutSize of the output Hilbert space
Returns
Random isometry matrix
template<typename Derived >
double qpp::renyi ( const Eigen::MatrixBase< Derived > &  A,
double  alpha 
)

Renyi- $\alpha$ entropy of the density matrix A, for $\alpha\geq 0$.

Note
When $ \alpha\to 1$ the Renyi entropy converges to the von-Neumann entropy, with the logarithm in base 2
Parameters
AEigen expression
alphaNon-negative real number, use qpp::infty for $\alpha = \infty$
Returns
Renyi- $\alpha$ entropy, with the logarithm in base 2
double qpp::renyi ( const std::vector< double > &  prob,
double  alpha 
)
inline

Renyi- $\alpha$ entropy of the probability distribution prob, for $\alpha\geq 0$.

Note
When $ \alpha\to 1$ the Renyi entropy converges to the Shannon entropy, with the logarithm in base 2
Parameters
probReal probability vector
alphaNon-negative real number, use qpp::infty for $\alpha = \infty$
Returns
Renyi- $\alpha$ entropy, with the logarithm in base 2
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::reshape ( const Eigen::MatrixBase< Derived > &  A,
idx  rows,
idx  cols 
)

Reshape.

Uses column-major order when reshaping (same as MATLAB)

Parameters
AEigen expression
rowsNumber of rows of the reshaped matrix
colsNumber of columns of the reshaped matrix
Returns
Reshaped matrix with rows rows and cols columns, as a dynamic matrix over the same scalar field as A
template<typename Derived >
std::vector<double> qpp::rho2bloch ( const Eigen::MatrixBase< Derived > &  A)

Computes the 3-dimensional real Bloch vector corresponding to the qubit density matrix A.

See also
qpp::bloch2rho()
Note
It is implicitly assumed that the density matrix is Hermitian
Parameters
AEigen expression
Returns
3-dimensional Bloch vector
template<typename Derived >
dyn_col_vect<typename Derived::Scalar> qpp::rho2pure ( const Eigen::MatrixBase< Derived > &  A)

Finds the pure state representation of a matrix proportional to a projector onto a pure state.

Note
No purity check is done, the input state A must have rank one, otherwise the function returns the first non-zero eigenvector of A
Parameters
AEigen expression, assumed to be proportional to a projector onto a pure state, i.e. A is assumed to have rank one
Returns
The unique non-zero eigenvector of A, as a dynamic column vector over the same scalar field as A
template<typename Derived >
void qpp::save ( const Eigen::MatrixBase< Derived > &  A,
const std::string &  fname 
)

Saves Eigen expression to a binary file (internal format) in double precision.

See also
qpp::load()
Parameters
AEigen expression
fnameOutput file name
template<typename Derived >
void qpp::saveMATLABmatrix ( const Eigen::MatrixBase< Derived > &  ,
const std::string &  ,
const std::string &  ,
const std::string &   
)

Saves an Eigen dynamic matrix to a MATLAB .mat file, generic version.

See also
qpp::loadMATLABmatrix()

This is the generic version that always throws qpp::Exception::Type::UNDEFINED_TYPE. It is specialized only for qpp::dmat and qpp::cmat (the only matrix types that can be saved)

template<>
void qpp::saveMATLABmatrix ( const Eigen::MatrixBase< dmat > &  A,
const std::string &  mat_file,
const std::string &  var_name,
const std::string &  mode 
)
inline

Saves an Eigen dynamic matrix to a MATLAB .mat file, specialization for double matrices (qpp::dmat)

See also
qpp::loadMATLABmatrix()
Parameters
AEigen expression over the complex field
mat_fileMATALB .mat file
var_nameVariable name in the .mat file representing the matrix to be saved
modeSaving mode (append, overwrite etc.), see MATLAB matOpen() documentation for details
template<>
void qpp::saveMATLABmatrix ( const Eigen::MatrixBase< cmat > &  A,
const std::string &  mat_file,
const std::string &  var_name,
const std::string &  mode 
)
inline

Saves an Eigen dynamic matrix to a MATLAB .mat file, specialization for complex matrices (qpp::cmat)

See also
qpp::loadMATLABmatrix()
Parameters
AEigen expression over the complex field
mat_fileMATALB .mat file
var_nameVariable name in the .mat file representing the matrix to be saved
modeSaving mode (append, overwrite etc.), see MATLAB matOpen() documentation for details
template<typename Derived >
double qpp::schatten ( const Eigen::MatrixBase< Derived > &  A,
double  p 
)

Schatten matrix norm.

Parameters
AEigen expression
pReal number, greater or equal to 1, use qpp::infty for $p = \infty$
Returns
Schatten-p matrix norm of A
template<typename Derived >
cmat qpp::schmidtA ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  dims 
)

Schmidt basis on Alice side.

Parameters
AEigen expression
dimsDimensions of the bi-partite system
Returns
Unitary matrix $ U $ whose columns represent the Schmidt basis vectors on Alice side.
template<typename Derived >
cmat qpp::schmidtB ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  dims 
)

Schmidt basis on Bob side.

Parameters
AEigen expression
dimsDimensions of the bi-partite system
Returns
Unitary matrix $ V $ whose columns represent the Schmidt basis vectors on Bob side.
template<typename Derived >
dyn_col_vect<double> qpp::schmidtcoeffs ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  dims 
)

Schmidt coefficients of the bi-partite pure state A.

Note
The sum of the squares of the Schmidt coefficients equals 1
See also
qpp::schmidtprobs()
Parameters
AEigen expression
dimsDimensions of the bi-partite system
Returns
Schmidt coefficients of A, as a real dynamic column vector
template<typename Derived >
std::vector<double> qpp::schmidtprobs ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  dims 
)

Schmidt probabilities of the bi-partite pure state A.

Defined as the squares of the Schmidt coefficients. The sum of the Schmidt probabilities equals 1.

See also
qpp::schmidtcoeffs()
Parameters
AEigen expression
dimsDimensions of the bi-partite system
Returns
Real vector consisting of the Schmidt probabilites of A
template<typename Container >
double qpp::sigma ( const std::vector< double > &  prob,
const Container &  X,
typename std::enable_if< is_iterable< Container >::value >::type *  = nullptr 
)

Standard deviation.

Parameters
probReal probability vector representing the probability distribution of X
XRandom variable values represented by an STL-like container
Returns
Standard deviation of X
template<typename Derived >
cmat qpp::sinm ( const Eigen::MatrixBase< Derived > &  A)

Matrix sin.

Parameters
AEigen expression
Returns
Matrix sine of A
template<typename Derived >
cmat qpp::spectralpowm ( const Eigen::MatrixBase< Derived > &  A,
const cplx  z 
)

Matrix power.

See also
qpp::powm()

Uses the spectral decomposition of A to compute the matrix power. By convention $A^0 = I$.

Parameters
AEigen expression
zComplex number
Returns
Matrix power $A^z$
template<typename Derived >
cmat qpp::sqrtm ( const Eigen::MatrixBase< Derived > &  A)

Matrix square root.

Parameters
AEigen expression
Returns
Matrix square root of A
template<typename Derived >
Derived::Scalar qpp::sum ( const Eigen::MatrixBase< Derived > &  A)

Element-wise sum of A.

Parameters
AEigen expression
Returns
Element-wise sum of A, as a scalar over the same scalar field as A
template<typename InputIterator >
std::iterator_traits<InputIterator>::value_type qpp::sum ( InputIterator  first,
InputIterator  last 
)

Element-wise sum of an STL-like range.

Parameters
firstIterator to the first element of the range
lastIterator to the last element of the range
Returns
Element-wise sum of the range, as a scalar over the same scalar field as the range
template<typename Container >
Container::value_type qpp::sum ( const Container &  c,
typename std::enable_if< is_iterable< Container >::value >::type *  = nullptr 
)

Element-wise sum of the elements of an STL-like container.

Parameters
cSTL-like container
Returns
Element-wise sum of the elements of the container, as a scalar over the same scalar field as the container
cmat qpp::super2choi ( const cmat A)
inline

Converts superoperator matrix to Choi matrix.

See also
qpp::choi2super()
Parameters
ASuperoperator matrix
Returns
Choi matrix
template<typename Derived >
dyn_col_vect<double> qpp::svals ( const Eigen::MatrixBase< Derived > &  A)

Singular values.

Parameters
AEigen expression
Returns
Singular values of A, ordered in decreasing order, as a real dynamic column vector
template<typename Derived >
std::tuple<cmat, dyn_col_vect < double>, cmat> qpp::svd ( const Eigen::MatrixBase< Derived > &  A)

Full singular value decomposition.

Parameters
AEigen expression
Returns
Tuple of: 1. Left sigular vectors of A, as columns of a complex dynamic matrix, 2. Singular values of A, ordered in decreasing order, as a real dynamic column vector, and 3. Right singular vectors of A, as columns of a complex dynamic matrix
template<typename Derived >
cmat qpp::svdU ( const Eigen::MatrixBase< Derived > &  A)

Left singular vectors.

Parameters
AEigen expression
Returns
Complex dynamic matrix, whose columns are the left singular vectors of A
template<typename Derived >
cmat qpp::svdV ( const Eigen::MatrixBase< Derived > &  A)

Right singular vectors.

Parameters
AEigen expression
Returns
Complex dynamic matrix, whose columns are the right singular vectors of A
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::syspermute ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  perm,
const std::vector< idx > &  dims 
)

Subsystem permutation.

Permutes the subsystems of a state vector or density matrix. The qubit perm[i] is permuted to the location i.

Parameters
AEigen expression
permPermutation
dimsDimensions of the multi-partite system
Returns
Permuted system, as a dynamic matrix over the same scalar field as A
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::syspermute ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  perm,
idx  d = 2 
)

Subsystem permutation.

Permutes the subsystems of a state vector or density matrix. The qubit perm[i] is permuted to the location i.

Parameters
AEigen expression
permPermutation
dSubsystem dimensions
Returns
Permuted system, as a dynamic matrix over the same scalar field as A
template<typename Derived >
Derived::Scalar qpp::trace ( const Eigen::MatrixBase< Derived > &  A)

Trace.

Parameters
AEigen expression
Returns
Trace of A, as a scalar over the same scalar field as A
template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::transpose ( const Eigen::MatrixBase< Derived > &  A)

Transpose.

Parameters
AEigen expression
Returns
Transpose of A, as a dynamic matrix over the same scalar field as A
template<typename Derived >
double qpp::tsallis ( const Eigen::MatrixBase< Derived > &  A,
double  q 
)

Tsallis- $q$ entropy of the density matrix A, for $q\geq 0$.

Note
When $ q\to 1$ the Tsallis entropy converges to the von-Neumann entropy, with the logarithm in base $ e $
Parameters
AEigen expression
qNon-negative real number
Returns
Tsallis- $q$ entropy
double qpp::tsallis ( const std::vector< double > &  prob,
double  q 
)
inline

Tsallis- $q$ entropy of the probability distribution prob, for $q\geq 0$.

Note
When $ q\to 1$ the Tsallis entropy converges to the Shannon entropy, with the logarithm in base $ e $
Parameters
probReal probability vector
qNon-negative real number
Returns
Tsallis- $q$ entropy
std::vector<double> qpp::uniform ( idx  N)
inline

Uniform probability distribution vector.

Parameters
NSize of the alphabet
Returns
Real vector consisting of a uniform distribution of size N
template<typename Container >
double qpp::var ( const std::vector< double > &  prob,
const Container &  X,
typename std::enable_if< is_iterable< Container >::value >::type *  = nullptr 
)

Variance.

Parameters
probReal probability vector representing the probability distribution of X
XRandom variable values represented by an STL-like container
Returns
Variance of X
std::vector<int> qpp::x2contfrac ( double  x,
idx  n,
idx  cut = 1e5 
)
inline

Simple continued fraction expansion.

See also
qpp::contfrac2x()
Parameters
xReal number
nMaximum number of terms in the expansion
cutStop the expansion when the next term is greater than cut
Returns
Integer vector containing the simple continued fraction expansion of x. If there are m less than n terms in the expansion, a shorter vector with m components is returned.

Variable Documentation

constexpr double qpp::chop = 1e-10

Used in qpp::disp() for setting to zero numbers that have their absolute value smaller than qpp::chop.

constexpr double qpp::ee = 2.718281828459045235360287471352662497

Base of natural logarithm, $e$.

constexpr double qpp::eps = 1e-12

Used to decide whether a number or expression in double precision is zero or not.

Example:

if(std::abs(x) < qpp::eps) // x is zero
constexpr double qpp::infty = std::numeric_limits<double>::infinity()

Used to denote infinity in double precision.

constexpr idx qpp::maxn = 64

Maximum number of allowed qu(d)its (subsystems)

Used internally to allocate arrays on the stack (for speed reasons)

constexpr double qpp::pi = 3.141592653589793238462643383279502884

$ \pi $