Lean / Reader
Lean readerOddCycles.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports TerminalCycles, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import TerminalCyclesopen SimpleGraph SimpleGraph.Walkopen scoped Sym2namespace TerminalCyclesvariable {V : Type*} {G : SimpleGraph V} {s t : V}private theorem terminal_edge_length {u v : V} (e : G.Adj u v) (p : G.Walk v u)(simple : p.IsPath) (mem : s(u,v) ∈ p.edges) : p.length = 1 := bycases p with| nil => simp at mem| @cons _ w _ a q =>obtain ⟨hq,fresh⟩ := (cons_isPath_iff _ _).mp simplesimp only [edges_cons,List.mem_cons] at memrcases mem with eq | inside· rcases Sym2.eq_iff.mp eq with ⟨same,_⟩ | ⟨same,_⟩· exact (e.ne same).elim· subst wrw [(isPath_iff_eq_nil q).mp hq]rfl· exact (fresh (q.snd_mem_support_of_mem_edges inside)).elim/-- When all simple cycles are even, loop erasure preserves walk parity. -/private theorem bypass_parity [DecidableEq V](even : ∀ (u : V) (w : G.Walk u u), w.IsCycle → w.length % 2 = 0){u v : V} (p : G.Walk u v) : p.bypass.length % 2 = p.length % 2 := byinduction p with| nil => rfl| @cons u w v e p ih =>rw [Walk.bypass]split_ifs with hs· let q := p.bypass.takeUntil u hslet r := p.bypass.dropUntil u hshave split : q.length + r.length = p.bypass.length := byrw [← length_append]; exact congrArg Walk.length (take_spec p.bypass hs)have simple : q.IsPath := p.bypass_isPath.takeUntil hshave first : (q.length + 1) % 2 = 0 := byby_cases hit : s(u,w) ∈ q.edges· rw [terminal_edge_length e q simple hit]· exact even u (cons e q) ((cons_isCycle_iff q e).mpr ⟨simple,hit⟩)change r.length % 2 = (p.length+1) % 2omega· simp only [length_cons]; omega/-- The odd-cycle conclusion of iis:2611.00573, from its two-path test. -/theorem odd_cycle_of_sum_tests (h : sumTests (lengths G s t)) :∃ (u : V) (c : G.Walk u u), c.IsCycle ∧ c.length % 2 = 1 := byclassicalby_contra missinghave even : ∀ (u : V) (w : G.Walk u u), w.IsCycle → w.length % 2 = 0 := byintro u w hwhave no : w.length % 2 ≠ 1 := fun bad => missing ⟨u,w,hw,bad⟩omegaobtain ⟨a, ⟨p,_,rfl⟩, b, ⟨q,_,rfl⟩, k, hk, total⟩ := h 1 (by decide)let loop := p.append q.reversehave erased : loop.bypass = nil := (isPath_iff_eq_nil _).mp loop.bypass_isPathhave par := bypass_parity even looprw [erased] at parsimp only [loop,length_nil,length_append,length_reverse] at parhave powEven := dyadic_mod_two hkomegaend TerminalCycles