mathlib documentation

data.nat.bits

Additional properties of binary recursion on nat #

This file documents additional properties of binary recursion, which allows us to more easily work with operations which do depend on the number of leading zeros in the binary representation of n. For example, we can more easily work with nat.bits and nat.size.

See also: nat.bitwise, nat.pow (for various lemmas about size and shiftl/shiftr), and nat.digits.

theorem nat.bit_eq_zero_iff {n : } {b : bool} :
nat.bit b n = 0 n = 0 b = bool.ff
theorem nat.binary_rec_eq' {C : Sort u_1} {z : C 0} {f : Π (b : bool) (n : ), C nC (nat.bit b n)} (b : bool) (n : ) (h : f bool.ff 0 z = z (n = 0b = bool.tt)) :
nat.binary_rec z f (nat.bit b n) = f b n (nat.binary_rec z f n)

The same as binary_rec_eq, but that one unfortunately requires f to be the identity when appending ff to 0. Here, we allow you to explicitly say that that case is not happening, i.e. supplying n = 0 → b = tt.

def nat.binary_rec' {C : Sort u_1} (z : C 0) (f : Π (b : bool) (n : ), (n = 0b = bool.tt)C nC (nat.bit b n)) (n : ) :
C n

The same as binary_rec, but the induction step can assume that if n=0, the bit being appended is tt

Equations
def nat.binary_rec_from_one {C : Sort u_1} (z₀ : C 0) (z₁ : C 1) (f : Π (b : bool) (n : ), n 0C nC (nat.bit b n)) (n : ) :
C n

The same as binary_rec, but special casing both 0 and 1 as base cases

Equations
@[simp]
theorem nat.zero_bits  :
@[simp]
theorem nat.bits_append_bit (n : ) (b : bool) (hn : n = 0b = bool.tt) :
(nat.bit b n).bits = b :: n.bits
@[simp]
theorem nat.bit0_bits (n : ) (hn : n 0) :
@[simp]
theorem nat.bit1_bits (n : ) :
@[simp]
theorem nat.one_bits  :
theorem nat.bodd_eq_bits_head (n : ) :