Lean / Reader
Lean reader

SixEqualityMoments.lean

88 lines11 declarationsno sorry
  1. import SixEqualityCoordinates
  2. namespace SixEquality
  3. set_option maxRecDepth 16384
  4. set_option maxHeartbeats 2400000
  5. private theorem fin3 : ((2 : Fin 5).succ : V) = 3 := rfl
  6. private theorem fin4 : ((2 : Fin 4).succ.succ : V) = 4 := rfl
  7. private theorem fin5 : ((2 : Fin 3).succ.succ.succ : V) = 5 := rfl
  8. private theorem last_coordinate (x : V → ℝ) (hz : ∑ v, x v=0) :
  9. x 5 = -(x 0+x 1+x 2+x 3+x 4) := by
  10. norm_num [Fin.sum_univ_succ] at hz
  11. simp only [fin3,fin4,fin5] at hz
  12. linarith
  13. theorem projected_squares (x : V → ℝ) (hz : ∑ v, x v = 0) :
  14. sqSum (projection x) = 3*sqSum x := by
  15. have hf := last_coordinate x hz
  16. norm_num [sqSum,projection,sign,Fin.sum_univ_succ]
  17. simp only [fin3,fin4,fin5]
  18. rw [hf]
  19. ring
  20. private def squareGaps (x : V → ℝ) : ℝ :=
  21. ((x 0)^2-(x 1)^2)^2 +
  22. ((x 0)^2-(x 2)^2)^2 +
  23. ((x 0)^2-(x 3)^2)^2 +
  24. ((x 0)^2-(x 4)^2)^2 +
  25. ((x 0)^2-(x 5)^2)^2 +
  26. ((x 1)^2-(x 2)^2)^2 +
  27. ((x 1)^2-(x 3)^2)^2 +
  28. ((x 1)^2-(x 4)^2)^2 +
  29. ((x 1)^2-(x 5)^2)^2 +
  30. ((x 2)^2-(x 3)^2)^2 +
  31. ((x 2)^2-(x 4)^2)^2 +
  32. ((x 2)^2-(x 5)^2)^2 +
  33. ((x 3)^2-(x 4)^2)^2 +
  34. ((x 3)^2-(x 5)^2)^2 +
  35. ((x 4)^2-(x 5)^2)^2
  36. theorem projected_fourth_bound (x : V → ℝ) (hz : ∑ v, x v = 0) :
  37. 18 * fourth (projection x) ≤ 5*(sqSum (projection x))^2 := by
  38. have hf := last_coordinate x hz
  39. have he : 5*(sqSum (projection x))^2-18*fourth (projection x) = 9*squareGaps x := by
  40. rw [projected_squares x hz]
  41. norm_num [fourth,projection,sqSum,sign,Fin.sum_univ_succ,squareGaps]
  42. simp only [fin3,fin4,fin5]
  43. rw [hf]
  44. ring
  45. have hp : 0 ≤ squareGaps x := by unfold squareGaps; positivity
  46. linarith
  47. theorem sign_squares (i : H) : sqSum (sign i) = 6 := by
  48. fin_cases i <;> norm_num [sqSum, sign, Fin.sum_univ_succ]
  49. /-- Squared distance from the line spanned by the sign vector of the partition. -/
  50. theorem projection_residual (x : V → ℝ) (i : H) :
  51. 3 * sqSum (fun v => x v - (projection x i)/3 * sign i v) =
  52. 3*sqSum x - 2*(projection x i)^2 := by
  53. let P := projection x i
  54. have hi := sign_squares i
  55. change ∑ v, (sign i v)^2 = 6 at hi
  56. have hp : ∑ v, sign i v*x v = 2*P := by dsimp [P,projection]; ring
  57. have point (v : V) : (x v - P/3 * sign i v)^2 =
  58. (x v)^2 - (2*P/3)*(sign i v*x v) + (P/3)^2*(sign i v)^2 := by ring
  59. change 3 * (∑ v, (x v-P/3*sign i v)^2) = 3 * (∑ v, (x v)^2) - 2*P^2
  60. simp only [point, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, hp, hi]
  61. ring
  62. theorem projection_bound (x : V → ℝ) (hz : ∑ v, x v = 0) (i : H) :
  63. 2*(projection x i)^2 ≤ sqSum (projection x) := by
  64. rw [projected_squares x hz]
  65. have hpos := sq_nonnegative (fun v => x v-projection x i/3*sign i v)
  66. linarith [projection_residual x i]
  67. theorem coordinates_on_partition (x : V → ℝ) (hz : ∑ v, x v = 0) (i : H)
  68. (hi : 2*(projection x i)^2 = sqSum (projection x)) :
  69. ∀ v, x v = (projection x i)/3 * sign i v := by
  70. rw [projected_squares x hz] at hi
  71. intro v
  72. have h := single_sq_le (fun k => x k-projection x i/3*sign i k) v
  73. have hr := projection_residual x i
  74. nlinarith only [hr,h,hi,sq_nonneg (x v-projection x i/3*sign i v)]
  75. end SixEquality