AFTD Auto-Formalizing Theoretical Domains

perfect_matching_internal_edge_card

theoremverified

For a perfect matching and a specified matching-partner map, twice the number of internal edges is the number of vertices whose partners are internal.

Statement

theorem perfect_matching_internal_edge_card
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)
    (P : G.Subgraph) (hP : P.IsPerfectMatching) (f : V → V)
    (hf : ∀ v, P.Adj v (f v)) (S : Finset V) :
    2*(P.induce (S : Set V)).edgeSet.ncard = (S.filter (fun v => f v ∈ S)).card
Source
Balanced-cut matching symmetry for OP-1957; https://arxiv.org/abs/2611.22690.
Verified
26 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1
Used by 1

The proof, explained

The proof constructs a subgraph Q of G whose vertices are those v ∈ S whose matching partner f(v) also belongs to S, and whose edges are the edges of P with both endpoints in S. It shows that Q is a matching whose edge set is identical to that of the induced subgraph P[S] and whose vertex count is |{v ∈ S | f(v) ∈ S}|. Applying the identity that twice the number of edges of any matching equals its vertex count (in1076_matching_twice_card) to Q immediately gives the result.

  1. The matching partner function f is an involution on V, so f(f(v)) = v for every vertex v.

    For every vertex v, v is matched to f(v) in P by hypothesis, so by symmetry f(v) is adjacent to v. At the same time, f(v) is matched to f(f(v)). Since P is a matching, every vertex has a unique neighbor in P, which implies f(f(v)) = v.

    lines 6–10

      set_option maxHeartbeats 4000000 in
        classical
        have hinv : Function.Involutive f := by
          intro v
          exact ((hP.1 (hP.2 (f v))).unique (hf (f v)) (hf v).symm)
  2. Define a subgraph Q of G with vertices V(Q) = {v ∈ S | f(v) ∈ S} and edges being the edges of P whose endpoints both lie in S.

    We construct Q and verify the subgraph conditions: edges in Q are edges in P and hence in G; if u and v are adjacent in Q, then u, v ∈ S and u is adjacent to v in P, so by uniqueness of the matching partner of u, f(u) = v ∈ S, placing u in V(Q); and adjacency is symmetric.

    lines 11–19

        let Q : G.Subgraph := {
          verts := {v | v ∈ S ∧ f v ∈ S}
          Adj := fun u v => P.Adj u v ∧ u ∈ S ∧ v ∈ S
          adj_sub := by intro u v h; exact P.adj_sub h.1
          edge_vert := by
            intro u v h
            have hfv : f u = v := (hP.1 (hP.2 u)).unique (hf u) h.1
            exact ⟨h.2.1,hfv ▸ h.2.2⟩
          symm := ⟨by intro u v h; exact ⟨h.1.symm,h.2.2,h.2.1⟩⟩ }
  3. The subgraph Q is a matching on its vertex set.

    For every vertex v ∈ V(Q), both v and f(v) belong to S, so f(v) is adjacent to v in Q. Furthermore, if w is any neighbor of v in Q, it is also a neighbor in P, so the uniqueness of the partner of v in P forces w = f(v). Thus each vertex in Q has exactly one neighbor in Q.

    lines 20–24

        have hQ : Q.IsMatching := by
          intro v hv
          refine ⟨f v,⟨hf v,hv.1,hv.2⟩,?_⟩
          intro w hw
          exact (hP.1 (hP.2 v)).unique hw.1 (hf v)
  4. The edge set of Q equals the edge set of the induced subgraph P[S].

    By definition, an edge between u and v belongs to Q if and only if u is adjacent to v in P and both u, v ∈ S, which is identical to the definition of the induced subgraph P[S]. We verify equality of the edge sets by inducting on an unordered pair and rearranging conjunctions.

    lines 25–30

    uses Sym2.inductionOn, SimpleGraph.Subgraph.mem_edgeSet, SimpleGraph.Subgraph.induce_adj, and_comm, and_left_comm, and_assoc

        have hedge : Q.edgeSet = (P.induce (S : Set V)).edgeSet := by
          ext e
          induction e using Sym2.inductionOn with
          | _ u v =>
            simp [Q,SimpleGraph.Subgraph.mem_edgeSet,SimpleGraph.Subgraph.induce_adj,
              and_comm,and_left_comm,and_assoc]
  5. The number of vertices in Q equals the cardinality of the filtered finset {v ∈ S | f(v) ∈ S}.

    The vertex set V(Q) is defined as the set of vertices in S whose partner is in S. Rewriting the finset cardinality as the set cardinality of its coercion using Set.ncard_coe_finset, the two underlying sets are extentionally equal.

    lines 31–35

    uses Set.ncard_coe_finset

        have hverts : Q.verts.ncard = (S.filter (fun v => f v ∈ S)).card := by
          rw [← Set.ncard_coe_finset]
          congr 1
          ext v
          simp [Q]
  6. Twice the number of edges in P[S] equals the number of vertices in S whose partner is in S.

    Applying the general lemma in1076_matching_twice_card to the matching Q yields 2 * |E(Q)| = |V(Q)|. Substituting E(Q) = E(P[S]) and |V(Q)| = |{v ∈ S | f(v) ∈ S}| concludes the proof.

    lines 36–38

    uses in1076_matching_twice_card

        have hh := in1076_matching_twice_card hQ
        rw [hedge,hverts] at hh
        exact hh
