Z3
 
Loading...
Searching...
No Matches
Data Structures | Public Member Functions | Friends
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 ()
 
 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)
 
std::string to_string () const
 
- Public Member Functions inherited from object
 object (context &c)
 
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 2575 of file z3++.h.

Constructor & Destructor Documentation

◆ model() [1/4]

model ( context c)
inline

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

2583:object(c) { init(Z3_mk_model(c)); }
object(context &c)
Definition: z3++.h:472
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.

Referenced by ModelRef::__del__(), ModelRef::__getitem__(), ModelRef::__len__(), ModelRef::decls(), ModelRef::eval(), ModelRef::get_interp(), ModelRef::get_sort(), ModelRef::get_universe(), ModelRef::num_sorts(), ModelRef::sexpr(), FuncInterp::translate(), ModelRef::translate(), and ModelRef::update_value().

◆ model() [2/4]

model ( context c,
Z3_model  m 
)
inline

◆ model() [3/4]

model ( model const &  s)
inline

◆ model() [4/4]

model ( model src,
context dst,
translate   
)
inline

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

2586: 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.

Referenced by ModelRef::__del__(), ModelRef::__getitem__(), ModelRef::__len__(), ModelRef::decls(), ModelRef::eval(), ModelRef::get_interp(), ModelRef::get_sort(), ModelRef::get_universe(), ModelRef::num_sorts(), ModelRef::sexpr(), FuncInterp::translate(), ModelRef::translate(), and ModelRef::update_value().

◆ ~model()

~model ( )
inline

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

2587{ Z3_model_dec_ref(ctx(), m_model); }
context & ctx() const
Definition: z3++.h:473
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 2646 of file z3++.h.

2646 {
2647 Z3_add_const_interp(ctx(), m_model, f, value);
2648 check_error();
2649 }
Z3_error_code check_error() const
Definition: z3++.h:474
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 2640 of file z3++.h.

2640 {
2641 Z3_func_interp r = Z3_add_func_interp(ctx(), m_model, f, else_val);
2642 check_error();
2643 return func_interp(ctx(), r);
2644 }
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 2597 of file z3++.h.

2597 {
2598 check_context(*this, n);
2599 Z3_ast r = 0;
2600 bool status = Z3_model_eval(ctx(), m_model, n, model_completion, &r);
2601 check_error();
2602 if (status == false && ctx().enable_exceptions())
2603 Z3_THROW(exception("failed to evaluate expression"));
2604 return expr(ctx(), r);
2605 }
friend void check_context(object const &a, object const &b)
Definition: z3++.h:477
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.
#define Z3_THROW(x)
Definition: z3++.h:103

Referenced by ModelRef::evaluate().

◆ get_const_decl()

func_decl get_const_decl ( unsigned  i) const
inline

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

2609{ 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 model::operator[]().

◆ get_const_interp()

expr get_const_interp ( func_decl  c) const
inline

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

2620 {
2621 check_context(*this, c);
2622 Z3_ast r = Z3_model_get_const_interp(ctx(), m_model, c);
2623 check_error();
2624 return expr(ctx(), r);
2625 }
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 2610 of file z3++.h.

2610{ 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 model::operator[]().

◆ get_func_interp()

func_interp get_func_interp ( func_decl  f) const
inline

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

2626 {
2627 check_context(*this, f);
2628 Z3_func_interp r = Z3_model_get_func_interp(ctx(), m_model, f);
2629 check_error();
2630 return func_interp(ctx(), r);
2631 }
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...

◆ has_interp()

bool has_interp ( func_decl  f) const
inline

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

2635 {
2636 check_context(*this, f);
2637 return Z3_model_has_interp(ctx(), m_model, f);
2638 }
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 2607 of file z3++.h.

2607{ 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 model::operator[](), and model::size().

◆ num_funcs()

unsigned num_funcs ( ) const
inline

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

2608{ 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 model::size().

◆ operator Z3_model()

operator Z3_model ( ) const
inline

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

2588{ return m_model; }

◆ operator=()

model & operator= ( model const &  s)
inline

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

2589 {
2590 Z3_model_inc_ref(s.ctx(), s.m_model);
2591 Z3_model_dec_ref(ctx(), m_model);
2592 object::operator=(s);
2593 m_model = s.m_model;
2594 return *this;
2595 }
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 2612 of file z3++.h.

2612 {
2613 assert(0 <= i);
2614 return static_cast<unsigned>(i) < num_consts() ? get_const_decl(i) : get_func_decl(i - num_consts());
2615 }
unsigned num_consts() const
Definition: z3++.h:2607
func_decl get_func_decl(unsigned i) const
Definition: z3++.h:2610
func_decl get_const_decl(unsigned i) const
Definition: z3++.h:2609

◆ size()

unsigned size ( ) const
inline

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

2611{ return num_consts() + num_funcs(); }
unsigned num_funcs() const
Definition: z3++.h:2608

Referenced by ParamDescrsRef::__len__(), Goal::__len__(), BitVecNumRef::as_signed_long(), and BitVecSortRef::subsort().

◆ to_string()

std::string to_string ( ) const
inline

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

2653{ 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.

Friends And Related Function Documentation

◆ operator<<

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

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

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