Lean / Reader
Lean reader

CubeSpectrum.lean

166 lines18 declarationsno sorryimports CubeSpectrum.Entries CubeSpectrum.Certificates Mathlib.Topology.Order.IntermediateValue Mathlib.Topology.Instances.Real.Lemmas

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

  1. import CubeSpectrum.Entries
  2. import CubeSpectrum.Certificates
  3. import Mathlib.Topology.Order.IntermediateValue
  4. import Mathlib.Topology.Instances.Real.Lemmas
  5. namespace CubeSpectrum
  6. noncomputable section
  7. def top : (n : ℕ) → Cube n
  8. | 0 => ()
  9. | n+1 => (true, top n)
  10. lemma weight_top (n : ℕ) (s : Cube n) : weight n s = n ↔ s = top n := by
  11. induction n with
  12. | zero => cases s; simp [top, weight]
  13. | succ n ih =>
  14. obtain ⟨b,s⟩ := s
  15. have h := weight_le n s
  16. cases b <;> simp [weight, top, ih, show weight n s ≠ n+1 by omega]
  17. theorem nonparity_positive {u : ℝ} (lo : 0 < u) (hi : u < 1)
  18. (s : Cube 8) (hs : s ≠ top 8) : 0 < eigen 8 (kernel u) s := by
  19. have h := weight_le 8 s
  20. have hn := mt (weight_top 8 s).mp hs
  21. have : weight 8 s = 0 ∨ weight 8 s = 1 ∨ weight 8 s = 2 ∨ weight 8 s = 3 ∨
  22. weight 8 s = 4 ∨ weight 8 s = 5 ∨ weight 8 s = 6 ∨ weight 8 s = 7 := by omega
  23. rcases this with h|h|h|h|h|h|h|h
  24. · rw [eigen, h]; exact positive0 lo hi
  25. · rw [eigen, h]; exact positive1 lo hi
  26. · rw [eigen, h]; exact positive2 lo hi
  27. · rw [eigen, h]; exact positive3 lo hi
  28. · rw [eigen, h]; exact positive4 lo hi
  29. · rw [eigen, h]; exact positive5 lo hi
  30. · rw [eigen, h]; exact positive6 lo hi
  31. · rw [eigen, h]; exact positive7 lo hi
  32. theorem parity_formula {u : ℝ} (lo : 0 < u) (hi : u < 1) :
  33. eigen 8 (kernel u) (top 8) = (505774080 * u^8 * (1-u^2) / common u) * cubic (u^2) := by
  34. have h := cleared8 lo hi
  35. have ht : weight 8 (top 8) = 8 := (weight_top ..).2 rfl
  36. simp only [eigen, ht, Nat.sub_self]
  37. rw [div_mul_eq_mul_div, eq_div_iff (common_pos lo hi).ne', mul_comm]
  38. exact h
  39. lemma parity_factor_pos {u : ℝ} (lo : 0 < u) (hi : u < 1) :
  40. 0 < 505774080 * u^8 * (1-u^2) / common u := by
  41. have := common_pos lo hi
  42. have : 0 < 1-u^2 := by nlinarith [mul_pos lo (sub_pos.mpr hi)]
  43. positivity
  44. lemma onto (n) : Function.Surjective (W n) := by
  45. intro w
  46. refine ⟨fun s => W n w s / 2^n, ?_⟩
  47. funext x
  48. change (∑ s, character n x s * (W n w s / 2^n)) = w x
  49. simp_rw [← mul_div_assoc]
  50. simp only [div_eq_mul_inv]
  51. rw [← Finset.sum_mul]
  52. change W n (W n w) x * (2^n)⁻¹ = w x
  53. rw [twice]; field_simp
  54. lemma W_zero (n) : W n 0 = 0 := by funext x; simp [W]
  55. def spike (s : Cube 8) (x : Cube 8) : ℝ := by classical exact if x=s then 1 else 0
  56. lemma form_spike (u : ℝ) (s : Cube 8) :
  57. form 8 (kernel u) (W 8 (spike s)) = 256 * eigen 8 (kernel u) s := by
  58. rw [diagonal]
  59. simp [spike, ite_pow, mul_ite]
  60. <;> norm_num
  61. def PSD (u : ℝ) := ∀ w, 0 ≤ form 8 (kernel u) w
  62. def PD (u : ℝ) := ∀ w, w ≠ 0 → 0 < form 8 (kernel u) w
  63. lemma all_nonneg {u : ℝ} (lo : 0 < u) (hi : u < 1) (h : 0 ≤ cubic (u^2))
  64. (s : Cube 8) : 0 ≤ eigen 8 (kernel u) s := by
  65. by_cases hs : s = top 8
  66. · rw [hs, parity_formula lo hi]; exact mul_nonneg (parity_factor_pos lo hi).le h
  67. · exact (nonparity_positive lo hi s hs).le
  68. theorem psd_iff {u : ℝ} (lo : 0 < u) (hi : u < 1) : PSD u ↔ 0 ≤ cubic (u^2) := by
  69. constructor
  70. · intro h
  71. have b := h (W 8 (spike (top 8)))
  72. rw [form_spike, parity_formula lo hi] at b
  73. exact nonneg_of_mul_nonneg_right (nonneg_of_mul_nonneg_right b (by norm_num)) (parity_factor_pos lo hi)
  74. · intro h w
  75. obtain ⟨a,rfl⟩ := onto 8 w
  76. rw [diagonal]
  77. exact mul_nonneg (by norm_num) (Finset.sum_nonneg fun s _ => mul_nonneg (all_nonneg lo hi h s) (sq_nonneg _))
  78. theorem pd_iff {u : ℝ} (lo : 0 < u) (hi : u < 1) : PD u ↔ 0 < cubic (u^2) := by
  79. constructor
  80. · intro h
  81. have nz : W 8 (spike (top 8)) ≠ 0 := by
  82. intro he
  83. have H := twice 8 (spike (top 8)) (top 8)
  84. rw [he,W_zero] at H
  85. norm_num [spike] at H
  86. have H := h _ nz
  87. rw [form_spike, parity_formula lo hi] at H
  88. exact pos_of_mul_pos_right (pos_of_mul_pos_right H (by norm_num)) (parity_factor_pos lo hi).le
  89. · intro h w hw
  90. obtain ⟨a,rfl⟩ := onto 8 w
  91. have ex : ∃ s, a s ≠ 0 := by
  92. by_contra! Hz
  93. exact hw ((congrArg (W 8) (show a=0 from funext Hz)).trans (W_zero 8))
  94. obtain ⟨t,ht⟩ := ex
  95. rw [diagonal]
  96. apply mul_pos (by norm_num)
  97. apply Finset.sum_pos' (fun s _ => mul_nonneg (all_nonneg lo hi h.le s) (sq_nonneg _))
  98. refine ⟨t, Finset.mem_univ _, mul_pos ?_ (sq_pos_of_ne_zero ht)⟩
  99. by_cases he : t = top 8
  100. · rw [he, parity_formula lo hi]; exact mul_pos (parity_factor_pos lo hi) h
  101. · exact nonparity_positive lo hi t he
  102. theorem boundary_null {u : ℝ} (lo : 0 < u) (hi : u < 1) (h : cubic (u^2)=0)
  103. (a : Cube 8 → ℝ) :
  104. form 8 (kernel u) (W 8 a) = 0 ↔ ∀ s, s ≠ top 8 → a s = 0 := by
  105. rw [diagonal, mul_eq_zero]
  106. simp only [pow_ne_zero 8 (by norm_num : (2:ℝ) ≠ 0), false_or]
  107. rw [Finset.sum_eq_zero_iff_of_nonneg (fun s _ => mul_nonneg (all_nonneg lo hi h.ge s) (sq_nonneg _))]
  108. constructor
  109. · intro H s hs
  110. have he := H s (Finset.mem_univ _)
  111. rcases mul_eq_zero.mp he with he|he
  112. · exact ((nonparity_positive lo hi s hs).ne' he).elim
  113. · simpa using he
  114. · intro H s _
  115. by_cases hs : s = top 8
  116. · simp [hs, parity_formula lo hi, h]
  117. · simp [H s hs]
  118. lemma cubic_mono : StrictMonoOn cubic (Set.Icc (0:ℝ) 1) := by
  119. intro x hx y hy hxy
  120. have H : 0 < 4*(y^2+y*x+x^2) + 791-190*(y+x) := by
  121. nlinarith [sq_nonneg y, sq_nonneg x, mul_nonneg hy.1 hx.1, hx.2,hy.2]
  122. unfold cubic
  123. nlinarith only [mul_pos (sub_pos.mpr hxy) H]
  124. theorem unique_crossing : ∃! z : ℝ, z ∈ Set.Ioo (0:ℝ) 1 ∧ cubic z = 0 := by
  125. have hc : Continuous cubic := by unfold cubic; fun_prop
  126. obtain ⟨z,hz,he⟩ := intermediate_value_Icc (by norm_num : (0:ℝ) ≤ 1) hc.continuousOn
  127. (show (0:ℝ) ∈ Set.Icc (cubic 0) (cubic 1) by constructor <;> norm_num [cubic])
  128. have h0 : z ≠ 0 := by rintro rfl; norm_num [cubic] at he
  129. have h1 : z ≠ 1 := by rintro rfl; norm_num [cubic] at he
  130. refine ⟨z, ⟨⟨lt_of_le_of_ne hz.1 h0.symm, lt_of_le_of_ne hz.2 h1⟩, he⟩, ?_⟩
  131. intro y hy
  132. exact cubic_mono.injOn ⟨hy.1.1.le,hy.1.2.le⟩ hz (hy.2.trans he.symm)
  133. theorem radius_threshold {z r : ℝ} (hz : z ∈ Set.Ioo (0:ℝ) 1) (root : cubic z = 0)
  134. (lo : 0 < r) (hi : r < 1) :
  135. (PSD (r^2) ↔ z ≤ r^4) ∧ (PD (r^2) ↔ z < r^4) := by
  136. have hu : r^2 < 1 := by nlinarith [mul_pos lo (sub_pos.mpr hi)]
  137. have hr : r^4 ∈ Set.Icc (0:ℝ) 1 := by
  138. constructor
  139. · positivity
  140. · nlinarith [mul_pos (sq_pos_of_pos lo) (sub_pos.mpr hu)]
  141. have hz' : z ∈ Set.Icc (0:ℝ) 1 := ⟨hz.1.le,hz.2.le⟩
  142. rw [psd_iff (sq_pos_of_pos lo) hu, pd_iff (sq_pos_of_pos lo) hu,
  143. show (r^2)^2 = r^4 by ring, ← root]
  144. exact ⟨cubic_mono.le_iff_le hz' hr, cubic_mono.lt_iff_lt hz' hr⟩
  145. end
  146. end CubeSpectrum