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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 7662 of file z3py.py.

7662 def __init__(self, fixedpoint=None, ctx=None):
7663 assert fixedpoint is None or ctx is not None
7664 self.ctx = _get_ctx(ctx)
7665 self.fixedpoint = None
7666 if fixedpoint is None:
7667 self.fixedpoint = Z3_mk_fixedpoint(self.ctx.ref())
7668 else:
7669 self.fixedpoint = fixedpoint
7670 Z3_fixedpoint_inc_ref(self.ctx.ref(), self.fixedpoint)
7671 self.vars = []
7672
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 7676 of file z3py.py.

7676 def __del__(self):
7677 if self.fixedpoint is not None and self.ctx.ref() is not None and Z3_fixedpoint_dec_ref is not None:
7678 Z3_fixedpoint_dec_ref(self.ctx.ref(), self.fixedpoint)
7679
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 7673 of file z3py.py.

7673 def __deepcopy__(self, memo={}):
7674 return FixedPoint(self.fixedpoint, self.ctx)
7675

◆ __iadd__()

__iadd__ ( self,
fml )

Definition at line 7712 of file z3py.py.

7712 def __iadd__(self, fml):
7713 self.add(fml)
7714 return self
7715

◆ __repr__()

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

Definition at line 7873 of file z3py.py.

7873 def __repr__(self):
7874 """Return a formatted string with all added rules and constraints."""
7875 return self.sexpr()
7876

◆ abstract()

abstract ( self,
fml,
is_forall = True )

Definition at line 7910 of file z3py.py.

7910 def abstract(self, fml, is_forall=True):
7911 if self.vars == []:
7912 return fml
7913 if is_forall:
7914 return ForAll(self.vars, fml)
7915 else:
7916 return Exists(self.vars, fml)
7917
7918

◆ add()

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

Definition at line 7708 of file z3py.py.

7708 def add(self, *args):
7709 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7710 self.assert_exprs(*args)
7711

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

7835 def add_cover(self, level, predicate, property):
7836 """Add property to predicate for the level'th unfolding.
7837 -1 is treated as infinity (infinity)
7838 """
7839 Z3_fixedpoint_add_cover(self.ctx.ref(), self.fixedpoint, level, predicate.ast, property.ast)
7840
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 7724 of file z3py.py.

7724 def add_rule(self, head, body=None, name=None):
7725 """Assert rules defining recursive predicates to the fixedpoint solver.
7726 >>> a = Bool('a')
7727 >>> b = Bool('b')
7728 >>> s = Fixedpoint()
7729 >>> s.register_relation(a.decl())
7730 >>> s.register_relation(b.decl())
7731 >>> s.fact(a)
7732 >>> s.rule(b, a)
7733 >>> s.query(b)
7734 sat
7735 """
7736 if name is None:
7737 name = ""
7738 name = to_symbol(name, self.ctx)
7739 if body is None:
7740 head = self.abstract(head)
7741 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, head.as_ast(), name)
7742 else:
7743 body = _get_args(body)
7744 f = self.abstract(Implies(And(body, self.ctx), head))
7745 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
7746
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 7716 of file z3py.py.

7716 def append(self, *args):
7717 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7718 self.assert_exprs(*args)
7719

◆ assert_exprs()

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

Definition at line 7694 of file z3py.py.

7694 def assert_exprs(self, *args):
7695 """Assert constraints as background axioms for the fixedpoint solver."""
7696 args = _get_args(args)
7697 s = BoolSort(self.ctx)
7698 for arg in args:
7699 if isinstance(arg, Goal) or isinstance(arg, AstVector):
7700 for f in arg:
7701 f = self.abstract(f)
7702 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, f.as_ast())
7703 else:
7704 arg = s.cast(arg)
7705 arg = self.abstract(arg)
7706 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, arg.as_ast())
7707
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 7901 of file z3py.py.

7901 def declare_var(self, *vars):
7902 """Add variable or several variables.
7903 The added variable or variables will be bound in the rules
7904 and queries
7905 """
7906 vars = _get_args(vars)
7907 for v in vars:
7908 self.vars += [v]
7909

◆ fact()

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

Definition at line 7751 of file z3py.py.

7751 def fact(self, head, name=None):
7752 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7753 self.add_rule(head, None, name)
7754

