AFTD Auto-Formalizing Theoretical Domains

op309_p3_forest_selected_edge_count

theoremverified

A selected-edge graph of maximum degree two, with no selected edge joining two degree-two vertices and no isolated selected edge, has three covered vertices per two selected edges.

Statement

theorem op309_p3_forest_selected_edge_count
    {V : Type*} [Fintype V] [DecidableEq V]
    (G : SimpleGraph V) [DecidableRel G.Adj] (R : Finset G.edgeSet)
    (hbound : ∀ v, (R.filter fun e => v ∈ e.1).card ≤ 2)
    (hpaths : ∀ e ∈ R, ¬ ∃ a b : V, e.1 = s(a,b) ∧
      (R.filter fun f => a ∈ f.1).card = 2 ∧
      (R.filter fun f => b ∈ f.1).card = 2)
    (hneighbors : ∀ e ∈ R, ∃ f ∈ R, G.lineGraph.Adj e f) :
    3 * R.card + 2 * ((Finset.univ : Finset V).filter
      fun v => (R.filter fun e => v ∈ e.1).card = 0).card = 2 * Fintype.card V
Source
P3-forest edge count needed for the cubic equality boundary in OP-309.
Verified
28 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1
Used by 1

The proof, explained

The theorem is proved by first establishing a general counting formula for any finite graph of maximum degree at most two whose adjacent vertices have distinct degrees. In such a graph, every edge must connect a vertex of degree two to a vertex of degree one, making the graph bipartite between its degree-two and degree-one vertices; counting edges via degrees in both parts yields 2|V₂| = |E| and |V₁| = |E|, which together with |V₂| + |V₁| + |V₀| = |V| yields 3|E| + 2|V₀| = 2|V|. For the selected edge set R, the path condition guarantees that no selected edge connects two degree-two vertices, while the neighbor condition ensures no selected edge connects two degree-one vertices. Hence the subgraph of selected edges satisfies the hypotheses of the general formula, which immediately proves the identity.

  1. The set C of vertices of degree 2 and the set L of vertices of degree 1 in H are disjoint.

    If a vertex belonged to both sets, its degree would be both 2 and 1, which is impossible.

    lines 10–19

    uses Finset.disjoint_left.mpr, Finset.mem_filter.mp

      classical
      let C : Finset V := Finset.univ.filter fun v => H.degree v = 2
      let L : Finset V := Finset.univ.filter fun v => H.degree v = 1
      let U : Finset V := Finset.univ.filter fun v => H.degree v = 0
      have hdis : Disjoint C L := by
        apply Finset.disjoint_left.mpr
        intro v hvC hvL
        have hc := (Finset.mem_filter.mp hvC).2
        have hl := (Finset.mem_filter.mp hvL).2
        omega
  2. The graph H is bipartite with parts C and L.

    For every edge between vertices a and b, both endpoints have positive degree (at least 1) and degree at most 2. Because adjacent vertices have distinct degrees, one endpoint must have degree 2 and the other degree 1, so every edge has one endpoint in C and one in L.

    lines 20–29

    uses Finset.disjoint_coe.mpr, Finset.mem_coe, Finset.mem_filter, Finset.mem_univ, true_and

      have hbip : H.IsBipartiteWith (C : Set V) (L : Set V) := by
        refine ⟨Finset.disjoint_coe.mpr hdis, ?_⟩
        intro a b hab
        have ha := hab.degree_pos_left
        have hb := hab.degree_pos_right
        have hba := hbound a
        have hbb := hbound b
        have hne := hdifferent a b hab
        simp only [Finset.mem_coe, C, L, Finset.mem_filter, Finset.mem_univ, true_and]
        omega
  3. The sum of degrees over C is 2|C|, and the sum of degrees over L is |L|.

    Every vertex in C has degree 2, so the sum of degrees over C is ∑_{v ∈ C} 2 = 2|C|. Similarly, every vertex in L has degree 1, so the sum over L is ∑_{v ∈ L} 1 = |L|.

    lines 30–37

    uses Finset.sum_congr, Finset.mem_filter.mp, Nat.mul_comm

      have hsumC : ∑ v ∈ C, H.degree v = 2 * C.card := by
        calc
          _ = ∑ _v ∈ C, 2 := Finset.sum_congr rfl (fun v hv => (Finset.mem_filter.mp hv).2)
          _ = _ := by simp [Nat.mul_comm]
      have hsumL : ∑ v ∈ L, H.degree v = L.card := by
        calc
          _ = ∑ _v ∈ L, 1 := Finset.sum_congr rfl (fun v hv => (Finset.mem_filter.mp hv).2)
          _ = _ := by simp
  4. The edge count of H satisfies 2|C| = |E(H)| and |L| = |E(H)|.

    In any bipartite graph, the sum of degrees in either partition part equals the total number of edges. Applying this to C and L equates 2|C| and |L| each to |E(H)|.

    lines 38–43

    uses H.isBipartiteWith_sum_degrees_eq_card_edges, H.isBipartiteWith_sum_degrees_eq_card_edges'

      have hedgesC : 2 * C.card = H.edgeFinset.card := by
        rw [← hsumC]
        exact H.isBipartiteWith_sum_degrees_eq_card_edges hbip
      have hedgesL : L.card = H.edgeFinset.card := by
        rw [← hsumL]
        exact H.isBipartiteWith_sum_degrees_eq_card_edges' hbip
  5. The union of C and L is the complement of the degree-0 vertices U, and |C| + |L| + |U| = |V|.

    Since every vertex has degree at most 2, every vertex has degree 2, 1, or 0, so C ∪ L = Uᶜ. Because C and L are disjoint, |C ∪ L| = |C| + |L| = |V| - |U|, which rearranges to |C| + |L| + |U| = |V|.

    lines 44–54

    uses Finset.mem_union, Finset.mem_compl, Finset.mem_filter, Finset.mem_univ, true_and, Finset.card_union_of_disjoint, Finset.card_compl, Finset.card_le_univ

      have hpartition : C ∪ L = Uᶜ := by
        ext v
        have h := hbound v
        simp only [Finset.mem_union, Finset.mem_compl, C, L, U, Finset.mem_filter,
          Finset.mem_univ, true_and]
        omega
      have hcard : C.card + L.card + U.card = Fintype.card V := by
        have hc := Finset.card_union_of_disjoint hdis
        rw [hpartition, Finset.card_compl] at hc
        have hu := Finset.card_le_univ U
        omega
  6. The helper identity 3|E(H)| + 2|U| = 2|V| holds.

    Multiplying |C| + |L| + |U| = |V| by 2 gives 2|C| + 2|L| + 2|U| = 2|V|. Substituting 2|C| = |E(H)| and 2|L| = 2|E(H)| yields |E(H)| + 2|E(H)| + 2|U| = 3|E(H)| + 2|U| = 2|V|.

    lines 55–56

      change 3 * H.edgeFinset.card + 2 * U.card = 2 * Fintype.card V
      omega
  7. Define H as the simple subgraph of G induced by the selected edge set R.

    We construct H from the edges of R via classical logic to provide decidability for adjacency.

    lines 68–70

    uses Classical.decRel

      classical
      let H := op309_selected_edge_graph G R
      letI : DecidableRel H.Adj := Classical.decRel _
  8. The edge finset of H is in bijection with R.

    Constructing a simple graph from an edge set discards only self-loops (diagonal pairs). Since G has no self-loops, every edge in R joins distinct vertices, so no edges are discarded and E(H) = R.

    lines 71–83

    uses SimpleGraph.mem_edgeFinset, SimpleGraph.edgeSet_fromEdgeSet, Finset.mem_image.mp, G.not_isDiag_of_mem_edgeSet, Sym2.mem_diagSet

      have hedges : H.edgeFinset = R.image Subtype.val := by
        ext e
        rw [SimpleGraph.mem_edgeFinset]
        change e ∈ (SimpleGraph.fromEdgeSet (↑(R.image Subtype.val) : Set (Sym2 V))).edgeSet ↔ _
        rw [SimpleGraph.edgeSet_fromEdgeSet]
        constructor
        · intro he
          exact he.1
        · intro he
          obtain ⟨f,hf,hfe⟩ := Finset.mem_image.mp he
          refine ⟨he, ?_⟩
          have hnot := G.not_isDiag_of_mem_edgeSet f.2
          simpa [Sym2.mem_diagSet, ← hfe] using hnot
  9. The degree of every vertex v in H equals its degree in R, and so deg_H(v) ≤ 2 everywhere.

    The degree of v in H is the count of incident edges in H. Since E(H) corresponds bijectively to R, this equals the count of edges in R containing v, which is at most 2 by assumption.

    lines 84–89

    uses H.card_incidenceFinset_eq_degree, H.incidenceFinset_eq_filter, Finset.filter_image, Finset.card_image_iff.mpr, Subtype.ext

      have hdegree : ∀ v, H.degree v = (R.filter fun e => v ∈ e.1).card := by
        intro v
        rw [← H.card_incidenceFinset_eq_degree v, H.incidenceFinset_eq_filter, hedges,
          Finset.filter_image]
        exact Finset.card_image_iff.mpr (fun _ _ _ _ h => Subtype.ext h)
      have hHbound : ∀ v, H.degree v ≤ 2 := by intro v; rw [hdegree]; exact hbound v
  10. Adjacent vertices in H have distinct degrees.

    Suppose adjacent vertices a and b had the same degree in H. Since they are adjacent, their degrees are either both 2 or both 1. If both are 2, the edge joining them connects two degree-2 vertices, contradicting the path hypothesis. If both are 1, by the neighbor hypothesis the edge e = {a, b} must share an endpoint with another edge f ∈ R, which would give that endpoint degree at least 2 in R, contradicting that its degree is 1.

    lines 90–120

    uses SimpleGraph.fromEdgeSet_adj, Finset.mem_image.mp, SimpleGraph.lineGraph_adj_iff_exists.mp, Sym2.mem_iff, Finset.card_le_one.mp

      have hdiff : ∀ a b, H.Adj a b → H.degree a ≠ H.degree b := by
        intro a b hab heq
        have hposA := hab.degree_pos_left
        have hposB := hab.degree_pos_right
        have hbA := hHbound a
        have hbB := hHbound b
        have hp : s(a,b) ∈ R.image Subtype.val := by
          exact ((SimpleGraph.fromEdgeSet_adj (↑(R.image Subtype.val) : Set (Sym2 V))).mp hab).1
        obtain ⟨e,he,heval⟩ := Finset.mem_image.mp hp
        by_cases htwo : H.degree a = 2
        · apply hpaths e he
          exact ⟨a,b,heval, by simpa [hdegree] using htwo,
            by rw [← hdegree b, ← heq]; exact htwo⟩
        · have ha : (R.filter fun f => a ∈ f.1).card = 1 := by rw [← hdegree]; omega
          have hb : (R.filter fun f => b ∈ f.1).card = 1 := by rw [← hdegree]; omega
          obtain ⟨f,hf,hef⟩ := hneighbors e he
          obtain ⟨hne,w,hwe,hwf⟩ := SimpleGraph.lineGraph_adj_iff_exists.mp hef
          have hw : w = a ∨ w = b := by rw [heval, Sym2.mem_iff] at hwe; exact hwe
          rcases hw with hwa | hwb
          · subst w
            have hle : (R.filter fun f => a ∈ f.1).card ≤ 1 := by omega
            have he' : e ∈ R.filter (fun f => a ∈ f.1) := by
              simp [he,heval]
            have hf' : f ∈ R.filter (fun f => a ∈ f.1) := by simp [hf,hwf]
            exact hne ((Finset.card_le_one.mp hle) e he' f hf')
          · subst w
            have hle : (R.filter fun f => b ∈ f.1).card ≤ 1 := by omega
            have he' : e ∈ R.filter (fun f => b ∈ f.1) := by
              simp [he,heval]
            have hf' : f ∈ R.filter (fun f => b ∈ f.1) := by simp [hf,hwf]
            exact hne ((Finset.card_le_one.mp hle) e he' f hf')
  11. The edge count |E(H)| equals |R|, and the vertices of degree 0 in H are precisely those of degree 0 in R.

    The projection from G's edges to Sym2 V is injective, so |E(H)| = |R|. Furthermore, since vertex degrees in H agree with degrees in R, their sets of degree-0 vertices coincide.

    lines 121–127

    uses Finset.card_image_iff.mpr, Subtype.ext

      have hc : H.edgeFinset.card = R.card := by
        rw [hedges]
        exact Finset.card_image_iff.mpr (fun _ _ _ _ h => Subtype.ext h)
      have hu : ((Finset.univ : Finset V).filter fun v => H.degree v = 0) =
          ((Finset.univ : Finset V).filter fun v => (R.filter fun e => v ∈ e.1).card = 0) := by
        ext v
        simp [hdegree]
  12. The formula 3|R| + 2|{v | deg_R(v) = 0}| = 2|V| holds.

    Since H has maximum degree at most 2 and no adjacent vertices of the same degree, the helper theorem in1254_degree_one_two_edge_count applies to H, yielding the conclusion after rewriting |E(H)| = |R| and matching the degree-0 sets.

    line 128

    uses in1254_degree_one_two_edge_count

      simpa only [hc,hu] using in1254_degree_one_two_edge_count H hHbound hdiff
