@@ -12,22 +12,22 @@ import Mathlib.Data.Nat.Bits
12
12
13
13
namespace Nat
14
14
15
- /-! ### `shiftl ` and `shiftr ` -/
15
+ /-! ### `shiftLeft ` and `shiftRight ` -/
16
16
17
17
section
18
18
set_option linter.deprecated false
19
19
20
20
theorem shiftLeft_eq_mul_pow (m) : ∀ n, m <<< n = m * 2 ^ n := shiftLeft_eq _
21
21
#align nat.shiftl_eq_mul_pow Nat.shiftLeft_eq_mul_pow
22
22
23
- theorem shiftl '_tt_eq_mul_pow (m) : ∀ n, shiftl ' true m n + 1 = (m + 1 ) * 2 ^ n
24
- | 0 => by simp [shiftl ', pow_zero, Nat.one_mul]
23
+ theorem shiftLeft '_tt_eq_mul_pow (m) : ∀ n, shiftLeft ' true m n + 1 = (m + 1 ) * 2 ^ n
24
+ | 0 => by simp [shiftLeft ', pow_zero, Nat.one_mul]
25
25
| k + 1 => by
26
- change bit1 (shiftl ' true m k) + 1 = (m + 1 ) * (2 ^ k * 2 )
26
+ change bit1 (shiftLeft ' true m k) + 1 = (m + 1 ) * (2 ^ k * 2 )
27
27
rw [bit1_val]
28
- change 2 * (shiftl ' true m k + 1 ) = _
29
- rw [shiftl '_tt_eq_mul_pow m k, mul_left_comm, mul_comm 2 ]
30
- #align nat.shiftl'_tt_eq_mul_pow Nat.shiftl '_tt_eq_mul_pow
28
+ change 2 * (shiftLeft ' true m k + 1 ) = _
29
+ rw [shiftLeft '_tt_eq_mul_pow m k, mul_left_comm, mul_comm 2 ]
30
+ #align nat.shiftl'_tt_eq_mul_pow Nat.shiftLeft '_tt_eq_mul_pow
31
31
32
32
end
33
33
@@ -43,14 +43,14 @@ theorem shiftRight_eq_div_pow (m) : ∀ n, m >>> n = m / 2 ^ n
43
43
simp [Nat.div_div_eq_div_mul, ← Nat.pow_succ]
44
44
#align nat.shiftr_eq_div_pow Nat.shiftRight_eq_div_pow
45
45
46
- theorem shiftl '_ne_zero_left (b) {m} (h : m ≠ 0 ) (n) : shiftl ' b m n ≠ 0 := by
47
- induction n <;> simp [bit_ne_zero, shiftl ', *]
48
- #align nat.shiftl'_ne_zero_left Nat.shiftl '_ne_zero_left
46
+ theorem shiftLeft '_ne_zero_left (b) {m} (h : m ≠ 0 ) (n) : shiftLeft ' b m n ≠ 0 := by
47
+ induction n <;> simp [bit_ne_zero, shiftLeft ', *]
48
+ #align nat.shiftl'_ne_zero_left Nat.shiftLeft '_ne_zero_left
49
49
50
- theorem shiftl '_tt_ne_zero (m) : ∀ {n}, (n ≠ 0 ) → shiftl ' true m n ≠ 0
50
+ theorem shiftLeft '_tt_ne_zero (m) : ∀ {n}, (n ≠ 0 ) → shiftLeft ' true m n ≠ 0
51
51
| 0 , h => absurd rfl h
52
52
| succ _, _ => Nat.bit1_ne_zero _
53
- #align nat.shiftl'_tt_ne_zero Nat.shiftl '_tt_ne_zero
53
+ #align nat.shiftl'_tt_ne_zero Nat.shiftLeft '_tt_ne_zero
54
54
55
55
/-! ### `size` -/
56
56
@@ -90,27 +90,28 @@ theorem size_one : size 1 = 1 :=
90
90
end
91
91
92
92
@[simp]
93
- theorem size_shiftl' {b m n} (h : shiftl' b m n ≠ 0 ) : size (shiftl' b m n) = size m + n := by
94
- induction' n with n IH <;> simp [shiftl'] at h ⊢
93
+ theorem size_shiftLeft' {b m n} (h : shiftLeft' b m n ≠ 0 ) :
94
+ size (shiftLeft' b m n) = size m + n := by
95
+ induction' n with n IH <;> simp [shiftLeft'] at h ⊢
95
96
rw [size_bit h, Nat.add_succ]
96
- by_cases s0 : shiftl ' b m n = 0 <;> [skip; rw [IH s0]]
97
+ by_cases s0 : shiftLeft ' b m n = 0 <;> [skip; rw [IH s0]]
97
98
rw [s0] at h ⊢
98
99
cases b; · exact absurd rfl h
99
- have : shiftl ' true m n + 1 = 1 := congr_arg (· + 1 ) s0
100
- rw [shiftl '_tt_eq_mul_pow] at this
100
+ have : shiftLeft ' true m n + 1 = 1 := congr_arg (· + 1 ) s0
101
+ rw [shiftLeft '_tt_eq_mul_pow] at this
101
102
obtain rfl := succ.inj (eq_one_of_dvd_one ⟨_, this.symm⟩)
102
103
simp only [zero_add, one_mul] at this
103
104
obtain rfl : n = 0 :=
104
105
Nat.eq_zero_of_le_zero
105
106
(le_of_not_gt fun hn => ne_of_gt (pow_lt_pow_of_lt_right (by decide) hn) this)
106
107
rfl
107
- #align nat.size_shiftl' Nat.size_shiftl '
108
+ #align nat.size_shiftl' Nat.size_shiftLeft '
108
109
109
110
-- TODO: decide whether `Nat.shiftLeft_eq` (which rewrites the LHS into a power) should be a simp
110
111
-- lemma; it was not in mathlib3. Until then, tell the simpNF linter to ignore the issue.
111
112
@[simp, nolint simpNF]
112
113
theorem size_shiftLeft {m} (h : m ≠ 0 ) (n) : size (m <<< n) = size m + n :=
113
- by simp only [size_shiftl ' (shiftl '_ne_zero_left _ h _), ← shiftl '_false]
114
+ by simp only [size_shiftLeft ' (shiftLeft '_ne_zero_left _ h _), ← shiftLeft '_false]
114
115
#align nat.size_shiftl Nat.size_shiftLeft
115
116
116
117
theorem lt_size_self (n : ℕ) : n < 2 ^ size n := by
0 commit comments