Skip to content

Commit 93bcc03

Browse files
committed
chore: rename Nat.shiftl' to Nat.shiftLeft' (#6788)
This makes it match the unprimed `Nat.shiftLeft`. Follows on from #6356 which removed `Nat.shiftl`.
1 parent 49a849e commit 93bcc03

File tree

5 files changed

+45
-44
lines changed

5 files changed

+45
-44
lines changed

Mathlib/Data/Int/Bitwise.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ theorem shiftr_coe_nat (m n : ℕ) : shiftr m n = m >>> n := by cases n <;> rfl
385385
#align int.shiftr_coe_nat Int.shiftr_coe_nat
386386

387387
@[simp]
388-
theorem shiftl_negSucc (m n : ℕ) : shiftl -[m+1] n = -[Nat.shiftl' true m n+1] :=
388+
theorem shiftl_negSucc (m n : ℕ) : shiftl -[m+1] n = -[Nat.shiftLeft' true m n+1] :=
389389
rfl
390390
#align int.shiftl_neg_succ Int.shiftl_negSucc
391391

@@ -407,22 +407,22 @@ attribute [local simp] Int.zero_div
407407
theorem shiftl_add : ∀ (m : ℤ) (n : ℕ) (k : ℤ), shiftl m (n + k) = shiftl (shiftl m n) k
408408
| (m : ℕ), n, (k : ℕ) =>
409409
congr_arg ofNat (by simp [Nat.pow_add, mul_assoc])
410-
| -[m+1], n, (k : ℕ) => congr_arg negSucc (Nat.shiftl'_add _ _ _ _)
410+
| -[m+1], n, (k : ℕ) => congr_arg negSucc (Nat.shiftLeft'_add _ _ _ _)
411411
| (m : ℕ), n, -[k+1] =>
412-
subNatNat_elim n k.succ (fun n k i => shiftl (↑m) i = (Nat.shiftl' false m n) >>> k)
412+
subNatNat_elim n k.succ (fun n k i => shiftl (↑m) i = (Nat.shiftLeft' false m n) >>> k)
413413
(fun (i n : ℕ) =>
414414
by dsimp; simp [- Nat.shiftLeft_eq, ← Nat.shiftLeft_sub _ , add_tsub_cancel_left])
415415
fun i n =>
416416
by dsimp; simp [- Nat.shiftLeft_eq, Nat.shiftLeft_zero, Nat.shiftRight_add,
417417
← Nat.shiftLeft_sub, shiftl]
418418
| -[m+1], n, -[k+1] =>
419419
subNatNat_elim n k.succ
420-
(fun n k i => shiftl -[m+1] i = -[(Nat.shiftl' true m n) >>> k+1])
420+
(fun n k i => shiftl -[m+1] i = -[(Nat.shiftLeft' true m n) >>> k+1])
421421
(fun i n =>
422422
congr_arg negSucc <| by
423-
rw [← Nat.shiftl'_sub, add_tsub_cancel_left]; apply Nat.le_add_right)
423+
rw [← Nat.shiftLeft'_sub, add_tsub_cancel_left]; apply Nat.le_add_right)
424424
fun i n =>
425-
congr_arg negSucc <| by rw [add_assoc, Nat.shiftRight_add, ← Nat.shiftl'_sub, tsub_self]
425+
congr_arg negSucc <| by rw [add_assoc, Nat.shiftRight_add, ← Nat.shiftLeft'_sub, tsub_self]
426426
<;> rfl
427427
#align int.shiftl_add Int.shiftl_add
428428

@@ -432,7 +432,7 @@ theorem shiftl_sub (m : ℤ) (n : ℕ) (k : ℤ) : shiftl m (n - k) = shiftr (sh
432432

433433
theorem shiftl_eq_mul_pow : ∀ (m : ℤ) (n : ℕ), shiftl m n = m * ↑(2 ^ n)
434434
| (m : ℕ), _ => congr_arg ((↑) : ℕ → ℤ) (by simp)
435-
| -[_+1], _ => @congr_arg ℕ ℤ _ _ (fun i => -i) (Nat.shiftl'_tt_eq_mul_pow _ _)
435+
| -[_+1], _ => @congr_arg ℕ ℤ _ _ (fun i => -i) (Nat.shiftLeft'_tt_eq_mul_pow _ _)
436436
#align int.shiftl_eq_mul_pow Int.shiftl_eq_mul_pow
437437

438438
theorem shiftr_eq_div_pow : ∀ (m : ℤ) (n : ℕ), shiftr m n = m / ↑(2 ^ n)

Mathlib/Data/Nat/Bits.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ which allows us to more easily work with operations which do depend
1717
on the number of leading zeros in the binary representation of `n`.
1818
For example, we can more easily work with `Nat.bits` and `Nat.size`.
1919
20-
See also: `Nat.bitwise`, `Nat.pow` (for various lemmas about `size` and `shiftl`/`shiftr`),
20+
See also: `Nat.bitwise`, `Nat.pow` (for various lemmas about `size` and `shiftLeft`/`shiftRight`),
2121
and `Nat.digits`.
2222
-/
2323

Mathlib/Data/Nat/Size.lean

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ import Mathlib.Data.Nat.Bits
1212

1313
namespace Nat
1414

15-
/-! ### `shiftl` and `shiftr` -/
15+
/-! ### `shiftLeft` and `shiftRight` -/
1616

1717
section
1818
set_option linter.deprecated false
1919

2020
theorem shiftLeft_eq_mul_pow (m) : ∀ n, m <<< n = m * 2 ^ n := shiftLeft_eq _
2121
#align nat.shiftl_eq_mul_pow Nat.shiftLeft_eq_mul_pow
2222

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]
2525
| 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)
2727
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
3131

3232
end
3333

@@ -43,14 +43,14 @@ theorem shiftRight_eq_div_pow (m) : ∀ n, m >>> n = m / 2 ^ n
4343
simp [Nat.div_div_eq_div_mul, ← Nat.pow_succ]
4444
#align nat.shiftr_eq_div_pow Nat.shiftRight_eq_div_pow
4545

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
4949

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
5151
| 0, h => absurd rfl h
5252
| 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
5454

5555
/-! ### `size` -/
5656

@@ -90,27 +90,28 @@ theorem size_one : size 1 = 1 :=
9090
end
9191

9292
@[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 ⊢
9596
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]]
9798
rw [s0] at h ⊢
9899
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
101102
obtain rfl := succ.inj (eq_one_of_dvd_one ⟨_, this.symm⟩)
102103
simp only [zero_add, one_mul] at this
103104
obtain rfl : n = 0 :=
104105
Nat.eq_zero_of_le_zero
105106
(le_of_not_gt fun hn => ne_of_gt (pow_lt_pow_of_lt_right (by decide) hn) this)
106107
rfl
107-
#align nat.size_shiftl' Nat.size_shiftl'
108+
#align nat.size_shiftl' Nat.size_shiftLeft'
108109

109110
-- TODO: decide whether `Nat.shiftLeft_eq` (which rewrites the LHS into a power) should be a simp
110111
-- lemma; it was not in mathlib3. Until then, tell the simpNF linter to ignore the issue.
111112
@[simp, nolint simpNF]
112113
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]
114115
#align nat.size_shiftl Nat.size_shiftLeft
115116

116117
theorem lt_size_self (n : ℕ) : n < 2 ^ size n := by

Mathlib/Init/Data/Int/Bitwise.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def lxor' : ℤ → ℤ → ℤ
104104
/-- `shiftl m n` produces an integer whose binary representation
105105
is obtained by left-shifting the binary representation of `m` by `n` places -/
106106
def shiftl : ℤ → ℤ → ℤ
107-
| (m : ℕ), (n : ℕ) => Nat.shiftl' false m n
107+
| (m : ℕ), (n : ℕ) => Nat.shiftLeft' false m n
108108
| (m : ℕ), -[n +1] => m >>> (Nat.succ n)
109-
| -[m +1], (n : ℕ) => -[Nat.shiftl' true m n +1]
109+
| -[m +1], (n : ℕ) => -[Nat.shiftLeft' true m n +1]
110110
| -[m +1], -[n +1] => -[m >>> (Nat.succ n) +1]
111111
#align int.shiftl Int.shiftl
112112

Mathlib/Init/Data/Nat/Bitwise.lean

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,21 @@ theorem bit_zero : bit false 0 = 0 :=
180180
rfl
181181
#align nat.bit_zero Nat.bit_zero
182182

183-
/--`shiftl' b m n` performs a left shift of `m` `n` times
183+
/--`shiftLeft' b m n` performs a left shift of `m` `n` times
184184
and adds the bit `b` as the least significant bit each time.
185185
Returns the corresponding natural number-/
186-
def shiftl' (b : Bool) (m : ℕ) : ℕ → ℕ
186+
def shiftLeft' (b : Bool) (m : ℕ) : ℕ → ℕ
187187
| 0 => m
188-
| n + 1 => bit b (shiftl' b m n)
189-
#align nat.shiftl' Nat.shiftl'
188+
| n + 1 => bit b (shiftLeft' b m n)
189+
#align nat.shiftl' Nat.shiftLeft'
190190

191191
@[simp]
192-
theorem shiftl'_false : ∀ n, shiftl' false m n = m <<< n
192+
theorem shiftLeft'_false : ∀ n, shiftLeft' false m n = m <<< n
193193
| 0 => rfl
194194
| n + 1 => by
195195
have : 2 * (m * 2^n) = 2^(n+1)*m := by
196196
rw [Nat.mul_comm, Nat.mul_assoc, ← pow_succ]; simp
197-
simp [shiftl', bit_val, shiftl'_false, this]
197+
simp [shiftLeft', bit_val, shiftLeft'_false, this]
198198

199199
/-- Std4 takes the unprimed name for `Nat.shiftLeft_eq m n : m <<< n = m * 2 ^ n`. -/
200200
@[simp]
@@ -318,28 +318,28 @@ theorem div2_bit (b n) : div2 (bit b n) = n := by
318318
<;> exact by decide
319319
#align nat.div2_bit Nat.div2_bit
320320

321-
theorem shiftl'_add (b m n) : ∀ k, shiftl' b m (n + k) = shiftl' b (shiftl' b m n) k
321+
theorem shiftLeft'_add (b m n) : ∀ k, shiftLeft' b m (n + k) = shiftLeft' b (shiftLeft' b m n) k
322322
| 0 => rfl
323-
| k + 1 => congr_arg (bit b) (shiftl'_add b m n k)
324-
#align nat.shiftl'_add Nat.shiftl'_add
323+
| k + 1 => congr_arg (bit b) (shiftLeft'_add b m n k)
324+
#align nat.shiftl'_add Nat.shiftLeft'_add
325325

326326
theorem shiftLeft_add (m n : Nat) : ∀ k, m <<< (n + k) = (m <<< n) <<< k := by
327-
intro k; simp only [← shiftl'_false, shiftl'_add]
327+
intro k; simp only [← shiftLeft'_false, shiftLeft'_add]
328328

329329
theorem shiftRight_add (m n : Nat) : ∀ k, m >>> (n + k) = (m >>> n) >>> k
330330
| 0 => rfl
331331
| k + 1 => by simp [add_succ, shiftRight_add]
332332

333-
theorem shiftl'_sub (b m) : ∀ {n k}, k ≤ n → shiftl' b m (n - k) = (shiftl' b m n) >>> k
333+
theorem shiftLeft'_sub (b m) : ∀ {n k}, k ≤ n → shiftLeft' b m (n - k) = (shiftLeft' b m n) >>> k
334334
| n, 0, _ => rfl
335335
| n + 1, k + 1, h => by
336-
rw [succ_sub_succ_eq_sub, shiftl', Nat.add_comm, shiftRight_add]
337-
simp only [shiftl'_sub, Nat.le_of_succ_le_succ h, shiftRight_succ, shiftRight_zero]
336+
rw [succ_sub_succ_eq_sub, shiftLeft', Nat.add_comm, shiftRight_add]
337+
simp only [shiftLeft'_sub, Nat.le_of_succ_le_succ h, shiftRight_succ, shiftRight_zero]
338338
simp [← div2_val, div2_bit]
339-
#align nat.shiftl'_sub Nat.shiftl'_sub
339+
#align nat.shiftl'_sub Nat.shiftLeft'_sub
340340

341341
theorem shiftLeft_sub : ∀ (m : Nat) {n k}, k ≤ n → m <<< (n - k) = (m <<< n) >>> k :=
342-
fun _ _ _ hk => by simp only [← shiftl'_false, shiftl'_sub false _ hk]
342+
fun _ _ _ hk => by simp only [← shiftLeft'_false, shiftLeft'_sub false _ hk]
343343

344344
@[simp]
345345
theorem testBit_zero (b n) : testBit (bit b n) 0 = b :=

0 commit comments

Comments
 (0)