Lean / Reader
Lean readerTwoCopy.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports TwoSideTests, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import TwoSideTestsopen SimpleGraph SimpleGraph.Walknamespace TerminalCyclesuniverse uvariable {V W Z : Type u} [Finite V] [Finite W]private abbrev Bit : Type u := ULift.{u} Boolprivate abbrev first : Bit.{u} := ⟨false⟩private abbrev last : Bit.{u} := ⟨true⟩private abbrev edgeGraph : SimpleGraph Bit.{u} := ⊤private theorem bit_deg (v : Bit.{u}) : valence edgeGraph v = 1 := byrw [valence_eq_degree]simp [Bit,Fintype.card_ulift]private theorem bit_path (p : edgeGraph.Walk first.{u} last) (simple : p.IsPath) : p.length=1 := byhave upper := simple.length_lthave n : Fintype.card Bit.{u} = 2 := by simp [Bit]have low : p.length ≠ 0 := fun h => (by decide : first.{u} ≠ last) (eq_of_length_eq_zero h)omegaprivate theorem bit_absent : ¬ hasPowerCycle edgeGraph.{u} := byrintro ⟨k,v,p,hk,hp,len⟩cases p with| nil => exact hp.ne_nil rfl| cons h q =>have simple := ((cons_isCycle_iff _ _).mp hp).1have upper := simple.length_lthave n : Fintype.card Bit.{u} = 2 := by simp [Bit]have pow := Nat.pow_le_pow_right (by decide : 0 < 2) hksimp only [length_cons] at lenomegaabbrev LeafGraph (B : SimpleGraph W) (b : W) := wedge edgeGraph B first babbrev leafVertex {b : W} : WedgeVertex Bit b := Sum.inl lastabbrev leafEnd {b : W} (y : ExceptRoot b) : WedgeVertex Bit b := Sum.inr ytheorem leaf_side (B : SimpleGraph W) {b y : W} (right : TerminalSide B b y) (db : 2 ≤ valence B b) :TerminalSide (LeafGraph B b) leafVertex (leafEnd ⟨y,right.distinct⟩) ∧1 ≤ valence (LeafGraph B b) leafVertex := bylet yi : ExceptRoot b := ⟨y,right.distinct⟩let L := wedge edgeGraph B first blet leaf : WedgeVertex Bit b := Sum.inl lastlet endV : WedgeVertex Bit b := Sum.inr yihave leaf1 : 1 ≤ valence L leaf := (bit_deg last).symm.le.trans (wedge_left_degree edgeGraph B first b last)have dy := wedge_right_degree edgeGraph B first b yihave newSide : TerminalSide L leaf endV := byrefine ⟨Sum.inr_ne_inl,right.target.trans dy,?_,?_⟩· rintro (v|v) vl ve· have eq : v=first := byrcases v with ⟨(_|_)⟩· rfl· exact (vl rfl).elimsubst vhave cap := wedge_root_degree edgeGraph B first bhave tiny := bit_deg first.{u}change 3 ≤ valence (wedge edgeGraph B first b) (Sum.inl first)omega· exact (right.others v.val v.property (fun e => ve (congrArg Sum.inr (Subtype.ext e)))).trans(wedge_right_degree edgeGraph B first b v)· intro yesexact (wedge_cycle_from_side edgeGraph B first b yes).elim bit_absent right.noCycleexact ⟨newSide,leaf1⟩theorem leaf_order (b : W) : Nat.card (WedgeVertex Bit.{u} b) = Nat.card W + 1 := byhave space := wedge_order (V:=Bit.{u}) bhave card : Nat.card Bit.{u} = 2 := by simp [Bit,Nat.card_eq_fintype_card]omegaomit [Finite W] intheorem leaf_path (B : SimpleGraph W) {b : W} (y : ExceptRoot b)(q : (LeafGraph B b).Walk leafVertex (leafEnd y)) (hq : q.IsPath) :∃ r : B.Walk b y.val, r.IsPath ∧ r.length+1=q.length := byobtain ⟨e,r,he,hr,paths⟩ := wedge_terminal_split edgeGraph B first b last y q hqhave one := bit_path e heexact ⟨r,hr,by omega⟩/-- Joining both pairs of corresponding terminals by edges forces thesum of two terminal path lengths plus two to be a power of two. -/theorem two_join_sum (A : SimpleGraph V) (B : SimpleGraph W) (G : SimpleGraph Z){a x : V} {b y : W} (left : TerminalSide A a x) (right : TerminalSide B b y)(da : 2 ≤ valence A a) (db : 2 ≤ valence B b)(small : Nat.card V + Nat.card W < Nat.card Z) (minimal : smaller_graphs_have_cycle G) :∃ k ≥ 2, ∃ (l : A.Walk a x) (r : B.Walk b y), l.IsPath ∧ r.IsPath ∧ l.length+r.length+2=2^k := bylet yi : ExceptRoot b := ⟨y,right.distinct⟩let L := LeafGraph B bobtain ⟨newSide,leaf1⟩ := leaf_side B right dbchange 1 ≤ valence L leafVertex at leaf1have space := leaf_order bhave sz : Nat.card V + Nat.card (WedgeVertex Bit b) ≤ Nat.card Z := by omegaobtain ⟨k,hk,p,q,hp,hq,len⟩ := one_join_sum A L G left newSide (by omega) sz minimalobtain ⟨r,hr,paths⟩ := leaf_path B yi q hqexact ⟨k,hk,p,r,hp,hr,by omega⟩/-- The three offsets hold for two independent sides, even if they arenonisomorphic or have different sets of terminal path lengths. -/theorem mixed_sum_tests (A : SimpleGraph V) (B : SimpleGraph W) (G : SimpleGraph Z){a x : V} {b y : W} (left : TerminalSide A a x) (right : TerminalSide B b y)(da : 2 ≤ valence A a) (db : 2 ≤ valence B b)(small : Nat.card V + Nat.card W < Nat.card Z) (minimal : smaller_graphs_have_cycle G) :∀ d ≤ 2, ∃ i ∈ lengths A a x, ∃ j ∈ lengths B b y, ∃ k ≥ 2, i+j+d = 2^k := byintro d hdhave spec : ∃ k ≥ 2, ∃ (p : A.Walk a x) (q : B.Walk b y), p.IsPath ∧ q.IsPath ∧ p.length+q.length+d = 2^k := byinterval_cases d· simpa using zero_join_sum A B G left right (by omega) small.le minimal· exact one_join_sum A B G left right (by omega) small.le minimal· exact two_join_sum A B G left right da db small minimalobtain ⟨k,hk,p,q,hp,hq,len⟩ := specexact ⟨p.length,⟨p,hp,rfl⟩,q.length,⟨q,hq,rfl⟩,k,hk,len⟩/-- The original two-copy sum test of iis:2611.00573, specialized to abalanced cut side from Ducoffe and Dumitru's structure theorem. -/theorem cut_side_sum_tests (A : SimpleGraph V) (G : SimpleGraph Z) (f : A ↪g G) {a x : V}(ne : x ≠ a) (da : 2 ≤ valence A a) (dx : 2 ≤ valence A x)(rest : ∀ v, v ≠ a → v ≠ x → 3 ≤ valence A v) (balanced : Nat.card Z = 2*Nat.card V+1)(absent : ¬ hasPowerCycle G) (minimal : smaller_graphs_have_cycle G) : sumTests (lengths A a x) := byhave side : TerminalSide A a x := ⟨ne,dx,rest,absent_below f absent⟩exact mixed_sum_tests A A G side side da da (by omega) minimalend TerminalCycles