Class AbstractTensor

Inheritance Relationships

Derived Types

Class Documentation

class AbstractTensor

AbstractTensor is a tensor over general (i.e., not necessarily commutative) rings. A tensor with \( k \geq 0 \) ket (see Dirac notation ) and \( b \geq 0 \) bra modes describes elements of a tensor product of \( b+k \) vector spaces. Equivalently it represents a linear map between the tensor product of \( k \) primal vector spaces to the tensor product of \( b \) dual vector spaces. Tensor modes are 1-to-1 represented by unique indices, represented by Index objects.

It is also necessary to support modes that are “array-like” in that they do not refer to a vector space or its dual; such modes can represent ordinal indices (e.g. to treat a collection/sequence of tensors as a single tensor) Thus each tensor has zero or more auxiliary (aux) modes. The aux modes are invariant under the transformations of vector spaces and do not contribute to the tensor symmetries.

Tensors can have the following symmetries:

  • Tensors can be symmetric or nonsymmetric with respect to the transposition of corresponding {bra,ket} modes in bra/ket mode ranges. This symmetry is used to treat particles as indistinguishable or distinguishable in physical simulation. See more below on how such mode bundles are handled.

  • Tensors can be symmetric, antisymmetric, and nonsymmetric with respect to the transposition of modes within the bra or ket sets. This symmetry is used to model the distinguishable and indistinguishable (bosonic and fermionic) degrees of freedom in many-body quantum mechanics context. More complicated symmetries are not yet supported.

  • Tensors can be symmetric, conjugate, or nonsymmetric with respect to swap of bra with ket. This symmetry corresponds to time reversal in physical simulation.

The supporting rings are not assumed to be scalars, hence tensor product supporting the concept of tensor is not necessarily commutative.

For some applications the pairing of bra and ket modes is important, hence it is necessary to support not only tensors where first bra mode is paired with the first ket, but it is then necessary to support bra and ket modes that are unpaired. This introduces notion of bra/ket slots. A slot is either occupied by a non-null Index (hence corresponds to a bra or ket mode), or empty (i.e., occupied by a null Index). Tensors with non-symmetric bras and kets can have empty slots in arbitrary positions in bra and ket slot bundles. Such tensors symmetric with respect to reordering of braket bundles (_column_symmetry()) assume the canonical order of slots, defined as follows:

  • paired braket slot bundles (both bra and ket slots are nonempty) appear first

  • unpaired bra slots appear next (with ket slots empty, or without altogether is there are no unpaired ket slots)

  • unpaired ket slots appear next (without matching bra slots).

Empty aux slots are not permitted.

Note

This interface class defines a Tensor concept. All Tensor objects must fulfill the is_tensor trait (see below). To adapt an existing class intrusively derive it from AbstractTensor and implement all member functions. This allows to implement heterogeneous containers of objects that meet the Tensor concept.

Subclassed by sequant::NormalOperator< S >, sequant::Tensor

Public Types

using const_any_view_rand = ranges::any_view<const Index&, ranges::category::random_access>
using const_any_view_randsz = ranges::any_view<const Index&, ranges::category::random_access | ranges::category::sized>
using any_view_rand = ranges::any_view<Index&, ranges::category::random_access>
using any_view_randsz = ranges::any_view<Index&, ranges::category::random_access | ranges::category::sized>

Public Functions

virtual ~AbstractTensor() = default
inline virtual AbstractTensor *_clone() const

clones this object /

Throws:

missing_instantiation_for – if not overloaded

inline virtual std::shared_ptr<AbstractTensor> _clone_shared() const

clones this object producing a shared_ptr<AbstractTensor> so that if the derived class is an Expr, hence derived from std::enable_shared_from_this, the weak pointer is set correctly

inline virtual const_any_view_randsz _bra() const

accessor for bra slots

Returns:

view of a contiguous range of bra Index objects; empty slots may be empty (i.e., occupied by null indices).

