/- Copyright 2026 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ module public import FormalConjecturesForMathlib.Combinatorics.Ramsey public import Mathlib.Data.Nat.Choose.Central

Erdős–Szekeres 1935 upper bound for the diagonal Ramsey number

Statement (Erdős–Szekeres 1935): For every k : ℕ, the diagonal Ramsey number satisfies Combinatorics.hypergraphRamsey 2 k ≤ 4 ^ k.

Proof sketch. Use the symmetric recursion R(s, t) ≤ R(s-1, t) + R(s, t-1) with base cases R(0, t) = R(s, 0) = 1. Induction on s + t then gives R(s, t) ≤ C(s+t, s); for s = t = k this is R(k, k) ≤ C(2k, k) ≤ 4 ^ k (the Catalan-like central binomial coefficient bound).

The whole argument is phrased directly on the Mathlib-style coloring data c : Finset (Fin m) → Bool of 2-element subsets — no auxiliary "edge colouring" structure is introduced.

Reference: [ES35] Erdős, P. and Szekeres, G. (1935). "A combinatorial problem in geometry." Compositio Math. 2, pp. 463–470.

@[expose] public sectionnamespace Combinatoricsnamespace Diagonal

Off-diagonal Ramsey via a subset-indexed predicate

Rather than introduce an auxiliary edge-colouring structure, we phrase the off-diagonal Ramsey statement as a property of an arbitrary Finset (Fin m) of sufficient cardinality inside a Bool-valued coloring of all subsets of Fin m. We only ever query the coloring on 2-element subsets. This setup matches the shape of Combinatorics.hypergraphRamsey 2 directly.

HasRamseyProperty N s t asserts: for every m, every coloring c : Finset (Fin m) → Bool, and every V : Finset (Fin m) with V.card ≥ N, the subset V contains either a subset of size s whose 2-element subsets are all false-coloured, or a subset of size t whose 2-element subsets are all true-coloured.

This is the "off-diagonal Ramsey number does not exceed N" form of the classical Erdős–Szekeres Ramsey recurrence, packaged in the same shape used by Combinatorics.hypergraphRamsey.

def HasRamseyProperty (N s t : ) : Prop := {m : } (c : Finset (Fin m) Bool) (V : Finset (Fin m)), N V.card ( S V, S.card = s e S, e.card = 2 c e = false) ( S V, S.card = t e S, e.card = 2 c e = true)

Monotonicity. If N ≤ N' then HasRamseyProperty N s t → HasRamseyProperty N' s t.

