Lean / Reader
Lean reader

OddCycles.lean

66 lines3 declarationsno sorryimports TerminalCycles

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.

  1. import TerminalCycles
  2. open SimpleGraph SimpleGraph.Walk
  3. open scoped Sym2
  4. namespace TerminalCycles
  5. variable {V : Type*} {G : SimpleGraph V} {s t : V}
  6. private theorem terminal_edge_length {u v : V} (e : G.Adj u v) (p : G.Walk v u)
  7. (simple : p.IsPath) (mem : s(u,v) ∈ p.edges) : p.length = 1 := by
  8. cases p with
  9. | nil => simp at mem
  10. | @cons _ w _ a q =>
  11. obtain ⟨hq,fresh⟩ := (cons_isPath_iff _ _).mp simple
  12. simp only [edges_cons,List.mem_cons] at mem
  13. rcases mem with eq | inside
  14. · rcases Sym2.eq_iff.mp eq with ⟨same,_⟩ | ⟨same,_⟩
  15. · exact (e.ne same).elim
  16. · subst w
  17. rw [(isPath_iff_eq_nil q).mp hq]
  18. rfl
  19. · exact (fresh (q.snd_mem_support_of_mem_edges inside)).elim
  20. /-- When all simple cycles are even, loop erasure preserves walk parity. -/
  21. private theorem bypass_parity [DecidableEq V]
  22. (even : ∀ (u : V) (w : G.Walk u u), w.IsCycle → w.length % 2 = 0)
  23. {u v : V} (p : G.Walk u v) : p.bypass.length % 2 = p.length % 2 := by
  24. induction p with
  25. | nil => rfl
  26. | @cons u w v e p ih =>
  27. rw [Walk.bypass]
  28. split_ifs with hs
  29. · let q := p.bypass.takeUntil u hs
  30. let r := p.bypass.dropUntil u hs
  31. have split : q.length + r.length = p.bypass.length := by
  32. rw [← length_append]; exact congrArg Walk.length (take_spec p.bypass hs)
  33. have simple : q.IsPath := p.bypass_isPath.takeUntil hs
  34. have first : (q.length + 1) % 2 = 0 := by
  35. by_cases hit : s(u,w) ∈ q.edges
  36. · rw [terminal_edge_length e q simple hit]
  37. · exact even u (cons e q) ((cons_isCycle_iff q e).mpr ⟨simple,hit⟩)
  38. change r.length % 2 = (p.length+1) % 2
  39. omega
  40. · simp only [length_cons]; omega
  41. /-- The odd-cycle conclusion of iis:2611.00573, from its two-path test. -/
  42. theorem odd_cycle_of_sum_tests (h : sumTests (lengths G s t)) :
  43. ∃ (u : V) (c : G.Walk u u), c.IsCycle ∧ c.length % 2 = 1 := by
  44. classical
  45. by_contra missing
  46. have even : ∀ (u : V) (w : G.Walk u u), w.IsCycle → w.length % 2 = 0 := by
  47. intro u w hw
  48. have no : w.length % 2 ≠ 1 := fun bad => missing ⟨u,w,hw,bad⟩
  49. omega
  50. obtain ⟨a, ⟨p,_,rfl⟩, b, ⟨q,_,rfl⟩, k, hk, total⟩ := h 1 (by decide)
  51. let loop := p.append q.reverse
  52. have erased : loop.bypass = nil := (isPath_iff_eq_nil _).mp loop.bypass_isPath
  53. have par := bypass_parity even loop
  54. rw [erased] at par
  55. simp only [loop,length_nil,length_append,length_reverse] at par
  56. have powEven := dyadic_mod_two hk
  57. omega
  58. end TerminalCycles