AFTD Auto-Formalizing Theoretical Domains

op874_four_two_incidence_cover

theoremverified

In a finite incidence system with four edges at every left vertex and two vertices at every edge, any edge subset of left degree at most two can be covered while choosing a different incident edge for every left vertex.

Statement

theorem op874_four_two_incidence_cover {L E : Type*} [Fintype L] [Fintype E] [DecidableEq L] [DecidableEq E] (inc : L → E → Prop) [DecidableRel inc] (S : Finset E) (hleft : ∀ l, (Finset.univ.filter (fun e => inc l e)).card = 4) (hright : ∀ e, (Finset.univ.filter (fun l => inc l e)).card = 2) (hS : ∀ l, (S.filter (fun e => inc l e)).card ≤ 2) : ∃ f : L → E, Function.Injective f ∧ (∀ l, inc l (f l)) ∧ ∀ e ∈ S, ∃ l, f l = e
Source
OP-874: required same-bit factor edges and matching-owned ports via the finite matching criterion
Verified
22 Nov 2026
Axioms
Classical.choiceQuot.soundpropext

The proof, explained

We reformulate the problem as finding a bijection f : L ⊕ L → E via Hall's Marriage Theorem. Double counting incidences shows that |E| = 2|L| = |L ⊕ L|, that neighborhoods satisfy |N(A)| ≥ 2|A|, and that non-incident edges in S satisfy |S \ N(A)| ≤ |L \ A|. We define candidate choices on L ⊕ L by letting the first copy of l pick among its four incident edges and the second copy pick from E \ S. Hall's condition is verified by checking whether the subset of L ⊕ L contains an element from the second copy (yielding at least |E| - |S \ N(A)| ≥ |L| + |A| choices) or not (yielding |N(A)| ≥ 2|A| choices). The resulting Hall injection is a bijection, and because elements of the second copy never select edges in S, all of S is covered by the first copy.

  1. The total number of edges is twice the number of left vertices: |E| = 2|L|.

    We double count incidences between the universal set of left vertices L and the universal set of edges E. Summing the left degrees (which are all 4) gives 4|L|, while summing the right degrees (which are all 2) gives 2|E|. Equating these gives 4|L| = 2|E|, which linear arithmetic simplifies to |E| = 2|L|.

    lines 4–9

    uses Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, Nat.cast_id

      classical
      have heq : Fintype.card E = 2 * Fintype.card L := by
        have hh := Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow (s := (Finset.univ : Finset L)) (t := (Finset.univ : Finset E)) inc
        simp only [Finset.bipartiteAbove, Finset.bipartiteBelow, hleft, hright,
          Finset.sum_const, Finset.card_univ, nsmul_eq_mul, Nat.cast_id] at hh
        omega
  2. For every vertex subset A ⊆ L, its edge neighborhood N(A) satisfies 4|A| ≤ 2|N(A)|.

    Define N(A) as the set of edges incident to at least one vertex in A. Each vertex l ∈ A has degree 4, and all 4 of its incident edges belong to N(A) by definition. Conversely, each edge e ∈ N(A) is incident to at most 2 vertices in A because its total degree in L is 2. Counting incidences between A and N(A) using card_nsmul_le_card_nsmul with bounds m = 4 and n = 2 establishes 4|A| ≤ 2|N(A)|.

    lines 10–26

    uses Finset.card_nsmul_le_card_nsmul, Finset.mem_filter, Finset.mem_univ, true_and, Finset.card_le_card, Finset.filter_subset_filter, Finset.subset_univ, nsmul_eq_mul, Nat.mul_comm, Nat.cast_id

      let N : Finset L → Finset E := fun A => Finset.univ.filter (fun e => ∃ l ∈ A, inc l e)
      have hN (A : Finset L) : 4 * A.card ≤ 2 * (N A).card := by
        have h := Finset.card_nsmul_le_card_nsmul (R := ℕ) (m := 4) (n := 2) (s := A) (t := N A) inc
          (by
            intro l hl
            have he : (N A).filter (fun e => inc l e) = Finset.univ.filter (fun e => inc l e) := by
              ext e; simp only [Finset.mem_filter, Finset.mem_univ, true_and, N]
              constructor
              · exact fun h => h.2
              · intro he; exact ⟨⟨l, hl, he⟩, he⟩
            simpa [Finset.bipartiteAbove, he, hleft l])
          (by
            intro e he
            have hh : (A.filter (fun l => inc l e)).card ≤ (Finset.univ.filter (fun l => inc l e)).card :=
              Finset.card_le_card (Finset.filter_subset_filter _ (Finset.subset_univ _))
            simpa [Finset.bipartiteBelow, hright e] using hh)
        simpa only [nsmul_eq_mul, Nat.mul_comm, Nat.cast_id] using h
  3. For every vertex subset A ⊆ L, the edges in S not incident to A satisfy |S \ N(A)| ≤ |L \ A|.

    An edge e ∈ S \ N(A) is incident to no vertex in A, so both of its incident vertices must lie in L \ A; thus its degree in L \ A is 2. In the reverse direction, every vertex l ∈ L \ A has degree at most 2 into S by the hypothesis hS, and therefore degree at most 2 into S \ N(A). Counting incidences between S \ N(A) and L \ A using card_nsmul_le_card_nsmul with m = 2 and n = 2 yields 2|S \ N(A)| ≤ 2|L \ A|, from which linear arithmetic concludes |S \ N(A)| ≤ |L \ A|.

    lines 27–51

    uses Finset.card_nsmul_le_card_nsmul, Finset.mem_sdiff, Finset.mem_filter, Finset.mem_univ, true_and, Finset.card_le_card, Finset.filter_subset_filter, Finset.sdiff_subset, nsmul_eq_mul, Nat.cast_id

      have hbad (A : Finset L) : (S \ N A).card ≤ (Finset.univ \ A).card := by
        have h := Finset.card_nsmul_le_card_nsmul (R := ℕ) (m := 2) (n := 2)
          (s := S \ N A) (t := Finset.univ \ A) (fun e l => inc l e)
          (by
            intro e he
            have heN : e ∉ N A := (Finset.mem_sdiff.mp he).2
            have heq' : (Finset.univ \ A).filter (fun l => inc l e) = Finset.univ.filter (fun l => inc l e) := by
              ext l; simp only [Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and]
              constructor
              · exact fun h => h.2
              · intro hil
                have hn : l ∉ A := by
                  intro hl
                  apply heN
                  simp only [N, Finset.mem_filter, Finset.mem_univ, true_and]
                  exact ⟨l, hl, hil⟩
                exact ⟨hn, hil⟩
            simpa [Finset.bipartiteAbove, heq', hright e])
          (by
            intro l hl
            have hh : ((S \ N A).filter (fun e => inc l e)).card ≤ (S.filter (fun e => inc l e)).card :=
              Finset.card_le_card (Finset.filter_subset_filter _ (Finset.sdiff_subset))
            exact (by simpa [Finset.bipartiteBelow] using hh.trans (hS l)))
        simp only [nsmul_eq_mul, Nat.cast_id] at h
        omega
  4. Hall's marriage condition holds for the choice family on L ⊕ L.

    We set up a choice problem on L ⊕ L where each inl(l) can choose from its incident edges in E, and each inr(l) can choose from E \ S. For any subset T ⊆ L ⊕ L with left component A and right component B, we have |T| = |A| + |B|, and the union of available choices always contains N(A). We consider two cases: if B is nonempty, choosing an element from B includes all of E \ S in the union, giving a combined available set containing E \ (S \ N(A)) of size at least |E| - |S \ N(A)| = 2|L| - |S \ N(A)| ≥ 2|L| - (|L| - |A|) = |L| + |A| ≥ |B| + |A| = |T|; if B is empty, then |T| = |A| and the union contains N(A), which has size at least 2|A| ≥ |A| = |T|. In both cases, the union has cardinality at least |T|.

    lines 52–96

    uses Finset.card_toLeft_add_card_toRight, Finset.card_le_univ, Finset.card_sdiff_add_card_eq_card, Finset.subset_univ, Finset.mem_filter, Finset.mem_biUnion, Finset.mem_toLeft, Finset.mem_sdiff, Or.inl, Finset.mem_toRight, Finset.card_le_card, Finset.card_eq_zero, Finset.not_nonempty_iff_eq_empty

      let choices : L ⊕ L → Finset E := fun x =>
        match x with
        | .inl l => Finset.univ.filter (fun e => inc l e)
        | .inr _ => Finset.univ \ S
      have hcriterion : ∀ T : Finset (L ⊕ L), T.card ≤ (T.biUnion choices).card := by
        intro T
        let A := T.toLeft
        let B := T.toRight
        have hAB : A.card + B.card = T.card := Finset.card_toLeft_add_card_toRight
        have hB : B.card ≤ Fintype.card L := by simpa using Finset.card_le_univ B
        have hA : A.card ≤ Fintype.card L := by simpa using Finset.card_le_univ A
        have hAc : (Finset.univ \ A).card + A.card = Fintype.card L := by
          simpa using Finset.card_sdiff_add_card_eq_card (Finset.subset_univ A)
        have hNsub : N A ⊆ T.biUnion choices := by
          intro e he
          obtain ⟨_, l, hl, hle⟩ := Finset.mem_filter.mp he
          apply Finset.mem_biUnion.mpr
          refine ⟨Sum.inl l, ?_, ?_⟩
          · exact Finset.mem_toLeft.mp hl
          · simp [choices, hle]
        by_cases hB0 : B.Nonempty
        · obtain ⟨l, hl⟩ := hB0
          have hcomp : (Finset.univ \ (S \ N A)) ⊆ T.biUnion choices := by
            intro e he
            have he' : e ∉ S ∨ e ∈ N A := by
              by_cases hs : e ∈ S
              · right
                by_contra hn
                exact (Finset.mem_sdiff.mp he).2 (Finset.mem_sdiff.mpr ⟨hs, hn⟩)
              · exact Or.inl hs
            rcases he' with hnot | hN'
            · apply Finset.mem_biUnion.mpr
              refine ⟨Sum.inr l, Finset.mem_toRight.mp hl, ?_⟩
              simp [choices, hnot]
            · exact hNsub hN'
          have hcb := Finset.card_le_card hcomp
          have hbad' := hbad A
          have hbadsub : S \ N A ⊆ (Finset.univ : Finset E) := Finset.subset_univ _
          have hcard : (Finset.univ \ (S \ N A)).card + (S \ N A).card = Fintype.card E := by
            simpa using Finset.card_sdiff_add_card_eq_card hbadsub
          omega
        · have hBz : B.card = 0 := Finset.card_eq_zero.mpr (Finset.not_nonempty_iff_eq_empty.mp hB0)
          have hn := hN A
          have hh := Finset.card_le_card hNsub
          omega
  5. There exists a bijection f : L ⊕ L → E respecting the choice family.

    By Hall's Marriage Theorem (Finset.all_card_le_biUnion_card_iff_existsInjective'), the marriage condition yields an injective function f : L ⊕ L → E with f(x) ∈ choices(x). Since |L ⊕ L| = |L| + |L| = 2|L| = |E|, the domain and codomain have the same finite cardinality, so injectivity implies that f is a bijection, and in particular surjective.

    lines 97–99

    uses Finset.all_card_le_biUnion_card_iff_existsInjective', Fintype.card_sum, two_mul, Fintype.bijective_iff_injective_and_card

      obtain ⟨f, hfinj, hfmem⟩ := (Finset.all_card_le_biUnion_card_iff_existsInjective' choices).mp hcriterion
      have hc : Fintype.card (L ⊕ L) = Fintype.card E := by simp [Fintype.card_sum, heq, two_mul]
      have hsurj := (Fintype.bijective_iff_injective_and_card f).mpr ⟨hfinj, hc⟩ |>.2
  6. The restriction l ↦ f(inl(l)) is an injective incidence choice covering all of S.

    The restricted map l ↦ f(inl(l)) is injective because both f and inl are injective. It selects an incident edge because f(inl(l)) ∈ choices(inl(l)) = {e | inc l e}. Finally, it covers S: for any e ∈ S, surjectivity of f gives a preimage x with f(x) = e; this preimage cannot be of the form inr(l') because choices(inr(l')) = E \ S excludes all edges of S, so x must be inl(l) for some l ∈ L, yielding f(inl(l)) = e.

    lines 100–112

    uses Sum.inl.inj, Finset.mem_sdiff, Finset.mem_univ, true_and, False.elim

      refine ⟨fun l => f (Sum.inl l), ?_, ?_, ?_⟩
      · intro a b hab
        exact Sum.inl.inj (hfinj hab)
      · intro l
        simpa [choices] using hfmem (Sum.inl l)
      · intro e he
        obtain ⟨x, hx⟩ := hsurj e
        cases x with
        | inl l => exact ⟨l, hx⟩
        | inr l =>
          have hm := hfmem (Sum.inr l)
          simp only [choices, Finset.mem_sdiff, Finset.mem_univ, true_and] at hm
          exact False.elim (hm (hx ▸ he))
Finset.all_card_le_biUnion_card_iff_existsInjective'
Hall's Marriage Theorem for finsets: a family of finsets indexed by a finite type admits an injective choice function if and only if every finite index subset s satisfies |s| ≤ |⋃_{x ∈ s} t(x)|.
Finset.card_le_card
If s ⊆ t, then |s| ≤ |t|.
Finset.card_le_univ
The cardinality of any finset s ⊆ α is at most Fintype.card α.
Finset.card_nsmul_le_card_nsmul
For a bipartite incidence relation between finite sets s and t, if every element of s has degree at least m into t and every element of t has degree at most n into s, then m · |s| ≤ n · |t|.
Finset.card_sdiff_add_card_eq_card
If s ⊆ t, then |t \ s| + |s| = |t|.
Finset.card_eq_zero
A finset has cardinality 0 if and only if it is the empty set.
Finset.card_toLeft_add_card_toRight
The cardinality of a finset u ⊆ α ⊕ β is the sum of the cardinalities of its left projection and right projection.
Finset.card_univ
The cardinality of the universal finset on a finite type α equals Fintype.card α.
Finset.filter_subset_filter
Filtering subsets preserves inclusions: if s ⊆ t, then {x ∈ s | p(x)} ⊆ {x ∈ t | p(x)}.
Finset.mem_biUnion
An element belongs to ⋃_{a ∈ s} t(a) if and only if it belongs to t(a) for some a ∈ s.
Finset.mem_filter
An element belongs to {x ∈ s | p(x)} if and only if it belongs to s and satisfies p.
Finset.mem_sdiff
An element belongs to s \ t if and only if it belongs to s and does not belong to t.
Finset.mem_toLeft
An element a belongs to u.toLeft if and only if Sum.inl a ∈ u.
Finset.mem_toRight
An element b belongs to u.toRight if and only if Sum.inr b ∈ u.
Finset.mem_univ
Every element of a finite type belongs to its universal finset.
Finset.not_nonempty_iff_eq_empty
A finset is not nonempty if and only if it is empty.
Finset.sdiff_subset
The set difference s \ t is a subset of s.
Finset.subset_univ
Every finset of elements of α is a subset of the universal finset on α.
Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow
For any bipartite relation on finite sets s and t, the sum of out-degrees from s to t equals the sum of in-degrees from t to s.
Finset.sum_const
Summing a constant value b over a finite set s yields |s| • b.
Fintype.bijective_iff_injective_and_card
A map between finite types of the same cardinality is bijective if and only if it is injective.
Fintype.card_sum
The cardinality of the sum type α ⊕ β is Fintype.card α + Fintype.card β.
Nat.mul_comm
Multiplication of natural numbers is commutative: n * m = m * n.
Nat.cast_id
The coercion from ℕ to ℕ is the identity map.
nsmul_eq_mul
Scalar multiplication by a natural number n • a equals the product n * a.
Or.inl
If P holds, then P ∨ Q holds.
Sum.inl.inj
Sum.inl is injective: Sum.inl a = Sum.inl b implies a = b.
two_mul
Multiplication by two is repeated addition: 2 * n = n + n.
true_and
The conjunction True ∧ p is equivalent to p.
False.elim
From a contradiction (False), any conclusion follows.

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 Finsettheorem op874_four_two_incidence_cover {L E : Type*} [Fintype L] [Fintype E] [DecidableEq L] [DecidableEq E] (inc : L → E → Prop) [DecidableRel inc] (S : Finset E) (hleft : ∀ l, (Finset.univ.filter (fun e => inc l e)).card = 4) (hright : ∀ e, (Finset.univ.filter (fun l => inc l e)).card = 2) (hS : ∀ l, (S.filter (fun e => inc l e)).card ≤ 2) : ∃ f : L → E, Function.Injective f ∧ (∀ l, inc l (f l)) ∧ ∀ e ∈ S, ∃ l, f l = e := by  classical  have heq : Fintype.card E = 2 * Fintype.card L := by    have hh := Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow (s := (Finset.univ : Finset L)) (t := (Finset.univ : Finset E)) inc    simp only [Finset.bipartiteAbove, Finset.bipartiteBelow, hleft, hright,      Finset.sum_const, Finset.card_univ, nsmul_eq_mul, Nat.cast_id] at hh    omega  let N : Finset L → Finset E := fun A => Finset.univ.filter (fun e => ∃ l ∈ A, inc l e)  have hN (A : Finset L) : 4 * A.card ≤ 2 * (N A).card := by    have h := Finset.card_nsmul_le_card_nsmul (R := ℕ) (m := 4) (n := 2) (s := A) (t := N A) inc      (by        intro l hl        have he : (N A).filter (fun e => inc l e) = Finset.univ.filter (fun e => inc l e) := by          ext e; simp only [Finset.mem_filter, Finset.mem_univ, true_and, N]          constructor          · exact fun h => h.2          · intro he; exact ⟨⟨l, hl, he⟩, he⟩        simpa [Finset.bipartiteAbove, he, hleft l])      (by        intro e he        have hh : (A.filter (fun l => inc l e)).card ≤ (Finset.univ.filter (fun l => inc l e)).card :=          Finset.card_le_card (Finset.filter_subset_filter _ (Finset.subset_univ _))        simpa [Finset.bipartiteBelow, hright e] using hh)    simpa only [nsmul_eq_mul, Nat.mul_comm, Nat.cast_id] using h  have hbad (A : Finset L) : (S \ N A).card ≤ (Finset.univ \ A).card := by    have h := Finset.card_nsmul_le_card_nsmul (R := ℕ) (m := 2) (n := 2)      (s := S \ N A) (t := Finset.univ \ A) (fun e l => inc l e)      (by        intro e he        have heN : e ∉ N A := (Finset.mem_sdiff.mp he).2        have heq' : (Finset.univ \ A).filter (fun l => inc l e) = Finset.univ.filter (fun l => inc l e) := by          ext l; simp only [Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and]          constructor          · exact fun h => h.2          · intro hil            have hn : l ∉ A := by              intro hl              apply heN              simp only [N, Finset.mem_filter, Finset.mem_univ, true_and]              exact ⟨l, hl, hil⟩            exact ⟨hn, hil⟩        simpa [Finset.bipartiteAbove, heq', hright e])      (by        intro l hl        have hh : ((S \ N A).filter (fun e => inc l e)).card ≤ (S.filter (fun e => inc l e)).card :=          Finset.card_le_card (Finset.filter_subset_filter _ (Finset.sdiff_subset))        exact (by simpa [Finset.bipartiteBelow] using hh.trans (hS l)))    simp only [nsmul_eq_mul, Nat.cast_id] at h    omega  let choices : L ⊕ L → Finset E := fun x =>    match x with    | .inl l => Finset.univ.filter (fun e => inc l e)    | .inr _ => Finset.univ \ S  have hcriterion : ∀ T : Finset (L ⊕ L), T.card ≤ (T.biUnion choices).card := by    intro T    let A := T.toLeft    let B := T.toRight    have hAB : A.card + B.card = T.card := Finset.card_toLeft_add_card_toRight    have hB : B.card ≤ Fintype.card L := by simpa using Finset.card_le_univ B    have hA : A.card ≤ Fintype.card L := by simpa using Finset.card_le_univ A    have hAc : (Finset.univ \ A).card + A.card = Fintype.card L := by      simpa using Finset.card_sdiff_add_card_eq_card (Finset.subset_univ A)    have hNsub : N A ⊆ T.biUnion choices := by      intro e he      obtain ⟨_, l, hl, hle⟩ := Finset.mem_filter.mp he      apply Finset.mem_biUnion.mpr      refine ⟨Sum.inl l, ?_, ?_⟩      · exact Finset.mem_toLeft.mp hl      · simp [choices, hle]    by_cases hB0 : B.Nonempty    · obtain ⟨l, hl⟩ := hB0      have hcomp : (Finset.univ \ (S \ N A)) ⊆ T.biUnion choices := by        intro e he        have he' : e ∉ S ∨ e ∈ N A := by          by_cases hs : e ∈ S          · right            by_contra hn            exact (Finset.mem_sdiff.mp he).2 (Finset.mem_sdiff.mpr ⟨hs, hn⟩)          · exact Or.inl hs        rcases he' with hnot | hN'        · apply Finset.mem_biUnion.mpr          refine ⟨Sum.inr l, Finset.mem_toRight.mp hl, ?_⟩          simp [choices, hnot]        · exact hNsub hN'      have hcb := Finset.card_le_card hcomp      have hbad' := hbad A      have hbadsub : S \ N A ⊆ (Finset.univ : Finset E) := Finset.subset_univ _      have hcard : (Finset.univ \ (S \ N A)).card + (S \ N A).card = Fintype.card E := by        simpa using Finset.card_sdiff_add_card_eq_card hbadsub      omega    · have hBz : B.card = 0 := Finset.card_eq_zero.mpr (Finset.not_nonempty_iff_eq_empty.mp hB0)      have hn := hN A      have hh := Finset.card_le_card hNsub      omega  obtain ⟨f, hfinj, hfmem⟩ := (Finset.all_card_le_biUnion_card_iff_existsInjective' choices).mp hcriterion  have hc : Fintype.card (L ⊕ L) = Fintype.card E := by simp [Fintype.card_sum, heq, two_mul]  have hsurj := (Fintype.bijective_iff_injective_and_card f).mpr ⟨hfinj, hc⟩ |>.2  refine ⟨fun l => f (Sum.inl l), ?_, ?_, ?_⟩  · intro a b hab    exact Sum.inl.inj (hfinj hab)  · intro l    simpa [choices] using hfmem (Sum.inl l)  · intro e he    obtain ⟨x, hx⟩ := hsurj e    cases x with    | inl l => exact ⟨l, hx⟩    | inr l =>      have hm := hfmem (Sum.inr l)      simp only [choices, Finset.mem_sdiff, Finset.mem_univ, true_and] at hm      exact False.elim (hm (hx ▸ he))
See it in the graphDiscuss this resultChallenge it