AFTD Auto-Formalizing Theoretical Domains

indexed_disjoint_cross_edges_form_matching

theoremverified

Injectively indexed edges with disjoint endpoint ranges form a matching of the expected size.

Statement

theorem indexed_disjoint_cross_edges_form_matching
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) (r : ℕ)
    (f g : Fin r → V) (hf : Function.Injective f) (hg : Function.Injective g)
    (hdis : ∀ i j, f i ≠ g j) (hadj : ∀ i, G.Adj (f i) (g i)) :
    ∃ N : G.Subgraph, N.IsMatching ∧ N.edgeSet.ncard = r ∧
      N.verts = Set.range f ∪ Set.range g
Source
Indexed matching construction for OP-1957; https://arxiv.org/abs/2611.22690.
Verified
26 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1
Used by 16

The proof, explained

The proof constructs a matching from the r cross edges connecting f(i) and g(i). Because f and g are injective and have disjoint ranges A and B, composing their inverses yields a bijection between A and B connecting adjacent vertices, which gives a matching subgraph N with vertex set A ∪ B. Since |A| = r, |B| = r, and the sets are disjoint, N has 2r vertices, and since any matching satisfies 2|E(N)| = |V(N)|, the matching consists of exactly r edges.

  1. The image sets A = range(f) and B = range(g) are disjoint.

    Any vertex in A has the form f(i) and any vertex in B has the form g(j) for indices i, j ∈ {0, ..., r - 1}. If f(i) = g(j), this contradicts the hypothesis that the images are disjoint, so A and B have no vertices in common.

    lines 7–13

    uses Set.disjoint_left.mpr

      classical
      let A : Set V := Set.range f
      let B : Set V := Set.range g
      have hAB : Disjoint A B := by
        apply Set.disjoint_left.mpr
        rintro x ⟨i,rfl⟩ ⟨j,hj⟩
        exact hdis i j hj.symm
  2. There is a bijection e : A ≃ B pairing each f(i) with g(i).

    Because f and g are injective, they restrict to bijections between {0, ..., r - 1} and their ranges A and B. Composing the inverse of the first bijection with the second yields a bijection e from A to B.

    lines 14–16

    uses Equiv.ofInjective

      let ef : Fin r ≃ A := Equiv.ofInjective f hf
      let eg : Fin r ≃ B := Equiv.ofInjective g hg
      let e : A ≃ B := ef.symm.trans eg
  3. Every vertex v ∈ A is adjacent in G to its partner e(v) ∈ B.

    For any v ∈ A, writing v = f(i) for the unique index i, its image under e is g(i). The hypothesis that f(i) is adjacent to g(i) for every index i directly implies that v and e(v) are adjacent.

    lines 17–23

    uses Equiv.apply_ofInjective_symm

      have he : ∀ v : A, G.Adj v (e v) := by
        intro v
        have hfv : f (ef.symm v) = v.val := Equiv.apply_ofInjective_symm hf v
        have hgv : (e v).val = g (ef.symm v) := by
          rfl
        rw [← hfv,hgv]
        exact hadj (ef.symm v)
  4. There exists a matching subgraph N of G whose vertex set is A ∪ B.

    By applying a general lemma that builds a matching from a bijection between disjoint sets of adjacent vertices, we obtain a subgraph N that is a matching spanning A ∪ B. This provides the desired witness, leaving only its edge count to be verified.

    lines 24–25

    uses SimpleGraph.Subgraph.IsMatching.exists_of_disjoint_sets_of_equiv

      obtain ⟨N,hverts,hN⟩ := SimpleGraph.Subgraph.IsMatching.exists_of_disjoint_sets_of_equiv hAB e he
      refine ⟨N,hN,?_,hverts⟩
  5. The matching N has exactly r edges.

    In any matching, twice the number of edges equals the number of vertices. Since f and g are injective maps from a set of size r, both A and B have cardinality r. Because A and B are disjoint, the vertex set of N has cardinality r + r = 2r. Linear arithmetic then yields that the number of edges in N is r.

    lines 26–30

    uses in1076_matching_twice_card, Set.ncard_range_of_injective, Set.ncard_union_eq

      have hn := in1076_matching_twice_card hN
      have hA : A.ncard = r := by simpa [A] using Set.ncard_range_of_injective hf
      have hB : B.ncard = r := by simpa [B] using Set.ncard_range_of_injective hg
      rw [hverts, Set.ncard_union_eq hAB, hA, hB] at hn
      omega
Set.disjoint_left.mpr
Two sets are disjoint if no element of the first belongs to the second.
Equiv.ofInjective
An injective function induces a bijection between its domain and its range.
Equiv.apply_ofInjective_symm
Applying an injective function to the preimage of an element in its range recovers that element.
SimpleGraph.Subgraph.IsMatching.exists_of_disjoint_sets_of_equiv
Given two disjoint vertex sets and a bijection between them pairing adjacent vertices, there exists a matching subgraph whose vertex set is their union.
in1076_matching_twice_card
In any matching subgraph of a finite graph, twice the number of edges equals the number of vertices.
Set.ncard_range_of_injective
The cardinality of the range of an injective map equals the cardinality of its domain.
Set.ncard_union_eq
The cardinality of the union of two disjoint finite sets is the sum of their cardinalities.

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 indexed_disjoint_cross_edges_form_matching    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) (r : ℕ)    (f g : Fin r → V) (hf : Function.Injective f) (hg : Function.Injective g)    (hdis : ∀ i j, f i ≠ g j) (hadj : ∀ i, G.Adj (f i) (g i)) :    ∃ N : G.Subgraph, N.IsMatching ∧ N.edgeSet.ncard = r ∧      N.verts = Set.range f ∪ Set.range g := by  classical  let A : Set V := Set.range f  let B : Set V := Set.range g  have hAB : Disjoint A B := by    apply Set.disjoint_left.mpr    rintro x ⟨i,rfl⟩ ⟨j,hj⟩    exact hdis i j hj.symm  let ef : Fin r ≃ A := Equiv.ofInjective f hf  let eg : Fin r ≃ B := Equiv.ofInjective g hg  let e : A ≃ B := ef.symm.trans eg  have he : ∀ v : A, G.Adj v (e v) := by    intro v    have hfv : f (ef.symm v) = v.val := Equiv.apply_ofInjective_symm hf v    have hgv : (e v).val = g (ef.symm v) := by      rfl    rw [← hfv,hgv]    exact hadj (ef.symm v)  obtain ⟨N,hverts,hN⟩ := SimpleGraph.Subgraph.IsMatching.exists_of_disjoint_sets_of_equiv hAB e he  refine ⟨N,hN,?_,hverts⟩  have hn := in1076_matching_twice_card hN  have hA : A.ncard = r := by simpa [A] using Set.ncard_range_of_injective hf  have hB : B.ncard = r := by simpa [B] using Set.ncard_range_of_injective hg  rw [hverts, Set.ncard_union_eq hAB, hA, hB] at hn  omega
See it in the graphDiscuss this resultChallenge it