Zulip Chat Archive
Stream: general
Topic: even_odd_rec as a wrapper for binary_rec?
Stuart Presnell (Jul 16 2022 at 08:36):
Would it be reasonable to PR something like the following? This would allow recursion over even/odd numbers without having to deal with implementation details like bit0
and bit1
.
def even_odd_rec (n : ℕ) (P : ℕ → Sort*) (h0 : P 0)
(h_even : ∀ i, P i → P (2 * i))
(h_odd : ∀ i, P i → P (2 * i + 1)) : P n :=
begin
refine @binary_rec P h0 (λ b i hi, _) n,
cases b,
{ simpa [bit0_val i] using h_even i hi },
{ simpa [bit1_val i] using h_odd i hi },
end
Eric Wieser (Jul 16 2022 at 10:30):
I feel like the bit0 and bit1 version might still be more useful
Eric Wieser (Jul 16 2022 at 10:30):
Since we have lots of lemmas about those
Eric Wieser (Jul 16 2022 at 10:31):
But I can see that the one in terms of nat.bit could be annoying to use
Stuart Presnell (Jul 16 2022 at 13:18):
The bit0 and bit1 version would still be there for anyone who wants them, of course.
Stuart Presnell (Jul 16 2022 at 13:21):
It just seems wrong and inconvenient to have to drop out of the familiar world of natural numbers and into the world of bits, when we could just as easily provide the same functionality within ℕ
.
Stuart Presnell (Jul 17 2022 at 10:40):
Last updated: Dec 20 2023 at 11:08 UTC