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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 8291 of file z3py.py.

8291 def __init__(self, fixedpoint=None, ctx=None):
8292 assert fixedpoint is None or ctx is not None
8293 self.ctx = _get_ctx(ctx)
8294 self.fixedpoint = None
8295 if fixedpoint is None:
8296 self.fixedpoint = Z3_mk_fixedpoint(self.ctx.ref())
8297 else:
8298 self.fixedpoint = fixedpoint
8299 Z3_fixedpoint_inc_ref(self.ctx.ref(), self.fixedpoint)
8300 self.vars = []
8301
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 8305 of file z3py.py.

8305 def __del__(self):
8306 if self.fixedpoint is not None and self.ctx.ref() is not None and Z3_fixedpoint_dec_ref is not None:
8307 Z3_fixedpoint_dec_ref(self.ctx.ref(), self.fixedpoint)
8308
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 8302 of file z3py.py.

8302 def __deepcopy__(self, memo={}):
8303 return FixedPoint(self.fixedpoint, self.ctx)
8304

◆ __iadd__()

__iadd__ ( self,
fml )

Definition at line 8341 of file z3py.py.

8341 def __iadd__(self, fml):
8342 self.add(fml)
8343 return self
8344

◆ __repr__()

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

Definition at line 8502 of file z3py.py.

8502 def __repr__(self):
8503 """Return a formatted string with all added rules and constraints."""
8504 return self.sexpr()
8505

◆ abstract()

abstract ( self,
fml,
is_forall = True )

Definition at line 8539 of file z3py.py.

8539 def abstract(self, fml, is_forall=True):
8540 if self.vars == []:
8541 return fml
8542 if is_forall:
8543 return ForAll(self.vars, fml)
8544 else:
8545 return Exists(self.vars, fml)
8546
8547

◆ add()

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

Definition at line 8337 of file z3py.py.

8337 def add(self, *args):
8338 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
8339 self.assert_exprs(*args)
8340

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

8464 def add_cover(self, level, predicate, property):
8465 """Add property to predicate for the level'th unfolding.
8466 -1 is treated as infinity (infinity)
8467 """
8468 Z3_fixedpoint_add_cover(self.ctx.ref(), self.fixedpoint, level, predicate.ast, property.ast)
8469
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 8353 of file z3py.py.

8353 def add_rule(self, head, body=None, name=None):
8354 """Assert rules defining recursive predicates to the fixedpoint solver.
8355 >>> a = Bool('a')
8356 >>> b = Bool('b')
8357 >>> s = Fixedpoint()
8358 >>> s.register_relation(a.decl())
8359 >>> s.register_relation(b.decl())
8360 >>> s.fact(a)
8361 >>> s.rule(b, a)
8362 >>> s.query(b)
8363 sat
8364 """
8365 if name is None:
8366 name = ""
8367 name = to_symbol(name, self.ctx)
8368 if body is None:
8369 head = self.abstract(head)
8370 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, head.as_ast(), name)
8371 else:
8372 body = _get_args(body)
8373 f = self.abstract(Implies(And(body, self.ctx), head))
8374 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
8375
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 8345 of file z3py.py.

8345 def append(self, *args):
8346 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
8347 self.assert_exprs(*args)
8348

◆ assert_exprs()

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

Definition at line 8323 of file z3py.py.

8323 def assert_exprs(self, *args):
8324 """Assert constraints as background axioms for the fixedpoint solver."""
8325 args = _get_args(args)
8326 s = BoolSort(self.ctx)
8327 for arg in args:
8328 if isinstance(arg, Goal) or isinstance(arg, AstVector):
8329 for f in arg:
8330 f = self.abstract(f)
8331 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, f.as_ast())
8332 else:
8333 arg = s.cast(arg)
8334 arg = self.abstract(arg)
8335 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, arg.as_ast())
8336
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 8530 of file z3py.py.

8530 def declare_var(self, *vars):
8531 """Add variable or several variables.
8532 The added variable or variables will be bound in the rules
8533 and queries
8534 """
8535 vars = _get_args(vars)
8536 for v in vars:
8537 self.vars += [v]
8538

◆ fact()

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

Definition at line 8380 of file z3py.py.

8380 def fact(self, head, name=None):
8381 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
8382 self.add_rule(head, None, name)
8383

