Struct smtlib::Solver

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

The Solver type is the primary entrypoint to interaction with the solver. Checking for validity of a set of assertions requires:

// 1. Set up the backend (in this case z3)
let backend = smtlib::backend::z3_binary::Z3Binary::new("z3")?;
// 2. Set up the solver
let mut solver = smtlib::Solver::new(backend)?;
// 3. Declare the necessary constants
let x = Int::from_name("x");
// 4. Add assertions to the solver
solver.assert(x._eq(12))?;
// 5. Check for validity, and optionally construct a model
let sat_res = solver.check_sat_with_model()?;
// 6. In this case we expect sat, and thus want to extract the model
let model = sat_res.expect_sat()?;
// 7. Interpret the result by extract the values of constants which
//    satisfy the assertions.
match model.eval(x) {
    Some(x) => println!("This is the value of x: {x}"),
    None => panic!("Oh no! This should never happen, as x was part of an assert"),
}

Implementations§

source§

impl<B> Solver<B>
where B: Backend,

source

pub fn new(backend: B) -> Result<Self, Error>

Construct a new solver provided with the backend to use.

The read more about which backends are available, check out the documentation of the backend module.

source

pub fn set_logic(&mut self, logic: Logic) -> Result<(), Error>

Explicitly sets the logic for the solver. For some backends this is not required, as they will infer what ever logic fits the current program.

To read more about logics read the documentation of Logic.

source

pub fn run_command(&mut self, cmd: &Command) -> Result<GeneralResponse, Error>

Runs the given command on the solver, and returns the result.

source

pub fn assert(&mut self, b: Bool) -> Result<(), Error>

Adds the constraint of b as an assertion to the solver. To check for satisfiability call Solver::check_sat or Solver::check_sat_with_model.

source

pub fn check_sat(&mut self) -> Result<SatResult, Error>

Checks for satisfiability of the assertions sent to the solver using Solver::assert.

If you are interested in producing a model satisfying the assertions check out Solver::check_sat.

source

pub fn check_sat_with_model(&mut self) -> Result<SatResultWithModel, Error>

Checks for satisfiability of the assertions sent to the solver using Solver::assert, and produces a model in case of sat.

If you are not interested in the produced model, check out Solver::check_sat.

source

pub fn get_model(&mut self) -> Result<Model, Error>

Produces the model for satisfying the assertions. If you are looking to retrieve a model after calling Solver::check_sat, consider using Solver::check_sat_with_model instead.

NOTE: This must only be called after having called Solver::check_sat and it returning SatResult::Sat.

source

pub fn simplify(&mut self, t: Dynamic) -> Result<Term, Error>

Simplifies the given term

Trait Implementations§

source§

impl<B: Debug> Debug for Solver<B>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Freeze for Solver<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Solver<B>
where B: RefUnwindSafe,

§

impl<B> Send for Solver<B>
where B: Send,

§

impl<B> Sync for Solver<B>
where B: Sync,

§

impl<B> Unpin for Solver<B>
where B: Unpin,

§

impl<B> UnwindSafe for Solver<B>
where B: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where 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 T
where 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.