Z3
Loading...
Searching...
No Matches
QuantifierRef Class Reference

Quantifiers. More...

Inheritance diagram for QuantifierRef:

Public Member Functions

 as_ast (self)
 get_id (self)
 sort (self)
 is_forall (self)
 is_exists (self)
 is_lambda (self)
 __getitem__ (self, arg)
 weight (self)
 skolem_id (self)
 qid (self)
 num_patterns (self)
 pattern (self, idx)
 num_no_patterns (self)
 no_pattern (self, idx)
 body (self)
 num_vars (self)
 var_name (self, idx)
 var_sort (self, idx)
 children (self)
Public Member Functions inherited from BoolRef
 __add__ (self, other)
 __radd__ (self, other)
 __rmul__ (self, other)
 __mul__ (self, other)
 __and__ (self, other)
 __or__ (self, other)
 __xor__ (self, other)
 __invert__ (self)
 py_value (self)
Public Member Functions inherited from ExprRef
 sort_kind (self)
 __eq__ (self, other)
 __hash__ (self)
 __ne__ (self, other)
 params (self)
 decl (self)
 kind (self)
 num_args (self)
 arg (self, idx)
 from_string (self, s)
 serialize (self)
Public Member Functions inherited from AstRef
 __init__ (self, ast, ctx=None)
 __del__ (self)
 __deepcopy__ (self, memo={})
 __str__ (self)
 __repr__ (self)
 __eq__ (self, other)
 __hash__ (self)
 __nonzero__ (self)
 __bool__ (self)
 sexpr (self)
 ctx_ref (self)
 eq (self, other)
 translate (self, target)
 __copy__ (self)
 hash (self)
Public Member Functions inherited from Z3PPObject
 use_pp (self)

Additional Inherited Members

Data Fields inherited from AstRef
 ast = ast
 ctx = _get_ctx(ctx)
Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)

Detailed Description

Quantifiers.

Universally and Existentially quantified formulas.

Definition at line 2080 of file z3py.py.

Member Function Documentation

◆ __getitem__()

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

Definition at line 2137 of file z3py.py.

2137 def __getitem__(self, arg):
2138 """Return the Z3 expression `self[arg]`.
2139 """
2140 if z3_debug():
2141 _z3_assert(self.is_lambda(), "quantifier should be a lambda expression")
2142 return _array_select(self, arg)
2143

◆ as_ast()

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

Reimplemented from ExprRef.

Definition at line 2083 of file z3py.py.

2083 def as_ast(self):
2084 return self.ast
2085

◆ body()

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

2208 def body(self):
2209 """Return the expression being quantified.
2210
2211 >>> f = Function('f', IntSort(), IntSort())
2212 >>> x = Int('x')
2213 >>> q = ForAll(x, f(x) == 0)
2214 >>> q.body()
2215 f(Var(0)) == 0
2216 """
2217 return _to_expr_ref(Z3_get_quantifier_body(self.ctx_ref(), self.ast), self.ctx)
2218
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.

Referenced by children().

◆ children()

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

2263 def children(self):
2264 """Return a list containing a single element self.body()
2265
2266 >>> f = Function('f', IntSort(), IntSort())
2267 >>> x = Int('x')
2268 >>> q = ForAll(x, f(x) == 0)
2269 >>> q.children()
2270 [f(Var(0)) == 0]
2271 """
2272 return [self.body()]
2273
2274

◆ get_id()

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

Reimplemented from ExprRef.

Definition at line 2086 of file z3py.py.

2086 def get_id(self):
2087 return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
2088
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()

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

2109 def is_exists(self):
2110 """Return `True` if `self` is an existential quantifier.
2111
2112 >>> f = Function('f', IntSort(), IntSort())
2113 >>> x = Int('x')
2114 >>> q = ForAll(x, f(x) == 0)
2115 >>> q.is_exists()
2116 False
2117 >>> q = Exists(x, f(x) != 0)
2118 >>> q.is_exists()
2119 True
2120 """
2121 return Z3_is_quantifier_exists(self.ctx_ref(), self.ast)
2122
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.

◆ is_forall()

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

2095 def is_forall(self):
2096 """Return `True` if `self` is a universal quantifier.
2097
2098 >>> f = Function('f', IntSort(), IntSort())
2099 >>> x = Int('x')
2100 >>> q = ForAll(x, f(x) == 0)
2101 >>> q.is_forall()
2102 True
2103 >>> q = Exists(x, f(x) != 0)
2104 >>> q.is_forall()
2105 False
2106 """
2107 return Z3_is_quantifier_forall(self.ctx_ref(), self.ast)
2108
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.

◆ is_lambda()

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

2123 def is_lambda(self):
2124 """Return `True` if `self` is a lambda expression.
2125
2126 >>> f = Function('f', IntSort(), IntSort())
2127 >>> x = Int('x')
2128 >>> q = Lambda(x, f(x))
2129 >>> q.is_lambda()
2130 True
2131 >>> q = Exists(x, f(x) != 0)
2132 >>> q.is_lambda()
2133 False
2134 """
2135 return Z3_is_lambda(self.ctx_ref(), self.ast)
2136
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.

Referenced by __getitem__(), and sort().

◆ no_pattern()

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

Definition at line 2202 of file z3py.py.

