Open bollu opened 4 days ago
Mathlib CI status (docs):
nightly-with-mathlib
branch. Try git rebase 799b2b662825e646609963921f2c68489b2e664a --onto 72e952eadc6a171310f1d8e9d6e78acf98421494
. (2024-11-21 13:01:42)nightly-with-mathlib
branch. Try git rebase 799b2b662825e646609963921f2c68489b2e664a --onto 884a9ea2ff70bb4d0c6da4a1c23ffc26c3a974ee
. (2024-11-25 14:16:57)Can you drop the mention of 'stacked pr' in the commit message?
@tobiasgrosser done
awaiting-review
changelog-library
It doesn't need to be in this PR, but I would like to also have
theorem natAbs_toInt (x : BitVec w) : x.toInt.natAbs = if x.msb then x.toNat - (2^(w-1) - 1) else x.toNat
(didn't check the RHS carefully, but something like that ought to be true).
This PR implements
BitVec.toInt_abs
.The absolute value of
x : BitVec w
is naively a case split on the sign ofx
. However, recall that whenx = intMin w
,-x = x
. Thus, the full value ofabs x
is computed by the case split:x : BitVec w
isintMin
, then its absolute value is alsointMin w
, and thustoInt
will equalintMin.toInt
.x
is negative, thenx.abs.toInt = (-x).toInt
.x
is nonnegative, thenx.abs.toInt = x.toInt
.We also provide a variant of
toInt_abs
that hides the case split forx
being positive or negative by usingnatAbs
.Supercedes https://github.com/leanprover/lean4/pull/5787