AFTD Auto-Formalizing Theoretical Domains

list_switches

def

The function list_switches counts the number of indices where adjacent elements in a list of booleans differ, defined recursively.

Statement

def list_switches : List Bool → ℕ
Defined in
arXiv:2611.28727 Fig. 9
Verified
29 Nov 2026
Axioms
none listed
Used by 2
  • switch_seqFor natural numbers n and k, switch_seq n k is the finite set of functions from Fin n to Bool having at most k switches in their sequence…
  • list_switches_nilThe number of switches in the empty list of booleans is zero.

Read back from the Lean

list_switches is a function from List Bool to ℕ defined by recursion on the list: - If the list has at least two elements a :: b :: l, it returns (if a = b then 0 else 1) + list_switches (b :: l). - Otherwise (if the list has length less than 2, i.e., [] or [x]), it returns 0. In other words, it counts the number of adjacent pairs of elements in the list that are distinct (the number of switches/transitions between consecutive boolean values).

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 number of label switches between adjacent elements in a list of booleans. -/
def list_switches : List Bool → ℕ
| a :: b :: l => (if a = b then 0 else 1) + list_switches (b :: l)
| _ => 0
See it in the graphDiscuss this resultChallenge it