Lean / Reader
Lean reader

Boundary.lean

813 lines109 declarationsno sorryimports OMAReductions.R_oeis_a401670_R1

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports OMAReductions.R_oeis_a401670_R1, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import OMAReductions.R_oeis_a401670_R1
  2. /-! A direct free-square block construction for the first limit in A401670. -/
  3. namespace KingDimer
  4. open OMA.S_oeis_a401670 Filter
  5. open scoped Topology
  6. abbrev Matching (n : ℕ) := {mate : Cell n → Cell n // Function.Involutive mate ∧
  7. ∀ u, mate u ≠ u ∧ Near false n (mate u).1 u.1 ∧ Near false n (mate u).2 u.2}
  8. def flip (n : ℕ) (i : Fin (2*n)) : Fin (2*n) :=
  9. ⟨if i.val % 2 = 0 then i.val + 1 else i.val - 1, by split <;> omega⟩
  10. @[simp] lemma flip_flip (n : ℕ) (i : Fin (2*n)) : flip n (flip n i) = i := by
  11. apply Fin.ext
  12. simp only [flip]
  13. split_ifs <;> omega
  14. lemma flip_ne (n : ℕ) (i : Fin (2*n)) : flip n i ≠ i := by
  15. intro h
  16. have h' := congrArg Fin.val h
  17. simp only [flip] at h'
  18. split_ifs at h' <;> omega
  19. lemma flip_dist (n : ℕ) (i : Fin (2*n)) : Nat.dist (flip n i).val i.val ≤ 1 := by
  20. simp only [flip, Nat.dist]
  21. split_ifs <;> omega
  22. abbrev Axis (n k : ℕ) := (Fin (n/k) × Fin (2*k)) ⊕ Fin (2*(n%k))
  23. def axis (n k : ℕ) : Axis n k ≃ Fin (2*n) :=
  24. ((Equiv.sumCongr finProdFinEquiv (Equiv.refl _)).trans finSumFinEquiv).trans
  25. (finCongr (by have h := Nat.mod_add_div n k; nlinarith))
  26. lemma axis_left (n k : ℕ) (b : Fin (n/k)) (v : Fin (2*k)) :
  27. ((axis n k) (.inl (b, v))).val = v.val + (2*k)*b.val := rfl
  28. lemma axis_right (n k : ℕ) (w : Fin (2*(n%k))) :
  29. ((axis n k) (.inr w)).val = (n/k)*(2*k) + w.val := rfl
  30. abbrev Block (n k : ℕ) := Fin (n/k) × Fin (n/k)
  31. def rawMate {n k : ℕ} (tiles : Block n k → Matching k) :
  32. Axis n k × Axis n k → Axis n k × Axis n k
  33. | (.inl (a, x), .inl (b, y)) =>
  34. let p := (tiles (a,b)).val (x,y)
  35. (.inl (a,p.1), .inl (b,p.2))
  36. | (.inr x, .inl (b, y)) => (.inr x, .inl (b,flip k y))
  37. | (.inl x, .inr y) => (.inl x, .inr (flip (n%k) y))
  38. | (.inr x, .inr y) => (.inr x, .inr (flip (n%k) y))
  39. lemma raw_involutive {n k : ℕ} (tiles : Block n k → Matching k) :
  40. Function.Involutive (rawMate tiles) := by
  41. rintro ⟨⟨a,x⟩ | x, ⟨b,y⟩ | y⟩
  42. · have h := (tiles (a,b)).property.1 (x,y)
  43. simp only [rawMate, Prod.mk.eta, h]
  44. · simp [rawMate]
  45. · simp [rawMate]
  46. · simp [rawMate]
  47. lemma raw_valid {n k : ℕ} (tiles : Block n k → Matching k)
  48. (p : Axis n k × Axis n k) :
  49. rawMate tiles p ≠ p ∧
  50. Near false n (axis n k (rawMate tiles p).1) (axis n k p.1) ∧
  51. Near false n (axis n k (rawMate tiles p).2) (axis n k p.2) := by
  52. rcases p with ⟨⟨a,x⟩ | x, ⟨b,y⟩ | y⟩
  53. · obtain ⟨hne, hx, hy⟩ := (tiles (a,b)).property.2 (x,y)
  54. refine ⟨?_, ?_, ?_⟩
  55. · intro h
  56. simp only [rawMate, Prod.mk.injEq, Sum.inl.injEq, true_and] at h
  57. exact hne (Prod.ext h.1 h.2)
  58. · simpa [Near, rawMate, axis_left, Nat.dist_add_add_right] using hx
  59. · simpa [Near, rawMate, axis_left, Nat.dist_add_add_right] using hy
  60. · simp [rawMate, Near, axis_right, Nat.dist_add_add_left, flip_ne, flip_dist]
  61. · simp [rawMate, Near, axis_left, Nat.dist_add_add_right, flip_ne, flip_dist]
  62. · simp [rawMate, Near, axis_right, Nat.dist_add_add_left, flip_ne, flip_dist]
  63. abbrev board (n k : ℕ) := (axis n k).prodCongr (axis n k)
  64. def glue {n k : ℕ} (tiles : Block n k → Matching k) : Matching n :=
  65. ⟨fun z => board n k (rawMate tiles ((board n k).symm z)), by
  66. constructor
  67. · intro z
  68. simp only [Equiv.symm_apply_apply]
  69. rw [raw_involutive tiles, Equiv.apply_symm_apply]
  70. · intro z
  71. obtain ⟨p, rfl⟩ := (board n k).surjective z
  72. simp only [Equiv.symm_apply_apply]
  73. obtain ⟨hn, hx, hy⟩ := raw_valid tiles p
  74. exact ⟨fun h => hn ((board n k).injective h), hx, hy⟩⟩
  75. lemma glue_injective (n k : ℕ) : Function.Injective (@glue n k) := by
  76. intro A B h
  77. funext b
  78. apply Subtype.ext
  79. funext p
  80. have h' := congrFun (congrArg Subtype.val h) (board n k (.inl (b.1,p.1), .inl (b.2,p.2)))
  81. change board n k (rawMate A _) = board n k (rawMate B _) at h'
  82. simp only [Equiv.symm_apply_apply] at h'
  83. have hin := (board n k).injective h'
  84. simp only [rawMate, Prod.mk.eta, Prod.mk.injEq, Sum.inl.injEq, true_and] at hin
  85. exact Prod.ext hin.1 hin.2
  86. theorem free_pack (n k : ℕ) : tilingCount false k ^ ((n/k)^2) ≤ tilingCount false n := by
  87. have h := Nat.card_le_card_of_injective (@glue n k) (glue_injective n k)
  88. simpa [tilingCount, Matching, Block, Nat.card_fun, Nat.card_prod, Nat.card_fin, pow_two] using h
  89. lemma free_pos (n : ℕ) : 0 < tilingCount false n := by
  90. let mate : Cell n → Cell n := fun p => (p.1, flip n p.2)
  91. have valid : ∀ p, mate p ≠ p ∧ Near false n (mate p).1 p.1 ∧ Near false n (mate p).2 p.2 := by
  92. rintro ⟨x,y⟩
  93. simp [mate, Near, flip_ne, flip_dist]
  94. have inv : Function.Involutive mate := by rintro ⟨x,y⟩; simp [mate]
  95. exact Nat.card_pos_iff.2 ⟨⟨⟨mate, inv, valid⟩⟩, inferInstance⟩
  96. def delta {m : ℕ} (j i : Fin m) (h : Nat.dist j.val i.val ≤ 1) : Fin 3 :=
  97. ⟨j.val + 1 - i.val, by simp only [Nat.dist] at h; omega⟩
  98. def encode {n : ℕ} (M : Matching n) (u : Cell n) : Fin 3 × Fin 3 :=
  99. (delta (M.val u).1 u.1 (by simpa [Near] using (M.property.2 u).2.1),
  100. delta (M.val u).2 u.2 (by simpa [Near] using (M.property.2 u).2.2))
  101. lemma encode_injective (n : ℕ) : Function.Injective (@encode n) := by
  102. intro A B h
  103. apply Subtype.ext
  104. funext u
  105. obtain ⟨_,hA₁,hA₂⟩ := A.property.2 u
  106. obtain ⟨_,hB₁,hB₂⟩ := B.property.2 u
  107. simp [Near, Nat.dist] at hA₁ hA₂ hB₁ hB₂
  108. have hx := congrArg (fun p : Fin 3 × Fin 3 => p.1.val) (congrFun h u)
  109. have hy := congrArg (fun p : Fin 3 × Fin 3 => p.2.val) (congrFun h u)
  110. simp only [encode, delta] at hx hy
  111. apply Prod.ext <;> apply Fin.ext <;> omega
  112. lemma free_upper (n : ℕ) : tilingCount false n ≤ 9^((2*n)^2) := by
  113. have h := Nat.card_le_card_of_injective (@encode n) (encode_injective n)
  114. simpa [tilingCount, Matching, Cell, Nat.card_fun, Nat.card_prod, Nat.card_fin, pow_two] using h
  115. noncomputable def density (n : ℕ) : ℝ := Real.log (tilingCount false n : ℝ) / (4 * (n : ℝ)^2)
  116. lemma density_bd (n : ℕ) : density n ≤ Real.log 9 := by
  117. rcases eq_or_ne n 0 with rfl | hn
  118. · simpa [density] using (Real.log_nonneg (by norm_num : (1:ℝ) ≤ 9))
  119. have h := Real.log_le_log (Nat.cast_pos.mpr (free_pos n))
  120. (by exact_mod_cast free_upper n : (tilingCount false n : ℝ) ≤ (9:ℝ)^((2*n)^2))
  121. rw [Real.log_pow] at h
  122. push_cast at h
  123. unfold density
  124. apply (div_le_iff₀ (by positivity)).2
  125. exact h.trans_eq (by ring)
  126. lemma density_pack {k n : ℕ} (hk : 0 < k) (hkn : k ≤ n) :
  127. density k * (1 - (k : ℝ) / n)^2 ≤ density n := by
  128. have hn : 0 < n := hk.trans_le hkn
  129. have kr : 0 < (k : ℝ) := by exact_mod_cast hk
  130. have nr : 0 < (n : ℝ) := by exact_mod_cast hn
  131. have fr : 0 < (tilingCount false k : ℝ) := by exact_mod_cast free_pos k
  132. have logpos : 0 ≤ Real.log (tilingCount false k : ℝ) := Real.log_nonneg (by exact_mod_cast free_pos k)
  133. have h := Real.log_le_log (pow_pos fr ((n/k)^2))
  134. (by exact_mod_cast free_pack n k : (tilingCount false k : ℝ)^((n/k)^2) ≤ (tilingCount false n : ℝ))
  135. rw [Real.log_pow] at h
  136. push_cast at h
  137. have rem := Nat.mod_lt n hk
  138. have split := Nat.mod_add_div n k
  139. have small : n ≤ (n/k)*k + k := by nlinarith
  140. have small' : (n:ℝ) ≤ (n/k:ℕ)*k + k := by exact_mod_cast small
  141. have bound : ((n:ℝ) - k)^2 ≤ ((n/k:ℕ):ℝ)^2 * (k:ℝ)^2 := by
  142. rw [← mul_pow]
  143. gcongr <;> linarith [show (k:ℝ) ≤ n by exact_mod_cast hkn]
  144. unfold density
  145. calc
  146. _ = Real.log (tilingCount false k : ℝ) * (n-k)^2 / (4*(k:ℝ)^2*(n:ℝ)^2) := by field_simp
  147. _ ≤ Real.log (tilingCount false k : ℝ) * (((n/k:ℕ):ℝ)^2*(k:ℝ)^2) / (4*(k:ℝ)^2*(n:ℝ)^2) := by gcongr
  148. _ = ((n/k:ℕ):ℝ)^2 * Real.log (tilingCount false k : ℝ) / (4*(n:ℝ)^2) := by field_simp
  149. _ ≤ _ := by gcongr
  150. noncomputable def freeEntropy : ℝ := sSup (Set.range fun j : ℕ => density (j+1))
  151. /-- The unrestricted first limit with the original `tilingCount` and a specified limit. -/
  152. theorem density_to_freeEntropy : Tendsto density atTop (𝓝 freeEntropy) := by
  153. let E := Set.range (fun j : ℕ => density (j+1))
  154. have hb : BddAbove E := ⟨Real.log 9, by rintro _ ⟨j,rfl⟩; exact density_bd _⟩
  155. have he : E.Nonempty := ⟨_, ⟨0,rfl⟩⟩
  156. change Tendsto density atTop (𝓝 (sSup E))
  157. apply tendsto_order.2
  158. constructor
  159. · intro b hlt
  160. obtain ⟨_, ⟨j, rfl⟩, hj⟩ := (lt_csSup_iff hb he).1 hlt
  161. let k := j+1
  162. have hz := tendsto_const_div_atTop_nhds_zero_nat (k:ℝ)
  163. have hs : Tendsto (fun n : ℕ => density k * (1 - (k:ℝ)/n)^2)
  164. atTop (𝓝 (density k)) := by
  165. simpa using ((tendsto_const_nhds (x := density k)).mul (((tendsto_const_nhds (x := (1:ℝ))).sub hz).pow 2))
  166. filter_upwards [(tendsto_order.1 hs).1 b hj, eventually_ge_atTop k] with n h₁ h₂
  167. exact lt_of_lt_of_le h₁ (density_pack (Nat.succ_pos _) h₂)
  168. · intro b hb'
  169. filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn
  170. obtain ⟨j, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : n ≠ 0)
  171. exact lt_of_le_of_lt (le_csSup hb ⟨j,rfl⟩) hb'
  172. theorem free_entropy_exists : ∃ s : ℝ,
  173. Tendsto (fun n : ℕ => Real.log (tilingCount false n : ℝ) / (4 * (n : ℝ)^2)) atTop (𝓝 s) :=
  174. ⟨freeEntropy, density_to_freeEntropy⟩
  175. end KingDimer
  176. /-! A finite-state perfect matching on a two-cell collar. -/
  177. namespace KingCollar
  178. variable {α ι : Type*} [DecidableEq α] [DecidableEq ι]
  179. /-- `false` is the outer channel and `true` the inner channel. -/
  180. abbrev Extended (α ι : Type*) := α ⊕ (ι × Bool)
  181. structure Data (α ι : Type*) [DecidableEq α] [DecidableEq ι] where
  182. partialMate : α → α
  183. inv : Function.Involutive partialMate
  184. slot : α → ι
  185. marked : ι → Bool
  186. owner : ι → α
  187. attached : ∀ x, partialMate x = x → marked (slot x) = true ∧ owner (slot x) = x
  188. marked_owner : ∀ i, marked i = true → partialMate (owner i) = owner i ∧ slot (owner i) = i
  189. next : ι ≃ ι
  190. carry : ι → Bool
  191. step : ∀ i, carry (next i) = xor (carry i) (marked i)
  192. def Data.mate (D : Data α ι) : Extended α ι → Extended α ι
  193. | .inl u => if D.partialMate u = u then .inr (D.slot u, true) else .inl (D.partialMate u)
  194. | .inr (i,true) => if D.marked i then .inl (D.owner i)
  195. else if D.carry i then .inr (D.next i, false) else .inr (i, false)
  196. | .inr (i,false) => if D.carry i then .inr (D.next.symm i, !(D.marked (D.next.symm i)))
  197. else if D.marked i then .inr (D.next i, false) else .inr (i, true)
  198. lemma Data.mate_involutive (D : Data α ι) : Function.Involutive D.mate := by
  199. rintro (u | ⟨i,b⟩)
  200. · by_cases h : D.partialMate u = u
  201. · obtain ⟨hm,ho⟩ := D.attached u h
  202. simp [Data.mate,h,hm,ho]
  203. · simp [Data.mate,h,Ne.symm h,D.inv u]
  204. · cases b with
  205. | true =>
  206. cases hm : D.marked i with
  207. | true =>
  208. obtain ⟨hx,hi⟩ := D.marked_owner i hm
  209. simp [Data.mate,hm,hx,hi]
  210. | false =>
  211. cases hc : D.carry i <;> simp [Data.mate,hc,hm,D.step]
  212. | false =>
  213. cases hc : D.carry i with
  214. | false => cases hm : D.marked i <;> simp [Data.mate,hc,hm,D.step]
  215. | true =>
  216. obtain ⟨j,rfl⟩ := D.next.surjective i
  217. have hs := D.step j
  218. cases hm : D.marked j <;> cases hj : D.carry j <;> simp_all [Data.mate]
  219. lemma Data.mate_ne (D : Data α ι) (hmove : ∀ i, D.next i ≠ i) (p : Extended α ι) : D.mate p ≠ p := by
  220. cases p with
  221. | inl u => by_cases h : D.partialMate u = u <;> simp [Data.mate,h]
  222. | inr p =>
  223. rcases p with ⟨i,b⟩
  224. have back : D.next.symm i ≠ i := by
  225. intro h
  226. exact hmove i (by rw [← h, D.next.apply_symm_apply, h])
  227. cases b <;> cases hc : D.carry i <;> cases hm : D.marked i <;>
  228. simp [Data.mate,hc,hm,hmove,back]
  229. lemma Data.mate_rel (D : Data α ι) (R : Extended α ι → Extended α ι → Prop)
  230. (symm : ∀ {u v}, R u v → R v u)
  231. (old : ∀ u, D.partialMate u ≠ u → R (.inl u) (.inl (D.partialMate u)))
  232. (hang : ∀ u, D.partialMate u = u → R (.inl u) (.inr (D.slot u,true)))
  233. (rad : ∀ i, R (.inr (i,false)) (.inr (i,true)))
  234. (ahead : ∀ i b, R (.inr (i,b)) (.inr (D.next i,false))) : ∀ z, R z (D.mate z) := by
  235. rintro (u | ⟨i,b⟩)
  236. · by_cases h : D.partialMate u=u
  237. · simpa [Data.mate,h] using hang u h
  238. · simpa [Data.mate,h] using old u h
  239. · cases b with
  240. | false =>
  241. cases hc : D.carry i with
  242. | false =>
  243. cases hm : D.marked i
  244. · simpa [Data.mate,hc,hm] using rad i
  245. · simpa [Data.mate,hc,hm] using ahead i false
  246. | true =>
  247. simpa [Data.mate,hc] using symm (ahead (D.next.symm i) (!(D.marked (D.next.symm i))))
  248. | true =>
  249. cases hm : D.marked i with
  250. | true =>
  251. obtain ⟨hx,hi⟩ := D.marked_owner i hm
  252. simpa [Data.mate,hm,hi] using symm (hang (D.owner i) hx)
  253. | false =>
  254. cases hc : D.carry i
  255. · simpa [Data.mate,hc,hm] using symm (rad i)
  256. · simpa [Data.mate,hc,hm] using ahead i true
  257. end KingCollar
  258. namespace KingCollar
  259. def cycle {m : ℕ} (hm : 1 < m) : Fin m ≃ Fin m where
  260. toFun i := ⟨if i.val+1 < m then i.val+1 else 0, by split <;> omega⟩
  261. invFun i := ⟨if i.val=0 then m-1 else i.val-1, by split <;> omega⟩
  262. left_inv i := by have hi := i.isLt; apply Fin.ext; dsimp; split_ifs at * <;> omega
  263. right_inv i := by have hi := i.isLt; apply Fin.ext; dsimp; split_ifs at * <;> omega
  264. lemma cycle_move {m : ℕ} (hm : 1 < m) (i : Fin m) : cycle hm i ≠ i := by
  265. intro h
  266. have h' := congrArg Fin.val h
  267. simp only [cycle, Equiv.coe_fn_mk] at h'
  268. split_ifs at h' <;> omega
  269. def before {m : ℕ} (S : Finset (Fin m)) (r : ℕ) : ℕ := (S.filter fun j => j.val < r).card
  270. lemma before_zero {m : ℕ} (S : Finset (Fin m)) : before S 0 = 0 := by simp [before]
  271. lemma before_full {m : ℕ} (S : Finset (Fin m)) : before S m = S.card := by simp [before]
  272. lemma before_succ {m : ℕ} (S : Finset (Fin m)) (i : Fin m) : before S (i.val+1) =
  273. before S i.val + if i ∈ S then 1 else 0 := by
  274. classical
  275. by_cases hi : i ∈ S
  276. · have heq : (S.filter fun j => j.val < i.val+1) = insert i (S.filter fun j => j.val < i.val) := by
  277. ext j
  278. by_cases h : j=i
  279. · subst j; simp [hi]
  280. · have hne : j.val ≠ i.val := fun H => h (Fin.ext H)
  281. simp only [Finset.mem_filter,Finset.mem_insert,h,false_or]
  282. constructor <;> rintro ⟨hs,hlt⟩ <;> exact ⟨hs,by omega⟩
  283. unfold before
  284. rw [heq,Finset.card_insert_of_notMem (by simp),if_pos hi]
  285. · have heq : (S.filter fun j => j.val < i.val+1) = S.filter fun j => j.val < i.val := by
  286. ext j
  287. by_cases h : j=i
  288. · subst j; simp [hi]
  289. · have hne : j.val ≠ i.val := fun H => h (Fin.ext H)
  290. simp only [Finset.mem_filter]
  291. constructor <;> rintro ⟨hs,hlt⟩ <;> exact ⟨hs,by omega⟩
  292. unfold before
  293. rw [heq,if_neg hi,Nat.add_zero]
  294. def flag {m : ℕ} (S : Finset (Fin m)) (i : Fin m) : Bool := decide (before S i.val % 2 = 1)
  295. lemma flag_step {m : ℕ} (hm : 1 < m) (S : Finset (Fin m)) (he : S.card % 2 = 0)
  296. (i : Fin m) : flag S (cycle hm i) = xor (flag S i) (decide (i ∈ S)) := by
  297. have hs := before_succ S i
  298. by_cases hn : i.val+1 < m
  299. · simp only [flag,cycle,Equiv.coe_fn_mk,if_pos hn]
  300. by_cases hi : i ∈ S <;> by_cases ho : before S i.val % 2 = 1 <;>
  301. simp [hi,ho] at hs ⊢ <;> omega
  302. · have hlast : i.val+1 = m := by omega
  303. rw [hlast,before_full] at hs
  304. simp only [flag,cycle,Equiv.coe_fn_mk,if_neg hn,before_zero]
  305. by_cases hi : i ∈ S <;> by_cases ho : before S i.val % 2 = 1 <;>
  306. simp [hi,ho] at hs ⊢ <;> omega
  307. end KingCollar
  308. namespace KingCollar
  309. abbrev Pt (L : ℕ) := Fin L × Fin L
  310. abbrev Ring (L : ℕ) := Fin 4 × Fin (L+2)
  311. abbrev Pair := ℕ × ℕ
  312. def coords {L : ℕ} (u : Pt L) : Pair := (u.1.val,u.2.val)
  313. def turn (L : ℕ) (q : Fin 4) (p : Pair) : Pair :=
  314. match q.val with
  315. | 0 => p
  316. | 1 => (p.2,L+3-p.1)
  317. | 2 => (L+3-p.1,L+3-p.2)
  318. | _ => (L+3-p.2,p.1)
  319. def unt (L : ℕ) (q : Fin 4) (p : Pair) : Pair :=
  320. match q.val with
  321. | 0 => p
  322. | 1 => (L+3-p.2,p.1)
  323. | 2 => (L+3-p.1,L+3-p.2)
  324. | _ => (p.2,L+3-p.1)
  325. def quad (L : ℕ) (p : Pair) : ℕ :=
  326. if p.1 < 2 ∧ 2 ≤ p.2 then 0 else if L+2 ≤ p.2 ∧ 2 ≤ p.1 then 1
  327. else if L+2 ≤ p.1 ∧ p.2 < L+2 then 2 else 3
  328. def top (L : ℕ) (t : ℕ) (b : Bool) : Pair :=
  329. if t<L then (b.toNat, t+2) else if t=L then (0,L+2+b.toNat) else (1,L+3-b.toNat)
  330. lemma top_bounds (L : ℕ) (t : Fin (L+2)) (b : Bool) :
  331. (top L t b).1 < 2 ∧ 2 ≤ (top L t b).2 ∧ (top L t b).2 < L+4 := by
  332. cases b <;> simp [top] <;> split_ifs <;> simp_all
  333. lemma top_inj {L : ℕ} {t u : Fin (L+2)} {b c : Bool} (h : top L t b = top L u c) : t=u ∧ b=c := by
  334. have ht := t.isLt
  335. have hu := u.isLt
  336. cases b <;> cases c <;> simp only [top,Bool.toNat] at h <;> split_ifs at h <;>
  337. simp_all [Prod.mk.injEq,Fin.ext_iff] <;> omega
  338. lemma where_turn (L : ℕ) (q : Fin 4) (p : Pair) (hr : p.1<2) (hc : 2≤p.2) (hd : p.2<L+4) :
  339. quad L (turn L q p) = q.val ∧ unt L q (turn L q p) = p ∧
  340. (turn L q p).1 < L+4 ∧ (turn L q p).2 < L+4 := by
  341. rcases p with ⟨x,y⟩
  342. dsimp at hr hc hd
  343. fin_cases q <;> simp [turn,unt,quad] <;> split_ifs <;> simp_all <;> omega
  344. def outside {L : ℕ} (i : Ring L) (b : Bool) : Pt (L+4) :=
  345. let p := turn L i.1 (top L i.2 b)
  346. let h := top_bounds L i.2 b
  347. let h' := where_turn L i.1 _ h.1 h.2.1 h.2.2
  348. (⟨p.1,h'.2.2.1⟩,⟨p.2,h'.2.2.2⟩)
  349. def inside {L : ℕ} (p : Pt L) : Pt (L+4) :=
  350. (⟨p.1.val+2,by omega⟩,⟨p.2.val+2,by omega⟩)
  351. lemma outside_inj {L : ℕ} {i j : Ring L} {b c : Bool}
  352. (h : outside i b = outside j c) : i=j ∧ b=c := by
  353. rcases i with ⟨q,t⟩; rcases j with ⟨s,u⟩
  354. have hp := congrArg coords h
  355. change turn L q (top L t b) = turn L s (top L u c) at hp
  356. obtain ⟨h₁,h₂,h₃⟩ := top_bounds L t b
  357. obtain ⟨k₁,k₂,k₃⟩ := top_bounds L u c
  358. obtain ⟨hq,huq,_⟩ := where_turn L q _ h₁ h₂ h₃
  359. obtain ⟨hs,hus,_⟩ := where_turn L s _ k₁ k₂ k₃
  360. have eq : q=s := Fin.ext (hq.symm.trans ((congrArg (quad L) hp).trans hs))
  361. subst s
  362. have ht := top_inj (huq.symm.trans ((congrArg (unt L q) hp).trans hus))
  363. simp [ht.1,ht.2]
  364. lemma outside_border {L : ℕ} (i : Ring L) (b : Bool) :
  365. (outside i b).1.val < 2 ∨ (outside i b).2.val < 2 ∨
  366. L+2 ≤ (outside i b).1.val ∨ L+2 ≤ (outside i b).2.val := by
  367. obtain ⟨hr,_,_⟩ := top_bounds L i.2 b
  368. rcases i with ⟨q,t⟩
  369. fin_cases q <;> simp [outside,turn] at * <;> omega
  370. def place {L : ℕ} : Pt L ⊕ (Ring L × Bool) → Pt (L+4)
  371. | .inl x => inside x
  372. | .inr (i,b) => outside i b
  373. lemma place_injective (L : ℕ) : Function.Injective (@place L) := by
  374. have separate (x : Pt L) (i : Ring L) (b : Bool) : inside x ≠ outside i b := by
  375. intro h
  376. have bor := outside_border i b
  377. rw [← h] at bor
  378. dsimp [inside] at bor
  379. omega
  380. rintro (x | ⟨i,b⟩) (y | ⟨j,c⟩) h
  381. · have h' := congrArg coords h
  382. dsimp [place,inside,coords] at h'
  383. simp only [Prod.mk.injEq,Nat.add_right_cancel_iff] at h'
  384. exact congrArg Sum.inl (Prod.ext (Fin.ext h'.1) (Fin.ext h'.2))
  385. · exact (separate _ _ _ h).elim
  386. · exact (separate _ _ _ h.symm).elim
  387. · obtain ⟨rfl,rfl⟩ := outside_inj h
  388. rfl
  389. noncomputable def placeEquiv (L : ℕ) : Pt L ⊕ (Ring L × Bool) ≃ Pt (L+4) :=
  390. Equiv.ofBijective place ((Fintype.bijective_iff_injective_and_card _).2
  391. ⟨place_injective L,by simp [Pt,Ring,Fintype.card_prod]; ring⟩)
  392. end KingCollar
  393. namespace KingCollar
  394. def Adj (p q : Pair) : Prop := Nat.dist p.1 q.1 ≤ 1 ∧ Nat.dist p.2 q.2 ≤ 1
  395. lemma Adj.symm {p q : Pair} (h : Adj p q) : Adj q p := by simpa [Adj,Nat.dist_comm] using h
  396. abbrev rank (L : ℕ) : Ring L ≃ Fin (4*(L+2)) := finProdFinEquiv
  397. def advance (L : ℕ) : Ring L ≃ Ring L :=
  398. ((rank L).trans (cycle (by omega))).trans (rank L).symm
  399. def nextPair (L : ℕ) (i : Ring L) : Ring L :=
  400. if h : i.2.val+1<L+2 then (i.1,⟨i.2.val+1,h⟩)
  401. else (⟨if i.1.val<3 then i.1.val+1 else 0,by split <;> omega⟩,0)
  402. lemma advance_eq (L : ℕ) (i : Ring L) : advance L i = nextPair L i := by
  403. apply (rank L).injective
  404. change (rank L) ((rank L).symm (cycle (by omega) ((rank L) i))) = _
  405. rw [Equiv.apply_symm_apply]
  406. apply Fin.ext
  407. rcases i with ⟨q,t⟩
  408. have ht := t.isLt
  409. fin_cases q <;> simp [cycle,rank,finProdFinEquiv,nextPair] <;>
  410. split_ifs <;> simp_all <;> omega
  411. lemma advance_move (L : ℕ) (i : Ring L) : advance L i ≠ i := by
  412. intro h
  413. have hp := congrArg (rank L) h
  414. change (rank L) ((rank L).symm (cycle (by omega) ((rank L) i))) = (rank L) i at hp
  415. rw [Equiv.apply_symm_apply] at hp
  416. exact cycle_move _ _ hp
  417. lemma radial_adj (L : ℕ) (i : Ring L) : Adj (coords (outside i false)) (coords (outside i true)) := by
  418. rcases i with ⟨q,t⟩
  419. have ht := t.isLt
  420. fin_cases q <;> simp [outside,coords,Adj,top,turn,Nat.dist] <;> split_ifs <;> simp_all
  421. lemma turn_adj (L : ℕ) (q : Fin 4) (p r : Pair) (hp : p.1<L+4 ∧ p.2<L+4)
  422. (hr : r.1<L+4 ∧ r.2<L+4) (h : Adj p r) : Adj (turn L q p) (turn L q r) := by
  423. rcases p with ⟨a,b⟩; rcases r with ⟨c,d⟩
  424. fin_cases q <;> simp [turn,Adj,Nat.dist] at * <;> omega
  425. lemma ahead_adj (L : ℕ) (i : Ring L) (b : Bool) :
  426. Adj (coords (outside i b)) (coords (outside (advance L i) false)) := by
  427. rw [advance_eq]
  428. rcases i with ⟨q,t⟩
  429. have ht := t.isLt
  430. by_cases hn : t.val+1<L+2
  431. · simp only [nextPair,dif_pos hn]
  432. change Adj (turn L q (top L t b)) (turn L q (top L (t.val+1) false))
  433. obtain ⟨h₁,_,h₂⟩ := top_bounds L t b
  434. obtain ⟨k₁,_,k₂⟩ := top_bounds L ⟨t.val+1,hn⟩ false
  435. apply turn_adj L q _ _ ⟨by omega,h₂⟩ ⟨by exact lt_trans k₁ (by omega),k₂⟩
  436. cases b <;> simp [Adj,top,Nat.dist] <;> split_ifs <;> simp_all <;> omega
  437. · have he : t.val=L+1 := by omega
  438. cases L with
  439. | zero => fin_cases q <;> cases b <;> simp [outside,coords,Adj,turn,nextPair,he,Nat.dist,top]
  440. | succ L => fin_cases q <;> cases b <;> simp [outside,coords,Adj,turn,nextPair,he,Nat.dist,top]
  441. def Border {L : ℕ} (x : Pt L) : Prop :=
  442. x.1.val = 0 ∨ x.2.val+1 = L ∨ x.1.val+1 = L ∨ x.2.val = 0
  443. def slot {L : ℕ} (x : Pt L) : Ring L :=
  444. if x.1.val=0 then (0,⟨x.2.val,by omega⟩)
  445. else if x.2.val+1=L then (1,⟨x.1.val,by omega⟩)
  446. else if x.1.val+1=L then (2,⟨L-1-x.2.val,by omega⟩)
  447. else (3,⟨L-1-x.1.val,by omega⟩)
  448. def decodeSlot {L : ℕ} (i : Ring L) : Pair :=
  449. match i.1.val with
  450. | 0 => (0,i.2.val)
  451. | 1 => (i.2.val,L-1)
  452. | 2 => (L-1,L-1-i.2.val)
  453. | _ => (L-1-i.2.val,0)
  454. lemma decode_slot {L : ℕ} (p : Pt L) (hp : Border p) : decodeSlot (slot p) = coords p := by
  455. rcases p with ⟨x,y⟩
  456. have hx := x.isLt
  457. have hy := y.isLt
  458. simp only [Border,coords,slot] at *
  459. split_ifs <;> simp [decodeSlot] <;> omega
  460. lemma slot_injective {L : ℕ} {x y : Pt L} (hx : Border x) (hy : Border y) (h : slot x = slot y) : x=y := by
  461. have hc := (decode_slot x hx).symm.trans ((congrArg decodeSlot h).trans (decode_slot y hy))
  462. exact Prod.ext (Fin.ext (congrArg Prod.fst hc)) (Fin.ext (congrArg Prod.snd hc))
  463. lemma attachment_adj {L : ℕ} (p : Pt L) (hp : Border p) :
  464. Adj (coords (inside p)) (coords (outside (slot p) true)) := by
  465. rcases p with ⟨x,y⟩
  466. have hx := x.isLt
  467. have hy := y.isLt
  468. simp only [Border,slot] at *
  469. split_ifs <;> simp [coords,inside,outside,turn,top,Adj,Nat.dist] <;>
  470. (try split_ifs) <;> simp_all <;> omega
  471. lemma inner_adj {L : ℕ} {p q : Pt L} (h : Adj (coords p) (coords q)) :
  472. Adj (coords (inside p)) (coords (inside q)) := by
  473. simpa [Adj,coords,inside,Nat.dist_add_add_right] using h
  474. end KingCollar
  475. namespace KingCollar
  476. open OMA.S_oeis_a401670
  477. abbrev Matched (w : Bool) (n : ℕ) := {mate : Cell n → Cell n // Function.Involutive mate ∧
  478. ∀ u, mate u ≠ u ∧ Near w n (mate u).1 u.1 ∧ Near w n (mate u).2 u.2}
  479. instance decAdj (p q : Pair) : Decidable (Adj p q) := by unfold Adj; infer_instance
  480. def cleaned {n : ℕ} (M : Matched true n) (u : Cell n) : Cell n :=
  481. if Adj (coords (M.val u)) (coords u) then M.val u else u
  482. lemma cleaned_inv {n : ℕ} (M : Matched true n) : Function.Involutive (cleaned M) := by
  483. intro u
  484. by_cases h : Adj (coords (M.val u)) (coords u)
  485. · simp [cleaned,h,M.property.1 u,h.symm]
  486. · simp [cleaned,h]
  487. lemma cleaned_fix {n : ℕ} (M : Matched true n) (u : Cell n) : cleaned M u = u ↔
  488. ¬Adj (coords (M.val u)) (coords u) := by
  489. simp [cleaned,(M.property.2 u).1]
  490. lemma fixed_border {n : ℕ} (M : Matched true n) (u : Cell n) (hu : cleaned M u=u) : Border u := by
  491. have hn := (cleaned_fix M u).1 hu
  492. obtain ⟨_,hx,hy⟩ := M.property.2 u
  493. have hu₁ := u.1.isLt; have hu₂ := u.2.isLt
  494. have hm₁ := (M.val u).1.isLt; have hm₂ := (M.val u).2.isLt
  495. simp [Near,Adj,coords,Border,Nat.dist] at *
  496. omega
  497. lemma cleaned_adj {n : ℕ} (M : Matched true n) (u : Cell n) : Adj (coords u) (coords (cleaned M u)) := by
  498. by_cases h : Adj (coords (M.val u)) (coords u)
  499. · simpa [cleaned,h] using h.symm
  500. · rw [cleaned,if_neg h]
  501. simp [Adj]
  502. def fixedCells {n : ℕ} (M : Matched true n) : Finset (Cell n) :=
  503. Finset.univ.filter fun u => cleaned M u=u
  504. lemma card_fixed_even {n : ℕ} (M : Matched true n) : (fixedCells M).card%2=0 := by
  505. classical
  506. let f : Function.End (Cell n) := cleaned M
  507. have hpow : f ^ 2 ^ 1 = 1 := by
  508. funext x
  509. change cleaned M (cleaned M x) = x
  510. exact cleaned_inv M x
  511. have h := Equiv.Perm.card_fixedPoints_modEq (p:=2) (n:=1) hpow
  512. have eqn : Fintype.card (Function.fixedPoints f) = (fixedCells M).card := by
  513. rw [← Fintype.card_coe]
  514. apply Fintype.card_congr
  515. apply Equiv.subtypeEquivRight
  516. intro x
  517. simp [Function.fixedPoints,Function.IsFixedPt,f,fixedCells]
  518. rw [eqn] at h
  519. simpa [Nat.ModEq,Cell,Fintype.card_prod,Nat.mul_mod] using h.symm
  520. def markedSet {n : ℕ} (M : Matched true n) : Finset (Ring (2*n)) := (fixedCells M).image slot
  521. lemma mem_marked {n : ℕ} (M : Matched true n) (i : Ring (2*n)) : i ∈ markedSet M ↔
  522. ∃ u, cleaned M u=u ∧ slot u=i := by simp [markedSet,fixedCells]
  523. lemma marked_even {n : ℕ} (M : Matched true n) : (markedSet M).card%2=0 := by
  524. have hin : Set.InjOn (@slot (2*n)) (↑(fixedCells M) : Set (Cell n)) := by
  525. intro x hx y hy hxy
  526. simp [fixedCells] at hx hy
  527. exact slot_injective (fixed_border M x hx) (fixed_border M y hy) hxy
  528. rw [markedSet,Finset.card_image_of_injOn hin]
  529. exact card_fixed_even M
  530. noncomputable def owner {n : ℕ} (hn : 0<n) (M : Matched true n) (i : Ring (2*n)) : Cell n :=
  531. if h : i ∈ markedSet M then ((mem_marked M i).1 h).choose else (⟨0,by omega⟩,⟨0,by omega⟩)
  532. lemma owner_spec {n : ℕ} (hn : 0<n) (M : Matched true n) (i : Ring (2*n)) (hm : i ∈ markedSet M) :
  533. cleaned M (owner hn M i) = owner hn M i ∧ slot (owner hn M i) = i := by
  534. simpa only [owner,dif_pos hm] using ((mem_marked M i).1 hm).choose_spec
  535. noncomputable def collarData {n : ℕ} (hn : 0<n) (M : Matched true n) : Data (Cell n) (Ring (2*n)) where
  536. partialMate := cleaned M
  537. inv := cleaned_inv M
  538. slot := slot
  539. marked i := decide (i ∈ markedSet M)
  540. owner := owner hn M
  541. attached u hu := by
  542. have hm := (mem_marked M _).2 ⟨u,hu,rfl⟩
  543. obtain ⟨hfix,hs⟩ := owner_spec hn M _ hm
  544. exact ⟨by simpa using hm, slot_injective (fixed_border M _ hfix) (fixed_border M _ hu) hs⟩
  545. marked_owner i hm := owner_spec hn M i (by simpa using hm)
  546. next := advance _
  547. carry i := flag ((markedSet M).map (rank (2*n)).toEmbedding) (rank _ i)
  548. step i := by
  549. have he : ((markedSet M).map (rank (2*n)).toEmbedding).card%2=0 := by simpa using marked_even M
  550. have hh := flag_step (by omega : 1 < 4*(2*n+2)) _ he (rank _ i)
  551. have hr : rank (2*n) (advance (2*n) i) = cycle (by omega) (rank (2*n) i) :=
  552. (rank (2*n)).apply_symm_apply _
  553. rw [hr]
  554. simpa using hh
  555. end KingCollar
  556. namespace KingCollar
  557. open OMA.S_oeis_a401670
  558. noncomputable def big (n : ℕ) : Extended (Cell n) (Ring (2*n)) ≃ Cell (n+2) :=
  559. (placeEquiv (2*n)).trans ((finCongr (by omega)).prodCongr (finCongr (by omega)))
  560. lemma big_coords (n : ℕ) (p : Extended (Cell n) (Ring (2*n))) : coords (big n p) = coords (place p) := rfl
  561. noncomputable def enlarge {n : ℕ} (hn : 0<n) (M : Matched true n) : Matched false (n+2) := by
  562. let D := collarData hn M
  563. refine ⟨fun u => big n (D.mate ((big n).symm u)), ?_, ?_⟩
  564. · intro u
  565. simp only [Equiv.symm_apply_apply]
  566. rw [D.mate_involutive,Equiv.apply_symm_apply]
  567. · intro u
  568. obtain ⟨p,rfl⟩ := (big n).surjective u
  569. simp only [Equiv.symm_apply_apply]
  570. let R (x y : Extended (Cell n) (Ring (2*n))) := Adj (coords (place x)) (coords (place y))
  571. have rel := D.mate_rel R (fun h => h.symm)
  572. (fun x _ => inner_adj (cleaned_adj M x))
  573. (fun x hx => attachment_adj x (fixed_border M x hx))
  574. (radial_adj _) (ahead_adj _) p
  575. have had : Adj (coords (big n (D.mate p))) (coords (big n p)) := rel.symm
  576. exact ⟨fun h => D.mate_ne (advance_move _) _ ((big n).injective h), Or.inl had.1, Or.inl had.2⟩
  577. def axisCode {m : ℕ} (x y : Fin m) : Fin 5 :=
  578. if x.val=y.val then 0 else if x.val+1=y.val then 1 else if y.val+1=x.val then 2
  579. else if x.val<y.val then 3 else 4
  580. lemma axis_decode {n : ℕ} {x y z : Fin (2*n)} (hy : Near true n y x) (hz : Near true n z x)
  581. (h : axisCode x y = axisCode x z) : y=z := by
  582. apply Fin.ext
  583. have hv := congrArg Fin.val h
  584. simp [Near,Nat.dist] at hy hz
  585. simp only [axisCode] at hv
  586. split_ifs at hv <;> norm_num at hv <;> omega
  587. def code {n : ℕ} (M : Matched true n) (x : Cell n) : Fin 5 × Fin 5 :=
  588. (axisCode x.1 (M.val x).1,axisCode x.2 (M.val x).2)
  589. lemma code_decode {n : ℕ} (A B : Matched true n) (x : Cell n) (h : code A x = code B x) : A.val x=B.val x :=
  590. Prod.ext (axis_decode (A.property.2 x).2.1 (B.property.2 x).2.1 (congrArg Prod.fst h))
  591. (axis_decode (A.property.2 x).2.2 (B.property.2 x).2.2 (congrArg Prod.snd h))
  592. noncomputable def boundaryCode {n : ℕ} (hn : 0<n) (M : Matched true n) (i : Ring (2*n)) : Fin 5 × Fin 5 :=
  593. code M (owner hn M i)
  594. lemma owner_of_fixed {n : ℕ} (hn : 0<n) (M : Matched true n) (u : Cell n) (hu : cleaned M u=u) :
  595. owner hn M (slot u) = u := ((collarData hn M).attached u hu).2
  596. lemma clean_old {n : ℕ} (M : Matched true n) (u : Cell n) (hu : cleaned M u≠u) : cleaned M u = M.val u := by
  597. have h : Adj (coords (M.val u)) (coords u) := by
  598. by_contra hf
  599. exact hu ((cleaned_fix M u).2 hf)
  600. simp [cleaned,h]
  601. lemma enlarge_inj {n : ℕ} (hn : 0<n) :
  602. Function.Injective (fun M : Matched true n => (enlarge hn M,boundaryCode hn M)) := by
  603. intro A B h
  604. have hf := congrArg (fun p : Matched false (n+2) × (Ring (2*n) → Fin 5 × Fin 5) => p.1.val) h
  605. have hb := congrArg Prod.snd h
  606. apply Subtype.ext
  607. funext u
  608. have hbig := congrFun hf (big n (.inl u))
  609. change big n ((collarData hn A).mate ((big n).symm (big n (.inl u)))) =
  610. big n ((collarData hn B).mate ((big n).symm (big n (.inl u)))) at hbig
  611. simp only [Equiv.symm_apply_apply] at hbig
  612. have hm := (big n).injective hbig
  613. change (if cleaned A u=u then Sum.inr (slot u,true) else Sum.inl (cleaned A u)) =
  614. (if cleaned B u=u then Sum.inr (slot u,true) else Sum.inl (cleaned B u)) at hm
  615. by_cases ha : cleaned A u=u <;> by_cases hb' : cleaned B u=u
  616. · apply code_decode
  617. simpa only [boundaryCode,owner_of_fixed hn A u ha,owner_of_fixed hn B u hb'] using congrFun hb (slot u)
  618. · simp [ha,hb'] at hm
  619. · simp [ha,hb'] at hm
  620. · simp only [if_neg ha,if_neg hb',Sum.inl.injEq] at hm
  621. simpa only [clean_old A u ha,clean_old B u hb'] using hm
  622. theorem torus_enlarge_bound {n : ℕ} (hn : 0<n) :
  623. tilingCount true n ≤ tilingCount false (n+2) * 25^(4*(2*n+2)) := by
  624. have h := Nat.card_le_card_of_injective _ (enlarge_inj hn)
  625. simpa [tilingCount,Matched,Ring,Nat.card_prod,Nat.card_fun,Nat.card_fin] using h
  626. lemma free_le_torus (n : ℕ) : tilingCount false n ≤ tilingCount true n := by
  627. let f (M : Matched false n) : Matched true n := ⟨M.val,M.property.1, fun x =>
  628. ⟨(M.property.2 x).1,Or.inl (by simpa [Near] using (M.property.2 x).2.1),
  629. Or.inl (by simpa [Near] using (M.property.2 x).2.2)⟩⟩
  630. exact Nat.card_le_card_of_injective f (fun A B h => Subtype.ext (congrArg (fun z : Matched true n => z.val) h))
  631. end KingCollar
  632. namespace KingCollar
  633. open KingDimer OMA.S_oeis_a401670 Filter
  634. open scoped Topology
  635. lemma shifted_free_limit : Tendsto (fun n : ℕ =>
  636. Real.log (tilingCount false (n+2) : ℝ) / (4*(n:ℝ)^2)) atTop (𝓝 freeEntropy) := by
  637. have base := density_to_freeEntropy.comp (tendsto_add_atTop_nat 2)
  638. have factor : Tendsto (fun n : ℕ => (1+(2:ℝ)/n)^2) atTop (𝓝 1) := by
  639. simpa using ((tendsto_const_nhds (x:=(1:ℝ))).add (tendsto_const_div_atTop_nhds_zero_nat (2:ℝ))).pow 2
  640. have h := base.mul factor
  641. simp only [mul_one] at h
  642. apply h.congr'
  643. filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn
  644. have hnr : (n:ℝ) ≠ 0 := by exact_mod_cast (by omega : n ≠ 0)
  645. simp only [Function.comp_apply,density,Nat.cast_add,Nat.cast_ofNat]
  646. field_simp
  647. lemma torus_log_bound {n : ℕ} (hn : 0<n) :
  648. Real.log (tilingCount true n : ℝ) ≤ Real.log (tilingCount false (n+2) : ℝ) +
  649. (4*(2*(n:ℝ)+2))*Real.log 25 := by
  650. have hp : 0 < (tilingCount true n : ℝ) := by exact_mod_cast (free_pos n).trans_le (free_le_torus n)
  651. have hu : (tilingCount true n : ℝ) ≤ (tilingCount false (n+2) : ℝ)*(25:ℝ)^(4*(2*n+2)) := by
  652. exact_mod_cast torus_enlarge_bound hn
  653. have h := Real.log_le_log hp hu
  654. have hf : 0 < (tilingCount false (n+2) : ℝ) := by exact_mod_cast free_pos _
  655. rw [Real.log_mul hf.ne' (by positivity),Real.log_pow] at h
  656. push_cast at h
  657. exact h
  658. /-- Boundary effects in the registered torus model vanish after division by area. -/
  659. theorem boundary_limit : OMA.R_oeis_a401670_R1.H2 := by
  660. let E (n : ℕ) := Real.log 25 * (2/(n:ℝ) + 2/(n:ℝ)^2)
  661. have hz := tendsto_const_div_atTop_nhds_zero_nat (2:ℝ)
  662. have hz2 : Tendsto (fun n : ℕ => (2:ℝ)/(n:ℝ)^2) atTop (𝓝 0) := by
  663. simpa only [div_mul_div_comm,mul_one,← sq,zero_pow (by decide : 2≠0)] using
  664. hz.mul (tendsto_const_div_atTop_nhds_zero_nat (1:ℝ))
  665. have he : Tendsto E atTop (𝓝 0) := by simpa [E] using (hz.add hz2).const_mul (Real.log 25)
  666. have upper := (shifted_free_limit.sub density_to_freeEntropy).add he
  667. simp only [sub_self,add_zero] at upper
  668. apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds upper
  669. · filter_upwards with n
  670. apply div_nonneg _ (by positivity)
  671. apply sub_nonneg.mpr
  672. exact Real.log_le_log (by exact_mod_cast free_pos n) (by exact_mod_cast free_le_torus n)
  673. · filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn
  674. have nr : 0 < (n:ℝ) := by exact_mod_cast hn
  675. have hb := torus_log_bound hn
  676. dsimp [density,E]
  677. calc
  678. _ ≤ (Real.log (tilingCount false (n+2) : ℝ) + (4*(2*(n:ℝ)+2))*Real.log 25 - Real.log (tilingCount false n : ℝ)) /
  679. (4*(n:ℝ)^2) := by gcongr
  680. _ = _ := by field_simp; ring
  681. end KingCollar
  682. theorem OMA.solution : OMA.R_oeis_a401670_R1.H2 := KingCollar.boundary_limit