Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 5.21 — a graph is 2-colorable iff it contains no odd cycle

Proved
AppliedComb.Graphs.two_colorable_iff

by mikedeng1 · Sep 28, 2026 · Mathlib 0df444a (Lean v4.33.1)

coloringcombinatoricsgraph-theoryp2o-batch-books5p2o-gran-per-chapterp2o-plan-bookp2o-v1

Let GGG be a finite graph and χ(G)\chi(G)χ(G) its chromatic number, the least ttt for which GGG has a proper coloring with ttt colors. Then

χ(G)≤2  ⟺  G contains no odd cycle,\chi(G) \le 2 \iff G \text{ contains no odd cycle},χ(G)≤2⟺G contains no odd cycle,

where an odd cycle is a sequence (x1,…,xn)(x_1, \dots, x_n)(x1​,…,xn​) of n≥3n \ge 3n≥3 distinct vertices, nnn odd, with xixi+1x_i x_{i+1}xi​xi+1​ an edge for i<ni < ni<n and x1xnx_1 x_nx1​xn​ an edge.

This characterizes bipartite graphs and makes 2-colorability easy to recognize.

Formalization Note. χ(G)\chi(G)χ(G) is Mathlib's SimpleGraph.chromaticNumber (valued in N∞\mathbb N_\inftyN∞​), which on a finite graph is the book's least number of colors. The obstruction is an odd cycle in the book's sense (distinct vertices), not an odd closed walk.

Preamble
import Mathlib
import Definitions.Def_AppliedComb_Graphs_IsCycle
Formal statement
namespace AppliedComb.Graphs

/-- Keller–Trotter, p. 82, Theorem 5.21. A (finite) graph is 2-colorable, i.e. `χ(G) ≤ 2`, if
and only if it does not contain an odd cycle (a cycle of `n ≥ 3` distinct vertices with `n`
odd, p. 71). -/
theorem two_colorable_iff {V : Type*} [Fintype V] (G : SimpleGraph V) :
    G.chromaticNumber ≤ 2 ↔ ¬ ContainsOddCycle G := by sorry

end AppliedComb.Graphs
Source
Keller & Trotter, Applied Combinatorics (2017 Edition), p. 82, Theorem 5.21 (2-colorable: p. 82; cycle: p. 71)
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Setting. Let VVV be a finite type of vertices, and let GGG be a simple graph on VVV.

Conclusion. The theorem states:

χ(G)≤2  ⟺  G contains no odd cycle.\chi(G) \le 2 \iff G \text{ contains no odd cycle}.χ(G)≤2⟺G contains no odd cycle.

The two sides mean the following.

  • χ(G)\chi(G)χ(G) is Mathlib's chromatic number. It is valued in N∪{∞}\mathbb{N} \cup \{\infty\}N∪{∞} and equals the least kkk such that GGG has a proper colouring with kkk colours. It would be ∞\infty∞ if no such kkk existed, but that cannot happen for finite VVV.
  • Contains an odd cycle: there is a list (x1,…,xn)(x_1, \dots, x_n)(x1​,…,xn​) of pairwise distinct vertices satisfying all of these:
    • n≥3n \ge 3n≥3;
    • nnn is odd;
    • xi∼Gxi+1x_i \sim_G x_{i+1}xi​∼G​xi+1​ for 1≤i<n1 \le i < n1≤i<n;
    • x1∼Gxnx_1 \sim_G x_nx1​∼G​xn​.

Degenerate cases.

  • VVV empty: χ(G)=0≤2\chi(G) = 0 \le 2χ(G)=0≤2 and there are no cycles, so both sides are true.
  • Edgeless graph: χ(G)≤1\chi(G) \le 1χ(G)≤1 and there are no cycles, so both sides are true.
  • Fewer than 3 vertices: there are no cycles, and χ(G)≤2\chi(G) \le 2χ(G)≤2 holds.
Human review
  • Endorsed by Shuze Chen · Oct 2, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 2, 2026

    Confirmed by the mission captain (proposal self-audit).

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, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me