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

Fixedpoint. More...

Inheritance diagram for Fixedpoint:

Public Member Functions

 __init__ (self, fixedpoint=None, ctx=None)
 __deepcopy__ (self, memo={})
 __del__ (self)
 set (self, *args, **keys)
 help (self)
 param_descrs (self)
 assert_exprs (self, *args)
 add (self, *args)
 __iadd__ (self, fml)
 append (self, *args)
 insert (self, *args)
 add_rule (self, head, body=None, name=None)
 rule (self, head, body=None, name=None)
 fact (self, head, name=None)
 query (self, *query)
 query_from_lvl (self, lvl, *query)
 update_rule (self, head, body, name)
 get_answer (self)
 get_ground_sat_answer (self)
 get_rules_along_trace (self)
 get_rule_names_along_trace (self)
 get_num_levels (self, predicate)
 get_cover_delta (self, level, predicate)
 add_cover (self, level, predicate, property)
 register_relation (self, *relations)
 set_predicate_representation (self, f, *representations)
 parse_string (self, s)
 parse_file (self, f)
 get_rules (self)
 get_assertions (self)
 __repr__ (self)
 sexpr (self)
 to_string (self, queries)
 statistics (self)
 reason_unknown (self)
 declare_var (self, *vars)
 abstract (self, fml, is_forall=True)
Public Member Functions inherited from Z3PPObject
 use_pp (self)

Data Fields

 ctx = _get_ctx(ctx)
 fixedpoint = None
list vars = []

Additional Inherited Members

Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)

Detailed Description

Fixedpoint.

Fixedpoint API provides methods for solving with recursive predicates

Definition at line 8155 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
fixedpoint = None,
ctx = None )

Definition at line 8158 of file z3py.py.

8158 def __init__(self, fixedpoint=None, ctx=None):
8159 assert fixedpoint is None or ctx is not None
8160 self.ctx = _get_ctx(ctx)
8161 self.fixedpoint = None
8162 if fixedpoint is None:
8163 self.fixedpoint = Z3_mk_fixedpoint(self.ctx.ref())
8164 else:
8165 self.fixedpoint = fixedpoint
8166 Z3_fixedpoint_inc_ref(self.ctx.ref(), self.fixedpoint)
8167 self.vars = []
8168
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.

◆ __del__()

__del__ ( self)

Definition at line 8172 of file z3py.py.

8172 def __del__(self):
8173 if self.fixedpoint is not None and self.ctx.ref() is not None and Z3_fixedpoint_dec_ref is not None:
8174 Z3_fixedpoint_dec_ref(self.ctx.ref(), self.fixedpoint)
8175
void Z3_API Z3_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.

Member Function Documentation

◆ __deepcopy__()

__deepcopy__ ( self,
memo = {} )

Definition at line 8169 of file z3py.py.

8169 def __deepcopy__(self, memo={}):
8170 return FixedPoint(self.fixedpoint, self.ctx)
8171

◆ __iadd__()

__iadd__ ( self,
fml )

Definition at line 8208 of file z3py.py.

8208 def __iadd__(self, fml):
8209 self.add(fml)
8210 return self
8211

◆ __repr__()

__repr__ ( self)
Return a formatted string with all added rules and constraints.

Definition at line 8369 of file z3py.py.

8369 def __repr__(self):
8370 """Return a formatted string with all added rules and constraints."""
8371 return self.sexpr()
8372

◆ abstract()

abstract ( self,
fml,
is_forall = True )

Definition at line 8406 of file z3py.py.

8406 def abstract(self, fml, is_forall=True):
8407 if self.vars == []:
8408 return fml
8409 if is_forall:
8410 return ForAll(self.vars, fml)
8411 else:
8412 return Exists(self.vars, fml)
8413
8414

◆ add()

add ( self,
* args )
Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.

Definition at line 8204 of file z3py.py.

8204 def add(self, *args):
8205 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
8206 self.assert_exprs(*args)
8207

◆ add_cover()

add_cover ( self,
level,
predicate,
property )
Add property to predicate for the level'th unfolding.
-1 is treated as infinity (infinity)

