AFTD Auto-Formalizing Theoretical Domains

twin_star_leaf_count

theoremverifiedformalization

For any natural number d ≥ 2, the number of leaves graph_leaf_count of the twin-star graph TS_d on Fin d ⊕ Fin d is equal to 2 * d - 2.

Statement

open Classical in
theorem twin_star_leaf_count (d : ℕ) (hd : 2 ≤ d) :
    graph_leaf_count (twin_star d) = 2 * d - 2
Formalizes
arXiv:2611.19473, Lemma 2.7
Verified
22 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 2
  • graph_leaf_countThe number of leaves of a simple graph on a finite vertex type is the number of vertices with degree 1.
  • twin_starFor any natural number d, the twin-star graph TS_d is the simple graph on vertex type Fin d ⊕ Fin d, where distinct vertices x and y are…

Read back from the Lean

For every natural number $d$ satisfying $2 \le d$, the number of leaves (vertices of degree 1) in the graph twin_star d is equal to $2 * d - 2$.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

The proof, explained

The twin-star graph TS_d consists of two star graphs, each with a central vertex of index 0 and d - 1 leaves of index 1 through d - 1, connected by an edge between the two centers. The argument first characterizes the leaves (vertices of degree 1) as precisely those with a non-zero index: the two centers each have degree at least 2 because d ≥ 2, while every non-center vertex connects solely to its own center. Counting the leaves then amounts to taking the cardinality of the disjoint sum of the non-zero elements in Fin d with itself, which yields (d - 1) + (d - 1) = 2d - 2.

  1. For any non-zero index i, the unique neighbor of Sum.inl i is the left center Sum.inl 0.

    By the definition of twin_star, edges between two left vertices require one index to be 0 and the other non-zero; since i ≠ 0, any left neighbor must have index 0. Moreover, cross-edges between left and right vertices can only connect the two central vertices (index 0 on both sides), which cannot connect to Sum.inl i since i ≠ 0. Therefore, the neighbor set is precisely {Sum.inl 0}.

    lines 1–22

    uses SimpleGraph.mem_neighborFinset, Finset.mem_singleton

    open Classical in
    private theorem twin_star_leaf_count_nf_inl (d : ℕ) (hd : 2 ≤ d) (i : Fin d) (hi : i.val ≠ 0) :
        (twin_star d).neighborFinset (Sum.inl i) = {Sum.inl ⟨0, by omega⟩} := by
      ext (y | y)
      · rw [SimpleGraph.mem_neighborFinset, Finset.mem_singleton]
        dsimp [twin_star, SimpleGraph.fromRel]
        constructor
        · rintro ⟨_, ⟨hi0, -⟩ | ⟨hy0, -⟩⟩
          · contradiction
          · congr 1; ext; exact hy0
        · intro h
          injection h with hy
          subst hy
          refine ⟨by intro h; injection h with h; exact hi (by subst h; rfl), Or.inr ⟨rfl, hi⟩⟩
      · rw [SimpleGraph.mem_neighborFinset, Finset.mem_singleton]
        dsimp [twin_star, SimpleGraph.fromRel]
        constructor
        · rintro ⟨-, ⟨hi0, -⟩ | h_false⟩
          · contradiction
          · contradiction
        · intro h; contradiction
    
  2. For any non-zero index i, the unique neighbor of Sum.inr i is the right center Sum.inr 0.

    Symmetrically, any right neighbor of Sum.inr i must have index 0, and no cross-edges to the left side exist for a vertex with non-zero index. Hence, the neighbor set of Sum.inr i is precisely {Sum.inr 0}.

    lines 23–44

    uses SimpleGraph.mem_neighborFinset, Finset.mem_singleton

    open Classical in
    private theorem twin_star_leaf_count_nf_inr (d : ℕ) (hd : 2 ≤ d) (i : Fin d) (hi : i.val ≠ 0) :
        (twin_star d).neighborFinset (Sum.inr i) = {Sum.inr ⟨0, by omega⟩} := by
      ext (y | y)
      · rw [SimpleGraph.mem_neighborFinset, Finset.mem_singleton]
        dsimp [twin_star, SimpleGraph.fromRel]
        constructor
        · rintro ⟨-, h_false | ⟨hy0, hi0⟩⟩
          · contradiction
          · exact (hi hi0).elim
        · intro h; contradiction
      · rw [SimpleGraph.mem_neighborFinset, Finset.mem_singleton]
        dsimp [twin_star, SimpleGraph.fromRel]
        constructor
        · rintro ⟨_, ⟨hi0, -⟩ | ⟨hy0, -⟩⟩
          · contradiction
          · congr 1; ext; exact hy0
        · intro h
          injection h with hy
          subst hy
          refine ⟨by intro h; injection h with h; exact hi (by subst h; rfl), Or.inr ⟨rfl, hi⟩⟩
    
  3. The left center vertex Sum.inl 0 does not have degree 1.

    Since d ≥ 2, we can identify two distinct neighbors of Sum.inl 0: the right center a = Sum.inr 0 and the left leaf b = Sum.inl 1. Since {a, b} is a subset of the neighbor set and |{a, b}| = 2, the degree is at least 2, and therefore cannot be 1.

    lines 45–73

    uses SimpleGraph.mem_neighborFinset, Finset.mem_insert, Finset.mem_singleton, Finset.card_le_card, Finset.card_pair

    open Classical in
    private theorem twin_star_leaf_count_deg_inl_zero (d : ℕ) (hd : 2 ≤ d) (i : Fin d) (hi : i.val = 0) :
        (twin_star d).degree (Sum.inl i) ≠ 1 := by
      let a : Fin d ⊕ Fin d := Sum.inr ⟨0, by omega⟩
      let b : Fin d ⊕ Fin d := Sum.inl ⟨1, by omega⟩
      have hab : a ≠ b := by intro h; contradiction
      have ha : a ∈ (twin_star d).neighborFinset (Sum.inl i) := by
        rw [SimpleGraph.mem_neighborFinset]
        dsimp [twin_star, SimpleGraph.fromRel, a]
        refine ⟨by intro h; contradiction, Or.inl ⟨hi, rfl⟩⟩
      have hb : b ∈ (twin_star d).neighborFinset (Sum.inl i) := by
        rw [SimpleGraph.mem_neighborFinset]
        dsimp [twin_star, SimpleGraph.fromRel, b]
        refine ⟨?_, Or.inl ⟨hi, by decide⟩⟩
        intro h
        injection h with h
        have : (⟨1, by omega⟩ : Fin d).val = 1 := rfl
        have : i.val = 1 := by rw [h]
        omega
      intro h
      have hsub : {a, b} ⊆ (twin_star d).neighborFinset (Sum.inl i) := by
        intro x hx
        simp only [Finset.mem_insert, Finset.mem_singleton] at hx
        rcases hx with rfl | rfl <;> assumption
      have hle := Finset.card_le_card hsub
      rw [Finset.card_pair hab] at hle
      change ((twin_star d).neighborFinset (Sum.inl i)).card = 1 at h
      omega
    
  4. The right center vertex Sum.inr 0 does not have degree 1.

    Symmetrically, the right center Sum.inr 0 has at least two distinct neighbors: the left center a = Sum.inl 0 and the right leaf b = Sum.inr 1. Thus its degree is at least 2, ruling out degree 1.

    lines 74–102

    uses SimpleGraph.mem_neighborFinset, Finset.mem_insert, Finset.mem_singleton, Finset.card_le_card, Finset.card_pair

    open Classical in
    private theorem twin_star_leaf_count_deg_inr_zero (d : ℕ) (hd : 2 ≤ d) (i : Fin d) (hi : i.val = 0) :
        (twin_star d).degree (Sum.inr i) ≠ 1 := by
      let a : Fin d ⊕ Fin d := Sum.inl ⟨0, by omega⟩
      let b : Fin d ⊕ Fin d := Sum.inr ⟨1, by omega⟩
      have hab : a ≠ b := by intro h; contradiction
      have ha : a ∈ (twin_star d).neighborFinset (Sum.inr i) := by
        rw [SimpleGraph.mem_neighborFinset]
        dsimp [twin_star, SimpleGraph.fromRel, a]
        refine ⟨by intro h; contradiction, Or.inr ⟨rfl, hi⟩⟩
      have hb : b ∈ (twin_star d).neighborFinset (Sum.inr i) := by
        rw [SimpleGraph.mem_neighborFinset]
        dsimp [twin_star, SimpleGraph.fromRel, b]
        refine ⟨?_, Or.inl ⟨hi, by decide⟩⟩
        intro h
        injection h with h
        have : (⟨1, by omega⟩ : Fin d).val = 1 := rfl
        have : i.val = 1 := by rw [h]
        omega
      intro h
      have hsub : {a, b} ⊆ (twin_star d).neighborFinset (Sum.inr i) := by
        intro x hx
        simp only [Finset.mem_insert, Finset.mem_singleton] at hx
        rcases hx with rfl | rfl <;> assumption
      have hle := Finset.card_le_card hsub
      rw [Finset.card_pair hab] at hle
      change ((twin_star d).neighborFinset (Sum.inr i)).card = 1 at h
      omega
    
  5. The leaf count equals the cardinality of the finset of vertices with degree 1.

    By definition, graph_leaf_count filters Finset.univ for vertices of degree 1 and takes the cardinality.

    lines 103–107

    open Classical in
    /-- The twin-star graph TS_d has exactly 2d - 2 leaves for d ≥ 2. -/
    theorem twin_star_leaf_count (d : ℕ) (hd : 2 ≤ d) :
        graph_leaf_count (twin_star d) = 2 * d - 2 := by
      change (Finset.univ.filter (fun v => (twin_star d).degree v = 1)).card = 2 * d - 2
  6. A vertex has degree 1 if and only if its index is non-zero.

    By the previous helper lemmas, the center vertices (index 0) have degree different from 1, whereas every non-center vertex (index i ≠ 0) has a singleton neighborhood and thus has degree 1. Applying Finset.filter_congr replaces the condition degree(v) = 1 with the condition that the index is non-zero.

    lines 108–131

    uses twin_star_leaf_count_deg_inl_zero, twin_star_leaf_count_nf_inl, Finset.card_singleton, twin_star_leaf_count_deg_inr_zero, twin_star_leaf_count_nf_inr, Finset.filter_congr

      have h_iff : ∀ v : Fin d ⊕ Fin d,
          ((twin_star d).degree v = 1) ↔ (match v with | .inl i => i.val ≠ 0 | .inr i => i.val ≠ 0) := by
        intro v
        rcases v with i | i
        · dsimp only
          by_cases hi : i.val = 0
          · have hdeg := twin_star_leaf_count_deg_inl_zero d hd i hi
            simp [hi, hdeg]
          · simp [hi]
            have hnf := twin_star_leaf_count_nf_inl d hd i hi
            change ((twin_star d).neighborFinset (Sum.inl i)).card = 1
            rw [hnf, Finset.card_singleton]
        · dsimp only
          by_cases hi : i.val = 0
          · have hdeg := twin_star_leaf_count_deg_inr_zero d hd i hi
            simp [hi, hdeg]
          · simp [hi]
            have hnf := twin_star_leaf_count_nf_inr d hd i hi
            change ((twin_star d).neighborFinset (Sum.inr i)).card = 1
            rw [hnf, Finset.card_singleton]
      have h_filter : Finset.univ.filter (fun v => (twin_star d).degree v = 1) =
          Finset.univ.filter (fun v => match v with | .inl i => i.val ≠ 0 | .inr i => i.val ≠ 0) :=
        Finset.filter_congr (fun v _ => h_iff v)
      rw [h_filter]
  7. The filtered vertex set decomposes into the disjoint sum of non-zero left indices and non-zero right indices.

    The condition on Sum.inl i and Sum.inr i splits the filtered set of Fin d ⊕ Fin d into the disjoint sum of {i : Fin d | i.val ≠ 0} with itself. By Finset.card_disjSum, the total size is the sum of their individual sizes.

    lines 132–139

    uses Finset.card_disjSum

      have h_disj : (Finset.univ.filter (fun (v : Fin d ⊕ Fin d) =>
            match v with | .inl i => i.val ≠ 0 | .inr i => i.val ≠ 0)) =
          ((Finset.univ.filter (fun (i : Fin d) => i.val ≠ 0)).disjSum
           (Finset.univ.filter (fun (i : Fin d) => i.val ≠ 0))) := by
        change (Finset.disjSum Finset.univ Finset.univ).filter
          (fun (v : Fin d ⊕ Fin d) => match v with | .inl i => i.val ≠ 0 | .inr i => i.val ≠ 0) = _
        ext (x | y) <;> simp
      rw [h_disj, Finset.card_disjSum]
  8. The twin-star graph has exactly 2 * d - 2 leaves.

    In Fin d, the elements with index equal to 0 form the singleton {0}, which has size 1. Since the total size of Fin d is d, the number of non-zero indices is d - 1. Summing the two copies yields (d - 1) + (d - 1) = 2 * d - 2.

    lines 140–146

    uses Finset.card_filter_add_card_filter_not, Fin.ext_iff, Finset.card_singleton, Finset.card_univ, Fintype.card_fin

      have h_add := Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset (Fin d)))
        (p := fun (i : Fin d) => i.val ≠ 0)
      have h_not : (Finset.univ.filter (fun (i : Fin d) => ¬(i.val ≠ 0))) = {⟨0, by omega⟩} := by
        ext ⟨x, hx⟩
        simp [Fin.ext_iff]
      rw [h_not, Finset.card_singleton, Finset.card_univ, Fintype.card_fin] at h_add
      omega
