Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Progression-free sets and the counting function rk(N)r_k(N)rk​(N)

Definition
Erdos142Basic

by Zexuan Liu · Sep 10, 2026 · Mathlib 0df444a (Lean v4.33.1)

additive-combinatoricsarithmetic-progressionscombinatoricsnumber-theory

This 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 sss, a length l∈N∪{∞}l \in \mathbb{N} \cup \{\infty\}l∈N∪{∞} and elements a,da, da,d, the predicate IsAPOfLengthWith says that sss is the arithmetic progression of length lll with first term aaa and common difference ddd: it has exactly lll elements and

s  =  { a+nd  :  n<l }.s \;=\; \{\, a + n d \;:\; n < l \,\}.s={a+nd:n<l}.

IsAPOfLength existentially quantifies over aaa and ddd.

Progression-freeness. IsAPOfLengthFree declares sss free of progressions of length lll when

∀ t⊆s,t is an arithmetic progression of length l  ⟹  l≤1.\forall\, t \subseteq s,\quad t \text{ is an arithmetic progression of length } l \;\Longrightarrow\; l \le 1 .∀t⊆s,t is an arithmetic progression of length l⟹l≤1.

Progressions of length 000 and 111 count as trivial, so every set is free of them; the condition has content only for l≥2l \ge 2l≥2.

The counting function. For natural numbers kkk and NNN,

rk(N)  =  sup⁡{ ∣S∣  :  S⊆{1,…,N}, S is free of length-k progressions }.r_k(N) \;=\; \sup\bigl\{\, |S| \;:\; S \subseteq \{1,\dots,N\},\ S \text{ is free of length-}k\text{ progressions} \,\bigr\}.rk​(N)=sup{∣S∣:S⊆{1,…,N}, S is free of length-k progressions}.

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 AAA contains a first term aaa and a common difference d>0d > 0d>0 with a+id∈Aa + id \in Aa+id∈A for every i<ki < ki<k, 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 {1,…,N}\{1,\dots,N\}{1,…,N} has at most rk(N)r_k(N)rk​(N) elements, and rk(N)≤Nr_k(N) \le Nrk​(N)≤N.

Formalization Note. The ground set is Finset.Icc 1 N, that is {1,…,N}\{1,\dots,N\}{1,…,N}, matching the problem statement and the source file rather than Finset.range N. The supremum is sSup over N\mathbb{N}N; le_r and r_le are the two facts that make it a genuine maximum. Under the source convention r0(N)=r1(N)=Nr_0(N) = r_1(N) = Nr0​(N)=r1​(N)=N, since every set is free of trivial progressions; statements that need to exclude that carry an explicit hypothesis on kkk.

Definition code
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
Source
Google DeepMind, formal-conjectures, FormalConjectures/ErdosProblems/142.lean and FormalConjecturesForMathlib/Combinatorics/AP/Basic.lean (definitions Set.IsAPOfLengthWith, Set.IsAPOfLength, Set.IsAPOfLengthFree, Set.IsAPOfLengthFree.maxCard), https://github.com/google-deepmind/formal-conjectures/blob/main/FormalConjectures/ErdosProblems/142.lean ; Erdős Problem #142, https://www.erdosproblems.com/142 (cited there as [Er80, p.92], [Er81, p.4], [Er97c], [Va99, 1.27])
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 α\alphaα carrying the structure of an additive commutative monoid (so α\alphaα has an addition that is associative and commutative, and a neutral element 000; there is no subtraction, no order, and no cancellation available). The remaining declarations are stated concretely for the natural numbers N\mathbb{N}N.

Throughout, N∞\mathbb{N}_\inftyN∞​ denotes the extended naturals N∪{∞}\mathbb{N} \cup \{\infty\}N∪{∞} (ℕ∞), with ∞\infty∞ (written ⊤\top⊤) as the largest element, and #s\#s#s denotes the N∞\mathbb{N}_\inftyN∞​-valued cardinality of a set sss (ENat.card), which equals the ordinary number of elements when sss is finite and equals ∞\infty∞ when sss is infinite. For n∈Nn \in \mathbb{N}n∈N and d∈αd \in \alphad∈α, n⋅dn \cdot dn⋅d denotes the monoid multiple d+⋯+dd + \dots + dd+⋯+d (nnn summands), with 0⋅d=00 \cdot d = 00⋅d=0.


1. IsAPOfLengthWith (definition)

For an additive commutative monoid α\alphaα, a set s⊆αs \subseteq \alphas⊆α, an extended natural number l∈N∞l \in \mathbb{N}_\inftyl∈N∞​, and two elements a,d∈αa, d \in \alphaa,d∈α, the proposition IsAPOfLengthWith(s,l,a,d)\mathrm{IsAPOfLengthWith}(s, l, a, d)IsAPOfLengthWith(s,l,a,d) is defined to be the conjunction of two conditions:

#s=lands={ a+n⋅d  :  n∈N, n<l }.\#s = l \qquad\text{and}\qquad s = \{\, a + n\cdot d \;:\; n \in \mathbb{N},\ n < l \,\}.#s=lands={a+n⋅d:n∈N, n<l}.

Here the comparison n<ln < ln<l is taken in N∞\mathbb{N}_\inftyN∞​ after coercing the natural number nnn; the second condition is a set equality (both inclusions), where the right-hand side is the set of all elements expressible as a+n⋅da + n \cdot da+n⋅d for some natural number nnn strictly below lll.

Points that this definition silently includes:

  • Nothing forbids d=0d = 0d=0. If d=0d = 0d=0 then the right-hand set is {a}\{a\}{a} when l≥1l \ge 1l≥1 and ∅\emptyset∅ when l=0l = 0l=0; the first conjunct #s=l\#s = l#s=l then forces l=1l = 1l=1 (resp. l=0l = 0l=0), so the two conjuncts together can only be met at l≤1l \le 1l≤1 in that case.
  • l=0l = 0l=0: the right-hand set is empty (no natural number is <0< 0<0) and #s=0\#s = 0#s=0, so the definition holds exactly when s=∅s = \emptysets=∅, and it then holds for every choice of aaa and ddd.
  • l=1l = 1l=1: the right-hand set is {a+0⋅d}={a}\{a + 0\cdot d\} = \{a\}{a+0⋅d}={a} and #s=1\#s = 1#s=1, so the definition holds exactly when s={a}s = \{a\}s={a}, again for every choice of ddd.
  • l=∞l = \inftyl=∞: every natural number satisfies n<∞n < \inftyn<∞, so the right-hand set is the full forward orbit {a+n⋅d:n∈N}\{a + n\cdot d : n \in \mathbb{N}\}{a+n⋅d:n∈N}, and #s=∞\#s = \infty#s=∞ requires sss to be infinite.
  • There is no injectivity hypothesis on n↦a+n⋅dn \mapsto a + n\cdot dn↦a+n⋅d; the only thing that constrains repetitions is the cardinality equation #s=l\#s = l#s=l, which requires the displayed set to have exactly lll elements. In particular the condition is an exact cardinality, not an inequality.
  • aaa itself is always a member of sss whenever l≥1l \ge 1l≥1 (take n=0n = 0n=0).

2. IsAPOfLength (definition)

For an additive commutative monoid α\alphaα, a set s⊆αs \subseteq \alphas⊆α and l∈N∞l \in \mathbb{N}_\inftyl∈N∞​, the proposition IsAPOfLength(s,l)\mathrm{IsAPOfLength}(s, l)IsAPOfLength(s,l) says that there exist a∈αa \in \alphaa∈α and d∈αd \in \alphad∈α such that IsAPOfLengthWith(s,l,a,d)\mathrm{IsAPOfLengthWith}(s, l, a, d)IsAPOfLengthWith(s,l,a,d) holds, i.e. such that

#s=lands={ a+n⋅d:n∈N, n<l }.\#s = l \qquad\text{and}\qquad s = \{\, a + n\cdot d : n \in \mathbb{N},\ n < l \,\}.#s=lands={a+n⋅d:n∈N, n<l}.

Both aaa and ddd are existentially quantified over all of α\alphaα; in particular d=0d = 0d=0 is an allowed witness. By the previous item, IsAPOfLength(s,0)\mathrm{IsAPOfLength}(s, 0)IsAPOfLength(s,0) holds precisely when s=∅s = \emptysets=∅, and IsAPOfLength(s,1)\mathrm{IsAPOfLength}(s, 1)IsAPOfLength(s,1) holds precisely when sss is a singleton (both because α\alphaα, being a monoid, is nonempty and supplies witnesses a,da, da,d).

3. IsAPOfLengthFree (definition)

For an additive commutative monoid α\alphaα, a set s⊆αs \subseteq \alphas⊆α and l∈N∞l \in \mathbb{N}_\inftyl∈N∞​, the proposition IsAPOfLengthFree(s,l)\mathrm{IsAPOfLengthFree}(s, l)IsAPOfLengthFree(s,l) is defined as:

∀ t⊆s,IsAPOfLength(t,l)  ⟶  l≤1.\forall\, t \subseteq s,\quad \mathrm{IsAPOfLength}(t, l) \;\longrightarrow\; l \le 1 .∀t⊆s,IsAPOfLength(t,l)⟶l≤1.

