Class Product¶
Defined in File product.hpp
Inheritance Relationships¶
Base Type¶
public sequant::Expr(Class Expr)
Derived Types¶
public sequant::CProduct(Class CProduct)public sequant::NCProduct(Class NCProduct)
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
-
using scalar_type = Constant::scalar_type¶
Public Functions
-
Product() = default¶
-
virtual ~Product() = default¶
-
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>
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; if rng is a Product, it will be flattened into this Product and its scalar prefactor will be preserved
flatten_tag – if Flatten::Yes, flatten the factors
-
template<typename T, typename Range>
inline explicit Product(T scalar, Range &&rng, Flatten flatten_tag = Flatten::Yes)¶ construct a Product of the range of factors and multiply by
scalar- 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
scalartimesfactor- 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
scalartimesfactorWarning
if
factoris 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
-
Product &append(ExprPtr factor, Flatten flatten_tag = Flatten::Yes)¶
(post-)multiplies the product by
factor- Parameters:
factor – a factor by which to multiply the product
flatten_tag – specifies whether (and how) to flatten the argument(s)
- Returns:
*this
-
template<typename Factor, typename = std::enable_if_t<is_an_expr_v<Factor>>>
inline Product &append(Factor &&factor, Flatten flatten_tag = Flatten::Yes)¶ (post-)multiplies the product by
factorWarning
if
factoris a Product, it is flattened recursively- Parameters:
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
scalartimesfactorNote
this is less efficient than append()
Warning
if
factoris 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
scalartimesfactorNote
this is less efficient than append()
Warning
if
factoris 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
-
const scalar_type &scalar() const¶
-
virtual bool is_zero() const override¶
- Returns:
Constant::is_zero(this->scalar())
-
const factors_type &factors() const¶
-
factors_type &factors()¶
-
inline auto scalar_factors() const¶
View view of factors that are scalars (anything for which Expr::is_scalar() returns true).
Note
Order-preserving.
-
inline auto nonscalar_factors() const¶
View of factors that are NOT scalars (i.e. tensor- or operator-like factors).
-
const ExprPtr &factor(size_t i) const¶
Factor accessor
- Parameters:
i – factor index
- Returns:
ith factor
-
bool empty() const¶
- Returns:
true if the number of factors is zero
-
virtual bool is_commutative() const¶
checks commutativity recursively
See also
Note
this is recomputed on every call
- 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
-
virtual std::wstring to_latex() const override¶
- Returns:
the string representation of
thisin the LaTeX format
-
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
-
virtual type_id_type type_id() const override¶
Computes and returns the derived type identifier
See also
- Returns:
the hash value for this Expr
-
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)
-
virtual ExprIterator begin_subexpr() override¶
-
virtual ExprIterator end_subexpr() override¶
-
virtual ConstExprIterator begin_subexpr() const override¶
-
virtual ConstExprIterator end_subexpr() const override¶
-
virtual ExprPtr canonicalize(CanonicalizeOptions opt = CanonicalizeOptions::default_options()) override¶
Canonicalizes
thisand returns the byproduct of canonicalization (e.g. phase)- Returns:
the byproduct of canonicalization, or
nullptrif no byproduct generated
-
virtual ExprPtr rapid_canonicalize(CanonicalizeOptions opts = CanonicalizeOptions::default_options().copy_and_set(CanonicalizationMethod::Rapid)) override¶
Performs approximate, but fast, canonicalization of
thisand returns the byproduct of canonicalization (e.g. phase) The default is to use canonicalize(), unless overridden in the derived class.- Returns:
the byproduct of canonicalization, or
nullptrif no byproduct generated
-
using scalar_type = Constant::scalar_type¶