Lean library · module TopologyByExample.Slices.SparseBounds

Cardinality bounds from sparse row certificates

Source file

A family of distinct realised rows gives a lower bound, and a candidate cover gives an upper bound. Neither argument enumerates all Boolean rows. Bounded natural-number encodings provide a convenient way to certify that a finite family of rows is distinct.

This file was written by Codex (OpenAI's AI model) working under the direction of David R. MacIver, who reviews it and is responsible for it.

Imports

theorem le_ncard_of_witnesses

TopologyByExample.Slices.Sparse.le_ncard_of_witnesses

Distinct rows belonging to a set give a lower bound on its cardinality.

theorem le_ncard_of_witnesses {n m : ℕ} (S : Set (Row n)) (witnesses : Fin m → Row n)
    (distinct : Function.Injective witnesses) (realised : ∀ i, witnesses i ∈ S) :
    m ≤ S.ncard
Proof
:= by
  calc
    m = (Set.range witnesses).ncard := by
      simp [Set.ncard_range_of_injective distinct]
    _ ≤ S.ncard := Set.ncard_le_ncard (by
      rintro r ⟨i, rfl⟩
      exact realised i) (Set.toFinite S)

theorem ncard_le_of_cover

TopologyByExample.Slices.Sparse.ncard_le_of_cover

A finite family covering a set of rows gives an upper bound on its cardinality.

theorem ncard_le_of_cover {n k : ℕ} (S : Set (Row n)) (candidates : Fin k → Row n)
    (covered : ∀ r ∈ S, ∃ i, r = candidates i) : S.ncard ≤ k
Proof
:= by
  calc
    S.ncard ≤ (Set.range candidates).ncard := Set.ncard_le_ncard (by
      intro r hr
      obtain ⟨i, hi⟩ := covered r hr
      exact ⟨i, hi.symm⟩) (Set.finite_range candidates)
    _ ≤ k := by
      rw [← Set.image_univ]
      simpa using Set.ncard_image_le (f := candidates) (s := Set.univ)

theorem bitRows_injective

TopologyByExample.Slices.Sparse.bitRows_injective

Distinct natural numbers below 2 ^ n encode distinct n-coordinate Boolean rows.

theorem bitRows_injective {n m : ℕ} (words : Fin m → ℕ)
    (bounded : ∀ i, words i < 2 ^ n) (distinct : Function.Injective words) :
    Function.Injective (fun i (j : Fin n) ↦ (words i).testBit j.val)
Proof
:= by
  intro i j h
  apply distinct
  apply Nat.eq_of_testBit_eq
  intro k
  by_cases hk : k < n
  · exact congrFun h ⟨k, hk⟩
  · have hn : n ≤ k := Nat.le_of_not_gt hk
    have hp : 2 ^ n ≤ 2 ^ k := Nat.pow_le_pow_right (by decide) hn
    rw [Nat.testBit_eq_false_of_lt ((bounded i).trans_le hp),
      Nat.testBit_eq_false_of_lt ((bounded j).trans_le hp)]