Z3
Public Member Functions
QuantifierRef Class Reference

Quantifiers. More...

+ Inheritance diagram for QuantifierRef:

Public Member Functions

def as_ast (self)
 
def get_id (self)
 
def sort (self)
 
def is_forall (self)
 
def is_exists (self)
 
def is_lambda (self)
 
def __getitem__ (self, arg)
 
def weight (self)
 
def num_patterns (self)
 
def pattern (self, idx)
 
def num_no_patterns (self)
 
def no_pattern (self, idx)
 
def body (self)
 
def num_vars (self)
 
def var_name (self, idx)
 
def var_sort (self, idx)
 
def children (self)
 
- Public Member Functions inherited from BoolRef
def sort (self)
 
def __rmul__ (self, other)
 
def __mul__ (self, other)
 
- Public Member Functions inherited from ExprRef
def as_ast (self)
 
def get_id (self)
 
def sort (self)
 
def sort_kind (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __ne__ (self, other)
 
def params (self)
 
def decl (self)
 
def num_args (self)
 
def arg (self, idx)
 
def children (self)
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__ (self)
 
def __deepcopy__
 
def __str__ (self)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (self)
 
def as_ast (self)
 
def get_id (self)
 
def ctx_ref (self)
 
def eq (self, other)
 
def translate (self, target)
 
def __copy__ (self)
 
def hash (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Additional Inherited Members

- Data Fields inherited from AstRef
 ast
 
 ctx
 

Detailed Description

Quantifiers.

Universally and Existentially quantified formulas.

Definition at line 1954 of file z3py.py.

Member Function Documentation

def __getitem__ (   self,
  arg 
)
Return the Z3 expression `self[arg]`.

Definition at line 2011 of file z3py.py.

2011  def __getitem__(self, arg):
2012  """Return the Z3 expression `self[arg]`.
2013  """
2014  if z3_debug():
2015  _z3_assert(self.is_lambda(), "quantifier should be a lambda expression")
2016  arg = self.sort().domain().cast(arg)
2017  return _to_expr_ref(Z3_mk_select(self.ctx_ref(), self.as_ast(), arg.as_ast()), self.ctx)
2018 
def as_ast(self)
Definition: z3py.py:391
def is_lambda(self)
Definition: z3py.py:1997
def __getitem__(self, arg)
Definition: z3py.py:2011
def sort(self)
Definition: z3py.py:977
def z3_debug()
Definition: z3py.py:64
def ctx_ref(self)
Definition: z3py.py:399
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i)
Array read. The argument a is the array and i is the index of the array that gets read...
def as_ast (   self)

Definition at line 1957 of file z3py.py.

1957  def as_ast(self):
1958  return self.ast
1959 
def as_ast(self)
Definition: z3py.py:1957
def body (   self)
Return the expression being quantified.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0)
>>> q.body()
f(Var(0)) == 0

Definition at line 2073 of file z3py.py.

Referenced by QuantifierRef.children().

2073  def body(self):
2074  """Return the expression being quantified.
2075 
2076  >>> f = Function('f', IntSort(), IntSort())
2077  >>> x = Int('x')
2078  >>> q = ForAll(x, f(x) == 0)
2079  >>> q.body()
2080  f(Var(0)) == 0
2081  """
2082  return _to_expr_ref(Z3_get_quantifier_body(self.ctx_ref(), self.ast), self.ctx)
2083 
def ctx_ref(self)
Definition: z3py.py:399
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.
def body(self)
Definition: z3py.py:2073
def children (   self)
Return a list containing a single element self.body()

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0)
>>> q.children()
[f(Var(0)) == 0]

Definition at line 2128 of file z3py.py.

2128  def children(self):
2129  """Return a list containing a single element self.body()
2130 
2131  >>> f = Function('f', IntSort(), IntSort())
2132  >>> x = Int('x')
2133  >>> q = ForAll(x, f(x) == 0)
2134  >>> q.children()
2135  [f(Var(0)) == 0]
2136  """
2137  return [self.body()]
2138 
2139 
def children(self)
Definition: z3py.py:2128
def body(self)
Definition: z3py.py:2073
def get_id (   self)