inline virtual const_any_view_randsz _ket() const

accesses ket slots

Returns:

view of a contiguous range of ket Index objects; empty slots may be empty (i.e., occupied by null indices).

inline virtual const_any_view_randsz _aux() const

accesses aux (non-vector-space) indices

Returns:

view of a contiguous range of aux Index objects

inline virtual const_any_view_rand _braket() const

accesses bra and ket slots

Returns:

concatenated (hence, non contiguous) view of bra and ket slots

inline virtual const_any_view_rand _braketaux() const

accesses bra, ket, and aux slots

Returns:

view of a not necessarily contiguous view of bra, ket, and aux slots

inline virtual const_any_view_rand _slots() const

accesses all slots

Returns:

view of a not necessarily contiguous range of Index objects

inline virtual std::size_t _bra_rank() const
Returns:

the number of bra slots (some may be empty, hence this is the gross rank)

inline virtual std::size_t _bra_net_rank() const
Returns:

the number of nonempty bra slots (i.e., nonnull bra indices)

inline virtual std::size_t _ket_rank() const
Returns:

the number of bra slots (some may be empty, hence this is the gross rank)

inline virtual std::size_t _ket_net_rank() const
Returns:

the number of nonempty ket slots (i.e., nonnull bra indices)

inline virtual std::size_t _aux_rank() const
Returns:

the number of aux slots

inline virtual std::size_t _num_slots() const
Returns:

the number of slots

inline virtual std::size_t _num_indices() const
Returns:

the number of indices

inline virtual Symmetry _symmetry() const
Returns:

the permutational symmetry of the vector space indices of the tensor

inline virtual BraKetSymmetry _braket_symmetry() const
Returns:

the symmetry of tensor under exchange of vectors space (bra) and its dual (ket)

inline virtual ColumnSymmetry _column_symmetry() const

Note

slots are left-aligned

Returns:

the symmetry of tensor under exchange of matching {bra,ket} slot pairs

inline virtual std::size_t _color() const
inline virtual bool _is_cnumber() const

Returns:

true if this is a c-number; if false,

inline virtual std::wstring_view _label() const
inline virtual std::wstring _to_latex() const
inline virtual bool operator<(const AbstractTensor&) const
inline virtual std::size_t _hash_value() const

hashes the tensor’s identity , i.e., this includes hashes of the index labels (ordinals)

Warning

this hash value is not invariant with respect to tensor symmetries, i.e. permuting bra indices will not leave the hash invariant even if the tensor is

Returns:

hash of the tensor’s identity

inline virtual bool _transform_indices(const container::map<Index, Index>&)
inline virtual void _reset_tags()
inline virtual void _permute_bra(std::span<const std::size_t> perm)

permutes bra slots according to perm

Parameters:

perm – from-permutation, i.e. Index in slot permutation[i] will be in slot i

inline virtual void _permute_ket(std::span<const std::size_t> perm)

permutes ket slots according to perm

Parameters:

perm – from-permutation, i.e. Index in slot permutation[i] will be in slot i

inline virtual void _permute_aux(std::span<const std::size_t> perm)

permutes aux slots according to perm

Parameters:

perm – from-permutation, i.e. Index in slot permutation[i] will be in slot i

inline virtual void _permute_columns(std::span<std::size_t> perm)

permutes column slot bundles according to perm

Parameters:

perm – from-permutation, i.e. Index pair in column permutation[i] will end up in column i

inline virtual void _swap_bra_ket()

swaps bra and ket slots

inline virtual any_view_randsz _bra_mutable()

Warning

this is used for mutable access, flush memoized state before returning!

Returns:

mutable view of bra

inline virtual any_view_randsz _ket_mutable()

Warning

this is used for mutable access, flush memoized state before returning!

Returns:

mutable view to ket

inline virtual any_view_randsz _aux_mutable()

Warning

this is used for mutable access, flush memoized state before returning!

Returns:

mutable view of aux indices