Sym2.inductionOn
A property holds for all unordered pairs if it holds for every pair of the form s(x, y).
SimpleGraph.Subgraph.mem_edgeSet
An unordered pair s(v, w) belongs to the edge set of a subgraph if and only if v and w are adjacent in that subgraph.
SimpleGraph.Subgraph.induce_adj
Two vertices u and v are adjacent in the induced subgraph G'[s] if and only if u ∈ s, v ∈ s, and u and v are adjacent in G'.
and_comm
Conjunction is commutative: a ∧ b ↔ b ∧ a.
and_left_comm
Conjunction satisfies left-commutativity: a ∧ b ∧ c ↔ b ∧ a ∧ c.
and_assoc
Conjunction is associative: (a ∧ b) ∧ c ↔ a ∧ b ∧ c.
Set.ncard_coe_finset
The set cardinality (ncard) of a coerced finite set equals its finset cardinality (card).
in1076_matching_twice_card
For any matching subgraph M, twice the number of edges equals the number of vertices: 2 * |E(M)| = |V(M)|.

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 perfect_matching_internal_edge_card    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)    (P : G.Subgraph) (hP : P.IsPerfectMatching) (f : V → V)    (hf : ∀ v, P.Adj v (f v)) (S : Finset V) :    2*(P.induce (S : Set V)).edgeSet.ncard = (S.filter (fun v => f v ∈ S)).card := by  set_option maxHeartbeats 4000000 in    classical    have hinv : Function.Involutive f := by      intro v      exact ((hP.1 (hP.2 (f v))).unique (hf (f v)) (hf v).symm)    let Q : G.Subgraph := {      verts := {v | v ∈ S ∧ f v ∈ S}      Adj := fun u v => P.Adj u v ∧ u ∈ S ∧ v ∈ S      adj_sub := by intro u v h; exact P.adj_sub h.1      edge_vert := by        intro u v h        have hfv : f u = v := (hP.1 (hP.2 u)).unique (hf u) h.1        exact ⟨h.2.1,hfv ▸ h.2.2⟩      symm := ⟨by intro u v h; exact ⟨h.1.symm,h.2.2,h.2.1⟩⟩ }    have hQ : Q.IsMatching := by      intro v hv      refine ⟨f v,⟨hf v,hv.1,hv.2⟩,?_⟩      intro w hw      exact (hP.1 (hP.2 v)).unique hw.1 (hf v)    have hedge : Q.edgeSet = (P.induce (S : Set V)).edgeSet := by      ext e      induction e using Sym2.inductionOn with      | _ u v =>        simp [Q,SimpleGraph.Subgraph.mem_edgeSet,SimpleGraph.Subgraph.induce_adj,          and_comm,and_left_comm,and_assoc]    have hverts : Q.verts.ncard = (S.filter (fun v => f v ∈ S)).card := by      rw [← Set.ncard_coe_finset]      congr 1      ext v      simp [Q]    have hh := in1076_matching_twice_card hQ    rw [hedge,hverts] at hh    exact hh
See it in the graphDiscuss this resultChallenge it