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 2437 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.

Definition at line 2475 of file z3py.py.

2475 def cast(self, val):
2476 """Try to cast `val` as an Integer or Real.
2477
2478 >>> IntSort().cast(10)
2479 10
2480 >>> is_int(IntSort().cast(10))
2481 True
2482 >>> is_int(10)
2483 False
2484 >>> RealSort().cast(10)
2485 10
2486 >>> is_real(RealSort().cast(10))
2487 True
2488 """
2489 if is_expr(val):
2490 if z3_debug():
2491 _z3_assert(self.ctx == val.ctx, "Context mismatch")
2492 val_s = val.sort()
2493 if self.eq(val_s):
2494 return val
2495 if val_s.is_int() and self.is_real():
2496 return ToReal(val)
2497 if val_s.is_bool() and self.is_int():
2498 return If(val, 1, 0)
2499 if val_s.is_bool() and self.is_real():
2500 return ToReal(If(val, 1, 0))
2501 if z3_debug():
2502 _z3_assert(False, "Z3 Integer/Real expression expected")
2503 else:
2504 if self.is_int():
2505 return IntVal(val, self.ctx)
2506 if self.is_real():
2507 return RealVal(val, self.ctx)
2508 if z3_debug():
2509 msg = "int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2510 _z3_assert(False, msg % self)
2511
2512

◆ is_bool()

is_bool ( self)

Definition at line 2468 of file z3py.py.

2468 def is_bool(self):
2469 return False
2470

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

2454 def is_int(self):
2455 """Return `True` if `self` is of the sort Integer.
2456
2457 >>> x = Int('x')
2458 >>> x.is_int()
2459 True
2460 >>> (x + 1).is_int()
2461 True
2462 >>> x = Real('x')
2463 >>> x.is_int()
2464 False
2465 """
2466 return self.kind() == Z3_INT_SORT
2467

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

2440 def is_real(self):
2441 """Return `True` if `self` is of the sort Real.
2442
2443 >>> x = Real('x')
2444 >>> x.is_real()
2445 True
2446 >>> (x + 1).is_real()
2447 True
2448 >>> x = Int('x')
2449 >>> x.is_real()
2450 False
2451 """
2452 return self.kind() == Z3_REAL_SORT
2453

◆ subsort()

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

Reimplemented from SortRef.

Definition at line 2471 of file z3py.py.

2471 def subsort(self, other):
2472 """Return `True` if `self` is a subsort of `other`."""
2473 return self.is_int() and is_arith_sort(other) and other.is_real()
2474