Z3
 
Loading...
Searching...
No Matches
Data Structures | Namespaces | Macros | Typedefs | Enumerations | Functions
z3++.h File Reference

Go to the source code of this file.

Data Structures

class  exception
 Exception used to sign API usage errors. More...
 
class  config
 Z3 global configuration object. More...
 
class  context
 A Context manages all other Z3 objects, global configuration options, etc. More...
 
class  array< T >
 
class  object
 
class  symbol
 
class  param_descrs
 
class  params
 
class  ast
 
class  ast_vector_tpl< T >
 
class  ast_vector_tpl< T >::iterator
 
class  sort
 A Z3 sort (aka type). Every expression (i.e., formula or term) in Z3 has a sort. More...
 
class  func_decl
 Function declaration (aka function definition). It is the signature of interpreted and uninterpreted functions in Z3. The basic building block in Z3 is the function application. More...
 
class  expr
 A Z3 expression is used to represent formulas and terms. For Z3, a formula is any expression of sort Boolean. Every expression has a sort. More...
 
class  expr::iterator
 
class  cast_ast< ast >
 
class  cast_ast< expr >
 
class  cast_ast< sort >
 
class  cast_ast< func_decl >
 
class  func_entry
 
class  func_interp
 
class  model
 
struct  model::translate
 
class  stats
 
class  parameter
 class for auxiliary parameters associated with func_decl The class is initialized with a func_decl or application expression and an index The accessor get_expr, get_sort, ... is available depending on the value of kind(). The caller is responsible to check that the kind of the parameter aligns with the call (get_expr etc). More...
 
class  solver
 
struct  solver::simple
 
struct  solver::translate
 
class  solver::cube_iterator
 
class  solver::cube_generator
 
class  goal
 
class  apply_result
 
class  tactic
 
class  simplifier
 
class  probe
 
class  optimize
 
struct  optimize::translate
 
class  optimize::handle
 
class  fixedpoint
 
class  constructor_list
 
class  constructors
 
class  on_clause
 
class  user_propagator_base
 
class  rcf_num
 Wrapper for Z3 Real Closed Field (RCF) numerals. More...
 

Namespaces

namespace  z3
 Z3 C++ namespace.
 

Macros

#define Z3_THROW(x)   {}
 
#define _Z3_MK_BIN_(a, b, binop)
 
#define _Z3_MK_UN_(a, mkun)
 
#define MK_EXPR1(_fn, _arg)
 
#define MK_EXPR2(_fn, _arg1, _arg2)
 

Typedefs

typedef ast_vector_tpl< astast_vector
 
typedef ast_vector_tpl< exprexpr_vector
 
typedef ast_vector_tpl< sortsort_vector
 
typedef ast_vector_tpl< func_declfunc_decl_vector
 
typedef std::function< void(expr const &proof, std::vector< unsigned > const &deps, expr_vector const &clause)> on_clause_eh_t
 

Enumerations

enum  check_result { unsat , sat , unknown }
 
enum  rounding_mode {
  RNA , RNE , RTP , RTN ,
  RTZ
}
 

Functions

void set_param (char const *param, char const *value)
 
void set_param (char const *param, bool value)
 
void set_param (char const *param, int value)
 
void reset_params ()
 
void get_version (unsigned &major, unsigned &minor, unsigned &build_number, unsigned &revision_number)
 Return Z3 version number information.
 
std::string get_full_version ()
 Return a string that fully describes the version of Z3 in use.
 
void enable_trace (char const *tag)
 Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
 
void disable_trace (char const *tag)
 Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
 
std::ostream & operator<< (std::ostream &out, exception const &e)
 
check_result to_check_result (Z3_lbool l)
 
void check_context (object const &a, object const &b)
 
std::ostream & operator<< (std::ostream &out, symbol const &s)
 
std::ostream & operator<< (std::ostream &out, param_descrs const &d)
 
std::ostream & operator<< (std::ostream &out, params const &p)
 
std::ostream & operator<< (std::ostream &out, ast const &n)
 
bool eq (ast const &a, ast const &b)
 
expr select (expr const &a, expr const &i)
 forward declarations
 
expr select (expr const &a, expr_vector const &i)
 
expr implies (expr const &a, expr const &b)
 
expr implies (expr const &a, bool b)
 
expr implies (bool a, expr const &b)
 
expr pw (expr const &a, expr const &b)
 
expr pw (expr const &a, int b)
 
expr pw (int a, expr const &b)
 
expr mod (expr const &a, expr const &b)
 
expr mod (expr const &a, int b)
 
expr mod (int a, expr const &b)
 
expr operator% (expr const &a, expr const &b)
 
expr operator% (expr const &a, int b)
 
expr operator% (int a, expr const &b)
 
expr rem (expr const &a, expr const &b)
 
expr rem (expr const &a, int b)
 
expr rem (int a, expr const &b)
 
expr operator! (expr const &a)
 
expr is_int (expr const &e)
 
expr operator&& (expr const &a, expr const &b)
 
expr operator&& (expr const &a, bool b)
 
expr operator&& (bool a, expr const &b)
 
expr operator|| (expr const &a, expr const &b)
 
expr operator|| (expr const &a, bool b)
 
expr operator|| (bool a, expr const &b)
 
expr operator== (expr const &a, expr const &b)
 
expr operator== (expr const &a, int b)
 
expr operator== (int a, expr const &b)
 
expr operator== (expr const &a, double b)
 
expr operator== (double a, expr const &b)
 
expr operator!= (expr const &a, expr const &b)
 
expr operator!= (expr const &a, int b)
 
expr operator!= (int a, expr const &b)
 
expr operator!= (expr const &a, double b)
 
expr operator!= (double a, expr const &b)
 
expr operator+ (expr const &a, expr const &b)
 
expr operator+ (expr const &a, int b)
 
expr operator+ (int a, expr const &b)
 
expr operator* (expr const &a, expr const &b)
 
expr operator* (expr const &a, int b)
 
expr operator* (int a, expr const &b)
 
expr operator>= (expr const &a, expr const &b)
 
expr operator/ (expr const &a, expr const &b)
 
expr operator/ (expr const &a, int b)
 
expr operator/ (int a, expr const &b)
 
expr operator- (expr const &a)
 
expr operator- (expr const &a, expr const &b)
 
expr operator- (expr const &a, int b)
 
expr operator- (int a, expr const &b)
 
expr operator<= (expr const &a, expr const &b)
 
expr operator<= (expr const &a, int b)
 
expr operator<= (int a, expr const &b)
 
expr operator>= (expr const &a, int b)
 
expr operator>= (int a, expr const &b)
 
expr operator< (expr const &a, expr const &b)
 
expr operator< (expr const &a, int b)
 
expr operator< (int a, expr const &b)
 
expr operator> (expr const &a, expr const &b)
 
expr operator> (expr const &a, int b)
 
expr operator> (int a, expr const &b)
 
expr operator& (expr const &a, expr const &b)
 
expr operator& (expr const &a, int b)
 
expr operator& (int a, expr const &b)
 
expr operator^ (expr const &a, expr const &b)
 
expr operator^ (expr const &a, int b)
 
expr operator^ (int a, expr const &b)
 
expr operator| (expr const &a, expr const &b)
 
expr operator| (expr const &a, int b)
 
expr operator| (int a, expr const &b)
 
expr nand (expr const &a, expr const &b)
 
expr nor (expr const &a, expr const &b)
 
expr xnor (expr const &a, expr const &b)
 
expr min (expr const &a, expr const &b)
 
expr max (expr const &a, expr const &b)
 
expr bvredor (expr const &a)
 
expr bvredand (expr const &a)
 
expr abs (expr const &a)
 
expr sqrt (expr const &a, expr const &rm)
 
expr fp_eq (expr const &a, expr const &b)
 
expr operator~ (expr const &a)
 
expr fma (expr const &a, expr const &b, expr const &c, expr const &rm)
 
expr fpa_fp (expr const &sgn, expr const &exp, expr const &sig)
 
expr fpa_to_sbv (expr const &t, unsigned sz)
 
expr fpa_to_ubv (expr const &t, unsigned sz)
 
expr sbv_to_fpa (expr const &t, sort s)
 
expr ubv_to_fpa (expr const &t, sort s)
 
expr fpa_to_fpa (expr const &t, sort s)
 
expr round_fpa_to_closest_integer (expr const &t)
 
expr ite (expr const &c, expr const &t, expr const &e)
 Create the if-then-else expression ite(c, t, e)
 
expr to_expr (context &c, Z3_ast a)
 Wraps a Z3_ast as an expr object. It also checks for errors. This function allows the user to use the whole C API with the C++ layer defined in this file.
 
sort to_sort (context &c, Z3_sort s)
 
func_decl to_func_decl (context &c, Z3_func_decl f)
 
expr sle (expr const &a, expr const &b)
 signed less than or equal to operator for bitvectors.
 
expr sle (expr const &a, int b)
 
expr sle (int a, expr const &b)
 
expr slt (expr const &a, expr const &b)
 signed less than operator for bitvectors.
 
expr slt (expr const &a, int b)
 
expr slt (int a, expr const &b)
 
expr sge (expr const &a, expr const &b)
 signed greater than or equal to operator for bitvectors.
 
expr sge (expr const &a, int b)
 
expr sge (int a, expr const &b)
 
expr sgt (expr const &a, expr const &b)
 signed greater than operator for bitvectors.
 
expr sgt (expr const &a, int b)
 
expr sgt (int a, expr const &b)
 
expr ule (expr const &a, expr const &b)
 unsigned less than or equal to operator for bitvectors.
 
expr ule (expr const &a, int b)
 
expr ule (int a, expr const &b)
 
expr ult (expr const &a, expr const &b)
 unsigned less than operator for bitvectors.
 
expr ult (expr const &a, int b)
 
expr ult (int a, expr const &b)
 
expr uge (expr const &a, expr const &b)
 unsigned greater than or equal to operator for bitvectors.
 
expr uge (expr const &a, int b)
 
expr uge (int a, expr const &b)
 
expr ugt (expr const &a, expr const &b)
 unsigned greater than operator for bitvectors.
 
expr ugt (expr const &a, int b)
 
expr ugt (int a, expr const &b)
 
expr sdiv (expr const &a, expr const &b)
 signed division operator for bitvectors.
 
expr sdiv (expr const &a, int b)
 
expr sdiv (int a, expr const &b)
 
expr udiv (expr const &a, expr const &b)
 unsigned division operator for bitvectors.
 
expr udiv (expr const &a, int b)
 
expr udiv (int a, expr const &b)
 
expr srem (expr const &a, expr const &b)
 signed remainder operator for bitvectors
 
expr srem (expr const &a, int b)
 
expr srem (int a, expr const &b)
 
expr smod (expr const &a, expr const &b)
 signed modulus operator for bitvectors
 
expr smod (expr const &a, int b)
 
expr smod (int a, expr const &b)
 
expr urem (expr const &a, expr const &b)
 unsigned reminder operator for bitvectors
 
expr urem (expr const &a, int b)
 
expr urem (int a, expr const &b)
 
expr shl (expr const &a, expr const &b)
 shift left operator for bitvectors
 
expr shl (expr const &a, int b)
 
expr shl (int a, expr const &b)
 
expr lshr (expr const &a, expr const &b)
 logic shift right operator for bitvectors
 
expr lshr (expr const &a, int b)
 
expr lshr (int a, expr const &b)
 
expr ashr (expr const &a, expr const &b)
 arithmetic shift right operator for bitvectors
 
expr ashr (expr const &a, int b)
 
expr ashr (int a, expr const &b)
 
expr zext (expr const &a, unsigned i)
 Extend the given bit-vector with zeros to the (unsigned) equivalent bitvector of size m+i, where m is the size of the given bit-vector.
 
expr bv2int (expr const &a, bool is_signed)
 bit-vector and integer conversions.
 
expr int2bv (unsigned n, expr const &a)
 
expr bvadd_no_overflow (expr const &a, expr const &b, bool is_signed)
 bit-vector overflow/underflow checks
 
expr bvadd_no_underflow (expr const &a, expr const &b)
 
expr bvsub_no_overflow (expr const &a, expr const &b)
 
expr bvsub_no_underflow (expr const &a, expr const &b, bool is_signed)
 
expr bvsdiv_no_overflow (expr const &a, expr const &b)
 
expr bvneg_no_overflow (expr const &a)
 
expr bvmul_no_overflow (expr const &a, expr const &b, bool is_signed)
 
expr bvmul_no_underflow (expr const &a, expr const &b)
 
expr sext (expr const &a, unsigned i)
 Sign-extend of the given bit-vector to the (signed) equivalent bitvector of size m+i, where m is the size of the given bit-vector.
 
func_decl linear_order (sort const &a, unsigned index)
 
func_decl partial_order (sort const &a, unsigned index)
 
func_decl piecewise_linear_order (sort const &a, unsigned index)
 
func_decl tree_order (sort const &a, unsigned index)
 
expr_vector polynomial_subresultants (expr const &p, expr const &q, expr const &x)
 Return the nonzero subresultants of p and q with respect to the "variable" x.
 
expr forall (expr const &x, expr const &b)
 
expr forall (expr const &x1, expr const &x2, expr const &b)
 
expr forall (expr const &x1, expr const &x2, expr const &x3, expr const &b)
 
expr forall (expr const &x1, expr const &x2, expr const &x3, expr const &x4, expr const &b)
 
expr forall (expr_vector const &xs, expr const &b)
 
expr exists (expr const &x, expr const &b)
 
expr exists (expr const &x1, expr const &x2, expr const &b)
 
expr exists (expr const &x1, expr const &x2, expr const &x3, expr const &b)
 
expr exists (expr const &x1, expr const &x2, expr const &x3, expr const &x4, expr const &b)
 
expr exists (expr_vector const &xs, expr const &b)
 
expr lambda (expr const &x, expr const &b)
 
expr lambda (expr const &x1, expr const &x2, expr const &b)
 
expr lambda (expr const &x1, expr const &x2, expr const &x3, expr const &b)
 
expr lambda (expr const &x1, expr const &x2, expr const &x3, expr const &x4, expr const &b)
 
expr lambda (expr_vector const &xs, expr const &b)
 
expr pble (expr_vector const &es, int const *coeffs, int bound)
 
expr pbge (expr_vector const &es, int const *coeffs, int bound)
 
expr pbeq (expr_vector const &es, int const *coeffs, int bound)
 
expr atmost (expr_vector const &es, unsigned bound)
 
expr atleast (expr_vector const &es, unsigned bound)
 
expr sum (expr_vector const &args)
 
expr distinct (expr_vector const &args)
 
expr concat (expr const &a, expr const &b)
 
expr concat (expr_vector const &args)
 
expr map (expr const &f, expr const &list)
 
expr mapi (expr const &f, expr const &i, expr const &list)
 
expr foldl (expr const &f, expr const &a, expr const &list)
 
expr foldli (expr const &f, expr const &i, expr const &a, expr const &list)
 
expr mk_or (expr_vector const &args)
 
expr mk_and (expr_vector const &args)
 
expr mk_xor (expr_vector const &args)
 
std::ostream & operator<< (std::ostream &out, model const &m)
 
std::ostream & operator<< (std::ostream &out, stats const &s)
 
std::ostream & operator<< (std::ostream &out, check_result r)
 
std::ostream & operator<< (std::ostream &out, solver const &s)
 
std::ostream & operator<< (std::ostream &out, goal const &g)
 
std::ostream & operator<< (std::ostream &out, apply_result const &r)
 
tactic operator& (tactic const &t1, tactic const &t2)
 
tactic operator| (tactic const &t1, tactic const &t2)
 
tactic repeat (tactic const &t, unsigned max=UINT_MAX)
 
tactic with (tactic const &t, params const &p)
 
tactic try_for (tactic const &t, unsigned ms)
 
tactic par_or (unsigned n, tactic const *tactics)
 
tactic par_and_then (tactic const &t1, tactic const &t2)
 
simplifier operator& (simplifier const &t1, simplifier const &t2)
 
simplifier with (simplifier const &t, params const &p)
 
probe operator<= (probe const &p1, probe const &p2)
 
probe operator<= (probe const &p1, double p2)
 
probe operator<= (double p1, probe const &p2)
 
probe operator>= (probe const &p1, probe const &p2)
 
probe operator>= (probe const &p1, double p2)
 
probe operator>= (double p1, probe const &p2)
 
probe operator< (probe const &p1, probe const &p2)
 
probe operator< (probe const &p1, double p2)
 
probe operator< (double p1, probe const &p2)
 
probe operator> (probe const &p1, probe const &p2)
 
probe operator> (probe const &p1, double p2)
 
probe operator> (double p1, probe const &p2)
 
probe operator== (probe const &p1, probe const &p2)
 
probe operator== (probe const &p1, double p2)
 
probe operator== (double p1, probe const &p2)
 
probe operator&& (probe const &p1, probe const &p2)
 
probe operator|| (probe const &p1, probe const &p2)
 
probe operator! (probe const &p)
 
std::ostream & operator<< (std::ostream &out, optimize const &s)
 
std::ostream & operator<< (std::ostream &out, fixedpoint const &f)
 
tactic fail_if (probe const &p)
 
tactic when (probe const &p, tactic const &t)
 
tactic cond (probe const &p, tactic const &t1, tactic const &t2)
 
expr to_real (expr const &a)
 
func_decl function (symbol const &name, unsigned arity, sort const *domain, sort const &range)
 
func_decl function (char const *name, unsigned arity, sort const *domain, sort const &range)
 
func_decl function (char const *name, sort const &domain, sort const &range)
 
func_decl function (char const *name, sort const &d1, sort const &d2, sort const &range)
 
func_decl function (char const *name, sort const &d1, sort const &d2, sort const &d3, sort const &range)
 
func_decl function (char const *name, sort const &d1, sort const &d2, sort const &d3, sort const &d4, sort const &range)
 
func_decl function (char const *name, sort const &d1, sort const &d2, sort const &d3, sort const &d4, sort const &d5, sort const &range)
 
func_decl function (char const *name, sort_vector const &domain, sort const &range)
 
func_decl function (std::string const &name, sort_vector const &domain, sort const &range)
 
func_decl recfun (symbol const &name, unsigned arity, sort const *domain, sort const &range)
 
func_decl recfun (char const *name, unsigned arity, sort const *domain, sort const &range)
 
func_decl recfun (char const *name, sort const &d1, sort const &range)
 
func_decl recfun (char const *name, sort const &d1, sort const &d2, sort const &range)
 
expr select (expr const &a, int i)
 
expr store (expr const &a, expr const &i, expr const &v)
 
expr store (expr const &a, int i, expr const &v)
 
expr store (expr const &a, expr i, int v)
 
expr store (expr const &a, int i, int v)
 
expr store (expr const &a, expr_vector const &i, expr const &v)
 
expr as_array (func_decl &f)
 
expr array_default (expr const &a)
 
expr array_ext (expr const &a, expr const &b)
 
expr const_array (sort const &d, expr const &v)
 
expr empty_set (sort const &s)
 
expr full_set (sort const &s)
 
expr set_add (expr const &s, expr const &e)
 
expr set_del (expr const &s, expr const &e)
 
expr set_union (expr const &a, expr const &b)
 
expr set_intersect (expr const &a, expr const &b)
 
expr set_difference (expr const &a, expr const &b)
 
expr set_complement (expr const &a)
 
expr set_member (expr const &s, expr const &e)
 
expr set_subset (expr const &a, expr const &b)
 
expr empty (sort const &s)
 
expr suffixof (expr const &a, expr const &b)
 
expr prefixof (expr const &a, expr const &b)
 
expr indexof (expr const &s, expr const &substr, expr const &offset)
 
expr last_indexof (expr const &s, expr const &substr)
 
expr to_re (expr const &s)
 
expr in_re (expr const &s, expr const &re)
 
expr plus (expr const &re)
 
expr option (expr const &re)
 
expr star (expr const &re)
 
expr re_empty (sort const &s)
 
expr re_full (sort const &s)
 
expr re_intersect (expr_vector const &args)
 
expr re_diff (expr const &a, expr const &b)
 
expr re_complement (expr const &a)
 
expr range (expr const &lo, expr const &hi)
 
rcf_num rcf_pi (context &c)
 Create an RCF numeral representing pi.
 
rcf_num rcf_e (context &c)
 Create an RCF numeral representing e (Euler's constant).
 
rcf_num rcf_infinitesimal (context &c)
 Create an RCF numeral representing an infinitesimal.
 
std::vector< rcf_numrcf_roots (context &c, std::vector< rcf_num > const &coeffs)
 Find roots of a polynomial with given coefficients.
 

Macro Definition Documentation

◆ _Z3_MK_BIN_

#define _Z3_MK_BIN_ (   a,
  b,
  binop 
)
Value:
check_context(a, b); \
Z3_ast r = binop(a.ctx(), a, b); \
a.check_error(); \
return expr(a.ctx(), r); \

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

