11#include "mcrl2/data/list.h"
12#include "mcrl2/smt/translate_specification.h"
13#include "mcrl2/smt/solver.h"
14#include "mcrl2/smt/unfold_pattern_matching.h"
25 std::string result = timeout == std::chrono::microseconds::zero() ? z3.read() : z3.read(timeout);
26 if(result.compare(0, 3,
"sat") == 0)
30 else if(result.compare(0, 5,
"unsat") == 0)
34 else if(result.compare(0, 7,
"unknown") == 0)
40 mCRL2log(log::error) <<
"Error when checking satisfiability of \n" << s.substr(0, 500) <<
"...." << std::endl;
41 throw mcrl2::runtime_error(
"Got unexpected response from SMT-solver:\n" + result);
49 std::ostringstream out;
50 translate_data_specification(dataspec, out, m_cache, m_native);
57 std::ostringstream out;
58 translate_variable_declaration(vars, out, m_cache, m_native);
59 translate_assertion(expr, out, m_cache, m_native);
60 out <<
"(check-sat)\n";
78 const std::function<
void(
std::string)>& output_func,
81 output_func(translation);
105#ifndef MCRL2_ENABLE_MACHINENUMBERS
129 using namespace data;
137nt.sorts[sort_machine_word::machine_word()] =
"Int";
139 std::vector<sort_expression> number_sorts({ sort_pos::pos(), sort_nat::nat(), sort_int::int_(), sort_real::real_() });
140 std::set<sort_expression> sorts = dataspec.sorts();
142 for(
const auto& alias: dataspec.sort_alias_map())
144 sorts.insert(alias.first);
146 for(
const sort_expression& sort: sorts)
148 if(is_basic_sort(sort) || is_container_sort(sort))
150 nt.set_native_definition(equal_to(sort),
"=");
151 nt.set_native_definition(not_equal_to(sort),
"distinct");
152 nt.set_native_definition(if_(sort),
"ite");
154 if(std::find(number_sorts.begin(), number_sorts.end(), sort) != number_sorts.end())
156 nt.set_native_definition(less(sort));
157 nt.set_native_definition(less_equal(sort));
158 nt.set_native_definition(greater(sort));
159 nt.set_native_definition(greater_equal(sort));
160 nt.set_alternative_name(sort_real::exp(sort, sort == sort_real::real_() ? sort_int::int_() : sort_nat::nat()),
"^");
161 nt.set_alternative_name(sort_real::minus(sort, sort),
"-");
162 nt.set_alternative_name(sort_real::negate(sort),
"-");
164 else if(sort == basic_sort(
"@NatPair") || sort == basic_sort(
"@NatNatPair") || sort == basic_sort(
"@word"))
167 nt.set_native_definition(less(sort));
168 nt.set_native_definition(less_equal(sort));
169 nt.set_native_definition(greater(sort));
170 nt.set_native_definition(greater_equal(sort));
175 nt.set_alternative_name(less(sort),
"@less");
176 nt.set_alternative_name(less_equal(sort),
"@less_equal");
177 nt.set_alternative_name(greater(sort),
"@greater");
178 nt.set_alternative_name(greater_equal(sort),
"@greater_equal");
181 std::string printed_sort_name = nt.sorts.find(sort) != nt.sorts.end() ? nt.sorts.find(sort)->second : translate_identifier(pp(sort));
182 std::string list_sort_name =
"(List " + printed_sort_name +
")";
183 nt.set_alternative_name(sort_list::count(sort),
"@list_count");
184 nt.set_alternative_name(sort_list::snoc(sort),
"@snoc");
185 nt.set_native_definition(sort_list::empty(sort),
"nil");
186 nt.set_ambiguous(sort_list::empty(sort));
187 nt.set_native_definition(sort_list::cons_(sort),
"insert");
188 nt.set_native_definition(sort_list::head(sort));
189 nt.set_native_definition(sort_list::tail(sort));
190 nt.sorts[sort_list::list(sort)] = list_sort_name;
194 std::vector<function_symbol_vector> fs_numbers(
196 sort_pos::pos_generate_functions_code(),
197 sort_nat::nat_generate_functions_code(),
198 sort_int::int_generate_functions_code(),
199 sort_real::real_generate_functions_code()
202 for(
const auto& fsv: fs_numbers)
204 for(
const auto& fs: fsv)
206 nt.set_native_definition(fs);
212 return s == sort_int::int_() ? sort_int::int_(1) : sort_real::real_(1);
214 for(
const sort_expression& s: { sort_int::int_(), sort_real::real_() })
216 variable v1(
"v1", s);
217 variable v2(
"v2", s);
218 variable_list l1({v1});
219 variable_list l2({v1,v2});
220 nt.mappings[sort_real::minimum(s,s)] = data_equation(l2, sort_real::minimum(v1, v2), if_(less(v1,v2), v1, v2));
221 nt.mappings[sort_real::maximum(s,s)] = data_equation(l2, sort_real::maximum(v1, v2), if_(less(v1,v2), v2, v1));
222 nt.mappings[sort_real::succ(s)] = data_equation(l1, sort_real::succ(v1), sort_real::plus(v1, one(s)));
223 nt.mappings[sort_real::pred(s)] = data_equation(l1, sort_real::pred(v1), sort_real::minus(v1, one(s)));
224 nt.set_ambiguous(sort_real::minimum(s,s));
225 nt.set_ambiguous(sort_real::maximum(s,s));
226 nt.set_ambiguous(sort_real::succ(s));
227 nt.set_ambiguous(sort_real::pred(s));
229 nt.expressions[sort_nat::first()] = reconstruct_divmod;
230 nt.expressions[sort_nat::last()] = reconstruct_divmod;
244#ifdef MCRL2_ENABLE_MACHINENUMBERS
245 nt.set_native_definition(sort_pos::succpos(),
"+ 1");
246 nt.set_native_definition(sort_nat::succ_nat(),
"+ 1");
247 variable v1(
"v1", sort_nat::nat());
248 nt.mappings[sort_nat::natpred()] = data_equation(variable_list({v1}), sort_nat::natpred(v1), sort_int::minus(v1, sort_nat::nat(1)));
249 nt.set_native_definition(sort_machine_word::zero_word(),
"0");
250 nt.set_native_definition(sort_machine_word::one_word(),
"1");
251 nt.expressions[sort_pos::most_significant_digit()] = pp_translation;
252 nt.expressions[sort_pos::concat_digit()] = pp_translation;
253 nt.expressions[sort_nat::most_significant_digit_nat()] = pp_translation;
254 nt.expressions[sort_nat::concat_digit(sort_nat::nat(), sort_machine_word::machine_word())] = pp_translation;
257 nt.expressions[sort_pos::cdub()] = pp_translation;
262 nt.expressions[sort_real::creal()] = pp_real_translation;
269#ifdef MCRL2_ENABLE_MACHINENUMBERS
270nt.special_recogniser[sort_pos::succpos()] =
">= 2";
271 nt.special_recogniser[sort_nat::succ_nat()] =
">= 1";
298 nt.mappings[id_bool] = data_equation(variable_list({vb}), id_bool
(vb
), vb);
299 nt.mappings[id_int] = data_equation(variable_list({vi}), id_int
(vi
), vi);
300 nt.mappings[id_real] = data_equation(variable_list({vr}), id_real
(vr
), vr);
application operator()(const data_expression &e) const
Apply a data expression to a data expression.
answer solve(const data::variable_list &vars, const data::data_expression &expr, const std::chrono::microseconds &timeout=std::chrono::microseconds::zero())
answer execute_and_check(const std::string &command, const std::chrono::microseconds &timeout) const
smt_solver(const data::data_specification &dataspec)
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Namespace for system defined sort bool_.
const basic_sort & bool_()
Constructor for sort expression Bool.
const function_symbol & implies()
Constructor for function symbol =>.
const function_symbol & and_()
Constructor for function symbol &&.
const function_symbol & false_()
Constructor for function symbol false.
const function_symbol & or_()
Constructor for function symbol ||.
const function_symbol & not_()
Constructor for function symbol !.
const function_symbol & true_()
Constructor for function symbol true.
Namespace for system defined sort int_.
const function_symbol & pos2int()
Constructor for function symbol Pos2Int.
const function_symbol & int2nat()
Constructor for function symbol Int2Nat.
const function_symbol & nat2int()
Constructor for function symbol Nat2Int.
const function_symbol & cneg()
Constructor for function symbol @cNeg.
const function_symbol & int2pos()
Constructor for function symbol Int2Pos.
const function_symbol & cint()
Constructor for function symbol @cInt.
const basic_sort & int_()
Constructor for sort expression Int.
Namespace for system defined sort nat.
const function_symbol & c0()
Constructor for function symbol @c0.
const function_symbol & cnat()
Constructor for function symbol @cNat.
const basic_sort & nat()
Constructor for sort expression Nat.
const function_symbol & nat2pos()
Constructor for function symbol Nat2Pos.
const function_symbol & pos2nat()
Constructor for function symbol Pos2Nat.
Namespace for system defined sort pos.
const function_symbol & c1()
Constructor for function symbol @c1.
const function_symbol & cdub()
Constructor for function symbol @cDub.
const basic_sort & pos()
Constructor for sort expression Pos.
Namespace for system defined sort real_.
const function_symbol & creal()
Constructor for function symbol @cReal.
const function_symbol & pos2real()
Constructor for function symbol Pos2Real.
const function_symbol & real2nat()
Constructor for function symbol Real2Nat.
const function_symbol & real2int()
Constructor for function symbol Real2Int.
const basic_sort & real_()
Constructor for sort expression Real.
const function_symbol & nat2real()
Constructor for function symbol Nat2Real.
const function_symbol & int2real()
Constructor for function symbol Int2Real.
const function_symbol & real2pos()
Constructor for function symbol Real2Pos.
Namespace for all data library functionality.
atermpp::term_list< variable > variable_list
\brief list of variables
function_symbol equal_to(const sort_expression &s)
Constructor for function symbol ==.
static const native_translation_t pp_real_translation
static const native_translation_t pp_translation
static const native_translation_t reconstruct_divmod
native_translations initialise_native_translation(const data::data_specification &dataspec)
void unfold_pattern_matching(const data::data_specification &dataspec, native_translations &nt)
std::function< void(data::data_expression, std::function< void(std::string)>, std::function< void(data::data_expression)>)> native_translation_t
fixed_string_translation(const std::string &s)
void operator()(const data::data_expression &, const std::function< void(std::string)> &output_func, const std::function< void(data::data_expression)> &) const
void set_native_definition(const data::function_symbol &f)
Record that the mapping and equations for f should not be translated.
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const