Fin.ext_iff
Two elements of Fin n are equal if and only if their underlying natural values are equal.
Finset.card_univ
The cardinality of Finset.univ for a finite type is the cardinality of that type.
Fintype.card_fin
The cardinality of Fin n is n.
SimpleGraph.mem_neighborFinset
A vertex w is in the neighbor finset of v in graph G if and only if v and w are adjacent.
Finset.mem_singleton
An element b is in the singleton finset {a} if and only if b = a.
Finset.mem_insert
An element a is in insert b s if and only if a = b or a ∈ s.
Finset.card_le_card
If finset s is a subset of finset t, then the cardinality of s is at most that of t.
Finset.card_pair
If a ≠ b, the two-element set {a, b} has cardinality 2.
Finset.card_singleton
A singleton finset {a} has cardinality 1.
Finset.filter_congr
Filtering with two predicates that are equivalent on all elements of a finset produces the same finset.
Finset.card_disjSum
The cardinality of the disjoint sum of two finsets is the sum of their individual cardinalities.
Finset.card_filter_add_card_filter_not
The number of elements of s satisfying predicate p plus the number satisfying ¬p equals the cardinality of s.
twin_star_leaf_count_deg_inl_zero
In the twin-star graph TS_d (d ≥ 2), the left center vertex with index 0 does not have degree 1.
twin_star_leaf_count_nf_inl
In the twin-star graph TS_d (d ≥ 2), any left vertex with index i ≠ 0 has neighbor finset {Sum.inl 0}.
twin_star_leaf_count_deg_inr_zero
In the twin-star graph TS_d (d ≥ 2), the right center vertex with index 0 does not have degree 1.
twin_star_leaf_count_nf_inr
In the twin-star graph TS_d (d ≥ 2), any right vertex with index i ≠ 0 has neighbor finset {Sum.inr 0}.

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

