Bit.lean

Lean 4 source, lean/DataMiningAsObservation/Bit.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.

/-
Bit.lean. Chapter 0 section 0.7, the bit.

A bit is the unit of a budget. A direction quantized with `b` bits is stored at one of `2^b`
levels, so one more bit doubles the levels, halves a uniform quantizer's step, and quarters
the squared error of the high-rate model, which is the four to the minus bits of
equation 0.13. Bits add across directions, since the levels of two directions multiply.
-/
import Mathlib

namespace DMO.Bit

/-- The levels available with `b` bits. -/
def levels (b : ℕ) : ℕ := 2 ^ b

/-- **One more bit doubles the levels.** -/
theorem levels_succ (b : ℕ) : levels (b + 1) = 2 * levels b := by
  unfold levels; ring

/-- **Bits add across directions**, since the levels multiply. -/
theorem levels_add (a b : ℕ) : levels (a + b) = levels a * levels b := by
  unfold levels; exact pow_add 2 a b

/-- The step of a uniform quantizer of a range with `b` bits. -/
noncomputable def step (range : ℝ) (b : ℕ) : ℝ := range / 2 ^ b

/-- **One more bit halves the step.** -/
theorem step_succ (range : ℝ) (b : ℕ) : step range (b + 1) = step range b / 2 := by
  unfold step
  rw [pow_succ]
  ring

/-- The squared error of the high-rate model, a constant times four to the minus bits. -/
noncomputable def sqError (c : ℝ) (b : ℕ) : ℝ := c * (1 / 4) ^ b

/-- **One more bit quarters the squared error**, equation 0.13's factor. -/
theorem sqError_succ (c : ℝ) (b : ℕ) : sqError c (b + 1) = sqError c b / 4 := by
  unfold sqError
  rw [pow_succ]
  ring

/-- **The squared error falls with the bits** for a nonnegative constant. -/
theorem sqError_antitone (c : ℝ) (hc : 0 ≤ c) (b : ℕ) : sqError c (b + 1) ≤ sqError c b := by
  rw [sqError_succ]
  have : 0 ≤ sqError c b := by unfold sqError; positivity
  linarith

/-- **No bits, one level.** A direction with no bits is stored at a single value. -/
theorem levels_zero : levels 0 = 1 := rfl

end DMO.Bit