Term leq = slv.mkTerm(LEQ, {start, start});
// create the grammar object
- Grammar g = slv.mkSygusGrammar({x, y}, {start, start_bool});
+ Grammar g = slv.mkGrammar({x, y}, {start, start_bool});
// bind each non-terminal to its rules
g.addRules(start, {zero, one, x, y, plus, minus, ite});
Term plus = slv.mkTerm(ADD, {x, start});
// create the grammar object
- Grammar g1 = slv.mkSygusGrammar({x}, {start});
+ Grammar g1 = slv.mkGrammar({x}, {start});
// bind each non-terminal to its rules
g1.addRules(start, {neg_x, plus});
Term leq = slv.mkTerm(LEQ, start, start);
// create the grammar object
- Grammar g = slv.mkSygusGrammar(new Term[] {x, y}, new Term[] {start, start_bool});
+ Grammar g =
+ slv.mkGrammar(new Term[] {x, y}, new Term[] {start, start_bool});
// bind each non-terminal to its rules
g.addRules(start, new Term[] {zero, one, x, y, plus, minus, ite});
Term plus = slv.mkTerm(ADD, x, start);
// create the grammar object
- Grammar g1 = slv.mkSygusGrammar(new Term[] {x}, new Term[] {start});
+ Grammar g1 = slv.mkGrammar(new Term[] {x}, new Term[] {start});
// bind each non-terminal to its rules
g1.addRules(start, new Term[] {neg_x, plus});
leq = slv.mkTerm(Kind.LEQ, start, start)
# create the grammar object
- g = slv.mkSygusGrammar([x, y], [start, start_bool])
+ g = slv.mkGrammar([x, y], [start, start_bool])
# bind each non-terminal to its rules
g.addRules(start, {zero, one, x, y, plus, minus, ite})
plus = slv.mkTerm(Kind.ADD, x, start)
# create the grammar object
- g1 = slv.mkSygusGrammar({x}, {start})
- g2 = slv.mkSygusGrammar({x}, {start})
- g3 = slv.mkSygusGrammar({x}, {start})
+ g1 = slv.mkGrammar({x}, {start})
+ g2 = slv.mkGrammar({x}, {start})
+ g3 = slv.mkGrammar({x}, {start})
# bind each non-terminal to its rules
g1.addRules(start, {neg_x, plus})
CVC5_API_TRY_CATCH_END;
}
-Grammar Solver::mkSygusGrammar(const std::vector<Term>& boundVars,
- const std::vector<Term>& ntSymbols) const
+Grammar Solver::mkGrammar(const std::vector<Term>& boundVars,
+ const std::vector<Term>& ntSymbols) const
{
CVC5_API_TRY_CATCH_BEGIN;
CVC5_API_ARG_SIZE_CHECK_EXPECTED(!ntSymbols.empty(), ntSymbols)
* @param ntSymbols the pre-declaration of the non-terminal symbols
* @return the grammar
*/
- Grammar mkSygusGrammar(const std::vector<Term>& boundVars,
- const std::vector<Term>& ntSymbols) const;
+ Grammar mkGrammar(const std::vector<Term>& boundVars,
+ const std::vector<Term>& ntSymbols) const;
/**
* Synthesize n-ary function.
* @param ntSymbols the pre-declaration of the non-terminal symbols
* @return the grammar
*/
- public Grammar mkSygusGrammar(Term[] boundVars, Term[] ntSymbols)
- {
+ public Grammar mkGrammar(Term[] boundVars, Term[] ntSymbols) {
long[] boundVarPointers = Utils.getPointers(boundVars);
long[] ntSymbolPointers = Utils.getPointers(ntSymbols);
- long grammarPointer = mkSygusGrammar(pointer, boundVarPointers, ntSymbolPointers);
+ long grammarPointer =
+ mkGrammar(pointer, boundVarPointers, ntSymbolPointers);
return new Grammar(this, grammarPointer);
}
- private native long mkSygusGrammar(
+ private native long mkGrammar(
long pointer, long[] boundVarPointers, long[] ntSymbolPointers);
/**
/*
* Class: io_github_cvc5_Solver
- * Method: mkSygusGrammar
+ * Method: mkGrammar
* Signature: (J[J[J)J
*/
JNIEXPORT jlong JNICALL
-Java_io_github_cvc5_Solver_mkSygusGrammar(JNIEnv* env,
- jobject,
- jlong pointer,
- jlongArray jBoundVars,
- jlongArray jNtSymbols)
+Java_io_github_cvc5_Solver_mkGrammar(JNIEnv* env,
+ jobject,
+ jlong pointer,
+ jlongArray jBoundVars,
+ jlongArray jNtSymbols)
{
CVC5_JAVA_API_TRY_CATCH_BEGIN;
Solver* solver = reinterpret_cast<Solver*>(pointer);
std::vector<Term> boundVars = getObjectsFromPointers<Term>(env, jBoundVars);
std::vector<Term> ntSymbols = getObjectsFromPointers<Term>(env, jNtSymbols);
- Grammar* retPointer =
- new Grammar(solver->mkSygusGrammar(boundVars, ntSymbols));
+ Grammar* retPointer = new Grammar(solver->mkGrammar(boundVars, ntSymbols));
return reinterpret_cast<jlong>(retPointer);
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
}
Op mkOp(Kind kind, const string& arg) except +
Op mkOp(Kind kind, const vector[uint32_t]& args) except +
# Sygus related functions
- Grammar mkSygusGrammar(const vector[Term]& boundVars, const vector[Term]& ntSymbols) except +
+ Grammar mkGrammar(const vector[Term]& boundVars, const vector[Term]& ntSymbols) except +
Term declareSygusVar(const string& symbol, Sort sort) except +
void addSygusConstraint(Term term) except +
void addSygusAssume(Term term) except +
r.cr = self.csolver.checkSat()
return r
- def mkSygusGrammar(self, boundVars, ntSymbols):
+ def mkGrammar(self, boundVars, ntSymbols):
"""
Create a SyGuS grammar. The first non-terminal is treated as the
starting non-terminal, so the order of non-terminals matters.
bvc.push_back((<Term?> bv).cterm)
for nt in ntSymbols:
ntc.push_back((<Term?> nt).cterm)
- grammar.cgrammar = self.csolver.mkSygusGrammar(<const vector[c_Term]&> bvc, <const vector[c_Term]&> ntc)
+ grammar.cgrammar = self.csolver.mkGrammar(<const vector[c_Term]&> bvc, <const vector[c_Term]&> ntc)
return grammar
def declareSygusVar(self, str symbol, Sort sort):
const std::vector<cvc5::Term>& ntSymbols)
{
d_allocGrammars.emplace_back(
- new cvc5::Grammar(d_solver->mkSygusGrammar(boundVars, ntSymbols)));
+ new cvc5::Grammar(d_solver->mkGrammar(boundVars, ntSymbols)));
return d_allocGrammars.back().get();
}
Term start = d_solver.mkVar(boolean);
Term nts = d_solver.mkVar(boolean);
- Grammar g = d_solver.mkSygusGrammar({}, {start});
+ Grammar g = d_solver.mkGrammar({}, {start});
ASSERT_NO_THROW(g.addRule(start, d_solver.mkBoolean(false)));
Term start = d_solver.mkVar(boolean);
Term nts = d_solver.mkVar(boolean);
- Grammar g = d_solver.mkSygusGrammar({}, {start});
+ Grammar g = d_solver.mkGrammar({}, {start});
ASSERT_NO_THROW(g.addRules(start, {d_solver.mkBoolean(false)}));
Term start = d_solver.mkVar(boolean);
Term nts = d_solver.mkVar(boolean);
- Grammar g = d_solver.mkSygusGrammar({}, {start});
+ Grammar g = d_solver.mkGrammar({}, {start});
ASSERT_NO_THROW(g.addAnyConstant(start));
ASSERT_NO_THROW(g.addAnyConstant(start));
Term start = d_solver.mkVar(boolean);
Term nts = d_solver.mkVar(boolean);
- Grammar g1 = d_solver.mkSygusGrammar({x}, {start});
- Grammar g2 = d_solver.mkSygusGrammar({}, {start});
+ Grammar g1 = d_solver.mkGrammar({x}, {start});
+ Grammar g2 = d_solver.mkGrammar({}, {start});
ASSERT_NO_THROW(g1.addAnyVariable(start));
ASSERT_NO_THROW(g1.addAnyVariable(start));
Term truen = d_solver.mkBoolean(true);
Term start = d_solver.mkVar(boolean);
Term output2;
- Grammar g = d_solver.mkSygusGrammar({}, {start});
+ Grammar g = d_solver.mkGrammar({}, {start});
Term conj2 = d_solver.mkTerm(GT, {x, zero});
ASSERT_NO_THROW(g.addRule(start, truen));
// Call the abduction api, while the resulting abduct is the output
ASSERT_THROW(slv.declareSygusVar("", boolSort), CVC5ApiException);
}
-TEST_F(TestApiBlackSolver, mkSygusGrammar)
+TEST_F(TestApiBlackSolver, mkGrammar)
{
Term nullTerm;
Term boolTerm = d_solver.mkBoolean(true);
Term boolVar = d_solver.mkVar(d_solver.getBooleanSort());
Term intVar = d_solver.mkVar(d_solver.getIntegerSort());
- ASSERT_NO_THROW(d_solver.mkSygusGrammar({}, {intVar}));
- ASSERT_NO_THROW(d_solver.mkSygusGrammar({boolVar}, {intVar}));
- ASSERT_THROW(d_solver.mkSygusGrammar({}, {}), CVC5ApiException);
- ASSERT_THROW(d_solver.mkSygusGrammar({}, {nullTerm}), CVC5ApiException);
- ASSERT_THROW(d_solver.mkSygusGrammar({}, {boolTerm}), CVC5ApiException);
- ASSERT_THROW(d_solver.mkSygusGrammar({boolTerm}, {intVar}), CVC5ApiException);
+ ASSERT_NO_THROW(d_solver.mkGrammar({}, {intVar}));
+ ASSERT_NO_THROW(d_solver.mkGrammar({boolVar}, {intVar}));
+ ASSERT_THROW(d_solver.mkGrammar({}, {}), CVC5ApiException);
+ ASSERT_THROW(d_solver.mkGrammar({}, {nullTerm}), CVC5ApiException);
+ ASSERT_THROW(d_solver.mkGrammar({}, {boolTerm}), CVC5ApiException);
+ ASSERT_THROW(d_solver.mkGrammar({boolTerm}, {intVar}), CVC5ApiException);
Solver slv;
Term boolVar2 = slv.mkVar(slv.getBooleanSort());
Term intVar2 = slv.mkVar(slv.getIntegerSort());
- ASSERT_NO_THROW(slv.mkSygusGrammar({boolVar2}, {intVar2}));
- ASSERT_THROW(slv.mkSygusGrammar({boolVar}, {intVar2}), CVC5ApiException);
- ASSERT_THROW(slv.mkSygusGrammar({boolVar2}, {intVar}), CVC5ApiException);
+ ASSERT_NO_THROW(slv.mkGrammar({boolVar2}, {intVar2}));
+ ASSERT_THROW(slv.mkGrammar({boolVar}, {intVar2}), CVC5ApiException);
+ ASSERT_THROW(slv.mkGrammar({boolVar2}, {intVar}), CVC5ApiException);
}
TEST_F(TestApiBlackSolver, synthFun)
Term start1 = d_solver.mkVar(boolean);
Term start2 = d_solver.mkVar(integer);
- Grammar g1 = d_solver.mkSygusGrammar({x}, {start1});
+ Grammar g1 = d_solver.mkGrammar({x}, {start1});
g1.addRule(start1, d_solver.mkBoolean(false));
- Grammar g2 = d_solver.mkSygusGrammar({x}, {start2});
+ Grammar g2 = d_solver.mkGrammar({x}, {start2});
g2.addRule(start2, d_solver.mkInteger(0));
ASSERT_NO_THROW(d_solver.synthFun("", {}, boolean));
Term start1 = d_solver.mkVar(boolean);
Term start2 = d_solver.mkVar(integer);
- Grammar g1 = d_solver.mkSygusGrammar({x}, {start1});
+ Grammar g1 = d_solver.mkGrammar({x}, {start1});
g1.addRule(start1, d_solver.mkBoolean(false));
- Grammar g2 = d_solver.mkSygusGrammar({x}, {start2});
+ Grammar g2 = d_solver.mkGrammar({x}, {start2});
g2.addRule(start2, d_solver.mkInteger(0));
ASSERT_NO_THROW(d_solver.synthInv("", {}));
Term start = d_solver.mkVar(bool);
Term nts = d_solver.mkVar(bool);
- Grammar g = d_solver.mkSygusGrammar(new Term[] {}, new Term[] {start});
+ Grammar g = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
assertDoesNotThrow(() -> g.addRule(start, d_solver.mkBoolean(false)));
Term start = d_solver.mkVar(bool);
Term nts = d_solver.mkVar(bool);
- Grammar g = d_solver.mkSygusGrammar(new Term[] {}, new Term[] {start});
+ Grammar g = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
assertDoesNotThrow(() -> g.addRules(start, new Term[] {d_solver.mkBoolean(false)}));
Term start = d_solver.mkVar(bool);
Term nts = d_solver.mkVar(bool);
- Grammar g = d_solver.mkSygusGrammar(new Term[] {}, new Term[] {start});
+ Grammar g = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
assertDoesNotThrow(() -> g.addAnyConstant(start));
assertDoesNotThrow(() -> g.addAnyConstant(start));
Term start = d_solver.mkVar(bool);
Term nts = d_solver.mkVar(bool);
- Grammar g1 = d_solver.mkSygusGrammar(new Term[] {x}, new Term[] {start});
- Grammar g2 = d_solver.mkSygusGrammar(new Term[] {}, new Term[] {start});
+ Grammar g1 = d_solver.mkGrammar(new Term[] {x}, new Term[] {start});
+ Grammar g2 = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
assertDoesNotThrow(() -> g1.addAnyVariable(start));
assertDoesNotThrow(() -> g1.addAnyVariable(start));
Term truen = d_solver.mkBoolean(true);
Term start = d_solver.mkVar(bsort);
Term output2 = d_solver.getNullTerm();
- Grammar g = d_solver.mkSygusGrammar(new Term[] {}, new Term[] {start});
+ Grammar g = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
Term conj2 = d_solver.mkTerm(GT, x, zero);
assertDoesNotThrow(() -> g.addRule(start, truen));
// Call the abduction api, while the resulting abduct is the output
}
@Test
- void mkSygusGrammar() throws CVC5ApiException
- {
+ void mkGrammar() throws CVC5ApiException {
Term nullTerm = d_solver.getNullTerm();
Term boolTerm = d_solver.mkBoolean(true);
Term boolVar = d_solver.mkVar(d_solver.getBooleanSort());
Term intVar = d_solver.mkVar(d_solver.getIntegerSort());
- assertDoesNotThrow(() -> d_solver.mkSygusGrammar(new Term[] {}, new Term[] {intVar}));
- assertDoesNotThrow(() -> d_solver.mkSygusGrammar(new Term[] {boolVar}, new Term[] {intVar}));
+ assertDoesNotThrow(
+ () -> d_solver.mkGrammar(new Term[] {}, new Term[] {intVar}));
+ assertDoesNotThrow(
+ () -> d_solver.mkGrammar(new Term[] {boolVar}, new Term[] {intVar}));
- assertThrows(
- CVC5ApiException.class, () -> d_solver.mkSygusGrammar(new Term[] {}, new Term[] {}));
assertThrows(CVC5ApiException.class,
- () -> d_solver.mkSygusGrammar(new Term[] {}, new Term[] {nullTerm}));
+ () -> d_solver.mkGrammar(new Term[] {}, new Term[] {}));
+ assertThrows(CVC5ApiException.class,
+ () -> d_solver.mkGrammar(new Term[] {}, new Term[] {nullTerm}));
assertThrows(CVC5ApiException.class,
- () -> d_solver.mkSygusGrammar(new Term[] {}, new Term[] {boolTerm}));
+ () -> d_solver.mkGrammar(new Term[] {}, new Term[] {boolTerm}));
assertThrows(CVC5ApiException.class,
- () -> d_solver.mkSygusGrammar(new Term[] {boolTerm}, new Term[] {intVar}));
+ () -> d_solver.mkGrammar(new Term[] {boolTerm}, new Term[] {intVar}));
Solver slv = new Solver();
slv.setOption("sygus", "true");
Term boolVar2 = slv.mkVar(slv.getBooleanSort());
Term intVar2 = slv.mkVar(slv.getIntegerSort());
- assertDoesNotThrow(() -> slv.mkSygusGrammar(new Term[] {boolVar2}, new Term[] {intVar2}));
+ assertDoesNotThrow(
+ () -> slv.mkGrammar(new Term[] {boolVar2}, new Term[] {intVar2}));
assertThrows(CVC5ApiException.class,
- () -> slv.mkSygusGrammar(new Term[] {boolVar}, new Term[] {intVar2}));
+ () -> slv.mkGrammar(new Term[] {boolVar}, new Term[] {intVar2}));
assertThrows(CVC5ApiException.class,
- () -> slv.mkSygusGrammar(new Term[] {boolVar2}, new Term[] {intVar}));
+ () -> slv.mkGrammar(new Term[] {boolVar2}, new Term[] {intVar}));
slv.close();
}
Term start1 = d_solver.mkVar(bool);
Term start2 = d_solver.mkVar(integer);
- Grammar g1 = d_solver.mkSygusGrammar(new Term[] {x}, new Term[] {start1});
+ Grammar g1 = d_solver.mkGrammar(new Term[] {x}, new Term[] {start1});
g1.addRule(start1, d_solver.mkBoolean(false));
- Grammar g2 = d_solver.mkSygusGrammar(new Term[] {x}, new Term[] {start2});
+ Grammar g2 = d_solver.mkGrammar(new Term[] {x}, new Term[] {start2});
g2.addRule(start2, d_solver.mkInteger(0));
assertDoesNotThrow(() -> d_solver.synthFun("", new Term[] {}, bool));
Term start1 = d_solver.mkVar(bool);
Term start2 = d_solver.mkVar(integer);
- Grammar g1 = d_solver.mkSygusGrammar(new Term[] {x}, new Term[] {start1});
+ Grammar g1 = d_solver.mkGrammar(new Term[] {x}, new Term[] {start1});
g1.addRule(start1, d_solver.mkBoolean(false));
- Grammar g2 = d_solver.mkSygusGrammar(new Term[] {x}, new Term[] {start2});
+ Grammar g2 = d_solver.mkGrammar(new Term[] {x}, new Term[] {start2});
g2.addRule(start2, d_solver.mkInteger(0));
assertDoesNotThrow(() -> d_solver.synthInv("", new Term[] {}));
nts = solver.mkVar(boolean)
# expecting no error
- g = solver.mkSygusGrammar([], [start])
+ g = solver.mkGrammar([], [start])
g.addRule(start, solver.mkBoolean(False))
start = solver.mkVar(boolean)
nts = solver.mkVar(boolean)
- g = solver.mkSygusGrammar([], [start])
+ g = solver.mkGrammar([], [start])
g.addRules(start, {solver.mkBoolean(False)})
start = solver.mkVar(boolean)
nts = solver.mkVar(boolean)
- g = solver.mkSygusGrammar({}, {start})
+ g = solver.mkGrammar({}, {start})
g.addAnyConstant(start)
g.addAnyConstant(start)
start = solver.mkVar(boolean)
nts = solver.mkVar(boolean)
- g1 = solver.mkSygusGrammar({x}, {start})
- g2 = solver.mkSygusGrammar({}, {start})
+ g1 = solver.mkGrammar({x}, {start})
+ g2 = solver.mkGrammar({}, {start})
g1.addAnyVariable(start)
g1.addAnyVariable(start)
boolVar = solver.mkVar(solver.getBooleanSort())
intVar = solver.mkVar(solver.getIntegerSort())
- solver.mkSygusGrammar([], [intVar])
- solver.mkSygusGrammar([boolVar], [intVar])
+ solver.mkGrammar([], [intVar])
+ solver.mkGrammar([boolVar], [intVar])
with pytest.raises(RuntimeError):
- solver.mkSygusGrammar([], [])
+ solver.mkGrammar([], [])
with pytest.raises(RuntimeError):
- solver.mkSygusGrammar([], [nullTerm])
+ solver.mkGrammar([], [nullTerm])
with pytest.raises(RuntimeError):
- solver.mkSygusGrammar([], [boolTerm])
+ solver.mkGrammar([], [boolTerm])
with pytest.raises(RuntimeError):
- solver.mkSygusGrammar([boolTerm], [intVar])
+ solver.mkGrammar([boolTerm], [intVar])
slv = cvc5.Solver()
boolVar2 = slv.mkVar(slv.getBooleanSort())
intVar2 = slv.mkVar(slv.getIntegerSort())
- slv.mkSygusGrammar([boolVar2], [intVar2])
+ slv.mkGrammar([boolVar2], [intVar2])
with pytest.raises(RuntimeError):
- slv.mkSygusGrammar([boolVar], [intVar2])
+ slv.mkGrammar([boolVar], [intVar2])
with pytest.raises(RuntimeError):
- slv.mkSygusGrammar([boolVar2], [intVar])
+ slv.mkGrammar([boolVar2], [intVar])
def test_synth_inv(solver):
start1 = solver.mkVar(boolean)
start2 = solver.mkVar(integer)
- g1 = solver.mkSygusGrammar([x], [start1])
+ g1 = solver.mkGrammar([x], [start1])
g1.addRule(start1, solver.mkBoolean(False))
- g2 = solver.mkSygusGrammar([x], [start2])
+ g2 = solver.mkGrammar([x], [start2])
g2.addRule(start2, solver.mkInteger(0))
solver.synthInv("", [])
truen = solver.mkBoolean(True)
start = solver.mkVar(boolean)
output2 = cvc5.Term(solver)
- g = solver.mkSygusGrammar([], [start])
+ g = solver.mkGrammar([], [start])
conj2 = solver.mkTerm(Kind.GT, x, zero)
g.addRule(start, truen)
output2 = solver.getAbduct(conj2, g)
start1 = solver.mkVar(boolean)
start2 = solver.mkVar(integer)
- g1 = solver.mkSygusGrammar(x, [start1])
+ g1 = solver.mkGrammar(x, [start1])
g1.addRule(start1, solver.mkBoolean(False))
- g2 = solver.mkSygusGrammar(x, [start2])
+ g2 = solver.mkGrammar(x, [start2])
g2.addRule(start2, solver.mkInteger(0))
solver.synthFun("", [], boolean)