op874_extend_bits_along_paths
If every vertex can reach a prescribed finite set, any Boolean assignment on that set extends so that every outside vertex has an outgoing edge to a vertex of the opposite bit.
Statement
theorem op874_extend_bits_along_paths {X : Type*} [Fintype X] [DecidableEq X] (R : X → X → Prop) (S : Finset X) (b0 : X → Bool) (hreach : ∀ x, ∃ y ∈ S, Relation.ReflTransGen R x y) : ∃ b : X → Bool, (∀ x ∈ S, b x = b0 x) ∧ ∀ x, x ∉ S → ∃ y, R x y ∧ b x ≠ b y
- Source
- Finite partial bit assignment extended by reverse reachability.
- Verified
- 22 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Used by 2
- op874_partial_bits_extend_to_rootedA partial bit assignment with the desired rooted mixed and double-cross properties extends to the whole strongly connected directed graph.
- op874_no_partial_mixed_closed_setIn a strongly connected directed two-out graph with no globally mixed bit assignment, no nonempty finite set can have a bit assignment…
The proof, explained
The proof proceeds by strong induction on the size of the complement X \ S. In the base case where S is the entire vertex set, the initial assignment b0 already works vacuously. When S is a proper subset, reachability guarantees a path from an outside vertex to S, from which a preliminary 'bridge' lemma extracts an edge u → v crossing into S. We enlarge S to T = S ∪ {u} and assign u the opposite bit of b0(v), strictly shrinking the complement while preserving reachability to T. Applying the induction hypothesis to this enlarged set produces the required Boolean extension.
Any directed path starting outside S and ending inside S contains an edge u → v crossing into S (u ∉ S and v ∈ S).
We enable classical reasoning and prove the helper lemma `bridge` by induction on the path `hp` from a to b. The zero-step base case (a = b) is contradictory because a ∉ S and b ∈ S. In the inductive step where the path ends with an edge c → d with d = b ∈ S, we split into cases: if c ∈ S, the induction hypothesis on the subpath from a to c provides a crossing edge; if c ∉ S, the final step c → d is itself the desired edge.
classical have bridge (S : Finset X) (a b : X) (hp : Relation.ReflTransGen R a b) (ha : a ∉ S) (hb : b ∈ S) : ∃ u v, u ∉ S ∧ v ∈ S ∧ R u v := by induction hp with | refl => exact (ha hb).elim | @tail c d hac hcd ih => by_cases hc : c ∈ S · exact ih hc · exact ⟨c, d, hc, hb, hcd⟩
It suffices to prove the auxiliary statement `aux n` by strong induction on n = |X \ S|.
We formulate the auxiliary statement `aux n` asserting that any set S whose complement has size n admits a valid extension under the reachability hypothesis. We proceed by strong induction on n using `Nat.strong_induction_on`, assuming the result for all smaller complements, and introduce the set S, the equality |X \ S| = n, the initial assignment b0, and the reachability condition `hreach`.
uses
Nat.strong_induction_onhave aux (n : ℕ) : ∀ S : Finset X, (Finset.univ \ S).card = n → ∀ b0 : X → Bool, (∀ x, ∃ y ∈ S, Relation.ReflTransGen R x y) → ∃ b : X → Bool, (∀ x ∈ S, b x = b0 x) ∧ ∀ x, x ∉ S → ∃ y, R x y ∧ b x ≠ b y := by induction n using Nat.strong_induction_on with | h n ih => intro S hn b0 hreach
If S is the entire universe, the initial assignment b0 already satisfies the theorem.
When S = X, b0 trivially agrees with itself on S, and there are no vertices outside S, so the second condition holds vacuously.
uses
Finset.mem_univby_cases hall : S = Finset.univ · refine ⟨b0, by simp, ?_⟩ intro x hx exact (hx (hall ▸ Finset.mem_univ x)).elim
When S ≠ X, there exists a directed edge u → v with u ∉ S and v ∈ S.
Since S ≠ X, the complement X \ S is nonempty, so we can pick a vertex z ∉ S. By the reachability hypothesis, z can reach some vertex y ∈ S. Applying the helper lemma `bridge` to this path yields a directed edge u → v with u ∉ S and v ∈ S.
uses
Finset.nonempty_iff_ne_empty.mpr,Finset.mem_sdiff.mp,bridge· have hnon : (Finset.univ \ S).Nonempty := by apply Finset.nonempty_iff_ne_empty.mpr intro h apply hall ext z have : z ∉ Finset.univ \ S := by rw [h]; simp simpa using this obtain ⟨z, hz⟩ := hnon have hzs : z ∉ S := (Finset.mem_sdiff.mp hz).2 obtain ⟨y, hy, hp⟩ := hreach z obtain ⟨u, v, hu, hv, huv⟩ := bridge S z y hp hzs hy
Augmenting S to T = S ∪ {u} and defining b1(u) = ¬b0(v) strictly decreases the complement size: |X \ T| < n.
We define T = S ∪ {u} and let b1 agree with b0 except at u, where it is set to the opposite bit of b0(v). Since u ∉ S, the complement X \ T is a strict subset of X \ S, and therefore its cardinality is strictly less than n by `Finset.card_lt_card`.
uses
Finset.card_lt_card,Finset.ssubset_iff_subset_ne.mpr,Finset.mem_sdiff,Finset.mem_univ,true_and,Finset.mem_insert_of_memlet T := insert u S let b1 := Function.update b0 u (!b0 v) have hlt : (Finset.univ \ T).card < n := by rw [← hn] apply Finset.card_lt_card apply Finset.ssubset_iff_subset_ne.mpr constructor · intro w hw simp only [Finset.mem_sdiff, Finset.mem_univ, true_and] at hw ⊢ exact fun hs => hw (Finset.mem_insert_of_mem hs) · intro heq have hu0 : u ∈ Finset.univ \ S := by simp [hu] have hu1 : u ∉ Finset.univ \ T := by simp [T] exact hu1 (heq ▸ hu0)
Every vertex can reach T, so the induction hypothesis yields a valid extension b for T and b1.
Since S ⊆ T, any path reaching S also reaches T, preserving the reachability hypothesis. Because |X \ T| < n, we can apply the induction hypothesis `ih` to T and b1, obtaining a Boolean assignment b that agrees with b1 on T and has outgoing edges to opposite bits for all vertices outside T.
uses
Finset.mem_insert_of_memhave hreachT : ∀ x, ∃ y ∈ T, Relation.ReflTransGen R x y := by intro x obtain ⟨y, hy, hp⟩ := hreach x exact ⟨y, Finset.mem_insert_of_mem hy, hp⟩ obtain ⟨b, hb, hm⟩ := ih _ hlt T rfl b1 hreachT
The function b agrees with the initial coloring b0 on S.
For any w ∈ S, since u ∉ S we have w ≠ u. Because w ∈ S ⊆ T, b(w) = b1(w), which equals b0(w) because b1 only differs from b0 at u.
uses
Finset.mem_insert_of_memrefine ⟨b, ?_, ?_⟩ · intro w hw have hwu : w ≠ u := fun he => hu (he ▸ hw) rw [hb w (Finset.mem_insert_of_mem hw)] simp [b1, hwu]
Every vertex w ∉ S has an outgoing edge to a vertex of opposite bit under b.
We split into cases on whether w = u: - If w = u, the edge u → v connects to v ∈ S ⊆ T with v ≠ u (as u ∉ S and v ∈ S). Then b(u) = b1(u) = ¬b0(v) and b(v) = b1(v) = b0(v), so b(u) ≠ b(v). - If w ≠ u, then w ∉ T = S ∪ {u}. The inductive guarantee for b on T directly provides an outgoing edge from w to a vertex of opposite bit.
uses
Finset.mem_insert_of_mem· intro w hw by_cases hwu : w = u · subst w refine ⟨v, huv, ?_⟩ have hvu : v ≠ u := fun he => hu (he ▸ hv) rw [hb u (by simp [T]), hb v (Finset.mem_insert_of_mem hv)] simp [b1, hvu] · apply hm w simp [T, hw, hwu]
The main theorem follows by applying `aux` to S with n = |X \ S|.
We apply the auxiliary lemma `aux` with n = |X \ S| and the given reachability hypothesis, which immediately establishes the theorem.
uses
auxexact aux _ S rfl b0 hreach
Nat.strong_induction_on- Principle of strong induction on natural numbers: to prove a statement for all n, it suffices to prove it for n assuming it holds for all m < n.
Finset.mem_univ- Every element of a finite type belongs to the universal finset `Finset.univ`.
Finset.nonempty_iff_ne_empty.mpr- A finset is nonempty if and only if it is not equal to the empty set (forward direction).
Finset.mem_sdiff.mp- If an element belongs to the difference s \ t, then it belongs to s and does not belong to t.
bridge- Any directed path starting outside a set S and ending inside S contains a directed edge u → v with u ∉ S and v ∈ S.
Finset.card_lt_card- A strict subset of a finset has strictly smaller cardinality.
Finset.ssubset_iff_subset_ne.mpr- A subset that is not equal to the superset is a strict subset.
Finset.mem_sdiff- An element belongs to s \ t if and only if it belongs to s and not to t.
true_and- The conjunction of True and p simplifies to p.
Finset.mem_insert_of_mem- If an element belongs to a finset s, it belongs to insert a s.
aux- The inductive claim that any subset S with complement size n admits a valid Boolean extension, given the reachability hypothesis.
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_extend_bits_along_paths {X : Type*} [Fintype X] [DecidableEq X] (R : X → X → Prop) (S : Finset X) (b0 : X → Bool) (hreach : ∀ x, ∃ y ∈ S, Relation.ReflTransGen R x y) : ∃ b : X → Bool, (∀ x ∈ S, b x = b0 x) ∧ ∀ x, x ∉ S → ∃ y, R x y ∧ b x ≠ b y := by classical have bridge (S : Finset X) (a b : X) (hp : Relation.ReflTransGen R a b) (ha : a ∉ S) (hb : b ∈ S) : ∃ u v, u ∉ S ∧ v ∈ S ∧ R u v := by induction hp with | refl => exact (ha hb).elim | @tail c d hac hcd ih => by_cases hc : c ∈ S · exact ih hc · exact ⟨c, d, hc, hb, hcd⟩ have aux (n : ℕ) : ∀ S : Finset X, (Finset.univ \ S).card = n → ∀ b0 : X → Bool, (∀ x, ∃ y ∈ S, Relation.ReflTransGen R x y) → ∃ b : X → Bool, (∀ x ∈ S, b x = b0 x) ∧ ∀ x, x ∉ S → ∃ y, R x y ∧ b x ≠ b y := by induction n using Nat.strong_induction_on with | h n ih => intro S hn b0 hreach by_cases hall : S = Finset.univ · refine ⟨b0, by simp, ?_⟩ intro x hx exact (hx (hall ▸ Finset.mem_univ x)).elim · have hnon : (Finset.univ \ S).Nonempty := by apply Finset.nonempty_iff_ne_empty.mpr intro h apply hall ext z have : z ∉ Finset.univ \ S := by rw [h]; simp simpa using this obtain ⟨z, hz⟩ := hnon have hzs : z ∉ S := (Finset.mem_sdiff.mp hz).2 obtain ⟨y, hy, hp⟩ := hreach z obtain ⟨u, v, hu, hv, huv⟩ := bridge S z y hp hzs hy let T := insert u S let b1 := Function.update b0 u (!b0 v) have hlt : (Finset.univ \ T).card < n := by rw [← hn] apply Finset.card_lt_card apply Finset.ssubset_iff_subset_ne.mpr constructor · intro w hw simp only [Finset.mem_sdiff, Finset.mem_univ, true_and] at hw ⊢ exact fun hs => hw (Finset.mem_insert_of_mem hs) · intro heq have hu0 : u ∈ Finset.univ \ S := by simp [hu] have hu1 : u ∉ Finset.univ \ T := by simp [T] exact hu1 (heq ▸ hu0) have hreachT : ∀ x, ∃ y ∈ T, Relation.ReflTransGen R x y := by intro x obtain ⟨y, hy, hp⟩ := hreach x exact ⟨y, Finset.mem_insert_of_mem hy, hp⟩ obtain ⟨b, hb, hm⟩ := ih _ hlt T rfl b1 hreachT refine ⟨b, ?_, ?_⟩ · intro w hw have hwu : w ≠ u := fun he => hu (he ▸ hw) rw [hb w (Finset.mem_insert_of_mem hw)] simp [b1, hwu] · intro w hw by_cases hwu : w = u · subst w refine ⟨v, huv, ?_⟩ have hvu : v ≠ u := fun he => hu (he ▸ hv) rw [hb u (by simp [T]), hb v (Finset.mem_insert_of_mem hv)] simp [b1, hvu] · apply hm w simp [T, hw, hwu] exact aux _ S rfl b0 hreach