Lean / Reader
Lean readerDecayPaletteGraphs.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports DecayProducts, DecayCopies, DecayConverse, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import DecayProductsimport DecayCopiesimport DecayConversenamespace DecayClassificationstructure PaletteGraph (n r k : ℕ) wherecolor : Fin n → Fin n → Fin rsymm : ∀ x y, color x y = color y xcliques : DecayProducts.BoundedCliques color knamespace PaletteGraphdef labels {n r k} (G : PaletteGraph n r k) (e : Fin n × Fin n) : ℕ := (G.color e.1 e.2).valtheorem no_clique {n r k} (G : PaletteGraph n r k) (hk : 1 ≤ k) : ¬MonoClique (k+1) G.labels := byrintro ⟨s,hcard,i,hmono⟩have two : 1 < s.card := by omegaobtain ⟨x,hx,y,hy,ne⟩ := Finset.one_lt_card.mp twohave ord : ∃ x ∈ s, ∃ y ∈ s, x < y := byrcases ne.lt_or_gt with h | h· exact ⟨x,hx,y,hy,h⟩· exact ⟨y,hy,x,hx,h⟩obtain ⟨x,hx,y,hy,lt⟩ := ordhave hi : i < r := by rw [← hmono x hx y hy lt]; exact (G.color x y).isLthave hm : DecayProducts.OneColor G.color ⟨i,hi⟩ s := byintro u hu v hv hneapply Fin.extrcases hne.lt_or_gt with h | h· exact hmono u hu v hv h· rw [G.symm]; exact hmono v hv u hu hhave := G.cliques _ _ hmomegatheorem transport {V U L H : Type*} [DecidableEq U] (e : V ≃ U) (f : L ≃ H){c : U → U → L} {k : ℕ} (bound : DecayProducts.BoundedCliques c k) :DecayProducts.BoundedCliques (fun x y => f (c (e x) (e y))) k := byclassicalintro col s hhave image_bound : (s.image e).card ≤ k := byapply bound (f.symm col)intro x hx y hy neobtain ⟨u,hu,rfl⟩ := Finset.mem_image.mp hxobtain ⟨v,hv,rfl⟩ := Finset.mem_image.mp hyexact (f.eq_symm_apply).mpr (h u hu v hv (fun eq => ne (congrArg e eq)))rwa [Finset.card_image_of_injective _ e.injective] at image_bounddef same {n m r p q} (G : PaletteGraph n r p) (H : PaletteGraph m r q) :PaletteGraph (n*m) r (p*q) wherecolor x y := DecayProducts.lexSame G.color H.color (finProdFinEquiv.symm x) (finProdFinEquiv.symm y)symm x y := bydsimp [DecayProducts.lexSame]split_ifs with h h' h'all_goals first | exact G.symm .. | exact H.symm .. | grindcliques := transport finProdFinEquiv.symm (Equiv.refl _) (DecayProducts.lex_same_clique _ _ G.cliques H.cliques)def apart {n m r s p q} (G : PaletteGraph n r p) (H : PaletteGraph m s q) :PaletteGraph (n*m) (r+s) (max p q) wherecolor x y := finSumFinEquiv (DecayProducts.lexApart G.color H.color (finProdFinEquiv.symm x) (finProdFinEquiv.symm y))symm x y := byapply congrArg finSumFinEquivdsimp [DecayProducts.lexApart]split_ifs with h h' h'all_goals first | rw [G.symm] | rw [H.symm] | grindcliques := transport finProdFinEquiv.symm finSumFinEquiv (DecayProducts.lex_apart_clique _ _ G.cliques H.cliques)def power {n r p} (G : PaletteGraph n r p) : (t : ℕ) → PaletteGraph (n^(t+1)) r (p^(t+1))| 0 => by simpa using G| t+1 => by simpa only [pow_succ n (t+1),pow_succ p (t+1)] using (power G t).same Gtheorem apart_labels {n m r s p q} (G : PaletteGraph n r p) (H : PaletteGraph m s q)(e : Fin (n*m) × Fin (n*m)) :(G.apart H).labels e = if origin e.1 = origin e.2 thenr + H.labels (part e.1,part e.2) else G.labels (origin e.1,origin e.2) := bychange ((finSumFinEquiv (if origin e.1 = origin e.2 thenSum.inr (H.color (part e.1) (part e.2)) else Sum.inl (G.color (origin e.1) (origin e.2)))).val : ℕ) = _split <;> rfltheorem old_count {n m r s p q} (G : PaletteGraph n r p) (H : PaletteGraph m s q)(i : ℕ) (hi : i < r) :((edges (n*m)).filter (fun e => (G.apart H).labels e = i)).card ≤((edges n).filter (fun e => G.labels e = i)).card * (m*m) := byclassicallet S := ((edges n).filter fun e => G.labels e = i) ×ˢ (Finset.univ : Finset (Fin m × Fin m))let f (e : Fin (n*m) × Fin (n*m)) := ((origin e.1,origin e.2),(part e.1,part e.2))have hle : ((edges (n*m)).filter (fun e => (G.apart H).labels e = i)).card ≤ S.card := byapply Finset.card_le_card_of_injOn f· intro e heobtain ⟨hedge,hcol⟩ := Finset.mem_filter.mp hehave lt := (Finset.mem_filter.mp hedge).2have ne : origin e.1 ≠ origin e.2 := byintro eqrw [apart_labels,if_pos eq] at hcolomegahave earlier : origin e.1 < origin e.2 := lt_of_not_ge (byintro revhave hrev := replica_lt (part e.2) (part e.1) (lt_of_le_of_ne rev ne.symm)simp only [replica_origin_part] at hrevexact (not_lt_of_ge hrev.le) lt)exact Finset.mem_product.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_filter.mpr⟨Finset.mem_univ _,earlier⟩,by simpa only [apart_labels,if_neg ne] using hcol⟩, Finset.mem_univ _⟩· intro e _ z _ eqhave inv := congrArg (fun v : (Fin n × Fin n) × (Fin m × Fin m) =>(replica v.1.1 v.2.1,replica v.1.2 v.2.2)) eqsimpa [f] using invsimpa [S] using hletheorem new_count {n m r s p q} (G : PaletteGraph n r p) (H : PaletteGraph m s q)(i : ℕ) (hi : r ≤ i) :((edges (n*m)).filter (fun e => (G.apart H).labels e = i)).card ≤ n*(edges m).card := byclassicallet S := (Finset.univ : Finset (Fin n)) ×ˢ edges mlet f (e : Fin (n*m) × Fin (n*m)) := (origin e.1,(part e.1,part e.2))have hle : ((edges (n*m)).filter (fun e => (G.apart H).labels e = i)).card ≤ S.card := byapply Finset.card_le_card_of_injOn f· intro e heobtain ⟨hedge,hcol⟩ := Finset.mem_filter.mp hehave lt := (Finset.mem_filter.mp hedge).2have eq : origin e.1 = origin e.2 := byby_contra nerw [apart_labels,if_neg ne] at hcolhave : G.labels (origin e.1,origin e.2) < r := (G.color ..).isLtomegahave ee : ∀ w : Fin (n*m), w.val = (part w).val + m*(origin w).val := byintro wexact congrArg Fin.val (replica_origin_part w).symmhave partlt : part e.1 < part e.2 := bychange e.1.val < e.2.val at ltrw [ee e.1,ee e.2,eq] at ltexact Nat.lt_of_add_lt_add_right ltexact Finset.mem_product.mpr ⟨Finset.mem_univ _,Finset.mem_filter.mpr ⟨Finset.mem_univ _,partlt⟩⟩· intro e he z hz eqhave same {v} (hv : v ∈ (edges (n*m)).filter (fun e => (G.apart H).labels e = i)) :origin v.1 = origin v.2 := byby_contra nehave c := (Finset.mem_filter.mp hv).2rw [apart_labels,if_neg ne] at chave : G.labels (origin v.1,origin v.2) < r := (G.color ..).isLtomegahave inv := congrArg (fun v : Fin n × (Fin m × Fin m) =>(replica v.1 v.2.1,replica v.1 v.2.2)) eqhave repair {v} (hv : v ∈ (edges (n*m)).filter (fun e => (G.apart H).labels e = i)) :replica (origin v.1) (part v.2) = v.2 := by rw [same hv,replica_origin_part]simpa only [f,replica_origin_part,repair he,repair hz] using invsimpa [S] using hleend PaletteGraphend DecayClassification