AFTD Auto-Formalizing Theoretical Domains

no_two_crossing_matching_independence_incidence_bound

theoremverified

If distinct vertices of U cannot cross to adjacent vertices of R, |U|=2r, |R|=2k, a (k−r)-matching inside R and α≤k imply e(U,R)≤2rk+2r.

Statement

theorem no_two_crossing_matching_independence_incidence_bound
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj]
    (U R : Finset V) (r k : ℕ) (hr : 1 ≤ r)
    (hU : U.card = 2*r) (hR : R.card = 2*k)
    (N : G.Subgraph) (hN : N.IsMatching) (hNR : N.verts ⊆ (R : Set V))
    (hNcard : N.edgeSet.ncard + r = k)
    (hforbid : ∀ u ∈ U, ∀ v ∈ U, u ≠ v → ∀ x ∈ R, ∀ y ∈ R,
      G.Adj u x → G.Adj v y → ¬ G.Adj x y)
    (hind : ∀ I : Finset V, (∀ x ∈ I, ∀ y ∈ I, x ≠ y → ¬ G.Adj x y) → I.card ≤ k) :
    (∑ u ∈ U, ((G.neighborFinset u) ∩ R).card) ≤ 2*r*k + 2*r
Source
Balanced-cut reduction for OP-1957; https://arxiv.org/abs/1011.3384.
Verified
28 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 4
Used by 1

The proof, explained