Definition at line 1960 of file z3py.py.

1960  def get_id(self):
1961  return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
1962 
def get_id(self)
Definition: z3py.py:1960
def as_ast(self)
Definition: z3py.py:391
unsigned Z3_API Z3_get_ast_id(Z3_context c, Z3_ast t)
Return a unique identifier for t. The identifier is unique up to structural equality. Thus, two ast nodes created by the same context and having the same children and same function symbols have the same identifiers. Ast nodes created in the same context, but having different children or different functions have different identifiers. Variables and quantifiers are also assigned different identifiers according to their structure.
def ctx_ref(self)
Definition: z3py.py:399
def is_exists (   self)
Return `True` if `self` is an existential quantifier.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0)
>>> q.is_exists()
False
>>> q = Exists(x, f(x) != 0)
>>> q.is_exists()
True

Definition at line 1983 of file z3py.py.

1983  def is_exists(self):
1984  """Return `True` if `self` is an existential quantifier.
1985 
1986  >>> f = Function('f', IntSort(), IntSort())
1987  >>> x = Int('x')
1988  >>> q = ForAll(x, f(x) == 0)
1989  >>> q.is_exists()
1990  False
1991  >>> q = Exists(x, f(x) != 0)
1992  >>> q.is_exists()
1993  True
1994  """
1995  return Z3_is_quantifier_exists(self.ctx_ref(), self.ast)
1996 
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.
def is_exists(self)
Definition: z3py.py:1983
def ctx_ref(self)
Definition: z3py.py:399
def is_forall (   self)
Return `True` if `self` is a universal quantifier.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0)
>>> q.is_forall()
True
>>> q = Exists(x, f(x) != 0)
>>> q.is_forall()
False

Definition at line 1969 of file z3py.py.

1969  def is_forall(self):
1970  """Return `True` if `self` is a universal quantifier.
1971 
1972  >>> f = Function('f', IntSort(), IntSort())
1973  >>> x = Int('x')
1974  >>> q = ForAll(x, f(x) == 0)
1975  >>> q.is_forall()
1976  True
1977  >>> q = Exists(x, f(x) != 0)
1978  >>> q.is_forall()
1979  False
1980  """
1981  return Z3_is_quantifier_forall(self.ctx_ref(), self.ast)
1982 
def is_forall(self)
Definition: z3py.py:1969
def ctx_ref(self)
Definition: z3py.py:399
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.
def is_lambda (   self)
Return `True` if `self` is a lambda expression.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = Lambda(x, f(x))
>>> q.is_lambda()
True
>>> q = Exists(x, f(x) != 0)
>>> q.is_lambda()
False

Definition at line 1997 of file z3py.py.

Referenced by QuantifierRef.__getitem__().

1997  def is_lambda(self):
1998  """Return `True` if `self` is a lambda expression.
1999 
2000  >>> f = Function('f', IntSort(), IntSort())
2001  >>> x = Int('x')
2002  >>> q = Lambda(x, f(x))
2003  >>> q.is_lambda()
2004  True
2005  >>> q = Exists(x, f(x) != 0)
2006  >>> q.is_lambda()
2007  False
2008  """
2009  return Z3_is_lambda(self.ctx_ref(), self.ast)
2010 
def is_lambda(self)
Definition: z3py.py:1997
def ctx_ref(self)
Definition: z3py.py:399
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.
def no_pattern (   self,
  idx 
)
Return a no-pattern.

Definition at line 2067 of file z3py.py.

