Skip to content

Commit 604f23c

Browse files
Add an linear_functiont::add for linear function
This will be useful for instance to compute the inverse of a function.
1 parent b7b8798 commit 604f23c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/solvers/strings/string_constraint_instantiation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ linear_functiont::linear_functiont(const exprt &f)
9191
}
9292
}
9393

94+
void linear_functiont::add(const linear_functiont &other)
95+
{
96+
PRECONDITION(type == other.type);
97+
constant_coefficient += other.constant_coefficient;
98+
for(auto pair : other.coefficients)
99+
coefficients[pair.first] += pair.second;
100+
}
101+
94102
exprt linear_functiont::to_expr(bool negated) const
95103
{
96104
exprt sum = nil_exprt{};

src/solvers/strings/string_constraint_instantiation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ struct linear_functiont
4848
/// its cannonical representation
4949
explicit linear_functiont(const exprt &f);
5050

51+
/// Make this function the sum of the current function with \p other
52+
void add(const linear_functiont &other);
53+
5154
/// \param negated: optional Boolean asking to negate the function
5255
/// \return an expression corresponding to the linear function
5356
exprt to_expr(bool negated = false) const;

0 commit comments

Comments
 (0)