Class Tensor

Nested Relationships

Nested Types

Inheritance Relationships

Base Types

Class Documentation

class Tensor : public sequant::Expr, public sequant::AbstractTensor, public sequant::MutatableLabeled

a Tensor is an instance of AbstractTensor over a scalar field, i.e. Tensors have commutative addition and product operations

nontrivial constructors

Note

if SEQUANT_ASSERT_ENABLED is #defined and invalid combinations of indices are found, these will assert via SEQUANT_ASSERT that these conditions do not occur:

  • null indices are found in any slot of antisymmetric bra or ket (it’s not clear what permutation of 2 empty slots is supposed to do in general)

  • null indices are found in any slot of symmetric bra or ket: can assign consistent semantics if have empty slots in the shorter of the bra/ket, but not clear if there is a use case that demands this

  • null indices are found in both slots of bra-ket slot pairs (meaning is unclear)

  • null indices are found in any aux slot (why would empty slots be needed?)

  • asymmetric tensor has a bra/ket slot without a matching ket/bra slot; this is primarily to make operations (such as canonicalization) easier on such tensors; null indices can be used to ensure complete bra/ket bundles in asymmetric tensors

  • duplicate indices are found within bra, within ket, or within aux (but same index can appear in bra and ket, for example).

template<basic_string_convertible S, range_of_castables_to_index IndexRange1, range_of_castables_to_index IndexRange2>
inline Tensor(S &&label, const bra<IndexRange1> &bra_indices, const ket<IndexRange2> &ket_indices, Symmetry s = Symmetry::Nonsymm, BraKetSymmetry bks = get_default_context().braket_symmetry(), ColumnSymmetry ps = ColumnSymmetry::Symm)
Parameters:
  • label – the tensor label

  • bra_indices – list of bra indices (or objects that can be converted to indices)

  • ket_indices – list of ket indices (or objects that can be converted to indices)

  • s – the symmetry of bra or ket

  • bks – the symmetry with respect to bra-ket exchange

  • ps – the symmetry under exchange of particles

template<basic_string_convertible S, range_of_castables_to_index IndexRange1, range_of_castables_to_index IndexRange2, range_of_castables_to_index IndexRange3>
inline Tensor(S &&label, const bra<IndexRange1> &bra_indices, const ket<IndexRange2> &ket_indices, const aux<IndexRange3> &aux_indices, Symmetry s = Symmetry::Nonsymm, BraKetSymmetry bks = get_default_context().braket_symmetry(), ColumnSymmetry ps = ColumnSymmetry::Symm)
Parameters:
  • label – the tensor label

  • bra_indices – list of bra indices (or objects that can be converted to indices)

  • ket_indices – list of ket indices (or objects that can be converted to indices)

  • aux_indices – list of aux indices (or objects that can be converted to indices)

  • s – the symmetry of bra or ket

  • bks – the symmetry with respect to bra-ket exchange

  • ps – the symmetry under exchange of particles

template<basic_string_convertible S>
inline Tensor(S &&label, bra<index_container_type> &&bra_indices, ket<index_container_type> &&ket_indices, Symmetry s = Symmetry::Nonsymm, BraKetSymmetry bks = get_default_context().braket_symmetry(), ColumnSymmetry ps = ColumnSymmetry::Symm)
Parameters:
  • label – the tensor label

  • bra_indices – list of bra indices (or objects that can be converted to indices)

  • ket_indices – list of ket indices (or objects that can be converted to indices)

  • s – the symmetry of bra or ket

  • bks – the symmetry with respect to bra-ket exchange

  • ps – the symmetry under exchange of particles

template<basic_string_convertible S>
inline Tensor(S &&label, bra<index_container_type> &&bra_indices, ket<index_container_type> &&ket_indices, aux<index_container_type> &&aux_indices, Symmetry s = Symmetry::Nonsymm, BraKetSymmetry bks = get_default_context().braket_symmetry(), ColumnSymmetry ps = ColumnSymmetry::Symm)
Parameters:
  • label – the tensor label

  • bra_indices – list of bra indices (or objects that can be converted to indices)

  • ket_indices – list of ket indices (or objects that can be converted to indices)

  • aux_indices – list of aux indices (or objects that can be converted to indices)

  • s – the symmetry of bra or ket

  • bks – the symmetry with respect to bra-ket exchange

  • ps – the symmetry under exchange of particles

Public Functions

Tensor() = default

constructs an uninitialized Tensor

virtual ~Tensor()
inline explicit operator bool() const
Returns:

