AFTD Auto-Formalizing Theoretical Domains

op874_partial_bits_extend_to_rooted

theoremverified

A partial bit assignment with the desired rooted mixed and double-cross properties extends to the whole strongly connected directed graph.

Statement

theorem op874_partial_bits_extend_to_rooted {X : Type*} [Fintype X] [DecidableEq X]
    (p q : Equiv.Perm X)
    (hstrong : ∀ u v, ∃ w : List Bool, w.foldl (fun x bit => if bit then p x else q x) u = v)
    (r x : X) (S : Finset X) (b0 : X → Bool)
    (hr : r ∈ S) (hx : x ∈ S) (hp : p x ∈ S) (hq : q x ∈ S)
    (hpartial : ∀ y ∈ S, y ≠ r → (p y ∈ S ∧ b0 y ≠ b0 (p y)) ∨ (q y ∈ S ∧ b0 y ≠ b0 (q y)))
    (hpx : b0 x ≠ b0 (p x)) (hqx : b0 x ≠ b0 (q x)) :
    ∃ b : X → Bool, (∀ y, y ≠ r → b y ≠ b (p y) ∨ b y ≠ b (q y)) ∧
      b x ≠ b (p x) ∧ b x ≠ b (q x)
Source
Extend a partial rooted double-cross bit assignment along directed paths.
Verified
22 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1
  • op874_extend_bits_along_pathsIf every vertex can reach a prescribed finite set, any Boolean assignment on that set extends so that every outside vertex has an outgoing…

The proof, explained

We define a directed graph on X whose edges correspond to transitions under the permutations p and q. Using strong connectivity, every vertex can reach the root r in S, which allows us to invoke op874_extend_bits_along_paths to extend the partial bit assignment b₀ to the entire set X while ensuring that every vertex outside S has an outgoing edge where the bit flips. The rooted mixed condition and double-cross condition at x then follow from the partial hypotheses on S and the guaranteed outgoing flipping edges outside S.

  1. Sequences of steps along the permutations p and q define valid paths in the transition relation R.

    We define the directed relation R(u, v) by p(u) = v ∨ q(u) = v. By induction on the list of bits w, we show that the fold applying p or q reaches a vertex in the reflexive-transitive closure R*. The empty list is reflexive (Relation.ReflTransGen.refl). For a non-empty list, List.foldl_cons simplifies the fold to take an initial step; case analysis on the boolean bit confirms that this step satisfies R, and Relation.ReflTransGen.head prepends it to the path provided by the induction hypothesis.

    lines 10–17

    uses Relation.ReflTransGen.refl, List.foldl_cons, Relation.ReflTransGen.head

      let R : X → X → Prop := fun u v => p u = v ∨ q u = v
      have walk (u : X) (w : List Bool) : Relation.ReflTransGen R u (w.foldl (fun x bit => if bit then p x else q x) u) := by
        induction w generalizing u with
        | nil => exact Relation.ReflTransGen.refl
        | cons bit w ih =>
          simp only [List.foldl_cons]
          apply Relation.ReflTransGen.head _ (ih _)
          cases bit <;> simp [R]
  2. Every vertex u can reach a vertex in S via paths in the relation R.

    By strong connectivity (hstrong), there is a word w moving u to the root r. Since r belongs to S (hr) and following w yields a path in R* by the previous step, r is the desired target in S reachable from u.

    lines 18–20

      have hreach (u : X) : ∃ v ∈ S, Relation.ReflTransGen R u v := by
        obtain ⟨w, hw⟩ := hstrong u r
        exact ⟨r, hr, hw ▸ walk u w⟩
  3. The partial bit assignment b₀ on S extends to a function b on X such that every vertex outside S has an outgoing edge across which the bit flips.

    Applying the lemma op874_extend_bits_along_paths with the reachability hypothesis produces a function b : X → Bool that agrees with b₀ on S and guarantees that every y ∉ S has an R-successor with a differing bit value.

    line 21

    uses op874_extend_bits_along_paths

      obtain ⟨b, hb, hout⟩ := op874_extend_bits_along_paths R S b0 hreach
  4. The extended assignment b satisfies the rooted condition: every vertex y ≠ r has an outgoing edge under p or q with an opposite bit value.

    We take b as the witness. For any y ≠ r, we split into two cases: if y ∈ S, the partial assignment hypothesis hpartial provides an edge to an element in S where b₀ flips, which carries over to b since b agrees with b₀ on S; if y ∉ S, the extension property guarantees an R-successor z with b(y) ≠ b(z), and since z is either p(y) or q(y), one of the two edges flips b.

    lines 22–31

      refine ⟨b, ?_, ?_, ?_⟩
      · intro y hyr
        by_cases hy : y ∈ S
        · rcases hpartial y hy hyr with ⟨hyp, hne⟩ | ⟨hyq, hne⟩
          · left; rw [hb y hy, hb (p y) hyp]; exact hne
          · right; rw [hb y hy, hb (q y) hyq]; exact hne
        · obtain ⟨z, hyz, hn⟩ := hout y hy
          rcases hyz with hpz | hqz
          · left; exact hpz ▸ hn
          · right; exact hqz ▸ hn
  5. The extended assignment b satisfies the double-cross condition at x: b(x) ≠ b(p(x)) and b(x) ≠ b(q(x)).

    Since x, p(x), and q(x) all lie in S, the values of b at these points match those of b₀. Rewriting with this agreement reduces the claims to the given hypotheses hpx and hqx.

    lines 32–33

      · rw [hb x hx, hb (p x) hp]; exact hpx
      · rw [hb x hx, hb (q x) hq]; exact hqx
