/-- If a multigraph has an Euler circuit, every vertex has even degree.
Hint: write the walk as `a :: rest`; the circuit ends where it starts, so `rest.getLastD a = a`.
Then `degree_walkEdges a rest v` and `degree_perm` give
`degree G v + 2 * (if a = v then 1 else 0) = 2 * (a :: rest).count v`. -/
theorem euler_circuit_even {n : ℕ} {G : Multigraph n} {w : List (Fin n)}
(h : IsEulerCircuit G w) (v : Fin n) : Even (degree G v) := by
sorryShow the compiled solution
/-- **Euler's theorem, necessity (circuits).** If a multigraph has an Euler circuit, every
vertex has even degree: the circuit's start and finish coincide, so every visit to a vertex
uses an even number of edge-ends there. -/
theorem euler_circuit_even {n : ℕ} {G : Multigraph n} {w : List (Fin n)}
(h : IsEulerCircuit G w) (v : Fin n) : Even (degree G v) := by
obtain ⟨⟨hne, hperm⟩, hends⟩ := h
obtain ⟨a, rest, rfl⟩ := List.exists_cons_of_ne_nil hne
-- the walk finishes where it starts
have hlast : rest.getLastD a = a := by
simp only [List.head?_cons, List.getLast?_cons, Option.some.injEq] at hends
rw [List.getLastD_eq_getLast?]
exact hends.symm
have key := degree_walkEdges a rest v
rw [hlast, degree_perm hperm v] at key
rw [Nat.even_iff]
by_cases hav : a = v <;> simp [hav] at key <;> omegaAxioms used: propext, Classical.choice, Quot.soundformal/Lumenary/GraphBasics.leanTry it in the Lean web editor