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: TermManagerTerm manager
Implementations§
Source§impl Context
impl Context
Sourcepub fn declare_const(&mut self, name: &str, sort: SortId) -> TermId
pub fn declare_const(&mut self, name: &str, sort: SortId) -> TermId
Declare a constant
Sourcepub fn declare_fun(
&mut self,
name: &str,
arg_sorts: Vec<SortId>,
ret_sort: SortId,
)
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.
Sourcepub fn get_fun_signature(&self, name: &str) -> Option<(Vec<SortId>, SortId)>
pub fn get_fun_signature(&self, name: &str) -> Option<(Vec<SortId>, SortId)>
Get function signature if it exists
Sourcepub fn check_sat(&mut self) -> SolverResult
pub fn check_sat(&mut self) -> SolverResult
Check satisfiability
Sourcepub fn get_model(&self) -> Option<Vec<(String, String, String)>>
pub fn get_model(&self) -> Option<Vec<(String, String, String)>>
Get the model (if SAT) Returns a list of (name, sort, value) tuples
Sourcepub fn format_model(&self) -> String
pub fn format_model(&self) -> String
Format the model as SMT-LIB2
Sourcepub fn reset_assertions(&mut self)
pub fn reset_assertions(&mut self)
Reset assertions (keep declarations and options)
Sourcepub fn get_assertions(&self) -> &[TermId]
pub fn get_assertions(&self) -> &[TermId]
Get all current assertions
Sourcepub fn format_assertions(&self) -> String
pub fn format_assertions(&self) -> String
Format assertions as SMT-LIB2
Sourcepub fn set_option(&mut self, key: &str, value: &str)
pub fn set_option(&mut self, key: &str, value: &str)
Set an option
Sourcepub fn get_option(&self, key: &str) -> Option<&str>
pub fn get_option(&self, key: &str) -> Option<&str>
Get an option
Sourcepub fn get_assignment(&self) -> String
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
Sourcepub fn get_proof(&self) -> String
pub fn get_proof(&self) -> String
Get proof (if proof generation is enabled and result is unsat)
Sourcepub fn get_statistics(&self) -> String
pub fn get_statistics(&self) -> String
Get solver statistics Returns statistics about the last solving run
Sourcepub fn execute_script(&mut self, script: &str) -> Result<Vec<String>>
pub fn execute_script(&mut self, script: &str) -> Result<Vec<String>>
Execute an SMT-LIB2 script
Sourcepub fn stats(&self) -> &SolverStats
pub fn stats(&self) -> &SolverStats
Get solver statistics
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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