Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub terms: TermManager,
    /* private fields */
}
Expand description

Solver context for managing the solving process

The Context provides a high-level API for SMT solving, similar to the SMT-LIB2 standard. It manages declarations, assertions, and solver state.

§Examples

§Basic Usage

use oxiz_solver::Context;

let mut ctx = Context::new();
ctx.set_logic("QF_UF");

// Declare boolean constants
let p = ctx.declare_const("p", ctx.terms.sorts.bool_sort);
let q = ctx.declare_const("q", ctx.terms.sorts.bool_sort);

// Assert p AND q
let formula = ctx.terms.mk_and(vec![p, q]);
ctx.assert(formula);

// Check satisfiability
ctx.check_sat();

§SMT-LIB2 Script Execution

use oxiz_solver::Context;

let mut ctx = Context::new();

let script = r#"
(set-logic QF_LIA)
(declare-const x Int)
(assert (>= x 0))
(assert (<= x 10))
(check-sat)
"#;

let _ = ctx.execute_script(script);

Fields§

§terms: TermManager

Term manager

Implementations§

Source§

impl Context

Source

pub fn new() -> Self

Create a new context

Source

pub fn declare_const(&mut self, name: &str, sort: SortId) -> TermId

Declare a constant

Source

pub fn declare_fun( &mut self, name: &str, arg_sorts: Vec<SortId>, ret_sort: SortId, )

Declare a function

Registers a function signature in the context. For nullary functions (constants), use declare_const instead.

Source

pub fn get_fun_signature(&self, name: &str) -> Option<(Vec<SortId>, SortId)>

Get function signature if it exists

Source

pub fn set_logic(&mut self, logic: &str)

Set the logic

Source

pub fn logic(&self) -> Option<&str>

Get the current logic

Source

pub fn assert(&mut self, term: TermId)

Add an assertion

Source

pub fn check_sat(&mut self) -> SolverResult

Check satisfiability

Source

pub fn get_model(&self) -> Option<Vec<(String, String, String)>>

Get the model (if SAT) Returns a list of (name, sort, value) tuples

Source

pub fn format_model(&self) -> String

Format the model as SMT-LIB2

Source

pub fn push(&mut self)

Push a context level

Source

pub fn pop(&mut self)

Pop a context level with incremental declaration removal

Source

pub fn reset(&mut self)

Reset the context

Source

pub fn reset_assertions(&mut self)

Reset assertions (keep declarations and options)

Source

pub fn get_assertions(&self) -> &[TermId]

Get all current assertions

Source

pub fn format_assertions(&self) -> String

Format assertions as SMT-LIB2

Source

pub fn set_option(&mut self, key: &str, value: &str)

Set an option

Source

pub fn get_option(&self, key: &str) -> Option<&str>

Get an option

Source

pub fn get_assignment(&self) -> String

Get assignment (for propositional variables with :named attribute) Returns an empty list as we don’t track named literals yet

Source

pub fn get_proof(&self) -> String

Get proof (if proof generation is enabled and result is unsat)

Source

pub fn get_statistics(&self) -> String

Get solver statistics Returns statistics about the last solving run

Source

pub fn execute_script(&mut self, script: &str) -> Result<Vec<String>>

Execute an SMT-LIB2 script

Source

pub fn stats(&self) -> &SolverStats

Get solver statistics

Trait Implementations§

Source§

impl Debug for Context

Source§

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

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

impl Default for Context

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more