hamming_weight
def
The Hamming weight of a Boolean vector x is the number of true coordinates.
Statement
def hamming_weight {n : ℕ} (x : Fin n → Bool) : ℕ- Defined in
- scout/2611-21910-new-gate-weight-and-wire-complexity-bounds-for-sigmoid-neur.md:713
- Verified
- 18 Nov 2026
- Axioms
- none listed
- Used by 2
- is_symmetric_boolean_funcA Boolean function f on n variables is symmetric if its value on any input depends only on the Hamming weight of the input.
- symmetric_boolean_func_depth3_sigmoid_circuitFor every symmetric Boolean function f on n ≥ 1 variables, there exists a depth-3 sigmoidal circuit C on n inputs with at most 3n wires…
Read back from the Lean
hamming_weight defines a function that, given an implicit natural number n and a function x : Fin n → Bool, returns the number of indices i : Fin n for which x i = true (computed as the cardinality of the filtered universal Finset).
Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.
Lean source view module on GitHub
/-- The Hamming weight of a Boolean vector x in {0,1}^n. -/ def hamming_weight {n : ℕ} (x : Fin n → Bool) : ℕ := (Finset.univ.filter (fun i => x i = true)).card