Z3
 
Loading...
Searching...
No Matches
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)
 
def from_string (self, s)
 
def serialize (self)
 
- Public Member Functions inherited from AstRef
def __init__ (self, ast, ctx=None)
 
def __del__ (self)
 
def __deepcopy__ (self, memo={})
 
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
 
- Protected Member Functions inherited from Z3PPObject
def _repr_html_ (self)
 

Detailed Description

Quantifiers.

Universally and Existentially quantified formulas.

Definition at line 1988 of file z3py.py.

Member Function Documentation

◆ __getitem__()

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

Definition at line 2045 of file z3py.py.

2045 def __getitem__(self, arg):
2046 """Return the Z3 expression `self[arg]`.
2047 """
2048 if z3_debug():
2049 _z3_assert(self.is_lambda(), "quantifier should be a lambda expression")
2050 return _array_select(self, arg)
2051

◆ as_ast()

def as_ast (   self)
Return a pointer to the corresponding C Z3_ast object.

Reimplemented from ExprRef.

Definition at line 1991 of file z3py.py.

1991 def as_ast(self):
1992 return self.ast
1993

Referenced by AstRef.__del__(), SeqRef.__ge__(), SeqRef.__getitem__(), SeqRef.__gt__(), BitVecRef.__invert__(), SeqRef.__le__(), CharRef.__le__(), SeqRef.__lt__(), ArithRef.__neg__(), BitVecRef.__neg__(), AlgebraicNumRef.approx(), ExprRef.arg(), IntNumRef.as_binary_string(), BitVecNumRef.as_binary_string(), RatNumRef.as_decimal(), AlgebraicNumRef.as_decimal(), IntNumRef.as_string(), RatNumRef.as_string(), BitVecNumRef.as_string(), FiniteDomainRef.as_string(), FiniteDomainNumRef.as_string(), FPRef.as_string(), FPRMRef.as_string(), FPNumRef.as_string(), SeqRef.as_string(), SeqRef.at(), ExprRef.decl(), ArrayRef.default(), RatNumRef.denominator(), AstRef.eq(), FPNumRef.exponent(), FPNumRef.exponent_as_bv(), FPNumRef.exponent_as_long(), AstRef.get_id(), SortRef.get_id(), FuncDeclRef.get_id(), ExprRef.get_id(), PatternRef.get_id(), QuantifierRef.get_id(), AstRef.hash(), AlgebraicNumRef.index(), CharRef.is_digit(), SeqRef.is_string(), SeqRef.is_string_value(), FPNumRef.isInf(), FPNumRef.isNaN(), FPNumRef.isNegative(), FPNumRef.isNormal(), FPNumRef.isPositive(), FPNumRef.isSubnormal(), FPNumRef.isZero(), ExprRef.num_args(), RatNumRef.numerator(), AlgebraicNumRef.poly(), AstRef.sexpr(), FPNumRef.sign(), FPNumRef.sign_as_bv(), FPNumRef.significand(), FPNumRef.significand_as_bv(), FPNumRef.significand_as_long(), ExprRef.sort(), BoolRef.sort(), QuantifierRef.sort(), ArithRef.sort(), BitVecRef.sort(), ArrayRef.sort(), DatatypeRef.sort(), FiniteDomainRef.sort(), FPRef.sort(), SeqRef.sort(), CharRef.to_bv(), CharRef.to_int(), and AstRef.translate().

◆ body()

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 2106 of file z3py.py.

2106 def body(self):
2107 """Return the expression being quantified.
2108
2109 >>> f = Function('f', IntSort(), IntSort())
2110 >>> x = Int('x')
2111 >>> q = ForAll(x, f(x) == 0)
2112 >>> q.body()
2113 f(Var(0)) == 0
2114 """
2115 return _to_expr_ref(Z3_get_quantifier_body(self.ctx_ref(), self.ast), self.ctx)
2116
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.

Referenced by QuantifierRef.children().

◆ children()

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]

