forked from leanprover/lean4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: getLsb_sshiftRight (leanprover#4179)
In the course of the development, I grabbed facts about right shifting over integers [from `mathlib4`](https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/Int/Bitwise.lean). The core proof strategy is to perform a case analysis of the msb: - If `msb = false`, then `sshiftRight = ushiftRight`. - If `msb = true`. then `x >>>s i = ~~~(~~~(x >>>u i))`. The double negation introduces the high `1` bits that one expects of the arithmetic shift. --------- Co-authored-by: Kim Morrison <[email protected]>
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/- | ||
Copyright (c) 2023 Siddharth Bhat. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Siddharth Bhat, Jeremy Avigad | ||
-/ | ||
prelude | ||
import Init.Data.Nat.Bitwise.Lemmas | ||
import Init.Data.Int.Bitwise | ||
|
||
namespace Int | ||
|
||
theorem shiftRight_eq (n : Int) (s : Nat) : n >>> s = Int.shiftRight n s := rfl | ||
@[simp] | ||
theorem natCast_shiftRight (n s : Nat) : (n : Int) >>> s = n >>> s := rfl | ||
|
||
@[simp] | ||
theorem negSucc_shiftRight (m n : Nat) : | ||
-[m+1] >>> n = -[m >>>n +1] := rfl | ||
|
||
theorem shiftRight_add (i : Int) (m n : Nat) : | ||
i >>> (m + n) = i >>> m >>> n := by | ||
simp only [shiftRight_eq, Int.shiftRight] | ||
cases i <;> simp [Nat.shiftRight_add] | ||
|
||
theorem shiftRight_eq_div_pow (m : Int) (n : Nat) : | ||
m >>> n = m / ((2 ^ n) : Nat) := by | ||
simp only [shiftRight_eq, Int.shiftRight, Nat.shiftRight_eq_div_pow] | ||
split | ||
· simp | ||
· rw [negSucc_ediv _ (by norm_cast; exact Nat.pow_pos (Nat.zero_lt_two))] | ||
rfl | ||
|
||
@[simp] | ||
theorem zero_shiftRight (n : Nat) : (0 : Int) >>> n = 0 := by | ||
simp [Int.shiftRight_eq_div_pow] | ||
|
||
end Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters