TCSLib

145 Euler Hamilton

145.1 Euler Hamilton

Definition 145.1 \(G\) is eulerian: it has a closed Euler trail (an Euler tour)
#

\(\exists \) u, \(\exists \) p : G.Walk u u, p.IsEulerian — a closed walk using every edge exactly once. Mathlib’s Walk.IsEulerian is defined via List.count on p.edges, which is why [DecidableEq V] is genuinely required here and not merely convenient.

Note the book’s three-way vocabulary collapses in Lean: IsEulerian already implies IsTrail, so "closed Euler trail" and "Euler tour" are the same predicate on a Walk u u.

Definition 145.2 Component count \(\omega (G)\)
#

Nat.card G.ConnectedComponent, following Mathlib’s own idiom in Tutte.lean. Deliberately not named omega, which is a tactic.

Theorem 4.2 only, as the left-hand side of the toughness condition \(\omega (G - S) \le |S|\): a hamiltonian graph cannot fall into many pieces when few vertices are deleted.

Definition 145.3 join
#

\(G \lor H\), rebuilt on Mathlib: within-side edges from \(\oplus g\), all cross edges from completeBipartiteGraph. symm/loopless are inherited from \(\sqcup \).

Lay the two graphs side by side keeping all their own edges, then add every edge running between them. The book’s \(G + H\) (disjoint union) is Mathlib’s \(\oplus g\), and "joining each vertex of \(G\) to each vertex of \(H\)" is exactly completeBipartiteGraph V W, so

join G H = (G \(\oplus \)g H) \(\sqcup \) completeBipartiteGraph V W

on carrier \(V \oplus W\). Building it as a \(\sqcup \) of two existing graphs means symm and loopless are inherited and need no proof.

The building block of the graphs Cmn below.

Definition 145.4 \(C_{m,n} = K_m \lor (K_m^c + K_{n-2m})\), with \(+\) the Mathlib disjoint sum \(\oplus g\)
#

Take \(m\) "hub" vertices forming a complete graph, \(m\) isolated vertices, and a complete graph on the remaining \(n - 2m\); then join every hub to everything else. Carrier Fin m \(\oplus \) (Fin m \(\oplus \) Fin (n - 2 * m)), with \(K_m^{c} = \bot \) on Fin m.

Degrees: the \(m\) hubs have degree \(n - 1\), the \(m\) isolated vertices have degree \(m\), and the remaining \(n - 2m\) have degree \(n - m - 1\). That is the degree sequence Theorem 4.6 majorises against.

! The side condition \(1 \le m \lt n/2\) is not carried in the type. For \(m = 0\) or \(2m \gt n\) the definition still elaborates (with \(n - 2 * m\) truncating to \(0\)) but no longer matches the book’s figure. Callers must supply the bound.

Definition 145.5 The sorted (ascending) degree sequence of \(G\)
#

Simply list how many neighbours each vertex has, smallest first.

Degree is written Nat.card (G.neighborSet v) rather than G.degree v, so the definition works for any graph on a Fintype without threading a DecidableRel G.Adj instance; the two agree when \(V\) is finite.

The book indexes from \(1\) (\(d_{1} \le \dots \le d_\nu \)); the Lean list is \(0\)-indexed, so the book’s \(d_m\) is degreeSequence.getD (m - 1) 0. Statements below that quote Theorem 4.5 must account for that shift.

Chvátal’s Theorem 4.5 reads hamiltonicity off this list alone; Theorem 4.6 and Corollary 4.6 compare two such lists via DegreeMajorised.

Definition 145.6 \(G\) is degree-majorised by \(H\): same order, and every sorted-degree entry of \(G\) is \(\le \) the…
#

Line up both degree sequences in increasing order and compare entry by entry; \(G\) is degree-majorised by \(H\) when \(H\) wins or ties at every position.

Quantifying over all \(i : \mathbb {N}\) with getD i 0 rather than over Fin \(\nu \) is deliberate: past the end of both lists the comparison is \(0 \le 0\), so the extra indices are harmless and no bounds proof has to be threaded through.

