Z3
Loading...
Searching...
No Matches
ArithSortRef Class Reference

Arithmetic. More...

Inheritance diagram for ArithSortRef:

Public Member Functions

 is_real (self)
 is_int (self)
 is_bool (self)
 subsort (self, other)
 cast (self, val)
Public Member Functions inherited from SortRef
 as_ast (self)
 get_id (self)
 kind (self)
 name (self)
 __eq__ (self, other)
 __ne__ (self, other)
 __gt__ (self, other)
 __hash__ (self)
Public Member Functions inherited from AstRef
 __init__ (self, ast, ctx=None)
 __del__ (self)
 __deepcopy__ (self, memo={})
 __str__ (self)
 __repr__ (self)
 __eq__ (self, other)
 __hash__ (self)
 __nonzero__ (self)
 __bool__ (self)
 sexpr (self)
 ctx_ref (self)
 eq (self, other)
 translate (self, target)
 __copy__ (self)
 hash (self)
 py_value (self)
Public Member Functions inherited from Z3PPObject
 use_pp (self)

Additional Inherited Members

Data Fields inherited from AstRef
 ast = ast
 ctx = _get_ctx(ctx)
Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)

Detailed Description

Arithmetic.

Real and Integer sorts.

Definition at line 2459 of file z3py.py.

Member Function Documentation

◆ cast()

cast ( self,
val )
Try to cast `val` as an Integer or Real.

>>> IntSort().cast(10)
10
>>> is_int(IntSort().cast(10))
True
>>> is_int(10)
False
>>> RealSort().cast(10)
10
>>> is_real(RealSort().cast(10))
True

Reimplemented from SortRef.

Reimplemented in ComplexSortRef.

Definition at line 2497 of file z3py.py.

2497 def cast(self, val):
2498 """Try to cast `val` as an Integer or Real.
2499
2500 >>> IntSort().cast(10)
2501 10
2502 >>> is_int(IntSort().cast(10))
2503 True
2504 >>> is_int(10)
2505 False
2506 >>> RealSort().cast(10)
2507 10
2508 >>> is_real(RealSort().cast(10))
2509 True
2510 """
2511 if is_expr(val):
2512 if z3_debug():
2513 _z3_assert(self.ctx == val.ctx, "Context mismatch")
2514 val_s = val.sort()
2515 if self.eq(val_s):
2516 return val
2517 if val_s.is_int() and self.is_real():
2518 return ToReal(val)
2519 if val_s.is_bool() and self.is_int():
2520 return If(val, 1, 0)
2521 if val_s.is_bool() and self.is_real():
2522 return ToReal(If(val, 1, 0))
2523 if z3_debug():
2524 _z3_assert(False, "Z3 Integer/Real expression expected")
2525 else:
2526 if self.is_int():
2527 return IntVal(val, self.ctx)
2528 if self.is_real():
2529 return RealVal(val, self.ctx)
2530 if z3_debug():
2531 msg = "int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2532 _z3_assert(False, msg % self)
2533
2534

◆ is_bool()

is_bool ( self)

Definition at line 2490 of file z3py.py.

2490 def is_bool(self):
2491 return False
2492

◆ is_int()

is_int ( self)
Return `True` if `self` is of the sort Integer.

>>> x = Int('x')
>>> x.is_int()
True
>>> (x + 1).is_int()
True
>>> x = Real('x')
>>> x.is_int()
False

Definition at line 2476 of file z3py.py.

2476 def is_int(self):
2477 """Return `True` if `self` is of the sort Integer.
2478
2479 >>> x = Int('x')
2480 >>> x.is_int()
2481 True
2482 >>> (x + 1).is_int()
2483 True
2484 >>> x = Real('x')
2485 >>> x.is_int()
2486 False
2487 """
2488 return self.kind() == Z3_INT_SORT
2489

Referenced by IntNumRef.as_long(), and subsort().

◆ is_real()

is_real ( self)
Return `True` if `self` is of the sort Real.

>>> x = Real('x')
>>> x.is_real()
True
>>> (x + 1).is_real()
True
>>> x = Int('x')
>>> x.is_real()
False

Definition at line 2462 of file z3py.py.

2462 def is_real(self):
2463 """Return `True` if `self` is of the sort Real.
2464
2465 >>> x = Real('x')
2466 >>> x.is_real()
2467 True
2468 >>> (x + 1).is_real()
2469 True
2470 >>> x = Int('x')
2471 >>> x.is_real()
2472 False
2473 """
2474 return self.kind() == Z3_REAL_SORT
2475

◆ subsort()

subsort ( self,
other )
Return `True` if `self` is a subsort of `other`.

Reimplemented from SortRef.

Reimplemented in ComplexSortRef.

Definition at line 2493 of file z3py.py.

2493 def subsort(self, other):
2494 """Return `True` if `self` is a subsort of `other`."""
2495 return is_complex_sort(other) or (self.is_int() and is_arith_sort(other) and other.is_real())
2496