static void testI(char const *ex) { ast_manager m; reg_decl_plugins(m); arith_util a(m); expr_ref fml = parse_fml(m, ex); symbol x_name("i"); sort_ref x_sort(a.mk_int(), m); app_ref var(m.mk_const(x_name, x_sort), m); test(var, fml); }
static void test2(char const *ex) { smt_params params; params.m_model = true; ast_manager m; reg_decl_plugins(m); arith_util a(m); expr_ref fml = parse_fml(m, ex); app_ref_vector vars(m); expr_ref_vector lits(m); vars.push_back(m.mk_const(symbol("x"), a.mk_real())); vars.push_back(m.mk_const(symbol("y"), a.mk_real())); vars.push_back(m.mk_const(symbol("z"), a.mk_real())); flatten_and(fml, lits); smt::context ctx(m, params); ctx.push(); ctx.assert_expr(fml); lbool result = ctx.check(); VERIFY(result == l_true); ref<model> md; ctx.get_model(md); ctx.pop(1); std::cout << mk_pp(fml, m) << "\n"; expr_ref pr1(m), pr2(m), fml2(m); expr_ref_vector bound(m); ptr_vector<sort> sorts; svector<symbol> names; for (unsigned i = 0; i < vars.size(); ++i) { bound.push_back(vars[i].get()); names.push_back(vars[i]->get_decl()->get_name()); sorts.push_back(m.get_sort(vars[i].get())); } expr_abstract(m, 0, bound.size(), bound.c_ptr(), fml, fml2); fml2 = m.mk_exists(bound.size(), sorts.c_ptr(), names.c_ptr(), fml2); qe::expr_quant_elim qe(m, params); for (unsigned i = 0; i < vars.size(); ++i) { VERIFY(qe::arith_project(*md, vars[i].get(), lits)); } pr1 = mk_and(lits); qe(m.mk_true(), fml2, pr2); std::cout << mk_pp(pr1, m) << "\n"; std::cout << mk_pp(pr2, m) << "\n"; expr_ref npr2(m); npr2 = m.mk_not(pr2); ctx.push(); ctx.assert_expr(pr1); ctx.assert_expr(npr2); VERIFY(l_false == ctx.check()); ctx.pop(1); }
static void parse_fml(char const* str, app_ref_vector& vars, expr_ref& fml) { ast_manager& m = fml.get_manager(); fml = parse_fml(m, str); if (is_exists(fml)) { quantifier* q = to_quantifier(fml); for (unsigned i = 0; i < q->get_num_decls(); ++i) { vars.push_back(m.mk_const(q->get_decl_name(i), q->get_decl_sort(i))); } fml = q->get_expr(); var_subst vs(m, true); vs(fml, vars.size(), (expr*const*)vars.c_ptr(), fml); } }
void tst_arith_rewriter() { ast_manager m; reg_decl_plugins(m); arith_rewriter ar(m); arith_util au(m); expr_ref t1(m), t2(m), result(m); t1 = au.mk_numeral(rational(0),false); t2 = au.mk_numeral(rational(-3),false); expr* args[2] = { t1, t2 }; ar.mk_mul(2, args, result); std::cout << mk_pp(result, m) << "\n"; th_rewriter rw(m); expr_ref fml = parse_fml(m, example1); rw(fml); std::cout << mk_pp(fml, m) << "\n"; fml = parse_fml(m, example2); rw(fml); std::cout << mk_pp(fml, m) << "\n"; }
static void test(char const *ex) { smt_params params; params.m_model = true; ast_manager m; reg_decl_plugins(m); arith_util a(m); expr_ref fml = parse_fml(m, ex); app_ref_vector vars(m); expr_ref_vector lits(m); vars.push_back(m.mk_const(symbol("x"), a.mk_real())); flatten_and(fml, lits); smt::context ctx(m, params); ctx.assert_expr(fml); lbool result = ctx.check(); SASSERT(result == l_true); ref<model> md; ctx.get_model(md); expr_ref pr = qe::arith_project(*md, vars, lits); std::cout << mk_pp(fml, m) << "\n"; std::cout << mk_pp(pr, m) << "\n"; }
static void test_quant_solver(ast_manager& m, char const* str, bool validate = true) { expr_ref fml(m); app_ref_vector vars(m); parse_fml(str, vars, fml); test_quant_solver(m, vars.size(), vars.c_ptr(), fml, validate); }
static void test_quant_solver(ast_manager& m, unsigned sz, app*const* xs, char const* str, bool validate = true) { expr_ref fml = parse_fml(m, str); test_quant_solver(m, sz, xs, fml, validate); }
static void test_quant_solver(ast_manager& m, app* x, char const* str, bool validate = true) { expr_ref fml = parse_fml(m, str); test_quant_solver(m, 1, &x, fml, validate); }