Class Product

Inheritance Relationships

Base Type

Derived Types

Class Documentation

class Product : public sequant::Expr

generalized product, i.e. a scalar times a product of zero or more terms.

Product is distributive over addition (see Sum). It is associative. All constructors and mutating methods (append/prepend) will by default flatten its factors recursively (but this can be fully controlled by specifying the flatten tag). The commutativity of factors is checked at runtime for each factor (see CProduct and NCProduct for statically commutative and noncommutative Product, respectively)

Subclassed by sequant::CProduct, sequant::NCProduct

Public Types

enum class Flatten

Values:

enumerator Once
enumerator Recursively
enumerator Yes
enumerator No
using scalar_type = Constant::scalar_type

Public Functions

Product() = default
virtual ~Product() = default
Product(const Product&) = default
Product(Product&&) = default
Product &operator=(const Product&) = default
Product &operator=(Product&&) = default
inline Product(ExprPtrList factors, Flatten flatten_tag = Flatten::Yes)

construct a Product out of zero or more factors (multiplied by 1)

Parameters:
  • factors – the factors

  • flatten_tag – if Flatten::Yes, flatten the factors

template<typename Range, typename = std::enable_if_t<meta::is_range_v<std::decay_t<Range>> && !meta::is_same_v<Range, ExprPtrList> && !meta::is_same_v<Range, Product>>>
inline explicit Product(Range &&rng, Flatten flatten_tag = Flatten::Yes)

construct a Product out of zero or more factors (multiplied by 1)

Parameters:
  • rng – a range of factors

  • flatten_tag – if Flatten::Yes, flatten the factors

template<typename T, typename Range, typename = std::enable_if_t<meta::is_range_v<std::decay_t<Range>> && !std::is_same_v<std::remove_reference_t<Range>, ExprPtrList> && !std::is_same_v<std::remove_reference_t<Range>, Product>>>
inline explicit Product(T scalar, Range &&rng, Flatten flatten_tag = Flatten::Yes)

construct a Product out of zero or more factors (multiplied by 1)

Template Parameters:

T – a numeric type; it must be able to multiply Product::scalar_type

Parameters:
  • scalar – a scalar of type T

  • rng – a range of factors

  • flatten_tag – if Flatten::Yes, flatten the factors

template<typename T>
inline Product(T scalar, ExprPtrList factors, Flatten flatten_tag = Flatten::Yes)

construct a Product out of zero or more factors multiplied by a scalar

Template Parameters:

T – a numeric type; it must be able to multiply Product::scalar_type

Parameters:
  • scalar – a scalar of type T

  • factors – an initializer list of factors

  • flatten_tag – if Flatten::Yes, flatten the factors

template<typename Iterator>
inline Product(Iterator begin, Iterator end, Flatten flatten_tag = Flatten::Yes)

construct a Product out of a range of factors

Parameters:
  • begin – the begin iterator

  • end – the end iterator

  • flatten_tag – specifies whether (and how) to flatten the argument(s)

template<typename T, typename Iterator>
inline Product(T scalar, Iterator begin, Iterator end, Flatten flatten_tag = Flatten::Yes)

construct a Product out of a range of factors

Template Parameters:

T – a numeric type; it must be able to multiply Product::scalar_type

Parameters:
  • scalar – a scalar of type T

  • begin – the begin iterator

  • end – the end iterator

  • flatten_tag – specifies whether (and how) to flatten the argument(s)

template<typename T>
inline Product &scale(T scalar)

multiplies the product by scalar

Parameters:

scalar – a scalar by which to multiply the product

Returns:

*this

template<typename T>
inline Product &append(T scalar, ExprPtr factor, Flatten flatten_tag = Flatten::Yes)

(post-)multiplies the product by scalar times factor

Parameters:
  • scalar – a scalar by which to multiply the product

  • factor – a factor by which to multiply the product

  • flatten_tag – specifies whether (and how) to flatten the argument(s)

Returns:

*this

template<typename T, typename Factor, typename = std::enable_if_t<is_an_expr_v<Factor>>>
inline Product &append(T scalar, Factor &&factor, Flatten flatten_tag = Flatten::Yes)

(post-)multiplies the product by scalar times factor

Warning

if factor is a Product, it is flattened recursively

Parameters:
  • scalar – a scalar by which to multiply the product

  • factor – a factor by which to multiply the product

  • flatten_tag – specifies whether (and how) to flatten the argument(s)

Returns:

*this

template<typename T>
inline Product &prepend(T scalar, ExprPtr factor, Flatten flatten_tag = Flatten::Yes)

(pre-)multiplies the product by scalar times factor

Note

this is less efficient than append()

Warning

if factor is a Product, it is flattened recursively

Parameters:
  • scalar – a scalar by which to multiply the product

  • factor – a factor by which to multiply the product

  • flatten_tag – specifies whether (and how) to flatten the argument(s)

Returns:

*this

template<typename T, typename Factor, typename = std::enable_if_t<is_an_expr_v<Factor>>>
inline Product &prepend(T scalar, Factor &&factor, Flatten flatten_tag = Flatten::Yes)

(pre-)multiplies the product by scalar times factor

Note

this is less efficient than append()

Warning

if factor is a Product, it is flattened recursively

Parameters:
  • scalar – a scalar by which to multiply the product

  • factor – a factor by which to multiply the product

  • flatten_tag – specifies whether (and how) to flatten the argument(s)

Returns:

*this

inline const auto &scalar() const
inline bool is_zero() const
Returns:

Constant::is_zero(this->scalar())

inline const auto &factors() const
inline auto &factors()
inline const ExprPtr &factor(size_t i) const

Factor accessor

Parameters:

i – factor index

Returns:

ith factor

inline bool empty() const
Returns:

true if the number of factors is zero

virtual bool is_commutative() const

checks commutativity recursively

Note

this is memoizing

Returns:

true if definitely commutative, false definitely not commutative

virtual void adjoint() override

adjoint of a Product is a reversed product of adjoints of its factors, with complex-conjugated scalar

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

the string representation of this in the LaTeX format

inline std::wstring to_latex(bool negate) const

just like Expr::to_latex() , but can negate before conversion

Parameters:

negate[in] if true, scalar will be before conversion

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

the string representation of this in the Wolfram Language format

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

this does not flatten the product

Returns:

an identical clone of this Product (a deep copy allocated on the heap)

inline Product deep_copy() const
inline virtual Expr &operator*=(const Expr &that) override

in-place multiply *this by that

Throws:

std::logic_error – if not implemented for this class, or cannot be implemented for the particular that

Returns:

reference to *this

inline void add_identical(const Product &other)
inline void add_identical(const std::shared_ptr<Product> &other)