mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
merge with master
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
commit
c513f3ca09
883 changed files with 13979 additions and 16480 deletions
|
@ -13,6 +13,22 @@ find_package(Z3
|
|||
# use this option.
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Z3 C++ API bindings require C++11
|
||||
################################################################################
|
||||
if ("${CMAKE_VERSION}" VERSION_LESS "3.1")
|
||||
# Legacy CMake support
|
||||
if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
else()
|
||||
message(FATAL_ERROR "Setting C++ version to C++11 not supported for \"${CMAKE_CXX_COMPILER_ID}\"")
|
||||
endif()
|
||||
else ()
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
endif ()
|
||||
|
||||
message(STATUS "Z3_FOUND: ${Z3_FOUND}")
|
||||
message(STATUS "Found Z3 ${Z3_VERSION_STRING}")
|
||||
message(STATUS "Z3_DIR: ${Z3_DIR}")
|
||||
|
|
|
@ -1138,8 +1138,11 @@ static void parse_example() {
|
|||
decls.push_back(c.function("a", 0, 0, B));
|
||||
expr_vector a = c.parse_string("(assert a)", sorts, decls);
|
||||
std::cout << a << "\n";
|
||||
|
||||
// expr b = c.parse_string("(benchmark tst :extrafuns ((x Int) (y Int)) :formula (> x y) :formula (> x 0))");
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
try {
|
||||
|
|
|
@ -395,11 +395,10 @@ void assert_comm_axiom(Z3_context ctx, Z3_solver s, Z3_func_decl f)
|
|||
t_name = Z3_mk_string_symbol(ctx, "T");
|
||||
|
||||
|
||||
Z3_parse_smtlib_string(ctx,
|
||||
"(benchmark comm :formula (forall (x T) (y T) (= (f x y) (f y x))))",
|
||||
q = Z3_parse_smtlib2_string(ctx,
|
||||
"(assert (forall ((x T) (y T)) (= (f x y) (f y x))))",
|
||||
1, &t_name, &t,
|
||||
1, &f_name, &f);
|
||||
q = Z3_get_smtlib_formula(ctx, 0);
|
||||
printf("assert axiom:\n%s\n", Z3_ast_to_string(ctx, q));
|
||||
Z3_solver_assert(ctx, s, q);
|
||||
}
|
||||
|
@ -1547,7 +1546,7 @@ void two_contexts_example1()
|
|||
}
|
||||
|
||||
/**
|
||||
\brief Demonstrates how error codes can be read insted of registering an error handler.
|
||||
\brief Demonstrates how error codes can be read instead of registering an error handler.
|
||||
*/
|
||||
void error_code_example1()
|
||||
{
|
||||
|
@ -1632,35 +1631,6 @@ void error_code_example2() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Demonstrates how to use the SMTLIB parser.
|
||||
*/
|
||||
void parser_example1()
|
||||
{
|
||||
Z3_context ctx = mk_context();
|
||||
Z3_solver s = mk_solver(ctx);
|
||||
unsigned i, num_formulas;
|
||||
|
||||
printf("\nparser_example1\n");
|
||||
LOG_MSG("parser_example1");
|
||||
|
||||
|
||||
Z3_parse_smtlib_string(ctx,
|
||||
"(benchmark tst :extrafuns ((x Int) (y Int)) :formula (> x y) :formula (> x 0))",
|
||||
0, 0, 0,
|
||||
0, 0, 0);
|
||||
num_formulas = Z3_get_smtlib_num_formulas(ctx);
|
||||
for (i = 0; i < num_formulas; i++) {
|
||||
Z3_ast f = Z3_get_smtlib_formula(ctx, i);
|
||||
printf("formula %d: %s\n", i, Z3_ast_to_string(ctx, f));
|
||||
Z3_solver_assert(ctx, s, f);
|
||||
}
|
||||
|
||||
check(ctx, s, Z3_L_TRUE);
|
||||
|
||||
del_solver(ctx, s);
|
||||
Z3_del_context(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Demonstrates how to initialize the parser symbol table.
|
||||
|
@ -1690,12 +1660,11 @@ void parser_example2()
|
|||
names[0] = Z3_mk_string_symbol(ctx, "a");
|
||||
names[1] = Z3_mk_string_symbol(ctx, "b");
|
||||
|
||||
Z3_parse_smtlib_string(ctx,
|
||||
"(benchmark tst :formula (> a b))",
|
||||
f = Z3_parse_smtlib2_string(ctx,
|
||||
"(assert (> a b))",
|
||||
0, 0, 0,
|
||||
/* 'x' and 'y' declarations are inserted as 'a' and 'b' into the parser symbol table. */
|
||||
2, names, decls);
|
||||
f = Z3_get_smtlib_formula(ctx, 0);
|
||||
printf("formula: %s\n", Z3_ast_to_string(ctx, f));
|
||||
Z3_solver_assert(ctx, s, f);
|
||||
check(ctx, s, Z3_L_TRUE);
|
||||
|
@ -1737,11 +1706,10 @@ void parser_example3()
|
|||
|
||||
assert_comm_axiom(ctx, s, g);
|
||||
|
||||
Z3_parse_smtlib_string(ctx,
|
||||
"(benchmark tst :formula (forall (x Int) (y Int) (implies (= x y) (= (g x 0) (g 0 y)))))",
|
||||
thm = Z3_parse_smtlib2_string(ctx,
|
||||
"(assert (forall ((x Int) (y Int)) (=> (= x y) (= (g x 0) (g 0 y)))))",
|
||||
0, 0, 0,
|
||||
1, &g_name, &g);
|
||||
thm = Z3_get_smtlib_formula(ctx, 0);
|
||||
printf("formula: %s\n", Z3_ast_to_string(ctx, thm));
|
||||
prove(ctx, s, thm, Z3_TRUE);
|
||||
|
||||
|
@ -1749,41 +1717,6 @@ void parser_example3()
|
|||
Z3_del_context(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Display the declarations, assumptions and formulas in a SMT-LIB string.
|
||||
*/
|
||||
void parser_example4()
|
||||
{
|
||||
Z3_context ctx;
|
||||
unsigned i, num_decls, num_assumptions, num_formulas;
|
||||
|
||||
printf("\nparser_example4\n");
|
||||
LOG_MSG("parser_example4");
|
||||
|
||||
ctx = mk_context();
|
||||
|
||||
Z3_parse_smtlib_string(ctx,
|
||||
"(benchmark tst :extrafuns ((x Int) (y Int)) :assumption (= x 20) :formula (> x y) :formula (> x 0))",
|
||||
0, 0, 0,
|
||||
0, 0, 0);
|
||||
num_decls = Z3_get_smtlib_num_decls(ctx);
|
||||
for (i = 0; i < num_decls; i++) {
|
||||
Z3_func_decl d = Z3_get_smtlib_decl(ctx, i);
|
||||
printf("declaration %d: %s\n", i, Z3_func_decl_to_string(ctx, d));
|
||||
}
|
||||
num_assumptions = Z3_get_smtlib_num_assumptions(ctx);
|
||||
for (i = 0; i < num_assumptions; i++) {
|
||||
Z3_ast a = Z3_get_smtlib_assumption(ctx, i);
|
||||
printf("assumption %d: %s\n", i, Z3_ast_to_string(ctx, a));
|
||||
}
|
||||
num_formulas = Z3_get_smtlib_num_formulas(ctx);
|
||||
for (i = 0; i < num_formulas; i++) {
|
||||
Z3_ast f = Z3_get_smtlib_formula(ctx, i);
|
||||
printf("formula %d: %s\n", i, Z3_ast_to_string(ctx, f));
|
||||
}
|
||||
Z3_del_context(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Demonstrates how to handle parser errors using Z3 error handling support.
|
||||
*/
|
||||
|
@ -1802,9 +1735,9 @@ void parser_example5() {
|
|||
s = mk_solver(ctx);
|
||||
Z3_del_config(cfg);
|
||||
|
||||
Z3_parse_smtlib_string(ctx,
|
||||
Z3_parse_smtlib2_string(ctx,
|
||||
/* the following string has a parsing error: missing parenthesis */
|
||||
"(benchmark tst :extrafuns ((x Int (y Int)) :formula (> x y) :formula (> x 0))",
|
||||
"(declare-const x Int) declare-const y Int) (assert (and (> x y) (> x 0)))",
|
||||
0, 0, 0,
|
||||
0, 0, 0);
|
||||
e = Z3_get_error_code(ctx);
|
||||
|
@ -1817,7 +1750,7 @@ void parser_example5() {
|
|||
err:
|
||||
printf("Z3 error: %s.\n", Z3_get_error_msg(ctx, e));
|
||||
if (ctx != NULL) {
|
||||
printf("Error message: '%s'.\n",Z3_get_smtlib_error(ctx));
|
||||
printf("Error message: '%s'.\n",Z3_get_parser_error(ctx));
|
||||
del_solver(ctx, s);
|
||||
Z3_del_context(ctx);
|
||||
}
|
||||
|
@ -2600,7 +2533,7 @@ void reference_counter_example() {
|
|||
|
||||
cfg = Z3_mk_config();
|
||||
Z3_set_param_value(cfg, "model", "true");
|
||||
// Create a Z3 context where the user is reponsible for managing
|
||||
// Create a Z3 context where the user is responsible for managing
|
||||
// Z3_ast reference counters.
|
||||
ctx = Z3_mk_context_rc(cfg);
|
||||
Z3_del_config(cfg);
|
||||
|
@ -3067,10 +3000,8 @@ int main() {
|
|||
two_contexts_example1();
|
||||
error_code_example1();
|
||||
error_code_example2();
|
||||
parser_example1();
|
||||
parser_example2();
|
||||
parser_example3();
|
||||
parser_example4();
|
||||
parser_example5();
|
||||
numeral_example();
|
||||
ite_example();
|
||||
|
|
|
@ -173,10 +173,9 @@ namespace test_mapi
|
|||
throw new Exception("function must be binary, and argument types must be equal to return type");
|
||||
}
|
||||
|
||||
string bench = string.Format("(benchmark comm :formula (forall (x {0}) (y {1}) (= ({2} x y) ({3} y x))))",
|
||||
string bench = string.Format("(assert (forall ((x {0}) (y {1})) (= ({2} x y) ({3} y x))))",
|
||||
t.Name, t.Name, f.Name, f.Name);
|
||||
ctx.ParseSMTLIBString(bench, new Symbol[] { t.Name }, new Sort[] { t }, new Symbol[] { f.Name }, new FuncDecl[] { f });
|
||||
return ctx.SMTLIBFormulas[0];
|
||||
return ctx.ParseSMTLIB2String(bench, new Symbol[] { t.Name }, new Sort[] { t }, new Symbol[] { f.Name }, new FuncDecl[] { f });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -623,7 +622,7 @@ namespace test_mapi
|
|||
Console.WriteLine("{0}", q1);
|
||||
}
|
||||
|
||||
// Quantifier with de-Brujin indices.
|
||||
// Quantifier with de-Bruijn indices.
|
||||
{
|
||||
Expr x = ctx.MkBound(1, ctx.IntSort);
|
||||
Expr y = ctx.MkBound(0, ctx.IntSort);
|
||||
|
@ -965,21 +964,6 @@ namespace test_mapi
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows how to read an SMT1 file.
|
||||
/// </summary>
|
||||
static void SMT1FileTest(string filename)
|
||||
{
|
||||
Console.Write("SMT File test ");
|
||||
|
||||
using (Context ctx = new Context(new Dictionary<string, string>() { { "MODEL", "true" } }))
|
||||
{
|
||||
ctx.ParseSMTLIBFile(filename);
|
||||
|
||||
BoolExpr a = ctx.MkAnd(ctx.SMTLIBFormulas);
|
||||
Console.WriteLine("read formula: " + a);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows how to read an SMT2 file.
|
||||
|
@ -1399,11 +1383,10 @@ namespace test_mapi
|
|||
{
|
||||
Console.WriteLine("ParserExample1");
|
||||
|
||||
ctx.ParseSMTLIBString("(benchmark tst :extrafuns ((x Int) (y Int)) :formula (> x y) :formula (> x 0))");
|
||||
foreach (BoolExpr f in ctx.SMTLIBFormulas)
|
||||
Console.WriteLine("formula {0}", f);
|
||||
var fml = ctx.ParseSMTLIB2String("(declare-const x Int) (declare-const y Int) (assert (> x y)) (assert (> x 0))");
|
||||
Console.WriteLine("formula {0}", fml);
|
||||
|
||||
Model m = Check(ctx, ctx.MkAnd(ctx.SMTLIBFormulas), Status.SATISFIABLE);
|
||||
Model m = Check(ctx, fml, Status.SATISFIABLE);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1412,15 +1395,11 @@ namespace test_mapi
|
|||
public static void ParserExample2(Context ctx)
|
||||
{
|
||||
Console.WriteLine("ParserExample2");
|
||||
|
||||
Symbol[] declNames = { ctx.MkSymbol("a"), ctx.MkSymbol("b") };
|
||||
FuncDecl a = ctx.MkConstDecl(declNames[0], ctx.MkIntSort());
|
||||
FuncDecl b = ctx.MkConstDecl(declNames[1], ctx.MkIntSort());
|
||||
FuncDecl[] decls = new FuncDecl[] { a, b };
|
||||
|
||||
ctx.ParseSMTLIBString("(benchmark tst :formula (> a b))",
|
||||
null, null, declNames, decls);
|
||||
BoolExpr f = ctx.SMTLIBFormulas[0];
|
||||
BoolExpr f = ctx.ParseSMTLIB2String("(assert (> a b))", null, null, declNames, decls);
|
||||
Console.WriteLine("formula: {0}", f);
|
||||
Check(ctx, f, Status.SATISFIABLE);
|
||||
}
|
||||
|
@ -1438,39 +1417,15 @@ namespace test_mapi
|
|||
|
||||
BoolExpr ca = CommAxiom(ctx, g);
|
||||
|
||||
ctx.ParseSMTLIBString("(benchmark tst :formula (forall (x Int) (y Int) (implies (= x y) (= (gg x 0) (gg 0 y)))))",
|
||||
BoolExpr thm = ctx.ParseSMTLIB2String("(assert (forall ((x Int) (y Int)) (=> (= x y) (= (gg x 0) (gg 0 y)))))",
|
||||
null, null,
|
||||
new Symbol[] { ctx.MkSymbol("gg") },
|
||||
new FuncDecl[] { g });
|
||||
|
||||
BoolExpr thm = ctx.SMTLIBFormulas[0];
|
||||
Console.WriteLine("formula: {0}", thm);
|
||||
Prove(ctx, thm, false, ca);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display the declarations, assumptions and formulas in a SMT-LIB string.
|
||||
/// </summary>
|
||||
public static void ParserExample4(Context ctx)
|
||||
{
|
||||
Console.WriteLine("ParserExample4");
|
||||
|
||||
ctx.ParseSMTLIBString
|
||||
("(benchmark tst :extrafuns ((x Int) (y Int)) :assumption (= x 20) :formula (> x y) :formula (> x 0))");
|
||||
foreach (var decl in ctx.SMTLIBDecls)
|
||||
{
|
||||
Console.WriteLine("Declaration: {0}", decl);
|
||||
}
|
||||
foreach (var f in ctx.SMTLIBAssumptions)
|
||||
{
|
||||
Console.WriteLine("Assumption: {0}", f);
|
||||
}
|
||||
foreach (var f in ctx.SMTLIBFormulas)
|
||||
{
|
||||
Console.WriteLine("Formula: {0}", f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demonstrates how to handle parser errors using Z3 error handling support.
|
||||
/// </summary>
|
||||
|
@ -1481,9 +1436,9 @@ namespace test_mapi
|
|||
|
||||
try
|
||||
{
|
||||
ctx.ParseSMTLIBString(
|
||||
ctx.ParseSMTLIB2String(
|
||||
/* the following string has a parsing error: missing parenthesis */
|
||||
"(benchmark tst :extrafuns ((x Int (y Int)) :formula (> x y) :formula (> x 0))");
|
||||
"(declare-const x Int (declare-const y Int)) (assert (> x y))");
|
||||
}
|
||||
catch (Z3Exception e)
|
||||
{
|
||||
|
@ -1990,7 +1945,7 @@ namespace test_mapi
|
|||
BoolExpr p2 = ctx.MkBoolConst("P2");
|
||||
BoolExpr p3 = ctx.MkBoolConst("P3");
|
||||
BoolExpr p4 = ctx.MkBoolConst("P4");
|
||||
BoolExpr[] assumptions = new BoolExpr[] { ctx.MkNot(p1), ctx.MkNot(p2), ctx.MkNot(p3), ctx.MkNot(p4) };
|
||||
Expr[] assumptions = new Expr[] { ctx.MkNot(p1), ctx.MkNot(p2), ctx.MkNot(p3), ctx.MkNot(p4) };
|
||||
BoolExpr f1 = ctx.MkAnd(new BoolExpr[] { pa, pb, pc });
|
||||
BoolExpr f2 = ctx.MkAnd(new BoolExpr[] { pa, ctx.MkNot(pb), pc });
|
||||
BoolExpr f3 = ctx.MkOr(ctx.MkNot(pa), ctx.MkNot(pc));
|
||||
|
@ -2213,7 +2168,6 @@ namespace test_mapi
|
|||
BitvectorExample2(ctx);
|
||||
ParserExample1(ctx);
|
||||
ParserExample2(ctx);
|
||||
ParserExample4(ctx);
|
||||
ParserExample5(ctx);
|
||||
ITEExample(ctx);
|
||||
EvalExample1(ctx);
|
||||
|
|
|
@ -170,10 +170,9 @@ class JavaExample
|
|||
String bench = "(benchmark comm :formula (forall (x " + t.getName()
|
||||
+ ") (y " + t.getName() + ") (= (" + f.getName() + " x y) ("
|
||||
+ f.getName() + " y x))))";
|
||||
ctx.parseSMTLIBString(bench, new Symbol[] { t.getName() },
|
||||
return ctx.parseSMTLIB2String(bench, new Symbol[] { t.getName() },
|
||||
new Sort[] { t }, new Symbol[] { f.getName() },
|
||||
new FuncDecl[] { f });
|
||||
return ctx.getSMTLIBFormulas()[0];
|
||||
}
|
||||
|
||||
// / "Hello world" example: create a Z3 logical context, and delete it.
|
||||
|
@ -661,7 +660,7 @@ class JavaExample
|
|||
System.out.println(q1);
|
||||
}
|
||||
|
||||
// Quantifier with de-Brujin indices.
|
||||
// Quantifier with de-Bruijn indices.
|
||||
{
|
||||
Expr x = ctx.mkBound(1, ctx.getIntSort());
|
||||
Expr y = ctx.mkBound(0, ctx.getIntSort());
|
||||
|
@ -1028,21 +1027,6 @@ class JavaExample
|
|||
}
|
||||
}
|
||||
|
||||
// / Shows how to read an SMT1 file.
|
||||
|
||||
void smt1FileTest(String filename)
|
||||
{
|
||||
System.out.print("SMT File test ");
|
||||
|
||||
{
|
||||
HashMap<String, String> cfg = new HashMap<String, String>();
|
||||
Context ctx = new Context(cfg);
|
||||
ctx.parseSMTLIBFile(filename, null, null, null, null);
|
||||
|
||||
BoolExpr a = ctx.mkAnd(ctx.getSMTLIBFormulas());
|
||||
System.out.println("read formula: " + a);
|
||||
}
|
||||
}
|
||||
|
||||
// / Shows how to read an SMT2 file.
|
||||
|
||||
|
@ -1459,15 +1443,13 @@ class JavaExample
|
|||
System.out.println("ParserExample1");
|
||||
Log.append("ParserExample1");
|
||||
|
||||
ctx.parseSMTLIBString(
|
||||
"(benchmark tst :extrafuns ((x Int) (y Int)) :formula (> x y) :formula (> x 0))",
|
||||
BoolExpr f = ctx.parseSMTLIB2String(
|
||||
"(declare-const x Int) (declare-const y Int) (assert (and (> x y) (> x 0)))",
|
||||
null, null, null, null);
|
||||
for (BoolExpr f : ctx.getSMTLIBFormulas())
|
||||
System.out.println("formula " + f);
|
||||
System.out.println("formula " + f);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Model m = check(ctx, ctx.mkAnd(ctx.getSMTLIBFormulas()),
|
||||
Status.SATISFIABLE);
|
||||
Model m = check(ctx, f, Status.SATISFIABLE);
|
||||
}
|
||||
|
||||
// / Demonstrates how to initialize the parser symbol table.
|
||||
|
@ -1482,9 +1464,8 @@ class JavaExample
|
|||
FuncDecl b = ctx.mkConstDecl(declNames[1], ctx.mkIntSort());
|
||||
FuncDecl[] decls = new FuncDecl[] { a, b };
|
||||
|
||||
ctx.parseSMTLIBString("(benchmark tst :formula (> a b))", null, null,
|
||||
BoolExpr f = ctx.parseSMTLIB2String("(assert (> a b))", null, null,
|
||||
declNames, decls);
|
||||
BoolExpr f = ctx.getSMTLIBFormulas()[0];
|
||||
System.out.println("formula: " + f);
|
||||
check(ctx, f, Status.SATISFIABLE);
|
||||
}
|
||||
|
@ -1502,39 +1483,14 @@ class JavaExample
|
|||
|
||||
BoolExpr ca = commAxiom(ctx, g);
|
||||
|
||||
ctx.parseSMTLIBString(
|
||||
"(benchmark tst :formula (forall (x Int) (y Int) (implies (= x y) (= (gg x 0) (gg 0 y)))))",
|
||||
BoolExpr thm = ctx.parseSMTLIB2String(
|
||||
"(assert (forall ((x Int) (y Int)) (=> (= x y) (= (gg x 0) (gg 0 y)))))",
|
||||
null, null, new Symbol[] { ctx.mkSymbol("gg") },
|
||||
new FuncDecl[] { g });
|
||||
|
||||
BoolExpr thm = ctx.getSMTLIBFormulas()[0];
|
||||
System.out.println("formula: " + thm);
|
||||
prove(ctx, thm, false, ca);
|
||||
}
|
||||
|
||||
// / Display the declarations, assumptions and formulas in a SMT-LIB string.
|
||||
|
||||
public void parserExample4(Context ctx)
|
||||
{
|
||||
System.out.println("ParserExample4");
|
||||
Log.append("ParserExample4");
|
||||
|
||||
ctx.parseSMTLIBString(
|
||||
"(benchmark tst :extrafuns ((x Int) (y Int)) :assumption (= x 20) :formula (> x y) :formula (> x 0))",
|
||||
null, null, null, null);
|
||||
for (FuncDecl decl : ctx.getSMTLIBDecls())
|
||||
{
|
||||
System.out.println("Declaration: " + decl);
|
||||
}
|
||||
for (BoolExpr f : ctx.getSMTLIBAssumptions())
|
||||
{
|
||||
System.out.println("Assumption: " + f);
|
||||
}
|
||||
for (BoolExpr f : ctx.getSMTLIBFormulas())
|
||||
{
|
||||
System.out.println("Formula: " + f);
|
||||
}
|
||||
}
|
||||
|
||||
// / Demonstrates how to handle parser errors using Z3 error handling
|
||||
// support.
|
||||
|
@ -1546,12 +1502,12 @@ class JavaExample
|
|||
|
||||
try
|
||||
{
|
||||
ctx.parseSMTLIBString(
|
||||
ctx.parseSMTLIB2String(
|
||||
/*
|
||||
* the following string has a parsing error: missing
|
||||
* parenthesis
|
||||
*/
|
||||
"(benchmark tst :extrafuns ((x Int (y Int)) :formula (> x y) :formula (> x 0))",
|
||||
"(declare-const x Int (declare-const y Int)) (assert (> x y))",
|
||||
null, null, null, null);
|
||||
} catch (Z3Exception e)
|
||||
{
|
||||
|
@ -2341,7 +2297,6 @@ class JavaExample
|
|||
p.bitvectorExample2(ctx);
|
||||
p.parserExample1(ctx);
|
||||
p.parserExample2(ctx);
|
||||
p.parserExample4(ctx);
|
||||
p.parserExample5(ctx);
|
||||
p.iteExample(ctx);
|
||||
p.evalExample1(ctx);
|
||||
|
|
|
@ -9,4 +9,4 @@ On OSX and Linux, you must install z3 first using
|
|||
sudo make install
|
||||
OR update LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX) with the build directory. You need that to be able to find the Z3 shared library.
|
||||
|
||||
This directory contains a test file (ex.smt) that can be use as input for the maxsat test application.
|
||||
This directory contains a test file (ex.smt) that can be used as input for the maxsat test application.
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
(benchmark ex
|
||||
:logic AUFLIA
|
||||
:extrafuns ((x Int) (y Int) (z Int))
|
||||
:assumption (> x 0)
|
||||
:assumption (<= x -1)
|
||||
:assumption (or (> x 0) (< y 1))
|
||||
:assumption (> y 2)
|
||||
:assumption (> y 3)
|
||||
:assumption (<= y -1)
|
||||
:formula (= z (+ x y)))
|
||||
(declare-const x Int)
|
||||
(declare-const y Int)
|
||||
(declare-const z Int)
|
||||
(assert-soft (> x 0))
|
||||
(assert-soft (<= x -1))
|
||||
(assert-soft (or (> x 0) (< y 1)))
|
||||
(assert-soft (> y 2))
|
||||
(assert-soft (> y 3))
|
||||
(assert-soft (<= y -1))
|
||||
(assert (= z (+ x y)))
|
||||
|
|
@ -116,41 +116,6 @@ Z3_ast mk_binary_and(Z3_context ctx, Z3_ast in_1, Z3_ast in_2)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Get hard constraints from a SMT-LIB file. We assume hard constraints
|
||||
are formulas preceeded with the keyword :formula.
|
||||
Return an array containing all formulas read by the last Z3_parse_smtlib_file invocation.
|
||||
It will store the number of formulas in num_cnstrs.
|
||||
*/
|
||||
Z3_ast * get_hard_constraints(Z3_context ctx, unsigned * num_cnstrs)
|
||||
{
|
||||
Z3_ast * result;
|
||||
unsigned i;
|
||||
*num_cnstrs = Z3_get_smtlib_num_formulas(ctx);
|
||||
result = (Z3_ast *) malloc(sizeof(Z3_ast) * (*num_cnstrs));
|
||||
for (i = 0; i < *num_cnstrs; i++) {
|
||||
result[i] = Z3_get_smtlib_formula(ctx, i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Get soft constraints from a SMT-LIB file. We assume soft constraints
|
||||
are formulas preceeded with the keyword :assumption.
|
||||
Return an array containing all assumptions read by the last Z3_parse_smtlib_file invocation.
|
||||
It will store the number of formulas in num_cnstrs.
|
||||
*/
|
||||
Z3_ast * get_soft_constraints(Z3_context ctx, unsigned * num_cnstrs)
|
||||
{
|
||||
Z3_ast * result;
|
||||
unsigned i;
|
||||
*num_cnstrs = Z3_get_smtlib_num_assumptions(ctx);
|
||||
result = (Z3_ast *) malloc(sizeof(Z3_ast) * (*num_cnstrs));
|
||||
for (i = 0; i < *num_cnstrs; i++) {
|
||||
result[i] = Z3_get_smtlib_assumption(ctx, i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Free the given array of cnstrs that was allocated using get_hard_constraints or get_soft_constraints.
|
||||
|
@ -610,14 +575,37 @@ int smtlib_maxsat(char * file_name, int approach)
|
|||
{
|
||||
Z3_context ctx;
|
||||
Z3_solver s;
|
||||
unsigned i;
|
||||
Z3_optimize opt;
|
||||
unsigned num_hard_cnstrs, num_soft_cnstrs;
|
||||
Z3_ast * hard_cnstrs, * soft_cnstrs;
|
||||
Z3_ast_vector hard, objs;
|
||||
Z3_app soft;
|
||||
unsigned result = 0;
|
||||
ctx = mk_context();
|
||||
s = mk_solver(ctx);
|
||||
Z3_parse_smtlib_file(ctx, file_name, 0, 0, 0, 0, 0, 0);
|
||||
hard_cnstrs = get_hard_constraints(ctx, &num_hard_cnstrs);
|
||||
soft_cnstrs = get_soft_constraints(ctx, &num_soft_cnstrs);
|
||||
opt = Z3_mk_optimize(ctx);
|
||||
Z3_optimize_inc_ref(ctx, opt);
|
||||
Z3_optimize_from_file(ctx, opt, file_name);
|
||||
hard = Z3_optimize_get_assertions(ctx, opt);
|
||||
Z3_ast_vector_inc_ref(ctx, hard);
|
||||
num_hard_cnstrs = Z3_ast_vector_size(ctx, hard);
|
||||
hard_cnstrs = (Z3_ast *) malloc(sizeof(Z3_ast) * (num_hard_cnstrs));
|
||||
for (i = 0; i < num_hard_cnstrs; i++) {
|
||||
hard_cnstrs[i] = Z3_ast_vector_get(ctx, hard, i);
|
||||
}
|
||||
objs = Z3_optimize_get_objectives(ctx, opt);
|
||||
Z3_ast_vector_inc_ref(ctx, objs);
|
||||
|
||||
// soft constraints are stored in a single objective which is a sum
|
||||
// of if-then-else expressions.
|
||||
soft = Z3_to_app(ctx, Z3_ast_vector_get(ctx, objs, 0));
|
||||
num_soft_cnstrs = Z3_get_app_num_args(ctx, soft);
|
||||
soft_cnstrs = (Z3_ast *) malloc(sizeof(Z3_ast) * (num_soft_cnstrs));
|
||||
for (i = 0; i < num_soft_cnstrs; ++i) {
|
||||
soft_cnstrs[i] = Z3_get_app_arg(ctx, Z3_to_app(ctx, Z3_get_app_arg(ctx, soft, i)), 0);
|
||||
}
|
||||
|
||||
switch (approach) {
|
||||
case NAIVE_MAXSAT:
|
||||
result = naive_maxsat(ctx, s, num_hard_cnstrs, hard_cnstrs, num_soft_cnstrs, soft_cnstrs);
|
||||
|
@ -633,6 +621,7 @@ int smtlib_maxsat(char * file_name, int approach)
|
|||
free_cnstr_array(hard_cnstrs);
|
||||
free_cnstr_array(soft_cnstrs);
|
||||
Z3_solver_dec_ref(ctx, s);
|
||||
Z3_optimize_dec_ref(ctx, opt);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1609,7 +1609,6 @@ public:
|
|||
display_inference(out, "rewrite", "thm", p);
|
||||
break;
|
||||
case Z3_OP_PR_PULL_QUANT:
|
||||
case Z3_OP_PR_PULL_QUANT_STAR:
|
||||
display_inference(out, "pull_quant", "thm", p);
|
||||
break;
|
||||
case Z3_OP_PR_PUSH_QUANT:
|
||||
|
@ -1669,12 +1668,6 @@ public:
|
|||
case Z3_OP_PR_NNF_NEG:
|
||||
display_inference(out, "nnf_neg", "sab", p);
|
||||
break;
|
||||
case Z3_OP_PR_NNF_STAR:
|
||||
display_inference(out, "nnf", "sab", p);
|
||||
break;
|
||||
case Z3_OP_PR_CNF_STAR:
|
||||
display_inference(out, "cnf", "sab", p);
|
||||
break;
|
||||
case Z3_OP_PR_SKOLEMIZE:
|
||||
display_inference(out, "skolemize", "sab", p);
|
||||
break;
|
||||
|
@ -1706,10 +1699,6 @@ public:
|
|||
return display_hyp_inference(out, "modus_ponens", "thm", conclusion, hyp, hyp2);
|
||||
}
|
||||
case Z3_OP_PR_NNF_POS:
|
||||
case Z3_OP_PR_NNF_STAR:
|
||||
return display_hyp_inference(out, "nnf", "sab", conclusion, hyp);
|
||||
case Z3_OP_PR_CNF_STAR:
|
||||
return display_hyp_inference(out, "cnf", "sab", conclusion, hyp);
|
||||
case Z3_OP_PR_SKOLEMIZE:
|
||||
return display_hyp_inference(out, "skolemize", "sab", conclusion, hyp);
|
||||
case Z3_OP_PR_TRANSITIVITY:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue