# Coefficient extraction¶

Functions in this module allow easy extraction of monomial coefficients from many_body_operator_generic objects. Each of extract_*() functions selects a particular class of monimials (quadratic/quartic) and returns a dictionary, which maps tuples of monomial indices to the values of the corresponding coefficients.

Utility function dict_to_matrix() converts such dictionaries into a matrix/tensor representation (interaction U-matrix, for instance) given a valid fundamental operator set.

## C++¶

In order to make code cleaner, the following shorthand types are defined in triqs/operators/util/extractors.hpp,

// Shorthand for many_body_operator_generic
template<typename scalar_t>
using op_t = operators::many_body_operator_generic<scalar_t>;

// Mapping: index pair -> coefficient of type T
template<typename T>
using dict2_t = std::map<std::tuple<indices_t,indices_t>,T>;

// Mapping: index quadruple -> coefficient of type T
template<typename T>
using dict4_t = std::map<std::tuple<indices_t,indices_t,indices_t,indices_t>,T>;


Here indices_t represents an operator index sequence (see fundamental_operator_set).

Coefficient extractors

Dictionary to matrix/tensor conversion

## Python¶

Functions to extract coefficients from many-body operators

pytriqs.operators.util.extractors.dict_to_matrix()

Convert a 2/4-index dictionary to a 2/4-dimensional NumPy array given the structure of the Green’s function. The elements missing from the dictionary are assumed to be zero.

Parameters: d : dict The 2/4-index dictionary. gf_struct : dict The structure of the Green’s function, {block_index : [inner indices]}. arr : array The resulting NumPy array.
pytriqs.operators.util.extractors.extract_U_dict2()

Signature : (many_body_operator H, bool ignore_irrelevant = false) -> dict2_t<real_or_complex>

Extract U-matrix of the density-density interaction part $$\frac{1}{2}\sum_{ij} U_{ij} n_i n_j$$ from a Hamiltonian H as a 2-index dictionary.

Parameters: H : Operator The Hamiltonian. ignore_irrelevant : bool If True, ignore all irrelevant terms in H. Otherwise raise an exception when such terms are met. U_dict : dict The 2-index interaction dictionary, {(i,j) : float}.
pytriqs.operators.util.extractors.extract_U_dict4()

Signature : (many_body_operator H, bool ignore_irrelevant = false) -> dict4_t<real_or_complex>

Extract U-matrix of the interaction part $$\frac{1}{2}\sum_{ijkl} U_{ijkl} c^\dagger_i c^\dagger_j c_l c_k$$ from a Hamiltonian H as a 4-index dictionary.

Parameters: H : Operator The Hamiltonian. ignore_irrelevant : bool If True, ignore all irrelevant terms in H. Otherwise raise an exception when such terms are met. U_dict : dict The 4-index interaction dictionary, {(i,j,k,l) : float}.
pytriqs.operators.util.extractors.extract_h_dict()

Signature : (many_body_operator H, bool ignore_irrelevant = false) -> dict2_t<real_or_complex>

Extract coefficients of the normal quadratic part $$\sum_{ij}h_{ij} c^\dagger_i c_j$$ from a Hamiltonian H as a 2-index dictionary.

Parameters: H : Operator The Hamiltonian. ignore_irrelevant : bool If True, ignore all irrelevant terms in H. Otherwise raise an exception when such terms are met. h_dict : dict The 2-index dictionary of the quadratic part coefficients, {(i,j) : float}.