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
impl RecFuncDecl
pub fn new<S: Into<Symbol>>(name: S, domain: &[&Sort], range: &Sort) -> Self
Sourcepub fn add_def(&self, args: &[&dyn Ast], body: &dyn Ast)
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>§
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(
"f",
&[&Sort::int(), &Sort::real()],
&Sort::int());
assert_eq!(f.arity(), 2);Sourcepub fn apply(&self, args: &[&dyn Ast]) -> Dynamic
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.
Sourcepub fn name(&self) -> String
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.