◆ get_answer()

get_answer ( self)
Retrieve answer from last query call.

Definition at line 8431 of file z3py.py.

8431 def get_answer(self):
8432 """Retrieve answer from last query call."""
8433 r = Z3_fixedpoint_get_answer(self.ctx.ref(), self.fixedpoint)
8434 return _to_expr_ref(r, self.ctx)
8435
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 8498 of file z3py.py.

8498 def get_assertions(self):
8499 """retrieve assertions that have been added to fixedpoint context"""
8500 return AstVector(Z3_fixedpoint_get_assertions(self.ctx.ref(), self.fixedpoint), self.ctx)
8501
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 8457 of file z3py.py.

8457 def get_cover_delta(self, level, predicate):
8458 """Retrieve properties known about predicate for the level'th unfolding.
8459 -1 is treated as the limit (infinity)
8460 """
8461 r = Z3_fixedpoint_get_cover_delta(self.ctx.ref(), self.fixedpoint, level, predicate.ast)
8462 return _to_expr_ref(r, self.ctx)
8463
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 8436 of file z3py.py.

8436 def get_ground_sat_answer(self):
8437 """Retrieve a ground cex from last query call."""
8438 r = Z3_fixedpoint_get_ground_sat_answer(self.ctx.ref(), self.fixedpoint)
8439 return _to_expr_ref(r, self.ctx)
8440

◆ get_num_levels()

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

Definition at line 8453 of file z3py.py.

8453 def get_num_levels(self, predicate):
8454 """Retrieve number of levels used for predicate in PDR engine"""
8455 return Z3_fixedpoint_get_num_levels(self.ctx.ref(), self.fixedpoint, predicate.ast)
8456
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 8445 of file z3py.py.

8445 def get_rule_names_along_trace(self):
8446 """retrieve rule names along the counterexample trace"""
8447 # this is a hack as I don't know how to return a list of symbols from C++;
8448 # obtain names as a single string separated by semicolons
8449 names = _symbol2py(self.ctx, Z3_fixedpoint_get_rule_names_along_trace(self.ctx.ref(), self.fixedpoint))
8450 # split into individual names
8451 return names.split(";")
8452

◆ get_rules()

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

Definition at line 8494 of file z3py.py.

8494 def get_rules(self):
8495 """retrieve rules that have been added to fixedpoint context"""
8496 return AstVector(Z3_fixedpoint_get_rules(self.ctx.ref(), self.fixedpoint), self.ctx)
8497
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 8441 of file z3py.py.

8441 def get_rules_along_trace(self):
8442 """retrieve rules along the counterexample trace"""
8443 return AstVector(Z3_fixedpoint_get_rules_along_trace(self.ctx.ref(), self.fixedpoint), self.ctx)
8444

◆ help()

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

Definition at line 8315 of file z3py.py.

8315 def help(self):
8316 """Display a string describing all available options."""
8317 print(Z3_fixedpoint_get_help(self.ctx.ref(), self.fixedpoint))
8318
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 8349 of file z3py.py.

8349 def insert(self, *args):
8350 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
8351 self.assert_exprs(*args)
8352

◆ param_descrs()

param_descrs ( self)
Return the parameter description set.

Definition at line 8319 of file z3py.py.

8319 def param_descrs(self):
8320 """Return the parameter description set."""
8321 return ParamDescrsRef(Z3_fixedpoint_get_param_descrs(self.ctx.ref(), self.fixedpoint), self.ctx)
8322
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 8490 of file z3py.py.

8490 def parse_file(self, f):
8491 """Parse rules and queries from a file"""
8492 return AstVector(Z3_fixedpoint_from_file(self.ctx.ref(), self.fixedpoint, f), self.ctx)
8493
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 8486 of file z3py.py.

8486 def parse_string(self, s):
8487 """Parse rules and queries from a string"""
8488 return AstVector(Z3_fixedpoint_from_string(self.ctx.ref(), self.fixedpoint, s), self.ctx)
8489
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 8384 of file z3py.py.