1715 {
1716 assert(a.is_bool() && b.is_bool());
1718 }
1719 inline expr implies(expr const & a, bool b) { return implies(a, a.ctx().bool_val(b)); }
1720 inline expr implies(bool a, expr const & b) { return implies(b.ctx().bool_val(a), b); }
1721
1722
1723 inline expr pw(expr const & a, expr const & b) { _Z3_MK_BIN_(a, b, Z3_mk_power); }
1724 inline expr pw(expr const & a, int b) { return pw(a, a.ctx().num_val(b, a.get_sort())); }
1725 inline expr pw(int a, expr const & b) { return pw(b.ctx().num_val(a, b.get_sort()), b); }
1726
1727 inline expr mod(expr const& a, expr const& b) {
1728 if (a.is_bv()) {
1729 _Z3_MK_BIN_(a, b, Z3_mk_bvsmod);
1730 }
1731 else {
1732 _Z3_MK_BIN_(a, b, Z3_mk_mod);
1733 }
1734 }
1735 inline expr mod(expr const & a, int b) { return mod(a, a.ctx().num_val(b, a.get_sort())); }
1736 inline expr mod(int a, expr const & b) { return mod(b.ctx().num_val(a, b.get_sort()), b); }
1737
1738 inline expr operator%(expr const& a, expr const& b) { return mod(a, b); }
1739 inline expr operator%(expr const& a, int b) { return mod(a, b); }
1740 inline expr operator%(int a, expr const& b) { return mod(a, b); }
1741
1742
1743 inline expr rem(expr const& a, expr const& b) {
1744 if (a.is_fpa() && b.is_fpa()) {
1746 } else {
1747 _Z3_MK_BIN_(a, b, Z3_mk_rem);
1748 }
1749 }
1750 inline expr rem(expr const & a, int b) { return rem(a, a.ctx().num_val(b, a.get_sort())); }
1751 inline expr rem(int a, expr const & b) { return rem(b.ctx().num_val(a, b.get_sort()), b); }
1752
1753#undef _Z3_MK_BIN_
1754
1755#define _Z3_MK_UN_(a, mkun) \
1756 Z3_ast r = mkun(a.ctx(), a); \
1757 a.check_error(); \
1758 return expr(a.ctx(), r); \
1759
1760
1761 inline expr operator!(expr const & a) { assert(a.is_bool()); _Z3_MK_UN_(a, Z3_mk_not); }
1762
1763 inline expr is_int(expr const& e) { _Z3_MK_UN_(e, Z3_mk_is_int); }
1764
1765#undef _Z3_MK_UN_
1766
1767 inline expr operator&&(expr const & a, expr const & b) {
1768 check_context(a, b);
1769 assert(a.is_bool() && b.is_bool());
1770 Z3_ast args[2] = { a, b };
1771 Z3_ast r = Z3_mk_and(a.ctx(), 2, args);
1772 a.check_error();
1773 return expr(a.ctx(), r);
1774 }
1775
1776 inline expr operator&&(expr const & a, bool b) { return a && a.ctx().bool_val(b); }
1777 inline expr operator&&(bool a, expr const & b) { return b.ctx().bool_val(a) && b; }
1778
1779 inline expr operator||(expr const & a, expr const & b) {
1780 check_context(a, b);
1781 assert(a.is_bool() && b.is_bool());
1782 Z3_ast args[2] = { a, b };
1783 Z3_ast r = Z3_mk_or(a.ctx(), 2, args);
1784 a.check_error();
1785 return expr(a.ctx(), r);
1786 }
1787
1788 inline expr operator||(expr const & a, bool b) { return a || a.ctx().bool_val(b); }
1789
1790 inline expr operator||(bool a, expr const & b) { return b.ctx().bool_val(a) || b; }
1791
1792 inline expr operator==(expr const & a, expr const & b) {
1793 check_context(a, b);
1794 Z3_ast r = Z3_mk_eq(a.ctx(), a, b);
1795 a.check_error();
1796 return expr(a.ctx(), r);
1797 }
1798 inline expr operator==(expr const & a, int b) { assert(a.is_arith() || a.is_bv() || a.is_fpa()); return a == a.ctx().num_val(b, a.get_sort()); }
1799 inline expr operator==(int a, expr const & b) { assert(b.is_arith() || b.is_bv() || b.is_fpa()); return b.ctx().num_val(a, b.get_sort()) == b; }
1800 inline expr operator==(expr const & a, double b) { assert(a.is_fpa()); return a == a.ctx().fpa_val(b); }
1801 inline expr operator==(double a, expr const & b) { assert(b.is_fpa()); return b.ctx().fpa_val(a) == b; }
1802
1803 inline expr operator!=(expr const & a, expr const & b) {
1804 check_context(a, b);
1805 Z3_ast args[2] = { a, b };
1806 Z3_ast r = Z3_mk_distinct(a.ctx(), 2, args);
1807 a.check_error();
1808 return expr(a.ctx(), r);
1809 }
1810 inline expr operator!=(expr const & a, int b) { assert(a.is_arith() || a.is_bv() || a.is_fpa()); return a != a.ctx().num_val(b, a.get_sort()); }
1811 inline expr operator!=(int a, expr const & b) { assert(b.is_arith() || b.is_bv() || b.is_fpa()); return b.ctx().num_val(a, b.get_sort()) != b; }
1812 inline expr operator!=(expr const & a, double b) { assert(a.is_fpa()); return a != a.ctx().fpa_val(b); }
1813 inline expr operator!=(double a, expr const & b) { assert(b.is_fpa()); return b.ctx().fpa_val(a) != b; }
1814
1815 inline expr operator+(expr const & a, expr const & b) {
1816 check_context(a, b);
1817 Z3_ast r = 0;
1818 if (a.is_arith() && b.is_arith()) {
1819 Z3_ast args[2] = { a, b };
1820 r = Z3_mk_add(a.ctx(), 2, args);
1821 }
1822 else if (a.is_bv() && b.is_bv()) {
1823 r = Z3_mk_bvadd(a.ctx(), a, b);
1824 }
1825 else if (a.is_seq() && b.is_seq()) {
1826 return concat(a, b);
1827 }
1828 else if (a.is_re() && b.is_re()) {
1829 Z3_ast _args[2] = { a, b };
1830 r = Z3_mk_re_union(a.ctx(), 2, _args);
1831 }
1832 else if (a.is_fpa() && b.is_fpa()) {
1833 r = Z3_mk_fpa_add(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1834 }
1835 else {
1836 // operator is not supported by given arguments.
1837 assert(false);
1838 }
1839 a.check_error();
1840 return expr(a.ctx(), r);
1841 }
1842 inline expr operator+(expr const & a, int b) { return a + a.ctx().num_val(b, a.get_sort()); }
1843 inline expr operator+(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) + b; }
1844
1845 inline expr operator*(expr const & a, expr const & b) {
1846 check_context(a, b);
1847 Z3_ast r = 0;
1848 if (a.is_arith() && b.is_arith()) {
1849 Z3_ast args[2] = { a, b };
1850 r = Z3_mk_mul(a.ctx(), 2, args);
1851 }
1852 else if (a.is_bv() && b.is_bv()) {
1853 r = Z3_mk_bvmul(a.ctx(), a, b);
1854 }
1855 else if (a.is_fpa() && b.is_fpa()) {
1856 r = Z3_mk_fpa_mul(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1857 }
1858 else {
1859 // operator is not supported by given arguments.
1860 assert(false);
1861 }
1862 a.check_error();
1863 return expr(a.ctx(), r);
1864 }
1865 inline expr operator*(expr const & a, int b) { return a * a.ctx().num_val(b, a.get_sort()); }
1866 inline expr operator*(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) * b; }
1867
1868
1869 inline expr operator>=(expr const & a, expr const & b) {
1870 check_context(a, b);
1871 Z3_ast r = 0;
1872 if (a.is_arith() && b.is_arith()) {
1873 r = Z3_mk_ge(a.ctx(), a, b);
1874 }
1875 else if (a.is_bv() && b.is_bv()) {
1876 r = Z3_mk_bvsge(a.ctx(), a, b);
1877 }
1878 else if (a.is_fpa() && b.is_fpa()) {
1879 r = Z3_mk_fpa_geq(a.ctx(), a, b);
1880 }
1881 else {
1882 // operator is not supported by given arguments.
1883 assert(false);
1884 }
1885 a.check_error();
1886 return expr(a.ctx(), r);
1887 }
1888
1889 inline expr operator/(expr const & a, expr const & b) {
1890 check_context(a, b);
1891 Z3_ast r = 0;
1892 if (a.is_arith() && b.is_arith()) {
1893 r = Z3_mk_div(a.ctx(), a, b);
1894 }
1895 else if (a.is_bv() && b.is_bv()) {
1896 r = Z3_mk_bvsdiv(a.ctx(), a, b);
1897 }
1898 else if (a.is_fpa() && b.is_fpa()) {
1899 r = Z3_mk_fpa_div(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1900 }
1901 else {
1902 // operator is not supported by given arguments.
1903 assert(false);
1904 }
1905 a.check_error();
1906 return expr(a.ctx(), r);
1907 }
1908 inline expr operator/(expr const & a, int b) { return a / a.ctx().num_val(b, a.get_sort()); }
1909 inline expr operator/(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) / b; }
1910
1911 inline expr operator-(expr const & a) {
1912 Z3_ast r = 0;
1913 if (a.is_arith()) {
1914 r = Z3_mk_unary_minus(a.ctx(), a);
1915 }
1916 else if (a.is_bv()) {
1917 r = Z3_mk_bvneg(a.ctx(), a);
1918 }
1919 else if (a.is_fpa()) {
1920 r = Z3_mk_fpa_neg(a.ctx(), a);
1921 }
1922 else {
1923 // operator is not supported by given arguments.
1924 assert(false);
1925 }
1926 a.check_error();
1927 return expr(a.ctx(), r);
1928 }
1929
1930 inline expr operator-(expr const & a, expr const & b) {
1931 check_context(a, b);
1932 Z3_ast r = 0;
1933 if (a.is_arith() && b.is_arith()) {
1934 Z3_ast args[2] = { a, b };
1935 r = Z3_mk_sub(a.ctx(), 2, args);
1936 }
1937 else if (a.is_bv() && b.is_bv()) {
1938 r = Z3_mk_bvsub(a.ctx(), a, b);
1939 }
1940 else if (a.is_fpa() && b.is_fpa()) {
1941 r = Z3_mk_fpa_sub(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1942 }
1943 else {
1944 // operator is not supported by given arguments.
1945 assert(false);
1946 }
1947 a.check_error();
1948 return expr(a.ctx(), r);
1949 }
1950 inline expr operator-(expr const & a, int b) { return a - a.ctx().num_val(b, a.get_sort()); }
1951 inline expr operator-(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) - b; }
1952
1953 inline expr operator<=(expr const & a, expr const & b) {
1954 check_context(a, b);
1955 Z3_ast r = 0;
1956 if (a.is_arith() && b.is_arith()) {
1957 r = Z3_mk_le(a.ctx(), a, b);
1958 }
1959 else if (a.is_bv() && b.is_bv()) {
1960 r = Z3_mk_bvsle(a.ctx(), a, b);
1961 }
1962 else if (a.is_fpa() && b.is_fpa()) {
1963 r = Z3_mk_fpa_leq(a.ctx(), a, b);
1964 }
1965 else {
1966 // operator is not supported by given arguments.
1967 assert(false);
1968 }
1969 a.check_error();
1970 return expr(a.ctx(), r);
1971 }
1972 inline expr operator<=(expr const & a, int b) { return a <= a.ctx().num_val(b, a.get_sort()); }
1973 inline expr operator<=(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) <= b; }
1974
1975 inline expr operator>=(expr const & a, int b) { return a >= a.ctx().num_val(b, a.get_sort()); }
1976 inline expr operator>=(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) >= b; }
1977
1978 inline expr operator<(expr const & a, expr const & b) {
1979 check_context(a, b);
1980 Z3_ast r = 0;
1981 if (a.is_arith() && b.is_arith()) {
1982 r = Z3_mk_lt(a.ctx(), a, b);
1983 }
1984 else if (a.is_bv() && b.is_bv()) {
1985 r = Z3_mk_bvslt(a.ctx(), a, b);
1986 }
1987 else if (a.is_fpa() && b.is_fpa()) {
1988 r = Z3_mk_fpa_lt(a.ctx(), a, b);
1989 }
1990 else {
1991 // operator is not supported by given arguments.
1992 assert(false);
1993 }
1994 a.check_error();
1995 return expr(a.ctx(), r);
1996 }
1997 inline expr operator<(expr const & a, int b) { return a < a.ctx().num_val(b, a.get_sort()); }
1998 inline expr operator<(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) < b; }
1999
2000 inline expr operator>(expr const & a, expr const & b) {
2001 check_context(a, b);
2002 Z3_ast r = 0;
2003 if (a.is_arith() && b.is_arith()) {
2004 r = Z3_mk_gt(a.ctx(), a, b);
2005 }
2006 else if (a.is_bv() && b.is_bv()) {
2007 r = Z3_mk_bvsgt(a.ctx(), a, b);
2008 }
2009 else if (a.is_fpa() && b.is_fpa()) {
2010 r = Z3_mk_fpa_gt(a.ctx(), a, b);
2011 }
2012 else {
2013 // operator is not supported by given arguments.
2014 assert(false);
2015 }
2016 a.check_error();
2017 return expr(a.ctx(), r);
2018 }
2019 inline expr operator>(expr const & a, int b) { return a > a.ctx().num_val(b, a.get_sort()); }
2020 inline expr operator>(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) > b; }
2021
2022 inline expr operator&(expr const & a, expr const & b) { if (a.is_bool()) return a && b; check_context(a, b); Z3_ast r = Z3_mk_bvand(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r); }
2023 inline expr operator&(expr const & a, int b) { return a & a.ctx().num_val(b, a.get_sort()); }
2024 inline expr operator&(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) & b; }
2025
2026 inline expr operator^(expr const & a, expr const & b) { check_context(a, b); Z3_ast r = a.is_bool() ? Z3_mk_xor(a.ctx(), a, b) : Z3_mk_bvxor(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r); }
2027 inline expr operator^(expr const & a, int b) { return a ^ a.ctx().num_val(b, a.get_sort()); }
2028 inline expr operator^(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) ^ b; }
2029
2030 inline expr operator|(expr const & a, expr const & b) { if (a.is_bool()) return a || b; check_context(a, b); Z3_ast r = Z3_mk_bvor(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r); }
2031 inline expr operator|(expr const & a, int b) { return a | a.ctx().num_val(b, a.get_sort()); }
2032 inline expr operator|(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) | b; }
2033
2034 inline expr nand(expr const& a, expr const& b) { if (a.is_bool()) return !(a && b); check_context(a, b); Z3_ast r = Z3_mk_bvnand(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r); }
2035 inline expr nor(expr const& a, expr const& b) { if (a.is_bool()) return !(a || b); check_context(a, b); Z3_ast r = Z3_mk_bvnor(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r); }
2036 inline expr xnor(expr const& a, expr const& b) { if (a.is_bool()) return !(a ^ b); check_context(a, b); Z3_ast r = Z3_mk_bvxnor(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r); }
2037 inline expr min(expr const& a, expr const& b) {
2038 check_context(a, b);
2039 Z3_ast r;
2040 if (a.is_arith()) {
2041 r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, b), b, a);
2042 }
2043 else if (a.is_bv()) {
2044 r = Z3_mk_ite(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b), b, a);
2045 }
2046 else {
2047 assert(a.is_fpa());
2048 r = Z3_mk_fpa_min(a.ctx(), a, b);
2049 }
2050 a.check_error();
2051 return expr(a.ctx(), r);
2052 }
2053 inline expr max(expr const& a, expr const& b) {
2054 check_context(a, b);
2055 Z3_ast r;
2056 if (a.is_arith()) {
2057 r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, b), a, b);
2058 }
2059 else if (a.is_bv()) {
2060 r = Z3_mk_ite(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b), a, b);
2061 }
2062 else {
2063 assert(a.is_fpa());
2064 r = Z3_mk_fpa_max(a.ctx(), a, b);
2065 }
2066 a.check_error();
2067 return expr(a.ctx(), r);
2068 }
2069 inline expr bvredor(expr const & a) {
2070 assert(a.is_bv());
2071 Z3_ast r = Z3_mk_bvredor(a.ctx(), a);
2072 a.check_error();
2073 return expr(a.ctx(), r);
2074 }
2075 inline expr bvredand(expr const & a) {
2076 assert(a.is_bv());
2077 Z3_ast r = Z3_mk_bvredand(a.ctx(), a);
2078 a.check_error();
2079 return expr(a.ctx(), r);
2080 }
2081 inline expr abs(expr const & a) {
2082 Z3_ast r;
2083 if (a.is_int()) {
2084 expr zero = a.ctx().int_val(0);
2085 expr ge = a >= zero;
2086 expr na = -a;
2087 r = Z3_mk_ite(a.ctx(), ge, a, na);
2088 }
2089 else if (a.is_real()) {
2090 expr zero = a.ctx().real_val(0);
2091 expr ge = a >= zero;
2092 expr na = -a;
2093 r = Z3_mk_ite(a.ctx(), ge, a, na);
2094 }
2095 else {
2096 r = Z3_mk_fpa_abs(a.ctx(), a);
2097 }
2098 a.check_error();
2099 return expr(a.ctx(), r);
2100 }
2101 inline expr sqrt(expr const & a, expr const& rm) {
2102 check_context(a, rm);
2103 assert(a.is_fpa());
2104 Z3_ast r = Z3_mk_fpa_sqrt(a.ctx(), rm, a);
2105 a.check_error();
2106 return expr(a.ctx(), r);
2107 }
2108 inline expr fp_eq(expr const & a, expr const & b) {
2109 check_context(a, b);
2110 assert(a.is_fpa());
2111 Z3_ast r = Z3_mk_fpa_eq(a.ctx(), a, b);
2112 a.check_error();
2113 return expr(a.ctx(), r);
2114 }
2115 inline expr operator~(expr const & a) { Z3_ast r = Z3_mk_bvnot(a.ctx(), a); return expr(a.ctx(), r); }
2116
2117 inline expr fma(expr const& a, expr const& b, expr const& c, expr const& rm) {
2118 check_context(a, b); check_context(a, c); check_context(a, rm);
2119 assert(a.is_fpa() && b.is_fpa() && c.is_fpa());
2120 Z3_ast r = Z3_mk_fpa_fma(a.ctx(), rm, a, b, c);
2121 a.check_error();
2122 return expr(a.ctx(), r);
2123 }
2124
2125 inline expr fpa_fp(expr const& sgn, expr const& exp, expr const& sig) {
2126 check_context(sgn, exp); check_context(exp, sig);
2127 assert(sgn.is_bv() && exp.is_bv() && sig.is_bv());
2128 Z3_ast r = Z3_mk_fpa_fp(sgn.ctx(), sgn, exp, sig);
2129 sgn.check_error();
2130 return expr(sgn.ctx(), r);
2131 }
2132
2133 inline expr fpa_to_sbv(expr const& t, unsigned sz) {
2134 assert(t.is_fpa());
2135 Z3_ast r = Z3_mk_fpa_to_sbv(t.ctx(), t.ctx().fpa_rounding_mode(), t, sz);
2136 t.check_error();
2137 return expr(t.ctx(), r);
2138 }
2139
2140 inline expr fpa_to_ubv(expr const& t, unsigned sz) {
2141 assert(t.is_fpa());
2142 Z3_ast r = Z3_mk_fpa_to_ubv(t.ctx(), t.ctx().fpa_rounding_mode(), t, sz);
2143 t.check_error();
2144 return expr(t.ctx(), r);
2145 }
2146
2147 inline expr sbv_to_fpa(expr const& t, sort s) {
2148 assert(t.is_bv());
2149 Z3_ast r = Z3_mk_fpa_to_fp_signed(t.ctx(), t.ctx().fpa_rounding_mode(), t, s);
2150 t.check_error();
2151 return expr(t.ctx(), r);
2152 }
2153
2154 inline expr ubv_to_fpa(expr const& t, sort s) {
2155 assert(t.is_bv());
2156 Z3_ast r = Z3_mk_fpa_to_fp_unsigned(t.ctx(), t.ctx().fpa_rounding_mode(), t, s);
2157 t.check_error();
2158 return expr(t.ctx(), r);
2159 }
2160
2161 inline expr fpa_to_fpa(expr const& t, sort s) {
2162 assert(t.is_fpa());
2163 Z3_ast r = Z3_mk_fpa_to_fp_float(t.ctx(), t.ctx().fpa_rounding_mode(), t, s);
2164 t.check_error();
2165 return expr(t.ctx(), r);
2166 }
2167
2168 inline expr round_fpa_to_closest_integer(expr const& t) {
2169 assert(t.is_fpa());
2170 Z3_ast r = Z3_mk_fpa_round_to_integral(t.ctx(), t.ctx().fpa_rounding_mode(), t);
2171 t.check_error();
2172 return expr(t.ctx(), r);
2173 }
2174
2180 inline expr ite(expr const & c, expr const & t, expr const & e) {
2181 check_context(c, t); check_context(c, e);
2182 assert(c.is_bool());
2183 Z3_ast r = Z3_mk_ite(c.ctx(), c, t, e);
2184 c.check_error();
2185 return expr(c.ctx(), r);
2186 }
2187
2188
2193 inline expr to_expr(context & c, Z3_ast a) {
2194 c.check_error();
2195 assert(Z3_get_ast_kind(c, a) == Z3_APP_AST ||
2197 Z3_get_ast_kind(c, a) == Z3_VAR_AST ||
2199 return expr(c, a);
2200 }
2201
2202 inline sort to_sort(context & c, Z3_sort s) {
2203 c.check_error();
2204 return sort(c, s);
2205 }
2206
2207 inline func_decl to_func_decl(context & c, Z3_func_decl f) {
2208 c.check_error();
2209 return func_decl(c, f);
2210 }
2211
2215 inline expr sle(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsle(a.ctx(), a, b)); }
2216 inline expr sle(expr const & a, int b) { return sle(a, a.ctx().num_val(b, a.get_sort())); }
2217 inline expr sle(int a, expr const & b) { return sle(b.ctx().num_val(a, b.get_sort()), b); }
2221 inline expr slt(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvslt(a.ctx(), a, b)); }
2222 inline expr slt(expr const & a, int b) { return slt(a, a.ctx().num_val(b, a.get_sort())); }
2223 inline expr slt(int a, expr const & b) { return slt(b.ctx().num_val(a, b.get_sort()), b); }
2227 inline expr sge(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsge(a.ctx(), a, b)); }
2228 inline expr sge(expr const & a, int b) { return sge(a, a.ctx().num_val(b, a.get_sort())); }
2229 inline expr sge(int a, expr const & b) { return sge(b.ctx().num_val(a, b.get_sort()), b); }
2233 inline expr sgt(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsgt(a.ctx(), a, b)); }
2234 inline expr sgt(expr const & a, int b) { return sgt(a, a.ctx().num_val(b, a.get_sort())); }
2235 inline expr sgt(int a, expr const & b) { return sgt(b.ctx().num_val(a, b.get_sort()), b); }
2236
2237
2241 inline expr ule(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvule(a.ctx(), a, b)); }
2242 inline expr ule(expr const & a, int b) { return ule(a, a.ctx().num_val(b, a.get_sort())); }
2243 inline expr ule(int a, expr const & b) { return ule(b.ctx().num_val(a, b.get_sort()), b); }
2247 inline expr ult(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvult(a.ctx(), a, b)); }
2248 inline expr ult(expr const & a, int b) { return ult(a, a.ctx().num_val(b, a.get_sort())); }
2249 inline expr ult(int a, expr const & b) { return ult(b.ctx().num_val(a, b.get_sort()), b); }
2253 inline expr uge(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b)); }
2254 inline expr uge(expr const & a, int b) { return uge(a, a.ctx().num_val(b, a.get_sort())); }
2255 inline expr uge(int a, expr const & b) { return uge(b.ctx().num_val(a, b.get_sort()), b); }
2259 inline expr ugt(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvugt(a.ctx(), a, b)); }
2260 inline expr ugt(expr const & a, int b) { return ugt(a, a.ctx().num_val(b, a.get_sort())); }
2261 inline expr ugt(int a, expr const & b) { return ugt(b.ctx().num_val(a, b.get_sort()), b); }
2262
2266 inline expr sdiv(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsdiv(a.ctx(), a, b)); }
2267 inline expr sdiv(expr const & a, int b) { return sdiv(a, a.ctx().num_val(b, a.get_sort())); }
2268 inline expr sdiv(int a, expr const & b) { return sdiv(b.ctx().num_val(a, b.get_sort()), b); }
2269
2273 inline expr udiv(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvudiv(a.ctx(), a, b)); }
2274 inline expr udiv(expr const & a, int b) { return udiv(a, a.ctx().num_val(b, a.get_sort())); }
2275 inline expr udiv(int a, expr const & b) { return udiv(b.ctx().num_val(a, b.get_sort()), b); }
2276
2280 inline expr srem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsrem(a.ctx(), a, b)); }
2281 inline expr srem(expr const & a, int b) { return srem(a, a.ctx().num_val(b, a.get_sort())); }
2282 inline expr srem(int a, expr const & b) { return srem(b.ctx().num_val(a, b.get_sort()), b); }
2283
2287 inline expr smod(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsmod(a.ctx(), a, b)); }
2288 inline expr smod(expr const & a, int b) { return smod(a, a.ctx().num_val(b, a.get_sort())); }
2289 inline expr smod(int a, expr const & b) { return smod(b.ctx().num_val(a, b.get_sort()), b); }
2290
2294 inline expr urem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvurem(a.ctx(), a, b)); }
2295 inline expr urem(expr const & a, int b) { return urem(a, a.ctx().num_val(b, a.get_sort())); }
2296 inline expr urem(int a, expr const & b) { return urem(b.ctx().num_val(a, b.get_sort()), b); }
2297
2301 inline expr shl(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvshl(a.ctx(), a, b)); }
2302 inline expr shl(expr const & a, int b) { return shl(a, a.ctx().num_val(b, a.get_sort())); }
2303 inline expr shl(int a, expr const & b) { return shl(b.ctx().num_val(a, b.get_sort()), b); }
2304
2308 inline expr lshr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvlshr(a.ctx(), a, b)); }
2309 inline expr lshr(expr const & a, int b) { return lshr(a, a.ctx().num_val(b, a.get_sort())); }
2310 inline expr lshr(int a, expr const & b) { return lshr(b.ctx().num_val(a, b.get_sort()), b); }
2311
2315 inline expr ashr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvashr(a.ctx(), a, b)); }
2316 inline expr ashr(expr const & a, int b) { return ashr(a, a.ctx().num_val(b, a.get_sort())); }
2317 inline expr ashr(int a, expr const & b) { return ashr(b.ctx().num_val(a, b.get_sort()), b); }
2318
2322 inline expr zext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_zero_ext(a.ctx(), i, a)); }
2323
2327 inline expr bv2int(expr const& a, bool is_signed) { Z3_ast r = Z3_mk_bv2int(a.ctx(), a, is_signed); a.check_error(); return expr(a.ctx(), r); }
2328 inline expr int2bv(unsigned n, expr const& a) { Z3_ast r = Z3_mk_int2bv(a.ctx(), n, a); a.check_error(); return expr(a.ctx(), r); }
2329
2333 inline expr bvadd_no_overflow(expr const& a, expr const& b, bool is_signed) {
2334 check_context(a, b); Z3_ast r = Z3_mk_bvadd_no_overflow(a.ctx(), a, b, is_signed); a.check_error(); return expr(a.ctx(), r);
2335 }
2336 inline expr bvadd_no_underflow(expr const& a, expr const& b) {
2337 check_context(a, b); Z3_ast r = Z3_mk_bvadd_no_underflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2338 }
2339 inline expr bvsub_no_overflow(expr const& a, expr const& b) {
2340 check_context(a, b); Z3_ast r = Z3_mk_bvsub_no_overflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2341 }
2342 inline expr bvsub_no_underflow(expr const& a, expr const& b, bool is_signed) {
2343 check_context(a, b); Z3_ast r = Z3_mk_bvsub_no_underflow(a.ctx(), a, b, is_signed); a.check_error(); return expr(a.ctx(), r);
2344 }
2345 inline expr bvsdiv_no_overflow(expr const& a, expr const& b) {
2346 check_context(a, b); Z3_ast r = Z3_mk_bvsdiv_no_overflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2347 }
2348 inline expr bvneg_no_overflow(expr const& a) {
2349 Z3_ast r = Z3_mk_bvneg_no_overflow(a.ctx(), a); a.check_error(); return expr(a.ctx(), r);
2350 }
2351 inline expr bvmul_no_overflow(expr const& a, expr const& b, bool is_signed) {
2352 check_context(a, b); Z3_ast r = Z3_mk_bvmul_no_overflow(a.ctx(), a, b, is_signed); a.check_error(); return expr(a.ctx(), r);
2353 }
2354 inline expr bvmul_no_underflow(expr const& a, expr const& b) {
2355 check_context(a, b); Z3_ast r = Z3_mk_bvmul_no_underflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2356 }
2357
2358
2362 inline expr sext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_sign_ext(a.ctx(), i, a)); }
2363
2364 inline func_decl linear_order(sort const& a, unsigned index) {
2365 return to_func_decl(a.ctx(), Z3_mk_linear_order(a.ctx(), a, index));
2366 }
2367 inline func_decl partial_order(sort const& a, unsigned index) {
2368 return to_func_decl(a.ctx(), Z3_mk_partial_order(a.ctx(), a, index));
2369 }
2370 inline func_decl piecewise_linear_order(sort const& a, unsigned index) {
2371 return to_func_decl(a.ctx(), Z3_mk_piecewise_linear_order(a.ctx(), a, index));
2372 }
2373 inline func_decl tree_order(sort const& a, unsigned index) {
2374 return to_func_decl(a.ctx(), Z3_mk_tree_order(a.ctx(), a, index));
2375 }
2376
2383 inline expr_vector polynomial_subresultants(expr const& p, expr const& q, expr const& x) {
2384 check_context(p, q); check_context(p, x);
2385 Z3_ast_vector r = Z3_polynomial_subresultants(p.ctx(), p, q, x);
2386 p.check_error();
2387 return expr_vector(p.ctx(), r);
2388 }
2389
2390 template<> class cast_ast<ast> {
2391 public:
2392 ast operator()(context & c, Z3_ast a) { return ast(c, a); }
2393 };
2394
2395 template<> class cast_ast<expr> {
2396 public:
2397 expr operator()(context & c, Z3_ast a) {
2398 assert(Z3_get_ast_kind(c, a) == Z3_NUMERAL_AST ||
2399 Z3_get_ast_kind(c, a) == Z3_APP_AST ||
2401 Z3_get_ast_kind(c, a) == Z3_VAR_AST);
2402 return expr(c, a);
2403 }
2404 };
2405
2406 template<> class cast_ast<sort> {
2407 public:
2408 sort operator()(context & c, Z3_ast a) {
2409 assert(Z3_get_ast_kind(c, a) == Z3_SORT_AST);
2410 return sort(c, reinterpret_cast<Z3_sort>(a));
2411 }
2412 };
2413
2414 template<> class cast_ast<func_decl> {
2415 public:
2416 func_decl operator()(context & c, Z3_ast a) {
2417 assert(Z3_get_ast_kind(c, a) == Z3_FUNC_DECL_AST);
2418 return func_decl(c, reinterpret_cast<Z3_func_decl>(a));
2419 }
2420 };
2421
2422 template<typename T>
2423 template<typename T2>
2424 array<T>::array(ast_vector_tpl<T2> const & v):m_array(new T[v.size()]), m_size(v.size()) {
2425 for (unsigned i = 0; i < m_size; ++i) {
2426 m_array[i] = v[i];
2427 }
2428 }
2429
2430 // Basic functions for creating quantified formulas.
2431 // The C API should be used for creating quantifiers with patterns, weights, many variables, etc.
2432 inline expr forall(expr const & x, expr const & b) {
2433 check_context(x, b);
2434 Z3_app vars[] = {(Z3_app) x};
2435 Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 1, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2436 }
2437 inline expr forall(expr const & x1, expr const & x2, expr const & b) {
2438 check_context(x1, b); check_context(x2, b);
2439 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2};
2440 Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 2, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2441 }
2442 inline expr forall(expr const & x1, expr const & x2, expr const & x3, expr const & b) {
2443 check_context(x1, b); check_context(x2, b); check_context(x3, b);
2444 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3 };
2445 Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 3, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2446 }
2447 inline expr forall(expr const & x1, expr const & x2, expr const & x3, expr const & x4, expr const & b) {
2448 check_context(x1, b); check_context(x2, b); check_context(x3, b); check_context(x4, b);
2449 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3, (Z3_app) x4 };
2450 Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 4, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2451 }
2452 inline expr forall(expr_vector const & xs, expr const & b) {
2453 array<Z3_app> vars(xs);
2454 Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, vars.size(), vars.ptr(), 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2455 }
2456 inline expr exists(expr const & x, expr const & b) {
2457 check_context(x, b);
2458 Z3_app vars[] = {(Z3_app) x};
2459 Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 1, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2460 }
2461 inline expr exists(expr const & x1, expr const & x2, expr const & b) {
2462 check_context(x1, b); check_context(x2, b);
2463 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2};
2464 Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 2, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2465 }
2466 inline expr exists(expr const & x1, expr const & x2, expr const & x3, expr const & b) {
2467 check_context(x1, b); check_context(x2, b); check_context(x3, b);
2468 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3 };
2469 Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 3, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2470 }
2471 inline expr exists(expr const & x1, expr const & x2, expr const & x3, expr const & x4, expr const & b) {
2472 check_context(x1, b); check_context(x2, b); check_context(x3, b); check_context(x4, b);
2473 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3, (Z3_app) x4 };
2474 Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 4, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2475 }
2476 inline expr exists(expr_vector const & xs, expr const & b) {
2477 array<Z3_app> vars(xs);
2478 Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, vars.size(), vars.ptr(), 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2479 }
2480 inline expr lambda(expr const & x, expr const & b) {
2481 check_context(x, b);
2482 Z3_app vars[] = {(Z3_app) x};
2483 Z3_ast r = Z3_mk_lambda_const(b.ctx(), 1, vars, b); b.check_error(); return expr(b.ctx(), r);
2484 }
2485 inline expr lambda(expr const & x1, expr const & x2, expr const & b) {
2486 check_context(x1, b); check_context(x2, b);
2487 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2};
2488 Z3_ast r = Z3_mk_lambda_const(b.ctx(), 2, vars, b); b.check_error(); return expr(b.ctx(), r);
2489 }
2490 inline expr lambda(expr const & x1, expr const & x2, expr const & x3, expr const & b) {
2491 check_context(x1, b); check_context(x2, b); check_context(x3, b);
2492 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3 };
2493 Z3_ast r = Z3_mk_lambda_const(b.ctx(), 3, vars, b); b.check_error(); return expr(b.ctx(), r);
2494 }
2495 inline expr lambda(expr const & x1, expr const & x2, expr const & x3, expr const & x4, expr const & b) {
2496 check_context(x1, b); check_context(x2, b); check_context(x3, b); check_context(x4, b);
2497 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3, (Z3_app) x4 };
2498 Z3_ast r = Z3_mk_lambda_const(b.ctx(), 4, vars, b); b.check_error(); return expr(b.ctx(), r);
2499 }
2500 inline expr lambda(expr_vector const & xs, expr const & b) {
2501 array<Z3_app> vars(xs);
2502 Z3_ast r = Z3_mk_lambda_const(b.ctx(), vars.size(), vars.ptr(), b); b.check_error(); return expr(b.ctx(), r);
2503 }
2504
2505 inline expr pble(expr_vector const& es, int const* coeffs, int bound) {
2506 assert(es.size() > 0);
2507 context& ctx = es[0u].ctx();
2508 array<Z3_ast> _es(es);
2509 Z3_ast r = Z3_mk_pble(ctx, _es.size(), _es.ptr(), coeffs, bound);
2510 ctx.check_error();
2511 return expr(ctx, r);
2512 }
2513 inline expr pbge(expr_vector const& es, int const* coeffs, int bound) {
2514 assert(es.size() > 0);
2515 context& ctx = es[0u].ctx();
2516 array<Z3_ast> _es(es);
2517 Z3_ast r = Z3_mk_pbge(ctx, _es.size(), _es.ptr(), coeffs, bound);
2518 ctx.check_error();
2519 return expr(ctx, r);
2520 }
2521 inline expr pbeq(expr_vector const& es, int const* coeffs, int bound) {
2522 assert(es.size() > 0);
2523 context& ctx = es[0u].ctx();
2524 array<Z3_ast> _es(es);
2525 Z3_ast r = Z3_mk_pbeq(ctx, _es.size(), _es.ptr(), coeffs, bound);
2526 ctx.check_error();
2527 return expr(ctx, r);
2528 }
2529 inline expr atmost(expr_vector const& es, unsigned bound) {
2530 assert(es.size() > 0);
2531 context& ctx = es[0u].ctx();
2532 array<Z3_ast> _es(es);
2533 Z3_ast r = Z3_mk_atmost(ctx, _es.size(), _es.ptr(), bound);
2534 ctx.check_error();
2535 return expr(ctx, r);
2536 }
2537 inline expr atleast(expr_vector const& es, unsigned bound) {
2538 assert(es.size() > 0);
2539 context& ctx = es[0u].ctx();
2540 array<Z3_ast> _es(es);
2541 Z3_ast r = Z3_mk_atleast(ctx, _es.size(), _es.ptr(), bound);
2542 ctx.check_error();
2543 return expr(ctx, r);
2544 }
2545 inline expr sum(expr_vector const& args) {
2546 assert(args.size() > 0);
2547 context& ctx = args[0u].ctx();
2548 array<Z3_ast> _args(args);
2549 Z3_ast r = Z3_mk_add(ctx, _args.size(), _args.ptr());
2550 ctx.check_error();
2551 return expr(ctx, r);
2552 }
2553
2554 inline expr distinct(expr_vector const& args) {
2555 assert(args.size() > 0);
2556 context& ctx = args[0u].ctx();
2557 array<Z3_ast> _args(args);
2558 Z3_ast r = Z3_mk_distinct(ctx, _args.size(), _args.ptr());
2559 ctx.check_error();
2560 return expr(ctx, r);
2561 }
2562
2563 inline expr concat(expr const& a, expr const& b) {
2564 check_context(a, b);
2565 Z3_ast r;
2566 if (Z3_is_seq_sort(a.ctx(), a.get_sort())) {
2567 Z3_ast _args[2] = { a, b };
2568 r = Z3_mk_seq_concat(a.ctx(), 2, _args);
2569 }
2570 else if (Z3_is_re_sort(a.ctx(), a.get_sort())) {
2571 Z3_ast _args[2] = { a, b };
2572 r = Z3_mk_re_concat(a.ctx(), 2, _args);
2573 }
2574 else {
2575 r = Z3_mk_concat(a.ctx(), a, b);
2576 }
2577 a.ctx().check_error();
2578 return expr(a.ctx(), r);
2579 }
2580
2581 inline expr concat(expr_vector const& args) {
2582 Z3_ast r;
2583 assert(args.size() > 0);
2584 if (args.size() == 1) {
2585 return args[0u];
2586 }
2587 context& ctx = args[0u].ctx();
2588 array<Z3_ast> _args(args);
2589 if (Z3_is_seq_sort(ctx, args[0u].get_sort())) {
2590 r = Z3_mk_seq_concat(ctx, _args.size(), _args.ptr());
2591 }
2592 else if (Z3_is_re_sort(ctx, args[0u].get_sort())) {
2593 r = Z3_mk_re_concat(ctx, _args.size(), _args.ptr());
2594 }
2595 else {
2596 r = _args[args.size()-1];
2597 for (unsigned i = args.size()-1; i > 0; ) {
2598 --i;
2599 r = Z3_mk_concat(ctx, _args[i], r);
2600 ctx.check_error();
2601 }
2602 }
2603 ctx.check_error();
2604 return expr(ctx, r);
2605 }
2606
2607 inline expr map(expr const& f, expr const& list) {
2608 context& ctx = f.ctx();
2609 Z3_ast r = Z3_mk_seq_map(ctx, f, list);
2610 ctx.check_error();
2611 return expr(ctx, r);
2612 }
2613
2614 inline expr mapi(expr const& f, expr const& i, expr const& list) {
2615 context& ctx = f.ctx();
2616 Z3_ast r = Z3_mk_seq_mapi(ctx, f, i, list);
2617 ctx.check_error();
2618 return expr(ctx, r);
2619 }
2620
2621 inline expr foldl(expr const& f, expr const& a, expr const& list) {
2622 context& ctx = f.ctx();
2623 Z3_ast r = Z3_mk_seq_foldl(ctx, f, a, list);
2624 ctx.check_error();
2625 return expr(ctx, r);
2626 }
2627
2628 inline expr foldli(expr const& f, expr const& i, expr const& a, expr const& list) {
2629 context& ctx = f.ctx();
2630 Z3_ast r = Z3_mk_seq_foldli(ctx, f, i, a, list);
2631 ctx.check_error();
2632 return expr(ctx, r);
2633 }
2634
2635 inline expr mk_or(expr_vector const& args) {
2636 array<Z3_ast> _args(args);
2637 Z3_ast r = Z3_mk_or(args.ctx(), _args.size(), _args.ptr());
2638 args.check_error();
2639 return expr(args.ctx(), r);
2640 }
2641 inline expr mk_and(expr_vector const& args) {
2642 array<Z3_ast> _args(args);
2643 Z3_ast r = Z3_mk_and(args.ctx(), _args.size(), _args.ptr());
2644 args.check_error();
2645 return expr(args.ctx(), r);
2646 }
2647 inline expr mk_xor(expr_vector const& args) {
2648 if (args.empty())
2649 return args.ctx().bool_val(false);
2650 expr r = args[0u];
2651 for (unsigned i = 1; i < args.size(); ++i)
2652 r = r ^ args[i];
2653 return r;
2654 }
2655
2656
2657 class func_entry : public object {
2658 Z3_func_entry m_entry;
2659 void init(Z3_func_entry e) {
2660 m_entry = e;
2661 Z3_func_entry_inc_ref(ctx(), m_entry);
2662 }
2663 public:
2664 func_entry(context & c, Z3_func_entry e):object(c) { init(e); }
2665 func_entry(func_entry const & s):object(s) { init(s.m_entry); }
2666 ~func_entry() override { Z3_func_entry_dec_ref(ctx(), m_entry); }
2667 operator Z3_func_entry() const { return m_entry; }
2668 func_entry & operator=(func_entry const & s) {
2669 Z3_func_entry_inc_ref(s.ctx(), s.m_entry);
2670 Z3_func_entry_dec_ref(ctx(), m_entry);
2671 object::operator=(s);
2672 m_entry = s.m_entry;
2673 return *this;
2674 }
2675 expr value() const { Z3_ast r = Z3_func_entry_get_value(ctx(), m_entry); check_error(); return expr(ctx(), r); }
2676 unsigned num_args() const { unsigned r = Z3_func_entry_get_num_args(ctx(), m_entry); check_error(); return r; }
2677 expr arg(unsigned i) const { Z3_ast r = Z3_func_entry_get_arg(ctx(), m_entry, i); check_error(); return expr(ctx(), r); }
2678 };
2679
2680 class func_interp : public object {
2681 Z3_func_interp m_interp;
2682 void init(Z3_func_interp e) {
2683 m_interp = e;
2684 Z3_func_interp_inc_ref(ctx(), m_interp);
2685 }
2686 public:
2687 func_interp(context & c, Z3_func_interp e):object(c) { init(e); }
2688 func_interp(func_interp const & s):object(s) { init(s.m_interp); }
2689 ~func_interp() override { Z3_func_interp_dec_ref(ctx(), m_interp); }
2690 operator Z3_func_interp() const { return m_interp; }
2691 func_interp & operator=(func_interp const & s) {
2692 Z3_func_interp_inc_ref(s.ctx(), s.m_interp);
2693 Z3_func_interp_dec_ref(ctx(), m_interp);
2694 object::operator=(s);
2695 m_interp = s.m_interp;
2696 return *this;
2697 }
2698 expr else_value() const { Z3_ast r = Z3_func_interp_get_else(ctx(), m_interp); check_error(); return expr(ctx(), r); }
2699 unsigned num_entries() const { unsigned r = Z3_func_interp_get_num_entries(ctx(), m_interp); check_error(); return r; }
2700 func_entry entry(unsigned i) const { Z3_func_entry e = Z3_func_interp_get_entry(ctx(), m_interp, i); check_error(); return func_entry(ctx(), e); }
2701 void add_entry(expr_vector const& args, expr& value) {
2702 Z3_func_interp_add_entry(ctx(), m_interp, args, value);
2703 check_error();
2704 }
2705 void set_else(expr& value) {
2706 Z3_func_interp_set_else(ctx(), m_interp, value);
2707 check_error();
2708 }
2709 };
2710
2711 class model : public object {
2712 Z3_model m_model;
2713 void init(Z3_model m) {
2714 m_model = m;
2715 Z3_model_inc_ref(ctx(), m);
2716 }
2717 public:
2718 struct translate {};
2719 model(context & c):object(c) { init(Z3_mk_model(c)); }
2720 model(context & c, Z3_model m):object(c) { init(m); }
2721 model(model const & s):object(s) { init(s.m_model); }
2722 model(model& src, context& dst, translate) : object(dst) { init(Z3_model_translate(src.ctx(), src, dst)); }
2723 ~model() override { Z3_model_dec_ref(ctx(), m_model); }
2724 operator Z3_model() const { return m_model; }
2725 model & operator=(model const & s) {
2726 Z3_model_inc_ref(s.ctx(), s.m_model);
2727 Z3_model_dec_ref(ctx(), m_model);
2728 object::operator=(s);
2729 m_model = s.m_model;
2730 return *this;
2731 }
2732
2733 expr eval(expr const & n, bool model_completion=false) const {
2734 check_context(*this, n);
2735 Z3_ast r = 0;
2736 bool status = Z3_model_eval(ctx(), m_model, n, model_completion, &r);
2737 check_error();
2738 if (status == false && ctx().enable_exceptions())
2739 Z3_THROW(exception("failed to evaluate expression"));
2740 return expr(ctx(), r);
2741 }
2742
2743 unsigned num_consts() const { return Z3_model_get_num_consts(ctx(), m_model); }
2744 unsigned num_funcs() const { return Z3_model_get_num_funcs(ctx(), m_model); }
2745 func_decl get_const_decl(unsigned i) const { Z3_func_decl r = Z3_model_get_const_decl(ctx(), m_model, i); check_error(); return func_decl(ctx(), r); }
2746 func_decl get_func_decl(unsigned i) const { Z3_func_decl r = Z3_model_get_func_decl(ctx(), m_model, i); check_error(); return func_decl(ctx(), r); }
2747 unsigned size() const { return num_consts() + num_funcs(); }
2748 func_decl operator[](int i) const {
2749 assert(0 <= i);
2750 return static_cast<unsigned>(i) < num_consts() ? get_const_decl(i) : get_func_decl(i - num_consts());
2751 }
2752
2753 // returns interpretation of constant declaration c.
2754 // If c is not assigned any value in the model it returns
2755 // an expression with a null ast reference.
2756 expr get_const_interp(func_decl c) const {
2757 check_context(*this, c);
2758 Z3_ast r = Z3_model_get_const_interp(ctx(), m_model, c);
2759 check_error();
2760 return expr(ctx(), r);
2761 }
2762 func_interp get_func_interp(func_decl f) const {
2763 check_context(*this, f);
2764 Z3_func_interp r = Z3_model_get_func_interp(ctx(), m_model, f);
2765 check_error();
2766 return func_interp(ctx(), r);
2767 }
2768
2769 // returns true iff the model contains an interpretation
2770 // for function f.
2771 bool has_interp(func_decl f) const {
2772 check_context(*this, f);
2773 return Z3_model_has_interp(ctx(), m_model, f);
2774 }
2775
2776 func_interp add_func_interp(func_decl& f, expr& else_val) {
2777 Z3_func_interp r = Z3_add_func_interp(ctx(), m_model, f, else_val);
2778 check_error();
2779 return func_interp(ctx(), r);
2780 }
2781
2782 void add_const_interp(func_decl& f, expr& value) {
2783 Z3_add_const_interp(ctx(), m_model, f, value);
2784 check_error();
2785 }
2786
2787 unsigned num_sorts() const {
2788 unsigned r = Z3_model_get_num_sorts(ctx(), m_model);
2789 check_error();
2790 return r;
2791 }
2792
2797 sort get_sort(unsigned i) const {
2798 Z3_sort s = Z3_model_get_sort(ctx(), m_model, i);
2799 check_error();
2800 return sort(ctx(), s);
2801 }
2802
2803 expr_vector sort_universe(sort const& s) const {
2804 check_context(*this, s);
2805 Z3_ast_vector r = Z3_model_get_sort_universe(ctx(), m_model, s);
2806 check_error();
2807 return expr_vector(ctx(), r);
2808 }
2809
2810 friend std::ostream & operator<<(std::ostream & out, model const & m);
2811
2812 std::string to_string() const { return m_model ? std::string(Z3_model_to_string(ctx(), m_model)) : "null"; }
2813 };
2814 inline std::ostream & operator<<(std::ostream & out, model const & m) { return out << m.to_string(); }
2815
2816 class stats : public object {
2817 Z3_stats m_stats;
2818 void init(Z3_stats e) {
2819 m_stats = e;
2820 Z3_stats_inc_ref(ctx(), m_stats);
2821 }
2822 public:
2823 stats(context & c):object(c), m_stats(0) {}
2824 stats(context & c, Z3_stats e):object(c) { init(e); }
2825 stats(stats const & s):object(s) { init(s.m_stats); }
2826 ~stats() override { if (m_stats) Z3_stats_dec_ref(ctx(), m_stats); }
2827 operator Z3_stats() const { return m_stats; }
2828 stats & operator=(stats const & s) {
2829 Z3_stats_inc_ref(s.ctx(), s.m_stats);
2830 if (m_stats) Z3_stats_dec_ref(ctx(), m_stats);
2831 object::operator=(s);
2832 m_stats = s.m_stats;
2833 return *this;
2834 }
2835 unsigned size() const { return Z3_stats_size(ctx(), m_stats); }
2836 std::string key(unsigned i) const { Z3_string s = Z3_stats_get_key(ctx(), m_stats, i); check_error(); return s; }
2837 bool is_uint(unsigned i) const { bool r = Z3_stats_is_uint(ctx(), m_stats, i); check_error(); return r; }
2838 bool is_double(unsigned i) const { bool r = Z3_stats_is_double(ctx(), m_stats, i); check_error(); return r; }
2839 unsigned uint_value(unsigned i) const { unsigned r = Z3_stats_get_uint_value(ctx(), m_stats, i); check_error(); return r; }
2840 double double_value(unsigned i) const { double r = Z3_stats_get_double_value(ctx(), m_stats, i); check_error(); return r; }
2841 friend std::ostream & operator<<(std::ostream & out, stats const & s);
2842 };
2843 inline std::ostream & operator<<(std::ostream & out, stats const & s) { out << Z3_stats_to_string(s.ctx(), s); return out; }
2844
2845
2846 inline std::ostream & operator<<(std::ostream & out, check_result r) {
2847 if (r == unsat) out << "unsat";
2848 else if (r == sat) out << "sat";
2849 else out << "unknown";
2850 return out;
2851 }
2852
2863 class parameter {
2864 Z3_parameter_kind m_kind;
2865 func_decl m_decl;
2866 unsigned m_index;
2867 context& ctx() const { return m_decl.ctx(); }
2868 void check_error() const { ctx().check_error(); }
2869 public:
2870 parameter(func_decl const& d, unsigned idx) : m_decl(d), m_index(idx) {
2871 if (ctx().enable_exceptions() && idx >= d.num_parameters())
2872 Z3_THROW(exception("parameter index is out of bounds"));
2873 m_kind = Z3_get_decl_parameter_kind(ctx(), d, idx);
2874 }
2875 parameter(expr const& e, unsigned idx) : m_decl(e.decl()), m_index(idx) {
2876 if (ctx().enable_exceptions() && idx >= m_decl.num_parameters())
2877 Z3_THROW(exception("parameter index is out of bounds"));
2878 m_kind = Z3_get_decl_parameter_kind(ctx(), m_decl, idx);
2879 }
2880 Z3_parameter_kind kind() const { return m_kind; }
2881 expr get_expr() const { Z3_ast a = Z3_get_decl_ast_parameter(ctx(), m_decl, m_index); check_error(); return expr(ctx(), a); }
2882 sort get_sort() const { Z3_sort s = Z3_get_decl_sort_parameter(ctx(), m_decl, m_index); check_error(); return sort(ctx(), s); }
2883 func_decl get_decl() const { Z3_func_decl f = Z3_get_decl_func_decl_parameter(ctx(), m_decl, m_index); check_error(); return func_decl(ctx(), f); }
2884 symbol get_symbol() const { Z3_symbol s = Z3_get_decl_symbol_parameter(ctx(), m_decl, m_index); check_error(); return symbol(ctx(), s); }
2885 std::string get_rational() const { Z3_string s = Z3_get_decl_rational_parameter(ctx(), m_decl, m_index); check_error(); return s; }
2886 double get_double() const { double d = Z3_get_decl_double_parameter(ctx(), m_decl, m_index); check_error(); return d; }
2887 int get_int() const { int i = Z3_get_decl_int_parameter(ctx(), m_decl, m_index); check_error(); return i; }
2888 };
2889
2890
2891 class solver : public object {
2892 Z3_solver m_solver;
2893 void init(Z3_solver s) {
2894 m_solver = s;
2895 if (s)
2896 Z3_solver_inc_ref(ctx(), s);
2897 }
2898 public:
2899 struct simple {};
2900 struct translate {};
2901 solver(context & c):object(c) { init(Z3_mk_solver(c)); check_error(); }
2902 solver(context & c, simple):object(c) { init(Z3_mk_simple_solver(c)); check_error(); }
2903 solver(context & c, Z3_solver s):object(c) { init(s); }
2904 solver(context & c, char const * logic):object(c) { init(Z3_mk_solver_for_logic(c, c.str_symbol(logic))); check_error(); }
2905 solver(context & c, solver const& src, translate): object(c) { Z3_solver s = Z3_solver_translate(src.ctx(), src, c); check_error(); init(s); }
2906 solver(solver const & s):object(s) { init(s.m_solver); }
2907 solver(solver const& s, simplifier const& simp);
2908 ~solver() override { Z3_solver_dec_ref(ctx(), m_solver); }
2909 operator Z3_solver() const { return m_solver; }
2910 solver & operator=(solver const & s) {
2911 Z3_solver_inc_ref(s.ctx(), s.m_solver);
2912 Z3_solver_dec_ref(ctx(), m_solver);
2913 object::operator=(s);
2914 m_solver = s.m_solver;
2915 return *this;
2916 }
2917 void set(params const & p) { Z3_solver_set_params(ctx(), m_solver, p); check_error(); }
2918 void set(char const * k, bool v) { params p(ctx()); p.set(k, v); set(p); }
2919 void set(char const * k, unsigned v) { params p(ctx()); p.set(k, v); set(p); }
2920 void set(char const * k, double v) { params p(ctx()); p.set(k, v); set(p); }
2921 void set(char const * k, symbol const & v) { params p(ctx()); p.set(k, v); set(p); }
2922 void set(char const * k, char const* v) { params p(ctx()); p.set(k, v); set(p); }
2933 void push() { Z3_solver_push(ctx(), m_solver); check_error(); }
2934 void pop(unsigned n = 1) { Z3_solver_pop(ctx(), m_solver, n); check_error(); }
2935 void reset() { Z3_solver_reset(ctx(), m_solver); check_error(); }
2936 void add(expr const & e) { assert(e.is_bool()); Z3_solver_assert(ctx(), m_solver, e); check_error(); }
2937 void add(expr const & e, expr const & p) {
2938 assert(e.is_bool()); assert(p.is_bool()); assert(p.is_const());
2939 Z3_solver_assert_and_track(ctx(), m_solver, e, p);
2940 check_error();
2941 }
2942 void add(expr const & e, char const * p) {
2943 add(e, ctx().bool_const(p));
2944 }
2945 void add(expr_vector const& v) {
2946 check_context(*this, v);
2947 for (unsigned i = 0; i < v.size(); ++i)
2948 add(v[i]);
2949 }
2950 void from_file(char const* file) { Z3_solver_from_file(ctx(), m_solver, file); ctx().check_parser_error(); }
2951 void from_string(char const* s) { Z3_solver_from_string(ctx(), m_solver, s); ctx().check_parser_error(); }
2952
2953 check_result check() { Z3_lbool r = Z3_solver_check(ctx(), m_solver); check_error(); return to_check_result(r); }
2954 check_result check(unsigned n, expr * const assumptions) {
2955 array<Z3_ast> _assumptions(n);
2956 for (unsigned i = 0; i < n; ++i) {
2957 check_context(*this, assumptions[i]);
2958 _assumptions[i] = assumptions[i];
2959 }
2960 Z3_lbool r = Z3_solver_check_assumptions(ctx(), m_solver, n, _assumptions.ptr());
2961 check_error();
2962 return to_check_result(r);
2963 }
2964 check_result check(expr_vector const& assumptions) {
2965 unsigned n = assumptions.size();
2966 array<Z3_ast> _assumptions(n);
2967 for (unsigned i = 0; i < n; ++i) {
2968 check_context(*this, assumptions[i]);
2969 _assumptions[i] = assumptions[i];
2970 }
2971 Z3_lbool r = Z3_solver_check_assumptions(ctx(), m_solver, n, _assumptions.ptr());
2972 check_error();
2973 return to_check_result(r);
2974 }
2975 model get_model() const { Z3_model m = Z3_solver_get_model(ctx(), m_solver); check_error(); return model(ctx(), m); }
2976 check_result consequences(expr_vector& assumptions, expr_vector& vars, expr_vector& conseq) {
2977 Z3_lbool r = Z3_solver_get_consequences(ctx(), m_solver, assumptions, vars, conseq);
2978 check_error();
2979 return to_check_result(r);
2980 }
2981 std::string reason_unknown() const { Z3_string r = Z3_solver_get_reason_unknown(ctx(), m_solver); check_error(); return r; }
2982 stats statistics() const { Z3_stats r = Z3_solver_get_statistics(ctx(), m_solver); check_error(); return stats(ctx(), r); }
2983 expr_vector unsat_core() const { Z3_ast_vector r = Z3_solver_get_unsat_core(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2984 expr_vector assertions() const { Z3_ast_vector r = Z3_solver_get_assertions(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2985 expr_vector non_units() const { Z3_ast_vector r = Z3_solver_get_non_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2986 expr_vector units() const { Z3_ast_vector r = Z3_solver_get_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2987 expr_vector trail() const { Z3_ast_vector r = Z3_solver_get_trail(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2988 expr_vector trail(array<unsigned>& levels) const {
2989 Z3_ast_vector r = Z3_solver_get_trail(ctx(), m_solver);
2990 check_error();
2991 expr_vector result(ctx(), r);
2992 unsigned sz = result.size();
2993 levels.resize(sz);
2994 Z3_solver_get_levels(ctx(), m_solver, r, sz, levels.ptr());
2995 check_error();
2996 return result;
2997 }
2998 expr congruence_root(expr const& t) const {
2999 check_context(*this, t);
3000 Z3_ast r = Z3_solver_congruence_root(ctx(), m_solver, t);
3001 check_error();
3002 return expr(ctx(), r);
3003 }
3004 expr congruence_next(expr const& t) const {
3005 check_context(*this, t);
3006 Z3_ast r = Z3_solver_congruence_next(ctx(), m_solver, t);
3007 check_error();
3008 return expr(ctx(), r);
3009 }
3010 expr congruence_explain(expr const& a, expr const& b) const {
3011 check_context(*this, a);
3012 check_context(*this, b);
3013 Z3_ast r = Z3_solver_congruence_explain(ctx(), m_solver, a, b);
3014 check_error();
3015 return expr(ctx(), r);
3016 }
3017 void set_initial_value(expr const& var, expr const& value) {
3018 Z3_solver_set_initial_value(ctx(), m_solver, var, value);
3019 check_error();
3020 }
3021 void set_initial_value(expr const& var, int i) {
3022 set_initial_value(var, ctx().num_val(i, var.get_sort()));
3023 }
3024 void set_initial_value(expr const& var, bool b) {
3025 set_initial_value(var, ctx().bool_val(b));
3026 }
3027
3028 void solve_for(expr_vector const& vars, expr_vector& terms, expr_vector& guards) {
3029 // Create a copy of vars since the C API modifies the variables vector
3030 expr_vector variables(ctx());
3031 for (unsigned i = 0; i < vars.size(); ++i) {
3032 check_context(*this, vars[i]);
3033 variables.push_back(vars[i]);
3034 }
3035 // Clear output vectors before calling C API
3036 terms = expr_vector(ctx());
3037 guards = expr_vector(ctx());
3038 Z3_solver_solve_for(ctx(), m_solver, variables, terms, guards);
3039 check_error();
3040 }
3041
3042 void import_model_converter(solver const& src) {
3043 check_context(*this, src);
3044 Z3_solver_import_model_converter(ctx(), src.m_solver, m_solver);
3045 check_error();
3046 }
3047
3048 expr proof() const { Z3_ast r = Z3_solver_get_proof(ctx(), m_solver); check_error(); return expr(ctx(), r); }
3049 friend std::ostream & operator<<(std::ostream & out, solver const & s);
3050
3051 std::string to_smt2(char const* status = "unknown") {
3052 array<Z3_ast> es(assertions());
3053 Z3_ast const* fmls = es.ptr();
3054 Z3_ast fml = 0;
3055 unsigned sz = es.size();
3056 if (sz > 0) {
3057 --sz;
3058 fml = fmls[sz];
3059 }
3060 else {
3061 fml = ctx().bool_val(true);
3062 }
3063 return std::string(Z3_benchmark_to_smtlib_string(
3064 ctx(),
3065 "", "", status, "",
3066 sz,
3067 fmls,
3068 fml));
3069 }
3070
3071 std::string dimacs(bool include_names = true) const { return std::string(Z3_solver_to_dimacs_string(ctx(), m_solver, include_names)); }
3072
3073 param_descrs get_param_descrs() { return param_descrs(ctx(), Z3_solver_get_param_descrs(ctx(), m_solver)); }
3074
3075
3076 expr_vector cube(expr_vector& vars, unsigned cutoff) {
3077 Z3_ast_vector r = Z3_solver_cube(ctx(), m_solver, vars, cutoff);
3078 check_error();
3079 return expr_vector(ctx(), r);
3080 }
3081
3082 class cube_iterator {
3083 solver& m_solver;
3084 unsigned& m_cutoff;
3085 expr_vector& m_vars;
3086 expr_vector m_cube;
3087 bool m_end;
3088 bool m_empty;
3089
3090 void inc() {
3091 assert(!m_end && !m_empty);
3092 m_cube = m_solver.cube(m_vars, m_cutoff);
3093 m_cutoff = 0xFFFFFFFF;
3094 if (m_cube.size() == 1 && m_cube[0u].is_false()) {
3095 m_cube = z3::expr_vector(m_solver.ctx());
3096 m_end = true;
3097 }
3098 else if (m_cube.empty()) {
3099 m_empty = true;
3100 }
3101 }
3102 public:
3103 cube_iterator(solver& s, expr_vector& vars, unsigned& cutoff, bool end):
3104 m_solver(s),
3105 m_cutoff(cutoff),
3106 m_vars(vars),
3107 m_cube(s.ctx()),
3108 m_end(end),
3109 m_empty(false) {
3110 if (!m_end) {
3111 inc();
3112 }
3113 }
3114
3115 cube_iterator& operator++() {
3116 assert(!m_end);
3117 if (m_empty) {
3118 m_end = true;
3119 }
3120 else {
3121 inc();
3122 }
3123 return *this;
3124 }
3125 cube_iterator operator++(int) { assert(false); return *this; }
3126 expr_vector const * operator->() const { return &(operator*()); }
3127 expr_vector const& operator*() const noexcept { return m_cube; }
3128
3129 bool operator==(cube_iterator const& other) const noexcept {
3130 return other.m_end == m_end;
3131 };
3132 bool operator!=(cube_iterator const& other) const noexcept {
3133 return other.m_end != m_end;
3134 };
3135
3136 };
3137
3138 class cube_generator {
3139 solver& m_solver;
3140 unsigned m_cutoff;
3141 expr_vector m_default_vars;
3142 expr_vector& m_vars;
3143 public:
3144 cube_generator(solver& s):
3145 m_solver(s),
3146 m_cutoff(0xFFFFFFFF),
3147 m_default_vars(s.ctx()),
3148 m_vars(m_default_vars)
3149 {}
3150
3151 cube_generator(solver& s, expr_vector& vars):
3152 m_solver(s),
3153 m_cutoff(0xFFFFFFFF),
3154 m_default_vars(s.ctx()),
3155 m_vars(vars)
3156 {}
3157
3158 cube_iterator begin() { return cube_iterator(m_solver, m_vars, m_cutoff, false); }
3159 cube_iterator end() { return cube_iterator(m_solver, m_vars, m_cutoff, true); }
3160 void set_cutoff(unsigned c) noexcept { m_cutoff = c; }
3161 };
3162
3163 cube_generator cubes() { return cube_generator(*this); }
3164 cube_generator cubes(expr_vector& vars) { return cube_generator(*this, vars); }
3165
3166 };
3167 inline std::ostream & operator<<(std::ostream & out, solver const & s) { out << Z3_solver_to_string(s.ctx(), s); return out; }
3168
3169 class goal : public object {
3170 Z3_goal m_goal;
3171 void init(Z3_goal s) {
3172 m_goal = s;
3173 Z3_goal_inc_ref(ctx(), s);
3174 }
3175 public:
3176 goal(context & c, bool models=true, bool unsat_cores=false, bool proofs=false):object(c) { init(Z3_mk_goal(c, models, unsat_cores, proofs)); }
3177 goal(context & c, Z3_goal s):object(c) { init(s); }
3178 goal(goal const & s):object(s) { init(s.m_goal); }
3179 ~goal() override { Z3_goal_dec_ref(ctx(), m_goal); }
3180 operator Z3_goal() const { return m_goal; }
3181 goal & operator=(goal const & s) {
3182 Z3_goal_inc_ref(s.ctx(), s.m_goal);
3183 Z3_goal_dec_ref(ctx(), m_goal);
3184 object::operator=(s);
3185 m_goal = s.m_goal;
3186 return *this;
3187 }
3188 void add(expr const & f) { check_context(*this, f); Z3_goal_assert(ctx(), m_goal, f); check_error(); }
3189 void add(expr_vector const& v) { check_context(*this, v); for (unsigned i = 0; i < v.size(); ++i) add(v[i]); }
3190 unsigned size() const { return Z3_goal_size(ctx(), m_goal); }
3191 expr operator[](int i) const { assert(0 <= i); Z3_ast r = Z3_goal_formula(ctx(), m_goal, i); check_error(); return expr(ctx(), r); }
3192 Z3_goal_prec precision() const { return Z3_goal_precision(ctx(), m_goal); }
3193 bool inconsistent() const { return Z3_goal_inconsistent(ctx(), m_goal); }
3194 unsigned depth() const { return Z3_goal_depth(ctx(), m_goal); }
3195 void reset() { Z3_goal_reset(ctx(), m_goal); }
3196 unsigned num_exprs() const { return Z3_goal_num_exprs(ctx(), m_goal); }
3197 bool is_decided_sat() const { return Z3_goal_is_decided_sat(ctx(), m_goal); }
3198 bool is_decided_unsat() const { return Z3_goal_is_decided_unsat(ctx(), m_goal); }
3199 model convert_model(model const & m) const {
3200 check_context(*this, m);
3201 Z3_model new_m = Z3_goal_convert_model(ctx(), m_goal, m);
3202 check_error();
3203 return model(ctx(), new_m);
3204 }
3205 model get_model() const {
3206 Z3_model new_m = Z3_goal_convert_model(ctx(), m_goal, 0);
3207 check_error();
3208 return model(ctx(), new_m);
3209 }
3210 expr as_expr() const {
3211 unsigned n = size();
3212 if (n == 0)
3213 return ctx().bool_val(true);
3214 else if (n == 1)
3215 return operator[](0u);
3216 else {
3217 array<Z3_ast> args(n);
3218 for (unsigned i = 0; i < n; ++i)
3219 args[i] = operator[](i);
3220 return expr(ctx(), Z3_mk_and(ctx(), n, args.ptr()));
3221 }
3222 }
3223 std::string dimacs(bool include_names = true) const { return std::string(Z3_goal_to_dimacs_string(ctx(), m_goal, include_names)); }
3224 friend std::ostream & operator<<(std::ostream & out, goal const & g);
3225 };
3226 inline std::ostream & operator<<(std::ostream & out, goal const & g) { out << Z3_goal_to_string(g.ctx(), g); return out; }
3227
3228 class apply_result : public object {
3229 Z3_apply_result m_apply_result;
3230 void init(Z3_apply_result s) {
3231 m_apply_result = s;
3232 Z3_apply_result_inc_ref(ctx(), s);
3233 }
3234 public:
3235 apply_result(context & c, Z3_apply_result s):object(c) { init(s); }
3236 apply_result(apply_result const & s):object(s) { init(s.m_apply_result); }
3237 ~apply_result() override { Z3_apply_result_dec_ref(ctx(), m_apply_result); }
3238 operator Z3_apply_result() const { return m_apply_result; }
3239 apply_result & operator=(apply_result const & s) {
3240 Z3_apply_result_inc_ref(s.ctx(), s.m_apply_result);
3241 Z3_apply_result_dec_ref(ctx(), m_apply_result);
3242 object::operator=(s);
3243 m_apply_result = s.m_apply_result;
3244 return *this;
3245 }
3246 unsigned size() const { return Z3_apply_result_get_num_subgoals(ctx(), m_apply_result); }
3247 goal operator[](int i) const { assert(0 <= i); Z3_goal r = Z3_apply_result_get_subgoal(ctx(), m_apply_result, i); check_error(); return goal(ctx(), r); }
3248 friend std::ostream & operator<<(std::ostream & out, apply_result const & r);
3249 };
3250 inline std::ostream & operator<<(std::ostream & out, apply_result const & r) { out << Z3_apply_result_to_string(r.ctx(), r); return out; }
3251
3252 class tactic : public object {
3253 Z3_tactic m_tactic;
3254 void init(Z3_tactic s) {
3255 m_tactic = s;
3256 Z3_tactic_inc_ref(ctx(), s);
3257 }
3258 public:
3259 tactic(context & c, char const * name):object(c) { Z3_tactic r = Z3_mk_tactic(c, name); check_error(); init(r); }
3260 tactic(context & c, Z3_tactic s):object(c) { init(s); }
3261 tactic(tactic const & s):object(s) { init(s.m_tactic); }
3262 ~tactic() override { Z3_tactic_dec_ref(ctx(), m_tactic); }
3263 operator Z3_tactic() const { return m_tactic; }
3264 tactic & operator=(tactic const & s) {
3265 Z3_tactic_inc_ref(s.ctx(), s.m_tactic);
3266 Z3_tactic_dec_ref(ctx(), m_tactic);
3267 object::operator=(s);
3268 m_tactic = s.m_tactic;
3269 return *this;
3270 }
3271 solver mk_solver() const { Z3_solver r = Z3_mk_solver_from_tactic(ctx(), m_tactic); check_error(); return solver(ctx(), r); }
3272 apply_result apply(goal const & g) const {
3273 check_context(*this, g);
3274 Z3_apply_result r = Z3_tactic_apply(ctx(), m_tactic, g);
3275 check_error();
3276 return apply_result(ctx(), r);
3277 }
3278 apply_result operator()(goal const & g) const {
3279 return apply(g);
3280 }
3281 std::string help() const { char const * r = Z3_tactic_get_help(ctx(), m_tactic); check_error(); return r; }
3282 friend tactic operator&(tactic const & t1, tactic const & t2);
3283 friend tactic operator|(tactic const & t1, tactic const & t2);
3284 friend tactic repeat(tactic const & t, unsigned max);
3285 friend tactic with(tactic const & t, params const & p);
3286 friend tactic try_for(tactic const & t, unsigned ms);
3287 friend tactic par_or(unsigned n, tactic const* tactics);
3288 friend tactic par_and_then(tactic const& t1, tactic const& t2);
3289 param_descrs get_param_descrs() { return param_descrs(ctx(), Z3_tactic_get_param_descrs(ctx(), m_tactic)); }
3290 };
3291
3292 inline tactic operator&(tactic const & t1, tactic const & t2) {
3293 check_context(t1, t2);
3294 Z3_tactic r = Z3_tactic_and_then(t1.ctx(), t1, t2);
3295 t1.check_error();
3296 return tactic(t1.ctx(), r);
3297 }
3298
3299 inline tactic operator|(tactic const & t1, tactic const & t2) {
3300 check_context(t1, t2);
3301 Z3_tactic r = Z3_tactic_or_else(t1.ctx(), t1, t2);
3302 t1.check_error();
3303 return tactic(t1.ctx(), r);
3304 }
3305
3306 inline tactic repeat(tactic const & t, unsigned max=UINT_MAX) {
3307 Z3_tactic r = Z3_tactic_repeat(t.ctx(), t, max);
3308 t.check_error();
3309 return tactic(t.ctx(), r);
3310 }
3311
3312 inline tactic with(tactic const & t, params const & p) {
3313 Z3_tactic r = Z3_tactic_using_params(t.ctx(), t, p);
3314 t.check_error();
3315 return tactic(t.ctx(), r);
3316 }
3317 inline tactic try_for(tactic const & t, unsigned ms) {
3318 Z3_tactic r = Z3_tactic_try_for(t.ctx(), t, ms);
3319 t.check_error();
3320 return tactic(t.ctx(), r);
3321 }
3322 inline tactic par_or(unsigned n, tactic const* tactics) {
3323 if (n == 0) {
3324 Z3_THROW(exception("a non-zero number of tactics need to be passed to par_or"));
3325 }
3326 array<Z3_tactic> buffer(n);
3327 for (unsigned i = 0; i < n; ++i) buffer[i] = tactics[i];
3328 return tactic(tactics[0u].ctx(), Z3_tactic_par_or(tactics[0u].ctx(), n, buffer.ptr()));
3329 }
3330
3331 inline tactic par_and_then(tactic const & t1, tactic const & t2) {
3332 check_context(t1, t2);
3333 Z3_tactic r = Z3_tactic_par_and_then(t1.ctx(), t1, t2);
3334 t1.check_error();
3335 return tactic(t1.ctx(), r);
3336 }
3337
3338 class simplifier : public object {
3339 Z3_simplifier m_simplifier;
3340 void init(Z3_simplifier s) {
3341 m_simplifier = s;
3342 Z3_simplifier_inc_ref(ctx(), s);
3343 }
3344 public:
3345 simplifier(context & c, char const * name):object(c) { Z3_simplifier r = Z3_mk_simplifier(c, name); check_error(); init(r); }
3346 simplifier(context & c, Z3_simplifier s):object(c) { init(s); }
3347 simplifier(simplifier const & s):object(s) { init(s.m_simplifier); }
3348 ~simplifier() override { Z3_simplifier_dec_ref(ctx(), m_simplifier); }
3349 operator Z3_simplifier() const { return m_simplifier; }
3350 simplifier & operator=(simplifier const & s) {
3351 Z3_simplifier_inc_ref(s.ctx(), s.m_simplifier);
3352 Z3_simplifier_dec_ref(ctx(), m_simplifier);
3353 object::operator=(s);
3354 m_simplifier = s.m_simplifier;
3355 return *this;
3356 }
3357 std::string help() const { char const * r = Z3_simplifier_get_help(ctx(), m_simplifier); check_error(); return r; }
3358 friend simplifier operator&(simplifier const & t1, simplifier const & t2);
3359 friend simplifier with(simplifier const & t, params const & p);
3360 param_descrs get_param_descrs() { return param_descrs(ctx(), Z3_simplifier_get_param_descrs(ctx(), m_simplifier)); }
3361 };
3362
3363 inline solver::solver(solver const& s, simplifier const& simp):object(s) { init(Z3_solver_add_simplifier(s.ctx(), s, simp)); }
3364
3365
3366 inline simplifier operator&(simplifier const & t1, simplifier const & t2) {
3367 check_context(t1, t2);
3368 Z3_simplifier r = Z3_simplifier_and_then(t1.ctx(), t1, t2);
3369 t1.check_error();
3370 return simplifier(t1.ctx(), r);
3371 }
3372
3373 inline simplifier with(simplifier const & t, params const & p) {
3374 Z3_simplifier r = Z3_simplifier_using_params(t.ctx(), t, p);
3375 t.check_error();
3376 return simplifier(t.ctx(), r);
3377 }
3378
3379 class probe : public object {
3380 Z3_probe m_probe;
3381 void init(Z3_probe s) {
3382 m_probe = s;
3383 Z3_probe_inc_ref(ctx(), s);
3384 }
3385 public:
3386 probe(context & c, char const * name):object(c) { Z3_probe r = Z3_mk_probe(c, name); check_error(); init(r); }
3387 probe(context & c, double val):object(c) { Z3_probe r = Z3_probe_const(c, val); check_error(); init(r); }
3388 probe(context & c, Z3_probe s):object(c) { init(s); }
3389 probe(probe const & s):object(s) { init(s.m_probe); }
3390 ~probe() override { Z3_probe_dec_ref(ctx(), m_probe); }
3391 operator Z3_probe() const { return m_probe; }
3392 probe & operator=(probe const & s) {
3393 Z3_probe_inc_ref(s.ctx(), s.m_probe);
3394 Z3_probe_dec_ref(ctx(), m_probe);
3395 object::operator=(s);
3396 m_probe = s.m_probe;
3397 return *this;
3398 }
3399 double apply(goal const & g) const { double r = Z3_probe_apply(ctx(), m_probe, g); check_error(); return r; }
3400 double operator()(goal const & g) const { return apply(g); }
3401 friend probe operator<=(probe const & p1, probe const & p2);
3402 friend probe operator<=(probe const & p1, double p2);
3403 friend probe operator<=(double p1, probe const & p2);
3404 friend probe operator>=(probe const & p1, probe const & p2);
3405 friend probe operator>=(probe const & p1, double p2);
3406 friend probe operator>=(double p1, probe const & p2);
3407 friend probe operator<(probe const & p1, probe const & p2);
3408 friend probe operator<(probe const & p1, double p2);
3409 friend probe operator<(double p1, probe const & p2);
3410 friend probe operator>(probe const & p1, probe const & p2);
3411 friend probe operator>(probe const & p1, double p2);
3412 friend probe operator>(double p1, probe const & p2);
3413 friend probe operator==(probe const & p1, probe const & p2);
3414 friend probe operator==(probe const & p1, double p2);
3415 friend probe operator==(double p1, probe const & p2);
3416 friend probe operator&&(probe const & p1, probe const & p2);
3417 friend probe operator||(probe const & p1, probe const & p2);
3418 friend probe operator!(probe const & p);
3419 };
3420
3421 inline probe operator<=(probe const & p1, probe const & p2) {
3422 check_context(p1, p2); Z3_probe r = Z3_probe_le(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3423 }
3424 inline probe operator<=(probe const & p1, double p2) { return p1 <= probe(p1.ctx(), p2); }
3425 inline probe operator<=(double p1, probe const & p2) { return probe(p2.ctx(), p1) <= p2; }
3426 inline probe operator>=(probe const & p1, probe const & p2) {
3427 check_context(p1, p2); Z3_probe r = Z3_probe_ge(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3428 }
3429 inline probe operator>=(probe const & p1, double p2) { return p1 >= probe(p1.ctx(), p2); }
3430 inline probe operator>=(double p1, probe const & p2) { return probe(p2.ctx(), p1) >= p2; }
3431 inline probe operator<(probe const & p1, probe const & p2) {
3432 check_context(p1, p2); Z3_probe r = Z3_probe_lt(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3433 }
3434 inline probe operator<(probe const & p1, double p2) { return p1 < probe(p1.ctx(), p2); }
3435 inline probe operator<(double p1, probe const & p2) { return probe(p2.ctx(), p1) < p2; }
3436 inline probe operator>(probe const & p1, probe const & p2) {
3437 check_context(p1, p2); Z3_probe r = Z3_probe_gt(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3438 }
3439 inline probe operator>(probe const & p1, double p2) { return p1 > probe(p1.ctx(), p2); }
3440 inline probe operator>(double p1, probe const & p2) { return probe(p2.ctx(), p1) > p2; }
3441 inline probe operator==(probe const & p1, probe const & p2) {
3442 check_context(p1, p2); Z3_probe r = Z3_probe_eq(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3443 }
3444 inline probe operator==(probe const & p1, double p2) { return p1 == probe(p1.ctx(), p2); }
3445 inline probe operator==(double p1, probe const & p2) { return probe(p2.ctx(), p1) == p2; }
3446 inline probe operator&&(probe const & p1, probe const & p2) {
3447 check_context(p1, p2); Z3_probe r = Z3_probe_and(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3448 }
3449 inline probe operator||(probe const & p1, probe const & p2) {
3450 check_context(p1, p2); Z3_probe r = Z3_probe_or(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3451 }
3452 inline probe operator!(probe const & p) {
3453 Z3_probe r = Z3_probe_not(p.ctx(), p); p.check_error(); return probe(p.ctx(), r);
3454 }
3455
3456 class optimize : public object {
3457 Z3_optimize m_opt;
3458
3459 public:
3460 struct translate {};
3461 class handle final {
3462 unsigned m_h;
3463 public:
3464 handle(unsigned h): m_h(h) {}
3465 unsigned h() const { return m_h; }
3466 };
3467 optimize(context& c):object(c) { m_opt = Z3_mk_optimize(c); Z3_optimize_inc_ref(c, m_opt); }
3468 optimize(context & c, optimize const& src, translate): object(c) {
3469 Z3_optimize o = Z3_optimize_translate(src.ctx(), src, c);
3470 check_error();
3471 m_opt = o;
3472 Z3_optimize_inc_ref(c, m_opt);
3473 }
3474 optimize(optimize const & o):object(o), m_opt(o.m_opt) {
3475 Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3476 }
3477 optimize(context& c, optimize& src):object(c) {
3478 m_opt = Z3_mk_optimize(c);
3479 Z3_optimize_inc_ref(c, m_opt);
3480 add(expr_vector(c, src.assertions()));
3481 expr_vector v(c, src.objectives());
3482 for (expr_vector::iterator it = v.begin(); it != v.end(); ++it) minimize(*it);
3483 }
3484 optimize& operator=(optimize const& o) {
3485 Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3486 Z3_optimize_dec_ref(ctx(), m_opt);
3487 m_opt = o.m_opt;
3488 object::operator=(o);
3489 return *this;
3490 }
3491 ~optimize() override { Z3_optimize_dec_ref(ctx(), m_opt); }
3492 operator Z3_optimize() const { return m_opt; }
3493 void add(expr const& e) {
3494 assert(e.is_bool());
3495 Z3_optimize_assert(ctx(), m_opt, e);
3496 }
3497 void add(expr_vector const& es) {
3498 for (expr_vector::iterator it = es.begin(); it != es.end(); ++it) add(*it);
3499 }
3500 void add(expr const& e, expr const& t) {
3501 assert(e.is_bool());
3502 Z3_optimize_assert_and_track(ctx(), m_opt, e, t);
3503 }
3504 void add(expr const& e, char const* p) {
3505 assert(e.is_bool());
3506 add(e, ctx().bool_const(p));
3507 }
3508 handle add_soft(expr const& e, unsigned weight) {
3509 assert(e.is_bool());
3510 auto str = std::to_string(weight);
3511 return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, str.c_str(), 0));
3512 }
3513 handle add_soft(expr const& e, char const* weight) {
3514 assert(e.is_bool());
3515 return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, weight, 0));
3516 }
3517 handle add(expr const& e, unsigned weight) {
3518 return add_soft(e, weight);
3519 }
3520 void set_initial_value(expr const& var, expr const& value) {
3521 Z3_optimize_set_initial_value(ctx(), m_opt, var, value);
3522 check_error();
3523 }
3524 void set_initial_value(expr const& var, int i) {
3525 set_initial_value(var, ctx().num_val(i, var.get_sort()));
3526 }
3527 void set_initial_value(expr const& var, bool b) {
3528 set_initial_value(var, ctx().bool_val(b));
3529 }
3530
3531 handle maximize(expr const& e) {
3532 return handle(Z3_optimize_maximize(ctx(), m_opt, e));
3533 }
3534 handle minimize(expr const& e) {
3535 return handle(Z3_optimize_minimize(ctx(), m_opt, e));
3536 }
3537 void push() {
3538 Z3_optimize_push(ctx(), m_opt);
3539 }
3540 void pop() {
3541 Z3_optimize_pop(ctx(), m_opt);
3542 }
3543 check_result check() { Z3_lbool r = Z3_optimize_check(ctx(), m_opt, 0, 0); check_error(); return to_check_result(r); }
3544 check_result check(expr_vector const& asms) {
3545 unsigned n = asms.size();
3546 array<Z3_ast> _asms(n);
3547 for (unsigned i = 0; i < n; ++i) {
3548 check_context(*this, asms[i]);
3549 _asms[i] = asms[i];
3550 }
3551 Z3_lbool r = Z3_optimize_check(ctx(), m_opt, n, _asms.ptr());
3552 check_error();
3553 return to_check_result(r);
3554 }
3555 model get_model() const { Z3_model m = Z3_optimize_get_model(ctx(), m_opt); check_error(); return model(ctx(), m); }
3556 expr_vector unsat_core() const { Z3_ast_vector r = Z3_optimize_get_unsat_core(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
3557 void set(params const & p) { Z3_optimize_set_params(ctx(), m_opt, p); check_error(); }
3558 expr lower(handle const& h) {
3559 Z3_ast r = Z3_optimize_get_lower(ctx(), m_opt, h.h());
3560 check_error();
3561 return expr(ctx(), r);
3562 }
3563 expr upper(handle const& h) {
3564 Z3_ast r = Z3_optimize_get_upper(ctx(), m_opt, h.h());
3565 check_error();
3566 return expr(ctx(), r);
3567 }
3568 expr_vector assertions() const { Z3_ast_vector r = Z3_optimize_get_assertions(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
3569 expr_vector objectives() const { Z3_ast_vector r = Z3_optimize_get_objectives(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
3570 stats statistics() const { Z3_stats r = Z3_optimize_get_statistics(ctx(), m_opt); check_error(); return stats(ctx(), r); }
3571 friend std::ostream & operator<<(std::ostream & out, optimize const & s);
3572 void from_file(char const* filename) { Z3_optimize_from_file(ctx(), m_opt, filename); check_error(); }
3573 void from_string(char const* constraints) { Z3_optimize_from_string(ctx(), m_opt, constraints); check_error(); }
3574 std::string help() const { char const * r = Z3_optimize_get_help(ctx(), m_opt); check_error(); return r; }
3575 };
3576 inline std::ostream & operator<<(std::ostream & out, optimize const & s) { out << Z3_optimize_to_string(s.ctx(), s.m_opt); return out; }
3577
3578 class fixedpoint : public object {
3579 Z3_fixedpoint m_fp;
3580 public:
3581 fixedpoint(context& c):object(c) { m_fp = Z3_mk_fixedpoint(c); Z3_fixedpoint_inc_ref(c, m_fp); }
3582 fixedpoint(fixedpoint const & o):object(o), m_fp(o.m_fp) { Z3_fixedpoint_inc_ref(ctx(), m_fp); }
3583 ~fixedpoint() override { Z3_fixedpoint_dec_ref(ctx(), m_fp); }
3584 fixedpoint & operator=(fixedpoint const & o) {
3585 Z3_fixedpoint_inc_ref(o.ctx(), o.m_fp);
3586 Z3_fixedpoint_dec_ref(ctx(), m_fp);
3587 m_fp = o.m_fp;
3588 object::operator=(o);
3589 return *this;
3590 }
3591 operator Z3_fixedpoint() const { return m_fp; }
3592 expr_vector from_string(char const* s) {
3593 Z3_ast_vector r = Z3_fixedpoint_from_string(ctx(), m_fp, s);
3594 check_error();
3595 return expr_vector(ctx(), r);
3596 }
3597 expr_vector from_file(char const* s) {
3598 Z3_ast_vector r = Z3_fixedpoint_from_file(ctx(), m_fp, s);
3599 check_error();
3600 return expr_vector(ctx(), r);
3601 }
3602 void add_rule(expr& rule, symbol const& name) { Z3_fixedpoint_add_rule(ctx(), m_fp, rule, name); check_error(); }
3603 void add_fact(func_decl& f, unsigned * args) { Z3_fixedpoint_add_fact(ctx(), m_fp, f, f.arity(), args); check_error(); }
3604 check_result query(expr& q) { Z3_lbool r = Z3_fixedpoint_query(ctx(), m_fp, q); check_error(); return to_check_result(r); }
3605 check_result query(func_decl_vector& relations) {
3606 array<Z3_func_decl> rs(relations);
3607 Z3_lbool r = Z3_fixedpoint_query_relations(ctx(), m_fp, rs.size(), rs.ptr());
3608 check_error();
3609 return to_check_result(r);
3610 }
3611 expr get_answer() { Z3_ast r = Z3_fixedpoint_get_answer(ctx(), m_fp); check_error(); return expr(ctx(), r); }
3612 std::string reason_unknown() { return Z3_fixedpoint_get_reason_unknown(ctx(), m_fp); }
3613 void update_rule(expr& rule, symbol const& name) { Z3_fixedpoint_update_rule(ctx(), m_fp, rule, name); check_error(); }
3614 unsigned get_num_levels(func_decl& p) { unsigned r = Z3_fixedpoint_get_num_levels(ctx(), m_fp, p); check_error(); return r; }
3615 expr get_cover_delta(int level, func_decl& p) {
3616 Z3_ast r = Z3_fixedpoint_get_cover_delta(ctx(), m_fp, level, p);
3617 check_error();
3618 return expr(ctx(), r);
3619 }
3620 void add_cover(int level, func_decl& p, expr& property) { Z3_fixedpoint_add_cover(ctx(), m_fp, level, p, property); check_error(); }
3621 stats statistics() const { Z3_stats r = Z3_fixedpoint_get_statistics(ctx(), m_fp); check_error(); return stats(ctx(), r); }
3622 void register_relation(func_decl& p) { Z3_fixedpoint_register_relation(ctx(), m_fp, p); }
3623 expr_vector assertions() const { Z3_ast_vector r = Z3_fixedpoint_get_assertions(ctx(), m_fp); check_error(); return expr_vector(ctx(), r); }
3624 expr_vector rules() const { Z3_ast_vector r = Z3_fixedpoint_get_rules(ctx(), m_fp); check_error(); return expr_vector(ctx(), r); }
3625 void set(params const & p) { Z3_fixedpoint_set_params(ctx(), m_fp, p); check_error(); }
3626 std::string help() const { return Z3_fixedpoint_get_help(ctx(), m_fp); }
3627 param_descrs get_param_descrs() { return param_descrs(ctx(), Z3_fixedpoint_get_param_descrs(ctx(), m_fp)); }
3628 std::string to_string() { return Z3_fixedpoint_to_string(ctx(), m_fp, 0, 0); }
3629 std::string to_string(expr_vector const& queries) {
3630 array<Z3_ast> qs(queries);
3631 return Z3_fixedpoint_to_string(ctx(), m_fp, qs.size(), qs.ptr());
3632 }
3633 };
3634 inline std::ostream & operator<<(std::ostream & out, fixedpoint const & f) { return out << Z3_fixedpoint_to_string(f.ctx(), f, 0, 0); }
3635
3636 inline tactic fail_if(probe const & p) {
3637 Z3_tactic r = Z3_tactic_fail_if(p.ctx(), p);
3638 p.check_error();
3639 return tactic(p.ctx(), r);
3640 }
3641 inline tactic when(probe const & p, tactic const & t) {
3642 check_context(p, t);
3643 Z3_tactic r = Z3_tactic_when(t.ctx(), p, t);
3644 t.check_error();
3645 return tactic(t.ctx(), r);
3646 }
3647 inline tactic cond(probe const & p, tactic const & t1, tactic const & t2) {
3648 check_context(p, t1); check_context(p, t2);
3649 Z3_tactic r = Z3_tactic_cond(t1.ctx(), p, t1, t2);
3650 t1.check_error();
3651 return tactic(t1.ctx(), r);
3652 }
3653
3654 inline symbol context::str_symbol(char const * s) { Z3_symbol r = Z3_mk_string_symbol(m_ctx, s); check_error(); return symbol(*this, r); }
3655 inline symbol context::int_symbol(int n) { Z3_symbol r = Z3_mk_int_symbol(m_ctx, n); check_error(); return symbol(*this, r); }
3656
3657 inline sort context::bool_sort() { Z3_sort s = Z3_mk_bool_sort(m_ctx); check_error(); return sort(*this, s); }
3658 inline sort context::int_sort() { Z3_sort s = Z3_mk_int_sort(m_ctx); check_error(); return sort(*this, s); }
3659 inline sort context::real_sort() { Z3_sort s = Z3_mk_real_sort(m_ctx); check_error(); return sort(*this, s); }
3660 inline sort context::bv_sort(unsigned sz) { Z3_sort s = Z3_mk_bv_sort(m_ctx, sz); check_error(); return sort(*this, s); }
3661 inline sort context::string_sort() { Z3_sort s = Z3_mk_string_sort(m_ctx); check_error(); return sort(*this, s); }
3662 inline sort context::char_sort() { Z3_sort s = Z3_mk_char_sort(m_ctx); check_error(); return sort(*this, s); }
3663 inline sort context::seq_sort(sort& s) { Z3_sort r = Z3_mk_seq_sort(m_ctx, s); check_error(); return sort(*this, r); }
3664 inline sort context::re_sort(sort& s) { Z3_sort r = Z3_mk_re_sort(m_ctx, s); check_error(); return sort(*this, r); }
3665 inline sort context::fpa_sort(unsigned ebits, unsigned sbits) { Z3_sort s = Z3_mk_fpa_sort(m_ctx, ebits, sbits); check_error(); return sort(*this, s); }
3666
3667 template<>
3668 inline sort context::fpa_sort<16>() { return fpa_sort(5, 11); }
3669
3670 template<>
3671 inline sort context::fpa_sort<32>() { return fpa_sort(8, 24); }
3672
3673 template<>
3674 inline sort context::fpa_sort<64>() { return fpa_sort(11, 53); }
3675
3676 template<>
3677 inline sort context::fpa_sort<128>() { return fpa_sort(15, 113); }
3678
3679 inline sort context::fpa_rounding_mode_sort() { Z3_sort r = Z3_mk_fpa_rounding_mode_sort(m_ctx); check_error(); return sort(*this, r); }
3680
3681 inline sort context::array_sort(sort d, sort r) { Z3_sort s = Z3_mk_array_sort(m_ctx, d, r); check_error(); return sort(*this, s); }
3682 inline sort context::array_sort(sort_vector const& d, sort r) {
3683 array<Z3_sort> dom(d);
3684 Z3_sort s = Z3_mk_array_sort_n(m_ctx, dom.size(), dom.ptr(), r); check_error(); return sort(*this, s);
3685 }
3686 inline sort context::enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts) {
3687 array<Z3_symbol> _enum_names(n);
3688 for (unsigned i = 0; i < n; ++i) { _enum_names[i] = Z3_mk_string_symbol(*this, enum_names[i]); }
3689 array<Z3_func_decl> _cs(n);
3690 array<Z3_func_decl> _ts(n);
3691 Z3_symbol _name = Z3_mk_string_symbol(*this, name);
3692 sort s = to_sort(*this, Z3_mk_enumeration_sort(*this, _name, n, _enum_names.ptr(), _cs.ptr(), _ts.ptr()));
3693 check_error();
3694 for (unsigned i = 0; i < n; ++i) { cs.push_back(func_decl(*this, _cs[i])); ts.push_back(func_decl(*this, _ts[i])); }
3695 return s;
3696 }
3697 inline func_decl context::tuple_sort(char const * name, unsigned n, char const * const * names, sort const* sorts, func_decl_vector & projs) {
3698 array<Z3_symbol> _names(n);
3699 array<Z3_sort> _sorts(n);
3700 for (unsigned i = 0; i < n; ++i) { _names[i] = Z3_mk_string_symbol(*this, names[i]); _sorts[i] = sorts[i]; }
3701 array<Z3_func_decl> _projs(n);
3702 Z3_symbol _name = Z3_mk_string_symbol(*this, name);
3703 Z3_func_decl tuple;
3704 sort _ignore_s = to_sort(*this, Z3_mk_tuple_sort(*this, _name, n, _names.ptr(), _sorts.ptr(), &tuple, _projs.ptr()));
3705 check_error();
3706 for (unsigned i = 0; i < n; ++i) { projs.push_back(func_decl(*this, _projs[i])); }
3707 return func_decl(*this, tuple);
3708 }
3709
3710 class constructor_list {
3711 context& ctx;
3712 Z3_constructor_list clist;
3713 public:
3714 constructor_list(constructors const& cs);
3715 ~constructor_list() { Z3_del_constructor_list(ctx, clist); }
3716 operator Z3_constructor_list() const { return clist; }
3717 };
3718
3719 class constructors {
3720 friend class constructor_list;
3721 context& ctx;
3722 std::vector<Z3_constructor> cons;
3723 std::vector<unsigned> num_fields;
3724 public:
3725 constructors(context& ctx): ctx(ctx) {}
3726
3727 ~constructors() {
3728 for (auto con : cons)
3729 Z3_del_constructor(ctx, con);
3730 }
3731
3732 void add(symbol const& name, symbol const& rec, unsigned n, symbol const* names, sort const* fields) {
3733 array<unsigned> sort_refs(n);
3734 array<Z3_sort> sorts(n);
3735 array<Z3_symbol> _names(n);
3736 for (unsigned i = 0; i < n; ++i) sorts[i] = fields[i], _names[i] = names[i];
3737 cons.push_back(Z3_mk_constructor(ctx, name, rec, n, _names.ptr(), sorts.ptr(), sort_refs.ptr()));
3738 num_fields.push_back(n);
3739 }
3740
3741 Z3_constructor operator[](unsigned i) const { return cons[i]; }
3742
3743 unsigned size() const { return (unsigned)cons.size(); }
3744
3745 void query(unsigned i, func_decl& constructor, func_decl& test, func_decl_vector& accs) {
3746 Z3_func_decl _constructor;
3747 Z3_func_decl _test;
3748 array<Z3_func_decl> accessors(num_fields[i]);
3749 accs.resize(0);
3751 cons[i],
3752 num_fields[i],
3753 &_constructor,
3754 &_test,
3755 accessors.ptr());
3756 constructor = func_decl(ctx, _constructor);
3757
3758 test = func_decl(ctx, _test);
3759 for (unsigned j = 0; j < num_fields[i]; ++j)
3760 accs.push_back(func_decl(ctx, accessors[j]));
3761 }
3762 };
3763
3764 inline constructor_list::constructor_list(constructors const& cs): ctx(cs.ctx) {
3765 array<Z3_constructor> cons(cs.size());
3766 for (unsigned i = 0; i < cs.size(); ++i)
3767 cons[i] = cs[i];
3768 clist = Z3_mk_constructor_list(ctx, cs.size(), cons.ptr());
3769 }
3770
3771 inline sort context::datatype(symbol const& name, constructors const& cs) {
3772 array<Z3_constructor> _cs(cs.size());
3773 for (unsigned i = 0; i < cs.size(); ++i) _cs[i] = cs[i];
3774 Z3_sort s = Z3_mk_datatype(*this, name, cs.size(), _cs.ptr());
3775 check_error();
3776 return sort(*this, s);
3777 }
3778
3779 inline sort context::datatype(symbol const &name, sort_vector const& params, constructors const &cs) {
3780 array<Z3_sort> _params(params);
3781 array<Z3_constructor> _cs(cs.size());
3782 for (unsigned i = 0; i < cs.size(); ++i)
3783 _cs[i] = cs[i];
3784 Z3_sort s = Z3_mk_polymorphic_datatype(*this, name, _params.size(), _params.ptr(), cs.size(), _cs.ptr());
3785 check_error();
3786 return sort(*this, s);
3787 }
3788
3789 inline sort_vector context::datatypes(
3790 unsigned n, symbol const* names,
3791 constructor_list *const* cons) {
3792 sort_vector result(*this);
3793 array<Z3_symbol> _names(n);
3794 array<Z3_sort> _sorts(n);
3795 array<Z3_constructor_list> _cons(n);
3796 for (unsigned i = 0; i < n; ++i)
3797 _names[i] = names[i], _cons[i] = *cons[i];
3798 Z3_mk_datatypes(*this, n, _names.ptr(), _sorts.ptr(), _cons.ptr());
3799 for (unsigned i = 0; i < n; ++i)
3800 result.push_back(sort(*this, _sorts[i]));
3801 return result;
3802 }
3803
3804
3805 inline sort context::datatype_sort(symbol const& name) {
3806 Z3_sort s = Z3_mk_datatype_sort(*this, name, 0, nullptr);
3807 check_error();
3808 return sort(*this, s);
3809 }
3810
3811 inline sort context::datatype_sort(symbol const& name, sort_vector const& params) {
3812 array<Z3_sort> _params(params);
3813 Z3_sort s = Z3_mk_datatype_sort(*this, name, _params.size(), _params.ptr());
3814 check_error();
3815 return sort(*this, s);
3816 }
3817
3818
3819 inline sort context::uninterpreted_sort(char const* name) {
3820 Z3_symbol _name = Z3_mk_string_symbol(*this, name);
3821 return to_sort(*this, Z3_mk_uninterpreted_sort(*this, _name));
3822 }
3823 inline sort context::uninterpreted_sort(symbol const& name) {
3824 return to_sort(*this, Z3_mk_uninterpreted_sort(*this, name));
3825 }
3826
3827 inline func_decl context::function(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
3828 array<Z3_sort> args(arity);
3829 for (unsigned i = 0; i < arity; ++i) {
3830 check_context(domain[i], range);
3831 args[i] = domain[i];
3832 }
3833 Z3_func_decl f = Z3_mk_func_decl(m_ctx, name, arity, args.ptr(), range);
3834 check_error();
3835 return func_decl(*this, f);
3836 }
3837
3838 inline func_decl context::function(char const * name, unsigned arity, sort const * domain, sort const & range) {
3839 return function(range.ctx().str_symbol(name), arity, domain, range);
3840 }
3841
3842 inline func_decl context::function(symbol const& name, sort_vector const& domain, sort const& range) {
3843 array<Z3_sort> args(domain.size());
3844 for (unsigned i = 0; i < domain.size(); ++i) {
3845 check_context(domain[i], range);
3846 args[i] = domain[i];
3847 }
3848 Z3_func_decl f = Z3_mk_func_decl(m_ctx, name, domain.size(), args.ptr(), range);
3849 check_error();
3850 return func_decl(*this, f);
3851 }
3852
3853 inline func_decl context::function(char const * name, sort_vector const& domain, sort const& range) {
3854 return function(range.ctx().str_symbol(name), domain, range);
3855 }
3856
3857
3858 inline func_decl context::function(char const * name, sort const & domain, sort const & range) {
3859 check_context(domain, range);
3860 Z3_sort args[1] = { domain };
3861 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 1, args, range);
3862 check_error();
3863 return func_decl(*this, f);
3864 }
3865
3866 inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & range) {
3867 check_context(d1, range); check_context(d2, range);
3868 Z3_sort args[2] = { d1, d2 };
3869 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 2, args, range);
3870 check_error();
3871 return func_decl(*this, f);
3872 }
3873
3874 inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & range) {
3875 check_context(d1, range); check_context(d2, range); check_context(d3, range);
3876 Z3_sort args[3] = { d1, d2, d3 };
3877 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 3, args, range);
3878 check_error();
3879 return func_decl(*this, f);
3880 }
3881
3882 inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & range) {
3883 check_context(d1, range); check_context(d2, range); check_context(d3, range); check_context(d4, range);
3884 Z3_sort args[4] = { d1, d2, d3, d4 };
3885 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 4, args, range);
3886 check_error();
3887 return func_decl(*this, f);
3888 }
3889
3890 inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & d5, sort const & range) {
3891 check_context(d1, range); check_context(d2, range); check_context(d3, range); check_context(d4, range); check_context(d5, range);
3892 Z3_sort args[5] = { d1, d2, d3, d4, d5 };
3893 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 5, args, range);
3894 check_error();
3895 return func_decl(*this, f);
3896 }
3897
3898 inline func_decl context::recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
3899 array<Z3_sort> args(arity);
3900 for (unsigned i = 0; i < arity; ++i) {
3901 check_context(domain[i], range);
3902 args[i] = domain[i];
3903 }
3904 Z3_func_decl f = Z3_mk_rec_func_decl(m_ctx, name, arity, args.ptr(), range);
3905 check_error();
3906 return func_decl(*this, f);
3907
3908 }
3909
3910 inline func_decl context::recfun(symbol const & name, sort_vector const& domain, sort const & range) {
3911 check_context(domain, range);
3912 array<Z3_sort> domain1(domain);
3913 Z3_func_decl f = Z3_mk_rec_func_decl(m_ctx, name, domain1.size(), domain1.ptr(), range);
3914 check_error();
3915 return func_decl(*this, f);
3916 }
3917
3918 inline func_decl context::recfun(char const * name, sort_vector const& domain, sort const & range) {
3919 return recfun(str_symbol(name), domain, range);
3920
3921 }
3922
3923 inline func_decl context::recfun(char const * name, unsigned arity, sort const * domain, sort const & range) {
3924 return recfun(str_symbol(name), arity, domain, range);
3925 }
3926
3927 inline func_decl context::recfun(char const * name, sort const& d1, sort const & range) {
3928 return recfun(str_symbol(name), 1, &d1, range);
3929 }
3930
3931 inline func_decl context::recfun(char const * name, sort const& d1, sort const& d2, sort const & range) {
3932 sort dom[2] = { d1, d2 };
3933 return recfun(str_symbol(name), 2, dom, range);
3934 }
3935
3936 inline void context::recdef(func_decl f, expr_vector const& args, expr const& body) {
3937 check_context(f, args); check_context(f, body);
3938 array<Z3_ast> vars(args);
3939 Z3_add_rec_def(f.ctx(), f, vars.size(), vars.ptr(), body);
3940 }
3941
3942 inline func_decl context::user_propagate_function(symbol const& name, sort_vector const& domain, sort const& range) {
3943 check_context(domain, range);
3944 array<Z3_sort> domain1(domain);
3945 Z3_func_decl f = Z3_solver_propagate_declare(range.ctx(), name, domain1.size(), domain1.ptr(), range);
3946 check_error();
3947 return func_decl(*this, f);
3948 }
3949
3950 inline expr context::constant(symbol const & name, sort const & s) {
3951 Z3_ast r = Z3_mk_const(m_ctx, name, s);
3952 check_error();
3953 return expr(*this, r);
3954 }
3955 inline expr context::constant(char const * name, sort const & s) { return constant(str_symbol(name), s); }
3956 inline expr context::variable(unsigned idx, sort const& s) {
3957 Z3_ast r = Z3_mk_bound(m_ctx, idx, s);
3958 check_error();
3959 return expr(*this, r);
3960 }
3961 inline expr context::bool_const(char const * name) { return constant(name, bool_sort()); }
3962 inline expr context::int_const(char const * name) { return constant(name, int_sort()); }
3963 inline expr context::real_const(char const * name) { return constant(name, real_sort()); }
3964 inline expr context::string_const(char const * name) { return constant(name, string_sort()); }
3965 inline expr context::bv_const(char const * name, unsigned sz) { return constant(name, bv_sort(sz)); }
3966 inline expr context::fpa_const(char const * name, unsigned ebits, unsigned sbits) { return constant(name, fpa_sort(ebits, sbits)); }
3967
3968 template<size_t precision>
3969 inline expr context::fpa_const(char const * name) { return constant(name, fpa_sort<precision>()); }
3970
3971 inline void context::set_rounding_mode(rounding_mode rm) { m_rounding_mode = rm; }
3972
3973 inline expr context::fpa_rounding_mode() {
3974 switch (m_rounding_mode) {
3975 case RNA: return expr(*this, Z3_mk_fpa_rna(m_ctx));
3976 case RNE: return expr(*this, Z3_mk_fpa_rne(m_ctx));
3977 case RTP: return expr(*this, Z3_mk_fpa_rtp(m_ctx));
3978 case RTN: return expr(*this, Z3_mk_fpa_rtn(m_ctx));
3979 case RTZ: return expr(*this, Z3_mk_fpa_rtz(m_ctx));
3980 default: return expr(*this);
3981 }
3982 }
3983
3984 inline expr context::bool_val(bool b) { return b ? expr(*this, Z3_mk_true(m_ctx)) : expr(*this, Z3_mk_false(m_ctx)); }
3985
3986 inline expr context::int_val(int n) { Z3_ast r = Z3_mk_int(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
3987 inline expr context::int_val(unsigned n) { Z3_ast r = Z3_mk_unsigned_int(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
3988 inline expr context::int_val(int64_t n) { Z3_ast r = Z3_mk_int64(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
3989 inline expr context::int_val(uint64_t n) { Z3_ast r = Z3_mk_unsigned_int64(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
3990 inline expr context::int_val(char const * n) { Z3_ast r = Z3_mk_numeral(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
3991
3992 inline expr context::real_val(int64_t n, int64_t d) { Z3_ast r = Z3_mk_real_int64(m_ctx, n, d); check_error(); return expr(*this, r); }
3993 inline expr context::real_val(int n) { Z3_ast r = Z3_mk_int(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
3994 inline expr context::real_val(unsigned n) { Z3_ast r = Z3_mk_unsigned_int(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
3995 inline expr context::real_val(int64_t n) { Z3_ast r = Z3_mk_int64(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
3996 inline expr context::real_val(uint64_t n) { Z3_ast r = Z3_mk_unsigned_int64(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
3997 inline expr context::real_val(char const * n) { Z3_ast r = Z3_mk_numeral(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
3998
3999 inline expr context::bv_val(int n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_int(m_ctx, n, s); check_error(); return expr(*this, r); }
4000 inline expr context::bv_val(unsigned n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_unsigned_int(m_ctx, n, s); check_error(); return expr(*this, r); }
4001 inline expr context::bv_val(int64_t n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_int64(m_ctx, n, s); check_error(); return expr(*this, r); }
4002 inline expr context::bv_val(uint64_t n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_unsigned_int64(m_ctx, n, s); check_error(); return expr(*this, r); }
4003 inline expr context::bv_val(char const * n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_numeral(m_ctx, n, s); check_error(); return expr(*this, r); }
4004 inline expr context::bv_val(unsigned n, bool const* bits) {
4005 array<bool> _bits(n);
4006 for (unsigned i = 0; i < n; ++i) _bits[i] = bits[i] ? 1 : 0;
4007 Z3_ast r = Z3_mk_bv_numeral(m_ctx, n, _bits.ptr()); check_error(); return expr(*this, r);
4008 }
4009
4010 inline expr context::fpa_val(double n) { sort s = fpa_sort<64>(); Z3_ast r = Z3_mk_fpa_numeral_double(m_ctx, n, s); check_error(); return expr(*this, r); }
4011 inline expr context::fpa_val(float n) { sort s = fpa_sort<32>(); Z3_ast r = Z3_mk_fpa_numeral_float(m_ctx, n, s); check_error(); return expr(*this, r); }
4012 inline expr context::fpa_nan(sort const & s) { Z3_ast r = Z3_mk_fpa_nan(m_ctx, s); check_error(); return expr(*this, r); }
4013 inline expr context::fpa_inf(sort const & s, bool sgn) { Z3_ast r = Z3_mk_fpa_inf(m_ctx, s, sgn); check_error(); return expr(*this, r); }
4014
4015 inline expr context::string_val(char const* s, unsigned n) { Z3_ast r = Z3_mk_lstring(m_ctx, n, s); check_error(); return expr(*this, r); }
4016 inline expr context::string_val(char const* s) { Z3_ast r = Z3_mk_string(m_ctx, s); check_error(); return expr(*this, r); }
4017 inline expr context::string_val(std::string const& s) { Z3_ast r = Z3_mk_string(m_ctx, s.c_str()); check_error(); return expr(*this, r); }
4018 inline expr context::string_val(std::u32string const& s) { Z3_ast r = Z3_mk_u32string(m_ctx, (unsigned)s.size(), (unsigned const*)s.c_str()); check_error(); return expr(*this, r); }
4019
4020 inline expr context::num_val(int n, sort const & s) { Z3_ast r = Z3_mk_int(m_ctx, n, s); check_error(); return expr(*this, r); }
4021
4022 inline expr func_decl::operator()(unsigned n, expr const * args) const {
4023 array<Z3_ast> _args(n);
4024 for (unsigned i = 0; i < n; ++i) {
4025 check_context(*this, args[i]);
4026 _args[i] = args[i];
4027 }
4028 Z3_ast r = Z3_mk_app(ctx(), *this, n, _args.ptr());
4029 check_error();
4030 return expr(ctx(), r);
4031
4032 }
4033 inline expr func_decl::operator()(expr_vector const& args) const {
4034 array<Z3_ast> _args(args.size());
4035 for (unsigned i = 0; i < args.size(); ++i) {
4036 check_context(*this, args[i]);
4037 _args[i] = args[i];
4038 }
4039 Z3_ast r = Z3_mk_app(ctx(), *this, args.size(), _args.ptr());
4040 check_error();
4041 return expr(ctx(), r);
4042 }
4043 inline expr func_decl::operator()() const {
4044 Z3_ast r = Z3_mk_app(ctx(), *this, 0, 0);
4045 ctx().check_error();
4046 return expr(ctx(), r);
4047 }
4048 inline expr func_decl::operator()(expr const & a) const {
4049 check_context(*this, a);
4050 Z3_ast args[1] = { a };
4051 Z3_ast r = Z3_mk_app(ctx(), *this, 1, args);
4052 ctx().check_error();
4053 return expr(ctx(), r);
4054 }
4055 inline expr func_decl::operator()(int a) const {
4056 Z3_ast args[1] = { ctx().num_val(a, domain(0)) };
4057 Z3_ast r = Z3_mk_app(ctx(), *this, 1, args);
4058 ctx().check_error();
4059 return expr(ctx(), r);
4060 }
4061 inline expr func_decl::operator()(expr const & a1, expr const & a2) const {
4062 check_context(*this, a1); check_context(*this, a2);
4063 Z3_ast args[2] = { a1, a2 };
4064 Z3_ast r = Z3_mk_app(ctx(), *this, 2, args);
4065 ctx().check_error();
4066 return expr(ctx(), r);
4067 }
4068 inline expr func_decl::operator()(expr const & a1, int a2) const {
4069 check_context(*this, a1);
4070 Z3_ast args[2] = { a1, ctx().num_val(a2, domain(1)) };
4071 Z3_ast r = Z3_mk_app(ctx(), *this, 2, args);
4072 ctx().check_error();
4073 return expr(ctx(), r);
4074 }
4075 inline expr func_decl::operator()(int a1, expr const & a2) const {
4076 check_context(*this, a2);
4077 Z3_ast args[2] = { ctx().num_val(a1, domain(0)), a2 };
4078 Z3_ast r = Z3_mk_app(ctx(), *this, 2, args);
4079 ctx().check_error();
4080 return expr(ctx(), r);
4081 }
4082 inline expr func_decl::operator()(expr const & a1, expr const & a2, expr const & a3) const {
4083 check_context(*this, a1); check_context(*this, a2); check_context(*this, a3);
4084 Z3_ast args[3] = { a1, a2, a3 };
4085 Z3_ast r = Z3_mk_app(ctx(), *this, 3, args);
4086 ctx().check_error();
4087 return expr(ctx(), r);
4088 }
4089 inline expr func_decl::operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4) const {
4090 check_context(*this, a1); check_context(*this, a2); check_context(*this, a3); check_context(*this, a4);
4091 Z3_ast args[4] = { a1, a2, a3, a4 };
4092 Z3_ast r = Z3_mk_app(ctx(), *this, 4, args);
4093 ctx().check_error();
4094 return expr(ctx(), r);
4095 }
4096 inline expr func_decl::operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4, expr const & a5) const {
4097 check_context(*this, a1); check_context(*this, a2); check_context(*this, a3); check_context(*this, a4); check_context(*this, a5);
4098 Z3_ast args[5] = { a1, a2, a3, a4, a5 };
4099 Z3_ast r = Z3_mk_app(ctx(), *this, 5, args);
4100 ctx().check_error();
4101 return expr(ctx(), r);
4102 }
4103
4104 inline expr to_real(expr const & a) { Z3_ast r = Z3_mk_int2real(a.ctx(), a); a.check_error(); return expr(a.ctx(), r); }
4105
4106 inline func_decl function(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
4107 return range.ctx().function(name, arity, domain, range);
4108 }
4109 inline func_decl function(char const * name, unsigned arity, sort const * domain, sort const & range) {
4110 return range.ctx().function(name, arity, domain, range);
4111 }
4112 inline func_decl function(char const * name, sort const & domain, sort const & range) {
4113 return range.ctx().function(name, domain, range);
4114 }
4115 inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & range) {
4116 return range.ctx().function(name, d1, d2, range);
4117 }
4118 inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & range) {
4119 return range.ctx().function(name, d1, d2, d3, range);
4120 }
4121 inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & range) {
4122 return range.ctx().function(name, d1, d2, d3, d4, range);
4123 }
4124 inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & d5, sort const & range) {
4125 return range.ctx().function(name, d1, d2, d3, d4, d5, range);
4126 }
4127 inline func_decl function(char const* name, sort_vector const& domain, sort const& range) {
4128 return range.ctx().function(name, domain, range);
4129 }
4130 inline func_decl function(std::string const& name, sort_vector const& domain, sort const& range) {
4131 return range.ctx().function(name.c_str(), domain, range);
4132 }
4133
4134 inline func_decl recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
4135 return range.ctx().recfun(name, arity, domain, range);
4136 }
4137 inline func_decl recfun(char const * name, unsigned arity, sort const * domain, sort const & range) {
4138 return range.ctx().recfun(name, arity, domain, range);
4139 }
4140 inline func_decl recfun(char const * name, sort const& d1, sort const & range) {
4141 return range.ctx().recfun(name, d1, range);
4142 }
4143 inline func_decl recfun(char const * name, sort const& d1, sort const& d2, sort const & range) {
4144 return range.ctx().recfun(name, d1, d2, range);
4145 }
4146
4147 inline expr select(expr const & a, expr const & i) {
4148 check_context(a, i);
4149 Z3_ast r = Z3_mk_select(a.ctx(), a, i);
4150 a.check_error();
4151 return expr(a.ctx(), r);
4152 }
4153 inline expr select(expr const & a, int i) {
4154 return select(a, a.ctx().num_val(i, a.get_sort().array_domain()));
4155 }
4156 inline expr select(expr const & a, expr_vector const & i) {
4157 check_context(a, i);
4158 array<Z3_ast> idxs(i);
4159 Z3_ast r = Z3_mk_select_n(a.ctx(), a, idxs.size(), idxs.ptr());
4160 a.check_error();
4161 return expr(a.ctx(), r);
4162 }
4163
4164 inline expr store(expr const & a, expr const & i, expr const & v) {
4165 check_context(a, i); check_context(a, v);
4166 Z3_ast r = Z3_mk_store(a.ctx(), a, i, v);
4167 a.check_error();
4168 return expr(a.ctx(), r);
4169 }
4170
4171 inline expr store(expr const & a, int i, expr const & v) { return store(a, a.ctx().num_val(i, a.get_sort().array_domain()), v); }
4172 inline expr store(expr const & a, expr i, int v) { return store(a, i, a.ctx().num_val(v, a.get_sort().array_range())); }
4173 inline expr store(expr const & a, int i, int v) {
4174 return store(a, a.ctx().num_val(i, a.get_sort().array_domain()), a.ctx().num_val(v, a.get_sort().array_range()));
4175 }
4176 inline expr store(expr const & a, expr_vector const & i, expr const & v) {
4177 check_context(a, i); check_context(a, v);
4178 array<Z3_ast> idxs(i);
4179 Z3_ast r = Z3_mk_store_n(a.ctx(), a, idxs.size(), idxs.ptr(), v);
4180 a.check_error();
4181 return expr(a.ctx(), r);
4182 }
4183
4184 inline expr as_array(func_decl & f) {
4185 Z3_ast r = Z3_mk_as_array(f.ctx(), f);
4186 f.check_error();
4187 return expr(f.ctx(), r);
4188 }
4189
4190 inline expr array_default(expr const & a) {
4191 Z3_ast r = Z3_mk_array_default(a.ctx(), a);
4192 a.check_error();
4193 return expr(a.ctx(), r);
4194 }
4195
4196 inline expr array_ext(expr const & a, expr const & b) {
4197 check_context(a, b);
4198 Z3_ast r = Z3_mk_array_ext(a.ctx(), a, b);
4199 a.check_error();
4200 return expr(a.ctx(), r);
4201 }
4202
4203#define MK_EXPR1(_fn, _arg) \
4204 Z3_ast r = _fn(_arg.ctx(), _arg); \
4205 _arg.check_error(); \
4206 return expr(_arg.ctx(), r);
4207
4208#define MK_EXPR2(_fn, _arg1, _arg2) \
4209 check_context(_arg1, _arg2); \
4210 Z3_ast r = _fn(_arg1.ctx(), _arg1, _arg2); \
4211 _arg1.check_error(); \
4212 return expr(_arg1.ctx(), r);
4213
4214 inline expr const_array(sort const & d, expr const & v) {
4216 }
4217
4218 inline expr empty_set(sort const& s) {
4220 }
4221
4222 inline expr full_set(sort const& s) {
4224 }
4225
4226 inline expr set_add(expr const& s, expr const& e) {
4227 MK_EXPR2(Z3_mk_set_add, s, e);
4228 }
4229
4230 inline expr set_del(expr const& s, expr const& e) {
4231 MK_EXPR2(Z3_mk_set_del, s, e);
4232 }
4233
4234 inline expr set_union(expr const& a, expr const& b) {
4235 check_context(a, b);
4236 Z3_ast es[2] = { a, b };
4237 Z3_ast r = Z3_mk_set_union(a.ctx(), 2, es);
4238 a.check_error();
4239 return expr(a.ctx(), r);
4240 }
4241
4242 inline expr set_intersect(expr const& a, expr const& b) {
4243 check_context(a, b);
4244 Z3_ast es[2] = { a, b };
4245 Z3_ast r = Z3_mk_set_intersect(a.ctx(), 2, es);
4246 a.check_error();
4247 return expr(a.ctx(), r);
4248 }
4249
4250 inline expr set_difference(expr const& a, expr const& b) {
4252 }
4253
4254 inline expr set_complement(expr const& a) {
4256 }
4257
4258 inline expr set_member(expr const& s, expr const& e) {
4260 }
4261
4262 inline expr set_subset(expr const& a, expr const& b) {
4264 }
4265
4266 // sequence and regular expression operations.
4267 // union is +
4268 // concat is overloaded to handle sequences and regular expressions
4269
4270 inline expr empty(sort const& s) {
4271 Z3_ast r = Z3_mk_seq_empty(s.ctx(), s);
4272 s.check_error();
4273 return expr(s.ctx(), r);
4274 }
4275 inline expr suffixof(expr const& a, expr const& b) {
4276 check_context(a, b);
4277 Z3_ast r = Z3_mk_seq_suffix(a.ctx(), a, b);
4278 a.check_error();
4279 return expr(a.ctx(), r);
4280 }
4281 inline expr prefixof(expr const& a, expr const& b) {
4282 check_context(a, b);
4283 Z3_ast r = Z3_mk_seq_prefix(a.ctx(), a, b);
4284 a.check_error();
4285 return expr(a.ctx(), r);
4286 }
4287 inline expr indexof(expr const& s, expr const& substr, expr const& offset) {
4288 check_context(s, substr); check_context(s, offset);
4289 Z3_ast r = Z3_mk_seq_index(s.ctx(), s, substr, offset);
4290 s.check_error();
4291 return expr(s.ctx(), r);
4292 }
4293 inline expr last_indexof(expr const& s, expr const& substr) {
4294 check_context(s, substr);
4295 Z3_ast r = Z3_mk_seq_last_index(s.ctx(), s, substr);
4296 s.check_error();
4297 return expr(s.ctx(), r);
4298 }
4299 inline expr to_re(expr const& s) {
4301 }
4302 inline expr in_re(expr const& s, expr const& re) {
4303 MK_EXPR2(Z3_mk_seq_in_re, s, re);
4304 }
4305 inline expr plus(expr const& re) {
4307 }
4308 inline expr option(expr const& re) {
4310 }
4311 inline expr star(expr const& re) {
4313 }
4314 inline expr re_empty(sort const& s) {
4315 Z3_ast r = Z3_mk_re_empty(s.ctx(), s);
4316 s.check_error();
4317 return expr(s.ctx(), r);
4318 }
4319 inline expr re_full(sort const& s) {
4320 Z3_ast r = Z3_mk_re_full(s.ctx(), s);
4321 s.check_error();
4322 return expr(s.ctx(), r);
4323 }
4324 inline expr re_intersect(expr_vector const& args) {
4325 assert(args.size() > 0);
4326 context& ctx = args[0u].ctx();
4327 array<Z3_ast> _args(args);
4328 Z3_ast r = Z3_mk_re_intersect(ctx, _args.size(), _args.ptr());
4329 ctx.check_error();
4330 return expr(ctx, r);
4331 }
4332 inline expr re_diff(expr const& a, expr const& b) {
4333 check_context(a, b);
4334 context& ctx = a.ctx();
4335 Z3_ast r = Z3_mk_re_diff(ctx, a, b);
4336 ctx.check_error();
4337 return expr(ctx, r);
4338 }
4339 inline expr re_complement(expr const& a) {
4341 }
4342 inline expr range(expr const& lo, expr const& hi) {
4343 check_context(lo, hi);
4344 Z3_ast r = Z3_mk_re_range(lo.ctx(), lo, hi);
4345 lo.check_error();
4346 return expr(lo.ctx(), r);
4347 }
4348
4349
4350
4351
4352
4353 inline expr_vector context::parse_string(char const* s) {
4354 Z3_ast_vector r = Z3_parse_smtlib2_string(*this, s, 0, 0, 0, 0, 0, 0);
4355 check_error();
4356 return expr_vector(*this, r);
4357
4358 }
4359 inline expr_vector context::parse_file(char const* s) {
4360 Z3_ast_vector r = Z3_parse_smtlib2_file(*this, s, 0, 0, 0, 0, 0, 0);
4361 check_error();
4362 return expr_vector(*this, r);
4363 }
4364
4365 inline expr_vector context::parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
4366 array<Z3_symbol> sort_names(sorts.size());
4367 array<Z3_symbol> decl_names(decls.size());
4368 array<Z3_sort> sorts1(sorts);
4369 array<Z3_func_decl> decls1(decls);
4370 for (unsigned i = 0; i < sorts.size(); ++i) {
4371 sort_names[i] = sorts[i].name();
4372 }
4373 for (unsigned i = 0; i < decls.size(); ++i) {
4374 decl_names[i] = decls[i].name();
4375 }
4376
4377 Z3_ast_vector r = Z3_parse_smtlib2_string(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
4378 check_error();
4379 return expr_vector(*this, r);
4380 }
4381
4382 inline expr_vector context::parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
4383 array<Z3_symbol> sort_names(sorts.size());
4384 array<Z3_symbol> decl_names(decls.size());
4385 array<Z3_sort> sorts1(sorts);
4386 array<Z3_func_decl> decls1(decls);
4387 for (unsigned i = 0; i < sorts.size(); ++i) {
4388 sort_names[i] = sorts[i].name();
4389 }
4390 for (unsigned i = 0; i < decls.size(); ++i) {
4391 decl_names[i] = decls[i].name();
4392 }
4393 Z3_ast_vector r = Z3_parse_smtlib2_file(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
4394 check_error();
4395 return expr_vector(*this, r);
4396 }
4397
4398 inline func_decl_vector sort::constructors() {
4399 assert(is_datatype());
4400 func_decl_vector cs(ctx());
4401 unsigned n = Z3_get_datatype_sort_num_constructors(ctx(), *this);
4402 for (unsigned i = 0; i < n; ++i)
4403 cs.push_back(func_decl(ctx(), Z3_get_datatype_sort_constructor(ctx(), *this, i)));
4404 return cs;
4405 }
4406
4407 inline func_decl_vector sort::recognizers() {
4408 assert(is_datatype());
4409 func_decl_vector rs(ctx());
4410 unsigned n = Z3_get_datatype_sort_num_constructors(ctx(), *this);
4411 for (unsigned i = 0; i < n; ++i)
4412 rs.push_back(func_decl(ctx(), Z3_get_datatype_sort_recognizer(ctx(), *this, i)));
4413 return rs;
4414 }
4415
4416 inline func_decl_vector func_decl::accessors() {
4417 sort s = range();
4418 assert(s.is_datatype());
4419 unsigned n = Z3_get_datatype_sort_num_constructors(ctx(), s);
4420 unsigned idx = 0;
4421 for (; idx < n; ++idx) {
4422 func_decl f(ctx(), Z3_get_datatype_sort_constructor(ctx(), s, idx));
4423 if (id() == f.id())
4424 break;
4425 }
4426 assert(idx < n);
4427 n = arity();
4428 func_decl_vector as(ctx());
4429 for (unsigned i = 0; i < n; ++i)
4430 as.push_back(func_decl(ctx(), Z3_get_datatype_sort_constructor_accessor(ctx(), s, idx, i)));
4431 return as;
4432 }
4433
4434
4435 inline expr expr::substitute(expr_vector const& src, expr_vector const& dst) {
4436 assert(src.size() == dst.size());
4437 array<Z3_ast> _src(src.size());
4438 array<Z3_ast> _dst(dst.size());
4439 for (unsigned i = 0; i < src.size(); ++i) {
4440 _src[i] = src[i];
4441 _dst[i] = dst[i];
4442 }
4443 Z3_ast r = Z3_substitute(ctx(), m_ast, src.size(), _src.ptr(), _dst.ptr());
4444 check_error();
4445 return expr(ctx(), r);
4446 }
4447
4448 inline expr expr::substitute(expr_vector const& dst) {
4449 array<Z3_ast> _dst(dst.size());
4450 for (unsigned i = 0; i < dst.size(); ++i) {
4451 _dst[i] = dst[i];
4452 }
4453 Z3_ast r = Z3_substitute_vars(ctx(), m_ast, dst.size(), _dst.ptr());
4454 check_error();
4455 return expr(ctx(), r);
4456 }
4457
4458 inline expr expr::substitute(func_decl_vector const& funs, expr_vector const& dst) {
4459 array<Z3_ast> _dst(dst.size());
4460 array<Z3_func_decl> _funs(funs.size());
4461 if (dst.size() != funs.size()) {
4462 Z3_THROW(exception("length of argument lists don't align"));
4463 return expr(ctx(), nullptr);
4464 }
4465 for (unsigned i = 0; i < dst.size(); ++i) {
4466 _dst[i] = dst[i];
4467 _funs[i] = funs[i];
4468 }
4469 Z3_ast r = Z3_substitute_funs(ctx(), m_ast, dst.size(), _funs.ptr(), _dst.ptr());
4470 check_error();
4471 return expr(ctx(), r);
4472 }
4473
4474 inline expr expr::update(expr_vector const& args) const {
4475 array<Z3_ast> _args(args.size());
4476 for (unsigned i = 0; i < args.size(); ++i) {
4477 _args[i] = args[i];
4478 }
4479 Z3_ast r = Z3_update_term(ctx(), m_ast, args.size(), _args.ptr());
4480 check_error();
4481 return expr(ctx(), r);
4482 }
4483
4484 inline expr expr::update_field(func_decl const& field_access, expr const& new_value) const {
4485 assert(is_datatype());
4486 Z3_ast r = Z3_datatype_update_field(ctx(), field_access, m_ast, new_value);
4487 check_error();
4488 return expr(ctx(), r);
4489 }
4490
4491 typedef std::function<void(expr const& proof, std::vector<unsigned> const& deps, expr_vector const& clause)> on_clause_eh_t;
4492
4493 class on_clause {
4494 context& c;
4495 on_clause_eh_t m_on_clause;
4496
4497 static void _on_clause_eh(void* _ctx, Z3_ast _proof, unsigned n, unsigned const* dep, Z3_ast_vector _literals) {
4498 on_clause* ctx = static_cast<on_clause*>(_ctx);
4499 expr_vector lits(ctx->c, _literals);
4500 expr proof(ctx->c, _proof);
4501 std::vector<unsigned> deps;
4502 for (unsigned i = 0; i < n; ++i)
4503 deps.push_back(dep[i]);
4504 ctx->m_on_clause(proof, deps, lits);
4505 }
4506 public:
4507 on_clause(solver& s, on_clause_eh_t& on_clause_eh): c(s.ctx()) {
4508 m_on_clause = on_clause_eh;
4509 Z3_solver_register_on_clause(c, s, this, _on_clause_eh);
4510 c.check_error();
4511 }
4512 };
4513
4514 class user_propagator_base {
4515
4516 typedef std::function<void(expr const&, expr const&)> fixed_eh_t;
4517 typedef std::function<void(void)> final_eh_t;
4518 typedef std::function<void(expr const&, expr const&)> eq_eh_t;
4519 typedef std::function<void(expr const&)> created_eh_t;
4520 typedef std::function<void(expr, unsigned, bool)> decide_eh_t;
4521 typedef std::function<bool(expr const&, expr const&)> on_binding_eh_t;
4522
4523 final_eh_t m_final_eh;
4524 eq_eh_t m_eq_eh;
4525 fixed_eh_t m_fixed_eh;
4526 created_eh_t m_created_eh;
4527 decide_eh_t m_decide_eh;
4528 on_binding_eh_t m_on_binding_eh;
4529 solver* s;
4530 context* c;
4531 std::vector<z3::context*> subcontexts;
4532
4533 unsigned m_callbackNesting = 0;
4534 Z3_solver_callback cb { nullptr };
4535
4536 struct scoped_cb {
4537 user_propagator_base& p;
4538 scoped_cb(void* _p, Z3_solver_callback cb):p(*static_cast<user_propagator_base*>(_p)) {
4539 p.cb = cb;
4540 p.m_callbackNesting++;
4541 }
4542 ~scoped_cb() {
4543 if (--p.m_callbackNesting == 0)
4544 p.cb = nullptr;
4545 }
4546 };
4547
4548 static void push_eh(void* _p, Z3_solver_callback cb) {
4549 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4550 scoped_cb _cb(p, cb);
4551 static_cast<user_propagator_base*>(p)->push();
4552 }
4553
4554 static void pop_eh(void* _p, Z3_solver_callback cb, unsigned num_scopes) {
4555 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4556 scoped_cb _cb(p, cb);
4557 static_cast<user_propagator_base*>(_p)->pop(num_scopes);
4558 }
4559
4560 static void* fresh_eh(void* _p, Z3_context ctx) {
4561 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4562 context* c = new context(ctx);
4563 p->subcontexts.push_back(c);
4564 return p->fresh(*c);
4565 }
4566
4567 static void fixed_eh(void* _p, Z3_solver_callback cb, Z3_ast _var, Z3_ast _value) {
4568 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4569 scoped_cb _cb(p, cb);
4570 expr value(p->ctx(), _value);
4571 expr var(p->ctx(), _var);
4572 p->m_fixed_eh(var, value);
4573 }
4574
4575 static void eq_eh(void* _p, Z3_solver_callback cb, Z3_ast _x, Z3_ast _y) {
4576 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4577 scoped_cb _cb(p, cb);
4578 expr x(p->ctx(), _x), y(p->ctx(), _y);
4579 p->m_eq_eh(x, y);
4580 }
4581
4582 static void final_eh(void* p, Z3_solver_callback cb) {
4583 scoped_cb _cb(p, cb);
4584 static_cast<user_propagator_base*>(p)->m_final_eh();
4585 }
4586
4587 static void created_eh(void* _p, Z3_solver_callback cb, Z3_ast _e) {
4588 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4589 scoped_cb _cb(p, cb);
4590 expr e(p->ctx(), _e);
4591 p->m_created_eh(e);
4592 }
4593
4594 static void decide_eh(void* _p, Z3_solver_callback cb, Z3_ast _val, unsigned bit, bool is_pos) {
4595 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4596 scoped_cb _cb(p, cb);
4597 expr val(p->ctx(), _val);
4598 p->m_decide_eh(val, bit, is_pos);
4599 }
4600
4601 static bool on_binding_eh(void* _p, Z3_solver_callback cb, Z3_ast _q, Z3_ast _inst) {
4602 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4603 scoped_cb _cb(p, cb);
4604 expr q(p->ctx(), _q), inst(p->ctx(), _inst);
4605 return p->m_on_binding_eh(q, inst);
4606 }
4607
4608 public:
4609 user_propagator_base(context& c) : s(nullptr), c(&c) {}
4610
4611 user_propagator_base(solver* s): s(s), c(nullptr) {
4612 Z3_solver_propagate_init(ctx(), *s, this, push_eh, pop_eh, fresh_eh);
4613 }
4614
4615 virtual void push() = 0;
4616 virtual void pop(unsigned num_scopes) = 0;
4617
4618 virtual ~user_propagator_base() {
4619 for (auto& subcontext : subcontexts) {
4620 subcontext->detach(); // detach first; the subcontexts will be freed internally!
4621 delete subcontext;
4622 }
4623 }
4624
4625 context& ctx() {
4626 return c ? *c : s->ctx();
4627 }
4628
4637 virtual user_propagator_base* fresh(context& ctx) = 0;
4638
4645 void register_fixed(fixed_eh_t& f) {
4646 m_fixed_eh = f;
4647 if (s) {
4648 Z3_solver_propagate_fixed(ctx(), *s, fixed_eh);
4649 }
4650 }
4651
4652 void register_fixed() {
4653 m_fixed_eh = [this](expr const &id, expr const &e) {
4654 fixed(id, e);
4655 };
4656 if (s) {
4657 Z3_solver_propagate_fixed(ctx(), *s, fixed_eh);
4658 }
4659 }
4660
4661 void register_eq(eq_eh_t& f) {
4662 m_eq_eh = f;
4663 if (s) {
4664 Z3_solver_propagate_eq(ctx(), *s, eq_eh);
4665 }
4666 }
4667
4668 void register_eq() {
4669 m_eq_eh = [this](expr const& x, expr const& y) {
4670 eq(x, y);
4671 };
4672 if (s) {
4673 Z3_solver_propagate_eq(ctx(), *s, eq_eh);
4674 }
4675 }
4676
4685 void register_final(final_eh_t& f) {
4686 m_final_eh = f;
4687 if (s) {
4688 Z3_solver_propagate_final(ctx(), *s, final_eh);
4689 }
4690 }
4691
4692 void register_final() {
4693 m_final_eh = [this]() {
4694 final();
4695 };
4696 if (s) {
4697 Z3_solver_propagate_final(ctx(), *s, final_eh);
4698 }
4699 }
4700
4701 void register_created(created_eh_t& c) {
4702 m_created_eh = c;
4703 if (s) {
4704 Z3_solver_propagate_created(ctx(), *s, created_eh);
4705 }
4706 }
4707
4708 void register_created() {
4709 m_created_eh = [this](expr const& e) {
4710 created(e);
4711 };
4712 if (s) {
4713 Z3_solver_propagate_created(ctx(), *s, created_eh);
4714 }
4715 }
4716
4717 void register_decide(decide_eh_t& c) {
4718 m_decide_eh = c;
4719 if (s) {
4720 Z3_solver_propagate_decide(ctx(), *s, decide_eh);
4721 }
4722 }
4723
4724 void register_decide() {
4725 m_decide_eh = [this](expr val, unsigned bit, bool is_pos) {
4726 decide(val, bit, is_pos);
4727 };
4728 if (s) {
4729 Z3_solver_propagate_decide(ctx(), *s, decide_eh);
4730 }
4731 }
4732
4733 void register_on_binding() {
4734 m_on_binding_eh = [this](expr const& q, expr const& inst) {
4735 return on_binding(q, inst);
4736 };
4737 if (s)
4738 Z3_solver_propagate_on_binding(ctx(), *s, on_binding_eh);
4739 }
4740
4741 virtual void fixed(expr const& /*id*/, expr const& /*e*/) { }
4742
4743 virtual void eq(expr const& /*x*/, expr const& /*y*/) { }
4744
4745 virtual void final() { }
4746
4747 virtual void created(expr const& /*e*/) {}
4748
4749 virtual void decide(expr const& /*val*/, unsigned /*bit*/, bool /*is_pos*/) {}
4750
4751 virtual bool on_binding(expr const& /*q*/, expr const& /*inst*/) { return true; }
4752
4753 bool next_split(expr const& e, unsigned idx, Z3_lbool phase) {
4754 assert(cb);
4755 return Z3_solver_next_split(ctx(), cb, e, idx, phase);
4756 }
4757
4772 void add(expr const& e) {
4773 if (cb)
4774 Z3_solver_propagate_register_cb(ctx(), cb, e);
4775 else if (s)
4776 Z3_solver_propagate_register(ctx(), *s, e);
4777 else
4778 assert(false);
4779 }
4780
4781 void conflict(expr_vector const& fixed) {
4782 assert(cb);
4783 expr conseq = ctx().bool_val(false);
4784 array<Z3_ast> _fixed(fixed);
4785 Z3_solver_propagate_consequence(ctx(), cb, fixed.size(), _fixed.ptr(), 0, nullptr, nullptr, conseq);
4786 }
4787
4788 void conflict(expr_vector const& fixed, expr_vector const& lhs, expr_vector const& rhs) {
4789 assert(cb);
4790 assert(lhs.size() == rhs.size());
4791 expr conseq = ctx().bool_val(false);
4792 array<Z3_ast> _fixed(fixed);
4793 array<Z3_ast> _lhs(lhs);
4794 array<Z3_ast> _rhs(rhs);
4795 Z3_solver_propagate_consequence(ctx(), cb, fixed.size(), _fixed.ptr(), lhs.size(), _lhs.ptr(), _rhs.ptr(), conseq);
4796 }
4797
4798 bool propagate(expr_vector const& fixed, expr const& conseq) {
4799 assert(cb);
4800 assert((Z3_context)conseq.ctx() == (Z3_context)ctx());
4801 array<Z3_ast> _fixed(fixed);
4802 return Z3_solver_propagate_consequence(ctx(), cb, _fixed.size(), _fixed.ptr(), 0, nullptr, nullptr, conseq);
4803 }
4804
4805 bool propagate(expr_vector const& fixed,
4806 expr_vector const& lhs, expr_vector const& rhs,
4807 expr const& conseq) {
4808 assert(cb);
4809 assert((Z3_context)conseq.ctx() == (Z3_context)ctx());
4810 assert(lhs.size() == rhs.size());
4811 array<Z3_ast> _fixed(fixed);
4812 array<Z3_ast> _lhs(lhs);
4813 array<Z3_ast> _rhs(rhs);
4814
4815 return Z3_solver_propagate_consequence(ctx(), cb, _fixed.size(), _fixed.ptr(), lhs.size(), _lhs.ptr(), _rhs.ptr(), conseq);
4816 }
4817 };
4818
4828 class rcf_num {
4829 Z3_context m_ctx;
4830 Z3_rcf_num m_num;
4831
4832 void check_context(rcf_num const& other) const {
4833 if (m_ctx != other.m_ctx) {
4834 throw exception("rcf_num objects from different contexts");
4835 }
4836 }
4837
4838 public:
4839 rcf_num(context& c, Z3_rcf_num n): m_ctx(c), m_num(n) {}
4840
4841 rcf_num(context& c, int val): m_ctx(c) {
4842 m_num = Z3_rcf_mk_small_int(c, val);
4843 }
4844
4845 rcf_num(context& c, char const* val): m_ctx(c) {
4846 m_num = Z3_rcf_mk_rational(c, val);
4847 }
4848
4849 rcf_num(rcf_num const& other): m_ctx(other.m_ctx) {
4850 // Create a copy by converting to string and back
4851 std::string str = Z3_rcf_num_to_string(m_ctx, other.m_num, false, false);
4852 m_num = Z3_rcf_mk_rational(m_ctx, str.c_str());
4853 }
4854
4855 rcf_num& operator=(rcf_num const& other) {
4856 if (this != &other) {
4857 Z3_rcf_del(m_ctx, m_num);
4858 m_ctx = other.m_ctx;
4859 std::string str = Z3_rcf_num_to_string(m_ctx, other.m_num, false, false);
4860 m_num = Z3_rcf_mk_rational(m_ctx, str.c_str());
4861 }
4862 return *this;
4863 }
4864
4865 ~rcf_num() {
4866 Z3_rcf_del(m_ctx, m_num);
4867 }
4868
4869 operator Z3_rcf_num() const { return m_num; }
4870 Z3_context ctx() const { return m_ctx; }
4871
4875 std::string to_string(bool compact = false) const {
4876 return std::string(Z3_rcf_num_to_string(m_ctx, m_num, compact, false));
4877 }
4878
4882 std::string to_decimal(unsigned precision = 10) const {
4883 return std::string(Z3_rcf_num_to_decimal_string(m_ctx, m_num, precision));
4884 }
4885
4886 // Arithmetic operations
4887 rcf_num operator+(rcf_num const& other) const {
4888 check_context(other);
4889 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
4890 Z3_rcf_add(m_ctx, m_num, other.m_num));
4891 }
4892
4893 rcf_num operator-(rcf_num const& other) const {
4894 check_context(other);
4895 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
4896 Z3_rcf_sub(m_ctx, m_num, other.m_num));
4897 }
4898
4899 rcf_num operator*(rcf_num const& other) const {
4900 check_context(other);
4901 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
4902 Z3_rcf_mul(m_ctx, m_num, other.m_num));
4903 }
4904
4905 rcf_num operator/(rcf_num const& other) const {
4906 check_context(other);
4907 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
4908 Z3_rcf_div(m_ctx, m_num, other.m_num));
4909 }
4910
4911 rcf_num operator-() const {
4912 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
4913 Z3_rcf_neg(m_ctx, m_num));
4914 }
4915
4919 rcf_num power(unsigned k) const {
4920 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
4921 Z3_rcf_power(m_ctx, m_num, k));
4922 }
4923
4927 rcf_num inv() const {
4928 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
4929 Z3_rcf_inv(m_ctx, m_num));
4930 }
4931
4932 // Comparison operations
4933 bool operator<(rcf_num const& other) const {
4934 check_context(other);
4935 return Z3_rcf_lt(m_ctx, m_num, other.m_num);
4936 }
4937
4938 bool operator>(rcf_num const& other) const {
4939 check_context(other);
4940 return Z3_rcf_gt(m_ctx, m_num, other.m_num);
4941 }
4942
4943 bool operator<=(rcf_num const& other) const {
4944 check_context(other);
4945 return Z3_rcf_le(m_ctx, m_num, other.m_num);
4946 }
4947
4948 bool operator>=(rcf_num const& other) const {
4949 check_context(other);
4950 return Z3_rcf_ge(m_ctx, m_num, other.m_num);
4951 }
4952
4953 bool operator==(rcf_num const& other) const {
4954 check_context(other);
4955 return Z3_rcf_eq(m_ctx, m_num, other.m_num);
4956 }
4957
4958 bool operator!=(rcf_num const& other) const {
4959 check_context(other);
4960 return Z3_rcf_neq(m_ctx, m_num, other.m_num);
4961 }
4962
4963 // Type queries
4964 bool is_rational() const {
4965 return Z3_rcf_is_rational(m_ctx, m_num);
4966 }
4967
4968 bool is_algebraic() const {
4969 return Z3_rcf_is_algebraic(m_ctx, m_num);
4970 }
4971
4972 bool is_infinitesimal() const {
4973 return Z3_rcf_is_infinitesimal(m_ctx, m_num);
4974 }
4975
4976 bool is_transcendental() const {
4977 return Z3_rcf_is_transcendental(m_ctx, m_num);
4978 }
4979
4980 friend std::ostream& operator<<(std::ostream& out, rcf_num const& n) {
4981 return out << n.to_string();
4982 }
4983 };
4984
4988 inline rcf_num rcf_pi(context& c) {
4989 return rcf_num(c, Z3_rcf_mk_pi(c));
4990 }
4991
4995 inline rcf_num rcf_e(context& c) {
4996 return rcf_num(c, Z3_rcf_mk_e(c));
4997 }
4998
5002 inline rcf_num rcf_infinitesimal(context& c) {
5003 return rcf_num(c, Z3_rcf_mk_infinitesimal(c));
5004 }
5005
5012 inline std::vector<rcf_num> rcf_roots(context& c, std::vector<rcf_num> const& coeffs) {
5013 if (coeffs.empty()) {
5014 throw exception("polynomial coefficients cannot be empty");
5015 }
5016
5017 unsigned n = static_cast<unsigned>(coeffs.size());
5018 std::vector<Z3_rcf_num> a(n);
5019 std::vector<Z3_rcf_num> roots(n);
5020
5021 for (unsigned i = 0; i < n; ++i) {
5022 a[i] = coeffs[i];
5023 }
5024
5025 unsigned num_roots = Z3_rcf_mk_roots(c, n, a.data(), roots.data());
5026
5027 std::vector<rcf_num> result;
5028 result.reserve(num_roots);
5029 for (unsigned i = 0; i < num_roots; ++i) {
5030 result.push_back(rcf_num(c, roots[i]));
5031 }
5032
5033 return result;
5034 }
5035
5036}
5037
5040#undef Z3_THROW
5041
symbol str_symbol(char const *s)
Create a Z3 symbol based on the given string.
Definition z3++.h:3655
expr num_val(int n, sort const &s)
Definition z3++.h:4021
func_decl recfun(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition z3++.h:3899
expr bool_val(bool b)
Definition z3++.h:3985
func_decl function(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition z3++.h:3828
Z3_error_code check_error() const
Definition z3++.h:541
context & ctx() const
Definition z3++.h:540
Z3_ast Z3_API Z3_mk_exists_const(Z3_context c, unsigned weight, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], Z3_ast body)
Similar to Z3_mk_forall_const.
void Z3_API Z3_solver_propagate_on_binding(Z3_context c, Z3_solver s, Z3_on_binding_eh on_binding_eh)
register a callback when the solver instantiates a quantifier. If the callback returns false,...
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o)
Return the set of asserted formulas on the optimization context.
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,...
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
Z3_simplifier Z3_API Z3_simplifier_and_then(Z3_context c, Z3_simplifier t1, Z3_simplifier t2)
Return a simplifier that applies t1 to a given goal and t2 to every subgoal produced by t1.
Z3_probe Z3_API Z3_probe_lt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than the value returned...
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
Z3_ast Z3_API Z3_mk_bvxnor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise xnor.
Z3_parameter_kind Z3_API Z3_get_decl_parameter_kind(Z3_context c, Z3_func_decl d, unsigned idx)
Return the parameter type associated with a declaration.
bool Z3_API Z3_is_seq_sort(Z3_context c, Z3_sort s)
Check if s is a sequence sort.
Z3_ast Z3_API Z3_mk_bvnor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise nor.
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.
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.
Z3_ast Z3_API Z3_func_interp_get_else(Z3_context c, Z3_func_interp f)
Return the 'else' value of the given function interpretation.
Z3_ast Z3_API Z3_mk_bvsge(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than or equal to.
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
Z3_rcf_num Z3_API Z3_rcf_div(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return the value a / b.
void Z3_API Z3_simplifier_inc_ref(Z3_context c, Z3_simplifier t)
Increment the reference counter of the given simplifier.
unsigned Z3_API Z3_rcf_mk_roots(Z3_context c, unsigned n, Z3_rcf_num const a[], Z3_rcf_num roots[])
Store in roots the roots of the polynomial a[n-1]*x^{n-1} + ... + a[0]. The output vector roots must ...
void Z3_API Z3_fixedpoint_add_rule(Z3_context c, Z3_fixedpoint d, Z3_ast rule, Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form:
Z3_probe Z3_API Z3_probe_eq(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned ...
Z3_ast_vector Z3_API Z3_optimize_get_unsat_core(Z3_context c, Z3_optimize o)
Retrieve the unsat core for the last Z3_optimize_check The unsat core is a subset of the assumptions ...
Z3_sort Z3_API Z3_mk_char_sort(Z3_context c)
Create a sort for unicode characters.
Z3_ast Z3_API Z3_mk_unsigned_int(Z3_context c, unsigned v, Z3_sort ty)
Create a numeral of a int, bit-vector, or finite-domain sort.
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].
Z3_ast Z3_API Z3_mk_bvsle(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than or equal to.
void Z3_API Z3_query_constructor(Z3_context c, Z3_constructor constr, unsigned num_fields, Z3_func_decl *constructor, Z3_func_decl *tester, Z3_func_decl accessors[])
Query constructor for declared functions.
void Z3_API Z3_optimize_set_initial_value(Z3_context c, Z3_optimize o, Z3_ast v, Z3_ast val)
provide an initialization hint to the solver. The initialization hint is used to calibrate an initial...
Z3_ast Z3_API Z3_substitute(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const from[], Z3_ast const to[])
Substitute every occurrence of from[i] in a with to[i], for i smaller than num_exprs....
Z3_ast Z3_API Z3_mk_mul(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] * ... * args[num_args-1].
Z3_func_decl Z3_API Z3_get_decl_func_decl_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
Z3_goal_prec
Z3 custom error handler (See Z3_set_error_handler).
Definition z3_api.h:1388
Z3_ast_vector Z3_API Z3_polynomial_subresultants(Z3_context c, Z3_ast p, Z3_ast q, Z3_ast x)
Return the nonzero subresultants of p and q with respect to the "variable" x.
Z3_ast Z3_API Z3_mk_zero_ext(Z3_context c, unsigned i, Z3_ast t1)
Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i,...
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_ast Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
Z3_ast Z3_API Z3_mk_int(Z3_context c, int v, Z3_sort ty)
Create a numeral of an int, bit-vector, or finite-domain sort.
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.
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context....
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
Z3_rcf_num Z3_API Z3_rcf_mk_rational(Z3_context c, Z3_string val)
Return a RCF rational using the given string.
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort.
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body)
Define the body of a recursive function.
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.
Z3_ast Z3_API Z3_mk_fpa_to_sbv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into a signed bit-vector.
Z3_ast Z3_API Z3_mk_true(Z3_context c)
Create an AST node representing true.
Z3_ast Z3_API Z3_optimize_get_lower(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective.
Z3_ast Z3_API Z3_mk_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
void Z3_API Z3_apply_result_inc_ref(Z3_context c, Z3_apply_result r)
Increment the reference counter of the given Z3_apply_result object.
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...
Z3_ast Z3_API Z3_mk_bvsdiv_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed division of t1 and t2 does not overflow.
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
Z3_param_descrs Z3_API Z3_fixedpoint_get_param_descrs(Z3_context c, Z3_fixedpoint f)
Return the parameter description set for the given fixedpoint object.
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
void Z3_API Z3_optimize_from_file(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 file with assertions, soft constraints and optimization objectives....
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
Z3_string Z3_API Z3_simplifier_get_help(Z3_context c, Z3_simplifier t)
Return a string containing a description of parameters accepted by the given simplifier.
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.
Z3_tactic Z3_API Z3_tactic_par_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and then t2 to every subgoal produced by t1....
void Z3_API Z3_fixedpoint_update_rule(Z3_context c, Z3_fixedpoint d, Z3_ast a, Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created.
void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than.
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.
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
unsigned Z3_API Z3_func_entry_get_num_args(Z3_context c, Z3_func_entry e)
Return the number of arguments in a Z3_func_entry object.
Z3_rcf_num Z3_API Z3_rcf_add(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return the value a + b.
Z3_symbol Z3_API Z3_get_decl_symbol_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string str)
load solver assertions from a string.
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
Z3_ast Z3_API Z3_mk_fpa_rna(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode.
Z3_probe Z3_API Z3_probe_ge(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than or equal to the...
Z3_ast Z3_API Z3_mk_and(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] and ... and args[num_args-1].
void Z3_API Z3_simplifier_dec_ref(Z3_context c, Z3_simplifier g)
Decrement the reference counter of the given simplifier.
Z3_ast Z3_API Z3_mk_fpa_sub(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point subtraction.
void Z3_API Z3_goal_assert(Z3_context c, Z3_goal g, Z3_ast a)
Add a new formula a to the given goal. The formula is split according to the following procedure that...
Z3_sort Z3_API Z3_mk_polymorphic_datatype(Z3_context c, Z3_symbol name, unsigned num_parameters, Z3_sort parameters[], unsigned num_constructors, Z3_constructor constructors[])
Create a parametric datatype with explicit type parameters.
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
Z3_ast_vector Z3_API Z3_fixedpoint_from_string(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 string with fixedpoint rules. Add the rules to the current fixedpoint context....
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
Z3_sort Z3_API Z3_mk_datatype(Z3_context c, Z3_symbol name, unsigned num_constructors, Z3_constructor constructors[])
Create datatype, such as lists, trees, records, enumerations or unions of records....
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.
Z3_ast Z3_API Z3_mk_fpa_to_ubv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into an unsigned bit-vector.
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.
Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m)
Convert a model of the formulas of a goal to a model of an original goal. The model may be null,...
void Z3_API Z3_del_constructor(Z3_context c, Z3_constructor constr)
Reclaim memory allocated to constructor.
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
bool Z3_API Z3_rcf_eq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a == b.
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
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_solver Z3_API Z3_mk_solver_from_tactic(Z3_context c, Z3_tactic t)
Create a new solver that is implemented using the given tactic. The solver supports the commands Z3_s...
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a unsigned integer.
bool Z3_API Z3_stats_is_double(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a double.
Z3_ast Z3_API Z3_mk_fpa_rtn(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
bool Z3_API Z3_rcf_lt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a < b.
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
Z3_ast Z3_API Z3_mk_bvadd_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed addition of t1 and t2 does not underflow.
Z3_ast Z3_API Z3_mk_fpa_rtp(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode.
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise addition of t1 and t2 does not overflow.
bool Z3_API Z3_solver_propagate_consequence(Z3_context c, Z3_solver_callback cb, unsigned num_fixed, Z3_ast const *fixed, unsigned num_eqs, Z3_ast const *eq_lhs, Z3_ast const *eq_rhs, Z3_ast conseq)
propagate a consequence based on fixed values and equalities. A client may invoke it during the pro...
Z3_rcf_num Z3_API Z3_rcf_inv(Z3_context c, Z3_rcf_num a)
Return the value 1/a.
Z3_ast Z3_API Z3_mk_array_default(Z3_context c, Z3_ast array)
Access the array default value. Produces the default range value, for arrays that can be represented ...
Z3_ast Z3_API Z3_datatype_update_field(Z3_context c, Z3_func_decl field_access, Z3_ast t, Z3_ast value)
Update record field with a value.
Z3_ast Z3_API Z3_mk_forall_const(Z3_context c, unsigned weight, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], Z3_ast body)
Create a universal quantifier using a list of constants that will form the set of bound variables.
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.
bool Z3_API Z3_rcf_gt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a > b.
const char * Z3_string
Z3 string type. It is just an alias for const char *.
Definition z3_api.h:50
Z3_param_descrs Z3_API Z3_tactic_get_param_descrs(Z3_context c, Z3_tactic t)
Return the parameter description set for the given tactic object.
Z3_sort Z3_API Z3_mk_tuple_sort(Z3_context c, Z3_symbol mk_tuple_name, unsigned num_fields, Z3_symbol const field_names[], Z3_sort const field_sorts[], Z3_func_decl *mk_tuple_decl, Z3_func_decl proj_decl[])
Create a tuple type.
void Z3_API Z3_func_entry_inc_ref(Z3_context c, Z3_func_entry e)
Increment the reference counter of the given Z3_func_entry object.
Z3_ast Z3_API Z3_mk_bvsub_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed subtraction of t1 and t2 does not overflow.
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow.
Z3_rcf_num Z3_API Z3_rcf_sub(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return the value a - b.
Z3_ast Z3_API Z3_mk_fpa_max(Z3_context c, Z3_ast t1, Z3_ast t2)
Maximum of floating-point numbers.
void Z3_API Z3_optimize_assert_and_track(Z3_context c, Z3_optimize o, Z3_ast a, Z3_ast t)
Assert tracked hard constraint to the optimization context.
unsigned Z3_API Z3_optimize_assert_soft(Z3_context c, Z3_optimize o, Z3_ast a, Z3_string weight, Z3_symbol id)
Assert soft constraint to the optimization context.
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
Z3_ast_vector Z3_API Z3_solver_get_trail(Z3_context c, Z3_solver s)
Return the trail modulo model conversion, in order of decision level The decision level can be retrie...
bool Z3_API Z3_rcf_le(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a <= b.
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id)
create a tree ordering relation over signature a identified using index id.
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
Z3_ast Z3_API Z3_solver_congruence_next(Z3_context c, Z3_solver s, Z3_ast a)
retrieve the next expression in the congruence class. The set of congruent siblings form a cyclic lis...
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.
unsigned Z3_API Z3_goal_num_exprs(Z3_context c, Z3_goal g)
Return the number of formulas, subformulas and terms in the given goal.
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...
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
unsigned Z3_API Z3_apply_result_get_num_subgoals(Z3_context c, Z3_apply_result r)
Return the number of subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
bool Z3_API Z3_rcf_is_infinitesimal(Z3_context c, Z3_rcf_num a)
Return true if a represents an infinitesimal.
Z3_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i)
Array read. The argument a is the array and i is the index of the array that gets read.
Z3_ast Z3_API Z3_mk_sign_ext(Z3_context c, unsigned i, Z3_ast t1)
Sign-extend of the given bit-vector to the (signed) equivalent bit-vector of size m+i,...
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.
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...
Z3_ast Z3_API Z3_mk_u32string(Z3_context c, unsigned len, unsigned const chars[])
Create a string constant out of the string that is passed in It takes the length of the string as wel...
void Z3_API Z3_fixedpoint_add_fact(Z3_context c, Z3_fixedpoint d, Z3_func_decl r, unsigned num_args, unsigned args[])
Add a Database fact.
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
Z3_func_decl Z3_API Z3_solver_propagate_declare(Z3_context c, Z3_symbol name, unsigned n, Z3_sort *domain, Z3_sort range)
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
Z3_ast Z3_API Z3_mk_select_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs)
n-ary Array read. The argument a is the array and idxs are the indices of the array that gets read.
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
Z3_sort Z3_API Z3_mk_datatype_sort(Z3_context c, Z3_symbol name, unsigned num_params, Z3_sort const params[])
create a forward reference to a recursive datatype being declared. The forward reference can be used ...
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
void Z3_API Z3_func_interp_inc_ref(Z3_context c, Z3_func_interp f)
Increment the reference counter of the given Z3_func_interp object.
Z3_func_decl Z3_API Z3_mk_piecewise_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a piecewise linear ordering relation over signature a and index id.
Z3_rcf_num Z3_API Z3_rcf_mk_infinitesimal(Z3_context c)
Return a new infinitesimal that is smaller than all elements in the Z3 field.
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 ...
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.
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
Z3_ast Z3_API Z3_optimize_get_upper(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
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.
Z3_ast Z3_API Z3_mk_fpa_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point greater than.
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.
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.
Z3_simplifier Z3_API Z3_simplifier_using_params(Z3_context c, Z3_simplifier t, Z3_params p)
Return a simplifier that applies t using the given set of parameters.
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, bool is_signed)
Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is t...
void Z3_API Z3_solver_import_model_converter(Z3_context ctx, Z3_solver src, Z3_solver dst)
Ad-hoc method for importing model conversion from solver.
bool Z3_API Z3_rcf_ge(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a >= b.
Z3_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow.
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
Z3_param_descrs Z3_API Z3_simplifier_get_param_descrs(Z3_context c, Z3_simplifier t)
Return the parameter description set for the given simplifier object.
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.
int Z3_API Z3_get_decl_int_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the integer value associated with an integer parameter.
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition z3_api.h:58
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
Z3_probe Z3_API Z3_mk_probe(Z3_context c, Z3_string name)
Return a probe associated with the given name. The complete list of probes may be obtained using the ...
Z3_tactic Z3_API Z3_tactic_when(Z3_context c, Z3_probe p, Z3_tactic t)
Return a tactic that applies t to a given goal is the probe p evaluates to true. If p evaluates to fa...
Z3_ast Z3_API Z3_mk_seq_suffix(Z3_context c, Z3_ast suffix, Z3_ast s)
Check if suffix is a suffix of s.
void Z3_API Z3_solver_set_initial_value(Z3_context c, Z3_solver s, Z3_ast v, Z3_ast val)
provide an initialization hint to the solver. The initialization hint is used to calibrate an initial...
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.
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx)
Return the unsigned value of the given statistical data.
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
Z3_ast Z3_API Z3_mk_fpa_eq(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point equality.
void Z3_API Z3_solver_propagate_register_cb(Z3_context c, Z3_solver_callback cb, Z3_ast e)
register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Ve...
Z3_ast Z3_API Z3_mk_bvmul_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflo...
void Z3_API Z3_add_const_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast a)
Add a constant interpretation.
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
void Z3_API Z3_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
Z3_ast Z3_API Z3_solver_congruence_root(Z3_context c, Z3_solver s, Z3_ast a)
retrieve the congruence closure root of an expression. The root is retrieved relative to the state wh...
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.
Z3_string Z3_API Z3_tactic_get_help(Z3_context c, Z3_tactic t)
Return a string containing a description of parameters accepted by the given tactic.
void Z3_API Z3_solver_propagate_final(Z3_context c, Z3_solver s, Z3_final_eh final_eh)
register a callback on final check. This provides freedom to the propagator to delay actions or imple...
Z3_parameter_kind
The different kinds of parameters that can be associated with function symbols.
Definition z3_api.h:94
Z3_ast_vector Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Parse the given string using the SMT-LIB2 parser.
Z3_ast Z3_API Z3_mk_fpa_geq(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point greater than or equal.
void Z3_API Z3_solver_register_on_clause(Z3_context c, Z3_solver s, void *user_context, Z3_on_clause_eh on_clause_eh)
register a callback to that retrieves assumed, inferred and deleted clauses during search.
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g, bool include_names)
Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF...
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
double Z3_API Z3_stats_get_double_value(Z3_context c, Z3_stats s, unsigned idx)
Return the double value of the given statistical data.
Z3_ast Z3_API Z3_mk_fpa_numeral_float(Z3_context c, float v, Z3_sort ty)
Create a numeral of FloatingPoint sort from a float.
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
unsigned Z3_API Z3_goal_depth(Z3_context c, Z3_goal g)
Return the depth of the given goal. It tracks how many transformations were applied to it.
Z3_ast Z3_API Z3_update_term(Z3_context c, Z3_ast a, unsigned num_args, Z3_ast const args[])
Update the arguments of term a using the arguments args. The number of arguments num_args should coin...
Z3_ast Z3_API Z3_mk_fpa_rtz(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
Z3_simplifier Z3_API Z3_mk_simplifier(Z3_context c, Z3_string name)
Return a simplifier associated with the given name. The complete list of simplifiers may be obtained ...
Z3_ast Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
Z3_ast Z3_API Z3_mk_seq_foldli(Z3_context c, Z3_ast f, Z3_ast i, Z3_ast a, Z3_ast s)
Create a fold with index tracking of the function f over the sequence s with accumulator a starting a...
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
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.
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.
Z3_ast_vector Z3_API Z3_optimize_get_objectives(Z3_context c, Z3_optimize o)
Return objectives on the optimization context. If the objective function is a max-sat objective it is...
Z3_ast Z3_API Z3_mk_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of the first occurrence of substr in s starting from offset offset. If s does not contai...
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
Z3_tactic Z3_API Z3_tactic_fail_if(Z3_context c, Z3_probe p)
Return a tactic that fails if the probe p evaluates to false.
void Z3_API Z3_goal_reset(Z3_context c, Z3_goal g)
Erase all formulas from the given goal.
void Z3_API Z3_func_interp_dec_ref(Z3_context c, Z3_func_interp f)
Decrement the reference counter of the given Z3_func_interp object.
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
Z3_ast Z3_API Z3_mk_distinct(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing distinct(args[0], ..., args[num_args-1]).
Z3_string Z3_API Z3_rcf_num_to_decimal_string(Z3_context c, Z3_rcf_num a, unsigned prec)
Convert the RCF numeral into a string in decimal notation.
Z3_ast Z3_API Z3_mk_seq_prefix(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if prefix is a prefix of s.
Z3_rcf_num Z3_API Z3_rcf_power(Z3_context c, Z3_rcf_num a, unsigned k)
Return the value a^k.
Z3_ast Z3_API Z3_solver_congruence_explain(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast b)
retrieve explanation for congruence.
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
Z3_ast Z3_API Z3_mk_fpa_rem(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point remainder.
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
Z3_probe Z3_API Z3_probe_or(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when p1 or p2 evaluates to true.
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
void Z3_API Z3_solver_propagate_init(Z3_context c, Z3_solver s, void *user_context, Z3_push_eh push_eh, Z3_pop_eh pop_eh, Z3_fresh_eh fresh_eh)
register a user-propagator with the solver.
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.
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.
Z3_ast Z3_API Z3_mk_bvnand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise nand.
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
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.
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.
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
Z3_ast Z3_API Z3_mk_bv_numeral(Z3_context c, unsigned sz, bool const *bits)
create a bit-vector numeral from a vector of Booleans.
void Z3_API Z3_func_entry_dec_ref(Z3_context c, Z3_func_entry e)
Decrement the reference counter of the given Z3_func_entry object.
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
Z3_ast Z3_API Z3_mk_fpa_min(Z3_context c, Z3_ast t1, Z3_ast t2)
Minimum of floating-point numbers.
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
Z3_ast Z3_API Z3_mk_seq_mapi(Z3_context c, Z3_ast f, Z3_ast i, Z3_ast s)
Create a map of the function f over the sequence s starting at index i.
Z3_ast Z3_API Z3_mk_bvneg_no_overflow(Z3_context c, Z3_ast t1)
Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector.
Z3_ast Z3_API Z3_mk_fpa_round_to_integral(Z3_context c, Z3_ast rm, Z3_ast t)
Floating-point roundToIntegral. Rounds a floating-point number to the closest integer,...
Z3_rcf_num Z3_API Z3_rcf_mk_small_int(Z3_context c, int val)
Return a RCF small integer.
Z3_string Z3_API Z3_stats_get_key(Z3_context c, Z3_stats s, unsigned idx)
Return the key (a string) for a particular statistical data.
Z3_ast Z3_API Z3_mk_re_diff(Z3_context c, Z3_ast re1, Z3_ast re2)
Create the difference of regular expressions.
unsigned Z3_API Z3_fixedpoint_get_num_levels(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred)
Query the PDR engine for the maximal levels properties are known about predicate.
Z3_ast Z3_API Z3_mk_int64(Z3_context c, int64_t v, Z3_sort ty)
Create a numeral of a int, bit-vector, or finite-domain sort.
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
Z3_ast Z3_API Z3_mk_fpa_add(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point addition.
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.
bool Z3_API Z3_goal_is_decided_unsat(Z3_context c, Z3_goal g)
Return true if the goal contains false, and it is precise or the product of an over approximation.
Z3_ast Z3_API Z3_mk_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
Z3_ast_vector Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows divisor).
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
Z3_string Z3_API Z3_fixedpoint_to_string(Z3_context c, Z3_fixedpoint f, unsigned num_queries, Z3_ast queries[])
Print the current rules and background axioms as a string.
void Z3_API Z3_solver_get_levels(Z3_context c, Z3_solver s, Z3_ast_vector literals, unsigned sz, unsigned levels[])
retrieve the decision depth of Boolean literals (variables or their negations). Assumes a check-sat c...
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort.
Z3_ast Z3_API Z3_mk_int2bv(Z3_context c, unsigned n, Z3_ast t1)
Create an n bit bit-vector from the integer argument t1.
void Z3_API Z3_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
Z3_tactic Z3_API Z3_mk_tactic(Z3_context c, Z3_string name)
Return a tactic associated with the given name. The complete list of tactics may be obtained using th...
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
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 Z3_API Z3_del_constructor_list(Z3_context c, Z3_constructor_list clist)
Reclaim memory allocated for constructor list.
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a variable.
Z3_ast Z3_API Z3_substitute_funs(Z3_context c, Z3_ast a, unsigned num_funs, Z3_func_decl const from[], Z3_ast const to[])
Substitute functions in from with new expressions in to.
Z3_ast Z3_API Z3_func_entry_get_arg(Z3_context c, Z3_func_entry e, unsigned i)
Return an argument of a Z3_func_entry object.
Z3_ast Z3_API Z3_mk_eq(Z3_context c, Z3_ast l, Z3_ast r)
Create an AST node representing l = r.
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
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...
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
Z3_string Z3_API Z3_rcf_num_to_string(Z3_context c, Z3_rcf_num a, bool compact, bool html)
Convert the RCF numeral into a string.
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.
Z3_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id)
create a partial ordering relation over signature a and index id.
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
bool Z3_API Z3_rcf_neq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a != b.
void Z3_API Z3_solver_solve_for(Z3_context c, Z3_solver s, Z3_ast_vector variables, Z3_ast_vector terms, Z3_ast_vector guards)
retrieve a 'solution' for variables as defined by equalities in maintained by solvers....
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
void Z3_API Z3_rcf_del(Z3_context c, Z3_rcf_num a)
Delete a RCF numeral created using the RCF API.
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
Z3_goal_prec Z3_API Z3_goal_precision(Z3_context c, Z3_goal g)
Return the "precision" of the given goal. Goals can be transformed using over and under approximation...
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
Z3_goal Z3_API Z3_mk_goal(Z3_context c, bool models, bool unsat_cores, bool proofs)
Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or trans...
double Z3_API Z3_get_decl_double_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
Z3_ast Z3_API Z3_mk_fpa_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point less than.
Z3_ast Z3_API Z3_mk_unsigned_int64(Z3_context c, uint64_t v, Z3_sort ty)
Create a numeral of a int, bit-vector, or finite-domain sort.
Z3_rcf_num Z3_API Z3_rcf_mk_pi(Z3_context c)
Return Pi.
Z3_string Z3_API Z3_optimize_get_help(Z3_context c, Z3_optimize t)
Return a string containing a description of parameters accepted by optimize.
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
Z3_stats Z3_API Z3_optimize_get_statistics(Z3_context c, Z3_optimize d)
Retrieve statistics information from the last call to Z3_optimize_check.
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
Z3_probe Z3_API Z3_probe_gt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than the value retur...
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.
Z3_string Z3_API Z3_get_decl_rational_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the rational value, as a string, associated with a rational parameter.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
Z3_stats Z3_API Z3_fixedpoint_get_statistics(Z3_context c, Z3_fixedpoint d)
Retrieve statistics information from the last call to Z3_fixedpoint_query.
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.
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.
Z3_ast Z3_API Z3_mk_real_int64(Z3_context c, int64_t num, int64_t den)
Create a real from a fraction of int64.
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
Z3_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast s, Z3_ast substr)
Return index of the last occurrence of substr in s. If s does not contain substr, then the value is -...
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
void Z3_API Z3_solver_propagate_eq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression equalities.
Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string s)
Create a string constant out of the string that is passed in The string may contain escape encoding f...
Z3_tactic Z3_API Z3_tactic_try_for(Z3_context c, Z3_tactic t, unsigned ms)
Return a tactic that applies t to a given goal for ms milliseconds. If t does not terminate in ms mil...
void Z3_API Z3_apply_result_dec_ref(Z3_context c, Z3_apply_result r)
Decrement the reference counter of the given Z3_apply_result object.
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort s)
Create a sequence sort out of the sort for the elements.
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s)
Return the set of units modulo model conversion.
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
Z3_goal Z3_API Z3_apply_result_get_subgoal(Z3_context c, Z3_apply_result r, unsigned i)
Return one of the subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
Z3_probe Z3_API Z3_probe_le(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the va...
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
Z3_rcf_num Z3_API Z3_rcf_neg(Z3_context c, Z3_rcf_num a)
Return the value -a.
Z3_ast Z3_API Z3_mk_array_ext(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create array extensionality index given two arrays with the same sort. The meaning is given by the ax...
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
Z3_func_entry Z3_API Z3_func_interp_get_entry(Z3_context c, Z3_func_interp f, unsigned i)
Return a "point" of the given function interpretation. It represents the value of f in a particular p...
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a recursive function.
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
Z3_sort Z3_API Z3_get_decl_sort_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the sort value associated with a sort parameter.
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.
Z3_ast Z3_API Z3_mk_fpa_leq(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point less than or equal.
void Z3_API Z3_solver_propagate_created(Z3_context c, Z3_solver s, Z3_created_eh created_eh)
register a callback when a new expression with a registered function is used by the solver The regist...
bool Z3_API Z3_rcf_is_algebraic(Z3_context c, Z3_rcf_num a)
Return true if a represents an algebraic number.
Z3_ast Z3_API Z3_mk_fpa_numeral_double(Z3_context c, double v, Z3_sort ty)
Create a numeral of FloatingPoint sort from a double.
Z3_ast Z3_API Z3_mk_fpa_mul(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point multiplication.
Z3_ast Z3_API Z3_mk_app(Z3_context c, Z3_func_decl d, unsigned num_args, Z3_ast const args[])
Create a constant or function application.
Z3_stats Z3_API Z3_solver_get_statistics(Z3_context c, Z3_solver s)
Return statistics for the given solver.
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast t1)
Standard two's complement unary minus.
Z3_ast Z3_API Z3_mk_store_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs, Z3_ast v)
n-ary Array update.
Z3_string Z3_API Z3_fixedpoint_get_reason_unknown(Z3_context c, Z3_fixedpoint d)
Retrieve a string that describes the last status returned by Z3_fixedpoint_query.
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a linear ordering relation over signature a. The relation is identified by the index id.
Z3_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
Z3_ast Z3_API Z3_mk_seq_in_re(Z3_context c, Z3_ast seq, Z3_ast re)
Check if seq is in the language generated by the regular expression re.
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
Z3_ast Z3_API Z3_mk_sub(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] - ... - args[num_args - 1].
Z3_string Z3_API Z3_solver_to_dimacs_string(Z3_context c, Z3_solver s, bool include_names)
Convert a solver into a DIMACS formatted string.
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.
void Z3_API Z3_solver_propagate_decide(Z3_context c, Z3_solver s, Z3_decide_eh decide_eh)
register a callback when the solver decides to split on a registered expression. The callback may cha...
Z3_ast Z3_API Z3_mk_lstring(Z3_context c, unsigned len, Z3_string s)
Create a string constant out of the string that is passed in It takes the length of the string as wel...
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
double Z3_API Z3_probe_apply(Z3_context c, Z3_probe p, Z3_goal g)
Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0....
bool Z3_API Z3_rcf_is_transcendental(Z3_context c, Z3_rcf_num a)
Return true if a represents a transcendental number.
void Z3_API Z3_func_interp_set_else(Z3_context c, Z3_func_interp f, Z3_ast else_value)
Return the 'else' value of the given function interpretation.
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
void Z3_API Z3_solver_propagate_register(Z3_context c, Z3_solver s, Z3_ast e)
register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Ve...
Z3_ast Z3_API Z3_substitute_vars(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const to[])
Substitute the variables in a with the expressions in to. For every i smaller than num_exprs,...
Z3_ast Z3_API Z3_mk_or(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] or ... or args[num_args-1].
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
Z3_tactic Z3_API Z3_tactic_or_else(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that first applies t1 to a given goal, if it fails then returns the result of t2 appl...
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.
Z3_ast Z3_API Z3_mk_fpa_div(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point division.
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_sqrt(Z3_context c, Z3_ast rm, Z3_ast t)
Floating-point square root.
bool Z3_API Z3_goal_is_decided_sat(Z3_context c, Z3_goal g)
Return true if the goal is empty, and it is precise or the product of a under approximation.
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.
void Z3_API Z3_optimize_from_string(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives....
Z3_solver Z3_API Z3_solver_add_simplifier(Z3_context c, Z3_solver solver, Z3_simplifier simplifier)
Attach simplifier to a solver. The solver will use the simplifier for incremental pre-processing.
Z3_ast Z3_API Z3_mk_rem(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 rem arg2.
Z3_ast Z3_API Z3_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
bool Z3_API Z3_rcf_is_rational(Z3_context c, Z3_rcf_num a)
Return true if a represents a rational number.
void Z3_API Z3_solver_propagate_fixed(Z3_context c, Z3_solver s, Z3_fixed_eh fixed_eh)
register a callback for when an expression is bound to a fixed value. The supported expression types ...
Z3_ast Z3_API Z3_mk_seq_map(Z3_context c, Z3_ast f, Z3_ast s)
Create a map of the function f over the sequence s.
void Z3_API Z3_fixedpoint_register_relation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f)
Register relation as Fixedpoint defined. Fixedpoint defined relations have least-fixedpoint semantics...
void Z3_API Z3_fixedpoint_add_cover(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred, Z3_ast property)
Add property about the predicate pred. Add a property of predicate pred at level. It gets pushed forw...
void Z3_API Z3_func_interp_add_entry(Z3_context c, Z3_func_interp fi, Z3_ast_vector args, Z3_ast value)
add a function entry to a function interpretation.
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
Z3_lbool Z3_API Z3_fixedpoint_query_relations(Z3_context c, Z3_fixedpoint d, unsigned num_relations, Z3_func_decl const relations[])
Pose multiple queries against the asserted rules.
Z3_ast Z3_API Z3_mk_as_array(Z3_context c, Z3_func_decl f)
Create array with the same interpretation as a function. The array satisfies the property (f x) = (se...
Z3_string Z3_API Z3_apply_result_to_string(Z3_context c, Z3_apply_result r)
Convert the Z3_apply_result object returned by Z3_tactic_apply into a string.
Z3_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.
Z3_ast Z3_API Z3_mk_seq_foldl(Z3_context c, Z3_ast f, Z3_ast a, Z3_ast s)
Create a fold of the function f over the sequence s with accumulator a.
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...
Z3_ast Z3_API Z3_mk_fpa_fma(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Floating-point fused multiply-add.
Z3_rcf_num Z3_API Z3_rcf_mk_e(Z3_context c)
Return e (Euler's constant)
Z3_tactic Z3_API Z3_tactic_repeat(Z3_context c, Z3_tactic t, unsigned max)
Return a tactic that keeps applying t until the goal is not modified anymore or the maximum number of...
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
Z3_lbool Z3_API Z3_optimize_check(Z3_context c, Z3_optimize o, unsigned num_assumptions, Z3_ast const assumptions[])
Check consistency and produce optimal values.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
unsigned Z3_API Z3_func_interp_get_num_entries(Z3_context c, Z3_func_interp f)
Return the number of entries in the given function interpretation.
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort const sorts[], unsigned sort_refs[])
Create a constructor.
Z3_sort Z3_API Z3_mk_fpa_rounding_mode_sort(Z3_context c)
Create the RoundingMode sort.
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
Z3_ast Z3_API Z3_mk_fpa_rne(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
Z3_tactic Z3_API Z3_tactic_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and t2 to every subgoal produced by t1.
Z3_optimize Z3_API Z3_optimize_translate(Z3_context c, Z3_optimize o, Z3_context target)
Copy an optimization context from a source to a target context.
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...
void Z3_API Z3_solver_inc_ref(Z3_context c, Z3_solver s)
Increment the reference counter of the given solver.
bool Z3_API Z3_solver_next_split(Z3_context c, Z3_solver_callback cb, Z3_ast t, unsigned idx, Z3_lbool phase)
Z3_probe Z3_API Z3_probe_and(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when p1 and p2 evaluates to true.
bool Z3_API Z3_is_re_sort(Z3_context c, Z3_sort s)
Check if s is a regular expression sort.
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for unicode strings.
Z3_rcf_num Z3_API Z3_rcf_mul(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return the value a * b.
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a)
Return idx_a'th accessor for the idx_c'th constructor.
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
@ Z3_APP_AST
Definition z3_api.h:144
@ Z3_VAR_AST
Definition z3_api.h:145
@ Z3_SORT_AST
Definition z3_api.h:147
@ Z3_NUMERAL_AST
Definition z3_api.h:143
@ Z3_FUNC_DECL_AST
Definition z3_api.h:148
@ Z3_QUANTIFIER_AST
Definition z3_api.h:146
System.IntPtr Z3_model
System.IntPtr Z3_app
System.IntPtr Z3_context
Definition Context.cs:29
System.IntPtr Z3_ast_vector
System.IntPtr Z3_func_interp
System.IntPtr Z3_func_decl
System.IntPtr Z3_stats
System.IntPtr Z3_ast
System.IntPtr Z3_func_entry
System.IntPtr Z3_solver
System.IntPtr Z3_solver_callback
System.IntPtr Z3_sort
System.IntPtr Z3_symbol
expr set_intersect(expr const &a, expr const &b)
Definition z3++.h:4243
expr re_intersect(expr_vector const &args)
Definition z3++.h:4325
expr store(expr const &a, expr const &i, expr const &v)
Definition z3++.h:4165
expr pw(expr const &a, expr const &b)
Definition z3++.h:1724
expr sbv_to_fpa(expr const &t, sort s)
Definition z3++.h:2148
expr bvneg_no_overflow(expr const &a)
Definition z3++.h:2349
expr indexof(expr const &s, expr const &substr, expr const &offset)
Definition z3++.h:4288
tactic par_or(unsigned n, tactic const *tactics)
Definition z3++.h:3323
tactic par_and_then(tactic const &t1, tactic const &t2)
Definition z3++.h:3332
expr srem(expr const &a, expr const &b)
signed remainder operator for bitvectors
Definition z3++.h:2281
expr bvadd_no_underflow(expr const &a, expr const &b)
Definition z3++.h:2337
expr prefixof(expr const &a, expr const &b)
Definition z3++.h:4282
expr sum(expr_vector const &args)
Definition z3++.h:2546
expr ugt(expr const &a, expr const &b)
unsigned greater than operator for bitvectors.
Definition z3++.h:2260
expr operator/(expr const &a, expr const &b)
Definition z3++.h:1890
expr exists(expr const &x, expr const &b)
Definition z3++.h:2457
expr fp_eq(expr const &a, expr const &b)
Definition z3++.h:2109
func_decl tree_order(sort const &a, unsigned index)
Definition z3++.h:2374
expr concat(expr const &a, expr const &b)
Definition z3++.h:2564
expr bvmul_no_underflow(expr const &a, expr const &b)
Definition z3++.h:2355
expr lambda(expr const &x, expr const &b)
Definition z3++.h:2481
ast_vector_tpl< func_decl > func_decl_vector
Definition z3++.h:79
expr fpa_to_fpa(expr const &t, sort s)
Definition z3++.h:2162
expr operator&&(expr const &a, expr const &b)
Definition z3++.h:1768
std::function< void(expr const &proof, std::vector< unsigned > const &deps, expr_vector const &clause)> on_clause_eh_t
Definition z3++.h:4492
expr operator!=(expr const &a, expr const &b)
Definition z3++.h:1804
expr operator+(expr const &a, expr const &b)
Definition z3++.h:1816
expr set_complement(expr const &a)
Definition z3++.h:4255
check_result
Definition z3++.h:166
func_decl recfun(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition z3++.h:4135
expr const_array(sort const &d, expr const &v)
Definition z3++.h:4215
expr min(expr const &a, expr const &b)
Definition z3++.h:2038
expr set_difference(expr const &a, expr const &b)
Definition z3++.h:4251
expr forall(expr const &x, expr const &b)
Definition z3++.h:2433
expr array_default(expr const &a)
Definition z3++.h:4191
expr array_ext(expr const &a, expr const &b)
Definition z3++.h:4197
expr operator>(expr const &a, expr const &b)
Definition z3++.h:2001
sort to_sort(context &c, Z3_sort s)
Definition z3++.h:2203
expr to_expr(context &c, Z3_ast a)
Wraps a Z3_ast as an expr object. It also checks for errors. This function allows the user to use the...
Definition z3++.h:2194
expr bv2int(expr const &a, bool is_signed)
bit-vector and integer conversions.
Definition z3++.h:2328
expr operator%(expr const &a, expr const &b)
Definition z3++.h:1739
expr operator~(expr const &a)
Definition z3++.h:2116
expr sle(expr const &a, expr const &b)
signed less than or equal to operator for bitvectors.
Definition z3++.h:2216
expr nor(expr const &a, expr const &b)
Definition z3++.h:2036
expr fpa_fp(expr const &sgn, expr const &exp, expr const &sig)
Definition z3++.h:2126
expr bvsub_no_underflow(expr const &a, expr const &b, bool is_signed)
Definition z3++.h:2343
expr mk_xor(expr_vector const &args)
Definition z3++.h:2648
expr lshr(expr const &a, expr const &b)
logic shift right operator for bitvectors
Definition z3++.h:2309
expr operator*(expr const &a, expr const &b)
Definition z3++.h:1846
expr nand(expr const &a, expr const &b)
Definition z3++.h:2035
expr fpa_to_ubv(expr const &t, unsigned sz)
Definition z3++.h:2141
expr bvredor(expr const &a)
Definition z3++.h:2070
ast_vector_tpl< sort > sort_vector
Definition z3++.h:78
func_decl piecewise_linear_order(sort const &a, unsigned index)
Definition z3++.h:2371
expr slt(expr const &a, expr const &b)
signed less than operator for bitvectors.
Definition z3++.h:2222
tactic when(probe const &p, tactic const &t)
Definition z3++.h:3642
expr last_indexof(expr const &s, expr const &substr)
Definition z3++.h:4294
expr int2bv(unsigned n, expr const &a)
Definition z3++.h:2329
expr max(expr const &a, expr const &b)
Definition z3++.h:2054
expr xnor(expr const &a, expr const &b)
Definition z3++.h:2037
expr udiv(expr const &a, expr const &b)
unsigned division operator for bitvectors.
Definition z3++.h:2274
expr abs(expr const &a)
Definition z3++.h:2082
expr pbge(expr_vector const &es, int const *coeffs, int bound)
Definition z3++.h:2514
expr round_fpa_to_closest_integer(expr const &t)
Definition z3++.h:2169
expr distinct(expr_vector const &args)
Definition z3++.h:2555
expr ashr(expr const &a, expr const &b)
arithmetic shift right operator for bitvectors
Definition z3++.h:2316
expr bvmul_no_overflow(expr const &a, expr const &b, bool is_signed)
Definition z3++.h:2352
expr bvsub_no_overflow(expr const &a, expr const &b)
Definition z3++.h:2340
expr star(expr const &re)
Definition z3++.h:4312
expr urem(expr const &a, expr const &b)
unsigned reminder operator for bitvectors
Definition z3++.h:2295
tactic repeat(tactic const &t, unsigned max=UINT_MAX)
Definition z3++.h:3307
expr mod(expr const &a, expr const &b)
Definition z3++.h:1728
expr fma(expr const &a, expr const &b, expr const &c, expr const &rm)
Definition z3++.h:2118
check_result to_check_result(Z3_lbool l)
Definition z3++.h:178
expr mk_or(expr_vector const &args)
Definition z3++.h:2636
expr to_re(expr const &s)
Definition z3++.h:4300
void check_context(object const &a, object const &b)
Definition z3++.h:544
expr_vector polynomial_subresultants(expr const &p, expr const &q, expr const &x)
Return the nonzero subresultants of p and q with respect to the "variable" x.
Definition z3++.h:2384
std::ostream & operator<<(std::ostream &out, exception const &e)
Definition z3++.h:128
expr ule(expr const &a, expr const &b)
unsigned less than or equal to operator for bitvectors.
Definition z3++.h:2242
func_decl to_func_decl(context &c, Z3_func_decl f)
Definition z3++.h:2208
tactic with(tactic const &t, params const &p)
Definition z3++.h:3313
expr ite(expr const &c, expr const &t, expr const &e)
Create the if-then-else expression ite(c, t, e)
Definition z3++.h:2181
expr ult(expr const &a, expr const &b)
unsigned less than operator for bitvectors.
Definition z3++.h:2248
expr pbeq(expr_vector const &es, int const *coeffs, int bound)
Definition z3++.h:2522
expr operator^(expr const &a, expr const &b)
Definition z3++.h:2027
expr operator<=(expr const &a, expr const &b)
Definition z3++.h:1954
expr set_union(expr const &a, expr const &b)
Definition z3++.h:4235
expr operator>=(expr const &a, expr const &b)
Definition z3++.h:1870
func_decl linear_order(sort const &a, unsigned index)
Definition z3++.h:2365
expr sqrt(expr const &a, expr const &rm)
Definition z3++.h:2102
expr pble(expr_vector const &es, int const *coeffs, int bound)
Definition z3++.h:2506
expr operator==(expr const &a, expr const &b)
Definition z3++.h:1793
expr foldli(expr const &f, expr const &i, expr const &a, expr const &list)
Definition z3++.h:2629
expr full_set(sort const &s)
Definition z3++.h:4223
std::vector< rcf_num > rcf_roots(context &c, std::vector< rcf_num > const &coeffs)
Find roots of a polynomial with given coefficients.
Definition z3++.h:5013
expr smod(expr const &a, expr const &b)
signed modulus operator for bitvectors
Definition z3++.h:2288
expr implies(expr const &a, expr const &b)
Definition z3++.h:1716
expr empty_set(sort const &s)
Definition z3++.h:4219
expr in_re(expr const &s, expr const &re)
Definition z3++.h:4303
expr bvadd_no_overflow(expr const &a, expr const &b, bool is_signed)
bit-vector overflow/underflow checks
Definition z3++.h:2334
expr suffixof(expr const &a, expr const &b)
Definition z3++.h:4276
expr re_diff(expr const &a, expr const &b)
Definition z3++.h:4333
expr set_add(expr const &s, expr const &e)
Definition z3++.h:4227
rcf_num rcf_e(context &c)
Create an RCF numeral representing e (Euler's constant).
Definition z3++.h:4996
expr plus(expr const &re)
Definition z3++.h:4306
expr set_subset(expr const &a, expr const &b)
Definition z3++.h:4263
expr select(expr const &a, expr const &i)
forward declarations
Definition z3++.h:4148
expr bvredand(expr const &a)
Definition z3++.h:2076
expr operator&(expr const &a, expr const &b)
Definition z3++.h:2023
expr operator-(expr const &a)
Definition z3++.h:1912
expr set_member(expr const &s, expr const &e)
Definition z3++.h:4259
expr bvsdiv_no_overflow(expr const &a, expr const &b)
Definition z3++.h:2346
tactic try_for(tactic const &t, unsigned ms)
Definition z3++.h:3318
expr sdiv(expr const &a, expr const &b)
signed division operator for bitvectors.
Definition z3++.h:2267
func_decl partial_order(sort const &a, unsigned index)
Definition z3++.h:2368
ast_vector_tpl< expr > expr_vector
Definition z3++.h:77
expr rem(expr const &a, expr const &b)
Definition z3++.h:1744
expr sge(expr const &a, expr const &b)
signed greater than or equal to operator for bitvectors.
Definition z3++.h:2228
expr operator!(expr const &a)
Definition z3++.h:1762
expr re_empty(sort const &s)
Definition z3++.h:4315
expr foldl(expr const &f, expr const &a, expr const &list)
Definition z3++.h:2622
rcf_num rcf_pi(context &c)
Create an RCF numeral representing pi.
Definition z3++.h:4989
expr mk_and(expr_vector const &args)
Definition z3++.h:2642
@ RNE
Definition z3++.h:172
@ RNA
Definition z3++.h:171
@ RTZ
Definition z3++.h:175
@ RTN
Definition z3++.h:174
@ RTP
Definition z3++.h:173
expr sext(expr const &a, unsigned i)
Sign-extend of the given bit-vector to the (signed) equivalent bitvector of size m+i,...
Definition z3++.h:2363
expr to_real(expr const &a)
Definition z3++.h:4105
expr shl(expr const &a, expr const &b)
shift left operator for bitvectors
Definition z3++.h:2302
expr operator||(expr const &a, expr const &b)
Definition z3++.h:1780
expr set_del(expr const &s, expr const &e)
Definition z3++.h:4231
expr ubv_to_fpa(expr const &t, sort s)
Definition z3++.h:2155
expr map(expr const &f, expr const &list)
Definition z3++.h:2608
tactic cond(probe const &p, tactic const &t1, tactic const &t2)
Definition z3++.h:3648
expr as_array(func_decl &f)
Definition z3++.h:4185
expr sgt(expr const &a, expr const &b)
signed greater than operator for bitvectors.
Definition z3++.h:2234
expr fpa_to_sbv(expr const &t, unsigned sz)
Definition z3++.h:2134
expr operator|(expr const &a, expr const &b)
Definition z3++.h:2031
expr atmost(expr_vector const &es, unsigned bound)
Definition z3++.h:2530
expr range(expr const &lo, expr const &hi)
Definition z3++.h:4343
expr zext(expr const &a, unsigned i)
Extend the given bit-vector with zeros to the (unsigned) equivalent bitvector of size m+i,...
Definition z3++.h:2323
expr atleast(expr_vector const &es, unsigned bound)
Definition z3++.h:2538
expr uge(expr const &a, expr const &b)
unsigned greater than or equal to operator for bitvectors.
Definition z3++.h:2254
expr mapi(expr const &f, expr const &i, expr const &list)
Definition z3++.h:2615
expr operator<(expr const &a, expr const &b)
Definition z3++.h:1979
expr option(expr const &re)
Definition z3++.h:4309
expr re_full(sort const &s)
Definition z3++.h:4320
expr re_complement(expr const &a)
Definition z3++.h:4340
expr empty(sort const &s)
Definition z3++.h:4271
rcf_num rcf_infinitesimal(context &c)
Create an RCF numeral representing an infinitesimal.
Definition z3++.h:5003
tactic fail_if(probe const &p)
Definition z3++.h:3637
_on_clause_eh
Definition z3py.py:11831
bool is_int(a)
Definition z3py.py:2840
bool eq(AstRef a, AstRef b)
Definition z3py.py:503
on_clause_eh(ctx, p, n, dep, clause)
Definition z3py.py:11824
#define _Z3_MK_BIN_(a, b, binop)
Definition z3++.h:1709
#define MK_EXPR1(_fn, _arg)
Definition z3++.h:4204
#define MK_EXPR2(_fn, _arg1, _arg2)
Definition z3++.h:4209
#define Z3_THROW(x)
Definition z3++.h:134
#define _Z3_MK_UN_(a, mkun)
Definition z3++.h:1756

◆ _Z3_MK_UN_

#define _Z3_MK_UN_ (   a,
  mkun 
)
Value:
Z3_ast r = mkun(a.ctx(), a); \
a.check_error(); \
return expr(a.ctx(), r); \

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

◆ MK_EXPR1

#define MK_EXPR1 (   _fn,
  _arg 
)
Value:
Z3_ast r = _fn(_arg.ctx(), _arg); \
_arg.check_error(); \
return expr(_arg.ctx(), r);

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

◆ MK_EXPR2

#define MK_EXPR2 (   _fn,
  _arg1,
  _arg2 
)
Value:
check_context(_arg1, _arg2); \
Z3_ast r = _fn(_arg1.ctx(), _arg1, _arg2); \
_arg1.check_error(); \
return expr(_arg1.ctx(), r);

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

◆ Z3_THROW

#define Z3_THROW (   x)    {}

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