Z3
Data Structures | Public Member Functions | Friends
solver Class Reference
+ Inheritance diagram for solver:

Data Structures

class  cube_generator
 
class  cube_iterator
 
struct  simple
 
struct  translate
 

Public Member Functions

 solver (context &c)
 
 solver (context &c, simple)
 
 solver (context &c, Z3_solver s)
 
 solver (context &c, char const *logic)
 
 solver (context &c, solver const &src, translate)
 
 solver (solver const &s)
 
 ~solver ()
 
 operator Z3_solver () const
 
solveroperator= (solver const &s)
 
void set (params const &p)
 
void set (char const *k, bool v)
 
void set (char const *k, unsigned v)
 
void set (char const *k, double v)
 
void set (char const *k, symbol const &v)
 
void set (char const *k, char const *v)
 
void push ()
 
void pop (unsigned n=1)
 
void reset ()
 
void add (expr const &e)
 
void add (expr const &e, expr const &p)
 
void add (expr const &e, char const *p)
 
void from_file (char const *file)
 
void from_string (char const *s)
 
check_result check ()
 
check_result check (unsigned n, expr *const assumptions)
 
check_result check (expr_vector assumptions)
 
model get_model () const
 
check_result consequences (expr_vector &assumptions, expr_vector &vars, expr_vector &conseq)
 
std::string reason_unknown () const
 
stats statistics () const
 
expr_vector unsat_core () const
 
expr_vector assertions () const
 
expr_vector non_units () const
 
expr_vector units () const
 
expr proof () const
 
std::string to_smt2 (char const *status="unknown")
 
param_descrs get_param_descrs ()
 
expr_vector cube (expr_vector &vars, unsigned cutoff)
 
cube_generator cubes ()
 
cube_generator cubes (expr_vector &vars)
 
- Public Member Functions inherited from object
 object (context &c)
 
 object (object const &s)
 
contextctx () const
 
Z3_error_code check_error () const
 

Friends

std::ostream & operator<< (std::ostream &out, solver const &s)
 

Additional Inherited Members

- Protected Attributes inherited from object
contextm_ctx
 

Detailed Description

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

Constructor & Destructor Documentation

◆ solver() [1/6]

solver ( context c)
inline

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

2141 :object(c) { init(Z3_mk_solver(c)); }
Z3_solver Z3_API Z3_mk_solver(Z3_context c)
Create a new solver. This solver is a "combined solver" (see combined_solver module) that internally ...
object(context &c)
Definition: z3++.h:402

◆ solver() [2/6]

solver ( context c,
simple   
)
inline

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

2142 :object(c) { init(Z3_mk_simple_solver(c)); }
object(context &c)
Definition: z3++.h:402
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.

◆ solver() [3/6]

solver ( context c,
Z3_solver  s 
)
inline

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

2143 :object(c) { init(s); }
object(context &c)
Definition: z3++.h:402

◆ solver() [4/6]

solver ( context c,
char const *  logic 
)
inline

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

2144 :object(c) { init(Z3_mk_solver_for_logic(c, c.str_symbol(logic))); }
Z3_solver Z3_API Z3_mk_solver_for_logic(Z3_context c, Z3_symbol logic)
Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unkn...
object(context &c)
Definition: z3++.h:402

◆ solver() [5/6]

solver ( context c,
solver const &  src,
translate   
)
inline

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

2145 : object(c) { init(Z3_solver_translate(src.ctx(), src, c)); }
Z3_solver Z3_API Z3_solver_translate(Z3_context source, Z3_solver s, Z3_context target)
Copy a solver s from the context source to the context target.
object(context &c)
Definition: z3++.h:402

◆ solver() [6/6]

solver ( solver const &  s)
inline

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

2146 :object(s) { init(s.m_solver); }
object(context &c)
Definition: z3++.h:402

◆ ~solver()

~solver ( )
inline

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

2147 { Z3_solver_dec_ref(ctx(), m_solver); }
context & ctx() const
Definition: z3++.h:404
void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.

Member Function Documentation

◆ add() [1/3]

void add ( expr const &  e)
inline

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

Referenced by solver::add().

2165 { assert(e.is_bool()); Z3_solver_assert(ctx(), m_solver, e); check_error(); }
Z3_error_code check_error() const
Definition: z3++.h:405
void Z3_API Z3_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
context & ctx() const
Definition: z3++.h:404

◆ add() [2/3]

void add ( expr const &  e,
expr const &  p 
)
inline

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

2166  {
2167  assert(e.is_bool()); assert(p.is_bool()); assert(p.is_const());
2168  Z3_solver_assert_and_track(ctx(), m_solver, e, p);
2169  check_error();
2170  }
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404
void Z3_API Z3_solver_assert_and_track(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast p)
Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p...

◆ add() [3/3]

void add ( expr const &  e,
char const *  p 
)
inline

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

2171  {
2172  add(e, ctx().bool_const(p));
2173  }
context & ctx() const
Definition: z3++.h:404
void add(expr const &e)
Definition: z3++.h:2165

◆ assertions()

expr_vector assertions ( ) const
inline

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

Referenced by solver::to_smt2().

2210 { Z3_ast_vector r = Z3_solver_get_assertions(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
Z3_ast_vector Z3_API Z3_solver_get_assertions(Z3_context c, Z3_solver s)
Return the set of asserted formulas on the solver.
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:71

◆ check() [1/3]

check_result check ( )
inline

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

2179 { Z3_lbool r = Z3_solver_check(ctx(), m_solver); check_error(); return to_check_result(r); }
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:98
Z3_lbool Z3_API Z3_solver_check(Z3_context c, Z3_solver s)
Check whether the assertions in a given solver are consistent or not.
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:141

◆ check() [2/3]

check_result check ( unsigned  n,
expr *const  assumptions 
)
inline

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

2180  {
2181  array<Z3_ast> _assumptions(n);
2182  for (unsigned i = 0; i < n; i++) {
2183  check_context(*this, assumptions[i]);
2184  _assumptions[i] = assumptions[i];
2185  }
2186  Z3_lbool r = Z3_solver_check_assumptions(ctx(), m_solver, n, _assumptions.ptr());
2187  check_error();
2188  return to_check_result(r);
2189  }
Z3_error_code check_error() const
Definition: z3++.h:405
Z3_lbool Z3_API Z3_solver_check_assumptions(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[])
Check whether the assertions in the given solver and optional assumptions are consistent or not...
context & ctx() const
Definition: z3++.h:404
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:98
friend void check_context(object const &a, object const &b)
Definition: z3++.h:408
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:141

◆ check() [3/3]

check_result check ( expr_vector  assumptions)
inline

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

2190  {
2191  unsigned n = assumptions.size();
2192  array<Z3_ast> _assumptions(n);
2193  for (unsigned i = 0; i < n; i++) {
2194  check_context(*this, assumptions[i]);
2195  _assumptions[i] = assumptions[i];
2196  }
2197  Z3_lbool r = Z3_solver_check_assumptions(ctx(), m_solver, n, _assumptions.ptr());
2198  check_error();
2199  return to_check_result(r);
2200  }
Z3_error_code check_error() const
Definition: z3++.h:405
Z3_lbool Z3_API Z3_solver_check_assumptions(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[])
Check whether the assertions in the given solver and optional assumptions are consistent or not...
context & ctx() const
Definition: z3++.h:404
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:98
friend void check_context(object const &a, object const &b)
Definition: z3++.h:408
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:141

◆ consequences()

check_result consequences ( expr_vector assumptions,
expr_vector vars,
expr_vector conseq 
)
inline

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

2202  {
2203  Z3_lbool r = Z3_solver_get_consequences(ctx(), m_solver, assumptions, vars, conseq);
2204  check_error();
2205  return to_check_result(r);
2206  }
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:98
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:141
Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, Z3_solver s, Z3_ast_vector assumptions, Z3_ast_vector variables, Z3_ast_vector consequences)
retrieve consequences from solver that determine values of the supplied function symbols.

◆ cube()

expr_vector cube ( expr_vector vars,
unsigned  cutoff 
)
inline

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

2239  {
2240  Z3_ast_vector r = Z3_solver_cube(ctx(), m_solver, vars, cutoff);
2241  check_error();
2242  return expr_vector(ctx(), r);
2243  }
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404
Z3_ast_vector Z3_API Z3_solver_cube(Z3_context c, Z3_solver s, Z3_ast_vector vars, unsigned backtrack_level)
extract a next cube for a solver. The last cube is the constant true or false. The number of (non-con...
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:71

◆ cubes() [1/2]

cube_generator cubes ( )
inline

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

2326 { return cube_generator(*this); }

◆ cubes() [2/2]

cube_generator cubes ( expr_vector vars)
inline

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

2327 { return cube_generator(*this, vars); }

◆ from_file()

void from_file ( char const *  file)
inline

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

2176 { Z3_solver_from_file(ctx(), m_solver, file); ctx().check_parser_error(); }
context & ctx() const
Definition: z3++.h:404
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
void check_parser_error() const
Definition: z3++.h:185

◆ from_string()

void from_string ( char const *  s)
inline

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

2177 { Z3_solver_from_string(ctx(), m_solver, s); ctx().check_parser_error(); }
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a string.
context & ctx() const
Definition: z3++.h:404
void check_parser_error() const
Definition: z3++.h:185

◆ get_model()

model get_model ( ) const
inline

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

2201 { Z3_model m = Z3_solver_get_model(ctx(), m_solver); check_error(); return model(ctx(), m); }
Z3_error_code check_error() const
Definition: z3++.h:405
Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s)
Retrieve the model for the last Z3_solver_check or Z3_solver_check_assumptions.
context & ctx() const
Definition: z3++.h:404

◆ get_param_descrs()

param_descrs get_param_descrs ( )
inline

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

2236 { return param_descrs(ctx(), Z3_solver_get_param_descrs(ctx(), m_solver)); }
context & ctx() const
Definition: z3++.h:404
Z3_param_descrs Z3_API Z3_solver_get_param_descrs(Z3_context c, Z3_solver s)
Return the parameter description set for the given solver object.

◆ non_units()

expr_vector non_units ( ) const
inline

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

2211 { Z3_ast_vector r = Z3_solver_get_non_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404
Z3_ast_vector Z3_API Z3_solver_get_non_units(Z3_context c, Z3_solver s)
Return the set of non units in the solver state.
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:71

◆ operator Z3_solver()

operator Z3_solver ( ) const
inline

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

2148 { return m_solver; }

◆ operator=()

solver& operator= ( solver const &  s)
inline

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

2149  {
2150  Z3_solver_inc_ref(s.ctx(), s.m_solver);
2151  Z3_solver_dec_ref(ctx(), m_solver);
2152  m_ctx = s.m_ctx;
2153  m_solver = s.m_solver;
2154  return *this;
2155  }
void Z3_API Z3_solver_inc_ref(Z3_context c, Z3_solver s)
Increment the reference counter of the given solver.
context & ctx() const
Definition: z3++.h:404
context * m_ctx
Definition: z3++.h:400
void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.

◆ pop()

void pop ( unsigned  n = 1)
inline

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

2163 { Z3_solver_pop(ctx(), m_solver, n); check_error(); }
Z3_error_code check_error() const
Definition: z3++.h:405
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
context & ctx() const
Definition: z3++.h:404

◆ proof()

expr proof ( ) const
inline

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

2213 { Z3_ast r = Z3_solver_get_proof(ctx(), m_solver); check_error(); return expr(ctx(), r); }
Z3_error_code check_error() const
Definition: z3++.h:405
Z3_ast Z3_API Z3_solver_get_proof(Z3_context c, Z3_solver s)
Retrieve the proof for the last Z3_solver_check or Z3_solver_check_assumptions.
context & ctx() const
Definition: z3++.h:404

◆ push()

void push ( )
inline

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

2162 { Z3_solver_push(ctx(), m_solver); check_error(); }
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404

◆ reason_unknown()

std::string reason_unknown ( ) const
inline

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

2207 { Z3_string r = Z3_solver_get_reason_unknown(ctx(), m_solver); check_error(); return r; }
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404
Z3_string Z3_API Z3_solver_get_reason_unknown(Z3_context c, Z3_solver s)
Return a brief justification for an "unknown" result (i.e., Z3_L_UNDEF) for the commands Z3_solver_ch...
const char * Z3_string
Z3 string type. It is just an alias for const char *.
Definition: z3_api.h:82

◆ reset()

void reset ( )
inline

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

2164 { Z3_solver_reset(ctx(), m_solver); check_error(); }
Z3_error_code check_error() const
Definition: z3++.h:405
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
context & ctx() const
Definition: z3++.h:404

◆ set() [1/6]

void set ( params const &  p)
inline

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

2156 { Z3_solver_set_params(ctx(), m_solver, p); check_error(); }
void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p)
Set the given solver using the given parameters.
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404

◆ set() [2/6]

void set ( char const *  k,
bool  v 
)
inline

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

2157 { params p(ctx()); p.set(k, v); set(p); }
context & ctx() const
Definition: z3++.h:404

◆ set() [3/6]

void set ( char const *  k,
unsigned  v 
)
inline

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

2158 { params p(ctx()); p.set(k, v); set(p); }
context & ctx() const
Definition: z3++.h:404

◆ set() [4/6]

void set ( char const *  k,
double  v 
)
inline

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

2159 { params p(ctx()); p.set(k, v); set(p); }
context & ctx() const
Definition: z3++.h:404

◆ set() [5/6]

void set ( char const *  k,
symbol const &  v 
)
inline

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

2160 { params p(ctx()); p.set(k, v); set(p); }
context & ctx() const
Definition: z3++.h:404

◆ set() [6/6]

void set ( char const *  k,
char const *  v 
)
inline

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

2161 { params p(ctx()); p.set(k, v); set(p); }
context & ctx() const
Definition: z3++.h:404

◆ statistics()

stats statistics ( ) const
inline

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

2208 { Z3_stats r = Z3_solver_get_statistics(ctx(), m_solver); check_error(); return stats(ctx(), r); }
Z3_error_code check_error() const
Definition: z3++.h:405
Z3_stats Z3_API Z3_solver_get_statistics(Z3_context c, Z3_solver s)
Return statistics for the given solver.
context & ctx() const
Definition: z3++.h:404

◆ to_smt2()

std::string to_smt2 ( char const *  status = "unknown")
inline

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

2216  {
2217  array<Z3_ast> es(assertions());
2218  Z3_ast const* fmls = es.ptr();
2219  Z3_ast fml = 0;
2220  unsigned sz = es.size();
2221  if (sz > 0) {
2222  --sz;
2223  fml = fmls[sz];
2224  }
2225  else {
2226  fml = ctx().bool_val(true);
2227  }
2228  return std::string(Z3_benchmark_to_smtlib_string(
2229  ctx(),
2230  "", "", status, "",
2231  sz,
2232  fmls,
2233  fml));
2234  }
context & ctx() const
Definition: z3++.h:404
expr bool_val(bool b)
Definition: z3++.h:2916
expr_vector assertions() const
Definition: z3++.h:2210
Z3_string Z3_API Z3_benchmark_to_smtlib_string(Z3_context c, Z3_string name, Z3_string logic, Z3_string status, Z3_string attributes, unsigned num_assumptions, Z3_ast const assumptions[], Z3_ast formula)
Convert the given benchmark into SMT-LIB formatted string.

◆ units()

expr_vector units ( ) const
inline

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

2212 { Z3_ast_vector r = Z3_solver_get_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
Z3_error_code check_error() const
Definition: z3++.h:405
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s)
Return the set of units modulo model conversion.
context & ctx() const
Definition: z3++.h:404
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:71

◆ unsat_core()

expr_vector unsat_core ( ) const
inline

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

2209 { Z3_ast_vector r = Z3_solver_get_unsat_core(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
Z3_error_code check_error() const
Definition: z3++.h:405
context & ctx() const
Definition: z3++.h:404
Z3_ast_vector Z3_API Z3_solver_get_unsat_core(Z3_context c, Z3_solver s)
Retrieve the unsat core for the last Z3_solver_check_assumptions The unsat core is a subset of the as...
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:71

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
solver const &  s 
)
friend

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

2330 { out << Z3_solver_to_string(s.ctx(), s); return out; }
Z3_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.