8384 def query(self, *query):
8385 """Query the fixedpoint engine whether formula is derivable.
8386 You can also pass an tuple or list of recursive predicates.
8387 """
8388 query = _get_args(query)
8389 sz = len(query)
8390 if sz >= 1 and isinstance(query[0], FuncDeclRef):
8391 _decls = (FuncDecl * sz)()
8392 i = 0
8393 for q in query:
8394 _decls[i] = q.ast
8395 i = i + 1
8396 r = Z3_fixedpoint_query_relations(self.ctx.ref(), self.fixedpoint, sz, _decls)
8397 else:
8398 if sz == 1:
8399 query = query[0]
8400 else:
8401 query = And(query, self.ctx)
8402 query = self.abstract(query, False)
8403 r = Z3_fixedpoint_query(self.ctx.ref(), self.fixedpoint, query.as_ast())
8404 return CheckSatResult(r)
8405
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 8406 of file z3py.py.

8406 def query_from_lvl(self, lvl, *query):
8407 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
8408 """
8409 query = _get_args(query)
8410 sz = len(query)
8411 if sz >= 1 and isinstance(query[0], FuncDecl):
8412 _z3_assert(False, "unsupported")
8413 else:
8414 if sz == 1:
8415 query = query[0]
8416 else:
8417 query = And(query)
8418 query = self.abstract(query, False)
8419 r = Z3_fixedpoint_query_from_lvl(self.ctx.ref(), self.fixedpoint, query.as_ast(), lvl)
8420 return CheckSatResult(r)
8421

◆ reason_unknown()

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

Definition at line 8525 of file z3py.py.

8525 def reason_unknown(self):
8526 """Return a string describing why the last `query()` returned `unknown`.
8527 """
8528 return Z3_fixedpoint_get_reason_unknown(self.ctx.ref(), self.fixedpoint)
8529
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 8470 of file z3py.py.

8470 def register_relation(self, *relations):
8471 """Register relation as recursive"""
8472 relations = _get_args(relations)
8473 for f in relations:
8474 Z3_fixedpoint_register_relation(self.ctx.ref(), self.fixedpoint, f.ast)
8475
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 8376 of file z3py.py.

8376 def rule(self, head, body=None, name=None):
8377 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
8378 self.add_rule(head, body, name)
8379

◆ set()

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

Definition at line 8309 of file z3py.py.

8309 def set(self, *args, **keys):
8310 """Set a configuration option. The method `help()` return a string containing all available options.
8311 """
8312 p = args2params(args, keys, self.ctx)
8313 Z3_fixedpoint_set_params(self.ctx.ref(), self.fixedpoint, p.params)
8314
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 8476 of file z3py.py.

8476 def set_predicate_representation(self, f, *representations):
8477 """Control how relation is represented"""
8478 representations = _get_args(representations)
8479 representations = [to_symbol(s) for s in representations]
8480 sz = len(representations)
8481 args = (Symbol * sz)()
8482 for i in range(sz):
8483 args[i] = representations[i]
8484 Z3_fixedpoint_set_predicate_representation(self.ctx.ref(), self.fixedpoint, f.ast, sz, args)
8485
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 8506 of file z3py.py.

8506 def sexpr(self):
8507 """Return a formatted string (in Lisp-like format) with all added constraints.
8508 We say the string is in s-expression format.
8509 """
8510 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, 0, (Ast * 0)())
8511
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 8520 of file z3py.py.

8520 def statistics(self):
8521 """Return statistics for the last `query()`.
8522 """
8523 return Statistics(Z3_fixedpoint_get_statistics(self.ctx.ref(), self.fixedpoint), self.ctx)
8524
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 8512 of file z3py.py.

8512 def to_string(self, queries):
8513 """Return a formatted string (in Lisp-like format) with all added constraints.
8514 We say the string is in s-expression format.
8515 Include also queries.
8516 """
8517 args, len = _to_ast_array(queries)
8518 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, len, args)
8519

◆ update_rule()

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

Definition at line 8422 of file z3py.py.

8422 def update_rule(self, head, body, name):
8423 """update rule"""
8424 if name is None:
8425 name = ""
8426 name = to_symbol(name, self.ctx)
8427 body = _get_args(body)
8428 f = self.abstract(Implies(And(body, self.ctx), head))
8429 Z3_fixedpoint_update_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
8430
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 8293 of file z3py.py.

◆ fixedpoint

fixedpoint = None

Definition at line 8294 of file z3py.py.

◆ vars

vars = []

Definition at line 8300 of file z3py.py.