Z3
Public Member Functions | Data Fields
Fixedpoint Class Reference

Fixedpoint. More...

+ Inheritance diagram for Fixedpoint:

Public Member Functions

def __init__
 
def __del__ (self)
 
def set (self, args, keys)
 
def help (self)
 
def param_descrs (self)
 
def assert_exprs (self, args)
 
def add (self, args)
 
def append (self, args)
 
def insert (self, args)
 
def add_rule
 
def rule
 
def fact
 
def query (self, query)
 
def push (self)
 
def pop (self)
 
def update_rule (self, head, body, name)
 
def get_answer (self)
 
def get_num_levels (self, predicate)
 
def get_cover_delta (self, level, predicate)
 
def add_cover (self, level, predicate, property)
 
def register_relation (self, relations)
 
def set_predicate_representation (self, f, representations)
 
def parse_string (self, s)
 
def parse_file (self, f)
 
def get_rules (self)
 
def get_assertions (self)
 
def __repr__ (self)
 
def sexpr (self)
 
def to_string (self, queries)
 
def statistics (self)
 
def reason_unknown (self)
 
def declare_var (self, vars)
 
def abstract
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Data Fields

 ctx
 
 fixedpoint
 
 vars
 

Detailed Description

Fixedpoint.

Fixedpoint API provides methods for solving with recursive predicates

Definition at line 6091 of file z3py.py.

Constructor & Destructor Documentation

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

Definition at line 6094 of file z3py.py.

