Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
ast * get_ast_ref(cmd_context & ctx, symbol const & v) {
    object_ref * r = ctx.find_object_ref(v);
    SASSERT(r != 0);
    if (r->kind() != ast_object_ref::cls_kind()) 
        throw cmd_exception("global variable does not reference an AST");
    return static_cast<ast_object_ref*>(r)->get_ast();
}
Ejemplo n.º 3
0
    virtual void execute(cmd_context& ctx) {
        if (m_target == 0) {
            throw cmd_exception("invalid query command, argument expected");
        }
        datalog::context& dlctx = m_dl_ctx->get_dl_context();
        set_background(ctx);        
        dlctx.updt_params(m_params);
        unsigned timeout   = m_params.get_uint(":timeout", UINT_MAX);
        cancel_eh<datalog::context> eh(dlctx);
        lbool status = l_undef;
        {
            scoped_ctrl_c ctrlc(eh);
            scoped_timer timer(timeout, &eh);
            cmd_context::scoped_watch sw(ctx);
            try {
                status = dlctx.query(m_target);
            }
            catch (z3_error & ex) {
                throw ex;
            }
            catch (z3_exception& ex) {
                ctx.regular_stream() << "(error \"query failed: " << ex.msg() << "\")" << std::endl;
            }
            dlctx.cleanup();
        }
        switch (status) {
        case l_false:
            ctx.regular_stream() << "unsat\n";
            print_certificate(ctx);
            break;
        case l_true: 
            ctx.regular_stream() << "sat\n";
            print_answer(ctx);
            print_certificate(ctx);
            break;
        case l_undef: 
            ctx.regular_stream() << "unknown\n";
            switch(dlctx.get_status()) {
            case datalog::INPUT_ERROR:
                break;
                
            case datalog::MEMOUT:
                ctx.regular_stream() << "memory bounds exceeded\n";
                break;

            case datalog::TIMEOUT:
                ctx.regular_stream() << "timeout\n";
                break;
                
            case datalog::OK: 
                break;
            default:
                UNREACHABLE();
            }
            break;
        }
        print_statistics(ctx);
        m_target = 0;
    }
Ejemplo n.º 4
0
 virtual void set_next_arg(cmd_context & ctx, expr * t) {
     SASSERT(m_idx == 0);
     if (!ctx.m().is_bool(t)) {
         throw cmd_exception("Invalid type for expression. Expected Boolean type.");
     }
     m_formula = t;
     ++m_idx;
 }
Ejemplo n.º 5
0
 virtual void set_next_arg(cmd_context & ctx, symbol const & s) {
     cmd * c = ctx.find_cmd(s);
     if (c == 0) {
         std::string err_msg("unknown command '");
         err_msg = err_msg + s.bare_str() + "'";
         throw cmd_exception(err_msg);
     }
     m_cmds.push_back(s);
 }
Ejemplo n.º 6
0
static expr *make_tree(cmd_context & ctx, const ptr_vector<expr> &exprs){
    if(exprs.size() == 0)
        throw cmd_exception("not enough arguments");
    expr *foo = exprs[0];
    for(unsigned i = 1; i < exprs.size(); i++){
        foo = ctx.m().mk_and(ctx.m().mk_interp(foo),exprs[i]);
    }    
    return foo;
}
Ejemplo n.º 7
0
 void print_certificate(cmd_context& ctx) {
     if (m_params.get_bool(":print-certificate", false)) {
         datalog::context& dlctx = m_dl_ctx->get_dl_context();
         if (!dlctx.display_certificate(ctx.regular_stream())) {
             throw cmd_exception("certificates are not supported for selected DL_ENGINE");
         }
         ctx.regular_stream() << "\n";
     }
 }
Ejemplo n.º 8
0
 void set_next_arg(cmd_context & ctx, symbol const & s) override {
     cmd * c = ctx.find_cmd(s);
     if (c == nullptr) {
         std::string err_msg("unknown command '");
         err_msg = err_msg + s.bare_str() + "'";
         throw cmd_exception(std::move(err_msg));
     }
     m_cmds.push_back(s);
 }
Ejemplo n.º 9
0
void parametric_cmd::set_next_arg(cmd_context & ctx, symbol const & s) { 
    if (m_last == symbol::null) {
        m_last = symbol(norm_param_name(s).c_str());
        if (pdescrs(ctx).get_kind(m_last.bare_str()) == CPK_INVALID)
            throw cmd_exception("invalid keyword argument");
        return;
    }
    else {
        m_params.set_sym(m_last.bare_str(), s);
        m_last = symbol::null;
    }
}
Ejemplo n.º 10
0
static void get_interpolant_and_maybe_check(cmd_context & ctx, expr * t, params_ref &m_params, bool check) {

    check_can_interpolate(ctx);

    // get the proof, if there is one

    if (!ctx.has_manager() ||
        ctx.cs_state() != cmd_context::css_unsat)
        throw cmd_exception("proof is not available");
    expr_ref pr(ctx.m());
    pr = ctx.get_check_sat_result()->get_proof();
    if (pr == 0)
        throw cmd_exception("proof is not available");

    // get the assertions from the context

    ptr_vector<expr>::const_iterator it  = ctx.begin_assertions();
    ptr_vector<expr>::const_iterator end = ctx.end_assertions();
    ptr_vector<ast> cnsts((unsigned)(end - it));
    for (int i = 0; it != end; ++it, ++i)
        cnsts[i] = *it;
    
    // compute an interpolant
  
    ptr_vector<ast> interps;
 
    try {
        iz3interpolate(ctx.m(),pr.get(),cnsts,t,interps,0);
    }
    catch (iz3_bad_tree &) {
        throw cmd_exception("interpolation pattern contains non-asserted formula");
    }
    catch (iz3_incompleteness &) {
        throw cmd_exception("incompleteness in interpolator");
    }

    show_interpolant_and_maybe_check(ctx, cnsts, t, interps, m_params, check);
}
Ejemplo n.º 11
0
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]);

}
Ejemplo n.º 12
0
    virtual void execute(cmd_context & ctx) {
        if(m_arg_idx<2) {
            throw cmd_exception("at least 2 arguments expected");
        }
        ensure_domain(ctx);
        ast_manager& m = ctx.m();

        func_decl_ref pred(
            m.mk_func_decl(m_rel_name, m_domain->size(), m_domain->c_ptr(), m.mk_bool_sort()), m);
        ctx.insert(pred);
        datalog::context& dctx = m_dl_ctx->get_dl_context();
        dctx.register_predicate(pred, false);
        if(!m_kinds.empty()) {
            dctx.set_predicate_representation(pred, m_kinds.size(), m_kinds.c_ptr());
        }
        m_domain = 0;
    }
Ejemplo n.º 13
0
expr * get_expr_ref(cmd_context & ctx, symbol const & v) {
    ast * r = get_ast_ref(ctx, v);
    if (!is_expr(r))
        throw cmd_exception("global variable does not reference a term");
    return to_expr(r);
}
Ejemplo n.º 14
0
static void check_can_interpolate(cmd_context & ctx){
    if (!ctx.produce_interpolants())
        throw cmd_exception("interpolation is not enabled, use command (set-option :produce-interpolants true)");
}
Ejemplo n.º 15
0
 virtual void set_next_arg(cmd_context & ctx, expr * t) {
     if (!is_app(t)) {
         throw cmd_exception("malformed objective term: it cannot be a quantifier or bound variable");
     }
     get_opt(ctx, m_opt).add_objective(to_app(t), m_is_max);
 }