AFTD Auto-Formalizing Theoretical Domains

finset_sdiff_card_le_erase_sdiff_card_add_one

theoremverified

Erasing one element from a finite set lowers the size of its difference with any set by at most one.

Statement

theorem finset_sdiff_card_le_erase_sdiff_card_add_one {V : Type*} [DecidableEq V] (s Q : Finset V) (y : V) :
    (s \ Q).card ≤ ((s.erase y) \ Q).card + 1
Source
OP-1957: graph-to-count transfer for the size-five block forced-edge route (IN-1126).
Verified
22 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Used by 2

The proof, explained

We first establish that s \ Q is a subset of insert y ((s.erase y) \ Q). For any element w ∈ s \ Q, it is either equal to y (hence in the inserted set) or distinct from y (hence in the difference (s.erase y) \ Q). The desired inequality then follows from the monotonicity of cardinality under subset inclusion and the fact that inserting an element increases cardinality by at most one.

  1. To show s \ Q ⊆ insert y ((s.erase y) \ Q), take an arbitrary element w ∈ s \ Q; then w ∈ s and w ∉ Q.

    We begin proving the inclusion s \ Q ⊆ insert y ((s.erase y) \ Q) by introducing an element w ∈ s \ Q and rewriting its membership hypothesis with Finset.mem_sdiff into the conjunction w ∈ s and w ∉ Q.

    lines 3–5

    uses Finset.mem_sdiff

      have hsub : s \ Q ⊆ insert y ((s.erase y) \ Q) := by
        intro w hw
        rw [Finset.mem_sdiff] at hw
  2. If w = y, then w ∈ insert y ((s.erase y) \ Q).

    We split into cases depending on whether w = y. If w = y, then w is the newly inserted element y, so membership in insert y ((s.erase y) \ Q) holds immediately.

    lines 6–7

        by_cases h : w = y
        · simp [h]
  3. If w ≠ y, then w ∈ (s.erase y) \ Q, and hence w ∈ insert y ((s.erase y) \ Q), completing the inclusion s \ Q ⊆ insert y ((s.erase y) \ Q).

    If w ≠ y, then since w ∈ s, we have w ∈ s.erase y by Finset.mem_erase. Since also w ∉ Q, it follows by Finset.mem_sdiff that w ∈ (s.erase y) \ Q. Simplification using these facts completes the second branch and establishes the inclusion.

    line 8

    uses Finset.mem_sdiff, Finset.mem_erase

        · simp [Finset.mem_sdiff, Finset.mem_erase, h, hw.1, hw.2]
  4. |s \ Q| ≤ |(s.erase y) \ Q| + 1.

    Applying monotonicity of cardinality under inclusion (Finset.card_le_card) to the established subset relation yields |s \ Q| ≤ |insert y ((s.erase y) \ Q)|. Since inserting an element increases cardinality by at most one (Finset.card_insert_le), transitivity of inequality gives the result.

    line 9

    uses Finset.card_le_card, Finset.card_insert_le

      exact (Finset.card_le_card hsub).trans (Finset.card_insert_le _ _)
Finset.mem_sdiff
An element belongs to the difference of two finite sets s \ t if and only if it belongs to s and not to t.
Finset.mem_erase
An element a belongs to s.erase b if and only if a ≠ b and a ∈ s.
Finset.card_le_card
If s ⊆ t for finite sets s and t, then |s| ≤ |t|.
Finset.card_insert_le
Inserting an element into a finite set increases its cardinality by at most one: |insert a s| ≤ |s| + 1.

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 finset_sdiff_card_le_erase_sdiff_card_add_one {V : Type*} [DecidableEq V] (s Q : Finset V) (y : V) :    (s \ Q).card ≤ ((s.erase y) \ Q).card + 1 := by  have hsub : s \ Q ⊆ insert y ((s.erase y) \ Q) := by    intro w hw    rw [Finset.mem_sdiff] at hw    by_cases h : w = y    · simp [h]    · simp [Finset.mem_sdiff, Finset.mem_erase, h, hw.1, hw.2]  exact (Finset.card_le_card hsub).trans (Finset.card_insert_le _ _)
See it in the graphDiscuss this resultChallenge it