pith. machine review for the scientific record. sign in
theorem

nonzero_card

proved
show as:
view math explainer →
module
IndisputableMonolith.Algebra.F2Power
domain
Algebra
line
126 · github
papers citing
none yet

open explainer

Read the cached plain-language explainer.

open lean source

IndisputableMonolith.Algebra.F2Power on GitHub at line 126.

browse module

All declarations in this module, on Recognition.

explainer page

A cached Ask Recognition explainer exists for this declaration.

open explainer

depends on

used by

formal source

 123  simp [Fintype.card_bool, Fintype.card_fin]
 124
 125/-- The number of non-zero vectors in `F2Power D` is `2 ^ D - 1`. -/
 126theorem nonzero_card :
 127    (Finset.univ.filter (fun v : F2Power D => v ≠ 0)).card = 2 ^ D - 1 := by
 128  have h : (Finset.univ.filter (fun v : F2Power D => v ≠ 0)).card =
 129           Fintype.card (F2Power D) - 1 := by
 130    rw [show (Finset.univ.filter (fun v : F2Power D => v ≠ 0)) =
 131            Finset.univ.erase 0 from ?_, Finset.card_erase_of_mem (Finset.mem_univ _)]
 132    · rfl
 133    · ext v
 134      simp [Finset.mem_filter, Finset.mem_erase, Finset.mem_univ]
 135  rw [h, card_eq]
 136
 137/-- At `D = 3`, the non-zero count is `7`. The seven Booker plot
 138    families bijection in `Aesthetics.NarrativeGeodesic` chains off
 139    this corollary. -/
 140theorem nonzero_card_three :
 141    (Finset.univ.filter (fun v : F2Power 3 => v ≠ 0)).card = 7 := by
 142  have h := @nonzero_card 3
 143  -- h : … = 2 ^ 3 - 1
 144  have h2 : (2 : ℕ) ^ 3 - 1 = 7 := by norm_num
 145  rw [h2] at h
 146  exact h
 147
 148/-! ## Hamming weight -/
 149
 150/-- The Hamming weight of `v`: the number of coordinates equal to
 151    `true`. -/
 152def hammingWeight (v : F2Power D) : ℕ :=
 153  (Finset.univ.filter (fun i => v i = true)).card
 154
 155@[simp] theorem hammingWeight_zero : hammingWeight (0 : F2Power D) = 0 := by
 156  unfold hammingWeight