Skip to main content

Prepared

Struct Prepared 

Source
pub struct Prepared<'c> { /* private fields */ }
Expand description

A fixed family of feasibility questions. Every check requires the same Boolean facts and binds any subset of the observations (words or predicates) to concrete values. The family is simplified without target assumptions, blasted and encoded once. The mutable context borrow freezes declarations and prevents rollback until the family is dropped. A returned model is checked on the original facts and requested observations.

Unlike Incremental, each search starts with a private copy of the unsearched SAT state: no learned clause, phase or spent budget leaks from another target. This trades copying the clause database for target-order independent answers, even at small limits. Preparation uses one simplify budget and one circuit cap for the whole catalog; each target gets the configured search limits. This is not the same circuit or search as a standalone question. If preparation returns Unknown::TooLarge, prepare a smaller family or ask each original question separately: it says nothing about feasibility.

use bitwright::{BitVec, Context, ParseOptions, Width};
use bitwright::prove::{Config, Prepared, Simplifiers};

let mut cx = Context::new();
let o = ParseOptions::width(Width::W8);
let fact = cx.parse("x + y == 7", &o)?;
let x = cx.parse("x", &o)?;
let goal = cx.parse("y == 4", &o)?;
let cfg = Config::default().with_sweeping(false);
let mut family = Prepared::new(&mut cx, &[fact], &[x, goal], &cfg, &Simplifiers::new())?
    .expect("supported family within its circuit cap");
let three = BitVec::from_u64(Width::W8, 3).unwrap();
// Is there a counterexample to `goal` under `fact` and `x == 3`?
assert_eq!(family.check(&[(0, three), (1, BitVec::from_bool(false))])?, Ok(None));
assert!(family.check(&[(0, three)])?.unwrap().is_some());

Implementations§

Source§

impl<'c> Prepared<'c>

Source

pub fn new( cx: &'c mut Context, facts: &[Expr], observations: &[Expr], cfg: &Config, simplifiers: &Simplifiers, ) -> Result<Result<Self, Unknown>, Error>

Prepare exact shared predicates (use Assumptions::predicates for scoped facts) and observed outputs, in the order used by check. Sampling, if enabled, only finds witnesses. Certificate requests, sweeping, word sampling, exhaustive enumeration, shared-sum rewriting and root-conditioned relational lemmas require the ordinary Question pipeline and return Unknown::Unsupported here.

Source

pub fn check( &mut self, bindings: &[(usize, BitVec)], ) -> Result<Result<Option<Model>, Unknown>, Error>

Whether the facts hold with observations[i] == value for every (i, value). Ok(Some(model)) is a replayed witness; Ok(None) is unsatisfiable. An unknown (including budget exhaustion) is not a negative answer. Indices and widths are checked even if another binding is contradictory.

Trait Implementations§

Source§

impl<'c> Debug for Prepared<'c>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'c> !RefUnwindSafe for Prepared<'c>

§

impl<'c> !UnwindSafe for Prepared<'c>

§

impl<'c> Forget for Prepared<'c>

§

impl<'c> Freeze for Prepared<'c>

§

impl<'c> Move for Prepared<'c>

§

impl<'c> Send for Prepared<'c>

§

impl<'c> Sync for Prepared<'c>

§

impl<'c> Unpin for Prepared<'c>

§

impl<'c> UnsafeUnpin for Prepared<'c>

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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.