Definition 145.7 One Bondy–Chvátal closure step: add a nonadjacent pair whose degree sum is \(\ge \) \(\nu \)
#

Look for two vertices not yet joined but which between them already have at least \(\nu \) neighbours; Lemma 4.4.1 says adding the edge changes nothing about hamiltonicity, so add it. Repeat until no such pair is left.

ClosureStep G H captures a single such addition, H = G \(\sqcup \) edge u v. The closure is then reached by Relation.ReflTransGen ClosureStep, and "no such pair remains" is expressed at the use site as \(H = \top \) or as the absence of a further step, rather than by a fixpoint operator.

Defining \(c(G)\) as a function presupposes Lemma 4.4.2 — that the result is independent of the order in which edges are added — and that lemma is itself one of the chapter’s results. Positing the fixpoint would therefore assume what the chapter sets out to prove. Using the step relation keeps the development honest; the price is that statements below quantify over ReflTransGen ClosureStep chains instead of mentioning \(c(G)\) directly.

Degree is Nat.card (G.neighborSet \(\cdot \)) so the relation is well-typed for arbitrary graphs on \(V\) without a DecidableRel instance.

Definition 145.8 \(G\) is Hamilton-connected: every ordered pair is joined by a Hamilton path (Ex 4.2.11)
#

Not merely that some spanning path exists, but that both endpoints may be prescribed arbitrarily: \(\forall \) u v, u \(\ne \) v \(\to \) \(\exists \) p : G.Walk u v, p.IsHamiltonian.

Substantially stronger than being hamiltonian, and correspondingly forces many edges — part (a) is hamiltonConnected_edge_bound below, part (b) is exists_extremal_hamiltonConnected.

The book’s \([x]\) here denotes the ceiling, so \([\tfrac {1}{2}(3\nu +1)]\) is \((3 * \nu + 1 + 1) / 2\) in natural-number division.

Definition 145.9 \(G\) is hypohamiltonian: not Hamiltonian, but every vertex-deleted subgraph is (Ex 4.2.12)
#

The graph just barely fails to be hamiltonian: no spanning cycle itself, yet deleting any single vertex repairs the defect.

\(G - v\) is G.induce ({v}\(^{c}\) : Set V), whose carrier is a subtype, so each IsHamiltonian obligation is about a different vertex type. The open scoped Classical in above the definition is what discharges the resulting Fintype/DecidableEq instances on those carriers.

petersen_isHypohamiltonian below — the exercise itself.

Theorem 145.10 Thm 4.1: a nonempty connected graph is eulerian iff it has no odd-degree vertex

Every visit to a vertex consumes one edge coming in and one going out, so the edges at each vertex must pair up.