lemma HasRamseyProperty.mono {N N' s t : } (hNN' : N N') (h : HasRamseyProperty N s t) : HasRamseyProperty N' s t := N:N':s:t:hNN':N N'h:HasRamseyProperty N s tHasRamseyProperty N' s t N:N':s:t:hNN':N N'h:HasRamseyProperty N s tm:c:Finset (Fin m) BoolV:Finset (Fin m)hV:N' V.card(∃ S V, S.card = s e S, e.card = 2 c e = false) S V, S.card = t e S, e.card = 2 c e = true All goals completed! 🐙

Base case s = 0. Any V contains an empty false-monochromatic set.

lemma hasRamseyProperty_zero_left (N t : ) : HasRamseyProperty N 0 t := N:t:HasRamseyProperty N 0 t N:t:m:c:Finset (Fin m) BoolV:Finset (Fin m)_hV:N V.card(∃ S V, S.card = 0 e S, e.card = 2 c e = false) S V, S.card = t e S, e.card = 2 c e = true refine Or.inl , Finset.empty_subset _, N:t:m:c:Finset (Fin m) BoolV:Finset (Fin m)_hV:N V.card.card = 0 All goals completed! 🐙, ?_ N:t:m:c:Finset (Fin m) BoolV:Finset (Fin m)_hV:N V.carde:Finset (Fin m)he:e a✝:e.card = 2c e = false -- e ⊆ ∅, so e = ∅, but e.card = 2. N:t:m:c:Finset (Fin m) BoolV:Finset (Fin m)_hV:N V.carde:Finset (Fin m)he:e a✝:e.card = 2he_empty:e = c e = false All goals completed! 🐙

Base case t = 0. Any V contains an empty true-monochromatic set.

lemma hasRamseyProperty_zero_right (N s : ) : HasRamseyProperty N s 0 := N:s:HasRamseyProperty N s 0 N:s:m:c:Finset (Fin m) BoolV:Finset (Fin m)_hV:N V.card(∃ S V, S.card = s e S, e.card = 2 c e = false) S V, S.card = 0 e S, e.card = 2 c e = true refine Or.inr , Finset.empty_subset _, N:s:m:c:Finset (Fin m) BoolV:Finset (Fin m)_hV:N V.card.card = 0 All goals completed! 🐙, ?_ N:s:m:c:Finset (Fin m) BoolV:Finset (Fin m)_hV:N V.carde:Finset (Fin m)he:e a✝:e.card = 2c e = true N:s:m:c:Finset (Fin m) BoolV:Finset (Fin m)_hV:N V.carde:Finset (Fin m)he:e a✝:e.card = 2he_empty:e = c e = true All goals completed! 🐙

A singleton has no 2-element subsets, hence is monochromatic of any colour.

m:v:Fin mb:Boolc:Finset (Fin m) Boole:Finset (Fin m)he:e {v}hecard:e.card = 2this:e.card 1c e = b All goals completed! 🐙

Base case s = 1. Any nonempty V contains a singleton false-monochromatic set.

t:m:c:Finset (Fin m) BoolV:Finset (Fin m)hV:1 V.cardv:Fin mhv:v V(∃ S V, S.card = 1 e S, e.card = 2 c e = false) S V, S.card = t e S, e.card = 2 c e = true refine Or.inl {v}, t:m:c:Finset (Fin m) BoolV:Finset (Fin m)hV:1 V.cardv:Fin mhv:v V{v} V All goals completed! 🐙, t:m:c:Finset (Fin m) BoolV:Finset (Fin m)hV:1 V.cardv:Fin mhv:v V{v}.card = 1 All goals completed! 🐙, ?_ All goals completed! 🐙

Base case t = 1. Any nonempty V contains a singleton true-monochromatic set.

s:m:c:Finset (Fin m) BoolV:Finset (Fin m)hV:1 V.cardv:Fin mhv:v V(∃ S V, S.card = s e S, e.card = 2 c e = false) S V, S.card = 1 e S, e.card = 2 c e = true refine Or.inr {v}, s:m:c:Finset (Fin m) BoolV:Finset (Fin m)hV:1 V.cardv:Fin mhv:v V{v} V All goals completed! 🐙, s:m:c:Finset (Fin m) BoolV:Finset (Fin m)hV:1 V.cardv:Fin mhv:v V{v}.card = 1 All goals completed! 🐙, ?_ All goals completed! 🐙

Pigeonhole step: splitting V \ {v} by colour. For any vertex v ∈ V, the set V.erase v partitions into false-neighbours of v and true-neighbours of v, and the cardinalities sum to V.card - 1.

All goals completed! 🐙

Extending a b-monochromatic clique S by a vertex v that is b-adjacent to every element of S. Parameterised over the colour b : Bool, this covers both the false and true extension steps used in HasRamseyProperty.step.

m:c:Finset (Fin m) Boolb:BoolS:Finset (Fin m)hSmono: e S, e.card = 2 c e = bv:Fin mhvAdj: u S, c {v, u} = bx:Fin my:Fin mhxy:x yhe:{x, y} insert v Shecard:{x, y}.card = 2hx:x insert v Shy:y insert v ShxS:x ShyS:y Shsub:{x, y} Shcard2:{x, y}.card = 2c {x, y} = b All goals completed! 🐙

Recurrence. If HasRamseyProperty Ns s (t+1) and HasRamseyProperty Nt (s+1) t hold, then HasRamseyProperty (Ns + Nt) (s+1) (t+1) holds.

This is the core Erdős–Szekeres 1935 pigeonhole step: pick any vertex v ∈ V, split V.erase v into false-neighbours R_v and true-neighbours B_v; by pigeonhole |R_v| ≥ Ns or |B_v| ≥ Nt. In the first case, invoke HasRamseyProperty Ns s (t+1) on R_v: either we get a false-mono K_s on R_v (extend by v to a false-mono K_{s+1} on V), or a true-mono K_{t+1} on R_v ⊆ V (done). The second case is symmetric.

All goals completed! 🐙 Ns:Nt:s:t:hs:HasRamseyProperty Ns s (t + 1)ht:HasRamseyProperty Nt (s + 1) thNs:1 Nsm:c:Finset (Fin m) BoolV:Finset (Fin m)hV:Ns + Nt V.cardhVpos:0 < V.cardv:Fin mhv:v VR:Finset (Fin m) := {u V.erase v | c {v, u} = false}hR_def:R = {u V.erase v | c {v, u} = false}B:Finset (Fin m) := {u V.erase v | c {v, u} = true}hB_def:B = {u V.erase v | c {v, u} = true}hsplit:R.card + B.card = V.card - 1hRsubV:R VhBsubV:B VhvnR:v RhvnB:v BhRcard:R.card < NsS:Finset (Fin m)hSsub:S BhScard:S.card = thSmono: e S, e.card = 2 c e = truehvS:v S e insert v S, e.card = 2 c e = true Ns:Nt:s:t:hs:HasRamseyProperty Ns s (t + 1)ht:HasRamseyProperty Nt (s + 1) thNs:1 Nsm:c:Finset (Fin m) BoolV:Finset (Fin m)hV:Ns + Nt V.cardhVpos:0 < V.cardv:Fin mhv:v VR:Finset (Fin m) := {u V.erase v | c {v, u} = false}hR_def:R = {u V.erase v | c {v, u} = false}B:Finset (Fin m) := {u V.erase v | c {v, u} = true}hB_def:B = {u V.erase v | c {v, u} = true}hsplit:R.card + B.card = V.card - 1hRsubV:R VhBsubV:B VhvnR:v RhvnB:v BhRcard:R.card < NsS:Finset (Fin m)hSsub:S BhScard:S.card = thSmono: e S, e.card = 2 c e = truehvS:v S u S, c {v, u} = true Ns:Nt:s:t:hs:HasRamseyProperty Ns s (t + 1)ht:HasRamseyProperty Nt (s + 1) thNs:1 Nsm:c:Finset (Fin m) BoolV:Finset (Fin m)hV:Ns + Nt V.cardhVpos:0 < V.cardv:Fin mhv:v VR:Finset (Fin m) := {u V.erase v | c {v, u} = false}hR_def:R = {u V.erase v | c {v, u} = false}B:Finset (Fin m) := {u V.erase v | c {v, u} = true}hB_def:B = {u V.erase v | c {v, u} = true}hsplit:R.card + B.card = V.card - 1hRsubV:R VhBsubV:B VhvnR:v RhvnB:v BhRcard:R.card < NsS:Finset (Fin m)hSsub:S BhScard:S.card = thSmono: e S, e.card = 2 c e = truehvS:v Su:Fin mhu:u Sc {v, u} = true Ns:Nt:s:t:hs:HasRamseyProperty Ns s (t + 1)ht:HasRamseyProperty Nt (s + 1) thNs:1 Nsm:c:Finset (Fin m) BoolV:Finset (Fin m)hV:Ns + Nt V.cardhVpos:0 < V.cardv:Fin mhv:v VR:Finset (Fin m) := {u V.erase v | c {v, u} = false}hR_def:R = {u V.erase v | c {v, u} = false}B:Finset (Fin m) := {u V.erase v | c {v, u} = true}hB_def:B = {u V.erase v | c {v, u} = true}hsplit:R.card + B.card = V.card - 1hRsubV:R VhBsubV:B VhvnR:v RhvnB:v BhRcard:R.card < NsS:Finset (Fin m)hSsub:S BhScard:S.card = thSmono: e S, e.card = 2 c e = truehvS:v Su:Fin mhu:u Shu':u Bc {v, u} = true All goals completed! 🐙

Binomial bound via Erdős–Szekeres induction. HasRamseyProperty (Nat.choose (s + t) s) s t for all s, t.

n:ih: m < n, (s t : ), s + t = m HasRamseyProperty (m.choose s) s ts✝:t✝:hst✝:s + t = ns:t:hst:s + 1 + (t + 1) = nhn_pred:n - 1 + 1 = nhs_ih:HasRamseyProperty ((n - 1).choose s) s (t + 1)ht_ih:HasRamseyProperty ((n - 1).choose (s + 1)) (s + 1) thNs_pos:1 (n - 1).choose shrec:HasRamseyProperty ((n - 1).choose s + (n - 1).choose (s + 1)) (s + 1) (t + 1)hpascal:n.choose (s + 1) = (n - 1).choose s + (n - 1).choose (s + 1)HasRamseyProperty ((n - 1).choose s + (n - 1).choose (s + 1)) (s + 1) (t + 1) All goals completed! 🐙end Diagonal

Erdős–Szekeres 1935 in hypergraphRamsey form: Combinatorics.hypergraphRamsey 2 k ≤ 4 ^ k for all k.

Proof. Diagonal.hasRamseyProperty_choose applied at s = t = k and the full vertex set V = Finset.univ of Fin (C(2k, k)) shows that C(2k, k) is a member of the defining set of hypergraphRamsey 2 k, hence by Nat.sInf_le we get hypergraphRamsey 2 k ≤ C(2k, k); the central binomial bound C(2k, k) ≤ 4 ^ k closes the result.

k:hprop:Diagonal.HasRamseyProperty ((k + k).choose k) k khmem:(k + k).choose k {m | (c : Finset (Fin m) Bool), S, S.card = k color, e S, e.card = 2 c e = color}hle:hypergraphRamsey 2 k (2 * k).choose kh2kk:(k + k).choose k = (2 * k).choose khypergraphRamsey 2 k 4 ^ k All goals completed! 🐙end Combinatorics