Z3 |

Public Member Functions
ArithRef Class Reference
Inheritance diagram for ArithRef:

## Public Member Functions
def | sort (self)
def | is_int (self)
def | is_real (self)
def | __add__ (self, other)
def | __radd__ (self, other)
def | __mul__ (self, other)
def | __rmul__ (self, other)
def | __sub__ (self, other)
def | __rsub__ (self, other)
def | __pow__ (self, other)
def | __rpow__ (self, other)
def | __div__ (self, other)
def | __truediv__ (self, other)
def | __rdiv__ (self, other)
def | __rtruediv__ (self, other)
def | __mod__ (self, other)
def | __rmod__ (self, other)
def | __neg__ (self)
def | __pos__ (self)
def | __le__ (self, other)
def | __lt__ (self, other)
def | __gt__ (self, other)
def | __ge__ (self, other)
Public Member Functions inherited from ExprRef
def | as_ast (self)
def | get_id (self)
def | sort (self)
def | sort_kind (self)
def | __eq__ (self, other)
def | __hash__ (self)
def | __ne__ (self, other)
def | params (self)
def | decl (self)
def | num_args (self)
def | arg (self, idx)
def | children (self)
Public Member Functions inherited from AstRef
def | __init__ (self, ast, ctx=None)
def | __del__ (self)
def | __deepcopy__ (self, memo={})
def | __str__ (self)
def | __repr__ (self)
def | __eq__ (self, other)
def | __hash__ (self)
def | __nonzero__ (self)
def | __bool__ (self)
def | sexpr (self)
def | as_ast (self)
def | get_id (self)
def | ctx_ref (self)
def | eq (self, other)
def | translate (self, target)
def | __copy__ (self)
def | hash (self)
Public Member Functions inherited from Z3PPObject
def | use_pp (self)

## Additional Inherited Members
Data Fields inherited from AstRef
| ast
| ctx

## Detailed Description

    Integer and Real expressions.

Definition at line 2342 of file z3py.py.

## Member Function Documentation

## ◆ __add__()

def __add__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `self + other`.

    >>> x = Int('x')
    >>> y = Int('y')
    >>> x + y
    x + y
    >>> (x + y).sort()
    Int

Definition at line 2380 of file z3py.py.

2380 def __add__(self, other):
2381 """Create the Z3 expression `self + other`.
2382
2383 >>> x = Int('x')
2384 >>> y = Int('y')
2385 >>> x + y
2386 x + y
2387 >>> (x + y).sort()
2388 Int
2389 """
2390 a, b = _coerce_exprs(self, other)
2391 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2392
z3py.Int
def Int(name, ctx=None)
Definition: z3py.py:3210

## ◆ __div__()

def __div__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other/self`.

    >>> x = Int('x')
    >>> y = Int('y')
    >>> x/y
    x/y
    >>> (x/y).sort()
    Int
    >>> (x/y).sexpr()
    '(div x y)'
    >>> x = Real('x')
    >>> y = Real('y')
    >>> x/y
    x/y
    >>> (x/y).sort()
    Real
    >>> (x/y).sexpr()
    '(/ x y)'

Definition at line 2479 of file z3py.py.

2479 def __div__(self, other):
2480 """Create the Z3 expression `other/self`.
2481
2482 >>> x = Int('x')
2483 >>> y = Int('y')
2484 >>> x/y
2485 x/y
2486 >>> (x/y).sort()
2487 Int
2488 >>> (x/y).sexpr()
2489 '(div x y)'
2490 >>> x = Real('x')
2491 >>> y = Real('y')
2492 >>> x/y
2493 x/y
2494 >>> (x/y).sort()
2495 Real
2496 >>> (x/y).sexpr()
2497 '(/ x y)'
2498 """
2499 a, b = _coerce_exprs(self, other)
2500 return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2501
z3py.Real
def Real(name, ctx=None)
Definition: z3py.py:3263
Z3_mk_div
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.

Referenced by ArithRef.__truediv__(), BitVecRef.__truediv__(), and FPRef.__truediv__().

## ◆ __ge__()

def __ge__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other >= self`.

    >>> x, y = Ints('x y')
    >>> x >= y
    x >= y
    >>> y = Real('y')
    >>> x >= y
    ToReal(x) >= y

Definition at line 2613 of file z3py.py.

