pub struct FuncDecl { /* private fields */ }Expand description
Function declaration. Every constant and function have an associated declaration.
The declaration assigns a name, a sort (i.e., type), and for function the sort (i.e., type) of each of its arguments. Note that, in Z3, a constant is a function with 0 arguments.
§See also:
Implementations§
Source§impl FuncDecl
impl FuncDecl
pub fn new<S: Into<Symbol>>(name: S, domain: &[&Sort], range: &Sort) -> Self
Sourcepub fn partial_order<A: Borrow<Sort>>(a: A, id: usize) -> Self
pub fn partial_order<A: Borrow<Sort>>(a: A, id: usize) -> Self
Create a partial order FuncDecl “Special Relation” over the given Sort.
The Sort may have many
partial orders derived this way, distinguished by the second integer argument to this call,
which represents the “id” of the partial order. Calling this twice with the same ID will
yield the same partial order FuncDecl.
See https://microsoft.github.io/z3guide/docs/theories/Special%20Relations/ for more info.
A partial order is a binary relation that is reflexive, antisymmetric, and transitive.
§Example
let sort = Sort::int();
let partial_order = FuncDecl::partial_order(&sort, 0);
// Create a solver to assert properties of the partial order.
let solver = Solver::new();
let x = Int::new_const("x");
let y = Int::new_const("y");
let z = Int::new_const("z");
solver.assert(&partial_order.apply(&[&x, &x]).as_bool().unwrap());
// test reflexivity
assert_eq!(
solver.check_assumptions(&[partial_order.apply(&[&x, &x]).as_bool().unwrap().not()]),
SatResult::Unsat
);
// test antisymmetry
assert_eq!(
solver.check_assumptions(&[
partial_order.apply(&[&x, &y]).as_bool().unwrap(),
partial_order.apply(&[&y, &x]).as_bool().unwrap(),
x.eq(&y).not()
]),
SatResult::Unsat
);
// test transitivity
assert_eq!(
solver.check_assumptions(&[
partial_order.apply(&[&x, &y]).as_bool().unwrap(),
partial_order.apply(&[&y, &z]).as_bool().unwrap(),
partial_order.apply(&[&x, &z]).as_bool().unwrap().not(),
]),
SatResult::Unsat
);§See also
Sourcepub fn piecewise_linear_order<A: Borrow<Sort>>(a: A, id: usize) -> Self
pub fn piecewise_linear_order<A: Borrow<Sort>>(a: A, id: usize) -> Self
Create a piecewise linear order FuncDecl “Special Relation” over the given Sort.
See https://microsoft.github.io/z3guide/docs/theories/Special%20Relations/ for more info.
§See also
Sourcepub fn linear_order<A: Borrow<Sort>>(a: A, id: usize) -> Self
pub fn linear_order<A: Borrow<Sort>>(a: A, id: usize) -> Self
Create a linear order FuncDecl “Special Relation” over the given Sort.
See https://microsoft.github.io/z3guide/docs/theories/Special%20Relations/ for more info.
§See also
Sourcepub fn tree_order<A: Borrow<Sort>>(a: A, id: usize) -> Self
pub fn tree_order<A: Borrow<Sort>>(a: A, id: usize) -> Self
Create a tree order FuncDecl “Special Relation” over the given Sort.
See https://microsoft.github.io/z3guide/docs/theories/Special%20Relations/ for more info.
§See also
Sourcepub fn transitive_closure<A: Borrow<FuncDecl>>(a: A) -> Self
pub fn transitive_closure<A: Borrow<FuncDecl>>(a: A) -> Self
Create a transitive closure FuncDecl “Special Relation” over the given FuncDecl.
See https://microsoft.github.io/z3guide/docs/theories/Special%20Relations/ for more info.
§See also
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.