Skip to content

smt2: convert mathematical_function types and function_application #6709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion regression/cbmc/uninterpreted_function/uf1.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE broken-smt-backend
CORE
uf1.c

^EXIT=10$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc/uninterpreted_function/uf2.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE broken-smt-backend
CORE
uf2.c

^EXIT=0$
Expand Down
106 changes: 97 additions & 9 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,26 @@ void smt2_convt::convert_expr(const exprt &expr)
{
convert_expr(simplify_expr(to_bitreverse_expr(expr).lower(), ns));
}
else if(expr.id() == ID_function_application)
{
const auto &function_application_expr = to_function_application_expr(expr);
// do not use parentheses if there function is a constant
if(function_application_expr.arguments().empty())
{
convert_expr(function_application_expr.function());
}
else
{
out << '(';
convert_expr(function_application_expr.function());
for(auto &op : function_application_expr.arguments())
{
out << ' ';
convert_expr(op);
}
out << ')';
}
}
else
INVARIANT_WITH_DIAGNOSTICS(
false,
Expand Down Expand Up @@ -4468,13 +4488,49 @@ void smt2_convt::set_to(const exprt &expr, bool value)
smt2_identifiers.insert(smt2_identifier);

out << "; set_to true (equal)\n";
out << "(define-fun |" << smt2_identifier << "| () ";
out << "(define-fun |" << smt2_identifier << '|';

convert_type(equal_expr.lhs().type());
out << " ";
convert_expr(prepared_rhs);
if(equal_expr.lhs().type().id() == ID_mathematical_function)
{
auto &mathematical_function_type =
to_mathematical_function_type(equal_expr.lhs().type());
out << " (";
bool first = true;

for(std::size_t p_nr = 0;
p_nr < mathematical_function_type.domain().size();
p_nr++)
{
if(first)
first = false;
else
out << ' ';

out << '(' << 'p' << (p_nr + 1) << ' ';
convert_type(mathematical_function_type.domain()[p_nr]);
out << ')';
}

out << ")" << "\n";
out << ") ";
convert_type(mathematical_function_type.codomain());

out << ' ' << '(';
convert_expr(prepared_rhs);
for(std::size_t p_nr = 0;
p_nr < mathematical_function_type.domain().size();
p_nr++)
out << ' ' << 'p' << (p_nr + 1);
out << ')';
}
else
{
out << " () ";
convert_type(equal_expr.lhs().type());
out << ' ';
convert_expr(prepared_rhs);
}

out << ')' << '\n';
return; // done
}
}
Expand Down Expand Up @@ -4616,10 +4672,33 @@ void smt2_convt::find_symbols(const exprt &expr)
smt2_identifiers.insert(smt2_identifier);

out << "; find_symbols\n";
out << "(declare-fun |"
<< smt2_identifier
<< "| () ";
convert_type(expr.type());
out << "(declare-fun |" << smt2_identifier << '|';

if(expr.type().id() == ID_mathematical_function)
{
auto &mathematical_function_type =
to_mathematical_function_type(expr.type());
out << " (";
bool first = true;

for(auto &type : mathematical_function_type.domain())
{
if(first)
first = false;
else
out << ' ';
convert_type(type);
}

out << ") ";
convert_type(mathematical_function_type.codomain());
}
else
{
out << " () ";
convert_type(expr.type());
}

out << ")" << "\n";
}
}
Expand Down Expand Up @@ -5218,6 +5297,15 @@ void smt2_convt::find_symbols_rec(
find_symbols_rec(ns.follow_tag(union_tag), recstack);
}
}
else if(type.id() == ID_mathematical_function)
{
const auto &mathematical_function_type =
to_mathematical_function_type(type);
for(auto &d_type : mathematical_function_type.domain())
find_symbols_rec(d_type, recstack);

find_symbols_rec(mathematical_function_type.codomain(), recstack);
}
}

std::size_t smt2_convt::get_number_of_solver_calls() const
Expand Down