3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-17 06:11:44 +00:00

Alias ArithRef.__abs__ to Abs

This integrates with the `abs(Int('x'))` Python builtin.
This commit is contained in:
Daniel Tang 2026-02-14 01:37:58 -05:00
parent e2486eff77
commit c172b58268
No known key found for this signature in database
GPG key ID: E1523803636E3951

View file

@ -2804,6 +2804,17 @@ class ArithRef(ExprRef):
a, b = _coerce_exprs(self, other)
return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
def __abs__(self):
"""Return an expression representing `abs(self)`.
>>> x = Int('x')
>>> abs(x)
If(x > 0, x, -x)
>>> eq(abs(x), Abs(x))
True
"""
return Abs(self)
def is_arith(a):
"""Return `True` if `a` is an arithmetical expression.