Lean / Reader
Lean readerVertexDeletion.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports PairPaths, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import PairPathsopen SimpleGraph SimpleGraph.Walknamespace TerminalCyclesvariable {V : Type*}/-- The remaining neighbors after passing to an induced graph. -/theorem induced_valence (G : SimpleGraph V) (U : Set V) (v : U) :valence (G.induce U) v = (G.neighborSet v.val ∩ U).ncard := byapply Nat.card_congrexact {toFun := fun a => ⟨a.val.val,a.property,a.val.property⟩invFun := fun a => ⟨⟨a.val,a.property.2⟩,a.property.1⟩left_inv := fun _ => rflright_inv := fun _ => rfl }/-- If every other neighbor of a common vertex can lose one incidence,there is a dyadic path between the nonadjacent endpoints avoiding that vertex. -/theorem dyadic_path_avoiding_common [Finite V] (G : SimpleGraph V) {s t z : V}(ne : s ≠ t) (missing : ¬ G.Adj s t) (zs : G.Adj z s) (zt : G.Adj z t)(deg : ∀ v, 3 ≤ valence G v) (absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G)(spare : ∀ w, G.Adj z w → w ≠ s → w ≠ t → 4 ≤ valence G w) :∃ k ≥ 2, ∃ p : G.Walk s t, p.IsPath ∧ p.length = 2^k ∧ z ∉ p.support := byclassicallet U : Set V := {v | v ≠ z}let H := G.induce Ulet a : U := ⟨s,zs.ne.symm⟩let b : U := ⟨t,zt.ne.symm⟩let f : H ↪g G := SimpleGraph.Embedding.induce Uhave different : a ≠ b := fun he => ne (congrArg Subtype.val he)have disj : ∀ v, H.Adj v a → H.Adj v b → False := byintro v vs vtexact v.property (common_neighbors_unique G ne absent vs.symm vt.symm zs.symm zt.symm)have diff (v : U) : valence H v = (G.neighborSet v.val \ {z}).ncard := induced_valence G U vhave loss (v : U) : valence G v.val ≤ valence H v + 1 := byrw [diff]; simpa only [Set.ncard_singleton] using Set.ncard_le_ncard_diff_add_ncard (G.neighborSet v.val) {z}have ds := deg shave dt := deg thave da := loss ahave db := loss bchange valence G s ≤ valence H a + 1 at dachange valence G t ≤ valence H b + 1 at dbhave rest (v : U) (va : v ≠ a) (vb : v ≠ b) : 3 ≤ valence H v := byby_cases hit : G.Adj z v.val· have h := spare v.val hit (fun eq => va (Subtype.ext eq)) (fun eq => vb (Subtype.ext eq))have := loss vomega· have all : G.neighborSet v.val \ {z} = G.neighborSet v.val := byext yconstructor· exact fun h => h.1· intro adjexact ⟨adj,fun eq => hit ((eq ▸ (show G.Adj v.val y from adj)).symm)⟩rw [diff,all]exact deg v.valhave size : Nat.card U ≤ Nat.card V := Nat.card_le_card_of_injective Subtype.val Subtype.val_injectivehave merged := minimal _ (identify H a b) (lt_of_lt_of_le (identified_strict_size a b different) size)(identified_minimum H a b missing disj (by omega) (by omega) rest)obtain ⟨k,hk,p,simple,len⟩ := identification_forces_dyadic_path H a b different (absent_below f absent) mergedrefine ⟨k,hk,p.map f.toHom,map_isPath_of_injective f.injective simple,(length_map _ _).trans len,?_⟩rw [Walk.support_map,List.mem_map]rintro ⟨v,_,eq⟩exact v.property eq/-- An exceptional nonedge must have a cubic common neighbor whose thirdneighbor is also cubic. -/theorem exceptional_nonedge_cubic_edge [Finite V] (G : SimpleGraph V) {s t : V}(ne : s ≠ t) (missing : ¬ G.Adj s t) (deg : ∀ v, 3 ≤ valence G v)(absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G)(fail : ¬ ∃ k ≥ 2, ∃ p : G.Walk s t, p.IsPath ∧ p.length = 2^k) :∃ z w, G.Adj z s ∧ G.Adj z t ∧ valence G z = 3 ∧ G.Adj z w ∧w ≠ s ∧ w ≠ t ∧ valence G w = 3 := byhave shared : ∃ z, G.Adj z s ∧ G.Adj z t ∧ valence G z = 3 := byby_contra noapply fail (dyadic_path_unless_cubic_common G ne deg absent minimal ?_)intro v vs vthave bound := deg vhave neq : valence G v ≠ 3 := fun h => no ⟨v,vs,vt,h⟩omegaobtain ⟨z,zs,zt,three⟩ := sharedby_contra nohave spare (w : V) (zw : G.Adj z w) (ws : w ≠ s) (wt : w ≠ t) : 4 ≤ valence G w := byhave bound := deg whave neq : valence G w ≠ 3 := fun h => no ⟨z,w,zs,zt,three,zw,ws,wt,h⟩omegaobtain ⟨k,hk,p,simple,len,_⟩ := dyadic_path_avoiding_common G ne missing zs zt deg absent minimal spareexact fail ⟨k,hk,p,simple,len⟩noncomputable def exceptionalNonedges [Fintype V] (G : SimpleGraph V) : Finset (Finset V) := byclassicalexact (exceptionalPairs G).filter (fun P => ∀ s ∈ P, ∀ t ∈ P, ¬ G.Adj s t)/-- The nonadjacent exceptional pairs can be charged to oriented edges ofthe subgraph on cubic vertices, with at most one pair per orientation. -/theorem exceptional_nonedge_bound [Fintype V] (G : SimpleGraph V) [DecidableRel G.Adj](deg : ∀ v, 3 ≤ valence G v) (absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G) :let C := Finset.univ.filter (fun v => valence G v = 3)(exceptionalNonedges G).card ≤ ∑ v ∈ C, ((G.neighborFinset v).filter (fun w => valence G w = 3)).card := byclassicallet C := Finset.univ.filter (fun v => valence G v = 3)let out := fun v : V => (G.neighborFinset v).filter (fun w => valence G w = 3)let wedge := fun v : V => (out v).image (fun w => (G.neighborFinset v).erase w)have sub : exceptionalNonedges G ⊆ C.biUnion wedge := byintro P hPsimp only [exceptionalNonedges,Finset.mem_filter] at hPobtain ⟨pair,noEdges⟩ := hPsimp only [exceptionalPairs,Finset.mem_filter] at pairobtain ⟨size,s,t,rfl,ne,fail⟩ := pairhave no := noEdges s (by simp) t (by simp)obtain ⟨z,w,zs,zt,cz,zw,ws,wt,cw⟩ := exceptional_nonedge_cubic_edge G ne no deg absent minimal failhave win := (G.mem_neighborFinset _ _).mpr zwapply Finset.mem_biUnion.mprrefine ⟨z,by simp [C,cz],Finset.mem_image.mpr ⟨w,Finset.mem_filter.mpr ⟨win,cw⟩,?_⟩⟩symmapply Finset.eq_of_subset_of_card_le· intro u hurcases Finset.mem_insert.mp hu with rfl|hu· exact Finset.mem_erase.mpr ⟨ws.symm,(G.mem_neighborFinset _ _).mpr zs⟩· obtain rfl := Finset.mem_singleton.mp huexact Finset.mem_erase.mpr ⟨wt.symm,(G.mem_neighborFinset _ _).mpr zt⟩· have hsize := (Finset.mem_powersetCard.mp size).2rw [Finset.card_erase_of_mem win,G.card_neighborFinset_eq_degree,← valence_eq_degree,cz]omegacalc(exceptionalNonedges G).card ≤ (C.biUnion wedge).card := Finset.card_le_card sub_ ≤ ∑ v ∈ C, (wedge v).card := Finset.card_biUnion_le_ ≤ ∑ v ∈ C, (out v).card := Finset.sum_le_sum (fun _ _ => Finset.card_image_le)/-- Every pair separated by a vertex of degree at least four has a dyadicpath through that vertex. Its two pieces have lengths summing to the same power. -/theorem separated_pair_dyadic_path [Finite V] (G : SimpleGraph V) (c : V)(a b : {v : V // v ≠ c})(apart : ¬ (G.induce {v | v ≠ c}).Reachable a b) (four : 4 ≤ valence G c)(deg : ∀ v, 3 ≤ valence G v) (absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G) :∃ k ≥ 2, ∃ p : G.Walk a.val b.val, p.IsPath ∧ p.length = 2^k ∧∃ (l : G.Walk a.val c) (r : G.Walk c b.val), l.IsPath ∧ r.IsPath ∧ l.append r = p := byclassicallet U : Set V := {v | v ≠ c}have diff : a.val ≠ b.val := byintro eqobtain rfl : a=b := Subtype.ext eqexact apart ⟨nil⟩have share (v : V) (va : G.Adj v a.val) (vb : G.Adj v b.val) : 4 ≤ valence G v := byby_cases keep : v=c· simpa [keep] using four· let u : U := ⟨v,keep⟩have au : (G.induce U).Adj a u := va.symmhave ub : (G.induce U).Adj u b := vbexact (apart ⟨cons au (cons ub nil)⟩).elimobtain ⟨k,hk,p,hp,len⟩ := dyadic_path_unless_cubic_common G diff deg absent minimal sharehave onpath : c ∈ p.support := byby_contra outhave keep (v : V) (hv : v ∈ p.support) : v ∈ U := fun eq => out (eq ▸ hv)exact apart ⟨p.induce U keep⟩exact ⟨k,hk,p,hp,len,p.takeUntil c onpath,p.dropUntil c onpath,hp.takeUntil onpath,hp.dropUntil onpath,take_spec p onpath⟩end TerminalCycles