Inheritance diagram for ModelRef:Public Member Functions | |
| def | __init__ |
| def | __del__ |
| def | __repr__ |
| def | sexpr |
| def | eval |
| def | evaluate |
| def | __len__ |
| def | get_interp |
| def | num_sorts |
| def | get_sort |
| def | sorts |
| def | get_universe |
| def | __getitem__ |
| def | decls |
Data Fields | |
| model | |
| ctx | |
Model/Solution of a satisfiability problem (aka system of constraints).
| def __init__ | ( | self, | |
| m, | |||
| ctx | |||
| ) |
| def __del__ | ( | self | ) |
| def __getitem__ | ( | self, | |
| idx | |||
| ) |
If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned. If `idx` is a declaration, then the actual interpreation is returned.
The elements can be retrieved using position or the actual declaration.
>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2, f(x) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> len(m)
2
>>> m[0]
x
>>> m[1]
f
>>> m[x]
1
>>> m[f]
[1 -> 0, else -> 0]
>>> for d in m: print("%s -> %s" % (d, m[d]))
x -> 1
f -> [1 -> 0, else -> 0]
Definition at line 5526 of file z3py.py.
05526 05527 def __getitem__(self, idx): 05528 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned. If `idx` is a declaration, then the actual interpreation is returned. 05529 05530 The elements can be retrieved using position or the actual declaration. 05531 05532 >>> f = Function('f', IntSort(), IntSort()) 05533 >>> x = Int('x') 05534 >>> s = Solver() 05535 >>> s.add(x > 0, x < 2, f(x) == 0) 05536 >>> s.check() 05537 sat 05538 >>> m = s.model() 05539 >>> len(m) 05540 2 05541 >>> m[0] 05542 x 05543 >>> m[1] 05544 f 05545 >>> m[x] 05546 1 05547 >>> m[f] 05548 [1 -> 0, else -> 0] 05549 >>> for d in m: print("%s -> %s" % (d, m[d])) 05550 x -> 1 05551 f -> [1 -> 0, else -> 0] 05552 """ 05553 if isinstance(idx, int): 05554 if idx >= len(self): 05555 raise IndexError 05556 num_consts = Z3_model_get_num_consts(self.ctx.ref(), self.model) 05557 if (idx < num_consts): 05558 return FuncDeclRef(Z3_model_get_const_decl(self.ctx.ref(), self.model, idx), self.ctx) 05559 else: 05560 return FuncDeclRef(Z3_model_get_func_decl(self.ctx.ref(), self.model, idx - num_consts), self.ctx) 05561 if isinstance(idx, FuncDeclRef): 05562 return self.get_interp(idx) 05563 if is_const(idx): 05564 return self.get_interp(idx.decl()) 05565 if isinstance(idx, SortRef): 05566 return self.get_universe(idx) 05567 if __debug__: 05568 _z3_assert(False, "Integer, Z3 declaration, or Z3 constant expected") 05569 return None
| def __len__ | ( | self | ) |
Return the number of constant and function declarations in the model `self`.
>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, f(x) != x)
>>> s.check()
sat
>>> m = s.model()
>>> len(m)
2
Definition at line 5405 of file z3py.py.
05405 05406 def __len__(self): 05407 """Return the number of constant and function declarations in the model `self`. 05408 05409 >>> f = Function('f', IntSort(), IntSort()) 05410 >>> x = Int('x') 05411 >>> s = Solver() 05412 >>> s.add(x > 0, f(x) != x) 05413 >>> s.check() 05414 sat 05415 >>> m = s.model() 05416 >>> len(m) 05417 2 05418 """ 05419 return int(Z3_model_get_num_consts(self.ctx.ref(), self.model)) + int(Z3_model_get_num_funcs(self.ctx.ref(), self.model))
| def __repr__ | ( | self | ) |
| def decls | ( | self | ) |
Return a list with all symbols that have an interpreation in the model `self`.
>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2, f(x) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> m.decls()
[x, f]
Definition at line 5570 of file z3py.py.
05570 05571 def decls(self): 05572 """Return a list with all symbols that have an interpreation in the model `self`. 05573 >>> f = Function('f', IntSort(), IntSort()) 05574 >>> x = Int('x') 05575 >>> s = Solver() 05576 >>> s.add(x > 0, x < 2, f(x) == 0) 05577 >>> s.check() 05578 sat 05579 >>> m = s.model() 05580 >>> m.decls() 05581 [x, f] 05582 """ 05583 r = [] 05584 for i in range(Z3_model_get_num_consts(self.ctx.ref(), self.model)): 05585 r.append(FuncDeclRef(Z3_model_get_const_decl(self.ctx.ref(), self.model, i), self.ctx)) 05586 for i in range(Z3_model_get_num_funcs(self.ctx.ref(), self.model)): 05587 r.append(FuncDeclRef(Z3_model_get_func_decl(self.ctx.ref(), self.model, i), self.ctx)) 05588 return r
| def eval | ( | self, | |
| t, | |||
model_completion = False |
|||
| ) |
Evaluate the expression `t` in the model `self`. If `model_completion` is enabled, then a default interpretation is automatically added for symbols that do not have an interpretation in the model `self`.
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2)
>>> s.check()
sat
>>> m = s.model()
>>> m.eval(x + 1)
2
>>> m.eval(x == 1)
True
>>> y = Int('y')
>>> m.eval(y + x)
1 + y
>>> m.eval(y)
y
>>> m.eval(y, model_completion=True)
0
>>> # Now, m contains an interpretation for y
>>> m.eval(y + x)
1
Definition at line 5350 of file z3py.py.
05350 05351 def eval(self, t, model_completion=False): 05352 """Evaluate the expression `t` in the model `self`. If `model_completion` is enabled, then a default interpretation is automatically added for symbols that do not have an interpretation in the model `self`. 05353 05354 >>> x = Int('x') 05355 >>> s = Solver() 05356 >>> s.add(x > 0, x < 2) 05357 >>> s.check() 05358 sat 05359 >>> m = s.model() 05360 >>> m.eval(x + 1) 05361 2 05362 >>> m.eval(x == 1) 05363 True 05364 >>> y = Int('y') 05365 >>> m.eval(y + x) 05366 1 + y 05367 >>> m.eval(y) 05368 y 05369 >>> m.eval(y, model_completion=True) 05370 0 05371 >>> # Now, m contains an interpretation for y 05372 >>> m.eval(y + x) 05373 1 05374 """ 05375 r = (Ast * 1)() 05376 if Z3_model_eval(self.ctx.ref(), self.model, t.as_ast(), model_completion, r): 05377 return _to_expr_ref(r[0], self.ctx) 05378 raise Z3Exception("failed to evaluate expression in the model")
| def evaluate | ( | self, | |
| t, | |||
model_completion = False |
|||
| ) |
Alias for `eval`.
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2)
>>> s.check()
sat
>>> m = s.model()
>>> m.evaluate(x + 1)
2
>>> m.evaluate(x == 1)
True
>>> y = Int('y')
>>> m.evaluate(y + x)
1 + y
>>> m.evaluate(y)
y
>>> m.evaluate(y, model_completion=True)
0
>>> # Now, m contains an interpretation for y
>>> m.evaluate(y + x)
1
Definition at line 5379 of file z3py.py.
05379 05380 def evaluate(self, t, model_completion=False): 05381 """Alias for `eval`. 05382 05383 >>> x = Int('x') 05384 >>> s = Solver() 05385 >>> s.add(x > 0, x < 2) 05386 >>> s.check() 05387 sat 05388 >>> m = s.model() 05389 >>> m.evaluate(x + 1) 05390 2 05391 >>> m.evaluate(x == 1) 05392 True 05393 >>> y = Int('y') 05394 >>> m.evaluate(y + x) 05395 1 + y 05396 >>> m.evaluate(y) 05397 y 05398 >>> m.evaluate(y, model_completion=True) 05399 0 05400 >>> # Now, m contains an interpretation for y 05401 >>> m.evaluate(y + x) 05402 1 05403 """ 05404 return self.eval(t, model_completion)
| def get_interp | ( | self, | |
| decl | |||
| ) |
Return the interpretation for a given declaration or constant.
>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> s = Solver()
>>> s.add(x > 0, x < 2, f(x) == 0)
>>> s.check()
sat
>>> m = s.model()
>>> m[x]
1
>>> m[f]
[1 -> 0, else -> 0]
Definition at line 5420 of file z3py.py.
Referenced by ModelRef.__getitem__().
05420 05421 def get_interp(self, decl): 05422 """Return the interpretation for a given declaration or constant. 05423 05424 >>> f = Function('f', IntSort(), IntSort()) 05425 >>> x = Int('x') 05426 >>> s = Solver() 05427 >>> s.add(x > 0, x < 2, f(x) == 0) 05428 >>> s.check() 05429 sat 05430 >>> m = s.model() 05431 >>> m[x] 05432 1 05433 >>> m[f] 05434 [1 -> 0, else -> 0] 05435 """ 05436 if __debug__: 05437 _z3_assert(isinstance(decl, FuncDeclRef) or is_const(decl), "Z3 declaration expected") 05438 if is_const(decl): 05439 decl = decl.decl() 05440 try: 05441 if decl.arity() == 0: 05442 r = _to_expr_ref(Z3_model_get_const_interp(self.ctx.ref(), self.model, decl.ast), self.ctx) 05443 if is_as_array(r): 05444 return self.get_interp(get_as_array_func(r)) 05445 else: 05446 return r 05447 else: 05448 return FuncInterp(Z3_model_get_func_interp(self.ctx.ref(), self.model, decl.ast), self.ctx) 05449 except Z3Exception: 05450 return None
| def get_sort | ( | self, | |
| idx | |||
| ) |
Return the unintepreted sort at position `idx` < self.num_sorts().
>>> A = DeclareSort('A')
>>> B = DeclareSort('B')
>>> a1, a2 = Consts('a1 a2', A)
>>> b1, b2 = Consts('b1 b2', B)
>>> s = Solver()
>>> s.add(a1 != a2, b1 != b2)
>>> s.check()
sat
>>> m = s.model()
>>> m.num_sorts()
2
>>> m.get_sort(0)
A
>>> m.get_sort(1)
B
Definition at line 5466 of file z3py.py.
05466 05467 def get_sort(self, idx): 05468 """Return the unintepreted sort at position `idx` < self.num_sorts(). 05469 05470 >>> A = DeclareSort('A') 05471 >>> B = DeclareSort('B') 05472 >>> a1, a2 = Consts('a1 a2', A) 05473 >>> b1, b2 = Consts('b1 b2', B) 05474 >>> s = Solver() 05475 >>> s.add(a1 != a2, b1 != b2) 05476 >>> s.check() 05477 sat 05478 >>> m = s.model() 05479 >>> m.num_sorts() 05480 2 05481 >>> m.get_sort(0) 05482 A 05483 >>> m.get_sort(1) 05484 B 05485 """ 05486 if idx >= self.num_sorts(): 05487 raise IndexError 05488 return _to_sort_ref(Z3_model_get_sort(self.ctx.ref(), self.model, idx), self.ctx)
| def get_universe | ( | self, | |
| s | |||
| ) |
Return the intepretation for the uninterpreted sort `s` in the model `self`.
>>> A = DeclareSort('A')
>>> a, b = Consts('a b', A)
>>> s = Solver()
>>> s.add(a != b)
>>> s.check()
sat
>>> m = s.model()
>>> m.get_universe(A)
[A!val!0, A!val!1]
Definition at line 5506 of file z3py.py.
Referenced by ModelRef.__getitem__().
05506 05507 def get_universe(self, s): 05508 """Return the intepretation for the uninterpreted sort `s` in the model `self`. 05509 05510 >>> A = DeclareSort('A') 05511 >>> a, b = Consts('a b', A) 05512 >>> s = Solver() 05513 >>> s.add(a != b) 05514 >>> s.check() 05515 sat 05516 >>> m = s.model() 05517 >>> m.get_universe(A) 05518 [A!val!0, A!val!1] 05519 """ 05520 if __debug__: 05521 _z3_assert(isinstance(s, SortRef), "Z3 sort expected") 05522 try: 05523 return AstVector(Z3_model_get_sort_universe(self.ctx.ref(), self.model, s.ast), self.ctx) 05524 except Z3Exception: 05525 return None
| def num_sorts | ( | self | ) |
Return the number of unintepreted sorts that contain an interpretation in the model `self`.
>>> A = DeclareSort('A')
>>> a, b = Consts('a b', A)
>>> s = Solver()
>>> s.add(a != b)
>>> s.check()
sat
>>> m = s.model()
>>> m.num_sorts()
1
Definition at line 5451 of file z3py.py.
Referenced by ModelRef.get_sort().
05451 05452 def num_sorts(self): 05453 """Return the number of unintepreted sorts that contain an interpretation in the model `self`. 05454 05455 >>> A = DeclareSort('A') 05456 >>> a, b = Consts('a b', A) 05457 >>> s = Solver() 05458 >>> s.add(a != b) 05459 >>> s.check() 05460 sat 05461 >>> m = s.model() 05462 >>> m.num_sorts() 05463 1 05464 """ 05465 return int(Z3_model_get_num_sorts(self.ctx.ref(), self.model))
| def sexpr | ( | self | ) |
Return a textual representation of the s-expression representing the model.
Definition at line 5346 of file z3py.py.
Referenced by Fixedpoint.__repr__(), and Optimize.__repr__().
05346 05347 def sexpr(self): 05348 """Return a textual representation of the s-expression representing the model.""" 05349 return Z3_model_to_string(self.ctx.ref(), self.model)
| def sorts | ( | self | ) |
Return all uninterpreted sorts that have an interpretation in the model `self`.
>>> A = DeclareSort('A')
>>> B = DeclareSort('B')
>>> a1, a2 = Consts('a1 a2', A)
>>> b1, b2 = Consts('b1 b2', B)
>>> s = Solver()
>>> s.add(a1 != a2, b1 != b2)
>>> s.check()
sat
>>> m = s.model()
>>> m.sorts()
[A, B]
Definition at line 5489 of file z3py.py.
05489 05490 def sorts(self): 05491 """Return all uninterpreted sorts that have an interpretation in the model `self`. 05492 05493 >>> A = DeclareSort('A') 05494 >>> B = DeclareSort('B') 05495 >>> a1, a2 = Consts('a1 a2', A) 05496 >>> b1, b2 = Consts('b1 b2', B) 05497 >>> s = Solver() 05498 >>> s.add(a1 != a2, b1 != b2) 05499 >>> s.check() 05500 sat 05501 >>> m = s.model() 05502 >>> m.sorts() 05503 [A, B] 05504 """ 05505 return [ self.get_sort(i) for i in range(self.num_sorts()) ]
Definition at line 5334 of file z3py.py.
Referenced by ArithRef.__add__(), BitVecRef.__add__(), BitVecRef.__and__(), FuncDeclRef.__call__(), ArithRef.__div__(), BitVecRef.__div__(), ExprRef.__eq__(), Probe.__eq__(), ArithRef.__ge__(), BitVecRef.__ge__(), Probe.__ge__(), ArrayRef.__getitem__(), ModelRef.__getitem__(), ApplyResult.__getitem__(), ArithRef.__gt__(), BitVecRef.__gt__(), Probe.__gt__(), BitVecRef.__invert__(), ArithRef.__le__(), BitVecRef.__le__(), Probe.__le__(), BitVecRef.__lshift__(), ArithRef.__lt__(), BitVecRef.__lt__(), Probe.__lt__(), ArithRef.__mod__(), BitVecRef.__mod__(), ArithRef.__mul__(), BitVecRef.__mul__(), ExprRef.__ne__(), Probe.__ne__(), ArithRef.__neg__(), BitVecRef.__neg__(), BitVecRef.__or__(), ArithRef.__pow__(), ArithRef.__radd__(), BitVecRef.__radd__(), BitVecRef.__rand__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), BitVecRef.__rlshift__(), ArithRef.__rmod__(), BitVecRef.__rmod__(), ArithRef.__rmul__(), BitVecRef.__rmul__(), BitVecRef.__ror__(), ArithRef.__rpow__(), BitVecRef.__rrshift__(), BitVecRef.__rshift__(), ArithRef.__rsub__(), BitVecRef.__rsub__(), BitVecRef.__rxor__(), ArithRef.__sub__(), BitVecRef.__sub__(), BitVecRef.__xor__(), DatatypeSortRef.accessor(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), AlgebraicNumRef.approx(), ExprRef.arg(), ApplyResult.as_expr(), Fixedpoint.assert_exprs(), QuantifierRef.body(), BoolSortRef.cast(), DatatypeSortRef.constructor(), ApplyResult.convert_model(), ExprRef.decl(), ModelRef.decls(), RatNumRef.denominator(), FuncDeclRef.domain(), ArraySortRef.domain(), ModelRef.eval(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), ModelRef.get_interp(), Fixedpoint.get_rules(), ModelRef.get_sort(), ModelRef.get_universe(), SortRef.kind(), ArrayRef.mk_default(), Optimize.model(), SortRef.name(), FuncDeclRef.name(), QuantifierRef.no_pattern(), RatNumRef.numerator(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), QuantifierRef.pattern(), Fixedpoint.query(), FuncDeclRef.range(), ArraySortRef.range(), DatatypeSortRef.recognizer(), Fixedpoint.set(), Optimize.set(), Tactic.solver(), ExprRef.sort(), BoolRef.sort(), QuantifierRef.sort(), ArithRef.sort(), BitVecRef.sort(), ArrayRef.sort(), DatatypeRef.sort(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), Fixedpoint.update_rule(), QuantifierRef.var_name(), and QuantifierRef.var_sort().
Definition at line 5334 of file z3py.py.
Referenced by ModelRef::__del__(), ModelRef::__getitem__(), ModelRef::__len__(), ModelRef::decls(), ModelRef::eval(), ModelRef::get_interp(), ModelRef::get_sort(), ModelRef::get_universe(), ModelRef::num_sorts(), and ModelRef::sexpr().
1.7.6.1