AFTD Auto-Formalizing Theoretical Domains

perfect_matching_of_adjacency_involution

theoremverified

A simple graph has a perfect matching if it has an involution that sends every vertex to an adjacent vertex.

Statement

theorem perfect_matching_of_adjacency_involution {V : Type*} (G : SimpleGraph V) (f : V → V)
    (hinv : Function.Involutive f) (hadj : ∀ x, G.Adj x (f x)) :
    ∃ P : G.Subgraph, P.IsPerfectMatching
Source
OP-1957: explicit matching witness.
Verified
22 Nov 2026
Axioms
propext
Used by 11

The proof, explained

The proof constructs an explicit spanning subgraph $P$ of $G$ whose edges connect each vertex $x$ to $f(x)$. Because $f$ is an involution mapping every vertex to an adjacent vertex, this relation is symmetric and forms a valid subgraph of $G$. The subgraph is a perfect matching because each vertex $x$ has exactly one partner in $P$, namely $f(x)$.

  1. A valid subgraph $P$ of $G$ is constructed with all vertices of $V$ and with edges connecting each vertex $x$ to $f(x)$.

    Working under classical logic, we define a subgraph $P$ whose vertex set is the universe of all vertices and whose adjacency relation is $y = f(x)$. We verify the three axioms defining a subgraph: 1. Every edge of $P$ is an edge of $G$, which holds because $G\text{.Adj}(x, f(x))$ is given by `hadj`. 2. Every endpoint of an edge belongs to the vertex set `Set.univ`, which holds by `Set.mem_univ`. 3. The adjacency relation is symmetric: if $y = f(x)$, then $x = f(f(x)) = f(y)$ because $f$ is an involution (`hinv`), so $x = f(y)$.

    lines 4–12

    uses Set.mem_univ

      classical
      let P : G.Subgraph := ⟨Set.univ, fun x y => y = f x,
        by intro x y h; subst y; exact hadj x,
        by intro x y h; exact Set.mem_univ x,
        by
          constructor
          intro x y h
          subst y
          exact (hinv x).symm⟩
  2. To prove that $P$ is a perfect matching, it suffices to show that each vertex has a unique neighbor in $P$.

    We supply $P$ as the witness for the existential quantifier. Rewriting with `SimpleGraph.Subgraph.isPerfectMatching_iff` transforms the goal into showing that for every vertex $v$, there exists a unique vertex $w$ adjacent to $v$ in $P$.

    lines 13–14

    uses SimpleGraph.Subgraph.isPerfectMatching_iff

      refine ⟨P, ?_⟩
      rw [SimpleGraph.Subgraph.isPerfectMatching_iff]
  3. Every vertex has $f(x)$ as its unique neighbor in $P$, completing the proof.

    For any vertex $x$, its unique neighbor in $P$ is $f(x)$: the adjacency condition $f(x) = f(x)$ holds reflexively, and if any vertex $y$ is adjacent to $x$ in $P$, then $y = f(x)$ by definition of $P$'s edges.

    lines 15–16

      intro x
      exact ⟨f x, rfl, fun y h => h⟩
Set.mem_univ
Every element of a type belongs to the universal set `univ` of that type.
SimpleGraph.Subgraph.isPerfectMatching_iff
A subgraph of a simple graph is a perfect matching if and only if every vertex in the graph has exactly one neighbor in the subgraph.

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_of_adjacency_involution {V : Type*} (G : SimpleGraph V) (f : V → V)    (hinv : Function.Involutive f) (hadj : ∀ x, G.Adj x (f x)) :    ∃ P : G.Subgraph, P.IsPerfectMatching := by  classical  let P : G.Subgraph := ⟨Set.univ, fun x y => y = f x,    by intro x y h; subst y; exact hadj x,    by intro x y h; exact Set.mem_univ x,    by      constructor      intro x y h      subst y      exact (hinv x).symm⟩  refine ⟨P, ?_⟩  rw [SimpleGraph.Subgraph.isPerfectMatching_iff]  intro x  exact ⟨f x, rfl, fun y h => h⟩
See it in the graphDiscuss this resultChallenge it