The (\(\Leftarrow \)) direction is a minimal counterexample argument. In Lean that is strong induction on \(\varepsilon (G)\) — the book’s "choose such a graph with as few edges as possible" — generalised over the graph, since \(G'\) is a different graph on (the subtype of) the same vertex type.

Theorem 145.11 Cor 4.1: a connected graph has an Euler trail iff at most two vertices have odd degree
#

By Corollary 1.1 the number of odd-degree vertices is always even, so "at most two" means exactly \(0\) or \(2\).

This is the precise answer to the Königsberg question and to exercise 4.1.1: a figure can be drawn "without lifting the pen and without retracing" exactly when it is connected and has at most two odd-degree vertices.

Theorem 145.12 Thm 4.2: if \(G\) is hamiltonian then \(\omega (G - S) \le |S|\) for every nonempty proper \(S\)
#

A hamiltonian graph is held together by a single cycle through every vertex, and a cycle is hard to shatter: removing \(k\) vertices from it leaves at most \(k\) arcs.

\(G - S\) is rendered as ((\(\top \) : G.Subgraph).deleteVerts ↑S).coe, so the component count is Nat.card of that graph’s ConnectedComponent. Using the Subgraph API rather than G.induce (↑S)\(^{c}\) is what lets the "spanning subgraph" step be stated at all, since \(C - S\) and \(G - S\) then live over the same vertex set.

Theorem 145.13 Thm 4.3: \(\nu \ge 3\) and \(\delta \ge \nu /2\) (stated as \(\nu \le 2\delta \)) imply \(G\) is hamiltonian
#

If every vertex is joined to at least half the graph, there is enough adjacency that a spanning cycle cannot be avoided.

\(\delta \ge \nu /2\) is formalised as \(\nu \le 2\delta \) to stay in the natural numbers and avoid the rounding ambiguity of \(\nu /2\) under truncated division.

Theorem 145.14 Lem 4.4.1: for nonadjacent \(u,v\) with \(d(u)+d(v) \ge \nu \), \(G\) is hamiltonian iff \(G+uv\) is
#

The book’s proof is two sentences only because it reuses the \(S\)/\(T\) counting argument (4.4) from Theorem 4.3. In Lean that argument has to exist somewhere concrete — so this lemma, not Dirac, is the right place to write it out, and Dirac then follows from the closure machinery.

Expanded, (4.4) is: from a Hamilton cycle of \(G + uv\) that must use \(uv\), extract a Hamilton path \(v_{1} \dots v_\nu \) in \(G\) with \(v_{1} = u\), \(v_\nu = v\). Put \(S = {v_{i} | u ~ v_{i+1}}\) and \(T = {v_{i} | v_{i} ~ v}\). Then \(v_\nu \notin S \cup T\) gives \(|S \cup T| \lt \nu \), and \(S \cap T = \emptyset \) because a common \(v_{i}\) would close the Hamilton cycle \(v_{1} \dots v_{i} v_\nu v_{\nu -1} \dots v_{i+1} v_{1}\) in \(G\). Hence \(d(u) + d(v) = |S| + |T| \lt \nu \).

Theorem 145.15 Thm 4.4 (honest restatement): reachability by closure steps preserves hamiltonicity

Stated in the file’s "honest restatement" form: instead of positing a closure operator, it says that if \(H\) is reachable from \(G\) by any finite chain of ClosureSteps, then \(G\) is hamiltonian exactly when \(H\) is. Taking \(H\) to admit no further step recovers the book’s statement.

This restatement is what lets the file skip Lemma 4.4.2 entirely — see below.

The book must prove \(c(G)\) well defined before Theorem 4.4 can even be stated; its proof (§4.2, p. 64) is the argument:

Because this file quantifies over ReflTransGen ClosureStep chains rather than naming a closure, Lemma 4.4.2 is not needed and is not formalised: the statement above holds for every chain, confluent or not. It would only be required if a closure : SimpleGraph V \(\to \) SimpleGraph V function were introduced.

Theorem 145.16 Cor 4.4 (honest restatement): if closure steps reach \(\top \), then \(G\) was hamiltonian

Stated with \(\top \) in place of "\(c(G)\) is complete", and ClosureStep reachability in place of the closure operator.

Theorem 145.17 Reusable helper (! absent from Mathlib): \(\top \) on \(\ge \) 3 vertices is hamiltonian
#

In \(K_{n}\) every pair of distinct vertices is adjacent, so any enumeration \(v_{1} v_{2} \dots v_n v_{1}\) is already a Hamilton cycle. Three vertices are needed because a cycle must have length at least three — \(K_{1}\) and \(K_{2}\) have no cycle at all.

! Despite the book calling it "trivial", Mathlib has no such lemma, and it is not trivial in Lean: it requires exhibiting a concrete cyclic enumeration of \(V\) and proving the resulting walk is a cycle whose support is nodup and spans.

Theorem 145.18 Thm 4.5 (counting form): the Chvátal degree condition implies hamiltonicity
#

! The hypothesis is formalised in counting form, not by indexing the sorted degree sequence. The book’s \(d_m \le m\) says "at least \(m\) vertices have degree \(\le m\)", and \(d_{\nu -m} \lt \nu - m\) says "at least \(\nu - m\) vertices have degree \(\lt \nu - m\)" — precisely the two Finset.filter cardinalities in hcond. This avoids all \(1\)- versus \(0\)-indexing hazards around degreeSequence, at the cost of no longer looking like the book’s inequality.

The book’s \(m \lt \nu /2\) is written \(2 * m \lt \nu \), and \(m \ge 1\) is made explicit (the book’s \(m\) is a degree \(d'(u)\), and \(m = 0\) is excluded by connectivity considerations implicit in "as large as possible").

Theorem 145.19 Thm 4.6: a nonhamiltonian simple graph with \(\nu \ge 3\) is degree-majorised by some \(C_{m,\nu }\)

The family \({C_{m,\nu }}\) consists of the degree-maximal nonhamiltonian graphs: any nonhamiltonian graph has degrees dominated, position by position, by one of them.

Corollary 4.6 — bounding the edge count of a nonhamiltonian graph reduces to computing \(\varepsilon (C_{m,\nu })\).

Theorem 145.20 Cor 4.6a: \(\varepsilon \gt C(\nu - 1,2) + 1\) implies hamiltonicity
#

Enough edges guarantee a spanning cycle, and this pins down exactly how many "enough" is: a nonhamiltonian graph has at most \(C(\nu -1, 2) + 1\) edges.

"By theorem 1.1" is the handshaking lemma — degree majorisation transfers to an edge-count inequality because \(2\varepsilon = \sum d(v)\).

! The book’s algebra is over \(\mathbb {Q}\) (note the \(\tfrac {1}{2}\)); in \(\mathbb {N}\) the identity \(\tfrac {1}{2}(m^{2} + (\nu -2m)(\nu -m-1) + m(\nu -1)) = C(\nu -1,2) + 1 - \tfrac {1}{2}(m-1)(m-2) - (m-1)(\nu -2m-1)\) involves subtraction that truncates. Either clear denominators and work with \(2\varepsilon \) throughout, or cast to \(\mathbb {Z}\)/\(\mathbb {Q}\) for the identity and cast back. The latter is likely cleaner.

Theorem 145.21 Cor 4.6b: the extremal nonhamiltonian graphs at \(C(\nu - 1,2)+1\) edges are \(C_{1,\nu }\) (and \(C_{2,5}\))
#

The equality analysis of the first half. The final inequality is tight only when both subtracted terms \(\tfrac {1}{2}(m-1)(m-2)\) and \((m-1)(\nu -2m-1)\) vanish, which happens only for \(m = 1\), or \(m = 2\) together with \(\nu = 5\).

So the bound is attained by exactly one graph for each \(\nu \), plus one sporadic extra at \(\nu = 5\): the densest nonhamiltonian simple graphs there are.

! The book’s closing "which is easily seen to imply that \(G \cong C_{1,\nu }\)" is the hardest step to formalise, and it is not easy in Lean. Degree sequence does not in general determine a graph up to isomorphism; the implication holds here only because of the specific structure of \(C_{1,\nu }\) and \(C_{2,5}\), and recovering an explicit \(\simeq \)g requires constructing the vertex bijection by hand.

Theorem 145.22 Ex 4.1.4: no odd degree \(\Rightarrow \) an edge-disjoint decomposition into cycles
#

Even degrees everywhere means no "loose ends". Peel cycles off one at a time: removing a cycle subtracts \(2\) from the degree of each vertex it visits, so all degrees stay even and the argument repeats until no edges are left.

"\(E(G) = \bigcup E(C_{i})\) with the \(C_{i}\) edge-disjoint" is rendered as the single \(\exists !\) statement — every edge lies in exactly one of the cycles — which packages covering and disjointness together.

Note this needs no connectivity hypothesis: it is the local content of Euler’s theorem. Connectivity is what additionally lets the cycles be spliced into one tour (Theorem 4.1).

Theorem 145.23 Ex 4.1.5: exactly \(2k\) odd-degree vertices \(\Rightarrow \) \(k\) edge-disjoint covering trails
#

By Corollary 1.1 the odd-degree vertices come in pairs, so there are \(k\) pairs. Pair them up and add \(k\) new edges joining the members of each pair; every vertex of the enlarged graph then has even degree, so Theorem 4.1 gives an Euler tour. Deleting the \(k\) added edges cuts that tour into exactly \(k\) trails, which are edge-disjoint and between them cover every edge of \(G\).

The practical reading: a road network with \(2k\) awkward junctions needs \(k\) separate pen-strokes; one Euler trail is the case \(k = 1\).

Theorem 145.24 Ex 4.2.1(a): not 2-connected (with \(\nu \ge 3\)) \(\Rightarrow \) nonhamiltonian (restated on the repo…

A graph that is not 2-connected is either disconnected or has a cut vertex \(v\). Disconnected: no cycle reaches every vertex. Cut vertex: take \(S = {v}\) in Theorem 4.2 — deleting \(v\) leaves at least two components, so \(\omega (G - S) \ge 2 \gt 1 = |S|\), violating the necessary condition.

A Hamilton cycle visits every vertex and returns, which needs two independent routes out of every vertex — exactly 2-connectivity. Necessary but far from sufficient (the Petersen graph is 3-connected and nonhamiltonian).

Stated against this file’s local vertexConnectivity, not the one in Connectivity.lean — see the warning on that definition above.

Theorem 145.25 Ex 4.2.1(b): an unbalanced bipartite graph is nonhamiltonian

Every edge crosses between \(X\) and \(Y\), so a cycle alternates sides and uses equally many vertices from each. A Hamilton cycle uses all vertices, forcing \(|X| = |Y|\).

This is why the book’s Herschel graph is nonhamiltonian:

(§4.2, p. 61.) Equivalently, apply Theorem 4.2 with \(S\) the smaller side.

Theorem 145.26 Ex 4.2.3: a Hamilton path implies \(\omega (G - S) \le |S| + 1\)
#

The path analogue of Theorem 4.2. Deleting \(k\) vertices from a path breaks it into at most \(k + 1\) pieces — one more than for a cycle, because a path has two loose ends rather than being closed up. The Hamilton path \(P\) is a spanning subgraph of \(G\), so \(\omega (G - S) \le \omega (P - S) \le |S| + 1\).

The extra \(+1\) is the price of not closing the cycle, making the condition weaker — as it must be, since a Hamilton path is weaker than a Hamilton cycle.

Theorem 145.27 Ex 4.2.4*: Chvátal’s Hamilton-path degree condition (counting form)
#

The Hamilton-path counterpart of Theorem 4.5, with thresholds shifted by one. Formalised in counting form, exactly as Theorem 4.5 is — see the note there on why indexing the sorted sequence is avoided.

Note the strict \(d_m \lt m\) here versus \(d_m \le m\) in Theorem 4.5; the hcond filters use \(\lt \) accordingly.

Theorem 145.28 Ex 4.2.5: a self-complementary graph has a Hamilton path (Clapham)

Only part (b) is formalised — part (a) has no separate declaration in this file.

Part (b) from part (a): if \(G \cong G^{c}\) the two sorted degree sequences are identical, so \(d_m \ge d_m'\) holds trivially at every index.

Recall from exercise 1.2.11(b) that self-complementary graphs exist only when \(\nu \equiv 0\) or 1 (mod 4).

Theorem 145.29 Ex 4.2.5(a) (Clapham): if \(G\) dominates \(G^{c}\) on the lower half of the sorted degree sequence, \(G\) has a…

This file previously formalised only part (b) (hamiltonian_path_of_self_complementary), even though the book deduces (b) from (a) — so (a) was a hidden prerequisite with no declaration. The triage (log/graphtheory-EXERCISE_TRIAGE.md §A.3) recorded this as a fidelity gap and recommended stating (a). Nothing here is invented: the statement is the book’s own, quoted above.

The two sorted degree sequences are rendered the way chvatal_hamiltonian_path renders its sequence — via a sorting equiv \(\sigma \) on Fin \(\nu \) making the degrees Antitone/Monotone — rather than as raw lists, so the two conditions in this file are stated in the same idiom and can share lemmas.

\(m \le \nu /2\) is written \(2 * m \le \nu \) to avoid \(\mathbb {N}\)-division.

Theorem 145.30 Ex 4.2.8: Erdős’ edge bound \(\nu \ge 6\delta \), \(\varepsilon \gt C(\nu -\delta ,2) + \delta ^{2}\)…
#

Corollary 4.6 gives a sufficient edge count taking no account of the minimum degree. Erdős’ refinement: when \(\delta \) is known and small relative to \(\nu \), a weaker count suffices — \(C(\nu -\delta , 2) + \delta ^{2}\) rather than \(C(\nu -1, 2) + 1\).

The shape of the bound reflects the extremal configuration: a clique on \(\nu - \delta \) vertices with \(\delta \) low-degree vertices attached, the densest way to be nonhamiltonian while holding the minimum degree at \(\delta \). \(\nu \ge 6\delta \) keeps \(\delta \) genuinely small.

Theorem 145.31 Ex 4.2.9*: connected with \(\nu \gt 2\delta \) \(\Rightarrow \) a path of length \(\ge \) \(2\delta \) (Dirac)

Exercise 1.6.3 already gives a path of length \(\delta \) from the minimum degree alone; Dirac’s sharpening doubles that, at the cost of connectivity and \(\nu \gt 2\delta \).

The bracketed cycle version — 2-connected, \(\nu \ge 2\delta \), cycle of length \(\ge 2\delta \) — is stated but not proved in the chapter. It is what exercise 4.2.10 relies on; see the warning there. It is not stated in this file either.

Theorem 145.32 Ex 4.2.10: a \(2k\)-regular graph on \(4k+1\) vertices is hamiltonian (Nash-Williams)

Such a graph has \(\delta = \Delta = 2k\) and \(\nu = 4k + 1 = 2\delta + 1\), one vertex above the threshold \(\nu \ge 2\delta \) of Dirac’s cycle remark. That remark yields a cycle of length at least \(2\delta = 4k\) — missing at most one vertex — and regularity plus parity then force the cycle to pick up the last vertex too.

! The Lean signature omits the book’s \(k \ge 1\). At \(k = 0\) the statement reads "every \(0\)-regular graph on \(1\) vertex is hamiltonian", which is false in Mathlib: a Hamilton cycle needs length \(\ge 3\), so the one-vertex graph is not IsHamiltonian. The hypothesis \(1 \le k\) must be added.

Theorem 145.33 Ex 4.2.11(a): a Hamilton-connected graph satisfies \(3\nu + 1 \le 2\varepsilon \) (Moon)

Hamilton-connectedness demands a spanning path between every pair, forcing many edges. Every vertex must have degree at least \(3\): a degree-\(2\) vertex has both its edges forced into any spanning path through it as an interior vertex, leaving no way to make it an endpoint of a spanning path to a third vertex. Summing \(d(v) \ge 3\) and applying handshaking gives \(2\varepsilon \ge 3\nu \), and a parity refinement pushes this to \(2\varepsilon \ge 3\nu + 1\).

Formalised as \(3\nu + 1 \le 2\varepsilon \) to stay in the natural numbers and avoid the ceiling.

! The Lean signature omits the book’s \(\nu \ge 4\). It is needed: for \(\nu = 3\), \(\top \) on three vertices is Hamilton-connected with \(\varepsilon = 3\), but \(3\nu + 1 = 10 \gt 6 = 2\varepsilon \). So the statement as written is false at \(\nu = 3\) and 4 \(\le \) Fintype.card V must be added.