AFTD Auto-Formalizing Theoretical Domains

op874_balanced_trap_enters_only_at_successor

theoremverified

A trap whose only possible exit is x, with an r→x arc and an entry from x, has no other entering arc. Parallel arcs count separately.

Statement

theorem op874_balanced_trap_enters_only_at_successor {X : Type*} [Fintype X] [DecidableEq X] (p q : Equiv.Perm X) (S : Finset X) (r x : X) (hr : r ∉ S) (hx : x ∉ S) (harc : p r = x ∨ q r = x) (hclosed : ∀ u ∈ S, (p u ∈ S ∨ p u = x) ∧ (q u ∈ S ∨ q u = x)) (hentry : ∃ v ∈ S, p x = v ∨ q x = v) : ∀ u, u ∉ S → u ≠ x → p u ∉ S ∧ q u ∉ S
Source
Finite balanced cut lemma for the rooted branch reduction.
Verified
22 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Used by 1

The proof, explained

The proof uses a conservation-of-flux (double-counting) argument on the product graph X × {true, false}, where the two boolean tags represent the transitions under the permutations p and q. Because p and q are bijections, the combined map f is injective, which implies that the number of arcs exiting S equals the number of arcs entering S. The existence of an external vertex r ∉ S with an arc to x blocks one of the two possible exit arcs from S to x, bounding the number of exit arcs—and therefore entry arcs—by 1. Since x already contributes an arc entering S, no other vertex outside S can have an entering arc.

  1. The combined transition map f : X × Bool → X × Bool is injective.

    We define f to apply permutation p when the boolean tag is true and permutation q when it is false. To show f is injective, we consider two pairs and split into cases on their boolean tags: if the tags differ, their images have different second components; if they agree, the injectivity of p or q implies their first components are equal.

    lines 2–6

    uses Prod.mk.injEq

      classical
      let f : X × Bool → X × Bool := fun z => (if z.2 then p z.1 else q z.1, z.2)
      have hinj : Function.Injective f := by
        intro ⟨a,ba⟩ ⟨b,bb⟩ h
        cases ba <;> cases bb <;> simp_all [f, Prod.mk.injEq, p.injective.eq_iff, q.injective.eq_iff]
  2. The number of arcs exiting S equals the number of arcs entering S: |T \ W| = |W \ T|.

    We represent S in X × Bool by W = S × Bool, and let T = f(W) be its image under f. Because f is injective, Finset.card_image_of_injective gives |T| = |W|. By Finset.card_sdiff_comm, any two finite sets of the same size satisfy |T \ W| = |W \ T|, establishing conservation of flux between W and its complement.

    lines 7–12

    uses Finset.card_image_of_injective, Finset.card_sdiff_comm

      let W : Finset (X × Bool) := Finset.univ.filter fun z => z.1 ∈ S
      let T := W.image f
      have hcard : T.card = W.card := Finset.card_image_of_injective W hinj
      have hequal : (T \ W).card = (W \ T).card := Finset.card_sdiff_comm hcard
      have hW (z : X × Bool) : z ∈ W ↔ z.1 ∈ S := by simp [W]
      have hT (z : X × Bool) : z ∈ T ↔ ∃ a ∈ W, f a = z := by simp [T]
  3. Every arc exiting W lands on x in its first coordinate: for any z ∈ T \ W, z.1 = x.

    An element z ∈ T \ W is the image f(a, ba) of some a ∈ S, but its first component does not belong to S. Under the trap closure condition (hclosed), every arc leaving a ∈ S under p or q must land either in S or at x. Since the destination does not lie in S, it must equal x.

    lines 13–24

    uses Finset.mem_sdiff.mp

      have hout (z : X × Bool) (hz : z ∈ T \ W) : z.1 = x := by
        have hzt : z ∈ T := (Finset.mem_sdiff.mp hz).1
        have hzw : z ∉ W := (Finset.mem_sdiff.mp hz).2
        obtain ⟨⟨a, ba⟩, ha, hfa⟩ := (hT z).mp hzt
        have has : a ∈ S := (hW _).mp ha
        cases ba
        · have out : q a ∉ S := by simpa [f, ← hfa, hW] using hzw
          have eq : q a = x := (hclosed a has).2.resolve_left out
          simpa [f, ← hfa] using eq
        · have out : p a ∉ S := by simpa [f, ← hfa, hW] using hzw
          have eq : p a = x := (hclosed a has).1.resolve_left out
          simpa [f, ← hfa] using eq
  4. At most one arc exits W: |T \ W| ≤ 1.

    We case split on the assumption that an external vertex r ∉ S has an arc to x (harc : p r = x ∨ q r = x). If p r = x, any exiting edge z ∈ T \ W with second component true would come from p v = x for some v ∈ S; injectivity of p would force v = r ∉ S, contradiction. Thus all elements of T \ W must have second component false, and since their first component is always x, any two elements of T \ W coincide by Prod.ext, proving |T \ W| ≤ 1 by Finset.card_le_one.mpr. The symmetric argument holds when q r = x, forcing the second component to be true.

    lines 25–60

    uses Finset.card_le_one.mpr, Finset.mem_sdiff.mp, Prod.ext

      have hle : (T \ W).card ≤ 1 := by
        rcases harc with hp | hq
        · apply Finset.card_le_one.mpr
          intro a ha b hb
          have ha1 := hout a ha
          have hb1 := hout b hb
          have hfalse (z : X × Bool) (hz : z ∈ T \ W) : z.2 = false := by
            have ht := (Finset.mem_sdiff.mp hz).1
            obtain ⟨⟨v, bv⟩, hv, he⟩ := (hT z).mp ht
            have vs : v ∈ S := (hW _).mp hv
            cases bv
            · simpa [f, ← he]
            · have pv : p v = x := by simpa [f, ← he] using hout z hz
              have : v = r := p.injective (pv.trans hp.symm)
              subst v
              exact (hr vs).elim
          apply Prod.ext
          · exact ha1.trans hb1.symm
          · rw [hfalse a ha, hfalse b hb]
        · apply Finset.card_le_one.mpr
          intro a ha b hb
          have ha1 := hout a ha
          have hb1 := hout b hb
          have htrue (z : X × Bool) (hz : z ∈ T \ W) : z.2 = true := by
            have ht := (Finset.mem_sdiff.mp hz).1
            obtain ⟨⟨v, bv⟩, hv, he⟩ := (hT z).mp ht
            have vs : v ∈ S := (hW _).mp hv
            cases bv
            · have qv : q v = x := by simpa [f, ← he] using hout z hz
              have : v = r := q.injective (qv.trans hq.symm)
              subst v
              exact (hr vs).elim
            · simpa [f, ← he]
          apply Prod.ext
          · exact ha1.trans hb1.symm
          · rw [htrue a ha, htrue b hb]
  5. At most one arc enters W (|W \ T| ≤ 1), and any arc from outside S into S yields an element of W \ T.

    From |T \ W| = |W \ T| and |T \ W| ≤ 1, linear arithmetic gives |W \ T| ≤ 1. Furthermore, if u ∉ S and f(u, bu) has its first component in S, then f(u, bu) ∈ W; it cannot belong to T = f(W) because injectivity of f would force u ∈ S, so f(u, bu) ∈ W \ T by Finset.mem_sdiff.mpr.

    lines 61–70

    uses Finset.mem_sdiff.mpr

      have hinle : (W \ T).card ≤ 1 := by omega
      have hin (u : X) (bu : Bool) (hus : u ∉ S)
          (hres : (f (u,bu)).1 ∈ S) : f (u,bu) ∈ W \ T := by
        apply Finset.mem_sdiff.mpr
        refine ⟨(hW _).mpr hres, ?_⟩
        intro hf
        obtain ⟨a, ha, eq⟩ := (hT _).mp hf
        have : a = (u,bu) := hinj eq
        subst a
        exact hus ((hW _).mp ha)
  6. If x enters S via p, then no other vertex u ∉ S (u ≠ x) has an arc entering S.

    Under hentry, x has an entering arc to some v ∈ S. If p x = v, the transition f(x, true) belongs to W \ T. For any u ∉ S with u ≠ x, if p u ∈ S, then f(u, true) ∈ W \ T; because |W \ T| ≤ 1, Finset.card_le_one.mp forces f(u, true) = f(x, true), and injectivity of f together with projection to the first component (congrArg Prod.fst) gives u = x, a contradiction. The same argument rules out q u ∈ S.

    lines 71–84

    uses Finset.card_le_one.mp, congrArg, Prod.fst

      obtain ⟨v, hv, hvp | hvq⟩ := hentry
      · have hentry' : f (x,true) ∈ W \ T := hin x true hx (by simpa [f,hvp] using hv)
        intro u hu hux
        constructor
        · intro hup
          have hu' : f (u,true) ∈ W \ T := hin u true hu (by simpa [f] using hup)
          have eq : f (u,true) = f (x,true) := Finset.card_le_one.mp hinle _ hu' _ hentry'
          have : (u,true) = (x,true) := hinj eq
          exact hux (congrArg Prod.fst this)
        · intro huq
          have hu' : f (u,false) ∈ W \ T := hin u false hu (by simpa [f] using huq)
          have eq : f (u,false) = f (x,true) := Finset.card_le_one.mp hinle _ hu' _ hentry'
          have : (u,false) = (x,true) := hinj eq
          exact hux (congrArg Prod.fst this)
  7. If x enters S via q, then no other vertex u ∉ S (u ≠ x) has an arc entering S.

    In the remaining case where q x = v ∈ S, the transition f(x, false) belongs to W \ T. Assuming p u ∈ S or q u ∈ S for u ∉ S with u ≠ x yields an element of W \ T that must equal f(x, false) since |W \ T| ≤ 1. By injectivity of f and congrArg Prod.fst, this forces u = x, contradicting u ≠ x.

    lines 85–97

    uses Finset.card_le_one.mp, congrArg, Prod.fst

      · have hentry' : f (x,false) ∈ W \ T := hin x false hx (by simpa [f,hvq] using hv)
        intro u hu hux
        constructor
        · intro hup
          have hu' : f (u,true) ∈ W \ T := hin u true hu (by simpa [f] using hup)
          have eq : f (u,true) = f (x,false) := Finset.card_le_one.mp hinle _ hu' _ hentry'
          have : (u,true) = (x,false) := hinj eq
          exact hux (congrArg Prod.fst this)
        · intro huq
          have hu' : f (u,false) ∈ W \ T := hin u false hu (by simpa [f] using huq)
          have eq : f (u,false) = f (x,false) := Finset.card_le_one.mp hinle _ hu' _ hentry'
          have : (u,false) = (x,false) := hinj eq
          exact hux (congrArg Prod.fst this)
