Documentation

CslibFrontier.Foundations.Data.Nat.Radix.Digit

Digit sums for fixed-position digits #

Lemmas about the fixed-position, zero-padded digits Cslib.Radix.digit of CslibFrontier/Foundations/Data/Nat/Radix.lean: a digit is below a positive radix, the first k digits recover x modulo B ^ k, and the base-2 digits are the bits of Nat.testBit.

Main results #

theorem Cslib.Radix.digit_lt {B : ℕ} (hB : 0 < B) (x i : ℕ) :
digit B x i < B

A digit is below a positive radix.

theorem Cslib.Radix.sum_digit_mul_pow (B x k : ℕ) :
∑ i ∈ Finset.range k, B ^ i * digit B x i = x % B ^ k

The first k base-B digits of x recover x modulo B ^ k.

The bit j of x is its base-2 digit j.

theorem Nat.sum_two_pow_mul_testBit {n w : ℕ} (hn : n < 2 ^ w) :
∑ i : Fin w, 2 ^ ↑i * (n.testBit ↑i).toNat = n

A natural below 2 ^ w is the sum of the place values of its first w binary digits.