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)
 update (self, *args)
 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 2127 of file z3py.py.

Member Function Documentation

◆ __getitem__()

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

Definition at line 2184 of file z3py.py.

2184 def __getitem__(self, arg):
2185 """Return the Z3 expression `self[arg]`.
2186 """
2187 if z3_debug():
2188 _z3_assert(self.is_lambda(), "quantifier should be a lambda expression")
2189 return _array_select(self, arg)
2190

◆ as_ast()

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

Reimplemented from ExprRef.

Definition at line 2130 of file z3py.py.

2130 def as_ast(self):
2131 return self.ast
2132

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

2255 def body(self):
2256 """Return the expression being quantified.
2257
2258 >>> f = Function('f', IntSort(), IntSort())
2259 >>> x = Int('x')
2260 >>> q = ForAll(x, f(x) == 0)
2261 >>> q.body()
2262 f(Var(0)) == 0
2263 """
2264 return _to_expr_ref(Z3_get_quantifier_body(self.ctx_ref(), self.ast), self.ctx)
2265
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 2310 of file z3py.py.

2310 def children(self):
2311 """Return a list containing a single element self.body()
2312
2313 >>> f = Function('f', IntSort(), IntSort())
2314 >>> x = Int('x')
2315 >>> q = ForAll(x, f(x) == 0)
2316 >>> q.children()
2317 [f(Var(0)) == 0]
2318 """
2319 return [self.body()]
2320
2321

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

2133 def get_id(self):
2134 return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
2135
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 2156 of file z3py.py.

2156 def is_exists(self):
2157 """Return `True` if `self` is an existential quantifier.
2158
2159 >>> f = Function('f', IntSort(), IntSort())
2160 >>> x = Int('x')
2161 >>> q = ForAll(x, f(x) == 0)
2162 >>> q.is_exists()
2163 False
2164 >>> q = Exists(x, f(x) != 0)
2165 >>> q.is_exists()
2166 True
2167 """
2168 return Z3_is_quantifier_exists(self.ctx_ref(), self.ast)
2169
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 2142 of file z3py.py.

2142 def is_forall(self):
2143 """Return `True` if `self` is a universal quantifier.
2144
2145 >>> f = Function('f', IntSort(), IntSort())
2146 >>> x = Int('x')
2147 >>> q = ForAll(x, f(x) == 0)
2148 >>> q.is_forall()
2149 True
2150 >>> q = Exists(x, f(x) != 0)
2151 >>> q.is_forall()
2152 False
2153 """
2154 return Z3_is_quantifier_forall(self.ctx_ref(), self.ast)
2155
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 2170 of file z3py.py.

2170 def is_lambda(self):
2171 """Return `True` if `self` is a lambda expression.
2172
2173 >>> f = Function('f', IntSort(), IntSort())
2174 >>> x = Int('x')
2175 >>> q = Lambda(x, f(x))
2176 >>> q.is_lambda()
2177 True
2178 >>> q = Exists(x, f(x) != 0)
2179 >>> q.is_lambda()
2180 False
2181 """
2182 return Z3_is_lambda(self.ctx_ref(), self.ast)
2183
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 2249 of file z3py.py.

2249 def no_pattern(self, idx):
2250 """Return a no-pattern."""
2251 if z3_debug():
2252 _z3_assert(idx < self.num_no_patterns(), "Invalid no-pattern idx")
2253 return _to_expr_ref(Z3_get_quantifier_no_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2254
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 2245 of file z3py.py.

2245 def num_no_patterns(self):
2246 """Return the number of no-patterns."""
2247 return Z3_get_quantifier_num_no_patterns(self.ctx_ref(), self.ast)
2248
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 2215 of file z3py.py.

2215 def num_patterns(self):
2216 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2217
2218 >>> f = Function('f', IntSort(), IntSort())
2219 >>> g = Function('g', IntSort(), IntSort())
2220 >>> x = Int('x')
2221 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2222 >>> q.num_patterns()
2223 2
2224 """
2225 return int(Z3_get_quantifier_num_patterns(self.ctx_ref(), self.ast))
2226
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 2266 of file z3py.py.

2266 def num_vars(self):
2267 """Return the number of variables bounded by this quantifier.
2268
2269 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2270 >>> x = Int('x')
2271 >>> y = Int('y')
2272 >>> q = ForAll([x, y], f(x, y) >= x)
2273 >>> q.num_vars()
2274 2
2275 """
2276 return int(Z3_get_quantifier_num_bound(self.ctx_ref(), self.ast))
2277
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 2227 of file z3py.py.

2227 def pattern(self, idx):
2228 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2229
2230 >>> f = Function('f', IntSort(), IntSort())
2231 >>> g = Function('g', IntSort(), IntSort())
2232 >>> x = Int('x')
2233 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2234 >>> q.num_patterns()
2235 2
2236 >>> q.pattern(0)
2237 f(Var(0))
2238 >>> q.pattern(1)
2239 g(Var(0))
2240 """
2241 if z3_debug():
2242 _z3_assert(idx < self.num_patterns(), "Invalid pattern idx")
2243 return PatternRef(Z3_get_quantifier_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2244
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 2210 of file z3py.py.

2210 def qid(self):
2211 """Return the quantifier id of `self`.
2212 """
2213 return _symbol2py(self.ctx, Z3_get_quantifier_id(self.ctx_ref(), self.ast))
2214
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 2205 of file z3py.py.

2205 def skolem_id(self):
2206 """Return the skolem id of `self`.
2207 """
2208 return _symbol2py(self.ctx, Z3_get_quantifier_skolem_id(self.ctx_ref(), self.ast))
2209
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 2136 of file z3py.py.

2136 def sort(self):
2137 """Return the Boolean sort or sort of Lambda."""
2138 if self.is_lambda():
2139 return _sort(self.ctx, self.as_ast())
2140 return BoolSort(self.ctx)
2141

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

2278 def var_name(self, idx):
2279 """Return a string representing a name used when displaying the quantifier.
2280
2281 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2282 >>> x = Int('x')
2283 >>> y = Int('y')
2284 >>> q = ForAll([x, y], f(x, y) >= x)
2285 >>> q.var_name(0)
2286 'x'
2287 >>> q.var_name(1)
2288 'y'
2289 """
2290 if z3_debug():
2291 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2292 return _symbol2py(self.ctx, Z3_get_quantifier_bound_name(self.ctx_ref(), self.ast, idx))
2293
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 2294 of file z3py.py.

2294 def var_sort(self, idx):
2295 """Return the sort of a bound variable.
2296
2297 >>> f = Function('f', IntSort(), RealSort(), IntSort())
2298 >>> x = Int('x')
2299 >>> y = Real('y')
2300 >>> q = ForAll([x, y], f(x, y) >= x)
2301 >>> q.var_sort(0)
2302 Int
2303 >>> q.var_sort(1)
2304 Real
2305 """
2306 if z3_debug():
2307 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2308 return _to_sort_ref(Z3_get_quantifier_bound_sort(self.ctx_ref(), self.ast, idx), self.ctx)
2309
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 2191 of file z3py.py.

2191 def weight(self):
2192 """Return the weight annotation of `self`.
2193
2194 >>> f = Function('f', IntSort(), IntSort())
2195 >>> x = Int('x')
2196 >>> q = ForAll(x, f(x) == 0)
2197 >>> q.weight()
2198 1
2199 >>> q = ForAll(x, f(x) == 0, weight=10)
2200 >>> q.weight()
2201 10
2202 """
2203 return int(Z3_get_quantifier_weight(self.ctx_ref(), self.ast))
2204
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.