delpi  0.0.1
DElta-complete LP solver
Loading...
Searching...
No Matches
delpi::ExpressionCell Class Reference

Symbolic expression representing an addition between linear monomials. More...

#include <ExpressionCell.h>

Inheritance diagram for delpi::ExpressionCell:
delpi::SelfReferenceCountingObject

Public Member Functions

ExpressionCell & Add (const Variable &var, const mpq_class &coeff)
 Add a linear monomial \( c \cdot x \), where \( c \) is a constant and \( x \) is a Variable, to the current expression.
ExpressionCell & Multiply (const mpq_class &coeff)
 Multiply all terms of the summation by a coeff.
ExpressionCell & Divide (const mpq_class &coeff)
 Divide all terms of the summation by a coeff.
template<MapFromTo< Variable, mpq_class > T>
mpq_class Evaluate (const T &env={}) const
 Evaluates using a given environment (by default, an empty environment).
Expression Substitute (const SubstitutionMap &s) const
 Create a copy of this expression, replacing all occurrences of the variables in s with corresponding expressions in s.

Protected Attributes

std::size_t hash_
 Cached hash of the object.
Expression::Addends addends_
 Map between each variable and it coefficient as terms of the summation.

Additional Inherited Members

Protected Member Functions inherited from delpi::SelfReferenceCountingObject
virtual ~SelfReferenceCountingObject ()=default
 Virtual destructor for the SelfReferenceCountingObject.

Detailed Description

Symbolic expression representing an addition between linear monomials.

It can be used to encode expression of the kind

\[ \sum c_i \cdot x_i \]

where \( c_i \) is a constant and \( x_i \) is a Variable. Internally this class maintains a member variable addends_ to represent a mapping between each variable \( x_i \) to its rational \( c_i \).

Definition at line 27 of file ExpressionCell.h.

Member Function Documentation

◆ Add()

ExpressionCell & delpi::ExpressionCell::Add ( const Variable & var,
const mpq_class & coeff )

Add a linear monomial \( c \cdot x \), where \( c \) is a constant and \( x \) is a Variable, to the current expression.

Parameters
varvariable of the linear monomial
coeffcoefficient of the linear monomial
Returns
reference to this object

Definition at line 70 of file ExpressionCell.cpp.

◆ Divide()

ExpressionCell & delpi::ExpressionCell::Divide ( const mpq_class & coeff)

Divide all terms of the summation by a coeff.

Parameters
coeffcoefficient all the terms will be divided by
Returns
reference to this object
Exceptions
delpi::DelpiExceptiondivision by 0 detected

Definition at line 92 of file ExpressionCell.cpp.

◆ Evaluate()

template<MapFromTo< Variable, mpq_class > T>
template mpq_class delpi::ExpressionCell::Evaluate ( const T & env = {}) const
nodiscard

Evaluates using a given environment (by default, an empty environment).

Template Parameters
Tmap from variable to value (i.e. std::map<Variable, mpq_class>, std::unordered_map<Variable, mpq_class>)
Parameters
envmap between each variable and its value
Returns
value of the expression in the given environment
Exceptions
std::exceptionif there exists variable in this expression whose assignment is not provided by env

Definition at line 101 of file ExpressionCell.cpp.

◆ Multiply()

ExpressionCell & delpi::ExpressionCell::Multiply ( const mpq_class & coeff)

Multiply all terms of the summation by a coeff.

Parameters
coeffcoefficient all the terms will be mutiplied by
Returns
reference to this object

Definition at line 85 of file ExpressionCell.cpp.

◆ Substitute()

Expression delpi::ExpressionCell::Substitute ( const SubstitutionMap & s) const
nodiscard

Create a copy of this expression, replacing all occurrences of the variables in s with corresponding expressions in s.

Note that the substitutions occur simultaneously.

Expression e = x + 5 * y;
Substitution s = {{x, y}, {y, x}};
e.Substitute(s); // returns y + 5 * x
Represents a symbolic form of an expression.
Definition Expression.h:37
Expression Substitute(const SubstitutionMap &s) const
Create a copy of this expression, replacing all occurrences of the variables in s with corresponding ...

Definition at line 108 of file ExpressionCell.cpp.


The documentation for this class was generated from the following files: