op874_disjoint_two_edge_families_hit_by_pair_swaps
If the edges are partitioned into paired assignments f and g, g avoids required edges, and disjoint edge families each contain at least two nonrequired edges, then independently swapping some pairs preserves all required edges on the f side and makes the g side meet every family.
Statement
theorem op874_disjoint_two_edge_families_hit_by_pair_swaps {L E I : Type*} [Fintype L] [Fintype E] [Fintype I] [DecidableEq L] [DecidableEq E] [DecidableEq I] (f g : L → E) (S : Finset E) (C : I → Finset E) (hf : Function.Injective f) (hg : Function.Injective g) (hdisjoint : ∀ x y, f x ≠ g y) (hcover : ∀ e, ∃ l, f l = e ∨ g l = e) (hgS : ∀ l, g l ∉ S) (hCdisjoint : ∀ i j, i ≠ j → Disjoint (C i) (C j)) (hCtwo : ∀ i, 2 ≤ ((C i).filter fun e => e ∉ S).card) : ∃ swap : L → Bool, (∀ l, f l ∈ S → swap l = false) ∧ ∀ i, ∃ l, (if swap l then f l else g l) ∈ C i
- Source
- Ownership reduction for OP-874, motivated by https://arxiv.org/abs/2610.41950 and experiment 41563.
- Verified
- 27 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 2
- op874_four_two_incidence_two_pseudoforest_coverIn a finite four-by-two incidence system, if every left vertex meets at most two required edges, the edges split into two injective…
- finite_two_appearances_system_of_distinct_representativesFor a finite indexed family of finite sets, if every set has at least two elements and every element occurs in at most two sets, then the…
The proof, explained
The proof formulates the selection of a pair for each family C(i) as a bipartite matching problem via Hall's Marriage Theorem. For each family C(i), let U(i) = C(i) \\ S be its nonrequired edges (at least two per family), and let A(i) be the set of pair indices meeting U(i). Because the families C(i) are pairwise disjoint, any subfamily J ⊆ I contains at least 2|J| nonrequired edges, while the corresponding pairs provide at most 2|⋃_{i ∈ J} A(i)| edges, establishing Hall's condition |J| ≤ |⋃_{i ∈ J} A(i)|. Hall's Marriage Theorem then yields an injection r : I → L selecting a distinct pair r(i) for each family i. Finally, swapping pair r(i) if and only if its f-side edge meets U(i) guarantees that all required edges remain on the f side while the g side meets every family C(i).
Define the set U(i) of nonrequired edges in each family and the set A(i) of pair indices meeting U(i)
For each family index i ∈ I, let U(i) = C(i) \\ S be the set of edges in C(i) outside the required set S. Define A(i) ⊆ L to be the set of pair indices l such that at least one of f(l) or g(l) belongs to U(i).
classical let U : I → Finset E := fun i => (C i).filter fun e => e ∉ S let A : I → Finset L := fun i => Finset.univ.filter fun l => f l ∈ U i ∨ g l ∈ U i
For any subfamily J ⊆ I, the total number of nonrequired edges T = ⋃_{i ∈ J} U(i) is at least 2|J|
Fix a subset J ⊆ I and let T = ⋃_{i ∈ J} U(i). Because the families C(i) are pairwise disjoint (hCdisjoint), their subsets U(i) are pairwise disjoint (Finset.disjoint_of_subset_left, Finset.filter_subset, Finset.disjoint_of_subset_right). Thus |T| = ∑_{i ∈ J} |U(i)| by Finset.card_biUnion. Since each family contains at least two nonrequired edges (hCtwo), this sum is at least ∑_{i ∈ J} 2 = 2|J| (Finset.sum_le_sum, mul_comm).
uses
Finset.disjoint_of_subset_left,Finset.filter_subset,Finset.disjoint_of_subset_right,mul_comm,Finset.sum_le_sum,Finset.card_biUnionhave hall : ∀ J : Finset I, J.card ≤ (J.biUnion A).card := by intro J let N := J.biUnion A let T := J.biUnion U have hdis : (↑J : Set I).PairwiseDisjoint U := by intro i hi j hj hij exact Finset.disjoint_of_subset_left (Finset.filter_subset _ _) (Finset.disjoint_of_subset_right (Finset.filter_subset _ _) (hCdisjoint i j hij)) have hsum : 2 * J.card ≤ ∑ i ∈ J, (U i).card := by calc _ = ∑ _i ∈ J, 2 := by simp [mul_comm] _ ≤ _ := Finset.sum_le_sum (by intro i hi; exact hCtwo i) have hTcard : T.card = ∑ i ∈ J, (U i).card := Finset.card_biUnion hdis
The nonrequired edges T are contained in the pair images f(N) ∪ g(N), where N = ⋃_{i ∈ J} A(i)
Let e ∈ T. By definition of the union (Finset.mem_biUnion.mp), e ∈ U(i) for some i ∈ J. Because the paired assignments cover all edges (hcover), e = f(l) or e = g(l) for some l ∈ L. In either case, l satisfies the membership condition of A(i), so l ∈ N (Finset.mem_biUnion.mpr). Consequently, e lies in f(N) or g(N) (Finset.mem_union_left, Finset.mem_union_right, Finset.mem_image.mpr), establishing T ⊆ f(N) ∪ g(N).
uses
Finset.mem_biUnion.mp,Finset.mem_union_left,Finset.mem_image.mpr,Finset.mem_biUnion.mpr,Finset.mem_union_righthave hsub : T ⊆ N.image f ∪ N.image g := by intro e he obtain ⟨i,hi,hei⟩ := Finset.mem_biUnion.mp he obtain ⟨l,hl | hl⟩ := hcover e · apply Finset.mem_union_left apply Finset.mem_image.mpr refine ⟨l,?_,hl⟩ apply Finset.mem_biUnion.mpr exact ⟨i,hi,by simp [A,hl,hei]⟩ · apply Finset.mem_union_right apply Finset.mem_image.mpr refine ⟨l,?_,hl⟩ apply Finset.mem_biUnion.mpr exact ⟨i,hi,by simp [A,hl,hei]⟩
Hall's marriage condition holds: |J| ≤ |⋃_{i ∈ J} A(i)| for all J ⊆ I
From T ⊆ f(N) ∪ g(N), the cardinality of T is at most |f(N) ∪ g(N)| ≤ |f(N)| + |g(N)| ≤ 2|N| (Finset.card_le_card, Finset.card_union_le, Finset.card_image_le, Nat.add_le_add). Combining this upper bound |T| ≤ 2|N| with the lower bound 2|J| ≤ |T| implies 2|J| ≤ 2|N|, hence |J| ≤ |N| by linear integer arithmetic (omega).
uses
Finset.card_le_card,Finset.card_union_le,Nat.add_le_add,Finset.card_image_lehave hupper : T.card ≤ 2*N.card := by calc _ ≤ (N.image f ∪ N.image g).card := Finset.card_le_card hsub _ ≤ (N.image f).card + (N.image g).card := Finset.card_union_le _ _ _ ≤ N.card + N.card := Nat.add_le_add Finset.card_image_le Finset.card_image_le _ = 2*N.card := by omega change J.card ≤ N.card omega
Apply Hall's Marriage Theorem to obtain an injective selector r : I → L, define the swap function, and reduce to verifying the two properties
Hall's Marriage Theorem (Finset.all_card_le_biUnion_card_iff_existsInjective') produces an injective function r : I → L such that r(i) ∈ A(i) for every i ∈ I. Define the function swap : L → Bool to be true at l precisely when l = r(i) for some i with f(l) ∈ U(i). Providing this swap function reduces the goal to checking that required edges are not swapped and that every family is met on the g side.
uses
Finset.all_card_le_biUnion_card_iff_existsInjective'obtain ⟨r,hrinj,hrmem⟩ := (Finset.all_card_le_biUnion_card_iff_existsInjective' A).mp hall let swap : L → Bool := fun l => decide (∃ i : I, r i = l ∧ f l ∈ U i) refine ⟨swap,?_,?_⟩
Swapping preserves all required edges: if f(l) ∈ S, then swap(l) = false
Assume f(l) ∈ S. If there were an i such that r(i) = l and f(l) ∈ U(i), then f(l) would belong to C(i) \\ S (Finset.mem_filter.mp), contradicting f(l) ∈ S. Thus no such i exists, so swap(l) evaluates to false by definition.
uses
Finset.mem_filter.mp· intro l hl have hn : ¬ ∃ i : I, r i = l ∧ f l ∈ U i := by rintro ⟨i,hi,hui⟩ exact (Finset.mem_filter.mp hui).2 hl simp [swap,hn]
The swapped configuration hits every family C(i) on the g side
For any i ∈ I, consider the selected pair index l = r(i). Since r(i) ∈ A(i), either f(r(i)) ∈ U(i) or g(r(i)) ∈ U(i). If f(r(i)) ∈ U(i), then i witnesses the existential condition defining swap, so swap(r(i)) = true, and the resulting element is f(r(i)) ∈ U(i) ⊆ C(i) (Finset.mem_filter.mp). If f(r(i)) ∉ U(i), then g(r(i)) ∈ U(i), and injectivity of r ensures no other index j satisfies r(j) = r(i), so swap(r(i)) = false; the resulting element is g(r(i)) ∈ U(i) ⊆ C(i) (Finset.mem_filter.mp). Either way, family C(i) contains the chosen edge.
uses
Finset.mem_filter.mp· intro i refine ⟨r i,?_⟩ have hi : f (r i) ∈ U i ∨ g (r i) ∈ U i := by simpa [A] using hrmem i by_cases hfi : f (r i) ∈ U i · have hex : ∃ j : I, r j = r i ∧ f (r i) ∈ U j := ⟨i,rfl,hfi⟩ have hsw : swap (r i) = true := by simp [swap,hex] simpa [hsw] using (Finset.mem_filter.mp hfi).1 · have hgi : g (r i) ∈ U i := hi.resolve_left hfi have hn : ¬ ∃ j : I, r j = r i ∧ f (r i) ∈ U j := by rintro ⟨j,hj,hf⟩ have hji : j=i := hrinj hj subst j exact hfi hf have hsw : swap (r i) = false := by simp [swap,hn] simpa [hsw] using (Finset.mem_filter.mp hgi).1
Finset.disjoint_of_subset_left- If s ⊆ u and u is disjoint from t, then s is disjoint from t
Finset.filter_subset- Filtering a finite set by a predicate produces a subset of the original set
Finset.disjoint_of_subset_right- If t ⊆ u and s is disjoint from u, then s is disjoint from t
mul_comm- Multiplication in a commutative magma is commutative: a * b = b * a
Finset.sum_le_sum- If f(i) ≤ g(i) for all i in a finite set s, then ∑_{i ∈ s} f(i) ≤ ∑_{i ∈ s} g(i)
Finset.card_biUnion- The cardinality of a union of pairwise disjoint finite sets is the sum of their cardinalities
Finset.mem_biUnion.mp- An element belongs to an indexed union ⋃_{i ∈ s} t(i) only if it belongs to t(i) for some i ∈ s
Finset.mem_union_left- An element belonging to s also belongs to the union s ∪ t
Finset.mem_image.mpr- If a ∈ s and f(a) = b, then b ∈ f(s)
Finset.mem_biUnion.mpr- If i ∈ s and x ∈ t(i), then x belongs to the indexed union ⋃_{j ∈ s} t(j)
Finset.mem_union_right- An element belonging to t also belongs to the union s ∪ t
Finset.card_le_card- If s ⊆ t, then |s| ≤ |t|
Finset.card_union_le- The cardinality of a union satisfies |s ∪ t| ≤ |s| + |t|
Nat.add_le_add- If a ≤ b and c ≤ d, then a + c ≤ b + d
Finset.card_image_le- The cardinality of the image f(s) is at most the cardinality of s
Finset.all_card_le_biUnion_card_iff_existsInjective'- Hall's Marriage Theorem for indexed finite sets: an injective system of distinct representatives exists if and only if every finite index subset J satisfies |J| ≤ |⋃_{i ∈ J} t(i)|
Finset.mem_filter.mp- An element belongs to a filtered set {x ∈ s | p(x)} only if it belongs to s and satisfies p
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.
theorem op874_disjoint_two_edge_families_hit_by_pair_swaps {L E I : Type*} [Fintype L] [Fintype E] [Fintype I] [DecidableEq L] [DecidableEq E] [DecidableEq I] (f g : L → E) (S : Finset E) (C : I → Finset E) (hf : Function.Injective f) (hg : Function.Injective g) (hdisjoint : ∀ x y, f x ≠ g y) (hcover : ∀ e, ∃ l, f l = e ∨ g l = e) (hgS : ∀ l, g l ∉ S) (hCdisjoint : ∀ i j, i ≠ j → Disjoint (C i) (C j)) (hCtwo : ∀ i, 2 ≤ ((C i).filter fun e => e ∉ S).card) : ∃ swap : L → Bool, (∀ l, f l ∈ S → swap l = false) ∧ ∀ i, ∃ l, (if swap l then f l else g l) ∈ C i := by classical let U : I → Finset E := fun i => (C i).filter fun e => e ∉ S let A : I → Finset L := fun i => Finset.univ.filter fun l => f l ∈ U i ∨ g l ∈ U i have hall : ∀ J : Finset I, J.card ≤ (J.biUnion A).card := by intro J let N := J.biUnion A let T := J.biUnion U have hdis : (↑J : Set I).PairwiseDisjoint U := by intro i hi j hj hij exact Finset.disjoint_of_subset_left (Finset.filter_subset _ _) (Finset.disjoint_of_subset_right (Finset.filter_subset _ _) (hCdisjoint i j hij)) have hsum : 2 * J.card ≤ ∑ i ∈ J, (U i).card := by calc _ = ∑ _i ∈ J, 2 := by simp [mul_comm] _ ≤ _ := Finset.sum_le_sum (by intro i hi; exact hCtwo i) have hTcard : T.card = ∑ i ∈ J, (U i).card := Finset.card_biUnion hdis have hsub : T ⊆ N.image f ∪ N.image g := by intro e he obtain ⟨i,hi,hei⟩ := Finset.mem_biUnion.mp he obtain ⟨l,hl | hl⟩ := hcover e · apply Finset.mem_union_left apply Finset.mem_image.mpr refine ⟨l,?_,hl⟩ apply Finset.mem_biUnion.mpr exact ⟨i,hi,by simp [A,hl,hei]⟩ · apply Finset.mem_union_right apply Finset.mem_image.mpr refine ⟨l,?_,hl⟩ apply Finset.mem_biUnion.mpr exact ⟨i,hi,by simp [A,hl,hei]⟩ have hupper : T.card ≤ 2*N.card := by calc _ ≤ (N.image f ∪ N.image g).card := Finset.card_le_card hsub _ ≤ (N.image f).card + (N.image g).card := Finset.card_union_le _ _ _ ≤ N.card + N.card := Nat.add_le_add Finset.card_image_le Finset.card_image_le _ = 2*N.card := by omega change J.card ≤ N.card omega obtain ⟨r,hrinj,hrmem⟩ := (Finset.all_card_le_biUnion_card_iff_existsInjective' A).mp hall let swap : L → Bool := fun l => decide (∃ i : I, r i = l ∧ f l ∈ U i) refine ⟨swap,?_,?_⟩ · intro l hl have hn : ¬ ∃ i : I, r i = l ∧ f l ∈ U i := by rintro ⟨i,hi,hui⟩ exact (Finset.mem_filter.mp hui).2 hl simp [swap,hn] · intro i refine ⟨r i,?_⟩ have hi : f (r i) ∈ U i ∨ g (r i) ∈ U i := by simpa [A] using hrmem i by_cases hfi : f (r i) ∈ U i · have hex : ∃ j : I, r j = r i ∧ f (r i) ∈ U j := ⟨i,rfl,hfi⟩ have hsw : swap (r i) = true := by simp [swap,hex] simpa [hsw] using (Finset.mem_filter.mp hfi).1 · have hgi : g (r i) ∈ U i := hi.resolve_left hfi have hn : ¬ ∃ j : I, r j = r i ∧ f (r i) ∈ U j := by rintro ⟨j,hj,hf⟩ have hji : j=i := hrinj hj subst j exact hfi hf have hsw : swap (r i) = false := by simp [swap,hn] simpa [hsw] using (Finset.mem_filter.mp hgi).1