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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 7598 of file z3py.py.

7598 def __init__(self, fixedpoint=None, ctx=None):
7599 assert fixedpoint is None or ctx is not None
7600 self.ctx = _get_ctx(ctx)
7601 self.fixedpoint = None
7602 if fixedpoint is None:
7603 self.fixedpoint = Z3_mk_fixedpoint(self.ctx.ref())
7604 else:
7605 self.fixedpoint = fixedpoint
7606 Z3_fixedpoint_inc_ref(self.ctx.ref(), self.fixedpoint)
7607 self.vars = []
7608
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 7612 of file z3py.py.

7612 def __del__(self):
7613 if self.fixedpoint is not None and self.ctx.ref() is not None and Z3_fixedpoint_dec_ref is not None:
7614 Z3_fixedpoint_dec_ref(self.ctx.ref(), self.fixedpoint)
7615
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 7609 of file z3py.py.

7609 def __deepcopy__(self, memo={}):
7610 return FixedPoint(self.fixedpoint, self.ctx)
7611

◆ __iadd__()

__iadd__ ( self,
fml )

Definition at line 7648 of file z3py.py.

7648 def __iadd__(self, fml):
7649 self.add(fml)
7650 return self
7651

◆ __repr__()

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

Definition at line 7809 of file z3py.py.

7809 def __repr__(self):
7810 """Return a formatted string with all added rules and constraints."""
7811 return self.sexpr()
7812

◆ abstract()

abstract ( self,
fml,
is_forall = True )

Definition at line 7846 of file z3py.py.

7846 def abstract(self, fml, is_forall=True):
7847 if self.vars == []:
7848 return fml
7849 if is_forall:
7850 return ForAll(self.vars, fml)
7851 else:
7852 return Exists(self.vars, fml)
7853
7854

◆ add()

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

Definition at line 7644 of file z3py.py.

7644 def add(self, *args):
7645 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7646 self.assert_exprs(*args)
7647

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

7771 def add_cover(self, level, predicate, property):
7772 """Add property to predicate for the level'th unfolding.
7773 -1 is treated as infinity (infinity)
7774 """
7775 Z3_fixedpoint_add_cover(self.ctx.ref(), self.fixedpoint, level, predicate.ast, property.ast)
7776
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 7660 of file z3py.py.

7660 def add_rule(self, head, body=None, name=None):
7661 """Assert rules defining recursive predicates to the fixedpoint solver.
7662 >>> a = Bool('a')
7663 >>> b = Bool('b')
7664 >>> s = Fixedpoint()
7665 >>> s.register_relation(a.decl())
7666 >>> s.register_relation(b.decl())
7667 >>> s.fact(a)
7668 >>> s.rule(b, a)
7669 >>> s.query(b)
7670 sat
7671 """
7672 if name is None:
7673 name = ""
7674 name = to_symbol(name, self.ctx)
7675 if body is None:
7676 head = self.abstract(head)
7677 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, head.as_ast(), name)
7678 else:
7679 body = _get_args(body)
7680 f = self.abstract(Implies(And(body, self.ctx), head))
7681 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
7682
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 7652 of file z3py.py.

7652 def append(self, *args):
7653 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7654 self.assert_exprs(*args)
7655

◆ assert_exprs()

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

Definition at line 7630 of file z3py.py.

7630 def assert_exprs(self, *args):
7631 """Assert constraints as background axioms for the fixedpoint solver."""
7632 args = _get_args(args)
7633 s = BoolSort(self.ctx)
7634 for arg in args:
7635 if isinstance(arg, Goal) or isinstance(arg, AstVector):
7636 for f in arg:
7637 f = self.abstract(f)
7638 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, f.as_ast())
7639 else:
7640 arg = s.cast(arg)
7641 arg = self.abstract(arg)
7642 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, arg.as_ast())
7643
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 7837 of file z3py.py.

7837 def declare_var(self, *vars):
7838 """Add variable or several variables.
7839 The added variable or variables will be bound in the rules
7840 and queries
7841 """
7842 vars = _get_args(vars)
7843 for v in vars:
7844 self.vars += [v]
7845

◆ fact()

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

Definition at line 7687 of file z3py.py.

7687 def fact(self, head, name=None):
7688 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7689 self.add_rule(head, None, name)
7690

