AFTD Auto-Formalizing Theoretical Domains

good_slopes_five_levels_no_vertical

theoremverified

A finite set has five rows and five columns, each of size eleven. If each x-fiber has at most fifteen points, each row-column-x fiber at most three, and x is either constant or injective on each column, then x cannot be constant on a row.

Statement

theorem good_slopes_five_levels_no_vertical
    {α : Type} [DecidableEq α] (S : Finset α) (row col : α → Fin 5) (x : α → Fin 11)
    (hrows : ∀ i, (S.filter fun p => row p = i).card = 11)
    (hcols : ∀ j, (S.filter fun p => col p = j).card = 11)
    (hbound : ∀ k, (S.filter fun p => x p = k).card ≤ 15)
    (hcross : ∀ i j k, (S.filter fun p => row p = i ∧ col p = j ∧ x p = k).card ≤ 3)
    (hclass : ∀ j, (∃ k, ∀ p ∈ S, col p = j → x p = k) ∨
      Set.InjOn x {p | p ∈ S ∧ col p = j}) :
    ∀ i k, ¬ ∀ p ∈ S, row p = i → x p = k
Source
The vertical-slice counting step for the 55-point fiber in OP-1027.
Verified
18 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1
Used by 1

The proof, explained

Suppose for contradiction that x takes a constant value k on row i. We call a column bad if x is constant with value k on that whole column. Because each column has 11 points and distinct columns are disjoint, two bad columns would place 22 points in the fiber x⁻¹(k), exceeding the fiber bound of 15; thus at most one column is bad. Each intersection of row i with a column has at most 3 points if the column is bad, and at most 1 point if it is not bad. Summing over all five columns, row i has at most 3 + 4 × 1 = 7 points, contradicting that row i has size 11.

  1. Assume for contradiction that row i is identically equal to k, and define the bad column predicate and column-row intersection cells.

    We assume for contradiction that row i is constant with value k (hconst). A column j is defined to be bad if x takes the value k on all of column j. For each column j, Tj j denotes the set of points in S lying in row i and column j.

    lines 10–13

      classical
      intro i k hconst
      set bad : Fin 5 → Prop := fun j => ∀ p ∈ S, col p = j → x p = k with hbaddef
      set Tj : Fin 5 → Finset α := fun j => S.filter (fun p => row p = i ∧ col p = j) with hTjdef
  2. At most one column is bad.

    If two distinct columns a and b were both bad, every point in column a and every point in column b would have x = k, so their union would be contained in the fiber x⁻¹(k). Since columns a and b are disjoint and each contains 11 points, their union has 11 + 11 = 22 points. But every x-fiber has at most 15 points (hbound), giving 22 ≤ 15, an impossible arithmetic inequality. Thus at most one column is bad.

    lines 14–33

    uses Finset.card_le_one, Finset.mem_filter, Finset.mem_univ, true_and, Finset.disjoint_filter, Finset.mem_union, Finset.card_le_card, Finset.card_union_of_disjoint

      have hbad_le_one : (Finset.univ.filter bad).card ≤ 1 := by
        rw [Finset.card_le_one]
        intro a ha b hb
        simp only [Finset.mem_filter, Finset.mem_univ, true_and] at ha hb
        by_contra hab
        have hdisj : Disjoint (S.filter fun p => col p = a) (S.filter fun p => col p = b) := by
          rw [Finset.disjoint_filter]
          intro p hp hpa hpb
          exact hab (hpa.symm.trans hpb)
        have hsub : (S.filter fun p => col p = a) ∪ (S.filter fun p => col p = b) ⊆
            S.filter (fun p => x p = k) := by
          intro p hp
          simp only [Finset.mem_union, Finset.mem_filter] at hp ⊢
          rcases hp with ⟨hpS, hpa⟩ | ⟨hpS, hpb⟩
          · exact ⟨hpS, ha p hpS hpa⟩
          · exact ⟨hpS, hb p hpS hpb⟩
        have hcard := Finset.card_le_card hsub
        rw [Finset.card_union_of_disjoint hdisj, hcols a, hcols b] at hcard
        have hb15 := hbound k
        omega
  3. Each cell Tj j has size at most 3 if column j is bad, and at most 1 otherwise.

    We split into cases on whether column j is bad. If j is bad, all points in Tj j have row i, col j, and x = k, so Tj j has size at most 3 by the row-column-x fiber bound (hcross). If j is not bad, by hclass the function x on column j is either constant or injective. If it were constant with value k', any element a in Tj j would have x a = k' and x a = k, forcing k' = k and contradicting that j is not bad. If x is injective on column j, any two elements a, b in Tj j satisfy x a = k = x b, which forces a = b. Hence Tj j has size at most 1 when j is not bad.

    lines 34–61

    uses if_pos, Finset.mem_filter, le_trans, Finset.card_le_card, if_neg, Finset.card_le_one

      have hb : ∀ j, (Tj j).card ≤ (if bad j then 3 else 1) := by
        intro j
        by_cases hbj : bad j
        · rw [if_pos hbj]
          have hsub : Tj j ⊆ S.filter (fun p => row p = i ∧ col p = j ∧ x p = k) := by
            intro p hp
            simp only [hTjdef, Finset.mem_filter] at hp ⊢
            exact ⟨hp.1, hp.2.1, hp.2.2, hconst p hp.1 hp.2.1⟩
          exact le_trans (Finset.card_le_card hsub) (hcross i j k)
        · rw [if_neg hbj]
          rcases hclass j with ⟨k', hk'⟩ | hinj
          · have hle1 : (Tj j).card ≤ 1 := by
              rw [Finset.card_le_one]
              intro a ha b hb2
              simp only [hTjdef, Finset.mem_filter] at ha
              have h1 : x a = k' := hk' a ha.1 ha.2.2
              have h2 : x a = k := hconst a ha.1 ha.2.1
              exact absurd (fun q hqS hqcol => (hk' q hqS hqcol).trans (h1.symm.trans h2)) hbj
            exact hle1
          · have hle1 : (Tj j).card ≤ 1 := by
              rw [Finset.card_le_one]
              intro a ha b hb2
              simp only [hTjdef, Finset.mem_filter] at ha hb2
              have hxa : x a = k := hconst a ha.1 ha.2.1
              have hxb : x b = k := hconst b hb2.1 hb2.2.1
              have hxx : x a = x b := by rw [hxa, hxb]
              exact hinj ⟨ha.1, ha.2.2⟩ ⟨hb2.1, hb2.2.2⟩ hxx
            exact hle1
  4. The sum of the sizes of the cells Tj j across all five columns equals 11.

    Partitioning row i into fibers according to the column coordinate col decomposes the 11 points of row i into the disjoint union of the five cells Tj j. By Finset.card_eq_sum_card_fiberwise, the sum of their cardinalities equals the row size 11.

    lines 62–70

    uses Finset.card_eq_sum_card_fiberwise, Finset.sum_congr, Finset.filter_filter

      have hsum_eq_11 : ∑ j : Fin 5, (Tj j).card = 11 := by
        have hfiber := Finset.card_eq_sum_card_fiberwise
          (f := col) (s := S.filter (fun p => row p = i)) (t := Finset.univ)
          (fun p _ => by simp)
        rw [hrows i] at hfiber
        rw [hfiber]
        apply Finset.sum_congr rfl
        intro j _
        simp only [hTjdef, Finset.filter_filter]
  5. The sum of the bounds across all five columns is at most 7.

    Each term (if bad j then 3 else 1) can be rewritten as 1 + 2 * (if bad j then 1 else 0). Summing this over the five columns j ∈ Fin 5 produces 5 plus twice the number of bad columns. Since the number of bad columns is at most 1, this sum is at most 5 + 2 * 1 = 7.

    lines 71–86

    uses Finset.sum_congr, Finset.sum_add_distrib, Finset.mul_sum, Finset.card_filter

      have hbound7 : ∑ j : Fin 5, (if bad j then 3 else 1) ≤ 7 := by
        have heq : ∑ j : Fin 5, (if bad j then 3 else 1) = 5 + 2 * (Finset.univ.filter bad).card := by
          have hpt : ∀ j : Fin 5, (if bad j then 3 else 1) = 1 + 2 * (if bad j then (1:ℕ) else 0) := by
            intro j; split <;> rfl
          have h1 : (∑ j : Fin 5, (1:ℕ)) = 5 := by simp
          calc ∑ j : Fin 5, (if bad j then 3 else 1)
              = ∑ j : Fin 5, (1 + 2 * (if bad j then (1:ℕ) else 0)) := by
                  apply Finset.sum_congr rfl; intro j _; exact hpt j
            _ = ∑ j : Fin 5, (1:ℕ) + ∑ j : Fin 5, 2 * (if bad j then (1:ℕ) else 0) := by
                  rw [Finset.sum_add_distrib]
            _ = 5 + 2 * ∑ j : Fin 5, (if bad j then (1:ℕ) else 0) := by
                  rw [← Finset.mul_sum, h1]
            _ = 5 + 2 * (Finset.univ.filter bad).card := by
                  rw [Finset.card_filter]
        rw [heq]
        omega
  6. Row i cannot have size 11, completing the proof by contradiction.

    Summing the bounds |Tj j| ≤ (if bad j then 3 else 1) over all five columns shows that the row size 11 is bounded above by 7, which is impossible. Linear arithmetic closes the goal.

    lines 87–90

    uses Finset.sum_le_sum, le_trans

      have hsum_le : ∑ j : Fin 5, (Tj j).card ≤ ∑ j : Fin 5, (if bad j then 3 else 1) :=
        Finset.sum_le_sum (fun j _ => hb j)
      have : 11 ≤ 7 := by rw [← hsum_eq_11]; exact le_trans hsum_le hbound7
      omega
Finset.card_le_one
A finite set has cardinality at most 1 if and only if any two of its elements are equal.
Finset.mem_filter
An element belongs to the filter of a finite set by a predicate if and only if it belongs to the set and satisfies the predicate.
Finset.mem_univ
Every element of a finite type belongs to Finset.univ.
true_and
The conjunction True ∧ p is equivalent to p.
Finset.disjoint_filter
Two subsets obtained by filtering the same set with two predicates are disjoint if and only if no element satisfies both predicates.
Finset.mem_union
An element belongs to the union of two finite sets if and only if it belongs to at least one of them.
Finset.card_le_card
If one finite set is a subset of another, its cardinality is at most that of the superset.
Finset.card_union_of_disjoint
The cardinality of the union of two disjoint finite sets is the sum of their cardinalities.
if_pos
An if-then-else expression evaluates to the then branch when the condition is true.
if_neg
An if-then-else expression evaluates to the else branch when the condition is false.
le_trans
The inequality relation ≤ is transitive: a ≤ b and b ≤ c imply a ≤ c.
Finset.card_eq_sum_card_fiberwise
The cardinality of a finite set equals the sum of the cardinalities of its fibers under a map.
Finset.sum_congr
Two finite sums are equal if their index sets are equal and their terms are pointwise equal.
Finset.filter_filter
Successively filtering a finite set by two predicates is equivalent to filtering by their conjunction.
Finset.sum_add_distrib
A finite sum of sums equals the sum of the respective finite sums.
Finset.mul_sum
Multiplication by a constant distributes over a finite sum.
Finset.card_filter
The cardinality of a filtered subset equals the sum over the parent set of the indicator of the predicate.
Finset.sum_le_sum
A sum of pointwise smaller terms is less than or equal to the sum of the larger terms.

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 good_slopes_five_levels_no_vertical    {α : Type} [DecidableEq α] (S : Finset α) (row col : α → Fin 5) (x : α → Fin 11)    (hrows : ∀ i, (S.filter fun p => row p = i).card = 11)    (hcols : ∀ j, (S.filter fun p => col p = j).card = 11)    (hbound : ∀ k, (S.filter fun p => x p = k).card ≤ 15)    (hcross : ∀ i j k, (S.filter fun p => row p = i ∧ col p = j ∧ x p = k).card ≤ 3)    (hclass : ∀ j, (∃ k, ∀ p ∈ S, col p = j → x p = k) ∨      Set.InjOn x {p | p ∈ S ∧ col p = j}) :    ∀ i k, ¬ ∀ p ∈ S, row p = i → x p = k := by  classical  intro i k hconst  set bad : Fin 5 → Prop := fun j => ∀ p ∈ S, col p = j → x p = k with hbaddef  set Tj : Fin 5 → Finset α := fun j => S.filter (fun p => row p = i ∧ col p = j) with hTjdef  have hbad_le_one : (Finset.univ.filter bad).card ≤ 1 := by    rw [Finset.card_le_one]    intro a ha b hb    simp only [Finset.mem_filter, Finset.mem_univ, true_and] at ha hb    by_contra hab    have hdisj : Disjoint (S.filter fun p => col p = a) (S.filter fun p => col p = b) := by      rw [Finset.disjoint_filter]      intro p hp hpa hpb      exact hab (hpa.symm.trans hpb)    have hsub : (S.filter fun p => col p = a) ∪ (S.filter fun p => col p = b) ⊆        S.filter (fun p => x p = k) := by      intro p hp      simp only [Finset.mem_union, Finset.mem_filter] at hp ⊢      rcases hp with ⟨hpS, hpa⟩ | ⟨hpS, hpb⟩      · exact ⟨hpS, ha p hpS hpa⟩      · exact ⟨hpS, hb p hpS hpb⟩    have hcard := Finset.card_le_card hsub    rw [Finset.card_union_of_disjoint hdisj, hcols a, hcols b] at hcard    have hb15 := hbound k    omega  have hb : ∀ j, (Tj j).card ≤ (if bad j then 3 else 1) := by    intro j    by_cases hbj : bad j    · rw [if_pos hbj]      have hsub : Tj j ⊆ S.filter (fun p => row p = i ∧ col p = j ∧ x p = k) := by        intro p hp        simp only [hTjdef, Finset.mem_filter] at hp ⊢        exact ⟨hp.1, hp.2.1, hp.2.2, hconst p hp.1 hp.2.1⟩      exact le_trans (Finset.card_le_card hsub) (hcross i j k)    · rw [if_neg hbj]      rcases hclass j with ⟨k', hk'⟩ | hinj      · have hle1 : (Tj j).card ≤ 1 := by          rw [Finset.card_le_one]          intro a ha b hb2          simp only [hTjdef, Finset.mem_filter] at ha          have h1 : x a = k' := hk' a ha.1 ha.2.2          have h2 : x a = k := hconst a ha.1 ha.2.1          exact absurd (fun q hqS hqcol => (hk' q hqS hqcol).trans (h1.symm.trans h2)) hbj        exact hle1      · have hle1 : (Tj j).card ≤ 1 := by          rw [Finset.card_le_one]          intro a ha b hb2          simp only [hTjdef, Finset.mem_filter] at ha hb2          have hxa : x a = k := hconst a ha.1 ha.2.1          have hxb : x b = k := hconst b hb2.1 hb2.2.1          have hxx : x a = x b := by rw [hxa, hxb]          exact hinj ⟨ha.1, ha.2.2⟩ ⟨hb2.1, hb2.2.2⟩ hxx        exact hle1  have hsum_eq_11 : ∑ j : Fin 5, (Tj j).card = 11 := by    have hfiber := Finset.card_eq_sum_card_fiberwise      (f := col) (s := S.filter (fun p => row p = i)) (t := Finset.univ)      (fun p _ => by simp)    rw [hrows i] at hfiber    rw [hfiber]    apply Finset.sum_congr rfl    intro j _    simp only [hTjdef, Finset.filter_filter]  have hbound7 : ∑ j : Fin 5, (if bad j then 3 else 1) ≤ 7 := by    have heq : ∑ j : Fin 5, (if bad j then 3 else 1) = 5 + 2 * (Finset.univ.filter bad).card := by      have hpt : ∀ j : Fin 5, (if bad j then 3 else 1) = 1 + 2 * (if bad j then (1:ℕ) else 0) := by        intro j; split <;> rfl      have h1 : (∑ j : Fin 5, (1:ℕ)) = 5 := by simp      calc ∑ j : Fin 5, (if bad j then 3 else 1)          = ∑ j : Fin 5, (1 + 2 * (if bad j then (1:ℕ) else 0)) := by              apply Finset.sum_congr rfl; intro j _; exact hpt j        _ = ∑ j : Fin 5, (1:ℕ) + ∑ j : Fin 5, 2 * (if bad j then (1:ℕ) else 0) := by              rw [Finset.sum_add_distrib]        _ = 5 + 2 * ∑ j : Fin 5, (if bad j then (1:ℕ) else 0) := by              rw [← Finset.mul_sum, h1]        _ = 5 + 2 * (Finset.univ.filter bad).card := by              rw [Finset.card_filter]    rw [heq]    omega  have hsum_le : ∑ j : Fin 5, (Tj j).card ≤ ∑ j : Fin 5, (if bad j then 3 else 1) :=    Finset.sum_le_sum (fun j _ => hb j)  have : 11 ≤ 7 := by rw [← hsum_eq_11]; exact le_trans hsum_le hbound7  omega
See it in the graphDiscuss this resultChallenge it