Lean / Reader
Lean reader

DecayPaletteGraphs.lean

149 lines10 declarationsno sorryimports DecayProducts DecayCopies DecayConverse

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.

  1. import DecayProducts
  2. import DecayCopies
  3. import DecayConverse
  4. namespace DecayClassification
  5. structure PaletteGraph (n r k : ℕ) where
  6. color : Fin n → Fin n → Fin r
  7. symm : ∀ x y, color x y = color y x
  8. cliques : DecayProducts.BoundedCliques color k
  9. namespace PaletteGraph
  10. def labels {n r k} (G : PaletteGraph n r k) (e : Fin n × Fin n) : ℕ := (G.color e.1 e.2).val
  11. theorem no_clique {n r k} (G : PaletteGraph n r k) (hk : 1 ≤ k) : ¬MonoClique (k+1) G.labels := by
  12. rintro ⟨s,hcard,i,hmono⟩
  13. have two : 1 < s.card := by omega
  14. obtain ⟨x,hx,y,hy,ne⟩ := Finset.one_lt_card.mp two
  15. have ord : ∃ x ∈ s, ∃ y ∈ s, x < y := by
  16. rcases ne.lt_or_gt with h | h
  17. · exact ⟨x,hx,y,hy,h⟩
  18. · exact ⟨y,hy,x,hx,h⟩
  19. obtain ⟨x,hx,y,hy,lt⟩ := ord
  20. have hi : i < r := by rw [← hmono x hx y hy lt]; exact (G.color x y).isLt
  21. have hm : DecayProducts.OneColor G.color ⟨i,hi⟩ s := by
  22. intro u hu v hv hne
  23. apply Fin.ext
  24. rcases hne.lt_or_gt with h | h
  25. · exact hmono u hu v hv h
  26. · rw [G.symm]; exact hmono v hv u hu h
  27. have := G.cliques _ _ hm
  28. omega
  29. theorem transport {V U L H : Type*} [DecidableEq U] (e : V ≃ U) (f : L ≃ H)
  30. {c : U → U → L} {k : ℕ} (bound : DecayProducts.BoundedCliques c k) :
  31. DecayProducts.BoundedCliques (fun x y => f (c (e x) (e y))) k := by
  32. classical
  33. intro col s h
  34. have image_bound : (s.image e).card ≤ k := by
  35. apply bound (f.symm col)
  36. intro x hx y hy ne
  37. obtain ⟨u,hu,rfl⟩ := Finset.mem_image.mp hx
  38. obtain ⟨v,hv,rfl⟩ := Finset.mem_image.mp hy
  39. exact (f.eq_symm_apply).mpr (h u hu v hv (fun eq => ne (congrArg e eq)))
  40. rwa [Finset.card_image_of_injective _ e.injective] at image_bound
  41. def same {n m r p q} (G : PaletteGraph n r p) (H : PaletteGraph m r q) :
  42. PaletteGraph (n*m) r (p*q) where
  43. color x y := DecayProducts.lexSame G.color H.color (finProdFinEquiv.symm x) (finProdFinEquiv.symm y)
  44. symm x y := by
  45. dsimp [DecayProducts.lexSame]
  46. split_ifs with h h' h'
  47. all_goals first | exact G.symm .. | exact H.symm .. | grind
  48. cliques := transport finProdFinEquiv.symm (Equiv.refl _) (DecayProducts.lex_same_clique _ _ G.cliques H.cliques)
  49. def apart {n m r s p q} (G : PaletteGraph n r p) (H : PaletteGraph m s q) :
  50. PaletteGraph (n*m) (r+s) (max p q) where
  51. color x y := finSumFinEquiv (DecayProducts.lexApart G.color H.color (finProdFinEquiv.symm x) (finProdFinEquiv.symm y))
  52. symm x y := by
  53. apply congrArg finSumFinEquiv
  54. dsimp [DecayProducts.lexApart]
  55. split_ifs with h h' h'
  56. all_goals first | rw [G.symm] | rw [H.symm] | grind
  57. cliques := transport finProdFinEquiv.symm finSumFinEquiv (DecayProducts.lex_apart_clique _ _ G.cliques H.cliques)
  58. def power {n r p} (G : PaletteGraph n r p) : (t : ℕ) → PaletteGraph (n^(t+1)) r (p^(t+1))
  59. | 0 => by simpa using G
  60. | t+1 => by simpa only [pow_succ n (t+1),pow_succ p (t+1)] using (power G t).same G
  61. theorem apart_labels {n m r s p q} (G : PaletteGraph n r p) (H : PaletteGraph m s q)
  62. (e : Fin (n*m) × Fin (n*m)) :
  63. (G.apart H).labels e = if origin e.1 = origin e.2 then
  64. r + H.labels (part e.1,part e.2) else G.labels (origin e.1,origin e.2) := by
  65. change ((finSumFinEquiv (if origin e.1 = origin e.2 then
  66. Sum.inr (H.color (part e.1) (part e.2)) else Sum.inl (G.color (origin e.1) (origin e.2)))).val : ℕ) = _
  67. split <;> rfl
  68. theorem old_count {n m r s p q} (G : PaletteGraph n r p) (H : PaletteGraph m s q)
  69. (i : ℕ) (hi : i < r) :
  70. ((edges (n*m)).filter (fun e => (G.apart H).labels e = i)).card ≤
  71. ((edges n).filter (fun e => G.labels e = i)).card * (m*m) := by
  72. classical
  73. let S := ((edges n).filter fun e => G.labels e = i) ×ˢ (Finset.univ : Finset (Fin m × Fin m))
  74. let f (e : Fin (n*m) × Fin (n*m)) := ((origin e.1,origin e.2),(part e.1,part e.2))
  75. have hle : ((edges (n*m)).filter (fun e => (G.apart H).labels e = i)).card ≤ S.card := by
  76. apply Finset.card_le_card_of_injOn f
  77. · intro e he
  78. obtain ⟨hedge,hcol⟩ := Finset.mem_filter.mp he
  79. have lt := (Finset.mem_filter.mp hedge).2
  80. have ne : origin e.1 ≠ origin e.2 := by
  81. intro eq
  82. rw [apart_labels,if_pos eq] at hcol
  83. omega
  84. have earlier : origin e.1 < origin e.2 := lt_of_not_ge (by
  85. intro rev
  86. have hrev := replica_lt (part e.2) (part e.1) (lt_of_le_of_ne rev ne.symm)
  87. simp only [replica_origin_part] at hrev
  88. exact (not_lt_of_ge hrev.le) lt)
  89. exact Finset.mem_product.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_filter.mpr
  90. ⟨Finset.mem_univ _,earlier⟩,by simpa only [apart_labels,if_neg ne] using hcol⟩, Finset.mem_univ _⟩
  91. · intro e _ z _ eq
  92. have inv := congrArg (fun v : (Fin n × Fin n) × (Fin m × Fin m) =>
  93. (replica v.1.1 v.2.1,replica v.1.2 v.2.2)) eq
  94. simpa [f] using inv
  95. simpa [S] using hle
  96. theorem new_count {n m r s p q} (G : PaletteGraph n r p) (H : PaletteGraph m s q)
  97. (i : ℕ) (hi : r ≤ i) :
  98. ((edges (n*m)).filter (fun e => (G.apart H).labels e = i)).card ≤ n*(edges m).card := by
  99. classical
  100. let S := (Finset.univ : Finset (Fin n)) ×ˢ edges m
  101. let f (e : Fin (n*m) × Fin (n*m)) := (origin e.1,(part e.1,part e.2))
  102. have hle : ((edges (n*m)).filter (fun e => (G.apart H).labels e = i)).card ≤ S.card := by
  103. apply Finset.card_le_card_of_injOn f
  104. · intro e he
  105. obtain ⟨hedge,hcol⟩ := Finset.mem_filter.mp he
  106. have lt := (Finset.mem_filter.mp hedge).2
  107. have eq : origin e.1 = origin e.2 := by
  108. by_contra ne
  109. rw [apart_labels,if_neg ne] at hcol
  110. have : G.labels (origin e.1,origin e.2) < r := (G.color ..).isLt
  111. omega
  112. have ee : ∀ w : Fin (n*m), w.val = (part w).val + m*(origin w).val := by
  113. intro w
  114. exact congrArg Fin.val (replica_origin_part w).symm
  115. have partlt : part e.1 < part e.2 := by
  116. change e.1.val < e.2.val at lt
  117. rw [ee e.1,ee e.2,eq] at lt
  118. exact Nat.lt_of_add_lt_add_right lt
  119. exact Finset.mem_product.mpr ⟨Finset.mem_univ _,Finset.mem_filter.mpr ⟨Finset.mem_univ _,partlt⟩⟩
  120. · intro e he z hz eq
  121. have same {v} (hv : v ∈ (edges (n*m)).filter (fun e => (G.apart H).labels e = i)) :
  122. origin v.1 = origin v.2 := by
  123. by_contra ne
  124. have c := (Finset.mem_filter.mp hv).2
  125. rw [apart_labels,if_neg ne] at c
  126. have : G.labels (origin v.1,origin v.2) < r := (G.color ..).isLt
  127. omega
  128. have inv := congrArg (fun v : Fin n × (Fin m × Fin m) =>
  129. (replica v.1 v.2.1,replica v.1 v.2.2)) eq
  130. have repair {v} (hv : v ∈ (edges (n*m)).filter (fun e => (G.apart H).labels e = i)) :
  131. replica (origin v.1) (part v.2) = v.2 := by rw [same hv,replica_origin_part]
  132. simpa only [f,replica_origin_part,repair he,repair hz] using inv
  133. simpa [S] using hle
  134. end PaletteGraph
  135. end DecayClassification