2067  def no_pattern(self, idx):
2068  """Return a no-pattern."""
2069  if z3_debug():
2070  _z3_assert(idx < self.num_no_patterns(), "Invalid no-pattern idx")
2071  return _to_expr_ref(Z3_get_quantifier_no_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2072 
def num_no_patterns(self)
Definition: z3py.py:2063
Z3_ast Z3_API Z3_get_quantifier_no_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th no_pattern.
def z3_debug()
Definition: z3py.py:64
def ctx_ref(self)
Definition: z3py.py:399
def no_pattern(self, idx)
Definition: z3py.py:2067
def num_no_patterns (   self)
Return the number of no-patterns.

Definition at line 2063 of file z3py.py.

Referenced by QuantifierRef.no_pattern().

2063  def num_no_patterns(self):
2064  """Return the number of no-patterns."""
2065  return Z3_get_quantifier_num_no_patterns(self.ctx_ref(), self.ast)
2066 
def num_no_patterns(self)
Definition: z3py.py:2063
def ctx_ref(self)
Definition: z3py.py:399
unsigned Z3_API Z3_get_quantifier_num_no_patterns(Z3_context c, Z3_ast a)
Return number of no_patterns used in quantifier.
def num_patterns (   self)
Return the number of patterns (i.e., quantifier instantiation hints) in `self`.

>>> f = Function('f', IntSort(), IntSort())
>>> g = Function('g', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
>>> q.num_patterns()
2

Definition at line 2033 of file z3py.py.

2033  def num_patterns(self):
2034  """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2035 
2036  >>> f = Function('f', IntSort(), IntSort())
2037  >>> g = Function('g', IntSort(), IntSort())
2038  >>> x = Int('x')
2039  >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2040  >>> q.num_patterns()
2041  2
2042  """
2043  return int(Z3_get_quantifier_num_patterns(self.ctx_ref(), self.ast))
2044 
def num_patterns(self)
Definition: z3py.py:2033
unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a)
Return number of patterns used in quantifier.
def ctx_ref(self)
Definition: z3py.py:399
def num_vars (   self)
Return the number of variables bounded by this quantifier.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> x = Int('x')
>>> y = Int('y')
>>> q = ForAll([x, y], f(x, y) >= x)
>>> q.num_vars()
2

Definition at line 2084 of file z3py.py.

2084  def num_vars(self):
2085  """Return the number of variables bounded by this quantifier.
2086 
2087  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2088  >>> x = Int('x')
2089  >>> y = Int('y')
2090  >>> q = ForAll([x, y], f(x, y) >= x)
2091  >>> q.num_vars()
2092  2
2093  """
2094  return int(Z3_get_quantifier_num_bound(self.ctx_ref(), self.ast))
2095 
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a)
Return number of bound variables of quantifier.
def ctx_ref(self)
Definition: z3py.py:399
def num_vars(self)
Definition: z3py.py:2084
def pattern (   self,
  idx 
)
Return a pattern (i.e., quantifier instantiation hints) in `self`.

