Skip to main content

FuncDecl

Struct FuncDecl 

Source
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

Source

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

Source

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
Source

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
Source

pub fn linear_order<A: Borrow<Sort>>(a: A, id: usize) -> Self

Source

pub fn tree_order<A: Borrow<Sort>>(a: A, id: usize) -> Self

Source

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
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 FuncDecl

Source§

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

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

impl Display for FuncDecl

Source§

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

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

impl Drop for FuncDecl

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Translate for FuncDecl

Source§

fn translate(&self, dest: &Context) -> Self

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<T> PrepareSynchronized for T
where T: Translate,

Source§

type Inner = T

Source§

fn synchronized(&self) -> Synchronized<<T as PrepareSynchronized>::Inner>

Creates a thread-safe wrapper that is both Send and Sync. Read more
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.