Reimplemented from ExprRef.

Definition at line 2161 of file z3py.py.

2161 def children(self):
2162 """Return a list containing a single element self.body()
2163
2164 >>> f = Function('f', IntSort(), IntSort())
2165 >>> x = Int('x')
2166 >>> q = ForAll(x, f(x) == 0)
2167 >>> q.children()
2168 [f(Var(0)) == 0]
2169 """
2170 return [self.body()]
2171
2172

◆ get_id()

def get_id (   self)
Return unique identifier for object. It can be used for hash-tables and maps.

Reimplemented from ExprRef.

Definition at line 1994 of file z3py.py.

1994 def get_id(self):
1995 return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
1996
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....

◆ is_exists()

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 2017 of file z3py.py.

2017 def is_exists(self):
2018 """Return `True` if `self` is an existential quantifier.
2019
2020 >>> f = Function('f', IntSort(), IntSort())
2021 >>> x = Int('x')
2022 >>> q = ForAll(x, f(x) == 0)
2023 >>> q.is_exists()
2024 False
2025 >>> q = Exists(x, f(x) != 0)
2026 >>> q.is_exists()
2027 True
2028 """
2029 return Z3_is_quantifier_exists(self.ctx_ref(), self.ast)
2030
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.

◆ is_forall()

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 2003 of file z3py.py.

2003 def is_forall(self):
2004 """Return `True` if `self` is a universal quantifier.
2005
2006 >>> f = Function('f', IntSort(), IntSort())
2007 >>> x = Int('x')
2008 >>> q = ForAll(x, f(x) == 0)
2009 >>> q.is_forall()
2010 True
2011 >>> q = Exists(x, f(x) != 0)
2012 >>> q.is_forall()
2013 False
2014 """
2015 return Z3_is_quantifier_forall(self.ctx_ref(), self.ast)
2016
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.

◆ is_lambda()

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 2031 of file z3py.py.

2031 def is_lambda(self):
2032 """Return `True` if `self` is a lambda expression.
2033
2034 >>> f = Function('f', IntSort(), IntSort())
2035 >>> x = Int('x')
2036 >>> q = Lambda(x, f(x))
2037 >>> q.is_lambda()
2038 True
2039 >>> q = Exists(x, f(x) != 0)
2040 >>> q.is_lambda()
2041 False
2042 """
2043 return Z3_is_lambda(self.ctx_ref(), self.ast)
2044
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.

Referenced by QuantifierRef.__getitem__(), and QuantifierRef.sort().

◆ no_pattern()

def no_pattern (   self,
  idx 
)
Return a no-pattern.

Definition at line 2100 of file z3py.py.

