From 064122a123be87a92780409678ba750eca2849a6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:44:40 +0000 Subject: [PATCH] Improve documentation for RatVal division by zero handling Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --- src/api/python/z3/z3.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/python/z3/z3.py b/src/api/python/z3/z3.py index c4b35bf3d..f859ab961 100644 --- a/src/api/python/z3/z3.py +++ b/src/api/python/z3/z3.py @@ -3376,6 +3376,9 @@ def RatVal(a, b, ctx=None): """Return a Z3 rational a/b. If `ctx=None`, then the global context is used. + + Note: Division by zero (b == 0) is allowed in Z3 symbolic expressions. + Z3 can reason about such expressions symbolically. >>> RatVal(3,5) 3/5 @@ -3385,8 +3388,7 @@ def RatVal(a, b, ctx=None): if z3_debug(): _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer") _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer") - if b == 0: - pass # division by 0 is legal in z3 expressions. + # Division by 0 is intentionally allowed - Z3 handles it symbolically return simplify(RealVal(a, ctx) / RealVal(b, ctx))