Relation.ReflTransGen.refl
Every element is related to itself in the reflexive-transitive closure of any binary relation.
List.foldl_cons
Folding a function over a non-empty list starting from an accumulator equals folding over the tail starting from the updated accumulator.
Relation.ReflTransGen.head
In a reflexive-transitive closure, if a relates to b in one step and b reaches c, then a reaches c.
op874_extend_bits_along_paths
Given a binary relation R on a finite type and a subset S such that every vertex can reach S along R-paths, any boolean function on S extends to the entire type such that every vertex outside S has an outgoing R-neighbor with an opposite boolean value.

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 op874_partial_bits_extend_to_rooted {X : Type*} [Fintype X] [DecidableEq X]    (p q : Equiv.Perm X)    (hstrong : ∀ u v, ∃ w : List Bool, w.foldl (fun x bit => if bit then p x else q x) u = v)    (r x : X) (S : Finset X) (b0 : X → Bool)    (hr : r ∈ S) (hx : x ∈ S) (hp : p x ∈ S) (hq : q x ∈ S)    (hpartial : ∀ y ∈ S, y ≠ r → (p y ∈ S ∧ b0 y ≠ b0 (p y)) ∨ (q y ∈ S ∧ b0 y ≠ b0 (q y)))    (hpx : b0 x ≠ b0 (p x)) (hqx : b0 x ≠ b0 (q x)) :    ∃ b : X → Bool, (∀ y, y ≠ r → b y ≠ b (p y) ∨ b y ≠ b (q y)) ∧      b x ≠ b (p x) ∧ b x ≠ b (q x) := by  let R : X → X → Prop := fun u v => p u = v ∨ q u = v  have walk (u : X) (w : List Bool) : Relation.ReflTransGen R u (w.foldl (fun x bit => if bit then p x else q x) u) := by    induction w generalizing u with    | nil => exact Relation.ReflTransGen.refl    | cons bit w ih =>      simp only [List.foldl_cons]      apply Relation.ReflTransGen.head _ (ih _)      cases bit <;> simp [R]  have hreach (u : X) : ∃ v ∈ S, Relation.ReflTransGen R u v := by    obtain ⟨w, hw⟩ := hstrong u r    exact ⟨r, hr, hw ▸ walk u w⟩  obtain ⟨b, hb, hout⟩ := op874_extend_bits_along_paths R S b0 hreach  refine ⟨b, ?_, ?_, ?_⟩  · intro y hyr    by_cases hy : y ∈ S    · rcases hpartial y hy hyr with ⟨hyp, hne⟩ | ⟨hyq, hne⟩      · left; rw [hb y hy, hb (p y) hyp]; exact hne      · right; rw [hb y hy, hb (q y) hyq]; exact hne    · obtain ⟨z, hyz, hn⟩ := hout y hy      rcases hyz with hpz | hqz      · left; exact hpz ▸ hn      · right; exact hqz ▸ hn  · rw [hb x hx, hb (p x) hp]; exact hpx  · rw [hb x hx, hb (q x) hq]; exact hqx
See it in the graphDiscuss this resultChallenge it