Z3
Loading...
Searching...
No Matches
user_propagator_base Class Referenceabstract

#include <z3++.h>

Public Member Functions

 user_propagator_base (context &c)
 user_propagator_base (solver *s)
virtual void push ()=0
virtual void pop (unsigned num_scopes)=0
virtual ~user_propagator_base ()
contextctx ()
virtual user_propagator_basefresh (context &ctx)=0
 user_propagators created using fresh() are created during search and their lifetimes are restricted to search time. They should be garbage collected by the propagator used to invoke fresh(). The life-time of the Z3_context object can only be assumed valid during callbacks, such as fixed(), which contains expressions based on the context.
void register_fixed (fixed_eh_t &f)
 register callbacks. Callbacks can only be registered with user_propagators that were created using a solver.
void register_fixed ()
void register_eq (eq_eh_t &f)
void register_eq ()
void register_final (final_eh_t &f)
 register a callback on final-check. During the final check stage, all propagations have been processed. This is an opportunity for the user-propagator to delay some analysis that could be expensive to perform incrementally. It is also an opportunity for the propagator to implement branch and bound optimization.
void register_final ()
void register_created (created_eh_t &c)
void register_created ()
void register_decide (decide_eh_t &c)
void register_decide ()
void register_on_binding ()
virtual void fixed (expr const &, expr const &)
virtual void eq (expr const &, expr const &)
virtual void final ()
virtual void created (expr const &)
virtual void decide (expr const &, unsigned, bool)
virtual bool on_binding (expr const &, expr const &)
bool next_split (expr const &e, unsigned idx, Z3_lbool phase)
void add (expr const &e)
 tracks e by a unique identifier that is returned by the call.
void conflict (expr_vector const &fixed)
void conflict (expr_vector const &fixed, expr_vector const &lhs, expr_vector const &rhs)
bool propagate (expr_vector const &fixed, expr const &conseq)
bool propagate (expr_vector const &fixed, expr_vector const &lhs, expr_vector const &rhs, expr const &conseq)

Detailed Description

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

Constructor & Destructor Documentation

◆ user_propagator_base() [1/2]

user_propagator_base ( context & c)
inline

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

4428: s(nullptr), c(&c) {}

Referenced by fresh().

◆ user_propagator_base() [2/2]

user_propagator_base ( solver * s)
inline

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

4430 : s(s), c(nullptr) {
4431 Z3_solver_propagate_init(ctx(), *s, this, push_eh, pop_eh, fresh_eh);
4432 }
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.

◆ ~user_propagator_base()

virtual ~user_propagator_base ( )
inlinevirtual

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

4437 {
4438 for (auto& subcontext : subcontexts) {
4439 subcontext->detach(); // detach first; the subcontexts will be freed internally!
4440 delete subcontext;
4441 }
4442 }

Member Function Documentation

◆ add()

void add ( expr const & e)
inline

tracks e by a unique identifier that is returned by the call.

If the fixed() callback is registered and if e is a Boolean or Bit-vector, the fixed() callback gets invoked when e is bound to a value. If the eq() callback is registered, then equalities between registered expressions are reported. A consumer can use the propagate or conflict functions to invoke propagations or conflicts as a consequence of these callbacks. These functions take a list of identifiers for registered expressions that have been fixed. The list of identifiers must correspond to already fixed values. Similarly, a list of propagated equalities can be supplied. These must correspond to equalities that have been registered during a callback.

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

4591 {
4592 if (cb)
4593 Z3_solver_propagate_register_cb(ctx(), cb, e);
4594 else if (s)
4595 Z3_solver_propagate_register(ctx(), *s, e);
4596 else
4597 assert(false);
4598 }
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...
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...

◆ conflict() [1/2]

void conflict ( expr_vector const & fixed)
inline

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

4600 {
4601 assert(cb);
4602 expr conseq = ctx().bool_val(false);
4603 array<Z3_ast> _fixed(fixed);
4604 Z3_solver_propagate_consequence(ctx(), cb, fixed.size(), _fixed.ptr(), 0, nullptr, nullptr, conseq);
4605 }
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...

◆ conflict() [2/2]

void conflict ( expr_vector const & fixed,
expr_vector const & lhs,
expr_vector const & rhs )
inline

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

4607 {
4608 assert(cb);
4609 assert(lhs.size() == rhs.size());
4610 expr conseq = ctx().bool_val(false);
4611 array<Z3_ast> _fixed(fixed);
4612 array<Z3_ast> _lhs(lhs);
4613 array<Z3_ast> _rhs(rhs);
4614 Z3_solver_propagate_consequence(ctx(), cb, fixed.size(), _fixed.ptr(), lhs.size(), _lhs.ptr(), _rhs.ptr(), conseq);
4615 }

◆ created()

virtual void created ( expr const & )
inlinevirtual

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

4566{}

Referenced by register_created().

◆ ctx()

◆ decide()

virtual void decide ( expr const & ,
unsigned ,
bool  )
inlinevirtual

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

4568{}

Referenced by register_decide().

◆ eq()

virtual void eq ( expr const & ,
expr const &  )
inlinevirtual

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

4562{ }

Referenced by register_eq().

◆ final()

virtual void final ( )
inlinevirtual

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

4564{ }

◆ fixed()

virtual void fixed ( expr const & ,
expr const &  )
inlinevirtual

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

4560{ }

Referenced by conflict(), conflict(), propagate(), propagate(), and register_fixed().

◆ fresh()

virtual user_propagator_base * fresh ( context & ctx)
pure virtual

user_propagators created using fresh() are created during search and their lifetimes are restricted to search time. They should be garbage collected by the propagator used to invoke fresh(). The life-time of the Z3_context object can only be assumed valid during callbacks, such as fixed(), which contains expressions based on the context.

