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

Member Function Documentation

◆ __getitem__()

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

Definition at line 2122 of file z3py.py.

2122 def __getitem__(self, arg):
2123 """Return the Z3 expression `self[arg]`.
2124 """
2125 if z3_debug():
2126 _z3_assert(self.is_lambda(), "quantifier should be a lambda expression")
2127 return _array_select(self, arg)
2128

◆ as_ast()

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

Reimplemented from ExprRef.

Definition at line 2068 of file z3py.py.

2068 def as_ast(self):
2069 return self.ast
2070

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

2193 def body(self):
2194 """Return the expression being quantified.
2195
2196 >>> f = Function('f', IntSort(), IntSort())
2197 >>> x = Int('x')
2198 >>> q = ForAll(x, f(x) == 0)
2199 >>> q.body()
2200 f(Var(0)) == 0
2201 """
2202 return _to_expr_ref(Z3_get_quantifier_body(self.ctx_ref(), self.ast), self.ctx)
2203
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 2248 of file z3py.py.

2248 def children(self):
2249 """Return a list containing a single element self.body()
2250
2251 >>> f = Function('f', IntSort(), IntSort())
2252 >>> x = Int('x')
2253 >>> q = ForAll(x, f(x) == 0)
2254 >>> q.children()
2255 [f(Var(0)) == 0]
2256 """
2257 return [self.body()]
2258
2259

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

2071 def get_id(self):
2072 return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
2073
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 2094 of file z3py.py.

2094 def is_exists(self):
2095 """Return `True` if `self` is an existential quantifier.
2096
2097 >>> f = Function('f', IntSort(), IntSort())
2098 >>> x = Int('x')
2099 >>> q = ForAll(x, f(x) == 0)
2100 >>> q.is_exists()
2101 False
2102 >>> q = Exists(x, f(x) != 0)
2103 >>> q.is_exists()
2104 True
2105 """
2106 return Z3_is_quantifier_exists(self.ctx_ref(), self.ast)
2107
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 2080 of file z3py.py.

2080 def is_forall(self):
2081 """Return `True` if `self` is a universal quantifier.
2082
2083 >>> f = Function('f', IntSort(), IntSort())
2084 >>> x = Int('x')
2085 >>> q = ForAll(x, f(x) == 0)
2086 >>> q.is_forall()
2087 True
2088 >>> q = Exists(x, f(x) != 0)
2089 >>> q.is_forall()
2090 False
2091 """
2092 return Z3_is_quantifier_forall(self.ctx_ref(), self.ast)
2093
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 2108 of file z3py.py.

2108 def is_lambda(self):
2109 """Return `True` if `self` is a lambda expression.
2110
2111 >>> f = Function('f', IntSort(), IntSort())
2112 >>> x = Int('x')
2113 >>> q = Lambda(x, f(x))
2114 >>> q.is_lambda()
2115 True
2116 >>> q = Exists(x, f(x) != 0)
2117 >>> q.is_lambda()
2118 False
2119 """
2120 return Z3_is_lambda(self.ctx_ref(), self.ast)
2121
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 2187 of file z3py.py.

2187 def no_pattern(self, idx):
2188 """Return a no-pattern."""
2189 if z3_debug():
2190 _z3_assert(idx < self.num_no_patterns(), "Invalid no-pattern idx")
2191 return _to_expr_ref(Z3_get_quantifier_no_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2192
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 2183 of file z3py.py.

2183 def num_no_patterns(self):
2184 """Return the number of no-patterns."""
2185 return Z3_get_quantifier_num_no_patterns(self.ctx_ref(), self.ast)
2186
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 2153 of file z3py.py.

2153 def num_patterns(self):
2154 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2155
2156 >>> f = Function('f', IntSort(), IntSort())
2157 >>> g = Function('g', IntSort(), IntSort())
2158 >>> x = Int('x')
2159 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2160 >>> q.num_patterns()
2161 2
2162 """
2163 return int(Z3_get_quantifier_num_patterns(self.ctx_ref(), self.ast))
2164
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 2204 of file z3py.py.

2204 def num_vars(self):
2205 """Return the number of variables bounded by this quantifier.
2206
2207 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2208 >>> x = Int('x')
2209 >>> y = Int('y')
2210 >>> q = ForAll([x, y], f(x, y) >= x)
2211 >>> q.num_vars()
2212 2
2213 """
2214 return int(Z3_get_quantifier_num_bound(self.ctx_ref(), self.ast))
2215
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 2165 of file z3py.py.

2165 def pattern(self, idx):
2166 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2167
2168 >>> f = Function('f', IntSort(), IntSort())
2169 >>> g = Function('g', IntSort(), IntSort())
2170 >>> x = Int('x')
2171 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2172 >>> q.num_patterns()
2173 2
2174 >>> q.pattern(0)
2175 f(Var(0))
2176 >>> q.pattern(1)
2177 g(Var(0))
2178 """
2179 if z3_debug():
2180 _z3_assert(idx < self.num_patterns(), "Invalid pattern idx")
2181 return PatternRef(Z3_get_quantifier_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2182
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 2148 of file z3py.py.

2148 def qid(self):
2149 """Return the quantifier id of `self`.
2150 """
2151 return _symbol2py(self.ctx, Z3_get_quantifier_id(self.ctx_ref(), self.ast))
2152
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 2143 of file z3py.py.

2143 def skolem_id(self):
2144 """Return the skolem id of `self`.
2145 """
2146 return _symbol2py(self.ctx, Z3_get_quantifier_skolem_id(self.ctx_ref(), self.ast))
2147
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 2074 of file z3py.py.

2074 def sort(self):
2075 """Return the Boolean sort or sort of Lambda."""
2076 if self.is_lambda():
2077 return _sort(self.ctx, self.as_ast())
2078 return BoolSort(self.ctx)
2079

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

2216 def var_name(self, idx):
2217 """Return a string representing a name used when displaying the quantifier.
2218
2219 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2220 >>> x = Int('x')
2221 >>> y = Int('y')
2222 >>> q = ForAll([x, y], f(x, y) >= x)
2223 >>> q.var_name(0)
2224 'x'
2225 >>> q.var_name(1)
2226 'y'
2227 """
2228 if z3_debug():
2229 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2230 return _symbol2py(self.ctx, Z3_get_quantifier_bound_name(self.ctx_ref(), self.ast, idx))
2231
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 2232 of file z3py.py.

2232 def var_sort(self, idx):
2233 """Return the sort of a bound variable.
2234
2235 >>> f = Function('f', IntSort(), RealSort(), IntSort())
2236 >>> x = Int('x')
2237 >>> y = Real('y')
2238 >>> q = ForAll([x, y], f(x, y) >= x)
2239 >>> q.var_sort(0)
2240 Int
2241 >>> q.var_sort(1)
2242 Real
2243 """
2244 if z3_debug():
2245 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2246 return _to_sort_ref(Z3_get_quantifier_bound_sort(self.ctx_ref(), self.ast, idx), self.ctx)
2247
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 2129 of file z3py.py.

2129 def weight(self):
2130 """Return the weight annotation of `self`.
2131
2132 >>> f = Function('f', IntSort(), IntSort())
2133 >>> x = Int('x')
2134 >>> q = ForAll(x, f(x) == 0)
2135 >>> q.weight()
2136 1
2137 >>> q = ForAll(x, f(x) == 0, weight=10)
2138 >>> q.weight()
2139 10
2140 """
2141 return int(Z3_get_quantifier_weight(self.ctx_ref(), self.ast))
2142
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.