3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

New API for adding 'tracked assertions'. Added wrappers for creating existential and universal quantifiers in the C++ API fronted. Added new examples for the C++ API

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2012-11-10 15:54:31 -08:00
parent 108bbb0597
commit caced62f40
5 changed files with 168 additions and 7 deletions

View file

@ -336,6 +336,35 @@ void ite_example() {
std::cout << "term: " << ite << "\n";
}
/**
\brief Small example using quantifiers.
*/
void quantifier_example() {
std::cout << "quantifier example\n";
context c;
expr x = c.int_const("x");
expr y = c.int_const("y");
sort I = c.int_sort();
func_decl f = function("f", I, I, I);
solver s(c);
// making sure model based quantifier instantiation is enabled.
params p(c);
p.set(":mbqi", true);
s.set(p);
s.add(forall(x, y, f(x, y) >= 0));
expr a = c.int_const("a");
s.add(f(a, a) < a);
std::cout << s << "\n";
std::cout << s.check() << "\n";
std::cout << s.get_model() << "\n";
s.add(a < 0);
std::cout << s.check() << "\n";
}
/**
\brief Unsat core example
*/
@ -426,6 +455,37 @@ void unsat_core_example2() {
}
}
/**
\brief Unsat core example 3
*/
void unsat_core_example3() {
// Extract unsat core using tracked assertions
std::cout << "unsat core example 3\n";
context c;
expr x = c.int_const("x");
expr y = c.int_const("y");
solver s(c);
// enabling unsat core tracking
params p(c);
p.set(":unsat-core", true);
s.set(p);
// The following assertion will not be tracked.
s.add(x > 0);
// The following assertion will be tracked using Boolean variable p1.
// The C++ wrapper will automatically create the Boolean variable.
s.add(y > 0, "p1");
// Asserting other tracked assertions.
s.add(x < 10, "p2");
s.add(y < 0, "p3");
std::cout << s.check() << "\n";
std::cout << s.unsat_core() << "\n";
}
void tactic_example1() {
/*
Z3 implements a methodology for orchestrating reasoning engines where "big" symbolic
@ -709,11 +769,8 @@ void tactic_qe() {
expr x = c.int_const("x");
expr f = implies(x <= a, x < b);
// We have to use the C API directly for creating quantified formulas.
Z3_app vars[] = {(Z3_app) x};
expr qf = to_expr(c, Z3_mk_forall_const(c, 0, 1, vars,
0, 0, // no pattern
f));
expr qf = forall(x, f);
std::cout << qf << "\n";
s.add(qf);
@ -769,8 +826,10 @@ int main() {
error_example(); std::cout << "\n";
numeral_example(); std::cout << "\n";
ite_example(); std::cout << "\n";
quantifier_example(); std::cout << "\n";
unsat_core_example1(); std::cout << "\n";
unsat_core_example2(); std::cout << "\n";
unsat_core_example3(); std::cout << "\n";
tactic_example1(); std::cout << "\n";
tactic_example2(); std::cout << "\n";
tactic_example3(); std::cout << "\n";