Finset.disjoint_left.mpr
Two finsets are disjoint if every element of the first does not belong to the second.
Finset.mem_filter.mp
An element in a filtered finset belongs to the original finset and satisfies the filter predicate.
Finset.disjoint_coe.mpr
If two finsets are disjoint, their coercions to sets are disjoint.
Finset.mem_coe
An element belongs to the set coercion of a finset if and only if it belongs to the finset.
Finset.mem_filter
An element belongs to a filtered finset if and only if it belongs to the finset and satisfies the predicate.
Finset.mem_univ
Every element of a finite type belongs to the universal finset.
true_and
The conjunction True ∧ p is equivalent to p.
Finset.sum_congr
Two sums over finsets are equal if their index sets are equal and their summands agree on every element.
Nat.mul_comm
Multiplication of natural numbers is commutative.
H.isBipartiteWith_sum_degrees_eq_card_edges
In a bipartite graph, the sum of degrees over the first partition part equals the number of edges.
H.isBipartiteWith_sum_degrees_eq_card_edges'
In a bipartite graph, the sum of degrees over the second partition part equals the number of edges.
Finset.mem_union
An element belongs to the union of two finsets if and only if it belongs to either finset.
Finset.mem_compl
An element belongs to the complement of a finset if and only if it does not belong to the finset.
Finset.card_union_of_disjoint
The cardinality of the union of two disjoint finsets is the sum of their cardinalities.
Finset.card_compl
The cardinality of the complement of a finset s in a finite type V is |V| - |s|.
Finset.card_le_univ
The cardinality of any finset of a finite type is at most the cardinality of the type.
Classical.decRel
Constructs a classical decidability instance for any binary relation.
SimpleGraph.mem_edgeFinset
An unordered pair is in the edge finset of a graph if and only if it is in its edge set.
SimpleGraph.edgeSet_fromEdgeSet
The edge set of a simple graph formed from a set of pairs consists of all non-diagonal pairs in that set.
Finset.mem_image.mp
An element in the image of a finset is the value of the function on some member of the finset.
G.not_isDiag_of_mem_edgeSet
No edge of a simple graph is a self-loop (diagonal pair).
Sym2.mem_diagSet
A pair in the symmetric square is diagonal if and only if both endpoints are identical.
H.card_incidenceFinset_eq_degree
The number of incident edges to a vertex equals its degree.
H.incidenceFinset_eq_filter
The incidence finset of a vertex consists of all graph edges that contain that vertex.
Finset.filter_image
Filtering the image of a finset is the image of the filtered finset under the same function.
Finset.card_image_iff.mpr
The image of a finset under a function has the same cardinality as the finset if the function is injective on it.
Subtype.ext
Two elements of a subtype are equal if and only if their underlying values are equal.
SimpleGraph.fromEdgeSet_adj
Two vertices are adjacent in a graph induced by an edge set if and only if their pair is in the set and they are distinct.
SimpleGraph.lineGraph_adj_iff_exists.mp
Two edges are adjacent in the line graph if and only if they are distinct and share a vertex.
Sym2.mem_iff
An element belongs to an unordered pair s(a, b) if and only if it equals a or b.
Finset.card_le_one.mp
A finset has cardinality at most 1 if and only if any two of its elements are equal.
in1254_degree_one_two_edge_count
In a finite graph with maximum degree at most 2 and no adjacent vertices of the same degree, 3|E| + 2|V₀| = 2|V|.

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 scoped BigOperatorsprivate theorem in1254_degree_one_two_edge_count    {V : Type*} [Fintype V] [DecidableEq V]    (H : SimpleGraph V) [DecidableRel H.Adj]    (hbound : ∀ v, H.degree v ≤ 2)    (hdifferent : ∀ a b, H.Adj a b → H.degree a ≠ H.degree b) :    3 * H.edgeFinset.card + 2 * ((Finset.univ : Finset V).filter      fun v => H.degree v = 0).card = 2 * Fintype.card V := by  classical  let C : Finset V := Finset.univ.filter fun v => H.degree v = 2  let L : Finset V := Finset.univ.filter fun v => H.degree v = 1  let U : Finset V := Finset.univ.filter fun v => H.degree v = 0  have hdis : Disjoint C L := by    apply Finset.disjoint_left.mpr    intro v hvC hvL    have hc := (Finset.mem_filter.mp hvC).2    have hl := (Finset.mem_filter.mp hvL).2    omega  have hbip : H.IsBipartiteWith (C : Set V) (L : Set V) := by    refine ⟨Finset.disjoint_coe.mpr hdis, ?_⟩    intro a b hab    have ha := hab.degree_pos_left    have hb := hab.degree_pos_right    have hba := hbound a    have hbb := hbound b    have hne := hdifferent a b hab    simp only [Finset.mem_coe, C, L, Finset.mem_filter, Finset.mem_univ, true_and]    omega  have hsumC : ∑ v ∈ C, H.degree v = 2 * C.card := by    calc      _ = ∑ _v ∈ C, 2 := Finset.sum_congr rfl (fun v hv => (Finset.mem_filter.mp hv).2)      _ = _ := by simp [Nat.mul_comm]  have hsumL : ∑ v ∈ L, H.degree v = L.card := by    calc      _ = ∑ _v ∈ L, 1 := Finset.sum_congr rfl (fun v hv => (Finset.mem_filter.mp hv).2)      _ = _ := by simp  have hedgesC : 2 * C.card = H.edgeFinset.card := by    rw [← hsumC]    exact H.isBipartiteWith_sum_degrees_eq_card_edges hbip  have hedgesL : L.card = H.edgeFinset.card := by    rw [← hsumL]    exact H.isBipartiteWith_sum_degrees_eq_card_edges' hbip  have hpartition : C ∪ L = Uᶜ := by    ext v    have h := hbound v    simp only [Finset.mem_union, Finset.mem_compl, C, L, U, Finset.mem_filter,      Finset.mem_univ, true_and]    omega  have hcard : C.card + L.card + U.card = Fintype.card V := by    have hc := Finset.card_union_of_disjoint hdis    rw [hpartition, Finset.card_compl] at hc    have hu := Finset.card_le_univ U    omega  change 3 * H.edgeFinset.card + 2 * U.card = 2 * Fintype.card V  omegatheorem op309_p3_forest_selected_edge_count    {V : Type*} [Fintype V] [DecidableEq V]    (G : SimpleGraph V) [DecidableRel G.Adj] (R : Finset G.edgeSet)    (hbound : ∀ v, (R.filter fun e => v ∈ e.1).card ≤ 2)    (hpaths : ∀ e ∈ R, ¬ ∃ a b : V, e.1 = s(a,b) ∧      (R.filter fun f => a ∈ f.1).card = 2 ∧      (R.filter fun f => b ∈ f.1).card = 2)    (hneighbors : ∀ e ∈ R, ∃ f ∈ R, G.lineGraph.Adj e f) :    3 * R.card + 2 * ((Finset.univ : Finset V).filter      fun v => (R.filter fun e => v ∈ e.1).card = 0).card = 2 * Fintype.card V := by  classical  let H := op309_selected_edge_graph G R  letI : DecidableRel H.Adj := Classical.decRel _  have hedges : H.edgeFinset = R.image Subtype.val := by    ext e    rw [SimpleGraph.mem_edgeFinset]    change e ∈ (SimpleGraph.fromEdgeSet (↑(R.image Subtype.val) : Set (Sym2 V))).edgeSet ↔ _    rw [SimpleGraph.edgeSet_fromEdgeSet]    constructor    · intro he      exact he.1    · intro he      obtain ⟨f,hf,hfe⟩ := Finset.mem_image.mp he      refine ⟨he, ?_⟩      have hnot := G.not_isDiag_of_mem_edgeSet f.2      simpa [Sym2.mem_diagSet, ← hfe] using hnot  have hdegree : ∀ v, H.degree v = (R.filter fun e => v ∈ e.1).card := by    intro v    rw [← H.card_incidenceFinset_eq_degree v, H.incidenceFinset_eq_filter, hedges,      Finset.filter_image]    exact Finset.card_image_iff.mpr (fun _ _ _ _ h => Subtype.ext h)  have hHbound : ∀ v, H.degree v ≤ 2 := by intro v; rw [hdegree]; exact hbound v  have hdiff : ∀ a b, H.Adj a b → H.degree a ≠ H.degree b := by    intro a b hab heq    have hposA := hab.degree_pos_left    have hposB := hab.degree_pos_right    have hbA := hHbound a    have hbB := hHbound b    have hp : s(a,b) ∈ R.image Subtype.val := by      exact ((SimpleGraph.fromEdgeSet_adj (↑(R.image Subtype.val) : Set (Sym2 V))).mp hab).1    obtain ⟨e,he,heval⟩ := Finset.mem_image.mp hp    by_cases htwo : H.degree a = 2    · apply hpaths e he      exact ⟨a,b,heval, by simpa [hdegree] using htwo,        by rw [← hdegree b, ← heq]; exact htwo⟩    · have ha : (R.filter fun f => a ∈ f.1).card = 1 := by rw [← hdegree]; omega      have hb : (R.filter fun f => b ∈ f.1).card = 1 := by rw [← hdegree]; omega      obtain ⟨f,hf,hef⟩ := hneighbors e he      obtain ⟨hne,w,hwe,hwf⟩ := SimpleGraph.lineGraph_adj_iff_exists.mp hef      have hw : w = a ∨ w = b := by rw [heval, Sym2.mem_iff] at hwe; exact hwe      rcases hw with hwa | hwb      · subst w        have hle : (R.filter fun f => a ∈ f.1).card ≤ 1 := by omega        have he' : e ∈ R.filter (fun f => a ∈ f.1) := by          simp [he,heval]        have hf' : f ∈ R.filter (fun f => a ∈ f.1) := by simp [hf,hwf]        exact hne ((Finset.card_le_one.mp hle) e he' f hf')      · subst w        have hle : (R.filter fun f => b ∈ f.1).card ≤ 1 := by omega        have he' : e ∈ R.filter (fun f => b ∈ f.1) := by          simp [he,heval]        have hf' : f ∈ R.filter (fun f => b ∈ f.1) := by simp [hf,hwf]        exact hne ((Finset.card_le_one.mp hle) e he' f hf')  have hc : H.edgeFinset.card = R.card := by    rw [hedges]    exact Finset.card_image_iff.mpr (fun _ _ _ _ h => Subtype.ext h)  have hu : ((Finset.univ : Finset V).filter fun v => H.degree v = 0) =      ((Finset.univ : Finset V).filter fun v => (R.filter fun e => v ∈ e.1).card = 0) := by    ext v    simp [hdegree]  simpa only [hc,hu] using in1254_degree_one_two_edge_count H hHbound hdiff
See it in the graphDiscuss this resultChallenge it