◆ get_answer()

get_answer ( self)
Retrieve answer from last query call.

Definition at line 7802 of file z3py.py.

7802 def get_answer(self):
7803 """Retrieve answer from last query call."""
7804 r = Z3_fixedpoint_get_answer(self.ctx.ref(), self.fixedpoint)
7805 return _to_expr_ref(r, self.ctx)
7806
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 7869 of file z3py.py.

7869 def get_assertions(self):
7870 """retrieve assertions that have been added to fixedpoint context"""
7871 return AstVector(Z3_fixedpoint_get_assertions(self.ctx.ref(), self.fixedpoint), self.ctx)
7872
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 7828 of file z3py.py.

7828 def get_cover_delta(self, level, predicate):
7829 """Retrieve properties known about predicate for the level'th unfolding.
7830 -1 is treated as the limit (infinity)
7831 """
7832 r = Z3_fixedpoint_get_cover_delta(self.ctx.ref(), self.fixedpoint, level, predicate.ast)
7833 return _to_expr_ref(r, self.ctx)
7834
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 7807 of file z3py.py.

7807 def get_ground_sat_answer(self):
7808 """Retrieve a ground cex from last query call."""
7809 r = Z3_fixedpoint_get_ground_sat_answer(self.ctx.ref(), self.fixedpoint)
7810 return _to_expr_ref(r, self.ctx)
7811

◆ get_num_levels()

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

Definition at line 7824 of file z3py.py.

7824 def get_num_levels(self, predicate):
7825 """Retrieve number of levels used for predicate in PDR engine"""
7826 return Z3_fixedpoint_get_num_levels(self.ctx.ref(), self.fixedpoint, predicate.ast)
7827
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 7816 of file z3py.py.

7816 def get_rule_names_along_trace(self):
7817 """retrieve rule names along the counterexample trace"""
7818 # this is a hack as I don't know how to return a list of symbols from C++;
7819 # obtain names as a single string separated by semicolons
7820 names = _symbol2py(self.ctx, Z3_fixedpoint_get_rule_names_along_trace(self.ctx.ref(), self.fixedpoint))
7821 # split into individual names
7822 return names.split(";")
7823

◆ get_rules()

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

Definition at line 7865 of file z3py.py.

7865 def get_rules(self):
7866 """retrieve rules that have been added to fixedpoint context"""
7867 return AstVector(Z3_fixedpoint_get_rules(self.ctx.ref(), self.fixedpoint), self.ctx)
7868
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 7812 of file z3py.py.

7812 def get_rules_along_trace(self):
7813 """retrieve rules along the counterexample trace"""
7814 return AstVector(Z3_fixedpoint_get_rules_along_trace(self.ctx.ref(), self.fixedpoint), self.ctx)
7815

◆ help()

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

Definition at line 7686 of file z3py.py.

7686 def help(self):
7687 """Display a string describing all available options."""
7688 print(Z3_fixedpoint_get_help(self.ctx.ref(), self.fixedpoint))
7689
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 7720 of file z3py.py.

7720 def insert(self, *args):
7721 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7722 self.assert_exprs(*args)
7723

◆ param_descrs()

param_descrs ( self)
Return the parameter description set.

Definition at line 7690 of file z3py.py.

7690 def param_descrs(self):
7691 """Return the parameter description set."""
7692 return ParamDescrsRef(Z3_fixedpoint_get_param_descrs(self.ctx.ref(), self.fixedpoint), self.ctx)
7693
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 7861 of file z3py.py.

7861 def parse_file(self, f):
7862 """Parse rules and queries from a file"""
7863 return AstVector(Z3_fixedpoint_from_file(self.ctx.ref(), self.fixedpoint, f), self.ctx)
7864
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 7857 of file z3py.py.

7857 def parse_string(self, s):
7858 """Parse rules and queries from a string"""
7859 return AstVector(Z3_fixedpoint_from_string(self.ctx.ref(), self.fixedpoint, s), self.ctx)
7860
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 7755 of file z3py.py.