congrArg
Applying a function to equal arguments produces equal values.
Finset.card_le_one.mp
If a finite set has cardinality at most 1, then any two of its elements are equal.
Finset.card_le_one.mpr
A finite set has cardinality at most 1 if every pair of elements in it are equal.
Finset.card_image_of_injective
The image of a finite set under an injective function has the same cardinality as the original set.
Finset.card_sdiff_comm
If two finite sets have equal cardinality, the set difference of the first minus the second has the same cardinality as the second minus the first.
Finset.mem_sdiff.mp
An element belongs to the difference of two sets only if it belongs to the first and does not belong to the second.
Finset.mem_sdiff.mpr
An element belongs to the difference of two sets if it belongs to the first and does not belong to the second.
Prod.ext
Two ordered pairs are equal if their respective first and second components are equal.
Prod.fst
The projection extracting the first coordinate from an ordered pair.
Prod.mk.injEq
Two pairs are equal if and only if their first coordinates are equal and their second coordinates are equal.

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_balanced_trap_enters_only_at_successor {X : Type*} [Fintype X] [DecidableEq X] (p q : Equiv.Perm X) (S : Finset X) (r x : X) (hr : r ∉ S) (hx : x ∉ S) (harc : p r = x ∨ q r = x) (hclosed : ∀ u ∈ S, (p u ∈ S ∨ p u = x) ∧ (q u ∈ S ∨ q u = x)) (hentry : ∃ v ∈ S, p x = v ∨ q x = v) : ∀ u, u ∉ S → u ≠ x → p u ∉ S ∧ q u ∉ S := by  classical  let f : X × Bool → X × Bool := fun z => (if z.2 then p z.1 else q z.1, z.2)  have hinj : Function.Injective f := by    intro ⟨a,ba⟩ ⟨b,bb⟩ h    cases ba <;> cases bb <;> simp_all [f, Prod.mk.injEq, p.injective.eq_iff, q.injective.eq_iff]  let W : Finset (X × Bool) := Finset.univ.filter fun z => z.1 ∈ S  let T := W.image f  have hcard : T.card = W.card := Finset.card_image_of_injective W hinj  have hequal : (T \ W).card = (W \ T).card := Finset.card_sdiff_comm hcard  have hW (z : X × Bool) : z ∈ W ↔ z.1 ∈ S := by simp [W]  have hT (z : X × Bool) : z ∈ T ↔ ∃ a ∈ W, f a = z := by simp [T]  have hout (z : X × Bool) (hz : z ∈ T \ W) : z.1 = x := by    have hzt : z ∈ T := (Finset.mem_sdiff.mp hz).1    have hzw : z ∉ W := (Finset.mem_sdiff.mp hz).2    obtain ⟨⟨a, ba⟩, ha, hfa⟩ := (hT z).mp hzt    have has : a ∈ S := (hW _).mp ha    cases ba    · have out : q a ∉ S := by simpa [f, ← hfa, hW] using hzw      have eq : q a = x := (hclosed a has).2.resolve_left out      simpa [f, ← hfa] using eq    · have out : p a ∉ S := by simpa [f, ← hfa, hW] using hzw      have eq : p a = x := (hclosed a has).1.resolve_left out      simpa [f, ← hfa] using eq  have hle : (T \ W).card ≤ 1 := by    rcases harc with hp | hq    · apply Finset.card_le_one.mpr      intro a ha b hb      have ha1 := hout a ha      have hb1 := hout b hb      have hfalse (z : X × Bool) (hz : z ∈ T \ W) : z.2 = false := by        have ht := (Finset.mem_sdiff.mp hz).1        obtain ⟨⟨v, bv⟩, hv, he⟩ := (hT z).mp ht        have vs : v ∈ S := (hW _).mp hv        cases bv        · simpa [f, ← he]        · have pv : p v = x := by simpa [f, ← he] using hout z hz          have : v = r := p.injective (pv.trans hp.symm)          subst v          exact (hr vs).elim      apply Prod.ext      · exact ha1.trans hb1.symm      · rw [hfalse a ha, hfalse b hb]    · apply Finset.card_le_one.mpr      intro a ha b hb      have ha1 := hout a ha      have hb1 := hout b hb      have htrue (z : X × Bool) (hz : z ∈ T \ W) : z.2 = true := by        have ht := (Finset.mem_sdiff.mp hz).1        obtain ⟨⟨v, bv⟩, hv, he⟩ := (hT z).mp ht        have vs : v ∈ S := (hW _).mp hv        cases bv        · have qv : q v = x := by simpa [f, ← he] using hout z hz          have : v = r := q.injective (qv.trans hq.symm)          subst v          exact (hr vs).elim        · simpa [f, ← he]      apply Prod.ext      · exact ha1.trans hb1.symm      · rw [htrue a ha, htrue b hb]  have hinle : (W \ T).card ≤ 1 := by omega  have hin (u : X) (bu : Bool) (hus : u ∉ S)      (hres : (f (u,bu)).1 ∈ S) : f (u,bu) ∈ W \ T := by    apply Finset.mem_sdiff.mpr    refine ⟨(hW _).mpr hres, ?_⟩    intro hf    obtain ⟨a, ha, eq⟩ := (hT _).mp hf    have : a = (u,bu) := hinj eq    subst a    exact hus ((hW _).mp ha)  obtain ⟨v, hv, hvp | hvq⟩ := hentry  · have hentry' : f (x,true) ∈ W \ T := hin x true hx (by simpa [f,hvp] using hv)    intro u hu hux    constructor    · intro hup      have hu' : f (u,true) ∈ W \ T := hin u true hu (by simpa [f] using hup)      have eq : f (u,true) = f (x,true) := Finset.card_le_one.mp hinle _ hu' _ hentry'      have : (u,true) = (x,true) := hinj eq      exact hux (congrArg Prod.fst this)    · intro huq      have hu' : f (u,false) ∈ W \ T := hin u false hu (by simpa [f] using huq)      have eq : f (u,false) = f (x,true) := Finset.card_le_one.mp hinle _ hu' _ hentry'      have : (u,false) = (x,true) := hinj eq      exact hux (congrArg Prod.fst this)  · have hentry' : f (x,false) ∈ W \ T := hin x false hx (by simpa [f,hvq] using hv)    intro u hu hux    constructor    · intro hup      have hu' : f (u,true) ∈ W \ T := hin u true hu (by simpa [f] using hup)      have eq : f (u,true) = f (x,false) := Finset.card_le_one.mp hinle _ hu' _ hentry'      have : (u,true) = (x,false) := hinj eq      exact hux (congrArg Prod.fst this)    · intro huq      have hu' : f (u,false) ∈ W \ T := hin u false hu (by simpa [f] using huq)      have eq : f (u,false) = f (x,false) := Finset.card_le_one.mp hinle _ hu' _ hentry'      have : (u,false) = (x,false) := hinj eq      exact hux (congrArg Prod.fst this)
See it in the graphDiscuss this resultChallenge it