pub struct Context { /* private fields */ }
Expand description
An SMT-LIB 2 context, usually backed by a solver subprocess.
Created via a ContextBuilder
.
Implementations§
source§impl Context
impl Context
Solver Commands and Assertions
These methods send a command or assertion to the context’s underlying solver. As such, they involve I/O with a subprocess and are therefore fallible.
Panics
These methods will panic when called if the context was not created with an
underlying solver (via
ContextBuilder::solver
).
pub fn set_option<K>(&mut self, name: K, value: SExpr) -> Result<()>where K: Into<String> + AsRef<str>,
sourcepub fn check_assuming(
&mut self,
props: impl IntoIterator<Item = SExpr>
) -> Result<Response>
pub fn check_assuming( &mut self, props: impl IntoIterator<Item = SExpr> ) -> Result<Response>
Assert check-sat-assuming
with the given list of assumptions.
sourcepub fn declare_const<S: Into<String> + AsRef<str>>(
&mut self,
name: S,
sort: SExpr
) -> Result<SExpr>
pub fn declare_const<S: Into<String> + AsRef<str>>( &mut self, name: S, sort: SExpr ) -> Result<SExpr>
Declare a new constant with the provided sort
pub fn declare_datatype<S: Into<String> + AsRef<str>>( &mut self, name: S, decl: SExpr ) -> Result<SExpr>
pub fn declare_datatypes<N, S, D>(&mut self, sorts: S, decls: D) -> Result<()>where N: Into<String> + AsRef<str>, S: IntoIterator<Item = (N, i32)>, D: IntoIterator<Item = SExpr>,
sourcepub fn declare_fun<S: Into<String> + AsRef<str>>(
&mut self,
name: S,
args: Vec<SExpr>,
out: SExpr
) -> Result<SExpr>
pub fn declare_fun<S: Into<String> + AsRef<str>>( &mut self, name: S, args: Vec<SExpr>, out: SExpr ) -> Result<SExpr>
Declares a new, uninterpreted function symbol.
sourcepub fn define_fun<S: Into<String> + AsRef<str>>(
&mut self,
name: S,
args: Vec<(S, SExpr)>,
out: SExpr,
body: SExpr
) -> Result<SExpr>
pub fn define_fun<S: Into<String> + AsRef<str>>( &mut self, name: S, args: Vec<(S, SExpr)>, out: SExpr, body: SExpr ) -> Result<SExpr>
Defines a new function with a body.
sourcepub fn define_const<S: Into<String> + AsRef<str>>(
&mut self,
name: S,
out: SExpr,
body: SExpr
) -> Result<SExpr>
pub fn define_const<S: Into<String> + AsRef<str>>( &mut self, name: S, out: SExpr, body: SExpr ) -> Result<SExpr>
Define a constant with a body with a value. This is a convenience wrapper over Self::define_fun since constants are nullary functions.
pub fn declare_sort<S: Into<String> + AsRef<str>>( &mut self, symbol: S, arity: i32 ) -> Result<SExpr>
pub fn assert(&mut self, expr: SExpr) -> Result<()>
sourcepub fn get_model(&mut self) -> Result<SExpr>
pub fn get_model(&mut self) -> Result<SExpr>
Get a model out from the solver. This is only meaningful after a check-sat
query.
sourcepub fn get_value(&mut self, vals: Vec<SExpr>) -> Result<Vec<(SExpr, SExpr)>>
pub fn get_value(&mut self, vals: Vec<SExpr>) -> Result<Vec<(SExpr, SExpr)>>
Get bindings for values in the model. This is only meaningful after a check-sat
query.
sourcepub fn get_unsat_core(&mut self) -> Result<SExpr>
pub fn get_unsat_core(&mut self) -> Result<SExpr>
Returns the names of the formulas involved in a contradiction.
pub fn set_logic<L: Into<String> + AsRef<str>>( &mut self, logic: L ) -> Result<()>
sourcepub fn push(&mut self) -> Result<()>
pub fn push(&mut self) -> Result<()>
Push a new context frame in the solver. Same as SMTLIB’s push
command.
pub fn push_many(&mut self, n: usize) -> Result<()>
sourcepub fn pop(&mut self) -> Result<()>
pub fn pop(&mut self) -> Result<()>
Pop a context frame in the solver. Same as SMTLIB’s pop
command.
pub fn pop_many(&mut self, n: usize) -> Result<()>
source§impl Context
impl Context
Basic S-Expression Construction and Inspection
These methods provide the foundation of building s-expressions. Even if you end up using higher-level helper methods most of the time, everything bottoms out in calls to these methods.
sourcepub fn atom(&self, name: impl Into<String> + AsRef<str>) -> SExpr
pub fn atom(&self, name: impl Into<String> + AsRef<str>) -> SExpr
Construct a non-list s-expression from the given string.
sourcepub fn list(&self, list: Vec<SExpr>) -> SExpr
pub fn list(&self, list: Vec<SExpr>) -> SExpr
Construct a list s-expression from the given elements.
sourcepub fn numeral(&self, val: impl IntoNumeral) -> SExpr
pub fn numeral(&self, val: impl IntoNumeral) -> SExpr
Create a numeral s-expression.
sourcepub fn decimal(&self, val: impl IntoDecimal) -> SExpr
pub fn decimal(&self, val: impl IntoDecimal) -> SExpr
Create a decimal s-expression.
sourcepub fn binary(&self, bit_width: usize, val: impl IntoBinary) -> SExpr
pub fn binary(&self, bit_width: usize, val: impl IntoBinary) -> SExpr
Create a binary s-expression of the given bit width.
sourcepub fn display(&self, expr: SExpr) -> DisplayExpr<'_>
pub fn display(&self, expr: SExpr) -> DisplayExpr<'_>
Get a std::fmt::Display
representation of the given s-expression.
This allows you to print, log, or otherwise format an s-expression creating within this context.
You may only pass in SExpr
s that were created by this
Context
. Failure to do so is safe, but may trigger a panic or return
invalid data.
sourcepub fn get(&self, expr: SExpr) -> SExprData<'_>
pub fn get(&self, expr: SExpr) -> SExprData<'_>
Get the atom or list data for the given s-expression.
This allows you to inspect s-expressions.
You may only pass in SExpr
s that were created by this
Context
. Failure to do so is safe, but may trigger a panic or return
invalid data.
sourcepub fn atoms(&self) -> &KnownAtoms
pub fn atoms(&self) -> &KnownAtoms
Access “known” atoms.
This lets you skip the is-it-already-interned-or-not checks and hash map lookups for certain frequently used atoms.
source§impl Context
impl Context
Generic and Polymorphic Helpers
Helpers for constructing s-expressions that are not specific to one sort.
pub fn par<N, S, D>(&self, symbols: S, decls: D) -> SExprwhere N: Into<String> + AsRef<str>, S: IntoIterator<Item = N>, D: IntoIterator<Item = SExpr>,
pub fn attr( &self, expr: SExpr, name: impl Into<String> + AsRef<str>, val: SExpr ) -> SExpr
pub fn named(&self, name: impl Into<String> + AsRef<str>, expr: SExpr) -> SExpr
sourcepub fn let_<N: Into<String> + AsRef<str>>(
&self,
name: N,
e: SExpr,
body: SExpr
) -> SExpr
pub fn let_<N: Into<String> + AsRef<str>>( &self, name: N, e: SExpr, body: SExpr ) -> SExpr
A let-declaration with a single binding.
sourcepub fn let_many<N, I>(&self, bindings: I, body: SExpr) -> SExprwhere
I: IntoIterator<Item = (N, SExpr)>,
N: Into<String> + AsRef<str>,
pub fn let_many<N, I>(&self, bindings: I, body: SExpr) -> SExprwhere I: IntoIterator<Item = (N, SExpr)>, N: Into<String> + AsRef<str>,
A let-declaration of multiple bindings.
sourcepub fn forall<N, I>(&self, vars: I, body: SExpr) -> SExprwhere
I: IntoIterator<Item = (N, SExpr)>,
N: Into<String> + AsRef<str>,
pub fn forall<N, I>(&self, vars: I, body: SExpr) -> SExprwhere I: IntoIterator<Item = (N, SExpr)>, N: Into<String> + AsRef<str>,
Universally quantify sorted variables in an expression.
sourcepub fn exists<N, I>(&self, vars: I, body: SExpr) -> SExprwhere
I: IntoIterator<Item = (N, SExpr)>,
N: Into<String> + AsRef<str>,
pub fn exists<N, I>(&self, vars: I, body: SExpr) -> SExprwhere I: IntoIterator<Item = (N, SExpr)>, N: Into<String> + AsRef<str>,
Existentially quantify sorted variables in an expression.
source§impl Context
impl Context
Bool Helpers
These methods help you construct s-expressions for various bool operations.
pub fn not(&self, val: SExpr) -> SExpr
pub fn imp(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn imp_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn and(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn and_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn or(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn or_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn xor(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn xor_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn eq(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn eq_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn distinct(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn distinct_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
source§impl Context
impl Context
Int Helpers
These methods help you construct s-expressions for various int operations.
pub fn negate(&self, val: SExpr) -> SExpr
pub fn sub(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn sub_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn plus(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn plus_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn times(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn times_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn div(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn div_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn modulo(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn modulo_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn rem(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn rem_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn lte(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn lte_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn lt(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn lt_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn gt(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn gt_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
pub fn gte(&self, lhs: SExpr, rhs: SExpr) -> SExpr
pub fn gte_many<I: IntoIterator<Item = SExpr>>(&self, items: I) -> SExpr
source§impl Context
impl Context
Array Helpers
These methods help you construct s-expressions for various array operations.
source§impl Context
impl Context
Bit Vector Helpers
These methods help you construct s-expressions for various bit vector operations.
sourcepub fn bit_vec_sort(&self, width: SExpr) -> SExpr
pub fn bit_vec_sort(&self, width: SExpr) -> SExpr
Construct a BitVec sort with the given width.