return false;
}
-void CegGrammarConstructor::collectTerms( Node n, std::map< TypeNode, std::vector< Node > >& consts ){
+void CegGrammarConstructor::collectTerms(
+ Node n,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>& consts)
+{
std::unordered_map<TNode, bool, TNodeHashFunction> visited;
std::unordered_map<TNode, bool, TNodeHashFunction>::iterator it;
std::stack<TNode> visit;
}
if( std::find( consts[tn].begin(), consts[tn].end(), c )==consts[tn].end() ){
Trace("cegqi-debug") << "...consider const : " << c << std::endl;
- consts[tn].push_back( c );
+ consts[tn].insert(c);
}
}
// recurse
// now, construct the grammar
Trace("cegqi") << "SynthConjecture : convert to deep embedding..."
<< std::endl;
- std::map< TypeNode, std::vector< Node > > extra_cons;
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>> extra_cons;
if( options::sygusAddConstGrammar() ){
Trace("cegqi") << "SynthConjecture : collect constants..." << std::endl;
collectTerms( q[1], extra_cons );
}
- std::map<TypeNode, std::vector<Node>> exc_cons;
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>> exc_cons;
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>> inc_cons;
NodeManager* nm = NodeManager::currentNM();
}
// make the default grammar
- tn = mkSygusDefaultType(
- preGrammarType, sfvl, ss.str(), extra_cons, exc_cons, term_irlv);
+ tn = mkSygusDefaultType(preGrammarType,
+ sfvl,
+ ss.str(),
+ extra_cons,
+ exc_cons,
+ inc_cons,
+ term_irlv);
}
// sfvl may be null for constant synthesis functions
Trace("cegqi-debug") << "...sygus var list associated with " << sf << " is "
TypeNode range,
Node bvl,
const std::string& fun,
- std::map<TypeNode, std::vector<Node>>& extra_cons,
- std::map<TypeNode, std::vector<Node>>& exc_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>& extra_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>& exc_cons,
+ const std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>&
+ inc_cons,
std::unordered_set<Node, NodeHashFunction>& term_irrelevant,
std::vector<CVC4::Datatype>& datatypes,
std::set<Type>& unres)
//add constants
std::vector< Node > consts;
mkSygusConstantsForType( types[i], consts );
- std::map< TypeNode, std::vector< Node > >::iterator itec = extra_cons.find( types[i] );
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>::iterator
+ itec = extra_cons.find(types[i]);
if( itec!=extra_cons.end() ){
- //consts.insert( consts.end(), itec->second.begin(), itec->second.end() );
- for (unsigned j = 0, size_j = itec->second.size(); j < size_j; ++j)
+ for (std::unordered_set<Node, NodeHashFunction>::iterator set_it =
+ itec->second.begin();
+ set_it != itec->second.end();
+ set_it++)
{
- if( std::find( consts.begin(), consts.end(), itec->second[j] )==consts.end() ){
- consts.push_back( itec->second[j] );
+ if (std::find(consts.begin(), consts.end(), *set_it) == consts.end())
+ {
+ consts.push_back(*set_it);
}
}
}
if (types[i].isReal())
{
- for (unsigned j = 0; j < 2; j++)
+ // Add PLUS, MINUS
+ Kind kinds[2] = {PLUS, MINUS};
+ for (const Kind k : kinds)
{
- Kind k = j == 0 ? PLUS : MINUS;
Trace("sygus-grammar-def") << "...add for " << k << std::endl;
ops[i].push_back(nm->operatorOf(k).toExpr());
cnames[i].push_back(kindToString(k));
{
Trace("sygus-grammar-def") << "...make datatype " << datatypes[i] << std::endl;
datatypes[i].setSygus( types[i].toType(), bvl.toExpr(), true, true );
- std::map<TypeNode, std::vector<Node>>::iterator itexc =
- exc_cons.find(types[i]);
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>::iterator
+ itexc = exc_cons.find(types[i]);
+ std::map<TypeNode,
+ std::unordered_set<Node, NodeHashFunction>>::const_iterator itinc =
+ inc_cons.find(types[i]);
for (unsigned j = 0, size = ops[i].size(); j < size; ++j)
{
- // add the constructor if it is not excluded
+ // add the constructor if it is not excluded,
+ // and it is in inc_cons, in case it is not empty
Node opn = Node::fromExpr(ops[i][j]);
+ Trace("sygus-grammar-def")
+ << "...considering " << opn.toString() << " of kind " << opn.getKind()
+ << " and of type " << opn.getType() << " and of kind of type "
+ << opn.getType().getKind() << " of metakind " << opn.getMetaKind()
+ << std::endl;
if (itexc == exc_cons.end()
|| std::find(itexc->second.begin(), itexc->second.end(), opn)
== itexc->second.end())
{
- datatypes[i].addSygusConstructor(
- ops[i][j], cnames[i][j], cargs[i][j], pcs[i][j], weights[i][j]);
+ Trace("sygus-grammar-def") << "......not excluded " << std::endl;
+ if ((opn.isVar()) || (opn.getType().getKind() != kind::TYPE_CONSTANT)
+ || (itinc == inc_cons.end())
+ || (std::find(itinc->second.begin(), itinc->second.end(), opn)
+ != itinc->second.end()))
+ {
+ Trace("sygus-grammar-def") << "......included " << std::endl;
+ datatypes[i].addSygusConstructor(
+ ops[i][j], cnames[i][j], cargs[i][j], pcs[i][j], weights[i][j]);
+ }
}
}
Trace("sygus-grammar-def") << "...built datatype " << datatypes[i] << " ";
TypeNode range,
Node bvl,
const std::string& fun,
- std::map<TypeNode, std::vector<Node>>& extra_cons,
- std::map<TypeNode, std::vector<Node>>& exclude_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>& extra_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>&
+ exclude_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>&
+ include_cons,
std::unordered_set<Node, NodeHashFunction>& term_irrelevant)
{
Trace("sygus-grammar-def") << "*** Make sygus default type " << range << ", make datatypes..." << std::endl;
- for( std::map< TypeNode, std::vector< Node > >::iterator it = extra_cons.begin(); it != extra_cons.end(); ++it ){
+ for (std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>::iterator
+ it = extra_cons.begin();
+ it != extra_cons.end();
+ ++it)
+ {
Trace("sygus-grammar-def") << " ...using " << it->second.size() << " extra constants for " << it->first << std::endl;
}
std::set<Type> unres;
fun,
extra_cons,
exclude_cons,
+ include_cons,
term_irrelevant,
datatypes,
unres);
/** is the syntax restricted? */
bool isSyntaxRestricted() { return d_is_syntax_restricted; }
/** make the default sygus datatype type corresponding to builtin type range
- * bvl is the set of free variables to include in the grammar
- * fun is for naming
- * extra_cons is a set of extra constant symbols to include in the grammar,
- * exclude_cons is used to exclude operators from the grammar,
- * term_irrelevant is a set of terms that should not be included in the
- * grammar.
- */
+ * arguments:
+ * - bvl: the set of free variables to include in the grammar
+ * - fun: used for naming
+ * - extra_cons: a set of extra constant symbols to include in the grammar,
+ * regardless of their inclusion in the default grammar.
+ * - exclude_cons: used to exclude operators from the grammar,
+ * - term_irrelevant: a set of terms that should not be included in the
+ * grammar.
+ * - include_cons: a set of operators such that if this set is not empty,
+ * its elements that are in the default grammar (and only them)
+ * will be included.
+ */
static TypeNode mkSygusDefaultType(
TypeNode range,
Node bvl,
const std::string& fun,
- std::map<TypeNode, std::vector<Node> >& extra_cons,
- std::map<TypeNode, std::vector<Node> >& exclude_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>& extra_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>&
+ exclude_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>&
+ include_cons,
std::unordered_set<Node, NodeHashFunction>& term_irrelevant);
/** make the default sygus datatype type corresponding to builtin type range */
static TypeNode mkSygusDefaultType(TypeNode range,
Node bvl,
const std::string& fun)
{
- std::map<TypeNode, std::vector<Node> > extra_cons;
- std::map<TypeNode, std::vector<Node> > exclude_cons;
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>> extra_cons;
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>> exclude_cons;
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>> include_cons;
std::unordered_set<Node, NodeHashFunction> term_irrelevant;
- return mkSygusDefaultType(
- range, bvl, fun, extra_cons, exclude_cons, term_irrelevant);
+ return mkSygusDefaultType(range,
+ bvl,
+ fun,
+ extra_cons,
+ exclude_cons,
+ include_cons,
+ term_irrelevant);
}
/** make the sygus datatype type that encodes the solution space (lambda
* templ_arg. templ[templ_arg]) where templ_arg
/** is the syntax restricted? */
bool d_is_syntax_restricted;
/** collect terms */
- void collectTerms( Node n, std::map< TypeNode, std::vector< Node > >& consts );
+ void collectTerms(
+ Node n,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>& consts);
//---------------- grammar construction
// helper for mkSygusDefaultGrammar (makes unresolved type for mutually recursive datatype construction)
static TypeNode mkUnresolvedType(const std::string& name, std::set<Type>& unres);
TypeNode range,
Node bvl,
const std::string& fun,
- std::map<TypeNode, std::vector<Node> >& extra_cons,
- std::map<TypeNode, std::vector<Node> >& exclude_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>&
+ extra_cons,
+ std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>&
+ exclude_cons,
+ const std::map<TypeNode, std::unordered_set<Node, NodeHashFunction>>&
+ include_cons,
std::unordered_set<Node, NodeHashFunction>& term_irrelevant,
std::vector<CVC4::Datatype>& datatypes,
std::set<Type>& unres);
+
// helper function for mkSygusTemplateType
static TypeNode mkSygusTemplateTypeRec( Node templ, Node templ_arg, TypeNode templ_arg_sygus_type, Node bvl,
const std::string& fun, unsigned& tcount );