delpi
0.0.1
DElta-complete LP solver
Toggle main menu visibility
Loading...
Searching...
No Matches
ExpressionCell.h
1
7
#pragma once
8
9
#include <vector>
10
11
#include "delpi/symbolic/Expression.h"
12
#include "delpi/util/SelfReferenceCountingObject.hpp"
13
#include "delpi/util/intrusive_ptr.hpp"
14
15
namespace
delpi
{
16
27
class
ExpressionCell :
public
SelfReferenceCountingObject
{
28
public
:
29
using
Addend = Expression::Addend;
30
using
Addends = Expression::Addends;
31
using
SubstitutionMap = Expression::SubstitutionMap;
32
34
[[nodiscard]] std::vector<Variable> variables()
const
;
36
[[nodiscard]]
const
Addends& addends()
const
noexcept
{
return
addends_
; }
37
39
[[nodiscard]]
bool
equal_to(
const
ExpressionCell& o)
const
noexcept
;
41
[[nodiscard]]
bool
less(
const
ExpressionCell& o)
const
noexcept
;
43
[[nodiscard]] std::size_t hash()
const
noexcept
;
44
52
ExpressionCell&
Add
(
const
Variable
& var,
const
mpq_class& coeff);
58
ExpressionCell&
Multiply
(
const
mpq_class& coeff);
65
ExpressionCell&
Divide
(
const
mpq_class& coeff);
66
74
template
<MapFromTo<Variable, mpq_
class
> T>
75
[[nodiscard]] mpq_class
Evaluate
(
const
T& env = {})
const
;
76
88
[[nodiscard]]
Expression
Substitute
(
const
SubstitutionMap& s)
const
;
89
90
std::ostream& Print(std::ostream& os)
const
;
91
static
std::ostream& PrintAddend(std::ostream& os,
bool
print_plus,
const
Variable
& var,
const
mpq_class& coeff);
92
93
static
intrusive_ptr<ExpressionCell>
New();
94
static
intrusive_ptr<ExpressionCell>
New(
Variable
var);
95
static
intrusive_ptr<ExpressionCell>
New(Addend linear_monomial);
96
static
intrusive_ptr<ExpressionCell>
New(Addends addends);
97
static
intrusive_ptr<ExpressionCell>
Copy(
const
ExpressionCell& o);
98
99
protected
:
100
ExpressionCell() =
default
;
101
explicit
ExpressionCell(
Variable
var);
102
explicit
ExpressionCell(Addend linear_monomial);
103
explicit
ExpressionCell(Addends addends);
104
105
mutable
std::size_t
hash_
;
106
Expression::Addends
addends_
;
107
};
108
109
}
// namespace delpi
delpi::ExpressionCell::hash_
std::size_t hash_
Cached hash of the object.
Definition
ExpressionCell.h:105
delpi::ExpressionCell::Add
ExpressionCell & Add(const Variable &var, const mpq_class &coeff)
Add a linear monomial , where is a constant and is a Variable, to the current expression.
Definition
ExpressionCell.cpp:70
delpi::ExpressionCell::Evaluate
mpq_class Evaluate(const T &env={}) const
Evaluates using a given environment (by default, an empty environment).
Definition
ExpressionCell.cpp:101
delpi::ExpressionCell::addends_
Expression::Addends addends_
Map between each variable and it coefficient as terms of the summation.
Definition
ExpressionCell.h:106
delpi::ExpressionCell::Divide
ExpressionCell & Divide(const mpq_class &coeff)
Divide all terms of the summation by a coeff.
Definition
ExpressionCell.cpp:92
delpi::ExpressionCell::Multiply
ExpressionCell & Multiply(const mpq_class &coeff)
Multiply all terms of the summation by a coeff.
Definition
ExpressionCell.cpp:85
delpi::ExpressionCell::Substitute
Expression Substitute(const SubstitutionMap &s) const
Create a copy of this expression, replacing all occurrences of the variables in s with corresponding ...
Definition
ExpressionCell.cpp:108
delpi::Expression
Represents a symbolic form of an expression.
Definition
Expression.h:37
delpi::SelfReferenceCountingObject
Utility class to be inherited from to obtain compatibility with the intrusive_ptr.
Definition
SelfReferenceCountingObject.hpp:34
delpi::Variable
Real symbolic variable.
Definition
Variable.h:20
delpi::intrusive_ptr
Pointer to a generic object that supports intrusive reference counting.
Definition
intrusive_ptr.hpp:22
delpi
Global namespace for the delpi library.
delpi
symbolic
ExpressionCell.h
Generated by
1.17.0