Struct z3::Tactic

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

Basic building block for creating custom solvers for specific problem domains.

Z3 provides a variety of tactics, which can be queried via Tactic::list_all(). Individual tactics can be created via Tactic::new().

Various combinators are available to combine tactics:

Finally, a solver utilizing a tactic can be created via Tactic::solver().

Implementations§

source§

impl<'ctx> Tactic<'ctx>

source

pub fn list_all( ctx: &'ctx Context ) -> impl Iterator<Item = Result<&'ctx str, Utf8Error>>

Iterate through the valid tactic names.

Example
use z3::{Config, Context, Tactic};

let cfg = Config::new();
let ctx = Context::new(&cfg);
let tactics: Vec<_> = Tactic::list_all(&ctx).filter_map(|r| r.ok()).collect();
assert!(tactics.contains(&"ufbv"));
source

pub fn new(ctx: &'ctx Context, name: &str) -> Tactic<'ctx>

Create a tactic by name.

Example
use z3::{Config, Context, Tactic};

let cfg = Config::new();
let ctx = Context::new(&cfg);
let tactic = Tactic::new(&ctx, "nlsat");
See also
source

pub fn create_skip(ctx: &'ctx Context) -> Tactic<'ctx>

Return a tactic that just return the given goal.

source

pub fn create_fail(ctx: &'ctx Context) -> Tactic<'ctx>

Return a tactic that always fails.

source

pub fn repeat(ctx: &'ctx Context, t: &Tactic<'ctx>, max: u32) -> Tactic<'ctx>

Return a tactic that keeps applying t until the goal is not modified anymore or the maximum number of iterations max is reached.

source

pub fn try_for(&self, timeout: Duration) -> Tactic<'ctx>

Return a tactic that applies the current tactic to a given goal, failing if it doesn’t terminate within the period specified by timeout.

source

pub fn and_then(&self, then_tactic: &Tactic<'ctx>) -> Tactic<'ctx>

Return a tactic that applies the current tactic to a given goal and the then_tactic to every subgoal produced by the original tactic.

source

pub fn or_else(&self, else_tactic: &Tactic<'ctx>) -> Tactic<'ctx>

Return a tactic that current tactic to a given goal, if it fails then returns the result of else_tactic applied to the given goal.

source

pub fn probe_or_else(&self, p: &Probe<'ctx>, t: &Tactic<'ctx>) -> Tactic<'ctx>

Return a tactic that applies self to a given goal if the probe p evaluates to true, and t if p evaluates to false.

source

pub fn when(&self, p: &Probe<'ctx>) -> Tactic<'ctx>

Return a tactic that applies itself to a given goal if the probe p evaluates to true. If p evaluates to false, then the new tactic behaves like the skip tactic.

source

pub fn cond( ctx: &'ctx Context, p: &Probe<'ctx>, t1: &Tactic<'ctx>, t2: &Tactic<'ctx> ) -> Tactic<'ctx>

Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluates to false.

source

pub fn fail_if(ctx: &'ctx Context, p: &Probe<'ctx>) -> Tactic<'ctx>

Return a tactic that fails if the probe p evaluates to false.

source

pub fn apply( &self, goal: &Goal<'ctx>, params: Option<&Params<'ctx>> ) -> Result<ApplyResult<'ctx>, String>

Attempts to apply the tactic to goal. If the tactic succeeds, returns Ok(_) with a ApplyResult. If the tactic fails, returns Err(_) with an error message describing why.

source

pub fn solver(&self) -> Solver<'ctx>

Create a new solver that is implemented using the given tactic.

Example
use z3::{ast, Config, Context, SatResult, Tactic};

let cfg = Config::new();
let ctx = Context::new(&cfg);
let tactic = Tactic::new(&ctx, "qfnra");
let solver = tactic.solver();

let x = ast::Int::new_const(&ctx, "x");
let y = ast::Int::new_const(&ctx, "y");

solver.assert(&x.gt(&y));
assert_eq!(solver.check(), SatResult::Sat);

Trait Implementations§

source§

impl<'ctx> Debug for Tactic<'ctx>

source§

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

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

impl<'ctx> Display for Tactic<'ctx>

source§

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

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

impl<'ctx> Drop for Tactic<'ctx>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'ctx> RefUnwindSafe for Tactic<'ctx>

§

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

§

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

§

impl<'ctx> Unpin for Tactic<'ctx>

§

impl<'ctx> UnwindSafe for Tactic<'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> 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.