Example #1
0
static void display_functions(std::ostream & out, model_core const & md, bool partial) {
    unsigned sz = md.get_num_functions();
    for (unsigned i = 0; i < sz; i++) {
        func_decl * f = md.get_function(i);
        display_function(out, md, f, partial);
    }
}
Example #2
0
std::string sym_mux::pp_model(const model_core & mdl) const
{
    decl_vector consts;
    unsigned sz = mdl.get_num_constants();
    for (unsigned i = 0; i < sz; i++) {
        func_decl * d = mdl.get_constant(i);
        consts.push_back(d);
    }

    std::sort(consts.begin(), consts.end(), decl_idx_comparator(*this));

    std::stringstream res;

    decl_vector::iterator end = consts.end();
    for (decl_vector::iterator it = consts.begin(); it != end; it++) {
        func_decl * d = *it;
        std::string name   = d->get_name().str();
        const char * arrow = " -> ";
        res << name << arrow;
        unsigned indent = static_cast<unsigned>(name.length() + strlen(arrow));
        res << mk_pp(mdl.get_const_interp(d), m, indent) << "\n";

        if (it + 1 != end) {
            unsigned idx1, idx2;
            if (!try_get_index(*it, idx1)) { idx1 = UINT_MAX; }
            if (!try_get_index(*(it + 1), idx2)) { idx2 = UINT_MAX; }
            if (idx1 != idx2) { res << "\n"; }
        }
    }
    return res.str();
}
Example #3
0
static void display_function(std::ostream & out, model_core const & md, func_decl * f, bool partial) {
    ast_manager & m = md.get_manager();
    func_interp * g = md.get_func_interp(f);
    out << f->get_name() << " -> {\n";
    unsigned num_entries = g->num_entries();
    unsigned arity       = g->get_arity();
    char const * else_str = num_entries == 0 ? "  " : "  else -> ";
    unsigned else_indent  = static_cast<unsigned>(strlen(else_str));
    for (unsigned i = 0; i < num_entries; i++) {
        func_entry const * entry = g->get_entry(i);
        out << "  ";
        for (unsigned j = 0; j < arity; j++) {
            expr * arg = entry->get_arg(j);
            out << mk_pp(arg, m);
            out << " ";
        }
        out << "-> "; 
        out << mk_pp(entry->get_result(), m);
        out << "\n";
    }
    if (partial) {
        out << else_str << "#unspecified\n";
    }
    else {
        expr * else_val = g->get_else();
        out << else_str;
        if (else_val)
            out << mk_pp(else_val, m, else_indent);
        else
            out << "#unspecified";
        out << "\n";
    }
    out << "}\n";
}
Example #4
0
static void display_constants(std::ostream & out, model_core const & md) {
    ast_manager & m = md.get_manager();
    unsigned sz = md.get_num_constants();
    for (unsigned i = 0; i < sz; i++) {
        func_decl * c = md.get_constant(i);
        char const * d = "(define ";
        std::string n  = c->get_name().str();
        unsigned indent = static_cast<unsigned>(n.length() + strlen(d) + 1);
        out << d << n << " " << mk_ismt2_pp(md.get_const_interp(c), m, indent) << ")\n";
    }
}
Example #5
0
static void display_constants(std::ostream & out, model_core const & md) {
    ast_manager & m = md.get_manager();
    unsigned sz = md.get_num_constants();
    for (unsigned i = 0; i < sz; i++) {
        func_decl * d = md.get_constant(i);

        std::string name   = d->get_name().str();
        const char * arrow = " -> "; 
        out << name << arrow;
        unsigned indent = static_cast<unsigned>(name.length() + strlen(arrow));
        out << mk_pp(md.get_const_interp(d), m, indent) << "\n";
    }
}
Example #6
0
static void display_uninterp_sorts(std::ostream & out, model_core const & md) {
    ast_manager & m = md.get_manager();
    unsigned sz = md.get_num_uninterpreted_sorts();
    for (unsigned i = 0; i < sz; i++) {
        sort * s = md.get_uninterpreted_sort(i);
        out << "(define-sort " << mk_pp(s, m); 
        ptr_vector<expr> const & univ  = md.get_universe(s);
        ptr_vector<expr>::const_iterator it  = univ.begin();
        ptr_vector<expr>::const_iterator end = univ.end();
        for (; it != end; ++it) {
            out << " " << mk_ismt2_pp(*it, m);
        }
        out << ")\n";
    }
}
Example #7
0
static void pp_consts(std::ostream & out, ast_printer_context & ctx, model_core const & md, unsigned indent) {
    unsigned num = md.get_num_constants();
    for (unsigned i = 0; i < num; i++) {
        func_decl * c = md.get_constant(i);
        expr * c_i    = md.get_const_interp(c);
        pp_indent(out, indent);
        out << "(define-fun ";
        unsigned len  = pp_symbol(out, c->get_name());
        out << " () ";
        ctx.display(out, c->get_range(), indent + len + 16);
        out << "\n";
        pp_indent(out, indent + TAB_SZ);
        ctx.display(out, c_i);
        out << ")\n";
    }
}
Example #8
0
static void display_functions(std::ostream & out, model_core const & md) {
    ast_manager & m = md.get_manager();
    unsigned sz = md.get_num_functions();
    for (unsigned i = 0; i < sz; i++) {
        func_decl * f = md.get_function(i);
        out << "(define (" << f->get_name();
        unsigned arity = f->get_arity();
        func_interp * fi = md.get_func_interp(f);
        for (unsigned j = 0; j < arity; j++) {
            out << " " << "x!" << j;
        }
        out << ")\n";
        
        unsigned num_entries = fi->num_entries();
        for (unsigned j = 0; j < num_entries; j++) {
            func_entry const * curr = fi->get_entry(j);
            out << "  (if ";
            if (arity > 1)
                out << "(and ";
            for (unsigned j = 0; j < arity; j++) {
                out << "(= x!" << j << " " << mk_ismt2_pp(curr->get_arg(j), m) << ")";
                if (j + 1 < arity)
                    out << " ";
            }
            if (arity > 1)
                out << ")";
            out << " " << mk_ismt2_pp(curr->get_result(), m) << "\n";
        }
        if (num_entries > 0)
            out << "  ";
        if (fi->is_partial())
            out << "  #unspecified";
        else {
            pp_params const & params = get_pp_default_params();
            out << "  " << mk_ismt2_pp(fi->get_else(), m, params, 5, arity, "x");
        }
        for (unsigned j = 0; j < num_entries; j++)
            out << ")";
        out << ")\n";
    }
}
Example #9
0
void sort_fun_decls(ast_manager & m, model_core const & md, ptr_buffer<func_decl> & result) {
    func_decl_set         visited;
    ptr_vector<func_decl> todo;
    unsigned sz = md.get_num_functions();
    for (unsigned i = 0; i < sz; i++) {
        func_decl * f = md.get_function(i);
        if (visited.contains(f))
            continue;
        visited.insert(f);
        todo.push_back(f);
        while (!todo.empty()) {
            func_decl * curr = todo.back();
            func_interp * curr_i = md.get_func_interp(curr);
            SASSERT(curr_i != 0);
            if (!curr_i->is_partial()) {
                func_decl_set deps;
                bool all_visited = true;
                collect_func_decls(m, curr_i->get_else(), deps);
                func_decl_set::iterator it2  = deps.begin();
                func_decl_set::iterator end2 = deps.end();
                for (; it2 != end2; ++it2) {
                    func_decl * d = *it2;
                    if (d->get_arity() > 0 && md.has_interpretation(d) && !visited.contains(d)) {
                        todo.push_back(d);
                        visited.insert(d);
                        all_visited = false;
                    }
                }
                if (!all_visited)
                    continue;
            }
            todo.pop_back();
            result.push_back(curr);
        }
    }
}
Example #10
0
static void pp_uninterp_sorts(std::ostream & out, ast_printer_context & ctx, model_core const & md, unsigned indent) {
    ast_manager & m = ctx.get_ast_manager();
    ptr_buffer<format> f_conds;
    unsigned num = md.get_num_uninterpreted_sorts();
    for (unsigned i = 0; i < num; i++) {
        sort * s = md.get_uninterpreted_sort(i);
        ptr_vector<expr> const & u = md.get_universe(s);
        std::ostringstream buffer;
        buffer << "universe for ";
        ctx.display(buffer, s, 13);
        buffer << ":\n";
        pp_indent(buffer, TAB_SZ);
        ptr_vector<expr>::const_iterator it  = u.begin();
        ptr_vector<expr>::const_iterator end = u.end();
        for (; it != end; ++it) {
            SASSERT(is_app(*it));
            app * c = to_app(*it);
            pp_symbol(buffer, c->get_decl()->get_name());
            buffer << " ";
        }
        buffer << "\n-----------";
        std::string buffer_str = buffer.str();
        unsigned len = static_cast<unsigned>(buffer_str.length());
        pp_indent(out, indent);
        out << ";; ";
        for (unsigned i = 0; i < len; i++) {
            char c = buffer_str[i];
            if (c == '\n') {
                out << "\n";
                pp_indent(out, indent);
                out << ";; ";
            }
            else {
                out << c;
            }
        }
        out << "\n";
        pp_indent(out, indent);
        out << ";; definitions for universe elements:\n";
        it  = u.begin();
        for (; it != end; ++it) {
            app * c = to_app(*it);
            pp_indent(out, indent);
            out << "(declare-fun ";
            unsigned len  = pp_symbol(out, c->get_decl()->get_name());
            out << " () ";
            ctx.display(out, c->get_decl()->get_range(), indent + len + 16);
            out << ")\n";
        }
        pp_indent(out, indent);
        out << ";; cardinality constraint:\n";
        f_conds.reset();
        format * var = mk_string(m, "x");
        it  = u.begin();
        for (; it != end; ++it) {
            app * c = to_app(*it);
            symbol csym = c->get_decl()->get_name();
            std::string cname;
            if (is_smt2_quoted_symbol(csym))
                cname = mk_smt2_quoted_symbol(csym);
            else
                cname = csym.str();
            format * c_args[2] = { var, mk_string(m, cname.c_str()) };
            f_conds.push_back(mk_seq1<format**, f2f>(m, c_args, c_args+2, f2f(), "="));
        }
        SASSERT(!f_conds.empty());
        format * f_cond;
        if (f_conds.size() > 1)
            f_cond = mk_seq1(m, f_conds.begin(), f_conds.end(), f2f(), "or");
        else
            f_cond = f_conds[0];
        format_ref f_s(fm(m));
        ctx.pp(s, f_s);
        format * f_args[2] = { mk_compose(m,
                                          mk_string(m, "((x "),
                                          mk_indent(m, 4, mk_compose(m, f_s.get(), mk_string(m, "))")))),
                               f_cond };
        format_ref f_card(fm(m));
        f_card = mk_indent(m, indent, mk_seq1<format**, f2f>(m, f_args, f_args+2, f2f(), "forall"));
        pp_indent(out, indent);
        pp(out, f_card, m);
        out << "\n";
        pp_indent(out, indent);
        out << ";; -----------\n";
    }
}
Example #11
0
static void pp_funs(std::ostream & out, ast_printer_context & ctx, model_core const & md, unsigned indent) {
    ast_manager & m = ctx.get_ast_manager();
    sbuffer<symbol>    var_names;
    ptr_buffer<format> f_var_names;
    ptr_buffer<format> f_arg_decls;
    ptr_buffer<format> f_entries;
    ptr_buffer<format> f_entry_conds;
    ptr_buffer<func_decl> func_decls;
    sort_fun_decls(m, md, func_decls);
    for (unsigned i = 0; i < func_decls.size(); i++) {
        func_decl * f     = func_decls[i];
        func_interp * f_i = md.get_func_interp(f);
        SASSERT(f->get_arity() == f_i->get_arity());
        format_ref body(fm(m));
        var_names.reset();
        if (f_i->is_partial()) {
            body = mk_string(m, "#unspecified");
            for (unsigned j = 0; j < f->get_arity(); j++) {
                std::stringstream strm;
                strm << "x!" << (j+1);
                var_names.push_back(symbol(strm.str().c_str()));
            }
        }
        else {
            ctx.pp(f_i->get_else(), f->get_arity(), "x", body, var_names);
        }
        TRACE("model_smt2_pp", for (unsigned i = 0; i < var_names.size(); i++) tout << var_names[i] << "\n";);
        f_var_names.reset();
        for (unsigned i = 0; i < f->get_arity(); i++)
            f_var_names.push_back(mk_string(m, var_names[i].bare_str()));
        f_arg_decls.reset();
        for (unsigned i = 0; i < f->get_arity(); i++) {
            format_ref f_domain(fm(m));
            ctx.pp(f->get_domain(i), f_domain);
            format * args[2] = { f_var_names[i], f_domain.get() };
            f_arg_decls.push_back(mk_seq5<format**, f2f>(m, args, args+2, f2f()));
        }
        format * f_domain = mk_seq5(m, f_arg_decls.begin(), f_arg_decls.end(), f2f());
        format_ref f_range(fm(m));
        ctx.pp(f->get_range(), f_range);
        if (f_i->num_entries() > 0) {
            f_entries.reset();
            for (unsigned i = 0; i < f_i->num_entries(); i++) {
                func_entry const * e = f_i->get_entry(i);
                f_entry_conds.reset();
                for (unsigned j = 0; j < f->get_arity(); j++) {
                    format_ref f_arg(fm(m));
                    ctx.pp(e->get_arg(j), f_arg);
                    format * eq_args[2] = { f_var_names[j], f_arg.get() };
                    f_entry_conds.push_back(mk_seq1<format**, f2f>(m, eq_args, eq_args+2, f2f(), "="));
                }
                format * f_entry_cond;
                SASSERT(!f_entry_conds.empty());
                if (f_entry_conds.size() > 1)
                    f_entry_cond = mk_seq1(m, f_entry_conds.begin(), f_entry_conds.end(), f2f(), "and");
                else
                    f_entry_cond = f_entry_conds[0];
                format_ref f_result(fm(m));
                ctx.pp(e->get_result(), f_result);
                if (i > 0)
                    f_entries.push_back(mk_line_break(m));
                f_entries.push_back(mk_group(m, mk_compose(m,
                                                           mk_string(m, "(ite "),
                                                           mk_indent(m, 5, f_entry_cond),
                                                           mk_indent(m, TAB_SZ, mk_compose(m,
                                                                                           mk_line_break(m),
                                                                                           f_result.get())))));
            }
            f_entries.push_back(mk_indent(m, TAB_SZ, mk_compose(m,
                                                                mk_line_break(m),
                                                                body.get())));
            for (unsigned i = 0; i < f_i->num_entries(); i++)
                f_entries.push_back(mk_string(m, ")"));
            body = mk_compose(m, f_entries.size(), f_entries.c_ptr());
        }
        format_ref def(fm(m));
        std::string fname;
        if (is_smt2_quoted_symbol(f->get_name()))
            fname = mk_smt2_quoted_symbol(f->get_name());
        else
            fname = f->get_name().str();
        def = mk_indent(m, indent, mk_compose(m,
                                              mk_compose(m,
                                                         mk_string(m, "(define-fun "),
                                                         mk_string(m, fname.c_str()),
                                                         mk_string(m, " "),
                                                         mk_compose(m,
                                                                    f_domain,
                                                                    mk_string(m, " "),
                                                                    f_range)),
                                              mk_indent(m, TAB_SZ, mk_compose(m,
                                                                              mk_line_break(m),
                                                                              body.get(),
                                                                              mk_string(m, ")")))));
        pp_indent(out, indent);
        pp(out, def.get(), m);
        out << "\n";
    }