Z3
z3++.h
Go to the documentation of this file.
1 /*++
2 Copyright (c) 2012 Microsoft Corporation
3 
4  Thin C++ layer on top of the Z3 C API.
5  Main features:
6  - Smart pointers for all Z3 objects.
7  - Object-Oriented interface.
8  - Operator overloading.
9  - Exceptions for signaling Z3 errors
10 
11  The C API can be used simultaneously with the C++ layer.
12  However, if you use the C API directly, you will have to check the error conditions manually.
13  Of course, you can invoke the method check_error() of the context object.
14 Author:
15 
16  Leonardo (leonardo) 2012-03-28
17 
18 Notes:
19 
20 --*/
21 #pragma once
22 
23 #include<cassert>
24 #include<ostream>
25 #include<string>
26 #include<memory>
27 #include<vector>
28 #include<z3.h>
29 #include<limits.h>
30 #include<functional>
31 
32 #undef min
33 #undef max
34 
49 namespace z3 {
50 
51  class exception;
52  class config;
53  class context;
54  class symbol;
55  class params;
56  class param_descrs;
57  class ast;
58  class sort;
59  class constructors;
60  class constructor_list;
61  class func_decl;
62  class expr;
63  class solver;
64  class goal;
65  class tactic;
66  class simplifier;
67  class probe;
68  class model;
69  class func_interp;
70  class func_entry;
71  class statistics;
72  class apply_result;
73  template<typename T> class cast_ast;
74  template<typename T> class ast_vector_tpl;
79 
80  inline void set_param(char const * param, char const * value) { Z3_global_param_set(param, value); }
81  inline void set_param(char const * param, bool value) { Z3_global_param_set(param, value ? "true" : "false"); }
82  inline void set_param(char const * param, int value) { auto str = std::to_string(value); Z3_global_param_set(param, str.c_str()); }
84 
88  class exception : public std::exception {
89  std::string m_msg;
90  public:
91  virtual ~exception() throw() = default;
92  exception(char const * msg):m_msg(msg) {}
93  char const * msg() const { return m_msg.c_str(); }
94  char const * what() const throw() { return m_msg.c_str(); }
95  friend std::ostream & operator<<(std::ostream & out, exception const & e);
96  };
97  inline std::ostream & operator<<(std::ostream & out, exception const & e) { out << e.msg(); return out; }
98 
99 #if !defined(Z3_THROW)
100 #if __cpp_exceptions || _CPPUNWIND || __EXCEPTIONS
101 #define Z3_THROW(x) throw x
102 #else
103 #define Z3_THROW(x) {}
104 #endif
105 #endif // !defined(Z3_THROW)
106 
110  class config {
111  Z3_config m_cfg;
112  config(config const &) = delete;
113  config & operator=(config const &) = delete;
114  public:
115  config() { m_cfg = Z3_mk_config(); }
116  ~config() { Z3_del_config(m_cfg); }
117  operator Z3_config() const { return m_cfg; }
121  void set(char const * param, char const * value) { Z3_set_param_value(m_cfg, param, value); }
125  void set(char const * param, bool value) { Z3_set_param_value(m_cfg, param, value ? "true" : "false"); }
129  void set(char const * param, int value) {
130  auto str = std::to_string(value);
131  Z3_set_param_value(m_cfg, param, str.c_str());
132  }
133  };
134 
137  };
138 
145  };
146 
148  if (l == Z3_L_TRUE) return sat;
149  else if (l == Z3_L_FALSE) return unsat;
150  return unknown;
151  }
152 
153 
154 
160  class context {
161  private:
162  friend class user_propagator_base;
163  bool m_enable_exceptions = true;
164  rounding_mode m_rounding_mode;
165  Z3_context m_ctx = nullptr;
166  void init(config & c) {
167  set_context(Z3_mk_context_rc(c));
168  }
169  void set_context(Z3_context ctx) {
170  m_ctx = ctx;
171  m_enable_exceptions = true;
172  m_rounding_mode = RNE;
173  Z3_set_error_handler(m_ctx, 0);
175  }
176 
177 
178  context(context const &) = delete;
179  context & operator=(context const &) = delete;
180 
181  context(Z3_context c) { set_context(c); }
182  void detach() { m_ctx = nullptr; }
183  public:
184  context() { config c; init(c); }
185  context(config & c) { init(c); }
186  ~context() { if (m_ctx) Z3_del_context(m_ctx); }
187  operator Z3_context() const { return m_ctx; }
188 
193  Z3_error_code e = Z3_get_error_code(m_ctx);
194  if (e != Z3_OK && enable_exceptions())
195  Z3_THROW(exception(Z3_get_error_msg(m_ctx, e)));
196  return e;
197  }
198 
199  void check_parser_error() const {
200  check_error();
201  }
202 
210  void set_enable_exceptions(bool f) { m_enable_exceptions = f; }
211 
212  bool enable_exceptions() const { return m_enable_exceptions; }
213 
217  void set(char const * param, char const * value) { Z3_update_param_value(m_ctx, param, value); }
221  void set(char const * param, bool value) { Z3_update_param_value(m_ctx, param, value ? "true" : "false"); }
225  void set(char const * param, int value) {
226  auto str = std::to_string(value);
227  Z3_update_param_value(m_ctx, param, str.c_str());
228  }
229 
234  void interrupt() { Z3_interrupt(m_ctx); }
235 
239  symbol str_symbol(char const * s);
243  symbol int_symbol(int n);
247  sort bool_sort();
251  sort int_sort();
255  sort real_sort();
259  sort bv_sort(unsigned sz);
260 
264  sort char_sort();
268  sort string_sort();
272  sort seq_sort(sort& s);
282  sort array_sort(sort d, sort r);
283  sort array_sort(sort_vector const& d, sort r);
290  sort fpa_sort(unsigned ebits, unsigned sbits);
294  template<size_t precision>
295  sort fpa_sort();
309  sort enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts);
310 
317  func_decl tuple_sort(char const * name, unsigned n, char const * const * names, sort const* sorts, func_decl_vector & projs);
318 
319 
328  sort datatype(symbol const& name, constructors const& cs);
329 
336  sort_vector datatypes(unsigned n, symbol const* names,
337  constructor_list *const* cons);
338 
339 
344  sort datatype_sort(symbol const& name);
345 
346 
350  sort uninterpreted_sort(char const* name);
351  sort uninterpreted_sort(symbol const& name);
352 
353  func_decl function(symbol const & name, unsigned arity, sort const * domain, sort const & range);
354  func_decl function(char const * name, unsigned arity, sort const * domain, sort const & range);
355  func_decl function(symbol const& name, sort_vector const& domain, sort const& range);
356  func_decl function(char const * name, sort_vector const& domain, sort const& range);
357  func_decl function(char const * name, sort const & domain, sort const & range);
358  func_decl function(char const * name, sort const & d1, sort const & d2, sort const & range);
359  func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & range);
360  func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & range);
361  func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & d5, sort const & range);
362 
363  func_decl recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range);
364  func_decl recfun(symbol const & name, const sort_vector& domain, sort const & range);
365  func_decl recfun(char const * name, sort_vector const& domain, sort const & range);
366  func_decl recfun(char const * name, unsigned arity, sort const * domain, sort const & range);
367  func_decl recfun(char const * name, sort const & domain, sort const & range);
368  func_decl recfun(char const * name, sort const & d1, sort const & d2, sort const & range);
369 
376  void recdef(func_decl decl, expr_vector const& args, expr const& body);
377  func_decl user_propagate_function(symbol const& name, sort_vector const& domain, sort const& range);
378 
382  expr constant(symbol const & name, sort const & s);
383  expr constant(char const * name, sort const & s);
387  expr bool_const(char const * name);
388  expr int_const(char const * name);
389  expr real_const(char const * name);
390  expr string_const(char const * name);
391  expr bv_const(char const * name, unsigned sz);
392  expr fpa_const(char const * name, unsigned ebits, unsigned sbits);
393 
394  template<size_t precision>
395  expr fpa_const(char const * name);
396 
400  expr variable(unsigned index, sort const& s);
401 
402 
404 
405  expr bool_val(bool b);
406 
407  expr int_val(int n);
408  expr int_val(unsigned n);
409  expr int_val(int64_t n);
410  expr int_val(uint64_t n);
411  expr int_val(char const * n);
412 
413  expr real_val(int n);
414  expr real_val(unsigned n);
415  expr real_val(int64_t n);
416  expr real_val(uint64_t n);
417  expr real_val(int64_t n, int64_t d);
418  expr real_val(char const * n);
419 
420  expr bv_val(int n, unsigned sz);
421  expr bv_val(unsigned n, unsigned sz);
422  expr bv_val(int64_t n, unsigned sz);
423  expr bv_val(uint64_t n, unsigned sz);
424  expr bv_val(char const * n, unsigned sz);
425  expr bv_val(unsigned n, bool const* bits);
426 
427  expr fpa_val(double n);
428  expr fpa_val(float n);
429  expr fpa_nan(sort const & s);
430  expr fpa_inf(sort const & s, bool sgn);
431 
432  expr string_val(char const* s);
433  expr string_val(char const* s, unsigned n);
434  expr string_val(std::string const& s);
435  expr string_val(std::u32string const& s);
436 
437  expr num_val(int n, sort const & s);
438 
442  expr_vector parse_string(char const* s);
443  expr_vector parse_file(char const* file);
444 
445  expr_vector parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
446  expr_vector parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
447  };
448 
449 
450  template<typename T>
451  class array {
452  std::unique_ptr<T[]> m_array;
453  unsigned m_size;
454  array(array const &) = delete;
455  array & operator=(array const &) = delete;
456  public:
457  array(unsigned sz):m_array(new T[sz]),m_size(sz) {}
458  template<typename T2>
459  array(ast_vector_tpl<T2> const & v);
460  void resize(unsigned sz) { m_array.reset(new T[sz]); m_size = sz; }
461  unsigned size() const { return m_size; }
462  T & operator[](int i) { assert(0 <= i); assert(static_cast<unsigned>(i) < m_size); return m_array[i]; }
463  T const & operator[](int i) const { assert(0 <= i); assert(static_cast<unsigned>(i) < m_size); return m_array[i]; }
464  T const * ptr() const { return m_array.get(); }
465  T * ptr() { return m_array.get(); }
466  };
467 
468  class object {
469  protected:
471  public:
472  object(context & c):m_ctx(&c) {}
473  virtual ~object() = default;
474  context & ctx() const { return *m_ctx; }
475  Z3_error_code check_error() const { return m_ctx->check_error(); }
476  friend void check_context(object const & a, object const & b);
477  };
478  inline void check_context(object const & a, object const & b) { (void)a; (void)b; assert(a.m_ctx == b.m_ctx); }
479 
480  class symbol : public object {
481  Z3_symbol m_sym;
482  public:
483  symbol(context & c, Z3_symbol s):object(c), m_sym(s) {}
484  operator Z3_symbol() const { return m_sym; }
485  Z3_symbol_kind kind() const { return Z3_get_symbol_kind(ctx(), m_sym); }
486  std::string str() const { assert(kind() == Z3_STRING_SYMBOL); return Z3_get_symbol_string(ctx(), m_sym); }
487  int to_int() const { assert(kind() == Z3_INT_SYMBOL); return Z3_get_symbol_int(ctx(), m_sym); }
488  friend std::ostream & operator<<(std::ostream & out, symbol const & s);
489  };
490 
491  inline std::ostream & operator<<(std::ostream & out, symbol const & s) {
492  if (s.kind() == Z3_INT_SYMBOL)
493  out << "k!" << s.to_int();
494  else
495  out << s.str();
496  return out;
497  }
498 
499 
500  class param_descrs : public object {
501  Z3_param_descrs m_descrs;
502  public:
503  param_descrs(context& c, Z3_param_descrs d): object(c), m_descrs(d) { Z3_param_descrs_inc_ref(c, d); }
504  param_descrs(param_descrs const& o): object(o.ctx()), m_descrs(o.m_descrs) { Z3_param_descrs_inc_ref(ctx(), m_descrs); }
506  Z3_param_descrs_inc_ref(o.ctx(), o.m_descrs);
507  Z3_param_descrs_dec_ref(ctx(), m_descrs);
508  m_descrs = o.m_descrs;
509  object::operator=(o);
510  return *this;
511  }
512  ~param_descrs() override { Z3_param_descrs_dec_ref(ctx(), m_descrs); }
515 
516  unsigned size() { return Z3_param_descrs_size(ctx(), m_descrs); }
517  symbol name(unsigned i) { return symbol(ctx(), Z3_param_descrs_get_name(ctx(), m_descrs, i)); }
518  Z3_param_kind kind(symbol const& s) { return Z3_param_descrs_get_kind(ctx(), m_descrs, s); }
519  std::string documentation(symbol const& s) { char const* r = Z3_param_descrs_get_documentation(ctx(), m_descrs, s); check_error(); return r; }
520  std::string to_string() const { return Z3_param_descrs_to_string(ctx(), m_descrs); }
521  };
522 
523  inline std::ostream& operator<<(std::ostream & out, param_descrs const & d) { return out << d.to_string(); }
524 
525  class params : public object {
526  Z3_params m_params;
527  public:
528  params(context & c):object(c) { m_params = Z3_mk_params(c); Z3_params_inc_ref(ctx(), m_params); }
529  params(params const & s):object(s), m_params(s.m_params) { Z3_params_inc_ref(ctx(), m_params); }
530  ~params() override { Z3_params_dec_ref(ctx(), m_params); }
531  operator Z3_params() const { return m_params; }
532  params & operator=(params const & s) {
533  Z3_params_inc_ref(s.ctx(), s.m_params);
534  Z3_params_dec_ref(ctx(), m_params);
535  object::operator=(s);
536  m_params = s.m_params;
537  return *this;
538  }
539  void set(char const * k, bool b) { Z3_params_set_bool(ctx(), m_params, ctx().str_symbol(k), b); }
540  void set(char const * k, unsigned n) { Z3_params_set_uint(ctx(), m_params, ctx().str_symbol(k), n); }
541  void set(char const * k, double n) { Z3_params_set_double(ctx(), m_params, ctx().str_symbol(k), n); }
542  void set(char const * k, symbol const & s) { Z3_params_set_symbol(ctx(), m_params, ctx().str_symbol(k), s); }
543  void set(char const * k, char const* s) { Z3_params_set_symbol(ctx(), m_params, ctx().str_symbol(k), ctx().str_symbol(s)); }
544  friend std::ostream & operator<<(std::ostream & out, params const & p);
545  };
546 
547  inline std::ostream & operator<<(std::ostream & out, params const & p) {
548  out << Z3_params_to_string(p.ctx(), p); return out;
549  }
550 
551  class ast : public object {
552  protected:
553  Z3_ast m_ast;
554  public:
555  ast(context & c):object(c), m_ast(0) {}
556  ast(context & c, Z3_ast n):object(c), m_ast(n) { Z3_inc_ref(ctx(), m_ast); }
557  ast(ast const & s) :object(s), m_ast(s.m_ast) { Z3_inc_ref(ctx(), m_ast); }
558  ~ast() override { if (m_ast) { Z3_dec_ref(*m_ctx, m_ast); } }
559  operator Z3_ast() const { return m_ast; }
560  operator bool() const { return m_ast != 0; }
561  ast & operator=(ast const & s) {
562  Z3_inc_ref(s.ctx(), s.m_ast);
563  if (m_ast)
564  Z3_dec_ref(ctx(), m_ast);
565  object::operator=(s);
566  m_ast = s.m_ast;
567  return *this;
568  }
569  Z3_ast_kind kind() const { Z3_ast_kind r = Z3_get_ast_kind(ctx(), m_ast); check_error(); return r; }
570  unsigned hash() const { unsigned r = Z3_get_ast_hash(ctx(), m_ast); check_error(); return r; }
571  friend std::ostream & operator<<(std::ostream & out, ast const & n);
572  std::string to_string() const { return std::string(Z3_ast_to_string(ctx(), m_ast)); }
573 
574 
578  friend bool eq(ast const & a, ast const & b);
579  };
580  inline std::ostream & operator<<(std::ostream & out, ast const & n) {
581  out << Z3_ast_to_string(n.ctx(), n.m_ast); return out;
582  }
583 
584  inline bool eq(ast const & a, ast const & b) { return Z3_is_eq_ast(a.ctx(), a, b); }
585 
586  template<typename T>
587  class ast_vector_tpl : public object {
588  Z3_ast_vector m_vector;
589  void init(Z3_ast_vector v) { Z3_ast_vector_inc_ref(ctx(), v); m_vector = v; }
590  public:
592  ast_vector_tpl(context & c, Z3_ast_vector v):object(c) { init(v); }
593  ast_vector_tpl(ast_vector_tpl const & s):object(s), m_vector(s.m_vector) { Z3_ast_vector_inc_ref(ctx(), m_vector); }
594  ast_vector_tpl(context& c, ast_vector_tpl const& src): object(c) { init(Z3_ast_vector_translate(src.ctx(), src, c)); }
595 
596  ~ast_vector_tpl() override { Z3_ast_vector_dec_ref(ctx(), m_vector); }
597  operator Z3_ast_vector() const { return m_vector; }
598  unsigned size() const { return Z3_ast_vector_size(ctx(), m_vector); }
599  T operator[](unsigned i) const { Z3_ast r = Z3_ast_vector_get(ctx(), m_vector, i); check_error(); return cast_ast<T>()(ctx(), r); }
600  void push_back(T const & e) { Z3_ast_vector_push(ctx(), m_vector, e); check_error(); }
601  void resize(unsigned sz) { Z3_ast_vector_resize(ctx(), m_vector, sz); check_error(); }
602  T back() const { return operator[](size() - 1); }
603  void pop_back() { assert(size() > 0); resize(size() - 1); }
604  bool empty() const { return size() == 0; }
606  Z3_ast_vector_inc_ref(s.ctx(), s.m_vector);
607  Z3_ast_vector_dec_ref(ctx(), m_vector);
608  object::operator=(s);
609  m_vector = s.m_vector;
610  return *this;
611  }
612  ast_vector_tpl& set(unsigned idx, ast& a) {
613  Z3_ast_vector_set(ctx(), m_vector, idx, a);
614  return *this;
615  }
616  /*
617  Disabled pending C++98 build upgrade
618  bool contains(T const& x) const {
619  for (T y : *this) if (eq(x, y)) return true;
620  return false;
621  }
622  */
623 
624  class iterator final {
625  ast_vector_tpl const* m_vector;
626  unsigned m_index;
627  public:
628  iterator(ast_vector_tpl const* v, unsigned i): m_vector(v), m_index(i) {}
629 
630  bool operator==(iterator const& other) const noexcept {
631  return other.m_index == m_index;
632  };
633  bool operator!=(iterator const& other) const noexcept {
634  return other.m_index != m_index;
635  };
636  iterator& operator++() noexcept {
637  ++m_index;
638  return *this;
639  }
640  void set(T& arg) {
641  Z3_ast_vector_set(m_vector->ctx(), *m_vector, m_index, arg);
642  }
643  iterator operator++(int) noexcept { iterator tmp = *this; ++m_index; return tmp; }
644  T * operator->() const { return &(operator*()); }
645  T operator*() const { return (*m_vector)[m_index]; }
646  };
647  iterator begin() const noexcept { return iterator(this, 0); }
648  iterator end() const { return iterator(this, size()); }
649  friend std::ostream & operator<<(std::ostream & out, ast_vector_tpl const & v) { out << Z3_ast_vector_to_string(v.ctx(), v); return out; }
650  std::string to_string() const { return std::string(Z3_ast_vector_to_string(ctx(), m_vector)); }
651  };
652 
653 
657  class sort : public ast {
658  public:
659  sort(context & c):ast(c) {}
660  sort(context & c, Z3_sort s):ast(c, reinterpret_cast<Z3_ast>(s)) {}
661  sort(context & c, Z3_ast a):ast(c, a) {}
662  operator Z3_sort() const { return reinterpret_cast<Z3_sort>(m_ast); }
663 
667  unsigned id() const { unsigned r = Z3_get_sort_id(ctx(), *this); check_error(); return r; }
668 
672  Z3_sort_kind sort_kind() const { return Z3_get_sort_kind(*m_ctx, *this); }
676  symbol name() const { Z3_symbol s = Z3_get_sort_name(ctx(), *this); check_error(); return symbol(ctx(), s); }
680  bool is_bool() const { return sort_kind() == Z3_BOOL_SORT; }
684  bool is_int() const { return sort_kind() == Z3_INT_SORT; }
688  bool is_real() const { return sort_kind() == Z3_REAL_SORT; }
692  bool is_arith() const { return is_int() || is_real(); }
696  bool is_bv() const { return sort_kind() == Z3_BV_SORT; }
700  bool is_array() const { return sort_kind() == Z3_ARRAY_SORT; }
704  bool is_datatype() const { return sort_kind() == Z3_DATATYPE_SORT; }
708  bool is_relation() const { return sort_kind() == Z3_RELATION_SORT; }
712  bool is_seq() const { return sort_kind() == Z3_SEQ_SORT; }
716  bool is_re() const { return sort_kind() == Z3_RE_SORT; }
720  bool is_finite_domain() const { return sort_kind() == Z3_FINITE_DOMAIN_SORT; }
724  bool is_fpa() const { return sort_kind() == Z3_FLOATING_POINT_SORT; }
725 
731  unsigned bv_size() const { assert(is_bv()); unsigned r = Z3_get_bv_sort_size(ctx(), *this); check_error(); return r; }
732 
733  unsigned fpa_ebits() const { assert(is_fpa()); unsigned r = Z3_fpa_get_ebits(ctx(), *this); check_error(); return r; }
734 
735  unsigned fpa_sbits() const { assert(is_fpa()); unsigned r = Z3_fpa_get_sbits(ctx(), *this); check_error(); return r; }
741  sort array_domain() const { assert(is_array()); Z3_sort s = Z3_get_array_sort_domain(ctx(), *this); check_error(); return sort(ctx(), s); }
747  sort array_range() const { assert(is_array()); Z3_sort s = Z3_get_array_sort_range(ctx(), *this); check_error(); return sort(ctx(), s); }
748 
749  friend std::ostream & operator<<(std::ostream & out, sort const & s) { return out << Z3_sort_to_string(s.ctx(), Z3_sort(s.m_ast)); }
750 
751  func_decl_vector constructors();
752  func_decl_vector recognizers();
753  };
754 
755 
760  class func_decl : public ast {
761  public:
762  func_decl(context & c):ast(c) {}
763  func_decl(context & c, Z3_func_decl n):ast(c, reinterpret_cast<Z3_ast>(n)) {}
764  operator Z3_func_decl() const { return reinterpret_cast<Z3_func_decl>(m_ast); }
765 
769  unsigned id() const { unsigned r = Z3_get_func_decl_id(ctx(), *this); check_error(); return r; }
770 
771  unsigned arity() const { return Z3_get_arity(ctx(), *this); }
772  sort domain(unsigned i) const { assert(i < arity()); Z3_sort r = Z3_get_domain(ctx(), *this, i); check_error(); return sort(ctx(), r); }
773  sort range() const { Z3_sort r = Z3_get_range(ctx(), *this); check_error(); return sort(ctx(), r); }
774  symbol name() const { Z3_symbol s = Z3_get_decl_name(ctx(), *this); check_error(); return symbol(ctx(), s); }
775  Z3_decl_kind decl_kind() const { return Z3_get_decl_kind(ctx(), *this); }
776  unsigned num_parameters() const { return Z3_get_decl_num_parameters(ctx(), *this); }
777 
778 
780  Z3_func_decl tc = Z3_mk_transitive_closure(ctx(), *this); check_error(); return func_decl(ctx(), tc);
781  }
782 
783  bool is_const() const { return arity() == 0; }
784 
785  expr operator()() const;
786  expr operator()(unsigned n, expr const * args) const;
787  expr operator()(expr_vector const& v) const;
788  expr operator()(expr const & a) const;
789  expr operator()(int a) const;
790  expr operator()(expr const & a1, expr const & a2) const;
791  expr operator()(expr const & a1, int a2) const;
792  expr operator()(int a1, expr const & a2) const;
793  expr operator()(expr const & a1, expr const & a2, expr const & a3) const;
794  expr operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4) const;
795  expr operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4, expr const & a5) const;
796 
797  func_decl_vector accessors();
798 
799  };
800 
804  expr select(expr const & a, expr const& i);
805  expr select(expr const & a, expr_vector const & i);
806 
811  class expr : public ast {
812  public:
813  expr(context & c):ast(c) {}
814  expr(context & c, Z3_ast n):ast(c, reinterpret_cast<Z3_ast>(n)) {}
815 
819  sort get_sort() const { Z3_sort s = Z3_get_sort(*m_ctx, m_ast); check_error(); return sort(*m_ctx, s); }
820 
824  bool is_bool() const { return get_sort().is_bool(); }
828  bool is_int() const { return get_sort().is_int(); }
832  bool is_real() const { return get_sort().is_real(); }
836  bool is_arith() const { return get_sort().is_arith(); }
840  bool is_bv() const { return get_sort().is_bv(); }
844  bool is_array() const { return get_sort().is_array(); }
848  bool is_datatype() const { return get_sort().is_datatype(); }
852  bool is_relation() const { return get_sort().is_relation(); }
856  bool is_seq() const { return get_sort().is_seq(); }
860  bool is_re() const { return get_sort().is_re(); }
861 
870  bool is_finite_domain() const { return get_sort().is_finite_domain(); }
874  bool is_fpa() const { return get_sort().is_fpa(); }
875 
881  bool is_numeral() const { return kind() == Z3_NUMERAL_AST; }
882  bool is_numeral_i64(int64_t& i) const { bool r = Z3_get_numeral_int64(ctx(), m_ast, &i); check_error(); return r;}
883  bool is_numeral_u64(uint64_t& i) const { bool r = Z3_get_numeral_uint64(ctx(), m_ast, &i); check_error(); return r;}
884  bool is_numeral_i(int& i) const { bool r = Z3_get_numeral_int(ctx(), m_ast, &i); check_error(); return r;}
885  bool is_numeral_u(unsigned& i) const { bool r = Z3_get_numeral_uint(ctx(), m_ast, &i); check_error(); return r;}
886  bool is_numeral(std::string& s) const { if (!is_numeral()) return false; s = Z3_get_numeral_string(ctx(), m_ast); check_error(); return true; }
887  bool is_numeral(std::string& s, unsigned precision) const { if (!is_numeral()) return false; s = Z3_get_numeral_decimal_string(ctx(), m_ast, precision); check_error(); return true; }
888  bool is_numeral(double& d) const { if (!is_numeral()) return false; d = Z3_get_numeral_double(ctx(), m_ast); check_error(); return true; }
889  bool as_binary(std::string& s) const { if (!is_numeral()) return false; s = Z3_get_numeral_binary_string(ctx(), m_ast); check_error(); return true; }
890 
891  double as_double() const { double d = 0; is_numeral(d); return d; }
892  uint64_t as_uint64() const { uint64_t r = 0; is_numeral_u64(r); return r; }
893  int64_t as_int64() const { int64_t r = 0; is_numeral_i64(r); return r; }
894 
895 
899  bool is_app() const { return kind() == Z3_APP_AST || kind() == Z3_NUMERAL_AST; }
903  bool is_const() const { return is_app() && num_args() == 0; }
907  bool is_quantifier() const { return kind() == Z3_QUANTIFIER_AST; }
908 
912  bool is_forall() const { return Z3_is_quantifier_forall(ctx(), m_ast); }
916  bool is_exists() const { return Z3_is_quantifier_exists(ctx(), m_ast); }
920  bool is_lambda() const { return Z3_is_lambda(ctx(), m_ast); }
925  bool is_var() const { return kind() == Z3_VAR_AST; }
929  bool is_algebraic() const { return Z3_is_algebraic_number(ctx(), m_ast); }
930 
934  bool is_well_sorted() const { bool r = Z3_is_well_sorted(ctx(), m_ast); check_error(); return r; }
935 
939  expr mk_is_inf() const {
940  assert(is_fpa());
941  Z3_ast r = Z3_mk_fpa_is_infinite(ctx(), m_ast);
942  check_error();
943  return expr(ctx(), r);
944  }
945 
949  expr mk_is_nan() const {
950  assert(is_fpa());
951  Z3_ast r = Z3_mk_fpa_is_nan(ctx(), m_ast);
952  check_error();
953  return expr(ctx(), r);
954  }
955 
959  expr mk_is_normal() const {
960  assert(is_fpa());
961  Z3_ast r = Z3_mk_fpa_is_normal(ctx(), m_ast);
962  check_error();
963  return expr(ctx(), r);
964  }
965 
970  assert(is_fpa());
971  Z3_ast r = Z3_mk_fpa_is_subnormal(ctx(), m_ast);
972  check_error();
973  return expr(ctx(), r);
974  }
975 
979  expr mk_is_zero() const {
980  assert(is_fpa());
981  Z3_ast r = Z3_mk_fpa_is_zero(ctx(), m_ast);
982  check_error();
983  return expr(ctx(), r);
984  }
985 
989  expr mk_to_ieee_bv() const {
990  assert(is_fpa());
991  Z3_ast r = Z3_mk_fpa_to_ieee_bv(ctx(), m_ast);
992  check_error();
993  return expr(ctx(), r);
994  }
995 
999  expr mk_from_ieee_bv(sort const &s) const {
1000  assert(is_bv());
1001  Z3_ast r = Z3_mk_fpa_to_fp_bv(ctx(), m_ast, s);
1002  check_error();
1003  return expr(ctx(), r);
1004  }
1005 
1012  std::string get_decimal_string(int precision) const {
1013  assert(is_numeral() || is_algebraic());
1014  return std::string(Z3_get_numeral_decimal_string(ctx(), m_ast, precision));
1015  }
1016 
1020  expr algebraic_lower(unsigned precision) const {
1021  assert(is_algebraic());
1022  Z3_ast r = Z3_get_algebraic_number_lower(ctx(), m_ast, precision);
1023  check_error();
1024  return expr(ctx(), r);
1025  }
1026 
1027  expr algebraic_upper(unsigned precision) const {
1028  assert(is_algebraic());
1029  Z3_ast r = Z3_get_algebraic_number_upper(ctx(), m_ast, precision);
1030  check_error();
1031  return expr(ctx(), r);
1032  }
1033 
1037  expr_vector algebraic_poly() const {
1038  assert(is_algebraic());
1039  Z3_ast_vector r = Z3_algebraic_get_poly(ctx(), m_ast);
1040  check_error();
1041  return expr_vector(ctx(), r);
1042  }
1043 
1047  unsigned algebraic_i() const {
1048  assert(is_algebraic());
1049  unsigned i = Z3_algebraic_get_i(ctx(), m_ast);
1050  check_error();
1051  return i;
1052  }
1053 
1057  unsigned id() const { unsigned r = Z3_get_ast_id(ctx(), m_ast); check_error(); return r; }
1058 
1069  int get_numeral_int() const {
1070  int result = 0;
1071  if (!is_numeral_i(result)) {
1072  assert(ctx().enable_exceptions());
1073  if (!ctx().enable_exceptions()) return 0;
1074  Z3_THROW(exception("numeral does not fit in machine int"));
1075  }
1076  return result;
1077  }
1078 
1088  unsigned get_numeral_uint() const {
1089  assert(is_numeral());
1090  unsigned result = 0;
1091  if (!is_numeral_u(result)) {
1092  assert(ctx().enable_exceptions());
1093  if (!ctx().enable_exceptions()) return 0;
1094  Z3_THROW(exception("numeral does not fit in machine uint"));
1095  }
1096  return result;
1097  }
1098 
1105  int64_t get_numeral_int64() const {
1106  assert(is_numeral());
1107  int64_t result = 0;
1108  if (!is_numeral_i64(result)) {
1109  assert(ctx().enable_exceptions());
1110  if (!ctx().enable_exceptions()) return 0;
1111  Z3_THROW(exception("numeral does not fit in machine int64_t"));
1112  }
1113  return result;
1114  }
1115 
1122  uint64_t get_numeral_uint64() const {
1123  assert(is_numeral());
1124  uint64_t result = 0;
1125  if (!is_numeral_u64(result)) {
1126  assert(ctx().enable_exceptions());
1127  if (!ctx().enable_exceptions()) return 0;
1128  Z3_THROW(exception("numeral does not fit in machine uint64_t"));
1129  }
1130  return result;
1131  }
1132 
1134  return Z3_get_bool_value(ctx(), m_ast);
1135  }
1136 
1137  expr numerator() const {
1138  assert(is_numeral());
1139  Z3_ast r = Z3_get_numerator(ctx(), m_ast);
1140  check_error();
1141  return expr(ctx(),r);
1142  }
1143 
1144 
1145  expr denominator() const {
1146  assert(is_numeral());
1147  Z3_ast r = Z3_get_denominator(ctx(), m_ast);
1148  check_error();
1149  return expr(ctx(),r);
1150  }
1151 
1152 
1157  bool is_string_value() const { return Z3_is_string(ctx(), m_ast); }
1158 
1164  std::string get_string() const {
1165  assert(is_string_value());
1166  char const* s = Z3_get_string(ctx(), m_ast);
1167  check_error();
1168  return std::string(s);
1169  }
1170 
1176  std::u32string get_u32string() const {
1177  assert(is_string_value());
1178  unsigned n = Z3_get_string_length(ctx(), m_ast);
1179  std::u32string s;
1180  s.resize(n);
1181  Z3_get_string_contents(ctx(), m_ast, n, (unsigned*)s.data());
1182  return s;
1183  }
1184 
1185  operator Z3_app() const { assert(is_app()); return reinterpret_cast<Z3_app>(m_ast); }
1186 
1193  func_decl decl() const { Z3_func_decl f = Z3_get_app_decl(ctx(), *this); check_error(); return func_decl(ctx(), f); }
1200  unsigned num_args() const { unsigned r = Z3_get_app_num_args(ctx(), *this); check_error(); return r; }
1208  expr arg(unsigned i) const { Z3_ast r = Z3_get_app_arg(ctx(), *this, i); check_error(); return expr(ctx(), r); }
1215  expr_vector args() const {
1216  expr_vector vec(ctx());
1217  unsigned argCnt = num_args();
1218  for (unsigned i = 0; i < argCnt; i++)
1219  vec.push_back(arg(i));
1220  return vec;
1221  }
1222 
1228  expr body() const { assert(is_quantifier()); Z3_ast r = Z3_get_quantifier_body(ctx(), *this); check_error(); return expr(ctx(), r); }
1229 
1235  friend expr operator!(expr const & a);
1236 
1243  friend expr operator&&(expr const & a, expr const & b);
1244 
1245 
1252  friend expr operator&&(expr const & a, bool b);
1259  friend expr operator&&(bool a, expr const & b);
1260 
1267  friend expr operator||(expr const & a, expr const & b);
1274  friend expr operator||(expr const & a, bool b);
1275 
1282  friend expr operator||(bool a, expr const & b);
1283 
1284  friend expr implies(expr const & a, expr const & b);
1285  friend expr implies(expr const & a, bool b);
1286  friend expr implies(bool a, expr const & b);
1287 
1288  friend expr mk_or(expr_vector const& args);
1289  friend expr mk_xor(expr_vector const& args);
1290  friend expr mk_and(expr_vector const& args);
1291 
1292  friend expr ite(expr const & c, expr const & t, expr const & e);
1293 
1294  bool is_true() const { return is_app() && Z3_OP_TRUE == decl().decl_kind(); }
1295  bool is_false() const { return is_app() && Z3_OP_FALSE == decl().decl_kind(); }
1296  bool is_not() const { return is_app() && Z3_OP_NOT == decl().decl_kind(); }
1297  bool is_and() const { return is_app() && Z3_OP_AND == decl().decl_kind(); }
1298  bool is_or() const { return is_app() && Z3_OP_OR == decl().decl_kind(); }
1299  bool is_xor() const { return is_app() && Z3_OP_XOR == decl().decl_kind(); }
1300  bool is_implies() const { return is_app() && Z3_OP_IMPLIES == decl().decl_kind(); }
1301  bool is_eq() const { return is_app() && Z3_OP_EQ == decl().decl_kind(); }
1302  bool is_ite() const { return is_app() && Z3_OP_ITE == decl().decl_kind(); }
1303  bool is_distinct() const { return is_app() && Z3_OP_DISTINCT == decl().decl_kind(); }
1304 
1305  friend expr distinct(expr_vector const& args);
1306  friend expr concat(expr const& a, expr const& b);
1307  friend expr concat(expr_vector const& args);
1308 
1309  friend expr operator==(expr const & a, expr const & b);
1310  friend expr operator==(expr const & a, int b);
1311  friend expr operator==(int a, expr const & b);
1312 
1313  friend expr operator!=(expr const & a, expr const & b);
1314  friend expr operator!=(expr const & a, int b);
1315  friend expr operator!=(int a, expr const & b);
1316 
1317  friend expr operator+(expr const & a, expr const & b);
1318  friend expr operator+(expr const & a, int b);
1319  friend expr operator+(int a, expr const & b);
1320  friend expr sum(expr_vector const& args);
1321 
1322  friend expr operator*(expr const & a, expr const & b);
1323  friend expr operator*(expr const & a, int b);
1324  friend expr operator*(int a, expr const & b);
1325 
1326  /* \brief Power operator */
1327  friend expr pw(expr const & a, expr const & b);
1328  friend expr pw(expr const & a, int b);
1329  friend expr pw(int a, expr const & b);
1330 
1331  /* \brief mod operator */
1332  friend expr mod(expr const& a, expr const& b);
1333  friend expr mod(expr const& a, int b);
1334  friend expr mod(int a, expr const& b);
1335 
1336  /* \brief rem operator */
1337  friend expr rem(expr const& a, expr const& b);
1338  friend expr rem(expr const& a, int b);
1339  friend expr rem(int a, expr const& b);
1340 
1341  friend expr is_int(expr const& e);
1342 
1343  friend expr operator/(expr const & a, expr const & b);
1344  friend expr operator/(expr const & a, int b);
1345  friend expr operator/(int a, expr const & b);
1346 
1347  friend expr operator-(expr const & a);
1348 
1349  friend expr operator-(expr const & a, expr const & b);
1350  friend expr operator-(expr const & a, int b);
1351  friend expr operator-(int a, expr const & b);
1352 
1353  friend expr operator<=(expr const & a, expr const & b);
1354  friend expr operator<=(expr const & a, int b);
1355  friend expr operator<=(int a, expr const & b);
1356 
1357 
1358  friend expr operator>=(expr const & a, expr const & b);
1359  friend expr operator>=(expr const & a, int b);
1360  friend expr operator>=(int a, expr const & b);
1361 
1362  friend expr operator<(expr const & a, expr const & b);
1363  friend expr operator<(expr const & a, int b);
1364  friend expr operator<(int a, expr const & b);
1365 
1366  friend expr operator>(expr const & a, expr const & b);
1367  friend expr operator>(expr const & a, int b);
1368  friend expr operator>(int a, expr const & b);
1369 
1370  friend expr pble(expr_vector const& es, int const * coeffs, int bound);
1371  friend expr pbge(expr_vector const& es, int const * coeffs, int bound);
1372  friend expr pbeq(expr_vector const& es, int const * coeffs, int bound);
1373  friend expr atmost(expr_vector const& es, unsigned bound);
1374  friend expr atleast(expr_vector const& es, unsigned bound);
1375 
1376  friend expr operator&(expr const & a, expr const & b);
1377  friend expr operator&(expr const & a, int b);
1378  friend expr operator&(int a, expr const & b);
1379 
1380  friend expr operator^(expr const & a, expr const & b);
1381  friend expr operator^(expr const & a, int b);
1382  friend expr operator^(int a, expr const & b);
1383 
1384  friend expr operator|(expr const & a, expr const & b);
1385  friend expr operator|(expr const & a, int b);
1386  friend expr operator|(int a, expr const & b);
1387  friend expr nand(expr const& a, expr const& b);
1388  friend expr nor(expr const& a, expr const& b);
1389  friend expr xnor(expr const& a, expr const& b);
1390 
1391  friend expr min(expr const& a, expr const& b);
1392  friend expr max(expr const& a, expr const& b);
1393 
1394  friend expr bv2int(expr const& a, bool is_signed);
1395  friend expr int2bv(unsigned n, expr const& a);
1396  friend expr bvadd_no_overflow(expr const& a, expr const& b, bool is_signed);
1397  friend expr bvadd_no_underflow(expr const& a, expr const& b);
1398  friend expr bvsub_no_overflow(expr const& a, expr const& b);
1399  friend expr bvsub_no_underflow(expr const& a, expr const& b, bool is_signed);
1400  friend expr bvsdiv_no_overflow(expr const& a, expr const& b);
1401  friend expr bvneg_no_overflow(expr const& a);
1402  friend expr bvmul_no_overflow(expr const& a, expr const& b, bool is_signed);
1403  friend expr bvmul_no_underflow(expr const& a, expr const& b);
1404 
1405  expr rotate_left(unsigned i) const { Z3_ast r = Z3_mk_rotate_left(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
1406  expr rotate_right(unsigned i) const { Z3_ast r = Z3_mk_rotate_right(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
1407  expr repeat(unsigned i) const { Z3_ast r = Z3_mk_repeat(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
1408 
1409  friend expr bvredor(expr const & a);
1410  friend expr bvredand(expr const & a);
1411 
1412  friend expr abs(expr const & a);
1413  friend expr sqrt(expr const & a, expr const & rm);
1414  friend expr fp_eq(expr const & a, expr const & b);
1415 
1416  friend expr operator~(expr const & a);
1417  expr extract(unsigned hi, unsigned lo) const { Z3_ast r = Z3_mk_extract(ctx(), hi, lo, *this); ctx().check_error(); return expr(ctx(), r); }
1418  expr bit2bool(unsigned i) const { Z3_ast r = Z3_mk_bit2bool(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
1419  unsigned lo() const { assert (is_app() && Z3_get_decl_num_parameters(ctx(), decl()) == 2); return static_cast<unsigned>(Z3_get_decl_int_parameter(ctx(), decl(), 1)); }
1420  unsigned hi() const { assert (is_app() && Z3_get_decl_num_parameters(ctx(), decl()) == 2); return static_cast<unsigned>(Z3_get_decl_int_parameter(ctx(), decl(), 0)); }
1421 
1425  friend expr fma(expr const& a, expr const& b, expr const& c, expr const& rm);
1426 
1430  friend expr fpa_fp(expr const& sgn, expr const& exp, expr const& sig);
1431 
1435  friend expr fpa_to_sbv(expr const& t, unsigned sz);
1436 
1440  friend expr fpa_to_ubv(expr const& t, unsigned sz);
1441 
1445  friend expr sbv_to_fpa(expr const& t, sort s);
1446 
1450  friend expr ubv_to_fpa(expr const& t, sort s);
1451 
1455  friend expr fpa_to_fpa(expr const& t, sort s);
1456 
1460  friend expr round_fpa_to_closest_integer(expr const& t);
1461 
1467  expr extract(expr const& offset, expr const& length) const {
1468  check_context(*this, offset); check_context(offset, length);
1469  Z3_ast r = Z3_mk_seq_extract(ctx(), *this, offset, length); check_error(); return expr(ctx(), r);
1470  }
1471  expr replace(expr const& src, expr const& dst) const {
1472  check_context(*this, src); check_context(src, dst);
1473  Z3_ast r = Z3_mk_seq_replace(ctx(), *this, src, dst);
1474  check_error();
1475  return expr(ctx(), r);
1476  }
1477  expr unit() const {
1478  Z3_ast r = Z3_mk_seq_unit(ctx(), *this);
1479  check_error();
1480  return expr(ctx(), r);
1481  }
1482  expr contains(expr const& s) const {
1483  check_context(*this, s);
1484  Z3_ast r = Z3_mk_seq_contains(ctx(), *this, s);
1485  check_error();
1486  return expr(ctx(), r);
1487  }
1488  expr at(expr const& index) const {
1489  check_context(*this, index);
1490  Z3_ast r = Z3_mk_seq_at(ctx(), *this, index);
1491  check_error();
1492  return expr(ctx(), r);
1493  }
1494  expr nth(expr const& index) const {
1495  check_context(*this, index);
1496  Z3_ast r = Z3_mk_seq_nth(ctx(), *this, index);
1497  check_error();
1498  return expr(ctx(), r);
1499  }
1500  expr length() const {
1501  Z3_ast r = Z3_mk_seq_length(ctx(), *this);
1502  check_error();
1503  return expr(ctx(), r);
1504  }
1505  expr stoi() const {
1506  Z3_ast r = Z3_mk_str_to_int(ctx(), *this);
1507  check_error();
1508  return expr(ctx(), r);
1509  }
1510  expr itos() const {
1511  Z3_ast r = Z3_mk_int_to_str(ctx(), *this);
1512  check_error();
1513  return expr(ctx(), r);
1514  }
1515  expr ubvtos() const {
1516  Z3_ast r = Z3_mk_ubv_to_str(ctx(), *this);
1517  check_error();
1518  return expr(ctx(), r);
1519  }
1520  expr sbvtos() const {
1521  Z3_ast r = Z3_mk_sbv_to_str(ctx(), *this);
1522  check_error();
1523  return expr(ctx(), r);
1524  }
1525  expr char_to_int() const {
1526  Z3_ast r = Z3_mk_char_to_int(ctx(), *this);
1527  check_error();
1528  return expr(ctx(), r);
1529  }
1530  expr char_to_bv() const {
1531  Z3_ast r = Z3_mk_char_to_bv(ctx(), *this);
1532  check_error();
1533  return expr(ctx(), r);
1534  }
1535  expr char_from_bv() const {
1536  Z3_ast r = Z3_mk_char_from_bv(ctx(), *this);
1537  check_error();
1538  return expr(ctx(), r);
1539  }
1540  expr is_digit() const {
1541  Z3_ast r = Z3_mk_char_is_digit(ctx(), *this);
1542  check_error();
1543  return expr(ctx(), r);
1544  }
1545 
1546  friend expr range(expr const& lo, expr const& hi);
1550  expr loop(unsigned lo) {
1551  Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, 0);
1552  check_error();
1553  return expr(ctx(), r);
1554  }
1555  expr loop(unsigned lo, unsigned hi) {
1556  Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, hi);
1557  check_error();
1558  return expr(ctx(), r);
1559  }
1560 
1564  expr operator[](expr const& index) const {
1565  assert(is_array() || is_seq());
1566  if (is_array()) {
1567  return select(*this, index);
1568  }
1569  return nth(index);
1570  }
1571 
1572  expr operator[](expr_vector const& index) const {
1573  return select(*this, index);
1574  }
1575 
1579  expr simplify() const { Z3_ast r = Z3_simplify(ctx(), m_ast); check_error(); return expr(ctx(), r); }
1583  expr simplify(params const & p) const { Z3_ast r = Z3_simplify_ex(ctx(), m_ast, p); check_error(); return expr(ctx(), r); }
1584 
1588  expr substitute(expr_vector const& src, expr_vector const& dst);
1589 
1593  expr substitute(expr_vector const& dst);
1594 
1598  expr substitute(func_decl_vector const& funs, expr_vector const& bodies);
1599 
1600 
1601  class iterator {
1602  expr& e;
1603  unsigned i;
1604  public:
1605  iterator(expr& e, unsigned i): e(e), i(i) {}
1606  bool operator==(iterator const& other) const noexcept {
1607  return i == other.i;
1608  }
1609  bool operator!=(iterator const& other) const noexcept {
1610  return i != other.i;
1611  }
1612  expr operator*() const { return e.arg(i); }
1613  iterator& operator++() { ++i; return *this; }
1614  iterator operator++(int) { assert(false); return *this; }
1615  };
1616 
1617  iterator begin() { return iterator(*this, 0); }
1618  iterator end() { return iterator(*this, is_app() ? num_args() : 0); }
1619 
1620  };
1621 
1622 #define _Z3_MK_BIN_(a, b, binop) \
1623  check_context(a, b); \
1624  Z3_ast r = binop(a.ctx(), a, b); \
1625  a.check_error(); \
1626  return expr(a.ctx(), r); \
1627 
1628 
1629  inline expr implies(expr const & a, expr const & b) {
1630  assert(a.is_bool() && b.is_bool());
1631  _Z3_MK_BIN_(a, b, Z3_mk_implies);
1632  }
1633  inline expr implies(expr const & a, bool b) { return implies(a, a.ctx().bool_val(b)); }
1634  inline expr implies(bool a, expr const & b) { return implies(b.ctx().bool_val(a), b); }
1635 
1636 
1637  inline expr pw(expr const & a, expr const & b) { _Z3_MK_BIN_(a, b, Z3_mk_power); }
1638  inline expr pw(expr const & a, int b) { return pw(a, a.ctx().num_val(b, a.get_sort())); }
1639  inline expr pw(int a, expr const & b) { return pw(b.ctx().num_val(a, b.get_sort()), b); }
1640 
1641  inline expr mod(expr const& a, expr const& b) {
1642  if (a.is_bv()) {
1643  _Z3_MK_BIN_(a, b, Z3_mk_bvsmod);
1644  }
1645  else {
1646  _Z3_MK_BIN_(a, b, Z3_mk_mod);
1647  }
1648  }
1649  inline expr mod(expr const & a, int b) { return mod(a, a.ctx().num_val(b, a.get_sort())); }
1650  inline expr mod(int a, expr const & b) { return mod(b.ctx().num_val(a, b.get_sort()), b); }
1651 
1652  inline expr operator%(expr const& a, expr const& b) { return mod(a, b); }
1653  inline expr operator%(expr const& a, int b) { return mod(a, b); }
1654  inline expr operator%(int a, expr const& b) { return mod(a, b); }
1655 
1656 
1657  inline expr rem(expr const& a, expr const& b) {
1658  if (a.is_fpa() && b.is_fpa()) {
1659  _Z3_MK_BIN_(a, b, Z3_mk_fpa_rem);
1660  } else {
1661  _Z3_MK_BIN_(a, b, Z3_mk_rem);
1662  }
1663  }
1664  inline expr rem(expr const & a, int b) { return rem(a, a.ctx().num_val(b, a.get_sort())); }
1665  inline expr rem(int a, expr const & b) { return rem(b.ctx().num_val(a, b.get_sort()), b); }
1666 
1667 #undef _Z3_MK_BIN_
1668 
1669 #define _Z3_MK_UN_(a, mkun) \
1670  Z3_ast r = mkun(a.ctx(), a); \
1671  a.check_error(); \
1672  return expr(a.ctx(), r); \
1673 
1674 
1675  inline expr operator!(expr const & a) { assert(a.is_bool()); _Z3_MK_UN_(a, Z3_mk_not); }
1676 
1677  inline expr is_int(expr const& e) { _Z3_MK_UN_(e, Z3_mk_is_int); }
1678 
1679 #undef _Z3_MK_UN_
1680 
1681  inline expr operator&&(expr const & a, expr const & b) {
1682  check_context(a, b);
1683  assert(a.is_bool() && b.is_bool());
1684  Z3_ast args[2] = { a, b };
1685  Z3_ast r = Z3_mk_and(a.ctx(), 2, args);
1686  a.check_error();
1687  return expr(a.ctx(), r);
1688  }
1689 
1690  inline expr operator&&(expr const & a, bool b) { return a && a.ctx().bool_val(b); }
1691  inline expr operator&&(bool a, expr const & b) { return b.ctx().bool_val(a) && b; }
1692 
1693  inline expr operator||(expr const & a, expr const & b) {
1694  check_context(a, b);
1695  assert(a.is_bool() && b.is_bool());
1696  Z3_ast args[2] = { a, b };
1697  Z3_ast r = Z3_mk_or(a.ctx(), 2, args);
1698  a.check_error();
1699  return expr(a.ctx(), r);
1700  }
1701 
1702  inline expr operator||(expr const & a, bool b) { return a || a.ctx().bool_val(b); }
1703 
1704  inline expr operator||(bool a, expr const & b) { return b.ctx().bool_val(a) || b; }
1705 
1706  inline expr operator==(expr const & a, expr const & b) {
1707  check_context(a, b);
1708  Z3_ast r = Z3_mk_eq(a.ctx(), a, b);
1709  a.check_error();
1710  return expr(a.ctx(), r);
1711  }
1712  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()); }
1713  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; }
1714  inline expr operator==(expr const & a, double b) { assert(a.is_fpa()); return a == a.ctx().fpa_val(b); }
1715  inline expr operator==(double a, expr const & b) { assert(b.is_fpa()); return b.ctx().fpa_val(a) == b; }
1716 
1717  inline expr operator!=(expr const & a, expr const & b) {
1718  check_context(a, b);
1719  Z3_ast args[2] = { a, b };
1720  Z3_ast r = Z3_mk_distinct(a.ctx(), 2, args);
1721  a.check_error();
1722  return expr(a.ctx(), r);
1723  }
1724  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()); }
1725  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; }
1726  inline expr operator!=(expr const & a, double b) { assert(a.is_fpa()); return a != a.ctx().fpa_val(b); }
1727  inline expr operator!=(double a, expr const & b) { assert(b.is_fpa()); return b.ctx().fpa_val(a) != b; }
1728 
1729  inline expr operator+(expr const & a, expr const & b) {
1730  check_context(a, b);
1731  Z3_ast r = 0;
1732  if (a.is_arith() && b.is_arith()) {
1733  Z3_ast args[2] = { a, b };
1734  r = Z3_mk_add(a.ctx(), 2, args);
1735  }
1736  else if (a.is_bv() && b.is_bv()) {
1737  r = Z3_mk_bvadd(a.ctx(), a, b);
1738  }
1739  else if (a.is_seq() && b.is_seq()) {
1740  return concat(a, b);
1741  }
1742  else if (a.is_re() && b.is_re()) {
1743  Z3_ast _args[2] = { a, b };
1744  r = Z3_mk_re_union(a.ctx(), 2, _args);
1745  }
1746  else if (a.is_fpa() && b.is_fpa()) {
1747  r = Z3_mk_fpa_add(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1748  }
1749  else {
1750  // operator is not supported by given arguments.
1751  assert(false);
1752  }
1753  a.check_error();
1754  return expr(a.ctx(), r);
1755  }
1756  inline expr operator+(expr const & a, int b) { return a + a.ctx().num_val(b, a.get_sort()); }
1757  inline expr operator+(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) + b; }
1758 
1759  inline expr operator*(expr const & a, expr const & b) {
1760  check_context(a, b);
1761  Z3_ast r = 0;
1762  if (a.is_arith() && b.is_arith()) {
1763  Z3_ast args[2] = { a, b };
1764  r = Z3_mk_mul(a.ctx(), 2, args);
1765  }
1766  else if (a.is_bv() && b.is_bv()) {
1767  r = Z3_mk_bvmul(a.ctx(), a, b);
1768  }
1769  else if (a.is_fpa() && b.is_fpa()) {
1770  r = Z3_mk_fpa_mul(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1771  }
1772  else {
1773  // operator is not supported by given arguments.
1774  assert(false);
1775  }
1776  a.check_error();
1777  return expr(a.ctx(), r);
1778  }
1779  inline expr operator*(expr const & a, int b) { return a * a.ctx().num_val(b, a.get_sort()); }
1780  inline expr operator*(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) * b; }
1781 
1782 
1783  inline expr operator>=(expr const & a, expr const & b) {
1784  check_context(a, b);
1785  Z3_ast r = 0;
1786  if (a.is_arith() && b.is_arith()) {
1787  r = Z3_mk_ge(a.ctx(), a, b);
1788  }
1789  else if (a.is_bv() && b.is_bv()) {
1790  r = Z3_mk_bvsge(a.ctx(), a, b);
1791  }
1792  else if (a.is_fpa() && b.is_fpa()) {
1793  r = Z3_mk_fpa_geq(a.ctx(), a, b);
1794  }
1795  else {
1796  // operator is not supported by given arguments.
1797  assert(false);
1798  }
1799  a.check_error();
1800  return expr(a.ctx(), r);
1801  }
1802 
1803  inline expr operator/(expr const & a, expr const & b) {
1804  check_context(a, b);
1805  Z3_ast r = 0;
1806  if (a.is_arith() && b.is_arith()) {
1807  r = Z3_mk_div(a.ctx(), a, b);
1808  }
1809  else if (a.is_bv() && b.is_bv()) {
1810  r = Z3_mk_bvsdiv(a.ctx(), a, b);
1811  }
1812  else if (a.is_fpa() && b.is_fpa()) {
1813  r = Z3_mk_fpa_div(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1814  }
1815  else {
1816  // operator is not supported by given arguments.
1817  assert(false);
1818  }
1819  a.check_error();
1820  return expr(a.ctx(), r);
1821  }
1822  inline expr operator/(expr const & a, int b) { return a / a.ctx().num_val(b, a.get_sort()); }
1823  inline expr operator/(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) / b; }
1824 
1825  inline expr operator-(expr const & a) {
1826  Z3_ast r = 0;
1827  if (a.is_arith()) {
1828  r = Z3_mk_unary_minus(a.ctx(), a);
1829  }
1830  else if (a.is_bv()) {
1831  r = Z3_mk_bvneg(a.ctx(), a);
1832  }
1833  else if (a.is_fpa()) {
1834  r = Z3_mk_fpa_neg(a.ctx(), a);
1835  }
1836  else {
1837  // operator is not supported by given arguments.
1838  assert(false);
1839  }
1840  a.check_error();
1841  return expr(a.ctx(), r);
1842  }
1843 
1844  inline expr operator-(expr const & a, expr const & b) {
1845  check_context(a, b);
1846  Z3_ast r = 0;
1847  if (a.is_arith() && b.is_arith()) {
1848  Z3_ast args[2] = { a, b };
1849  r = Z3_mk_sub(a.ctx(), 2, args);
1850  }
1851  else if (a.is_bv() && b.is_bv()) {
1852  r = Z3_mk_bvsub(a.ctx(), a, b);
1853  }
1854  else if (a.is_fpa() && b.is_fpa()) {
1855  r = Z3_mk_fpa_sub(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1856  }
1857  else {
1858  // operator is not supported by given arguments.
1859  assert(false);
1860  }
1861  a.check_error();
1862  return expr(a.ctx(), r);
1863  }
1864  inline expr operator-(expr const & a, int b) { return a - a.ctx().num_val(b, a.get_sort()); }
1865  inline expr operator-(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) - b; }
1866 
1867  inline expr operator<=(expr const & a, expr const & b) {
1868  check_context(a, b);
1869  Z3_ast r = 0;
1870  if (a.is_arith() && b.is_arith()) {
1871  r = Z3_mk_le(a.ctx(), a, b);
1872  }
1873  else if (a.is_bv() && b.is_bv()) {
1874  r = Z3_mk_bvsle(a.ctx(), a, b);
1875  }
1876  else if (a.is_fpa() && b.is_fpa()) {
1877  r = Z3_mk_fpa_leq(a.ctx(), a, b);
1878  }
1879  else {
1880  // operator is not supported by given arguments.
1881  assert(false);
1882  }
1883  a.check_error();
1884  return expr(a.ctx(), r);
1885  }
1886  inline expr operator<=(expr const & a, int b) { return a <= a.ctx().num_val(b, a.get_sort()); }
1887  inline expr operator<=(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) <= b; }
1888 
1889  inline expr operator>=(expr const & a, int b) { return a >= a.ctx().num_val(b, a.get_sort()); }
1890  inline expr operator>=(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) >= b; }
1891 
1892  inline expr operator<(expr const & a, expr const & b) {
1893  check_context(a, b);
1894  Z3_ast r = 0;
1895  if (a.is_arith() && b.is_arith()) {
1896  r = Z3_mk_lt(a.ctx(), a, b);
1897  }
1898  else if (a.is_bv() && b.is_bv()) {
1899  r = Z3_mk_bvslt(a.ctx(), a, b);
1900  }
1901  else if (a.is_fpa() && b.is_fpa()) {
1902  r = Z3_mk_fpa_lt(a.ctx(), a, b);
1903  }
1904  else {
1905  // operator is not supported by given arguments.
1906  assert(false);
1907  }
1908  a.check_error();
1909  return expr(a.ctx(), r);
1910  }
1911  inline expr operator<(expr const & a, int b) { return a < a.ctx().num_val(b, a.get_sort()); }
1912  inline expr operator<(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) < b; }
1913 
1914  inline expr operator>(expr const & a, expr const & b) {
1915  check_context(a, b);
1916  Z3_ast r = 0;
1917  if (a.is_arith() && b.is_arith()) {
1918  r = Z3_mk_gt(a.ctx(), a, b);
1919  }
1920  else if (a.is_bv() && b.is_bv()) {
1921  r = Z3_mk_bvsgt(a.ctx(), a, b);
1922  }
1923  else if (a.is_fpa() && b.is_fpa()) {
1924  r = Z3_mk_fpa_gt(a.ctx(), a, b);
1925  }
1926  else {
1927  // operator is not supported by given arguments.
1928  assert(false);
1929  }
1930  a.check_error();
1931  return expr(a.ctx(), r);
1932  }
1933  inline expr operator>(expr const & a, int b) { return a > a.ctx().num_val(b, a.get_sort()); }
1934  inline expr operator>(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) > b; }
1935 
1936  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); }
1937  inline expr operator&(expr const & a, int b) { return a & a.ctx().num_val(b, a.get_sort()); }
1938  inline expr operator&(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) & b; }
1939 
1940  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); }
1941  inline expr operator^(expr const & a, int b) { return a ^ a.ctx().num_val(b, a.get_sort()); }
1942  inline expr operator^(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) ^ b; }
1943 
1944  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); }
1945  inline expr operator|(expr const & a, int b) { return a | a.ctx().num_val(b, a.get_sort()); }
1946  inline expr operator|(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) | b; }
1947 
1948  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); }
1949  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); }
1950  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); }
1951  inline expr min(expr const& a, expr const& b) {
1952  check_context(a, b);
1953  Z3_ast r;
1954  if (a.is_arith()) {
1955  r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, b), b, a);
1956  }
1957  else if (a.is_bv()) {
1958  r = Z3_mk_ite(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b), b, a);
1959  }
1960  else {
1961  assert(a.is_fpa());
1962  r = Z3_mk_fpa_min(a.ctx(), a, b);
1963  }
1964  a.check_error();
1965  return expr(a.ctx(), r);
1966  }
1967  inline expr max(expr const& a, expr const& b) {
1968  check_context(a, b);
1969  Z3_ast r;
1970  if (a.is_arith()) {
1971  r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, b), a, b);
1972  }
1973  else if (a.is_bv()) {
1974  r = Z3_mk_ite(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b), a, b);
1975  }
1976  else {
1977  assert(a.is_fpa());
1978  r = Z3_mk_fpa_max(a.ctx(), a, b);
1979  }
1980  a.check_error();
1981  return expr(a.ctx(), r);
1982  }
1983  inline expr bvredor(expr const & a) {
1984  assert(a.is_bv());
1985  Z3_ast r = Z3_mk_bvredor(a.ctx(), a);
1986  a.check_error();
1987  return expr(a.ctx(), r);
1988  }
1989  inline expr bvredand(expr const & a) {
1990  assert(a.is_bv());
1991  Z3_ast r = Z3_mk_bvredand(a.ctx(), a);
1992  a.check_error();
1993  return expr(a.ctx(), r);
1994  }
1995  inline expr abs(expr const & a) {
1996  Z3_ast r;
1997  if (a.is_int()) {
1998  expr zero = a.ctx().int_val(0);
1999  expr ge = a >= zero;
2000  expr na = -a;
2001  r = Z3_mk_ite(a.ctx(), ge, a, na);
2002  }
2003  else if (a.is_real()) {
2004  expr zero = a.ctx().real_val(0);
2005  expr ge = a >= zero;
2006  expr na = -a;
2007  r = Z3_mk_ite(a.ctx(), ge, a, na);
2008  }
2009  else {
2010  r = Z3_mk_fpa_abs(a.ctx(), a);
2011  }
2012  a.check_error();
2013  return expr(a.ctx(), r);
2014  }
2015  inline expr sqrt(expr const & a, expr const& rm) {
2016  check_context(a, rm);
2017  assert(a.is_fpa());
2018  Z3_ast r = Z3_mk_fpa_sqrt(a.ctx(), rm, a);
2019  a.check_error();
2020  return expr(a.ctx(), r);
2021  }
2022  inline expr fp_eq(expr const & a, expr const & b) {
2023  check_context(a, b);
2024  assert(a.is_fpa());
2025  Z3_ast r = Z3_mk_fpa_eq(a.ctx(), a, b);
2026  a.check_error();
2027  return expr(a.ctx(), r);
2028  }
2029  inline expr operator~(expr const & a) { Z3_ast r = Z3_mk_bvnot(a.ctx(), a); return expr(a.ctx(), r); }
2030 
2031  inline expr fma(expr const& a, expr const& b, expr const& c, expr const& rm) {
2032  check_context(a, b); check_context(a, c); check_context(a, rm);
2033  assert(a.is_fpa() && b.is_fpa() && c.is_fpa());
2034  Z3_ast r = Z3_mk_fpa_fma(a.ctx(), rm, a, b, c);
2035  a.check_error();
2036  return expr(a.ctx(), r);
2037  }
2038 
2039  inline expr fpa_fp(expr const& sgn, expr const& exp, expr const& sig) {
2040  check_context(sgn, exp); check_context(exp, sig);
2041  assert(sgn.is_bv() && exp.is_bv() && sig.is_bv());
2042  Z3_ast r = Z3_mk_fpa_fp(sgn.ctx(), sgn, exp, sig);
2043  sgn.check_error();
2044  return expr(sgn.ctx(), r);
2045  }
2046 
2047  inline expr fpa_to_sbv(expr const& t, unsigned sz) {
2048  assert(t.is_fpa());
2049  Z3_ast r = Z3_mk_fpa_to_sbv(t.ctx(), t.ctx().fpa_rounding_mode(), t, sz);
2050  t.check_error();
2051  return expr(t.ctx(), r);
2052  }
2053 
2054  inline expr fpa_to_ubv(expr const& t, unsigned sz) {
2055  assert(t.is_fpa());
2056  Z3_ast r = Z3_mk_fpa_to_ubv(t.ctx(), t.ctx().fpa_rounding_mode(), t, sz);
2057  t.check_error();
2058  return expr(t.ctx(), r);
2059  }
2060 
2061  inline expr sbv_to_fpa(expr const& t, sort s) {
2062  assert(t.is_bv());
2063  Z3_ast r = Z3_mk_fpa_to_fp_signed(t.ctx(), t.ctx().fpa_rounding_mode(), t, s);
2064  t.check_error();
2065  return expr(t.ctx(), r);
2066  }
2067 
2068  inline expr ubv_to_fpa(expr const& t, sort s) {
2069  assert(t.is_bv());
2070  Z3_ast r = Z3_mk_fpa_to_fp_unsigned(t.ctx(), t.ctx().fpa_rounding_mode(), t, s);
2071  t.check_error();
2072  return expr(t.ctx(), r);
2073  }
2074 
2075  inline expr fpa_to_fpa(expr const& t, sort s) {
2076  assert(t.is_fpa());
2077  Z3_ast r = Z3_mk_fpa_to_fp_float(t.ctx(), t.ctx().fpa_rounding_mode(), t, s);
2078  t.check_error();
2079  return expr(t.ctx(), r);
2080  }
2081 
2083  assert(t.is_fpa());
2084  Z3_ast r = Z3_mk_fpa_round_to_integral(t.ctx(), t.ctx().fpa_rounding_mode(), t);
2085  t.check_error();
2086  return expr(t.ctx(), r);
2087  }
2088 
2094  inline expr ite(expr const & c, expr const & t, expr const & e) {
2095  check_context(c, t); check_context(c, e);
2096  assert(c.is_bool());
2097  Z3_ast r = Z3_mk_ite(c.ctx(), c, t, e);
2098  c.check_error();
2099  return expr(c.ctx(), r);
2100  }
2101 
2102 
2107  inline expr to_expr(context & c, Z3_ast a) {
2108  c.check_error();
2109  assert(Z3_get_ast_kind(c, a) == Z3_APP_AST ||
2110  Z3_get_ast_kind(c, a) == Z3_NUMERAL_AST ||
2111  Z3_get_ast_kind(c, a) == Z3_VAR_AST ||
2113  return expr(c, a);
2114  }
2115 
2116  inline sort to_sort(context & c, Z3_sort s) {
2117  c.check_error();
2118  return sort(c, s);
2119  }
2120 
2121  inline func_decl to_func_decl(context & c, Z3_func_decl f) {
2122  c.check_error();
2123  return func_decl(c, f);
2124  }
2125 
2129  inline expr sle(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsle(a.ctx(), a, b)); }
2130  inline expr sle(expr const & a, int b) { return sle(a, a.ctx().num_val(b, a.get_sort())); }
2131  inline expr sle(int a, expr const & b) { return sle(b.ctx().num_val(a, b.get_sort()), b); }
2135  inline expr slt(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvslt(a.ctx(), a, b)); }
2136  inline expr slt(expr const & a, int b) { return slt(a, a.ctx().num_val(b, a.get_sort())); }
2137  inline expr slt(int a, expr const & b) { return slt(b.ctx().num_val(a, b.get_sort()), b); }
2141  inline expr sge(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsge(a.ctx(), a, b)); }
2142  inline expr sge(expr const & a, int b) { return sge(a, a.ctx().num_val(b, a.get_sort())); }
2143  inline expr sge(int a, expr const & b) { return sge(b.ctx().num_val(a, b.get_sort()), b); }
2147  inline expr sgt(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsgt(a.ctx(), a, b)); }
2148  inline expr sgt(expr const & a, int b) { return sgt(a, a.ctx().num_val(b, a.get_sort())); }
2149  inline expr sgt(int a, expr const & b) { return sgt(b.ctx().num_val(a, b.get_sort()), b); }
2150 
2151 
2155  inline expr ule(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvule(a.ctx(), a, b)); }
2156  inline expr ule(expr const & a, int b) { return ule(a, a.ctx().num_val(b, a.get_sort())); }
2157  inline expr ule(int a, expr const & b) { return ule(b.ctx().num_val(a, b.get_sort()), b); }
2161  inline expr ult(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvult(a.ctx(), a, b)); }
2162  inline expr ult(expr const & a, int b) { return ult(a, a.ctx().num_val(b, a.get_sort())); }
2163  inline expr ult(int a, expr const & b) { return ult(b.ctx().num_val(a, b.get_sort()), b); }
2167  inline expr uge(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b)); }
2168  inline expr uge(expr const & a, int b) { return uge(a, a.ctx().num_val(b, a.get_sort())); }
2169  inline expr uge(int a, expr const & b) { return uge(b.ctx().num_val(a, b.get_sort()), b); }
2173  inline expr ugt(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvugt(a.ctx(), a, b)); }
2174  inline expr ugt(expr const & a, int b) { return ugt(a, a.ctx().num_val(b, a.get_sort())); }
2175  inline expr ugt(int a, expr const & b) { return ugt(b.ctx().num_val(a, b.get_sort()), b); }
2179  inline expr udiv(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvudiv(a.ctx(), a, b)); }
2180  inline expr udiv(expr const & a, int b) { return udiv(a, a.ctx().num_val(b, a.get_sort())); }
2181  inline expr udiv(int a, expr const & b) { return udiv(b.ctx().num_val(a, b.get_sort()), b); }
2182 
2186  inline expr srem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsrem(a.ctx(), a, b)); }
2187  inline expr srem(expr const & a, int b) { return srem(a, a.ctx().num_val(b, a.get_sort())); }
2188  inline expr srem(int a, expr const & b) { return srem(b.ctx().num_val(a, b.get_sort()), b); }
2189 
2193  inline expr smod(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsmod(a.ctx(), a, b)); }
2194  inline expr smod(expr const & a, int b) { return smod(a, a.ctx().num_val(b, a.get_sort())); }
2195  inline expr smod(int a, expr const & b) { return smod(b.ctx().num_val(a, b.get_sort()), b); }
2196 
2200  inline expr urem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvurem(a.ctx(), a, b)); }
2201  inline expr urem(expr const & a, int b) { return urem(a, a.ctx().num_val(b, a.get_sort())); }
2202  inline expr urem(int a, expr const & b) { return urem(b.ctx().num_val(a, b.get_sort()), b); }
2203 
2207  inline expr shl(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvshl(a.ctx(), a, b)); }
2208  inline expr shl(expr const & a, int b) { return shl(a, a.ctx().num_val(b, a.get_sort())); }
2209  inline expr shl(int a, expr const & b) { return shl(b.ctx().num_val(a, b.get_sort()), b); }
2210 
2214  inline expr lshr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvlshr(a.ctx(), a, b)); }
2215  inline expr lshr(expr const & a, int b) { return lshr(a, a.ctx().num_val(b, a.get_sort())); }
2216  inline expr lshr(int a, expr const & b) { return lshr(b.ctx().num_val(a, b.get_sort()), b); }
2217 
2221  inline expr ashr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvashr(a.ctx(), a, b)); }
2222  inline expr ashr(expr const & a, int b) { return ashr(a, a.ctx().num_val(b, a.get_sort())); }
2223  inline expr ashr(int a, expr const & b) { return ashr(b.ctx().num_val(a, b.get_sort()), b); }
2224 
2228  inline expr zext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_zero_ext(a.ctx(), i, a)); }
2229 
2233  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); }
2234  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); }
2235 
2239  inline expr bvadd_no_overflow(expr const& a, expr const& b, bool is_signed) {
2240  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);
2241  }
2242  inline expr bvadd_no_underflow(expr const& a, expr const& b) {
2243  check_context(a, b); Z3_ast r = Z3_mk_bvadd_no_underflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2244  }
2245  inline expr bvsub_no_overflow(expr const& a, expr const& b) {
2246  check_context(a, b); Z3_ast r = Z3_mk_bvsub_no_overflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2247  }
2248  inline expr bvsub_no_underflow(expr const& a, expr const& b, bool is_signed) {
2249  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);
2250  }
2251  inline expr bvsdiv_no_overflow(expr const& a, expr const& b) {
2252  check_context(a, b); Z3_ast r = Z3_mk_bvsdiv_no_overflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2253  }
2254  inline expr bvneg_no_overflow(expr const& a) {
2255  Z3_ast r = Z3_mk_bvneg_no_overflow(a.ctx(), a); a.check_error(); return expr(a.ctx(), r);
2256  }
2257  inline expr bvmul_no_overflow(expr const& a, expr const& b, bool is_signed) {
2258  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);
2259  }
2260  inline expr bvmul_no_underflow(expr const& a, expr const& b) {
2261  check_context(a, b); Z3_ast r = Z3_mk_bvmul_no_underflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2262  }
2263 
2264 
2268  inline expr sext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_sign_ext(a.ctx(), i, a)); }
2269 
2270  inline func_decl linear_order(sort const& a, unsigned index) {
2271  return to_func_decl(a.ctx(), Z3_mk_linear_order(a.ctx(), a, index));
2272  }
2273  inline func_decl partial_order(sort const& a, unsigned index) {
2274  return to_func_decl(a.ctx(), Z3_mk_partial_order(a.ctx(), a, index));
2275  }
2276  inline func_decl piecewise_linear_order(sort const& a, unsigned index) {
2277  return to_func_decl(a.ctx(), Z3_mk_piecewise_linear_order(a.ctx(), a, index));
2278  }
2279  inline func_decl tree_order(sort const& a, unsigned index) {
2280  return to_func_decl(a.ctx(), Z3_mk_tree_order(a.ctx(), a, index));
2281  }
2282 
2283  template<> class cast_ast<ast> {
2284  public:
2285  ast operator()(context & c, Z3_ast a) { return ast(c, a); }
2286  };
2287 
2288  template<> class cast_ast<expr> {
2289  public:
2290  expr operator()(context & c, Z3_ast a) {
2291  assert(Z3_get_ast_kind(c, a) == Z3_NUMERAL_AST ||
2292  Z3_get_ast_kind(c, a) == Z3_APP_AST ||
2294  Z3_get_ast_kind(c, a) == Z3_VAR_AST);
2295  return expr(c, a);
2296  }
2297  };
2298 
2299  template<> class cast_ast<sort> {
2300  public:
2301  sort operator()(context & c, Z3_ast a) {
2302  assert(Z3_get_ast_kind(c, a) == Z3_SORT_AST);
2303  return sort(c, reinterpret_cast<Z3_sort>(a));
2304  }
2305  };
2306 
2307  template<> class cast_ast<func_decl> {
2308  public:
2309  func_decl operator()(context & c, Z3_ast a) {
2310  assert(Z3_get_ast_kind(c, a) == Z3_FUNC_DECL_AST);
2311  return func_decl(c, reinterpret_cast<Z3_func_decl>(a));
2312  }
2313  };
2314 
2315  template<typename T>
2316  template<typename T2>
2317  array<T>::array(ast_vector_tpl<T2> const & v):m_array(new T[v.size()]), m_size(v.size()) {
2318  for (unsigned i = 0; i < m_size; i++) {
2319  m_array[i] = v[i];
2320  }
2321  }
2322 
2323  // Basic functions for creating quantified formulas.
2324  // The C API should be used for creating quantifiers with patterns, weights, many variables, etc.
2325  inline expr forall(expr const & x, expr const & b) {
2326  check_context(x, b);
2327  Z3_app vars[] = {(Z3_app) x};
2328  Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 1, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2329  }
2330  inline expr forall(expr const & x1, expr const & x2, expr const & b) {
2331  check_context(x1, b); check_context(x2, b);
2332  Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2};
2333  Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 2, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2334  }
2335  inline expr forall(expr const & x1, expr const & x2, expr const & x3, expr const & b) {
2336  check_context(x1, b); check_context(x2, b); check_context(x3, b);
2337  Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3 };
2338  Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 3, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2339  }
2340  inline expr forall(expr const & x1, expr const & x2, expr const & x3, expr const & x4, expr const & b) {
2341  check_context(x1, b); check_context(x2, b); check_context(x3, b); check_context(x4, b);
2342  Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3, (Z3_app) x4 };
2343  Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 4, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2344  }
2345  inline expr forall(expr_vector const & xs, expr const & b) {
2346  array<Z3_app> vars(xs);
2347  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);
2348  }
2349  inline expr exists(expr const & x, expr const & b) {
2350  check_context(x, b);
2351  Z3_app vars[] = {(Z3_app) x};
2352  Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 1, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2353  }
2354  inline expr exists(expr const & x1, expr const & x2, expr const & b) {
2355  check_context(x1, b); check_context(x2, b);
2356  Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2};
2357  Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 2, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2358  }
2359  inline expr exists(expr const & x1, expr const & x2, expr const & x3, expr const & b) {
2360  check_context(x1, b); check_context(x2, b); check_context(x3, b);
2361  Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3 };
2362  Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 3, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2363  }
2364  inline expr exists(expr const & x1, expr const & x2, expr const & x3, expr const & x4, expr const & b) {
2365  check_context(x1, b); check_context(x2, b); check_context(x3, b); check_context(x4, b);
2366  Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3, (Z3_app) x4 };
2367  Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 4, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2368  }
2369  inline expr exists(expr_vector const & xs, expr const & b) {
2370  array<Z3_app> vars(xs);
2371  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);
2372  }
2373  inline expr lambda(expr const & x, expr const & b) {
2374  check_context(x, b);
2375  Z3_app vars[] = {(Z3_app) x};
2376  Z3_ast r = Z3_mk_lambda_const(b.ctx(), 1, vars, b); b.check_error(); return expr(b.ctx(), r);
2377  }
2378  inline expr lambda(expr const & x1, expr const & x2, expr const & b) {
2379  check_context(x1, b); check_context(x2, b);
2380  Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2};
2381  Z3_ast r = Z3_mk_lambda_const(b.ctx(), 2, vars, b); b.check_error(); return expr(b.ctx(), r);
2382  }
2383  inline expr lambda(expr const & x1, expr const & x2, expr const & x3, expr const & b) {
2384  check_context(x1, b); check_context(x2, b); check_context(x3, b);
2385  Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3 };
2386  Z3_ast r = Z3_mk_lambda_const(b.ctx(), 3, vars, b); b.check_error(); return expr(b.ctx(), r);
2387  }
2388  inline expr lambda(expr const & x1, expr const & x2, expr const & x3, expr const & x4, expr const & b) {
2389  check_context(x1, b); check_context(x2, b); check_context(x3, b); check_context(x4, b);
2390  Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3, (Z3_app) x4 };
2391  Z3_ast r = Z3_mk_lambda_const(b.ctx(), 4, vars, b); b.check_error(); return expr(b.ctx(), r);
2392  }
2393  inline expr lambda(expr_vector const & xs, expr const & b) {
2394  array<Z3_app> vars(xs);
2395  Z3_ast r = Z3_mk_lambda_const(b.ctx(), vars.size(), vars.ptr(), b); b.check_error(); return expr(b.ctx(), r);
2396  }
2397 
2398  inline expr pble(expr_vector const& es, int const* coeffs, int bound) {
2399  assert(es.size() > 0);
2400  context& ctx = es[0u].ctx();
2401  array<Z3_ast> _es(es);
2402  Z3_ast r = Z3_mk_pble(ctx, _es.size(), _es.ptr(), coeffs, bound);
2403  ctx.check_error();
2404  return expr(ctx, r);
2405  }
2406  inline expr pbge(expr_vector const& es, int const* coeffs, int bound) {
2407  assert(es.size() > 0);
2408  context& ctx = es[0u].ctx();
2409  array<Z3_ast> _es(es);
2410  Z3_ast r = Z3_mk_pbge(ctx, _es.size(), _es.ptr(), coeffs, bound);
2411  ctx.check_error();
2412  return expr(ctx, r);
2413  }
2414  inline expr pbeq(expr_vector const& es, int const* coeffs, int bound) {
2415  assert(es.size() > 0);
2416  context& ctx = es[0u].ctx();
2417  array<Z3_ast> _es(es);
2418  Z3_ast r = Z3_mk_pbeq(ctx, _es.size(), _es.ptr(), coeffs, bound);
2419  ctx.check_error();
2420  return expr(ctx, r);
2421  }
2422  inline expr atmost(expr_vector const& es, unsigned bound) {
2423  assert(es.size() > 0);
2424  context& ctx = es[0u].ctx();
2425  array<Z3_ast> _es(es);
2426  Z3_ast r = Z3_mk_atmost(ctx, _es.size(), _es.ptr(), bound);
2427  ctx.check_error();
2428  return expr(ctx, r);
2429  }
2430  inline expr atleast(expr_vector const& es, unsigned bound) {
2431  assert(es.size() > 0);
2432  context& ctx = es[0u].ctx();
2433  array<Z3_ast> _es(es);
2434  Z3_ast r = Z3_mk_atleast(ctx, _es.size(), _es.ptr(), bound);
2435  ctx.check_error();
2436  return expr(ctx, r);
2437  }
2438  inline expr sum(expr_vector const& args) {
2439  assert(args.size() > 0);
2440  context& ctx = args[0u].ctx();
2441  array<Z3_ast> _args(args);
2442  Z3_ast r = Z3_mk_add(ctx, _args.size(), _args.ptr());
2443  ctx.check_error();
2444  return expr(ctx, r);
2445  }
2446 
2447  inline expr distinct(expr_vector const& args) {
2448  assert(args.size() > 0);
2449  context& ctx = args[0u].ctx();
2450  array<Z3_ast> _args(args);
2451  Z3_ast r = Z3_mk_distinct(ctx, _args.size(), _args.ptr());
2452  ctx.check_error();
2453  return expr(ctx, r);
2454  }
2455 
2456  inline expr concat(expr const& a, expr const& b) {
2457  check_context(a, b);
2458  Z3_ast r;
2459  if (Z3_is_seq_sort(a.ctx(), a.get_sort())) {
2460  Z3_ast _args[2] = { a, b };
2461  r = Z3_mk_seq_concat(a.ctx(), 2, _args);
2462  }
2463  else if (Z3_is_re_sort(a.ctx(), a.get_sort())) {
2464  Z3_ast _args[2] = { a, b };
2465  r = Z3_mk_re_concat(a.ctx(), 2, _args);
2466  }
2467  else {
2468  r = Z3_mk_concat(a.ctx(), a, b);
2469  }
2470  a.ctx().check_error();
2471  return expr(a.ctx(), r);
2472  }
2473 
2474  inline expr concat(expr_vector const& args) {
2475  Z3_ast r;
2476  assert(args.size() > 0);
2477  if (args.size() == 1) {
2478  return args[0u];
2479  }
2480  context& ctx = args[0u].ctx();
2481  array<Z3_ast> _args(args);
2482  if (Z3_is_seq_sort(ctx, args[0u].get_sort())) {
2483  r = Z3_mk_seq_concat(ctx, _args.size(), _args.ptr());
2484  }
2485  else if (Z3_is_re_sort(ctx, args[0u].get_sort())) {
2486  r = Z3_mk_re_concat(ctx, _args.size(), _args.ptr());
2487  }
2488  else {
2489  r = _args[args.size()-1];
2490  for (unsigned i = args.size()-1; i > 0; ) {
2491  --i;
2492  r = Z3_mk_concat(ctx, _args[i], r);
2493  ctx.check_error();
2494  }
2495  }
2496  ctx.check_error();
2497  return expr(ctx, r);
2498  }
2499 
2500  inline expr map(expr const& f, expr const& list) {
2501  context& ctx = f.ctx();
2502  Z3_ast r = Z3_mk_seq_map(ctx, f, list);
2503  ctx.check_error();
2504  return expr(ctx, r);
2505  }
2506 
2507  inline expr mapi(expr const& f, expr const& i, expr const& list) {
2508  context& ctx = f.ctx();
2509  Z3_ast r = Z3_mk_seq_mapi(ctx, f, i, list);
2510  ctx.check_error();
2511  return expr(ctx, r);
2512  }
2513 
2514  inline expr foldl(expr const& f, expr const& a, expr const& list) {
2515  context& ctx = f.ctx();
2516  Z3_ast r = Z3_mk_seq_foldl(ctx, f, a, list);
2517  ctx.check_error();
2518  return expr(ctx, r);
2519  }
2520 
2521  inline expr foldli(expr const& f, expr const& i, expr const& a, expr const& list) {
2522  context& ctx = f.ctx();
2523  Z3_ast r = Z3_mk_seq_foldli(ctx, f, i, a, list);
2524  ctx.check_error();
2525  return expr(ctx, r);
2526  }
2527 
2528  inline expr mk_or(expr_vector const& args) {
2529  array<Z3_ast> _args(args);
2530  Z3_ast r = Z3_mk_or(args.ctx(), _args.size(), _args.ptr());
2531  args.check_error();
2532  return expr(args.ctx(), r);
2533  }
2534  inline expr mk_and(expr_vector const& args) {
2535  array<Z3_ast> _args(args);
2536  Z3_ast r = Z3_mk_and(args.ctx(), _args.size(), _args.ptr());
2537  args.check_error();
2538  return expr(args.ctx(), r);
2539  }
2540  inline expr mk_xor(expr_vector const& args) {
2541  if (args.empty())
2542  return args.ctx().bool_val(false);
2543  expr r = args[0u];
2544  for (unsigned i = 1; i < args.size(); ++i)
2545  r = r ^ args[i];
2546  return r;
2547  }
2548 
2549 
2550  class func_entry : public object {
2551  Z3_func_entry m_entry;
2552  void init(Z3_func_entry e) {
2553  m_entry = e;
2554  Z3_func_entry_inc_ref(ctx(), m_entry);
2555  }
2556  public:
2557  func_entry(context & c, Z3_func_entry e):object(c) { init(e); }
2558  func_entry(func_entry const & s):object(s) { init(s.m_entry); }
2559  ~func_entry() override { Z3_func_entry_dec_ref(ctx(), m_entry); }
2560  operator Z3_func_entry() const { return m_entry; }
2562  Z3_func_entry_inc_ref(s.ctx(), s.m_entry);
2563  Z3_func_entry_dec_ref(ctx(), m_entry);
2564  object::operator=(s);
2565  m_entry = s.m_entry;
2566  return *this;
2567  }
2568  expr value() const { Z3_ast r = Z3_func_entry_get_value(ctx(), m_entry); check_error(); return expr(ctx(), r); }
2569  unsigned num_args() const { unsigned r = Z3_func_entry_get_num_args(ctx(), m_entry); check_error(); return r; }
2570  expr arg(unsigned i) const { Z3_ast r = Z3_func_entry_get_arg(ctx(), m_entry, i); check_error(); return expr(ctx(), r); }
2571  };
2572 
2573  class func_interp : public object {
2574  Z3_func_interp m_interp;
2575  void init(Z3_func_interp e) {
2576  m_interp = e;
2577  Z3_func_interp_inc_ref(ctx(), m_interp);
2578  }
2579  public:
2580  func_interp(context & c, Z3_func_interp e):object(c) { init(e); }
2581  func_interp(func_interp const & s):object(s) { init(s.m_interp); }
2582  ~func_interp() override { Z3_func_interp_dec_ref(ctx(), m_interp); }
2583  operator Z3_func_interp() const { return m_interp; }
2585  Z3_func_interp_inc_ref(s.ctx(), s.m_interp);
2586  Z3_func_interp_dec_ref(ctx(), m_interp);
2587  object::operator=(s);
2588  m_interp = s.m_interp;
2589  return *this;
2590  }
2591  expr else_value() const { Z3_ast r = Z3_func_interp_get_else(ctx(), m_interp); check_error(); return expr(ctx(), r); }
2592  unsigned num_entries() const { unsigned r = Z3_func_interp_get_num_entries(ctx(), m_interp); check_error(); return r; }
2593  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); }
2594  void add_entry(expr_vector const& args, expr& value) {
2595  Z3_func_interp_add_entry(ctx(), m_interp, args, value);
2596  check_error();
2597  }
2598  void set_else(expr& value) {
2599  Z3_func_interp_set_else(ctx(), m_interp, value);
2600  check_error();
2601  }
2602  };
2603 
2604  class model : public object {
2605  Z3_model m_model;
2606  void init(Z3_model m) {
2607  m_model = m;
2608  Z3_model_inc_ref(ctx(), m);
2609  }
2610  public:
2611  struct translate {};
2612  model(context & c):object(c) { init(Z3_mk_model(c)); }
2613  model(context & c, Z3_model m):object(c) { init(m); }
2614  model(model const & s):object(s) { init(s.m_model); }
2615  model(model& src, context& dst, translate) : object(dst) { init(Z3_model_translate(src.ctx(), src, dst)); }
2616  ~model() override { Z3_model_dec_ref(ctx(), m_model); }
2617  operator Z3_model() const { return m_model; }
2618  model & operator=(model const & s) {
2619  Z3_model_inc_ref(s.ctx(), s.m_model);
2620  Z3_model_dec_ref(ctx(), m_model);
2621  object::operator=(s);
2622  m_model = s.m_model;
2623  return *this;
2624  }
2625 
2626  expr eval(expr const & n, bool model_completion=false) const {
2627  check_context(*this, n);
2628  Z3_ast r = 0;
2629  bool status = Z3_model_eval(ctx(), m_model, n, model_completion, &r);
2630  check_error();
2631  if (status == false && ctx().enable_exceptions())
2632  Z3_THROW(exception("failed to evaluate expression"));
2633  return expr(ctx(), r);
2634  }
2635 
2636  unsigned num_consts() const { return Z3_model_get_num_consts(ctx(), m_model); }
2637  unsigned num_funcs() const { return Z3_model_get_num_funcs(ctx(), m_model); }
2638  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); }
2639  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); }
2640  unsigned size() const { return num_consts() + num_funcs(); }
2641  func_decl operator[](int i) const {
2642  assert(0 <= i);
2643  return static_cast<unsigned>(i) < num_consts() ? get_const_decl(i) : get_func_decl(i - num_consts());
2644  }
2645 
2646  // returns interpretation of constant declaration c.
2647  // If c is not assigned any value in the model it returns
2648  // an expression with a null ast reference.
2650  check_context(*this, c);
2651  Z3_ast r = Z3_model_get_const_interp(ctx(), m_model, c);
2652  check_error();
2653  return expr(ctx(), r);
2654  }
2656  check_context(*this, f);
2657  Z3_func_interp r = Z3_model_get_func_interp(ctx(), m_model, f);
2658  check_error();
2659  return func_interp(ctx(), r);
2660  }
2661 
2662  // returns true iff the model contains an interpretation
2663  // for function f.
2664  bool has_interp(func_decl f) const {
2665  check_context(*this, f);
2666  return Z3_model_has_interp(ctx(), m_model, f);
2667  }
2668 
2670  Z3_func_interp r = Z3_add_func_interp(ctx(), m_model, f, else_val);
2671  check_error();
2672  return func_interp(ctx(), r);
2673  }
2674 
2675  void add_const_interp(func_decl& f, expr& value) {
2676  Z3_add_const_interp(ctx(), m_model, f, value);
2677  check_error();
2678  }
2679 
2680  friend std::ostream & operator<<(std::ostream & out, model const & m);
2681 
2682  std::string to_string() const { return m_model ? std::string(Z3_model_to_string(ctx(), m_model)) : "null"; }
2683  };
2684  inline std::ostream & operator<<(std::ostream & out, model const & m) { return out << m.to_string(); }
2685 
2686  class stats : public object {
2687  Z3_stats m_stats;
2688  void init(Z3_stats e) {
2689  m_stats = e;
2690  Z3_stats_inc_ref(ctx(), m_stats);
2691  }
2692  public:
2693  stats(context & c):object(c), m_stats(0) {}
2694  stats(context & c, Z3_stats e):object(c) { init(e); }
2695  stats(stats const & s):object(s) { init(s.m_stats); }
2696  ~stats() override { if (m_stats) Z3_stats_dec_ref(ctx(), m_stats); }
2697  operator Z3_stats() const { return m_stats; }
2698  stats & operator=(stats const & s) {
2699  Z3_stats_inc_ref(s.ctx(), s.m_stats);
2700  if (m_stats) Z3_stats_dec_ref(ctx(), m_stats);
2701  object::operator=(s);
2702  m_stats = s.m_stats;
2703  return *this;
2704  }
2705  unsigned size() const { return Z3_stats_size(ctx(), m_stats); }
2706  std::string key(unsigned i) const { Z3_string s = Z3_stats_get_key(ctx(), m_stats, i); check_error(); return s; }
2707  bool is_uint(unsigned i) const { bool r = Z3_stats_is_uint(ctx(), m_stats, i); check_error(); return r; }
2708  bool is_double(unsigned i) const { bool r = Z3_stats_is_double(ctx(), m_stats, i); check_error(); return r; }
2709  unsigned uint_value(unsigned i) const { unsigned r = Z3_stats_get_uint_value(ctx(), m_stats, i); check_error(); return r; }
2710  double double_value(unsigned i) const { double r = Z3_stats_get_double_value(ctx(), m_stats, i); check_error(); return r; }
2711  friend std::ostream & operator<<(std::ostream & out, stats const & s);
2712  };
2713  inline std::ostream & operator<<(std::ostream & out, stats const & s) { out << Z3_stats_to_string(s.ctx(), s); return out; }
2714 
2715 
2716  inline std::ostream & operator<<(std::ostream & out, check_result r) {
2717  if (r == unsat) out << "unsat";
2718  else if (r == sat) out << "sat";
2719  else out << "unknown";
2720  return out;
2721  }
2722 
2733  class parameter {
2734  Z3_parameter_kind m_kind;
2735  func_decl m_decl;
2736  unsigned m_index;
2737  context& ctx() const { return m_decl.ctx(); }
2738  void check_error() const { ctx().check_error(); }
2739  public:
2740  parameter(func_decl const& d, unsigned idx) : m_decl(d), m_index(idx) {
2741  if (ctx().enable_exceptions() && idx >= d.num_parameters())
2742  Z3_THROW(exception("parameter index is out of bounds"));
2743  m_kind = Z3_get_decl_parameter_kind(ctx(), d, idx);
2744  }
2745  parameter(expr const& e, unsigned idx) : m_decl(e.decl()), m_index(idx) {
2746  if (ctx().enable_exceptions() && idx >= m_decl.num_parameters())
2747  Z3_THROW(exception("parameter index is out of bounds"));
2748  m_kind = Z3_get_decl_parameter_kind(ctx(), m_decl, idx);
2749  }
2750  Z3_parameter_kind kind() const { return m_kind; }
2751  expr get_expr() const { Z3_ast a = Z3_get_decl_ast_parameter(ctx(), m_decl, m_index); check_error(); return expr(ctx(), a); }
2752  sort get_sort() const { Z3_sort s = Z3_get_decl_sort_parameter(ctx(), m_decl, m_index); check_error(); return sort(ctx(), s); }
2753  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); }
2754  symbol get_symbol() const { Z3_symbol s = Z3_get_decl_symbol_parameter(ctx(), m_decl, m_index); check_error(); return symbol(ctx(), s); }
2755  std::string get_rational() const { Z3_string s = Z3_get_decl_rational_parameter(ctx(), m_decl, m_index); check_error(); return s; }
2756  double get_double() const { double d = Z3_get_decl_double_parameter(ctx(), m_decl, m_index); check_error(); return d; }
2757  int get_int() const { int i = Z3_get_decl_int_parameter(ctx(), m_decl, m_index); check_error(); return i; }
2758  };
2759 
2760 
2761  class solver : public object {
2762  Z3_solver m_solver;
2763  void init(Z3_solver s) {
2764  m_solver = s;
2765  if (s)
2766  Z3_solver_inc_ref(ctx(), s);
2767  }
2768  public:
2769  struct simple {};
2770  struct translate {};
2771  solver(context & c):object(c) { init(Z3_mk_solver(c)); check_error(); }
2773  solver(context & c, Z3_solver s):object(c) { init(s); }
2774  solver(context & c, char const * logic):object(c) { init(Z3_mk_solver_for_logic(c, c.str_symbol(logic))); check_error(); }
2775  solver(context & c, solver const& src, translate): object(c) { Z3_solver s = Z3_solver_translate(src.ctx(), src, c); check_error(); init(s); }
2776  solver(solver const & s):object(s) { init(s.m_solver); }
2777  solver(solver const& s, simplifier const& simp);
2778  ~solver() override { Z3_solver_dec_ref(ctx(), m_solver); }
2779  operator Z3_solver() const { return m_solver; }
2780  solver & operator=(solver const & s) {
2781  Z3_solver_inc_ref(s.ctx(), s.m_solver);
2782  Z3_solver_dec_ref(ctx(), m_solver);
2783  object::operator=(s);
2784  m_solver = s.m_solver;
2785  return *this;
2786  }
2787  void set(params const & p) { Z3_solver_set_params(ctx(), m_solver, p); check_error(); }
2788  void set(char const * k, bool v) { params p(ctx()); p.set(k, v); set(p); }
2789  void set(char const * k, unsigned v) { params p(ctx()); p.set(k, v); set(p); }
2790  void set(char const * k, double v) { params p(ctx()); p.set(k, v); set(p); }
2791  void set(char const * k, symbol const & v) { params p(ctx()); p.set(k, v); set(p); }
2792  void set(char const * k, char const* v) { params p(ctx()); p.set(k, v); set(p); }
2803  void push() { Z3_solver_push(ctx(), m_solver); check_error(); }
2804  void pop(unsigned n = 1) { Z3_solver_pop(ctx(), m_solver, n); check_error(); }
2805  void reset() { Z3_solver_reset(ctx(), m_solver); check_error(); }
2806  void add(expr const & e) { assert(e.is_bool()); Z3_solver_assert(ctx(), m_solver, e); check_error(); }
2807  void add(expr const & e, expr const & p) {
2808  assert(e.is_bool()); assert(p.is_bool()); assert(p.is_const());
2809  Z3_solver_assert_and_track(ctx(), m_solver, e, p);
2810  check_error();
2811  }
2812  void add(expr const & e, char const * p) {
2813  add(e, ctx().bool_const(p));
2814  }
2815  void add(expr_vector const& v) {
2816  check_context(*this, v);
2817  for (unsigned i = 0; i < v.size(); ++i)
2818  add(v[i]);
2819  }
2820  void from_file(char const* file) { Z3_solver_from_file(ctx(), m_solver, file); ctx().check_parser_error(); }
2821  void from_string(char const* s) { Z3_solver_from_string(ctx(), m_solver, s); ctx().check_parser_error(); }
2822 
2824  check_result check(unsigned n, expr * const assumptions) {
2825  array<Z3_ast> _assumptions(n);
2826  for (unsigned i = 0; i < n; i++) {
2827  check_context(*this, assumptions[i]);
2828  _assumptions[i] = assumptions[i];
2829  }
2830  Z3_lbool r = Z3_solver_check_assumptions(ctx(), m_solver, n, _assumptions.ptr());
2831  check_error();
2832  return to_check_result(r);
2833  }
2834  check_result check(expr_vector const& assumptions) {
2835  unsigned n = assumptions.size();
2836  array<Z3_ast> _assumptions(n);
2837  for (unsigned i = 0; i < n; i++) {
2838  check_context(*this, assumptions[i]);
2839  _assumptions[i] = assumptions[i];
2840  }
2841  Z3_lbool r = Z3_solver_check_assumptions(ctx(), m_solver, n, _assumptions.ptr());
2842  check_error();
2843  return to_check_result(r);
2844  }
2845  model get_model() const { Z3_model m = Z3_solver_get_model(ctx(), m_solver); check_error(); return model(ctx(), m); }
2846  check_result consequences(expr_vector& assumptions, expr_vector& vars, expr_vector& conseq) {
2847  Z3_lbool r = Z3_solver_get_consequences(ctx(), m_solver, assumptions, vars, conseq);
2848  check_error();
2849  return to_check_result(r);
2850  }
2851  std::string reason_unknown() const { Z3_string r = Z3_solver_get_reason_unknown(ctx(), m_solver); check_error(); return r; }
2852  stats statistics() const { Z3_stats r = Z3_solver_get_statistics(ctx(), m_solver); check_error(); return stats(ctx(), r); }
2853  expr_vector unsat_core() const { Z3_ast_vector r = Z3_solver_get_unsat_core(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2854  expr_vector assertions() const { Z3_ast_vector r = Z3_solver_get_assertions(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2855  expr_vector non_units() const { Z3_ast_vector r = Z3_solver_get_non_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2856  expr_vector units() const { Z3_ast_vector r = Z3_solver_get_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2857  expr_vector trail() const { Z3_ast_vector r = Z3_solver_get_trail(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2858  expr_vector trail(array<unsigned>& levels) const {
2859  Z3_ast_vector r = Z3_solver_get_trail(ctx(), m_solver);
2860  check_error();
2861  expr_vector result(ctx(), r);
2862  unsigned sz = result.size();
2863  levels.resize(sz);
2864  Z3_solver_get_levels(ctx(), m_solver, r, sz, levels.ptr());
2865  check_error();
2866  return result;
2867  }
2868  void set_initial_value(expr const& var, expr const& value) {
2869  Z3_solver_set_initial_value(ctx(), m_solver, var, value);
2870  check_error();
2871  }
2872  void set_initial_value(expr const& var, int i) {
2873  set_initial_value(var, ctx().num_val(i, var.get_sort()));
2874  }
2875  void set_initial_value(expr const& var, bool b) {
2876  set_initial_value(var, ctx().bool_val(b));
2877  }
2878 
2879  expr proof() const { Z3_ast r = Z3_solver_get_proof(ctx(), m_solver); check_error(); return expr(ctx(), r); }
2880  friend std::ostream & operator<<(std::ostream & out, solver const & s);
2881 
2882  std::string to_smt2(char const* status = "unknown") {
2883  array<Z3_ast> es(assertions());
2884  Z3_ast const* fmls = es.ptr();
2885  Z3_ast fml = 0;
2886  unsigned sz = es.size();
2887  if (sz > 0) {
2888  --sz;
2889  fml = fmls[sz];
2890  }
2891  else {
2892  fml = ctx().bool_val(true);
2893  }
2894  return std::string(Z3_benchmark_to_smtlib_string(
2895  ctx(),
2896  "", "", status, "",
2897  sz,
2898  fmls,
2899  fml));
2900  }
2901 
2902  std::string dimacs(bool include_names = true) const { return std::string(Z3_solver_to_dimacs_string(ctx(), m_solver, include_names)); }
2903 
2905 
2906 
2907  expr_vector cube(expr_vector& vars, unsigned cutoff) {
2908  Z3_ast_vector r = Z3_solver_cube(ctx(), m_solver, vars, cutoff);
2909  check_error();
2910  return expr_vector(ctx(), r);
2911  }
2912 
2914  solver& m_solver;
2915  unsigned& m_cutoff;
2916  expr_vector& m_vars;
2917  expr_vector m_cube;
2918  bool m_end;
2919  bool m_empty;
2920 
2921  void inc() {
2922  assert(!m_end && !m_empty);
2923  m_cube = m_solver.cube(m_vars, m_cutoff);
2924  m_cutoff = 0xFFFFFFFF;
2925  if (m_cube.size() == 1 && m_cube[0u].is_false()) {
2926  m_cube = z3::expr_vector(m_solver.ctx());
2927  m_end = true;
2928  }
2929  else if (m_cube.empty()) {
2930  m_empty = true;
2931  }
2932  }
2933  public:
2934  cube_iterator(solver& s, expr_vector& vars, unsigned& cutoff, bool end):
2935  m_solver(s),
2936  m_cutoff(cutoff),
2937  m_vars(vars),
2938  m_cube(s.ctx()),
2939  m_end(end),
2940  m_empty(false) {
2941  if (!m_end) {
2942  inc();
2943  }
2944  }
2945 
2947  assert(!m_end);
2948  if (m_empty) {
2949  m_end = true;
2950  }
2951  else {
2952  inc();
2953  }
2954  return *this;
2955  }
2956  cube_iterator operator++(int) { assert(false); return *this; }
2957  expr_vector const * operator->() const { return &(operator*()); }
2958  expr_vector const& operator*() const noexcept { return m_cube; }
2959 
2960  bool operator==(cube_iterator const& other) const noexcept {
2961  return other.m_end == m_end;
2962  };
2963  bool operator!=(cube_iterator const& other) const noexcept {
2964  return other.m_end != m_end;
2965  };
2966 
2967  };
2968 
2970  solver& m_solver;
2971  unsigned m_cutoff;
2972  expr_vector m_default_vars;
2973  expr_vector& m_vars;
2974  public:
2976  m_solver(s),
2977  m_cutoff(0xFFFFFFFF),
2978  m_default_vars(s.ctx()),
2979  m_vars(m_default_vars)
2980  {}
2981 
2982  cube_generator(solver& s, expr_vector& vars):
2983  m_solver(s),
2984  m_cutoff(0xFFFFFFFF),
2985  m_default_vars(s.ctx()),
2986  m_vars(vars)
2987  {}
2988 
2989  cube_iterator begin() { return cube_iterator(m_solver, m_vars, m_cutoff, false); }
2990  cube_iterator end() { return cube_iterator(m_solver, m_vars, m_cutoff, true); }
2991  void set_cutoff(unsigned c) noexcept { m_cutoff = c; }
2992  };
2993 
2994  cube_generator cubes() { return cube_generator(*this); }
2995  cube_generator cubes(expr_vector& vars) { return cube_generator(*this, vars); }
2996 
2997  };
2998  inline std::ostream & operator<<(std::ostream & out, solver const & s) { out << Z3_solver_to_string(s.ctx(), s); return out; }
2999 
3000  class goal : public object {
3001  Z3_goal m_goal;
3002  void init(Z3_goal s) {
3003  m_goal = s;
3004  Z3_goal_inc_ref(ctx(), s);
3005  }
3006  public:
3007  goal(context & c, bool models=true, bool unsat_cores=false, bool proofs=false):object(c) { init(Z3_mk_goal(c, models, unsat_cores, proofs)); }
3008  goal(context & c, Z3_goal s):object(c) { init(s); }
3009  goal(goal const & s):object(s) { init(s.m_goal); }
3010  ~goal() override { Z3_goal_dec_ref(ctx(), m_goal); }
3011  operator Z3_goal() const { return m_goal; }
3012  goal & operator=(goal const & s) {
3013  Z3_goal_inc_ref(s.ctx(), s.m_goal);
3014  Z3_goal_dec_ref(ctx(), m_goal);
3015  object::operator=(s);
3016  m_goal = s.m_goal;
3017  return *this;
3018  }
3019  void add(expr const & f) { check_context(*this, f); Z3_goal_assert(ctx(), m_goal, f); check_error(); }
3020  void add(expr_vector const& v) { check_context(*this, v); for (unsigned i = 0; i < v.size(); ++i) add(v[i]); }
3021  unsigned size() const { return Z3_goal_size(ctx(), m_goal); }
3022  expr operator[](int i) const { assert(0 <= i); Z3_ast r = Z3_goal_formula(ctx(), m_goal, i); check_error(); return expr(ctx(), r); }
3023  Z3_goal_prec precision() const { return Z3_goal_precision(ctx(), m_goal); }
3024  bool inconsistent() const { return Z3_goal_inconsistent(ctx(), m_goal); }
3025  unsigned depth() const { return Z3_goal_depth(ctx(), m_goal); }
3026  void reset() { Z3_goal_reset(ctx(), m_goal); }
3027  unsigned num_exprs() const { return Z3_goal_num_exprs(ctx(), m_goal); }
3028  bool is_decided_sat() const { return Z3_goal_is_decided_sat(ctx(), m_goal); }
3029  bool is_decided_unsat() const { return Z3_goal_is_decided_unsat(ctx(), m_goal); }
3030  model convert_model(model const & m) const {
3031  check_context(*this, m);
3032  Z3_model new_m = Z3_goal_convert_model(ctx(), m_goal, m);
3033  check_error();
3034  return model(ctx(), new_m);
3035  }
3036  model get_model() const {
3037  Z3_model new_m = Z3_goal_convert_model(ctx(), m_goal, 0);
3038  check_error();
3039  return model(ctx(), new_m);
3040  }
3041  expr as_expr() const {
3042  unsigned n = size();
3043  if (n == 0)
3044  return ctx().bool_val(true);
3045  else if (n == 1)
3046  return operator[](0u);
3047  else {
3048  array<Z3_ast> args(n);
3049  for (unsigned i = 0; i < n; i++)
3050  args[i] = operator[](i);
3051  return expr(ctx(), Z3_mk_and(ctx(), n, args.ptr()));
3052  }
3053  }
3054  std::string dimacs(bool include_names = true) const { return std::string(Z3_goal_to_dimacs_string(ctx(), m_goal, include_names)); }
3055  friend std::ostream & operator<<(std::ostream & out, goal const & g);
3056  };
3057  inline std::ostream & operator<<(std::ostream & out, goal const & g) { out << Z3_goal_to_string(g.ctx(), g); return out; }
3058 
3059  class apply_result : public object {
3060  Z3_apply_result m_apply_result;
3061  void init(Z3_apply_result s) {
3062  m_apply_result = s;
3064  }
3065  public:
3066  apply_result(context & c, Z3_apply_result s):object(c) { init(s); }
3067  apply_result(apply_result const & s):object(s) { init(s.m_apply_result); }
3068  ~apply_result() override { Z3_apply_result_dec_ref(ctx(), m_apply_result); }
3069  operator Z3_apply_result() const { return m_apply_result; }
3071  Z3_apply_result_inc_ref(s.ctx(), s.m_apply_result);
3072  Z3_apply_result_dec_ref(ctx(), m_apply_result);
3073  object::operator=(s);
3074  m_apply_result = s.m_apply_result;
3075  return *this;
3076  }
3077  unsigned size() const { return Z3_apply_result_get_num_subgoals(ctx(), m_apply_result); }
3078  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); }
3079  friend std::ostream & operator<<(std::ostream & out, apply_result const & r);
3080  };
3081  inline std::ostream & operator<<(std::ostream & out, apply_result const & r) { out << Z3_apply_result_to_string(r.ctx(), r); return out; }
3082 
3083  class tactic : public object {
3084  Z3_tactic m_tactic;
3085  void init(Z3_tactic s) {
3086  m_tactic = s;
3087  Z3_tactic_inc_ref(ctx(), s);
3088  }
3089  public:
3090  tactic(context & c, char const * name):object(c) { Z3_tactic r = Z3_mk_tactic(c, name); check_error(); init(r); }
3091  tactic(context & c, Z3_tactic s):object(c) { init(s); }
3092  tactic(tactic const & s):object(s) { init(s.m_tactic); }
3093  ~tactic() override { Z3_tactic_dec_ref(ctx(), m_tactic); }
3094  operator Z3_tactic() const { return m_tactic; }
3095  tactic & operator=(tactic const & s) {
3096  Z3_tactic_inc_ref(s.ctx(), s.m_tactic);
3097  Z3_tactic_dec_ref(ctx(), m_tactic);
3098  object::operator=(s);
3099  m_tactic = s.m_tactic;
3100  return *this;
3101  }
3102  solver mk_solver() const { Z3_solver r = Z3_mk_solver_from_tactic(ctx(), m_tactic); check_error(); return solver(ctx(), r); }
3103  apply_result apply(goal const & g) const {
3104  check_context(*this, g);
3105  Z3_apply_result r = Z3_tactic_apply(ctx(), m_tactic, g);
3106  check_error();
3107  return apply_result(ctx(), r);
3108  }
3109  apply_result operator()(goal const & g) const {
3110  return apply(g);
3111  }
3112  std::string help() const { char const * r = Z3_tactic_get_help(ctx(), m_tactic); check_error(); return r; }
3113  friend tactic operator&(tactic const & t1, tactic const & t2);
3114  friend tactic operator|(tactic const & t1, tactic const & t2);
3115  friend tactic repeat(tactic const & t, unsigned max);
3116  friend tactic with(tactic const & t, params const & p);
3117  friend tactic try_for(tactic const & t, unsigned ms);
3118  friend tactic par_or(unsigned n, tactic const* tactics);
3119  friend tactic par_and_then(tactic const& t1, tactic const& t2);
3121  };
3122 
3123  inline tactic operator&(tactic const & t1, tactic const & t2) {
3124  check_context(t1, t2);
3125  Z3_tactic r = Z3_tactic_and_then(t1.ctx(), t1, t2);
3126  t1.check_error();
3127  return tactic(t1.ctx(), r);
3128  }
3129 
3130  inline tactic operator|(tactic const & t1, tactic const & t2) {
3131  check_context(t1, t2);
3132  Z3_tactic r = Z3_tactic_or_else(t1.ctx(), t1, t2);
3133  t1.check_error();
3134  return tactic(t1.ctx(), r);
3135  }
3136 
3137  inline tactic repeat(tactic const & t, unsigned max=UINT_MAX) {
3138  Z3_tactic r = Z3_tactic_repeat(t.ctx(), t, max);
3139  t.check_error();
3140  return tactic(t.ctx(), r);
3141  }
3142 
3143  inline tactic with(tactic const & t, params const & p) {
3144  Z3_tactic r = Z3_tactic_using_params(t.ctx(), t, p);
3145  t.check_error();
3146  return tactic(t.ctx(), r);
3147  }
3148  inline tactic try_for(tactic const & t, unsigned ms) {
3149  Z3_tactic r = Z3_tactic_try_for(t.ctx(), t, ms);
3150  t.check_error();
3151  return tactic(t.ctx(), r);
3152  }
3153  inline tactic par_or(unsigned n, tactic const* tactics) {
3154  if (n == 0) {
3155  Z3_THROW(exception("a non-zero number of tactics need to be passed to par_or"));
3156  }
3157  array<Z3_tactic> buffer(n);
3158  for (unsigned i = 0; i < n; ++i) buffer[i] = tactics[i];
3159  return tactic(tactics[0u].ctx(), Z3_tactic_par_or(tactics[0u].ctx(), n, buffer.ptr()));
3160  }
3161 
3162  inline tactic par_and_then(tactic const & t1, tactic const & t2) {
3163  check_context(t1, t2);
3164  Z3_tactic r = Z3_tactic_par_and_then(t1.ctx(), t1, t2);
3165  t1.check_error();
3166  return tactic(t1.ctx(), r);
3167  }
3168 
3169  class simplifier : public object {
3170  Z3_simplifier m_simplifier;
3171  void init(Z3_simplifier s) {
3172  m_simplifier = s;
3173  Z3_simplifier_inc_ref(ctx(), s);
3174  }
3175  public:
3176  simplifier(context & c, char const * name):object(c) { Z3_simplifier r = Z3_mk_simplifier(c, name); check_error(); init(r); }
3177  simplifier(context & c, Z3_simplifier s):object(c) { init(s); }
3178  simplifier(simplifier const & s):object(s) { init(s.m_simplifier); }
3179  ~simplifier() override { Z3_simplifier_dec_ref(ctx(), m_simplifier); }
3180  operator Z3_simplifier() const { return m_simplifier; }
3182  Z3_simplifier_inc_ref(s.ctx(), s.m_simplifier);
3183  Z3_simplifier_dec_ref(ctx(), m_simplifier);
3184  object::operator=(s);
3185  m_simplifier = s.m_simplifier;
3186  return *this;
3187  }
3188  std::string help() const { char const * r = Z3_simplifier_get_help(ctx(), m_simplifier); check_error(); return r; }
3189  friend simplifier operator&(simplifier const & t1, simplifier const & t2);
3190  friend simplifier with(simplifier const & t, params const & p);
3192  };
3193 
3194  inline solver::solver(solver const& s, simplifier const& simp):object(s) { init(Z3_solver_add_simplifier(s.ctx(), s, simp)); }
3195 
3196 
3197  inline simplifier operator&(simplifier const & t1, simplifier const & t2) {
3198  check_context(t1, t2);
3199  Z3_simplifier r = Z3_simplifier_and_then(t1.ctx(), t1, t2);
3200  t1.check_error();
3201  return simplifier(t1.ctx(), r);
3202  }
3203 
3204  inline simplifier with(simplifier const & t, params const & p) {
3205  Z3_simplifier r = Z3_simplifier_using_params(t.ctx(), t, p);
3206  t.check_error();
3207  return simplifier(t.ctx(), r);
3208  }
3209 
3210  class probe : public object {
3211  Z3_probe m_probe;
3212  void init(Z3_probe s) {
3213  m_probe = s;
3214  Z3_probe_inc_ref(ctx(), s);
3215  }
3216  public:
3217  probe(context & c, char const * name):object(c) { Z3_probe r = Z3_mk_probe(c, name); check_error(); init(r); }
3218  probe(context & c, double val):object(c) { Z3_probe r = Z3_probe_const(c, val); check_error(); init(r); }
3219  probe(context & c, Z3_probe s):object(c) { init(s); }
3220  probe(probe const & s):object(s) { init(s.m_probe); }
3221  ~probe() override { Z3_probe_dec_ref(ctx(), m_probe); }
3222  operator Z3_probe() const { return m_probe; }
3223  probe & operator=(probe const & s) {
3224  Z3_probe_inc_ref(s.ctx(), s.m_probe);
3225  Z3_probe_dec_ref(ctx(), m_probe);
3226  object::operator=(s);
3227  m_probe = s.m_probe;
3228  return *this;
3229  }
3230  double apply(goal const & g) const { double r = Z3_probe_apply(ctx(), m_probe, g); check_error(); return r; }
3231  double operator()(goal const & g) const { return apply(g); }
3232  friend probe operator<=(probe const & p1, probe const & p2);
3233  friend probe operator<=(probe const & p1, double p2);
3234  friend probe operator<=(double p1, probe const & p2);
3235  friend probe operator>=(probe const & p1, probe const & p2);
3236  friend probe operator>=(probe const & p1, double p2);
3237  friend probe operator>=(double p1, probe const & p2);
3238  friend probe operator<(probe const & p1, probe const & p2);
3239  friend probe operator<(probe const & p1, double p2);
3240  friend probe operator<(double p1, probe const & p2);
3241  friend probe operator>(probe const & p1, probe const & p2);
3242  friend probe operator>(probe const & p1, double p2);
3243  friend probe operator>(double p1, probe const & p2);
3244  friend probe operator==(probe const & p1, probe const & p2);
3245  friend probe operator==(probe const & p1, double p2);
3246  friend probe operator==(double p1, probe const & p2);
3247  friend probe operator&&(probe const & p1, probe const & p2);
3248  friend probe operator||(probe const & p1, probe const & p2);
3249  friend probe operator!(probe const & p);
3250  };
3251 
3252  inline probe operator<=(probe const & p1, probe const & p2) {
3253  check_context(p1, p2); Z3_probe r = Z3_probe_le(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3254  }
3255  inline probe operator<=(probe const & p1, double p2) { return p1 <= probe(p1.ctx(), p2); }
3256  inline probe operator<=(double p1, probe const & p2) { return probe(p2.ctx(), p1) <= p2; }
3257  inline probe operator>=(probe const & p1, probe const & p2) {
3258  check_context(p1, p2); Z3_probe r = Z3_probe_ge(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3259  }
3260  inline probe operator>=(probe const & p1, double p2) { return p1 >= probe(p1.ctx(), p2); }
3261  inline probe operator>=(double p1, probe const & p2) { return probe(p2.ctx(), p1) >= p2; }
3262  inline probe operator<(probe const & p1, probe const & p2) {
3263  check_context(p1, p2); Z3_probe r = Z3_probe_lt(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3264  }
3265  inline probe operator<(probe const & p1, double p2) { return p1 < probe(p1.ctx(), p2); }
3266  inline probe operator<(double p1, probe const & p2) { return probe(p2.ctx(), p1) < p2; }
3267  inline probe operator>(probe const & p1, probe const & p2) {
3268  check_context(p1, p2); Z3_probe r = Z3_probe_gt(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3269  }
3270  inline probe operator>(probe const & p1, double p2) { return p1 > probe(p1.ctx(), p2); }
3271  inline probe operator>(double p1, probe const & p2) { return probe(p2.ctx(), p1) > p2; }
3272  inline probe operator==(probe const & p1, probe const & p2) {
3273  check_context(p1, p2); Z3_probe r = Z3_probe_eq(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3274  }
3275  inline probe operator==(probe const & p1, double p2) { return p1 == probe(p1.ctx(), p2); }
3276  inline probe operator==(double p1, probe const & p2) { return probe(p2.ctx(), p1) == p2; }
3277  inline probe operator&&(probe const & p1, probe const & p2) {
3278  check_context(p1, p2); Z3_probe r = Z3_probe_and(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3279  }
3280  inline probe operator||(probe const & p1, probe const & p2) {
3281  check_context(p1, p2); Z3_probe r = Z3_probe_or(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3282  }
3283  inline probe operator!(probe const & p) {
3284  Z3_probe r = Z3_probe_not(p.ctx(), p); p.check_error(); return probe(p.ctx(), r);
3285  }
3286 
3287  class optimize : public object {
3288  Z3_optimize m_opt;
3289 
3290  public:
3291  class handle final {
3292  unsigned m_h;
3293  public:
3294  handle(unsigned h): m_h(h) {}
3295  unsigned h() const { return m_h; }
3296  };
3297  optimize(context& c):object(c) { m_opt = Z3_mk_optimize(c); Z3_optimize_inc_ref(c, m_opt); }
3298  optimize(optimize const & o):object(o), m_opt(o.m_opt) {
3299  Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3300  }
3302  m_opt = Z3_mk_optimize(c);
3303  Z3_optimize_inc_ref(c, m_opt);
3304  add(expr_vector(c, src.assertions()));
3305  expr_vector v(c, src.objectives());
3306  for (expr_vector::iterator it = v.begin(); it != v.end(); ++it) minimize(*it);
3307  }
3309  Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3310  Z3_optimize_dec_ref(ctx(), m_opt);
3311  m_opt = o.m_opt;
3312  object::operator=(o);
3313  return *this;
3314  }
3315  ~optimize() override { Z3_optimize_dec_ref(ctx(), m_opt); }
3316  operator Z3_optimize() const { return m_opt; }
3317  void add(expr const& e) {
3318  assert(e.is_bool());
3319  Z3_optimize_assert(ctx(), m_opt, e);
3320  }
3321  void add(expr_vector const& es) {
3322  for (expr_vector::iterator it = es.begin(); it != es.end(); ++it) add(*it);
3323  }
3324  void add(expr const& e, expr const& t) {
3325  assert(e.is_bool());
3326  Z3_optimize_assert_and_track(ctx(), m_opt, e, t);
3327  }
3328  void add(expr const& e, char const* p) {
3329  assert(e.is_bool());
3330  add(e, ctx().bool_const(p));
3331  }
3332  handle add_soft(expr const& e, unsigned weight) {
3333  assert(e.is_bool());
3334  auto str = std::to_string(weight);
3335  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, str.c_str(), 0));
3336  }
3337  handle add_soft(expr const& e, char const* weight) {
3338  assert(e.is_bool());
3339  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, weight, 0));
3340  }
3341  handle add(expr const& e, unsigned weight) {
3342  return add_soft(e, weight);
3343  }
3344  void set_initial_value(expr const& var, expr const& value) {
3345  Z3_optimize_set_initial_value(ctx(), m_opt, var, value);
3346  check_error();
3347  }
3348  void set_initial_value(expr const& var, int i) {
3349  set_initial_value(var, ctx().num_val(i, var.get_sort()));
3350  }
3351  void set_initial_value(expr const& var, bool b) {
3352  set_initial_value(var, ctx().bool_val(b));
3353  }
3354 
3355  handle maximize(expr const& e) {
3356  return handle(Z3_optimize_maximize(ctx(), m_opt, e));
3357  }
3358  handle minimize(expr const& e) {
3359  return handle(Z3_optimize_minimize(ctx(), m_opt, e));
3360  }
3361  void push() {
3362  Z3_optimize_push(ctx(), m_opt);
3363  }
3364  void pop() {
3365  Z3_optimize_pop(ctx(), m_opt);
3366  }
3368  check_result check(expr_vector const& asms) {
3369  unsigned n = asms.size();
3370  array<Z3_ast> _asms(n);
3371  for (unsigned i = 0; i < n; i++) {
3372  check_context(*this, asms[i]);
3373  _asms[i] = asms[i];
3374  }
3375  Z3_lbool r = Z3_optimize_check(ctx(), m_opt, n, _asms.ptr());
3376  check_error();
3377  return to_check_result(r);
3378  }
3379  model get_model() const { Z3_model m = Z3_optimize_get_model(ctx(), m_opt); check_error(); return model(ctx(), m); }
3380  expr_vector unsat_core() const { Z3_ast_vector r = Z3_optimize_get_unsat_core(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
3381  void set(params const & p) { Z3_optimize_set_params(ctx(), m_opt, p); check_error(); }
3382  expr lower(handle const& h) {
3383  Z3_ast r = Z3_optimize_get_lower(ctx(), m_opt, h.h());
3384  check_error();
3385  return expr(ctx(), r);
3386  }
3387  expr upper(handle const& h) {
3388  Z3_ast r = Z3_optimize_get_upper(ctx(), m_opt, h.h());
3389  check_error();
3390  return expr(ctx(), r);
3391  }
3392  expr_vector assertions() const { Z3_ast_vector r = Z3_optimize_get_assertions(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
3393  expr_vector objectives() const { Z3_ast_vector r = Z3_optimize_get_objectives(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
3394  stats statistics() const { Z3_stats r = Z3_optimize_get_statistics(ctx(), m_opt); check_error(); return stats(ctx(), r); }
3395  friend std::ostream & operator<<(std::ostream & out, optimize const & s);
3396  void from_file(char const* filename) { Z3_optimize_from_file(ctx(), m_opt, filename); check_error(); }
3397  void from_string(char const* constraints) { Z3_optimize_from_string(ctx(), m_opt, constraints); check_error(); }
3398  std::string help() const { char const * r = Z3_optimize_get_help(ctx(), m_opt); check_error(); return r; }
3399  };
3400  inline std::ostream & operator<<(std::ostream & out, optimize const & s) { out << Z3_optimize_to_string(s.ctx(), s.m_opt); return out; }
3401 
3402  class fixedpoint : public object {
3403  Z3_fixedpoint m_fp;
3404  public:
3406  fixedpoint(fixedpoint const & o):object(o), m_fp(o.m_fp) { Z3_fixedpoint_inc_ref(ctx(), m_fp); }
3407  ~fixedpoint() override { Z3_fixedpoint_dec_ref(ctx(), m_fp); }
3409  Z3_fixedpoint_inc_ref(o.ctx(), o.m_fp);
3410  Z3_fixedpoint_dec_ref(ctx(), m_fp);
3411  m_fp = o.m_fp;
3412  object::operator=(o);
3413  return *this;
3414  }
3415  operator Z3_fixedpoint() const { return m_fp; }
3416  expr_vector from_string(char const* s) {
3417  Z3_ast_vector r = Z3_fixedpoint_from_string(ctx(), m_fp, s);
3418  check_error();
3419  return expr_vector(ctx(), r);
3420  }
3421  expr_vector from_file(char const* s) {
3422  Z3_ast_vector r = Z3_fixedpoint_from_file(ctx(), m_fp, s);
3423  check_error();
3424  return expr_vector(ctx(), r);
3425  }
3426  void add_rule(expr& rule, symbol const& name) { Z3_fixedpoint_add_rule(ctx(), m_fp, rule, name); check_error(); }
3427  void add_fact(func_decl& f, unsigned * args) { Z3_fixedpoint_add_fact(ctx(), m_fp, f, f.arity(), args); check_error(); }
3429  check_result query(func_decl_vector& relations) {
3430  array<Z3_func_decl> rs(relations);
3431  Z3_lbool r = Z3_fixedpoint_query_relations(ctx(), m_fp, rs.size(), rs.ptr());
3432  check_error();
3433  return to_check_result(r);
3434  }
3435  expr get_answer() { Z3_ast r = Z3_fixedpoint_get_answer(ctx(), m_fp); check_error(); return expr(ctx(), r); }
3436  std::string reason_unknown() { return Z3_fixedpoint_get_reason_unknown(ctx(), m_fp); }
3437  void update_rule(expr& rule, symbol const& name) { Z3_fixedpoint_update_rule(ctx(), m_fp, rule, name); check_error(); }
3438  unsigned get_num_levels(func_decl& p) { unsigned r = Z3_fixedpoint_get_num_levels(ctx(), m_fp, p); check_error(); return r; }
3439  expr get_cover_delta(int level, func_decl& p) {
3440  Z3_ast r = Z3_fixedpoint_get_cover_delta(ctx(), m_fp, level, p);
3441  check_error();
3442  return expr(ctx(), r);
3443  }
3444  void add_cover(int level, func_decl& p, expr& property) { Z3_fixedpoint_add_cover(ctx(), m_fp, level, p, property); check_error(); }
3445  stats statistics() const { Z3_stats r = Z3_fixedpoint_get_statistics(ctx(), m_fp); check_error(); return stats(ctx(), r); }
3447  expr_vector assertions() const { Z3_ast_vector r = Z3_fixedpoint_get_assertions(ctx(), m_fp); check_error(); return expr_vector(ctx(), r); }
3448  expr_vector rules() const { Z3_ast_vector r = Z3_fixedpoint_get_rules(ctx(), m_fp); check_error(); return expr_vector(ctx(), r); }
3449  void set(params const & p) { Z3_fixedpoint_set_params(ctx(), m_fp, p); check_error(); }
3450  std::string help() const { return Z3_fixedpoint_get_help(ctx(), m_fp); }
3452  std::string to_string() { return Z3_fixedpoint_to_string(ctx(), m_fp, 0, 0); }
3453  std::string to_string(expr_vector const& queries) {
3454  array<Z3_ast> qs(queries);
3455  return Z3_fixedpoint_to_string(ctx(), m_fp, qs.size(), qs.ptr());
3456  }
3457  };
3458  inline std::ostream & operator<<(std::ostream & out, fixedpoint const & f) { return out << Z3_fixedpoint_to_string(f.ctx(), f, 0, 0); }
3459 
3460  inline tactic fail_if(probe const & p) {
3461  Z3_tactic r = Z3_tactic_fail_if(p.ctx(), p);
3462  p.check_error();
3463  return tactic(p.ctx(), r);
3464  }
3465  inline tactic when(probe const & p, tactic const & t) {
3466  check_context(p, t);
3467  Z3_tactic r = Z3_tactic_when(t.ctx(), p, t);
3468  t.check_error();
3469  return tactic(t.ctx(), r);
3470  }
3471  inline tactic cond(probe const & p, tactic const & t1, tactic const & t2) {
3472  check_context(p, t1); check_context(p, t2);
3473  Z3_tactic r = Z3_tactic_cond(t1.ctx(), p, t1, t2);
3474  t1.check_error();
3475  return tactic(t1.ctx(), r);
3476  }
3477 
3478  inline symbol context::str_symbol(char const * s) { Z3_symbol r = Z3_mk_string_symbol(m_ctx, s); check_error(); return symbol(*this, r); }
3479  inline symbol context::int_symbol(int n) { Z3_symbol r = Z3_mk_int_symbol(m_ctx, n); check_error(); return symbol(*this, r); }
3480 
3481  inline sort context::bool_sort() { Z3_sort s = Z3_mk_bool_sort(m_ctx); check_error(); return sort(*this, s); }
3482  inline sort context::int_sort() { Z3_sort s = Z3_mk_int_sort(m_ctx); check_error(); return sort(*this, s); }
3483  inline sort context::real_sort() { Z3_sort s = Z3_mk_real_sort(m_ctx); check_error(); return sort(*this, s); }
3484  inline sort context::bv_sort(unsigned sz) { Z3_sort s = Z3_mk_bv_sort(m_ctx, sz); check_error(); return sort(*this, s); }
3485  inline sort context::string_sort() { Z3_sort s = Z3_mk_string_sort(m_ctx); check_error(); return sort(*this, s); }
3486  inline sort context::char_sort() { Z3_sort s = Z3_mk_char_sort(m_ctx); check_error(); return sort(*this, s); }
3487  inline sort context::seq_sort(sort& s) { Z3_sort r = Z3_mk_seq_sort(m_ctx, s); check_error(); return sort(*this, r); }
3488  inline sort context::re_sort(sort& s) { Z3_sort r = Z3_mk_re_sort(m_ctx, s); check_error(); return sort(*this, r); }
3489  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); }
3490 
3491  template<>
3492  inline sort context::fpa_sort<16>() { return fpa_sort(5, 11); }
3493 
3494  template<>
3495  inline sort context::fpa_sort<32>() { return fpa_sort(8, 24); }
3496 
3497  template<>
3498  inline sort context::fpa_sort<64>() { return fpa_sort(11, 53); }
3499 
3500  template<>
3501  inline sort context::fpa_sort<128>() { return fpa_sort(15, 113); }
3502 
3503  inline sort context::fpa_rounding_mode_sort() { Z3_sort r = Z3_mk_fpa_rounding_mode_sort(m_ctx); check_error(); return sort(*this, r); }
3504 
3505  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); }
3506  inline sort context::array_sort(sort_vector const& d, sort r) {
3507  array<Z3_sort> dom(d);
3508  Z3_sort s = Z3_mk_array_sort_n(m_ctx, dom.size(), dom.ptr(), r); check_error(); return sort(*this, s);
3509  }
3510  inline sort context::enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts) {
3511  array<Z3_symbol> _enum_names(n);
3512  for (unsigned i = 0; i < n; i++) { _enum_names[i] = Z3_mk_string_symbol(*this, enum_names[i]); }
3513  array<Z3_func_decl> _cs(n);
3514  array<Z3_func_decl> _ts(n);
3515  Z3_symbol _name = Z3_mk_string_symbol(*this, name);
3516  sort s = to_sort(*this, Z3_mk_enumeration_sort(*this, _name, n, _enum_names.ptr(), _cs.ptr(), _ts.ptr()));
3517  check_error();
3518  for (unsigned i = 0; i < n; i++) { cs.push_back(func_decl(*this, _cs[i])); ts.push_back(func_decl(*this, _ts[i])); }
3519  return s;
3520  }
3521  inline func_decl context::tuple_sort(char const * name, unsigned n, char const * const * names, sort const* sorts, func_decl_vector & projs) {
3522  array<Z3_symbol> _names(n);
3523  array<Z3_sort> _sorts(n);
3524  for (unsigned i = 0; i < n; i++) { _names[i] = Z3_mk_string_symbol(*this, names[i]); _sorts[i] = sorts[i]; }
3525  array<Z3_func_decl> _projs(n);
3526  Z3_symbol _name = Z3_mk_string_symbol(*this, name);
3527  Z3_func_decl tuple;
3528  sort _ignore_s = to_sort(*this, Z3_mk_tuple_sort(*this, _name, n, _names.ptr(), _sorts.ptr(), &tuple, _projs.ptr()));
3529  check_error();
3530  for (unsigned i = 0; i < n; i++) { projs.push_back(func_decl(*this, _projs[i])); }
3531  return func_decl(*this, tuple);
3532  }
3533 
3535  context& ctx;
3536  Z3_constructor_list clist;
3537  public:
3538  constructor_list(constructors const& cs);
3540  operator Z3_constructor_list() const { return clist; }
3541  };
3542 
3544  friend class constructor_list;
3545  context& ctx;
3546  std::vector<Z3_constructor> cons;
3547  std::vector<unsigned> num_fields;
3548  public:
3549  constructors(context& ctx): ctx(ctx) {}
3550 
3552  for (auto con : cons)
3553  Z3_del_constructor(ctx, con);
3554  }
3555 
3556  void add(symbol const& name, symbol const& rec, unsigned n, symbol const* names, sort const* fields) {
3557  array<unsigned> sort_refs(n);
3558  array<Z3_sort> sorts(n);
3559  array<Z3_symbol> _names(n);
3560  for (unsigned i = 0; i < n; ++i) sorts[i] = fields[i], _names[i] = names[i];
3561  cons.push_back(Z3_mk_constructor(ctx, name, rec, n, _names.ptr(), sorts.ptr(), sort_refs.ptr()));
3562  num_fields.push_back(n);
3563  }
3564 
3565  Z3_constructor operator[](unsigned i) const { return cons[i]; }
3566 
3567  unsigned size() const { return (unsigned)cons.size(); }
3568 
3569  void query(unsigned i, func_decl& constructor, func_decl& test, func_decl_vector& accs) {
3570  Z3_func_decl _constructor;
3571  Z3_func_decl _test;
3572  array<Z3_func_decl> accessors(num_fields[i]);
3573  accs.resize(0);
3575  cons[i],
3576  num_fields[i],
3577  &_constructor,
3578  &_test,
3579  accessors.ptr());
3580  constructor = func_decl(ctx, _constructor);
3581 
3582  test = func_decl(ctx, _test);
3583  for (unsigned j = 0; j < num_fields[i]; ++j)
3584  accs.push_back(func_decl(ctx, accessors[j]));
3585  }
3586  };
3587 
3588  inline constructor_list::constructor_list(constructors const& cs): ctx(cs.ctx) {
3589  array<Z3_constructor> cons(cs.size());
3590  for (unsigned i = 0; i < cs.size(); ++i)
3591  cons[i] = cs[i];
3592  clist = Z3_mk_constructor_list(ctx, cs.size(), cons.ptr());
3593  }
3594 
3595  inline sort context::datatype(symbol const& name, constructors const& cs) {
3596  array<Z3_constructor> _cs(cs.size());
3597  for (unsigned i = 0; i < cs.size(); ++i) _cs[i] = cs[i];
3598  Z3_sort s = Z3_mk_datatype(*this, name, cs.size(), _cs.ptr());
3599  check_error();
3600  return sort(*this, s);
3601  }
3602 
3603  inline sort_vector context::datatypes(
3604  unsigned n, symbol const* names,
3605  constructor_list *const* cons) {
3606  sort_vector result(*this);
3607  array<Z3_symbol> _names(n);
3608  array<Z3_sort> _sorts(n);
3609  array<Z3_constructor_list> _cons(n);
3610  for (unsigned i = 0; i < n; ++i)
3611  _names[i] = names[i], _cons[i] = *cons[i];
3612  Z3_mk_datatypes(*this, n, _names.ptr(), _sorts.ptr(), _cons.ptr());
3613  for (unsigned i = 0; i < n; ++i)
3614  result.push_back(sort(*this, _sorts[i]));
3615  return result;
3616  }
3617 
3618 
3619  inline sort context::datatype_sort(symbol const& name) {
3620  Z3_sort s = Z3_mk_datatype_sort(*this, name);
3621  check_error();
3622  return sort(*this, s);
3623  }
3624 
3625 
3626  inline sort context::uninterpreted_sort(char const* name) {
3627  Z3_symbol _name = Z3_mk_string_symbol(*this, name);
3628  return to_sort(*this, Z3_mk_uninterpreted_sort(*this, _name));
3629  }
3631  return to_sort(*this, Z3_mk_uninterpreted_sort(*this, name));
3632  }
3633 
3634  inline func_decl context::function(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
3635  array<Z3_sort> args(arity);
3636  for (unsigned i = 0; i < arity; i++) {
3637  check_context(domain[i], range);
3638  args[i] = domain[i];
3639  }
3640  Z3_func_decl f = Z3_mk_func_decl(m_ctx, name, arity, args.ptr(), range);
3641  check_error();
3642  return func_decl(*this, f);
3643  }
3644 
3645  inline func_decl context::function(char const * name, unsigned arity, sort const * domain, sort const & range) {
3646  return function(range.ctx().str_symbol(name), arity, domain, range);
3647  }
3648 
3649  inline func_decl context::function(symbol const& name, sort_vector const& domain, sort const& range) {
3650  array<Z3_sort> args(domain.size());
3651  for (unsigned i = 0; i < domain.size(); i++) {
3652  check_context(domain[i], range);
3653  args[i] = domain[i];
3654  }
3655  Z3_func_decl f = Z3_mk_func_decl(m_ctx, name, domain.size(), args.ptr(), range);
3656  check_error();
3657  return func_decl(*this, f);
3658  }
3659 
3660  inline func_decl context::function(char const * name, sort_vector const& domain, sort const& range) {
3661  return function(range.ctx().str_symbol(name), domain, range);
3662  }
3663 
3664 
3665  inline func_decl context::function(char const * name, sort const & domain, sort const & range) {
3666  check_context(domain, range);
3667  Z3_sort args[1] = { domain };
3668  Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 1, args, range);
3669  check_error();
3670  return func_decl(*this, f);
3671  }
3672 
3673  inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & range) {
3674  check_context(d1, range); check_context(d2, range);
3675  Z3_sort args[2] = { d1, d2 };
3676  Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 2, args, range);
3677  check_error();
3678  return func_decl(*this, f);
3679  }
3680 
3681  inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & range) {
3682  check_context(d1, range); check_context(d2, range); check_context(d3, range);
3683  Z3_sort args[3] = { d1, d2, d3 };
3684  Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 3, args, range);
3685  check_error();
3686  return func_decl(*this, f);
3687  }
3688 
3689  inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & range) {
3690  check_context(d1, range); check_context(d2, range); check_context(d3, range); check_context(d4, range);
3691  Z3_sort args[4] = { d1, d2, d3, d4 };
3692  Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 4, args, range);
3693  check_error();
3694  return func_decl(*this, f);
3695  }
3696 
3697  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) {
3698  check_context(d1, range); check_context(d2, range); check_context(d3, range); check_context(d4, range); check_context(d5, range);
3699  Z3_sort args[5] = { d1, d2, d3, d4, d5 };
3700  Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 5, args, range);
3701  check_error();
3702  return func_decl(*this, f);
3703  }
3704 
3705  inline func_decl context::recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
3706  array<Z3_sort> args(arity);
3707  for (unsigned i = 0; i < arity; i++) {
3708  check_context(domain[i], range);
3709  args[i] = domain[i];
3710  }
3711  Z3_func_decl f = Z3_mk_rec_func_decl(m_ctx, name, arity, args.ptr(), range);
3712  check_error();
3713  return func_decl(*this, f);
3714 
3715  }
3716 
3717  inline func_decl context::recfun(symbol const & name, sort_vector const& domain, sort const & range) {
3718  check_context(domain, range);
3719  array<Z3_sort> domain1(domain);
3720  Z3_func_decl f = Z3_mk_rec_func_decl(m_ctx, name, domain1.size(), domain1.ptr(), range);
3721  check_error();
3722  return func_decl(*this, f);
3723  }
3724 
3725  inline func_decl context::recfun(char const * name, sort_vector const& domain, sort const & range) {
3726  return recfun(str_symbol(name), domain, range);
3727 
3728  }
3729 
3730  inline func_decl context::recfun(char const * name, unsigned arity, sort const * domain, sort const & range) {
3731  return recfun(str_symbol(name), arity, domain, range);
3732  }
3733 
3734  inline func_decl context::recfun(char const * name, sort const& d1, sort const & range) {
3735  return recfun(str_symbol(name), 1, &d1, range);
3736  }
3737 
3738  inline func_decl context::recfun(char const * name, sort const& d1, sort const& d2, sort const & range) {
3739  sort dom[2] = { d1, d2 };
3740  return recfun(str_symbol(name), 2, dom, range);
3741  }
3742 
3743  inline void context::recdef(func_decl f, expr_vector const& args, expr const& body) {
3744  check_context(f, args); check_context(f, body);
3745  array<Z3_ast> vars(args);
3746  Z3_add_rec_def(f.ctx(), f, vars.size(), vars.ptr(), body);
3747  }
3748 
3749  inline func_decl context::user_propagate_function(symbol const& name, sort_vector const& domain, sort const& range) {
3750  check_context(domain, range);
3751  array<Z3_sort> domain1(domain);
3752  Z3_func_decl f = Z3_solver_propagate_declare(range.ctx(), name, domain1.size(), domain1.ptr(), range);
3753  check_error();
3754  return func_decl(*this, f);
3755  }
3756 
3757  inline expr context::constant(symbol const & name, sort const & s) {
3758  Z3_ast r = Z3_mk_const(m_ctx, name, s);
3759  check_error();
3760  return expr(*this, r);
3761  }
3762  inline expr context::constant(char const * name, sort const & s) { return constant(str_symbol(name), s); }
3763  inline expr context::variable(unsigned idx, sort const& s) {
3764  Z3_ast r = Z3_mk_bound(m_ctx, idx, s);
3765  check_error();
3766  return expr(*this, r);
3767  }
3768  inline expr context::bool_const(char const * name) { return constant(name, bool_sort()); }
3769  inline expr context::int_const(char const * name) { return constant(name, int_sort()); }
3770  inline expr context::real_const(char const * name) { return constant(name, real_sort()); }
3771  inline expr context::string_const(char const * name) { return constant(name, string_sort()); }
3772  inline expr context::bv_const(char const * name, unsigned sz) { return constant(name, bv_sort(sz)); }
3773  inline expr context::fpa_const(char const * name, unsigned ebits, unsigned sbits) { return constant(name, fpa_sort(ebits, sbits)); }
3774 
3775  template<size_t precision>
3776  inline expr context::fpa_const(char const * name) { return constant(name, fpa_sort<precision>()); }
3777 
3778  inline void context::set_rounding_mode(rounding_mode rm) { m_rounding_mode = rm; }
3779 
3781  switch (m_rounding_mode) {
3782  case RNA: return expr(*this, Z3_mk_fpa_rna(m_ctx));
3783  case RNE: return expr(*this, Z3_mk_fpa_rne(m_ctx));
3784  case RTP: return expr(*this, Z3_mk_fpa_rtp(m_ctx));
3785  case RTN: return expr(*this, Z3_mk_fpa_rtn(m_ctx));
3786  case RTZ: return expr(*this, Z3_mk_fpa_rtz(m_ctx));
3787  default: return expr(*this);
3788  }
3789  }
3790 
3791  inline expr context::bool_val(bool b) { return b ? expr(*this, Z3_mk_true(m_ctx)) : expr(*this, Z3_mk_false(m_ctx)); }
3792 
3793  inline expr context::int_val(int n) { Z3_ast r = Z3_mk_int(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
3794  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); }
3795  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); }
3796  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); }
3797  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); }
3798 
3799  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); }
3800  inline expr context::real_val(int n) { Z3_ast r = Z3_mk_int(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
3801  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); }
3802  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); }
3803  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); }
3804  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); }
3805 
3806  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); }
3807  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); }
3808  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); }
3809  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); }
3810  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); }
3811  inline expr context::bv_val(unsigned n, bool const* bits) {
3812  array<bool> _bits(n);
3813  for (unsigned i = 0; i < n; ++i) _bits[i] = bits[i] ? 1 : 0;
3814  Z3_ast r = Z3_mk_bv_numeral(m_ctx, n, _bits.ptr()); check_error(); return expr(*this, r);
3815  }
3816 
3817  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); }
3818  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); }
3819  inline expr context::fpa_nan(sort const & s) { Z3_ast r = Z3_mk_fpa_nan(m_ctx, s); check_error(); return expr(*this, r); }
3820  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); }
3821 
3822  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); }
3823  inline expr context::string_val(char const* s) { Z3_ast r = Z3_mk_string(m_ctx, s); check_error(); return expr(*this, r); }
3824  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); }
3825  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); }
3826 
3827  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); }
3828 
3829  inline expr func_decl::operator()(unsigned n, expr const * args) const {
3830  array<Z3_ast> _args(n);
3831  for (unsigned i = 0; i < n; i++) {
3832  check_context(*this, args[i]);
3833  _args[i] = args[i];
3834  }
3835  Z3_ast r = Z3_mk_app(ctx(), *this, n, _args.ptr());
3836  check_error();
3837  return expr(ctx(), r);
3838 
3839  }
3840  inline expr func_decl::operator()(expr_vector const& args) const {
3841  array<Z3_ast> _args(args.size());
3842  for (unsigned i = 0; i < args.size(); i++) {
3843  check_context(*this, args[i]);
3844  _args[i] = args[i];
3845  }
3846  Z3_ast r = Z3_mk_app(ctx(), *this, args.size(), _args.ptr());
3847  check_error();
3848  return expr(ctx(), r);
3849  }
3850  inline expr func_decl::operator()() const {
3851  Z3_ast r = Z3_mk_app(ctx(), *this, 0, 0);
3852  ctx().check_error();
3853  return expr(ctx(), r);
3854  }
3855  inline expr func_decl::operator()(expr const & a) const {
3856  check_context(*this, a);
3857  Z3_ast args[1] = { a };
3858  Z3_ast r = Z3_mk_app(ctx(), *this, 1, args);
3859  ctx().check_error();
3860  return expr(ctx(), r);
3861  }
3862  inline expr func_decl::operator()(int a) const {
3863  Z3_ast args[1] = { ctx().num_val(a, domain(0)) };
3864  Z3_ast r = Z3_mk_app(ctx(), *this, 1, args);
3865  ctx().check_error();
3866  return expr(ctx(), r);
3867  }
3868  inline expr func_decl::operator()(expr const & a1, expr const & a2) const {
3869  check_context(*this, a1); check_context(*this, a2);
3870  Z3_ast args[2] = { a1, a2 };
3871  Z3_ast r = Z3_mk_app(ctx(), *this, 2, args);
3872  ctx().check_error();
3873  return expr(ctx(), r);
3874  }
3875  inline expr func_decl::operator()(expr const & a1, int a2) const {
3876  check_context(*this, a1);
3877  Z3_ast args[2] = { a1, ctx().num_val(a2, domain(1)) };
3878  Z3_ast r = Z3_mk_app(ctx(), *this, 2, args);
3879  ctx().check_error();
3880  return expr(ctx(), r);
3881  }
3882  inline expr func_decl::operator()(int a1, expr const & a2) const {
3883  check_context(*this, a2);
3884  Z3_ast args[2] = { ctx().num_val(a1, domain(0)), a2 };
3885  Z3_ast r = Z3_mk_app(ctx(), *this, 2, args);
3886  ctx().check_error();
3887  return expr(ctx(), r);
3888  }
3889  inline expr func_decl::operator()(expr const & a1, expr const & a2, expr const & a3) const {
3890  check_context(*this, a1); check_context(*this, a2); check_context(*this, a3);
3891  Z3_ast args[3] = { a1, a2, a3 };
3892  Z3_ast r = Z3_mk_app(ctx(), *this, 3, args);
3893  ctx().check_error();
3894  return expr(ctx(), r);
3895  }
3896  inline expr func_decl::operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4) const {
3897  check_context(*this, a1); check_context(*this, a2); check_context(*this, a3); check_context(*this, a4);
3898  Z3_ast args[4] = { a1, a2, a3, a4 };
3899  Z3_ast r = Z3_mk_app(ctx(), *this, 4, args);
3900  ctx().check_error();
3901  return expr(ctx(), r);
3902  }
3903  inline expr func_decl::operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4, expr const & a5) const {
3904  check_context(*this, a1); check_context(*this, a2); check_context(*this, a3); check_context(*this, a4); check_context(*this, a5);
3905  Z3_ast args[5] = { a1, a2, a3, a4, a5 };
3906  Z3_ast r = Z3_mk_app(ctx(), *this, 5, args);
3907  ctx().check_error();
3908  return expr(ctx(), r);
3909  }
3910 
3911  inline expr to_real(expr const & a) { Z3_ast r = Z3_mk_int2real(a.ctx(), a); a.check_error(); return expr(a.ctx(), r); }
3912 
3913  inline func_decl function(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
3914  return range.ctx().function(name, arity, domain, range);
3915  }
3916  inline func_decl function(char const * name, unsigned arity, sort const * domain, sort const & range) {
3917  return range.ctx().function(name, arity, domain, range);
3918  }
3919  inline func_decl function(char const * name, sort const & domain, sort const & range) {
3920  return range.ctx().function(name, domain, range);
3921  }
3922  inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & range) {
3923  return range.ctx().function(name, d1, d2, range);
3924  }
3925  inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & range) {
3926  return range.ctx().function(name, d1, d2, d3, range);
3927  }
3928  inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & range) {
3929  return range.ctx().function(name, d1, d2, d3, d4, range);
3930  }
3931  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) {
3932  return range.ctx().function(name, d1, d2, d3, d4, d5, range);
3933  }
3934  inline func_decl function(char const* name, sort_vector const& domain, sort const& range) {
3935  return range.ctx().function(name, domain, range);
3936  }
3937  inline func_decl function(std::string const& name, sort_vector const& domain, sort const& range) {
3938  return range.ctx().function(name.c_str(), domain, range);
3939  }
3940 
3941  inline func_decl recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
3942  return range.ctx().recfun(name, arity, domain, range);
3943  }
3944  inline func_decl recfun(char const * name, unsigned arity, sort const * domain, sort const & range) {
3945  return range.ctx().recfun(name, arity, domain, range);
3946  }
3947  inline func_decl recfun(char const * name, sort const& d1, sort const & range) {
3948  return range.ctx().recfun(name, d1, range);
3949  }
3950  inline func_decl recfun(char const * name, sort const& d1, sort const& d2, sort const & range) {
3951  return range.ctx().recfun(name, d1, d2, range);
3952  }
3953 
3954  inline expr select(expr const & a, expr const & i) {
3955  check_context(a, i);
3956  Z3_ast r = Z3_mk_select(a.ctx(), a, i);
3957  a.check_error();
3958  return expr(a.ctx(), r);
3959  }
3960  inline expr select(expr const & a, int i) {
3961  return select(a, a.ctx().num_val(i, a.get_sort().array_domain()));
3962  }
3963  inline expr select(expr const & a, expr_vector const & i) {
3964  check_context(a, i);
3965  array<Z3_ast> idxs(i);
3966  Z3_ast r = Z3_mk_select_n(a.ctx(), a, idxs.size(), idxs.ptr());
3967  a.check_error();
3968  return expr(a.ctx(), r);
3969  }
3970 
3971  inline expr store(expr const & a, expr const & i, expr const & v) {
3972  check_context(a, i); check_context(a, v);
3973  Z3_ast r = Z3_mk_store(a.ctx(), a, i, v);
3974  a.check_error();
3975  return expr(a.ctx(), r);
3976  }
3977 
3978  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); }
3979  inline expr store(expr const & a, expr i, int v) { return store(a, i, a.ctx().num_val(v, a.get_sort().array_range())); }
3980  inline expr store(expr const & a, int i, int v) {
3981  return store(a, a.ctx().num_val(i, a.get_sort().array_domain()), a.ctx().num_val(v, a.get_sort().array_range()));
3982  }
3983  inline expr store(expr const & a, expr_vector const & i, expr const & v) {
3984  check_context(a, i); check_context(a, v);
3985  array<Z3_ast> idxs(i);
3986  Z3_ast r = Z3_mk_store_n(a.ctx(), a, idxs.size(), idxs.ptr(), v);
3987  a.check_error();
3988  return expr(a.ctx(), r);
3989  }
3990 
3991  inline expr as_array(func_decl & f) {
3992  Z3_ast r = Z3_mk_as_array(f.ctx(), f);
3993  f.check_error();
3994  return expr(f.ctx(), r);
3995  }
3996 
3997 #define MK_EXPR1(_fn, _arg) \
3998  Z3_ast r = _fn(_arg.ctx(), _arg); \
3999  _arg.check_error(); \
4000  return expr(_arg.ctx(), r);
4001 
4002 #define MK_EXPR2(_fn, _arg1, _arg2) \
4003  check_context(_arg1, _arg2); \
4004  Z3_ast r = _fn(_arg1.ctx(), _arg1, _arg2); \
4005  _arg1.check_error(); \
4006  return expr(_arg1.ctx(), r);
4007 
4008  inline expr const_array(sort const & d, expr const & v) {
4009  MK_EXPR2(Z3_mk_const_array, d, v);
4010  }
4011 
4012  inline expr empty_set(sort const& s) {
4014  }
4015 
4016  inline expr full_set(sort const& s) {
4018  }
4019 
4020  inline expr set_add(expr const& s, expr const& e) {
4021  MK_EXPR2(Z3_mk_set_add, s, e);
4022  }
4023 
4024  inline expr set_del(expr const& s, expr const& e) {
4025  MK_EXPR2(Z3_mk_set_del, s, e);
4026  }
4027 
4028  inline expr set_union(expr const& a, expr const& b) {
4029  check_context(a, b);
4030  Z3_ast es[2] = { a, b };
4031  Z3_ast r = Z3_mk_set_union(a.ctx(), 2, es);
4032  a.check_error();
4033  return expr(a.ctx(), r);
4034  }
4035 
4036  inline expr set_intersect(expr const& a, expr const& b) {
4037  check_context(a, b);
4038  Z3_ast es[2] = { a, b };
4039  Z3_ast r = Z3_mk_set_intersect(a.ctx(), 2, es);
4040  a.check_error();
4041  return expr(a.ctx(), r);
4042  }
4043 
4044  inline expr set_difference(expr const& a, expr const& b) {
4046  }
4047 
4048  inline expr set_complement(expr const& a) {
4050  }
4051 
4052  inline expr set_member(expr const& s, expr const& e) {
4053  MK_EXPR2(Z3_mk_set_member, s, e);
4054  }
4055 
4056  inline expr set_subset(expr const& a, expr const& b) {
4057  MK_EXPR2(Z3_mk_set_subset, a, b);
4058  }
4059 
4060  // sequence and regular expression operations.
4061  // union is +
4062  // concat is overloaded to handle sequences and regular expressions
4063 
4064  inline expr empty(sort const& s) {
4065  Z3_ast r = Z3_mk_seq_empty(s.ctx(), s);
4066  s.check_error();
4067  return expr(s.ctx(), r);
4068  }
4069  inline expr suffixof(expr const& a, expr const& b) {
4070  check_context(a, b);
4071  Z3_ast r = Z3_mk_seq_suffix(a.ctx(), a, b);
4072  a.check_error();
4073  return expr(a.ctx(), r);
4074  }
4075  inline expr prefixof(expr const& a, expr const& b) {
4076  check_context(a, b);
4077  Z3_ast r = Z3_mk_seq_prefix(a.ctx(), a, b);
4078  a.check_error();
4079  return expr(a.ctx(), r);
4080  }
4081  inline expr indexof(expr const& s, expr const& substr, expr const& offset) {
4082  check_context(s, substr); check_context(s, offset);
4083  Z3_ast r = Z3_mk_seq_index(s.ctx(), s, substr, offset);
4084  s.check_error();
4085  return expr(s.ctx(), r);
4086  }
4087  inline expr last_indexof(expr const& s, expr const& substr) {
4088  check_context(s, substr);
4089  Z3_ast r = Z3_mk_seq_last_index(s.ctx(), s, substr);
4090  s.check_error();
4091  return expr(s.ctx(), r);
4092  }
4093  inline expr to_re(expr const& s) {
4095  }
4096  inline expr in_re(expr const& s, expr const& re) {
4097  MK_EXPR2(Z3_mk_seq_in_re, s, re);
4098  }
4099  inline expr plus(expr const& re) {
4100  MK_EXPR1(Z3_mk_re_plus, re);
4101  }
4102  inline expr option(expr const& re) {
4104  }
4105  inline expr star(expr const& re) {
4106  MK_EXPR1(Z3_mk_re_star, re);
4107  }
4108  inline expr re_empty(sort const& s) {
4109  Z3_ast r = Z3_mk_re_empty(s.ctx(), s);
4110  s.check_error();
4111  return expr(s.ctx(), r);
4112  }
4113  inline expr re_full(sort const& s) {
4114  Z3_ast r = Z3_mk_re_full(s.ctx(), s);
4115  s.check_error();
4116  return expr(s.ctx(), r);
4117  }
4118  inline expr re_intersect(expr_vector const& args) {
4119  assert(args.size() > 0);
4120  context& ctx = args[0u].ctx();
4121  array<Z3_ast> _args(args);
4122  Z3_ast r = Z3_mk_re_intersect(ctx, _args.size(), _args.ptr());
4123  ctx.check_error();
4124  return expr(ctx, r);
4125  }
4126  inline expr re_diff(expr const& a, expr const& b) {
4127  check_context(a, b);
4128  context& ctx = a.ctx();
4129  Z3_ast r = Z3_mk_re_diff(ctx, a, b);
4130  ctx.check_error();
4131  return expr(ctx, r);
4132  }
4133  inline expr re_complement(expr const& a) {
4135  }
4136  inline expr range(expr const& lo, expr const& hi) {
4137  check_context(lo, hi);
4138  Z3_ast r = Z3_mk_re_range(lo.ctx(), lo, hi);
4139  lo.check_error();
4140  return expr(lo.ctx(), r);
4141  }
4142 
4143 
4144 
4145 
4146 
4147  inline expr_vector context::parse_string(char const* s) {
4148  Z3_ast_vector r = Z3_parse_smtlib2_string(*this, s, 0, 0, 0, 0, 0, 0);
4149  check_error();
4150  return expr_vector(*this, r);
4151 
4152  }
4153  inline expr_vector context::parse_file(char const* s) {
4154  Z3_ast_vector r = Z3_parse_smtlib2_file(*this, s, 0, 0, 0, 0, 0, 0);
4155  check_error();
4156  return expr_vector(*this, r);
4157  }
4158 
4159  inline expr_vector context::parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
4160  array<Z3_symbol> sort_names(sorts.size());
4161  array<Z3_symbol> decl_names(decls.size());
4162  array<Z3_sort> sorts1(sorts);
4163  array<Z3_func_decl> decls1(decls);
4164  for (unsigned i = 0; i < sorts.size(); ++i) {
4165  sort_names[i] = sorts[i].name();
4166  }
4167  for (unsigned i = 0; i < decls.size(); ++i) {
4168  decl_names[i] = decls[i].name();
4169  }
4170 
4171  Z3_ast_vector r = Z3_parse_smtlib2_string(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
4172  check_error();
4173  return expr_vector(*this, r);
4174  }
4175 
4176  inline expr_vector context::parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
4177  array<Z3_symbol> sort_names(sorts.size());
4178  array<Z3_symbol> decl_names(decls.size());
4179  array<Z3_sort> sorts1(sorts);
4180  array<Z3_func_decl> decls1(decls);
4181  for (unsigned i = 0; i < sorts.size(); ++i) {
4182  sort_names[i] = sorts[i].name();
4183  }
4184  for (unsigned i = 0; i < decls.size(); ++i) {
4185  decl_names[i] = decls[i].name();
4186  }
4187  Z3_ast_vector r = Z3_parse_smtlib2_file(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
4188  check_error();
4189  return expr_vector(*this, r);
4190  }
4191 
4192  inline func_decl_vector sort::constructors() {
4193  assert(is_datatype());
4194  func_decl_vector cs(ctx());
4195  unsigned n = Z3_get_datatype_sort_num_constructors(ctx(), *this);
4196  for (unsigned i = 0; i < n; ++i)
4198  return cs;
4199  }
4200 
4201  inline func_decl_vector sort::recognizers() {
4202  assert(is_datatype());
4203  func_decl_vector rs(ctx());
4204  unsigned n = Z3_get_datatype_sort_num_constructors(ctx(), *this);
4205  for (unsigned i = 0; i < n; ++i)
4207  return rs;
4208  }
4209 
4210  inline func_decl_vector func_decl::accessors() {
4211  sort s = range();
4212  assert(s.is_datatype());
4213  unsigned n = Z3_get_datatype_sort_num_constructors(ctx(), s);
4214  unsigned idx = 0;
4215  for (; idx < n; ++idx) {
4217  if (id() == f.id())
4218  break;
4219  }
4220  assert(idx < n);
4221  n = arity();
4222  func_decl_vector as(ctx());
4223  for (unsigned i = 0; i < n; ++i)
4225  return as;
4226  }
4227 
4228 
4229  inline expr expr::substitute(expr_vector const& src, expr_vector const& dst) {
4230  assert(src.size() == dst.size());
4231  array<Z3_ast> _src(src.size());
4232  array<Z3_ast> _dst(dst.size());
4233  for (unsigned i = 0; i < src.size(); ++i) {
4234  _src[i] = src[i];
4235  _dst[i] = dst[i];
4236  }
4237  Z3_ast r = Z3_substitute(ctx(), m_ast, src.size(), _src.ptr(), _dst.ptr());
4238  check_error();
4239  return expr(ctx(), r);
4240  }
4241 
4242  inline expr expr::substitute(expr_vector const& dst) {
4243  array<Z3_ast> _dst(dst.size());
4244  for (unsigned i = 0; i < dst.size(); ++i) {
4245  _dst[i] = dst[i];
4246  }
4247  Z3_ast r = Z3_substitute_vars(ctx(), m_ast, dst.size(), _dst.ptr());
4248  check_error();
4249  return expr(ctx(), r);
4250  }
4251 
4252  inline expr expr::substitute(func_decl_vector const& funs, expr_vector const& dst) {
4253  array<Z3_ast> _dst(dst.size());
4254  array<Z3_func_decl> _funs(funs.size());
4255  if (dst.size() != funs.size()) {
4256  Z3_THROW(exception("length of argument lists don't align"));
4257  return expr(ctx(), nullptr);
4258  }
4259  for (unsigned i = 0; i < dst.size(); ++i) {
4260  _dst[i] = dst[i];
4261  _funs[i] = funs[i];
4262  }
4263  Z3_ast r = Z3_substitute_funs(ctx(), m_ast, dst.size(), _funs.ptr(), _dst.ptr());
4264  check_error();
4265  return expr(ctx(), r);
4266  }
4267 
4268  typedef std::function<void(expr const& proof, std::vector<unsigned> const& deps, expr_vector const& clause)> on_clause_eh_t;
4269 
4270  class on_clause {
4271  context& c;
4272  on_clause_eh_t m_on_clause;
4273 
4274  static void _on_clause_eh(void* _ctx, Z3_ast _proof, unsigned n, unsigned const* dep, Z3_ast_vector _literals) {
4275  on_clause* ctx = static_cast<on_clause*>(_ctx);
4276  expr_vector lits(ctx->c, _literals);
4277  expr proof(ctx->c, _proof);
4278  std::vector<unsigned> deps;
4279  for (unsigned i = 0; i < n; ++i)
4280  deps.push_back(dep[i]);
4281  ctx->m_on_clause(proof, deps, lits);
4282  }
4283  public:
4285  m_on_clause = on_clause_eh;
4286  Z3_solver_register_on_clause(c, s, this, _on_clause_eh);
4287  c.check_error();
4288  }
4289  };
4290 
4292 
4293  typedef std::function<void(expr const&, expr const&)> fixed_eh_t;
4294  typedef std::function<void(void)> final_eh_t;
4295  typedef std::function<void(expr const&, expr const&)> eq_eh_t;
4296  typedef std::function<void(expr const&)> created_eh_t;
4297  typedef std::function<void(expr, unsigned, bool)> decide_eh_t;
4298 
4299  final_eh_t m_final_eh;
4300  eq_eh_t m_eq_eh;
4301  fixed_eh_t m_fixed_eh;
4302  created_eh_t m_created_eh;
4303  decide_eh_t m_decide_eh;
4304  solver* s;
4305  context* c;
4306  std::vector<z3::context*> subcontexts;
4307 
4308  unsigned m_callbackNesting = 0;
4309  Z3_solver_callback cb { nullptr };
4310 
4311  struct scoped_cb {
4313  scoped_cb(void* _p, Z3_solver_callback cb):p(*static_cast<user_propagator_base*>(_p)) {
4314  p.cb = cb;
4315  p.m_callbackNesting++;
4316  }
4317  ~scoped_cb() {
4318  if (--p.m_callbackNesting == 0)
4319  p.cb = nullptr;
4320  }
4321  };
4322 
4323  static void push_eh(void* _p, Z3_solver_callback cb) {
4324  user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4325  scoped_cb _cb(p, cb);
4326  static_cast<user_propagator_base*>(p)->push();
4327  }
4328 
4329  static void pop_eh(void* _p, Z3_solver_callback cb, unsigned num_scopes) {
4330  user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4331  scoped_cb _cb(p, cb);
4332  static_cast<user_propagator_base*>(_p)->pop(num_scopes);
4333  }
4334 
4335  static void* fresh_eh(void* _p, Z3_context ctx) {
4336  user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4337  context* c = new context(ctx);
4338  p->subcontexts.push_back(c);
4339  return p->fresh(*c);
4340  }
4341 
4342  static void fixed_eh(void* _p, Z3_solver_callback cb, Z3_ast _var, Z3_ast _value) {
4343  user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4344  scoped_cb _cb(p, cb);
4345  expr value(p->ctx(), _value);
4346  expr var(p->ctx(), _var);
4347  p->m_fixed_eh(var, value);
4348  }
4349 
4350  static void eq_eh(void* _p, Z3_solver_callback cb, Z3_ast _x, Z3_ast _y) {
4351  user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4352  scoped_cb _cb(p, cb);
4353  expr x(p->ctx(), _x), y(p->ctx(), _y);
4354  p->m_eq_eh(x, y);
4355  }
4356 
4357  static void final_eh(void* p, Z3_solver_callback cb) {
4358  scoped_cb _cb(p, cb);
4359  static_cast<user_propagator_base*>(p)->m_final_eh();
4360  }
4361 
4362  static void created_eh(void* _p, Z3_solver_callback cb, Z3_ast _e) {
4363  user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4364  scoped_cb _cb(p, cb);
4365  expr e(p->ctx(), _e);
4366  p->m_created_eh(e);
4367  }
4368 
4369  static void decide_eh(void* _p, Z3_solver_callback cb, Z3_ast _val, unsigned bit, bool is_pos) {
4370  user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4371  scoped_cb _cb(p, cb);
4372  expr val(p->ctx(), _val);
4373  p->m_decide_eh(val, bit, is_pos);
4374  }
4375 
4376  public:
4377  user_propagator_base(context& c) : s(nullptr), c(&c) {}
4378 
4379  user_propagator_base(solver* s): s(s), c(nullptr) {
4380  Z3_solver_propagate_init(ctx(), *s, this, push_eh, pop_eh, fresh_eh);
4381  }
4382 
4383  virtual void push() = 0;
4384  virtual void pop(unsigned num_scopes) = 0;
4385 
4387  for (auto& subcontext : subcontexts) {
4388  subcontext->detach(); // detach first; the subcontexts will be freed internally!
4389  delete subcontext;
4390  }
4391  }
4392 
4394  return c ? *c : s->ctx();
4395  }
4396 
4405  virtual user_propagator_base* fresh(context& ctx) = 0;
4406 
4413  void register_fixed(fixed_eh_t& f) {
4414  m_fixed_eh = f;
4415  if (s) {
4416  Z3_solver_propagate_fixed(ctx(), *s, fixed_eh);
4417  }
4418  }
4419 
4421  m_fixed_eh = [this](expr const &id, expr const &e) {
4422  fixed(id, e);
4423  };
4424  if (s) {
4425  Z3_solver_propagate_fixed(ctx(), *s, fixed_eh);
4426  }
4427  }
4428 
4429  void register_eq(eq_eh_t& f) {
4430  m_eq_eh = f;
4431  if (s) {
4432  Z3_solver_propagate_eq(ctx(), *s, eq_eh);
4433  }
4434  }
4435 
4436  void register_eq() {
4437  m_eq_eh = [this](expr const& x, expr const& y) {
4438  eq(x, y);
4439  };
4440  if (s) {
4441  Z3_solver_propagate_eq(ctx(), *s, eq_eh);
4442  }
4443  }
4444 
4453  void register_final(final_eh_t& f) {
4454  m_final_eh = f;
4455  if (s) {
4456  Z3_solver_propagate_final(ctx(), *s, final_eh);
4457  }
4458  }
4459 
4461  m_final_eh = [this]() {
4462  final();
4463  };
4464  if (s) {
4465  Z3_solver_propagate_final(ctx(), *s, final_eh);
4466  }
4467  }
4468 
4469  void register_created(created_eh_t& c) {
4470  m_created_eh = c;
4471  if (s) {
4472  Z3_solver_propagate_created(ctx(), *s, created_eh);
4473  }
4474  }
4475 
4477  m_created_eh = [this](expr const& e) {
4478  created(e);
4479  };
4480  if (s) {
4481  Z3_solver_propagate_created(ctx(), *s, created_eh);
4482  }
4483  }
4484 
4485  void register_decide(decide_eh_t& c) {
4486  m_decide_eh = c;
4487  if (s) {
4488  Z3_solver_propagate_decide(ctx(), *s, decide_eh);
4489  }
4490  }
4491 
4493  m_decide_eh = [this](expr val, unsigned bit, bool is_pos) {
4494  decide(val, bit, is_pos);
4495  };
4496  if (s) {
4497  Z3_solver_propagate_decide(ctx(), *s, decide_eh);
4498  }
4499  }
4500 
4501  virtual void fixed(expr const& /*id*/, expr const& /*e*/) { }
4502 
4503  virtual void eq(expr const& /*x*/, expr const& /*y*/) { }
4504 
4505  virtual void final() { }
4506 
4507  virtual void created(expr const& /*e*/) {}
4508 
4509  virtual void decide(expr const& /*val*/, unsigned /*bit*/, bool /*is_pos*/) {}
4510 
4511  bool next_split(expr const& e, unsigned idx, Z3_lbool phase) {
4512  assert(cb);
4513  return Z3_solver_next_split(ctx(), cb, e, idx, phase);
4514  }
4515 
4530  void add(expr const& e) {
4531  if (cb)
4533  else if (s)
4535  else
4536  assert(false);
4537  }
4538 
4539  void conflict(expr_vector const& fixed) {
4540  assert(cb);
4541  expr conseq = ctx().bool_val(false);
4542  array<Z3_ast> _fixed(fixed);
4543  Z3_solver_propagate_consequence(ctx(), cb, fixed.size(), _fixed.ptr(), 0, nullptr, nullptr, conseq);
4544  }
4545 
4546  void conflict(expr_vector const& fixed, expr_vector const& lhs, expr_vector const& rhs) {
4547  assert(cb);
4548  assert(lhs.size() == rhs.size());
4549  expr conseq = ctx().bool_val(false);
4550  array<Z3_ast> _fixed(fixed);
4551  array<Z3_ast> _lhs(lhs);
4552  array<Z3_ast> _rhs(rhs);
4553  Z3_solver_propagate_consequence(ctx(), cb, fixed.size(), _fixed.ptr(), lhs.size(), _lhs.ptr(), _rhs.ptr(), conseq);
4554  }
4555 
4556  bool propagate(expr_vector const& fixed, expr const& conseq) {
4557  assert(cb);
4558  assert((Z3_context)conseq.ctx() == (Z3_context)ctx());
4559  array<Z3_ast> _fixed(fixed);
4560  return Z3_solver_propagate_consequence(ctx(), cb, _fixed.size(), _fixed.ptr(), 0, nullptr, nullptr, conseq);
4561  }
4562 
4563  bool propagate(expr_vector const& fixed,
4564  expr_vector const& lhs, expr_vector const& rhs,
4565  expr const& conseq) {
4566  assert(cb);
4567  assert((Z3_context)conseq.ctx() == (Z3_context)ctx());
4568  assert(lhs.size() == rhs.size());
4569  array<Z3_ast> _fixed(fixed);
4570  array<Z3_ast> _lhs(lhs);
4571  array<Z3_ast> _rhs(rhs);
4572 
4573  return Z3_solver_propagate_consequence(ctx(), cb, _fixed.size(), _fixed.ptr(), lhs.size(), _lhs.ptr(), _rhs.ptr(), conseq);
4574  }
4575  };
4576 
4577 }
4578 
4581 #undef Z3_THROW
4582 
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.
cube_generator cubes(expr_vector &vars)
Definition: z3++.h:2995
ast_vector_tpl(context &c)
Definition: z3++.h:591
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
expr distinct(expr_vector const &args)
Definition: z3++.h:2447
expr mod(expr const &a, expr const &b)
Definition: z3++.h:1641
friend expr mk_or(expr_vector const &args)
Definition: z3++.h:2528
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.
expr bvadd_no_overflow(expr const &a, expr const &b, bool is_signed)
bit-vector overflow/underflow checks
Definition: z3++.h:2239
Z3_ast Z3_API Z3_mk_re_loop(Z3_context c, Z3_ast r, unsigned lo, unsigned hi)
Create a regular expression loop. The supplied regular expression r is repeated between lo and hi tim...
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...
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_fpa_fma(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Floating-point fused multiply-add.
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
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_true(Z3_context c)
Create an AST node representing true.
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_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
user_propagator_base(solver *s)
Definition: z3++.h:4379
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...
Z3_sort_kind
The different kinds of Z3 types (See Z3_get_sort_kind).
Definition: z3_api.h:109
bool is_numeral_u(unsigned &i) const
Definition: z3++.h:885
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
friend expr operator|(expr const &a, expr const &b)
Definition: z3++.h:1944
Z3_ast Z3_API Z3_mk_bvnor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise nor.
void register_final(final_eh_t &f)
register a callback on final-check. During the final check stage, all propagations have been processe...
Definition: z3++.h:4453
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value)
Set a global (or module) parameter. This setting is shared by all Z3 contexts.
std::string reason_unknown() const
Definition: z3++.h:2851
std::string help() const
Definition: z3++.h:3112
sort bool_sort()
Return the Boolean sort.
Definition: z3++.h:3481
void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p)
Set the given solver using the given parameters.
friend expr atmost(expr_vector const &es, unsigned bound)
Definition: z3++.h:2422
void check_parser_error() const
Definition: z3++.h:199
handle add_soft(expr const &e, char const *weight)
Definition: z3++.h:3337
friend expr operator+(expr const &a, expr const &b)
Definition: z3++.h:1729
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.
expr variable(unsigned index, sort const &s)
create a de-Bruijn variable.
Definition: z3++.h:3763
void add_const_interp(func_decl &f, expr &value)
Definition: z3++.h:2675
expr mk_and(expr_vector const &args)
Definition: z3++.h:2534
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.
friend expr pw(expr const &a, expr const &b)
Definition: z3++.h:1637
double as_double() const
Definition: z3++.h:891
bool is_numeral_i64(int64_t &i) const
Definition: z3++.h:882
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: ...
void set_initial_value(expr const &var, expr const &value)
Definition: z3++.h:3344
unsigned Z3_API Z3_get_string_length(Z3_context c, Z3_ast s)
Retrieve the length of the unescaped string constant stored in s.
bool as_binary(std::string &s) const
Definition: z3++.h:889
bool Z3_API Z3_get_numeral_uint(Z3_context c, Z3_ast v, unsigned *u)
Similar to Z3_get_numeral_string, but only succeeds if the value can fit in a machine unsigned int...
Z3_ast Z3_API Z3_mk_fpa_rtz(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
void set(char const *k, bool v)
Definition: z3++.h:2788
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
model(context &c)
Definition: z3++.h:2612
friend expr bv2int(expr const &a, bool is_signed)
bit-vector and integer conversions.
Definition: z3++.h:2233
bool is_int() const
Return true if this sort is the Integer sort.
Definition: z3++.h:684
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
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_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
iterator & operator++()
Definition: z3++.h:1613
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...
tactic & operator=(tactic const &s)
Definition: z3++.h:3095
expr operator[](expr const &index) const
Definition: z3++.h:1564
sort re_sort(sort &seq_sort)
Return a regular expression sort over sequences seq_sort.
Definition: z3++.h:3488
void Z3_API Z3_del_constructor(Z3_context c, Z3_constructor constr)
Reclaim memory allocated to constructor.
expr sle(expr const &a, expr const &b)
signed less than or equal to operator for bitvectors.
Definition: z3++.h:2129
expr bvredand(expr const &a)
Definition: z3++.h:1989
void add_fact(func_decl &f, unsigned *args)
Definition: z3++.h:3427
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.
probe(context &c, Z3_probe s)
Definition: z3++.h:3219
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string str)
load solver assertions from a string.
void Z3_API Z3_goal_reset(Z3_context c, Z3_goal g)
Erase all formulas from the given goal.
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.
expr pbeq(expr_vector const &es, int const *coeffs, int bound)
Definition: z3++.h:2414
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.
friend expr xnor(expr const &a, expr const &b)
Definition: z3++.h:1950
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.
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.
probe & operator=(probe const &s)
Definition: z3++.h:3223
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...
func_decl get_const_decl(unsigned i) const
Definition: z3++.h:2638
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a variable.
void register_fixed(fixed_eh_t &f)
register callbacks. Callbacks can only be registered with user_propagators that were created using a ...
Definition: z3++.h:4413
Z3_string Z3_API Z3_get_error_msg(Z3_context c, Z3_error_code err)
Return a string describing the given error code.
unsigned get_num_levels(func_decl &p)
Definition: z3++.h:3438
std::string documentation(symbol const &s)
Definition: z3++.h:519
~func_interp() override
Definition: z3++.h:2582
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_mul(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] * ... * args[num_args-1].
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.
virtual void eq(expr const &, expr const &)
Definition: z3++.h:4503
friend expr operator>=(expr const &a, expr const &b)
Definition: z3++.h:1783
#define Z3_THROW(x)
Definition: z3++.h:103
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...
iterator & operator++() noexcept
Definition: z3++.h:636
bool is_array() const
Return true if this is a Array expression.
Definition: z3++.h:844
unsigned id() const
retrieve unique identifier for expression.
Definition: z3++.h:1057
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
Z3_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.
Z3_string Z3_API Z3_param_descrs_get_documentation(Z3_context c, Z3_param_descrs p, Z3_symbol s)
Retrieve documentation string corresponding to parameter name s.
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
symbol str_symbol(char const *s)
Create a Z3 symbol based on the given string.
Definition: z3++.h:3478
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.
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:2228
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_full_set(Z3_context c, Z3_sort domain)
Create the full set.
Z3_ast Z3_API Z3_mk_char_is_digit(Z3_context c, Z3_ast ch)
Create a check if the character is a digit.
void set(char const *k, symbol const &s)
Definition: z3++.h:542
Z3_ast Z3_API Z3_mk_seq_at(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the unit sequence positioned at position index. The sequence is empty if the index is...
friend std::ostream & operator<<(std::ostream &out, sort const &s)
Definition: z3++.h:749
Z3_params Z3_API Z3_mk_params(Z3_context c)
Create a Z3 (empty) parameter set. Starting at Z3 4.0, parameter sets are used to configure many comp...
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...
friend bool eq(ast const &a, ast const &b)
Return true if the ASTs are structurally identical.
Definition: z3++.h:584
Z3_symbol_kind Z3_API Z3_get_symbol_kind(Z3_context c, Z3_symbol s)
Return Z3_INT_SYMBOL if the symbol was constructed using Z3_mk_int_symbol, and Z3_STRING_SYMBOL if th...
func_decl piecewise_linear_order(sort const &a, unsigned index)
Definition: z3++.h:2276
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
void push()
Create a backtracking point.
Definition: z3++.h:2803
friend expr bvmul_no_overflow(expr const &a, expr const &b, bool is_signed)
Definition: z3++.h:2257
expr length() const
Definition: z3++.h:1500
expr bvsub_no_underflow(expr const &a, expr const &b, bool is_signed)
Definition: z3++.h:2248
Z3_string Z3_API Z3_ast_to_string(Z3_context c, Z3_ast a)
Convert the given AST node into a string.
stats statistics() const
Definition: z3++.h:2852
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
tactic cond(probe const &p, tactic const &t1, tactic const &t2)
Definition: z3++.h:3471
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_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
friend expr bvadd_no_underflow(expr const &a, expr const &b)
Definition: z3++.h:2242
solver(context &c, simple)
Definition: z3++.h:2772
void Z3_API Z3_params_set_uint(Z3_context c, Z3_params p, Z3_symbol k, unsigned v)
Add a unsigned parameter k with value v to the parameter set p.
expr(context &c)
Definition: z3++.h:813
friend expr fp_eq(expr const &a, expr const &b)
Definition: z3++.h:2022
char const * msg() const
Definition: z3++.h:93
void Z3_API Z3_add_const_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast a)
Add a constant interpretation.
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:4136
expr bv_val(int n, unsigned sz)
Definition: z3++.h:3806
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.
expr operator!=(expr const &a, expr const &b)
Definition: z3++.h:1717
expr value() const
Definition: z3++.h:2568
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
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_fpa_is_zero(Z3_context c, Z3_ast t)
Predicate indicating whether t is a floating-point number with zero value, i.e., +zero or -zero...
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
friend expr bvsub_no_underflow(expr const &a, expr const &b, bool is_signed)
Definition: z3++.h:2248
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, again represented as a floating-point number.
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...
bool is_real() const
Return true if this is a real expression.
Definition: z3++.h:832
Definition: z3_api.h:1350
func_interp & operator=(func_interp const &s)
Definition: z3++.h:2584
friend expr operator!=(expr const &a, expr const &b)
Definition: z3++.h:1717
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...
func_decl_vector recognizers()
Definition: z3++.h:4201
friend expr bvredor(expr const &a)
Definition: z3++.h:1983
expr fpa_rounding_mode()
Definition: z3++.h:3780
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
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...
probe(context &c, double val)
Definition: z3++.h:3218
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.
uint64_t as_uint64() const
Definition: z3++.h:892
expr itos() const
Definition: z3++.h:1510
Definition: z3++.h:136
std::string help() const
Definition: z3++.h:3398
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
func_entry & operator=(func_entry const &s)
Definition: z3++.h:2561
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
Z3_ast Z3_API Z3_ast_vector_get(Z3_context c, Z3_ast_vector v, unsigned i)
Return the AST at position i in the AST vector v.
void set(char const *param, char const *value)
Set global parameter param with string value.
Definition: z3++.h:121
expr_vector units() const
Definition: z3++.h:2856
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...
constructor_list(constructors const &cs)
Definition: z3++.h:3588
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...
void set(char const *k, char const *v)
Definition: z3++.h:2792
simplifier(simplifier const &s)
Definition: z3++.h:3178
expr is_digit() const
Definition: z3++.h:1540
Definition: z3++.h:143
expr fma(expr const &a, expr const &b, expr const &c, expr const &rm)
Definition: z3++.h:2031
tactic when(probe const &p, tactic const &t)
Definition: z3++.h:3465
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
void set_else(expr &value)
Definition: z3++.h:2598
friend expr round_fpa_to_closest_integer(expr const &t)
Round a floating-point term into its closest integer.
Definition: z3++.h:2082
config()
Definition: z3++.h:115
friend std::ostream & operator<<(std::ostream &out, params const &p)
Definition: z3++.h:547
void set(char const *k, double n)
Definition: z3++.h:541
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
Z3_sort Z3_API Z3_get_array_sort_range(Z3_context c, Z3_sort t)
Return the range of the given array sort.
expr lower(handle const &h)
Definition: z3++.h:3382
cube_generator cubes()
Definition: z3++.h:2994
bool is_numeral_u64(uint64_t &i) const
Definition: z3++.h:883
friend expr operator/(expr const &a, expr const &b)
Definition: z3++.h:1803
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 ...
std::string help() const
Definition: z3++.h:3188
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
void set(char const *param, char const *value)
Update global parameter param with string value.
Definition: z3++.h:217
array(unsigned sz)
Definition: z3++.h:457
handle add_soft(expr const &e, unsigned weight)
Definition: z3++.h:3332
expr mk_is_inf() const
Return Boolean expression to test for whether an FP expression is inf.
Definition: z3++.h:939
std::ostream & operator<<(std::ostream &out, exception const &e)
Definition: z3++.h:97
void Z3_API Z3_get_string_contents(Z3_context c, Z3_ast s, unsigned length, unsigned contents[])
Retrieve the unescaped string constant stored in s.
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 ...
A Z3 sort (aka type). Every expression (i.e., formula or term) in Z3 has a sort.
Definition: z3++.h:657
optimize(context &c, optimize &src)
Definition: z3++.h:3301
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.
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. The result is the new AST. The arrays from and to must have size num_exprs. For every i smaller than num_exprs, we must have that sort of from[i] must be equal to sort of to[i].
expr simplify() const
Return a simplified version of this expression.
Definition: z3++.h:1579
unsigned bv_size() const
Return the size of this Bit-vector sort.
Definition: z3++.h:731
bool is_bv() const
Return true if this sort is a Bit-vector sort.
Definition: z3++.h:696
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
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_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
func_decl(context &c)
Definition: z3++.h:762
int to_int() const
Definition: z3++.h:487
friend expr operator^(expr const &a, expr const &b)
Definition: z3++.h:1940
void pop_back()
Definition: z3++.h:603
expr full_set(sort const &s)
Definition: z3++.h:4016
def on_clause_eh(ctx, p, n, dep, clause)
Definition: z3py.py:11633
model(model &src, context &dst, translate)
Definition: z3++.h:2615
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.
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_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. The datatype may be recursive. Return the datatype sort.
friend expr fpa_to_ubv(expr const &t, unsigned sz)
Conversion of a floating-point term into an unsigned bit-vector.
Definition: z3++.h:2054
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.
friend std::ostream & operator<<(std::ostream &out, ast const &n)
Definition: z3++.h:580
Z3_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.
bool is_true() const
Definition: z3++.h:1294
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_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.
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.
sort bv_sort(unsigned sz)
Return the Bit-vector sort of size sz. That is, the sort for bit-vectors of size sz.
Definition: z3++.h:3484
void interrupt()
Interrupt the current procedure being executed by any object managed by this context. This is a soft interruption: there is no guarantee the object will actually stop.
Definition: z3++.h:234
bool is_double(unsigned i) const
Definition: z3++.h:2708
expr lshr(expr const &a, expr const &b)
logic shift right operator for bitvectors
Definition: z3++.h:2214
expr udiv(expr const &a, expr const &b)
unsigned division operator for bitvectors.
Definition: z3++.h:2179
void add(expr const &e)
tracks e by a unique identifier that is returned by the call.
Definition: z3++.h:4530
apply_result operator()(goal const &g) const
Definition: z3++.h:3109
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
bool empty() const
Definition: z3++.h:604
T back() const
Definition: z3++.h:602
solver mk_solver() const
Definition: z3++.h:3102
friend expr concat(expr const &a, expr const &b)
Definition: z3++.h:2456
friend expr mod(expr const &a, expr const &b)
Definition: z3++.h:1641
Z3_symbol Z3_API Z3_param_descrs_get_name(Z3_context c, Z3_param_descrs p, unsigned i)
Return the name of the parameter at given index i.
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...
expr upper(handle const &h)
Definition: z3++.h:3387
Z3_goal_prec
Z3 custom error handler (See Z3_set_error_handler).
Definition: z3_api.h:1389
Z3_error_code
Z3 error codes (See Z3_get_error_code).
Definition: z3_api.h:1348
goal(context &c, Z3_goal s)
Definition: z3++.h:3008
optimize(optimize const &o)
Definition: z3++.h:3298
optimize & operator=(optimize const &o)
Definition: z3++.h:3308
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].
std::string to_string() const
Definition: z3++.h:520
expr eval(expr const &n, bool model_completion=false) const
Definition: z3++.h:2626
model(context &c, Z3_model m)
Definition: z3++.h:2613
Z3_ast_kind kind() const
Definition: z3++.h:569
~params() override
Definition: z3++.h:530
sort array_sort(sort d, sort r)
Return an array sort for arrays from d to r.
Definition: z3++.h:3505
expr constant(symbol const &name, sort const &s)
create an uninterpreted constant.
Definition: z3++.h:3757
void pop()
Definition: z3++.h:3364
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.
friend simplifier operator&(simplifier const &t1, simplifier const &t2)
Definition: z3++.h:3197
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
func_decl operator[](int i) const
Definition: z3++.h:2641
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast t1, Z3_ast t2)
Compare terms.
check_result query(expr &q)
Definition: z3++.h:3428
bool is_ite() const
Definition: z3++.h:1302
unsigned fpa_sbits() const
Definition: z3++.h:735
void set_initial_value(expr const &var, expr const &value)
Definition: z3++.h:2868
fixedpoint(context &c)
Definition: z3++.h:3405
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
sort char_sort()
Return the sort for Unicode characters.
Definition: z3++.h:3486
constructors(context &ctx)
Definition: z3++.h:3549
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_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
tactic(tactic const &s)
Definition: z3++.h:3092
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...
double get_double() const
Definition: z3++.h:2756
friend expr operator||(expr const &a, expr const &b)
Return an expression representing a or b.
Definition: z3++.h:1693
void set_enable_exceptions(bool f)
The C++ API uses by defaults exceptions on errors. For applications that don't work well with excepti...
Definition: z3++.h:210
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...
~fixedpoint() override
Definition: z3++.h:3407
bool is_datatype() const
Return true if this is a Datatype expression.
Definition: z3++.h:848
void add(expr const &e, expr const &t)
Definition: z3++.h:3324
Z3_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.
sort operator()(context &c, Z3_ast a)
Definition: z3++.h:2301
check_result check()
Definition: z3++.h:3367
expr ubv_to_fpa(expr const &t, sort s)
Definition: z3++.h:2068
simplifier(context &c, Z3_simplifier s)
Definition: z3++.h:3177
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.
expr rotate_left(unsigned i) const
Definition: z3++.h:1405
~simplifier() override
Definition: z3++.h:3179
friend probe operator||(probe const &p1, probe const &p2)
Definition: z3++.h:3280
expr is_int(expr const &e)
Definition: z3++.h:1677
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
expr fpa_to_fpa(expr const &t, sort s)
Definition: z3++.h:2075
expr contains(expr const &s) const
Definition: z3++.h:1482
friend expr bvadd_no_overflow(expr const &a, expr const &b, bool is_signed)
bit-vector overflow/underflow checks
Definition: z3++.h:2239
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.
iterator operator++(int) noexcept
Definition: z3++.h:643
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...
expr operator^(expr const &a, expr const &b)
Definition: z3++.h:1940
~param_descrs() override
Definition: z3++.h:512
unsigned Z3_API Z3_fpa_get_ebits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the exponent in a FloatingPoint sort.
friend std::ostream & operator<<(std::ostream &out, optimize const &s)
Definition: z3++.h:3400
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
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].
void from_string(char const *constraints)
Definition: z3++.h:3397
void add(expr const &e, char const *p)
Definition: z3++.h:3328
unsigned lo() const
Definition: z3++.h:1419
Exception used to sign API usage errors.
Definition: z3++.h:88
expr operator*(expr const &a, expr const &b)
Definition: z3++.h:1759
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.
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
unsigned uint_value(unsigned i) const
Definition: z3++.h:2709
unsigned Z3_API Z3_get_sort_id(Z3_context c, Z3_sort s)
Return a unique identifier for s.
Z3_context Z3_API Z3_mk_context_rc(Z3_config c)
Create a context using the given configuration. This function is similar to Z3_mk_context. However, in the context returned by this function, the user is responsible for managing Z3_ast reference counters. Managing reference counters is a burden and error-prone, but allows the user to use the memory more efficiently. The user must invoke Z3_inc_ref for any Z3_ast returned by Z3, and Z3_dec_ref whenever the Z3_ast is not needed anymore. This idiom is similar to the one used in BDD (binary decision diagrams) packages such as CUDD.
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.
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.
expr nth(expr const &index) const
Definition: z3++.h:1494
bool Z3_API Z3_get_numeral_uint64(Z3_context c, Z3_ast v, uint64_t *u)
Similar to Z3_get_numeral_string, but only succeeds if the value can fit in a machine uint64_t int...
ast_vector_tpl(context &c, Z3_ast_vector v)
Definition: z3++.h:592
A Z3 expression is used to represent formulas and terms. For Z3, a formula is any expression of sort ...
Definition: z3++.h:811
void reset_params()
Definition: z3++.h:83
void Z3_API Z3_update_param_value(Z3_context c, Z3_string param_id, Z3_string param_value)
Set a value of a context parameter.
Z3_string Z3_API Z3_sort_to_string(Z3_context c, Z3_sort s)
expr operator!(expr const &a)
Definition: z3++.h:1675
~ast_vector_tpl() override
Definition: z3++.h:596
ast_vector_tpl & set(unsigned idx, ast &a)
Definition: z3++.h:612
expr set_subset(expr const &a, expr const &b)
Definition: z3++.h:4056
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
void add(expr_vector const &es)
Definition: z3++.h:3321
unsigned Z3_API Z3_fpa_get_sbits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the significand in a FloatingPoint sort.
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
unsigned num_exprs() const
Definition: z3++.h:3027
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_fpa_is_subnormal(Z3_context c, Z3_ast t)
Predicate indicating whether t is a subnormal floating-point number.
bool is_uint(unsigned i) const
Definition: z3++.h:2707
expr ule(expr const &a, expr const &b)
unsigned less than or equal to operator for bitvectors.
Definition: z3++.h:2155
expr in_re(expr const &s, expr const &re)
Definition: z3++.h:4096
symbol name(unsigned i)
Definition: z3++.h:517
expr re_diff(expr const &a, expr const &b)
Definition: z3++.h:4126
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
expr_vector unsat_core() const
Definition: z3++.h:2853
bool is_lambda() const
Return true if this expression is a lambda expression.
Definition: z3++.h:920
iterator end() const
Definition: z3++.h:648
Z3_ast Z3_API Z3_mk_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.
~optimize() override
Definition: z3++.h:3315
bool is_fpa() const
Return true if this is a FloatingPoint expression. .
Definition: z3++.h:874
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.
sort datatype_sort(symbol const &name)
a reference to a recursively defined datatype. Expect that it gets defined as a datatype.
Definition: z3++.h:3619
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_error_code check_error() const
Definition: z3++.h:475
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s)
Return the set of units modulo model conversion.
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.
void set(char const *param, int value)
Update global parameter param with Integer value.
Definition: z3++.h:225
static param_descrs simplify_param_descrs(context &c)
Definition: z3++.h:513
friend expr mk_and(expr_vector const &args)
Definition: z3++.h:2534
Z3_ast Z3_API Z3_get_app_arg(Z3_context c, Z3_app a, unsigned i)
Return the i-th argument of the given application.
unsigned num_entries() const
Definition: z3++.h:2592
Z3_ast Z3_API Z3_mk_fpa_rne(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode...
cube_iterator begin()
Definition: z3++.h:2989
unsigned arity() const
Definition: z3++.h:771
iterator begin()
Definition: z3++.h:1617
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_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
sort_vector datatypes(unsigned n, symbol const *names, constructor_list *const *cons)
Create a set of mutually recursive datatypes. n - number of recursive datatypes names - array of name...
Definition: z3++.h:3603
void update_rule(expr &rule, symbol const &name)
Definition: z3++.h:3437
bool enable_exceptions() const
Definition: z3++.h:212
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.
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...
bool is_finite_domain() const
Return true if this sort is a Finite domain sort.
Definition: z3++.h:720
Z3_ast Z3_API Z3_mk_seq_nth(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the element positioned at position index. The function is under-specified if the inde...
func_decl operator()(context &c, Z3_ast a)
Definition: z3++.h:2309
std::string to_string(expr_vector const &queries)
Definition: z3++.h:3453
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.
ast_vector_tpl< func_decl > func_decl_vector
Definition: z3++.h:78
stats(context &c)
Definition: z3++.h:2693
expr algebraic_upper(unsigned precision) const
Definition: z3++.h:1027
Z3_stats Z3_API Z3_solver_get_statistics(Z3_context c, Z3_solver s)
Return statistics for the given solver.
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.
expr operator>=(expr const &a, expr const &b)
Definition: z3++.h:1783
std::string reason_unknown()
Definition: z3++.h:3436
#define MK_EXPR2(_fn, _arg1, _arg2)
Definition: z3++.h:4002
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...
expr replace(expr const &src, expr const &dst) const
Definition: z3++.h:1471
void add_entry(expr_vector const &args, expr &value)
Definition: z3++.h:2594
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.
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_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
expr pw(expr const &a, expr const &b)
Definition: z3++.h:1637
Z3_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
friend std::ostream & operator<<(std::ostream &out, goal const &g)
Definition: z3++.h:3057
friend expr fpa_fp(expr const &sgn, expr const &exp, expr const &sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.
Definition: z3++.h:2039
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p)
Convert a parameter description set into a string. This function is mainly used for printing the cont...
friend probe operator>=(probe const &p1, probe const &p2)
Definition: z3++.h:3257
expr(context &c, Z3_ast n)
Definition: z3++.h:814
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...
expr set_difference(expr const &a, expr const &b)
Definition: z3++.h:4044
symbol name() const
Return name of sort.
Definition: z3++.h:676
T * operator->() const
Definition: z3++.h:644
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
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.
bool is_and() const
Definition: z3++.h:1297
unsigned id() const
retrieve unique identifier for func_decl.
Definition: z3++.h:769
expr operator~(expr const &a)
Definition: z3++.h:2029
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.
expr operator[](int i) const
Definition: z3++.h:3022
bool propagate(expr_vector const &fixed, expr const &conseq)
Definition: z3++.h:4556
Z3_ast Z3_API Z3_mk_fpa_rtn(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode...
expr_vector assertions() const
Definition: z3++.h:3447
friend expr int2bv(unsigned n, expr const &a)
Definition: z3++.h:2234
expr_vector assertions() const
Definition: z3++.h:3392
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...
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
expr_vector unsat_core() const
Definition: z3++.h:3380
friend expr operator-(expr const &a)
Definition: z3++.h:1825
Z3_error_code Z3_API Z3_get_error_code(Z3_context c)
Return the error code for the last API call.
friend expr distinct(expr_vector const &args)
Definition: z3++.h:2447
check_result check(unsigned n, expr *const assumptions)
Definition: z3++.h:2824
Z3_ast Z3_API Z3_mk_bvnand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise nand.
expr bvredor(expr const &a)
Definition: z3++.h:1983
expr rem(expr const &a, expr const &b)
Definition: z3++.h:1657
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.
friend expr operator*(expr const &a, expr const &b)
Definition: z3++.h:1759
probe(context &c, char const *name)
Definition: z3++.h:3217
friend std::ostream & operator<<(std::ostream &out, solver const &s)
Definition: z3++.h:2998
iterator operator++(int)
Definition: z3++.h:1614
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than.
#define MK_EXPR1(_fn, _arg)
Definition: z3++.h:3997
expr get_answer()
Definition: z3++.h:3435
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for unicode strings.
bool is_forall() const
Return true if this expression is a universal quantifier.
Definition: z3++.h:912
~model() override
Definition: z3++.h:2616
friend expr min(expr const &a, expr const &b)
Definition: z3++.h:1951
sort seq_sort(sort &s)
Return a sequence sort over base sort s.
Definition: z3++.h:3487
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
friend expr bvmul_no_underflow(expr const &a, expr const &b)
Definition: z3++.h:2260
bool next_split(expr const &e, unsigned idx, Z3_lbool phase)
Definition: z3++.h:4511
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_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
friend expr operator<=(expr const &a, expr const &b)
Definition: z3++.h:1867
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...
Z3_ast Z3_API Z3_mk_char_to_bv(Z3_context c, Z3_ast ch)
Create a bit-vector (code point) from character.
Z3_ast Z3_API Z3_mk_bit2bool(Z3_context c, unsigned i, Z3_ast t1)
Extracts the bit at position i of a bit-vector and yields a boolean.
expr bvmul_no_underflow(expr const &a, expr const &b)
Definition: z3++.h:2260
friend expr bvredand(expr const &a)
Definition: z3++.h:1989
expr get_const_interp(func_decl c) const
Definition: z3++.h:2649
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.
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.
void Z3_API Z3_del_constructor_list(Z3_context c, Z3_constructor_list clist)
Reclaim memory allocated for constructor list.
A Context manages all other Z3 objects, global configuration options, etc.
Definition: z3++.h:160
Definition: z3++.h:551
Z3 C++ namespace.
Definition: z3++.h:49
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
expr set_add(expr const &s, expr const &e)
Definition: z3++.h:4020
expr ashr(expr const &a, expr const &b)
arithmetic shift right operator for bitvectors
Definition: z3++.h:2221
expr re_empty(sort const &s)
Definition: z3++.h:4108
void Z3_API Z3_set_ast_print_mode(Z3_context c, Z3_ast_print_mode mode)
Select mode for the format used for pretty-printing AST nodes.
void Z3_API Z3_solver_inc_ref(Z3_context c, Z3_solver s)
Increment the reference counter of the given solver.
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
sort fpa_sort()
Return a FloatingPoint sort with given precision bitwidth (16, 32, 64 or 128).
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.
friend tactic operator|(tactic const &t1, tactic const &t2)
Definition: z3++.h:3130
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
expr simplify(params const &p) const
Return a simplified version of this expression. The parameter p is a set of parameters for the Z3 sim...
Definition: z3++.h:1583
expr nor(expr const &a, expr const &b)
Definition: z3++.h:1949
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.
Z3_ast Z3_API Z3_mk_fpa_to_fp_bv(Z3_context c, Z3_ast bv, Z3_sort s)
Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.
std::string get_rational() const
Definition: z3++.h:2755
fixedpoint(fixedpoint const &o)
Definition: z3++.h:3406
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...
unsigned size() const
Definition: z3++.h:3567
solver(context &c, Z3_solver s)
Definition: z3++.h:2773
func_decl_vector accessors()
Definition: z3++.h:4210
expr ubvtos() const
Definition: z3++.h:1515
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.
Z3 global configuration object.
Definition: z3++.h:110
~goal() override
Definition: z3++.h:3010
solver & operator=(solver const &s)
Definition: z3++.h:2780
Z3_ast Z3_API Z3_mk_char_from_bv(Z3_context c, Z3_ast bv)
Create a character from a bit-vector (code point).
Z3_ast Z3_API Z3_mk_fpa_rtp(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode...
void set(char const *param, int value)
Set global parameter param with integer value.
Definition: z3++.h:129
void add_cover(int level, func_decl &p, expr &property)
Definition: z3++.h:3444
expr substitute(expr_vector const &src, expr_vector const &dst)
Apply substitution. Replace src expressions by dst.
Definition: z3++.h:4229
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.
ast(context &c, Z3_ast n)
Definition: z3++.h:556
ast_vector_tpl & operator=(ast_vector_tpl const &s)
Definition: z3++.h:605
expr_vector cube(expr_vector &vars, unsigned cutoff)
Definition: z3++.h:2907
friend expr fpa_to_sbv(expr const &t, unsigned sz)
Conversion of a floating-point term into a signed bit-vector.
Definition: z3++.h:2047
expr operator<=(expr const &a, expr const &b)
Definition: z3++.h:1867
friend std::ostream & operator<<(std::ostream &out, apply_result const &r)
Definition: z3++.h:3081
bool is_finite_domain() const
Return true if this is a Finite-domain expression.
Definition: z3++.h:870
expr proof() const
Definition: z3++.h:2879
void set(char const *k, char const *s)
Definition: z3++.h:543
expr bv_const(char const *name, unsigned sz)
Definition: z3++.h:3772
sort fpa_sort()
Definition: z3++.h:3492
void Z3_API Z3_param_descrs_inc_ref(Z3_context c, Z3_param_descrs p)
Increment the reference counter of the given parameter description set.
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.
user_propagator_base(context &c)
Definition: z3++.h:4377
expr real_val(int n)
Definition: z3++.h:3800
expr string_val(char const *s)
Definition: z3++.h:3823
uint64_t get_numeral_uint64() const
Return uint64_t value of numeral, throw if result cannot fit in uint64_t.
Definition: z3++.h:1122
tactic(context &c, char const *name)
Definition: z3++.h:3090
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
sort string_sort()
Return the sort for Unicode strings.
Definition: z3++.h:3485
std::string str() const
Definition: z3++.h:486
void conflict(expr_vector const &fixed, expr_vector const &lhs, expr_vector const &rhs)
Definition: z3++.h:4546
tactic with(tactic const &t, params const &p)
Definition: z3++.h:3143
expr empty_set(sort const &s)
Definition: z3++.h:4012
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.
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
expr as_array(func_decl &f)
Definition: z3++.h:3991
expr plus(expr const &re)
Definition: z3++.h:4099
func_decl partial_order(sort const &a, unsigned index)
Definition: z3++.h:2273
expr xnor(expr const &a, expr const &b)
Definition: z3++.h:1950
expr char_to_bv() const
Definition: z3++.h:1530
void reset()
Definition: z3++.h:2805
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_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...
expr operator*() const
Definition: z3++.h:1612
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
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_fpa_rem(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point remainder.
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.
std::string get_decimal_string(int precision) const
Return string representation of numeral or algebraic number This method assumes the expression is num...
Definition: z3++.h:1012
~config()
Definition: z3++.h:116
void from_string(char const *s)
Definition: z3++.h:2821
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
sort array_domain() const
Return the domain of this Array sort.
Definition: z3++.h:741
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
Z3_ast Z3_API Z3_mk_seq_replace(Z3_context c, Z3_ast s, Z3_ast src, Z3_ast dst)
Replace the first occurrence of src with dst in s.
Z3_ast_kind
The different kinds of Z3 AST (abstract syntax trees). That is, terms, formulas and types...
Definition: z3_api.h:141
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...
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.
expr_vector args() const
Return a vector of all the arguments of this application. This method assumes the expression is an ap...
Definition: z3++.h:1215
friend expr atleast(expr_vector const &es, unsigned bound)
Definition: z3++.h:2430
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.
expr fpa_fp(expr const &sgn, expr const &exp, expr const &sig)
Definition: z3++.h:2039
void set_initial_value(expr const &var, bool b)
Definition: z3++.h:2875
void Z3_API Z3_dec_ref(Z3_context c, Z3_ast a)
Decrement the reference counter of the given AST. The context c should have been created using Z3_mk_...
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...
func_entry(context &c, Z3_func_entry e)
Definition: z3++.h:2557
void resize(unsigned sz)
Definition: z3++.h:601
void Z3_API Z3_del_config(Z3_config c)
Delete the given configuration object.
bool is_var() const
Return true if this expression is a variable.
Definition: z3++.h:925
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.
expr extract(unsigned hi, unsigned lo) const
Definition: z3++.h:1417
model get_model() const
Definition: z3++.h:3036
Z3_ast_vector Z3_API Z3_algebraic_get_poly(Z3_context c, Z3_ast a)
Return the coefficients of the defining polynomial.
expr operator[](expr_vector const &index) const
Definition: z3++.h:1572
void add(expr const &e, char const *p)
Definition: z3++.h:2812
func_decl to_func_decl(context &c, Z3_func_decl f)
Definition: z3++.h:2121
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.
friend simplifier with(simplifier const &t, params const &p)
Definition: z3++.h:3204
unsigned depth() const
Definition: z3++.h:3025
optimize(context &c)
Definition: z3++.h:3297
expr min(expr const &a, expr const &b)
Definition: z3++.h:1951
context & ctx() const
Definition: z3++.h:474
sort array_range() const
Return the range of this Array sort.
Definition: z3++.h:747
cube_iterator(solver &s, expr_vector &vars, unsigned &cutoff, bool end)
Definition: z3++.h:2934
~ast() override
Definition: z3++.h:558
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...
param_descrs(param_descrs const &o)
Definition: z3++.h:504
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
void set_cutoff(unsigned c) noexcept
Definition: z3++.h:2991
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].
friend expr fpa_to_fpa(expr const &t, sort s)
Conversion of a floating-point term into another floating-point.
Definition: z3++.h:2075
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].
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_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
unsigned Z3_API Z3_get_bv_sort_size(Z3_context c, Z3_sort t)
Return the size of the given bit-vector sort.
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.
Definition: z3++.h:2550
bool is_const() const
Definition: z3++.h:783
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
sort fpa_rounding_mode_sort()
Return a RoundingMode sort.
Definition: z3++.h:3503
bool is_string_value() const
Return true if this expression is a string literal. The string can be accessed using get_string() and...
Definition: z3++.h:1157
check_result check()
Definition: z3++.h:2823
unsigned size() const
Definition: z3++.h:3077
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
std::string to_smt2(char const *status="unknown")
Definition: z3++.h:2882
unsigned get_numeral_uint() const
Return uint value of numeral, throw if result cannot fit in machine uint.
Definition: z3++.h:1088
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...
func_decl get_func_decl(unsigned i) const
Definition: z3++.h:2639
expr operator+(expr const &a, expr const &b)
Definition: z3++.h:1729
func_decl function(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition: z3++.h:3634
expr operator()(context &c, Z3_ast a)
Definition: z3++.h:2290
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.
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
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.
friend probe operator!(probe const &p)
Definition: z3++.h:3283
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.
expr as_expr() const
Definition: z3++.h:3041
bool is_numeral() const
Return true if this expression is a numeral. Specialized functions also return representations for th...
Definition: z3++.h:881
func_decl recfun(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition: z3++.h:3705
expr bvadd_no_underflow(expr const &a, expr const &b)
Definition: z3++.h:2242
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
expr int2bv(unsigned n, expr const &a)
Definition: z3++.h:2234
unsigned Z3_API Z3_get_ast_hash(Z3_context c, Z3_ast a)
Return a hash code for the given AST. The hash code is structural but two different AST objects can m...
expr bvneg_no_overflow(expr const &a)
Definition: z3++.h:2254
func_decl tree_order(sort const &a, unsigned index)
Definition: z3++.h:2279
Z3_string Z3_API Z3_params_to_string(Z3_context c, Z3_params p)
Convert a parameter set into a string. This function is mainly used for printing the contents of a pa...
expr re_complement(expr const &a)
Definition: z3++.h:4133
model convert_model(model const &m) const
Definition: z3++.h:3030
unsigned h() const
Definition: z3++.h:3295
expr srem(expr const &a, expr const &b)
signed remainder operator for bitvectors
Definition: z3++.h:2186
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.
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
expr operator&(expr const &a, expr const &b)
Definition: z3++.h:1936
expr set_intersect(expr const &a, expr const &b)
Definition: z3++.h:4036
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.
exception(char const *msg)
Definition: z3++.h:92
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...
expr mapi(expr const &f, expr const &i, expr const &list)
Definition: z3++.h:2507
solver(solver const &s)
Definition: z3++.h:2776
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_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:57
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_sort Z3_API Z3_mk_fpa_rounding_mode_sort(Z3_context c)
Create the RoundingMode sort.
unsigned Z3_API Z3_get_app_num_args(Z3_context c, Z3_app a)
Return the number of argument of an application. If t is an constant, then the number of arguments is...
friend expr max(expr const &a, expr const &b)
Definition: z3++.h:1967
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...
expr fpa_const(char const *name, unsigned ebits, unsigned sbits)
Definition: z3++.h:3773
virtual void pop(unsigned num_scopes)=0
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
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. ...
expr select(expr const &a, expr const &i)
forward declarations
Definition: z3++.h:3954
expr re_intersect(expr_vector const &args)
Definition: z3++.h:4118
friend expr ubv_to_fpa(expr const &t, sort s)
Conversion of an unsigned bit-vector term into a floating-point.
Definition: z3++.h:2068
Z3_ast Z3_API Z3_mk_fpa_is_infinite(Z3_context c, Z3_ast t)
Predicate indicating whether t is a floating-point number representing +oo or -oo.
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...
~apply_result() override
Definition: z3++.h:3068
expr foldli(expr const &f, expr const &i, expr const &a, expr const &list)
Definition: z3++.h:2521
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...
ast_vector_tpl< sort > sort_vector
Definition: z3++.h:77
std::function< void(expr const &proof, std::vector< unsigned > const &deps, expr_vector const &clause)> on_clause_eh_t
Definition: z3++.h:4268
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
expr mk_xor(expr_vector const &args)
Definition: z3++.h:2540
expr foldl(expr const &f, expr const &a, expr const &list)
Definition: z3++.h:2514
void add(expr const &e)
Definition: z3++.h:3317
Z3_ast Z3_API Z3_get_numerator(Z3_context c, Z3_ast a)
Return the numerator (as a numeral AST) of a numeral AST of sort Real.
expr prefixof(expr const &a, expr const &b)
Definition: z3++.h:4075
void Z3_API Z3_set_error_handler(Z3_context c, Z3_error_handler h)
Register a Z3 error handler.
Z3_ast Z3_API Z3_mk_ubv_to_str(Z3_context c, Z3_ast s)
Unsigned bit-vector to string conversion.
Z3_parameter_kind kind() const
Definition: z3++.h:2750
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...
func_interp(func_interp const &s)
Definition: z3++.h:2581
Z3_decl_kind decl_kind() const
Definition: z3++.h:775
sort datatype(symbol const &name, constructors const &cs)
Create a recursive datatype over a single sort. name is the name of the recursive datatype n - the nu...
Definition: z3++.h:3595
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...
model & operator=(model const &s)
Definition: z3++.h:2618
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
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...
expr operator%(expr const &a, expr const &b)
Definition: z3++.h:1652
expr_vector parse_file(char const *file)
Definition: z3++.h:4153
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_string Z3_API Z3_get_string(Z3_context c, Z3_ast s)
Retrieve the string constant stored in s. Characters outside the basic printable ASCII range are esca...
~func_entry() override
Definition: z3++.h:2559
Z3_ast Z3_API Z3_mk_rotate_right(Z3_context c, unsigned i, Z3_ast t1)
Rotate bits of t1 to the right i times.
tactic par_and_then(tactic const &t1, tactic const &t2)
Definition: z3++.h:3162
unsigned Z3_API Z3_param_descrs_size(Z3_context c, Z3_param_descrs p)
Return the number of parameters in the given parameter description set.
friend expr operator==(expr const &a, expr const &b)
Definition: z3++.h:1706
void set(char const *param, bool value)
Set global parameter param with Boolean value.
Definition: z3++.h:125
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
expr loop(unsigned lo)
create a looping regular expression.
Definition: z3++.h:1550
stats statistics() const
Definition: z3++.h:3394
func_entry entry(unsigned i) const
Definition: z3++.h:2593
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...
void add(expr const &e)
Definition: z3++.h:2806
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_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
bool is_relation() const
Return true if this is a Relation expression.
Definition: z3++.h:852
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_ast Z3_API Z3_mk_fpa_mul(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point multiplication.
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
bool is_bool() const
Return true if this sort is the Boolean sort.
Definition: z3++.h:680
void resize(unsigned sz)
Definition: z3++.h:460
expr ugt(expr const &a, expr const &b)
unsigned greater than operator for bitvectors.
Definition: z3++.h:2173
Z3_ast Z3_API Z3_mk_fpa_is_normal(Z3_context c, Z3_ast t)
Predicate indicating whether t is a normal floating-point number.
Z3_ast Z3_API Z3_mk_bvxnor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise xnor.
goal & operator=(goal const &s)
Definition: z3++.h:3012
expr option(expr const &re)
Definition: z3++.h:4102
Z3_sort Z3_API Z3_get_array_sort_domain(Z3_context c, Z3_sort t)
Return the domain of the given array sort. In the case of a multi-dimensional array, this function returns the sort of the first dimension.
expr const_array(sort const &d, expr const &v)
Definition: z3++.h:4008
stats(stats const &s)
Definition: z3++.h:2695
T const * ptr() const
Definition: z3++.h:464
cube_iterator operator++(int)
Definition: z3++.h:2956
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
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...
expr set_member(expr const &s, expr const &e)
Definition: z3++.h:4052
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
unsigned id() const
retrieve unique identifier for func_decl.
Definition: z3++.h:667
bool is_distinct() const
Definition: z3++.h:1303
Z3_sort Z3_API Z3_mk_datatype_sort(Z3_context c, Z3_symbol name)
create a forward reference to a recursive datatype being declared. The forward reference can be used ...
friend std::ostream & operator<<(std::ostream &out, model const &m)
Definition: z3++.h:2684
bool is_or() const
Definition: z3++.h:1298
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.
int Z3_API Z3_get_symbol_int(Z3_context c, Z3_symbol s)
Return the symbol int value.
bool is_not() const
Definition: z3++.h:1296
void Z3_API Z3_params_dec_ref(Z3_context c, Z3_params p)
Decrement the reference counter of the given parameter set.
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
sort uninterpreted_sort(char const *name)
create an uninterpreted sort with the name given by the string or symbol.
Definition: z3++.h:3626
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...
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...
goal operator[](int i) const
Definition: z3++.h:3078
check_result check(expr_vector const &assumptions)
Definition: z3++.h:2834
unsigned fpa_ebits() const
Definition: z3++.h:733
expr_vector trail() const
Definition: z3++.h:2857
iterator end()
Definition: z3++.h:1618
void reset()
Definition: z3++.h:3026
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows divisor).
bool is_numeral(double &d) const
Definition: z3++.h:888
T * ptr()
Definition: z3++.h:465
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.
bool is_implies() const
Definition: z3++.h:1300
params(params const &s)
Definition: z3++.h:529
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
expr_vector algebraic_poly() const
Return coefficients for p of an algebraic number (root-obj p i)
Definition: z3++.h:1037
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 set_param(char const *param, char const *value)
Definition: z3++.h:80
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_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
expr bv2int(expr const &a, bool is_signed)
bit-vector and integer conversions.
Definition: z3++.h:2233
friend void check_context(object const &a, object const &b)
Definition: z3++.h:478
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
parameter(expr const &e, unsigned idx)
Definition: z3++.h:2745
handle maximize(expr const &e)
Definition: z3++.h:3355
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 Z3_API Z3_mk_int2bv(Z3_context c, unsigned n, Z3_ast t1)
Create an n bit bit-vector from the integer argument t1.
func_decl decl() const
Return the declaration associated with this application. This method assumes the expression is an app...
Definition: z3++.h:1193
unsigned size() const
Definition: z3++.h:598
bool is_seq() const
Return true if this is a sequence expression.
Definition: z3++.h:856
std::u32string get_u32string() const
for a string value expression return an unespaced string value.
Definition: z3++.h:1176
Z3_param_kind
The different kinds of parameters that can be associated with parameter sets. (see Z3_mk_params)...
Definition: z3_api.h:1307
friend expr bvsdiv_no_overflow(expr const &a, expr const &b)
Definition: z3++.h:2251
bool Z3_API Z3_get_numeral_int(Z3_context c, Z3_ast v, int *i)
Similar to Z3_get_numeral_string, but only succeeds if the value can fit in a machine int...
friend probe operator<=(probe const &p1, probe const &p2)
Definition: z3++.h:3252
friend expr operator&&(expr const &a, expr const &b)
Return an expression representing a and b.
Definition: z3++.h:1681
expr get_cover_delta(int level, func_decl &p)
Definition: z3++.h:3439
Z3_string Z3_API Z3_get_numeral_string(Z3_context c, Z3_ast a)
Return numeral value, as a decimal string of a numeric constant term.
bool Z3_API Z3_is_string(Z3_context c, Z3_ast s)
Determine if s is a string constant.
expr int_const(char const *name)
Definition: z3++.h:3769
Z3_ast Z3_API Z3_mk_rem(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 rem arg2.
friend expr operator&(expr const &a, expr const &b)
Definition: z3++.h:1936
friend std::ostream & operator<<(std::ostream &out, exception const &e)
Definition: z3++.h:97
expr arg(unsigned i) const
Definition: z3++.h:2570
expr abs(expr const &a)
Definition: z3++.h:1995
bool operator==(iterator const &other) const noexcept
Definition: z3++.h:1606
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.
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.
bool Z3_API Z3_get_numeral_int64(Z3_context c, Z3_ast v, int64_t *i)
Similar to Z3_get_numeral_string, but only succeeds if the value can fit in a machine int64_t int...
expr sbvtos() const
Definition: z3++.h:1520
unsigned num_args() const
Return the number of arguments in this application. This method assumes the expression is an applicat...
Definition: z3++.h:1200
virtual void decide(expr const &, unsigned, bool)
Definition: z3++.h:4509
void register_decide(decide_eh_t &c)
Definition: z3++.h:4485
Z3_symbol_kind
The different kinds of symbol. In Z3, a symbol can be represented using integers and strings (See Z3_...
Definition: z3_api.h:71
expr sum(expr_vector const &args)
Definition: z3++.h:2438
Z3_string Z3_API Z3_get_numeral_binary_string(Z3_context c, Z3_ast a)
Return numeral value, as a binary string of a numeric constant term.
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
Z3_ast Z3_API Z3_mk_fpa_eq(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point equality.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
sort(context &c)
Definition: z3++.h:659
expr_vector from_string(char const *s)
Definition: z3++.h:3416
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
virtual void created(expr const &)
Definition: z3++.h:4507
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.
goal(context &c, bool models=true, bool unsat_cores=false, bool proofs=false)
Definition: z3++.h:3007
expr suffixof(expr const &a, expr const &b)
Definition: z3++.h:4069
void from_file(char const *filename)
Definition: z3++.h:3396
void Z3_API Z3_interrupt(Z3_context c)
Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers...
expr_vector const * operator->() const
Definition: z3++.h:2957
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.
check_result consequences(expr_vector &assumptions, expr_vector &vars, expr_vector &conseq)
Definition: z3++.h:2846
unsigned algebraic_i() const
Return i of an algebraic number (root-obj p i)
Definition: z3++.h:1047
bool is_app() const
Return true if this expression is an application.
Definition: z3++.h:899
std::string to_string() const
Definition: z3++.h:2682
friend tactic operator&(tactic const &t1, tactic const &t2)
Definition: z3++.h:3123
expr operator<(expr const &a, expr const &b)
Definition: z3++.h:1892
object(context &c)
Definition: z3++.h:472
friend expr operator>(expr const &a, expr const &b)
Definition: z3++.h:1914
unsigned size() const
Definition: z3++.h:3021
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.
handle add(expr const &e, unsigned weight)
Definition: z3++.h:3341
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.
fixedpoint & operator=(fixedpoint const &o)
Definition: z3++.h:3408
ast(context &c)
Definition: z3++.h:555
Z3_symbol_kind kind() const
Definition: z3++.h:485
param_descrs get_param_descrs()
Definition: z3++.h:3191
friend expr nand(expr const &a, expr const &b)
Definition: z3++.h:1948
void set(params const &p)
Definition: z3++.h:3449
expr fp_eq(expr const &a, expr const &b)
Definition: z3++.h:2022
expr atleast(expr_vector const &es, unsigned bound)
Definition: z3++.h:2430
friend tactic with(tactic const &t, params const &p)
Definition: z3++.h:3143
Z3_ast Z3_API Z3_mk_fpa_is_nan(Z3_context c, Z3_ast t)
Predicate indicating whether t is a NaN.
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.
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...
bool Z3_API Z3_is_seq_sort(Z3_context c, Z3_sort s)
Check if s is a sequence sort.
expr real_const(char const *name)
Definition: z3++.h:3770
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.
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.
~solver() override
Definition: z3++.h:2778
sort(context &c, Z3_ast a)
Definition: z3++.h:661
friend expr sbv_to_fpa(expr const &t, sort s)
Conversion of a signed bit-vector term into a floating-point.
Definition: z3++.h:2061
stats statistics() const
Definition: z3++.h:3445
model get_model() const
Definition: z3++.h:3379
context & ctx()
Definition: z3++.h:4393
func_interp get_func_interp(func_decl f) const
Definition: z3++.h:2655
friend probe operator==(probe const &p1, probe const &p2)
Definition: z3++.h:3272
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...
bool is_numeral(std::string &s, unsigned precision) const
Definition: z3++.h:887
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
void conflict(expr_vector const &fixed)
Definition: z3++.h:4539
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_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
bool operator!=(iterator const &other) const noexcept
Definition: z3++.h:633
expr algebraic_lower(unsigned precision) const
Definition: z3++.h:1020
bool is_eq() const
Definition: z3++.h:1301
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.
double Z3_API Z3_get_numeral_double(Z3_context c, Z3_ast a)
Return numeral as a double.
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_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.
Z3_sort_kind sort_kind() const
Return the internal sort kind.
Definition: z3++.h:672
bool is_numeral(std::string &s) const
Definition: z3++.h:886
bool is_arith() const
Return true if this sort is the Integer or Real sort.
Definition: z3++.h:692
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
std::string dimacs(bool include_names=true) const
Definition: z3++.h:2902
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.
Definition: z3++.h:2268
friend expr fma(expr const &a, expr const &b, expr const &c, expr const &rm)
FloatingPoint fused multiply-add.
Definition: z3++.h:2031
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.
expr mk_is_zero() const
Return Boolean expression to test for whether an FP expression is a zero.
Definition: z3++.h:979
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
void from_file(char const *file)
Definition: z3++.h:2820
Z3_sort Z3_API Z3_get_domain(Z3_context c, Z3_func_decl d, unsigned i)
Return the sort of the i-th parameter of the given function declaration.
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.
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...
Definition: z3++.h:140
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
friend expr pbeq(expr_vector const &es, int const *coeffs, int bound)
Definition: z3++.h:2414
expr at(expr const &index) const
Definition: z3++.h:1488
unsigned Z3_API Z3_get_ast_id(Z3_context c, Z3_ast t)
Return a unique identifier for t. The identifier is unique up to structural equality. Thus, two ast nodes created by the same context and having the same children and same function symbols have the same identifiers. Ast nodes created in the same context, but having different children or different functions have different identifiers. Variables and quantifiers are also assigned different identifiers according to their structure.
bool operator==(iterator const &other) const noexcept
Definition: z3++.h:630
void add(expr_vector const &v)
Definition: z3++.h:3020
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision)
Return numeral as a string in decimal notation. The result has at most precision decimal places...
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
expr_vector trail(array< unsigned > &levels) const
Definition: z3++.h:2858
bool operator!=(cube_iterator const &other) const noexcept
Definition: z3++.h:2963
Z3_ast Z3_API Z3_mk_fpa_rna(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode...
expr empty(sort const &s)
Definition: z3++.h:4064
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.
bool is_well_sorted() const
Return true if this expression is well sorted (aka type correct).
Definition: z3++.h:934
Z3_ast Z3_API Z3_mk_seq_extract(Z3_context c, Z3_ast s, Z3_ast offset, Z3_ast length)
Extract subsequence starting at offset of length.
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_fpa_add(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point addition.
Z3_config Z3_API Z3_mk_config(void)
Create a configuration object for the Z3 context object.
Z3_ast Z3_API Z3_mk_char_to_int(Z3_context c, Z3_ast ch)
Create an integer (code point) from character.
cube_generator(solver &s, expr_vector &vars)
Definition: z3++.h:2982
friend tactic par_and_then(tactic const &t1, tactic const &t2)
Definition: z3++.h:3162
char const * what() const
Definition: z3++.h:94
sort real_sort()
Return the Real sort.
Definition: z3++.h:3483
void set(char const *k, unsigned v)
Definition: z3++.h:2789
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.
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.
virtual ~user_propagator_base()
Definition: z3++.h:4386
friend std::ostream & operator<<(std::ostream &out, ast_vector_tpl const &v)
Definition: z3++.h:649
expr re_full(sort const &s)
Definition: z3++.h:4113
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d)
Return the range of the given declaration.
bool inconsistent() const
Definition: z3++.h:3024
bool is_const() const
Return true if this expression is a constant (i.e., an application with 0 arguments).
Definition: z3++.h:903
expr arg(unsigned i) const
Return the i-th argument of this application. This method assumes the expression is an application...
Definition: z3++.h:1208
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 -...
ast_vector_tpl(ast_vector_tpl const &s)
Definition: z3++.h:593
friend expr rem(expr const &a, expr const &b)
Definition: z3++.h:1657
expr num_val(int n, sort const &s)
Definition: z3++.h:3827
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. ...
bool eq(ast const &a, ast const &b)
Definition: z3++.h:584
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
unsigned num_consts() const
Definition: z3++.h:2636
expr map(expr const &f, expr const &list)
Definition: z3++.h:2500
symbol int_symbol(int n)
Create a Z3 symbol based on the given integer.
Definition: z3++.h:3479
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...
expr loop(unsigned lo, unsigned hi)
Definition: z3++.h:1555
void add(expr_vector const &v)
Definition: z3++.h:2815
~stats() override
Definition: z3++.h:2696
expr fpa_val(double n)
Definition: z3++.h:3817
func_decl transitive_closure(func_decl const &)
Definition: z3++.h:779
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.
expr bvmul_no_overflow(expr const &a, expr const &b, bool is_signed)
Definition: z3++.h:2257
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_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
friend probe operator>(probe const &p1, probe const &p2)
Definition: z3++.h:3267
expr indexof(expr const &s, expr const &substr, expr const &offset)
Definition: z3++.h:4081
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...
expr set_complement(expr const &a)
Definition: z3++.h:4048
unsigned num_funcs() const
Definition: z3++.h:2637
bool is_algebraic() const
Return true if expression is an algebraic number.
Definition: z3++.h:929
expr operator()() const
Definition: z3++.h:3850
Z3_constructor operator[](unsigned i) const
Definition: z3++.h:3565
expr_vector non_units() const
Definition: z3++.h:2855
Z3_parameter_kind
The different kinds of parameters that can be associated with function symbols.
Definition: z3_api.h:93
iterator(expr &e, unsigned i)
Definition: z3++.h:1605
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_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...
param_descrs & operator=(param_descrs const &o)
Definition: z3++.h:505
expr operator>(expr const &a, expr const &b)
Definition: z3++.h:1914
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].
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:147
expr star(expr const &re)
Definition: z3++.h:4105
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.
friend expr operator~(expr const &a)
Definition: z3++.h:2029
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.
expr operator==(expr const &a, expr const &b)
Definition: z3++.h:1706
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
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_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
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...
param_descrs(context &c, Z3_param_descrs d)
Definition: z3++.h:503
void Z3_API Z3_set_param_value(Z3_config c, Z3_string param_id, Z3_string param_value)
Set a configuration parameter.
friend tactic repeat(tactic const &t, unsigned max)
Definition: z3++.h:3137
expr operator|(expr const &a, expr const &b)
Definition: z3++.h:1944
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_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.
Z3_ast Z3_API Z3_mk_fpa_div(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point division.
friend tactic par_or(unsigned n, tactic const *tactics)
Definition: z3++.h:3153
expr pbge(expr_vector const &es, int const *coeffs, int bound)
Definition: z3++.h:2406
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
friend expr abs(expr const &a)
Definition: z3++.h:1995
tactic(context &c, Z3_tactic s)
Definition: z3++.h:3091
void check_context(object const &a, object const &b)
Definition: z3++.h:478
expr char_to_int() const
Definition: z3++.h:1525
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.
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_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.
expr mk_from_ieee_bv(sort const &s) const
Convert this IEEE BV into a fpa.
Definition: z3++.h:999
virtual user_propagator_base * fresh(context &ctx)=0
user_propagators created using fresh() are created during search and their lifetimes are restricted t...
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_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
expr bool_const(char const *name)
create uninterpreted constants of a given sort.
Definition: z3++.h:3768
expr urem(expr const &a, expr const &b)
unsigned reminder operator for bitvectors
Definition: z3++.h:2200
void Z3_API Z3_simplifier_inc_ref(Z3_context c, Z3_simplifier t)
Increment the reference counter of the given simplifier.
void Z3_API Z3_params_set_double(Z3_context c, Z3_params p, Z3_symbol k, double v)
Add a double parameter k with value v to the parameter set p.
expr sbv_to_fpa(expr const &t, sort s)
Definition: z3++.h:2061
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_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.
expr operator&&(expr const &a, expr const &b)
Definition: z3++.h:1681
double apply(goal const &g) const
Definition: z3++.h:3230
expr extract(expr const &offset, expr const &length) const
sequence and regular expression operations.
Definition: z3++.h:1467
rounding_mode
Definition: z3++.h:139
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_string Z3_API Z3_get_symbol_string(Z3_context c, Z3_symbol s)
Return the symbol name.
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_get_algebraic_number_upper(Z3_context c, Z3_ast a, unsigned precision)
Return a upper bound for the given real algebraic number. The interval isolating the number is smalle...
symbol get_symbol() const
Definition: z3++.h:2754
#define _Z3_MK_BIN_(a, b, binop)
Definition: z3++.h:1622
void set_rounding_mode(rounding_mode rm)
Sets RoundingMode of FloatingPoints.
Definition: z3++.h:3778
friend expr ite(expr const &c, expr const &t, expr const &e)
Create the if-then-else expression ite(c, t, e)
Definition: z3++.h:2094
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_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.
std::string dimacs(bool include_names=true) const
Definition: z3++.h:3054
expr_vector rules() const
Definition: z3++.h:3448
friend expr nor(expr const &a, expr const &b)
Definition: z3++.h:1949
params & operator=(params const &s)
Definition: z3++.h:532
friend std::ostream & operator<<(std::ostream &out, symbol const &s)
Definition: z3++.h:491
Z3_sort_kind Z3_API Z3_get_sort_kind(Z3_context c, Z3_sort t)
Return the sort kind (e.g., array, tuple, int, bool, etc).
model(model const &s)
Definition: z3++.h:2614
Z3_param_descrs Z3_API Z3_get_global_param_descrs(Z3_context c)
Retrieve description of global parameters.
unsigned hi() const
Definition: z3++.h:1420
check_result query(func_decl_vector &relations)
Definition: z3++.h:3429
Z3_lbool Z3_API Z3_get_bool_value(Z3_context c, Z3_ast a)
Return Z3_L_TRUE if a is true, Z3_L_FALSE if it is false, and Z3_L_UNDEF otherwise.
probe(probe const &s)
Definition: z3++.h:3220
Z3_param_kind Z3_API Z3_param_descrs_get_kind(Z3_context c, Z3_param_descrs p, Z3_symbol n)
Return the kind associated with the given parameter name n.
iterator(ast_vector_tpl const *v, unsigned i)
Definition: z3++.h:628
Definition: z3++.h:144
friend expr operator<(expr const &a, expr const &b)
Definition: z3++.h:1892
friend expr operator!(expr const &a)
Return an expression representing not(a).
Definition: z3++.h:1675
class for auxiliary parameters associated with func_decl The class is initialized with a func_decl or...
Definition: z3++.h:2733
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
virtual ~exception()=default
friend expr bvsub_no_overflow(expr const &a, expr const &b)
Definition: z3++.h:2245
solver(context &c, solver const &src, translate)
Definition: z3++.h:2775
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_goal_prec precision() const
Definition: z3++.h:3023
solver(context &c)
Definition: z3++.h:2771
expr get_expr() const
Definition: z3++.h:2751
unsigned Z3_API Z3_get_func_decl_id(Z3_context c, Z3_func_decl f)
Return a unique identifier for f.
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_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
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.
friend expr sum(expr_vector const &args)
Definition: z3++.h:2438
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...
expr lambda(expr const &x, expr const &b)
Definition: z3++.h:2373
parameter(func_decl const &d, unsigned idx)
Definition: z3++.h:2740
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.
func_decl get_decl() const
Definition: z3++.h:2753
func_decl(context &c, Z3_func_decl n)
Definition: z3++.h:763
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
ast_vector_tpl< ast > ast_vector
Definition: z3++.h:74
bool is_decided_unsat() const
Definition: z3++.h:3029
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.
handle minimize(expr const &e)
Definition: z3++.h:3358
expr mk_is_subnormal() const
Return Boolean expression to test for whether an FP expression is a subnormal.
Definition: z3++.h:969
friend probe operator<(probe const &p1, probe const &p2)
Definition: z3++.h:3262
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
expr_vector assertions() const
Definition: z3++.h:2854
cube_iterator & operator++()
Definition: z3++.h:2946
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
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_seq_map(Z3_context c, Z3_ast f, Z3_ast s)
Create a map of the function f over the sequence s.
sort get_sort() const
Return the sort of this expression.
Definition: z3++.h:819
friend probe operator&&(probe const &p1, probe const &p2)
Definition: z3++.h:3277
void set(char const *k, double v)
Definition: z3++.h:2790
void add(expr const &e, expr const &p)
Definition: z3++.h:2807
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.
expr store(expr const &a, expr const &i, expr const &v)
Definition: z3++.h:3971
Z3_ast Z3_API Z3_mk_fpa_geq(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point greater than or equal.
virtual ~object()=default
bool is_exists() const
Return true if this expression is an existential quantifier.
Definition: z3++.h:916
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
void set(char const *k, unsigned n)
Definition: z3++.h:540
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...
iterator begin() const noexcept
Definition: z3++.h:647
expr_vector const & operator*() const noexcept
Definition: z3++.h:2958
friend expr pble(expr_vector const &es, int const *coeffs, int bound)
Definition: z3++.h:2398
Z3_ast Z3_API Z3_mk_fpa_sub(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point subtraction.
std::string key(unsigned i) const
Definition: z3++.h:2706
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.
bool is_relation() const
Return true if this sort is a Relation sort.
Definition: z3++.h:708
Z3_ast m_ast
Definition: z3++.h:553
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
void set(char const *k, bool b)
Definition: z3++.h:539
tactic repeat(tactic const &t, unsigned max=UINT_MAX)
Definition: z3++.h:3137
expr bool_val(bool b)
Definition: z3++.h:3791
~context()
Definition: z3++.h:186
expr operator||(expr const &a, expr const &b)
Definition: z3++.h:1693
expr ult(expr const &a, expr const &b)
unsigned less than operator for bitvectors.
Definition: z3++.h:2161
void Z3_API Z3_params_inc_ref(Z3_context c, Z3_params p)
Increment the reference counter of the given parameter set.
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...
unsigned num_parameters() const
Definition: z3++.h:776
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...
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_params_set_symbol(Z3_context c, Z3_params p, Z3_symbol k, Z3_symbol v)
Add a symbol parameter k with value v to the parameter set p.
bool is_int() const
Return true if this is an integer expression.
Definition: z3++.h:828
friend expr pbge(expr_vector const &es, int const *coeffs, int bound)
Definition: z3++.h:2406
apply_result apply(goal const &g) const
Definition: z3++.h:3103
expr int_val(int n)
Definition: z3++.h:3793
bool is_arith() const
Return true if this is an integer or real expression.
Definition: z3++.h:836
void Z3_API Z3_global_param_reset_all(void)
Restore the value of all global (and module) parameters. This command will not affect already created...
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
model get_model() const
Definition: z3++.h:2845
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_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.
expr else_value() const
Definition: z3++.h:2591
expr mk_or(expr_vector const &args)
Definition: z3++.h:2528
tactic fail_if(probe const &p)
Definition: z3++.h:3460
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_param_kind kind(symbol const &s)
Definition: z3++.h:518
stats(context &c, Z3_stats e)
Definition: z3++.h:2694
expr exists(expr const &x, expr const &b)
Definition: z3++.h:2349
expr round_fpa_to_closest_integer(expr const &t)
Definition: z3++.h:2082
std::string to_string()
Definition: z3++.h:3452
expr sge(expr const &a, expr const &b)
signed greater than or equal to operator for bitvectors.
Definition: z3++.h:2141
ast operator()(context &c, Z3_ast a)
Definition: z3++.h:2285
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
Definition: z3++.h:142
expr rotate_right(unsigned i) const
Definition: z3++.h:1406
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
expr_vector parse_string(char const *s)
parsing
Definition: z3++.h:4147
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.
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.
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.
context(config &c)
Definition: z3++.h:185
func_decl user_propagate_function(symbol const &name, sort_vector const &domain, sort const &range)
Definition: z3++.h:3749
void recdef(func_decl decl, expr_vector const &args, expr const &body)
add function definition body to declaration decl. decl needs to be declared using context::recfun...
Definition: z3++.h:3743
expr unit() const
Definition: z3++.h:1477
bool is_array() const
Return true if this sort is a Array sort.
Definition: z3++.h:700
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.
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.
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...
expr_vector from_file(char const *s)
Definition: z3++.h:3421
void set(char const *k, symbol const &v)
Definition: z3++.h:2791
expr ite(expr const &c, expr const &t, expr const &e)
Create the if-then-else expression ite(c, t, e)
Definition: z3++.h:2094
T const & operator[](int i) const
Definition: z3++.h:463
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.
func_entry(func_entry const &s)
Definition: z3++.h:2558
Z3_ast Z3_API Z3_mk_extract(Z3_context c, unsigned high, unsigned low, Z3_ast t1)
Extract the bits high down to low from a bit-vector of size m to yield a new bit-vector of size n...
double double_value(unsigned i) const
Definition: z3++.h:2710
expr bit2bool(unsigned i) const
Definition: z3++.h:1418
func_decl recfun(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition: z3++.h:3941
void register_eq(eq_eh_t &f)
Definition: z3++.h:4429
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_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
expr body() const
Return the 'body' of this quantifier.
Definition: z3++.h:1228
std::string get_string() const
for a string value expression return an escaped string value.
Definition: z3++.h:1164
expr char_from_bv() const
Definition: z3++.h:1535
friend expr bvneg_no_overflow(expr const &a)
Definition: z3++.h:2254
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
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.
cube_generator(solver &s)
Definition: z3++.h:2975
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.
ast & operator=(ast const &s)
Definition: z3++.h:561
bool is_seq() const
Return true if this sort is a Sequence sort.
Definition: z3++.h:712
func_interp add_func_interp(func_decl &f, expr &else_val)
Definition: z3++.h:2669
expr repeat(unsigned i) const
Definition: z3++.h:1407
bool is_bv() const
Return true if this is a Bit-vector expression.
Definition: z3++.h:840
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
expr forall(expr const &x, expr const &b)
Definition: z3++.h:2325
void Z3_API Z3_params_set_bool(Z3_context c, Z3_params p, Z3_symbol k, bool v)
Add a Boolean parameter k with value v to the parameter set p.
sort domain(unsigned i) const
Definition: z3++.h:772
bool is_bool() const
Return true if this is a Boolean expression.
Definition: z3++.h:824
int64_t get_numeral_int64() const
Return int64_t value of numeral, throw if result cannot fit in int64_t.
Definition: z3++.h:1105
sort(context &c, Z3_sort s)
Definition: z3++.h:660
unsigned hash() const
Definition: z3++.h:570
double operator()(goal const &g) const
Definition: z3++.h:3231
Z3_error_code check_error() const
Auxiliary method used to check for API usage errors.
Definition: z3++.h:192
Z3_ast Z3_API Z3_mk_fpa_sqrt(Z3_context c, Z3_ast rm, Z3_ast t)
Floating-point square root.
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.
bool operator==(cube_iterator const &other) const noexcept
Definition: z3++.h:2960
Z3_ast Z3_API Z3_get_algebraic_number_lower(Z3_context c, Z3_ast a, unsigned precision)
Return a lower bound for the given real algebraic number. The interval isolating the number is smalle...
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).
bool is_datatype() const
Return true if this sort is a Datatype sort.
Definition: z3++.h:704
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.
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...
std::string to_string() const
Definition: z3++.h:572
expr implies(expr const &a, expr const &b)
Definition: z3++.h:1629
sort get_sort() const
Definition: z3++.h:2752
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_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...
friend expr sqrt(expr const &a, expr const &rm)
Definition: z3++.h:2015
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.
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:2107
bool has_interp(func_decl f) const
Definition: z3++.h:2664
bool operator!=(iterator const &other) const noexcept
Definition: z3++.h:1609
Z3_sort Z3_API Z3_mk_char_sort(Z3_context c)
Create a sort for unicode characters.
expr mk_is_normal() const
Return Boolean expression to test for whether an FP expression is a normal.
Definition: z3++.h:959
expr concat(expr const &a, expr const &b)
Definition: z3++.h:2456
symbol(context &c, Z3_symbol s)
Definition: z3++.h:483
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.
solver(context &c, char const *logic)
Definition: z3++.h:2774
bool is_false() const
Definition: z3++.h:1295
tactic try_for(tactic const &t, unsigned ms)
Definition: z3++.h:3148
func_interp(context &c, Z3_func_interp e)
Definition: z3++.h:2580
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 register_relation(func_decl &p)
Definition: z3++.h:3446
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.
expr fpa_nan(sort const &s)
Definition: z3++.h:3819
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.
void add_rule(expr &rule, symbol const &name)
Definition: z3++.h:3426
expr shl(expr const &a, expr const &b)
shift left operator for bitvectors
Definition: z3++.h:2207
expr bvsdiv_no_overflow(expr const &a, expr const &b)
Definition: z3++.h:2251
params(context &c)
Definition: z3++.h:528
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_rotate_left(Z3_context c, unsigned i, Z3_ast t1)
Rotate bits of t1 to the left i times.
Z3_ast Z3_API Z3_mk_re_diff(Z3_context c, Z3_ast re1, Z3_ast re2)
Create the difference of regular expressions.
friend tactic try_for(tactic const &t, unsigned ms)
Definition: z3++.h:3148
void push_back(T const &e)
Definition: z3++.h:600
expr pble(expr_vector const &es, int const *coeffs, int bound)
Definition: z3++.h:2398
expr max(expr const &a, expr const &b)
Definition: z3++.h:1967
sort range() const
Definition: z3++.h:773
expr sqrt(expr const &a, expr const &rm)
Definition: z3++.h:2015
expr mk_to_ieee_bv() const
Convert this fpa into an IEEE BV.
Definition: z3++.h:989
void set_initial_value(expr const &var, bool b)
Definition: z3++.h:3351
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:76
bool is_re() const
Return true if this is a regular expression.
Definition: z3++.h:860
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
int get_int() const
Definition: z3++.h:2757
expr mk_is_nan() const
Return Boolean expression to test for whether an FP expression is a NaN.
Definition: z3++.h:949
expr uge(expr const &a, expr const &b)
unsigned greater than or equal to operator for bitvectors.
Definition: z3++.h:2167
void push()
Definition: z3++.h:3361
expr last_indexof(expr const &s, expr const &substr)
Definition: z3++.h:4087
expr slt(expr const &a, expr const &b)
signed less than operator for bitvectors.
Definition: z3++.h:2135
void set(char const *param, bool value)
Update global parameter param with Boolean value.
Definition: z3++.h:221
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
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. Add the parsed constraints and objectives to the optimization context.
void set(params const &p)
Definition: z3++.h:2787
bool is_re() const
Return true if this sort is a regular expression sort.
Definition: z3++.h:716
func_decl_vector constructors()
Definition: z3++.h:4192
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
Z3_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.
bool is_quantifier() const
Return true if this expression is a quantifier.
Definition: z3++.h:907
func_decl tuple_sort(char const *name, unsigned n, char const *const *names, sort const *sorts, func_decl_vector &projs)
Return a tuple constructor. name is the name of the returned constructor, n are the number of argumen...
Definition: z3++.h:3521
context * m_ctx
Definition: z3++.h:470
bool propagate(expr_vector const &fixed, expr_vector const &lhs, expr_vector const &rhs, expr const &conseq)
Definition: z3++.h:4563
unsigned size()
Definition: z3++.h:516
unsigned size() const
Definition: z3++.h:461
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
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.
expr fpa_inf(sort const &s, bool sgn)
Definition: z3++.h:3820
symbol name() const
Definition: z3++.h:774
std::string help() const
Definition: z3++.h:3450
bool Z3_API Z3_is_re_sort(Z3_context c, Z3_sort s)
Check if s is a regular expression sort.
expr operator-(expr const &a)
Definition: z3++.h:1825
void pop(unsigned n=1)
Definition: z3++.h:2804
friend std::ostream & operator<<(std::ostream &out, stats const &s)
Definition: z3++.h:2713
expr smod(expr const &a, expr const &b)
signed modulus operator for bitvectors
Definition: z3++.h:2193
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 propa...
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.
expr to_real(expr const &a)
Definition: z3++.h:3911
cube_iterator end()
Definition: z3++.h:2990
handle(unsigned h)
Definition: z3++.h:3294
unsigned size() const
Definition: z3++.h:2705
void register_created(created_eh_t &c)
Definition: z3++.h:4469
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
friend expr implies(expr const &a, expr const &b)
Definition: z3++.h:1629
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...
virtual void push()=0
param_descrs get_param_descrs()
Definition: z3++.h:2904
Definition: z3++.h:141
void add(symbol const &name, symbol const &rec, unsigned n, symbol const *names, sort const *fields)
Definition: z3++.h:3556
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.
void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.
void Z3_API Z3_inc_ref(Z3_context c, Z3_ast a)
Increment the reference counter of the given AST. The context c should have been created using Z3_mk_...
ast(ast const &s)
Definition: z3++.h:557
sort enumeration_sort(char const *name, unsigned n, char const *const *enum_names, func_decl_vector &cs, func_decl_vector &ts)
Return an enumeration sort: enum_names[0], ..., enum_names[n-1]. cs and ts are output parameters...
Definition: z3++.h:3510
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
Z3_ast Z3_API Z3_mk_fpa_min(Z3_context c, Z3_ast t1, Z3_ast t2)
Minimum of floating-point numbers.
tactic par_or(unsigned n, tactic const *tactics)
Definition: z3++.h:3153
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.
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 ...
~tactic() override
Definition: z3++.h:3093
Z3_decl_kind
The different kinds of interpreted function kinds.
Definition: z3_api.h:962
T operator[](unsigned i) const
Definition: z3++.h:599
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
expr sgt(expr const &a, expr const &b)
signed greater than operator for bitvectors.
Definition: z3++.h:2147
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_fpa_leq(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point less than or equal.
apply_result(context &c, Z3_apply_result s)
Definition: z3++.h:3066
~probe() override
Definition: z3++.h:3221
expr nand(expr const &a, expr const &b)
Definition: z3++.h:1948
def tactics
Definition: z3py.py:8679
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.
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_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
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.
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.
void Z3_API Z3_ast_vector_set(Z3_context c, Z3_ast_vector v, unsigned i, Z3_ast a)
Update position i of the AST vector v with the AST a.
expr fpa_to_ubv(expr const &t, unsigned sz)
Definition: z3++.h:2054
expr stoi() const
Definition: z3++.h:1505
static param_descrs global_param_descrs(context &c)
Definition: z3++.h:514
expr operator/(expr const &a, expr const &b)
Definition: z3++.h:1803
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_ast Z3_API Z3_mk_fpa_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point less than.
void query(unsigned i, func_decl &constructor, func_decl &test, func_decl_vector &accs)
Definition: z3++.h:3569
Function declaration (aka function definition). It is the signature of interpreted and uninterpreted ...
Definition: z3++.h:760
expr set_union(expr const &a, expr const &b)
Definition: z3++.h:4028
Z3_ast Z3_API Z3_get_denominator(Z3_context c, Z3_ast a)
Return the denominator (as a numeral AST) of a numeral AST of sort Real.
T & operator[](int i)
Definition: z3++.h:462
expr_vector objectives() const
Definition: z3++.h:3393
bool Z3_API Z3_is_well_sorted(Z3_context c, Z3_ast t)
Return true if the given expression t is well sorted.
int get_numeral_int() const
Return int value of numeral, throw if result cannot fit in machine int.
Definition: z3++.h:1069
param_descrs get_param_descrs()
Definition: z3++.h:3120
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...
bool is_xor() const
Definition: z3++.h:1299
virtual void fixed(expr const &, expr const &)
Definition: z3++.h:4501
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.
goal(goal const &s)
Definition: z3++.h:3009
sort int_sort()
Return the integer sort.
Definition: z3++.h:3482
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_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
ast_vector_tpl(context &c, ast_vector_tpl const &src)
Definition: z3++.h:594
expr set_del(expr const &s, expr const &e)
Definition: z3++.h:4024
void set(params const &p)
Definition: z3++.h:3381
check_result check(expr_vector const &asms)
Definition: z3++.h:3368
void set_initial_value(expr const &var, int i)
Definition: z3++.h:3348
#define _Z3_MK_UN_(a, mkun)
Definition: z3++.h:1669
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.
simplifier & operator=(simplifier const &s)
Definition: z3++.h:3181
int64_t as_int64() const
Definition: z3++.h:893
stats & operator=(stats const &s)
Definition: z3++.h:2698
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.
simplifier(context &c, char const *name)
Definition: z3++.h:3176
unsigned num_args() const
Definition: z3++.h:2569
expr bvsub_no_overflow(expr const &a, expr const &b)
Definition: z3++.h:2245
Z3_ast Z3_API Z3_mk_sbv_to_str(Z3_context c, Z3_ast s)
Signed bit-vector to string conversion.
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_lbool bool_value() const
Definition: z3++.h:1133
expr fpa_to_sbv(expr const &t, unsigned sz)
Definition: z3++.h:2047
bool Z3_API Z3_solver_next_split(Z3_context c, Z3_solver_callback cb, Z3_ast t, unsigned idx, Z3_lbool phase)
void set_initial_value(expr const &var, int i)
Definition: z3++.h:2872
apply_result & operator=(apply_result const &s)
Definition: z3++.h:3070
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.
Z3_func_decl Z3_API Z3_solver_propagate_declare(Z3_context c, Z3_symbol name, unsigned n, Z3_sort *domain, Z3_sort range)
expr atmost(expr_vector const &es, unsigned bound)
Definition: z3++.h:2422
void Z3_API Z3_ast_vector_push(Z3_context c, Z3_ast_vector v, Z3_ast a)
Add the AST a in the end of the AST vector v. The size of v is increased by one.
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.
bool is_real() const
Return true if this sort is the Real sort.
Definition: z3++.h:688
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.
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.
sort to_sort(context &c, Z3_sort s)
Definition: z3++.h:2116
expr string_const(char const *name)
Definition: z3++.h:3771
context()
Definition: z3++.h:184
void Z3_API Z3_param_descrs_dec_ref(Z3_context c, Z3_param_descrs p)
Decrement the reference counter of the given parameter description set.
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 ...
expr numerator() const
Definition: z3++.h:1137
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.
void Z3_API Z3_solver_propagate_eq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression equalities.
bool is_decided_sat() const
Definition: z3++.h:3028
on_clause(solver &s, on_clause_eh_t &on_clause_eh)
Definition: z3++.h:4284
void add(expr const &f)
Definition: z3++.h:3019
friend expr mk_xor(expr_vector const &args)
Definition: z3++.h:2540
Z3_ast Z3_API Z3_mk_fpa_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point greater than.
friend expr range(expr const &lo, expr const &hi)
Definition: z3++.h:4136
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...
expr to_re(expr const &s)
Definition: z3++.h:4093
func_decl linear_order(sort const &a, unsigned index)
Definition: z3++.h:2270
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. Add the parsed constraints and objectives to the optimization context.
Z3_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.
check_result
Definition: z3++.h:135
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...
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.
expr denominator() const
Definition: z3++.h:1145
std::string to_string() const
Definition: z3++.h:650
bool is_numeral_i(int &i) const
Definition: z3++.h:884
param_descrs get_param_descrs()
Definition: z3++.h:3451
unsigned size() const
Definition: z3++.h:2640
const char * Z3_string
Z3 string type. It is just an alias for const char *.
Definition: z3_api.h:50
unsigned Z3_API Z3_algebraic_get_i(Z3_context c, Z3_ast a)
Return which root of the polynomial the algebraic number represents.
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...
apply_result(apply_result const &s)
Definition: z3++.h:3067
bool is_fpa() const
Return true if this sort is a Floating point sort.
Definition: z3++.h:724