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

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

◆ is_bool()

is_bool ( self)

Definition at line 2391 of file z3py.py.

2391 def is_bool(self):
2392 return False
2393

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

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

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

2363 def is_real(self):
2364 """Return `True` if `self` is of the sort Real.
2365
2366 >>> x = Real('x')
2367 >>> x.is_real()
2368 True
2369 >>> (x + 1).is_real()
2370 True
2371 >>> x = Int('x')
2372 >>> x.is_real()
2373 False
2374 """
2375 return self.kind() == Z3_REAL_SORT
2376

◆ subsort()

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

Reimplemented from SortRef.

Definition at line 2394 of file z3py.py.

2394 def subsort(self, other):
2395 """Return `True` if `self` is a subsort of `other`."""
2396 return self.is_int() and is_arith_sort(other) and other.is_real()
2397