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

Member Function Documentation

◆ __getitem__()

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

Definition at line 2107 of file z3py.py.

2107 def __getitem__(self, arg):
2108 """Return the Z3 expression `self[arg]`.
2109 """
2110 if z3_debug():
2111 _z3_assert(self.is_lambda(), "quantifier should be a lambda expression")
2112 return _array_select(self, arg)
2113

◆ as_ast()

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

Reimplemented from ExprRef.

Definition at line 2053 of file z3py.py.

2053 def as_ast(self):
2054 return self.ast
2055

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

2178 def body(self):
2179 """Return the expression being quantified.
2180
2181 >>> f = Function('f', IntSort(), IntSort())
2182 >>> x = Int('x')
2183 >>> q = ForAll(x, f(x) == 0)
2184 >>> q.body()
2185 f(Var(0)) == 0
2186 """
2187 return _to_expr_ref(Z3_get_quantifier_body(self.ctx_ref(), self.ast), self.ctx)
2188
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 2233 of file z3py.py.

2233 def children(self):
2234 """Return a list containing a single element self.body()
2235
2236 >>> f = Function('f', IntSort(), IntSort())
2237 >>> x = Int('x')
2238 >>> q = ForAll(x, f(x) == 0)
2239 >>> q.children()
2240 [f(Var(0)) == 0]
2241 """
2242 return [self.body()]
2243
2244

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

2056 def get_id(self):
2057 return Z3_get_ast_id(self.ctx_ref(), self.as_ast())
2058
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 2079 of file z3py.py.

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

2065 def is_forall(self):
2066 """Return `True` if `self` is a universal quantifier.
2067
2068 >>> f = Function('f', IntSort(), IntSort())
2069 >>> x = Int('x')
2070 >>> q = ForAll(x, f(x) == 0)
2071 >>> q.is_forall()
2072 True
2073 >>> q = Exists(x, f(x) != 0)
2074 >>> q.is_forall()
2075 False
2076 """
2077 return Z3_is_quantifier_forall(self.ctx_ref(), self.ast)
2078
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 2093 of file z3py.py.

2093 def is_lambda(self):
2094 """Return `True` if `self` is a lambda expression.
2095
2096 >>> f = Function('f', IntSort(), IntSort())
2097 >>> x = Int('x')
2098 >>> q = Lambda(x, f(x))
2099 >>> q.is_lambda()
2100 True
2101 >>> q = Exists(x, f(x) != 0)
2102 >>> q.is_lambda()
2103 False
2104 """
2105 return Z3_is_lambda(self.ctx_ref(), self.ast)
2106
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 2172 of file z3py.py.

2172 def no_pattern(self, idx):
2173 """Return a no-pattern."""
2174 if z3_debug():
2175 _z3_assert(idx < self.num_no_patterns(), "Invalid no-pattern idx")
2176 return _to_expr_ref(Z3_get_quantifier_no_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2177
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 2168 of file z3py.py.

2168 def num_no_patterns(self):
2169 """Return the number of no-patterns."""
2170 return Z3_get_quantifier_num_no_patterns(self.ctx_ref(), self.ast)
2171
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 2138 of file z3py.py.

2138 def num_patterns(self):
2139 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2140
2141 >>> f = Function('f', IntSort(), IntSort())
2142 >>> g = Function('g', IntSort(), IntSort())
2143 >>> x = Int('x')
2144 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2145 >>> q.num_patterns()
2146 2
2147 """
2148 return int(Z3_get_quantifier_num_patterns(self.ctx_ref(), self.ast))
2149
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 2189 of file z3py.py.

2189 def num_vars(self):
2190 """Return the number of variables bounded by this quantifier.
2191
2192 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2193 >>> x = Int('x')
2194 >>> y = Int('y')
2195 >>> q = ForAll([x, y], f(x, y) >= x)
2196 >>> q.num_vars()
2197 2
2198 """
2199 return int(Z3_get_quantifier_num_bound(self.ctx_ref(), self.ast))
2200
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 2150 of file z3py.py.

2150 def pattern(self, idx):
2151 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2152
2153 >>> f = Function('f', IntSort(), IntSort())
2154 >>> g = Function('g', IntSort(), IntSort())
2155 >>> x = Int('x')
2156 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2157 >>> q.num_patterns()
2158 2
2159 >>> q.pattern(0)
2160 f(Var(0))
2161 >>> q.pattern(1)
2162 g(Var(0))
2163 """
2164 if z3_debug():
2165 _z3_assert(idx < self.num_patterns(), "Invalid pattern idx")
2166 return PatternRef(Z3_get_quantifier_pattern_ast(self.ctx_ref(), self.ast, idx), self.ctx)
2167
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 2133 of file z3py.py.

2133 def qid(self):
2134 """Return the quantifier id of `self`.
2135 """
2136 return _symbol2py(self.ctx, Z3_get_quantifier_id(self.ctx_ref(), self.ast))
2137
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 2128 of file z3py.py.

2128 def skolem_id(self):
2129 """Return the skolem id of `self`.
2130 """
2131 return _symbol2py(self.ctx, Z3_get_quantifier_skolem_id(self.ctx_ref(), self.ast))
2132
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 2059 of file z3py.py.

2059 def sort(self):
2060 """Return the Boolean sort or sort of Lambda."""
2061 if self.is_lambda():
2062 return _sort(self.ctx, self.as_ast())
2063 return BoolSort(self.ctx)
2064

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

2201 def var_name(self, idx):
2202 """Return a string representing a name used when displaying the quantifier.
2203
2204 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2205 >>> x = Int('x')
2206 >>> y = Int('y')
2207 >>> q = ForAll([x, y], f(x, y) >= x)
2208 >>> q.var_name(0)
2209 'x'
2210 >>> q.var_name(1)
2211 'y'
2212 """
2213 if z3_debug():
2214 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2215 return _symbol2py(self.ctx, Z3_get_quantifier_bound_name(self.ctx_ref(), self.ast, idx))
2216
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 2217 of file z3py.py.

2217 def var_sort(self, idx):
2218 """Return the sort of a bound variable.
2219
2220 >>> f = Function('f', IntSort(), RealSort(), IntSort())
2221 >>> x = Int('x')
2222 >>> y = Real('y')
2223 >>> q = ForAll([x, y], f(x, y) >= x)
2224 >>> q.var_sort(0)
2225 Int
2226 >>> q.var_sort(1)
2227 Real
2228 """
2229 if z3_debug():
2230 _z3_assert(idx < self.num_vars(), "Invalid variable idx")
2231 return _to_sort_ref(Z3_get_quantifier_bound_sort(self.ctx_ref(), self.ast, idx), self.ctx)
2232
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 2114 of file z3py.py.

2114 def weight(self):
2115 """Return the weight annotation of `self`.
2116
2117 >>> f = Function('f', IntSort(), IntSort())
2118 >>> x = Int('x')
2119 >>> q = ForAll(x, f(x) == 0)
2120 >>> q.weight()
2121 1
2122 >>> q = ForAll(x, f(x) == 0, weight=10)
2123 >>> q.weight()
2124 10
2125 """
2126 return int(Z3_get_quantifier_weight(self.ctx_ref(), self.ast))
2127
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.