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

2413 def cast(self, val):
2414 """Try to cast `val` as an Integer or Real.
2415
2416 >>> IntSort().cast(10)
2417 10
2418 >>> is_int(IntSort().cast(10))
2419 True
2420 >>> is_int(10)
2421 False
2422 >>> RealSort().cast(10)
2423 10
2424 >>> is_real(RealSort().cast(10))
2425 True
2426 """
2427 if is_expr(val):
2428 if z3_debug():
2429 _z3_assert(self.ctx == val.ctx, "Context mismatch")
2430 val_s = val.sort()
2431 if self.eq(val_s):
2432 return val
2433 if val_s.is_int() and self.is_real():
2434 return ToReal(val)
2435 if val_s.is_bool() and self.is_int():
2436 return If(val, 1, 0)
2437 if val_s.is_bool() and self.is_real():
2438 return ToReal(If(val, 1, 0))
2439 if z3_debug():
2440 _z3_assert(False, "Z3 Integer/Real expression expected")
2441 else:
2442 if self.is_int():
2443 return IntVal(val, self.ctx)
2444 if self.is_real():
2445 return RealVal(val, self.ctx)
2446 if z3_debug():
2447 msg = "int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2448 _z3_assert(False, msg % self)
2449
2450

◆ is_bool()

is_bool ( self)

Definition at line 2406 of file z3py.py.

2406 def is_bool(self):
2407 return False
2408

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

2392 def is_int(self):
2393 """Return `True` if `self` is of the sort Integer.
2394
2395 >>> x = Int('x')
2396 >>> x.is_int()
2397 True
2398 >>> (x + 1).is_int()
2399 True
2400 >>> x = Real('x')
2401 >>> x.is_int()
2402 False
2403 """
2404 return self.kind() == Z3_INT_SORT
2405

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

2378 def is_real(self):
2379 """Return `True` if `self` is of the sort Real.
2380
2381 >>> x = Real('x')
2382 >>> x.is_real()
2383 True
2384 >>> (x + 1).is_real()
2385 True
2386 >>> x = Int('x')
2387 >>> x.is_real()
2388 False
2389 """
2390 return self.kind() == Z3_REAL_SORT
2391

◆ subsort()

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

Reimplemented from SortRef.

Definition at line 2409 of file z3py.py.

2409 def subsort(self, other):
2410 """Return `True` if `self` is a subsort of `other`."""
2411 return self.is_int() and is_arith_sort(other) and other.is_real()
2412