The proof bounds the edge count $e(U, R)$ by partitioning $R$ into vertices $B$ with degree at least 2 into $U$, vertices $Z$ with degree 0, and the remaining vertices $L$ with degree at most 1. The forbidden crossing condition implies that $B$ is an independent set (hence $|B| \le k$) and that every neighbor in $R$ of a vertex in $B$ must lie in $Z$. The $(k-r)$-matching $N \subseteq R$ injectively matches vertices of $B \cap V(N)$ into $Z$, which together with the unmatched vertices of $R$ bounds $|B| \le |Z| + 2r$. Combining $e(U, R) \le 2r|B| + |L|$ with $|B| + |Z| + |L| = 2k$ and the bounds on $|B|$ yields $e(U, R) \le 2rk + 2r$.

  1. Define $K(x) = N_U(x)$ for all $x$, and partition $R$ into high-degree vertices $B = \{x \in R \mid |K(x)| \ge 2\}$ and zero-degree vertices $Z = \{x \in R \mid |K(x)| = 0\}$; each vertex $x$ satisfies $|K(x)| \le 2r$.

    The neighborhood of any vertex $x$ inside $U$, denoted $K(x)$, is formed by filtering $U$ by adjacency to $x$. Since $K(x) \subseteq U$ and $|U| = 2r$, every vertex has at most $2r$ neighbors in $U$. The subsets $B$ and $Z$ collect vertices in $R$ with at least 2 neighbors and zero neighbors in $U$, respectively.

    lines 11–19

    uses Finset.card_filter_le

      set_option maxHeartbeats 4000000 in
        classical
        let K : V → Finset V := fun x => U.filter (fun u => G.Adj u x)
        let B : Finset V := R.filter (fun x => 2 ≤ (K x).card)
        let Z : Finset V := R.filter (fun x => (K x).card = 0)
        have hKR : ∀ x, (K x).card ≤ 2*r := by
          intro x
          have hh := Finset.card_filter_le U (fun u => G.Adj u x)
          simpa [K,hU] using hh
  2. $B$ and $Z$ are disjoint subsets of $R$.

    Both $B$ and $Z$ are defined by filtering $R$, so they are subsets of $R$. If a vertex $x$ belonged to both, its degree in $U$ would satisfy both $|K(x)| \ge 2$ and $|K(x)| = 0$, which is impossible.

    lines 20–27

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

        have hBsub : B ⊆ R := Finset.filter_subset _ _
        have hZsub : Z ⊆ R := Finset.filter_subset _ _
        have hBZ : Disjoint B Z := by
          apply Finset.disjoint_left.mpr
          intro x hxB hxZ
          have hb := (Finset.mem_filter.mp hxB).2
          have hz := (Finset.mem_filter.mp hxZ).2
          omega
  3. Every neighbor in $R$ of a vertex in $B$ belongs to $Z$.

    Suppose for contradiction that $x \in B$ has a neighbor $y \in R$ with $|K(y)| > 0$. Then there exists some $v \in U$ adjacent to $y$. Because $|K(x)| \ge 2$, $K(x)$ cannot be contained in the singleton $\{v\}$, so there is some $u \in K(x)$ with $u \ne v$. But then $u \sim x$ and $v \sim y$ with $u \ne v$ and $x \sim y$, directly violating the no-crossing hypothesis (`hforbid`). Hence $|K(y)| = 0$, which means $y \in Z$.

    lines 28–48

    uses Finset.mem_filter.mp, Finset.mem_filter.mpr, Nat.pos_of_ne_zero, Finset.card_pos.mp, Finset.card_le_card, Finset.not_subset.mp

        have hno : ∀ x ∈ B, ∀ y ∈ R, G.Adj x y → y ∈ Z := by
          intro x hxB y hyR hxy
          have hxR := hBsub hxB
          have hxcard : 2 ≤ (K x).card := (Finset.mem_filter.mp hxB).2
          apply Finset.mem_filter.mpr
          refine ⟨hyR,?_⟩
          by_contra hn
          have hpos : 0 < (K y).card := Nat.pos_of_ne_zero hn
          obtain ⟨v,hv⟩ := Finset.card_pos.mp hpos
          have hvU : v ∈ U := (Finset.mem_filter.mp hv).1
          have hvy : G.Adj v y := (Finset.mem_filter.mp hv).2
          have hnsub : ¬ K x ⊆ {v} := by
            intro hh
            have hc := Finset.card_le_card hh
            simp at hc
            omega
          obtain ⟨u,hu,huv⟩ := Finset.not_subset.mp hnsub
          have huU : u ∈ U := (Finset.mem_filter.mp hu).1
          have hux : G.Adj u x := (Finset.mem_filter.mp hu).2
          have huv' : u ≠ v := by simpa using huv
          exact hforbid u huU v hvU huv' x hxR y hyR hux hvy hxy
  4. $B$ is an independent set in $G$, and therefore $|B| \le k$.

    If two vertices in $B$ were adjacent, the second would have to lie in $Z$ by the previous step. But $B$ and $Z$ are disjoint, so no two vertices in $B$ are adjacent. Applying the hypothesis that every independent set has size at most $k$ (`hind`) yields $|B| \le k$.

    lines 49–53

    uses Finset.disjoint_left.mp

        have hBind : ∀ x ∈ B, ∀ y ∈ B, x ≠ y → ¬ G.Adj x y := by
          intro x hx y hy hne hxy
          have hyZ := hno x hx y (hBsub hy) hxy
          exact Finset.disjoint_left.mp hBZ hy hyZ
        have hBcard : B.card ≤ k := hind B hBind
  5. The vertex set $D$ of the matching $N$ is contained in $R$ and has size $2(k - r)$.

    The vertices of $N$ lie in $R$ by assumption (`hNR`). In any matching, the number of vertices is twice the number of edges. Since $|E(N)| + r = k$, we have $|E(N)| = k - r$, so $|D| = 2(k - r)$.

    lines 54–61

    uses Set.ncard_eq_toFinset_card', in1076_matching_twice_card

        let D : Finset V := N.verts.toFinset
        have hDcard : D.card = 2*N.edgeSet.ncard := by
          dsimp [D]
          rw [← Set.ncard_eq_toFinset_card']
          exact (in1076_matching_twice_card hN).symm
        have hDR : D ⊆ R := by
          intro x hx
          exact hNR (by simpa [D] using hx)
  6. The intersection $Q = B \cap D$ satisfies $|Q| \le |Z|$.

    Every vertex $x \in Q$ belongs to the matching $N$, so it has a unique matching partner $y \in V(N) \subseteq R$. Since $x \in B$ and $x \sim y$, $y$ must belong to $Z$. Mapping each $x \in Q$ to its partner $y \in Z$ defines an injective function because $N$ is a matching (no vertex is matched twice). The existence of this injection implies $|Q| \le |Z|$.

    lines 62–94

    uses Finset.mem_inter.mp, Classical.choose, Classical.choose_spec, congrArg, Subtype.val, Subtype.ext, Fintype.card_le_of_injective

        let Q : Finset V := B ∩ D
        have hQZ : Q.card ≤ Z.card := by
          let f : {x // x ∈ Q} → {y // y ∈ Z} := fun x =>
            let hxD : x.val ∈ N.verts := by
              have hx := (Finset.mem_inter.mp x.property).2
              simpa [D] using hx
            let y := Classical.choose (hN hxD)
            ⟨y, hno x.val (Finset.mem_inter.mp x.property).1 y
              (hNR (N.edge_vert (Classical.choose_spec (hN hxD)).1.symm))
              (N.adj_sub (Classical.choose_spec (hN hxD)).1)⟩
          have hinj : Function.Injective f := by
            intro a b hab
            let haD : a.val ∈ N.verts := by
              have ha := (Finset.mem_inter.mp a.property).2
              simpa [D] using ha
            let hbD : b.val ∈ N.verts := by
              have hb := (Finset.mem_inter.mp b.property).2
              simpa [D] using hb
            let ya := Classical.choose (hN haD)
            let yb := Classical.choose (hN hbD)
            have he : ya=yb := by
              have hh := congrArg Subtype.val hab
              change ya = yb at hh
              exact hh
            have hay : N.Adj ya a.val := (Classical.choose_spec (hN haD)).1.symm
            have hby : N.Adj ya b.val := by
              rw [he]
              exact (Classical.choose_spec (hN hbD)).1.symm
            have hya : ya ∈ N.verts := N.edge_vert hay
            apply Subtype.ext
            exact (hN hya).unique hay hby
          have hh := Fintype.card_le_of_injective f hinj
          simpa using hh
  7. $|B| \le |Z| + 2r$.

    The vertices of $B$ outside the matching satisfy $B \setminus D \subseteq R \setminus D$. Since $|R| = 2k$ and $|D| = 2(k - r)$, $|R \setminus D| = 2r$, so $|B \setminus D| \le 2r$. Decomposing $B$ into $(B \cap D) \cup (B \setminus D)$ gives $|B| = |Q| + |B \setminus D| \le |Z| + 2r$.

    lines 95–103

    uses Finset.mem_sdiff.mpr, Finset.mem_sdiff.mp, Finset.card_le_card, Finset.card_sdiff_add_card_eq_card, Finset.card_sdiff_add_card_inter

        have hBbound : B.card ≤ Z.card+2*r := by
          have hbd : (B \ D) ⊆ R \ D := by
            intro x hx
            exact Finset.mem_sdiff.mpr ⟨hBsub (Finset.mem_sdiff.mp hx).1,(Finset.mem_sdiff.mp hx).2⟩
          have hb := Finset.card_le_card hbd
          have hRD := Finset.card_sdiff_add_card_eq_card hDR
          have hBD := Finset.card_sdiff_add_card_inter B D
          dsimp [Q] at hQZ
          omega
  8. The number of edges between $U$ and $R$ equals $\sum_{x \in R} |K(x)|$.

    By standard double counting of edges in a bipartite graph, summing the number of neighbors in $R$ over all $u \in U$ is identical to summing the number of neighbors in $U$ over all $x \in R$.

    lines 104–111

    uses Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow, Finset.bipartiteAbove, Finset.bipartiteBelow

        have hsumEq : (∑ u ∈ U, ((G.neighborFinset u) ∩ R).card) = ∑ x ∈ R, (K x).card := by
          have hAbove : ∀ u, R.filter (fun x => G.Adj u x) = (G.neighborFinset u) ∩ R := by
            intro u
            ext x
            simp [and_comm]
          have hh := Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow (s:=U) (t:=R) G.Adj
          simp only [Finset.bipartiteAbove,Finset.bipartiteBelow,hAbove] at hh
          simpa [K] using hh
  9. $R$ is partitioned into pairwise disjoint sets $B$, $Z$, and $L = R \setminus (B \cup Z)$, where every $x \in L$ satisfies $|K(x)| \le 1$.

    Vertices in $L$ do not belong to $B$, so by definition $|K(x)| < 2$, which means $|K(x)| \le 1$. By definition of set difference and the disjointness of $B$ and $Z$, the three sets $B, Z, L$ are pairwise disjoint and their union is all of $R$.

    lines 112–146

    uses Finset.mem_sdiff.mp, Finset.mem_sdiff.mpr, Finset.mem_union_left, Finset.mem_union_right, Finset.mem_union.mp, Finset.mem_filter.mpr, Finset.disjoint_left.mpr, Finset.disjoint_union_left.mpr

        let L : Finset V := R \ (B ∪ Z)
        have hL : ∀ x ∈ L, (K x).card ≤ 1 := by
          intro x hx
          have hnB : x ∉ B := by
            intro h
            exact (Finset.mem_sdiff.mp hx).2 (Finset.mem_union_left Z h)
          have hxR : x ∈ R := (Finset.mem_sdiff.mp hx).1
          by_contra hn
          apply hnB
          exact Finset.mem_filter.mpr ⟨hxR,by omega⟩
        have hcover : B ∪ Z ∪ L = R := by
          ext x
          constructor
          · intro hx
            rcases Finset.mem_union.mp hx with hx | hx
            · rcases Finset.mem_union.mp hx with hx | hx
              · exact hBsub hx
              · exact hZsub hx
            · exact (Finset.mem_sdiff.mp hx).1
          · intro hx
            by_cases hb : x ∈ B
            · exact Finset.mem_union_left L (Finset.mem_union_left Z hb)
            · by_cases hz : x ∈ Z
              · exact Finset.mem_union_left L (Finset.mem_union_right B hz)
              · apply Finset.mem_union_right
                exact Finset.mem_sdiff.mpr ⟨hx,by simp [hb,hz]⟩
        have hdisBL : Disjoint B L := by
          apply Finset.disjoint_left.mpr
          intro x hxB hxL
          exact (Finset.mem_sdiff.mp hxL).2 (Finset.mem_union_left Z hxB)
        have hdisZL : Disjoint Z L := by
          apply Finset.disjoint_left.mpr
          intro x hxZ hxL
          exact (Finset.mem_sdiff.mp hxL).2 (Finset.mem_union_right B hxZ)
        have hBL : Disjoint (B ∪ Z) L := Finset.disjoint_union_left.mpr ⟨hdisBL,hdisZL⟩
  10. $\sum_{x \in R} |K(x)| \le 2r|B| + |L|$.

    Split the sum over the partition $R = B \cup Z \cup L$. On $B$, each vertex has $|K(x)| \le |U| = 2r$, giving at most $2r|B|$. On $Z$, each vertex has $|K(x)| = 0$, contributing 0. On $L$, each vertex has $|K(x)| \le 1$, contributing at most $|L|$. Adding these contributions gives the bound.

    lines 147–159

    uses Finset.sum_union, Finset.sum_le_sum, Nat.mul_comm, Finset.sum_eq_zero, Finset.mem_filter.mp

        have hsumBound : (∑ x ∈ R, (K x).card) ≤ 2*r*B.card+L.card := by
          rw [← hcover,Finset.sum_union hBL,Finset.sum_union hBZ]
          have hsumB : (∑ x ∈ B, (K x).card) ≤ 2*r*B.card := by
            have hh := Finset.sum_le_sum (s:=B) (fun x _ => hKR x)
            simpa [Nat.mul_comm] using hh
          have hsumZ : (∑ x ∈ Z, (K x).card) = 0 := by
            apply Finset.sum_eq_zero
            intro x hx
            exact (Finset.mem_filter.mp hx).2
          have hsumL : (∑ x ∈ L, (K x).card) ≤ L.card := by
            have hh := Finset.sum_le_sum (s:=L) hL
            simpa using hh
          omega
  11. $|B| + |Z| + |L| = 2k$.

    Because $B, Z$, and $L$ form a partition of $R$ into disjoint sets, the sum of their sizes equals $|R| = 2k$.

    lines 160–164

    uses Finset.card_union_of_disjoint

        have hcardR : B.card + Z.card + L.card = 2*k := by
          have hh := Finset.card_union_of_disjoint hBL
          have hg := Finset.card_union_of_disjoint hBZ
          rw [hcover,hR] at hh
          omega
  12. $\sum_{u \in U} |N(u) \cap R| \le 2rk + 2r$.

    From $|L| = 2k - |B| - |Z|$, the edge bound becomes $2r|B| + 2k - |B| - |Z| = (2r - 1)|B| - |Z| + 2k$. Since $|B| \le |Z| + 2r$, we have $-|Z| \le 2r - |B|$, so the bound simplifies to $(2r - 2)|B| + 2k + 2r$. Because $r \ge 1$, we have $2r - 2 \ge 0$, and multiplying $|B| \le k$ by $2r - 2$ yields $(2r - 2)|B| \le (2r - 2)k$. Adding $2k + 2r$ gives $(2r - 2)k + 2k + 2r = 2rk + 2r$.

    lines 165–172

    uses Nat.mul_le_mul_left, congrArg, Nat.add_mul

        have hr2 : 2 ≤ 2*r := by omega
        have hrw : 2*r-2+2 = 2*r := by omega
        have hprod := Nat.mul_le_mul_left (2*r-2) hBcard
        have hpB := congrArg (fun n : ℕ => n*B.card) hrw
        have hpK := congrArg (fun n : ℕ => n*k) hrw
        simp only [Nat.add_mul] at hpB hpK
        rw [hsumEq]
        nlinarith
Nat.add_mul
Right distributivity of multiplication over addition: $(n + m) \cdot k = n \cdot k + m \cdot k$.
Nat.mul_le_mul_left
Multiplying both sides of an inequality of natural numbers by a non-negative factor preserves the inequality: if $n \le m$, then $k \cdot n \le k \cdot m$.
Nat.mul_comm
Multiplication of natural numbers is commutative: $n \cdot m = m \cdot n$.
Nat.pos_of_ne_zero
A natural number that is non-zero is strictly positive: $n \ne 0 \implies 0 < n$.
congrArg
Applying a function to equal inputs yields equal outputs: if $a_1 = a_2$, then $f(a_1) = f(a_2)$.
Classical.choose
Given a proof of $\exists x, P(x)$, produces a witness $x$.
Classical.choose_spec
The witness produced by `Classical.choose` satisfies the defining property: $P(\text{choose } h)$.
Subtype.val
Projects an element of a subtype $\{x // P(x)\}$ to the underlying value $x$.
Subtype.ext
Two elements of a subtype are equal if and only if their underlying values are equal.
Fintype.card_le_of_injective
If there is an injective function from a finite type $\alpha$ to a finite type $\beta$, then $|\alpha| \le |\beta|$.
Finset.card_filter_le
The size of a set filtered by a predicate is at most the size of the original set: $|\{x \in s \mid P(x)\}| \le |s|$.
Finset.filter_subset
Filtering a set produces a subset: $\{x \in s \mid P(x)\} \subseteq s$.
Finset.disjoint_left.mpr
Two finite sets $s$ and $t$ are disjoint if every element of $s$ does not belong to $t$.
Finset.disjoint_left.mp
If two finite sets $s$ and $t$ are disjoint, no element of $s$ belongs to $t$.
Finset.disjoint_union_left.mpr
If two sets are each disjoint from a third set, their union is also disjoint from that third set.
Finset.mem_filter.mp
An element belongs to a filtered set $\{x \in s \mid P(x)\}$ if and only if it belongs to $s$ and satisfies $P$. This direction extracts the membership in $s$ and property $P$.
Finset.mem_filter.mpr
An element belongs to a filtered set $\{x \in s \mid P(x)\}$ if it belongs to $s$ and satisfies $P$.
Finset.card_pos.mp
A finite set with strictly positive cardinality is nonempty.
Finset.card_le_card
If $s \subseteq t$, then $|s| \le |t|$.
Finset.not_subset.mp
If $s \not\subseteq t$, then there exists an element $x \in s$ such that $x \notin t$.
Finset.mem_inter.mp
An element of an intersection $s \cap t$ belongs to both $s$ and $t$.
Finset.mem_sdiff.mp
An element belongs to $s \setminus t$ if and only if it belongs to $s$ and not to $t$. This direction extracts the two components.
Finset.mem_sdiff.mpr
An element belongs to $s \setminus t$ if it belongs to $s$ and does not belong to $t$.
Finset.card_sdiff_add_card_eq_card
If $s \subseteq t$, then $|t \setminus s| + |s| = |t|$.
Finset.card_sdiff_add_card_inter
For any sets $s$ and $t$, $|s \setminus t| + |s \cap t| = |s|$.
Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow
Double counting formula for bipartite graphs: the sum over $s$ of degrees into $t$ equals the sum over $t$ of degrees into $s$.
Finset.bipartiteAbove
The sub-finset of elements in $t$ related to $a$ under a binary relation.
Finset.bipartiteBelow
The sub-finset of elements in $s$ related to $b$ under a binary relation.
Finset.mem_union_left
If $a \in s$, then $a \in s \cup t$.
Finset.mem_union_right
If $a \in t$, then $a \in s \cup t$.
Finset.mem_union.mp
An element in $s \cup t$ belongs to $s$ or to $t$.
Finset.sum_union
The sum of a function over the disjoint union of two sets is the sum of the sums over each set.
Finset.sum_le_sum
If $f(x) \le g(x)$ for all $x \in s$, then $\sum_{x \in s} f(x) \le \sum_{x \in s} g(x)$.
Finset.sum_eq_zero
A sum over a finite set is zero if every summand is zero.
Finset.card_union_of_disjoint
If $s$ and $t$ are disjoint, then $|s \cup t| = |s| + |t|$.
Set.ncard_eq_toFinset_card'
For any finite set in a type, its cardinality as a set (`Set.ncard`) equals its cardinality as a finset (`Finset.card`).
in1076_matching_twice_card
In any matching subgraph, the number of vertices is twice the number of edges.

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 no_two_crossing_matching_independence_incidence_bound    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj]    (U R : Finset V) (r k : ℕ) (hr : 1 ≤ r)    (hU : U.card = 2*r) (hR : R.card = 2*k)    (N : G.Subgraph) (hN : N.IsMatching) (hNR : N.verts ⊆ (R : Set V))    (hNcard : N.edgeSet.ncard + r = k)    (hforbid : ∀ u ∈ U, ∀ v ∈ U, u ≠ v → ∀ x ∈ R, ∀ y ∈ R,      G.Adj u x → G.Adj v y → ¬ G.Adj x y)    (hind : ∀ I : Finset V, (∀ x ∈ I, ∀ y ∈ I, x ≠ y → ¬ G.Adj x y) → I.card ≤ k) :    (∑ u ∈ U, ((G.neighborFinset u) ∩ R).card) ≤ 2*r*k + 2*r := by  set_option maxHeartbeats 4000000 in    classical    let K : V → Finset V := fun x => U.filter (fun u => G.Adj u x)    let B : Finset V := R.filter (fun x => 2 ≤ (K x).card)    let Z : Finset V := R.filter (fun x => (K x).card = 0)    have hKR : ∀ x, (K x).card ≤ 2*r := by      intro x      have hh := Finset.card_filter_le U (fun u => G.Adj u x)      simpa [K,hU] using hh    have hBsub : B ⊆ R := Finset.filter_subset _ _    have hZsub : Z ⊆ R := Finset.filter_subset _ _    have hBZ : Disjoint B Z := by      apply Finset.disjoint_left.mpr      intro x hxB hxZ      have hb := (Finset.mem_filter.mp hxB).2      have hz := (Finset.mem_filter.mp hxZ).2      omega    have hno : ∀ x ∈ B, ∀ y ∈ R, G.Adj x y → y ∈ Z := by      intro x hxB y hyR hxy      have hxR := hBsub hxB      have hxcard : 2 ≤ (K x).card := (Finset.mem_filter.mp hxB).2      apply Finset.mem_filter.mpr      refine ⟨hyR,?_⟩      by_contra hn      have hpos : 0 < (K y).card := Nat.pos_of_ne_zero hn      obtain ⟨v,hv⟩ := Finset.card_pos.mp hpos      have hvU : v ∈ U := (Finset.mem_filter.mp hv).1      have hvy : G.Adj v y := (Finset.mem_filter.mp hv).2      have hnsub : ¬ K x ⊆ {v} := by        intro hh        have hc := Finset.card_le_card hh        simp at hc        omega      obtain ⟨u,hu,huv⟩ := Finset.not_subset.mp hnsub      have huU : u ∈ U := (Finset.mem_filter.mp hu).1      have hux : G.Adj u x := (Finset.mem_filter.mp hu).2      have huv' : u ≠ v := by simpa using huv      exact hforbid u huU v hvU huv' x hxR y hyR hux hvy hxy    have hBind : ∀ x ∈ B, ∀ y ∈ B, x ≠ y → ¬ G.Adj x y := by      intro x hx y hy hne hxy      have hyZ := hno x hx y (hBsub hy) hxy      exact Finset.disjoint_left.mp hBZ hy hyZ    have hBcard : B.card ≤ k := hind B hBind    let D : Finset V := N.verts.toFinset    have hDcard : D.card = 2*N.edgeSet.ncard := by      dsimp [D]      rw [← Set.ncard_eq_toFinset_card']      exact (in1076_matching_twice_card hN).symm    have hDR : D ⊆ R := by      intro x hx      exact hNR (by simpa [D] using hx)    let Q : Finset V := B ∩ D    have hQZ : Q.card ≤ Z.card := by      let f : {x // x ∈ Q} → {y // y ∈ Z} := fun x =>        let hxD : x.val ∈ N.verts := by          have hx := (Finset.mem_inter.mp x.property).2          simpa [D] using hx        let y := Classical.choose (hN hxD)        ⟨y, hno x.val (Finset.mem_inter.mp x.property).1 y          (hNR (N.edge_vert (Classical.choose_spec (hN hxD)).1.symm))          (N.adj_sub (Classical.choose_spec (hN hxD)).1)⟩      have hinj : Function.Injective f := by        intro a b hab        let haD : a.val ∈ N.verts := by          have ha := (Finset.mem_inter.mp a.property).2          simpa [D] using ha        let hbD : b.val ∈ N.verts := by          have hb := (Finset.mem_inter.mp b.property).2          simpa [D] using hb        let ya := Classical.choose (hN haD)        let yb := Classical.choose (hN hbD)        have he : ya=yb := by          have hh := congrArg Subtype.val hab          change ya = yb at hh          exact hh        have hay : N.Adj ya a.val := (Classical.choose_spec (hN haD)).1.symm        have hby : N.Adj ya b.val := by          rw [he]          exact (Classical.choose_spec (hN hbD)).1.symm        have hya : ya ∈ N.verts := N.edge_vert hay        apply Subtype.ext        exact (hN hya).unique hay hby      have hh := Fintype.card_le_of_injective f hinj      simpa using hh    have hBbound : B.card ≤ Z.card+2*r := by      have hbd : (B \ D) ⊆ R \ D := by        intro x hx        exact Finset.mem_sdiff.mpr ⟨hBsub (Finset.mem_sdiff.mp hx).1,(Finset.mem_sdiff.mp hx).2⟩      have hb := Finset.card_le_card hbd      have hRD := Finset.card_sdiff_add_card_eq_card hDR      have hBD := Finset.card_sdiff_add_card_inter B D      dsimp [Q] at hQZ      omega    have hsumEq : (∑ u ∈ U, ((G.neighborFinset u) ∩ R).card) = ∑ x ∈ R, (K x).card := by      have hAbove : ∀ u, R.filter (fun x => G.Adj u x) = (G.neighborFinset u) ∩ R := by        intro u        ext x        simp [and_comm]      have hh := Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow (s:=U) (t:=R) G.Adj      simp only [Finset.bipartiteAbove,Finset.bipartiteBelow,hAbove] at hh      simpa [K] using hh    let L : Finset V := R \ (B ∪ Z)    have hL : ∀ x ∈ L, (K x).card ≤ 1 := by      intro x hx      have hnB : x ∉ B := by        intro h        exact (Finset.mem_sdiff.mp hx).2 (Finset.mem_union_left Z h)      have hxR : x ∈ R := (Finset.mem_sdiff.mp hx).1      by_contra hn      apply hnB      exact Finset.mem_filter.mpr ⟨hxR,by omega⟩    have hcover : B ∪ Z ∪ L = R := by      ext x      constructor      · intro hx        rcases Finset.mem_union.mp hx with hx | hx        · rcases Finset.mem_union.mp hx with hx | hx          · exact hBsub hx          · exact hZsub hx        · exact (Finset.mem_sdiff.mp hx).1      · intro hx        by_cases hb : x ∈ B        · exact Finset.mem_union_left L (Finset.mem_union_left Z hb)        · by_cases hz : x ∈ Z          · exact Finset.mem_union_left L (Finset.mem_union_right B hz)          · apply Finset.mem_union_right            exact Finset.mem_sdiff.mpr ⟨hx,by simp [hb,hz]⟩    have hdisBL : Disjoint B L := by      apply Finset.disjoint_left.mpr      intro x hxB hxL      exact (Finset.mem_sdiff.mp hxL).2 (Finset.mem_union_left Z hxB)    have hdisZL : Disjoint Z L := by      apply Finset.disjoint_left.mpr      intro x hxZ hxL      exact (Finset.mem_sdiff.mp hxL).2 (Finset.mem_union_right B hxZ)    have hBL : Disjoint (B ∪ Z) L := Finset.disjoint_union_left.mpr ⟨hdisBL,hdisZL⟩    have hsumBound : (∑ x ∈ R, (K x).card) ≤ 2*r*B.card+L.card := by      rw [← hcover,Finset.sum_union hBL,Finset.sum_union hBZ]      have hsumB : (∑ x ∈ B, (K x).card) ≤ 2*r*B.card := by        have hh := Finset.sum_le_sum (s:=B) (fun x _ => hKR x)        simpa [Nat.mul_comm] using hh      have hsumZ : (∑ x ∈ Z, (K x).card) = 0 := by        apply Finset.sum_eq_zero        intro x hx        exact (Finset.mem_filter.mp hx).2      have hsumL : (∑ x ∈ L, (K x).card) ≤ L.card := by        have hh := Finset.sum_le_sum (s:=L) hL        simpa using hh      omega    have hcardR : B.card + Z.card + L.card = 2*k := by      have hh := Finset.card_union_of_disjoint hBL      have hg := Finset.card_union_of_disjoint hBZ      rw [hcover,hR] at hh      omega    have hr2 : 2 ≤ 2*r := by omega    have hrw : 2*r-2+2 = 2*r := by omega    have hprod := Nat.mul_le_mul_left (2*r-2) hBcard    have hpB := congrArg (fun n : ℕ => n*B.card) hrw    have hpK := congrArg (fun n : ℕ => n*k) hrw    simp only [Nat.add_mul] at hpB hpK    rw [hsumEq]    nlinarith
See it in the graphDiscuss this resultChallenge it