◆ next_split()

bool next_split ( expr const & e,
unsigned idx,
Z3_lbool phase )
inline

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

4572 {
4573 assert(cb);
4574 return Z3_solver_next_split(ctx(), cb, e, idx, phase);
4575 }
bool Z3_API Z3_solver_next_split(Z3_context c, Z3_solver_callback cb, Z3_ast t, unsigned idx, Z3_lbool phase)

◆ on_binding()

virtual bool on_binding ( expr const & ,
expr const &  )
inlinevirtual

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

4570{ return true; }

Referenced by register_on_binding().

◆ pop()

virtual void pop ( unsigned num_scopes)
pure virtual

◆ propagate() [1/2]

bool propagate ( expr_vector const & fixed,
expr const & conseq )
inline

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

4617 {
4618 assert(cb);
4619 assert((Z3_context)conseq.ctx() == (Z3_context)ctx());
4620 array<Z3_ast> _fixed(fixed);
4621 return Z3_solver_propagate_consequence(ctx(), cb, _fixed.size(), _fixed.ptr(), 0, nullptr, nullptr, conseq);
4622 }

◆ propagate() [2/2]

bool propagate ( expr_vector const & fixed,
expr_vector const & lhs,
expr_vector const & rhs,
expr const & conseq )
inline

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

4626 {
4627 assert(cb);
4628 assert((Z3_context)conseq.ctx() == (Z3_context)ctx());
4629 assert(lhs.size() == rhs.size());
4630 array<Z3_ast> _fixed(fixed);
4631 array<Z3_ast> _lhs(lhs);
4632 array<Z3_ast> _rhs(rhs);
4633
4634 return Z3_solver_propagate_consequence(ctx(), cb, _fixed.size(), _fixed.ptr(), lhs.size(), _lhs.ptr(), _rhs.ptr(), conseq);
4635 }

◆ push()

virtual void push ( )
pure virtual

◆ register_created() [1/2]

void register_created ( )
inline

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

4527 {
4528 m_created_eh = [this](expr const& e) {
4529 created(e);
4530 };
4531 if (s) {
4532 Z3_solver_propagate_created(ctx(), *s, created_eh);
4533 }
4534 }
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...

◆ register_created() [2/2]

void register_created ( created_eh_t & c)
inline

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

4520 {
4521 m_created_eh = c;
4522 if (s) {
4523 Z3_solver_propagate_created(ctx(), *s, created_eh);
4524 }
4525 }

◆ register_decide() [1/2]

void register_decide ( )
inline

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

4543 {
4544 m_decide_eh = [this](expr val, unsigned bit, bool is_pos) {
4545 decide(val, bit, is_pos);
4546 };
4547 if (s) {
4548 Z3_solver_propagate_decide(ctx(), *s, decide_eh);
4549 }
4550 }
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...

◆ register_decide() [2/2]

void register_decide ( decide_eh_t & c)
inline

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

4536 {
4537 m_decide_eh = c;
4538 if (s) {
4539 Z3_solver_propagate_decide(ctx(), *s, decide_eh);
4540 }
4541 }

◆ register_eq() [1/2]

void register_eq ( )
inline

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

4487 {
4488 m_eq_eh = [this](expr const& x, expr const& y) {
4489 eq(x, y);
4490 };
4491 if (s) {
4492 Z3_solver_propagate_eq(ctx(), *s, eq_eh);
4493 }
4494 }
void Z3_API Z3_solver_propagate_eq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression equalities.
bool eq(AstRef a, AstRef b)
Definition z3py.py:486

◆ register_eq() [2/2]

void register_eq ( eq_eh_t & f)
inline

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

4480 {
4481 m_eq_eh = f;
4482 if (s) {
4483 Z3_solver_propagate_eq(ctx(), *s, eq_eh);
4484 }
4485 }

◆ register_final() [1/2]

void register_final ( )
inline

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

4511 {
4512 m_final_eh = [this]() {
4513 final();
4514 };
4515 if (s) {
4516 Z3_solver_propagate_final(ctx(), *s, final_eh);
4517 }
4518 }
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...

◆ register_final() [2/2]

void register_final ( final_eh_t & f)
inline

register a callback on final-check. During the final check stage, all propagations have been processed. This is an opportunity for the user-propagator to delay some analysis that could be expensive to perform incrementally. It is also an opportunity for the propagator to implement branch and bound optimization.

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

4504 {
4505 m_final_eh = f;
4506 if (s) {
4507 Z3_solver_propagate_final(ctx(), *s, final_eh);
4508 }
4509 }

◆ register_fixed() [1/2]

void register_fixed ( )
inline

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

4471 {
4472 m_fixed_eh = [this](expr const &id, expr const &e) {
4473 fixed(id, e);
4474 };
4475 if (s) {
4476 Z3_solver_propagate_fixed(ctx(), *s, fixed_eh);
4477 }
4478 }
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 ...

◆ register_fixed() [2/2]

void register_fixed ( fixed_eh_t & f)
inline

register callbacks. Callbacks can only be registered with user_propagators that were created using a solver.

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

4464 {
4465 m_fixed_eh = f;
4466 if (s) {
4467 Z3_solver_propagate_fixed(ctx(), *s, fixed_eh);
4468 }
4469 }

◆ register_on_binding()

void register_on_binding ( )
inline

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

4552 {
4553 m_on_binding_eh = [this](expr const& q, expr const& inst) {
4554 return on_binding(q, inst);
4555 };
4556 if (s)
4557 Z3_solver_propagate_on_binding(ctx(), *s, on_binding_eh);
4558 }
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,...