AFTD Auto-Formalizing Theoretical Domains

cyclic_equal_cardinality_set_selection

theoremverified

For any nonempty cyclic sequence of nonempty finite sets of equal cardinality, one can select an element from each set so that, whenever the next selected element also lies in the current set, the two selected elements agree.

Statement

theorem cyclic_equal_cardinality_set_selection {Ω : Type*} [DecidableEq Ω]
    (n : ℕ) [NeZero n] (P : Fin n → Finset Ω)
    (hnonempty : ∀ i, (P i).Nonempty)
    (hcard : ∀ i j, (P i).card = (P j).card) :
    ∃ f : Fin n → Ω,
      (∀ i, f i ∈ P i) ∧
      (∀ i, f (i + 1) ∈ P i → f (i + 1) = f i)
Source
Elementary cyclic-selection lemma for the high-color cycle construction investigated for OP-874, arXiv:2610.41950.
Verified
19 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 2

The proof, explained

The proof reduces the cyclic selection problem to a linear path selection problem on $n$ sets $Q(0), \dots, Q(n-1)$ by unrolling the cyclic family $P$ via $Q(j) = P(j \pmod n)$. A known theorem (`path_selection_fixed_endpoints`) guarantees that a step-consistent selection connecting endpoints $x \in Q(0)$ and $y \in Q(n-1)$ exists as long as $x = y$ whenever $y$ is contained in every set along the path; to close the cycle at the wrap-around transition from $n-1$ back to $0$, one also needs $x = y$ whenever $x \in P(n-1)$. We find such endpoints $x$ and $y$ by checking whether $P(0) \cap P(n-1)$ is nonempty: if so, picking $x = y \in P(0) \cap P(n-1)$ trivially satisfies both conditions; if not, any choice of $x \in P(0)$ and $y \in P(n-1)$ satisfies both implications vacuously because $y \notin P(0)$ and $x \notin P(n-1)$. The resulting path selection then directly yields the desired cyclic selection.

  1. Since $n > 0$, we identify the boundary indices $0$ and $n-1$ in $\mathrm{Fin}\ n$ and unroll the cyclic family $P$ into an infinite sequence $Q : \mathbb{N} \to \mathrm{Finset}\ \Omega$ by $Q(j) = P(j \pmod n)$.

    Because $n \ne 0$, we have $n > 0$. We define the first index $\mathrm{first} = 0$ and last index $\mathrm{last} = n - 1$ in $\mathrm{Fin}\ n$, and unroll the cyclic sequence of sets into a sequence $Q : \mathbb{N} \to \mathrm{Finset}\ \Omega$ periodic modulo $n$.

    lines 8–12

    uses Nat.pos_of_ne_zero, NeZero.ne, Nat.mod_lt

      classical
      have hn : 0 < n := Nat.pos_of_ne_zero (NeZero.ne n)
      let first : Fin n := ⟨0, hn⟩
      let last : Fin n := ⟨n - 1, by omega⟩
      let Q : ℕ → Finset Ω := fun j => P ⟨j % n, Nat.mod_lt _ hn⟩
  2. Consecutive sets in $Q$ have equal cardinality, with $Q(0) = P(\mathrm{first})$ and $Q(n-1) = P(\mathrm{last})$.

    The equal-cardinality assumption on $P$ implies that each $Q(j)$ and $Q(j+1)$ have the same size. Furthermore, because $0 < n$ and $n - 1 < n$, reducing modulo $n$ identifies $Q(0)$ with $P(\mathrm{first})$ and $Q(n-1)$ with $P(\mathrm{last})$.

    lines 13–25

    uses congrArg, Fin.ext, Nat.mod_eq_of_lt

      have hQ : ∀ j, (Q j).card = (Q (j+1)).card := by
        intro j
        apply hcard
      have hQfirst : Q 0 = P first := by
        change P ⟨0 % n, Nat.mod_lt _ hn⟩ = P first
        apply congrArg P
        apply Fin.ext
        simp [first]
      have hQlast : Q (n-1) = P last := by
        change P ⟨(n-1) % n, Nat.mod_lt _ hn⟩ = P last
        apply congrArg P
        apply Fin.ext
        simp [last, Nat.mod_eq_of_lt (by omega : n-1 < n)]
  3. There exist endpoints $x \in P(\mathrm{first})$ and $y \in P(\mathrm{last})$ satisfying both the path endpoint condition ($(\forall j \le n - 1, y \in Q(j)) \implies x = y$) and the wrap-around consistency condition ($x \in P(\mathrm{last}) \implies x = y$).

    We split into cases on whether $P(\mathrm{first})$ and $P(\mathrm{last})$ have a common element. If there is some $z \in P(\mathrm{first}) \cap P(\mathrm{last})$, choosing $x = y = z$ trivially satisfies both implications because $x = y$. If they are disjoint, we choose arbitrary $x \in P(\mathrm{first})$ and $y \in P(\mathrm{last})$ using nonemptiness. Then $y \notin P(\mathrm{first}) = Q(0)$, so the hypothesis that $y$ lies in all $Q(j)$ is false (it fails at $j = 0$), making the first implication vacuously true. Similarly, $x \notin P(\mathrm{last})$, so the second implication is also vacuously true.

    lines 26–45

      have hend : ∃ x y : Ω, x ∈ P first ∧ y ∈ P last ∧
          ((∀ j ≤ n-1, y ∈ Q j) → x = y) ∧
          (x ∈ P last → x = y) := by
        by_cases h : ∃ z, z ∈ P first ∧ z ∈ P last
        · obtain ⟨z, hz1, hz2⟩ := h
          exact ⟨z, z, hz1, hz2, by intros; rfl, by intros; rfl⟩
        · obtain ⟨x, hx⟩ := hnonempty first
          obtain ⟨y, hy⟩ := hnonempty last
          have hxlast : x ∉ P last := by
            intro hmem
            exact h ⟨x, hx, hmem⟩
          have hyfirst : y ∉ P first := by
            intro hmem
            exact h ⟨y, hmem, hy⟩
          refine ⟨x, y, hx, hy, ?_, ?_⟩
          · intro hall
            exact (hyfirst (by simpa [hQfirst] using hall 0 (by omega))).elim
          · intro hmem
            exact (hxlast hmem).elim
      obtain ⟨x, y, hx, hy, hcondition, hclose⟩ := hend
  4. There exists a selection $f : \mathbb{N} \to \Omega$ on the path $Q$ with $f(0) = x$ and $f(n-1) = y$ such that $f(j) \in Q(j)$ for all $j \le n-1$, and $f(j+1) = f(j)$ whenever $f(j+1) \in Q(j)$ for $j < n-1$.

    Since $x \in Q(0)$, $y \in Q(n-1)$, and the endpoint condition holds for $(x, y)$, we invoke the path selection theorem `path_selection_fixed_endpoints` on $Q$ from $0$ to $n-1$. This guarantees the existence of a selection function $f$ satisfying the boundary values, membership, and step consistency along the path.

    lines 46–49

    uses path_selection_fixed_endpoints

      have hxQ : x ∈ Q 0 := by simpa [hQfirst] using hx
      have hyQ : y ∈ Q (n-1) := by simpa [hQlast] using hy
      obtain ⟨f, hf0, hfn, hfmem, hfstep⟩ :=
        (path_selection_fixed_endpoints Q hQ x hxQ (n-1) y hyQ).2 hcondition
  5. The restriction of $f$ to indices in $\mathrm{Fin}\ n$ provides a choice function $i \mapsto f(i)$ such that $f(i) \in P(i)$ for all $i$.

    We define the cyclic selection on $\mathrm{Fin}\ n$ by evaluating $f$ at the underlying natural value of $i$. Since $i < n$, we have $i \le n - 1$ and $i \pmod n = i$, so $Q(i) = P(i)$. The path membership property $f(i) \in Q(i)$ therefore translates directly to $f(i) \in P(i)$.

    lines 50–58

    uses congrArg, Fin.ext, Nat.mod_eq_of_lt

      refine ⟨fun i => f i.val, ?_, ?_⟩
      · intro i
        have hj : i.val ≤ n-1 := by have := i.isLt; omega
        have hi : Q i.val = P i := by
          change P ⟨i.val % n, Nat.mod_lt _ hn⟩ = P i
          apply congrArg P
          apply Fin.ext
          exact Nat.mod_eq_of_lt i.isLt
        simpa [hi] using hfmem i.val hj
  6. At the boundary index $i = \mathrm{last}$, if $f(i+1) \in P(i)$ then $f(i+1) = f(i)$.

    When $i = \mathrm{last} = n - 1$, addition in $\mathrm{Fin}\ n$ wraps around so that $\mathrm{last} + 1 = \mathrm{first} = 0$. Hence $f(i+1) = f(0) = x$ and $f(i) = f(n-1) = y$. The hypothesis $f(i+1) \in P(i)$ means $x \in P(\mathrm{last})$. By the wrap-around consistency condition chosen for $x$ and $y$, this implies $x = y$, and therefore $f(i+1) = f(i)$.

    lines 59–70

    uses Fin.ext, Fin.val_add, Fin.val_one', Nat.add_mod_mod, Nat.sub_add_cancel

      · intro i hmem
        by_cases hi : i.val = n-1
        · have hlast : i = last := by apply Fin.ext; simpa [last] using hi
          subst i
          have hwrap : last + 1 = first := by
            apply Fin.ext
            simp [first, last, Fin.val_add, Fin.val_one', Nat.add_mod_mod,
              Nat.sub_add_cancel hn]
          rw [hwrap] at hmem ⊢
          have hxlast : x ∈ P last := by simpa [first, hf0] using hmem
          have hxy := hclose hxlast
          simpa [first, last, hf0, hfn] using hxy
  7. For every interior index $i < n - 1$, if $f(i+1) \in P(i)$ then $f(i+1) = f(i)$.

    When $i < n - 1$, adding $1$ in $\mathrm{Fin}\ n$ does not wrap around and agrees with standard addition $i + 1$ in $\mathbb{N}$. Since $Q(i) = P(i)$, the assumption $f(i+1) \in P(i)$ becomes $f(i+1) \in Q(i)$, and the step property of the path selection $f$ immediately yields $f(i+1) = f(i)$.

    lines 71–82

    uses Fin.val_add_one_of_lt', congrArg, Fin.ext, Nat.mod_eq_of_lt

        · have hlt : i.val + 1 < n := by have := i.isLt; omega
          have hval : (i + 1).val = i.val + 1 := Fin.val_add_one_of_lt' hlt
          have hQ_i : Q i.val = P i := by
            change P ⟨i.val % n, Nat.mod_lt _ hn⟩ = P i
            apply congrArg P
            apply Fin.ext
            exact Nat.mod_eq_of_lt i.isLt
          have hstep := hfstep i.val (by omega)
          change f (i + 1).val ∈ P i at hmem
          change f (i + 1).val = f i.val
          rw [hval] at hmem ⊢
          exact hstep (by simpa [hQ_i] using hmem)