◆ get_answer()

get_answer ( self)
Retrieve answer from last query call.

Definition at line 7738 of file z3py.py.

7738 def get_answer(self):
7739 """Retrieve answer from last query call."""
7740 r = Z3_fixedpoint_get_answer(self.ctx.ref(), self.fixedpoint)
7741 return _to_expr_ref(r, self.ctx)
7742
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 7805 of file z3py.py.

7805 def get_assertions(self):
7806 """retrieve assertions that have been added to fixedpoint context"""
7807 return AstVector(Z3_fixedpoint_get_assertions(self.ctx.ref(), self.fixedpoint), self.ctx)
7808
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 7764 of file z3py.py.

7764 def get_cover_delta(self, level, predicate):
7765 """Retrieve properties known about predicate for the level'th unfolding.
7766 -1 is treated as the limit (infinity)
7767 """
7768 r = Z3_fixedpoint_get_cover_delta(self.ctx.ref(), self.fixedpoint, level, predicate.ast)
7769 return _to_expr_ref(r, self.ctx)
7770
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 7743 of file z3py.py.

7743 def get_ground_sat_answer(self):
7744 """Retrieve a ground cex from last query call."""
7745 r = Z3_fixedpoint_get_ground_sat_answer(self.ctx.ref(), self.fixedpoint)
7746 return _to_expr_ref(r, self.ctx)
7747

◆ get_num_levels()

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

Definition at line 7760 of file z3py.py.

7760 def get_num_levels(self, predicate):
7761 """Retrieve number of levels used for predicate in PDR engine"""
7762 return Z3_fixedpoint_get_num_levels(self.ctx.ref(), self.fixedpoint, predicate.ast)
7763
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 7752 of file z3py.py.

7752 def get_rule_names_along_trace(self):
7753 """retrieve rule names along the counterexample trace"""
7754 # this is a hack as I don't know how to return a list of symbols from C++;
7755 # obtain names as a single string separated by semicolons
7756 names = _symbol2py(self.ctx, Z3_fixedpoint_get_rule_names_along_trace(self.ctx.ref(), self.fixedpoint))
7757 # split into individual names
7758 return names.split(";")
7759

◆ get_rules()

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

Definition at line 7801 of file z3py.py.

7801 def get_rules(self):
7802 """retrieve rules that have been added to fixedpoint context"""
7803 return AstVector(Z3_fixedpoint_get_rules(self.ctx.ref(), self.fixedpoint), self.ctx)
7804
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 7748 of file z3py.py.

7748 def get_rules_along_trace(self):
7749 """retrieve rules along the counterexample trace"""
7750 return AstVector(Z3_fixedpoint_get_rules_along_trace(self.ctx.ref(), self.fixedpoint), self.ctx)
7751

◆ help()

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

Definition at line 7622 of file z3py.py.

7622 def help(self):
7623 """Display a string describing all available options."""
7624 print(Z3_fixedpoint_get_help(self.ctx.ref(), self.fixedpoint))
7625
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 7656 of file z3py.py.

7656 def insert(self, *args):
7657 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7658 self.assert_exprs(*args)
7659

◆ param_descrs()

param_descrs ( self)
Return the parameter description set.

Definition at line 7626 of file z3py.py.

7626 def param_descrs(self):
7627 """Return the parameter description set."""
7628 return ParamDescrsRef(Z3_fixedpoint_get_param_descrs(self.ctx.ref(), self.fixedpoint), self.ctx)
7629
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 7797 of file z3py.py.

7797 def parse_file(self, f):
7798 """Parse rules and queries from a file"""
7799 return AstVector(Z3_fixedpoint_from_file(self.ctx.ref(), self.fixedpoint, f), self.ctx)
7800
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 7793 of file z3py.py.

7793 def parse_string(self, s):
7794 """Parse rules and queries from a string"""
7795 return AstVector(Z3_fixedpoint_from_string(self.ctx.ref(), self.fixedpoint, s), self.ctx)
7796
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 7691 of file z3py.py.