7755 def query(self, *query):
7756 """Query the fixedpoint engine whether formula is derivable.
7757 You can also pass an tuple or list of recursive predicates.
7758 """
7759 query = _get_args(query)
7760 sz = len(query)
7761 if sz >= 1 and isinstance(query[0], FuncDeclRef):
7762 _decls = (FuncDecl * sz)()
7763 i = 0
7764 for q in query:
7765 _decls[i] = q.ast
7766 i = i + 1
7767 r = Z3_fixedpoint_query_relations(self.ctx.ref(), self.fixedpoint, sz, _decls)
7768 else:
7769 if sz == 1:
7770 query = query[0]
7771 else:
7772 query = And(query, self.ctx)
7773 query = self.abstract(query, False)
7774 r = Z3_fixedpoint_query(self.ctx.ref(), self.fixedpoint, query.as_ast())
7775 return CheckSatResult(r)
7776
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 7777 of file z3py.py.

7777 def query_from_lvl(self, lvl, *query):
7778 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7779 """
7780 query = _get_args(query)
7781 sz = len(query)
7782 if sz >= 1 and isinstance(query[0], FuncDecl):
7783 _z3_assert(False, "unsupported")
7784 else:
7785 if sz == 1:
7786 query = query[0]
7787 else:
7788 query = And(query)
7789 query = self.abstract(query, False)
7790 r = Z3_fixedpoint_query_from_lvl(self.ctx.ref(), self.fixedpoint, query.as_ast(), lvl)
7791 return CheckSatResult(r)
7792

◆ reason_unknown()

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

Definition at line 7896 of file z3py.py.

7896 def reason_unknown(self):
7897 """Return a string describing why the last `query()` returned `unknown`.
7898 """
7899 return Z3_fixedpoint_get_reason_unknown(self.ctx.ref(), self.fixedpoint)
7900
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 7841 of file z3py.py.

7841 def register_relation(self, *relations):
7842 """Register relation as recursive"""
7843 relations = _get_args(relations)
7844 for f in relations:
7845 Z3_fixedpoint_register_relation(self.ctx.ref(), self.fixedpoint, f.ast)
7846
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 7747 of file z3py.py.

7747 def rule(self, head, body=None, name=None):
7748 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7749 self.add_rule(head, body, name)
7750

◆ set()

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

Definition at line 7680 of file z3py.py.

7680 def set(self, *args, **keys):
7681 """Set a configuration option. The method `help()` return a string containing all available options.
7682 """
7683 p = args2params(args, keys, self.ctx)
7684 Z3_fixedpoint_set_params(self.ctx.ref(), self.fixedpoint, p.params)
7685
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 7847 of file z3py.py.

7847 def set_predicate_representation(self, f, *representations):
7848 """Control how relation is represented"""
7849 representations = _get_args(representations)
7850 representations = [to_symbol(s) for s in representations]
7851 sz = len(representations)
7852 args = (Symbol * sz)()
7853 for i in range(sz):
7854 args[i] = representations[i]
7855 Z3_fixedpoint_set_predicate_representation(self.ctx.ref(), self.fixedpoint, f.ast, sz, args)
7856
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 7877 of file z3py.py.

7877 def sexpr(self):
7878 """Return a formatted string (in Lisp-like format) with all added constraints.
7879 We say the string is in s-expression format.
7880 """
7881 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, 0, (Ast * 0)())
7882
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 7891 of file z3py.py.

7891 def statistics(self):
7892 """Return statistics for the last `query()`.
7893 """
7894 return Statistics(Z3_fixedpoint_get_statistics(self.ctx.ref(), self.fixedpoint), self.ctx)
7895
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 7883 of file z3py.py.

7883 def to_string(self, queries):
7884 """Return a formatted string (in Lisp-like format) with all added constraints.
7885 We say the string is in s-expression format.
7886 Include also queries.
7887 """
7888 args, len = _to_ast_array(queries)
7889 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, len, args)
7890

◆ update_rule()

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

Definition at line 7793 of file z3py.py.

7793 def update_rule(self, head, body, name):
7794 """update rule"""
7795 if name is None:
7796 name = ""
7797 name = to_symbol(name, self.ctx)
7798 body = _get_args(body)
7799 f = self.abstract(Implies(And(body, self.ctx), head))
7800 Z3_fixedpoint_update_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
7801
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 7664 of file z3py.py.

◆ fixedpoint

fixedpoint = None

Definition at line 7665 of file z3py.py.

◆ vars

vars = []

Definition at line 7671 of file z3py.py.