open Classical inprivate theorem twin_star_leaf_count_nf_inl (d : ℕ) (hd : 2 ≤ d) (i : Fin d) (hi : i.val ≠ 0) :    (twin_star d).neighborFinset (Sum.inl i) = {Sum.inl ⟨0, by omega⟩} := by  ext (y | y)  · rw [SimpleGraph.mem_neighborFinset, Finset.mem_singleton]    dsimp [twin_star, SimpleGraph.fromRel]    constructor    · rintro ⟨_, ⟨hi0, -⟩ | ⟨hy0, -⟩⟩      · contradiction      · congr 1; ext; exact hy0    · intro h      injection h with hy      subst hy      refine ⟨by intro h; injection h with h; exact hi (by subst h; rfl), Or.inr ⟨rfl, hi⟩⟩  · rw [SimpleGraph.mem_neighborFinset, Finset.mem_singleton]    dsimp [twin_star, SimpleGraph.fromRel]    constructor    · rintro ⟨-, ⟨hi0, -⟩ | h_false⟩      · contradiction      · contradiction    · intro h; contradictionopen Classical inprivate theorem twin_star_leaf_count_nf_inr (d : ℕ) (hd : 2 ≤ d) (i : Fin d) (hi : i.val ≠ 0) :    (twin_star d).neighborFinset (Sum.inr i) = {Sum.inr ⟨0, by omega⟩} := by  ext (y | y)  · rw [SimpleGraph.mem_neighborFinset, Finset.mem_singleton]    dsimp [twin_star, SimpleGraph.fromRel]    constructor    · rintro ⟨-, h_false | ⟨hy0, hi0⟩⟩      · contradiction      · exact (hi hi0).elim    · intro h; contradiction  · rw [SimpleGraph.mem_neighborFinset, Finset.mem_singleton]    dsimp [twin_star, SimpleGraph.fromRel]    constructor    · rintro ⟨_, ⟨hi0, -⟩ | ⟨hy0, -⟩⟩      · contradiction      · congr 1; ext; exact hy0    · intro h      injection h with hy      subst hy      refine ⟨by intro h; injection h with h; exact hi (by subst h; rfl), Or.inr ⟨rfl, hi⟩⟩open Classical inprivate theorem twin_star_leaf_count_deg_inl_zero (d : ℕ) (hd : 2 ≤ d) (i : Fin d) (hi : i.val = 0) :    (twin_star d).degree (Sum.inl i) ≠ 1 := by  let a : Fin d ⊕ Fin d := Sum.inr ⟨0, by omega⟩  let b : Fin d ⊕ Fin d := Sum.inl ⟨1, by omega⟩  have hab : a ≠ b := by intro h; contradiction  have ha : a ∈ (twin_star d).neighborFinset (Sum.inl i) := by    rw [SimpleGraph.mem_neighborFinset]    dsimp [twin_star, SimpleGraph.fromRel, a]    refine ⟨by intro h; contradiction, Or.inl ⟨hi, rfl⟩⟩  have hb : b ∈ (twin_star d).neighborFinset (Sum.inl i) := by    rw [SimpleGraph.mem_neighborFinset]    dsimp [twin_star, SimpleGraph.fromRel, b]    refine ⟨?_, Or.inl ⟨hi, by decide⟩⟩    intro h    injection h with h    have : (⟨1, by omega⟩ : Fin d).val = 1 := rfl    have : i.val = 1 := by rw [h]    omega  intro h  have hsub : {a, b} ⊆ (twin_star d).neighborFinset (Sum.inl i) := by    intro x hx    simp only [Finset.mem_insert, Finset.mem_singleton] at hx    rcases hx with rfl | rfl <;> assumption  have hle := Finset.card_le_card hsub  rw [Finset.card_pair hab] at hle  change ((twin_star d).neighborFinset (Sum.inl i)).card = 1 at h  omegaopen Classical inprivate theorem twin_star_leaf_count_deg_inr_zero (d : ℕ) (hd : 2 ≤ d) (i : Fin d) (hi : i.val = 0) :    (twin_star d).degree (Sum.inr i) ≠ 1 := by  let a : Fin d ⊕ Fin d := Sum.inl ⟨0, by omega⟩  let b : Fin d ⊕ Fin d := Sum.inr ⟨1, by omega⟩  have hab : a ≠ b := by intro h; contradiction  have ha : a ∈ (twin_star d).neighborFinset (Sum.inr i) := by    rw [SimpleGraph.mem_neighborFinset]    dsimp [twin_star, SimpleGraph.fromRel, a]    refine ⟨by intro h; contradiction, Or.inr ⟨rfl, hi⟩⟩  have hb : b ∈ (twin_star d).neighborFinset (Sum.inr i) := by    rw [SimpleGraph.mem_neighborFinset]    dsimp [twin_star, SimpleGraph.fromRel, b]    refine ⟨?_, Or.inl ⟨hi, by decide⟩⟩    intro h    injection h with h    have : (⟨1, by omega⟩ : Fin d).val = 1 := rfl    have : i.val = 1 := by rw [h]    omega  intro h  have hsub : {a, b} ⊆ (twin_star d).neighborFinset (Sum.inr i) := by    intro x hx    simp only [Finset.mem_insert, Finset.mem_singleton] at hx    rcases hx with rfl | rfl <;> assumption  have hle := Finset.card_le_card hsub  rw [Finset.card_pair hab] at hle  change ((twin_star d).neighborFinset (Sum.inr i)).card = 1 at h  omegaopen Classical in/-- The twin-star graph TS_d has exactly 2d - 2 leaves for d ≥ 2. -/theorem twin_star_leaf_count (d : ℕ) (hd : 2 ≤ d) :    graph_leaf_count (twin_star d) = 2 * d - 2 := by  change (Finset.univ.filter (fun v => (twin_star d).degree v = 1)).card = 2 * d - 2  have h_iff : ∀ v : Fin d ⊕ Fin d,      ((twin_star d).degree v = 1) ↔ (match v with | .inl i => i.val ≠ 0 | .inr i => i.val ≠ 0) := by    intro v    rcases v with i | i    · dsimp only      by_cases hi : i.val = 0      · have hdeg := twin_star_leaf_count_deg_inl_zero d hd i hi        simp [hi, hdeg]      · simp [hi]        have hnf := twin_star_leaf_count_nf_inl d hd i hi        change ((twin_star d).neighborFinset (Sum.inl i)).card = 1        rw [hnf, Finset.card_singleton]    · dsimp only      by_cases hi : i.val = 0      · have hdeg := twin_star_leaf_count_deg_inr_zero d hd i hi        simp [hi, hdeg]      · simp [hi]        have hnf := twin_star_leaf_count_nf_inr d hd i hi        change ((twin_star d).neighborFinset (Sum.inr i)).card = 1        rw [hnf, Finset.card_singleton]  have h_filter : Finset.univ.filter (fun v => (twin_star d).degree v = 1) =      Finset.univ.filter (fun v => match v with | .inl i => i.val ≠ 0 | .inr i => i.val ≠ 0) :=    Finset.filter_congr (fun v _ => h_iff v)  rw [h_filter]  have h_disj : (Finset.univ.filter (fun (v : Fin d ⊕ Fin d) =>        match v with | .inl i => i.val ≠ 0 | .inr i => i.val ≠ 0)) =      ((Finset.univ.filter (fun (i : Fin d) => i.val ≠ 0)).disjSum       (Finset.univ.filter (fun (i : Fin d) => i.val ≠ 0))) := by    change (Finset.disjSum Finset.univ Finset.univ).filter      (fun (v : Fin d ⊕ Fin d) => match v with | .inl i => i.val ≠ 0 | .inr i => i.val ≠ 0) = _    ext (x | y) <;> simp  rw [h_disj, Finset.card_disjSum]  have h_add := Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset (Fin d)))    (p := fun (i : Fin d) => i.val ≠ 0)  have h_not : (Finset.univ.filter (fun (i : Fin d) => ¬(i.val ≠ 0))) = {⟨0, by omega⟩} := by    ext ⟨x, hx⟩    simp [Fin.ext_iff]  rw [h_not, Finset.card_singleton, Finset.card_univ, Fintype.card_fin] at h_add  omega
See it in the graphDiscuss this resultChallenge it