Class Sum

Inheritance Relationships

Base Type

Class Documentation

class Sum : public sequant::Expr

sum of zero or more summands

Sum is associative and is flattened automatically.

Public Functions

Sum() = default
virtual ~Sum() = default
Sum(const Sum&) = default
Sum(Sum&&) = default
Sum &operator=(const Sum&) = default
Sum &operator=(Sum&&) = default
inline Sum(ExprPtrList summands)

construct a Sum out of zero or more summands

Parameters:

summands – an initializer list of summands

template<typename Iterator>
inline Sum(Iterator begin, Iterator end)

construct a Sum out of a range of summands

Parameters:
  • begin – the begin iterator

  • end – the end iterator

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

construct a Sum out of a range of summands

Parameters:

rng – a range

inline Sum &append(ExprPtr summand)

append a summand to the sum

Parameters:

summand – the summand

inline Sum &prepend(ExprPtr summand)

prepend a summand to the sum

Parameters:

summand – the summand

inline const auto &summands() const

Summands accessor.

inline const ExprPtr &summand(size_t i) const

Summand accessor

Parameters:

i – summand index

Returns:

ith summand

inline ExprPtr take_n(size_t count) const

Takes the first count elements of the sum.

inline ExprPtr take_n(size_t offset, size_t count) const

Takes the first count elements of the sum starting with element offset

template<typename Filter>
inline ExprPtr filter(Filter &&f) const
Template Parameters:

Filter – a boolean predicate type, such Filter(const ExprPtr&) evaluates to true

Parameters:

f – an object of Filter type Selects elements {e} for which f(e) is true

inline bool empty() const
Returns:

true if the number of factors is zero

inline std::size_t size() const
Returns:

the number of summands in a Sum

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

the string representation of this in the LaTeX format

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

the string representation of this in the Wolfram Language format

inline virtual Expr::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

virtual void adjoint() override

adjoint of a Sum is a sum of adjoints of its factors

inline virtual Expr &operator+=(const Expr &that) override

in-place add that to *this

Throws:

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

Returns:

reference to *this

inline virtual Expr &operator-=(const Expr &that) override

in-place subtract that from *this

Throws:

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

Returns:

reference to *this