Progression-free sets and the counting function
DefinitionErdos142BasicThis file fixes the objects of Erdős Problem #142. Its first four declarations are transcribed verbatim from the formal-conjectures entry for this problem, so that the mission's goal is literally the statement recorded there.
Progressions. For a set , a length and elements , the predicate IsAPOfLengthWith says that is the arithmetic progression of length with first term and common difference : it has exactly elements and
IsAPOfLength existentially quantifies over and .
Progression-freeness. IsAPOfLengthFree declares free of progressions of length when
Progressions of length and count as trivial, so every set is free of them; the condition has content only for .
The counting function. For natural numbers and ,
This is the function Erdős asked for an asymptotic formula for, and the subject of Roth's theorem, Behrend's construction, Szemerédi's theorem and every modern quantitative bound on progression-free sets.
An elementary handle. The file adds a second formulation for solvers to work with: HasAP k A says that the finite set contains a first term and a common difference with for every , and APFree k A is its negation. This version carries no cardinality side condition and is the form one actually induct on. The mission's first milestone is the bridge between the two formulations.
Three supporting lemmas are supplied so that the supremum is usable: the empty set is free of progressions of every length, every progression-free subset of has at most elements, and .
Formalization Note. The ground set is Finset.Icc 1 N, that is , matching the problem statement and the source file rather than Finset.range N. The supremum is sSup over ; le_r and r_le are the two facts that make it a genuine maximum. Under the source convention , since every set is free of trivial progressions; statements that need to exclude that carry an explicit hypothesis on .
import Mathlib
namespace Erdos142
variable {α : Type*} [AddCommMonoid α]
/-- A set `s` is an arithmetic progression of length `l` with first term `a` and difference `d`
if `s = {a, a + d, …, a + (l-1)d}` when `l` is finite, and `s = {a, a + d, a + 2d, …}` when
`l = ⊤`. -/
def IsAPOfLengthWith (s : Set α) (l : ℕ∞) (a d : α) : Prop :=
ENat.card s = l ∧ s = {a + n • d | (n : ℕ) (_ : n < l)}
/-- A set `s` is an arithmetic progression of length `l`, for some first term and difference. -/
def IsAPOfLength (s : Set α) (l : ℕ∞) : Prop :=
∃ a d : α, IsAPOfLengthWith s l a d
/-- A set `s` is free of arithmetic progressions of length `l` if it contains no non-trivial
arithmetic progression of length `l`. -/
def IsAPOfLengthFree (s : Set α) (l : ℕ∞) : Prop :=
∀ t ⊆ s, IsAPOfLength t l → l ≤ 1
/-- `r k N` is the largest possible size of a subset of `{1, …, N}` that does not contain
any non-trivial `k`-term arithmetic progression. -/
noncomputable def r (k N : ℕ) : ℕ :=
sSup {Finset.card S | (S) (_ : S ⊆ Finset.Icc 1 N) (_ : IsAPOfLengthFree (S : Set ℕ) k)}
/-- The elementary form of "contains a non-trivial `k`-term arithmetic progression": there are a
first term `a` and a common difference `d > 0` with `a + i * d ∈ A` for every `i < k`. -/
def HasAP (k : ℕ) (A : Finset ℕ) : Prop :=
∃ a d : ℕ, 0 < d ∧ ∀ i < k, a + i * d ∈ A
/-- The elementary form of progression-freeness: the negation of `HasAP k A`. -/
def APFree (k : ℕ) (A : Finset ℕ) : Prop :=
¬ HasAP k A
/-- The empty set is free of arithmetic progressions of every length. -/
theorem isAPOfLengthFree_empty (k : ℕ) : IsAPOfLengthFree (∅ : Set α) k := by
rintro t ht ⟨a, d, hcard, -⟩
rw [Set.subset_empty_iff] at ht
subst ht
rw [show ENat.card (↥(∅ : Set α)) = 0 by simp [ENat.card]] at hcard
simp [← hcard]
/-- Every progression-free subset of `{1, …, N}` has at most `r k N` elements. -/
theorem le_r {S : Finset ℕ} {k N : ℕ} (hS : S ⊆ Finset.Icc 1 N)
(hfree : IsAPOfLengthFree (S : Set ℕ) k) : S.card ≤ r k N := by
refine le_csSup ⟨N, ?_⟩ ⟨S, hS, hfree, rfl⟩
rintro m ⟨T, hT, -, rfl⟩
simpa using (Finset.card_le_card hT).trans_eq (by simp)
/-- The trivial upper bound `r k N ≤ N`. -/
theorem r_le (k N : ℕ) : r k N ≤ N := by
refine csSup_le ⟨0, ∅, by simp, by simpa using isAPOfLengthFree_empty (α := ℕ) k, rfl⟩ ?_
rintro m ⟨T, hT, -, rfl⟩
simpa using (Finset.card_le_card hT).trans_eq (by simp)
end Erdos142
Read-back
What the Lean code literally says, in plain math · claude-opus-5
Read-back — Erdos142Basic.lean
The whole file lives in a namespace Erdos142 and imports all of Mathlib. Two of the declarations below are stated for an arbitrary ambient type carrying the structure of an additive commutative monoid (so has an addition that is associative and commutative, and a neutral element ; there is no subtraction, no order, and no cancellation available). The remaining declarations are stated concretely for the natural numbers .
Throughout, denotes the extended naturals (ℕ∞), with (written ) as the largest element, and denotes the -valued cardinality of a set (ENat.card), which equals the ordinary number of elements when is finite and equals when is infinite. For and , denotes the monoid multiple ( summands), with .
1. IsAPOfLengthWith (definition)
For an additive commutative monoid , a set , an extended natural number , and two elements , the proposition is defined to be the conjunction of two conditions:
Here the comparison is taken in after coercing the natural number ; the second condition is a set equality (both inclusions), where the right-hand side is the set of all elements expressible as for some natural number strictly below .
Points that this definition silently includes:
- Nothing forbids . If then the right-hand set is when and when ; the first conjunct then forces (resp. ), so the two conjuncts together can only be met at in that case.
- : the right-hand set is empty (no natural number is ) and , so the definition holds exactly when , and it then holds for every choice of and .
- : the right-hand set is and , so the definition holds exactly when , again for every choice of .
- : every natural number satisfies , so the right-hand set is the full forward orbit , and requires to be infinite.
- There is no injectivity hypothesis on ; the only thing that constrains repetitions is the cardinality equation , which requires the displayed set to have exactly elements. In particular the condition is an exact cardinality, not an inequality.
- itself is always a member of whenever (take ).
2. IsAPOfLength (definition)
For an additive commutative monoid , a set and , the proposition says that there exist and such that holds, i.e. such that
Both and are existentially quantified over all of ; in particular is an allowed witness. By the previous item, holds precisely when , and holds precisely when is a singleton (both because , being a monoid, is nonempty and supplies witnesses ).
3. IsAPOfLengthFree (definition)
For an additive commutative monoid , a set and , the proposition is defined as:
The quantifier ranges over all subsets of (including and ). Note that the conclusion of the implication is , a statement about alone that does not mention or . Consequently the definition is logically equivalent to
Degenerate readings this entails:
- For and for the conclusion is true outright, so holds vacuously for every set whatsoever, including .
- For (including ) the definition says: no subset satisfies together with for some . Because cannot hold when (that set is a singleton), the excluded configurations are automatically ones with ; but this is a consequence of the cardinality equation, not a separately stated hypothesis.
- The excluded must be exactly equal to the progression set , not merely contain it.
4. r (noncomputable definition)
For natural numbers and , the natural number is defined as the supremum, taken in , of the set of cardinalities
where ranges over finite subsets of , the containment is in the integer interval (which is empty when ), is the number of elements of , and the freeness condition is of item 3 applied to viewed as a set of naturals, at the length coerced into (so the length is always a genuine natural number here, never ).
Conventions that this definition carries:
- The supremum is the -valued supremum. On this operation returns the junk value whenever the set has no greatest element — that is, when the set is empty, and also when it is nonempty but unbounded above. It returns the actual maximum only when the set is nonempty and bounded.
- By item 3, when or the freeness condition is satisfied by every , so the set being maximised is the set of all cardinalities of subsets of .
- The empty set always satisfies both side conditions (see item 7), so always belongs to the set; and every in the set has . Hence in this particular definition the supremum is an honest maximum and no junk value is triggered.
- No lower bound , and no restriction such as , appears anywhere in the definition.
5. HasAP (definition)
For a natural number and a finite set of natural numbers , the proposition says:
Here is allowed to be , is required to be strictly positive, and is ordinary multiplication of naturals. Edge cases:
- For the inner universal statement is vacuous, so holds for every , including (witnesses , ).
- For the statement reduces to , i.e. holds exactly when .
- Since , the listed terms are pairwise distinct naturals.
6. APFree (definition)
For a natural number and a finite set of natural numbers , is defined to be the negation , i.e. there are no and with such that for all . By the previous item, is false for every , and holds exactly when .
These two elementary predicates and are not referred to by any other declaration in this file; in particular no declaration here relates them to or to .
7. isAPOfLengthFree_empty (theorem)
For every additive commutative monoid (implicit type argument, with its AddCommMonoid instance) and every natural number , the empty subset of satisfies
where is coerced into . Unfolded, the assertion is: for every set , if there exist with and , then . The only such is , whose cardinality is , so the hypothesis forces and hence . The statement is asserted only for lengths that are natural numbers; the case is not covered by this declaration.
8. le_r (theorem)
Let be a finite set of natural numbers and let and be natural numbers (all three are implicit arguments). Assume:
- ; and
- — that is, for every set , if is an arithmetic progression of length exactly in the sense of item 2, then .
Then
with as defined in item 4 (the -valued supremum of the cardinalities of all progression-free subsets of ). Note that for and hypothesis 2 is automatically satisfied by every , so in those cases the theorem asserts for every .
9. r_le (theorem)
For all natural numbers and ,
This is asserted for every without exception, including and , and for every , including (where is empty).