2202 def no_pattern(self, idx):
2203 """Return a no-pattern."""
2204 if z3_debug():
2205 _z3_assert(idx < self.num_no_patterns(), "Invalid no-pattern idx")
2206 return _to_expr_ref(Z3_get_quantifier_no_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2207
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()

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

Definition at line 2198 of file z3py.py.

2198 def num_no_patterns(self):
2199 """Return the number of no-patterns."""
2200 return Z3_get_quantifier_num_no_patterns(self.ctx_ref(), self.ast)
2201
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 no_pattern().

◆ num_patterns()

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

2168 def num_patterns(self):
2169 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2170
2171 >>> f = Function('f', IntSort(), IntSort())
2172 >>> g = Function('g', IntSort(), IntSort())
2173 >>> x = Int('x')
2174 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2175 >>> q.num_patterns()
2176 2
2177 """
2178 return int(Z3_get_quantifier_num_patterns(self.ctx_ref(), self.ast))
2179
unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a)
Return number of patterns used in quantifier.

Referenced by pattern().

◆ num_vars()

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

2219 def num_vars(self):
2220 """Return the number of variables bounded by this quantifier.
2221
2222 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2223 >>> x = Int('x')
2224 >>> y = Int('y')
2225 >>> q = ForAll([x, y], f(x, y) >= x)
2226 >>> q.num_vars()
2227 2
2228 """
2229 return int(Z3_get_quantifier_num_bound(self.ctx_ref(), self.ast))
2230
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a)
Return number of bound variables of quantifier.

Referenced by var_name(), and var_sort().

◆ pattern()

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

2180 def pattern(self, idx):
2181 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2182
2183 >>> f = Function('f', IntSort(), IntSort())
2184 >>> g = Function('g', IntSort(), IntSort())
2185 >>> x = Int('x')
2186 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2187 >>> q.num_patterns()
2188 2
2189 >>> q.pattern(0)
2190 f(Var(0))
2191 >>> q.pattern(1)
2192 g(Var(0))
2193 """
2194 if z3_debug():
2195 _z3_assert(idx < self.num_patterns(), "Invalid pattern idx")
2196 return PatternRef(Z3_get_quantifier_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2197
Z3_pattern Z3_API Z3_get_quantifier_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th pattern.

◆ qid()

qid ( self)
Return the quantifier id of `self`.

Definition at line 2163 of file z3py.py.

2163 def qid(self):
2164 """Return the quantifier id of `self`.
2165 """
2166 return _symbol2py(self.ctx, Z3_get_quantifier_id(self.ctx_ref(), self.ast))
2167
Z3_symbol Z3_API Z3_get_quantifier_id(Z3_context c, Z3_ast a)
Obtain id of quantifier.

◆ skolem_id()

skolem_id ( self)
Return the skolem id of `self`.

Definition at line 2158 of file z3py.py.

2158 def skolem_id(self):
2159 """Return the skolem id of `self`.
2160 """
2161 return _symbol2py(self.ctx, Z3_get_quantifier_skolem_id(self.ctx_ref(), self.ast))
2162
Z3_symbol Z3_API Z3_get_quantifier_skolem_id(Z3_context c, Z3_ast a)
Obtain skolem id of quantifier.

◆ sort()

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

Reimplemented from BoolRef.

Definition at line 2089 of file z3py.py.

2089 def sort(self):
2090 """Return the Boolean sort or sort of Lambda."""
2091 if self.is_lambda():
2092 return _sort(self.ctx, self.as_ast())
2093 return BoolSort(self.ctx)
2094

◆ var_name()

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

2231 def var_name(self, idx):
2232 """Return a string representing a name used when displaying the quantifier.
2233
2234 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2235 >>> x = Int('x')
2236 >>> y = Int('y')
2237 >>> q = ForAll([x, y], f(x, y) >= x)
2238 >>> q.var_name(0)
2239 'x'
2240 >>> q.var_name(1)
2241 'y'
2242 """
2243 if z3_debug():
2244 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2245 return _symbol2py(self.ctx, Z3_get_quantifier_bound_name(self.ctx_ref(), self.ast, idx))
2246
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()

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

2247 def var_sort(self, idx):
2248 """Return the sort of a bound variable.
2249
2250 >>> f = Function('f', IntSort(), RealSort(), IntSort())
2251 >>> x = Int('x')
2252 >>> y = Real('y')
2253 >>> q = ForAll([x, y], f(x, y) >= x)
2254 >>> q.var_sort(0)
2255 Int
2256 >>> q.var_sort(1)
2257 Real
2258 """
2259 if z3_debug():
2260 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2261 return _to_sort_ref(Z3_get_quantifier_bound_sort(self.ctx_ref(), self.ast, idx), self.ctx)
2262
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()

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

2144 def weight(self):
2145 """Return the weight annotation of `self`.
2146
2147 >>> f = Function('f', IntSort(), IntSort())
2148 >>> x = Int('x')
2149 >>> q = ForAll(x, f(x) == 0)
2150 >>> q.weight()
2151 1
2152 >>> q = ForAll(x, f(x) == 0, weight=10)
2153 >>> q.weight()
2154 10
2155 """
2156 return int(Z3_get_quantifier_weight(self.ctx_ref(), self.ast))
2157
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.