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

Represents a symbolic form of an expression. More...

#include <Expression.h>

Public Member Functions

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.
Expression & 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.
Expression & Subtract (const Variable &var, const mpq_class &coeff)
 Subtract a linear monomial \( c \cdot x \), where \( c \) is a constant and \( x \) is a Variable, to the current expression.
std::ostream & Print (std::ostream &os) const
 Print a string representation of this class to the provided os.

Private Attributes

intrusive_ptr< ExpressionCellptr_
 Internal pointer to the ExpressionCell.

Detailed Description

Represents a symbolic form of an expression.

Its syntax tree is as follows:

E := Var | E + ... + E | Constant * E

To check structural equality between two expressions use Expression::equal_to.

Definition at line 37 of file Expression.h.

Member Function Documentation

◆ Add()

Expression & delpi::Expression::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 76 of file Expression.cpp.

◆ Evaluate()

template<MapFromTo< Variable, mpq_class > T>
template mpq_class delpi::Expression::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 45 of file Expression.cpp.

◆ Print()

std::ostream & delpi::Expression::Print ( std::ostream & os) const

Print a string representation of this class to the provided os.

It is an alternative to the more standard operator<<.

Parameters
osoutput stream
Returns
reference to the output stream

Definition at line 50 of file Expression.cpp.

◆ Substitute()

Expression delpi::Expression::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 + 2 * y;
Substitution s = {{x, y}, {y, x}};
e.Substitute(s); // returns y + 2 * x
Expression Substitute(const SubstitutionMap &s) const
Create a copy of this expression, replacing all occurrences of the variables in s with corresponding ...
Parameters
smap of substitutions. Maps the old variable to the new one.
Returns
expression produced by the substitution

Definition at line 48 of file Expression.cpp.

◆ Subtract()

Expression & delpi::Expression::Subtract ( const Variable & var,
const mpq_class & coeff )

Subtract 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 84 of file Expression.cpp.


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