Definition at line 8331 of file z3py.py.

8331 def add_cover(self, level, predicate, property):
8332 """Add property to predicate for the level'th unfolding.
8333 -1 is treated as infinity (infinity)
8334 """
8335 Z3_fixedpoint_add_cover(self.ctx.ref(), self.fixedpoint, level, predicate.ast, property.ast)
8336
void Z3_API Z3_fixedpoint_add_cover(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred, Z3_ast property)
Add property about the predicate pred. Add a property of predicate pred at level. It gets pushed forw...

◆ add_rule()

add_rule ( self,
head,
body = None,
name = None )
Assert rules defining recursive predicates to the fixedpoint solver.
>>> a = Bool('a')
>>> b = Bool('b')
>>> s = Fixedpoint()
>>> s.register_relation(a.decl())
>>> s.register_relation(b.decl())
>>> s.fact(a)
>>> s.rule(b, a)
>>> s.query(b)
sat

Definition at line 8220 of file z3py.py.

8220 def add_rule(self, head, body=None, name=None):
8221 """Assert rules defining recursive predicates to the fixedpoint solver.
8222 >>> a = Bool('a')
8223 >>> b = Bool('b')
8224 >>> s = Fixedpoint()
8225 >>> s.register_relation(a.decl())
8226 >>> s.register_relation(b.decl())
8227 >>> s.fact(a)
8228 >>> s.rule(b, a)
8229 >>> s.query(b)
8230 sat
8231 """
8232 if name is None:
8233 name = ""
8234 name = to_symbol(name, self.ctx)
8235 if body is None:
8236 head = self.abstract(head)
8237 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, head.as_ast(), name)
8238 else:
8239 body = _get_args(body)
8240 f = self.abstract(Implies(And(body, self.ctx), head))
8241 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
8242
void Z3_API Z3_fixedpoint_add_rule(Z3_context c, Z3_fixedpoint d, Z3_ast rule, Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form:

◆ append()

append ( self,
* args )
Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.

Definition at line 8212 of file z3py.py.

8212 def append(self, *args):
8213 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
8214 self.assert_exprs(*args)
8215

◆ assert_exprs()

assert_exprs ( self,
* args )
Assert constraints as background axioms for the fixedpoint solver.

Definition at line 8190 of file z3py.py.

8190 def assert_exprs(self, *args):
8191 """Assert constraints as background axioms for the fixedpoint solver."""
8192 args = _get_args(args)
8193 s = BoolSort(self.ctx)
8194 for arg in args:
8195 if isinstance(arg, Goal) or isinstance(arg, AstVector):
8196 for f in arg:
8197 f = self.abstract(f)
8198 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, f.as_ast())
8199 else:
8200 arg = s.cast(arg)
8201 arg = self.abstract(arg)
8202 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, arg.as_ast())
8203
void Z3_API Z3_fixedpoint_assert(Z3_context c, Z3_fixedpoint d, Z3_ast axiom)
Assert a constraint to the fixedpoint context.

◆ declare_var()

declare_var ( self,
* vars )
Add variable or several variables.
The added variable or variables will be bound in the rules
and queries

Definition at line 8397 of file z3py.py.

8397 def declare_var(self, *vars):
8398 """Add variable or several variables.
8399 The added variable or variables will be bound in the rules
8400 and queries
8401 """
8402 vars = _get_args(vars)
8403 for v in vars:
8404 self.vars += [v]
8405

◆ fact()

fact ( self,
head,
name = None )
Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule.

Definition at line 8247 of file z3py.py.

8247 def fact(self, head, name=None):
8248 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
8249 self.add_rule(head, None, name)
8250

◆ get_answer()

get_answer ( self)
Retrieve answer from last query call.

Definition at line 8298 of file z3py.py.

8298 def get_answer(self):
8299 """Retrieve answer from last query call."""
8300 r = Z3_fixedpoint_get_answer(self.ctx.ref(), self.fixedpoint)
8301 return _to_expr_ref(r, self.ctx)
8302
Z3_ast Z3_API Z3_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.

◆ get_assertions()

get_assertions ( self)
retrieve assertions that have been added to fixedpoint context

