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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 7730 of file z3py.py.

7730 def __init__(self, fixedpoint=None, ctx=None):
7731 assert fixedpoint is None or ctx is not None
7732 self.ctx = _get_ctx(ctx)
7733 self.fixedpoint = None
7734 if fixedpoint is None:
7735 self.fixedpoint = Z3_mk_fixedpoint(self.ctx.ref())
7736 else:
7737 self.fixedpoint = fixedpoint
7738 Z3_fixedpoint_inc_ref(self.ctx.ref(), self.fixedpoint)
7739 self.vars = []
7740
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 7744 of file z3py.py.

7744 def __del__(self):
7745 if self.fixedpoint is not None and self.ctx.ref() is not None and Z3_fixedpoint_dec_ref is not None:
7746 Z3_fixedpoint_dec_ref(self.ctx.ref(), self.fixedpoint)
7747
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 7741 of file z3py.py.

7741 def __deepcopy__(self, memo={}):
7742 return FixedPoint(self.fixedpoint, self.ctx)
7743

◆ __iadd__()

__iadd__ ( self,
fml )

Definition at line 7780 of file z3py.py.

7780 def __iadd__(self, fml):
7781 self.add(fml)
7782 return self
7783

◆ __repr__()

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

Definition at line 7941 of file z3py.py.

7941 def __repr__(self):
7942 """Return a formatted string with all added rules and constraints."""
7943 return self.sexpr()
7944

◆ abstract()

abstract ( self,
fml,
is_forall = True )

Definition at line 7978 of file z3py.py.

7978 def abstract(self, fml, is_forall=True):
7979 if self.vars == []:
7980 return fml
7981 if is_forall:
7982 return ForAll(self.vars, fml)
7983 else:
7984 return Exists(self.vars, fml)
7985
7986

◆ add()

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

Definition at line 7776 of file z3py.py.

7776 def add(self, *args):
7777 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7778 self.assert_exprs(*args)
7779

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

7903 def add_cover(self, level, predicate, property):
7904 """Add property to predicate for the level'th unfolding.
7905 -1 is treated as infinity (infinity)
7906 """
7907 Z3_fixedpoint_add_cover(self.ctx.ref(), self.fixedpoint, level, predicate.ast, property.ast)
7908
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 7792 of file z3py.py.

7792 def add_rule(self, head, body=None, name=None):
7793 """Assert rules defining recursive predicates to the fixedpoint solver.
7794 >>> a = Bool('a')
7795 >>> b = Bool('b')
7796 >>> s = Fixedpoint()
7797 >>> s.register_relation(a.decl())
7798 >>> s.register_relation(b.decl())
7799 >>> s.fact(a)
7800 >>> s.rule(b, a)
7801 >>> s.query(b)
7802 sat
7803 """
7804 if name is None:
7805 name = ""
7806 name = to_symbol(name, self.ctx)
7807 if body is None:
7808 head = self.abstract(head)
7809 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, head.as_ast(), name)
7810 else:
7811 body = _get_args(body)
7812 f = self.abstract(Implies(And(body, self.ctx), head))
7813 Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
7814
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 7784 of file z3py.py.

7784 def append(self, *args):
7785 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7786 self.assert_exprs(*args)
7787

◆ assert_exprs()

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

Definition at line 7762 of file z3py.py.

7762 def assert_exprs(self, *args):
7763 """Assert constraints as background axioms for the fixedpoint solver."""
7764 args = _get_args(args)
7765 s = BoolSort(self.ctx)
7766 for arg in args:
7767 if isinstance(arg, Goal) or isinstance(arg, AstVector):
7768 for f in arg:
7769 f = self.abstract(f)
7770 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, f.as_ast())
7771 else:
7772 arg = s.cast(arg)
7773 arg = self.abstract(arg)
7774 Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, arg.as_ast())
7775
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 7969 of file z3py.py.

7969 def declare_var(self, *vars):
7970 """Add variable or several variables.
7971 The added variable or variables will be bound in the rules
7972 and queries
7973 """
7974 vars = _get_args(vars)
7975 for v in vars:
7976 self.vars += [v]
7977

◆ fact()

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

Definition at line 7819 of file z3py.py.

7819 def fact(self, head, name=None):
7820 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7821 self.add_rule(head, None, name)
7822

