static void show_interpolant_and_maybe_check(cmd_context & ctx, ptr_vector<ast> &cnsts, expr *t, ptr_vector<ast> &interps, params_ref &m_params, bool check) { if (m_params.get_bool("som", false)) m_params.set_bool("flat", true); th_rewriter s(ctx.m(), m_params); for(unsigned i = 0; i < interps.size(); i++){ expr_ref r(ctx.m()); proof_ref pr(ctx.m()); s(to_expr(interps[i]),r,pr); ctx.regular_stream() << mk_pp(r.get(), ctx.m()) << std::endl; #if 0 ast_smt_pp pp(ctx.m()); pp.set_logic(ctx.get_logic().str().c_str()); pp.display_smt2(ctx.regular_stream(), to_expr(interps[i])); ctx.regular_stream() << std::endl; #endif } s.cleanup(); // verify, for the paranoid... if(check || interp_params(m_params).check()){ std::ostringstream err; ast_manager &_m = ctx.m(); // need a solver -- make one here FIXME is this right? bool proofs_enabled, models_enabled, unsat_core_enabled; params_ref p; ctx.params().get_solver_params(_m, p, proofs_enabled, models_enabled, unsat_core_enabled); scoped_ptr<solver> sp = (ctx.get_solver_factory())(_m, p, false, true, false, ctx.get_logic()); if(iz3check(_m,sp.get(),err,cnsts,t,interps)) ctx.regular_stream() << "correct\n"; else ctx.regular_stream() << "incorrect: " << err.str().c_str() << "\n"; } for(unsigned i = 0; i < interps.size(); i++){ ctx.m().dec_ref(interps[i]); } interp_params itp_params(m_params); if(itp_params.profile()) profiling::print(ctx.regular_stream()); }
virtual void execute(cmd_context & ctx) { if (m_target == 0) throw cmd_exception("invalid simplify command, argument expected"); expr_ref r(ctx.m()); proof_ref pr(ctx.m()); if (m_params.get_bool("som", false)) m_params.set_bool("flat", true); th_rewriter s(ctx.m(), m_params); unsigned cache_sz; unsigned num_steps = 0; unsigned timeout = m_params.get_uint("timeout", UINT_MAX); unsigned rlimit = m_params.get_uint("rlimit", UINT_MAX); bool failed = false; cancel_eh<reslimit> eh(ctx.m().limit()); { scoped_rlimit _rlimit(ctx.m().limit(), rlimit); scoped_ctrl_c ctrlc(eh); scoped_timer timer(timeout, &eh); cmd_context::scoped_watch sw(ctx); try { s(m_target, r, pr); } catch (z3_error & ex) { throw ex; } catch (z3_exception & ex) { ctx.regular_stream() << "(error \"simplifier failed: " << ex.msg() << "\")" << std::endl; failed = true; r = m_target; } cache_sz = s.get_cache_size(); num_steps = s.get_num_steps(); s.cleanup(); } if (m_params.get_bool("print", true)) { ctx.display(ctx.regular_stream(), r); ctx.regular_stream() << std::endl; } if (!failed && m_params.get_bool("print_proofs", false)) { ast_smt_pp pp(ctx.m()); pp.set_logic(ctx.get_logic().str().c_str()); pp.display_expr_smt2(ctx.regular_stream(), pr.get()); ctx.regular_stream() << std::endl; } if (m_params.get_bool("print_statistics", false)) { shared_occs s1(ctx.m()); if (!failed) s1(r); unsigned long long max_mem = memory::get_max_used_memory(); unsigned long long mem = memory::get_allocation_size(); ctx.regular_stream() << "(:time " << std::fixed << std::setprecision(2) << ctx.get_seconds() << " :num-steps " << num_steps << " :memory " << std::fixed << std::setprecision(2) << static_cast<double>(mem)/static_cast<double>(1024*1024) << " :max-memory " << std::fixed << std::setprecision(2) << static_cast<double>(max_mem)/static_cast<double>(1024*1024) << " :cache-size: " << cache_sz << " :num-nodes-before " << get_num_exprs(m_target); if (!failed) ctx.regular_stream() << " :num-shared " << s1.num_shared() << " :num-nodes " << get_num_exprs(r); ctx.regular_stream() << ")" << std::endl; } }
static void compute_interpolant_and_maybe_check(cmd_context & ctx, expr * t, params_ref &m_params, bool check){ // create a fresh solver suitable for interpolation bool proofs_enabled, models_enabled, unsat_core_enabled; params_ref p; ast_manager &_m = ctx.m(); // TODO: the following is a HACK to enable proofs in the old smt solver // When we stop using that solver, this hack can be removed scoped_proof_mode spm(_m,PGM_FINE); ctx.params().get_solver_params(_m, p, proofs_enabled, models_enabled, unsat_core_enabled); p.set_bool("proof", true); scoped_ptr<solver> sp = (ctx.get_interpolating_solver_factory())(_m, p, true, models_enabled, false, ctx.get_logic()); ptr_vector<ast> cnsts; ptr_vector<ast> interps; model_ref m; // compute an interpolant lbool res; try { res = iz3interpolate(_m, *sp.get(), t, cnsts, interps, m, 0); } catch (iz3_incompleteness &) { throw cmd_exception("incompleteness in interpolator"); } switch(res){ case l_false: ctx.regular_stream() << "unsat\n"; show_interpolant_and_maybe_check(ctx, cnsts, t, interps, m_params, check); break; case l_true: ctx.regular_stream() << "sat\n"; // TODO: how to return the model to the context, if it exists? break; case l_undef: ctx.regular_stream() << "unknown\n"; // TODO: how to return the model to the context, if it exists? break; } for(unsigned i = 0; i < cnsts.size(); i++) ctx.m().dec_ref(cnsts[i]); }