expr::ExprDag::Scope dagScope(out, dag);
if (tryToStream<AssertCommand>(out, c) || tryToStream<PushCommand>(out, c)
- || tryToStream<PopCommand>(out, c)
- || tryToStream<CheckSatCommand>(out, c)
+ || tryToStream<PopCommand>(out, c) || tryToStream<CheckSatCommand>(out, c)
|| tryToStream<CheckSatAssumingCommand>(out, c)
|| tryToStream<QueryCommand>(out, c, d_variant)
|| tryToStream<ResetCommand>(out, c)
|| tryToStream<DatatypeDeclarationCommand>(out, c, d_variant)
|| tryToStream<CommentCommand>(out, c, d_variant)
|| tryToStream<EmptyCommand>(out, c)
- || tryToStream<EchoCommand>(out, c, d_variant))
+ || tryToStream<EchoCommand>(out, c, d_variant)
+ || tryToStream<SynthFunCommand>(out, c)
+ || tryToStream<DeclareSygusPrimedVarCommand>(out, c)
+ || tryToStream<DeclareSygusFunctionCommand>(out, c)
+ || tryToStream<DeclareSygusVarCommand>(out, c)
+ || tryToStream<SygusConstraintCommand>(out, c)
+ || tryToStream<SygusInvConstraintCommand>(out, c)
+ || tryToStream<CheckSynthCommand>(out, c))
{
return;
}
out << "(echo \"" << s << "\")";
}
+/*
+ --------------------------------------------------------------------------
+ Handling SyGuS commands
+ --------------------------------------------------------------------------
+*/
+
+static void toStream(std::ostream& out, const SynthFunCommand* c)
+{
+ out << '(' << c->getCommandName() << ' ' << CVC4::quoteSymbol(c->getSymbol())
+ << ' ';
+ Type type = c->getFunction().getType();
+ const std::vector<Expr>& vars = c->getVars();
+ Assert(!type.isFunction() || !vars.empty());
+ c->getCommandName();
+ if (type.isFunction())
+ {
+ // print variable list
+ std::vector<Expr>::const_iterator i = vars.begin(), i_end = vars.end();
+ Assert(i != i_end);
+ out << '(';
+ do
+ {
+ out << '(' << *i << ' ' << (*i).getType() << ')';
+ if (++i != i_end)
+ {
+ out << ' ';
+ }
+ } while (i != i_end);
+ out << ')';
+ FunctionType ft = type;
+ type = ft.getRangeType();
+ }
+ // if not invariant-to-synthesize, print return type
+ if (!c->isInv())
+ {
+ out << ' ' << type;
+ }
+ // print grammar, if any
+ Type sygusType = c->getSygusType();
+ if (sygusType.isDatatype()
+ && static_cast<DatatypeType>(sygusType).getDatatype().isSygus())
+ {
+ std::stringstream types_predecl, types_list;
+ std::set<Type> grammarTypes;
+ std::list<Type> typesToPrint;
+ grammarTypes.insert(sygusType);
+ typesToPrint.push_back(sygusType);
+ // for each datatype in grammar
+ // name
+ // sygus type
+ // constructors in order
+ Printer* sygus_printer =
+ Printer::getPrinter(language::output::LANG_SYGUS_V2);
+ do
+ {
+ Type curr = typesToPrint.front();
+ typesToPrint.pop_front();
+ Assert(curr.isDatatype()
+ && static_cast<DatatypeType>(curr).getDatatype().isSygus());
+ const Datatype& dt = static_cast<DatatypeType>(curr).getDatatype();
+ types_list << "(" << dt.getName() << " " << dt.getSygusType() << "\n(";
+ types_predecl << "(" << dt.getName() << " " << dt.getSygusType() << ")";
+ if (dt.getSygusAllowConst())
+ {
+ types_list << "(Constant " << dt.getSygusType() << ") ";
+ }
+ for (const DatatypeConstructor& cons : dt)
+ {
+ DatatypeConstructor::const_iterator i = cons.begin(),
+ i_end = cons.end();
+ if (i != i_end)
+ {
+ types_list << "(";
+ SygusPrintCallback* spc = cons.getSygusPrintCallback().get();
+ if (spc != nullptr && options::sygusPrintCallbacks())
+ {
+ spc->toStreamSygus(sygus_printer, types_list, cons.getSygusOp());
+ }
+ else
+ {
+ types_list << cons.getSygusOp();
+ }
+ do
+ {
+ Type argType = (*i).getRangeType();
+ // print argument type
+ types_list << " " << argType;
+ // if fresh type, store it for later processing
+ if (grammarTypes.insert(argType).second)
+ {
+ typesToPrint.push_back(argType);
+ }
+ } while (++i != i_end);
+ types_list << ")";
+ }
+ else
+ {
+ SygusPrintCallback* spc = cons.getSygusPrintCallback().get();
+ if (spc != nullptr && options::sygusPrintCallbacks())
+ {
+ spc->toStreamSygus(sygus_printer, types_list, cons.getSygusOp());
+ }
+ else
+ {
+ types_list << cons.getSygusOp();
+ }
+ }
+ types_list << "\n";
+ }
+ types_list << "))\n";
+ } while (!typesToPrint.empty());
+
+ out << "\n(" << types_predecl.str() << ")\n(" << types_list.str() << ")";
+ }
+ out << ")";
+}
+
+static void toStream(std::ostream& out, const DeclareSygusFunctionCommand* c)
+{
+ out << '(' << c->getCommandName() << ' ' << CVC4::quoteSymbol(c->getSymbol());
+
+ FunctionType ft = c->getType();
+ stringstream ss;
+
+ for (const Type& i : ft.getArgTypes())
+ {
+ ss << i << ' ';
+ }
+
+ string argTypes = ss.str();
+ argTypes.pop_back();
+
+ out << " (" << argTypes << ") " << ft.getRangeType() << ')';
+}
+
+static void toStream(std::ostream& out, const DeclareSygusPrimedVarCommand* c)
+{
+ out << '(' << c->getCommandName() << ' ' << CVC4::quoteSymbol(c->getSymbol())
+ << ' ' << c->getType() << ')';
+}
+
+static void toStream(std::ostream& out, const DeclareSygusVarCommand* c)
+{
+ out << '(' << c->getCommandName() << ' ' << c->getVar() << ' ' << c->getType()
+ << ')';
+}
+
+static void toStream(std::ostream& out, const SygusConstraintCommand* c)
+{
+ out << '(' << c->getCommandName() << ' ' << c->getExpr() << ')';
+}
+
+static void toStream(std::ostream& out, const SygusInvConstraintCommand* c)
+{
+ out << '(' << c->getCommandName() << ' ';
+ copy(c->getPredicates().cbegin(),
+ c->getPredicates().cend(),
+ std::ostream_iterator<Expr>(out, " "));
+ out << ')';
+}
+
+static void toStream(std::ostream& out, const CheckSynthCommand* c)
+{
+ out << '(' << c->getCommandName() << ')';
+}
+
+/*
+ --------------------------------------------------------------------------
+ End of Handling SyGuS commands
+ --------------------------------------------------------------------------
+*/
+
template <class T>
static bool tryToStream(std::ostream& out, const Command* c)
{
Result SmtEngine::checkSat(const Expr& assumption, bool inUnsatCore)
{
+ Dump("benchmark") << CheckSatCommand(assumption);
return checkSatisfiability(assumption, inUnsatCore, false);
}
Result SmtEngine::checkSat(const vector<Expr>& assumptions, bool inUnsatCore)
{
+ if (assumptions.empty())
+ {
+ Dump("benchmark") << CheckSatCommand();
+ }
+ else
+ {
+ Dump("benchmark") << CheckSatAssumingCommand(assumptions);
+ }
+
return checkSatisfiability(assumptions, inUnsatCore, false);
}
Result SmtEngine::query(const Expr& assumption, bool inUnsatCore)
{
+ Dump("benchmark") << QueryCommand(assumption, inUnsatCore);
return checkSatisfiability(assumption.isNull()
? std::vector<Expr>()
: std::vector<Expr>{assumption},
d_needPostsolve = true;
- // Dump the query if requested
- if (Dump.isOn("benchmark"))
- {
- size_t size = assumptions.size();
- // the expr already got dumped out if assertion-dumping is on
- if (isQuery && size == 1)
- {
- Dump("benchmark") << QueryCommand(assumptions[0]);
- }
- else if (size == 0)
- {
- Dump("benchmark") << CheckSatCommand();
- }
- else
- {
- Dump("benchmark") << CheckSatAssumingCommand(d_assumptions);
- }
- }
-
// Pop the context
if (didInternalPush)
{
{
d_private->d_sygusVars.push_back(Node::fromExpr(var));
Trace("smt") << "SmtEngine::declareSygusVar: " << var << "\n";
+ Dump("raw-benchmark") << DeclareSygusVarCommand(id, var, type);
// don't need to set that the conjecture is stale
}
{
// do nothing (the command is spurious)
Trace("smt") << "SmtEngine::declareSygusPrimedVar: " << id << "\n";
+ Dump("raw-benchmark") << DeclareSygusPrimedVarCommand(id, type);
// don't need to set that the conjecture is stale
}
{
d_private->d_sygusVars.push_back(Node::fromExpr(var));
Trace("smt") << "SmtEngine::declareSygusFunctionVar: " << var << "\n";
+ Dump("raw-benchmark") << DeclareSygusFunctionCommand(id, var, type);
// don't need to set that the conjecture is stale
}
setUserAttribute("sygus-synth-grammar", func, attr_value, "");
}
Trace("smt") << "SmtEngine::declareSynthFun: " << func << "\n";
+ Dump("raw-benchmark") << SynthFunCommand(id, func, sygusType, isInv, vars);
// sygus conjecture is now stale
setSygusConjectureStale();
}
d_private->d_sygusConstraints.push_back(constraint);
Trace("smt") << "SmtEngine::assertSygusConstrant: " << constraint << "\n";
+ Dump("raw-benchmark") << SygusConstraintCommand(constraint);
// sygus conjecture is now stale
setSygusConjectureStale();
}
d_private->d_sygusConstraints.push_back(constraint);
Trace("smt") << "SmtEngine::assertSygusInvConstrant: " << constraint << "\n";
+ Dump("raw-benchmark") << SygusInvConstraintCommand(inv, pre, trans, post);
// sygus conjecture is now stale
setSygusConjectureStale();
}
setUserAttribute("sygus", sygusVar.toExpr(), {}, "");
Trace("smt") << "Check synthesis conjecture: " << body << std::endl;
+ Dump("raw-benchmark") << CheckSynthCommand();
d_private->d_sygusConjectureStale = false;
// Ensure expr is type-checked at this point.
e.getType(true);
}
- if(Dump.isOn("benchmark")) {
- Dump("benchmark") << ExpandDefinitionsCommand(e);
- }
+
unordered_map<Node, Node, NodeHashFunction> cache;
Node n = d_private->expandDefinitions(Node::fromExpr(e), cache, /* expandOnly = */ true);
n = postprocess(n, TypeNode::fromType(e.getType()));