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>
impl<'ctx> RecFuncDecl<'ctx>
pub fn new<S: Into<Symbol>>( ctx: &'ctx Context, name: S, domain: &[&Sort<'ctx>], range: &Sort<'ctx> ) -> Self
sourcepub fn add_def(&self, args: &[&dyn Ast<'ctx>], body: &dyn Ast<'ctx>)
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>>§
sourcepub fn arity(&self) -> usize
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);
Trait Implementations§
source§impl<'ctx> Debug for RecFuncDecl<'ctx>
impl<'ctx> Debug for RecFuncDecl<'ctx>
source§impl<'ctx> Deref for RecFuncDecl<'ctx>
impl<'ctx> Deref for RecFuncDecl<'ctx>
source§impl<'ctx> Display for RecFuncDecl<'ctx>
impl<'ctx> Display for RecFuncDecl<'ctx>
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> 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
Mutably borrows from an owned value. Read more