Lean / Reader
Lean readerPairPaths.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports CutVertex, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import CutVerteximport Mathlib.Algebra.Order.BigOperators.Group.Finsetimport Mathlib.Data.Finset.Powersetopen SimpleGraph SimpleGraph.Walknamespace TerminalCyclesvariable {V : Type*}theorem identified_strict_size [Finite V] (s t : V) (ne : s ≠ t) :Nat.card (Option (Interior s t)) < Nat.card V := byclassicalletI := Fintype.ofFinite Vlet f : Option (Interior s t) → V := fun x => x.elim s Subtype.valhave injective : Function.Injective f := byrintro (_|a) (_|b) e· rfl· exact (b.property.1 e.symm).elim· exact (a.property.1 e).elim· exact congrArg some (Subtype.ext e)simp only [Nat.card_eq_fintype_card]apply Fintype.card_lt_of_injective_of_notMem f injective (b := t)rintro ⟨(_|a),e⟩· exact ne e· exact a.property.2 e/-- Two distinct vertices have at most one common neighbor in a graphwithout a four-cycle. -/theorem common_neighbors_unique (G : SimpleGraph V) {s t : V} (ne : s ≠ t)(absent : ¬ hasPowerCycle G) {a b : V} (sa : G.Adj s a) (ta : G.Adj t a)(sb : G.Adj s b) (tb : G.Adj t b) : a = b := byby_contra ablet p : G.Walk a b := cons ta.symm (cons tb nil)have simple : p.IsPath := by simp [p,cons_isPath_iff,ta.ne.symm,ab,tb.ne]have fresh : s ∉ p.support := by simp [p,sa.ne,ne,sb.ne]exact absent ⟨2,s,_,by decide,close_internal p simple ab fresh sa sb.symm,rfl⟩theorem outer_degree_ge_three [Finite V] (G : SimpleGraph V) {s t : V}(ne : s ≠ t) (absent : ¬ hasPowerCycle G)(from_s : 2 ≤ (G.neighborSet s \ {t}).ncard)(from_t : 2 ≤ (G.neighborSet t \ {s}).ncard) : 3 ≤ (outerNeighbors G s t).ncard := bylet A := G.neighborSet s \ {t}let B := G.neighborSet t \ {s}have small : (A ∩ B).ncard ≤ 1 := byapply Set.ncard_le_one_iff_subsingleton.mprintro a ha b hbexact common_neighbors_unique G ne absent ha.1.1 ha.2.1 hb.1.1 hb.2.1have size := Set.ncard_union_add_ncard_inter A Bchange 2 ≤ A.ncard at from_schange 2 ≤ B.ncard at from_tchange 3 ≤ (A ∪ B).ncardomega/-- For any two distinct vertices of a minimum-order counterexample, acommon cubic neighbor is the only possible obstruction to the dyadic path. -/theorem dyadic_path_unless_cubic_common [Finite V] (G : SimpleGraph V) {s t : V}(ne : s ≠ t) (deg : ∀ v, 3 ≤ valence G v)(absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G)(shared : ∀ v, G.Adj v s → G.Adj v t → 4 ≤ valence G v) :∃ k ≥ 2, ∃ p : G.Walk s t, p.IsPath ∧ p.length = 2^k := byhave outer (a b : V) : 2 ≤ (G.neighborSet a \ {b}).ncard := byhave h := Set.ncard_le_ncard_diff_add_ncard (G.neighborSet a) {b}rw [Set.ncard_singleton] at hhave degree : 3 ≤ (G.neighborSet a).ncard := deg aomegaapply identification_forces_dyadic_path G s t ne absentapply minimal _ _ (identified_strict_size s t ne)exact identified_minimum_shared G s t (outer_degree_ge_three G ne absent (outer s t) (outer t s))(fun v _ _ => deg v) shared/-- Even in a biconnected minimum-order counterexample, every pair atdistance at least three must occur as the ends of a simple dyadic path. -/theorem dyadic_path_of_dist_three [Finite V] (G : SimpleGraph V) (s t : V)(far : 3 ≤ G.dist s t) (deg : ∀ v, 3 ≤ valence G v)(absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G) :∃ k ≥ 2, ∃ p : G.Walk s t, p.IsPath ∧ p.length = 2^k := byhave ne : s ≠ t := by rintro rfl; simp at farhave missing : ¬ G.Adj s t := byintro ehave bound := SimpleGraph.dist_le (cons e nil)simp at boundomegahave disj : ∀ v, G.Adj v s → G.Adj v t → False := byintro v vs vthave bound := SimpleGraph.dist_le (cons vs.symm (cons vt nil))simp at boundomegahave ds := deg shave dt := deg tapply identification_forces_dyadic_path G s t ne absentapply minimal _ _ (identified_strict_size s t ne)exact identified_minimum G s t missing disj (by omega) (by omega) (fun v _ _ => deg v)/-- Unordered pairs of distinct vertices without a simple path of length4, 8, 16, ... . The pair is represented by its two-element vertex set. -/noncomputable def exceptionalPairs [Fintype V] (G : SimpleGraph V) : Finset (Finset V) := byclassicalexact (Finset.univ.powersetCard 2).filter fun P =>∃ s t : V, P = {s,t} ∧ s ≠ t ∧ ¬ ∃ k ≥ 2, ∃ p : G.Walk s t, p.IsPath ∧ p.length = 2^ktheorem exceptional_pair_bound [Fintype V] (G : SimpleGraph V)(deg : ∀ v, 3 ≤ valence G v) (absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G) :(exceptionalPairs G).card ≤ 3 * (Finset.univ.filter (fun v => valence G v = 3)).card := byclassicallet C := Finset.univ.filter (fun v => valence G v = 3)let wedges := fun v : V => (G.neighborFinset v).powersetCard 2have covered : exceptionalPairs G ⊆ C.biUnion wedges := byintro P hPobtain ⟨size,s,t,rfl,ne,fail⟩ := Finset.mem_filter.mp hPhave center : ∃ v, G.Adj v s ∧ G.Adj v t ∧ valence G v = 3 := byby_contra missingapply failapply dyadic_path_unless_cubic_common G ne deg absent minimalintro v a bhave h := deg vhave not_three : valence G v ≠ 3 := fun e => missing ⟨v,a,b,e⟩omegaobtain ⟨v,vs,vt,three⟩ := centerapply Finset.mem_biUnion.mprrefine ⟨v,by simp [C,three],Finset.mem_powersetCard.mpr ⟨?_,(Finset.mem_powersetCard.mp size).2⟩⟩intro u hurcases (Finset.mem_insert.mp hu) with rfl | hu· exact (G.mem_neighborFinset _ _).mpr vs· have eq := Finset.mem_singleton.mp huexact (G.mem_neighborFinset _ _).mpr (eq ▸ vt)have cap := Finset.card_biUnion_le_card_mul C wedges 3 (byintro v hvhave three : valence G v = 3 := (Finset.mem_filter.mp hv).2rw [valence_eq_degree] at threesimp [wedges, Finset.card_powersetCard, G.card_neighborFinset_eq_degree, three])exact (Finset.card_le_card covered).trans (by simpa [C,Nat.mul_comm] using cap)end TerminalCycles