2613 def __ge__(self, other):
2614 """Create the Z3 expression `other >= self`.
2615
2616 >>> x, y = Ints('x y')
2617 >>> x >= y
2618 x >= y
2619 >>> y = Real('y')
2620 >>> x >= y
2621 ToReal(x) >= y
2622 """
2623 a, b = _coerce_exprs(self, other)
2624 return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2625
2626
z3py.ToReal
def ToReal(a)
Definition: z3py.py:3320
z3py.Ints
def Ints(names, ctx=None)
Definition: z3py.py:3223
Z3_mk_ge
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.

## ◆ __gt__()

def __gt__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other > self`.

    >>> x, y = Ints('x y')
    >>> x > y
    x > y
    >>> y = Real('y')
    >>> x > y
    ToReal(x) > y

Definition at line 2600 of file z3py.py.

2600 def __gt__(self, other):
2601 """Create the Z3 expression `other > self`.
2602
2603 >>> x, y = Ints('x y')
2604 >>> x > y
2605 x > y
2606 >>> y = Real('y')
2607 >>> x > y
2608 ToReal(x) > y
2609 """
2610 a, b = _coerce_exprs(self, other)
2611 return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2612
Z3_mk_gt
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.

## ◆ __le__()

def __le__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other <= self`.

    >>> x, y = Ints('x y')
    >>> x <= y
    x <= y
    >>> y = Real('y')
    >>> x <= y
    ToReal(x) <= y

Definition at line 2574 of file z3py.py.

2574 def __le__(self, other):
2575 """Create the Z3 expression `other <= self`.
2576
2577 >>> x, y = Ints('x y')
2578 >>> x <= y
2579 x <= y
2580 >>> y = Real('y')
2581 >>> x <= y
2582 ToReal(x) <= y
2583 """
2584 a, b = _coerce_exprs(self, other)
2585 return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2586
Z3_mk_le
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.

## ◆ __lt__()

def __lt__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other < self`.

    >>> x, y = Ints('x y')
    >>> x < y
    x < y
    >>> y = Real('y')
    >>> x < y
    ToReal(x) < y

Definition at line 2587 of file z3py.py.

2587 def __lt__(self, other):
2588 """Create the Z3 expression `other < self`.
2589
2590 >>> x, y = Ints('x y')
2591 >>> x < y
2592 x < y
2593 >>> y = Real('y')
2594 >>> x < y
2595 ToReal(x) < y
2596 """
2597 a, b = _coerce_exprs(self, other)
2598 return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2599
Z3_mk_lt
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.

## ◆ __mod__()

def __mod__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other%self`.

    >>> x = Int('x')
    >>> y = Int('y')
    >>> x % y
    x%y
    >>> simplify(IntVal(10) % IntVal(3))
    1

Definition at line 2527 of file z3py.py.

2527 def __mod__(self, other):
2528 """Create the Z3 expression `other%self`.
2529
2530 >>> x = Int('x')
2531 >>> y = Int('y')
2532 >>> x % y
2533 x%y
2534 >>> simplify(IntVal(10) % IntVal(3))
2535 1
2536 """
2537 a, b = _coerce_exprs(self, other)
2538 if z3_debug():
2539 _z3_assert(a.is_int(), "Z3 integer expression expected")
2540 return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2541
z3py.z3_debug
def z3_debug()
Definition: z3py.py:64
z3py.simplify
def simplify(a, *arguments, **keywords)
Utils.
Definition: z3py.py:8645
z3py.IntVal
def IntVal(val, ctx=None)
Definition: z3py.py:3150
Z3_mk_mod
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.

## ◆ __mul__()

def __mul__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `self * other`.

    >>> x = Real('x')
    >>> y = Real('y')
    >>> x * y
    x*y
    >>> (x * y).sort()
    Real

Definition at line 2403 of file z3py.py.

2403 def __mul__(self, other):
2404 """Create the Z3 expression `self * other`.
2405
2406 >>> x = Real('x')
2407 >>> y = Real('y')
2408 >>> x * y
2409 x*y
2410 >>> (x * y).sort()
2411 Real
2412 """
2413 if isinstance(other, BoolRef):
2414 return If(other, self, 0)
2415 a, b = _coerce_exprs(self, other)
2416 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2417
z3py.If
def If(a, b, c, ctx=None)
Definition: z3py.py:1349