true if the Tensor is initialized

inline virtual std::wstring_view label() const override
Returns:

“core” label of the tensor

inline virtual void set_label(std::wstring label) override

Sets the label of this object

Parameters:

label – The new label of this object

inline const auto &bra() const
Returns:

the bra slot range (empty slots are occupied by null indices)

inline void set_bra(index_container_type indices)
inline const auto &ket() const
Returns:

the ket slot range (empty slots are occupied by null indices)

inline void set_ket(index_container_type indices)
inline const auto &aux() const
Returns:

the aux slot range (empty slots are occupied by null indices)

inline void set_aux(index_container_type indices)
inline auto braket() const
Returns:

concatenated view of the bra and ket slot ranges

inline auto braket_indices() const
Returns:

concatenated view of the bra and ket index ranges (i.e., nonempty slots)

inline auto braketaux() const
Returns:

concatenated view of all indices of this tensor (bra, ket and aux)

inline auto slots() const
Returns:

concatenated view of all slots

inline auto braketaux_indices() const
Returns:

concatenated view of all nonnull indices of this tensor (bra, ket and aux)

inline auto indices() const
Returns:

concatenated view of all nonnull indices of this tensor

inline auto const_braket() const

Note

this is to work around broken lookup rules

Returns:

view of the bra+ket slots

inline auto const_braket_indices() const

Note

this is to work around broken lookup rules

Returns:

view of the bra+ket indices

inline auto const_braketaux() const

Note

this is to work around broken lookup rules

Returns:

const view of all slots

inline auto const_slots() const

Note

this is to work around broken lookup rules

Returns:

const view of all slots

inline auto const_braketaux_indices() const

Note

this is to work around broken lookup rules

Returns:

const view of all indices

inline auto const_indices() const

Note

this is to work around broken lookup rules

Returns:

const view of all indices

inline Symmetry symmetry() const

Returns the Symmetry object describing the symmetry of the bra and ket of the Tensor, i.e. what effect swapping indices in positions i and j in either bra or ket has on the elements of the Tensor; Tensor’s are always assumed to be particle-symmetric, i.e. swapping indices in positions i and j in both bra and ket; The allowed values are Symmetry::Symm, Symmetry::Antisymm, and Symmetry::Nonsymm

Returns:

the Symmetry object describing the symmetry of the bra and ket of the Tensor.

inline BraKetSymmetry braket_symmetry() const
Returns:

the BraKetSymmetry object describing the symmetry of the Tensor under exchange of bra and ket.

inline ColumnSymmetry column_symmetry() const
Returns:

the ColumnSymmetry object describing the symmetry of the Tensor under exchange of columns (i.e., pairs of matching {bra[i],ket[i]} slot bundles).

inline std::size_t bra_rank() const
Returns:

number of bra slots (some may be occupied by null indices, hence this is the gross rank)

inline std::size_t bra_net_rank() const
Returns:

number of nonnull bra indices (i.e. non-empty slots)

inline std::size_t ket_rank() const
Returns:

number of ket slots (some may be occupied by null indices, hence this is the gross rank)

inline std::size_t ket_net_rank() const
Returns:

number of nonnull ket indices (i.e. non-empty slots)

inline std::size_t aux_rank() const
Returns:

number of aux indices

inline std::size_t num_slots() const
Returns:

number of slots

inline std::size_t num_indices() const
Returns:

number of indices

inline std::size_t rank() const
Throws:

std::logic_error – if bra and ket ranks do not match

Returns:

number of indices in bra/ket

inline virtual std::wstring to_latex() const override
Returns:

the string representation of this in the LaTeX format

virtual ExprPtr canonicalize(CanonicalizeOptions = {}) override

Note

this performs rapid canonicalization only

virtual void adjoint() override

adjoint of a Tensor swaps its bra and ket

template<template<typename, typename, typename ...Args> class Map, typename ...Args>
inline bool transform_indices(const Map<Index, Index, Args...> &index_map)

Replaces indices using the index map

Parameters:

index_map – maps Index to Index

Returns:

true if one or more indices changed

inline virtual type_id_type type_id() const override

Computes and returns the derived type identifier

Note

this function must be overridden in the derived class

Returns:

the hash value for this Expr

inline virtual ExprPtr clone() const override

Note

- must be overridden in the derived class.

  • the default implementation throws an exception

Returns:

a clone of this object, i.e. an object that is equal to this

inline void reset_tags() const
inline hash_type bra_hash_value() const
inline virtual bool operator<(const AbstractTensor &other) const final override