dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
FunctionDefinition.cpp
1
6#include "FunctionDefinition.h"
7
8#include <utility>
9
10#include "dlinear/util/exception.h"
11
12namespace dlinear::smt2 {
13
14FunctionDefinition::FunctionDefinition(std::vector<Variable> parameters, Sort return_type, Term body)
15 : parameters_{std::move(parameters)}, return_type_{return_type}, body_{std::move(body)} {
17}
18
19Term FunctionDefinition::operator()(const std::vector<Term>& arguments) const {
20 if (parameters_.size() != arguments.size()) {
21 DLINEAR_RUNTIME_ERROR_FMT("This function definition expects #{} arguments ({}). Provided #{} arguments.",
22 parameters_.size(), parameters_, arguments.size());
23 }
24 Term t = body_;
25
26 for (std::size_t i = 0; i < parameters_.size(); ++i) {
27 const Variable& param_i{parameters_[i]};
28 const Term& arg_i{arguments[i]};
29 arg_i.Check(param_i.get_type());
30 t = t.Substitute(param_i, arg_i);
31 }
32
33 return t;
34}
35
36} // namespace dlinear::smt2
Represents a symbolic variable.
Sort return_type_
Return type of the function.
Term operator()(const std::vector< Term > &arguments) const
Call the function with the given arguments.
FunctionDefinition(std::vector< Variable > parameters, Sort return_type, Term body)
Construct a new function definition.
std::vector< Variable > parameters_
Parameters of the function.
Term body_
Body of the function.
Generic term that can be either an expression or a formula.
Definition Term.h:34
void Check(Sort s) const
Check if this term can be matched with s.
Definition Term.cpp:72
Term Substitute(const Variable &v, const Term &t)
Create a new Term with substitutes the variable v in this term with t.
Definition Term.cpp:41
Namespace for the SMT2 parser of the dlinear library.
Definition Driver.cpp:17
Sort
Sort of a term.
Definition Sort.h:18
STL namespace.