Definition at line 8365 of file z3py.py.

8365 def get_assertions(self):
8366 """retrieve assertions that have been added to fixedpoint context"""
8367 return AstVector(Z3_fixedpoint_get_assertions(self.ctx.ref(), self.fixedpoint), self.ctx)
8368
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.

◆ get_cover_delta()

get_cover_delta ( self,
level,
predicate )
Retrieve properties known about predicate for the level'th unfolding.
-1 is treated as the limit (infinity)

Definition at line 8324 of file z3py.py.

8324 def get_cover_delta(self, level, predicate):
8325 """Retrieve properties known about predicate for the level'th unfolding.
8326 -1 is treated as the limit (infinity)
8327 """
8328 r = Z3_fixedpoint_get_cover_delta(self.ctx.ref(), self.fixedpoint, level, predicate.ast)
8329 return _to_expr_ref(r, self.ctx)
8330
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)

◆ get_ground_sat_answer()

get_ground_sat_answer ( self)
Retrieve a ground cex from last query call.

Definition at line 8303 of file z3py.py.

8303 def get_ground_sat_answer(self):
8304 """Retrieve a ground cex from last query call."""
8305 r = Z3_fixedpoint_get_ground_sat_answer(self.ctx.ref(), self.fixedpoint)
8306 return _to_expr_ref(r, self.ctx)
8307

◆ get_num_levels()

get_num_levels ( self,
predicate )
Retrieve number of levels used for predicate in PDR engine

Definition at line 8320 of file z3py.py.

8320 def get_num_levels(self, predicate):
8321 """Retrieve number of levels used for predicate in PDR engine"""
8322 return Z3_fixedpoint_get_num_levels(self.ctx.ref(), self.fixedpoint, predicate.ast)
8323
unsigned Z3_API Z3_fixedpoint_get_num_levels(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred)
Query the PDR engine for the maximal levels properties are known about predicate.

◆ get_rule_names_along_trace()

get_rule_names_along_trace ( self)
retrieve rule names along the counterexample trace

Definition at line 8312 of file z3py.py.

8312 def get_rule_names_along_trace(self):
8313 """retrieve rule names along the counterexample trace"""
8314 # this is a hack as I don't know how to return a list of symbols from C++;
8315 # obtain names as a single string separated by semicolons
8316 names = _symbol2py(self.ctx, Z3_fixedpoint_get_rule_names_along_trace(self.ctx.ref(), self.fixedpoint))
8317 # split into individual names
8318 return names.split(";")
8319

◆ get_rules()

get_rules ( self)
retrieve rules that have been added to fixedpoint context

Definition at line 8361 of file z3py.py.

8361 def get_rules(self):
8362 """retrieve rules that have been added to fixedpoint context"""
8363 return AstVector(Z3_fixedpoint_get_rules(self.ctx.ref(), self.fixedpoint), self.ctx)
8364
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.

◆ get_rules_along_trace()

get_rules_along_trace ( self)
retrieve rules along the counterexample trace

Definition at line 8308 of file z3py.py.

8308 def get_rules_along_trace(self):
8309 """retrieve rules along the counterexample trace"""
8310 return AstVector(Z3_fixedpoint_get_rules_along_trace(self.ctx.ref(), self.fixedpoint), self.ctx)
8311

◆ help()

help ( self)
Display a string describing all available options.

Definition at line 8182 of file z3py.py.

8182 def help(self):
8183 """Display a string describing all available options."""
8184 print(Z3_fixedpoint_get_help(self.ctx.ref(), self.fixedpoint))
8185
Z3_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.

◆ insert()

insert ( self,
* args )
Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.

Definition at line 8216 of file z3py.py.

8216 def insert(self, *args):
8217 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
8218 self.assert_exprs(*args)
8219

◆ param_descrs()

param_descrs ( self)
Return the parameter description set.

Definition at line 8186 of file z3py.py.

8186 def param_descrs(self):
8187 """Return the parameter description set."""
8188 return ParamDescrsRef(Z3_fixedpoint_get_param_descrs(self.ctx.ref(), self.fixedpoint), self.ctx)
8189
Z3_param_descrs Z3_API Z3_fixedpoint_get_param_descrs(Z3_context c, Z3_fixedpoint f)
Return the parameter description set for the given fixedpoint object.

