Fixes #5341.
help = "print enumerated terms and candidates generated by the sygus solver"
description = "With ``-o sygus``, cvc5 prints information about the internal SyGuS solver including enumerated terms and generated candidates."
example-file = "regress0/sygus/print-debug.sy"
+[[option.mode.SYGUS_GRAMMAR]]
+ name = "sygus-grammar"
+ help = "print grammars automatically generated by the sygus solver"
+ description = "With ``-o sygus-grammar``, cvc5 prints the grammar it generates for a function-to-synthesize when no grammar was provided."
+ example-file = "regress0/sygus/print-grammar.sy"
[[option.mode.TRIGGER]]
name = "trigger"
help = "print selected triggers for quantified formulas"
[[option]]
name = "resourceWeightHolder"
category = "undocumented"
- type = "std::vector<std::string>"
\ No newline at end of file
+ type = "std::vector<std::string>"
--------------------------------------------------------------------------
*/
-static void toStreamSygusGrammar(std::ostream& out, const TypeNode& t)
+std::string Smt2Printer::sygusGrammarString(const TypeNode& t)
{
+ std::stringstream out;
if (!t.isNull() && t.isDatatype() && t.getDType().isSygus())
{
std::stringstream types_predecl, types_list;
out << "\n(" << types_predecl.str() << ")\n(" << types_list.str() << ')';
}
+ return out.str();
}
void Smt2Printer::toStreamCmdSynthFun(std::ostream& out,
// print grammar, if any
if (!sygusType.isNull())
{
- toStreamSygusGrammar(out, sygusType);
+ out << sygusGrammarString(sygusType);
}
out << ')' << std::endl;
}
out << "(get-interpol " << cvc5::quoteSymbol(name) << ' ' << conj;
if (!sygusType.isNull())
{
- out << ' ';
- toStreamSygusGrammar(out, sygusType);
+ out << ' ' << sygusGrammarString(sygusType);
}
out << ')' << std::endl;
}
// print grammar, if any
if (!sygusType.isNull())
{
- toStreamSygusGrammar(out, sygusType);
+ out << sygusGrammarString(sygusType);
}
out << ')' << std::endl;
}
* the SMT-LIB format (with variant v).
*/
static std::string smtKindString(Kind k, Variant v = smt2_6_variant);
+ /**
+ * Get the string corresponding to the sygus datatype t printed as a grammar.
+ */
+ static std::string sygusGrammarString(const TypeNode& t);
private:
/**
#include "expr/ascription_type.h"
#include "expr/dtype_cons.h"
#include "expr/node_algorithm.h"
+#include "options/base_options.h"
#include "options/quantifiers_options.h"
#include "theory/bv/theory_bv_utils.h"
#include "theory/datatypes/sygus_datatype_utils.h"
#include "theory/strings/word.h"
#include "util/floatingpoint.h"
#include "util/string.h"
+#include "printer/smt2/smt2_printer.h"
using namespace cvc5::kind;
namespace theory {
namespace quantifiers {
-CegGrammarConstructor::CegGrammarConstructor(TermDbSygus* tds,
+CegGrammarConstructor::CegGrammarConstructor(Env& env,
+ TermDbSygus* tds,
SynthConjecture* p)
- : d_tds(tds), d_parent(p), d_is_syntax_restricted(false)
+ : EnvObj(env), d_tds(tds), d_parent(p), d_is_syntax_restricted(false)
{
}
exc_cons,
inc_cons,
term_irlv);
+ // print the grammar
+ if (isOutputOn(OutputTag::SYGUS_GRAMMAR))
+ {
+ output(OutputTag::SYGUS_GRAMMAR)
+ << "(sygus-grammar " << ss.str()
+ << printer::smt2::Smt2Printer::sygusGrammarString(tn) << ")"
+ << std::endl;
+ }
}
// sfvl may be null for constant synthesis functions
Trace("cegqi-debug") << "...sygus var list associated with " << sf << " is "
Assert(!templ_arg.isNull());
// if there is a template for this argument, make a sygus type on top of
// it
- if (!options::sygusTemplEmbedGrammar())
+ if (!options().quantifiers.sygusTemplEmbedGrammar)
{
// otherwise, apply it as a preprocessing pass
Trace("cegqi-debug") << "Template for " << sf << " is : " << templ
qchildren.push_back(nm->mkNode(kind::BOUND_VAR_LIST, ebvl));
if( qbody_subs!=q[1] ){
Trace("cegqi") << "...rewriting : " << qbody_subs << std::endl;
- qbody_subs = Rewriter::rewrite( qbody_subs );
+ qbody_subs = rewrite(qbody_subs);
Trace("cegqi") << "...got : " << qbody_subs << std::endl;
}
qchildren.push_back(convertToEmbedding(qbody_subs));
#include "expr/attribute.h"
#include "expr/node.h"
#include "expr/sygus_datatype.h"
+#include "smt/env_obj.h"
namespace cvc5 {
namespace theory {
* Utility for constructing datatypes that correspond to syntactic restrictions,
* and applying the deep embedding from Section 4 of Reynolds et al CAV 2015.
*/
-class CegGrammarConstructor
+class CegGrammarConstructor : protected EnvObj
{
public:
- CegGrammarConstructor(TermDbSygus* tds, SynthConjecture* p);
+ CegGrammarConstructor(Env& env, TermDbSygus* tds, SynthConjecture* p);
~CegGrammarConstructor() {}
/** process
*
d_ceg_si(new CegSingleInv(env, tr, s)),
d_templInfer(new SygusTemplateInfer),
d_ceg_proc(new SynthConjectureProcess),
- d_ceg_gc(new CegGrammarConstructor(d_tds, this)),
+ d_ceg_gc(new CegGrammarConstructor(env, d_tds, this)),
d_sygus_rconst(new SygusRepairConst(env, d_tds)),
d_exampleInfer(new ExampleInfer(d_tds)),
d_ceg_pbe(new SygusPbe(env, qs, qim, d_tds, this)),
regress0/sygus/pLTL-sygus-syntax-err.sy
regress0/sygus/print-debug.sy
regress0/sygus/print-define-fun.sy
+ regress0/sygus/print-grammar.sy
regress0/sygus/real-si-all.sy
regress0/sygus/setFeature.sy
regress0/sygus/strings-unconstrained.sy
--- /dev/null
+; REQUIRES: no-competition
+; COMMAND-LINE: -o sygus-grammar
+; EXPECT: (sygus-grammar f
+; EXPECT: ((f_Int Int) (f_Bool Bool) )
+; EXPECT: ((f_Int Int ((Constant Int) x y 0 1 (+ f_Int f_Int) (- f_Int f_Int) (ite f_Bool f_Int f_Int) ))
+; EXPECT: (f_Bool Bool ((Constant Bool) true false (= f_Int f_Int) (<= f_Int f_Int) (not f_Bool) (and f_Bool f_Bool) (or f_Bool f_Bool) ))
+; EXPECT: ))
+; EXPECT: (
+; EXPECT: (define-fun f ((x Int) (y Int)) Int 0)
+; EXPECT: )
+
+(set-logic LIA)
+
+(synth-fun f ((x Int) (y Int)) Int)
+
+(check-synth)