[][src]Struct gf::smt::ConstFn

pub struct ConstFn { /* fields omitted */ }

Function expression that can be evaluated to a constant value given values of its arguments.

Example

This example calculates the maximum of two 32-bit integers using a function.

let arg_x = Expr::new_fn_arg(Sort::new_bit_vec(32), "x".to_string());
let arg_y = Expr::new_fn_arg(Sort::new_bit_vec(32), "y".to_string());
let max = Expr::new_fn(
    vec![arg_x.clone(), arg_y.clone()],
    Expr::new_bit_vec_operator(
        BitVecOperator::Ite,
        vec![
            Expr::new_bit_vec_operator(
                BitVecOperator::GtU,
                vec![arg_x.clone(), arg_y.clone()],
            )?,
            arg_x,
            arg_y,
        ],
    )?,
)?;
 
assert_eq!(
    ConstFn::new(max.clone())?.eval(vec![
        ExprValue::BitVec(20u32.into()),
        ExprValue::BitVec(10u32.into()),
    ])?,
    ExprValue::BitVec(20u32.into()),
);

assert_eq!(
    ConstFn::new(max.clone())?.eval(vec![
        ExprValue::BitVec(10u32.into()),
        ExprValue::BitVec(20u32.into()),
    ])?,
    ExprValue::BitVec(20u32.into()),
);

Methods

impl ConstFn[src]

pub fn new(expr: Expr) -> Result<Self, ExprError>[src]

Wrap an expression, checking that it is a constant function.

pub unsafe fn new_unchecked(expr: Expr) -> Self[src]

Wrap an expression skipping the checks.

pub fn from_const_expr(const_expr: ConstExpr) -> Self[src]

Wrap a constant expression into a nullary constant function.

pub fn from_value(value: ExprValue) -> Self[src]

Wrap a value into a nullary constant function.

pub fn identity(sort: Sort) -> Self[src]

Create a unary identity function, the created argument is named x.

pub fn into_inner(self) -> Expr[src]

Consume the wrapper and return the underlying expression.

pub fn args(&self) -> &[Expr][src]

Return function arguments.

pub fn body(&self) -> &Expr[src]

Return function body.

pub fn is_const_fn(expr: &Expr) -> bool[src]

Check if an expression is a constant function.

pub fn eval<I>(&self, args: I) -> Result<ExprValue, ExprError> where
    I: IntoIterator<Item = ExprValue>, 
[src]

Evaluate the function application given argument values.

Trait Implementations

impl Clone for ConstFn[src]

impl Eq for ConstFn[src]

impl PartialEq<ConstFn> for ConstFn[src]

impl Debug for ConstFn[src]

impl Hash for ConstFn[src]

impl StructuralPartialEq for ConstFn[src]

impl StructuralEq for ConstFn[src]

Auto Trait Implementations

impl Send for ConstFn

impl Sync for ConstFn

impl Unpin for ConstFn

impl UnwindSafe for ConstFn

impl RefUnwindSafe for ConstFn

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]