2100 def no_pattern(self, idx):
2101 """Return a no-pattern."""
2102 if z3_debug():
2103 _z3_assert(idx < self.num_no_patterns(), "Invalid no-pattern idx")
2104 return _to_expr_ref(Z3_get_quantifier_no_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2105
Z3_ast Z3_API Z3_get_quantifier_no_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th no_pattern.

◆ num_no_patterns()

def num_no_patterns (   self)
Return the number of no-patterns.

Definition at line 2096 of file z3py.py.

2096 def num_no_patterns(self):
2097 """Return the number of no-patterns."""
2098 return Z3_get_quantifier_num_no_patterns(self.ctx_ref(), self.ast)
2099
unsigned Z3_API Z3_get_quantifier_num_no_patterns(Z3_context c, Z3_ast a)
Return number of no_patterns used in quantifier.

Referenced by QuantifierRef.no_pattern().

◆ num_patterns()

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 2066 of file z3py.py.

2066 def num_patterns(self):
2067 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2068
2069 >>> f = Function('f', IntSort(), IntSort())
2070 >>> g = Function('g', IntSort(), IntSort())
2071 >>> x = Int('x')
2072 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2073 >>> q.num_patterns()
2074 2
2075 """
2076 return int(Z3_get_quantifier_num_patterns(self.ctx_ref(), self.ast))
2077
unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a)
Return number of patterns used in quantifier.

Referenced by QuantifierRef.pattern().

◆ num_vars()

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 2117 of file z3py.py.

2117 def num_vars(self):
2118 """Return the number of variables bounded by this quantifier.
2119
2120 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2121 >>> x = Int('x')
2122 >>> y = Int('y')
2123 >>> q = ForAll([x, y], f(x, y) >= x)
2124 >>> q.num_vars()
2125 2
2126 """
2127 return int(Z3_get_quantifier_num_bound(self.ctx_ref(), self.ast))
2128
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a)
Return number of bound variables of quantifier.

Referenced by QuantifierRef.var_name(), and QuantifierRef.var_sort().

◆ pattern()

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 2078 of file z3py.py.

2078 def pattern(self, idx):
2079 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2080
2081 >>> f = Function('f', IntSort(), IntSort())
2082 >>> g = Function('g', IntSort(), IntSort())
2083 >>> x = Int('x')
2084 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2085 >>> q.num_patterns()
2086 2
2087 >>> q.pattern(0)
2088 f(Var(0))
2089 >>> q.pattern(1)
2090 g(Var(0))
2091 """
2092 if z3_debug():
2093 _z3_assert(idx < self.num_patterns(), "Invalid pattern idx")
2094 return PatternRef(Z3_get_quantifier_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2095
Z3_pattern Z3_API Z3_get_quantifier_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th pattern.

◆ sort()

def sort (   self)
Return the Boolean sort or sort of Lambda.

Reimplemented from BoolRef.

Definition at line 1997 of file z3py.py.

1997 def sort(self):
1998 """Return the Boolean sort or sort of Lambda."""
1999 if self.is_lambda():
2000 return _sort(self.ctx, self.as_ast())
2001 return BoolSort(self.ctx)
2002

Referenced by FPNumRef.as_string(), ArrayRef.domain(), ArrayRef.domain_n(), FPRef.ebits(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), FPRef.sbits(), BitVecRef.size(), and ExprRef.sort_kind().

◆ var_name()

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 2129 of file z3py.py.

2129 def var_name(self, idx):
2130 """Return a string representing a name used when displaying the quantifier.
2131
2132 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2133 >>> x = Int('x')
2134 >>> y = Int('y')
2135 >>> q = ForAll([x, y], f(x, y) >= x)
2136 >>> q.var_name(0)
2137 'x'
2138 >>> q.var_name(1)
2139 'y'
2140 """
2141 if z3_debug():
2142 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2143 return _symbol2py(self.ctx, Z3_get_quantifier_bound_name(self.ctx_ref(), self.ast, idx))
2144
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.

◆ var_sort()

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 2145 of file z3py.py.

2145 def var_sort(self, idx):
2146 """Return the sort of a bound variable.
2147
2148 >>> f = Function('f', IntSort(), RealSort(), IntSort())
2149 >>> x = Int('x')
2150 >>> y = Real('y')
2151 >>> q = ForAll([x, y], f(x, y) >= x)
2152 >>> q.var_sort(0)
2153 Int
2154 >>> q.var_sort(1)
2155 Real
2156 """
2157 if z3_debug():
2158 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2159 return _to_sort_ref(Z3_get_quantifier_bound_sort(self.ctx_ref(), self.ast, idx), self.ctx)
2160
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.

◆ weight()

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 2052 of file z3py.py.

2052 def weight(self):
2053 """Return the weight annotation of `self`.
2054
2055 >>> f = Function('f', IntSort(), IntSort())
2056 >>> x = Int('x')
2057 >>> q = ForAll(x, f(x) == 0)
2058 >>> q.weight()
2059 1
2060 >>> q = ForAll(x, f(x) == 0, weight=10)
2061 >>> q.weight()
2062 10
2063 """
2064 return int(Z3_get_quantifier_weight(self.ctx_ref(), self.ast))
2065
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.