Nat.pos_of_ne_zero
A nonzero natural number is strictly positive ($n \neq 0 \implies 0 < n$).
NeZero.ne
Any element with a `NeZero` instance is nonzero.
Nat.mod_lt
The remainder of integer division $x \pmod y$ is strictly less than $y$, provided $y > 0$.
congrArg
Applying a function to equal inputs yields equal outputs ($a_1 = a_2 \implies f(a_1) = f(a_2)$).
Fin.ext
Two elements of $\mathrm{Fin}\ n$ are equal if and only if their underlying natural values are equal.
Nat.mod_eq_of_lt
If $a < b$, then $a \pmod b = a$.
path_selection_fixed_endpoints
Along a path of equal-cardinality finite sets, there exists a step-consistent selection connecting fixed endpoints $x \in P(0)$ and $y \in P(n)$ if and only if $x = y$ whenever $y$ belongs to every set in the path.
Fin.val_add
The underlying natural value of the sum $a + b$ in $\mathrm{Fin}\ n$ is $(a + b) \pmod n$.
Fin.val_one'
In $\mathrm{Fin}\ n$ with $n > 0$, the underlying natural value of $1$ is $1 \pmod n$.
Nat.add_mod_mod
For natural numbers, $(m + (n \pmod k)) \pmod k = (m + n) \pmod k$.
Nat.sub_add_cancel
If $m \le n$, then $(n - m) + m = n$.
Fin.val_add_one_of_lt'
If $i + 1 < n$, then the underlying value of $i + 1$ in $\mathrm{Fin}\ n$ is $i + 1$.

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

