Skip to main content

RecFuncDecl

Struct RecFuncDecl 

Source
pub struct RecFuncDecl { /* private fields */ }
Expand description

Recursive function declaration. Every function has an associated declaration.

The declaration assigns a name, a return sort (i.e., type), and the sort (i.e., type) of each of its arguments. This is the function declaration type you should use if you want to add a definition to your function, recursive or not.

This struct can dereference into a FuncDecl to access its methods.

§See also:

Implementations§

Source§

impl RecFuncDecl

Source

pub fn new<S: Into<Symbol>>(name: S, domain: &[&Sort], range: &Sort) -> Self

Source

pub fn add_def(&self, args: &[&dyn Ast], body: &dyn Ast)

Adds the body to a recursive function.

let mut f = RecFuncDecl::new(
    "f",
    &[&Sort::int()],
    &Sort::int());
let n = Int::new_const("n");
f.add_def(
    &[&n],
    &Int::add(&[&n, &Int::from_i64(1)])
);

let f_of_n = &f.apply(&[&n.clone()]);

let solver = Solver::new();
let forall: z3::ast::Bool = z3::ast::forall_const(
        &[&n],
        &[],
        &n.lt(&f_of_n.as_int().unwrap())
    ).try_into().unwrap();

solver.assert(&forall);
let res = solver.check();
assert_eq!(res, SatResult::Sat);

Note that args should have the types corresponding to the domain of the RecFuncDecl.

Methods from Deref<Target = FuncDecl>§

Source

pub fn arity(&self) -> usize

Return the number of arguments of a function declaration.

If the function declaration is a constant, then the arity is 0.

let f = FuncDecl::new(
    "f",
    &[&Sort::int(), &Sort::real()],
    &Sort::int());
assert_eq!(f.arity(), 2);
Source

pub fn apply(&self, args: &[&dyn Ast]) -> Dynamic

Create a constant (if args has length 0) or function application (otherwise).

Note that args should have the types corresponding to the domain of the FuncDecl.

Source

pub fn kind(&self) -> DeclKind

Return the DeclKind of this FuncDecl.

Source

pub fn name(&self) -> String

Return the name of this FuncDecl.

Strings will return the Symbol. Ints will have a "k!" prepended to the Symbol.

Source

pub fn domain(&self, i: usize) -> Option<SortKind>

Returns the kind of the i-th domain (parameter) of this FuncDecl.

Returns None if i >= |domain|.

Source

pub fn range(&self) -> SortKind

Returns the kind of range (output) of this FuncDecl.

Trait Implementations§

Source§

impl Debug for RecFuncDecl

Source§

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

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

impl Deref for RecFuncDecl

Source§

type Target = FuncDecl

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Display for RecFuncDecl

Source§

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

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

impl Drop for RecFuncDecl

Source§

fn drop(&mut self)

Executes the destructor for this 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, 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, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

Source§

fn into_ast(self, _a: &A) -> A

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.