◆ get_answer()

get_answer ( self)
Retrieve answer from last query call.

Definition at line 7870 of file z3py.py.

7870 def get_answer(self):
7871 """Retrieve answer from last query call."""
7872 r = Z3_fixedpoint_get_answer(self.ctx.ref(), self.fixedpoint)
7873 return _to_expr_ref(r, self.ctx)
7874
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 7937 of file z3py.py.

7937 def get_assertions(self):
7938 """retrieve assertions that have been added to fixedpoint context"""
7939 return AstVector(Z3_fixedpoint_get_assertions(self.ctx.ref(), self.fixedpoint), self.ctx)
7940
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 7896 of file z3py.py.

7896 def get_cover_delta(self, level, predicate):
7897 """Retrieve properties known about predicate for the level'th unfolding.
7898 -1 is treated as the limit (infinity)
7899 """
7900 r = Z3_fixedpoint_get_cover_delta(self.ctx.ref(), self.fixedpoint, level, predicate.ast)
7901 return _to_expr_ref(r, self.ctx)
7902
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 7875 of file z3py.py.

7875 def get_ground_sat_answer(self):
7876 """Retrieve a ground cex from last query call."""
7877 r = Z3_fixedpoint_get_ground_sat_answer(self.ctx.ref(), self.fixedpoint)
7878 return _to_expr_ref(r, self.ctx)
7879

◆ get_num_levels()

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

Definition at line 7892 of file z3py.py.

7892 def get_num_levels(self, predicate):
7893 """Retrieve number of levels used for predicate in PDR engine"""
7894 return Z3_fixedpoint_get_num_levels(self.ctx.ref(), self.fixedpoint, predicate.ast)
7895
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 7884 of file z3py.py.

7884 def get_rule_names_along_trace(self):
7885 """retrieve rule names along the counterexample trace"""
7886 # this is a hack as I don't know how to return a list of symbols from C++;
7887 # obtain names as a single string separated by semicolons
7888 names = _symbol2py(self.ctx, Z3_fixedpoint_get_rule_names_along_trace(self.ctx.ref(), self.fixedpoint))
7889 # split into individual names
7890 return names.split(";")
7891

◆ get_rules()

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

Definition at line 7933 of file z3py.py.

7933 def get_rules(self):
7934 """retrieve rules that have been added to fixedpoint context"""
7935 return AstVector(Z3_fixedpoint_get_rules(self.ctx.ref(), self.fixedpoint), self.ctx)
7936
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 7880 of file z3py.py.

7880 def get_rules_along_trace(self):
7881 """retrieve rules along the counterexample trace"""
7882 return AstVector(Z3_fixedpoint_get_rules_along_trace(self.ctx.ref(), self.fixedpoint), self.ctx)
7883

◆ help()

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

Definition at line 7754 of file z3py.py.

7754 def help(self):
7755 """Display a string describing all available options."""
7756 print(Z3_fixedpoint_get_help(self.ctx.ref(), self.fixedpoint))
7757
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 7788 of file z3py.py.

7788 def insert(self, *args):
7789 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7790 self.assert_exprs(*args)
7791

◆ param_descrs()

param_descrs ( self)
Return the parameter description set.

Definition at line 7758 of file z3py.py.

7758 def param_descrs(self):
7759 """Return the parameter description set."""
7760 return ParamDescrsRef(Z3_fixedpoint_get_param_descrs(self.ctx.ref(), self.fixedpoint), self.ctx)
7761
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 7929 of file z3py.py.

7929 def parse_file(self, f):
7930 """Parse rules and queries from a file"""
7931 return AstVector(Z3_fixedpoint_from_file(self.ctx.ref(), self.fixedpoint, f), self.ctx)
7932
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 7925 of file z3py.py.

7925 def parse_string(self, s):
7926 """Parse rules and queries from a string"""
7927 return AstVector(Z3_fixedpoint_from_string(self.ctx.ref(), self.fixedpoint, s), self.ctx)
7928
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 7823 of file z3py.py.

