/-
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
publicimport FormalConjecturesUtil
/-!
# Erdős Problem 23
*References:*
* [erdosproblems.com/23](https://www.erdosproblems.com/23)
* [OEIS A389646](https://oeis.org/A389646)
* [Balogh-Clemen-Lidicky, Max Cuts in Triangle-free Graphs](https://arxiv.org/abs/2103.14179)
* [McKay, Extremal graphs for bipartization of triangle-free graphs](https://users.cecs.anu.edu.au/~bdm/data/graphs.html)
-/
@[expose] publicsectionopen SimpleGraph BigOperators
namespace Erdos23
open scoped Classical in
/--
Every triangle-free graph on $5$ vertices can be made bipartite by removing at most $1$ edge.
This is the $n = 1$ case of Erdős Problem 23.
-/
@[category test, AMS 5]
theorem erdos_23.variants.n1 :
∀ (G : SimpleGraph (Fin 5)), G.CliqueFree 3 → ∃ (H : SimpleGraph (Fin 5)),
H ≤ G ∧ H.IsBipartite ∧ (G.edgeFinset \ H.edgeFinset).card ≤ 1 := by
sorry
open scoped Classical in
/--
There exists a triangle-free graph on $5$ vertices such that at least $1$ edge must be removed
to make it bipartite. This shows the bound in `erdos_23_n1` is tight.
-/
@[category test, AMS 5]
theorem erdos_23.variants.n1_tight :
∃ (G : SimpleGraph (Fin 5)), G.CliqueFree 3 ∧ ∀ (H : SimpleGraph (Fin 5)),
H ≤ G → H.IsBipartite → 1 ≤ (G.edgeFinset \ H.edgeFinset).card := by-- The `5`-cycle is triangle-free, and a bipartite subgraph missing no edge would be the-- `5`-cycle itself, which has chromatic number `3`.
refine ⟨cycleGraph 5, by unfold CliqueFree; decide +kernel, fun H hHG hH => ?_⟩
by_contra hcon
have h0 := Finset.card_eq_zero.1 (Nat.lt_one_iff.1 (not_le.1 hcon))
have hsub := Finset.sdiff_eq_empty_iff_subset.1 h0
rw [Finset.subset_iff] at hsub
simp only [mem_edgeFinset] at hsub
have hGH : cycleGraph 5 ≤ H := edgeSet_subset_edgeSet.1 fun _ he => hsub he
obtain rfl : H = cycleGraph 5 := le_antisymm hHG hGH
have h2 := hH.chromaticNumber_le
rw [chromaticNumber_cycleGraph_of_odd 5 (by norm_num) (by decide)] at h2
exact absurd h2 (by decide)
open scoped Classical in
/--
Every triangle-free graph on $25$ vertices can be made bipartite by removing at most $25$
edges.
This is the $n = 5$ case of Erdős Problem 23. It follows from the high-density range of
Balogh-Clemen-Lidicky together with McKay's complete catalogue of the 23-vertex extremal
graphs for bipartization of triangle-free graphs.
-/
@[category research solved, AMS 5]
theorem erdos_23.variants.n5 :
∀ (G : SimpleGraph (Fin 25)), G.CliqueFree 3 → ∃ (H : SimpleGraph (Fin 25)),
H ≤ G ∧ H.IsBipartite ∧ (G.edgeFinset \ H.edgeFinset).card ≤ 25 := by
sorry
open scoped Classical in
/--
There exists a triangle-free graph on $25$ vertices such that at least $25$ edges must be
removed to make it bipartite. The balanced blow-up of $C_5$ with five parts of size $5$
witnesses this.
-/
@[category research solved, AMS 5]
theorem erdos_23.variants.n5_tight :
∃ (G : SimpleGraph (Fin 25)), G.CliqueFree 3 ∧ ∀ (H : SimpleGraph (Fin 25)),
H ≤ G → H.IsBipartite → 25 ≤ (G.edgeFinset \ H.edgeFinset).card := by
sorry
/--
The blow-up of the 5-cycle $C_5$: replace each vertex of $C_5$ with an independent set of $n$
vertices, and connect two vertices iff their corresponding vertices in $C_5$ are adjacent.
The vertex set is $\mathbb{Z}/5\mathbb{Z} \times \{0, \ldots, n-1\}$, where $(i, a)$ and $(j, b)$
are adjacent iff $j = i + 1$ or $i = j + 1$ in $\mathbb{Z}/5\mathbb{Z}$.
-/
def blowupC5 (n : ℕ) : SimpleGraph (ZMod 5 × Fin n) :=
SimpleGraph.fromRel fun (i, _) (j, _) => i + 1 = j ∨ j + 1 = i
open scoped Classical in
/--
The blow-up of $C_5$ shows that the bound $n^2$ in Erdős Problem 23 is tight:
any bipartite subgraph must omit at least $n^2$ edges.
-/
@[category test, AMS 5]
theorem blowupC5_tight (n : ℕ) (_hn : 0 < n) (H : SimpleGraph (ZMod 5 × Fin n))
(hH : H ≤ blowupC5 n) (hBip : H.IsBipartite) :
n ^ 2 ≤ ((blowupC5 n).edgeFinset \ H.edgeFinset).card := by
sorry
open scoped Classical in
/--
Can every triangle-free graph on $5n$ vertices be made bipartite by deleting at most $n^2$ edges?
-/
@[category research open, question, AMS 5]
theorem erdos_23 :
∀ (n : ℕ) (V : Type) [Fintype V], Fintype.card V = 5 * n →
∀ (G : SimpleGraph V), G.CliqueFree 3 →
∃ (H : SimpleGraph V),
H ≤ G ∧ H.IsBipartite ∧ (G.edgeFinset \ H.edgeFinset).card ≤ n^2 := by
sorry
-- TODO: add the remaining variants/statements/commentsend Erdos23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152import FormalConjectures.ErdosProblems.«23»
namespace Submission
open SimpleGraph Finset Erdos23
/-- Arithmetic core: five classes of size `n`, class `i` holding `x i` vertices of colour `0`.
The same-coloured pairs between consecutive classes add up to at least `n ^ 2`. -/
theorem cyc_bound (n x0 x1 x2 x3 x4 : ℕ) (g0 : x0 ≤ n) (g1 : x1 ≤ n) (g2 : x2 ≤ n)
(g3 : x3 ≤ n) (g4 : x4 ≤ n) :
n ^ 2 ≤ x0 * x1 + (n - x0) * (n - x1) + (x1 * x2 + (n - x1) * (n - x2))
+ (x2 * x3 + (n - x2) * (n - x3)) + (x3 * x4 + (n - x3) * (n - x4))
+ (x4 * x0 + (n - x4) * (n - x0)) := by
have a0 : (0:ℤ) ≤ x0 := by positivity
have a1 : (0:ℤ) ≤ x1 := by positivity
have a2 : (0:ℤ) ≤ x2 := by positivity
have a3 : (0:ℤ) ≤ x3 := by positivity
have a4 : (0:ℤ) ≤ x4 := by positivity
have b0 : (0:ℤ) ≤ n - x0 := by omega
have b1 : (0:ℤ) ≤ n - x1 := by omega
have b2 : (0:ℤ) ≤ n - x2 := by omega
have b3 : (0:ℤ) ≤ n - x3 := by omega
have b4 : (0:ℤ) ≤ n - x4 := by omega
zify [g0, g1, g2, g3, g4]
nlinarith [mul_nonneg a0 a1, mul_nonneg a1 a2, mul_nonneg a2 a3, mul_nonneg a3 a4,
mul_nonneg a4 a0, mul_nonneg a0 b1, mul_nonneg a1 b0, mul_nonneg a1 b2, mul_nonneg a2 b1,
mul_nonneg a2 b3, mul_nonneg a3 b2, mul_nonneg a3 b4, mul_nonneg a4 b3, mul_nonneg a4 b0,
mul_nonneg a0 b4, mul_nonneg b0 b1, mul_nonneg b1 b2, mul_nonneg b2 b3, mul_nonneg b3 b4,
mul_nonneg b4 b0, mul_nonneg a0 b2, mul_nonneg a2 b0, mul_nonneg a1 b3, mul_nonneg a3 b1,
mul_nonneg a2 b4, mul_nonneg a4 b2, mul_nonneg a3 b0, mul_nonneg a0 b3, mul_nonneg a4 b1,
mul_nonneg a1 b4]
/-- Two colourings `p` (of one class) and `q` (of the next) of `Fin n`, with colours in `Fin 2`:
the same-coloured pairs number `R p * R q + (n - R p) * (n - R q)`, where `R` counts colour `0`. -/
theorem pair_count {n : ℕ} (p q : Fin n → Fin 2) :
(univ.filter (fun ab : Fin n × Fin n => p ab.1 = q ab.2)).card
= (univ.filter (fun a => p a = 0)).card * (univ.filter (fun b => q b = 0)).card
+ (n - (univ.filter (fun a => p a = 0)).card)
* (n - (univ.filter (fun b => q b = 0)).card) := by
have hp := card_filter_add_card_filter_not (s := (univ : Finset (Fin n)))
(fun a => p a = 0)
have hq := card_filter_add_card_filter_not (s := (univ : Finset (Fin n)))
(fun b => q b = 0)
simp only [card_univ, Fintype.card_fin] at hp hq
have hp' : (univ.filter (fun a => ¬ p a = 0)).card
= n - (univ.filter (fun a => p a = 0)).card := by omega
have hq' : (univ.filter (fun b => ¬ q b = 0)).card
= n - (univ.filter (fun b => q b = 0)).card := by omega
have hset : univ.filter (fun ab : Fin n × Fin n => p ab.1 = q ab.2)
= (univ.filter (fun a => p a = 0) ×ˢ univ.filter (fun b => q b = 0))
∪ (univ.filter (fun a => ¬ p a = 0) ×ˢ univ.filter (fun b => ¬ q b = 0)) := by
ext ⟨a, b⟩
simp only [mem_filter, mem_univ, true_and, mem_union, mem_product]
have key : ∀ x y : Fin 2, x = y ↔ (x = 0 ∧ y = 0) ∨ (¬ x = 0 ∧ ¬ y = 0) := by decide
exact key _ _
rw [hset, card_union_of_disjoint, card_product, card_product, hp', hq']
rw [Finset.disjoint_left]
rintro ⟨a, b⟩ h1 h2
simp only [mem_product, mem_filter, mem_univ, true_and] at h1 h2
exact h2.1 h1.1
theorem solution : type_of% @Erdos23.blowupC5_tight := by
intro n _hn H _hH hBip
classical
obtain ⟨c⟩ := hBip
have hne : ∀ i : ZMod 5, i ≠ i + 1 := by decide
have hsym : ∀ i j : ZMod 5, i + 1 = j → j + 1 = i → False := by decide
have hfive : ∀ f : ZMod 5 → ℕ, ∑ i : ZMod 5, f i = f 0 + f 1 + f 2 + f 3 + f 4 :=
fun f => Fin.sum_univ_five f
have hadj : ∀ (i : ZMod 5) (a b : Fin n), (blowupC5 n).Adj (i, a) (i + 1, b) := by
intro i a b
unfold blowupC5
rw [fromRel_adj]
refine ⟨fun h => hne i (congrArg Prod.fst h), ?_⟩
dsimp only
exact Or.inl (by simp)
have hmem : ∀ (i : ZMod 5) (a b : Fin n),
s((i, a), (i + 1, b)) ∈ (blowupC5 n).edgeFinset := fun i a b => by
rw [mem_edgeFinset, mem_edgeSet]
exact hadj i a b
have hnotH : ∀ (i : ZMod 5) (a b : Fin n), c (i, a) = c (i + 1, b) →
s((i, a), (i + 1, b)) ∉ H.edgeFinset := by
intro i a b h hH'
rw [mem_edgeFinset, mem_edgeSet] at hH'
exact c.valid hH' h
have hinj : ∀ i : ZMod 5, Function.Injective
(fun ab : Fin n × Fin n => s((i, ab.1), (i + 1, ab.2))) := by
rintro i ⟨a, b⟩ ⟨a', b'⟩ h
simp only [Sym2.eq_iff, Prod.mk.injEq] at h
rcases h with ⟨⟨_, ha⟩, ⟨_, hb⟩⟩ | ⟨⟨h1, _⟩, _⟩
· rw [ha, hb]
· exact absurd h1 (hne i)
have hdisj : ∀ i j : ZMod 5, ∀ a b a' b' : Fin n,
s((i, a), (i + 1, b)) = s((j, a'), (j + 1, b')) → i = j := by
intro i j a b a' b' h
simp only [Sym2.eq_iff, Prod.mk.injEq] at h
rcases h with ⟨⟨h1, _⟩, _⟩ | ⟨⟨h1, _⟩, ⟨h2, _⟩⟩
· exact h1
· exact (hsym i j h2 h1.symm).elim
-- monochromatic pairs between classes `i` and `i + 1`
let S : ZMod 5 → Finset (Fin n × Fin n) := fun i =>
univ.filter (fun ab => c (i, ab.1) = c (i + 1, ab.2))
have hsub : (univ : Finset (ZMod 5)).biUnion
(fun i => (S i).image (fun ab => s((i, ab.1), (i + 1, ab.2))))
⊆ (blowupC5 n).edgeFinset \ H.edgeFinset := by
intro e he
simp only [mem_biUnion, mem_image, mem_univ, true_and] at he
obtain ⟨i, ab, hab, rfl⟩ := he
rw [mem_sdiff]
exact ⟨hmem i ab.1 ab.2, hnotH i ab.1 ab.2 (mem_filter.1 hab).2⟩
have hcard_eq : ((univ : Finset (ZMod 5)).biUnion
(fun i => (S i).image (fun ab => s((i, ab.1), (i + 1, ab.2))))).card
= ∑ i : ZMod 5, (S i).card := by
rw [card_biUnion]
· exact Finset.sum_congr rfl fun i _ => card_image_of_injective _ (hinj i)
· intro i _ j _ hij
show Disjoint _ _
rw [Finset.disjoint_left]
intro e he he'
simp only [mem_image] at he he'
obtain ⟨ab, _, rfl⟩ := he
obtain ⟨cd, _, hcd⟩ := he'
exact hij (hdisj j i cd.1 cd.2 ab.1 ab.2 hcd).symm
have hpair : ∀ i : ZMod 5, (S i).card
= (univ.filter (fun a => c (i, a) = 0)).card * (univ.filter (fun b => c (i + 1, b) = 0)).card
+ (n - (univ.filter (fun a => c (i, a) = 0)).card)
* (n - (univ.filter (fun b => c (i + 1, b) = 0)).card) :=
fun i => pair_count (fun a => c (i, a)) (fun b => c (i + 1, b))
have e0 : (0 : ZMod 5) + 1 = 1 := by decide
have e1 : (1 : ZMod 5) + 1 = 2 := by decide
have e2 : (2 : ZMod 5) + 1 = 3 := by decide
have e3 : (3 : ZMod 5) + 1 = 4 := by decide
have e4 : (4 : ZMod 5) + 1 = 0 := by decide
have h0 := hpair 0
have h1 := hpair 1
have h2 := hpair 2
have h3 := hpair 3
have h4 := hpair 4
rw [e0] at h0
rw [e1] at h1
rw [e2] at h2
rw [e3] at h3
rw [e4] at h4
have hle : ∀ i : ZMod 5, (univ.filter (fun a => c (i, a) = 0)).card ≤ n := fun i => by
simpa using card_filter_le (univ : Finset (Fin n)) (fun a => c (i, a) = 0)
have hb := cyc_bound n _ _ _ _ _ (hle 0) (hle 1) (hle 2) (hle 3) (hle 4)
have hsum : n ^ 2 ≤ ∑ i : ZMod 5, (S i).card := by
rw [hfive (fun i => (S i).card), h0, h1, h2, h3, h4]
linarith
have hfin := card_le_card hsub
rw [hcard_eq] at hfin
exact le_trans hsum hfin
end Submission
Check it yourself
Project
formal-conjectures
Commit
f606af160664c5a10952e9a957b100a1cd45bbeb
Lean
leanprover/lean4:v4.33.1
Mathlib
0df444a360eaa60ab8c11dca51a86af692955474
With Git and Elan installed, put the download in a fresh working directory and run this there. Use a disposable environment. Lean prints the axioms at the end. The checker allows propext, Classical.choice, and Quot.sound.
(
set -eu
proof="$PWD/b0f36d6f-9ae3-49f8-9185-caee98862fde.lean"
git clone https://github.com/google-deepmind/formal-conjectures.git formal-conjectures
git -C formal-conjectures checkout --detach f606af160664c5a10952e9a957b100a1cd45bbeb
cd formal-conjectures
elan toolchain install leanprover/lean4:v4.33.1
lake +leanprover/lean4:v4.33.1 exe cache get
lake +leanprover/lean4:v4.33.1 build '+FormalConjectures.ErdosProblems.«23»'
check_dir="$(mktemp -d)"
trap 'rm -f "$check_dir/Check.lean"; rmdir "$check_dir"' EXIT
printf "%s\n" "import Lean" > "$check_dir/Check.lean"
cat "$proof" >> "$check_dir/Check.lean"
cat >> "$check_dir/Check.lean" <<'SOLVE_CHECK'
example : type_of% @_root_.Erdos23.blowupC5_tight := @_root_.Submission.solution
#print axioms Submission.solution
SOLVE_CHECK
lake +leanprover/lean4:v4.33.1 env lean "$check_dir/Check.lean"
)
Download the receipt verifier and public key. Run python3 verify-proof.py certificate.json b0f36d6f-9ae3-49f8-9185-caee98862fde.lean proof-key.pem with OpenSSL 3.
Bipartite H forces a 2-colouring; count same-coloured pairs between consecutive classes, giving n^2 by a cyclic 5-term inequality; checked by nlinarith.