>>> f = Function('f', IntSort(), IntSort())
>>> g = Function('g', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
>>> q.num_patterns()
2
>>> q.pattern(0)
f(Var(0))
>>> q.pattern(1)
g(Var(0))

Definition at line 2045 of file z3py.py.

2045  def pattern(self, idx):
2046  """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2047 
2048  >>> f = Function('f', IntSort(), IntSort())
2049  >>> g = Function('g', IntSort(), IntSort())
2050  >>> x = Int('x')
2051  >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2052  >>> q.num_patterns()
2053  2
2054  >>> q.pattern(0)
2055  f(Var(0))
2056  >>> q.pattern(1)
2057  g(Var(0))
2058  """
2059  if z3_debug():
2060  _z3_assert(idx < self.num_patterns(), "Invalid pattern idx")
2061  return PatternRef(Z3_get_quantifier_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2062 
Patterns.
Definition: z3py.py:1887
def num_patterns(self)
Definition: z3py.py:2033
Z3_pattern Z3_API Z3_get_quantifier_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th pattern.
def pattern(self, idx)
Definition: z3py.py:2045
def z3_debug()
Definition: z3py.py:64
def ctx_ref(self)
Definition: z3py.py:399
def sort (   self)
Return the Boolean sort or sort of Lambda.

Definition at line 1963 of file z3py.py.

1963  def sort(self):
1964  """Return the Boolean sort or sort of Lambda."""
1965  if self.is_lambda():
1966  return _sort(self.ctx, self.as_ast())
1967  return BoolSort(self.ctx)
1968 
def BoolSort
Definition: z3py.py:1657
def as_ast(self)
Definition: z3py.py:391
def sort(self)
Definition: z3py.py:1963
def is_lambda(self)
Definition: z3py.py:1997
def var_name (   self,
  idx 
)
Return a string representing a name used when displaying the quantifier.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> x = Int('x')
>>> y = Int('y')
>>> q = ForAll([x, y], f(x, y) >= x)
>>> q.var_name(0)
'x'
>>> q.var_name(1)
'y'

Definition at line 2096 of file z3py.py.

2096  def var_name(self, idx):
2097  """Return a string representing a name used when displaying the quantifier.
2098 
2099  >>> f = Function('f', IntSort(), IntSort(), IntSort())
2100  >>> x = Int('x')
2101  >>> y = Int('y')
2102  >>> q = ForAll([x, y], f(x, y) >= x)
2103  >>> q.var_name(0)
2104  'x'
2105  >>> q.var_name(1)
2106  'y'
2107  """
2108  if z3_debug():
2109  _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2110  return _symbol2py(self.ctx, Z3_get_quantifier_bound_name(self.ctx_ref(), self.ast, idx))
2111 
def var_name(self, idx)
Definition: z3py.py:2096
Z3_symbol Z3_API Z3_get_quantifier_bound_name(Z3_context c, Z3_ast a, unsigned i)
Return symbol of the i'th bound variable.
def z3_debug()
Definition: z3py.py:64
def ctx_ref(self)
Definition: z3py.py:399
def num_vars(self)
Definition: z3py.py:2084
def var_sort (   self,
  idx 
)
Return the sort of a bound variable.

>>> f = Function('f', IntSort(), RealSort(), IntSort())
>>> x = Int('x')
>>> y = Real('y')
>>> q = ForAll([x, y], f(x, y) >= x)
>>> q.var_sort(0)
Int
>>> q.var_sort(1)
Real

Definition at line 2112 of file z3py.py.

2112  def var_sort(self, idx):
2113  """Return the sort of a bound variable.
2114 
2115  >>> f = Function('f', IntSort(), RealSort(), IntSort())
2116  >>> x = Int('x')
2117  >>> y = Real('y')
2118  >>> q = ForAll([x, y], f(x, y) >= x)
2119  >>> q.var_sort(0)
2120  Int
2121  >>> q.var_sort(1)
2122  Real
2123  """
2124  if z3_debug():
2125  _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2126  return _to_sort_ref(Z3_get_quantifier_bound_sort(self.ctx_ref(), self.ast, idx), self.ctx)
2127 
def var_sort(self, idx)
Definition: z3py.py:2112
Z3_sort Z3_API Z3_get_quantifier_bound_sort(Z3_context c, Z3_ast a, unsigned i)
Return sort of the i'th bound variable.
def z3_debug()
Definition: z3py.py:64
def ctx_ref(self)
Definition: z3py.py:399
def num_vars(self)
Definition: z3py.py:2084
def weight (   self)
Return the weight annotation of `self`.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0)
>>> q.weight()
1
>>> q = ForAll(x, f(x) == 0, weight=10)
>>> q.weight()
10

Definition at line 2019 of file z3py.py.

2019  def weight(self):
2020  """Return the weight annotation of `self`.
2021 
2022  >>> f = Function('f', IntSort(), IntSort())
2023  >>> x = Int('x')
2024  >>> q = ForAll(x, f(x) == 0)
2025  >>> q.weight()
2026  1
2027  >>> q = ForAll(x, f(x) == 0, weight=10)
2028  >>> q.weight()
2029  10
2030  """
2031  return int(Z3_get_quantifier_weight(self.ctx_ref(), self.ast))
2032 
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.
def ctx_ref(self)
Definition: z3py.py:399
def weight(self)
Definition: z3py.py:2019