The quantifier ranges over all subsets ttt of sss (including t=∅t = \emptysett=∅ and t=st = st=s). Note that the conclusion of the implication is l≤1l \le 1l≤1, a statement about lll alone that does not mention ttt or sss. Consequently the definition is logically equivalent to

l≤1or(no subset t⊆s satisfies IsAPOfLength(t,l)).l \le 1 \quad\text{or}\quad \bigl(\text{no subset } t \subseteq s \text{ satisfies } \mathrm{IsAPOfLength}(t,l)\bigr).l≤1or(no subset t⊆s satisfies IsAPOfLength(t,l)).

Degenerate readings this entails:

  • For l=0l = 0l=0 and for l=1l = 1l=1 the conclusion l≤1l \le 1l≤1 is true outright, so IsAPOfLengthFree(s,l)\mathrm{IsAPOfLengthFree}(s, l)IsAPOfLengthFree(s,l) holds vacuously for every set sss whatsoever, including s=αs = \alphas=α.
  • For l≥2l \ge 2l≥2 (including l=∞l = \inftyl=∞) the definition says: no subset t⊆st \subseteq st⊆s satisfies #t=l\#t = l#t=l together with t={a+n⋅d:n<l}t = \{a + n\cdot d : n < l\}t={a+n⋅d:n<l} for some a,d∈αa, d \in \alphaa,d∈α. Because #t=l≥2\#t = l \ge 2#t=l≥2 cannot hold when d=0d = 0d=0 (that set is a singleton), the excluded configurations are automatically ones with d≠0d \ne 0d=0; but this is a consequence of the cardinality equation, not a separately stated hypothesis.
  • The excluded ttt must be exactly equal to the progression set {a+n⋅d:n<l}\{a + n\cdot d : n < l\}{a+n⋅d:n<l}, not merely contain it.

4. r (noncomputable definition)

For natural numbers kkk and NNN, the natural number r(k,N)r(k, N)r(k,N) is defined as the supremum, taken in N\mathbb{N}N, of the set of cardinalities

{ ∣S∣  :  S a finite set of naturals, S⊆{1,2,…,N}, IsAPOfLengthFree(S,k) }⊆N,\bigl\{\, |S| \;:\; S \text{ a finite set of naturals},\ S \subseteq \{1, 2, \dots, N\},\ \mathrm{IsAPOfLengthFree}(S, k) \,\bigr\} \subseteq \mathbb{N},{∣S∣:S a finite set of naturals, S⊆{1,2,…,N}, IsAPOfLengthFree(S,k)}⊆N,

where SSS ranges over finite subsets of N\mathbb{N}N, the containment is in the integer interval {m∈N:1≤m≤N}\{m \in \mathbb{N} : 1 \le m \le N\}{m∈N:1≤m≤N} (which is empty when N=0N = 0N=0), ∣S∣|S|∣S∣ is the number of elements of SSS, and the freeness condition is IsAPOfLengthFree\mathrm{IsAPOfLengthFree}IsAPOfLengthFree of item 3 applied to SSS viewed as a set of naturals, at the length kkk coerced into N∞\mathbb{N}_\inftyN∞​ (so the length is always a genuine natural number here, never ∞\infty∞).

Conventions that this definition carries:

  • The supremum is the N\mathbb{N}N-valued supremum. On N\mathbb{N}N this operation returns the junk value 000 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 k=0k = 0k=0 or k=1k = 1k=1 the freeness condition is satisfied by every SSS, so the set being maximised is the set of all cardinalities of subsets of {1,…,N}\{1,\dots,N\}{1,…,N}.
  • The empty set S=∅S = \emptysetS=∅ always satisfies both side conditions (see item 7), so 000 always belongs to the set; and every SSS in the set has ∣S∣≤N|S| \le N∣S∣≤N. Hence in this particular definition the supremum is an honest maximum and no junk value is triggered.
  • No lower bound k≥3k \ge 3k≥3, and no restriction such as d≠0d \ne 0d=0, appears anywhere in the definition.

5. HasAP (definition)

For a natural number kkk and a finite set of natural numbers AAA, the proposition HasAP(k,A)\mathrm{HasAP}(k, A)HasAP(k,A) says:

∃ a∈N, ∃ d∈N,d>0  and  ∀i∈N with i<k,  a+i d∈A.\exists\, a \in \mathbb{N},\ \exists\, d \in \mathbb{N},\quad d > 0 \ \text{ and } \ \forall i \in \mathbb{N} \text{ with } i < k,\ \ a + i\,d \in A .∃a∈N, ∃d∈N,d>0  and  ∀i∈N with i<k,  a+id∈A.

