Z3
 
Loading...
Searching...
No Matches
z3++.h
Go to the documentation of this file.
1/*++
2Copyright (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.
14Author:
15
16 Leonardo (leonardo) 2012-03-28
17
18Notes:
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
49namespace 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 inline void get_version(unsigned& major, unsigned& minor, unsigned& build_number, unsigned& revision_number) {
89 Z3_get_version(&major, &minor, &build_number, &revision_number);
90 }
91
95 inline std::string get_full_version() {
96 return std::string(Z3_get_full_version());
97 }
98
103 inline void enable_trace(char const * tag) {
104 Z3_enable_trace(tag);
105 }
106
111 inline void disable_trace(char const * tag) {
112 Z3_disable_trace(tag);
113 }
114
118 class exception : public std::exception {
119 std::string m_msg;
120 public:
121 virtual ~exception() throw() = default;
122 exception(char const * msg):m_msg(msg) {}
123 char const * msg() const { return m_msg.c_str(); }
124 char const * what() const throw() { return m_msg.c_str(); }
125 friend std::ostream & operator<<(std::ostream & out, exception const & e);
126 };
127 inline std::ostream & operator<<(std::ostream & out, exception const & e) { out << e.msg(); return out; }
128
129#if !defined(Z3_THROW)
130#if __cpp_exceptions || _CPPUNWIND || __EXCEPTIONS
131#define Z3_THROW(x) throw x
132#else
133#define Z3_THROW(x) {}
134#endif
135#endif // !defined(Z3_THROW)
136
140 class config {
141 Z3_config m_cfg;
142 config(config const &) = delete;
143 config & operator=(config const &) = delete;
144 public:
145 config() { m_cfg = Z3_mk_config(); }
146 ~config() { Z3_del_config(m_cfg); }
147 operator Z3_config() const { return m_cfg; }
151 void set(char const * param, char const * value) { Z3_set_param_value(m_cfg, param, value); }
155 void set(char const * param, bool value) { Z3_set_param_value(m_cfg, param, value ? "true" : "false"); }
159 void set(char const * param, int value) {
160 auto str = std::to_string(value);
161 Z3_set_param_value(m_cfg, param, str.c_str());
162 }
163 };
164
168
176
178 if (l == Z3_L_TRUE) return sat;
179 else if (l == Z3_L_FALSE) return unsat;
180 return unknown;
181 }
182
183
184
190 class context {
191 private:
193 bool m_enable_exceptions = true;
194 rounding_mode m_rounding_mode;
195 Z3_context m_ctx = nullptr;
196 void init(config & c) {
197 set_context(Z3_mk_context_rc(c));
198 }
199 void set_context(Z3_context ctx) {
200 m_ctx = ctx;
201 m_enable_exceptions = true;
202 m_rounding_mode = RNE;
203 Z3_set_error_handler(m_ctx, 0);
205 }
206
207
208 context(context const &) = delete;
209 context & operator=(context const &) = delete;
210
211 context(Z3_context c) { set_context(c); }
212 void detach() { m_ctx = nullptr; }
213 public:
214 context() { config c; init(c); }
215 context(config & c) { init(c); }
216 ~context() { if (m_ctx) Z3_del_context(m_ctx); }
217 operator Z3_context() const { return m_ctx; }
218
224 if (e != Z3_OK && enable_exceptions())
226 return e;
227 }
228
229 void check_parser_error() const {
230 check_error();
231 }
232
240 void set_enable_exceptions(bool f) { m_enable_exceptions = f; }
241
242 bool enable_exceptions() const { return m_enable_exceptions; }
243
247 void set(char const * param, char const * value) { Z3_update_param_value(m_ctx, param, value); }
251 void set(char const * param, bool value) { Z3_update_param_value(m_ctx, param, value ? "true" : "false"); }
255 void set(char const * param, int value) {
256 auto str = std::to_string(value);
257 Z3_update_param_value(m_ctx, param, str.c_str());
258 }
259
264 void interrupt() { Z3_interrupt(m_ctx); }
265
269 symbol str_symbol(char const * s);
273 symbol int_symbol(int n);
277 sort bool_sort();
281 sort int_sort();
285 sort real_sort();
289 sort bv_sort(unsigned sz);
290
294 sort char_sort();
302 sort seq_sort(sort& s);
312 sort array_sort(sort d, sort r);
313 sort array_sort(sort_vector const& d, sort r);
320 sort fpa_sort(unsigned ebits, unsigned sbits);
324 template<size_t precision>
339 sort enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts);
340
347 func_decl tuple_sort(char const * name, unsigned n, char const * const * names, sort const* sorts, func_decl_vector & projs);
348
349
358 sort datatype(symbol const& name, constructors const& cs);
359
367 sort datatype(symbol const &name, sort_vector const &params, constructors const &cs);
368
375 sort_vector datatypes(unsigned n, symbol const* names,
376 constructor_list *const* cons);
377
378
383 sort datatype_sort(symbol const& name);
384
391 sort datatype_sort(symbol const& name, sort_vector const& params);
392
393
397 sort uninterpreted_sort(char const* name);
398 sort uninterpreted_sort(symbol const& name);
399
400 func_decl function(symbol const & name, unsigned arity, sort const * domain, sort const & range);
401 func_decl function(char const * name, unsigned arity, sort const * domain, sort const & range);
402 func_decl function(symbol const& name, sort_vector const& domain, sort const& range);
403 func_decl function(char const * name, sort_vector const& domain, sort const& range);
404 func_decl function(char const * name, sort const & domain, sort const & range);
405 func_decl function(char const * name, sort const & d1, sort const & d2, sort const & range);
406 func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & range);
407 func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & range);
408 func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & d5, sort const & range);
409
410 func_decl recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range);
411 func_decl recfun(symbol const & name, const sort_vector& domain, sort const & range);
412 func_decl recfun(char const * name, sort_vector const& domain, sort const & range);
413 func_decl recfun(char const * name, unsigned arity, sort const * domain, sort const & range);
414 func_decl recfun(char const * name, sort const & domain, sort const & range);
415 func_decl recfun(char const * name, sort const & d1, sort const & d2, sort const & range);
416
423 void recdef(func_decl decl, expr_vector const& args, expr const& body);
424 func_decl user_propagate_function(symbol const& name, sort_vector const& domain, sort const& range);
425
429 expr constant(symbol const & name, sort const & s);
430 expr constant(char const * name, sort const & s);
434 expr bool_const(char const * name);
435 expr int_const(char const * name);
436 expr real_const(char const * name);
437 expr string_const(char const * name);
438 expr bv_const(char const * name, unsigned sz);
439 expr fpa_const(char const * name, unsigned ebits, unsigned sbits);
440
441 template<size_t precision>
442 expr fpa_const(char const * name);
443
447 expr variable(unsigned index, sort const& s);
448
449
451
452 expr bool_val(bool b);
453
454 expr int_val(int n);
455 expr int_val(unsigned n);
456 expr int_val(int64_t n);
457 expr int_val(uint64_t n);
458 expr int_val(char const * n);
459
460 expr real_val(int n);
461 expr real_val(unsigned n);
462 expr real_val(int64_t n);
463 expr real_val(uint64_t n);
464 expr real_val(int64_t n, int64_t d);
465 expr real_val(char const * n);
466
467 expr bv_val(int n, unsigned sz);
468 expr bv_val(unsigned n, unsigned sz);
469 expr bv_val(int64_t n, unsigned sz);
470 expr bv_val(uint64_t n, unsigned sz);
471 expr bv_val(char const * n, unsigned sz);
472 expr bv_val(unsigned n, bool const* bits);
473
474 expr fpa_val(double n);
475 expr fpa_val(float n);
476 expr fpa_nan(sort const & s);
477 expr fpa_inf(sort const & s, bool sgn);
478
479 expr string_val(char const* s);
480 expr string_val(char const* s, unsigned n);
481 expr string_val(std::string const& s);
482 expr string_val(std::u32string const& s);
483
484 expr num_val(int n, sort const & s);
485
489 expr_vector parse_string(char const* s);
490 expr_vector parse_file(char const* file);
491
492 expr_vector parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
493 expr_vector parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
494 };
495
496
497 template<typename T>
498 class array {
499 std::unique_ptr<T[]> m_array;
500 unsigned m_size;
501 array(array const &) = delete;
502 array & operator=(array const &) = delete;
503 public:
504 array(unsigned sz):m_array(new T[sz]),m_size(sz) {}
505 template<typename T2>
506 array(ast_vector_tpl<T2> const & v);
507 void resize(unsigned sz) { m_array.reset(new T[sz]); m_size = sz; }
508 unsigned size() const { return m_size; }
509 T & operator[](int i) { assert(0 <= i); assert(static_cast<unsigned>(i) < m_size); return m_array[i]; }
510 T const & operator[](int i) const { assert(0 <= i); assert(static_cast<unsigned>(i) < m_size); return m_array[i]; }
511 T const * ptr() const { return m_array.get(); }
512 T * ptr() { return m_array.get(); }
513 };
514
515 class object {
516 protected:
518 public:
519 object(context & c):m_ctx(&c) {}
520 virtual ~object() = default;
521 context & ctx() const { return *m_ctx; }
523 friend void check_context(object const & a, object const & b);
524 };
525 inline void check_context(object const & a, object const & b) { (void)a; (void)b; assert(a.m_ctx == b.m_ctx); }
526
527 class symbol : public object {
528 Z3_symbol m_sym;
529 public:
530 symbol(context & c, Z3_symbol s):object(c), m_sym(s) {}
531 operator Z3_symbol() const { return m_sym; }
532 Z3_symbol_kind kind() const { return Z3_get_symbol_kind(ctx(), m_sym); }
533 std::string str() const { assert(kind() == Z3_STRING_SYMBOL); return Z3_get_symbol_string(ctx(), m_sym); }
534 int to_int() const { assert(kind() == Z3_INT_SYMBOL); return Z3_get_symbol_int(ctx(), m_sym); }
535 friend std::ostream & operator<<(std::ostream & out, symbol const & s);
536 };
537
538 inline std::ostream & operator<<(std::ostream & out, symbol const & s) {
539 if (s.kind() == Z3_INT_SYMBOL)
540 out << "k!" << s.to_int();
541 else
542 out << s.str();
543 return out;
544 }
545
546
547 class param_descrs : public object {
548 Z3_param_descrs m_descrs;
549 public:
550 param_descrs(context& c, Z3_param_descrs d): object(c), m_descrs(d) { Z3_param_descrs_inc_ref(c, d); }
551 param_descrs(param_descrs const& o): object(o.ctx()), m_descrs(o.m_descrs) { Z3_param_descrs_inc_ref(ctx(), m_descrs); }
553 Z3_param_descrs_inc_ref(o.ctx(), o.m_descrs);
554 Z3_param_descrs_dec_ref(ctx(), m_descrs);
555 m_descrs = o.m_descrs;
556 object::operator=(o);
557 return *this;
558 }
559 ~param_descrs() override { Z3_param_descrs_dec_ref(ctx(), m_descrs); }
562
563 unsigned size() { return Z3_param_descrs_size(ctx(), m_descrs); }
564 symbol name(unsigned i) { return symbol(ctx(), Z3_param_descrs_get_name(ctx(), m_descrs, i)); }
565 Z3_param_kind kind(symbol const& s) { return Z3_param_descrs_get_kind(ctx(), m_descrs, s); }
566 std::string documentation(symbol const& s) { char const* r = Z3_param_descrs_get_documentation(ctx(), m_descrs, s); check_error(); return r; }
567 std::string to_string() const { return Z3_param_descrs_to_string(ctx(), m_descrs); }
568 };
569
570 inline std::ostream& operator<<(std::ostream & out, param_descrs const & d) { return out << d.to_string(); }
571
572 class params : public object {
573 Z3_params m_params;
574 public:
575 params(context & c):object(c) { m_params = Z3_mk_params(c); Z3_params_inc_ref(ctx(), m_params); }
576 params(params const & s):object(s), m_params(s.m_params) { Z3_params_inc_ref(ctx(), m_params); }
577 ~params() override { Z3_params_dec_ref(ctx(), m_params); }
578 operator Z3_params() const { return m_params; }
579 params & operator=(params const & s) {
580 Z3_params_inc_ref(s.ctx(), s.m_params);
581 Z3_params_dec_ref(ctx(), m_params);
582 object::operator=(s);
583 m_params = s.m_params;
584 return *this;
585 }
586 void set(char const * k, bool b) { Z3_params_set_bool(ctx(), m_params, ctx().str_symbol(k), b); }
587 void set(char const * k, unsigned n) { Z3_params_set_uint(ctx(), m_params, ctx().str_symbol(k), n); }
588 void set(char const * k, double n) { Z3_params_set_double(ctx(), m_params, ctx().str_symbol(k), n); }
589 void set(char const * k, symbol const & s) { Z3_params_set_symbol(ctx(), m_params, ctx().str_symbol(k), s); }
590 void set(char const * k, char const* s) { Z3_params_set_symbol(ctx(), m_params, ctx().str_symbol(k), ctx().str_symbol(s)); }
591 friend std::ostream & operator<<(std::ostream & out, params const & p);
592 };
593
594 inline std::ostream & operator<<(std::ostream & out, params const & p) {
595 out << Z3_params_to_string(p.ctx(), p); return out;
596 }
597
598 class ast : public object {
599 protected:
600 Z3_ast m_ast;
601 public:
602 ast(context & c):object(c), m_ast(0) {}
603 ast(context & c, Z3_ast n):object(c), m_ast(n) { Z3_inc_ref(ctx(), m_ast); }
604 ast(ast const & s) :object(s), m_ast(s.m_ast) { Z3_inc_ref(ctx(), m_ast); }
605 ~ast() override { if (m_ast) { Z3_dec_ref(*m_ctx, m_ast); } }
606 operator Z3_ast() const { return m_ast; }
607 operator bool() const { return m_ast != 0; }
608 ast & operator=(ast const & s) {
609 Z3_inc_ref(s.ctx(), s.m_ast);
610 if (m_ast)
611 Z3_dec_ref(ctx(), m_ast);
612 object::operator=(s);
613 m_ast = s.m_ast;
614 return *this;
615 }
617 unsigned hash() const { unsigned r = Z3_get_ast_hash(ctx(), m_ast); check_error(); return r; }
618 friend std::ostream & operator<<(std::ostream & out, ast const & n);
619 std::string to_string() const { return std::string(Z3_ast_to_string(ctx(), m_ast)); }
620
621
625 friend bool eq(ast const & a, ast const & b);
626 };
627 inline std::ostream & operator<<(std::ostream & out, ast const & n) {
628 out << Z3_ast_to_string(n.ctx(), n.m_ast); return out;
629 }
630
631 inline bool eq(ast const & a, ast const & b) { return Z3_is_eq_ast(a.ctx(), a, b); }
632
633 template<typename T>
634 class ast_vector_tpl : public object {
635 Z3_ast_vector m_vector;
636 void init(Z3_ast_vector v) { Z3_ast_vector_inc_ref(ctx(), v); m_vector = v; }
637 public:
639 ast_vector_tpl(context & c, Z3_ast_vector v):object(c) { init(v); }
640 ast_vector_tpl(ast_vector_tpl const & s):object(s), m_vector(s.m_vector) { Z3_ast_vector_inc_ref(ctx(), m_vector); }
641 ast_vector_tpl(context& c, ast_vector_tpl const& src): object(c) { init(Z3_ast_vector_translate(src.ctx(), src, c)); }
642
643 ~ast_vector_tpl() override { Z3_ast_vector_dec_ref(ctx(), m_vector); }
644 operator Z3_ast_vector() const { return m_vector; }
645 unsigned size() const { return Z3_ast_vector_size(ctx(), m_vector); }
646 T operator[](unsigned i) const { Z3_ast r = Z3_ast_vector_get(ctx(), m_vector, i); check_error(); return cast_ast<T>()(ctx(), r); }
647 void push_back(T const & e) { Z3_ast_vector_push(ctx(), m_vector, e); check_error(); }
648 void resize(unsigned sz) { Z3_ast_vector_resize(ctx(), m_vector, sz); check_error(); }
649 T back() const { return operator[](size() - 1); }
650 void pop_back() { assert(size() > 0); resize(size() - 1); }
651 bool empty() const { return size() == 0; }
653 Z3_ast_vector_inc_ref(s.ctx(), s.m_vector);
654 Z3_ast_vector_dec_ref(ctx(), m_vector);
655 object::operator=(s);
656 m_vector = s.m_vector;
657 return *this;
658 }
659 ast_vector_tpl& set(unsigned idx, ast& a) {
660 Z3_ast_vector_set(ctx(), m_vector, idx, a);
661 return *this;
662 }
663 /*
664 Disabled pending C++98 build upgrade
665 bool contains(T const& x) const {
666 for (T y : *this) if (eq(x, y)) return true;
667 return false;
668 }
669 */
670
671 class iterator final {
672 ast_vector_tpl const* m_vector;
673 unsigned m_index;
674 public:
675 iterator(ast_vector_tpl const* v, unsigned i): m_vector(v), m_index(i) {}
676
677 bool operator==(iterator const& other) const noexcept {
678 return other.m_index == m_index;
679 };
680 bool operator!=(iterator const& other) const noexcept {
681 return other.m_index != m_index;
682 };
684 ++m_index;
685 return *this;
686 }
687 void set(T& arg) {
688 Z3_ast_vector_set(m_vector->ctx(), *m_vector, m_index, arg);
689 }
690 iterator operator++(int) noexcept { iterator tmp = *this; ++m_index; return tmp; }
691 T * operator->() const { return &(operator*()); }
692 T operator*() const { return (*m_vector)[m_index]; }
693 };
694 iterator begin() const noexcept { return iterator(this, 0); }
695 iterator end() const { return iterator(this, size()); }
696 friend std::ostream & operator<<(std::ostream & out, ast_vector_tpl const & v) { out << Z3_ast_vector_to_string(v.ctx(), v); return out; }
697 std::string to_string() const { return std::string(Z3_ast_vector_to_string(ctx(), m_vector)); }
698 };
699
700
704 class sort : public ast {
705 public:
706 sort(context & c):ast(c) {}
707 sort(context & c, Z3_sort s):ast(c, reinterpret_cast<Z3_ast>(s)) {}
708 sort(context & c, Z3_ast a):ast(c, a) {}
709 operator Z3_sort() const { return reinterpret_cast<Z3_sort>(m_ast); }
710
714 unsigned id() const { unsigned r = Z3_get_sort_id(ctx(), *this); check_error(); return r; }
715
719 Z3_sort_kind sort_kind() const { return Z3_get_sort_kind(*m_ctx, *this); }
723 symbol name() const { Z3_symbol s = Z3_get_sort_name(ctx(), *this); check_error(); return symbol(ctx(), s); }
727 bool is_bool() const { return sort_kind() == Z3_BOOL_SORT; }
731 bool is_int() const { return sort_kind() == Z3_INT_SORT; }
735 bool is_real() const { return sort_kind() == Z3_REAL_SORT; }
739 bool is_arith() const { return is_int() || is_real(); }
743 bool is_bv() const { return sort_kind() == Z3_BV_SORT; }
747 bool is_array() const { return sort_kind() == Z3_ARRAY_SORT; }
751 bool is_datatype() const { return sort_kind() == Z3_DATATYPE_SORT; }
755 bool is_relation() const { return sort_kind() == Z3_RELATION_SORT; }
759 bool is_seq() const { return sort_kind() == Z3_SEQ_SORT; }
763 bool is_re() const { return sort_kind() == Z3_RE_SORT; }
771 bool is_fpa() const { return sort_kind() == Z3_FLOATING_POINT_SORT; }
772
778 unsigned bv_size() const { assert(is_bv()); unsigned r = Z3_get_bv_sort_size(ctx(), *this); check_error(); return r; }
779
780 unsigned fpa_ebits() const { assert(is_fpa()); unsigned r = Z3_fpa_get_ebits(ctx(), *this); check_error(); return r; }
781
782 unsigned fpa_sbits() const { assert(is_fpa()); unsigned r = Z3_fpa_get_sbits(ctx(), *this); check_error(); return r; }
788 sort array_domain() const { assert(is_array()); Z3_sort s = Z3_get_array_sort_domain(ctx(), *this); check_error(); return sort(ctx(), s); }
794 sort array_range() const { assert(is_array()); Z3_sort s = Z3_get_array_sort_range(ctx(), *this); check_error(); return sort(ctx(), s); }
795
796 friend std::ostream & operator<<(std::ostream & out, sort const & s) { return out << Z3_sort_to_string(s.ctx(), Z3_sort(s.m_ast)); }
797
800 };
801
802
807 class func_decl : public ast {
808 public:
810 func_decl(context & c, Z3_func_decl n):ast(c, reinterpret_cast<Z3_ast>(n)) {}
811 operator Z3_func_decl() const { return reinterpret_cast<Z3_func_decl>(m_ast); }
812
816 unsigned id() const { unsigned r = Z3_get_func_decl_id(ctx(), *this); check_error(); return r; }
817
818 unsigned arity() const { return Z3_get_arity(ctx(), *this); }
819 sort domain(unsigned i) const { assert(i < arity()); Z3_sort r = Z3_get_domain(ctx(), *this, i); check_error(); return sort(ctx(), r); }
820 sort range() const { Z3_sort r = Z3_get_range(ctx(), *this); check_error(); return sort(ctx(), r); }
821 symbol name() const { Z3_symbol s = Z3_get_decl_name(ctx(), *this); check_error(); return symbol(ctx(), s); }
822 Z3_decl_kind decl_kind() const { return Z3_get_decl_kind(ctx(), *this); }
823 unsigned num_parameters() const { return Z3_get_decl_num_parameters(ctx(), *this); }
824
825
827 Z3_func_decl tc = Z3_mk_transitive_closure(ctx(), *this); check_error(); return func_decl(ctx(), tc);
828 }
829
830 bool is_const() const { return arity() == 0; }
831
832 expr operator()() const;
833 expr operator()(unsigned n, expr const * args) const;
834 expr operator()(expr_vector const& v) const;
835 expr operator()(expr const & a) const;
836 expr operator()(int a) const;
837 expr operator()(expr const & a1, expr const & a2) const;
838 expr operator()(expr const & a1, int a2) const;
839 expr operator()(int a1, expr const & a2) const;
840 expr operator()(expr const & a1, expr const & a2, expr const & a3) const;
841 expr operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4) const;
842 expr operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4, expr const & a5) const;
843
845
846 };
847
851 expr select(expr const & a, expr const& i);
852 expr select(expr const & a, expr_vector const & i);
853
858 class expr : public ast {
859 public:
860 expr(context & c):ast(c) {}
861 expr(context & c, Z3_ast n):ast(c, reinterpret_cast<Z3_ast>(n)) {}
862
866 sort get_sort() const { Z3_sort s = Z3_get_sort(*m_ctx, m_ast); check_error(); return sort(*m_ctx, s); }
867
871 bool is_bool() const { return get_sort().is_bool(); }
875 bool is_int() const { return get_sort().is_int(); }
879 bool is_real() const { return get_sort().is_real(); }
883 bool is_arith() const { return get_sort().is_arith(); }
887 bool is_bv() const { return get_sort().is_bv(); }
891 bool is_array() const { return get_sort().is_array(); }
895 bool is_datatype() const { return get_sort().is_datatype(); }
899 bool is_relation() const { return get_sort().is_relation(); }
903 bool is_seq() const { return get_sort().is_seq(); }
907 bool is_re() const { return get_sort().is_re(); }
908
917 bool is_finite_domain() const { return get_sort().is_finite_domain(); }
921 bool is_fpa() const { return get_sort().is_fpa(); }
922
928 bool is_numeral() const { return kind() == Z3_NUMERAL_AST; }
929 bool is_numeral_i64(int64_t& i) const { bool r = Z3_get_numeral_int64(ctx(), m_ast, &i); check_error(); return r;}
930 bool is_numeral_u64(uint64_t& i) const { bool r = Z3_get_numeral_uint64(ctx(), m_ast, &i); check_error(); return r;}
931 bool is_numeral_i(int& i) const { bool r = Z3_get_numeral_int(ctx(), m_ast, &i); check_error(); return r;}
932 bool is_numeral_u(unsigned& i) const { bool r = Z3_get_numeral_uint(ctx(), m_ast, &i); check_error(); return r;}
933 bool is_numeral(std::string& s) const { if (!is_numeral()) return false; s = Z3_get_numeral_string(ctx(), m_ast); check_error(); return true; }
934 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; }
935 bool is_numeral(double& d) const { if (!is_numeral()) return false; d = Z3_get_numeral_double(ctx(), m_ast); check_error(); return true; }
936 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; }
937
938 double as_double() const { double d = 0; is_numeral(d); return d; }
939 uint64_t as_uint64() const { uint64_t r = 0; is_numeral_u64(r); return r; }
940 int64_t as_int64() const { int64_t r = 0; is_numeral_i64(r); return r; }
941
942
946 bool is_app() const { return kind() == Z3_APP_AST || kind() == Z3_NUMERAL_AST; }
950 bool is_const() const { return is_app() && num_args() == 0; }
954 bool is_quantifier() const { return kind() == Z3_QUANTIFIER_AST; }
955
959 bool is_forall() const { return Z3_is_quantifier_forall(ctx(), m_ast); }
963 bool is_exists() const { return Z3_is_quantifier_exists(ctx(), m_ast); }
967 bool is_lambda() const { return Z3_is_lambda(ctx(), m_ast); }
972 bool is_var() const { return kind() == Z3_VAR_AST; }
976 bool is_algebraic() const { return Z3_is_algebraic_number(ctx(), m_ast); }
977
981 bool is_well_sorted() const { bool r = Z3_is_well_sorted(ctx(), m_ast); check_error(); return r; }
982
986 expr mk_is_inf() const {
987 assert(is_fpa());
988 Z3_ast r = Z3_mk_fpa_is_infinite(ctx(), m_ast);
989 check_error();
990 return expr(ctx(), r);
991 }
992
996 expr mk_is_nan() const {
997 assert(is_fpa());
998 Z3_ast r = Z3_mk_fpa_is_nan(ctx(), m_ast);
999 check_error();
1000 return expr(ctx(), r);
1001 }
1002
1007 assert(is_fpa());
1008 Z3_ast r = Z3_mk_fpa_is_normal(ctx(), m_ast);
1009 check_error();
1010 return expr(ctx(), r);
1011 }
1012
1017 assert(is_fpa());
1018 Z3_ast r = Z3_mk_fpa_is_subnormal(ctx(), m_ast);
1019 check_error();
1020 return expr(ctx(), r);
1021 }
1022
1027 assert(is_fpa());
1028 Z3_ast r = Z3_mk_fpa_is_zero(ctx(), m_ast);
1029 check_error();
1030 return expr(ctx(), r);
1031 }
1032
1037 assert(is_fpa());
1038 Z3_ast r = Z3_mk_fpa_to_ieee_bv(ctx(), m_ast);
1039 check_error();
1040 return expr(ctx(), r);
1041 }
1042
1046 expr mk_from_ieee_bv(sort const &s) const {
1047 assert(is_bv());
1048 Z3_ast r = Z3_mk_fpa_to_fp_bv(ctx(), m_ast, s);
1049 check_error();
1050 return expr(ctx(), r);
1051 }
1052
1059 std::string get_decimal_string(int precision) const {
1061 return std::string(Z3_get_numeral_decimal_string(ctx(), m_ast, precision));
1062 }
1063
1067 expr algebraic_lower(unsigned precision) const {
1068 assert(is_algebraic());
1069 Z3_ast r = Z3_get_algebraic_number_lower(ctx(), m_ast, precision);
1070 check_error();
1071 return expr(ctx(), r);
1072 }
1073
1074 expr algebraic_upper(unsigned precision) const {
1075 assert(is_algebraic());
1076 Z3_ast r = Z3_get_algebraic_number_upper(ctx(), m_ast, precision);
1077 check_error();
1078 return expr(ctx(), r);
1079 }
1080
1086 Z3_ast_vector r = Z3_algebraic_get_poly(ctx(), m_ast);
1087 check_error();
1088 return expr_vector(ctx(), r);
1089 }
1090
1094 unsigned algebraic_i() const {
1096 unsigned i = Z3_algebraic_get_i(ctx(), m_ast);
1097 check_error();
1098 return i;
1099 }
1100
1104 unsigned id() const { unsigned r = Z3_get_ast_id(ctx(), m_ast); check_error(); return r; }
1105
1116 int get_numeral_int() const {
1117 int result = 0;
1118 if (!is_numeral_i(result)) {
1119 assert(ctx().enable_exceptions());
1120 if (!ctx().enable_exceptions()) return 0;
1121 Z3_THROW(exception("numeral does not fit in machine int"));
1122 }
1123 return result;
1124 }
1125
1135 unsigned get_numeral_uint() const {
1136 assert(is_numeral());
1137 unsigned result = 0;
1138 if (!is_numeral_u(result)) {
1139 assert(ctx().enable_exceptions());
1140 if (!ctx().enable_exceptions()) return 0;
1141 Z3_THROW(exception("numeral does not fit in machine uint"));
1142 }
1143 return result;
1144 }
1145
1153 assert(is_numeral());
1154 int64_t result = 0;
1155 if (!is_numeral_i64(result)) {
1156 assert(ctx().enable_exceptions());
1157 if (!ctx().enable_exceptions()) return 0;
1158 Z3_THROW(exception("numeral does not fit in machine int64_t"));
1159 }
1160 return result;
1161 }
1162
1170 assert(is_numeral());
1171 uint64_t result = 0;
1172 if (!is_numeral_u64(result)) {
1173 assert(ctx().enable_exceptions());
1174 if (!ctx().enable_exceptions()) return 0;
1175 Z3_THROW(exception("numeral does not fit in machine uint64_t"));
1176 }
1177 return result;
1178 }
1179
1181 return Z3_get_bool_value(ctx(), m_ast);
1182 }
1183
1184 expr numerator() const {
1185 assert(is_numeral());
1186 Z3_ast r = Z3_get_numerator(ctx(), m_ast);
1187 check_error();
1188 return expr(ctx(),r);
1189 }
1190
1191
1193 assert(is_numeral());
1194 Z3_ast r = Z3_get_denominator(ctx(), m_ast);
1195 check_error();
1196 return expr(ctx(),r);
1197 }
1198
1199
1204 bool is_string_value() const { return Z3_is_string(ctx(), m_ast); }
1205
1211 std::string get_string() const {
1213 char const* s = Z3_get_string(ctx(), m_ast);
1214 check_error();
1215 return std::string(s);
1216 }
1217
1223 std::u32string get_u32string() const {
1225 unsigned n = Z3_get_string_length(ctx(), m_ast);
1226 std::u32string s;
1227 s.resize(n);
1228 Z3_get_string_contents(ctx(), m_ast, n, (unsigned*)s.data());
1229 return s;
1230 }
1231
1232 operator Z3_app() const { assert(is_app()); return reinterpret_cast<Z3_app>(m_ast); }
1233
1240 func_decl decl() const { Z3_func_decl f = Z3_get_app_decl(ctx(), *this); check_error(); return func_decl(ctx(), f); }
1247 unsigned num_args() const { unsigned r = Z3_get_app_num_args(ctx(), *this); check_error(); return r; }
1255 expr arg(unsigned i) const { Z3_ast r = Z3_get_app_arg(ctx(), *this, i); check_error(); return expr(ctx(), r); }
1263 expr_vector vec(ctx());
1264 unsigned argCnt = num_args();
1265 for (unsigned i = 0; i < argCnt; i++)
1266 vec.push_back(arg(i));
1267 return vec;
1268 }
1269
1278 expr update(expr_vector const& args) const;
1279
1285 expr body() const { assert(is_quantifier()); Z3_ast r = Z3_get_quantifier_body(ctx(), *this); check_error(); return expr(ctx(), r); }
1286
1292 friend expr operator!(expr const & a);
1293
1300 friend expr operator&&(expr const & a, expr const & b);
1301
1302
1309 friend expr operator&&(expr const & a, bool b);
1316 friend expr operator&&(bool a, expr const & b);
1317
1324 friend expr operator||(expr const & a, expr const & b);
1331 friend expr operator||(expr const & a, bool b);
1332
1339 friend expr operator||(bool a, expr const & b);
1340
1341 friend expr implies(expr const & a, expr const & b);
1342 friend expr implies(expr const & a, bool b);
1343 friend expr implies(bool a, expr const & b);
1344
1345 friend expr mk_or(expr_vector const& args);
1346 friend expr mk_xor(expr_vector const& args);
1347 friend expr mk_and(expr_vector const& args);
1348
1349 friend expr ite(expr const & c, expr const & t, expr const & e);
1350
1351 bool is_true() const { return is_app() && Z3_OP_TRUE == decl().decl_kind(); }
1352 bool is_false() const { return is_app() && Z3_OP_FALSE == decl().decl_kind(); }
1353 bool is_not() const { return is_app() && Z3_OP_NOT == decl().decl_kind(); }
1354 bool is_and() const { return is_app() && Z3_OP_AND == decl().decl_kind(); }
1355 bool is_or() const { return is_app() && Z3_OP_OR == decl().decl_kind(); }
1356 bool is_xor() const { return is_app() && Z3_OP_XOR == decl().decl_kind(); }
1357 bool is_implies() const { return is_app() && Z3_OP_IMPLIES == decl().decl_kind(); }
1358 bool is_eq() const { return is_app() && Z3_OP_EQ == decl().decl_kind(); }
1359 bool is_ite() const { return is_app() && Z3_OP_ITE == decl().decl_kind(); }
1360 bool is_distinct() const { return is_app() && Z3_OP_DISTINCT == decl().decl_kind(); }
1361
1362 friend expr distinct(expr_vector const& args);
1363 friend expr concat(expr const& a, expr const& b);
1364 friend expr concat(expr_vector const& args);
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 operator!=(expr const & a, expr const & b);
1371 friend expr operator!=(expr const & a, int b);
1372 friend expr operator!=(int a, expr const & b);
1373
1374 friend expr operator+(expr const & a, expr const & b);
1375 friend expr operator+(expr const & a, int b);
1376 friend expr operator+(int a, expr const & b);
1377 friend expr sum(expr_vector const& args);
1378
1379 friend expr operator*(expr const & a, expr const & b);
1380 friend expr operator*(expr const & a, int b);
1381 friend expr operator*(int a, expr const & b);
1382
1383 /* \brief Power operator */
1384 friend expr pw(expr const & a, expr const & b);
1385 friend expr pw(expr const & a, int b);
1386 friend expr pw(int a, expr const & b);
1387
1388 /* \brief mod operator */
1389 friend expr mod(expr const& a, expr const& b);
1390 friend expr mod(expr const& a, int b);
1391 friend expr mod(int a, expr const& b);
1392
1393 /* \brief rem operator */
1394 friend expr rem(expr const& a, expr const& b);
1395 friend expr rem(expr const& a, int b);
1396 friend expr rem(int a, expr const& b);
1397
1398 friend expr is_int(expr const& e);
1399
1400 friend expr operator/(expr const & a, expr const & b);
1401 friend expr operator/(expr const & a, int b);
1402 friend expr operator/(int a, expr const & b);
1403
1404 friend expr operator-(expr const & a);
1405
1406 friend expr operator-(expr const & a, expr const & b);
1407 friend expr operator-(expr const & a, int b);
1408 friend expr operator-(int a, expr const & b);
1409
1410 friend expr operator<=(expr const & a, expr const & b);
1411 friend expr operator<=(expr const & a, int b);
1412 friend expr operator<=(int a, expr const & b);
1413
1414
1415 friend expr operator>=(expr const & a, expr const & b);
1416 friend expr operator>=(expr const & a, int b);
1417 friend expr operator>=(int a, expr const & b);
1418
1419 friend expr operator<(expr const & a, expr const & b);
1420 friend expr operator<(expr const & a, int b);
1421 friend expr operator<(int a, expr const & b);
1422
1423 friend expr operator>(expr const & a, expr const & b);
1424 friend expr operator>(expr const & a, int b);
1425 friend expr operator>(int a, expr const & b);
1426
1427 friend expr pble(expr_vector const& es, int const * coeffs, int bound);
1428 friend expr pbge(expr_vector const& es, int const * coeffs, int bound);
1429 friend expr pbeq(expr_vector const& es, int const * coeffs, int bound);
1430 friend expr atmost(expr_vector const& es, unsigned bound);
1431 friend expr atleast(expr_vector const& es, unsigned bound);
1432
1433 friend expr operator&(expr const & a, expr const & b);
1434 friend expr operator&(expr const & a, int b);
1435 friend expr operator&(int a, expr const & b);
1436
1437 friend expr operator^(expr const & a, expr const & b);
1438 friend expr operator^(expr const & a, int b);
1439 friend expr operator^(int a, expr const & b);
1440
1441 friend expr operator|(expr const & a, expr const & b);
1442 friend expr operator|(expr const & a, int b);
1443 friend expr operator|(int a, expr const & b);
1444 friend expr nand(expr const& a, expr const& b);
1445 friend expr nor(expr const& a, expr const& b);
1446 friend expr xnor(expr const& a, expr const& b);
1447
1448 friend expr min(expr const& a, expr const& b);
1449 friend expr max(expr const& a, expr const& b);
1450
1451 friend expr bv2int(expr const& a, bool is_signed);
1452 friend expr int2bv(unsigned n, expr const& a);
1453 friend expr bvadd_no_overflow(expr const& a, expr const& b, bool is_signed);
1454 friend expr bvadd_no_underflow(expr const& a, expr const& b);
1455 friend expr bvsub_no_overflow(expr const& a, expr const& b);
1456 friend expr bvsub_no_underflow(expr const& a, expr const& b, bool is_signed);
1457 friend expr bvsdiv_no_overflow(expr const& a, expr const& b);
1458 friend expr bvneg_no_overflow(expr const& a);
1459 friend expr bvmul_no_overflow(expr const& a, expr const& b, bool is_signed);
1460 friend expr bvmul_no_underflow(expr const& a, expr const& b);
1461
1462 expr rotate_left(unsigned i) const { Z3_ast r = Z3_mk_rotate_left(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
1463 expr rotate_right(unsigned i) const { Z3_ast r = Z3_mk_rotate_right(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
1464 expr repeat(unsigned i) const { Z3_ast r = Z3_mk_repeat(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
1465
1466 friend expr bvredor(expr const & a);
1467 friend expr bvredand(expr const & a);
1468
1469 friend expr abs(expr const & a);
1470 friend expr sqrt(expr const & a, expr const & rm);
1471 friend expr fp_eq(expr const & a, expr const & b);
1472
1473 friend expr operator~(expr const & a);
1474 expr extract(unsigned hi, unsigned lo) const { Z3_ast r = Z3_mk_extract(ctx(), hi, lo, *this); ctx().check_error(); return expr(ctx(), r); }
1475 expr bit2bool(unsigned i) const { Z3_ast r = Z3_mk_bit2bool(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
1476 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)); }
1477 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)); }
1478
1482 friend expr fma(expr const& a, expr const& b, expr const& c, expr const& rm);
1483
1487 friend expr fpa_fp(expr const& sgn, expr const& exp, expr const& sig);
1488
1492 friend expr fpa_to_sbv(expr const& t, unsigned sz);
1493
1497 friend expr fpa_to_ubv(expr const& t, unsigned sz);
1498
1502 friend expr sbv_to_fpa(expr const& t, sort s);
1503
1507 friend expr ubv_to_fpa(expr const& t, sort s);
1508
1512 friend expr fpa_to_fpa(expr const& t, sort s);
1513
1517 friend expr round_fpa_to_closest_integer(expr const& t);
1518
1524 expr extract(expr const& offset, expr const& length) const {
1526 Z3_ast r = Z3_mk_seq_extract(ctx(), *this, offset, length); check_error(); return expr(ctx(), r);
1527 }
1528 expr replace(expr const& src, expr const& dst) const {
1530 Z3_ast r = Z3_mk_seq_replace(ctx(), *this, src, dst);
1531 check_error();
1532 return expr(ctx(), r);
1533 }
1534 expr unit() const {
1535 Z3_ast r = Z3_mk_seq_unit(ctx(), *this);
1536 check_error();
1537 return expr(ctx(), r);
1538 }
1539 expr contains(expr const& s) const {
1540 check_context(*this, s);
1541 Z3_ast r = Z3_mk_seq_contains(ctx(), *this, s);
1542 check_error();
1543 return expr(ctx(), r);
1544 }
1545 expr at(expr const& index) const {
1546 check_context(*this, index);
1547 Z3_ast r = Z3_mk_seq_at(ctx(), *this, index);
1548 check_error();
1549 return expr(ctx(), r);
1550 }
1551 expr nth(expr const& index) const {
1552 check_context(*this, index);
1553 Z3_ast r = Z3_mk_seq_nth(ctx(), *this, index);
1554 check_error();
1555 return expr(ctx(), r);
1556 }
1557 expr length() const {
1558 Z3_ast r = Z3_mk_seq_length(ctx(), *this);
1559 check_error();
1560 return expr(ctx(), r);
1561 }
1562 expr stoi() const {
1563 Z3_ast r = Z3_mk_str_to_int(ctx(), *this);
1564 check_error();
1565 return expr(ctx(), r);
1566 }
1567 expr itos() const {
1568 Z3_ast r = Z3_mk_int_to_str(ctx(), *this);
1569 check_error();
1570 return expr(ctx(), r);
1571 }
1572 expr ubvtos() const {
1573 Z3_ast r = Z3_mk_ubv_to_str(ctx(), *this);
1574 check_error();
1575 return expr(ctx(), r);
1576 }
1577 expr sbvtos() const {
1578 Z3_ast r = Z3_mk_sbv_to_str(ctx(), *this);
1579 check_error();
1580 return expr(ctx(), r);
1581 }
1583 Z3_ast r = Z3_mk_char_to_int(ctx(), *this);
1584 check_error();
1585 return expr(ctx(), r);
1586 }
1588 Z3_ast r = Z3_mk_char_to_bv(ctx(), *this);
1589 check_error();
1590 return expr(ctx(), r);
1591 }
1593 Z3_ast r = Z3_mk_char_from_bv(ctx(), *this);
1594 check_error();
1595 return expr(ctx(), r);
1596 }
1597 expr is_digit() const {
1598 Z3_ast r = Z3_mk_char_is_digit(ctx(), *this);
1599 check_error();
1600 return expr(ctx(), r);
1601 }
1602
1603 friend expr range(expr const& lo, expr const& hi);
1607 expr loop(unsigned lo) {
1608 Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, 0);
1609 check_error();
1610 return expr(ctx(), r);
1611 }
1612 expr loop(unsigned lo, unsigned hi) {
1613 Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, hi);
1614 check_error();
1615 return expr(ctx(), r);
1616 }
1617
1621 expr operator[](expr const& index) const {
1622 assert(is_array() || is_seq());
1623 if (is_array()) {
1624 return select(*this, index);
1625 }
1626 return nth(index);
1627 }
1628
1629 expr operator[](expr_vector const& index) const {
1630 return select(*this, index);
1631 }
1632
1636 expr simplify() const { Z3_ast r = Z3_simplify(ctx(), m_ast); check_error(); return expr(ctx(), r); }
1640 expr simplify(params const & p) const { Z3_ast r = Z3_simplify_ex(ctx(), m_ast, p); check_error(); return expr(ctx(), r); }
1641
1645 expr substitute(expr_vector const& src, expr_vector const& dst);
1646
1651
1656
1657
1658 class iterator {
1659 expr& e;
1660 unsigned i;
1661 public:
1662 iterator(expr& e, unsigned i): e(e), i(i) {}
1663 bool operator==(iterator const& other) const noexcept {
1664 return i == other.i;
1665 }
1666 bool operator!=(iterator const& other) const noexcept {
1667 return i != other.i;
1668 }
1669 expr operator*() const { return e.arg(i); }
1670 iterator& operator++() { ++i; return *this; }
1671 iterator operator++(int) { assert(false); return *this; }
1672 };
1673
1674 iterator begin() { return iterator(*this, 0); }
1675 iterator end() { return iterator(*this, is_app() ? num_args() : 0); }
1676
1677 };
1678
1679#define _Z3_MK_BIN_(a, b, binop) \
1680 check_context(a, b); \
1681 Z3_ast r = binop(a.ctx(), a, b); \
1682 a.check_error(); \
1683 return expr(a.ctx(), r); \
1684
1685
1686 inline expr implies(expr const & a, expr const & b) {
1687 assert(a.is_bool() && b.is_bool());
1689 }
1690 inline expr implies(expr const & a, bool b) { return implies(a, a.ctx().bool_val(b)); }
1691 inline expr implies(bool a, expr const & b) { return implies(b.ctx().bool_val(a), b); }
1692
1693
1694 inline expr pw(expr const & a, expr const & b) { _Z3_MK_BIN_(a, b, Z3_mk_power); }
1695 inline expr pw(expr const & a, int b) { return pw(a, a.ctx().num_val(b, a.get_sort())); }
1696 inline expr pw(int a, expr const & b) { return pw(b.ctx().num_val(a, b.get_sort()), b); }
1697
1698 inline expr mod(expr const& a, expr const& b) {
1699 if (a.is_bv()) {
1701 }
1702 else {
1704 }
1705 }
1706 inline expr mod(expr const & a, int b) { return mod(a, a.ctx().num_val(b, a.get_sort())); }
1707 inline expr mod(int a, expr const & b) { return mod(b.ctx().num_val(a, b.get_sort()), b); }
1708
1709 inline expr operator%(expr const& a, expr const& b) { return mod(a, b); }
1710 inline expr operator%(expr const& a, int b) { return mod(a, b); }
1711 inline expr operator%(int a, expr const& b) { return mod(a, b); }
1712
1713
1714 inline expr rem(expr const& a, expr const& b) {
1715 if (a.is_fpa() && b.is_fpa()) {
1717 } else {
1719 }
1720 }
1721 inline expr rem(expr const & a, int b) { return rem(a, a.ctx().num_val(b, a.get_sort())); }
1722 inline expr rem(int a, expr const & b) { return rem(b.ctx().num_val(a, b.get_sort()), b); }
1723
1724#undef _Z3_MK_BIN_
1725
1726#define _Z3_MK_UN_(a, mkun) \
1727 Z3_ast r = mkun(a.ctx(), a); \
1728 a.check_error(); \
1729 return expr(a.ctx(), r); \
1730
1731
1732 inline expr operator!(expr const & a) { assert(a.is_bool()); _Z3_MK_UN_(a, Z3_mk_not); }
1733
1734 inline expr is_int(expr const& e) { _Z3_MK_UN_(e, Z3_mk_is_int); }
1735
1736#undef _Z3_MK_UN_
1737
1738 inline expr operator&&(expr const & a, expr const & b) {
1739 check_context(a, b);
1740 assert(a.is_bool() && b.is_bool());
1741 Z3_ast args[2] = { a, b };
1742 Z3_ast r = Z3_mk_and(a.ctx(), 2, args);
1743 a.check_error();
1744 return expr(a.ctx(), r);
1745 }
1746
1747 inline expr operator&&(expr const & a, bool b) { return a && a.ctx().bool_val(b); }
1748 inline expr operator&&(bool a, expr const & b) { return b.ctx().bool_val(a) && b; }
1749
1750 inline expr operator||(expr const & a, expr const & b) {
1751 check_context(a, b);
1752 assert(a.is_bool() && b.is_bool());
1753 Z3_ast args[2] = { a, b };
1754 Z3_ast r = Z3_mk_or(a.ctx(), 2, args);
1755 a.check_error();
1756 return expr(a.ctx(), r);
1757 }
1758
1759 inline expr operator||(expr const & a, bool b) { return a || a.ctx().bool_val(b); }
1760
1761 inline expr operator||(bool a, expr const & b) { return b.ctx().bool_val(a) || b; }
1762
1763 inline expr operator==(expr const & a, expr const & b) {
1764 check_context(a, b);
1765 Z3_ast r = Z3_mk_eq(a.ctx(), a, b);
1766 a.check_error();
1767 return expr(a.ctx(), r);
1768 }
1769 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()); }
1770 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; }
1771 inline expr operator==(expr const & a, double b) { assert(a.is_fpa()); return a == a.ctx().fpa_val(b); }
1772 inline expr operator==(double a, expr const & b) { assert(b.is_fpa()); return b.ctx().fpa_val(a) == b; }
1773
1774 inline expr operator!=(expr const & a, expr const & b) {
1775 check_context(a, b);
1776 Z3_ast args[2] = { a, b };
1777 Z3_ast r = Z3_mk_distinct(a.ctx(), 2, args);
1778 a.check_error();
1779 return expr(a.ctx(), r);
1780 }
1781 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()); }
1782 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; }
1783 inline expr operator!=(expr const & a, double b) { assert(a.is_fpa()); return a != a.ctx().fpa_val(b); }
1784 inline expr operator!=(double a, expr const & b) { assert(b.is_fpa()); return b.ctx().fpa_val(a) != b; }
1785
1786 inline expr operator+(expr const & a, expr const & b) {
1787 check_context(a, b);
1788 Z3_ast r = 0;
1789 if (a.is_arith() && b.is_arith()) {
1790 Z3_ast args[2] = { a, b };
1791 r = Z3_mk_add(a.ctx(), 2, args);
1792 }
1793 else if (a.is_bv() && b.is_bv()) {
1794 r = Z3_mk_bvadd(a.ctx(), a, b);
1795 }
1796 else if (a.is_seq() && b.is_seq()) {
1797 return concat(a, b);
1798 }
1799 else if (a.is_re() && b.is_re()) {
1800 Z3_ast _args[2] = { a, b };
1801 r = Z3_mk_re_union(a.ctx(), 2, _args);
1802 }
1803 else if (a.is_fpa() && b.is_fpa()) {
1804 r = Z3_mk_fpa_add(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1805 }
1806 else {
1807 // operator is not supported by given arguments.
1808 assert(false);
1809 }
1810 a.check_error();
1811 return expr(a.ctx(), r);
1812 }
1813 inline expr operator+(expr const & a, int b) { return a + a.ctx().num_val(b, a.get_sort()); }
1814 inline expr operator+(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) + b; }
1815
1816 inline expr operator*(expr const & a, expr const & b) {
1817 check_context(a, b);
1818 Z3_ast r = 0;
1819 if (a.is_arith() && b.is_arith()) {
1820 Z3_ast args[2] = { a, b };
1821 r = Z3_mk_mul(a.ctx(), 2, args);
1822 }
1823 else if (a.is_bv() && b.is_bv()) {
1824 r = Z3_mk_bvmul(a.ctx(), a, b);
1825 }
1826 else if (a.is_fpa() && b.is_fpa()) {
1827 r = Z3_mk_fpa_mul(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1828 }
1829 else {
1830 // operator is not supported by given arguments.
1831 assert(false);
1832 }
1833 a.check_error();
1834 return expr(a.ctx(), r);
1835 }
1836 inline expr operator*(expr const & a, int b) { return a * a.ctx().num_val(b, a.get_sort()); }
1837 inline expr operator*(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) * b; }
1838
1839
1840 inline expr operator>=(expr const & a, expr const & b) {
1841 check_context(a, b);
1842 Z3_ast r = 0;
1843 if (a.is_arith() && b.is_arith()) {
1844 r = Z3_mk_ge(a.ctx(), a, b);
1845 }
1846 else if (a.is_bv() && b.is_bv()) {
1847 r = Z3_mk_bvsge(a.ctx(), a, b);
1848 }
1849 else if (a.is_fpa() && b.is_fpa()) {
1850 r = Z3_mk_fpa_geq(a.ctx(), a, b);
1851 }
1852 else {
1853 // operator is not supported by given arguments.
1854 assert(false);
1855 }
1856 a.check_error();
1857 return expr(a.ctx(), r);
1858 }
1859
1860 inline expr operator/(expr const & a, expr const & b) {
1861 check_context(a, b);
1862 Z3_ast r = 0;
1863 if (a.is_arith() && b.is_arith()) {
1864 r = Z3_mk_div(a.ctx(), a, b);
1865 }
1866 else if (a.is_bv() && b.is_bv()) {
1867 r = Z3_mk_bvsdiv(a.ctx(), a, b);
1868 }
1869 else if (a.is_fpa() && b.is_fpa()) {
1870 r = Z3_mk_fpa_div(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1871 }
1872 else {
1873 // operator is not supported by given arguments.
1874 assert(false);
1875 }
1876 a.check_error();
1877 return expr(a.ctx(), r);
1878 }
1879 inline expr operator/(expr const & a, int b) { return a / a.ctx().num_val(b, a.get_sort()); }
1880 inline expr operator/(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) / b; }
1881
1882 inline expr operator-(expr const & a) {
1883 Z3_ast r = 0;
1884 if (a.is_arith()) {
1885 r = Z3_mk_unary_minus(a.ctx(), a);
1886 }
1887 else if (a.is_bv()) {
1888 r = Z3_mk_bvneg(a.ctx(), a);
1889 }
1890 else if (a.is_fpa()) {
1891 r = Z3_mk_fpa_neg(a.ctx(), a);
1892 }
1893 else {
1894 // operator is not supported by given arguments.
1895 assert(false);
1896 }
1897 a.check_error();
1898 return expr(a.ctx(), r);
1899 }
1900
1901 inline expr operator-(expr const & a, expr const & b) {
1902 check_context(a, b);
1903 Z3_ast r = 0;
1904 if (a.is_arith() && b.is_arith()) {
1905 Z3_ast args[2] = { a, b };
1906 r = Z3_mk_sub(a.ctx(), 2, args);
1907 }
1908 else if (a.is_bv() && b.is_bv()) {
1909 r = Z3_mk_bvsub(a.ctx(), a, b);
1910 }
1911 else if (a.is_fpa() && b.is_fpa()) {
1912 r = Z3_mk_fpa_sub(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
1913 }
1914 else {
1915 // operator is not supported by given arguments.
1916 assert(false);
1917 }
1918 a.check_error();
1919 return expr(a.ctx(), r);
1920 }
1921 inline expr operator-(expr const & a, int b) { return a - a.ctx().num_val(b, a.get_sort()); }
1922 inline expr operator-(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) - b; }
1923
1924 inline expr operator<=(expr const & a, expr const & b) {
1925 check_context(a, b);
1926 Z3_ast r = 0;
1927 if (a.is_arith() && b.is_arith()) {
1928 r = Z3_mk_le(a.ctx(), a, b);
1929 }
1930 else if (a.is_bv() && b.is_bv()) {
1931 r = Z3_mk_bvsle(a.ctx(), a, b);
1932 }
1933 else if (a.is_fpa() && b.is_fpa()) {
1934 r = Z3_mk_fpa_leq(a.ctx(), a, b);
1935 }
1936 else {
1937 // operator is not supported by given arguments.
1938 assert(false);
1939 }
1940 a.check_error();
1941 return expr(a.ctx(), r);
1942 }
1943 inline expr operator<=(expr const & a, int b) { return a <= a.ctx().num_val(b, a.get_sort()); }
1944 inline expr operator<=(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) <= b; }
1945
1946 inline expr operator>=(expr const & a, int b) { return a >= a.ctx().num_val(b, a.get_sort()); }
1947 inline expr operator>=(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) >= b; }
1948
1949 inline expr operator<(expr const & a, expr const & b) {
1950 check_context(a, b);
1951 Z3_ast r = 0;
1952 if (a.is_arith() && b.is_arith()) {
1953 r = Z3_mk_lt(a.ctx(), a, b);
1954 }
1955 else if (a.is_bv() && b.is_bv()) {
1956 r = Z3_mk_bvslt(a.ctx(), a, b);
1957 }
1958 else if (a.is_fpa() && b.is_fpa()) {
1959 r = Z3_mk_fpa_lt(a.ctx(), a, b);
1960 }
1961 else {
1962 // operator is not supported by given arguments.
1963 assert(false);
1964 }
1965 a.check_error();
1966 return expr(a.ctx(), r);
1967 }
1968 inline expr operator<(expr const & a, int b) { return a < a.ctx().num_val(b, a.get_sort()); }
1969 inline expr operator<(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) < b; }
1970
1971 inline expr operator>(expr const & a, expr const & b) {
1972 check_context(a, b);
1973 Z3_ast r = 0;
1974 if (a.is_arith() && b.is_arith()) {
1975 r = Z3_mk_gt(a.ctx(), a, b);
1976 }
1977 else if (a.is_bv() && b.is_bv()) {
1978 r = Z3_mk_bvsgt(a.ctx(), a, b);
1979 }
1980 else if (a.is_fpa() && b.is_fpa()) {
1981 r = Z3_mk_fpa_gt(a.ctx(), a, b);
1982 }
1983 else {
1984 // operator is not supported by given arguments.
1985 assert(false);
1986 }
1987 a.check_error();
1988 return expr(a.ctx(), r);
1989 }
1990 inline expr operator>(expr const & a, int b) { return a > a.ctx().num_val(b, a.get_sort()); }
1991 inline expr operator>(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) > b; }
1992
1993 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); }
1994 inline expr operator&(expr const & a, int b) { return a & a.ctx().num_val(b, a.get_sort()); }
1995 inline expr operator&(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) & b; }
1996
1997 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); }
1998 inline expr operator^(expr const & a, int b) { return a ^ a.ctx().num_val(b, a.get_sort()); }
1999 inline expr operator^(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) ^ b; }
2000
2001 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); }
2002 inline expr operator|(expr const & a, int b) { return a | a.ctx().num_val(b, a.get_sort()); }
2003 inline expr operator|(int a, expr const & b) { return b.ctx().num_val(a, b.get_sort()) | b; }
2004
2005 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); }
2006 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); }
2007 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); }
2008 inline expr min(expr const& a, expr const& b) {
2009 check_context(a, b);
2010 Z3_ast r;
2011 if (a.is_arith()) {
2012 r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, b), b, a);
2013 }
2014 else if (a.is_bv()) {
2015 r = Z3_mk_ite(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b), b, a);
2016 }
2017 else {
2018 assert(a.is_fpa());
2019 r = Z3_mk_fpa_min(a.ctx(), a, b);
2020 }
2021 a.check_error();
2022 return expr(a.ctx(), r);
2023 }
2024 inline expr max(expr const& a, expr const& b) {
2025 check_context(a, b);
2026 Z3_ast r;
2027 if (a.is_arith()) {
2028 r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, b), a, b);
2029 }
2030 else if (a.is_bv()) {
2031 r = Z3_mk_ite(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b), a, b);
2032 }
2033 else {
2034 assert(a.is_fpa());
2035 r = Z3_mk_fpa_max(a.ctx(), a, b);
2036 }
2037 a.check_error();
2038 return expr(a.ctx(), r);
2039 }
2040 inline expr bvredor(expr const & a) {
2041 assert(a.is_bv());
2042 Z3_ast r = Z3_mk_bvredor(a.ctx(), a);
2043 a.check_error();
2044 return expr(a.ctx(), r);
2045 }
2046 inline expr bvredand(expr const & a) {
2047 assert(a.is_bv());
2048 Z3_ast r = Z3_mk_bvredand(a.ctx(), a);
2049 a.check_error();
2050 return expr(a.ctx(), r);
2051 }
2052 inline expr abs(expr const & a) {
2053 Z3_ast r;
2054 if (a.is_int()) {
2055 expr zero = a.ctx().int_val(0);
2056 expr ge = a >= zero;
2057 expr na = -a;
2058 r = Z3_mk_ite(a.ctx(), ge, a, na);
2059 }
2060 else if (a.is_real()) {
2061 expr zero = a.ctx().real_val(0);
2062 expr ge = a >= zero;
2063 expr na = -a;
2064 r = Z3_mk_ite(a.ctx(), ge, a, na);
2065 }
2066 else {
2067 r = Z3_mk_fpa_abs(a.ctx(), a);
2068 }
2069 a.check_error();
2070 return expr(a.ctx(), r);
2071 }
2072 inline expr sqrt(expr const & a, expr const& rm) {
2073 check_context(a, rm);
2074 assert(a.is_fpa());
2075 Z3_ast r = Z3_mk_fpa_sqrt(a.ctx(), rm, a);
2076 a.check_error();
2077 return expr(a.ctx(), r);
2078 }
2079 inline expr fp_eq(expr const & a, expr const & b) {
2080 check_context(a, b);
2081 assert(a.is_fpa());
2082 Z3_ast r = Z3_mk_fpa_eq(a.ctx(), a, b);
2083 a.check_error();
2084 return expr(a.ctx(), r);
2085 }
2086 inline expr operator~(expr const & a) { Z3_ast r = Z3_mk_bvnot(a.ctx(), a); return expr(a.ctx(), r); }
2087
2088 inline expr fma(expr const& a, expr const& b, expr const& c, expr const& rm) {
2090 assert(a.is_fpa() && b.is_fpa() && c.is_fpa());
2091 Z3_ast r = Z3_mk_fpa_fma(a.ctx(), rm, a, b, c);
2092 a.check_error();
2093 return expr(a.ctx(), r);
2094 }
2095
2096 inline expr fpa_fp(expr const& sgn, expr const& exp, expr const& sig) {
2098 assert(sgn.is_bv() && exp.is_bv() && sig.is_bv());
2099 Z3_ast r = Z3_mk_fpa_fp(sgn.ctx(), sgn, exp, sig);
2100 sgn.check_error();
2101 return expr(sgn.ctx(), r);
2102 }
2103
2104 inline expr fpa_to_sbv(expr const& t, unsigned sz) {
2105 assert(t.is_fpa());
2106 Z3_ast r = Z3_mk_fpa_to_sbv(t.ctx(), t.ctx().fpa_rounding_mode(), t, sz);
2107 t.check_error();
2108 return expr(t.ctx(), r);
2109 }
2110
2111 inline expr fpa_to_ubv(expr const& t, unsigned sz) {
2112 assert(t.is_fpa());
2113 Z3_ast r = Z3_mk_fpa_to_ubv(t.ctx(), t.ctx().fpa_rounding_mode(), t, sz);
2114 t.check_error();
2115 return expr(t.ctx(), r);
2116 }
2117
2118 inline expr sbv_to_fpa(expr const& t, sort s) {
2119 assert(t.is_bv());
2120 Z3_ast r = Z3_mk_fpa_to_fp_signed(t.ctx(), t.ctx().fpa_rounding_mode(), t, s);
2121 t.check_error();
2122 return expr(t.ctx(), r);
2123 }
2124
2125 inline expr ubv_to_fpa(expr const& t, sort s) {
2126 assert(t.is_bv());
2127 Z3_ast r = Z3_mk_fpa_to_fp_unsigned(t.ctx(), t.ctx().fpa_rounding_mode(), t, s);
2128 t.check_error();
2129 return expr(t.ctx(), r);
2130 }
2131
2132 inline expr fpa_to_fpa(expr const& t, sort s) {
2133 assert(t.is_fpa());
2134 Z3_ast r = Z3_mk_fpa_to_fp_float(t.ctx(), t.ctx().fpa_rounding_mode(), t, s);
2135 t.check_error();
2136 return expr(t.ctx(), r);
2137 }
2138
2140 assert(t.is_fpa());
2141 Z3_ast r = Z3_mk_fpa_round_to_integral(t.ctx(), t.ctx().fpa_rounding_mode(), t);
2142 t.check_error();
2143 return expr(t.ctx(), r);
2144 }
2145
2151 inline expr ite(expr const & c, expr const & t, expr const & e) {
2152 check_context(c, t); check_context(c, e);
2153 assert(c.is_bool());
2154 Z3_ast r = Z3_mk_ite(c.ctx(), c, t, e);
2155 c.check_error();
2156 return expr(c.ctx(), r);
2157 }
2158
2159
2164 inline expr to_expr(context & c, Z3_ast a) {
2165 c.check_error();
2168 Z3_get_ast_kind(c, a) == Z3_VAR_AST ||
2170 return expr(c, a);
2171 }
2172
2173 inline sort to_sort(context & c, Z3_sort s) {
2174 c.check_error();
2175 return sort(c, s);
2176 }
2177
2178 inline func_decl to_func_decl(context & c, Z3_func_decl f) {
2179 c.check_error();
2180 return func_decl(c, f);
2181 }
2182
2186 inline expr sle(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsle(a.ctx(), a, b)); }
2187 inline expr sle(expr const & a, int b) { return sle(a, a.ctx().num_val(b, a.get_sort())); }
2188 inline expr sle(int a, expr const & b) { return sle(b.ctx().num_val(a, b.get_sort()), b); }
2192 inline expr slt(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvslt(a.ctx(), a, b)); }
2193 inline expr slt(expr const & a, int b) { return slt(a, a.ctx().num_val(b, a.get_sort())); }
2194 inline expr slt(int a, expr const & b) { return slt(b.ctx().num_val(a, b.get_sort()), b); }
2198 inline expr sge(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsge(a.ctx(), a, b)); }
2199 inline expr sge(expr const & a, int b) { return sge(a, a.ctx().num_val(b, a.get_sort())); }
2200 inline expr sge(int a, expr const & b) { return sge(b.ctx().num_val(a, b.get_sort()), b); }
2204 inline expr sgt(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsgt(a.ctx(), a, b)); }
2205 inline expr sgt(expr const & a, int b) { return sgt(a, a.ctx().num_val(b, a.get_sort())); }
2206 inline expr sgt(int a, expr const & b) { return sgt(b.ctx().num_val(a, b.get_sort()), b); }
2207
2208
2212 inline expr ule(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvule(a.ctx(), a, b)); }
2213 inline expr ule(expr const & a, int b) { return ule(a, a.ctx().num_val(b, a.get_sort())); }
2214 inline expr ule(int a, expr const & b) { return ule(b.ctx().num_val(a, b.get_sort()), b); }
2218 inline expr ult(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvult(a.ctx(), a, b)); }
2219 inline expr ult(expr const & a, int b) { return ult(a, a.ctx().num_val(b, a.get_sort())); }
2220 inline expr ult(int a, expr const & b) { return ult(b.ctx().num_val(a, b.get_sort()), b); }
2224 inline expr uge(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b)); }
2225 inline expr uge(expr const & a, int b) { return uge(a, a.ctx().num_val(b, a.get_sort())); }
2226 inline expr uge(int a, expr const & b) { return uge(b.ctx().num_val(a, b.get_sort()), b); }
2230 inline expr ugt(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvugt(a.ctx(), a, b)); }
2231 inline expr ugt(expr const & a, int b) { return ugt(a, a.ctx().num_val(b, a.get_sort())); }
2232 inline expr ugt(int a, expr const & b) { return ugt(b.ctx().num_val(a, b.get_sort()), b); }
2233
2237 inline expr sdiv(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsdiv(a.ctx(), a, b)); }
2238 inline expr sdiv(expr const & a, int b) { return sdiv(a, a.ctx().num_val(b, a.get_sort())); }
2239 inline expr sdiv(int a, expr const & b) { return sdiv(b.ctx().num_val(a, b.get_sort()), b); }
2240
2244 inline expr udiv(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvudiv(a.ctx(), a, b)); }
2245 inline expr udiv(expr const & a, int b) { return udiv(a, a.ctx().num_val(b, a.get_sort())); }
2246 inline expr udiv(int a, expr const & b) { return udiv(b.ctx().num_val(a, b.get_sort()), b); }
2247
2251 inline expr srem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsrem(a.ctx(), a, b)); }
2252 inline expr srem(expr const & a, int b) { return srem(a, a.ctx().num_val(b, a.get_sort())); }
2253 inline expr srem(int a, expr const & b) { return srem(b.ctx().num_val(a, b.get_sort()), b); }
2254
2258 inline expr smod(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsmod(a.ctx(), a, b)); }
2259 inline expr smod(expr const & a, int b) { return smod(a, a.ctx().num_val(b, a.get_sort())); }
2260 inline expr smod(int a, expr const & b) { return smod(b.ctx().num_val(a, b.get_sort()), b); }
2261
2265 inline expr urem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvurem(a.ctx(), a, b)); }
2266 inline expr urem(expr const & a, int b) { return urem(a, a.ctx().num_val(b, a.get_sort())); }
2267 inline expr urem(int a, expr const & b) { return urem(b.ctx().num_val(a, b.get_sort()), b); }
2268
2272 inline expr shl(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvshl(a.ctx(), a, b)); }
2273 inline expr shl(expr const & a, int b) { return shl(a, a.ctx().num_val(b, a.get_sort())); }
2274 inline expr shl(int a, expr const & b) { return shl(b.ctx().num_val(a, b.get_sort()), b); }
2275
2279 inline expr lshr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvlshr(a.ctx(), a, b)); }
2280 inline expr lshr(expr const & a, int b) { return lshr(a, a.ctx().num_val(b, a.get_sort())); }
2281 inline expr lshr(int a, expr const & b) { return lshr(b.ctx().num_val(a, b.get_sort()), b); }
2282
2286 inline expr ashr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvashr(a.ctx(), a, b)); }
2287 inline expr ashr(expr const & a, int b) { return ashr(a, a.ctx().num_val(b, a.get_sort())); }
2288 inline expr ashr(int a, expr const & b) { return ashr(b.ctx().num_val(a, b.get_sort()), b); }
2289
2293 inline expr zext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_zero_ext(a.ctx(), i, a)); }
2294
2298 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); }
2299 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); }
2300
2304 inline expr bvadd_no_overflow(expr const& a, expr const& b, bool is_signed) {
2305 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);
2306 }
2307 inline expr bvadd_no_underflow(expr const& a, expr const& b) {
2308 check_context(a, b); Z3_ast r = Z3_mk_bvadd_no_underflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2309 }
2310 inline expr bvsub_no_overflow(expr const& a, expr const& b) {
2311 check_context(a, b); Z3_ast r = Z3_mk_bvsub_no_overflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2312 }
2313 inline expr bvsub_no_underflow(expr const& a, expr const& b, bool is_signed) {
2314 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);
2315 }
2316 inline expr bvsdiv_no_overflow(expr const& a, expr const& b) {
2317 check_context(a, b); Z3_ast r = Z3_mk_bvsdiv_no_overflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2318 }
2319 inline expr bvneg_no_overflow(expr const& a) {
2320 Z3_ast r = Z3_mk_bvneg_no_overflow(a.ctx(), a); a.check_error(); return expr(a.ctx(), r);
2321 }
2322 inline expr bvmul_no_overflow(expr const& a, expr const& b, bool is_signed) {
2323 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);
2324 }
2325 inline expr bvmul_no_underflow(expr const& a, expr const& b) {
2326 check_context(a, b); Z3_ast r = Z3_mk_bvmul_no_underflow(a.ctx(), a, b); a.check_error(); return expr(a.ctx(), r);
2327 }
2328
2329
2333 inline expr sext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_sign_ext(a.ctx(), i, a)); }
2334
2335 inline func_decl linear_order(sort const& a, unsigned index) {
2336 return to_func_decl(a.ctx(), Z3_mk_linear_order(a.ctx(), a, index));
2337 }
2338 inline func_decl partial_order(sort const& a, unsigned index) {
2339 return to_func_decl(a.ctx(), Z3_mk_partial_order(a.ctx(), a, index));
2340 }
2341 inline func_decl piecewise_linear_order(sort const& a, unsigned index) {
2342 return to_func_decl(a.ctx(), Z3_mk_piecewise_linear_order(a.ctx(), a, index));
2343 }
2344 inline func_decl tree_order(sort const& a, unsigned index) {
2345 return to_func_decl(a.ctx(), Z3_mk_tree_order(a.ctx(), a, index));
2346 }
2347
2354 inline expr_vector polynomial_subresultants(expr const& p, expr const& q, expr const& x) {
2355 check_context(p, q); check_context(p, x);
2356 Z3_ast_vector r = Z3_polynomial_subresultants(p.ctx(), p, q, x);
2357 p.check_error();
2358 return expr_vector(p.ctx(), r);
2359 }
2360
2361 template<> class cast_ast<ast> {
2362 public:
2363 ast operator()(context & c, Z3_ast a) { return ast(c, a); }
2364 };
2365
2366 template<> class cast_ast<expr> {
2367 public:
2368 expr operator()(context & c, Z3_ast a) {
2370 Z3_get_ast_kind(c, a) == Z3_APP_AST ||
2373 return expr(c, a);
2374 }
2375 };
2376
2377 template<> class cast_ast<sort> {
2378 public:
2379 sort operator()(context & c, Z3_ast a) {
2381 return sort(c, reinterpret_cast<Z3_sort>(a));
2382 }
2383 };
2384
2385 template<> class cast_ast<func_decl> {
2386 public:
2389 return func_decl(c, reinterpret_cast<Z3_func_decl>(a));
2390 }
2391 };
2392
2393 template<typename T>
2394 template<typename T2>
2395 array<T>::array(ast_vector_tpl<T2> const & v):m_array(new T[v.size()]), m_size(v.size()) {
2396 for (unsigned i = 0; i < m_size; i++) {
2397 m_array[i] = v[i];
2398 }
2399 }
2400
2401 // Basic functions for creating quantified formulas.
2402 // The C API should be used for creating quantifiers with patterns, weights, many variables, etc.
2403 inline expr forall(expr const & x, expr const & b) {
2404 check_context(x, b);
2405 Z3_app vars[] = {(Z3_app) x};
2406 Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 1, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2407 }
2408 inline expr forall(expr const & x1, expr const & x2, expr const & b) {
2410 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2};
2411 Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 2, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2412 }
2413 inline expr forall(expr const & x1, expr const & x2, expr const & x3, expr const & b) {
2415 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3 };
2416 Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 3, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2417 }
2418 inline expr forall(expr const & x1, expr const & x2, expr const & x3, expr const & x4, expr const & b) {
2420 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3, (Z3_app) x4 };
2421 Z3_ast r = Z3_mk_forall_const(b.ctx(), 0, 4, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2422 }
2423 inline expr forall(expr_vector const & xs, expr const & b) {
2424 array<Z3_app> vars(xs);
2425 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);
2426 }
2427 inline expr exists(expr const & x, expr const & b) {
2428 check_context(x, b);
2429 Z3_app vars[] = {(Z3_app) x};
2430 Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 1, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2431 }
2432 inline expr exists(expr const & x1, expr const & x2, expr const & b) {
2434 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2};
2435 Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 2, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2436 }
2437 inline expr exists(expr const & x1, expr const & x2, expr const & x3, expr const & b) {
2439 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3 };
2440 Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 3, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2441 }
2442 inline expr exists(expr const & x1, expr const & x2, expr const & x3, expr const & x4, expr const & b) {
2444 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3, (Z3_app) x4 };
2445 Z3_ast r = Z3_mk_exists_const(b.ctx(), 0, 4, vars, 0, 0, b); b.check_error(); return expr(b.ctx(), r);
2446 }
2447 inline expr exists(expr_vector const & xs, expr const & b) {
2448 array<Z3_app> vars(xs);
2449 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);
2450 }
2451 inline expr lambda(expr const & x, expr const & b) {
2452 check_context(x, b);
2453 Z3_app vars[] = {(Z3_app) x};
2454 Z3_ast r = Z3_mk_lambda_const(b.ctx(), 1, vars, b); b.check_error(); return expr(b.ctx(), r);
2455 }
2456 inline expr lambda(expr const & x1, expr const & x2, expr const & b) {
2458 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2};
2459 Z3_ast r = Z3_mk_lambda_const(b.ctx(), 2, vars, b); b.check_error(); return expr(b.ctx(), r);
2460 }
2461 inline expr lambda(expr const & x1, expr const & x2, expr const & x3, expr const & b) {
2463 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3 };
2464 Z3_ast r = Z3_mk_lambda_const(b.ctx(), 3, vars, b); b.check_error(); return expr(b.ctx(), r);
2465 }
2466 inline expr lambda(expr const & x1, expr const & x2, expr const & x3, expr const & x4, expr const & b) {
2468 Z3_app vars[] = {(Z3_app) x1, (Z3_app) x2, (Z3_app) x3, (Z3_app) x4 };
2469 Z3_ast r = Z3_mk_lambda_const(b.ctx(), 4, vars, b); b.check_error(); return expr(b.ctx(), r);
2470 }
2471 inline expr lambda(expr_vector const & xs, expr const & b) {
2472 array<Z3_app> vars(xs);
2473 Z3_ast r = Z3_mk_lambda_const(b.ctx(), vars.size(), vars.ptr(), b); b.check_error(); return expr(b.ctx(), r);
2474 }
2475
2476 inline expr pble(expr_vector const& es, int const* coeffs, int bound) {
2477 assert(es.size() > 0);
2478 context& ctx = es[0u].ctx();
2480 Z3_ast r = Z3_mk_pble(ctx, _es.size(), _es.ptr(), coeffs, bound);
2481 ctx.check_error();
2482 return expr(ctx, r);
2483 }
2484 inline expr pbge(expr_vector const& es, int const* coeffs, int bound) {
2485 assert(es.size() > 0);
2486 context& ctx = es[0u].ctx();
2488 Z3_ast r = Z3_mk_pbge(ctx, _es.size(), _es.ptr(), coeffs, bound);
2489 ctx.check_error();
2490 return expr(ctx, r);
2491 }
2492 inline expr pbeq(expr_vector const& es, int const* coeffs, int bound) {
2493 assert(es.size() > 0);
2494 context& ctx = es[0u].ctx();
2496 Z3_ast r = Z3_mk_pbeq(ctx, _es.size(), _es.ptr(), coeffs, bound);
2497 ctx.check_error();
2498 return expr(ctx, r);
2499 }
2500 inline expr atmost(expr_vector const& es, unsigned bound) {
2501 assert(es.size() > 0);
2502 context& ctx = es[0u].ctx();
2504 Z3_ast r = Z3_mk_atmost(ctx, _es.size(), _es.ptr(), bound);
2505 ctx.check_error();
2506 return expr(ctx, r);
2507 }
2508 inline expr atleast(expr_vector const& es, unsigned bound) {
2509 assert(es.size() > 0);
2510 context& ctx = es[0u].ctx();
2512 Z3_ast r = Z3_mk_atleast(ctx, _es.size(), _es.ptr(), bound);
2513 ctx.check_error();
2514 return expr(ctx, r);
2515 }
2516 inline expr sum(expr_vector const& args) {
2517 assert(args.size() > 0);
2518 context& ctx = args[0u].ctx();
2519 array<Z3_ast> _args(args);
2520 Z3_ast r = Z3_mk_add(ctx, _args.size(), _args.ptr());
2521 ctx.check_error();
2522 return expr(ctx, r);
2523 }
2524
2525 inline expr distinct(expr_vector const& args) {
2526 assert(args.size() > 0);
2527 context& ctx = args[0u].ctx();
2528 array<Z3_ast> _args(args);
2529 Z3_ast r = Z3_mk_distinct(ctx, _args.size(), _args.ptr());
2530 ctx.check_error();
2531 return expr(ctx, r);
2532 }
2533
2534 inline expr concat(expr const& a, expr const& b) {
2535 check_context(a, b);
2536 Z3_ast r;
2537 if (Z3_is_seq_sort(a.ctx(), a.get_sort())) {
2538 Z3_ast _args[2] = { a, b };
2539 r = Z3_mk_seq_concat(a.ctx(), 2, _args);
2540 }
2541 else if (Z3_is_re_sort(a.ctx(), a.get_sort())) {
2542 Z3_ast _args[2] = { a, b };
2543 r = Z3_mk_re_concat(a.ctx(), 2, _args);
2544 }
2545 else {
2546 r = Z3_mk_concat(a.ctx(), a, b);
2547 }
2548 a.ctx().check_error();
2549 return expr(a.ctx(), r);
2550 }
2551
2552 inline expr concat(expr_vector const& args) {
2553 Z3_ast r;
2554 assert(args.size() > 0);
2555 if (args.size() == 1) {
2556 return args[0u];
2557 }
2558 context& ctx = args[0u].ctx();
2559 array<Z3_ast> _args(args);
2560 if (Z3_is_seq_sort(ctx, args[0u].get_sort())) {
2561 r = Z3_mk_seq_concat(ctx, _args.size(), _args.ptr());
2562 }
2563 else if (Z3_is_re_sort(ctx, args[0u].get_sort())) {
2564 r = Z3_mk_re_concat(ctx, _args.size(), _args.ptr());
2565 }
2566 else {
2567 r = _args[args.size()-1];
2568 for (unsigned i = args.size()-1; i > 0; ) {
2569 --i;
2570 r = Z3_mk_concat(ctx, _args[i], r);
2571 ctx.check_error();
2572 }
2573 }
2574 ctx.check_error();
2575 return expr(ctx, r);
2576 }
2577
2578 inline expr map(expr const& f, expr const& list) {
2579 context& ctx = f.ctx();
2580 Z3_ast r = Z3_mk_seq_map(ctx, f, list);
2581 ctx.check_error();
2582 return expr(ctx, r);
2583 }
2584
2585 inline expr mapi(expr const& f, expr const& i, expr const& list) {
2586 context& ctx = f.ctx();
2587 Z3_ast r = Z3_mk_seq_mapi(ctx, f, i, list);
2588 ctx.check_error();
2589 return expr(ctx, r);
2590 }
2591
2592 inline expr foldl(expr const& f, expr const& a, expr const& list) {
2593 context& ctx = f.ctx();
2594 Z3_ast r = Z3_mk_seq_foldl(ctx, f, a, list);
2595 ctx.check_error();
2596 return expr(ctx, r);
2597 }
2598
2599 inline expr foldli(expr const& f, expr const& i, expr const& a, expr const& list) {
2600 context& ctx = f.ctx();
2601 Z3_ast r = Z3_mk_seq_foldli(ctx, f, i, a, list);
2602 ctx.check_error();
2603 return expr(ctx, r);
2604 }
2605
2606 inline expr mk_or(expr_vector const& args) {
2607 array<Z3_ast> _args(args);
2608 Z3_ast r = Z3_mk_or(args.ctx(), _args.size(), _args.ptr());
2609 args.check_error();
2610 return expr(args.ctx(), r);
2611 }
2612 inline expr mk_and(expr_vector const& args) {
2613 array<Z3_ast> _args(args);
2614 Z3_ast r = Z3_mk_and(args.ctx(), _args.size(), _args.ptr());
2615 args.check_error();
2616 return expr(args.ctx(), r);
2617 }
2618 inline expr mk_xor(expr_vector const& args) {
2619 if (args.empty())
2620 return args.ctx().bool_val(false);
2621 expr r = args[0u];
2622 for (unsigned i = 1; i < args.size(); ++i)
2623 r = r ^ args[i];
2624 return r;
2625 }
2626
2627
2628 class func_entry : public object {
2629 Z3_func_entry m_entry;
2630 void init(Z3_func_entry e) {
2631 m_entry = e;
2632 Z3_func_entry_inc_ref(ctx(), m_entry);
2633 }
2634 public:
2635 func_entry(context & c, Z3_func_entry e):object(c) { init(e); }
2636 func_entry(func_entry const & s):object(s) { init(s.m_entry); }
2637 ~func_entry() override { Z3_func_entry_dec_ref(ctx(), m_entry); }
2638 operator Z3_func_entry() const { return m_entry; }
2640 Z3_func_entry_inc_ref(s.ctx(), s.m_entry);
2641 Z3_func_entry_dec_ref(ctx(), m_entry);
2642 object::operator=(s);
2643 m_entry = s.m_entry;
2644 return *this;
2645 }
2646 expr value() const { Z3_ast r = Z3_func_entry_get_value(ctx(), m_entry); check_error(); return expr(ctx(), r); }
2647 unsigned num_args() const { unsigned r = Z3_func_entry_get_num_args(ctx(), m_entry); check_error(); return r; }
2648 expr arg(unsigned i) const { Z3_ast r = Z3_func_entry_get_arg(ctx(), m_entry, i); check_error(); return expr(ctx(), r); }
2649 };
2650
2651 class func_interp : public object {
2652 Z3_func_interp m_interp;
2653 void init(Z3_func_interp e) {
2654 m_interp = e;
2655 Z3_func_interp_inc_ref(ctx(), m_interp);
2656 }
2657 public:
2658 func_interp(context & c, Z3_func_interp e):object(c) { init(e); }
2659 func_interp(func_interp const & s):object(s) { init(s.m_interp); }
2660 ~func_interp() override { Z3_func_interp_dec_ref(ctx(), m_interp); }
2661 operator Z3_func_interp() const { return m_interp; }
2663 Z3_func_interp_inc_ref(s.ctx(), s.m_interp);
2664 Z3_func_interp_dec_ref(ctx(), m_interp);
2665 object::operator=(s);
2666 m_interp = s.m_interp;
2667 return *this;
2668 }
2669 expr else_value() const { Z3_ast r = Z3_func_interp_get_else(ctx(), m_interp); check_error(); return expr(ctx(), r); }
2670 unsigned num_entries() const { unsigned r = Z3_func_interp_get_num_entries(ctx(), m_interp); check_error(); return r; }
2671 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); }
2672 void add_entry(expr_vector const& args, expr& value) {
2673 Z3_func_interp_add_entry(ctx(), m_interp, args, value);
2674 check_error();
2675 }
2676 void set_else(expr& value) {
2677 Z3_func_interp_set_else(ctx(), m_interp, value);
2678 check_error();
2679 }
2680 };
2681
2682 class model : public object {
2683 Z3_model m_model;
2684 void init(Z3_model m) {
2685 m_model = m;
2687 }
2688 public:
2689 struct translate {};
2690 model(context & c):object(c) { init(Z3_mk_model(c)); }
2691 model(context & c, Z3_model m):object(c) { init(m); }
2692 model(model const & s):object(s) { init(s.m_model); }
2694 ~model() override { Z3_model_dec_ref(ctx(), m_model); }
2695 operator Z3_model() const { return m_model; }
2696 model & operator=(model const & s) {
2697 Z3_model_inc_ref(s.ctx(), s.m_model);
2698 Z3_model_dec_ref(ctx(), m_model);
2699 object::operator=(s);
2700 m_model = s.m_model;
2701 return *this;
2702 }
2703
2704 expr eval(expr const & n, bool model_completion=false) const {
2705 check_context(*this, n);
2706 Z3_ast r = 0;
2707 bool status = Z3_model_eval(ctx(), m_model, n, model_completion, &r);
2708 check_error();
2709 if (status == false && ctx().enable_exceptions())
2710 Z3_THROW(exception("failed to evaluate expression"));
2711 return expr(ctx(), r);
2712 }
2713
2714 unsigned num_consts() const { return Z3_model_get_num_consts(ctx(), m_model); }
2715 unsigned num_funcs() const { return Z3_model_get_num_funcs(ctx(), m_model); }
2716 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); }
2717 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); }
2718 unsigned size() const { return num_consts() + num_funcs(); }
2719 func_decl operator[](int i) const {
2720 assert(0 <= i);
2721 return static_cast<unsigned>(i) < num_consts() ? get_const_decl(i) : get_func_decl(i - num_consts());
2722 }
2723
2724 // returns interpretation of constant declaration c.
2725 // If c is not assigned any value in the model it returns
2726 // an expression with a null ast reference.
2728 check_context(*this, c);
2729 Z3_ast r = Z3_model_get_const_interp(ctx(), m_model, c);
2730 check_error();
2731 return expr(ctx(), r);
2732 }
2734 check_context(*this, f);
2735 Z3_func_interp r = Z3_model_get_func_interp(ctx(), m_model, f);
2736 check_error();
2737 return func_interp(ctx(), r);
2738 }
2739
2740 // returns true iff the model contains an interpretation
2741 // for function f.
2742 bool has_interp(func_decl f) const {
2743 check_context(*this, f);
2744 return Z3_model_has_interp(ctx(), m_model, f);
2745 }
2746
2748 Z3_func_interp r = Z3_add_func_interp(ctx(), m_model, f, else_val);
2749 check_error();
2750 return func_interp(ctx(), r);
2751 }
2752
2754 Z3_add_const_interp(ctx(), m_model, f, value);
2755 check_error();
2756 }
2757
2758 unsigned num_sorts() const {
2759 unsigned r = Z3_model_get_num_sorts(ctx(), m_model);
2760 check_error();
2761 return r;
2762 }
2763
2768 sort get_sort(unsigned i) const {
2769 Z3_sort s = Z3_model_get_sort(ctx(), m_model, i);
2770 check_error();
2771 return sort(ctx(), s);
2772 }
2773
2775 check_context(*this, s);
2776 Z3_ast_vector r = Z3_model_get_sort_universe(ctx(), m_model, s);
2777 check_error();
2778 return expr_vector(ctx(), r);
2779 }
2780
2781 friend std::ostream & operator<<(std::ostream & out, model const & m);
2782
2783 std::string to_string() const { return m_model ? std::string(Z3_model_to_string(ctx(), m_model)) : "null"; }
2784 };
2785 inline std::ostream & operator<<(std::ostream & out, model const & m) { return out << m.to_string(); }
2786
2787 class stats : public object {
2788 Z3_stats m_stats;
2789 void init(Z3_stats e) {
2790 m_stats = e;
2791 Z3_stats_inc_ref(ctx(), m_stats);
2792 }
2793 public:
2794 stats(context & c):object(c), m_stats(0) {}
2795 stats(context & c, Z3_stats e):object(c) { init(e); }
2796 stats(stats const & s):object(s) { init(s.m_stats); }
2797 ~stats() override { if (m_stats) Z3_stats_dec_ref(ctx(), m_stats); }
2798 operator Z3_stats() const { return m_stats; }
2799 stats & operator=(stats const & s) {
2800 Z3_stats_inc_ref(s.ctx(), s.m_stats);
2801 if (m_stats) Z3_stats_dec_ref(ctx(), m_stats);
2802 object::operator=(s);
2803 m_stats = s.m_stats;
2804 return *this;
2805 }
2806 unsigned size() const { return Z3_stats_size(ctx(), m_stats); }
2807 std::string key(unsigned i) const { Z3_string s = Z3_stats_get_key(ctx(), m_stats, i); check_error(); return s; }
2808 bool is_uint(unsigned i) const { bool r = Z3_stats_is_uint(ctx(), m_stats, i); check_error(); return r; }
2809 bool is_double(unsigned i) const { bool r = Z3_stats_is_double(ctx(), m_stats, i); check_error(); return r; }
2810 unsigned uint_value(unsigned i) const { unsigned r = Z3_stats_get_uint_value(ctx(), m_stats, i); check_error(); return r; }
2811 double double_value(unsigned i) const { double r = Z3_stats_get_double_value(ctx(), m_stats, i); check_error(); return r; }
2812 friend std::ostream & operator<<(std::ostream & out, stats const & s);
2813 };
2814 inline std::ostream & operator<<(std::ostream & out, stats const & s) { out << Z3_stats_to_string(s.ctx(), s); return out; }
2815
2816
2817 inline std::ostream & operator<<(std::ostream & out, check_result r) {
2818 if (r == unsat) out << "unsat";
2819 else if (r == sat) out << "sat";
2820 else out << "unknown";
2821 return out;
2822 }
2823
2835 Z3_parameter_kind m_kind;
2836 func_decl m_decl;
2837 unsigned m_index;
2838 context& ctx() const { return m_decl.ctx(); }
2839 void check_error() const { ctx().check_error(); }
2840 public:
2841 parameter(func_decl const& d, unsigned idx) : m_decl(d), m_index(idx) {
2842 if (ctx().enable_exceptions() && idx >= d.num_parameters())
2843 Z3_THROW(exception("parameter index is out of bounds"));
2844 m_kind = Z3_get_decl_parameter_kind(ctx(), d, idx);
2845 }
2846 parameter(expr const& e, unsigned idx) : m_decl(e.decl()), m_index(idx) {
2847 if (ctx().enable_exceptions() && idx >= m_decl.num_parameters())
2848 Z3_THROW(exception("parameter index is out of bounds"));
2849 m_kind = Z3_get_decl_parameter_kind(ctx(), m_decl, idx);
2850 }
2851 Z3_parameter_kind kind() const { return m_kind; }
2852 expr get_expr() const { Z3_ast a = Z3_get_decl_ast_parameter(ctx(), m_decl, m_index); check_error(); return expr(ctx(), a); }
2853 sort get_sort() const { Z3_sort s = Z3_get_decl_sort_parameter(ctx(), m_decl, m_index); check_error(); return sort(ctx(), s); }
2854 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); }
2855 symbol get_symbol() const { Z3_symbol s = Z3_get_decl_symbol_parameter(ctx(), m_decl, m_index); check_error(); return symbol(ctx(), s); }
2856 std::string get_rational() const { Z3_string s = Z3_get_decl_rational_parameter(ctx(), m_decl, m_index); check_error(); return s; }
2857 double get_double() const { double d = Z3_get_decl_double_parameter(ctx(), m_decl, m_index); check_error(); return d; }
2858 int get_int() const { int i = Z3_get_decl_int_parameter(ctx(), m_decl, m_index); check_error(); return i; }
2859 };
2860
2861
2862 class solver : public object {
2863 Z3_solver m_solver;
2864 void init(Z3_solver s) {
2865 m_solver = s;
2866 if (s)
2867 Z3_solver_inc_ref(ctx(), s);
2868 }
2869 public:
2870 struct simple {};
2871 struct translate {};
2874 solver(context & c, Z3_solver s):object(c) { init(s); }
2876 solver(context & c, solver const& src, translate): object(c) { Z3_solver s = Z3_solver_translate(src.ctx(), src, c); check_error(); init(s); }
2877 solver(solver const & s):object(s) { init(s.m_solver); }
2878 solver(solver const& s, simplifier const& simp);
2879 ~solver() override { Z3_solver_dec_ref(ctx(), m_solver); }
2880 operator Z3_solver() const { return m_solver; }
2881 solver & operator=(solver const & s) {
2882 Z3_solver_inc_ref(s.ctx(), s.m_solver);
2883 Z3_solver_dec_ref(ctx(), m_solver);
2884 object::operator=(s);
2885 m_solver = s.m_solver;
2886 return *this;
2887 }
2888 void set(params const & p) { Z3_solver_set_params(ctx(), m_solver, p); check_error(); }
2889 void set(char const * k, bool v) { params p(ctx()); p.set(k, v); set(p); }
2890 void set(char const * k, unsigned v) { params p(ctx()); p.set(k, v); set(p); }
2891 void set(char const * k, double v) { params p(ctx()); p.set(k, v); set(p); }
2892 void set(char const * k, symbol const & v) { params p(ctx()); p.set(k, v); set(p); }
2893 void set(char const * k, char const* v) { params p(ctx()); p.set(k, v); set(p); }
2904 void push() { Z3_solver_push(ctx(), m_solver); check_error(); }
2905 void pop(unsigned n = 1) { Z3_solver_pop(ctx(), m_solver, n); check_error(); }
2906 void reset() { Z3_solver_reset(ctx(), m_solver); check_error(); }
2907 void add(expr const & e) { assert(e.is_bool()); Z3_solver_assert(ctx(), m_solver, e); check_error(); }
2908 void add(expr const & e, expr const & p) {
2909 assert(e.is_bool()); assert(p.is_bool()); assert(p.is_const());
2910 Z3_solver_assert_and_track(ctx(), m_solver, e, p);
2911 check_error();
2912 }
2913 void add(expr const & e, char const * p) {
2914 add(e, ctx().bool_const(p));
2915 }
2916 void add(expr_vector const& v) {
2917 check_context(*this, v);
2918 for (unsigned i = 0; i < v.size(); ++i)
2919 add(v[i]);
2920 }
2921 void from_file(char const* file) { Z3_solver_from_file(ctx(), m_solver, file); ctx().check_parser_error(); }
2922 void from_string(char const* s) { Z3_solver_from_string(ctx(), m_solver, s); ctx().check_parser_error(); }
2923
2925 check_result check(unsigned n, expr * const assumptions) {
2927 for (unsigned i = 0; i < n; i++) {
2928 check_context(*this, assumptions[i]);
2929 _assumptions[i] = assumptions[i];
2930 }
2931 Z3_lbool r = Z3_solver_check_assumptions(ctx(), m_solver, n, _assumptions.ptr());
2932 check_error();
2933 return to_check_result(r);
2934 }
2936 unsigned n = assumptions.size();
2938 for (unsigned i = 0; i < n; i++) {
2939 check_context(*this, assumptions[i]);
2940 _assumptions[i] = assumptions[i];
2941 }
2942 Z3_lbool r = Z3_solver_check_assumptions(ctx(), m_solver, n, _assumptions.ptr());
2943 check_error();
2944 return to_check_result(r);
2945 }
2946 model get_model() const { Z3_model m = Z3_solver_get_model(ctx(), m_solver); check_error(); return model(ctx(), m); }
2952 std::string reason_unknown() const { Z3_string r = Z3_solver_get_reason_unknown(ctx(), m_solver); check_error(); return r; }
2953 stats statistics() const { Z3_stats r = Z3_solver_get_statistics(ctx(), m_solver); check_error(); return stats(ctx(), r); }
2954 expr_vector unsat_core() const { Z3_ast_vector r = Z3_solver_get_unsat_core(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2955 expr_vector assertions() const { Z3_ast_vector r = Z3_solver_get_assertions(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2956 expr_vector non_units() const { Z3_ast_vector r = Z3_solver_get_non_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2957 expr_vector units() const { Z3_ast_vector r = Z3_solver_get_units(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2958 expr_vector trail() const { Z3_ast_vector r = Z3_solver_get_trail(ctx(), m_solver); check_error(); return expr_vector(ctx(), r); }
2960 Z3_ast_vector r = Z3_solver_get_trail(ctx(), m_solver);
2961 check_error();
2962 expr_vector result(ctx(), r);
2963 unsigned sz = result.size();
2964 levels.resize(sz);
2965 Z3_solver_get_levels(ctx(), m_solver, r, sz, levels.ptr());
2966 check_error();
2967 return result;
2968 }
2969 expr congruence_root(expr const& t) const {
2970 check_context(*this, t);
2971 Z3_ast r = Z3_solver_congruence_root(ctx(), m_solver, t);
2972 check_error();
2973 return expr(ctx(), r);
2974 }
2975 expr congruence_next(expr const& t) const {
2976 check_context(*this, t);
2977 Z3_ast r = Z3_solver_congruence_next(ctx(), m_solver, t);
2978 check_error();
2979 return expr(ctx(), r);
2980 }
2981 expr congruence_explain(expr const& a, expr const& b) const {
2982 check_context(*this, a);
2983 check_context(*this, b);
2984 Z3_ast r = Z3_solver_congruence_explain(ctx(), m_solver, a, b);
2985 check_error();
2986 return expr(ctx(), r);
2987 }
2988 void set_initial_value(expr const& var, expr const& value) {
2989 Z3_solver_set_initial_value(ctx(), m_solver, var, value);
2990 check_error();
2991 }
2992 void set_initial_value(expr const& var, int i) {
2993 set_initial_value(var, ctx().num_val(i, var.get_sort()));
2994 }
2995 void set_initial_value(expr const& var, bool b) {
2996 set_initial_value(var, ctx().bool_val(b));
2997 }
2998
2999 expr proof() const { Z3_ast r = Z3_solver_get_proof(ctx(), m_solver); check_error(); return expr(ctx(), r); }
3000 friend std::ostream & operator<<(std::ostream & out, solver const & s);
3001
3002 std::string to_smt2(char const* status = "unknown") {
3004 Z3_ast const* fmls = es.ptr();
3005 Z3_ast fml = 0;
3006 unsigned sz = es.size();
3007 if (sz > 0) {
3008 --sz;
3009 fml = fmls[sz];
3010 }
3011 else {
3012 fml = ctx().bool_val(true);
3013 }
3014 return std::string(Z3_benchmark_to_smtlib_string(
3015 ctx(),
3016 "", "", status, "",
3017 sz,
3018 fmls,
3019 fml));
3020 }
3021
3022 std::string dimacs(bool include_names = true) const { return std::string(Z3_solver_to_dimacs_string(ctx(), m_solver, include_names)); }
3023
3025
3026
3028 Z3_ast_vector r = Z3_solver_cube(ctx(), m_solver, vars, cutoff);
3029 check_error();
3030 return expr_vector(ctx(), r);
3031 }
3032
3034 solver& m_solver;
3035 unsigned& m_cutoff;
3036 expr_vector& m_vars;
3037 expr_vector m_cube;
3038 bool m_end;
3039 bool m_empty;
3040
3041 void inc() {
3042 assert(!m_end && !m_empty);
3043 m_cube = m_solver.cube(m_vars, m_cutoff);
3044 m_cutoff = 0xFFFFFFFF;
3045 if (m_cube.size() == 1 && m_cube[0u].is_false()) {
3046 m_cube = z3::expr_vector(m_solver.ctx());
3047 m_end = true;
3048 }
3049 else if (m_cube.empty()) {
3050 m_empty = true;
3051 }
3052 }
3053 public:
3054 cube_iterator(solver& s, expr_vector& vars, unsigned& cutoff, bool end):
3055 m_solver(s),
3056 m_cutoff(cutoff),
3057 m_vars(vars),
3058 m_cube(s.ctx()),
3059 m_end(end),
3060 m_empty(false) {
3061 if (!m_end) {
3062 inc();
3063 }
3064 }
3065
3067 assert(!m_end);
3068 if (m_empty) {
3069 m_end = true;
3070 }
3071 else {
3072 inc();
3073 }
3074 return *this;
3075 }
3076 cube_iterator operator++(int) { assert(false); return *this; }
3077 expr_vector const * operator->() const { return &(operator*()); }
3078 expr_vector const& operator*() const noexcept { return m_cube; }
3079
3080 bool operator==(cube_iterator const& other) const noexcept {
3081 return other.m_end == m_end;
3082 };
3083 bool operator!=(cube_iterator const& other) const noexcept {
3084 return other.m_end != m_end;
3085 };
3086
3087 };
3088
3090 solver& m_solver;
3091 unsigned m_cutoff;
3092 expr_vector m_default_vars;
3093 expr_vector& m_vars;
3094 public:
3096 m_solver(s),
3097 m_cutoff(0xFFFFFFFF),
3098 m_default_vars(s.ctx()),
3099 m_vars(m_default_vars)
3100 {}
3101
3103 m_solver(s),
3104 m_cutoff(0xFFFFFFFF),
3105 m_default_vars(s.ctx()),
3106 m_vars(vars)
3107 {}
3108
3109 cube_iterator begin() { return cube_iterator(m_solver, m_vars, m_cutoff, false); }
3110 cube_iterator end() { return cube_iterator(m_solver, m_vars, m_cutoff, true); }
3111 void set_cutoff(unsigned c) noexcept { m_cutoff = c; }
3112 };
3113
3115 cube_generator cubes(expr_vector& vars) { return cube_generator(*this, vars); }
3116
3117 };
3118 inline std::ostream & operator<<(std::ostream & out, solver const & s) { out << Z3_solver_to_string(s.ctx(), s); return out; }
3119
3120 class goal : public object {
3121 Z3_goal m_goal;
3122 void init(Z3_goal s) {
3123 m_goal = s;
3124 Z3_goal_inc_ref(ctx(), s);
3125 }
3126 public:
3127 goal(context & c, bool models=true, bool unsat_cores=false, bool proofs=false):object(c) { init(Z3_mk_goal(c, models, unsat_cores, proofs)); }
3128 goal(context & c, Z3_goal s):object(c) { init(s); }
3129 goal(goal const & s):object(s) { init(s.m_goal); }
3130 ~goal() override { Z3_goal_dec_ref(ctx(), m_goal); }
3131 operator Z3_goal() const { return m_goal; }
3132 goal & operator=(goal const & s) {
3133 Z3_goal_inc_ref(s.ctx(), s.m_goal);
3134 Z3_goal_dec_ref(ctx(), m_goal);
3135 object::operator=(s);
3136 m_goal = s.m_goal;
3137 return *this;
3138 }
3139 void add(expr const & f) { check_context(*this, f); Z3_goal_assert(ctx(), m_goal, f); check_error(); }
3140 void add(expr_vector const& v) { check_context(*this, v); for (unsigned i = 0; i < v.size(); ++i) add(v[i]); }
3141 unsigned size() const { return Z3_goal_size(ctx(), m_goal); }
3142 expr operator[](int i) const { assert(0 <= i); Z3_ast r = Z3_goal_formula(ctx(), m_goal, i); check_error(); return expr(ctx(), r); }
3143 Z3_goal_prec precision() const { return Z3_goal_precision(ctx(), m_goal); }
3144 bool inconsistent() const { return Z3_goal_inconsistent(ctx(), m_goal); }
3145 unsigned depth() const { return Z3_goal_depth(ctx(), m_goal); }
3146 void reset() { Z3_goal_reset(ctx(), m_goal); }
3147 unsigned num_exprs() const { return Z3_goal_num_exprs(ctx(), m_goal); }
3148 bool is_decided_sat() const { return Z3_goal_is_decided_sat(ctx(), m_goal); }
3149 bool is_decided_unsat() const { return Z3_goal_is_decided_unsat(ctx(), m_goal); }
3150 model convert_model(model const & m) const {
3151 check_context(*this, m);
3152 Z3_model new_m = Z3_goal_convert_model(ctx(), m_goal, m);
3153 check_error();
3154 return model(ctx(), new_m);
3155 }
3157 Z3_model new_m = Z3_goal_convert_model(ctx(), m_goal, 0);
3158 check_error();
3159 return model(ctx(), new_m);
3160 }
3161 expr as_expr() const {
3162 unsigned n = size();
3163 if (n == 0)
3164 return ctx().bool_val(true);
3165 else if (n == 1)
3166 return operator[](0u);
3167 else {
3168 array<Z3_ast> args(n);
3169 for (unsigned i = 0; i < n; i++)
3170 args[i] = operator[](i);
3171 return expr(ctx(), Z3_mk_and(ctx(), n, args.ptr()));
3172 }
3173 }
3174 std::string dimacs(bool include_names = true) const { return std::string(Z3_goal_to_dimacs_string(ctx(), m_goal, include_names)); }
3175 friend std::ostream & operator<<(std::ostream & out, goal const & g);
3176 };
3177 inline std::ostream & operator<<(std::ostream & out, goal const & g) { out << Z3_goal_to_string(g.ctx(), g); return out; }
3178
3179 class apply_result : public object {
3180 Z3_apply_result m_apply_result;
3181 void init(Z3_apply_result s) {
3182 m_apply_result = s;
3184 }
3185 public:
3186 apply_result(context & c, Z3_apply_result s):object(c) { init(s); }
3187 apply_result(apply_result const & s):object(s) { init(s.m_apply_result); }
3188 ~apply_result() override { Z3_apply_result_dec_ref(ctx(), m_apply_result); }
3189 operator Z3_apply_result() const { return m_apply_result; }
3191 Z3_apply_result_inc_ref(s.ctx(), s.m_apply_result);
3192 Z3_apply_result_dec_ref(ctx(), m_apply_result);
3193 object::operator=(s);
3194 m_apply_result = s.m_apply_result;
3195 return *this;
3196 }
3197 unsigned size() const { return Z3_apply_result_get_num_subgoals(ctx(), m_apply_result); }
3198 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); }
3199 friend std::ostream & operator<<(std::ostream & out, apply_result const & r);
3200 };
3201 inline std::ostream & operator<<(std::ostream & out, apply_result const & r) { out << Z3_apply_result_to_string(r.ctx(), r); return out; }
3202
3203 class tactic : public object {
3204 Z3_tactic m_tactic;
3205 void init(Z3_tactic s) {
3206 m_tactic = s;
3207 Z3_tactic_inc_ref(ctx(), s);
3208 }
3209 public:
3210 tactic(context & c, char const * name):object(c) { Z3_tactic r = Z3_mk_tactic(c, name); check_error(); init(r); }
3211 tactic(context & c, Z3_tactic s):object(c) { init(s); }
3212 tactic(tactic const & s):object(s) { init(s.m_tactic); }
3213 ~tactic() override { Z3_tactic_dec_ref(ctx(), m_tactic); }
3214 operator Z3_tactic() const { return m_tactic; }
3215 tactic & operator=(tactic const & s) {
3216 Z3_tactic_inc_ref(s.ctx(), s.m_tactic);
3217 Z3_tactic_dec_ref(ctx(), m_tactic);
3218 object::operator=(s);
3219 m_tactic = s.m_tactic;
3220 return *this;
3221 }
3222 solver mk_solver() const { Z3_solver r = Z3_mk_solver_from_tactic(ctx(), m_tactic); check_error(); return solver(ctx(), r); }
3223 apply_result apply(goal const & g) const {
3224 check_context(*this, g);
3225 Z3_apply_result r = Z3_tactic_apply(ctx(), m_tactic, g);
3226 check_error();
3227 return apply_result(ctx(), r);
3228 }
3230 return apply(g);
3231 }
3232 std::string help() const { char const * r = Z3_tactic_get_help(ctx(), m_tactic); check_error(); return r; }
3233 friend tactic operator&(tactic const & t1, tactic const & t2);
3234 friend tactic operator|(tactic const & t1, tactic const & t2);
3235 friend tactic repeat(tactic const & t, unsigned max);
3236 friend tactic with(tactic const & t, params const & p);
3237 friend tactic try_for(tactic const & t, unsigned ms);
3238 friend tactic par_or(unsigned n, tactic const* tactics);
3239 friend tactic par_and_then(tactic const& t1, tactic const& t2);
3241 };
3242
3243 inline tactic operator&(tactic const & t1, tactic const & t2) {
3245 Z3_tactic r = Z3_tactic_and_then(t1.ctx(), t1, t2);
3246 t1.check_error();
3247 return tactic(t1.ctx(), r);
3248 }
3249
3250 inline tactic operator|(tactic const & t1, tactic const & t2) {
3252 Z3_tactic r = Z3_tactic_or_else(t1.ctx(), t1, t2);
3253 t1.check_error();
3254 return tactic(t1.ctx(), r);
3255 }
3256
3257 inline tactic repeat(tactic const & t, unsigned max=UINT_MAX) {
3258 Z3_tactic r = Z3_tactic_repeat(t.ctx(), t, max);
3259 t.check_error();
3260 return tactic(t.ctx(), r);
3261 }
3262
3263 inline tactic with(tactic const & t, params const & p) {
3264 Z3_tactic r = Z3_tactic_using_params(t.ctx(), t, p);
3265 t.check_error();
3266 return tactic(t.ctx(), r);
3267 }
3268 inline tactic try_for(tactic const & t, unsigned ms) {
3269 Z3_tactic r = Z3_tactic_try_for(t.ctx(), t, ms);
3270 t.check_error();
3271 return tactic(t.ctx(), r);
3272 }
3273 inline tactic par_or(unsigned n, tactic const* tactics) {
3274 if (n == 0) {
3275 Z3_THROW(exception("a non-zero number of tactics need to be passed to par_or"));
3276 }
3278 for (unsigned i = 0; i < n; ++i) buffer[i] = tactics[i];
3279 return tactic(tactics[0u].ctx(), Z3_tactic_par_or(tactics[0u].ctx(), n, buffer.ptr()));
3280 }
3281
3282 inline tactic par_and_then(tactic const & t1, tactic const & t2) {
3284 Z3_tactic r = Z3_tactic_par_and_then(t1.ctx(), t1, t2);
3285 t1.check_error();
3286 return tactic(t1.ctx(), r);
3287 }
3288
3289 class simplifier : public object {
3290 Z3_simplifier m_simplifier;
3291 void init(Z3_simplifier s) {
3292 m_simplifier = s;
3294 }
3295 public:
3296 simplifier(context & c, char const * name):object(c) { Z3_simplifier r = Z3_mk_simplifier(c, name); check_error(); init(r); }
3297 simplifier(context & c, Z3_simplifier s):object(c) { init(s); }
3298 simplifier(simplifier const & s):object(s) { init(s.m_simplifier); }
3299 ~simplifier() override { Z3_simplifier_dec_ref(ctx(), m_simplifier); }
3300 operator Z3_simplifier() const { return m_simplifier; }
3302 Z3_simplifier_inc_ref(s.ctx(), s.m_simplifier);
3303 Z3_simplifier_dec_ref(ctx(), m_simplifier);
3304 object::operator=(s);
3305 m_simplifier = s.m_simplifier;
3306 return *this;
3307 }
3308 std::string help() const { char const * r = Z3_simplifier_get_help(ctx(), m_simplifier); check_error(); return r; }
3309 friend simplifier operator&(simplifier const & t1, simplifier const & t2);
3310 friend simplifier with(simplifier const & t, params const & p);
3312 };
3313
3314 inline solver::solver(solver const& s, simplifier const& simp):object(s) { init(Z3_solver_add_simplifier(s.ctx(), s, simp)); }
3315
3316
3317 inline simplifier operator&(simplifier const & t1, simplifier const & t2) {
3319 Z3_simplifier r = Z3_simplifier_and_then(t1.ctx(), t1, t2);
3320 t1.check_error();
3321 return simplifier(t1.ctx(), r);
3322 }
3323
3324 inline simplifier with(simplifier const & t, params const & p) {
3325 Z3_simplifier r = Z3_simplifier_using_params(t.ctx(), t, p);
3326 t.check_error();
3327 return simplifier(t.ctx(), r);
3328 }
3329
3330 class probe : public object {
3331 Z3_probe m_probe;
3332 void init(Z3_probe s) {
3333 m_probe = s;
3334 Z3_probe_inc_ref(ctx(), s);
3335 }
3336 public:
3337 probe(context & c, char const * name):object(c) { Z3_probe r = Z3_mk_probe(c, name); check_error(); init(r); }
3338 probe(context & c, double val):object(c) { Z3_probe r = Z3_probe_const(c, val); check_error(); init(r); }
3339 probe(context & c, Z3_probe s):object(c) { init(s); }
3340 probe(probe const & s):object(s) { init(s.m_probe); }
3341 ~probe() override { Z3_probe_dec_ref(ctx(), m_probe); }
3342 operator Z3_probe() const { return m_probe; }
3343 probe & operator=(probe const & s) {
3344 Z3_probe_inc_ref(s.ctx(), s.m_probe);
3345 Z3_probe_dec_ref(ctx(), m_probe);
3346 object::operator=(s);
3347 m_probe = s.m_probe;
3348 return *this;
3349 }
3350 double apply(goal const & g) const { double r = Z3_probe_apply(ctx(), m_probe, g); check_error(); return r; }
3351 double operator()(goal const & g) const { return apply(g); }
3352 friend probe operator<=(probe const & p1, probe const & p2);
3353 friend probe operator<=(probe const & p1, double p2);
3354 friend probe operator<=(double p1, probe const & p2);
3355 friend probe operator>=(probe const & p1, probe const & p2);
3356 friend probe operator>=(probe const & p1, double p2);
3357 friend probe operator>=(double p1, probe const & p2);
3358 friend probe operator<(probe const & p1, probe const & p2);
3359 friend probe operator<(probe const & p1, double p2);
3360 friend probe operator<(double p1, probe const & p2);
3361 friend probe operator>(probe const & p1, probe const & p2);
3362 friend probe operator>(probe const & p1, double p2);
3363 friend probe operator>(double p1, probe const & p2);
3364 friend probe operator==(probe const & p1, probe const & p2);
3365 friend probe operator==(probe const & p1, double p2);
3366 friend probe operator==(double p1, probe const & p2);
3367 friend probe operator&&(probe const & p1, probe const & p2);
3368 friend probe operator||(probe const & p1, probe const & p2);
3369 friend probe operator!(probe const & p);
3370 };
3371
3372 inline probe operator<=(probe const & p1, probe const & p2) {
3373 check_context(p1, p2); Z3_probe r = Z3_probe_le(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3374 }
3375 inline probe operator<=(probe const & p1, double p2) { return p1 <= probe(p1.ctx(), p2); }
3376 inline probe operator<=(double p1, probe const & p2) { return probe(p2.ctx(), p1) <= p2; }
3377 inline probe operator>=(probe const & p1, probe const & p2) {
3378 check_context(p1, p2); Z3_probe r = Z3_probe_ge(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3379 }
3380 inline probe operator>=(probe const & p1, double p2) { return p1 >= probe(p1.ctx(), p2); }
3381 inline probe operator>=(double p1, probe const & p2) { return probe(p2.ctx(), p1) >= p2; }
3382 inline probe operator<(probe const & p1, probe const & p2) {
3383 check_context(p1, p2); Z3_probe r = Z3_probe_lt(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3384 }
3385 inline probe operator<(probe const & p1, double p2) { return p1 < probe(p1.ctx(), p2); }
3386 inline probe operator<(double p1, probe const & p2) { return probe(p2.ctx(), p1) < p2; }
3387 inline probe operator>(probe const & p1, probe const & p2) {
3388 check_context(p1, p2); Z3_probe r = Z3_probe_gt(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3389 }
3390 inline probe operator>(probe const & p1, double p2) { return p1 > probe(p1.ctx(), p2); }
3391 inline probe operator>(double p1, probe const & p2) { return probe(p2.ctx(), p1) > p2; }
3392 inline probe operator==(probe const & p1, probe const & p2) {
3393 check_context(p1, p2); Z3_probe r = Z3_probe_eq(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3394 }
3395 inline probe operator==(probe const & p1, double p2) { return p1 == probe(p1.ctx(), p2); }
3396 inline probe operator==(double p1, probe const & p2) { return probe(p2.ctx(), p1) == p2; }
3397 inline probe operator&&(probe const & p1, probe const & p2) {
3398 check_context(p1, p2); Z3_probe r = Z3_probe_and(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3399 }
3400 inline probe operator||(probe const & p1, probe const & p2) {
3401 check_context(p1, p2); Z3_probe r = Z3_probe_or(p1.ctx(), p1, p2); p1.check_error(); return probe(p1.ctx(), r);
3402 }
3403 inline probe operator!(probe const & p) {
3404 Z3_probe r = Z3_probe_not(p.ctx(), p); p.check_error(); return probe(p.ctx(), r);
3405 }
3406
3407 class optimize : public object {
3408 Z3_optimize m_opt;
3409
3410 public:
3411 struct translate {};
3412 class handle final {
3413 unsigned m_h;
3414 public:
3415 handle(unsigned h): m_h(h) {}
3416 unsigned h() const { return m_h; }
3417 };
3420 Z3_optimize o = Z3_optimize_translate(src.ctx(), src, c);
3421 check_error();
3422 m_opt = o;
3423 Z3_optimize_inc_ref(c, m_opt);
3424 }
3425 optimize(optimize const & o):object(o), m_opt(o.m_opt) {
3426 Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3427 }
3429 m_opt = Z3_mk_optimize(c);
3430 Z3_optimize_inc_ref(c, m_opt);
3431 add(expr_vector(c, src.assertions()));
3432 expr_vector v(c, src.objectives());
3433 for (expr_vector::iterator it = v.begin(); it != v.end(); ++it) minimize(*it);
3434 }
3436 Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3437 Z3_optimize_dec_ref(ctx(), m_opt);
3438 m_opt = o.m_opt;
3439 object::operator=(o);
3440 return *this;
3441 }
3442 ~optimize() override { Z3_optimize_dec_ref(ctx(), m_opt); }
3443 operator Z3_optimize() const { return m_opt; }
3444 void add(expr const& e) {
3445 assert(e.is_bool());
3446 Z3_optimize_assert(ctx(), m_opt, e);
3447 }
3448 void add(expr_vector const& es) {
3449 for (expr_vector::iterator it = es.begin(); it != es.end(); ++it) add(*it);
3450 }
3451 void add(expr const& e, expr const& t) {
3452 assert(e.is_bool());
3453 Z3_optimize_assert_and_track(ctx(), m_opt, e, t);
3454 }
3455 void add(expr const& e, char const* p) {
3456 assert(e.is_bool());
3457 add(e, ctx().bool_const(p));
3458 }
3459 handle add_soft(expr const& e, unsigned weight) {
3460 assert(e.is_bool());
3461 auto str = std::to_string(weight);
3462 return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, str.c_str(), 0));
3463 }
3464 handle add_soft(expr const& e, char const* weight) {
3465 assert(e.is_bool());
3466 return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, weight, 0));
3467 }
3468 handle add(expr const& e, unsigned weight) {
3469 return add_soft(e, weight);
3470 }
3471 void set_initial_value(expr const& var, expr const& value) {
3472 Z3_optimize_set_initial_value(ctx(), m_opt, var, value);
3473 check_error();
3474 }
3475 void set_initial_value(expr const& var, int i) {
3476 set_initial_value(var, ctx().num_val(i, var.get_sort()));
3477 }
3478 void set_initial_value(expr const& var, bool b) {
3479 set_initial_value(var, ctx().bool_val(b));
3480 }
3481
3483 return handle(Z3_optimize_maximize(ctx(), m_opt, e));
3484 }
3486 return handle(Z3_optimize_minimize(ctx(), m_opt, e));
3487 }
3488 void push() {
3489 Z3_optimize_push(ctx(), m_opt);
3490 }
3491 void pop() {
3492 Z3_optimize_pop(ctx(), m_opt);
3493 }
3496 unsigned n = asms.size();
3498 for (unsigned i = 0; i < n; i++) {
3499 check_context(*this, asms[i]);
3500 _asms[i] = asms[i];
3501 }
3502 Z3_lbool r = Z3_optimize_check(ctx(), m_opt, n, _asms.ptr());
3503 check_error();
3504 return to_check_result(r);
3505 }
3506 model get_model() const { Z3_model m = Z3_optimize_get_model(ctx(), m_opt); check_error(); return model(ctx(), m); }
3507 expr_vector unsat_core() const { Z3_ast_vector r = Z3_optimize_get_unsat_core(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
3508 void set(params const & p) { Z3_optimize_set_params(ctx(), m_opt, p); check_error(); }
3509 expr lower(handle const& h) {
3510 Z3_ast r = Z3_optimize_get_lower(ctx(), m_opt, h.h());
3511 check_error();
3512 return expr(ctx(), r);
3513 }
3514 expr upper(handle const& h) {
3515 Z3_ast r = Z3_optimize_get_upper(ctx(), m_opt, h.h());
3516 check_error();
3517 return expr(ctx(), r);
3518 }
3519 expr_vector assertions() const { Z3_ast_vector r = Z3_optimize_get_assertions(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
3520 expr_vector objectives() const { Z3_ast_vector r = Z3_optimize_get_objectives(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
3521 stats statistics() const { Z3_stats r = Z3_optimize_get_statistics(ctx(), m_opt); check_error(); return stats(ctx(), r); }
3522 friend std::ostream & operator<<(std::ostream & out, optimize const & s);
3525 std::string help() const { char const * r = Z3_optimize_get_help(ctx(), m_opt); check_error(); return r; }
3526 };
3527 inline std::ostream & operator<<(std::ostream & out, optimize const & s) { out << Z3_optimize_to_string(s.ctx(), s.m_opt); return out; }
3528
3529 class fixedpoint : public object {
3530 Z3_fixedpoint m_fp;
3531 public:
3533 fixedpoint(fixedpoint const & o):object(o), m_fp(o.m_fp) { Z3_fixedpoint_inc_ref(ctx(), m_fp); }
3534 ~fixedpoint() override { Z3_fixedpoint_dec_ref(ctx(), m_fp); }
3536 Z3_fixedpoint_inc_ref(o.ctx(), o.m_fp);
3537 Z3_fixedpoint_dec_ref(ctx(), m_fp);
3538 m_fp = o.m_fp;
3539 object::operator=(o);
3540 return *this;
3541 }
3542 operator Z3_fixedpoint() const { return m_fp; }
3543 expr_vector from_string(char const* s) {
3544 Z3_ast_vector r = Z3_fixedpoint_from_string(ctx(), m_fp, s);
3545 check_error();
3546 return expr_vector(ctx(), r);
3547 }
3548 expr_vector from_file(char const* s) {
3549 Z3_ast_vector r = Z3_fixedpoint_from_file(ctx(), m_fp, s);
3550 check_error();
3551 return expr_vector(ctx(), r);
3552 }
3553 void add_rule(expr& rule, symbol const& name) { Z3_fixedpoint_add_rule(ctx(), m_fp, rule, name); check_error(); }
3554 void add_fact(func_decl& f, unsigned * args) { Z3_fixedpoint_add_fact(ctx(), m_fp, f, f.arity(), args); check_error(); }
3562 expr get_answer() { Z3_ast r = Z3_fixedpoint_get_answer(ctx(), m_fp); check_error(); return expr(ctx(), r); }
3563 std::string reason_unknown() { return Z3_fixedpoint_get_reason_unknown(ctx(), m_fp); }
3564 void update_rule(expr& rule, symbol const& name) { Z3_fixedpoint_update_rule(ctx(), m_fp, rule, name); check_error(); }
3565 unsigned get_num_levels(func_decl& p) { unsigned r = Z3_fixedpoint_get_num_levels(ctx(), m_fp, p); check_error(); return r; }
3567 Z3_ast r = Z3_fixedpoint_get_cover_delta(ctx(), m_fp, level, p);
3568 check_error();
3569 return expr(ctx(), r);
3570 }
3572 stats statistics() const { Z3_stats r = Z3_fixedpoint_get_statistics(ctx(), m_fp); check_error(); return stats(ctx(), r); }
3574 expr_vector assertions() const { Z3_ast_vector r = Z3_fixedpoint_get_assertions(ctx(), m_fp); check_error(); return expr_vector(ctx(), r); }
3575 expr_vector rules() const { Z3_ast_vector r = Z3_fixedpoint_get_rules(ctx(), m_fp); check_error(); return expr_vector(ctx(), r); }
3576 void set(params const & p) { Z3_fixedpoint_set_params(ctx(), m_fp, p); check_error(); }
3577 std::string help() const { return Z3_fixedpoint_get_help(ctx(), m_fp); }
3579 std::string to_string() { return Z3_fixedpoint_to_string(ctx(), m_fp, 0, 0); }
3580 std::string to_string(expr_vector const& queries) {
3582 return Z3_fixedpoint_to_string(ctx(), m_fp, qs.size(), qs.ptr());
3583 }
3584 };
3585 inline std::ostream & operator<<(std::ostream & out, fixedpoint const & f) { return out << Z3_fixedpoint_to_string(f.ctx(), f, 0, 0); }
3586
3587 inline tactic fail_if(probe const & p) {
3588 Z3_tactic r = Z3_tactic_fail_if(p.ctx(), p);
3589 p.check_error();
3590 return tactic(p.ctx(), r);
3591 }
3592 inline tactic when(probe const & p, tactic const & t) {
3593 check_context(p, t);
3594 Z3_tactic r = Z3_tactic_when(t.ctx(), p, t);
3595 t.check_error();
3596 return tactic(t.ctx(), r);
3597 }
3598 inline tactic cond(probe const & p, tactic const & t1, tactic const & t2) {
3600 Z3_tactic r = Z3_tactic_cond(t1.ctx(), p, t1, t2);
3601 t1.check_error();
3602 return tactic(t1.ctx(), r);
3603 }
3604
3605 inline symbol context::str_symbol(char const * s) { Z3_symbol r = Z3_mk_string_symbol(m_ctx, s); check_error(); return symbol(*this, r); }
3606 inline symbol context::int_symbol(int n) { Z3_symbol r = Z3_mk_int_symbol(m_ctx, n); check_error(); return symbol(*this, r); }
3607
3608 inline sort context::bool_sort() { Z3_sort s = Z3_mk_bool_sort(m_ctx); check_error(); return sort(*this, s); }
3609 inline sort context::int_sort() { Z3_sort s = Z3_mk_int_sort(m_ctx); check_error(); return sort(*this, s); }
3610 inline sort context::real_sort() { Z3_sort s = Z3_mk_real_sort(m_ctx); check_error(); return sort(*this, s); }
3611 inline sort context::bv_sort(unsigned sz) { Z3_sort s = Z3_mk_bv_sort(m_ctx, sz); check_error(); return sort(*this, s); }
3612 inline sort context::string_sort() { Z3_sort s = Z3_mk_string_sort(m_ctx); check_error(); return sort(*this, s); }
3613 inline sort context::char_sort() { Z3_sort s = Z3_mk_char_sort(m_ctx); check_error(); return sort(*this, s); }
3614 inline sort context::seq_sort(sort& s) { Z3_sort r = Z3_mk_seq_sort(m_ctx, s); check_error(); return sort(*this, r); }
3615 inline sort context::re_sort(sort& s) { Z3_sort r = Z3_mk_re_sort(m_ctx, s); check_error(); return sort(*this, r); }
3616 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); }
3617
3618 template<>
3619 inline sort context::fpa_sort<16>() { return fpa_sort(5, 11); }
3620
3621 template<>
3622 inline sort context::fpa_sort<32>() { return fpa_sort(8, 24); }
3623
3624 template<>
3625 inline sort context::fpa_sort<64>() { return fpa_sort(11, 53); }
3626
3627 template<>
3628 inline sort context::fpa_sort<128>() { return fpa_sort(15, 113); }
3629
3630 inline sort context::fpa_rounding_mode_sort() { Z3_sort r = Z3_mk_fpa_rounding_mode_sort(m_ctx); check_error(); return sort(*this, r); }
3631
3632 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); }
3635 Z3_sort s = Z3_mk_array_sort_n(m_ctx, dom.size(), dom.ptr(), r); check_error(); return sort(*this, s);
3636 }
3637 inline sort context::enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts) {
3639 for (unsigned i = 0; i < n; i++) { _enum_names[i] = Z3_mk_string_symbol(*this, enum_names[i]); }
3642 Z3_symbol _name = Z3_mk_string_symbol(*this, name);
3643 sort s = to_sort(*this, Z3_mk_enumeration_sort(*this, _name, n, _enum_names.ptr(), _cs.ptr(), _ts.ptr()));
3644 check_error();
3645 for (unsigned i = 0; i < n; i++) { cs.push_back(func_decl(*this, _cs[i])); ts.push_back(func_decl(*this, _ts[i])); }
3646 return s;
3647 }
3648 inline func_decl context::tuple_sort(char const * name, unsigned n, char const * const * names, sort const* sorts, func_decl_vector & projs) {
3651 for (unsigned i = 0; i < n; i++) { _names[i] = Z3_mk_string_symbol(*this, names[i]); _sorts[i] = sorts[i]; }
3653 Z3_symbol _name = Z3_mk_string_symbol(*this, name);
3654 Z3_func_decl tuple;
3655 sort _ignore_s = to_sort(*this, Z3_mk_tuple_sort(*this, _name, n, _names.ptr(), _sorts.ptr(), &tuple, _projs.ptr()));
3656 check_error();
3657 for (unsigned i = 0; i < n; i++) { projs.push_back(func_decl(*this, _projs[i])); }
3658 return func_decl(*this, tuple);
3659 }
3660
3662 context& ctx;
3663 Z3_constructor_list clist;
3664 public:
3667 operator Z3_constructor_list() const { return clist; }
3668 };
3669
3671 friend class constructor_list;
3672 context& ctx;
3673 std::vector<Z3_constructor> cons;
3674 std::vector<unsigned> num_fields;
3675 public:
3676 constructors(context& ctx): ctx(ctx) {}
3677
3679 for (auto con : cons)
3680 Z3_del_constructor(ctx, con);
3681 }
3682
3683 void add(symbol const& name, symbol const& rec, unsigned n, symbol const* names, sort const* fields) {
3685 array<Z3_sort> sorts(n);
3687 for (unsigned i = 0; i < n; ++i) sorts[i] = fields[i], _names[i] = names[i];
3688 cons.push_back(Z3_mk_constructor(ctx, name, rec, n, _names.ptr(), sorts.ptr(), sort_refs.ptr()));
3689 num_fields.push_back(n);
3690 }
3691
3692 Z3_constructor operator[](unsigned i) const { return cons[i]; }
3693
3694 unsigned size() const { return (unsigned)cons.size(); }
3695
3696 void query(unsigned i, func_decl& constructor, func_decl& test, func_decl_vector& accs) {
3697 Z3_func_decl _constructor;
3698 Z3_func_decl _test;
3699 array<Z3_func_decl> accessors(num_fields[i]);
3700 accs.resize(0);
3702 cons[i],
3703 num_fields[i],
3704 &_constructor,
3705 &_test,
3706 accessors.ptr());
3707 constructor = func_decl(ctx, _constructor);
3708
3709 test = func_decl(ctx, _test);
3710 for (unsigned j = 0; j < num_fields[i]; ++j)
3711 accs.push_back(func_decl(ctx, accessors[j]));
3712 }
3713 };
3714
3716 array<Z3_constructor> cons(cs.size());
3717 for (unsigned i = 0; i < cs.size(); ++i)
3718 cons[i] = cs[i];
3719 clist = Z3_mk_constructor_list(ctx, cs.size(), cons.ptr());
3720 }
3721
3722 inline sort context::datatype(symbol const& name, constructors const& cs) {
3724 for (unsigned i = 0; i < cs.size(); ++i) _cs[i] = cs[i];
3725 Z3_sort s = Z3_mk_datatype(*this, name, cs.size(), _cs.ptr());
3726 check_error();
3727 return sort(*this, s);
3728 }
3729
3730 inline sort context::datatype(symbol const &name, sort_vector const& params, constructors const &cs) {
3733 for (unsigned i = 0; i < cs.size(); ++i)
3734 _cs[i] = cs[i];
3735 Z3_sort s = Z3_mk_polymorphic_datatype(*this, name, _params.size(), _params.ptr(), cs.size(), _cs.ptr());
3736 check_error();
3737 return sort(*this, s);
3738 }
3739
3741 unsigned n, symbol const* names,
3742 constructor_list *const* cons) {
3743 sort_vector result(*this);
3747 for (unsigned i = 0; i < n; ++i)
3748 _names[i] = names[i], _cons[i] = *cons[i];
3749 Z3_mk_datatypes(*this, n, _names.ptr(), _sorts.ptr(), _cons.ptr());
3750 for (unsigned i = 0; i < n; ++i)
3751 result.push_back(sort(*this, _sorts[i]));
3752 return result;
3753 }
3754
3755
3756 inline sort context::datatype_sort(symbol const& name) {
3757 Z3_sort s = Z3_mk_datatype_sort(*this, name, 0, nullptr);
3758 check_error();
3759 return sort(*this, s);
3760 }
3761
3764 Z3_sort s = Z3_mk_datatype_sort(*this, name, _params.size(), _params.ptr());
3765 check_error();
3766 return sort(*this, s);
3767 }
3768
3769
3770 inline sort context::uninterpreted_sort(char const* name) {
3771 Z3_symbol _name = Z3_mk_string_symbol(*this, name);
3772 return to_sort(*this, Z3_mk_uninterpreted_sort(*this, _name));
3773 }
3775 return to_sort(*this, Z3_mk_uninterpreted_sort(*this, name));
3776 }
3777
3778 inline func_decl context::function(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
3779 array<Z3_sort> args(arity);
3780 for (unsigned i = 0; i < arity; i++) {
3781 check_context(domain[i], range);
3782 args[i] = domain[i];
3783 }
3784 Z3_func_decl f = Z3_mk_func_decl(m_ctx, name, arity, args.ptr(), range);
3785 check_error();
3786 return func_decl(*this, f);
3787 }
3788
3789 inline func_decl context::function(char const * name, unsigned arity, sort const * domain, sort const & range) {
3790 return function(range.ctx().str_symbol(name), arity, domain, range);
3791 }
3792
3793 inline func_decl context::function(symbol const& name, sort_vector const& domain, sort const& range) {
3794 array<Z3_sort> args(domain.size());
3795 for (unsigned i = 0; i < domain.size(); i++) {
3796 check_context(domain[i], range);
3797 args[i] = domain[i];
3798 }
3799 Z3_func_decl f = Z3_mk_func_decl(m_ctx, name, domain.size(), args.ptr(), range);
3800 check_error();
3801 return func_decl(*this, f);
3802 }
3803
3804 inline func_decl context::function(char const * name, sort_vector const& domain, sort const& range) {
3805 return function(range.ctx().str_symbol(name), domain, range);
3806 }
3807
3808
3809 inline func_decl context::function(char const * name, sort const & domain, sort const & range) {
3810 check_context(domain, range);
3811 Z3_sort args[1] = { domain };
3812 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 1, args, range);
3813 check_error();
3814 return func_decl(*this, f);
3815 }
3816
3817 inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & range) {
3819 Z3_sort args[2] = { d1, d2 };
3820 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 2, args, range);
3821 check_error();
3822 return func_decl(*this, f);
3823 }
3824
3825 inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & range) {
3827 Z3_sort args[3] = { d1, d2, d3 };
3828 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 3, args, range);
3829 check_error();
3830 return func_decl(*this, f);
3831 }
3832
3833 inline func_decl context::function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & range) {
3835 Z3_sort args[4] = { d1, d2, d3, d4 };
3836 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 4, args, range);
3837 check_error();
3838 return func_decl(*this, f);
3839 }
3840
3841 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) {
3843 Z3_sort args[5] = { d1, d2, d3, d4, d5 };
3844 Z3_func_decl f = Z3_mk_func_decl(m_ctx, str_symbol(name), 5, args, range);
3845 check_error();
3846 return func_decl(*this, f);
3847 }
3848
3849 inline func_decl context::recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
3850 array<Z3_sort> args(arity);
3851 for (unsigned i = 0; i < arity; i++) {
3852 check_context(domain[i], range);
3853 args[i] = domain[i];
3854 }
3855 Z3_func_decl f = Z3_mk_rec_func_decl(m_ctx, name, arity, args.ptr(), range);
3856 check_error();
3857 return func_decl(*this, f);
3858
3859 }
3860
3861 inline func_decl context::recfun(symbol const & name, sort_vector const& domain, sort const & range) {
3862 check_context(domain, range);
3863 array<Z3_sort> domain1(domain);
3864 Z3_func_decl f = Z3_mk_rec_func_decl(m_ctx, name, domain1.size(), domain1.ptr(), range);
3865 check_error();
3866 return func_decl(*this, f);
3867 }
3868
3869 inline func_decl context::recfun(char const * name, sort_vector const& domain, sort const & range) {
3870 return recfun(str_symbol(name), domain, range);
3871
3872 }
3873
3874 inline func_decl context::recfun(char const * name, unsigned arity, sort const * domain, sort const & range) {
3875 return recfun(str_symbol(name), arity, domain, range);
3876 }
3877
3878 inline func_decl context::recfun(char const * name, sort const& d1, sort const & range) {
3879 return recfun(str_symbol(name), 1, &d1, range);
3880 }
3881
3882 inline func_decl context::recfun(char const * name, sort const& d1, sort const& d2, sort const & range) {
3883 sort dom[2] = { d1, d2 };
3884 return recfun(str_symbol(name), 2, dom, range);
3885 }
3886
3887 inline void context::recdef(func_decl f, expr_vector const& args, expr const& body) {
3888 check_context(f, args); check_context(f, body);
3889 array<Z3_ast> vars(args);
3890 Z3_add_rec_def(f.ctx(), f, vars.size(), vars.ptr(), body);
3891 }
3892
3893 inline func_decl context::user_propagate_function(symbol const& name, sort_vector const& domain, sort const& range) {
3894 check_context(domain, range);
3895 array<Z3_sort> domain1(domain);
3896 Z3_func_decl f = Z3_solver_propagate_declare(range.ctx(), name, domain1.size(), domain1.ptr(), range);
3897 check_error();
3898 return func_decl(*this, f);
3899 }
3900
3901 inline expr context::constant(symbol const & name, sort const & s) {
3902 Z3_ast r = Z3_mk_const(m_ctx, name, s);
3903 check_error();
3904 return expr(*this, r);
3905 }
3906 inline expr context::constant(char const * name, sort const & s) { return constant(str_symbol(name), s); }
3907 inline expr context::variable(unsigned idx, sort const& s) {
3908 Z3_ast r = Z3_mk_bound(m_ctx, idx, s);
3909 check_error();
3910 return expr(*this, r);
3911 }
3912 inline expr context::bool_const(char const * name) { return constant(name, bool_sort()); }
3913 inline expr context::int_const(char const * name) { return constant(name, int_sort()); }
3914 inline expr context::real_const(char const * name) { return constant(name, real_sort()); }
3915 inline expr context::string_const(char const * name) { return constant(name, string_sort()); }
3916 inline expr context::bv_const(char const * name, unsigned sz) { return constant(name, bv_sort(sz)); }
3917 inline expr context::fpa_const(char const * name, unsigned ebits, unsigned sbits) { return constant(name, fpa_sort(ebits, sbits)); }
3918
3919 template<size_t precision>
3920 inline expr context::fpa_const(char const * name) { return constant(name, fpa_sort<precision>()); }
3921
3922 inline void context::set_rounding_mode(rounding_mode rm) { m_rounding_mode = rm; }
3923
3925 switch (m_rounding_mode) {
3926 case RNA: return expr(*this, Z3_mk_fpa_rna(m_ctx));
3927 case RNE: return expr(*this, Z3_mk_fpa_rne(m_ctx));
3928 case RTP: return expr(*this, Z3_mk_fpa_rtp(m_ctx));
3929 case RTN: return expr(*this, Z3_mk_fpa_rtn(m_ctx));
3930 case RTZ: return expr(*this, Z3_mk_fpa_rtz(m_ctx));
3931 default: return expr(*this);
3932 }
3933 }
3934
3935 inline expr context::bool_val(bool b) { return b ? expr(*this, Z3_mk_true(m_ctx)) : expr(*this, Z3_mk_false(m_ctx)); }
3936
3937 inline expr context::int_val(int n) { Z3_ast r = Z3_mk_int(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
3938 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); }
3939 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); }
3940 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); }
3941 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); }
3942
3943 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); }
3944 inline expr context::real_val(int n) { Z3_ast r = Z3_mk_int(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
3945 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); }
3946 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); }
3947 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); }
3948 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); }
3949
3950 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); }
3951 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); }
3952 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); }
3953 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); }
3954 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); }
3955 inline expr context::bv_val(unsigned n, bool const* bits) {
3956 array<bool> _bits(n);
3957 for (unsigned i = 0; i < n; ++i) _bits[i] = bits[i] ? 1 : 0;
3958 Z3_ast r = Z3_mk_bv_numeral(m_ctx, n, _bits.ptr()); check_error(); return expr(*this, r);
3959 }
3960
3961 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); }
3962 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); }
3963 inline expr context::fpa_nan(sort const & s) { Z3_ast r = Z3_mk_fpa_nan(m_ctx, s); check_error(); return expr(*this, r); }
3964 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); }
3965
3966 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); }
3967 inline expr context::string_val(char const* s) { Z3_ast r = Z3_mk_string(m_ctx, s); check_error(); return expr(*this, r); }
3968 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); }
3969 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); }
3970
3971 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); }
3972
3973 inline expr func_decl::operator()(unsigned n, expr const * args) const {
3975 for (unsigned i = 0; i < n; i++) {
3976 check_context(*this, args[i]);
3977 _args[i] = args[i];
3978 }
3979 Z3_ast r = Z3_mk_app(ctx(), *this, n, _args.ptr());
3980 check_error();
3981 return expr(ctx(), r);
3982
3983 }
3984 inline expr func_decl::operator()(expr_vector const& args) const {
3985 array<Z3_ast> _args(args.size());
3986 for (unsigned i = 0; i < args.size(); i++) {
3987 check_context(*this, args[i]);
3988 _args[i] = args[i];
3989 }
3990 Z3_ast r = Z3_mk_app(ctx(), *this, args.size(), _args.ptr());
3991 check_error();
3992 return expr(ctx(), r);
3993 }
3995 Z3_ast r = Z3_mk_app(ctx(), *this, 0, 0);
3996 ctx().check_error();
3997 return expr(ctx(), r);
3998 }
3999 inline expr func_decl::operator()(expr const & a) const {
4000 check_context(*this, a);
4001 Z3_ast args[1] = { a };
4002 Z3_ast r = Z3_mk_app(ctx(), *this, 1, args);
4003 ctx().check_error();
4004 return expr(ctx(), r);
4005 }
4006 inline expr func_decl::operator()(int a) const {
4007 Z3_ast args[1] = { ctx().num_val(a, domain(0)) };
4008 Z3_ast r = Z3_mk_app(ctx(), *this, 1, args);
4009 ctx().check_error();
4010 return expr(ctx(), r);
4011 }
4012 inline expr func_decl::operator()(expr const & a1, expr const & a2) const {
4013 check_context(*this, a1); check_context(*this, a2);
4014 Z3_ast args[2] = { a1, a2 };
4015 Z3_ast r = Z3_mk_app(ctx(), *this, 2, args);
4016 ctx().check_error();
4017 return expr(ctx(), r);
4018 }
4019 inline expr func_decl::operator()(expr const & a1, int a2) const {
4020 check_context(*this, a1);
4021 Z3_ast args[2] = { a1, ctx().num_val(a2, domain(1)) };
4022 Z3_ast r = Z3_mk_app(ctx(), *this, 2, args);
4023 ctx().check_error();
4024 return expr(ctx(), r);
4025 }
4026 inline expr func_decl::operator()(int a1, expr const & a2) const {
4027 check_context(*this, a2);
4028 Z3_ast args[2] = { ctx().num_val(a1, domain(0)), a2 };
4029 Z3_ast r = Z3_mk_app(ctx(), *this, 2, args);
4030 ctx().check_error();
4031 return expr(ctx(), r);
4032 }
4033 inline expr func_decl::operator()(expr const & a1, expr const & a2, expr const & a3) const {
4034 check_context(*this, a1); check_context(*this, a2); check_context(*this, a3);
4035 Z3_ast args[3] = { a1, a2, a3 };
4036 Z3_ast r = Z3_mk_app(ctx(), *this, 3, args);
4037 ctx().check_error();
4038 return expr(ctx(), r);
4039 }
4040 inline expr func_decl::operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4) const {
4041 check_context(*this, a1); check_context(*this, a2); check_context(*this, a3); check_context(*this, a4);
4042 Z3_ast args[4] = { a1, a2, a3, a4 };
4043 Z3_ast r = Z3_mk_app(ctx(), *this, 4, args);
4044 ctx().check_error();
4045 return expr(ctx(), r);
4046 }
4047 inline expr func_decl::operator()(expr const & a1, expr const & a2, expr const & a3, expr const & a4, expr const & a5) const {
4048 check_context(*this, a1); check_context(*this, a2); check_context(*this, a3); check_context(*this, a4); check_context(*this, a5);
4049 Z3_ast args[5] = { a1, a2, a3, a4, a5 };
4050 Z3_ast r = Z3_mk_app(ctx(), *this, 5, args);
4051 ctx().check_error();
4052 return expr(ctx(), r);
4053 }
4054
4055 inline expr to_real(expr const & a) { Z3_ast r = Z3_mk_int2real(a.ctx(), a); a.check_error(); return expr(a.ctx(), r); }
4056
4057 inline func_decl function(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
4058 return range.ctx().function(name, arity, domain, range);
4059 }
4060 inline func_decl function(char const * name, unsigned arity, sort const * domain, sort const & range) {
4061 return range.ctx().function(name, arity, domain, range);
4062 }
4063 inline func_decl function(char const * name, sort const & domain, sort const & range) {
4064 return range.ctx().function(name, domain, range);
4065 }
4066 inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & range) {
4067 return range.ctx().function(name, d1, d2, range);
4068 }
4069 inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & range) {
4070 return range.ctx().function(name, d1, d2, d3, range);
4071 }
4072 inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & range) {
4073 return range.ctx().function(name, d1, d2, d3, d4, range);
4074 }
4075 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) {
4076 return range.ctx().function(name, d1, d2, d3, d4, d5, range);
4077 }
4078 inline func_decl function(char const* name, sort_vector const& domain, sort const& range) {
4079 return range.ctx().function(name, domain, range);
4080 }
4081 inline func_decl function(std::string const& name, sort_vector const& domain, sort const& range) {
4082 return range.ctx().function(name.c_str(), domain, range);
4083 }
4084
4085 inline func_decl recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
4086 return range.ctx().recfun(name, arity, domain, range);
4087 }
4088 inline func_decl recfun(char const * name, unsigned arity, sort const * domain, sort const & range) {
4089 return range.ctx().recfun(name, arity, domain, range);
4090 }
4091 inline func_decl recfun(char const * name, sort const& d1, sort const & range) {
4092 return range.ctx().recfun(name, d1, range);
4093 }
4094 inline func_decl recfun(char const * name, sort const& d1, sort const& d2, sort const & range) {
4095 return range.ctx().recfun(name, d1, d2, range);
4096 }
4097
4098 inline expr select(expr const & a, expr const & i) {
4099 check_context(a, i);
4100 Z3_ast r = Z3_mk_select(a.ctx(), a, i);
4101 a.check_error();
4102 return expr(a.ctx(), r);
4103 }
4104 inline expr select(expr const & a, int i) {
4105 return select(a, a.ctx().num_val(i, a.get_sort().array_domain()));
4106 }
4107 inline expr select(expr const & a, expr_vector const & i) {
4108 check_context(a, i);
4110 Z3_ast r = Z3_mk_select_n(a.ctx(), a, idxs.size(), idxs.ptr());
4111 a.check_error();
4112 return expr(a.ctx(), r);
4113 }
4114
4115 inline expr store(expr const & a, expr const & i, expr const & v) {
4117 Z3_ast r = Z3_mk_store(a.ctx(), a, i, v);
4118 a.check_error();
4119 return expr(a.ctx(), r);
4120 }
4121
4122 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); }
4123 inline expr store(expr const & a, expr i, int v) { return store(a, i, a.ctx().num_val(v, a.get_sort().array_range())); }
4124 inline expr store(expr const & a, int i, int v) {
4125 return store(a, a.ctx().num_val(i, a.get_sort().array_domain()), a.ctx().num_val(v, a.get_sort().array_range()));
4126 }
4127 inline expr store(expr const & a, expr_vector const & i, expr const & v) {
4130 Z3_ast r = Z3_mk_store_n(a.ctx(), a, idxs.size(), idxs.ptr(), v);
4131 a.check_error();
4132 return expr(a.ctx(), r);
4133 }
4134
4136 Z3_ast r = Z3_mk_as_array(f.ctx(), f);
4137 f.check_error();
4138 return expr(f.ctx(), r);
4139 }
4140
4141 inline expr array_default(expr const & a) {
4142 Z3_ast r = Z3_mk_array_default(a.ctx(), a);
4143 a.check_error();
4144 return expr(a.ctx(), r);
4145 }
4146
4147 inline expr array_ext(expr const & a, expr const & b) {
4148 check_context(a, b);
4149 Z3_ast r = Z3_mk_array_ext(a.ctx(), a, b);
4150 a.check_error();
4151 return expr(a.ctx(), r);
4152 }
4153
4154#define MK_EXPR1(_fn, _arg) \
4155 Z3_ast r = _fn(_arg.ctx(), _arg); \
4156 _arg.check_error(); \
4157 return expr(_arg.ctx(), r);
4158
4159#define MK_EXPR2(_fn, _arg1, _arg2) \
4160 check_context(_arg1, _arg2); \
4161 Z3_ast r = _fn(_arg1.ctx(), _arg1, _arg2); \
4162 _arg1.check_error(); \
4163 return expr(_arg1.ctx(), r);
4164
4165 inline expr const_array(sort const & d, expr const & v) {
4167 }
4168
4169 inline expr empty_set(sort const& s) {
4171 }
4172
4173 inline expr full_set(sort const& s) {
4175 }
4176
4177 inline expr set_add(expr const& s, expr const& e) {
4178 MK_EXPR2(Z3_mk_set_add, s, e);
4179 }
4180
4181 inline expr set_del(expr const& s, expr const& e) {
4182 MK_EXPR2(Z3_mk_set_del, s, e);
4183 }
4184
4185 inline expr set_union(expr const& a, expr const& b) {
4186 check_context(a, b);
4187 Z3_ast es[2] = { a, b };
4188 Z3_ast r = Z3_mk_set_union(a.ctx(), 2, es);
4189 a.check_error();
4190 return expr(a.ctx(), r);
4191 }
4192
4193 inline expr set_intersect(expr const& a, expr const& b) {
4194 check_context(a, b);
4195 Z3_ast es[2] = { a, b };
4196 Z3_ast r = Z3_mk_set_intersect(a.ctx(), 2, es);
4197 a.check_error();
4198 return expr(a.ctx(), r);
4199 }
4200
4201 inline expr set_difference(expr const& a, expr const& b) {
4203 }
4204
4205 inline expr set_complement(expr const& a) {
4207 }
4208
4209 inline expr set_member(expr const& s, expr const& e) {
4211 }
4212
4213 inline expr set_subset(expr const& a, expr const& b) {
4215 }
4216
4217 // sequence and regular expression operations.
4218 // union is +
4219 // concat is overloaded to handle sequences and regular expressions
4220
4221 inline expr empty(sort const& s) {
4222 Z3_ast r = Z3_mk_seq_empty(s.ctx(), s);
4223 s.check_error();
4224 return expr(s.ctx(), r);
4225 }
4226 inline expr suffixof(expr const& a, expr const& b) {
4227 check_context(a, b);
4228 Z3_ast r = Z3_mk_seq_suffix(a.ctx(), a, b);
4229 a.check_error();
4230 return expr(a.ctx(), r);
4231 }
4232 inline expr prefixof(expr const& a, expr const& b) {
4233 check_context(a, b);
4234 Z3_ast r = Z3_mk_seq_prefix(a.ctx(), a, b);
4235 a.check_error();
4236 return expr(a.ctx(), r);
4237 }
4238 inline expr indexof(expr const& s, expr const& substr, expr const& offset) {
4240 Z3_ast r = Z3_mk_seq_index(s.ctx(), s, substr, offset);
4241 s.check_error();
4242 return expr(s.ctx(), r);
4243 }
4244 inline expr last_indexof(expr const& s, expr const& substr) {
4245 check_context(s, substr);
4246 Z3_ast r = Z3_mk_seq_last_index(s.ctx(), s, substr);
4247 s.check_error();
4248 return expr(s.ctx(), r);
4249 }
4250 inline expr to_re(expr const& s) {
4252 }
4253 inline expr in_re(expr const& s, expr const& re) {
4255 }
4256 inline expr plus(expr const& re) {
4258 }
4259 inline expr option(expr const& re) {
4261 }
4262 inline expr star(expr const& re) {
4264 }
4265 inline expr re_empty(sort const& s) {
4266 Z3_ast r = Z3_mk_re_empty(s.ctx(), s);
4267 s.check_error();
4268 return expr(s.ctx(), r);
4269 }
4270 inline expr re_full(sort const& s) {
4271 Z3_ast r = Z3_mk_re_full(s.ctx(), s);
4272 s.check_error();
4273 return expr(s.ctx(), r);
4274 }
4275 inline expr re_intersect(expr_vector const& args) {
4276 assert(args.size() > 0);
4277 context& ctx = args[0u].ctx();
4278 array<Z3_ast> _args(args);
4279 Z3_ast r = Z3_mk_re_intersect(ctx, _args.size(), _args.ptr());
4280 ctx.check_error();
4281 return expr(ctx, r);
4282 }
4283 inline expr re_diff(expr const& a, expr const& b) {
4284 check_context(a, b);
4285 context& ctx = a.ctx();
4286 Z3_ast r = Z3_mk_re_diff(ctx, a, b);
4287 ctx.check_error();
4288 return expr(ctx, r);
4289 }
4290 inline expr re_complement(expr const& a) {
4292 }
4293 inline expr range(expr const& lo, expr const& hi) {
4294 check_context(lo, hi);
4295 Z3_ast r = Z3_mk_re_range(lo.ctx(), lo, hi);
4296 lo.check_error();
4297 return expr(lo.ctx(), r);
4298 }
4299
4300
4301
4302
4303
4304 inline expr_vector context::parse_string(char const* s) {
4305 Z3_ast_vector r = Z3_parse_smtlib2_string(*this, s, 0, 0, 0, 0, 0, 0);
4306 check_error();
4307 return expr_vector(*this, r);
4308
4309 }
4310 inline expr_vector context::parse_file(char const* s) {
4311 Z3_ast_vector r = Z3_parse_smtlib2_file(*this, s, 0, 0, 0, 0, 0, 0);
4312 check_error();
4313 return expr_vector(*this, r);
4314 }
4315
4316 inline expr_vector context::parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
4319 array<Z3_sort> sorts1(sorts);
4321 for (unsigned i = 0; i < sorts.size(); ++i) {
4322 sort_names[i] = sorts[i].name();
4323 }
4324 for (unsigned i = 0; i < decls.size(); ++i) {
4325 decl_names[i] = decls[i].name();
4326 }
4327
4328 Z3_ast_vector r = Z3_parse_smtlib2_string(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
4329 check_error();
4330 return expr_vector(*this, r);
4331 }
4332
4333 inline expr_vector context::parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
4336 array<Z3_sort> sorts1(sorts);
4338 for (unsigned i = 0; i < sorts.size(); ++i) {
4339 sort_names[i] = sorts[i].name();
4340 }
4341 for (unsigned i = 0; i < decls.size(); ++i) {
4342 decl_names[i] = decls[i].name();
4343 }
4344 Z3_ast_vector r = Z3_parse_smtlib2_file(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
4345 check_error();
4346 return expr_vector(*this, r);
4347 }
4348
4350 assert(is_datatype());
4352 unsigned n = Z3_get_datatype_sort_num_constructors(ctx(), *this);
4353 for (unsigned i = 0; i < n; ++i)
4354 cs.push_back(func_decl(ctx(), Z3_get_datatype_sort_constructor(ctx(), *this, i)));
4355 return cs;
4356 }
4357
4359 assert(is_datatype());
4361 unsigned n = Z3_get_datatype_sort_num_constructors(ctx(), *this);
4362 for (unsigned i = 0; i < n; ++i)
4363 rs.push_back(func_decl(ctx(), Z3_get_datatype_sort_recognizer(ctx(), *this, i)));
4364 return rs;
4365 }
4366
4368 sort s = range();
4369 assert(s.is_datatype());
4370 unsigned n = Z3_get_datatype_sort_num_constructors(ctx(), s);
4371 unsigned idx = 0;
4372 for (; idx < n; ++idx) {
4374 if (id() == f.id())
4375 break;
4376 }
4377 assert(idx < n);
4378 n = arity();
4380 for (unsigned i = 0; i < n; ++i)
4381 as.push_back(func_decl(ctx(), Z3_get_datatype_sort_constructor_accessor(ctx(), s, idx, i)));
4382 return as;
4383 }
4384
4385
4387 assert(src.size() == dst.size());
4388 array<Z3_ast> _src(src.size());
4389 array<Z3_ast> _dst(dst.size());
4390 for (unsigned i = 0; i < src.size(); ++i) {
4391 _src[i] = src[i];
4392 _dst[i] = dst[i];
4393 }
4394 Z3_ast r = Z3_substitute(ctx(), m_ast, src.size(), _src.ptr(), _dst.ptr());
4395 check_error();
4396 return expr(ctx(), r);
4397 }
4398
4400 array<Z3_ast> _dst(dst.size());
4401 for (unsigned i = 0; i < dst.size(); ++i) {
4402 _dst[i] = dst[i];
4403 }
4404 Z3_ast r = Z3_substitute_vars(ctx(), m_ast, dst.size(), _dst.ptr());
4405 check_error();
4406 return expr(ctx(), r);
4407 }
4408
4410 array<Z3_ast> _dst(dst.size());
4412 if (dst.size() != funs.size()) {
4413 Z3_THROW(exception("length of argument lists don't align"));
4414 return expr(ctx(), nullptr);
4415 }
4416 for (unsigned i = 0; i < dst.size(); ++i) {
4417 _dst[i] = dst[i];
4418 _funs[i] = funs[i];
4419 }
4420 Z3_ast r = Z3_substitute_funs(ctx(), m_ast, dst.size(), _funs.ptr(), _dst.ptr());
4421 check_error();
4422 return expr(ctx(), r);
4423 }
4424
4425 inline expr expr::update(expr_vector const& args) const {
4427 for (unsigned i = 0; i < args.size(); ++i) {
4428 _args[i] = args[i];
4429 }
4430 Z3_ast r = Z3_update_term(ctx(), m_ast, args.size(), _args.ptr());
4431 check_error();
4432 return expr(ctx(), r);
4433 }
4434
4435 typedef std::function<void(expr const& proof, std::vector<unsigned> const& deps, expr_vector const& clause)> on_clause_eh_t;
4436
4438 context& c;
4439 on_clause_eh_t m_on_clause;
4440
4441 static void _on_clause_eh(void* _ctx, Z3_ast _proof, unsigned n, unsigned const* dep, Z3_ast_vector _literals) {
4442 on_clause* ctx = static_cast<on_clause*>(_ctx);
4443 expr_vector lits(ctx->c, _literals);
4444 expr proof(ctx->c, _proof);
4445 std::vector<unsigned> deps;
4446 for (unsigned i = 0; i < n; ++i)
4447 deps.push_back(dep[i]);
4448 ctx->m_on_clause(proof, deps, lits);
4449 }
4450 public:
4451 on_clause(solver& s, on_clause_eh_t& on_clause_eh): c(s.ctx()) {
4452 m_on_clause = on_clause_eh;
4453 Z3_solver_register_on_clause(c, s, this, _on_clause_eh);
4454 c.check_error();
4455 }
4456 };
4457
4459
4460 typedef std::function<void(expr const&, expr const&)> fixed_eh_t;
4461 typedef std::function<void(void)> final_eh_t;
4462 typedef std::function<void(expr const&, expr const&)> eq_eh_t;
4463 typedef std::function<void(expr const&)> created_eh_t;
4464 typedef std::function<void(expr, unsigned, bool)> decide_eh_t;
4465 typedef std::function<bool(expr const&, expr const&)> on_binding_eh_t;
4466
4467 final_eh_t m_final_eh;
4468 eq_eh_t m_eq_eh;
4469 fixed_eh_t m_fixed_eh;
4470 created_eh_t m_created_eh;
4471 decide_eh_t m_decide_eh;
4472 on_binding_eh_t m_on_binding_eh;
4473 solver* s;
4474 context* c;
4475 std::vector<z3::context*> subcontexts;
4476
4477 unsigned m_callbackNesting = 0;
4478 Z3_solver_callback cb { nullptr };
4479
4480 struct scoped_cb {
4482 scoped_cb(void* _p, Z3_solver_callback cb):p(*static_cast<user_propagator_base*>(_p)) {
4483 p.cb = cb;
4484 p.m_callbackNesting++;
4485 }
4486 ~scoped_cb() {
4487 if (--p.m_callbackNesting == 0)
4488 p.cb = nullptr;
4489 }
4490 };
4491
4492 static void push_eh(void* _p, Z3_solver_callback cb) {
4493 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4494 scoped_cb _cb(p, cb);
4495 static_cast<user_propagator_base*>(p)->push();
4496 }
4497
4498 static void pop_eh(void* _p, Z3_solver_callback cb, unsigned num_scopes) {
4499 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4500 scoped_cb _cb(p, cb);
4501 static_cast<user_propagator_base*>(_p)->pop(num_scopes);
4502 }
4503
4504 static void* fresh_eh(void* _p, Z3_context ctx) {
4505 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4506 context* c = new context(ctx);
4507 p->subcontexts.push_back(c);
4508 return p->fresh(*c);
4509 }
4510
4511 static void fixed_eh(void* _p, Z3_solver_callback cb, Z3_ast _var, Z3_ast _value) {
4512 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4513 scoped_cb _cb(p, cb);
4514 expr value(p->ctx(), _value);
4515 expr var(p->ctx(), _var);
4516 p->m_fixed_eh(var, value);
4517 }
4518
4519 static void eq_eh(void* _p, Z3_solver_callback cb, Z3_ast _x, Z3_ast _y) {
4520 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4521 scoped_cb _cb(p, cb);
4522 expr x(p->ctx(), _x), y(p->ctx(), _y);
4523 p->m_eq_eh(x, y);
4524 }
4525
4526 static void final_eh(void* p, Z3_solver_callback cb) {
4527 scoped_cb _cb(p, cb);
4528 static_cast<user_propagator_base*>(p)->m_final_eh();
4529 }
4530
4531 static void created_eh(void* _p, Z3_solver_callback cb, Z3_ast _e) {
4532 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4533 scoped_cb _cb(p, cb);
4534 expr e(p->ctx(), _e);
4535 p->m_created_eh(e);
4536 }
4537
4538 static void decide_eh(void* _p, Z3_solver_callback cb, Z3_ast _val, unsigned bit, bool is_pos) {
4539 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4540 scoped_cb _cb(p, cb);
4541 expr val(p->ctx(), _val);
4542 p->m_decide_eh(val, bit, is_pos);
4543 }
4544
4545 static bool on_binding_eh(void* _p, Z3_solver_callback cb, Z3_ast _q, Z3_ast _inst) {
4546 user_propagator_base* p = static_cast<user_propagator_base*>(_p);
4547 scoped_cb _cb(p, cb);
4548 expr q(p->ctx(), _q), inst(p->ctx(), _inst);
4549 return p->m_on_binding_eh(q, inst);
4550 }
4551
4552 public:
4554
4556 Z3_solver_propagate_init(ctx(), *s, this, push_eh, pop_eh, fresh_eh);
4557 }
4558
4559 virtual void push() = 0;
4560 virtual void pop(unsigned num_scopes) = 0;
4561
4563 for (auto& subcontext : subcontexts) {
4564 subcontext->detach(); // detach first; the subcontexts will be freed internally!
4565 delete subcontext;
4566 }
4567 }
4568
4570 return c ? *c : s->ctx();
4571 }
4572
4582
4589 void register_fixed(fixed_eh_t& f) {
4590 m_fixed_eh = f;
4591 if (s) {
4592 Z3_solver_propagate_fixed(ctx(), *s, fixed_eh);
4593 }
4594 }
4595
4597 m_fixed_eh = [this](expr const &id, expr const &e) {
4598 fixed(id, e);
4599 };
4600 if (s) {
4601 Z3_solver_propagate_fixed(ctx(), *s, fixed_eh);
4602 }
4603 }
4604
4605 void register_eq(eq_eh_t& f) {
4606 m_eq_eh = f;
4607 if (s) {
4608 Z3_solver_propagate_eq(ctx(), *s, eq_eh);
4609 }
4610 }
4611
4613 m_eq_eh = [this](expr const& x, expr const& y) {
4614 eq(x, y);
4615 };
4616 if (s) {
4617 Z3_solver_propagate_eq(ctx(), *s, eq_eh);
4618 }
4619 }
4620
4629 void register_final(final_eh_t& f) {
4630 m_final_eh = f;
4631 if (s) {
4632 Z3_solver_propagate_final(ctx(), *s, final_eh);
4633 }
4634 }
4635
4637 m_final_eh = [this]() {
4638 final();
4639 };
4640 if (s) {
4641 Z3_solver_propagate_final(ctx(), *s, final_eh);
4642 }
4643 }
4644
4645 void register_created(created_eh_t& c) {
4646 m_created_eh = c;
4647 if (s) {
4648 Z3_solver_propagate_created(ctx(), *s, created_eh);
4649 }
4650 }
4651
4653 m_created_eh = [this](expr const& e) {
4654 created(e);
4655 };
4656 if (s) {
4657 Z3_solver_propagate_created(ctx(), *s, created_eh);
4658 }
4659 }
4660
4661 void register_decide(decide_eh_t& c) {
4662 m_decide_eh = c;
4663 if (s) {
4664 Z3_solver_propagate_decide(ctx(), *s, decide_eh);
4665 }
4666 }
4667
4669 m_decide_eh = [this](expr val, unsigned bit, bool is_pos) {
4670 decide(val, bit, is_pos);
4671 };
4672 if (s) {
4673 Z3_solver_propagate_decide(ctx(), *s, decide_eh);
4674 }
4675 }
4676
4678 m_on_binding_eh = [this](expr const& q, expr const& inst) {
4679 return on_binding(q, inst);
4680 };
4681 if (s)
4682 Z3_solver_propagate_on_binding(ctx(), *s, on_binding_eh);
4683 }
4684
4685 virtual void fixed(expr const& /*id*/, expr const& /*e*/) { }
4686
4687 virtual void eq(expr const& /*x*/, expr const& /*y*/) { }
4688
4689 virtual void final() { }
4690
4691 virtual void created(expr const& /*e*/) {}
4692
4693 virtual void decide(expr const& /*val*/, unsigned /*bit*/, bool /*is_pos*/) {}
4694
4695 virtual bool on_binding(expr const& /*q*/, expr const& /*inst*/) { return true; }
4696
4697 bool next_split(expr const& e, unsigned idx, Z3_lbool phase) {
4698 assert(cb);
4699 return Z3_solver_next_split(ctx(), cb, e, idx, phase);
4700 }
4701
4716 void add(expr const& e) {
4717 if (cb)
4719 else if (s)
4721 else
4722 assert(false);
4723 }
4724
4726 assert(cb);
4727 expr conseq = ctx().bool_val(false);
4728 array<Z3_ast> _fixed(fixed);
4729 Z3_solver_propagate_consequence(ctx(), cb, fixed.size(), _fixed.ptr(), 0, nullptr, nullptr, conseq);
4730 }
4731
4732 void conflict(expr_vector const& fixed, expr_vector const& lhs, expr_vector const& rhs) {
4733 assert(cb);
4734 assert(lhs.size() == rhs.size());
4735 expr conseq = ctx().bool_val(false);
4736 array<Z3_ast> _fixed(fixed);
4739 Z3_solver_propagate_consequence(ctx(), cb, fixed.size(), _fixed.ptr(), lhs.size(), _lhs.ptr(), _rhs.ptr(), conseq);
4740 }
4741
4742 bool propagate(expr_vector const& fixed, expr const& conseq) {
4743 assert(cb);
4744 assert((Z3_context)conseq.ctx() == (Z3_context)ctx());
4745 array<Z3_ast> _fixed(fixed);
4746 return Z3_solver_propagate_consequence(ctx(), cb, _fixed.size(), _fixed.ptr(), 0, nullptr, nullptr, conseq);
4747 }
4748
4750 expr_vector const& lhs, expr_vector const& rhs,
4751 expr const& conseq) {
4752 assert(cb);
4753 assert((Z3_context)conseq.ctx() == (Z3_context)ctx());
4754 assert(lhs.size() == rhs.size());
4755 array<Z3_ast> _fixed(fixed);
4758
4759 return Z3_solver_propagate_consequence(ctx(), cb, _fixed.size(), _fixed.ptr(), lhs.size(), _lhs.ptr(), _rhs.ptr(), conseq);
4760 }
4761 };
4762
4763}
4764
4767#undef Z3_THROW
4768
unsigned size() const
Definition z3++.h:3197
apply_result & operator=(apply_result const &s)
Definition z3++.h:3190
apply_result(context &c, Z3_apply_result s)
Definition z3++.h:3186
goal operator[](int i) const
Definition z3++.h:3198
friend std::ostream & operator<<(std::ostream &out, apply_result const &r)
Definition z3++.h:3201
~apply_result() override
Definition z3++.h:3188
apply_result(apply_result const &s)
Definition z3++.h:3187
unsigned size() const
Definition z3++.h:508
void resize(unsigned sz)
Definition z3++.h:507
T const & operator[](int i) const
Definition z3++.h:510
array(unsigned sz)
Definition z3++.h:504
T const * ptr() const
Definition z3++.h:511
T * ptr()
Definition z3++.h:512
T & operator[](int i)
Definition z3++.h:509
iterator(ast_vector_tpl const *v, unsigned i)
Definition z3++.h:675
bool operator==(iterator const &other) const noexcept
Definition z3++.h:677
iterator operator++(int) noexcept
Definition z3++.h:690
bool operator!=(iterator const &other) const noexcept
Definition z3++.h:680
iterator & operator++() noexcept
Definition z3++.h:683
void pop_back()
Definition z3++.h:650
friend std::ostream & operator<<(std::ostream &out, ast_vector_tpl const &v)
Definition z3++.h:696
unsigned size() const
Definition z3++.h:645
void resize(unsigned sz)
Definition z3++.h:648
ast_vector_tpl & operator=(ast_vector_tpl const &s)
Definition z3++.h:652
~ast_vector_tpl() override
Definition z3++.h:643
ast_vector_tpl(ast_vector_tpl const &s)
Definition z3++.h:640
bool empty() const
Definition z3++.h:651
iterator end() const
Definition z3++.h:695
ast_vector_tpl(context &c, Z3_ast_vector v)
Definition z3++.h:639
void push_back(T const &e)
Definition z3++.h:647
T back() const
Definition z3++.h:649
std::string to_string() const
Definition z3++.h:697
T operator[](unsigned i) const
Definition z3++.h:646
ast_vector_tpl & set(unsigned idx, ast &a)
Definition z3++.h:659
ast_vector_tpl(context &c, ast_vector_tpl const &src)
Definition z3++.h:641
ast_vector_tpl(context &c)
Definition z3++.h:638
iterator begin() const noexcept
Definition z3++.h:694
friend std::ostream & operator<<(std::ostream &out, ast const &n)
Definition z3++.h:627
ast(ast const &s)
Definition z3++.h:604
~ast() override
Definition z3++.h:605
ast & operator=(ast const &s)
Definition z3++.h:608
friend bool eq(ast const &a, ast const &b)
Return true if the ASTs are structurally identical.
Definition z3++.h:631
Z3_ast_kind kind() const
Definition z3++.h:616
Z3_ast m_ast
Definition z3++.h:600
ast(context &c)
Definition z3++.h:602
std::string to_string() const
Definition z3++.h:619
ast(context &c, Z3_ast n)
Definition z3++.h:603
unsigned hash() const
Definition z3++.h:617
ast operator()(context &c, Z3_ast a)
Definition z3++.h:2363
expr operator()(context &c, Z3_ast a)
Definition z3++.h:2368
func_decl operator()(context &c, Z3_ast a)
Definition z3++.h:2387
sort operator()(context &c, Z3_ast a)
Definition z3++.h:2379
Z3 global configuration object.
Definition z3++.h:140
~config()
Definition z3++.h:146
void set(char const *param, int value)
Set global parameter param with integer value.
Definition z3++.h:159
void set(char const *param, char const *value)
Set global parameter param with string value.
Definition z3++.h:151
config()
Definition z3++.h:145
void set(char const *param, bool value)
Set global parameter param with Boolean value.
Definition z3++.h:155
constructor_list(constructors const &cs)
Definition z3++.h:3715
void query(unsigned i, func_decl &constructor, func_decl &test, func_decl_vector &accs)
Definition z3++.h:3696
unsigned size() const
Definition z3++.h:3694
constructors(context &ctx)
Definition z3++.h:3676
Z3_constructor operator[](unsigned i) const
Definition z3++.h:3692
void add(symbol const &name, symbol const &rec, unsigned n, symbol const *names, sort const *fields)
Definition z3++.h:3683
A Context manages all other Z3 objects, global configuration options, etc.
Definition z3++.h:190
symbol str_symbol(char const *s)
Create a Z3 symbol based on the given string.
Definition z3++.h:3605
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:3887
expr num_val(int n, sort const &s)
Definition z3++.h:3971
expr fpa_rounding_mode()
Definition z3++.h:3924
context()
Definition z3++.h:214
expr bv_val(int n, unsigned sz)
Definition z3++.h:3950
func_decl recfun(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition z3++.h:3849
expr bool_val(bool b)
Definition z3++.h:3935
expr fpa_const(char const *name, unsigned ebits, unsigned sbits)
Definition z3++.h:3917
expr string_val(char const *s)
Definition z3++.h:3967
sort real_sort()
Return the Real sort.
Definition z3++.h:3610
Z3_error_code check_error() const
Auxiliary method used to check for API usage errors.
Definition z3++.h:222
expr bv_const(char const *name, unsigned sz)
Definition z3++.h:3916
expr string_const(char const *name)
Definition z3++.h:3915
sort array_sort(sort d, sort r)
Return an array sort for arrays from d to r.
Definition z3++.h:3632
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:240
sort string_sort()
Return the sort for Unicode strings.
Definition z3++.h:3612
sort re_sort(sort &seq_sort)
Return a regular expression sort over sequences seq_sort.
Definition z3++.h:3615
sort uninterpreted_sort(char const *name)
create an uninterpreted sort with the name given by the string or symbol.
Definition z3++.h:3770
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:3637
void set(char const *param, int value)
Update global parameter param with Integer value.
Definition z3++.h:255
sort bool_sort()
Return the Boolean sort.
Definition z3++.h:3608
void set(char const *param, char const *value)
Update global parameter param with string value.
Definition z3++.h:247
~context()
Definition z3++.h:216
expr bool_const(char const *name)
create uninterpreted constants of a given sort.
Definition z3++.h:3912
void check_parser_error() const
Definition z3++.h:229
expr variable(unsigned index, sort const &s)
create a de-Bruijn variable.
Definition z3++.h:3907
expr_vector parse_string(char const *s)
parsing
Definition z3++.h:4304
sort fpa_sort()
Definition z3++.h:3619
symbol int_symbol(int n)
Create a Z3 symbol based on the given integer.
Definition z3++.h:3606
expr real_const(char const *name)
Definition z3++.h:3914
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:3722
expr int_const(char const *name)
Definition z3++.h:3913
expr fpa_nan(sort const &s)
Definition z3++.h:3963
expr fpa_val(double n)
Definition z3++.h:3961
bool enable_exceptions() const
Definition z3++.h:242
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:3611
expr int_val(int n)
Definition z3++.h:3937
expr fpa_inf(sort const &s, bool sgn)
Definition z3++.h:3964
func_decl function(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition z3++.h:3778
sort fpa_rounding_mode_sort()
Return a RoundingMode sort.
Definition z3++.h:3630
expr_vector parse_file(char const *file)
Definition z3++.h:4310
expr constant(symbol const &name, sort const &s)
create an uninterpreted constant.
Definition z3++.h:3901
sort char_sort()
Return the sort for Unicode characters.
Definition z3++.h:3613
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:3648
void set(char const *param, bool value)
Update global parameter param with Boolean value.
Definition z3++.h:251
sort int_sort()
Return the integer sort.
Definition z3++.h:3609
void interrupt()
Interrupt the current procedure being executed by any object managed by this context....
Definition z3++.h:264
void set_rounding_mode(rounding_mode rm)
Sets RoundingMode of FloatingPoints.
Definition z3++.h:3922
func_decl user_propagate_function(symbol const &name, sort_vector const &domain, sort const &range)
Definition z3++.h:3893
sort fpa_sort()
Return a FloatingPoint sort with given precision bitwidth (16, 32, 64 or 128).
expr real_val(int n)
Definition z3++.h:3944
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:3740
sort datatype_sort(symbol const &name)
a reference to a recursively defined datatype. Expect that it gets defined as a datatype.
Definition z3++.h:3756
context(config &c)
Definition z3++.h:215
sort seq_sort(sort &s)
Return a sequence sort over base sort s.
Definition z3++.h:3614
Exception used to sign API usage errors.
Definition z3++.h:118
char const * what() const
Definition z3++.h:124
virtual ~exception()=default
friend std::ostream & operator<<(std::ostream &out, exception const &e)
Definition z3++.h:127
char const * msg() const
Definition z3++.h:123
bool operator==(iterator const &other) const noexcept
Definition z3++.h:1663
iterator operator++(int)
Definition z3++.h:1671
iterator(expr &e, unsigned i)
Definition z3++.h:1662
expr operator*() const
Definition z3++.h:1669
iterator & operator++()
Definition z3++.h:1670
bool operator!=(iterator const &other) const noexcept
Definition z3++.h:1666
A Z3 expression is used to represent formulas and terms. For Z3, a formula is any expression of sort ...
Definition z3++.h:858
bool is_lambda() const
Return true if this expression is a lambda expression.
Definition z3++.h:967
expr numerator() const
Definition z3++.h:1184
friend expr pw(expr const &a, expr const &b)
Definition z3++.h:1694
friend expr sbv_to_fpa(expr const &t, sort s)
Conversion of a signed bit-vector term into a floating-point.
Definition z3++.h:2118
friend expr bvneg_no_overflow(expr const &a)
Definition z3++.h:2319
expr loop(unsigned lo, unsigned hi)
Definition z3++.h:1612
expr body() const
Return the 'body' of this quantifier.
Definition z3++.h:1285
friend expr bvadd_no_underflow(expr const &a, expr const &b)
Definition z3++.h:2307
expr ubvtos() const
Definition z3++.h:1572
friend expr sum(expr_vector const &args)
Definition z3++.h:2516
expr substitute(expr_vector const &src, expr_vector const &dst)
Apply substitution. Replace src expressions by dst.
Definition z3++.h:4386
bool is_quantifier() const
Return true if this expression is a quantifier.
Definition z3++.h:954
bool is_exists() const
Return true if this expression is an existential quantifier.
Definition z3++.h:963
bool is_numeral_u64(uint64_t &i) const
Definition z3++.h:930
bool is_int() const
Return true if this is an integer expression.
Definition z3++.h:875
friend expr operator/(expr const &a, expr const &b)
Definition z3++.h:1860
friend expr fp_eq(expr const &a, expr const &b)
Definition z3++.h:2079
friend expr concat(expr const &a, expr const &b)
Definition z3++.h:2534
friend expr bvmul_no_underflow(expr const &a, expr const &b)
Definition z3++.h:2325
int64_t get_numeral_int64() const
Return int64_t value of numeral, throw if result cannot fit in int64_t.
Definition z3++.h:1152
bool is_app() const
Return true if this expression is an application.
Definition z3++.h:946
friend expr fpa_to_fpa(expr const &t, sort s)
Conversion of a floating-point term into another floating-point.
Definition z3++.h:2132
friend expr operator&&(expr const &a, expr const &b)
Return an expression representing a and b.
Definition z3++.h:1738
friend expr operator!=(expr const &a, expr const &b)
Definition z3++.h:1774
friend expr operator+(expr const &a, expr const &b)
Definition z3++.h:1786
std::string get_string() const
for a string value expression return an escaped string value.
Definition z3++.h:1211
bool is_numeral(std::string &s) const
Definition z3++.h:933
expr char_to_int() const
Definition z3++.h:1582
bool is_var() const
Return true if this expression is a variable.
Definition z3++.h:972
bool is_numeral_u(unsigned &i) const
Definition z3++.h:932
friend expr min(expr const &a, expr const &b)
Definition z3++.h:2008
expr at(expr const &index) const
Definition z3++.h:1545
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:1262
expr denominator() const
Definition z3++.h:1192
bool is_real() const
Return true if this is a real expression.
Definition z3++.h:879
bool is_numeral_i(int &i) const
Definition z3++.h:931
friend expr operator>(expr const &a, expr const &b)
Definition z3++.h:1971
expr mk_is_nan() const
Return Boolean expression to test for whether an FP expression is a NaN.
Definition z3++.h:996
int get_numeral_int() const
Return int value of numeral, throw if result cannot fit in machine int.
Definition z3++.h:1116
expr is_digit() const
Definition z3++.h:1597
friend expr bv2int(expr const &a, bool is_signed)
bit-vector and integer conversions.
Definition z3++.h:2298
friend expr operator~(expr const &a)
Definition z3++.h:2086
unsigned num_args() const
Return the number of arguments in this application. This method assumes the expression is an applicat...
Definition z3++.h:1247
friend expr nor(expr const &a, expr const &b)
Definition z3++.h:2006
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:2096
expr arg(unsigned i) const
Return the i-th argument of this application. This method assumes the expression is an application.
Definition z3++.h:1255
expr mk_is_normal() const
Return Boolean expression to test for whether an FP expression is a normal.
Definition z3++.h:1006
friend expr bvsub_no_underflow(expr const &a, expr const &b, bool is_signed)
Definition z3++.h:2313
expr repeat(unsigned i) const
Definition z3++.h:1464
bool is_true() const
Definition z3++.h:1351
expr(context &c)
Definition z3++.h:860
friend expr mk_xor(expr_vector const &args)
Definition z3++.h:2618
bool is_numeral(std::string &s, unsigned precision) const
Definition z3++.h:934
unsigned get_numeral_uint() const
Return uint value of numeral, throw if result cannot fit in machine uint.
Definition z3++.h:1135
bool is_distinct() const
Definition z3++.h:1360
bool is_numeral(double &d) const
Definition z3++.h:935
expr rotate_left(unsigned i) const
Definition z3++.h:1462
friend expr operator*(expr const &a, expr const &b)
Definition z3++.h:1816
sort get_sort() const
Return the sort of this expression.
Definition z3++.h:866
friend expr nand(expr const &a, expr const &b)
Definition z3++.h:2005
bool is_and() const
Definition z3++.h:1354
friend expr fpa_to_ubv(expr const &t, unsigned sz)
Conversion of a floating-point term into an unsigned bit-vector.
Definition z3++.h:2111
friend expr bvredor(expr const &a)
Definition z3++.h:2040
expr extract(unsigned hi, unsigned lo) const
Definition z3++.h:1474
expr rotate_right(unsigned i) const
Definition z3++.h:1463
friend expr int2bv(unsigned n, expr const &a)
Definition z3++.h:2299
friend expr max(expr const &a, expr const &b)
Definition z3++.h:2024
bool is_relation() const
Return true if this is a Relation expression.
Definition z3++.h:899
friend expr xnor(expr const &a, expr const &b)
Definition z3++.h:2007
friend expr abs(expr const &a)
Definition z3++.h:2052
friend expr pbge(expr_vector const &es, int const *coeffs, int bound)
Definition z3++.h:2484
bool is_well_sorted() const
Return true if this expression is well sorted (aka type correct).
Definition z3++.h:981
bool is_or() const
Definition z3++.h:1355
friend expr round_fpa_to_closest_integer(expr const &t)
Round a floating-point term into its closest integer.
Definition z3++.h:2139
friend expr distinct(expr_vector const &args)
Definition z3++.h:2525
friend expr bvmul_no_overflow(expr const &a, expr const &b, bool is_signed)
Definition z3++.h:2322
friend expr bvsub_no_overflow(expr const &a, expr const &b)
Definition z3++.h:2310
bool is_const() const
Return true if this expression is a constant (i.e., an application with 0 arguments).
Definition z3++.h:950
expr length() const
Definition z3++.h:1557
friend expr mod(expr const &a, expr const &b)
Definition z3++.h:1698
friend expr fma(expr const &a, expr const &b, expr const &c, expr const &rm)
FloatingPoint fused multiply-add.
Definition z3++.h:2088
bool is_bool() const
Return true if this is a Boolean expression.
Definition z3++.h:871
expr update(expr_vector const &args) const
Update the arguments of this application. Return a new expression with the same function declaration ...
Definition z3++.h:4425
friend expr mk_or(expr_vector const &args)
Definition z3++.h:2606
expr contains(expr const &s) const
Definition z3++.h:1539
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:2151
expr algebraic_lower(unsigned precision) const
Definition z3++.h:1067
unsigned hi() const
Definition z3++.h:1477
expr simplify() const
Return a simplified version of this expression.
Definition z3++.h:1636
bool is_arith() const
Return true if this is an integer or real expression.
Definition z3++.h:883
expr mk_is_inf() const
Return Boolean expression to test for whether an FP expression is inf.
Definition z3++.h:986
expr stoi() const
Definition z3++.h:1562
expr_vector algebraic_poly() const
Return coefficients for p of an algebraic number (root-obj p i)
Definition z3++.h:1084
bool is_ite() const
Definition z3++.h:1359
bool is_bv() const
Return true if this is a Bit-vector expression.
Definition z3++.h:887
friend expr pbeq(expr_vector const &es, int const *coeffs, int bound)
Definition z3++.h:2492
friend expr operator^(expr const &a, expr const &b)
Definition z3++.h:1997
friend expr operator<=(expr const &a, expr const &b)
Definition z3++.h:1924
friend expr operator>=(expr const &a, expr const &b)
Definition z3++.h:1840
friend expr sqrt(expr const &a, expr const &rm)
Definition z3++.h:2072
friend expr pble(expr_vector const &es, int const *coeffs, int bound)
Definition z3++.h:2476
friend expr operator==(expr const &a, expr const &b)
Definition z3++.h:1763
bool is_finite_domain() const
Return true if this is a Finite-domain expression.
Definition z3++.h:917
expr operator[](expr_vector const &index) const
Definition z3++.h:1629
bool is_forall() const
Return true if this expression is a universal quantifier.
Definition z3++.h:959
bool is_implies() const
Definition z3++.h:1357
uint64_t as_uint64() const
Definition z3++.h:939
friend expr implies(expr const &a, expr const &b)
Definition z3++.h:1686
expr mk_is_subnormal() const
Return Boolean expression to test for whether an FP expression is a subnormal.
Definition z3++.h:1016
uint64_t get_numeral_uint64() const
Return uint64_t value of numeral, throw if result cannot fit in uint64_t.
Definition z3++.h:1169
expr(context &c, Z3_ast n)
Definition z3++.h:861
friend expr bvadd_no_overflow(expr const &a, expr const &b, bool is_signed)
bit-vector overflow/underflow checks
Definition z3++.h:2304
bool is_datatype() const
Return true if this is a Datatype expression.
Definition z3++.h:895
bool is_not() const
Definition z3++.h:1353
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:1204
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:1640
expr loop(unsigned lo)
create a looping regular expression.
Definition z3++.h:1607
expr sbvtos() const
Definition z3++.h:1577
expr mk_from_ieee_bv(sort const &s) const
Convert this IEEE BV into a fpa.
Definition z3++.h:1046
friend expr bvredand(expr const &a)
Definition z3++.h:2046
friend expr operator&(expr const &a, expr const &b)
Definition z3++.h:1993
friend expr operator-(expr const &a)
Definition z3++.h:1882
friend expr bvsdiv_no_overflow(expr const &a, expr const &b)
Definition z3++.h:2316
expr extract(expr const &offset, expr const &length) const
sequence and regular expression operations.
Definition z3++.h:1524
bool is_eq() const
Definition z3++.h:1358
expr unit() const
Definition z3++.h:1534
bool is_re() const
Return true if this is a regular expression.
Definition z3++.h:907
bool is_numeral_i64(int64_t &i) const
Definition z3++.h:929
bool as_binary(std::string &s) const
Definition z3++.h:936
unsigned id() const
retrieve unique identifier for expression.
Definition z3++.h:1104
friend expr rem(expr const &a, expr const &b)
Definition z3++.h:1714
friend expr operator!(expr const &a)
Return an expression representing not(a).
Definition z3++.h:1732
bool is_algebraic() const
Return true if expression is an algebraic number.
Definition z3++.h:976
friend expr mk_and(expr_vector const &args)
Definition z3++.h:2612
expr itos() const
Definition z3++.h:1567
bool is_false() const
Definition z3++.h:1352
int64_t as_int64() const
Definition z3++.h:940
double as_double() const
Definition z3++.h:938
iterator end()
Definition z3++.h:1675
expr mk_is_zero() const
Return Boolean expression to test for whether an FP expression is a zero.
Definition z3++.h:1026
std::u32string get_u32string() const
for a string value expression return an unespaced string value.
Definition z3++.h:1223
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:1059
Z3_lbool bool_value() const
Definition z3++.h:1180
expr replace(expr const &src, expr const &dst) const
Definition z3++.h:1528
iterator begin()
Definition z3++.h:1674
friend expr operator||(expr const &a, expr const &b)
Return an expression representing a or b.
Definition z3++.h:1750
bool is_array() const
Return true if this is a Array expression.
Definition z3++.h:891
bool is_xor() const
Definition z3++.h:1356
unsigned algebraic_i() const
Return i of an algebraic number (root-obj p i)
Definition z3++.h:1094
unsigned lo() const
Definition z3++.h:1476
friend expr ubv_to_fpa(expr const &t, sort s)
Conversion of an unsigned bit-vector term into a floating-point.
Definition z3++.h:2125
expr nth(expr const &index) const
Definition z3++.h:1551
friend expr fpa_to_sbv(expr const &t, unsigned sz)
Conversion of a floating-point term into a signed bit-vector.
Definition z3++.h:2104
bool is_seq() const
Return true if this is a sequence expression.
Definition z3++.h:903
friend expr operator|(expr const &a, expr const &b)
Definition z3++.h:2001
expr bit2bool(unsigned i) const
Definition z3++.h:1475
friend expr atmost(expr_vector const &es, unsigned bound)
Definition z3++.h:2500
friend expr range(expr const &lo, expr const &hi)
Definition z3++.h:4293
expr char_from_bv() const
Definition z3++.h:1592
friend expr atleast(expr_vector const &es, unsigned bound)
Definition z3++.h:2508
friend expr operator<(expr const &a, expr const &b)
Definition z3++.h:1949
expr mk_to_ieee_bv() const
Convert this fpa into an IEEE BV.
Definition z3++.h:1036
expr operator[](expr const &index) const
Definition z3++.h:1621
expr algebraic_upper(unsigned precision) const
Definition z3++.h:1074
bool is_numeral() const
Return true if this expression is a numeral. Specialized functions also return representations for th...
Definition z3++.h:928
bool is_fpa() const
Return true if this is a FloatingPoint expression. .
Definition z3++.h:921
func_decl decl() const
Return the declaration associated with this application. This method assumes the expression is an app...
Definition z3++.h:1240
expr char_to_bv() const
Definition z3++.h:1587
std::string to_string(expr_vector const &queries)
Definition z3++.h:3580
std::string help() const
Definition z3++.h:3577
fixedpoint & operator=(fixedpoint const &o)
Definition z3++.h:3535
expr_vector from_string(char const *s)
Definition z3++.h:3543
void add_fact(func_decl &f, unsigned *args)
Definition z3++.h:3554
void add_cover(int level, func_decl &p, expr &property)
Definition z3++.h:3571
expr_vector rules() const
Definition z3++.h:3575
stats statistics() const
Definition z3++.h:3572
expr get_answer()
Definition z3++.h:3562
~fixedpoint() override
Definition z3++.h:3534
expr get_cover_delta(int level, func_decl &p)
Definition z3++.h:3566
fixedpoint(context &c)
Definition z3++.h:3532
std::string reason_unknown()
Definition z3++.h:3563
check_result query(func_decl_vector &relations)
Definition z3++.h:3556
void register_relation(func_decl &p)
Definition z3++.h:3573
std::string to_string()
Definition z3++.h:3579
check_result query(expr &q)
Definition z3++.h:3555
param_descrs get_param_descrs()
Definition z3++.h:3578
expr_vector from_file(char const *s)
Definition z3++.h:3548
void update_rule(expr &rule, symbol const &name)
Definition z3++.h:3564
expr_vector assertions() const
Definition z3++.h:3574
fixedpoint(fixedpoint const &o)
Definition z3++.h:3533
unsigned get_num_levels(func_decl &p)
Definition z3++.h:3565
void add_rule(expr &rule, symbol const &name)
Definition z3++.h:3553
void set(params const &p)
Definition z3++.h:3576
Function declaration (aka function definition). It is the signature of interpreted and uninterpreted ...
Definition z3++.h:807
func_decl transitive_closure(func_decl const &)
Definition z3++.h:826
func_decl(context &c, Z3_func_decl n)
Definition z3++.h:810
symbol name() const
Definition z3++.h:821
expr operator()() const
Definition z3++.h:3994
bool is_const() const
Definition z3++.h:830
func_decl_vector accessors()
Definition z3++.h:4367
sort range() const
Definition z3++.h:820
func_decl(context &c)
Definition z3++.h:809
Z3_decl_kind decl_kind() const
Definition z3++.h:822
sort domain(unsigned i) const
Definition z3++.h:819
unsigned id() const
retrieve unique identifier for func_decl.
Definition z3++.h:816
unsigned num_parameters() const
Definition z3++.h:823
unsigned arity() const
Definition z3++.h:818
Definition z3++.h:2628
unsigned num_args() const
Definition z3++.h:2647
expr arg(unsigned i) const
Definition z3++.h:2648
~func_entry() override
Definition z3++.h:2637
func_entry(context &c, Z3_func_entry e)
Definition z3++.h:2635
expr value() const
Definition z3++.h:2646
func_entry & operator=(func_entry const &s)
Definition z3++.h:2639
func_entry(func_entry const &s)
Definition z3++.h:2636
expr else_value() const
Definition z3++.h:2669
void set_else(expr &value)
Definition z3++.h:2676
func_interp(context &c, Z3_func_interp e)
Definition z3++.h:2658
func_interp(func_interp const &s)
Definition z3++.h:2659
func_entry entry(unsigned i) const
Definition z3++.h:2671
void add_entry(expr_vector const &args, expr &value)
Definition z3++.h:2672
unsigned num_entries() const
Definition z3++.h:2670
func_interp & operator=(func_interp const &s)
Definition z3++.h:2662
~func_interp() override
Definition z3++.h:2660
void add(expr const &f)
Definition z3++.h:3139
unsigned size() const
Definition z3++.h:3141
Z3_goal_prec precision() const
Definition z3++.h:3143
model convert_model(model const &m) const
Definition z3++.h:3150
bool is_decided_unsat() const
Definition z3++.h:3149
goal(goal const &s)
Definition z3++.h:3129
bool inconsistent() const
Definition z3++.h:3144
~goal() override
Definition z3++.h:3130
model get_model() const
Definition z3++.h:3156
std::string dimacs(bool include_names=true) const
Definition z3++.h:3174
unsigned num_exprs() const
Definition z3++.h:3147
goal(context &c, Z3_goal s)
Definition z3++.h:3128
goal(context &c, bool models=true, bool unsat_cores=false, bool proofs=false)
Definition z3++.h:3127
void add(expr_vector const &v)
Definition z3++.h:3140
goal & operator=(goal const &s)
Definition z3++.h:3132
void reset()
Definition z3++.h:3146
friend std::ostream & operator<<(std::ostream &out, goal const &g)
Definition z3++.h:3177
unsigned depth() const
Definition z3++.h:3145
bool is_decided_sat() const
Definition z3++.h:3148
expr as_expr() const
Definition z3++.h:3161
expr operator[](int i) const
Definition z3++.h:3142
expr eval(expr const &n, bool model_completion=false) const
Definition z3++.h:2704
unsigned size() const
Definition z3++.h:2718
sort get_sort(unsigned i) const
Return the uninterpreted sort at position i.
Definition z3++.h:2768
expr get_const_interp(func_decl c) const
Definition z3++.h:2727
unsigned num_consts() const
Definition z3++.h:2714
model & operator=(model const &s)
Definition z3++.h:2696
unsigned num_funcs() const
Definition z3++.h:2715
expr_vector sort_universe(sort const &s) const
Definition z3++.h:2774
func_interp get_func_interp(func_decl f) const
Definition z3++.h:2733
func_decl get_func_decl(unsigned i) const
Definition z3++.h:2717
func_interp add_func_interp(func_decl &f, expr &else_val)
Definition z3++.h:2747
func_decl operator[](int i) const
Definition z3++.h:2719
friend std::ostream & operator<<(std::ostream &out, model const &m)
Definition z3++.h:2785
~model() override
Definition z3++.h:2694
model(model const &s)
Definition z3++.h:2692
unsigned num_sorts() const
Definition z3++.h:2758
model(context &c)
Definition z3++.h:2690
void add_const_interp(func_decl &f, expr &value)
Definition z3++.h:2753
func_decl get_const_decl(unsigned i) const
Definition z3++.h:2716
bool has_interp(func_decl f) const
Definition z3++.h:2742
std::string to_string() const
Definition z3++.h:2783
model(model &src, context &dst, translate)
Definition z3++.h:2693
model(context &c, Z3_model m)
Definition z3++.h:2691
context * m_ctx
Definition z3++.h:517
Z3_error_code check_error() const
Definition z3++.h:522
context & ctx() const
Definition z3++.h:521
object(context &c)
Definition z3++.h:519
friend void check_context(object const &a, object const &b)
Definition z3++.h:525
virtual ~object()=default
on_clause(solver &s, on_clause_eh_t &on_clause_eh)
Definition z3++.h:4451
handle(unsigned h)
Definition z3++.h:3415
unsigned h() const
Definition z3++.h:3416
std::string help() const
Definition z3++.h:3525
handle add_soft(expr const &e, char const *weight)
Definition z3++.h:3464
friend std::ostream & operator<<(std::ostream &out, optimize const &s)
Definition z3++.h:3527
~optimize() override
Definition z3++.h:3442
void add(expr const &e, expr const &t)
Definition z3++.h:3451
expr lower(handle const &h)
Definition z3++.h:3509
void pop()
Definition z3++.h:3491
expr_vector objectives() const
Definition z3++.h:3520
void add(expr_vector const &es)
Definition z3++.h:3448
void add(expr const &e, char const *p)
Definition z3++.h:3455
void set_initial_value(expr const &var, expr const &value)
Definition z3++.h:3471
model get_model() const
Definition z3++.h:3506
handle add(expr const &e, unsigned weight)
Definition z3++.h:3468
check_result check()
Definition z3++.h:3494
check_result check(expr_vector const &asms)
Definition z3++.h:3495
stats statistics() const
Definition z3++.h:3521
void add(expr const &e)
Definition z3++.h:3444
void set_initial_value(expr const &var, int i)
Definition z3++.h:3475
void push()
Definition z3++.h:3488
void set_initial_value(expr const &var, bool b)
Definition z3++.h:3478
optimize(context &c, optimize const &src, translate)
Definition z3++.h:3419
handle add_soft(expr const &e, unsigned weight)
Definition z3++.h:3459
handle maximize(expr const &e)
Definition z3++.h:3482
optimize(optimize const &o)
Definition z3++.h:3425
void from_file(char const *filename)
Definition z3++.h:3523
expr_vector assertions() const
Definition z3++.h:3519
optimize & operator=(optimize const &o)
Definition z3++.h:3435
void from_string(char const *constraints)
Definition z3++.h:3524
expr upper(handle const &h)
Definition z3++.h:3514
optimize(context &c, optimize &src)
Definition z3++.h:3428
handle minimize(expr const &e)
Definition z3++.h:3485
optimize(context &c)
Definition z3++.h:3418
void set(params const &p)
Definition z3++.h:3508
expr_vector unsat_core() const
Definition z3++.h:3507
param_descrs(param_descrs const &o)
Definition z3++.h:551
param_descrs(context &c, Z3_param_descrs d)
Definition z3++.h:550
Z3_param_kind kind(symbol const &s)
Definition z3++.h:565
std::string documentation(symbol const &s)
Definition z3++.h:566
symbol name(unsigned i)
Definition z3++.h:564
static param_descrs simplify_param_descrs(context &c)
Definition z3++.h:560
unsigned size()
Definition z3++.h:563
std::string to_string() const
Definition z3++.h:567
~param_descrs() override
Definition z3++.h:559
param_descrs & operator=(param_descrs const &o)
Definition z3++.h:552
static param_descrs global_param_descrs(context &c)
Definition z3++.h:561
class for auxiliary parameters associated with func_decl The class is initialized with a func_decl or...
Definition z3++.h:2834
int get_int() const
Definition z3++.h:2858
func_decl get_decl() const
Definition z3++.h:2854
sort get_sort() const
Definition z3++.h:2853
std::string get_rational() const
Definition z3++.h:2856
symbol get_symbol() const
Definition z3++.h:2855
Z3_parameter_kind kind() const
Definition z3++.h:2851
double get_double() const
Definition z3++.h:2857
parameter(func_decl const &d, unsigned idx)
Definition z3++.h:2841
expr get_expr() const
Definition z3++.h:2852
parameter(expr const &e, unsigned idx)
Definition z3++.h:2846
void set(char const *k, char const *s)
Definition z3++.h:590
params(context &c)
Definition z3++.h:575
params(params const &s)
Definition z3++.h:576
~params() override
Definition z3++.h:577
void set(char const *k, bool b)
Definition z3++.h:586
void set(char const *k, unsigned n)
Definition z3++.h:587
void set(char const *k, symbol const &s)
Definition z3++.h:589
params & operator=(params const &s)
Definition z3++.h:579
void set(char const *k, double n)
Definition z3++.h:588
friend std::ostream & operator<<(std::ostream &out, params const &p)
Definition z3++.h:594
probe & operator=(probe const &s)
Definition z3++.h:3343
friend probe operator<(probe const &p1, probe const &p2)
Definition z3++.h:3382
double operator()(goal const &g) const
Definition z3++.h:3351
friend probe operator==(probe const &p1, probe const &p2)
Definition z3++.h:3392
friend probe operator<=(probe const &p1, probe const &p2)
Definition z3++.h:3372
probe(context &c, Z3_probe s)
Definition z3++.h:3339
probe(context &c, double val)
Definition z3++.h:3338
probe(context &c, char const *name)
Definition z3++.h:3337
friend probe operator&&(probe const &p1, probe const &p2)
Definition z3++.h:3397
probe(probe const &s)
Definition z3++.h:3340
~probe() override
Definition z3++.h:3341
friend probe operator!(probe const &p)
Definition z3++.h:3403
double apply(goal const &g) const
Definition z3++.h:3350
friend probe operator>=(probe const &p1, probe const &p2)
Definition z3++.h:3377
friend probe operator>(probe const &p1, probe const &p2)
Definition z3++.h:3387
friend probe operator||(probe const &p1, probe const &p2)
Definition z3++.h:3400
std::string help() const
Definition z3++.h:3308
~simplifier() override
Definition z3++.h:3299
simplifier(context &c, char const *name)
Definition z3++.h:3296
friend simplifier with(simplifier const &t, params const &p)
Definition z3++.h:3324
simplifier(context &c, Z3_simplifier s)
Definition z3++.h:3297
simplifier(simplifier const &s)
Definition z3++.h:3298
param_descrs get_param_descrs()
Definition z3++.h:3311
simplifier & operator=(simplifier const &s)
Definition z3++.h:3301
friend simplifier operator&(simplifier const &t1, simplifier const &t2)
Definition z3++.h:3317
cube_iterator end()
Definition z3++.h:3110
cube_generator(solver &s, expr_vector &vars)
Definition z3++.h:3102
cube_iterator begin()
Definition z3++.h:3109
cube_generator(solver &s)
Definition z3++.h:3095
void set_cutoff(unsigned c) noexcept
Definition z3++.h:3111
expr_vector const * operator->() const
Definition z3++.h:3077
bool operator==(cube_iterator const &other) const noexcept
Definition z3++.h:3080
cube_iterator operator++(int)
Definition z3++.h:3076
cube_iterator & operator++()
Definition z3++.h:3066
bool operator!=(cube_iterator const &other) const noexcept
Definition z3++.h:3083
cube_iterator(solver &s, expr_vector &vars, unsigned &cutoff, bool end)
Definition z3++.h:3054
expr_vector const & operator*() const noexcept
Definition z3++.h:3078
void from_string(char const *s)
Definition z3++.h:2922
expr proof() const
Definition z3++.h:2999
cube_generator cubes(expr_vector &vars)
Definition z3++.h:3115
friend std::ostream & operator<<(std::ostream &out, solver const &s)
Definition z3++.h:3118
solver(context &c, solver const &src, translate)
Definition z3++.h:2876
expr_vector non_units() const
Definition z3++.h:2956
solver(context &c, simple)
Definition z3++.h:2873
solver(context &c, Z3_solver s)
Definition z3++.h:2874
solver(context &c, char const *logic)
Definition z3++.h:2875
void set(char const *k, bool v)
Definition z3++.h:2889
void add(expr const &e, expr const &p)
Definition z3++.h:2908
void add(expr const &e, char const *p)
Definition z3++.h:2913
check_result consequences(expr_vector &assumptions, expr_vector &vars, expr_vector &conseq)
Definition z3++.h:2947
void set_initial_value(expr const &var, expr const &value)
Definition z3++.h:2988
void set(char const *k, char const *v)
Definition z3++.h:2893
check_result check(unsigned n, expr *const assumptions)
Definition z3++.h:2925
expr congruence_explain(expr const &a, expr const &b) const
Definition z3++.h:2981
model get_model() const
Definition z3++.h:2946
std::string dimacs(bool include_names=true) const
Definition z3++.h:3022
check_result check()
Definition z3++.h:2924
expr congruence_next(expr const &t) const
Definition z3++.h:2975
stats statistics() const
Definition z3++.h:2953
expr_vector units() const
Definition z3++.h:2957
expr_vector trail() const
Definition z3++.h:2958
void add(expr const &e)
Definition z3++.h:2907
void set_initial_value(expr const &var, int i)
Definition z3++.h:2992
solver & operator=(solver const &s)
Definition z3++.h:2881
void set(char const *k, double v)
Definition z3++.h:2891
void pop(unsigned n=1)
Definition z3++.h:2905
void push()
Create a backtracking point.
Definition z3++.h:2904
void set_initial_value(expr const &var, bool b)
Definition z3++.h:2995
~solver() override
Definition z3++.h:2879
std::string to_smt2(char const *status="unknown")
Definition z3++.h:3002
solver(context &c)
Definition z3++.h:2872
param_descrs get_param_descrs()
Definition z3++.h:3024
void set(char const *k, unsigned v)
Definition z3++.h:2890
void add(expr_vector const &v)
Definition z3++.h:2916
expr_vector assertions() const
Definition z3++.h:2955
void from_file(char const *file)
Definition z3++.h:2921
expr_vector trail(array< unsigned > &levels) const
Definition z3++.h:2959
void reset()
Definition z3++.h:2906
std::string reason_unknown() const
Definition z3++.h:2952
void set(params const &p)
Definition z3++.h:2888
expr_vector cube(expr_vector &vars, unsigned cutoff)
Definition z3++.h:3027
cube_generator cubes()
Definition z3++.h:3114
expr_vector unsat_core() const
Definition z3++.h:2954
expr congruence_root(expr const &t) const
Definition z3++.h:2969
solver(solver const &s)
Definition z3++.h:2877
void set(char const *k, symbol const &v)
Definition z3++.h:2892
check_result check(expr_vector const &assumptions)
Definition z3++.h:2935
A Z3 sort (aka type). Every expression (i.e., formula or term) in Z3 has a sort.
Definition z3++.h:704
sort(context &c, Z3_sort s)
Definition z3++.h:707
func_decl_vector constructors()
Definition z3++.h:4349
Z3_sort_kind sort_kind() const
Return the internal sort kind.
Definition z3++.h:719
unsigned bv_size() const
Return the size of this Bit-vector sort.
Definition z3++.h:778
bool is_int() const
Return true if this sort is the Integer sort.
Definition z3++.h:731
sort(context &c)
Definition z3++.h:706
bool is_real() const
Return true if this sort is the Real sort.
Definition z3++.h:735
sort(context &c, Z3_ast a)
Definition z3++.h:708
friend std::ostream & operator<<(std::ostream &out, sort const &s)
Definition z3++.h:796
func_decl_vector recognizers()
Definition z3++.h:4358
symbol name() const
Return name of sort.
Definition z3++.h:723
bool is_relation() const
Return true if this sort is a Relation sort.
Definition z3++.h:755
unsigned fpa_ebits() const
Definition z3++.h:780
sort array_range() const
Return the range of this Array sort.
Definition z3++.h:794
bool is_bool() const
Return true if this sort is the Boolean sort.
Definition z3++.h:727
bool is_arith() const
Return true if this sort is the Integer or Real sort.
Definition z3++.h:739
bool is_bv() const
Return true if this sort is a Bit-vector sort.
Definition z3++.h:743
sort array_domain() const
Return the domain of this Array sort.
Definition z3++.h:788
bool is_finite_domain() const
Return true if this sort is a Finite domain sort.
Definition z3++.h:767
bool is_datatype() const
Return true if this sort is a Datatype sort.
Definition z3++.h:751
bool is_re() const
Return true if this sort is a regular expression sort.
Definition z3++.h:763
unsigned id() const
retrieve unique identifier for func_decl.
Definition z3++.h:714
bool is_array() const
Return true if this sort is a Array sort.
Definition z3++.h:747
bool is_seq() const
Return true if this sort is a Sequence sort.
Definition z3++.h:759
unsigned fpa_sbits() const
Definition z3++.h:782
bool is_fpa() const
Return true if this sort is a Floating point sort.
Definition z3++.h:771
stats & operator=(stats const &s)
Definition z3++.h:2799
unsigned size() const
Definition z3++.h:2806
bool is_uint(unsigned i) const
Definition z3++.h:2808
bool is_double(unsigned i) const
Definition z3++.h:2809
~stats() override
Definition z3++.h:2797
stats(stats const &s)
Definition z3++.h:2796
double double_value(unsigned i) const
Definition z3++.h:2811
unsigned uint_value(unsigned i) const
Definition z3++.h:2810
stats(context &c, Z3_stats e)
Definition z3++.h:2795
friend std::ostream & operator<<(std::ostream &out, stats const &s)
Definition z3++.h:2814
std::string key(unsigned i) const
Definition z3++.h:2807
stats(context &c)
Definition z3++.h:2794
Z3_symbol_kind kind() const
Definition z3++.h:532
symbol(context &c, Z3_symbol s)
Definition z3++.h:530
int to_int() const
Definition z3++.h:534
friend std::ostream & operator<<(std::ostream &out, symbol const &s)
Definition z3++.h:538
std::string str() const
Definition z3++.h:533
friend tactic par_or(unsigned n, tactic const *tactics)
Definition z3++.h:3273
friend tactic par_and_then(tactic const &t1, tactic const &t2)
Definition z3++.h:3282
std::string help() const
Definition z3++.h:3232
solver mk_solver() const
Definition z3++.h:3222
tactic(context &c, char const *name)
Definition z3++.h:3210
tactic(context &c, Z3_tactic s)
Definition z3++.h:3211
friend tactic repeat(tactic const &t, unsigned max)
Definition z3++.h:3257
friend tactic with(tactic const &t, params const &p)
Definition z3++.h:3263
apply_result apply(goal const &g) const
Definition z3++.h:3223
friend tactic operator&(tactic const &t1, tactic const &t2)
Definition z3++.h:3243
friend tactic try_for(tactic const &t, unsigned ms)
Definition z3++.h:3268
param_descrs get_param_descrs()
Definition z3++.h:3240
~tactic() override
Definition z3++.h:3213
tactic & operator=(tactic const &s)
Definition z3++.h:3215
apply_result operator()(goal const &g) const
Definition z3++.h:3229
tactic(tactic const &s)
Definition z3++.h:3212
friend tactic operator|(tactic const &t1, tactic const &t2)
Definition z3++.h:3250
void register_decide(decide_eh_t &c)
Definition z3++.h:4661
bool propagate(expr_vector const &fixed, expr_vector const &lhs, expr_vector const &rhs, expr const &conseq)
Definition z3++.h:4749
void register_created(created_eh_t &c)
Definition z3++.h:4645
virtual ~user_propagator_base()
Definition z3++.h:4562
virtual void decide(expr const &, unsigned, bool)
Definition z3++.h:4693
virtual void eq(expr const &, expr const &)
Definition z3++.h:4687
void register_eq(eq_eh_t &f)
Definition z3++.h:4605
void add(expr const &e)
tracks e by a unique identifier that is returned by the call.
Definition z3++.h:4716
virtual void created(expr const &)
Definition z3++.h:4691
virtual void push()=0
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:4629
virtual void pop(unsigned num_scopes)=0
virtual bool on_binding(expr const &, expr const &)
Definition z3++.h:4695
virtual void fixed(expr const &, expr const &)
Definition z3++.h:4685
void conflict(expr_vector const &fixed)
Definition z3++.h:4725
bool propagate(expr_vector const &fixed, expr const &conseq)
Definition z3++.h:4742
user_propagator_base(solver *s)
Definition z3++.h:4555
virtual user_propagator_base * fresh(context &ctx)=0
user_propagators created using fresh() are created during search and their lifetimes are restricted t...
user_propagator_base(context &c)
Definition z3++.h:4553
void conflict(expr_vector const &fixed, expr_vector const &lhs, expr_vector const &rhs)
Definition z3++.h:4732
bool next_split(expr const &e, unsigned idx, Z3_lbool phase)
Definition z3++.h:4697
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:4589
Z3_ast Z3_API Z3_mk_exists_const(Z3_context c, unsigned weight, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], Z3_ast body)
Similar to Z3_mk_forall_const.
void Z3_API Z3_solver_propagate_on_binding(Z3_context c, Z3_solver s, Z3_on_binding_eh on_binding_eh)
register a callback when the solver instantiates a quantifier. If the callback returns false,...
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o)
Return the set of asserted formulas on the optimization context.
Z3_ast_kind
The different kinds of Z3 AST (abstract syntax trees). That is, terms, formulas and types.
Definition z3_api.h:142
Z3_ast Z3_API Z3_model_get_const_interp(Z3_context c, Z3_model m, Z3_func_decl a)
Return the interpretation (i.e., assignment) of constant a in the model m. Return NULL,...
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
Z3_simplifier Z3_API Z3_simplifier_and_then(Z3_context c, Z3_simplifier t1, Z3_simplifier t2)
Return a simplifier that applies t1 to a given goal and t2 to every subgoal produced by t1.
Z3_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.
Z3_probe Z3_API Z3_probe_lt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than the value returned...
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
Z3_ast Z3_API Z3_mk_bvxnor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise xnor.
Z3_string Z3_API Z3_get_error_msg(Z3_context c, Z3_error_code err)
Return a string describing the given error code.
Z3_parameter_kind Z3_API Z3_get_decl_parameter_kind(Z3_context c, Z3_func_decl d, unsigned idx)
Return the parameter type associated with a declaration.
bool Z3_API Z3_is_seq_sort(Z3_context c, Z3_sort s)
Check if s is a sequence sort.
Z3_ast Z3_API Z3_mk_bvnor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise nor.
Z3_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.
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_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
void Z3_API Z3_solver_assert_and_track(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast p)
Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p.
Z3_ast Z3_API Z3_func_interp_get_else(Z3_context c, Z3_func_interp f)
Return the 'else' value of the given function interpretation.
Z3_ast Z3_API Z3_mk_char_to_bv(Z3_context c, Z3_ast ch)
Create a bit-vector (code point) from character.
Z3_ast Z3_API Z3_mk_bvsge(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than or equal to.
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
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_fixedpoint_add_rule(Z3_context c, Z3_fixedpoint d, Z3_ast rule, Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form:
Z3_probe Z3_API Z3_probe_eq(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned ...
Z3_ast_vector Z3_API Z3_optimize_get_unsat_core(Z3_context c, Z3_optimize o)
Retrieve the unsat core for the last Z3_optimize_check The unsat core is a subset of the assumptions ...
Z3_sort Z3_API Z3_mk_char_sort(Z3_context c)
Create a sort for unicode characters.
Z3_ast Z3_API Z3_mk_unsigned_int(Z3_context c, unsigned v, Z3_sort ty)
Create a numeral of a int, bit-vector, or finite-domain sort.
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].
Z3_ast Z3_API Z3_mk_bvsle(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than or equal to.
void Z3_API Z3_query_constructor(Z3_context c, Z3_constructor constr, unsigned num_fields, Z3_func_decl *constructor, Z3_func_decl *tester, Z3_func_decl accessors[])
Query constructor for declared functions.
Z3_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
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...
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.
Z3_ast Z3_API Z3_substitute(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const from[], Z3_ast const to[])
Substitute every occurrence of from[i] in a with to[i], for i smaller than num_exprs....
Z3_ast Z3_API Z3_mk_mul(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] * ... * args[num_args-1].
Z3_func_decl Z3_API Z3_get_decl_func_decl_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
Z3_goal_prec
Z3 custom error handler (See Z3_set_error_handler).
Definition z3_api.h:1388
Z3_ast 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_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_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...
Z3_ast_vector Z3_API Z3_polynomial_subresultants(Z3_context c, Z3_ast p, Z3_ast q, Z3_ast x)
Return the nonzero subresultants of p and q with respect to the "variable" x.
Z3_ast Z3_API Z3_mk_zero_ext(Z3_context c, unsigned i, Z3_ast t1)
Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i,...
void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p)
Set the given solver using the given parameters.
Z3_ast Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.
Z3_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_ast Z3_API Z3_mk_fpa_is_subnormal(Z3_context c, Z3_ast t)
Predicate indicating whether t is a subnormal floating-point number.
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
Z3_ast Z3_API Z3_mk_int(Z3_context c, int v, Z3_sort ty)
Create a numeral of an int, bit-vector, or finite-domain sort.
Z3_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.
Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, Z3_solver s, Z3_ast_vector assumptions, Z3_ast_vector variables, Z3_ast_vector consequences)
retrieve consequences from solver that determine values of the supplied function symbols.
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context....
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_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
Z3_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.
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.
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....
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body)
Define the body of a recursive function.
Z3_param_descrs Z3_API Z3_solver_get_param_descrs(Z3_context c, Z3_solver s)
Return the parameter description set for the given solver object.
Z3_ast Z3_API Z3_mk_fpa_to_sbv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into a signed bit-vector.
Z3_ast Z3_API Z3_mk_true(Z3_context c)
Create an AST node representing true.
Z3_ast Z3_API Z3_optimize_get_lower(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective.
Z3_ast Z3_API Z3_mk_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
void Z3_API Z3_apply_result_inc_ref(Z3_context c, Z3_apply_result r)
Increment the reference counter of the given Z3_apply_result object.
Z3_func_interp Z3_API Z3_add_func_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast default_value)
Create a fresh func_interp object, add it to a model for a specified function. It has reference count...
Z3_ast Z3_API Z3_mk_bvsdiv_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed division of t1 and t2 does not overflow.
Z3_decl_kind
The different kinds of interpreted function kinds.
Definition z3_api.h:962
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.
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.
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
Z3_param_descrs Z3_API Z3_fixedpoint_get_param_descrs(Z3_context c, Z3_fixedpoint f)
Return the parameter description set for the given fixedpoint object.
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
void Z3_API Z3_optimize_from_file(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 file with assertions, soft constraints and optimization objectives....
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
Z3_string Z3_API Z3_simplifier_get_help(Z3_context c, Z3_simplifier t)
Return a string containing a description of parameters accepted by the given simplifier.
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.
Z3_tactic Z3_API Z3_tactic_par_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and then t2 to every subgoal produced by t1....
void Z3_API Z3_fixedpoint_update_rule(Z3_context c, Z3_fixedpoint d, Z3_ast a, Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created.
void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than.
Z3_func_decl Z3_API Z3_model_get_func_decl(Z3_context c, Z3_model m, unsigned i)
Return the declaration of the i-th function in the given model.
Z3_ast Z3_API Z3_mk_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
unsigned Z3_API Z3_func_entry_get_num_args(Z3_context c, Z3_func_entry e)
Return the number of arguments in a Z3_func_entry object.
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
Z3_symbol Z3_API Z3_get_decl_symbol_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string str)
load solver assertions from a string.
Z3_ast Z3_API Z3_get_numerator(Z3_context c, Z3_ast a)
Return the numerator (as a numeral AST) of a numeral AST of sort Real.
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
Z3_ast Z3_API Z3_mk_fpa_rna(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode.
Z3_probe Z3_API Z3_probe_ge(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than or equal to the...
Z3_ast Z3_API Z3_mk_and(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] and ... and args[num_args-1].
void Z3_API Z3_simplifier_dec_ref(Z3_context c, Z3_simplifier g)
Decrement the reference counter of the given simplifier.
void Z3_API Z3_interrupt(Z3_context c)
Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers,...
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.
Z3_ast Z3_API Z3_mk_fpa_sub(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point subtraction.
void Z3_API Z3_goal_assert(Z3_context c, Z3_goal g, Z3_ast a)
Add a new formula a to the given goal. The formula is split according to the following procedure that...
Z3_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_sort Z3_API Z3_mk_polymorphic_datatype(Z3_context c, Z3_symbol name, unsigned num_parameters, Z3_sort parameters[], unsigned num_constructors, Z3_constructor constructors[])
Create a parametric datatype with explicit type parameters.
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.
Z3_ast_vector Z3_API Z3_fixedpoint_from_string(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 string with fixedpoint rules. Add the rules to the current fixedpoint context....
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_ast Z3_API Z3_mk_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_false(Z3_context c)
Create an AST node representing false.
Z3_sort Z3_API Z3_mk_datatype(Z3_context c, Z3_symbol name, unsigned num_constructors, Z3_constructor constructors[])
Create datatype, such as lists, trees, records, enumerations or unions of records....
Z3_lbool Z3_API Z3_solver_check(Z3_context c, Z3_solver s)
Check whether the assertions in a given solver are consistent or not.
Z3_ast Z3_API Z3_mk_fpa_to_ubv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into an unsigned bit-vector.
Z3_ast Z3_API Z3_mk_rotate_right(Z3_context c, unsigned i, Z3_ast t1)
Rotate bits of t1 to the right i times.
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.
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...
Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m)
Convert a model of the formulas of a goal to a model of an original goal. The model may be null,...
void Z3_API Z3_del_constructor(Z3_context c, Z3_constructor constr)
Reclaim memory allocated to constructor.
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.
Z3_string Z3_API Z3_ast_to_string(Z3_context c, Z3_ast a)
Convert the given AST node into a string.
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
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....
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.
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_string Z3_API Z3_get_full_version(void)
Return a string that fully describes the version of Z3 in use.
void Z3_API Z3_enable_trace(Z3_string tag)
Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Z3_solver Z3_API Z3_mk_solver_from_tactic(Z3_context c, Z3_tactic t)
Create a new solver that is implemented using the given tactic. The solver supports the commands Z3_s...
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a unsigned integer.
bool Z3_API Z3_stats_is_double(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a double.
Z3_ast Z3_API Z3_mk_fpa_rtn(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
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_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,...
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
Z3_ast Z3_API Z3_mk_bvadd_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed addition of t1 and t2 does not underflow.
Z3_ast Z3_API Z3_mk_fpa_rtp(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode.
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_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.
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.
bool Z3_API Z3_solver_propagate_consequence(Z3_context c, Z3_solver_callback cb, unsigned num_fixed, Z3_ast const *fixed, unsigned num_eqs, Z3_ast const *eq_lhs, Z3_ast const *eq_rhs, Z3_ast conseq)
propagate a consequence based on fixed values and equalities. A client may invoke it during the pro...
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.
Z3_ast Z3_API Z3_mk_array_default(Z3_context c, Z3_ast array)
Access the array default value. Produces the default range value, for arrays that can be represented ...
Z3_ast Z3_API Z3_mk_forall_const(Z3_context c, unsigned weight, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], Z3_ast body)
Create a universal quantifier using a list of constants that will form the set of bound variables.
unsigned Z3_API Z3_model_get_num_sorts(Z3_context c, Z3_model m)
Return the number of uninterpreted sorts that m assigns an interpretation to.
Z3_param_kind
The different kinds of parameters that can be associated with parameter sets. (see Z3_mk_params).
Definition z3_api.h:1305
const char * Z3_string
Z3 string type. It is just an alias for const char *.
Definition z3_api.h:50
Z3_param_descrs Z3_API Z3_tactic_get_param_descrs(Z3_context c, Z3_tactic t)
Return the parameter description set for the given tactic object.
Z3_sort Z3_API Z3_mk_tuple_sort(Z3_context c, Z3_symbol mk_tuple_name, unsigned num_fields, Z3_symbol const field_names[], Z3_sort const field_sorts[], Z3_func_decl *mk_tuple_decl, Z3_func_decl proj_decl[])
Create a tuple type.
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.
void Z3_API Z3_func_entry_inc_ref(Z3_context c, Z3_func_entry e)
Increment the reference counter of the given Z3_func_entry object.
Z3_ast Z3_API Z3_mk_bvsub_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed subtraction of t1 and t2 does not overflow.
Z3_sort_kind
The different kinds of Z3 types (See Z3_get_sort_kind).
Definition z3_api.h:110
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow.
Z3_ast Z3_API Z3_mk_fpa_max(Z3_context c, Z3_ast t1, Z3_ast t2)
Maximum of floating-point numbers.
void Z3_API Z3_optimize_assert_and_track(Z3_context c, Z3_optimize o, Z3_ast a, Z3_ast t)
Assert tracked hard constraint to the optimization context.
unsigned Z3_API Z3_optimize_assert_soft(Z3_context c, Z3_optimize o, Z3_ast a, Z3_string weight, Z3_symbol id)
Assert soft constraint to the optimization context.
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
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...
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id)
create a tree ordering relation over signature a identified using index id.
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
Z3_ast Z3_API Z3_solver_congruence_next(Z3_context c, Z3_solver s, Z3_ast a)
retrieve the next expression in the congruence class. The set of congruent siblings form a cyclic lis...
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.
unsigned Z3_API Z3_goal_num_exprs(Z3_context c, Z3_goal g)
Return the number of formulas, subformulas and terms in the given goal.
Z3_solver Z3_API Z3_mk_solver_for_logic(Z3_context c, Z3_symbol logic)
Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unkn...
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
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.
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_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i)
Array read. The argument a is the array and i is the index of the array that gets read.
Z3_ast Z3_API Z3_mk_sign_ext(Z3_context c, unsigned i, Z3_ast t1)
Sign-extend of the given bit-vector to the (signed) equivalent bit-vector of size m+i,...
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.
Z3_ast_vector Z3_API Z3_solver_cube(Z3_context c, Z3_solver s, Z3_ast_vector vars, unsigned backtrack_level)
extract a next cube for a solver. The last cube is the constant true or false. The number of (non-con...
Z3_ast Z3_API Z3_mk_u32string(Z3_context c, unsigned len, unsigned const chars[])
Create a string constant out of the string that is passed in It takes the length of the string as wel...
void Z3_API Z3_fixedpoint_add_fact(Z3_context c, Z3_fixedpoint d, Z3_func_decl r, unsigned num_args, unsigned args[])
Add a Database fact.
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
Z3_func_decl Z3_API Z3_solver_propagate_declare(Z3_context c, Z3_symbol name, unsigned n, Z3_sort *domain, Z3_sort range)
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
Z3_ast Z3_API Z3_mk_select_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs)
n-ary Array read. The argument a is the array and idxs are the indices of the array that gets read.
Z3_ast_vector Z3_API Z3_algebraic_get_poly(Z3_context c, Z3_ast a)
Return the coefficients of the defining polynomial.
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
Z3_sort Z3_API Z3_mk_datatype_sort(Z3_context c, Z3_symbol name, unsigned num_params, Z3_sort const params[])
create a forward reference to a recursive datatype being declared. The forward reference can be used ...
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
void Z3_API Z3_func_interp_inc_ref(Z3_context c, Z3_func_interp f)
Increment the reference counter of the given Z3_func_interp object.
Z3_func_decl Z3_API Z3_mk_piecewise_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a piecewise linear ordering relation over signature a and index id.
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.
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_solver Z3_API Z3_mk_solver(Z3_context c)
Create a new solver. This solver is a "combined solver" (see combined_solver module) that internally ...
Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s)
Retrieve the model for the last Z3_solver_check or Z3_solver_check_assumptions.
int Z3_API Z3_get_symbol_int(Z3_context c, Z3_symbol s)
Return the symbol int value.
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
Z3_ast Z3_API Z3_optimize_get_upper(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
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.
Z3_lbool Z3_API Z3_solver_check_assumptions(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[])
Check whether the assertions in the given solver and optional assumptions are consistent or not.
Z3_ast Z3_API Z3_mk_fpa_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point greater than.
Z3_sort Z3_API Z3_model_get_sort(Z3_context c, Z3_model m, unsigned i)
Return a uninterpreted sort that m assigns an interpretation.
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.
Z3_simplifier Z3_API Z3_simplifier_using_params(Z3_context c, Z3_simplifier t, Z3_params p)
Return a simplifier that applies t using the given set of parameters.
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, bool is_signed)
Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is t...
Z3_ast Z3_API Z3_mk_sbv_to_str(Z3_context c, Z3_ast s)
Signed bit-vector to string conversion.
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_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow.
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
Z3_param_descrs Z3_API Z3_simplifier_get_param_descrs(Z3_context c, Z3_simplifier t)
Return the parameter description set for the given simplifier object.
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.
int Z3_API Z3_get_decl_int_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the integer value associated with an integer parameter.
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition z3_api.h:58
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
Z3_probe Z3_API Z3_mk_probe(Z3_context c, Z3_string name)
Return a probe associated with the given name. The complete list of probes may be obtained using the ...
Z3_tactic Z3_API Z3_tactic_when(Z3_context c, Z3_probe p, Z3_tactic t)
Return a tactic that applies t to a given goal is the probe p evaluates to true. If p evaluates to fa...
Z3_ast Z3_API Z3_mk_seq_suffix(Z3_context c, Z3_ast suffix, Z3_ast s)
Check if suffix is a suffix of s.
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...
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...
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.
Z3_solver Z3_API Z3_solver_translate(Z3_context source, Z3_solver s, Z3_context target)
Copy a solver s from the context source to the context target.
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx)
Return the unsigned value of the given statistical data.
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
Z3_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,...
Z3_ast Z3_API Z3_mk_fpa_eq(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point equality.
void Z3_API Z3_solver_propagate_register_cb(Z3_context c, Z3_solver_callback cb, Z3_ast e)
register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Ve...
Z3_ast Z3_API Z3_mk_bvmul_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflo...
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....
void Z3_API Z3_add_const_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast a)
Add a constant interpretation.
Z3_string Z3_API Z3_sort_to_string(Z3_context c, Z3_sort s)
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
unsigned Z3_API Z3_algebraic_get_i(Z3_context c, Z3_ast a)
Return which root of the polynomial the algebraic number represents.
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_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
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.
Z3_ast Z3_API Z3_solver_congruence_root(Z3_context c, Z3_solver s, Z3_ast a)
retrieve the congruence closure root of an expression. The root is retrieved relative to the state wh...
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.
unsigned Z3_API Z3_get_string_length(Z3_context c, Z3_ast s)
Retrieve the length of the unescaped string constant stored in s.
Z3_string Z3_API Z3_tactic_get_help(Z3_context c, Z3_tactic t)
Return a string containing a description of parameters accepted by the given tactic.
void Z3_API Z3_solver_propagate_final(Z3_context c, Z3_solver s, Z3_final_eh final_eh)
register a callback on final check. This provides freedom to the propagator to delay actions or imple...
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.
Z3_parameter_kind
The different kinds of parameters that can be associated with function symbols.
Definition z3_api.h:94
Z3_ast_vector Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Parse the given string using the SMT-LIB2 parser.
Z3_ast Z3_API Z3_mk_fpa_geq(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point greater than or equal.
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.
void Z3_API Z3_solver_register_on_clause(Z3_context c, Z3_solver s, void *user_context, Z3_on_clause_eh on_clause_eh)
register a callback to that retrieves assumed, inferred and deleted clauses during search.
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g, bool include_names)
Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF...
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
double Z3_API Z3_stats_get_double_value(Z3_context c, Z3_stats s, unsigned idx)
Return the double value of the given statistical data.
Z3_ast Z3_API Z3_mk_fpa_numeral_float(Z3_context c, float v, Z3_sort ty)
Create a numeral of FloatingPoint sort from a float.
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
unsigned Z3_API Z3_goal_depth(Z3_context c, Z3_goal g)
Return the depth of the given goal. It tracks how many transformations were applied to it.
Z3_ast Z3_API Z3_update_term(Z3_context c, Z3_ast a, unsigned num_args, Z3_ast const args[])
Update the arguments of term a using the arguments args. The number of arguments num_args should coin...
Z3_ast Z3_API Z3_mk_fpa_rtz(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
Z3_string Z3_API Z3_get_symbol_string(Z3_context c, Z3_symbol s)
Return the symbol name.
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.
Z3_simplifier Z3_API Z3_mk_simplifier(Z3_context c, Z3_string name)
Return a simplifier associated with the given name. The complete list of simplifiers may be obtained ...
Z3_ast Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
Z3_ast Z3_API Z3_mk_seq_foldli(Z3_context c, Z3_ast f, Z3_ast i, Z3_ast a, Z3_ast s)
Create a fold with index tracking of the function f over the sequence s with accumulator a starting a...
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
Z3_ast_vector Z3_API Z3_solver_get_non_units(Z3_context c, Z3_solver s)
Return the set of non units in the solver state.
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.
Z3_ast_vector Z3_API Z3_optimize_get_objectives(Z3_context c, Z3_optimize o)
Return objectives on the optimization context. If the objective function is a max-sat objective it is...
Z3_ast Z3_API Z3_mk_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of the first occurrence of substr in s starting from offset offset. If s does not contai...
Z3_ast Z3_API Z3_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...
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.
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_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.
Z3_tactic Z3_API Z3_tactic_fail_if(Z3_context c, Z3_probe p)
Return a tactic that fails if the probe p evaluates to false.
void Z3_API Z3_goal_reset(Z3_context c, Z3_goal g)
Erase all formulas from the given goal.
void Z3_API Z3_func_interp_dec_ref(Z3_context c, Z3_func_interp f)
Decrement the reference counter of the given Z3_func_interp object.
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
void Z3_API Z3_params_inc_ref(Z3_context c, Z3_params p)
Increment the reference counter of the given parameter set.
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_distinct(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing distinct(args[0], ..., args[num_args-1]).
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_config Z3_API Z3_mk_config(void)
Create a configuration object for the Z3 context object.
void Z3_API Z3_set_param_value(Z3_config c, Z3_string param_id, Z3_string param_value)
Set a configuration parameter.
Z3_ast Z3_API Z3_solver_congruence_explain(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast b)
retrieve explanation for congruence.
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
Z3_ast Z3_API Z3_mk_fpa_rem(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point remainder.
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
Z3_probe Z3_API Z3_probe_or(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when p1 or p2 evaluates to true.
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
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...
Z3_param_descrs Z3_API Z3_get_global_param_descrs(Z3_context c)
Retrieve description of global parameters.
void Z3_API Z3_solver_propagate_init(Z3_context c, Z3_solver s, void *user_context, Z3_push_eh push_eh, Z3_pop_eh pop_eh, Z3_fresh_eh fresh_eh)
register a user-propagator with the solver.
Z3_func_decl Z3_API Z3_model_get_const_decl(Z3_context c, Z3_model m, unsigned i)
Return the i-th constant in the given model.
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.
Z3_ast Z3_API Z3_mk_bvnand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise nand.
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d)
Return the range of the given declaration.
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.
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s)
Return the finite set of distinct values that represent the interpretation for sort s.
Z3_string Z3_API Z3_benchmark_to_smtlib_string(Z3_context c, Z3_string name, Z3_string logic, Z3_string status, Z3_string attributes, unsigned num_assumptions, Z3_ast const assumptions[], Z3_ast formula)
Convert the given benchmark into SMT-LIB formatted string.
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
Z3_ast Z3_API Z3_mk_bv_numeral(Z3_context c, unsigned sz, bool const *bits)
create a bit-vector numeral from a vector of Booleans.
void Z3_API Z3_func_entry_dec_ref(Z3_context c, Z3_func_entry e)
Decrement the reference counter of the given Z3_func_entry object.
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.
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_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
Z3_ast Z3_API Z3_mk_fpa_min(Z3_context c, Z3_ast t1, Z3_ast t2)
Minimum of floating-point numbers.
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
Z3_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.
Z3_ast Z3_API Z3_mk_seq_mapi(Z3_context c, Z3_ast f, Z3_ast i, Z3_ast s)
Create a map of the function f over the sequence s starting at index i.
Z3_ast Z3_API Z3_mk_bvneg_no_overflow(Z3_context c, Z3_ast t1)
Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector.
Z3_ast Z3_API Z3_mk_fpa_round_to_integral(Z3_context c, Z3_ast rm, Z3_ast t)
Floating-point roundToIntegral. Rounds a floating-point number to the closest integer,...
Z3_string Z3_API Z3_stats_get_key(Z3_context c, Z3_stats s, unsigned idx)
Return the key (a string) for a particular statistical data.
Z3_ast Z3_API Z3_mk_re_diff(Z3_context c, Z3_ast re1, Z3_ast re2)
Create the difference of regular expressions.
unsigned Z3_API Z3_fixedpoint_get_num_levels(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred)
Query the PDR engine for the maximal levels properties are known about predicate.
Z3_ast Z3_API Z3_mk_int64(Z3_context c, int64_t v, Z3_sort ty)
Create a numeral of a int, bit-vector, or finite-domain sort.
Z3_symbol_kind
The different kinds of symbol. In Z3, a symbol can be represented using integers and strings (See Z3_...
Definition z3_api.h:72
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
Z3_ast Z3_API Z3_mk_fpa_add(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point addition.
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.
bool Z3_API Z3_goal_is_decided_unsat(Z3_context c, Z3_goal g)
Return true if the goal contains false, and it is precise or the product of an over approximation.
Z3_ast Z3_API Z3_mk_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
Z3_ast_vector Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows divisor).
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
Z3_string Z3_API Z3_fixedpoint_to_string(Z3_context c, Z3_fixedpoint f, unsigned num_queries, Z3_ast queries[])
Print the current rules and background axioms as a string.
void Z3_API Z3_solver_get_levels(Z3_context c, Z3_solver s, Z3_ast_vector literals, unsigned sz, unsigned levels[])
retrieve the decision depth of Boolean literals (variables or their negations). Assumes a check-sat c...
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort.
Z3_ast Z3_API Z3_mk_int2bv(Z3_context c, unsigned n, Z3_ast t1)
Create an n bit bit-vector from the integer argument t1.
void Z3_API Z3_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
Z3_tactic Z3_API Z3_mk_tactic(Z3_context c, Z3_string name)
Return a tactic associated with the given name. The complete list of tactics may be obtained using th...
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
bool Z3_API Z3_model_eval(Z3_context c, Z3_model m, Z3_ast t, bool model_completion, Z3_ast *v)
Evaluate the AST node t in the given model. Return true if succeeded, and store the result in v.
Z3_sort Z3_API Z3_get_array_sort_range(Z3_context c, Z3_sort t)
Return the range of the given array sort.
void Z3_API Z3_del_constructor_list(Z3_context c, Z3_constructor_list clist)
Reclaim memory allocated for constructor list.
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a variable.
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...
Z3_ast Z3_API Z3_substitute_funs(Z3_context c, Z3_ast a, unsigned num_funs, Z3_func_decl const from[], Z3_ast const to[])
Substitute functions in from with new expressions in to.
Z3_ast Z3_API Z3_func_entry_get_arg(Z3_context c, Z3_func_entry e, unsigned i)
Return an argument of a Z3_func_entry object.
Z3_error_code
Z3 error codes (See Z3_get_error_code).
Definition z3_api.h:1347
Z3_ast Z3_API Z3_mk_eq(Z3_context c, Z3_ast l, Z3_ast r)
Create an AST node representing l = r.
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
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_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...
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
Z3_string Z3_API Z3_get_string(Z3_context c, Z3_ast s)
Retrieve the string constant stored in s. Characters outside the basic printable ASCII range are esca...
Z3_ast Z3_API Z3_mk_fpa_is_nan(Z3_context c, Z3_ast t)
Predicate indicating whether t is a NaN.
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....
Z3_error_code Z3_API Z3_get_error_code(Z3_context c)
Return the error code for the last API call.
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.
Z3_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id)
create a partial ordering relation over signature a and index id.
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
bool Z3_API Z3_is_string(Z3_context c, Z3_ast s)
Determine if s is a string constant.
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_ast Z3_API Z3_mk_char_to_int(Z3_context c, Z3_ast ch)
Create an integer (code point) from character.
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
Z3_goal_prec Z3_API Z3_goal_precision(Z3_context c, Z3_goal g)
Return the "precision" of the given goal. Goals can be transformed using over and under approximation...
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
Z3_goal Z3_API Z3_mk_goal(Z3_context c, bool models, bool unsat_cores, bool proofs)
Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or trans...
double Z3_API Z3_get_decl_double_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
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...
Z3_ast Z3_API Z3_mk_fpa_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point less than.
Z3_ast Z3_API Z3_mk_unsigned_int64(Z3_context c, uint64_t v, Z3_sort ty)
Create a numeral of a int, bit-vector, or finite-domain sort.
Z3_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_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.
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...
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
Z3_stats Z3_API Z3_optimize_get_statistics(Z3_context c, Z3_optimize d)
Retrieve statistics information from the last call to Z3_optimize_check.
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
Z3_probe Z3_API Z3_probe_gt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than the value retur...
Z3_ast Z3_API Z3_solver_get_proof(Z3_context c, Z3_solver s)
Retrieve the proof for the last Z3_solver_check or Z3_solver_check_assumptions.
Z3_string Z3_API Z3_get_decl_rational_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the rational value, as a string, associated with a rational parameter.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
Z3_stats Z3_API Z3_fixedpoint_get_statistics(Z3_context c, Z3_fixedpoint d)
Retrieve statistics information from the last call to Z3_fixedpoint_query.
bool Z3_API Z3_model_has_interp(Z3_context c, Z3_model m, Z3_func_decl a)
Test if there exists an interpretation (i.e., assignment) for a in the model m.
void Z3_API Z3_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.
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast t1, Z3_ast t2)
Compare terms.
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.
Z3_ast Z3_API Z3_mk_real_int64(Z3_context c, int64_t num, int64_t den)
Create a real from a fraction of int64.
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
Z3_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast s, Z3_ast substr)
Return index of the last occurrence of substr in s. If s does not contain substr, then the value is -...
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
void Z3_API Z3_solver_propagate_eq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression equalities.
Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string s)
Create a string constant out of the string that is passed in The string may contain escape encoding f...
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.
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...
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.
void Z3_API Z3_apply_result_dec_ref(Z3_context c, Z3_apply_result r)
Decrement the reference counter of the given Z3_apply_result object.
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort s)
Create a sequence sort out of the sort for the elements.
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s)
Return the set of units modulo model conversion.
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
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_goal Z3_API Z3_apply_result_get_subgoal(Z3_context c, Z3_apply_result r, unsigned i)
Return one of the subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
Z3_probe Z3_API Z3_probe_le(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the va...
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
Z3_ast Z3_API Z3_mk_array_ext(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create array extensionality index given two arrays with the same sort. The meaning is given by the ax...
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
Z3_func_entry Z3_API Z3_func_interp_get_entry(Z3_context c, Z3_func_interp f, unsigned i)
Return a "point" of the given function interpretation. It represents the value of f in a particular p...
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a recursive function.
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....
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
Z3_sort Z3_API Z3_get_decl_sort_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the sort value associated with a sort parameter.
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.
Z3_ast Z3_API Z3_mk_fpa_leq(Z3_context c, Z3_ast t1, Z3_ast t2)
Floating-point less than or equal.
void Z3_API Z3_solver_propagate_created(Z3_context c, Z3_solver s, Z3_created_eh created_eh)
register a callback when a new expression with a registered function is used by the solver The regist...
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.
unsigned Z3_API Z3_get_sort_id(Z3_context c, Z3_sort s)
Return a unique identifier for s.
Z3_ast Z3_API Z3_mk_fpa_mul(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point multiplication.
Z3_ast Z3_API Z3_mk_app(Z3_context c, Z3_func_decl d, unsigned num_args, Z3_ast const args[])
Create a constant or function application.
Z3_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).
Z3_stats Z3_API Z3_solver_get_statistics(Z3_context c, Z3_solver s)
Return statistics for the given solver.
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast t1)
Standard two's complement unary minus.
Z3_ast Z3_API Z3_mk_store_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs, Z3_ast v)
n-ary Array update.
Z3_string Z3_API Z3_fixedpoint_get_reason_unknown(Z3_context c, Z3_fixedpoint d)
Retrieve a string that describes the last status returned by Z3_fixedpoint_query.
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a linear ordering relation over signature a. The relation is identified by the index id.
Z3_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
Z3_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_seq_in_re(Z3_context c, Z3_ast seq, Z3_ast re)
Check if seq is in the language generated by the regular expression re.
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
Z3_ast Z3_API Z3_mk_sub(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] - ... - args[num_args - 1].
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.
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.
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.
unsigned Z3_API Z3_get_func_decl_id(Z3_context c, Z3_func_decl f)
Return a unique identifier for f.
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.
void Z3_API Z3_solver_propagate_decide(Z3_context c, Z3_solver s, Z3_decide_eh decide_eh)
register a callback when the solver decides to split on a registered expression. The callback may cha...
Z3_ast Z3_API Z3_mk_lstring(Z3_context c, unsigned len, Z3_string s)
Create a string constant out of the string that is passed in It takes the length of the string as wel...
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
double Z3_API Z3_probe_apply(Z3_context c, Z3_probe p, Z3_goal g)
Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0....
void Z3_API Z3_func_interp_set_else(Z3_context c, Z3_func_interp f, Z3_ast else_value)
Return the 'else' value of the given function interpretation.
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
void Z3_API Z3_solver_propagate_register(Z3_context c, Z3_solver s, Z3_ast e)
register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Ve...
Z3_ast Z3_API Z3_substitute_vars(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const to[])
Substitute the variables in a with the expressions in to. For every i smaller than num_exprs,...
Z3_ast Z3_API Z3_mk_or(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] or ... or args[num_args-1].
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
Z3_tactic Z3_API Z3_tactic_or_else(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that first applies t1 to a given goal, if it fails then returns the result of t2 appl...
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.
Z3_ast Z3_API Z3_mk_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_fpa_div(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2)
Floating-point division.
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_sqrt(Z3_context c, Z3_ast rm, Z3_ast t)
Floating-point square root.
bool Z3_API Z3_goal_is_decided_sat(Z3_context c, Z3_goal g)
Return true if the goal is empty, and it is precise or the product of a under approximation.
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.
void Z3_API Z3_optimize_from_string(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives....
Z3_solver Z3_API Z3_solver_add_simplifier(Z3_context c, Z3_solver solver, Z3_simplifier simplifier)
Attach simplifier to a solver. The solver will use the simplifier for incremental pre-processing.
Z3_ast Z3_API Z3_mk_rem(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 rem arg2.
Z3_ast Z3_API Z3_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.
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_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.
void Z3_API Z3_solver_propagate_fixed(Z3_context c, Z3_solver s, Z3_fixed_eh fixed_eh)
register a callback for when an expression is bound to a fixed value. The supported expression types ...
Z3_ast Z3_API Z3_mk_seq_map(Z3_context c, Z3_ast f, Z3_ast s)
Create a map of the function f over the sequence s.
void Z3_API Z3_fixedpoint_register_relation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f)
Register relation as Fixedpoint defined. Fixedpoint defined relations have least-fixedpoint semantics...
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 Z3_API Z3_fixedpoint_add_cover(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred, Z3_ast property)
Add property about the predicate pred. Add a property of predicate pred at level. It gets pushed forw...
void Z3_API Z3_func_interp_add_entry(Z3_context c, Z3_func_interp fi, Z3_ast_vector args, Z3_ast value)
add a function entry to a function interpretation.
bool Z3_API Z3_is_well_sorted(Z3_context c, Z3_ast t)
Return true if the given expression t is well sorted.
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
Z3_lbool Z3_API Z3_fixedpoint_query_relations(Z3_context c, Z3_fixedpoint d, unsigned num_relations, Z3_func_decl const relations[])
Pose multiple queries against the asserted rules.
Z3_ast Z3_API Z3_mk_as_array(Z3_context c, Z3_func_decl f)
Create array with the same interpretation as a function. The array satisfies the property (f x) = (se...
Z3_string Z3_API Z3_apply_result_to_string(Z3_context c, Z3_apply_result r)
Convert the Z3_apply_result object returned by Z3_tactic_apply into a string.
Z3_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.
Z3_ast Z3_API Z3_mk_seq_foldl(Z3_context c, Z3_ast f, Z3_ast a, Z3_ast s)
Create a fold of the function f over the sequence s with accumulator a.
Z3_string Z3_API Z3_solver_get_reason_unknown(Z3_context c, Z3_solver s)
Return a brief justification for an "unknown" result (i.e., Z3_L_UNDEF) for the commands Z3_solver_ch...
Z3_ast Z3_API Z3_mk_fpa_fma(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Floating-point fused multiply-add.
Z3_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.
void Z3_API Z3_disable_trace(Z3_string tag)
Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Z3_tactic Z3_API Z3_tactic_repeat(Z3_context c, Z3_tactic t, unsigned max)
Return a tactic that keeps applying t until the goal is not modified anymore or the maximum number of...
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
Z3_lbool Z3_API Z3_optimize_check(Z3_context c, Z3_optimize o, unsigned num_assumptions, Z3_ast const assumptions[])
Check consistency and produce optimal values.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
Z3_ast Z3_API Z3_mk_char_from_bv(Z3_context c, Z3_ast bv)
Create a character from a bit-vector (code point).
unsigned Z3_API Z3_func_interp_get_num_entries(Z3_context c, Z3_func_interp f)
Return the number of entries in the given function interpretation.
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort const sorts[], unsigned sort_refs[])
Create a constructor.
Z3_sort Z3_API Z3_mk_fpa_rounding_mode_sort(Z3_context c)
Create the RoundingMode sort.
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
Z3_ast Z3_API Z3_mk_fpa_rne(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
void Z3_API Z3_del_config(Z3_config c)
Delete the given configuration object.
double Z3_API Z3_get_numeral_double(Z3_context c, Z3_ast a)
Return numeral as a double.
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_...
Z3_tactic Z3_API Z3_tactic_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and t2 to every subgoal produced by t1.
Z3_optimize Z3_API Z3_optimize_translate(Z3_context c, Z3_optimize o, Z3_context target)
Copy an optimization context from a source to a target context.
Z3_func_interp Z3_API Z3_model_get_func_interp(Z3_context c, Z3_model m, Z3_func_decl f)
Return the interpretation of the function f in the model m. Return NULL, if the model does not assign...
void Z3_API Z3_solver_inc_ref(Z3_context c, Z3_solver s)
Increment the reference counter of the given solver.
bool Z3_API Z3_solver_next_split(Z3_context c, Z3_solver_callback cb, Z3_ast t, unsigned idx, Z3_lbool phase)
Z3_probe Z3_API Z3_probe_and(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when p1 and p2 evaluates to true.
bool Z3_API Z3_is_re_sort(Z3_context c, Z3_sort s)
Check if s is a regular expression sort.
Z3_ast Z3_API Z3_mk_ubv_to_str(Z3_context c, Z3_ast s)
Unsigned bit-vector to string conversion.
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for unicode strings.
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_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a)
Return idx_a'th accessor for the idx_c'th constructor.
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
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...
Z3_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.
@ Z3_PRINT_SMTLIB2_COMPLIANT
Definition z3_api.h:1325
@ Z3_APP_AST
Definition z3_api.h:144
@ Z3_VAR_AST
Definition z3_api.h:145
@ Z3_SORT_AST
Definition z3_api.h:147
@ Z3_NUMERAL_AST
Definition z3_api.h:143
@ Z3_FUNC_DECL_AST
Definition z3_api.h:148
@ Z3_QUANTIFIER_AST
Definition z3_api.h:146
@ Z3_OP_DISTINCT
Definition z3_api.h:967
@ Z3_OP_AND
Definition z3_api.h:969
@ Z3_OP_FALSE
Definition z3_api.h:965
@ Z3_OP_XOR
Definition z3_api.h:972
@ Z3_OP_IMPLIES
Definition z3_api.h:974
@ Z3_OP_ITE
Definition z3_api.h:968
@ Z3_OP_EQ
Definition z3_api.h:966
@ Z3_OP_OR
Definition z3_api.h:970
@ Z3_OP_NOT
Definition z3_api.h:973
@ Z3_OP_TRUE
Definition z3_api.h:964
@ Z3_RELATION_SORT
Definition z3_api.h:118
@ Z3_BOOL_SORT
Definition z3_api.h:112
@ Z3_BV_SORT
Definition z3_api.h:115
@ Z3_DATATYPE_SORT
Definition z3_api.h:117
@ Z3_INT_SORT
Definition z3_api.h:113
@ Z3_FINITE_DOMAIN_SORT
Definition z3_api.h:119
@ Z3_RE_SORT
Definition z3_api.h:123
@ Z3_FLOATING_POINT_SORT
Definition z3_api.h:120
@ Z3_ARRAY_SORT
Definition z3_api.h:116
@ Z3_REAL_SORT
Definition z3_api.h:114
@ Z3_SEQ_SORT
Definition z3_api.h:122
@ Z3_L_TRUE
Definition z3_api.h:61
@ Z3_L_FALSE
Definition z3_api.h:59
@ Z3_STRING_SYMBOL
Definition z3_api.h:74
@ Z3_INT_SYMBOL
Definition z3_api.h:73
@ Z3_OK
Definition z3_api.h:1348
Z3 C++ namespace.
Definition z3++.h:49
expr set_intersect(expr const &a, expr const &b)
Definition z3++.h:4193
expr re_intersect(expr_vector const &args)
Definition z3++.h:4275
expr store(expr const &a, expr const &i, expr const &v)
Definition z3++.h:4115
expr pw(expr const &a, expr const &b)
Definition z3++.h:1694
expr sbv_to_fpa(expr const &t, sort s)
Definition z3++.h:2118
expr bvneg_no_overflow(expr const &a)
Definition z3++.h:2319
expr indexof(expr const &s, expr const &substr, expr const &offset)
Definition z3++.h:4238
tactic par_or(unsigned n, tactic const *tactics)
Definition z3++.h:3273
tactic par_and_then(tactic const &t1, tactic const &t2)
Definition z3++.h:3282
expr srem(expr const &a, expr const &b)
signed remainder operator for bitvectors
Definition z3++.h:2251
expr bvadd_no_underflow(expr const &a, expr const &b)
Definition z3++.h:2307
expr prefixof(expr const &a, expr const &b)
Definition z3++.h:4232
expr sum(expr_vector const &args)
Definition z3++.h:2516
expr ugt(expr const &a, expr const &b)
unsigned greater than operator for bitvectors.
Definition z3++.h:2230
expr operator/(expr const &a, expr const &b)
Definition z3++.h:1860
expr exists(expr const &x, expr const &b)
Definition z3++.h:2427
expr fp_eq(expr const &a, expr const &b)
Definition z3++.h:2079
func_decl tree_order(sort const &a, unsigned index)
Definition z3++.h:2344
expr concat(expr const &a, expr const &b)
Definition z3++.h:2534
expr bvmul_no_underflow(expr const &a, expr const &b)
Definition z3++.h:2325
expr lambda(expr const &x, expr const &b)
Definition z3++.h:2451
ast_vector_tpl< func_decl > func_decl_vector
Definition z3++.h:78
expr fpa_to_fpa(expr const &t, sort s)
Definition z3++.h:2132
void reset_params()
Definition z3++.h:83
expr operator&&(expr const &a, expr const &b)
Definition z3++.h:1738
std::function< void(expr const &proof, std::vector< unsigned > const &deps, expr_vector const &clause)> on_clause_eh_t
Definition z3++.h:4435
expr operator!=(expr const &a, expr const &b)
Definition z3++.h:1774
expr operator+(expr const &a, expr const &b)
Definition z3++.h:1786
expr set_complement(expr const &a)
Definition z3++.h:4205
check_result
Definition z3++.h:165
@ unknown
Definition z3++.h:166
@ sat
Definition z3++.h:166
@ unsat
Definition z3++.h:166
std::string get_full_version()
Return a string that fully describes the version of Z3 in use.
Definition z3++.h:95
bool eq(ast const &a, ast const &b)
Definition z3++.h:631
func_decl recfun(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition z3++.h:4085
expr const_array(sort const &d, expr const &v)
Definition z3++.h:4165
expr min(expr const &a, expr const &b)
Definition z3++.h:2008
expr set_difference(expr const &a, expr const &b)
Definition z3++.h:4201
expr forall(expr const &x, expr const &b)
Definition z3++.h:2403
expr array_default(expr const &a)
Definition z3++.h:4141
expr array_ext(expr const &a, expr const &b)
Definition z3++.h:4147
expr operator>(expr const &a, expr const &b)
Definition z3++.h:1971
sort to_sort(context &c, Z3_sort s)
Definition z3++.h:2173
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:2164
expr bv2int(expr const &a, bool is_signed)
bit-vector and integer conversions.
Definition z3++.h:2298
expr operator%(expr const &a, expr const &b)
Definition z3++.h:1709
expr operator~(expr const &a)
Definition z3++.h:2086
expr sle(expr const &a, expr const &b)
signed less than or equal to operator for bitvectors.
Definition z3++.h:2186
expr nor(expr const &a, expr const &b)
Definition z3++.h:2006
expr fpa_fp(expr const &sgn, expr const &exp, expr const &sig)
Definition z3++.h:2096
expr bvsub_no_underflow(expr const &a, expr const &b, bool is_signed)
Definition z3++.h:2313
expr mk_xor(expr_vector const &args)
Definition z3++.h:2618
expr lshr(expr const &a, expr const &b)
logic shift right operator for bitvectors
Definition z3++.h:2279
expr operator*(expr const &a, expr const &b)
Definition z3++.h:1816
expr nand(expr const &a, expr const &b)
Definition z3++.h:2005
expr fpa_to_ubv(expr const &t, unsigned sz)
Definition z3++.h:2111
expr bvredor(expr const &a)
Definition z3++.h:2040
ast_vector_tpl< sort > sort_vector
Definition z3++.h:77
func_decl piecewise_linear_order(sort const &a, unsigned index)
Definition z3++.h:2341
expr slt(expr const &a, expr const &b)
signed less than operator for bitvectors.
Definition z3++.h:2192
tactic when(probe const &p, tactic const &t)
Definition z3++.h:3592
expr last_indexof(expr const &s, expr const &substr)
Definition z3++.h:4244
expr int2bv(unsigned n, expr const &a)
Definition z3++.h:2299
expr max(expr const &a, expr const &b)
Definition z3++.h:2024
expr xnor(expr const &a, expr const &b)
Definition z3++.h:2007
expr udiv(expr const &a, expr const &b)
unsigned division operator for bitvectors.
Definition z3++.h:2244
expr abs(expr const &a)
Definition z3++.h:2052
expr pbge(expr_vector const &es, int const *coeffs, int bound)
Definition z3++.h:2484
void disable_trace(char const *tag)
Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Definition z3++.h:111
expr round_fpa_to_closest_integer(expr const &t)
Definition z3++.h:2139
expr distinct(expr_vector const &args)
Definition z3++.h:2525
expr ashr(expr const &a, expr const &b)
arithmetic shift right operator for bitvectors
Definition z3++.h:2286
expr bvmul_no_overflow(expr const &a, expr const &b, bool is_signed)
Definition z3++.h:2322
expr bvsub_no_overflow(expr const &a, expr const &b)
Definition z3++.h:2310
expr star(expr const &re)
Definition z3++.h:4262
expr urem(expr const &a, expr const &b)
unsigned reminder operator for bitvectors
Definition z3++.h:2265
tactic repeat(tactic const &t, unsigned max=UINT_MAX)
Definition z3++.h:3257
expr mod(expr const &a, expr const &b)
Definition z3++.h:1698
expr fma(expr const &a, expr const &b, expr const &c, expr const &rm)
Definition z3++.h:2088
void get_version(unsigned &major, unsigned &minor, unsigned &build_number, unsigned &revision_number)
Return Z3 version number information.
Definition z3++.h:88
check_result to_check_result(Z3_lbool l)
Definition z3++.h:177
expr mk_or(expr_vector const &args)
Definition z3++.h:2606
expr to_re(expr const &s)
Definition z3++.h:4250
void check_context(object const &a, object const &b)
Definition z3++.h:525
expr_vector polynomial_subresultants(expr const &p, expr const &q, expr const &x)
Return the nonzero subresultants of p and q with respect to the "variable" x.
Definition z3++.h:2354
std::ostream & operator<<(std::ostream &out, exception const &e)
Definition z3++.h:127
expr ule(expr const &a, expr const &b)
unsigned less than or equal to operator for bitvectors.
Definition z3++.h:2212
func_decl to_func_decl(context &c, Z3_func_decl f)
Definition z3++.h:2178
tactic with(tactic const &t, params const &p)
Definition z3++.h:3263
expr ite(expr const &c, expr const &t, expr const &e)
Create the if-then-else expression ite(c, t, e)
Definition z3++.h:2151
expr ult(expr const &a, expr const &b)
unsigned less than operator for bitvectors.
Definition z3++.h:2218
expr pbeq(expr_vector const &es, int const *coeffs, int bound)
Definition z3++.h:2492
expr operator^(expr const &a, expr const &b)
Definition z3++.h:1997
expr operator<=(expr const &a, expr const &b)
Definition z3++.h:1924
expr set_union(expr const &a, expr const &b)
Definition z3++.h:4185
expr operator>=(expr const &a, expr const &b)
Definition z3++.h:1840
func_decl linear_order(sort const &a, unsigned index)
Definition z3++.h:2335
expr sqrt(expr const &a, expr const &rm)
Definition z3++.h:2072
expr pble(expr_vector const &es, int const *coeffs, int bound)
Definition z3++.h:2476
expr operator==(expr const &a, expr const &b)
Definition z3++.h:1763
expr foldli(expr const &f, expr const &i, expr const &a, expr const &list)
Definition z3++.h:2599
expr full_set(sort const &s)
Definition z3++.h:4173
expr smod(expr const &a, expr const &b)
signed modulus operator for bitvectors
Definition z3++.h:2258
expr implies(expr const &a, expr const &b)
Definition z3++.h:1686
expr empty_set(sort const &s)
Definition z3++.h:4169
expr in_re(expr const &s, expr const &re)
Definition z3++.h:4253
expr bvadd_no_overflow(expr const &a, expr const &b, bool is_signed)
bit-vector overflow/underflow checks
Definition z3++.h:2304
expr suffixof(expr const &a, expr const &b)
Definition z3++.h:4226
expr re_diff(expr const &a, expr const &b)
Definition z3++.h:4283
expr set_add(expr const &s, expr const &e)
Definition z3++.h:4177
expr plus(expr const &re)
Definition z3++.h:4256
expr set_subset(expr const &a, expr const &b)
Definition z3++.h:4213
expr select(expr const &a, expr const &i)
forward declarations
Definition z3++.h:4098
expr bvredand(expr const &a)
Definition z3++.h:2046
expr operator&(expr const &a, expr const &b)
Definition z3++.h:1993
expr operator-(expr const &a)
Definition z3++.h:1882
expr set_member(expr const &s, expr const &e)
Definition z3++.h:4209
expr bvsdiv_no_overflow(expr const &a, expr const &b)
Definition z3++.h:2316
tactic try_for(tactic const &t, unsigned ms)
Definition z3++.h:3268
void set_param(char const *param, char const *value)
Definition z3++.h:80
expr sdiv(expr const &a, expr const &b)
signed division operator for bitvectors.
Definition z3++.h:2237
func_decl function(symbol const &name, unsigned arity, sort const *domain, sort const &range)
Definition z3++.h:4057
func_decl partial_order(sort const &a, unsigned index)
Definition z3++.h:2338
ast_vector_tpl< expr > expr_vector
Definition z3++.h:76
expr rem(expr const &a, expr const &b)
Definition z3++.h:1714
expr sge(expr const &a, expr const &b)
signed greater than or equal to operator for bitvectors.
Definition z3++.h:2198
expr is_int(expr const &e)
Definition z3++.h:1734
expr operator!(expr const &a)
Definition z3++.h:1732
expr re_empty(sort const &s)
Definition z3++.h:4265
expr foldl(expr const &f, expr const &a, expr const &list)
Definition z3++.h:2592
expr mk_and(expr_vector const &args)
Definition z3++.h:2612
rounding_mode
Definition z3++.h:169
@ RNE
Definition z3++.h:171
@ RNA
Definition z3++.h:170
@ RTZ
Definition z3++.h:174
@ RTN
Definition z3++.h:173
@ RTP
Definition z3++.h:172
expr sext(expr const &a, unsigned i)
Sign-extend of the given bit-vector to the (signed) equivalent bitvector of size m+i,...
Definition z3++.h:2333
expr to_real(expr const &a)
Definition z3++.h:4055
expr shl(expr const &a, expr const &b)
shift left operator for bitvectors
Definition z3++.h:2272
expr operator||(expr const &a, expr const &b)
Definition z3++.h:1750
expr set_del(expr const &s, expr const &e)
Definition z3++.h:4181
expr ubv_to_fpa(expr const &t, sort s)
Definition z3++.h:2125
expr map(expr const &f, expr const &list)
Definition z3++.h:2578
tactic cond(probe const &p, tactic const &t1, tactic const &t2)
Definition z3++.h:3598
expr as_array(func_decl &f)
Definition z3++.h:4135
expr sgt(expr const &a, expr const &b)
signed greater than operator for bitvectors.
Definition z3++.h:2204
expr fpa_to_sbv(expr const &t, unsigned sz)
Definition z3++.h:2104
ast_vector_tpl< ast > ast_vector
Definition z3++.h:75
void enable_trace(char const *tag)
Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Definition z3++.h:103
expr operator|(expr const &a, expr const &b)
Definition z3++.h:2001
expr atmost(expr_vector const &es, unsigned bound)
Definition z3++.h:2500
expr range(expr const &lo, expr const &hi)
Definition z3++.h:4293
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:2293
expr atleast(expr_vector const &es, unsigned bound)
Definition z3++.h:2508
expr uge(expr const &a, expr const &b)
unsigned greater than or equal to operator for bitvectors.
Definition z3++.h:2224
expr mapi(expr const &f, expr const &i, expr const &list)
Definition z3++.h:2585
expr operator<(expr const &a, expr const &b)
Definition z3++.h:1949
expr option(expr const &re)
Definition z3++.h:4259
expr re_full(sort const &s)
Definition z3++.h:4270
expr re_complement(expr const &a)
Definition z3++.h:4290
expr empty(sort const &s)
Definition z3++.h:4221
tactic fail_if(probe const &p)
Definition z3++.h:3587
#define _Z3_MK_BIN_(a, b, binop)
Definition z3++.h:1679
#define MK_EXPR1(_fn, _arg)
Definition z3++.h:4154
#define MK_EXPR2(_fn, _arg1, _arg2)
Definition z3++.h:4159
#define Z3_THROW(x)
Definition z3++.h:133
#define _Z3_MK_UN_(a, mkun)
Definition z3++.h:1726