Struct z3::RecFuncDecl

source ·
pub struct RecFuncDecl<'ctx> { /* 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<'ctx> RecFuncDecl<'ctx>

source

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

source

pub fn add_def(&self, args: &[&dyn Ast<'ctx>], body: &dyn Ast<'ctx>)

Adds the body to a recursive function.

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

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

let solver = Solver::new(&ctx);
let forall: z3::ast::Bool = z3::ast::forall_const(
        &ctx,
        &[&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<'ctx>>§

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(
    &ctx,
    "f",
    &[&Sort::int(&ctx), &Sort::real(&ctx)],
    &Sort::int(&ctx));
assert_eq!(f.arity(), 2);
source

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

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.

Trait Implementations§

source§

impl<'ctx> Debug for RecFuncDecl<'ctx>

source§

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

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

impl<'ctx> Deref for RecFuncDecl<'ctx>

§

type Target = FuncDecl<'ctx>

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'ctx> Display for RecFuncDecl<'ctx>

source§

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

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

impl<'ctx> Drop for RecFuncDecl<'ctx>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'ctx> RefUnwindSafe for RecFuncDecl<'ctx>

§

impl<'ctx> !Send for RecFuncDecl<'ctx>

§

impl<'ctx> !Sync for RecFuncDecl<'ctx>

§

impl<'ctx> Unpin for RecFuncDecl<'ctx>

§

impl<'ctx> UnwindSafe for RecFuncDecl<'ctx>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.