Z3
Loading...
Searching...
No Matches
model Class Reference

#include <z3++.h>

Inheritance diagram for model:

Data Structures

struct  translate

Public Member Functions

 model (context &c)
 model (context &c, Z3_model m)
 model (model const &s)
 model (model &src, context &dst, translate)
 ~model () override
 operator Z3_model () const
modeloperator= (model const &s)
expr eval (expr const &n, bool model_completion=false) const
unsigned num_consts () const
unsigned num_funcs () const
func_decl get_const_decl (unsigned i) const
func_decl get_func_decl (unsigned i) const
unsigned size () const
func_decl operator[] (int i) const
expr get_const_interp (func_decl c) const
func_interp get_func_interp (func_decl f) const
bool has_interp (func_decl f) const
func_interp add_func_interp (func_decl &f, expr &else_val)
void add_const_interp (func_decl &f, expr &value)
unsigned num_sorts () const
sort get_sort (unsigned i) const
 Return the uninterpreted sort at position i.
expr_vector sort_universe (sort const &s) const
std::string to_string () const
Public Member Functions inherited from object
 object (context &c)
virtual ~object ()=default
contextctx () const
Z3_error_code check_error () const

Friends

std::ostream & operator<< (std::ostream &out, model const &m)

Additional Inherited Members

Protected Attributes inherited from object
contextm_ctx

Detailed Description

Definition at line 2756 of file z3++.h.

Constructor & Destructor Documentation

◆ model() [1/4]

model ( context & c)
inline

Definition at line 2764 of file z3++.h.

2764:object(c) { init(Z3_mk_model(c)); }
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.

Referenced by model(), model(), operator<<, and operator=().

◆ model() [2/4]

model ( context & c,
Z3_model m )
inline

Definition at line 2765 of file z3++.h.

2765:object(c) { init(m); }

◆ model() [3/4]

model ( model const & s)
inline

Definition at line 2766 of file z3++.h.

2766:object(s) { init(s.m_model); }

◆ model() [4/4]

model ( model & src,
context & dst,
translate  )
inline

Definition at line 2767 of file z3++.h.

2767: object(dst) { init(Z3_model_translate(src.ctx(), src, dst)); }
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.

◆ ~model()

~model ( )
inlineoverride

Definition at line 2768 of file z3++.h.

2768{ Z3_model_dec_ref(ctx(), m_model); }
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.

Member Function Documentation

◆ add_const_interp()

void add_const_interp ( func_decl & f,
expr & value )
inline

Definition at line 2827 of file z3++.h.

2827 {
2828 Z3_add_const_interp(ctx(), m_model, f, value);
2829 check_error();
2830 }
void Z3_API Z3_add_const_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast a)
Add a constant interpretation.

◆ add_func_interp()

func_interp add_func_interp ( func_decl & f,
expr & else_val )
inline

Definition at line 2821 of file z3++.h.

2821 {
2822 Z3_func_interp r = Z3_add_func_interp(ctx(), m_model, f, else_val);
2823 check_error();
2824 return func_interp(ctx(), r);
2825 }
Z3_func_interp Z3_API Z3_add_func_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast default_value)
Create a fresh func_interp object, add it to a model for a specified function. It has reference count...

◆ eval()

expr eval ( expr const & n,
bool model_completion = false ) const
inline

Definition at line 2778 of file z3++.h.

2778 {
2779 check_context(*this, n);
2780 Z3_ast r = 0;
2781 bool status = Z3_model_eval(ctx(), m_model, n, model_completion, &r);
2782 check_error();
2783 if (status == false && ctx().enable_exceptions())
2784 Z3_THROW(exception("failed to evaluate expression"));
2785 return expr(ctx(), r);
2786 }
bool Z3_API Z3_model_eval(Z3_context c, Z3_model m, Z3_ast t, bool model_completion, Z3_ast *v)
Evaluate the AST node t in the given model. Return true if succeeded, and store the result in v.
void check_context(object const &a, object const &b)
Definition z3++.h:548
#define Z3_THROW(x)
Definition z3++.h:134

◆ get_const_decl()

func_decl get_const_decl ( unsigned i) const
inline

Definition at line 2790 of file z3++.h.

2790{ Z3_func_decl r = Z3_model_get_const_decl(ctx(), m_model, i); check_error(); return func_decl(ctx(), r); }
Z3_func_decl Z3_API Z3_model_get_const_decl(Z3_context c, Z3_model m, unsigned i)
Return the i-th constant in the given model.

Referenced by operator[]().

◆ get_const_interp()

expr get_const_interp ( func_decl c) const
inline

Definition at line 2801 of file z3++.h.