theorem cyclic_equal_cardinality_set_selection {Ω : Type*} [DecidableEq Ω]    (n : ℕ) [NeZero n] (P : Fin n → Finset Ω)    (hnonempty : ∀ i, (P i).Nonempty)    (hcard : ∀ i j, (P i).card = (P j).card) :    ∃ f : Fin n → Ω,      (∀ i, f i ∈ P i) ∧      (∀ i, f (i + 1) ∈ P i → f (i + 1) = f i) := by  classical  have hn : 0 < n := Nat.pos_of_ne_zero (NeZero.ne n)  let first : Fin n := ⟨0, hn⟩  let last : Fin n := ⟨n - 1, by omega⟩  let Q : ℕ → Finset Ω := fun j => P ⟨j % n, Nat.mod_lt _ hn⟩  have hQ : ∀ j, (Q j).card = (Q (j+1)).card := by    intro j    apply hcard  have hQfirst : Q 0 = P first := by    change P ⟨0 % n, Nat.mod_lt _ hn⟩ = P first    apply congrArg P    apply Fin.ext    simp [first]  have hQlast : Q (n-1) = P last := by    change P ⟨(n-1) % n, Nat.mod_lt _ hn⟩ = P last    apply congrArg P    apply Fin.ext    simp [last, Nat.mod_eq_of_lt (by omega : n-1 < n)]  have hend : ∃ x y : Ω, x ∈ P first ∧ y ∈ P last ∧      ((∀ j ≤ n-1, y ∈ Q j) → x = y) ∧      (x ∈ P last → x = y) := by    by_cases h : ∃ z, z ∈ P first ∧ z ∈ P last    · obtain ⟨z, hz1, hz2⟩ := h      exact ⟨z, z, hz1, hz2, by intros; rfl, by intros; rfl⟩    · obtain ⟨x, hx⟩ := hnonempty first      obtain ⟨y, hy⟩ := hnonempty last      have hxlast : x ∉ P last := by        intro hmem        exact h ⟨x, hx, hmem⟩      have hyfirst : y ∉ P first := by        intro hmem        exact h ⟨y, hmem, hy⟩      refine ⟨x, y, hx, hy, ?_, ?_⟩      · intro hall        exact (hyfirst (by simpa [hQfirst] using hall 0 (by omega))).elim      · intro hmem        exact (hxlast hmem).elim  obtain ⟨x, y, hx, hy, hcondition, hclose⟩ := hend  have hxQ : x ∈ Q 0 := by simpa [hQfirst] using hx  have hyQ : y ∈ Q (n-1) := by simpa [hQlast] using hy  obtain ⟨f, hf0, hfn, hfmem, hfstep⟩ :=    (path_selection_fixed_endpoints Q hQ x hxQ (n-1) y hyQ).2 hcondition  refine ⟨fun i => f i.val, ?_, ?_⟩  · intro i    have hj : i.val ≤ n-1 := by have := i.isLt; omega    have hi : Q i.val = P i := by      change P ⟨i.val % n, Nat.mod_lt _ hn⟩ = P i      apply congrArg P      apply Fin.ext      exact Nat.mod_eq_of_lt i.isLt    simpa [hi] using hfmem i.val hj  · intro i hmem    by_cases hi : i.val = n-1    · have hlast : i = last := by apply Fin.ext; simpa [last] using hi      subst i      have hwrap : last + 1 = first := by        apply Fin.ext        simp [first, last, Fin.val_add, Fin.val_one', Nat.add_mod_mod,          Nat.sub_add_cancel hn]      rw [hwrap] at hmem ⊢      have hxlast : x ∈ P last := by simpa [first, hf0] using hmem      have hxy := hclose hxlast      simpa [first, last, hf0, hfn] using hxy    · have hlt : i.val + 1 < n := by have := i.isLt; omega      have hval : (i + 1).val = i.val + 1 := Fin.val_add_one_of_lt' hlt      have hQ_i : Q i.val = P i := by        change P ⟨i.val % n, Nat.mod_lt _ hn⟩ = P i        apply congrArg P        apply Fin.ext        exact Nat.mod_eq_of_lt i.isLt      have hstep := hfstep i.val (by omega)      change f (i + 1).val ∈ P i at hmem      change f (i + 1).val = f i.val      rw [hval] at hmem ⊢      exact hstep (by simpa [hQ_i] using hmem)
See it in the graphDiscuss this resultChallenge it