7823 def query(self, *query):
7824 """Query the fixedpoint engine whether formula is derivable.
7825 You can also pass an tuple or list of recursive predicates.
7826 """
7827 query = _get_args(query)
7828 sz = len(query)
7829 if sz >= 1 and isinstance(query[0], FuncDeclRef):
7830 _decls = (FuncDecl * sz)()
7831 i = 0
7832 for q in query:
7833 _decls[i] = q.ast
7834 i = i + 1
7835 r = Z3_fixedpoint_query_relations(self.ctx.ref(), self.fixedpoint, sz, _decls)
7836 else:
7837 if sz == 1:
7838 query = query[0]
7839 else:
7840 query = And(query, self.ctx)
7841 query = self.abstract(query, False)
7842 r = Z3_fixedpoint_query(self.ctx.ref(), self.fixedpoint, query.as_ast())
7843 return CheckSatResult(r)
7844
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 7845 of file z3py.py.

7845 def query_from_lvl(self, lvl, *query):
7846 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7847 """
7848 query = _get_args(query)
7849 sz = len(query)
7850 if sz >= 1 and isinstance(query[0], FuncDecl):
7851 _z3_assert(False, "unsupported")
7852 else:
7853 if sz == 1:
7854 query = query[0]
7855 else:
7856 query = And(query)
7857 query = self.abstract(query, False)
7858 r = Z3_fixedpoint_query_from_lvl(self.ctx.ref(), self.fixedpoint, query.as_ast(), lvl)
7859 return CheckSatResult(r)
7860

◆ reason_unknown()

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

Definition at line 7964 of file z3py.py.

7964 def reason_unknown(self):
7965 """Return a string describing why the last `query()` returned `unknown`.
7966 """
7967 return Z3_fixedpoint_get_reason_unknown(self.ctx.ref(), self.fixedpoint)
7968
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 7909 of file z3py.py.

7909 def register_relation(self, *relations):
7910 """Register relation as recursive"""
7911 relations = _get_args(relations)
7912 for f in relations:
7913 Z3_fixedpoint_register_relation(self.ctx.ref(), self.fixedpoint, f.ast)
7914
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 7815 of file z3py.py.

7815 def rule(self, head, body=None, name=None):
7816 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7817 self.add_rule(head, body, name)
7818

◆ set()

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

Definition at line 7748 of file z3py.py.

7748 def set(self, *args, **keys):
7749 """Set a configuration option. The method `help()` return a string containing all available options.
7750 """
7751 p = args2params(args, keys, self.ctx)
7752 Z3_fixedpoint_set_params(self.ctx.ref(), self.fixedpoint, p.params)
7753
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 7915 of file z3py.py.

7915 def set_predicate_representation(self, f, *representations):
7916 """Control how relation is represented"""
7917 representations = _get_args(representations)
7918 representations = [to_symbol(s) for s in representations]
7919 sz = len(representations)
7920 args = (Symbol * sz)()
7921 for i in range(sz):
7922 args[i] = representations[i]
7923 Z3_fixedpoint_set_predicate_representation(self.ctx.ref(), self.fixedpoint, f.ast, sz, args)
7924
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 7945 of file z3py.py.

7945 def sexpr(self):
7946 """Return a formatted string (in Lisp-like format) with all added constraints.
7947 We say the string is in s-expression format.
7948 """
7949 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, 0, (Ast * 0)())
7950
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 7959 of file z3py.py.

7959 def statistics(self):
7960 """Return statistics for the last `query()`.
7961 """
7962 return Statistics(Z3_fixedpoint_get_statistics(self.ctx.ref(), self.fixedpoint), self.ctx)
7963
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 7951 of file z3py.py.

7951 def to_string(self, queries):
7952 """Return a formatted string (in Lisp-like format) with all added constraints.
7953 We say the string is in s-expression format.
7954 Include also queries.
7955 """
7956 args, len = _to_ast_array(queries)
7957 return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, len, args)
7958

◆ update_rule()

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

Definition at line 7861 of file z3py.py.

7861 def update_rule(self, head, body, name):
7862 """update rule"""
7863 if name is None:
7864 name = ""
7865 name = to_symbol(name, self.ctx)
7866 body = _get_args(body)
7867 f = self.abstract(Implies(And(body, self.ctx), head))
7868 Z3_fixedpoint_update_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
7869
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 7732 of file z3py.py.

◆ fixedpoint

fixedpoint = None

Definition at line 7733 of file z3py.py.

◆ vars

vars = []

Definition at line 7739 of file z3py.py.