2801 {
2802 check_context(*this, c);
2803 Z3_ast r = Z3_model_get_const_interp(ctx(), m_model, c);
2804 check_error();
2805 return expr(ctx(), r);
2806 }
Z3_ast Z3_API Z3_model_get_const_interp(Z3_context c, Z3_model m, Z3_func_decl a)
Return the interpretation (i.e., assignment) of constant a in the model m. Return NULL,...

◆ get_func_decl()

func_decl get_func_decl ( unsigned i) const
inline

Definition at line 2791 of file z3++.h.

2791{ Z3_func_decl r = Z3_model_get_func_decl(ctx(), m_model, i); check_error(); return func_decl(ctx(), r); }
Z3_func_decl Z3_API Z3_model_get_func_decl(Z3_context c, Z3_model m, unsigned i)
Return the declaration of the i-th function in the given model.

Referenced by operator[]().

◆ get_func_interp()

func_interp get_func_interp ( func_decl f) const
inline

Definition at line 2807 of file z3++.h.

2807 {
2808 check_context(*this, f);
2809 Z3_func_interp r = Z3_model_get_func_interp(ctx(), m_model, f);
2810 check_error();
2811 return func_interp(ctx(), r);
2812 }
Z3_func_interp Z3_API Z3_model_get_func_interp(Z3_context c, Z3_model m, Z3_func_decl f)
Return the interpretation of the function f in the model m. Return NULL, if the model does not assign...

◆ get_sort()

sort get_sort ( unsigned i) const
inline

Return the uninterpreted sort at position i.

Precondition
i < num_sorts()

Definition at line 2842 of file z3++.h.

2842 {
2843 Z3_sort s = Z3_model_get_sort(ctx(), m_model, i);
2844 check_error();
2845 return sort(ctx(), s);
2846 }
Z3_sort Z3_API Z3_model_get_sort(Z3_context c, Z3_model m, unsigned i)
Return a uninterpreted sort that m assigns an interpretation.

◆ has_interp()

bool has_interp ( func_decl f) const
inline

Definition at line 2816 of file z3++.h.

2816 {
2817 check_context(*this, f);
2818 return Z3_model_has_interp(ctx(), m_model, f);
2819 }
bool Z3_API Z3_model_has_interp(Z3_context c, Z3_model m, Z3_func_decl a)
Test if there exists an interpretation (i.e., assignment) for a in the model m.

◆ num_consts()

unsigned num_consts ( ) const
inline

Definition at line 2788 of file z3++.h.

2788{ return Z3_model_get_num_consts(ctx(), m_model); }
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.

Referenced by operator[](), and size().

◆ num_funcs()

unsigned num_funcs ( ) const
inline

Definition at line 2789 of file z3++.h.

2789{ return Z3_model_get_num_funcs(ctx(), m_model); }
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.

Referenced by size().

◆ num_sorts()

unsigned num_sorts ( ) const
inline

Definition at line 2832 of file z3++.h.

2832 {
2833 unsigned r = Z3_model_get_num_sorts(ctx(), m_model);
2834 check_error();
2835 return r;
2836 }
unsigned Z3_API Z3_model_get_num_sorts(Z3_context c, Z3_model m)
Return the number of uninterpreted sorts that m assigns an interpretation to.

◆ operator Z3_model()

operator Z3_model ( ) const
inline

Definition at line 2769 of file z3++.h.

2769{ return m_model; }

◆ operator=()

model & operator= ( model const & s)
inline

Definition at line 2770 of file z3++.h.

2770 {
2771 Z3_model_inc_ref(s.ctx(), s.m_model);
2772 Z3_model_dec_ref(ctx(), m_model);
2773 object::operator=(s);
2774 m_model = s.m_model;
2775 return *this;
2776 }
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.

◆ operator[]()

func_decl operator[] ( int i) const
inline

Definition at line 2793 of file z3++.h.

2793 {
2794 assert(0 <= i);
2795 return static_cast<unsigned>(i) < num_consts() ? get_const_decl(i) : get_func_decl(i - num_consts());
2796 }

◆ size()

unsigned size ( ) const
inline

Definition at line 2792 of file z3++.h.

2792{ return num_consts() + num_funcs(); }

◆ sort_universe()

expr_vector sort_universe ( sort const & s) const
inline

Definition at line 2848 of file z3++.h.

2848 {
2849 check_context(*this, s);
2850 Z3_ast_vector r = Z3_model_get_sort_universe(ctx(), m_model, s);
2851 check_error();
2852 return expr_vector(ctx(), r);
2853 }
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s)
Return the finite set of distinct values that represent the interpretation for sort s.
ast_vector_tpl< expr > expr_vector
Definition z3++.h:77

◆ to_string()

std::string to_string ( ) const
inline

Definition at line 2857 of file z3++.h.

2857{ return m_model ? std::string(Z3_model_to_string(ctx(), m_model)) : "null"; }
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.

Referenced by operator<<.

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
model const & m )
friend

Definition at line 2859 of file z3++.h.

2859{ return out << m.to_string(); }