## ◆ __neg__()

def __neg__ | ( |  | self | ) |

    Return an expression representing `-self`.

    >>> x = Int('x')
    >>> -x
    -x
    >>> simplify(-(-x))
    x

Definition at line 2554 of file z3py.py.

2554 def __neg__(self):
2555 """Return an expression representing `-self`.
2556
2557 >>> x = Int('x')
2558 >>> -x
2559 -x
2560 >>> simplify(-(-x))
2561 x
2562 """
2563 return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2564
Z3_mk_unary_minus
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.

## ◆ __pos__()

def __pos__ | ( |  | self | ) |

    Return `self`.

    >>> x = Int('x')
    >>> +x
    x

Definition at line 2565 of file z3py.py.

2565 def __pos__(self):
2566 """Return `self`.
2567
2568 >>> x = Int('x')
2569 >>> +x
2570 x
2571 """
2572 return self
2573

## ◆ __pow__()

def __pow__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `self**other` (** is the power operator).

    >>> x = Real('x')
    >>> x**3
    x**3
    >>> (x**3).sort()
    Real
    >>> simplify(IntVal(2)**8)
    256

Definition at line 2451 of file z3py.py.

2451 def __pow__(self, other):
2452 """Create the Z3 expression `self**other` (** is the power operator).
2453
2454 >>> x = Real('x')
2455 >>> x**3
2456 x**3
2457 >>> (x**3).sort()
2458 Real
2459 >>> simplify(IntVal(2)**8)
2460 256
2461 """
2462 a, b = _coerce_exprs(self, other)
2463 return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2464
Z3_mk_power
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.

## ◆ __radd__()

def __radd__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other + self`.

    >>> x = Int('x')
    >>> 10 + x
    10 + x

Definition at line 2393 of file z3py.py.

2393 def __radd__(self, other):
2394 """Create the Z3 expression `other + self`.
2395
2396 >>> x = Int('x')
2397 >>> 10 + x
2398 10 + x
2399 """
2400 a, b = _coerce_exprs(self, other)
2401 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2402

## ◆ __rdiv__()

def __rdiv__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other/self`.

    >>> x = Int('x')
    >>> 10/x
    10/x
    >>> (10/x).sexpr()
    '(div 10 x)'
    >>> x = Real('x')
    >>> 10/x
    10/x
    >>> (10/x).sexpr()
    '(/ 10.0 x)'

Definition at line 2506 of file z3py.py.

2506 def __rdiv__(self, other):
2507 """Create the Z3 expression `other/self`.
2508
2509 >>> x = Int('x')
2510 >>> 10/x
2511 10/x
2512 >>> (10/x).sexpr()
2513 '(div 10 x)'
2514 >>> x = Real('x')
2515 >>> 10/x
2516 10/x
2517 >>> (10/x).sexpr()
2518 '(/ 10.0 x)'
2519 """
2520 a, b = _coerce_exprs(self, other)
2521 return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2522

Referenced by ArithRef.__rtruediv__(), BitVecRef.__rtruediv__(), and FPRef.__rtruediv__().

## ◆ __rmod__()

def __rmod__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other%self`.

    >>> x = Int('x')
    >>> 10 % x
    10%x

Definition at line 2542 of file z3py.py.

2542 def __rmod__(self, other):
2543 """Create the Z3 expression `other%self`.
2544
2545 >>> x = Int('x')
2546 >>> 10 % x
2547 10%x
2548 """
2549 a, b = _coerce_exprs(self, other)
2550 if z3_debug():
2551 _z3_assert(a.is_int(), "Z3 integer expression expected")
2552 return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2553

## ◆ __rmul__()

def __rmul__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other * self`.

    >>> x = Real('x')
    >>> 10 * x
    10*x

Definition at line 2418 of file z3py.py.

2418 def __rmul__(self, other):
2419 """Create the Z3 expression `other * self`.
2420
2421 >>> x = Real('x')
2422 >>> 10 * x
2423 10*x
2424 """
2425 a, b = _coerce_exprs(self, other)
2426 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2427

## ◆ __rpow__()

