Lean / Reader
Lean readerAdjacentTerminals.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports VertexDeletion, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import VertexDeletionopen SimpleGraph SimpleGraph.Walkopen scoped Sym2namespace TerminalCyclesuniverse uvariable {V W : Type u}abbrev remainder (H : SimpleGraph V) (s t : V) : SimpleGraph (Interior s t) := H.induce {v | v ≠ s ∧ v ≠ t}/-- The nonterminal vertices only lose their incidences to the two terminals. -/private theorem remainder_degrees [Finite V] (H : SimpleGraph V) {s t : V} (x y : Interior s t)(xy : x ≠ y) (onlyS : ∀ v : Interior s t, H.Adj s v.val ↔ v=x)(onlyT : ∀ v : Interior s t, H.Adj t v.val ↔ v=y)(deg : ∀ v : Interior s t, 3 ≤ valence H v.val) :2 ≤ valence (remainder H s t) x ∧ 2 ≤ valence (remainder H s t) y ∧∀ v : Interior s t, v ≠ x → v ≠ y → 3 ≤ valence (remainder H s t) v := bylet U : Set V := {v | v ≠ s ∧ v ≠ t}have keep (v : Interior s t) (b : V) (safe : ∀ w, H.Adj v.val w → w ≠ b → w ∈ U) :2 ≤ valence (remainder H s t) v := byhave sub : H.neighborSet v.val \ {b} ⊆ H.neighborSet v.val ∩ U := fun w hw => ⟨hw.1,safe w hw.1 hw.2⟩have bound := Set.ncard_le_ncard subhave diff := Set.ncard_le_ncard_diff_add_ncard (H.neighborSet v.val) {b}rw [Set.ncard_singleton] at diffhave hv : 3 ≤ (H.neighborSet v.val).ncard := deg vchange 2 ≤ valence (H.induce U) vrw [induced_valence]omegarefine ⟨keep x s ?_,keep y t ?_,?_⟩· intro w e wsexact ⟨ws,fun wt => xy ((onlyT x).mp (wt ▸ e.symm))⟩· intro w e wtexact ⟨fun ws => xy.symm ((onlyS y).mp (ws ▸ e.symm)),wt⟩· intro v vx vyhave sub : H.neighborSet v.val ⊆ H.neighborSet v.val ∩ U := byintro w hwhave e : H.Adj v.val w := hwexact ⟨hw,fun ws => vx ((onlyS v).mp (ws ▸ e.symm)),fun wt => vy ((onlyT v).mp (wt ▸ e.symm))⟩exact (deg v).trans ((Set.ncard_le_ncard sub).trans_eq (induced_valence H U v).symm)private theorem path_after_completion (R : SimpleGraph V) (x y : V) (missing : ¬ R.Adj x y)(yes : hasPowerCycle (completeEdge R x y)) (noR : ¬ hasPowerCycle R) :∃ j ≥ 2, ∃ p : R.Walk x y, p.IsPath ∧ p.length+1 = 2^j := byhave del : ¬ hasPowerCycle ((completeEdge R x y).deleteEdges {s(x,y)}) := by rwa [delete_completed R x y missing]obtain ⟨j,hj,p⟩ := critical_edge_forces_path (completeEdge R x y) x y yes delrw [delete_completed R x y missing] at pexact ⟨j,hj,p⟩/-- Both competitor tests on the graph after removal of adjacent terminals.The two exceptional neighbors, their nonadjacency, and the degree boundsare derived from the indicated incidences and original side structure. -/theorem adjacent_terminal_remainder [Finite V] [Finite W] (H : SimpleGraph V) (G : SimpleGraph W)(f : H ↪g G) {s t : V} (st : H.Adj s t) (x y : Interior s t) (c : W)(onlyS : ∀ v : Interior s t, H.Adj s v.val ↔ v=x)(onlyT : ∀ v : Interior s t, H.Adj t v.val ↔ v=y)(outside : ∀ v, f v ≠ c) (cs : G.Adj c (f s)) (ct : G.Adj c (f t))(smaller : Nat.card V < Nat.card W) (deg : ∀ v : Interior s t, 3 ≤ valence H v.val)(absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G) :let R := remainder H s t(∃ j ≥ 2, ∃ p : R.Walk x y, p.IsPath ∧ p.length+1 = 2^j) ∧((∀ v, R.Adj v x → R.Adj v y → 4 ≤ valence R v) →∃ i ≥ 2, ∃ p : R.Walk x y, p.IsPath ∧ p.length = 2^i) := byclassicallet R := remainder H s tletI : Nonempty (Interior s t) := ⟨x⟩have sx := (onlyS x).mpr rflhave ty := (onlyT y).mpr rflhave xy : x ≠ y := byrintro rflhave h := common_neighbors_unique G (fun eq => st.ne (f.injective eq)) absentcs.symm ct.symm (f.toHom.map_adj sx) (f.toHom.map_adj ty)exact outside x.val h.symmhave noH := absent_below f absenthave missing : ¬ R.Adj x y := byintro edgehave h := common_neighbors_unique H y.property.1.symm noH sx (H.symm edge) st ty.symmexact x.property.2 hhave noR := absent_below (SimpleGraph.Embedding.induce {v | v ≠ s ∧ v ≠ t}) noHchange ¬ hasPowerCycle R at noRhave sz : Nat.card (Interior s t) < Nat.card W := lt_of_le_of_lt (Nat.card_le_card_of_injective Subtype.val Subtype.val_injective) smallerobtain ⟨dx,dy,other⟩ := remainder_degrees H x y xy onlyS onlyT deghave added := minimal _ (completeEdge R x y) sz (completed_minimum R x y xy missing dx dy other)refine ⟨path_after_completion R x y missing added noR,?_⟩intro sharedhave full (a b : Interior s t) (no : ¬ R.Adj a b) : R.neighborSet a \ {b} = R.neighborSet a := byext vexact ⟨fun hv => hv.1,fun hv => ⟨hv,fun eq => no (eq ▸ hv)⟩⟩have hub := outer_degree_ge_three R xy noR (from_s := by rwa [full x y missing])(from_t := by rwa [full y x (fun e => missing e.symm)])have merged := minimal _ (identify R x y) (lt_of_le_of_lt (identified_size x y) sz)(identified_minimum_shared R x y hub other shared)exact identification_forces_dyadic_path R x y xy noR merged/-- Every remainder path extends through the two attachment edges. It alsocloses in two ways, giving the offsets three and four. -/theorem adjacent_terminal_lift (H : SimpleGraph V) (G : SimpleGraph W) (f : H ↪g G){s t : V} (st : H.Adj s t) (x y : Interior s t) (sx : H.Adj s x.val) (ty : H.Adj t y.val)(c : W) (outside : ∀ v, f v ≠ c) (cs : G.Adj c (f s)) (ct : G.Adj c (f t))(absent : ¬ hasPowerCycle G) (p : (remainder H s t).Walk x y) (simple : p.IsPath) :(∃ q : H.Walk s t, q.IsPath ∧ q.length = p.length+2) ∧(∀ k ≥ 2, p.length+3 ≠ 2^k) ∧ (∀ k ≥ 2, p.length+4 ≠ 2^k) := bylet e : remainder H s t ↪g H := SimpleGraph.Embedding.induce _let q := p.map e.toHomhave ss : s ∉ q.support := bychange s ∉ (p.map e.toHom).supportrw [Walk.support_map,List.mem_map]rintro ⟨v,_,eq⟩exact v.property.1 eqhave tt : t ∉ q.support := bychange t ∉ (p.map e.toHom).supportrw [Walk.support_map,List.mem_map]rintro ⟨v,_,eq⟩exact v.property.2 eqhave good : q.IsPath := map_isPath_of_injective e.injective simplelet a := cons sx (q.concat ty.symm)have simpleA : a.IsPath := open_internal q good st.ne ss tt sx ty.symmhave len : a.length = p.length+2 := by simp [a,q,Nat.add_assoc]refine ⟨⟨a,simpleA,len⟩,?_,?_⟩· intro k hk badhave fresh : s ∉ (q.concat ty.symm).support := by simpa [support_concat,st.ne] using sshave cycle := close_internal (q.concat ty.symm) (good.concat tt ty.symm) x.property.2 fresh sx st.symmexact absent_below f absent ⟨k,s,_,hk,cycle,by simpa [q,Nat.add_assoc] using bad⟩· intro k hk badapply forbidden_plus_two f st.ne outside cs ct absent a simpleA k hkomega/-- The two simple terminal path lengths for the adjacent case, in H itself. -/theorem adjacent_terminal_lengths [Finite V] [Finite W] (H : SimpleGraph V) (G : SimpleGraph W)(f : H ↪g G) {s t : V} (st : H.Adj s t) (x y : Interior s t) (c : W)(onlyS : ∀ v : Interior s t, H.Adj s v.val ↔ v=x)(onlyT : ∀ v : Interior s t, H.Adj t v.val ↔ v=y)(outside : ∀ v, f v ≠ c) (cs : G.Adj c (f s)) (ct : G.Adj c (f t))(smaller : Nat.card V < Nat.card W) (deg : ∀ v : Interior s t, 3 ≤ valence H v.val)(absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G) :(∃ j ≥ 2, ∃ q : H.Walk s t, q.IsPath ∧ q.length = 2^j+1) ∧((∀ v, (remainder H s t).Adj v x → (remainder H s t).Adj v y → 4 ≤ valence (remainder H s t) v) →∃ i ≥ 2, ∃ q : H.Walk s t, q.IsPath ∧ q.length = 2^i+2) := byobtain ⟨mersenne,power⟩ := adjacent_terminal_remainder H G f st x y c onlyS onlyT outside cs ct smaller deg absent minimalhave lift := adjacent_terminal_lift H G f st x y ((onlyS x).mpr rfl) ((onlyT y).mpr rfl) c outside cs ct absentconstructor· obtain ⟨j,hj,p,hp,len⟩ := mersenneobtain ⟨q,hq,size⟩ := (lift p hp).1exact ⟨j,hj,q,hq,by omega⟩· intro sharedobtain ⟨i,hi,p,hp,len⟩ := power sharedobtain ⟨q,hq,size⟩ := (lift p hp).1exact ⟨i,hi,q,hq,by omega⟩end TerminalCycles