◆ parse_file()

parse_file ( self,
f )
Parse rules and queries from a file

Definition at line 8357 of file z3py.py.

8357 def parse_file(self, f):
8358 """Parse rules and queries from a file"""
8359 return AstVector(Z3_fixedpoint_from_file(self.ctx.ref(), self.fixedpoint, f), self.ctx)
8360
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context....

◆ parse_string()

parse_string ( self,
s )
Parse rules and queries from a string

Definition at line 8353 of file z3py.py.

8353 def parse_string(self, s):
8354 """Parse rules and queries from a string"""
8355 return AstVector(Z3_fixedpoint_from_string(self.ctx.ref(), self.fixedpoint, s), self.ctx)
8356
Z3_ast_vector Z3_API Z3_fixedpoint_from_string(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 string with fixedpoint rules. Add the rules to the current fixedpoint context....

◆ query()

query ( self,
* query )
Query the fixedpoint engine whether formula is derivable.
   You can also pass an tuple or list of recursive predicates.

Definition at line 8251 of file z3py.py.

8251 def query(self, *query):
8252 """Query the fixedpoint engine whether formula is derivable.
8253 You can also pass an tuple or list of recursive predicates.
8254 """
8255 query = _get_args(query)
8256 sz = len(query)
8257 if sz >= 1 and isinstance(query[0], FuncDeclRef):
8258 _decls = (FuncDecl * sz)()
8259 i = 0
8260 for q in query:
8261 _decls[i] = q.ast
8262 i = i + 1
8263 r = Z3_fixedpoint_query_relations(self.ctx.ref(), self.fixedpoint, sz, _decls)
8264 else:
8265 if sz == 1:
8266 query = query[0]
8267 else:
8268 query = And(query, self.ctx)
8269 query = self.abstract(query, False)
8270 r = Z3_fixedpoint_query(self.ctx.ref(), self.fixedpoint, query.as_ast())
8271 return CheckSatResult(r)
8272
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
Z3_lbool Z3_API Z3_fixedpoint_query_relations(Z3_context c, Z3_fixedpoint d, unsigned num_relations, Z3_func_decl const relations[])
Pose multiple queries against the asserted rules.

◆ query_from_lvl()

query_from_lvl ( self,
lvl,
* query )
Query the fixedpoint engine whether formula is derivable starting at the given query level.

Definition at line 8273 of file z3py.py.

8273 def query_from_lvl(self, lvl, *query):
8274 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
8275 """
8276 query = _get_args(query)
8277 sz = len(query)
8278 if sz >= 1 and isinstance(query[0], FuncDecl):
8279 _z3_assert(False, "unsupported")
8280 else:
8281 if sz == 1:
8282 query = query[0]
8283 else:
8284 query = And(query)
8285 query = self.abstract(query, False)
8286 r = Z3_fixedpoint_query_from_lvl(self.ctx.ref(), self.fixedpoint, query.as_ast(), lvl)
8287 return CheckSatResult(r)
8288

◆ reason_unknown()

reason_unknown ( self)
Return a string describing why the last `query()` returned `unknown`.

Definition at line 8392 of file z3py.py.

8392 def reason_unknown(self):
8393 """Return a string describing why the last `query()` returned `unknown`.
8394 """
8395 return Z3_fixedpoint_get_reason_unknown(self.ctx.ref(), self.fixedpoint)
8396
Z3_string Z3_API Z3_fixedpoint_get_reason_unknown(Z3_context c, Z3_fixedpoint d)
Retrieve a string that describes the last status returned by Z3_fixedpoint_query.

◆ register_relation()

register_relation ( self,
* relations )
Register relation as recursive

Definition at line 8337 of file z3py.py.

8337 def register_relation(self, *relations):
8338 """Register relation as recursive"""
8339 relations = _get_args(relations)
8340 for f in relations:
8341 Z3_fixedpoint_register_relation(self.ctx.ref(), self.fixedpoint, f.ast)
8342
void Z3_API Z3_fixedpoint_register_relation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f)
Register relation as Fixedpoint defined. Fixedpoint defined relations have least-fixedpoint semantics...

◆ rule()

rule ( self,
head,
body = None,
name = None )
Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule.

Definition at line 8243 of file z3py.py.

8243 def rule(self, head, body=None, name=None):
8244 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
8245 self.add_rule(head, body, name)
8246

◆ set()

set ( self,
* args,
** keys )
Set a configuration option. The method `help()` return a string containing all available options.

Definition at line 8176 of file z3py.py.

8176 def set(self, *args, **keys):
8177 """Set a configuration option. The method `help()` return a string containing all available options.
8178 """
8179 p = args2params(args, keys, self.ctx)
8180 Z3_fixedpoint_set_params(self.ctx.ref(), self.fixedpoint, p.params)
8181
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.

◆ set_predicate_representation()

set_predicate_representation ( self,
f,
* representations )
Control how relation is represented

Definition at line 8343 of file z3py.py.

8343 def set_predicate_representation(self, f, *representations):
8344 """Control how relation is represented"""
8345 representations = _get_args(representations)
8346 representations = [to_symbol(s) for s in representations]
8347 sz = len(representations)
8348 args = (Symbol * sz)()
8349 for i in range(sz):
8350 args[i] = representations[i]
8351 Z3_fixedpoint_set_predicate_representation(self.ctx.ref(), self.fixedpoint, f.ast, sz, args)
8352
void Z3_API Z3_fixedpoint_set_predicate_representation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f, unsigned num_relations, Z3_symbol const relation_kinds[])
Configure the predicate representation.

◆ sexpr()

sexpr ( self)
Return a formatted string (in Lisp-like format) with all added constraints.
We say the string is in s-expression format.

Definition at line 8373 of file z3py.py.

8373 def sexpr(self):
8374 """Return a formatted string (in Lisp-like format) with all added constraints.
8375 We say the string is in s-expression format.
8376 """
8377 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, 0, (Ast * 0)())
8378
Z3_string Z3_API Z3_fixedpoint_to_string(Z3_context c, Z3_fixedpoint f, unsigned num_queries, Z3_ast queries[])
Print the current rules and background axioms as a string.

◆ statistics()

statistics ( self)
Return statistics for the last `query()`.

Definition at line 8387 of file z3py.py.

8387 def statistics(self):
8388 """Return statistics for the last `query()`.
8389 """
8390 return Statistics(Z3_fixedpoint_get_statistics(self.ctx.ref(), self.fixedpoint), self.ctx)
8391
Z3_stats Z3_API Z3_fixedpoint_get_statistics(Z3_context c, Z3_fixedpoint d)
Retrieve statistics information from the last call to Z3_fixedpoint_query.

◆ to_string()

to_string ( self,
queries )
Return a formatted string (in Lisp-like format) with all added constraints.
   We say the string is in s-expression format.
   Include also queries.

Definition at line 8379 of file z3py.py.

8379 def to_string(self, queries):
8380 """Return a formatted string (in Lisp-like format) with all added constraints.
8381 We say the string is in s-expression format.
8382 Include also queries.
8383 """
8384 args, len = _to_ast_array(queries)
8385 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, len, args)
8386

◆ update_rule()

update_rule ( self,
head,
body,
name )
update rule

Definition at line 8289 of file z3py.py.

8289 def update_rule(self, head, body, name):
8290 """update rule"""
8291 if name is None:
8292 name = ""
8293 name = to_symbol(name, self.ctx)
8294 body = _get_args(body)
8295 f = self.abstract(Implies(And(body, self.ctx), head))
8296 Z3_fixedpoint_update_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
8297
void Z3_API Z3_fixedpoint_update_rule(Z3_context c, Z3_fixedpoint d, Z3_ast a, Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created.

Field Documentation

◆ ctx

ctx = _get_ctx(ctx)

Definition at line 8160 of file z3py.py.

◆ fixedpoint

fixedpoint = None

Definition at line 8161 of file z3py.py.

◆ vars

vars = []

Definition at line 8167 of file z3py.py.