def __rpow__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other**self` (** is the power operator).

    >>> x = Real('x')
    >>> 2**x
    2**x
    >>> (2**x).sort()
    Real
    >>> simplify(2**IntVal(8))
    256

Definition at line 2465 of file z3py.py.

2465 def __rpow__(self, other):
2466 """Create the Z3 expression `other**self` (** is the power operator).
2467
2468 >>> x = Real('x')
2469 >>> 2**x
2470 2**x
2471 >>> (2**x).sort()
2472 Real
2473 >>> simplify(2**IntVal(8))
2474 256
2475 """
2476 a, b = _coerce_exprs(self, other)
2477 return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2478

## ◆ __rsub__()

def __rsub__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other - self`.

    >>> x = Int('x')
    >>> 10 - x
    10 - x

Definition at line 2441 of file z3py.py.

2441 def __rsub__(self, other):
2442 """Create the Z3 expression `other - self`.
2443
2444 >>> x = Int('x')
2445 >>> 10 - x
2446 10 - x
2447 """
2448 a, b = _coerce_exprs(self, other)
2449 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2450

## ◆ __rtruediv__()

def __rtruediv__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other/self`.

Definition at line 2523 of file z3py.py.

2523 def __rtruediv__(self, other):
2524 """Create the Z3 expression `other/self`."""
2525 return self.__rdiv__(other)
2526

## ◆ __sub__()

def __sub__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `self - other`.

    >>> x = Int('x')
    >>> y = Int('y')
    >>> x - y
    x - y
    >>> (x - y).sort()
    Int

Definition at line 2428 of file z3py.py.

2428 def __sub__(self, other):
2429 """Create the Z3 expression `self - other`.
2430
2431 >>> x = Int('x')
2432 >>> y = Int('y')
2433 >>> x - y
2434 x - y
2435 >>> (x - y).sort()
2436 Int
2437 """
2438 a, b = _coerce_exprs(self, other)
2439 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2440

## ◆ __truediv__()

def __truediv__ | ( |  | self,
|  |  | other
| ) |  |

    Create the Z3 expression `other/self`.

Definition at line 2502 of file z3py.py.

2502 def __truediv__(self, other):
2503 """Create the Z3 expression `other/self`."""
2504 return self.__div__(other)
2505

## ◆ is_int()

def is_int | ( |  | self | ) |

    Return `True` if `self` is an integer expression.

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

Reimplemented in RatNumRef.

Definition at line 2355 of file z3py.py.

2355 def is_int(self):
2356 """Return `True` if `self` is an integer expression.
2357
2358 >>> x = Int('x')
2359 >>> x.is_int()
2360 True
2361 >>> (x + 1).is_int()
2362 True
2363 >>> y = Real('y')
2364 >>> (x + y).is_int()
2365 False
2366 """
2367 return self.sort().is_int()
2368
z3py.is_int
def is_int(a)
Definition: z3py.py:2648

Referenced by IntNumRef.as_long(), ArithRef.is_int(), and ArithSortRef.subsort().

## ◆ is_real()

def is_real | ( |  | self | ) |

    Return `True` if `self` is an real expression.

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

Reimplemented in RatNumRef.

Definition at line 2369 of file z3py.py.

2369 def is_real(self):
2370 """Return `True` if `self` is an real expression.
2371
2372 >>> x = Real('x')
2373 >>> x.is_real()
2374 True
2375 >>> (x + 1).is_real()
2376 True
2377 """
2378 return self.sort().is_real()
2379
z3py.is_real
def is_real(a)
Definition: z3py.py:2667

Referenced by ArithRef.is_real().

## ◆ sort()

def sort | ( |  | self | ) |

    Return the sort (type) of the arithmetical expression `self`.

    >>> Int('x').sort()
    Int
    >>> (Real('x') + 1).sort()
    Real

Reimplemented from ExprRef.

Definition at line 2345 of file z3py.py.

2345 def sort(self):
2346 """Return the sort (type) of the arithmetical expression `self`.
2347
2348 >>> Int('x').sort()
2349 Int
2350 >>> (Real('x') + 1).sort()
2351 Real
2352 """
2353 return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2354
Z3_get_sort
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

Referenced by ArithRef.__add__(), ArithRef.__div__(), QuantifierRef.__getitem__(), ArithRef.__mul__(), ArithRef.__pow__(), ArithRef.__rpow__(), ArithRef.__sub__(), FPNumRef.as_string(), ArrayRef.domain(), FPRef.ebits(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), FPRef.sbits(), BitVecRef.size(), ArithRef.sort(), and ExprRef.sort_kind().