|
TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
|
#include <triqs/operators/many_body_operator.hpp>
Generic many-body operator.
A generic many-body operator \( \hat{O} \) is defined as a linear combination of monomials \( \hat{m}_i \) such that
\[ \hat{O} = \sum_{i} a_i \hat{m}_i \; , \]
where \( a_i \) are real or complex coefficients.
Under the hood, we simply store all individual terms in a map/dictionary with the monomials as keys and the coefficients as values.
Operator-operator and operator-scalar arithmetic is supported such that many-body operators form an algebra over the field of real/complex numbers with an extra addition operation between operators and scalars.
| T | Value type of the coefficients. |
Definition at line 230 of file many_body_operator.hpp.
Public Types | |
| using | const_iterator = utility::dressed_iterator<typename monomials_map_t::const_iterator, _cdress> |
| Constant iterator type yielding (monomial, coefficient) pairs. | |
| using | monomials_map_t = std::map<monomial_t, T> |
| Container type for monomials and their coefficients. | |
| using | scalar_t = T |
| Value type of the coefficients (either real, complex or real_or_complex). | |
Public Member Functions | |
| many_body_operator_generic ()=default | |
| Default constructor creates a zero many-body operator, i.e. with no terms. | |
| template<typename S> | |
| many_body_operator_generic (many_body_operator_generic< S > const &p) | |
| Construct a many-body operator from another many-body operator with a different coefficient type. | |
| many_body_operator_generic (scalar_t const &x) | |
| Construct a many-body operator \( \hat{O} = a \hat{I} \). | |
| many_body_operator_generic (scalar_t const &x, monomial_t monomial) | |
| Construct a many-body operator \( \hat{O} = a \hat{m} \). | |
| const_iterator | begin () const noexcept |
| Get a const iterator to the beginning of the map that contains the monomials and their coefficients. | |
| const_iterator | cbegin () const noexcept |
| Get a const iterator to the beginning of the map that contains the monomials and their coefficients. | |
| const_iterator | cend () const noexcept |
| Get a const iterator past the end of the map that contains the monomials and their coefficients. | |
| void | deserialize (auto &ar) |
| Deserialize the many-body operator from a generic archive. | |
| const_iterator | end () const noexcept |
| Get a const iterator past the end of the map that contains the monomials and their coefficients. | |
| monomials_map_t const & | get_monomials () const |
| Get the map/dictionary of monomials and their coefficients. | |
| many_body_operator_generic | imag () const |
| Get a copy of the operator \( \hat{O} \) with the real parts of all monomial coefficients set to zero. | |
| bool | is_almost_zero (double precision=1e-10) const |
| Check if the current operator \( \hat{O} \) is close to zero. | |
| bool | is_zero () const |
| Check if the current operator \( \hat{O} \) is exactly zero. | |
| hilbert_space::fundamental_operator_set | make_fundamental_operator_set () const |
| Create a minimal fundamental operator set with all single particle state indices \( \alpha_i \) that appear in the monomials of this operator. | |
| many_body_operator_generic & | operator*= (many_body_operator_generic const &op) |
| Multiplication assignment operator to multiply the current many-body operator \( \hat{O} \) by another many-body operator \( \hat{P} \). | |
| many_body_operator_generic & | operator*= (scalar_t a) |
| Multiplication assignment operator to multiply the current many-body operator \( \hat{O} \) by a scalar \( a \). | |
| many_body_operator_generic & | operator+= (many_body_operator_generic const &op) |
| Addition assignment operator to add the many-body operator \( \hat{P} \) to the current many-body operator \( \hat{O} \). | |
| many_body_operator_generic & | operator+= (scalar_t a) |
| Addition assignment operator to add a scalar \( a \) to the current many-body operator \( \hat{O} \). | |
| many_body_operator_generic | operator- () const |
| Unary minus operator to negate the current many-body operator \( \hat{O} \). | |
| many_body_operator_generic & | operator-= (many_body_operator_generic const &op) |
| Subtraction assignment operator to subtract the many-body operator \( \hat{P} \) from the current many-body operator \( \hat{O} \). | |
| many_body_operator_generic & | operator-= (scalar_t a) |
| Subtraction assignment operator to subtract a scalar \( a \) from the current many-body operator \( \hat{O} \). | |
| many_body_operator_generic & | operator/= (scalar_t a) |
| Division assignment operator to divide the current many-body operator \( \hat{O} \) by a scalar \( a \). | |
| template<typename S> | |
| many_body_operator_generic & | operator= (many_body_operator_generic< S > const &p) |
| Assignment operator from a many-body operator with a different coefficient type. | |
| bool | operator== (many_body_operator_generic const &op) const |
| Equality operator to compare two many-body operators. | |
| many_body_operator_generic | real () const |
| Get a copy of the operator \( \hat{O} \) with the imaginary parts of all monomial coefficients set to zero. | |
| void | serialize (auto &ar) const |
| Serialize the many-body operator to a generic archive. | |
Static Public Member Functions | |
| static std::string | hdf5_format () |
| HDF5 format tag of the many-body operator. | |
| static many_body_operator_generic | make_canonical (bool is_dag, indices_t indices) |
| Create a many-body operator that represents a single canonical operator \( \hat{c}_{\alpha} \) or \( \hat{c}_{\alpha}^{\dagger} \). | |
Friends | |
| many_body_operator_generic | dagger (many_body_operator_generic const &op) |
| Compute the Hermitian conjugate (dagger) of the many-body operator \( \hat{O} \). | |
| void | h5_read (h5::group g, std::string const &name, many_body_operator &op, hilbert_space::fundamental_operator_set &fops) |
| Read a triqs::operators::many_body_operator together with a triqs::hilbert_space::fundamental_operator_set from HDF5. | |
| void | h5_read (h5::group g, std::string const &name, many_body_operator_generic &op) |
| Read a triqs::operators::many_body_operator_generic from HDF5. | |
| void | h5_write (h5::group g, std::string const &name, many_body_operator const &op, hilbert_space::fundamental_operator_set const &fops) |
| Write a triqs::operators::many_body_operator together with a triqs::hilbert_space::fundamental_operator_set to HDF5. | |
| void | h5_write (h5::group g, std::string const &name, many_body_operator_generic const &op) |
| Write a triqs::operators::many_body_operator_generic to HDF5. | |
| many_body_operator_generic | operator* (many_body_operator_generic lhs, many_body_operator_generic const &rhs) |
| Product of two many-body operators \( \hat{O} \) and \( \hat{P} \) (Fock-space operator product). | |
| many_body_operator_generic | operator* (many_body_operator_generic op, scalar_t a) |
| Multiply a many-body operator \( \hat{O} \) by a scalar \( a \) on the right. | |
| many_body_operator_generic | operator* (scalar_t a, many_body_operator_generic op) |
| Multiply a many-body operator \( \hat{O} \) by a scalar \( a \) on the left. | |
| many_body_operator_generic | operator+ (many_body_operator_generic lhs, many_body_operator_generic const &rhs) |
| Sum of two many-body operators \( \hat{O} \) and \( \hat{P} \). | |
| many_body_operator_generic | operator+ (many_body_operator_generic op, scalar_t a) |
| Add a scalar \( a \) to a many-body operator \( \hat{O} \). | |
| many_body_operator_generic | operator+ (scalar_t a, many_body_operator_generic op) |
| Add a many-body operator \( \hat{O} \) to a scalar \( a \). | |
| many_body_operator_generic | operator- (many_body_operator_generic lhs, many_body_operator_generic const &rhs) |
| Difference of two many-body operators \( \hat{O} \) and \( \hat{P} \). | |
| many_body_operator_generic | operator- (many_body_operator_generic op, scalar_t a) |
| Subtract a scalar \( a \) from a many-body operator \( \hat{O} \). | |
| many_body_operator_generic | operator- (scalar_t a, many_body_operator_generic const &op) |
| Subtract a many-body operator \( \hat{O} \) from a scalar \( a \). | |
| many_body_operator_generic | operator/ (many_body_operator_generic op, scalar_t a) |
| Divide a many-body operator \( \hat{O} \) by a scalar \( a \). | |
| std::ostream & | operator<< (std::ostream &os, many_body_operator_generic const &op) |
| Write a triqs::operators::many_body_operator_generic to a std::ostream. | |
| template<typename F> | |
| many_body_operator_generic | transform (many_body_operator_generic const &op, F &&f) |
| Transform the coefficients of an operator \( \hat{O} \) using a callable object. | |
|
inline |
Construct a many-body operator from another many-body operator with a different coefficient type.
Calls operator=() to assign all terms of the other operator to the new operator. The scalar type scalar_t must be constructible from S.
| S | Scalar type of the source operator. |
| p | Source many-body operator. |
Definition at line 250 of file many_body_operator.hpp.
|
inlineexplicit |
Construct a many-body operator \( \hat{O} = a \hat{I} \).
| x | Coefficient \( a \) of the identity operator \( \hat{I} \). |
Definition at line 260 of file many_body_operator.hpp.
|
inline |
Construct a many-body operator \( \hat{O} = a \hat{m} \).
| x | Coefficient \( a \) of the monomial. |
| monomial | Monomial \( \hat{m} \). |
Definition at line 271 of file many_body_operator.hpp.
|
inline |
Deserialize the many-body operator from a generic archive.
| ar | Archive to deserialize from. |
Definition at line 719 of file many_body_operator.hpp.
|
inlinenodiscard |
Check if the current operator \( \hat{O} \) is close to zero.
| precision | Tolerance \( \epsilon \) for considering a coefficient to be zero. |
Definition at line 362 of file many_body_operator.hpp.
|
inlinenodiscard |
Check if the current operator \( \hat{O} \) is exactly zero.
Definition at line 374 of file many_body_operator.hpp.
|
inlinestatic |
Create a many-body operator that represents a single canonical operator \( \hat{c}_{\alpha} \) or \( \hat{c}_{\alpha}^{\dagger} \).
| is_dag | Boolean flag indicating whether to create a creation (true) or annihilation (false) operator. |
| indices | Single particle state index \( \alpha \). |
Definition at line 320 of file many_body_operator.hpp.
|
inlinenodiscard |
Create a minimal fundamental operator set with all single particle state indices \( \alpha_i \) that appear in the monomials of this operator.
Definition at line 305 of file many_body_operator.hpp.
|
inline |
Multiplication assignment operator to multiply the current many-body operator \( \hat{O} \) by another many-body operator \( \hat{P} \).
Computes the product \( \hat{O} \times \hat{P} \) using the distributive property of operator multiplication.
All generated monomials are normalized, i.e. sorted according to the order defined by canonical_ops_t::operator<=>(), using fermionic anti-commutation relations and added to the resulting operator. If a monomial is already present in the resulting operator, their coefficients are added together.
All terms with vanishing coefficients are removed.
| op | Right hand side many-body operator \( \hat{P} \). |
Definition at line 580 of file many_body_operator.hpp.
|
inline |
Multiplication assignment operator to multiply the current many-body operator \( \hat{O} \) by a scalar \( a \).
Multiplies all coefficients \( a_i \) of the operator \( \hat{O} \) by the given scalar \( a \). If \( a = 0 \), the operator is set to zero (i.e. all terms are removed).
| a | Scalar \( a \). |
Definition at line 430 of file many_body_operator.hpp.
|
inline |
Addition assignment operator to add the many-body operator \( \hat{P} \) to the current many-body operator \( \hat{O} \).
Adds all terms of \( \hat{P} \) to the current operator \( \hat{O} \). If a monomial is already present in \( \hat{O} \), their coefficients are added; otherwise a new term is created. All terms with vanishing coefficients are removed.
| op | Right hand side many-body operator \( \hat{P} \). |
Definition at line 527 of file many_body_operator.hpp.
|
inline |
Addition assignment operator to add a scalar \( a \) to the current many-body operator \( \hat{O} \).
If the term with the empty monomial \( \hat{m} = \hat{I} \) (the identity operator) is already present, the given scalar \( a \) is added to its coefficient. Otherwise, a new term \( a \hat{I} \) is created and added to \( \hat{O} \).
| a | Scalar \( a \). |
Definition at line 396 of file many_body_operator.hpp.
|
inline |
Unary minus operator to negate the current many-body operator \( \hat{O} \).
Definition at line 380 of file many_body_operator.hpp.
|
inline |
Subtraction assignment operator to subtract the many-body operator \( \hat{P} \) from the current many-body operator \( \hat{O} \).
Subtracts all terms of \( \hat{P} \) from the current operator \( \hat{O} \). If a monomial is already present in \( \hat{O} \), their coefficients are subtracted. All terms with vanishing coefficients are removed.
| op | Right hand side many-body operator \( \hat{P} \). |
Definition at line 551 of file many_body_operator.hpp.
|
inline |
Subtraction assignment operator to subtract a scalar \( a \) from the current many-body operator \( \hat{O} \).
Equivalent to operator+=(-a).
| a | Scalar \( a \). |
Definition at line 418 of file many_body_operator.hpp.
|
inline |
Division assignment operator to divide the current many-body operator \( \hat{O} \) by a scalar \( a \).
It calls operator*=() with \( 1 / a \).
| a | Scalar \( a \). |
Definition at line 449 of file many_body_operator.hpp.
|
inline |
Assignment operator from a many-body operator with a different coefficient type.
Clears the current operator and copies all monomials from the source, converting each coefficient to scalar_t. The scalar type scalar_t must be constructible from S.
| S | Scalar type of the source operator. |
| p | Source many-body operator. |
Definition at line 289 of file many_body_operator.hpp.
|
inline |
Equality operator to compare two many-body operators.
Checks whether the difference \( \hat{O} - \hat{P} \) is exactly zero.
| op | Right hand side many-body operator \( \hat{P} \). |
Definition at line 629 of file many_body_operator.hpp.
|
inline |
Serialize the many-body operator to a generic archive.
| ar | Archive to serialize to. |
Definition at line 713 of file many_body_operator.hpp.
|
friend |
Compute the Hermitian conjugate (dagger) of the many-body operator \( \hat{O} \).
Computes the Hermitian conjugate by reversing the order of the canonical operators in each monomial and flipping their dagger flag. The coefficients are complex conjugated.
| op | Many-body operator \( \hat{O} \). |
Definition at line 651 of file many_body_operator.hpp.
|
friend |
Read a triqs::operators::many_body_operator together with a triqs::hilbert_space::fundamental_operator_set from HDF5.
| g | h5::group to be read from. |
| name | Name of the subgroup. |
| op | Operator to be read into. |
| fops | Fundamental operator set associated with the operator. |
Definition at line 139 of file many_body_operator.cpp.
|
friend |
Read a triqs::operators::many_body_operator_generic from HDF5.
| g | h5::group to be read from. |
| name | Name of the subgroup. |
| op | Operator to be read into. |
Definition at line 767 of file many_body_operator.hpp.
|
friend |
Write a triqs::operators::many_body_operator together with a triqs::hilbert_space::fundamental_operator_set to HDF5.
| g | h5::group to be written to. |
| name | Name of the subgroup. |
| op | Operator to be written. |
| fops | Fundamental operator set associated with the operator. |
Definition at line 94 of file many_body_operator.cpp.
|
friend |
Write a triqs::operators::many_body_operator_generic to HDF5.
A minimal fundamental operator set is constructed from the operator and used to label the canonical operators of each monomial.
| g | h5::group to be written to. |
| name | Name of the subgroup. |
| op | Operator to be written. |
Definition at line 745 of file many_body_operator.hpp.
|
friend |
Product of two many-body operators \( \hat{O} \) and \( \hat{P} \) (Fock-space operator product).
| lhs | Left hand side operator \( \hat{O} \). |
| rhs | Right hand side operator \( \hat{P} \). |
Definition at line 619 of file many_body_operator.hpp.
|
friend |
Multiply a many-body operator \( \hat{O} \) by a scalar \( a \) on the right.
| op | Operator \( \hat{O} \). |
| a | Scalar \( a \). |
Definition at line 496 of file many_body_operator.hpp.
|
friend |
Multiply a many-body operator \( \hat{O} \) by a scalar \( a \) on the left.
| a | Scalar \( a \). |
| op | Operator \( \hat{O} \). |
Definition at line 505 of file many_body_operator.hpp.
|
friend |
Sum of two many-body operators \( \hat{O} \) and \( \hat{P} \).
| lhs | Left hand side operator \( \hat{O} \). |
| rhs | Right hand side operator \( \hat{P} \). |
Definition at line 601 of file many_body_operator.hpp.
|
friend |
Add a scalar \( a \) to a many-body operator \( \hat{O} \).
| op | Operator \( \hat{O} \). |
| a | Scalar \( a \). |
Definition at line 458 of file many_body_operator.hpp.
|
friend |
Add a many-body operator \( \hat{O} \) to a scalar \( a \).
| a | Scalar \( a \). |
| op | Operator \( \hat{O} \). |
Definition at line 467 of file many_body_operator.hpp.
|
friend |
Difference of two many-body operators \( \hat{O} \) and \( \hat{P} \).
| lhs | Left hand side operator \( \hat{O} \). |
| rhs | Right hand side operator \( \hat{P} \). |
Definition at line 610 of file many_body_operator.hpp.
|
friend |
Subtract a scalar \( a \) from a many-body operator \( \hat{O} \).
| op | Operator \( \hat{O} \). |
| a | Scalar \( a \). |
Definition at line 476 of file many_body_operator.hpp.
|
friend |
Subtract a many-body operator \( \hat{O} \) from a scalar \( a \).
Equivalent to \( -\hat{O} + a \). See operator-() and operator+=(scalar_t).
| a | Scalar \( a \). |
| op | Many-body operator \( \hat{O} \). |
Definition at line 487 of file many_body_operator.hpp.
|
friend |
Divide a many-body operator \( \hat{O} \) by a scalar \( a \).
| op | Operator \( \hat{O} \). |
| a | Scalar \( a \). |
Definition at line 514 of file many_body_operator.hpp.
|
friend |
Write a triqs::operators::many_body_operator_generic to a std::ostream.
| os | std::ostream object. |
| op | Operator \( \hat{O} \) to be written. |
Definition at line 696 of file many_body_operator.hpp.
|
friend |
Transform the coefficients of an operator \( \hat{O} \) using a callable object.
The callable object must take two arguments, a monomial \( \hat{m}_i \) and the corresponding coefficient \( a_i \), and return a new coefficient \( \tilde{a}_i \).
The callable is applied to each term of the operator and the returned coefficient \( \tilde{a}_i \) together with the monomial \( \hat{m}_i \) is inserted in the resulting operator. If the returned coefficient is zero, the term is omitted.
| F | Callable type. |
| op | Operator \( \hat{O} \) to be transformed. |
| f | Callable object. |
Definition at line 673 of file many_body_operator.hpp.