graph_adjacent_twins_external_codegree_one_count
For adjacent complement twins and a common external nonneighbor set C, all but at most floor((d−1)(d−2)/2) vertices of C have complement codegree at most one with either twin.
Statement
theorem graph_adjacent_twins_external_codegree_one_count {V : Type*} [Fintype V] [DecidableEq V] (H : SimpleGraph V) [DecidableRel H.Adj] (d : ℕ) (hd : 2 ≤ d) (hmax : ∀ w, H.degree w ≤ d) (x y : V) (hxy : H.Adj x y) (htwins : ∀ w, w ≠ x → w ≠ y → (H.Adj x w ↔ H.Adj y w)) (C : Finset V) (hx : x ∉ C) (hy : y ∉ C) (hcover : ∀ z ∈ C, ¬ H.Adj x z) : C.card ≤ (C.filter (fun z => ((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)).card ≤ 1)).card + ((d-1)*(d-2))/2
- Source
- OP-1957: averaged complement-codegree bound from adjacent twins; experiment 34838 checks the sharpness construction.
- Verified
- 20 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext
The proof, explained
The proof partitions C into good vertices (having codegree with x at most one) and bad vertices (having codegree at least two), so that |C| = |Good| + |Bad|. It then bounds the number of edges between S = N(x) \ {y} and Bad by double counting. Each vertex in Bad has at least two neighbors in S, while each vertex in S has at most d - 2 neighbors in C and |S| ≤ d - 1, yielding 2|Bad| ≤ (d - 1)(d - 2) and thus |Bad| ≤ ⌊(d - 1)(d - 2)/2⌋.
Double counting identity for relations between two finite sets: the sum of row counts equals the sum of column counts.
We express each fiber size as a sum of 0-1 indicators using Finset.card_filter and congruence Finset.sum_congr. The resulting double sums are identical after exchanging the summation order using Finset.sum_comm.
uses
Finset.sum_congr,Finset.card_filter,Finset.sum_commlemma graph_adjacent_twins_external_codegree_one_count_finset_sum_card_filter_eq {α β : Type*} [DecidableEq α] [DecidableEq β] (s : Finset α) (t : Finset β) (R : α → β → Prop) [DecidableRel R] : ∑ a ∈ s, (t.filter (fun b => R a b)).card = ∑ b ∈ t, (s.filter (fun a => R a b)).card := by have h1 : (∑ a ∈ s, (t.filter (fun b => R a b)).card) = ∑ a ∈ s, ∑ b ∈ t, if R a b then 1 else 0 := by refine Finset.sum_congr rfl (fun a _ => ?_) exact Finset.card_filter (fun b => R a b) t have h2 : (∑ b ∈ t, (s.filter (fun a => R a b)).card) = ∑ b ∈ t, ∑ a ∈ s, if R a b then 1 else 0 := by refine Finset.sum_congr rfl (fun b _ => ?_) exact Finset.card_filter (fun a => R a b) s rw [h1, h2, Finset.sum_comm]
No vertex of C is adjacent to y.
Take any z ∈ C. Since neither x nor y belongs to C, z is distinct from both x and y. By the twin hypothesis, x is adjacent to z if and only if y is adjacent to z. Since x has no neighbors in C, y cannot be adjacent to z either.
lemma graph_adjacent_twins_external_codegree_one_count_not_adj_y_of_mem_C {V : Type*} (H : SimpleGraph V) (x y : V) (htwins : ∀ w, w ≠ x → w ≠ y → (H.Adj x w ↔ H.Adj y w)) (C : Finset V) (hx : x ∉ C) (hy : y ∉ C) (hcover : ∀ z ∈ C, ¬ H.Adj x z) {z : V} (hz : z ∈ C) : ¬ H.Adj y z := by have hzx : z ≠ x := by rintro rfl; exact hx hz have hzy : z ≠ y := by rintro rfl; exact hy hz have htw := htwins z hzx hzy have hxnz := hcover z hz intro hyz exact hxnz (htw.mpr hyz)
For any z ∈ C, the common neighbors of x and z in V are precisely the neighbors of z in S = N(x) \\ {y}.
By extensionality, a vertex w is adjacent to both x and z if and only if w ∈ N(x) \\ {y} and w is adjacent to z. If w were equal to y, then y would be adjacent to z, contradicting graph_adjacent_twins_external_codegree_one_count_not_adj_y_of_mem_C. The equivalence is verified by unpacking set memberships using Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_erase, and SimpleGraph.mem_neighborFinset.
uses
Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_erase,SimpleGraph.mem_neighborFinset,graph_adjacent_twins_external_codegree_one_count_not_adj_y_of_mem_Clemma graph_adjacent_twins_external_codegree_one_count_filter_adj_eq {V : Type*} [Fintype V] [DecidableEq V] (H : SimpleGraph V) [DecidableRel H.Adj] (x y : V) (htwins : ∀ w, w ≠ x → w ≠ y → (H.Adj x w ↔ H.Adj y w)) (C : Finset V) (hx : x ∉ C) (hy : y ∉ C) (hcover : ∀ z ∈ C, ¬ H.Adj x z) (z : V) (hz : z ∈ C) : ((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)) = ((H.neighborFinset x).erase y).filter (fun w => H.Adj w z) := by ext w simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_erase, SimpleGraph.mem_neighborFinset] constructor · rintro ⟨hxw, hzw⟩ refine ⟨⟨fun h => ?_, hxw⟩, H.adj_symm hzw⟩ have hyz : H.Adj y z := by rw [← h]; exact H.adj_symm hzw exact graph_adjacent_twins_external_codegree_one_count_not_adj_y_of_mem_C H x y htwins C hx hy hcover hz hyz · rintro ⟨⟨hwy, hxw⟩, hwz⟩ exact ⟨hxw, H.adj_symm hwz⟩
The set S = N(x) \\ {y} has cardinality at most d - 1.
Since x is adjacent to y, y belongs to N(x) by SimpleGraph.mem_neighborFinset. Removing y decreases the cardinality of N(x) by 1 by Finset.card_erase_of_mem. Since |N(x)| = deg(x) by SimpleGraph.card_neighborFinset_eq_degree and deg(x) ≤ d, we conclude |S| ≤ d - 1.
uses
SimpleGraph.mem_neighborFinset,Finset.card_erase_of_mem,SimpleGraph.card_neighborFinset_eq_degreelemma graph_adjacent_twins_external_codegree_one_count_card_S_le {V : Type*} [Fintype V] [DecidableEq V] (H : SimpleGraph V) [DecidableRel H.Adj] (d : ℕ) (hmax : ∀ w, H.degree w ≤ d) (x y : V) (hxy : H.Adj x y) : (((H.neighborFinset x).erase y).card) ≤ d - 1 := by have hy_mem : y ∈ H.neighborFinset x := by simp [SimpleGraph.mem_neighborFinset, hxy] rw [Finset.card_erase_of_mem hy_mem, SimpleGraph.card_neighborFinset_eq_degree] have := hmax x omega
Every vertex w ∈ S has at most d - 2 neighbors in C.
Because w ∈ N(x) \\ {y}, w is adjacent to x with w ≠ x and w ≠ y (using Finset.mem_of_mem_erase and Finset.ne_of_mem_erase). By the twin property, w is also adjacent to y. Both distinct vertices x and y are therefore in N(w) (using SimpleGraph.mem_neighborFinset). Since x, y ∉ C, the neighbors of w in C are contained in N(w) \\ {x, y} (using Finset.mem_filter, Finset.mem_sdiff, Finset.mem_insert, Finset.mem_singleton, and not_or). By Finset.card_sdiff_of_subset and Finset.card_pair, |N(w) \\ {x, y}| = deg(w) - 2. By Finset.card_le_card and SimpleGraph.card_neighborFinset_eq_degree, |N(w) ∩ C| ≤ deg(w) - 2 ≤ d - 2.
uses
Finset.mem_of_mem_erase,SimpleGraph.mem_neighborFinset,Finset.ne_of_mem_erase,Finset.mem_filter,Finset.mem_sdiff,Finset.mem_insert,Finset.mem_singleton,not_or,Finset.card_sdiff_of_subset,Finset.card_pair,Finset.card_le_card,SimpleGraph.card_neighborFinset_eq_degreelemma graph_adjacent_twins_external_codegree_one_count_card_neighbors_in_C_le {V : Type*} [Fintype V] [DecidableEq V] (H : SimpleGraph V) [DecidableRel H.Adj] (d : ℕ) (hmax : ∀ v, H.degree v ≤ d) (x y : V) (hxy : H.Adj x y) (htwins : ∀ v, v ≠ x → v ≠ y → (H.Adj x v ↔ H.Adj y v)) (C : Finset V) (hx : x ∉ C) (hy : y ∉ C) (w : V) (hw : w ∈ (H.neighborFinset x).erase y) : (C.filter (fun z => H.Adj w z)).card ≤ d - 2 := by have hw_adj_x : H.Adj x w := by have := Finset.mem_of_mem_erase hw rwa [SimpleGraph.mem_neighborFinset] at this have hwx : w ≠ x := hw_adj_x.ne' have hwy : w ≠ y := Finset.ne_of_mem_erase hw have hw_adj_y : H.Adj y w := (htwins w hwx hwy).mp hw_adj_x have hx_in_w : x ∈ H.neighborFinset w := by simp [SimpleGraph.mem_neighborFinset, hw_adj_x.symm] have hy_in_w : y ∈ H.neighborFinset w := by simp [SimpleGraph.mem_neighborFinset, hw_adj_y.symm] have hxy_ne : x ≠ y := hxy.ne have hsub : C.filter (fun z => H.Adj w z) ⊆ (H.neighborFinset w \ {x, y}) := by intro z hz simp only [Finset.mem_filter, Finset.mem_sdiff, Finset.mem_insert, Finset.mem_singleton, not_or, SimpleGraph.mem_neighborFinset] at hz ⊢ refine ⟨hz.2, ?_, ?_⟩ · rintro rfl; exact hx hz.1 · rintro rfl; exact hy hz.1 have hpair_sub : ({x, y} : Finset V) ⊆ H.neighborFinset w := by intro z hz simp only [Finset.mem_insert, Finset.mem_singleton] at hz rcases hz with rfl | rfl · exact hx_in_w · exact hy_in_w have hcard_sdiff : (H.neighborFinset w \ {x, y}).card = (H.neighborFinset w).card - 2 := by rw [Finset.card_sdiff_of_subset hpair_sub, Finset.card_pair hxy_ne] have hle := Finset.card_le_card hsub rw [hcard_sdiff, SimpleGraph.card_neighborFinset_eq_degree] at hle have := hmax w omega
Partition C into good vertices (codegree with x at most 1) and bad vertices (codegree at least 2), so |C| = |Good| + |Bad|.
We partition C into Good (vertices with at most 1 common neighbor with x) and Bad (vertices with at least 2 common neighbors with x). By Finset.card_filter_add_card_filter_not, |C| = |Good| + |Bad|.
uses
Finset.card_filter_add_card_filter_nottheorem graph_adjacent_twins_external_codegree_one_count {V : Type*} [Fintype V] [DecidableEq V] (H : SimpleGraph V) [DecidableRel H.Adj] (d : ℕ) (hd : 2 ≤ d) (hmax : ∀ w, H.degree w ≤ d) (x y : V) (hxy : H.Adj x y) (htwins : ∀ w, w ≠ x → w ≠ y → (H.Adj x w ↔ H.Adj y w)) (C : Finset V) (hx : x ∉ C) (hy : y ∉ C) (hcover : ∀ z ∈ C, ¬ H.Adj x z) : C.card ≤ (C.filter (fun z => ((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)).card ≤ 1)).card + ((d-1)*(d-2))/2 := by have _ := hd let Good := C.filter (fun z => ((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)).card ≤ 1) let Bad := C.filter (fun z => ¬ (((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)).card ≤ 1)) have hC_eq : C.card = Good.card + Bad.card := by exact (Finset.card_filter_add_card_filter_not _).symm
The sum over w ∈ S of the number of bad neighbors of w is at most (d - 1)(d - 2).
For each w ∈ S, the bad neighbors of w form a subset of all neighbors of w in C (by Finset.mem_filter and Finset.mem_of_mem_filter). By graph_adjacent_twins_external_codegree_one_count_card_neighbors_in_C_le, w has at most d - 2 neighbors in C. Summing this over S gives at most |S|(d - 2) by Finset.sum_le_sum and Finset.card_le_card. Since |S| ≤ d - 1 by graph_adjacent_twins_external_codegree_one_count_card_S_le, Nat.mul_le_mul_right gives the upper bound (d - 1)(d - 2).
uses
Finset.sum_le_sum,Finset.mem_filter,Finset.mem_of_mem_filter,Finset.card_le_card,graph_adjacent_twins_external_codegree_one_count_card_neighbors_in_C_le,Nat.mul_le_mul_right,graph_adjacent_twins_external_codegree_one_count_card_S_lelet S := (H.neighborFinset x).erase y have h_sum_le : ∑ w ∈ S, (Bad.filter (fun z => H.Adj w z)).card ≤ (d - 1) * (d - 2) := by have h1 : ∑ w ∈ S, (Bad.filter (fun z => H.Adj w z)).card ≤ ∑ w ∈ S, (d - 2) := by apply Finset.sum_le_sum intro w hw have hsub : Bad.filter (fun z => H.Adj w z) ⊆ C.filter (fun z => H.Adj w z) := by intro z hz simp only [Finset.mem_filter] at hz ⊢ exact ⟨Finset.mem_of_mem_filter z hz.1, hz.2⟩ exact (Finset.card_le_card hsub).trans (graph_adjacent_twins_external_codegree_one_count_card_neighbors_in_C_le H d hmax x y hxy htwins C hx hy w hw) have h2 : ∑ w ∈ S, (d - 2) = S.card * (d - 2) := by simp have h3 : S.card * (d - 2) ≤ (d - 1) * (d - 2) := Nat.mul_le_mul_right (d - 2) (graph_adjacent_twins_external_codegree_one_count_card_S_le H d hmax x y hxy) omega
The sum over z ∈ Bad of the number of neighbors of z in S is at least 2|Bad|.
For each z ∈ Bad, graph_adjacent_twins_external_codegree_one_count_filter_adj_eq shows that the common neighbors of x and z in V are precisely the neighbors of z in S. Since z ∈ Bad, this count is strictly greater than 1, so at least 2. Summing 2 over Bad using Finset.sum_le_sum and simplifying via mul_comm gives the lower bound 2|Bad|.
uses
Finset.mem_of_mem_filter,Finset.mem_filter,graph_adjacent_twins_external_codegree_one_count_filter_adj_eq,Finset.sum_le_sum,mul_commhave h_sum_ge : 2 * Bad.card ≤ ∑ z ∈ Bad, (S.filter (fun w => H.Adj w z)).card := by have h_each : ∀ z ∈ Bad, 2 ≤ (S.filter (fun w => H.Adj w z)).card := by intro z hz have hzC : z ∈ C := Finset.mem_of_mem_filter z hz have h_not_le : ¬ (((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)).card ≤ 1) := (Finset.mem_filter.mp hz).2 have h_eq : ((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)) = S.filter (fun w => H.Adj w z) := graph_adjacent_twins_external_codegree_one_count_filter_adj_eq H x y htwins C hx hy hcover z hzC rw [h_eq] at h_not_le omega have h_sum : ∑ z ∈ Bad, 2 ≤ ∑ z ∈ Bad, (S.filter (fun w => H.Adj w z)).card := Finset.sum_le_sum (fun z hz => h_each z hz) have : ∑ z ∈ Bad, 2 = 2 * Bad.card := by simp [mul_comm] rwa [this] at h_sum
The sum of bad neighbors over w ∈ S equals the sum of neighbors in S over z ∈ Bad by double counting.
By the double counting lemma graph_adjacent_twins_external_codegree_one_count_finset_sum_card_filter_eq applied to S, Bad, and the adjacency relation, both sums count the edges between S and Bad.
uses
graph_adjacent_twins_external_codegree_one_count_finset_sum_card_filter_eqhave h_double_count : ∑ w ∈ S, (Bad.filter (fun z => H.Adj w z)).card = ∑ z ∈ Bad, (S.filter (fun w => H.Adj w z)).card := graph_adjacent_twins_external_codegree_one_count_finset_sum_card_filter_eq S Bad H.Adj
The cardinality of C is at most |Good| + ⌊(d - 1)(d - 2) / 2⌋.
Combining the lower bound 2|Bad| with the upper bound (d - 1)(d - 2) via the double counting identity yields 2|Bad| ≤ (d - 1)(d - 2), so |Bad| ≤ ⌊(d - 1)(d - 2) / 2⌋. Adding |Good| to both sides gives |C| ≤ |Good| + ⌊(d - 1)(d - 2) / 2⌋ because |C| = |Good| + |Bad|.
have h_bad_le : 2 * Bad.card ≤ (d - 1) * (d - 2) := by omega change C.card ≤ Good.card + ((d - 1) * (d - 2)) / 2 omega
Finset.sum_congr- If two finite sets are equal and their summands agree on every element, their sums are equal.
Finset.card_filter- The size of a filtered finset equals the sum of indicator values (1 if the condition holds, 0 otherwise) over the set.
Finset.sum_comm- Fubini's theorem for finite sums: the order of summation in a double sum over finite sets can be exchanged.
Finset.mem_filter- An element belongs to a filtered finset if and only if it belongs to the underlying finset and satisfies the predicate.
Finset.mem_univ- Every element of a finite type belongs to the universal finset Finset.univ.
true_and- The logical equivalence (True ∧ p) = p.
Finset.mem_erase- An element belongs to s \\ {b} if and only if it is not equal to b and belongs to s.
SimpleGraph.mem_neighborFinset- A vertex w belongs to the neighbor finset of v if and only if v and w are adjacent in the graph.
graph_adjacent_twins_external_codegree_one_count_not_adj_y_of_mem_C- If x and y are twins with respect to vertices outside {x, y}, and no vertex in C is adjacent to x, then no vertex in C is adjacent to y.
Finset.card_erase_of_mem- Erasing an element that belongs to a finite set decreases its cardinality by 1.
SimpleGraph.card_neighborFinset_eq_degree- The cardinality of the neighbor finset of a vertex is equal to its graph degree.
Finset.mem_of_mem_erase- An element belonging to s \\ {a} belongs to s.
Finset.ne_of_mem_erase- An element belonging to s \\ {a} is not equal to a.
Finset.mem_sdiff- An element belongs to the set difference s \\ t if and only if it belongs to s and does not belong to t.
Finset.mem_insert- An element belongs to insert b s if and only if it equals b or belongs to s.
Finset.mem_singleton- An element belongs to the singleton set {a} if and only if it equals a.
not_or- De Morgan's law for disjunction: ¬(p ∨ q) ↔ ¬p ∧ ¬q.
Finset.card_sdiff_of_subset- If s ⊆ t for finite sets, then |t \\ s| = |t| - |s|.
Finset.card_pair- If a ≠ b, then the pair {a, b} has cardinality 2.
Finset.card_le_card- If one finite set is a subset of another, its cardinality is at most the cardinality of the larger set.
Finset.card_filter_add_card_filter_not- For any predicate p on a finite set s, the number of elements satisfying p plus the number of elements not satisfying p equals the size of s.
Finset.sum_le_sum- If f(i) ≤ g(i) for all elements i in a finite set, then the sum of f over the set is at most the sum of g.
Finset.mem_of_mem_filter- An element belonging to a filtered finset belongs to the underlying finset.
graph_adjacent_twins_external_codegree_one_count_card_neighbors_in_C_le- For any vertex w in N(x) \\ {y}, the number of neighbors of w in C is at most d - 2.
Nat.mul_le_mul_right- Multiplying both sides of an inequality of natural numbers on the right preserves the inequality.
graph_adjacent_twins_external_codegree_one_count_card_S_le- The set of neighbors of x other than y has size at most d - 1.
graph_adjacent_twins_external_codegree_one_count_filter_adj_eq- For any z ∈ C, the common neighbors of x and z in V coincide with the neighbors of z in S = N(x) \\ {y}.
mul_comm- Multiplication is commutative: a * b = b * a.
graph_adjacent_twins_external_codegree_one_count_finset_sum_card_filter_eq- Double counting: the sum over a ∈ s of the number of b ∈ t related to a equals the sum over b ∈ t of the number of a ∈ s related to b.
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
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
lemma graph_adjacent_twins_external_codegree_one_count_finset_sum_card_filter_eq {α β : Type*} [DecidableEq α] [DecidableEq β] (s : Finset α) (t : Finset β) (R : α → β → Prop) [DecidableRel R] : ∑ a ∈ s, (t.filter (fun b => R a b)).card = ∑ b ∈ t, (s.filter (fun a => R a b)).card := by have h1 : (∑ a ∈ s, (t.filter (fun b => R a b)).card) = ∑ a ∈ s, ∑ b ∈ t, if R a b then 1 else 0 := by refine Finset.sum_congr rfl (fun a _ => ?_) exact Finset.card_filter (fun b => R a b) t have h2 : (∑ b ∈ t, (s.filter (fun a => R a b)).card) = ∑ b ∈ t, ∑ a ∈ s, if R a b then 1 else 0 := by refine Finset.sum_congr rfl (fun b _ => ?_) exact Finset.card_filter (fun a => R a b) s rw [h1, h2, Finset.sum_comm]lemma graph_adjacent_twins_external_codegree_one_count_not_adj_y_of_mem_C {V : Type*} (H : SimpleGraph V) (x y : V) (htwins : ∀ w, w ≠ x → w ≠ y → (H.Adj x w ↔ H.Adj y w)) (C : Finset V) (hx : x ∉ C) (hy : y ∉ C) (hcover : ∀ z ∈ C, ¬ H.Adj x z) {z : V} (hz : z ∈ C) : ¬ H.Adj y z := by have hzx : z ≠ x := by rintro rfl; exact hx hz have hzy : z ≠ y := by rintro rfl; exact hy hz have htw := htwins z hzx hzy have hxnz := hcover z hz intro hyz exact hxnz (htw.mpr hyz)lemma graph_adjacent_twins_external_codegree_one_count_filter_adj_eq {V : Type*} [Fintype V] [DecidableEq V] (H : SimpleGraph V) [DecidableRel H.Adj] (x y : V) (htwins : ∀ w, w ≠ x → w ≠ y → (H.Adj x w ↔ H.Adj y w)) (C : Finset V) (hx : x ∉ C) (hy : y ∉ C) (hcover : ∀ z ∈ C, ¬ H.Adj x z) (z : V) (hz : z ∈ C) : ((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)) = ((H.neighborFinset x).erase y).filter (fun w => H.Adj w z) := by ext w simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_erase, SimpleGraph.mem_neighborFinset] constructor · rintro ⟨hxw, hzw⟩ refine ⟨⟨fun h => ?_, hxw⟩, H.adj_symm hzw⟩ have hyz : H.Adj y z := by rw [← h]; exact H.adj_symm hzw exact graph_adjacent_twins_external_codegree_one_count_not_adj_y_of_mem_C H x y htwins C hx hy hcover hz hyz · rintro ⟨⟨hwy, hxw⟩, hwz⟩ exact ⟨hxw, H.adj_symm hwz⟩lemma graph_adjacent_twins_external_codegree_one_count_card_S_le {V : Type*} [Fintype V] [DecidableEq V] (H : SimpleGraph V) [DecidableRel H.Adj] (d : ℕ) (hmax : ∀ w, H.degree w ≤ d) (x y : V) (hxy : H.Adj x y) : (((H.neighborFinset x).erase y).card) ≤ d - 1 := by have hy_mem : y ∈ H.neighborFinset x := by simp [SimpleGraph.mem_neighborFinset, hxy] rw [Finset.card_erase_of_mem hy_mem, SimpleGraph.card_neighborFinset_eq_degree] have := hmax x omegalemma graph_adjacent_twins_external_codegree_one_count_card_neighbors_in_C_le {V : Type*} [Fintype V] [DecidableEq V] (H : SimpleGraph V) [DecidableRel H.Adj] (d : ℕ) (hmax : ∀ v, H.degree v ≤ d) (x y : V) (hxy : H.Adj x y) (htwins : ∀ v, v ≠ x → v ≠ y → (H.Adj x v ↔ H.Adj y v)) (C : Finset V) (hx : x ∉ C) (hy : y ∉ C) (w : V) (hw : w ∈ (H.neighborFinset x).erase y) : (C.filter (fun z => H.Adj w z)).card ≤ d - 2 := by have hw_adj_x : H.Adj x w := by have := Finset.mem_of_mem_erase hw rwa [SimpleGraph.mem_neighborFinset] at this have hwx : w ≠ x := hw_adj_x.ne' have hwy : w ≠ y := Finset.ne_of_mem_erase hw have hw_adj_y : H.Adj y w := (htwins w hwx hwy).mp hw_adj_x have hx_in_w : x ∈ H.neighborFinset w := by simp [SimpleGraph.mem_neighborFinset, hw_adj_x.symm] have hy_in_w : y ∈ H.neighborFinset w := by simp [SimpleGraph.mem_neighborFinset, hw_adj_y.symm] have hxy_ne : x ≠ y := hxy.ne have hsub : C.filter (fun z => H.Adj w z) ⊆ (H.neighborFinset w \ {x, y}) := by intro z hz simp only [Finset.mem_filter, Finset.mem_sdiff, Finset.mem_insert, Finset.mem_singleton, not_or, SimpleGraph.mem_neighborFinset] at hz ⊢ refine ⟨hz.2, ?_, ?_⟩ · rintro rfl; exact hx hz.1 · rintro rfl; exact hy hz.1 have hpair_sub : ({x, y} : Finset V) ⊆ H.neighborFinset w := by intro z hz simp only [Finset.mem_insert, Finset.mem_singleton] at hz rcases hz with rfl | rfl · exact hx_in_w · exact hy_in_w have hcard_sdiff : (H.neighborFinset w \ {x, y}).card = (H.neighborFinset w).card - 2 := by rw [Finset.card_sdiff_of_subset hpair_sub, Finset.card_pair hxy_ne] have hle := Finset.card_le_card hsub rw [hcard_sdiff, SimpleGraph.card_neighborFinset_eq_degree] at hle have := hmax w omegatheorem graph_adjacent_twins_external_codegree_one_count {V : Type*} [Fintype V] [DecidableEq V] (H : SimpleGraph V) [DecidableRel H.Adj] (d : ℕ) (hd : 2 ≤ d) (hmax : ∀ w, H.degree w ≤ d) (x y : V) (hxy : H.Adj x y) (htwins : ∀ w, w ≠ x → w ≠ y → (H.Adj x w ↔ H.Adj y w)) (C : Finset V) (hx : x ∉ C) (hy : y ∉ C) (hcover : ∀ z ∈ C, ¬ H.Adj x z) : C.card ≤ (C.filter (fun z => ((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)).card ≤ 1)).card + ((d-1)*(d-2))/2 := by have _ := hd let Good := C.filter (fun z => ((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)).card ≤ 1) let Bad := C.filter (fun z => ¬ (((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)).card ≤ 1)) have hC_eq : C.card = Good.card + Bad.card := by exact (Finset.card_filter_add_card_filter_not _).symm let S := (H.neighborFinset x).erase y have h_sum_le : ∑ w ∈ S, (Bad.filter (fun z => H.Adj w z)).card ≤ (d - 1) * (d - 2) := by have h1 : ∑ w ∈ S, (Bad.filter (fun z => H.Adj w z)).card ≤ ∑ w ∈ S, (d - 2) := by apply Finset.sum_le_sum intro w hw have hsub : Bad.filter (fun z => H.Adj w z) ⊆ C.filter (fun z => H.Adj w z) := by intro z hz simp only [Finset.mem_filter] at hz ⊢ exact ⟨Finset.mem_of_mem_filter z hz.1, hz.2⟩ exact (Finset.card_le_card hsub).trans (graph_adjacent_twins_external_codegree_one_count_card_neighbors_in_C_le H d hmax x y hxy htwins C hx hy w hw) have h2 : ∑ w ∈ S, (d - 2) = S.card * (d - 2) := by simp have h3 : S.card * (d - 2) ≤ (d - 1) * (d - 2) := Nat.mul_le_mul_right (d - 2) (graph_adjacent_twins_external_codegree_one_count_card_S_le H d hmax x y hxy) omega have h_sum_ge : 2 * Bad.card ≤ ∑ z ∈ Bad, (S.filter (fun w => H.Adj w z)).card := by have h_each : ∀ z ∈ Bad, 2 ≤ (S.filter (fun w => H.Adj w z)).card := by intro z hz have hzC : z ∈ C := Finset.mem_of_mem_filter z hz have h_not_le : ¬ (((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)).card ≤ 1) := (Finset.mem_filter.mp hz).2 have h_eq : ((Finset.univ : Finset V).filter (fun w => H.Adj x w ∧ H.Adj z w)) = S.filter (fun w => H.Adj w z) := graph_adjacent_twins_external_codegree_one_count_filter_adj_eq H x y htwins C hx hy hcover z hzC rw [h_eq] at h_not_le omega have h_sum : ∑ z ∈ Bad, 2 ≤ ∑ z ∈ Bad, (S.filter (fun w => H.Adj w z)).card := Finset.sum_le_sum (fun z hz => h_each z hz) have : ∑ z ∈ Bad, 2 = 2 * Bad.card := by simp [mul_comm] rwa [this] at h_sum have h_double_count : ∑ w ∈ S, (Bad.filter (fun z => H.Adj w z)).card = ∑ z ∈ Bad, (S.filter (fun w => H.Adj w z)).card := graph_adjacent_twins_external_codegree_one_count_finset_sum_card_filter_eq S Bad H.Adj have h_bad_le : 2 * Bad.card ≤ (d - 1) * (d - 2) := by omega change C.card ≤ Good.card + ((d - 1) * (d - 2)) / 2 omega