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)
 
 __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 2369 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 2407 of file z3py.py.

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

◆ is_bool()

is_bool ( self)

Definition at line 2400 of file z3py.py.

2400 def is_bool(self):
2401 return False
2402

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

2386 def is_int(self):
2387 """Return `True` if `self` is of the sort Integer.
2388
2389 >>> x = Int('x')
2390 >>> x.is_int()
2391 True
2392 >>> (x + 1).is_int()
2393 True
2394 >>> x = Real('x')
2395 >>> x.is_int()
2396 False
2397 """
2398 return self.kind() == Z3_INT_SORT
2399

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

2372 def is_real(self):
2373 """Return `True` if `self` is of the sort Real.
2374
2375 >>> x = Real('x')
2376 >>> x.is_real()
2377 True
2378 >>> (x + 1).is_real()
2379 True
2380 >>> x = Int('x')
2381 >>> x.is_real()
2382 False
2383 """
2384 return self.kind() == Z3_REAL_SORT
2385

◆ subsort()

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

Reimplemented from SortRef.

Definition at line 2403 of file z3py.py.

2403 def subsort(self, other):
2404 """Return `True` if `self` is a subsort of `other`."""
2405 return self.is_int() and is_arith_sort(other) and other.is_real()
2406