7691 def query(self, *query):
7692 """Query the fixedpoint engine whether formula is derivable.
7693 You can also pass an tuple or list of recursive predicates.
7694 """
7695 query = _get_args(query)
7696 sz = len(query)
7697 if sz >= 1 and isinstance(query[0], FuncDeclRef):
7698 _decls = (FuncDecl * sz)()
7699 i = 0
7700 for q in query:
7701 _decls[i] = q.ast
7702 i = i + 1
7703 r = Z3_fixedpoint_query_relations(self.ctx.ref(), self.fixedpoint, sz, _decls)
7704 else:
7705 if sz == 1:
7706 query = query[0]
7707 else:
7708 query = And(query, self.ctx)
7709 query = self.abstract(query, False)
7710 r = Z3_fixedpoint_query(self.ctx.ref(), self.fixedpoint, query.as_ast())
7711 return CheckSatResult(r)
7712
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 7713 of file z3py.py.

7713 def query_from_lvl(self, lvl, *query):
7714 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7715 """
7716 query = _get_args(query)
7717 sz = len(query)
7718 if sz >= 1 and isinstance(query[0], FuncDecl):
7719 _z3_assert(False, "unsupported")
7720 else:
7721 if sz == 1:
7722 query = query[0]
7723 else:
7724 query = And(query)
7725 query = self.abstract(query, False)
7726 r = Z3_fixedpoint_query_from_lvl(self.ctx.ref(), self.fixedpoint, query.as_ast(), lvl)
7727 return CheckSatResult(r)
7728

◆ reason_unknown()

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

Definition at line 7832 of file z3py.py.

7832 def reason_unknown(self):
7833 """Return a string describing why the last `query()` returned `unknown`.
7834 """
7835 return Z3_fixedpoint_get_reason_unknown(self.ctx.ref(), self.fixedpoint)
7836
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 7777 of file z3py.py.

7777 def register_relation(self, *relations):
7778 """Register relation as recursive"""
7779 relations = _get_args(relations)
7780 for f in relations:
7781 Z3_fixedpoint_register_relation(self.ctx.ref(), self.fixedpoint, f.ast)
7782
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 7683 of file z3py.py.

7683 def rule(self, head, body=None, name=None):
7684 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7685 self.add_rule(head, body, name)
7686

◆ set()

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

Definition at line 7616 of file z3py.py.

7616 def set(self, *args, **keys):
7617 """Set a configuration option. The method `help()` return a string containing all available options.
7618 """
7619 p = args2params(args, keys, self.ctx)
7620 Z3_fixedpoint_set_params(self.ctx.ref(), self.fixedpoint, p.params)
7621
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 7783 of file z3py.py.

7783 def set_predicate_representation(self, f, *representations):
7784 """Control how relation is represented"""
7785 representations = _get_args(representations)
7786 representations = [to_symbol(s) for s in representations]
7787 sz = len(representations)
7788 args = (Symbol * sz)()
7789 for i in range(sz):
7790 args[i] = representations[i]
7791 Z3_fixedpoint_set_predicate_representation(self.ctx.ref(), self.fixedpoint, f.ast, sz, args)
7792
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 7813 of file z3py.py.

7813 def sexpr(self):
7814 """Return a formatted string (in Lisp-like format) with all added constraints.
7815 We say the string is in s-expression format.
7816 """
7817 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, 0, (Ast * 0)())
7818
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 7827 of file z3py.py.

7827 def statistics(self):
7828 """Return statistics for the last `query()`.
7829 """
7830 return Statistics(Z3_fixedpoint_get_statistics(self.ctx.ref(), self.fixedpoint), self.ctx)
7831
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 7819 of file z3py.py.

7819 def to_string(self, queries):
7820 """Return a formatted string (in Lisp-like format) with all added constraints.
7821 We say the string is in s-expression format.
7822 Include also queries.
7823 """
7824 args, len = _to_ast_array(queries)
7825 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, len, args)
7826

◆ update_rule()

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

Definition at line 7729 of file z3py.py.

7729 def update_rule(self, head, body, name):
7730 """update rule"""
7731 if name is None:
7732 name = ""
7733 name = to_symbol(name, self.ctx)
7734 body = _get_args(body)
7735 f = self.abstract(Implies(And(body, self.ctx), head))
7736 Z3_fixedpoint_update_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
7737
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 7600 of file z3py.py.

◆ fixedpoint

fixedpoint = None

Definition at line 7601 of file z3py.py.

◆ vars

vars = []

Definition at line 7607 of file z3py.py.