Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - chore: deprecate Nat.binaryRec_eq, rename Nat.binaryRec_eq' => Nat.binaryRec_eq #18039

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions Mathlib/Data/Nat/BinaryRec.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Praneeth Kolichala, Yuyang Zhao
-/
import Batteries.Tactic.Alias

/-!
# Binary recursion on `Nat`
Expand Down Expand Up @@ -127,12 +128,7 @@ theorem binaryRec_one {motive : Nat → Sort u} (z : motive 0) (f : ∀ b n, mot
simp only [add_one_ne_zero, ↓reduceDIte, Nat.reduceShiftRight, binaryRec_zero]
rfl

/--
The same as `binaryRec_eq`,
but that one unfortunately requires `f` to be the identity when appending `false` to `0`.
Here, we allow you to explicitly say that that case is not happening,
i.e. supplying `n = 0 → b = true`. -/
theorem binaryRec_eq' {motive : Nat → Sort u} {z : motive 0}
theorem binaryRec_eq {motive : Nat → Sort u} {z : motive 0}
{f : ∀ b n, motive n → motive (bit b n)} (b n)
(h : f false 0 z = z ∨ (n = 0 → b = true)) :
binaryRec z f (bit b n) = f b n (binaryRec z f n) := by
Expand All @@ -149,9 +145,6 @@ theorem binaryRec_eq' {motive : Nat → Sort u} {z : motive 0}
rw [testBit_bit_zero, bit_shiftRight_one]
intros; rfl

theorem binaryRec_eq {motive : Nat → Sort u} {z : motive 0} {f : ∀ b n, motive n → motive (bit b n)}
(h : f false 0 z = z) (b n) :
binaryRec z f (bit b n) = f b n (binaryRec z f n) :=
binaryRec_eq' b n (.inl h)
@[deprecated (since := "2024-10-21")] alias binaryRec_eq' := binaryRec_eq

end Nat
4 changes: 2 additions & 2 deletions Mathlib/Data/Nat/BitIndices.lean
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def bitIndices (n : ℕ) : List ℕ :=

theorem bitIndices_bit_true (n : ℕ) :
bitIndices (bit true n) = 0 :: ((bitIndices n).map (· + 1)) :=
binaryRec_eq rfl _ _
binaryRec_eq _ _ (.inl rfl)

theorem bitIndices_bit_false (n : ℕ) :
bitIndices (bit false n) = (bitIndices n).map (· + 1) :=
binaryRec_eq rfl _ _
binaryRec_eq _ _ (.inl rfl)

@[simp] theorem bitIndices_two_mul_add_one (n : ℕ) :
bitIndices (2 * n + 1) = 0 :: (bitIndices n).map (· + 1) := by
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Data/Nat/Bits.lean
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ theorem zero_bits : bits 0 = [] := by simp [Nat.bits]
@[simp]
theorem bits_append_bit (n : ℕ) (b : Bool) (hn : n = 0 → b = true) :
(bit b n).bits = b :: n.bits := by
rw [Nat.bits, Nat.bits, binaryRec_eq']
rw [Nat.bits, Nat.bits, binaryRec_eq]
simpa

@[simp]
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Data/Nat/Bitwise.lean
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ theorem binaryRec_of_ne_zero {C : Nat → Sort*} (z : C 0) (f : ∀ b n, C n →
binaryRec z f n = bit_decomp n ▸ f (bodd n) (div2 n) (binaryRec z f (div2 n)) := by
cases n using bitCasesOn with
| h b n =>
rw [binaryRec_eq' _ _ (by right; simpa [bit_eq_zero_iff] using h)]
rw [binaryRec_eq _ _ (by right; simpa [bit_eq_zero_iff] using h)]
generalize_proofs h; revert h
rw [bodd_bit, div2_bit]
simp
Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Data/Nat/EvenOddRec.lean
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ theorem evenOddRec_zero {P : ℕ → Sort*} (h0 : P 0) (h_even : ∀ i, P i →
theorem evenOddRec_even {P : ℕ → Sort*} (h0 : P 0) (h_even : ∀ i, P i → P (2 * i))
(h_odd : ∀ i, P i → P (2 * i + 1)) (H : h_even 0 h0 = h0) (n : ℕ) :
(2 * n).evenOddRec h0 h_even h_odd = h_even n (evenOddRec h0 h_even h_odd n) := by
apply binaryRec_eq' false n
apply binaryRec_eq false n
simp [H]

@[simp]
theorem evenOddRec_odd {P : ℕ → Sort*} (h0 : P 0) (h_even : ∀ i, P i → P (2 * i))
(h_odd : ∀ i, P i → P (2 * i + 1)) (H : h_even 0 h0 = h0) (n : ℕ) :
(2 * n + 1).evenOddRec h0 h_even h_odd = h_odd n (evenOddRec h0 h_even h_odd n) := by
apply binaryRec_eq' true n
apply binaryRec_eq true n
simp [H]

/-- Strong recursion principle on even and odd numbers: if for all `i : ℕ` we can prove `P (2 * i)`
Expand Down
11 changes: 5 additions & 6 deletions Mathlib/Data/Num/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ theorem bit1_of_bit1 : ∀ n : Num, (n + n) + 1 = n.bit1
theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat']

theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) :=
Nat.binaryRec_eq rfl _ _
Nat.binaryRec_eq _ _ (.inl rfl)

@[simp]
theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl
Expand Down Expand Up @@ -661,12 +661,11 @@ theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSiz
theorem ofNat'_eq : ∀ n, Num.ofNat' n = n :=
Nat.binaryRec (by simp) fun b n IH => by
rw [ofNat'] at IH ⊢
rw [Nat.binaryRec_eq, IH]
rw [Nat.binaryRec_eq _ _ (.inl rfl), IH]
-- Porting note: `Nat.cast_bit0` & `Nat.cast_bit1` are not `simp` theorems anymore.
· cases b <;> simp only [cond_false, cond_true, Nat.bit, two_mul, Nat.cast_add, Nat.cast_one]
· rw [bit0_of_bit0]
· rw [bit1_of_bit1]
· rfl
cases b <;> simp only [cond_false, cond_true, Nat.bit, two_mul, Nat.cast_add, Nat.cast_one]
· rw [bit0_of_bit0]
· rw [bit1_of_bit1]

theorem zneg_toZNum (n : Num) : -n.toZNum = n.toZNumNeg := by cases n <;> rfl

Expand Down
Loading