Here aaa is allowed to be 000, ddd is required to be strictly positive, and i di\,did is ordinary multiplication of naturals. Edge cases:

  • For k=0k = 0k=0 the inner universal statement is vacuous, so HasAP(0,A)\mathrm{HasAP}(0, A)HasAP(0,A) holds for every AAA, including A=∅A = \emptysetA=∅ (witnesses a=0a = 0a=0, d=1d = 1d=1).
  • For k=1k = 1k=1 the statement reduces to ∃a, a∈A\exists a,\ a \in A∃a, a∈A, i.e. HasAP(1,A)\mathrm{HasAP}(1, A)HasAP(1,A) holds exactly when A≠∅A \ne \emptysetA=∅.
  • Since d>0d > 0d>0, the kkk listed terms a,a+d,…,a+(k−1)da, a+d, \dots, a+(k-1)da,a+d,…,a+(k−1)d are pairwise distinct naturals.

6. APFree (definition)

For a natural number kkk and a finite set of natural numbers AAA, APFree(k,A)\mathrm{APFree}(k, A)APFree(k,A) is defined to be the negation ¬ HasAP(k,A)\neg\,\mathrm{HasAP}(k, A)¬HasAP(k,A), i.e. there are no a∈Na \in \mathbb{N}a∈N and d∈Nd \in \mathbb{N}d∈N with d>0d > 0d>0 such that a+i d∈Aa + i\,d \in Aa+id∈A for all i<ki < ki<k. By the previous item, APFree(0,A)\mathrm{APFree}(0, A)APFree(0,A) is false for every AAA, and APFree(1,A)\mathrm{APFree}(1, A)APFree(1,A) holds exactly when A=∅A = \emptysetA=∅.

These two elementary predicates HasAP\mathrm{HasAP}HasAP and APFree\mathrm{APFree}APFree are not referred to by any other declaration in this file; in particular no declaration here relates them to IsAPOfLengthFree\mathrm{IsAPOfLengthFree}IsAPOfLengthFree or to rrr.

7. isAPOfLengthFree_empty (theorem)

For every additive commutative monoid α\alphaα (implicit type argument, with its AddCommMonoid instance) and every natural number kkk, the empty subset of α\alphaα satisfies

IsAPOfLengthFree(∅, k),\mathrm{IsAPOfLengthFree}(\emptyset,\ k),IsAPOfLengthFree(∅, k),

where kkk is coerced into N∞\mathbb{N}_\inftyN∞​. Unfolded, the assertion is: for every set t⊆∅t \subseteq \emptysett⊆∅, if there exist a,d∈αa, d \in \alphaa,d∈α with #t=k\#t = k#t=k and t={a+n⋅d:n<k}t = \{a + n\cdot d : n < k\}t={a+n⋅d:n<k}, then k≤1k \le 1k≤1. The only such ttt is ∅\emptyset∅, whose cardinality is 000, so the hypothesis forces k=0k = 0k=0 and hence k≤1k \le 1k≤1. The statement is asserted only for lengths that are natural numbers; the case k=∞k = \inftyk=∞ is not covered by this declaration.

8. le_r (theorem)

Let SSS be a finite set of natural numbers and let kkk and NNN be natural numbers (all three are implicit arguments). Assume:

  1. S⊆{1,2,…,N}S \subseteq \{1, 2, \dots, N\}S⊆{1,2,…,N}; and
  2. IsAPOfLengthFree(S,k)\mathrm{IsAPOfLengthFree}(S, k)IsAPOfLengthFree(S,k) — that is, for every set t⊆St \subseteq St⊆S, if ttt is an arithmetic progression of length exactly kkk in the sense of item 2, then k≤1k \le 1k≤1.

Then

∣S∣  ≤  r(k,N),|S| \;\le\; r(k, N),∣S∣≤r(k,N),

with rrr as defined in item 4 (the N\mathbb{N}N-valued supremum of the cardinalities of all progression-free subsets of {1,…,N}\{1,\dots,N\}{1,…,N}). Note that for k=0k = 0k=0 and k=1k = 1k=1 hypothesis 2 is automatically satisfied by every SSS, so in those cases the theorem asserts ∣S∣≤r(k,N)|S| \le r(k,N)∣S∣≤r(k,N) for every S⊆{1,…,N}S \subseteq \{1,\dots,N\}S⊆{1,…,N}.

9. r_le (theorem)

For all natural numbers kkk and NNN,

r(k,N)  ≤  N.r(k, N) \;\le\; N .r(k,N)≤N.

This is asserted for every kkk without exception, including k=0k = 0k=0 and k=1k = 1k=1, and for every NNN, including N=0N = 0N=0 (where {1,…,N}\{1,\dots,N\}{1,…,N} is empty).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactJoin Slack© 2026 Prove2Me