Struct z3::Solver

source ·
pub struct Solver<'ctx> { /* private fields */ }
Expand description

(Incremental) solver, possibly specialized by a particular tactic or logic.

Implementations§

source§

impl<'ctx> Solver<'ctx>

source

pub fn new(ctx: &'ctx Context) -> Solver<'ctx>

Create a new solver. This solver is a “combined solver” that internally uses a non-incremental (solver1) and an incremental solver (solver2). This combined solver changes its behaviour based on how it is used and how its parameters are set.

If the solver is used in a non incremental way (i.e. no calls to Solver::push() or Solver::pop(), and no calls to Solver::assert() or Solver::assert_and_track() after checking satisfiability without an intervening Solver::reset()) then solver1 will be used. This solver will apply Z3’s “default” tactic.

The “default” tactic will attempt to probe the logic used by the assertions and will apply a specialized tactic if one is supported. Otherwise the general (and-then simplify smt) tactic will be used.

If the solver is used in an incremental way then the combined solver will switch to using solver2 (which behaves similarly to the general “smt” tactic).

Note however it is possible to set the solver2_timeout, solver2_unknown, and ignore_solver1 parameters of the combined solver to change its behaviour.

The function Solver::get_model() retrieves a model if the assertions is satisfiable (i.e., the result is SatResult::Sat) and model construction is enabled. The function Solver::get_model() can also be used even if the result is SatResult::Unknown, but the returned model is not guaranteed to satisfy quantified assertions.

source

pub fn from_string<T: Into<Vec<u8>>>(&self, source_string: T)

Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives. Add the parsed constraints and objectives to the solver.

source

pub fn new_for_logic<S: Into<Symbol>>( ctx: &'ctx Context, logic: S ) -> Option<Solver<'ctx>>

Create a new solver customized for the given logic. It returns None if the logic is unknown or unsupported.

source

pub fn translate<'dest_ctx>( &self, dest: &'dest_ctx Context ) -> Solver<'dest_ctx>

source

pub fn get_context(&self) -> &'ctx Context

Get this solver’s context.

source

pub fn assert(&self, ast: &Bool<'ctx>)

Assert a constraint into the solver.

The functions Solver::check() and Solver::check_assumptions() should be used to check whether the logical context is consistent or not.

See also:
source

pub fn assert_and_track(&self, ast: &Bool<'ctx>, p: &Bool<'ctx>)

Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p.

This API is an alternative to Solver::check_assumptions() for extracting unsat cores. Both APIs can be used in the same solver. The unsat core will contain a combination of the Boolean variables provided using Solver::assert_and_track() and the Boolean literals provided using Solver::check_assumptions().

See also:
source

pub fn reset(&self)

Remove all assertions from the solver.

source

pub fn check(&self) -> SatResult

Check whether the assertions in a given solver are consistent or not.

The function Solver::get_model() retrieves a model if the assertions is satisfiable (i.e., the result is SatResult::Sat) and model construction is enabled. Note that if the call returns SatResult::Unknown, Z3 does not ensure that calls to Solver::get_model() succeed and any models produced in this case are not guaranteed to satisfy the assertions.

The function Solver::get_proof() retrieves a proof if proof generation was enabled when the context was created, and the assertions are unsatisfiable (i.e., the result is SatResult::Unsat).

See also:
source

pub fn check_assumptions(&self, assumptions: &[Bool<'ctx>]) -> SatResult

Check whether the assertions in the given solver and optional assumptions are consistent or not.

The function Solver::get_unsat_core() retrieves the subset of the assumptions used in the unsatisfiability proof produced by Z3.

See also:
source

pub fn get_assertions(&self) -> Vec<Bool<'_>>

source

pub fn get_unsat_core(&self) -> Vec<Bool<'ctx>>

Return a subset of the assumptions provided to either the last

These are the assumptions Z3 used in the unsatisfiability proof. Assumptions are available in Z3. They are used to extract unsatisfiable cores. They may be also used to “retract” assumptions. Note that, assumptions are not really “soft constraints”, but they can be used to implement them.

See also:
source

pub fn push(&self)

Create a backtracking point.

The solver contains a stack of assertions.

See also:
source

pub fn pop(&self, n: u32)

Backtrack n backtracking points.

See also:
source

pub fn get_model(&self) -> Option<Model<'ctx>>

Retrieve the model for the last Solver::check() or Solver::check_assumptions().

The error handler is invoked if a model is not available because the commands above were not invoked for the given solver, or if the result was SatResult::Unsat.

source

pub fn get_proof(&self) -> Option<impl Ast<'ctx>>

Retrieve the proof for the last Solver::check() or Solver::check_assumptions().

The error handler is invoked if proof generation is not enabled, or if the commands above were not invoked for the given solver, or if the result was different from SatResult::Unsat.

See also:
source

pub fn get_reason_unknown(&self) -> Option<String>

Return a brief justification for an “unknown” result (i.e., SatResult::Unknown) for the commands Solver::check() and Solver::check_assumptions().

source

pub fn set_params(&self, params: &Params<'ctx>)

Set the current solver using the given parameters.

source

pub fn get_statistics(&self) -> Statistics<'ctx>

Retrieve the statistics for the last Solver::check().

Trait Implementations§

source§

impl<'ctx> Clone for Solver<'ctx>

source§

fn clone(self: &Solver<'ctx>) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'ctx> Debug for Solver<'ctx>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'ctx> Display for Solver<'ctx>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'ctx> Drop for Solver<'ctx>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'ctx> RefUnwindSafe for Solver<'ctx>

§

impl<'ctx> !Send for Solver<'ctx>

§

impl<'ctx> !Sync for Solver<'ctx>

§

impl<'ctx> Unpin for Solver<'ctx>

§

impl<'ctx> UnwindSafe for Solver<'ctx>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.