MCPcopy Create free account
hub / github.com/BasisResearch/lean.py / BVSubNoUnderflow

Function BVSubNoUnderflow

lean_py/z3/core.py:2021–2034  ·  view source on GitHub ↗

Check that a - b does not underflow.

(a: BitVecRef, b: BitVecRef, signed: bool = False)

Source from the content-addressed store, hash-verified

2019
2020
2021def BVSubNoUnderflow(a: BitVecRef, b: BitVecRef, signed: bool = False) -> BoolRef:
2022 """Check that a - b does not underflow."""
2023 sort = a._sort
2024 if not isinstance(sort, BitVecSortRef):
2025 raise TypeError("BVSubNoUnderflow requires BitVecRef")
2026 w = sort._width
2027 if signed:
2028 ea = SignExt(1, a)
2029 eb = SignExt(1, b)
2030 s = ea - eb
2031 lower = BitVecVal(-(1 << (w - 1)), w + 1)
2032 return s >= lower
2033 else:
2034 return ULE(b, a)
2035
2036
2037def BVMulNoOverflow(a: BitVecRef, b: BitVecRef, signed: bool = False) -> BoolRef:

Calls 3

SignExtFunction · 0.85
BitVecValFunction · 0.85
ULEFunction · 0.85

Tested by 2