6094  def __init__(self, fixedpoint=None, ctx=None):
6095  assert fixedpoint == None or ctx != None
6096  self.ctx = _get_ctx(ctx)
6097  self.fixedpoint = None
6098  if fixedpoint == None:
6099  self.fixedpoint = Z3_mk_fixedpoint(self.ctx.ref())
6100  else:
6101  self.fixedpoint = fixedpoint
6102  Z3_fixedpoint_inc_ref(self.ctx.ref(), self.fixedpoint)
6103  self.vars = []
6104 
def __init__
Definition: z3py.py:6094
void Z3_API Z3_fixedpoint_inc_ref(__in Z3_context c, __in Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(__in Z3_context c)
Create a new fixedpoint context.
def __del__ (   self)

Definition at line 6105 of file z3py.py.

6105  def __del__(self):
6106  if self.fixedpoint != None:
6107  Z3_fixedpoint_dec_ref(self.ctx.ref(), self.fixedpoint)
6108 
void Z3_API Z3_fixedpoint_dec_ref(__in Z3_context c, __in Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
def __del__(self)
Definition: z3py.py:6105

Member Function Documentation

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

Definition at line 6269 of file z3py.py.

6269  def __repr__(self):
6270  """Return a formatted string with all added rules and constraints."""
6271  return self.sexpr()
6272 
def __repr__(self)
Definition: z3py.py:6269
def sexpr(self)
Definition: z3py.py:6273
def abstract (   self,
  fml,
  is_forall = True 
)

Definition at line 6305 of file z3py.py.

Referenced by Fixedpoint.add_rule(), Fixedpoint.assert_exprs(), Fixedpoint.query(), and Fixedpoint.update_rule().

6305  def abstract(self, fml, is_forall=True):
6306  if self.vars == []:
6307  return fml
6308  if is_forall:
6309  return ForAll(self.vars, fml)
6310  else:
6311  return Exists(self.vars, fml)
6312 
def Exists
Definition: z3py.py:1808
def ForAll
Definition: z3py.py:1789
def abstract
Definition: z3py.py:6305
def add (   self,
  args 
)
Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.

Definition at line 6137 of file z3py.py.

6137  def add(self, *args):
6138  """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
6139  self.assert_exprs(*args)
6140 
def assert_exprs(self, args)
Definition: z3py.py:6123
def add(self, args)
Definition: z3py.py:6137
def add_cover (   self,
  level,
  predicate,
  property 
)
Add property to predicate for the level'th unfolding. -1 is treated as infinity (infinity)

Definition at line 6233 of file z3py.py.

6233  def add_cover(self, level, predicate, property):
6234  """Add property to predicate for the level'th unfolding. -1 is treated as infinity (infinity)"""
6235  Z3_fixedpoint_add_cover(self.ctx.ref(), self.fixedpoint, level, predicate.ast, property.ast)
6236 
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...
def add_cover(self, level, predicate, property)
Definition: z3py.py:6233
def 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 6149 of file z3py.py.

Referenced by Fixedpoint.fact(), and Fixedpoint.rule().

6149  def add_rule(self, head, body = None, name = None):
6150  """Assert rules defining recursive predicates to the fixedpoint solver.
6151  >>> a = Bool('a')
6152  >>> b = Bool('b')
6153  >>> s = Fixedpoint()
6154  >>> s.register_relation(a.decl())
6155  >>> s.register_relation(b.decl())
6156  >>> s.fact(a)
6157  >>> s.rule(b, a)
6158  >>> s.query(b)
6159  sat
6160  """
6161  if name == None:
6162  name = ""
6163  name = to_symbol(name, self.ctx)
6164  if body == None:
6165  head = self.abstract(head)
6166  Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, head.as_ast(), name)
6167  else:
6168  body = _get_args(body)
6169  f = self.abstract(Implies(And(body),head))
6170  Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
6171 
def Implies
Definition: z3py.py:1413
def And(args)
Definition: z3py.py:1468
def abstract
Definition: z3py.py:6305
void Z3_API Z3_fixedpoint_add_rule(__in Z3_context c, __in Z3_fixedpoint d, __in Z3_ast rule, __in Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form: ...
def add_rule
Definition: z3py.py:6149
def to_symbol
Definition: z3py.py:94
def append (   self,
  args 
)
Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.

Definition at line 6141 of file z3py.py.

6141  def append(self, *args):
6142  """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
6143  self.assert_exprs(*args)
6144 
def assert_exprs(self, args)
Definition: z3py.py:6123
def append(self, args)
Definition: z3py.py:6141
def assert_exprs (   self,
  args 
)
Assert constraints as background axioms for the fixedpoint solver.

Definition at line 6123 of file z3py.py.

Referenced by Fixedpoint.add(), Fixedpoint.append(), and Fixedpoint.insert().

6123  def assert_exprs(self, *args):
6124  """Assert constraints as background axioms for the fixedpoint solver."""
6125  args = _get_args(args)
6126  s = BoolSort(self.ctx)
6127  for arg in args:
6128  if isinstance(arg, Goal) or isinstance(arg, AstVector):
6129  for f in arg:
6130  f = self.abstract(f)
6131  Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, f.as_ast())
6132  else:
6133  arg = s.cast(arg)
6134  arg = self.abstract(arg)
6135  Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, arg.as_ast())
6136 
void Z3_API Z3_fixedpoint_assert(__in Z3_context c, __in Z3_fixedpoint d, __in Z3_ast axiom)
Assert a constraint to the fixedpoint context.
def BoolSort
Definition: z3py.py:1325
def assert_exprs(self, args)
Definition: z3py.py:6123
def abstract
Definition: z3py.py:6305
def 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 6296 of file z3py.py.

6296  def declare_var(self, *vars):
6297  """Add variable or several variables.
6298  The added variable or variables will be bound in the rules
6299  and queries
6300  """
6301  vars = _get_args(vars)
6302  for v in vars:
6303  self.vars += [v]
6304 
def declare_var(self, vars)
Definition: z3py.py:6296
def fact (   self,
  head,
  name = None 
)
Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule.

Definition at line 6176 of file z3py.py.

6176  def fact(self, head, name = None):
6177  """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
6178  self.add_rule(head, None, name)
6179 
def add_rule
Definition: z3py.py:6149
def get_answer (   self)
Retrieve answer from last query call.

Definition at line 6219 of file z3py.py.

6219  def get_answer(self):
6220  """Retrieve answer from last query call."""
6221  r = Z3_fixedpoint_get_answer(self.ctx.ref(), self.fixedpoint)
6222  return _to_expr_ref(r, self.ctx)
6223 
def get_answer(self)
Definition: z3py.py:6219
Z3_ast Z3_API Z3_fixedpoint_get_answer(__in Z3_context c, __in Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
def get_assertions (   self)
retrieve assertions that have been added to fixedpoint context

Definition at line 6265 of file z3py.py.

6265  def get_assertions(self):
6266  """retrieve assertions that have been added to fixedpoint context"""
6267  return AstVector(Z3_fixedpoint_get_assertions(self.ctx.ref(), self.fixedpoint), self.ctx)
6268 
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(__in Z3_context c, __in Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
def get_assertions(self)
Definition: z3py.py:6265
def 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 6228 of file z3py.py.

6228  def get_cover_delta(self, level, predicate):
6229  """Retrieve properties known about predicate for the level'th unfolding. -1 is treated as the limit (infinity)"""
6230  r = Z3_fixedpoint_get_cover_delta(self.ctx.ref(), self.fixedpoint, level, predicate.ast)
6231  return _to_expr_ref(r, self.ctx)
6232 
def get_cover_delta(self, level, predicate)
Definition: z3py.py:6228
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)
def get_num_levels (   self,
  predicate 
)
Retrieve number of levels used for predicate in PDR engine

Definition at line 6224 of file z3py.py.

6224  def get_num_levels(self, predicate):
6225  """Retrieve number of levels used for predicate in PDR engine"""
6226  return Z3_fixedpoint_get_num_levels(self.ctx.ref(), self.fixedpoint, predicate.ast)
6227 
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. ...
def get_num_levels(self, predicate)
Definition: z3py.py:6224
def get_rules (   self)
retrieve rules that have been added to fixedpoint context

Definition at line 6261 of file z3py.py.

6261  def get_rules(self):
6262  """retrieve rules that have been added to fixedpoint context"""
6263  return AstVector(Z3_fixedpoint_get_rules(self.ctx.ref(), self.fixedpoint), self.ctx)
6264 
def get_rules(self)
Definition: z3py.py:6261
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(__in Z3_context c, __in Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
def help (   self)
Display a string describing all available options.

Definition at line 6115 of file z3py.py.

6115  def help(self):
6116  """Display a string describing all available options."""
6117  print(Z3_fixedpoint_get_help(self.ctx.ref(), self.fixedpoint))
6118 
Z3_string Z3_API Z3_fixedpoint_get_help(__in Z3_context c, __in Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
def help(self)
Definition: z3py.py:6115
def insert (   self,
  args 
)
Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.

Definition at line 6145 of file z3py.py.

6145  def insert(self, *args):
6146  """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
6147  self.assert_exprs(*args)
6148 
def assert_exprs(self, args)
Definition: z3py.py:6123
def insert(self, args)
Definition: z3py.py:6145
def param_descrs (   self)
Return the parameter description set.

Definition at line 6119 of file z3py.py.

6119  def param_descrs(self):
6120  """Return the parameter description set."""
6121  return ParamDescrsRef(Z3_fixedpoint_get_param_descrs(self.ctx.ref(), self.fixedpoint), self.ctx)
6122 
def param_descrs(self)
Definition: z3py.py:6119
Z3_param_descrs Z3_API Z3_fixedpoint_get_param_descrs(__in Z3_context c, __in Z3_fixedpoint f)
Return the parameter description set for the given fixedpoint object.
def parse_file (   self,
  f 
)
Parse rules and queries from a file

Definition at line 6257 of file z3py.py.

6257  def parse_file(self, f):
6258  """Parse rules and queries from a file"""
6259  return AstVector(Z3_fixedpoint_from_file(self.ctx.ref(), self.fixedpoint, f), self.ctx)
6260 
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(__in Z3_context c, __in Z3_fixedpoint f, __in Z3_string s)
Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context...
def parse_file(self, f)
Definition: z3py.py:6257
def parse_string (   self,
  s 
)
Parse rules and queries from a string

Definition at line 6253 of file z3py.py.

6253  def parse_string(self, s):
6254  """Parse rules and queries from a string"""
6255  return AstVector(Z3_fixedpoint_from_string(self.ctx.ref(), self.fixedpoint, s), self.ctx)
6256 
Z3_ast_vector Z3_API Z3_fixedpoint_from_string(__in Z3_context c, __in Z3_fixedpoint f, __in Z3_string s)
Parse an SMT-LIB2 string with fixedpoint rules. Add the rules to the current fixedpoint context...
def parse_string(self, s)
Definition: z3py.py:6253
def pop (   self)
restore to previously created backtracking point

Definition at line 6206 of file z3py.py.

6206  def pop(self):
6207  """restore to previously created backtracking point"""
6208  Z3_fixedpoint_pop(self.ctx.ref(), self.fixedpoint)
6209 
void Z3_API Z3_fixedpoint_pop(Z3_context c, Z3_fixedpoint d)
Backtrack one backtracking point.
def pop(self)
Definition: z3py.py:6206
def push (   self)
create a backtracking point for added rules, facts and assertions

Definition at line 6202 of file z3py.py.

6202  def push(self):
6203  """create a backtracking point for added rules, facts and assertions"""
6204  Z3_fixedpoint_push(self.ctx.ref(), self.fixedpoint)
6205 
def push(self)
Definition: z3py.py:6202
void Z3_API Z3_fixedpoint_push(Z3_context c, Z3_fixedpoint d)
Create a backtracking point.
def 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 6180 of file z3py.py.

6180  def query(self, *query):
6181  """Query the fixedpoint engine whether formula is derivable.
6182  You can also pass an tuple or list of recursive predicates.
6183  """
6184  query = _get_args(query)
6185  sz = len(query)
6186  if sz >= 1 and isinstance(query[0], FuncDecl):
6187  _decls = (FuncDecl * sz)()
6188  i = 0
6189  for q in query:
6190  _decls[i] = q.ast
6191  i = i + 1
6192  r = Z3_fixedpoint_query_relations(self.ctx.ref(), self.fixedpoint, sz, _decls)
6193  else:
6194  if sz == 1:
6195  query = query[0]
6196  else:
6197  query = And(query)
6198  query = self.abstract(query, False)
6199  r = Z3_fixedpoint_query(self.ctx.ref(), self.fixedpoint, query.as_ast())
6200  return CheckSatResult(r)
6201 
def And(args)
Definition: z3py.py:1468
Z3_lbool Z3_API Z3_fixedpoint_query(__in Z3_context c, __in Z3_fixedpoint d, __in Z3_ast query)
Pose a query against the asserted rules.
Z3_lbool Z3_API Z3_fixedpoint_query_relations(__in Z3_context c, __in Z3_fixedpoint d, __in unsigned num_relations, __in_ecount(num_relations) Z3_func_decl const relations[])
Pose multiple queries against the asserted rules.
def abstract
Definition: z3py.py:6305
def query(self, query)
Definition: z3py.py:6180
def reason_unknown (   self)
Return a string describing why the last `query()` returned `unknown`.

Definition at line 6291 of file z3py.py.

6291  def reason_unknown(self):
6292  """Return a string describing why the last `query()` returned `unknown`.
6293  """
6294  return Z3_fixedpoint_get_reason_unknown(self.ctx.ref(), self.fixedpoint)
6295 
Z3_string Z3_API Z3_fixedpoint_get_reason_unknown(__in Z3_context c, __in Z3_fixedpoint d)
Retrieve a string that describes the last status returned by Z3_fixedpoint_query. ...
def reason_unknown(self)
Definition: z3py.py:6291
def register_relation (   self,
  relations 
)
Register relation as recursive

Definition at line 6237 of file z3py.py.

6237  def register_relation(self, *relations):
6238  """Register relation as recursive"""
6239  relations = _get_args(relations)
6240  for f in relations:
6241  Z3_fixedpoint_register_relation(self.ctx.ref(), self.fixedpoint, f.ast)
6242 
def register_relation(self, relations)
Definition: z3py.py:6237
void Z3_API Z3_fixedpoint_register_relation(__in Z3_context c, __in Z3_fixedpoint d, __in Z3_func_decl f)
Register relation as Fixedpoint defined. Fixedpoint defined relations have least-fixedpoint semantics...
def rule (   self,
  head,
  body = None,
  name = None 
)
Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule.

Definition at line 6172 of file z3py.py.

6172  def rule(self, head, body = None, name = None):
6173  """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
6174  self.add_rule(head, body, name)
6175 
def add_rule
Definition: z3py.py:6149
def set (   self,
  args,
  keys 
)
Set a configuration option. The method `help()` return a string containing all available options.        

Definition at line 6109 of file z3py.py.

6109  def set(self, *args, **keys):
6110  """Set a configuration option. The method `help()` return a string containing all available options.
6111  """
6112  p = args2params(args, keys, self.ctx)
6113  Z3_fixedpoint_set_params(self.ctx.ref(), self.fixedpoint, p.params)
6114 
def args2params
Definition: z3py.py:4467
def set(self, args, keys)
Definition: z3py.py:6109
void Z3_API Z3_fixedpoint_set_params(__in Z3_context c, __in Z3_fixedpoint f, __in Z3_params p)
Set parameters on fixedpoint context.
def set_predicate_representation (   self,
  f,
  representations 
)
Control how relation is represented

Definition at line 6243 of file z3py.py.

6243  def set_predicate_representation(self, f, *representations):
6244  """Control how relation is represented"""
6245  representations = _get_args(representations)
6246  representations = [to_symbol(s) for s in representations]
6247  sz = len(representations)
6248  args = (Symbol * sz)()
6249  for i in range(sz):
6250  args[i] = representations[i]
6251  Z3_fixedpoint_set_predicate_representation(self.ctx.ref(), self.fixedpoint, f.ast, sz, args)
6252 
def set_predicate_representation(self, f, representations)
Definition: z3py.py:6243
void Z3_API Z3_fixedpoint_set_predicate_representation(__in Z3_context c, __in Z3_fixedpoint d, __in Z3_func_decl f, __in unsigned num_relations, __in_ecount(num_relations) Z3_symbol const relation_kinds[])
Configure the predicate representation.
def to_symbol
Definition: z3py.py:94
def 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 6273 of file z3py.py.

Referenced by Fixedpoint.__repr__().

6273  def sexpr(self):
6274  """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
6275  """
6276  return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, 0, (Ast * 0)())
6277 
Z3_string Z3_API Z3_fixedpoint_to_string(__in Z3_context c, __in Z3_fixedpoint f, __in unsigned num_queries, __in_ecount(num_queries) Z3_ast queries[])
Print the current rules and background axioms as a string.
def sexpr(self)
Definition: z3py.py:6273
def statistics (   self)
Return statistics for the last `query()`.

Definition at line 6286 of file z3py.py.

6286  def statistics(self):
6287  """Return statistics for the last `query()`.
6288  """
6289  return Statistics(Z3_fixedpoint_get_statistics(self.ctx.ref(), self.fixedpoint), self.ctx)
6290 
Statistics.
Definition: z3py.py:5544
Z3_stats Z3_API Z3_fixedpoint_get_statistics(__in Z3_context c, __in Z3_fixedpoint d)
Retrieve statistics information from the last call to Z3_fixedpoint_query.
def statistics(self)
Definition: z3py.py:6286
def 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 6278 of file z3py.py.

6278  def to_string(self, queries):
6279  """Return a formatted string (in Lisp-like format) with all added constraints.
6280  We say the string is in s-expression format.
6281  Include also queries.
6282  """
6283  args, len = _to_ast_array(queries)
6284  return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, len, args)
6285 
Z3_string Z3_API Z3_fixedpoint_to_string(__in Z3_context c, __in Z3_fixedpoint f, __in unsigned num_queries, __in_ecount(num_queries) Z3_ast queries[])
Print the current rules and background axioms as a string.
def to_string(self, queries)
Definition: z3py.py:6278
def update_rule (   self,
  head,
  body,
  name 
)
update rule

Definition at line 6210 of file z3py.py.

6210  def update_rule(self, head, body, name):
6211  """update rule"""
6212  if name == None:
6213  name = ""
6214  name = to_symbol(name, self.ctx)
6215  body = _get_args(body)
6216  f = self.abstract(Implies(And(body),head))
6217  Z3_fixedpoint_update_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
6218 
def update_rule(self, head, body, name)
Definition: z3py.py:6210
void Z3_API Z3_fixedpoint_update_rule(__in Z3_context c, __in Z3_fixedpoint d, __in Z3_ast a, __in Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created. ...
def Implies
Definition: z3py.py:1413
def And(args)
Definition: z3py.py:1468
def abstract
Definition: z3py.py:6305
def to_symbol
Definition: z3py.py:94

Field Documentation

ctx
fixedpoint
vars

Definition at line 6103 of file z3py.py.

Referenced by Fixedpoint.abstract(), and Fixedpoint.declare_var().