Lean / Reader
Lean reader

SixEqualityCoordinates.lean

56 lines15 declarationsno sorryimports SixEqualityAlgebra

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

  1. import SixEqualityAlgebra
  2. noncomputable section
  3. namespace SixEquality
  4. /-- Edges in lexicographic order on the vertices 0 through 5. -/
  5. def endpoints : Edge → V × V := ![(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)]
  6. /-- Each row marks a triple containing vertex zero by +1 and its complement by -1.
  7. The ten rows are in lexicographic order. -/
  8. def sign : H → V → ℝ := ![![1, 1, 1, -1, -1, -1], ![1, 1, -1, 1, -1, -1], ![1, 1, -1, -1, 1, -1], ![1, 1, -1, -1, -1, 1], ![1, -1, 1, 1, -1, -1], ![1, -1, 1, -1, 1, -1], ![1, -1, 1, -1, -1, 1], ![1, -1, -1, 1, 1, -1], ![1, -1, -1, 1, -1, 1], ![1, -1, -1, -1, 1, 1]]
  9. /-- Sums of the three original edge weights on each chosen triangle. -/
  10. def left (w : Edge → ℝ) : H → ℝ := ![w 0 + w 1 + w 5, w 0 + w 2 + w 6, w 0 + w 3 + w 7, w 0 + w 4 + w 8, w 1 + w 2 + w 9, w 1 + w 3 + w 10, w 1 + w 4 + w 11, w 2 + w 3 + w 12, w 2 + w 4 + w 13, w 3 + w 4 + w 14]
  11. /-- Sums on their complementary triangles, in corresponding order. -/
  12. def right (w : Edge → ℝ) : H → ℝ := ![w 12 + w 13 + w 14, w 10 + w 11 + w 14, w 9 + w 11 + w 13, w 9 + w 10 + w 12, w 7 + w 8 + w 14, w 6 + w 8 + w 13, w 6 + w 7 + w 12, w 5 + w 8 + w 11, w 5 + w 7 + w 10, w 5 + w 6 + w 9]
  13. def degree (w : Edge → ℝ) : V → ℝ := ![w 0 + w 1 + w 2 + w 3 + w 4, w 0 + w 5 + w 6 + w 7 + w 8, w 1 + w 5 + w 9 + w 10 + w 11, w 2 + w 6 + w 9 + w 12 + w 13, w 3 + w 7 + w 10 + w 12 + w 14, w 4 + w 8 + w 11 + w 13 + w 14]
  14. def xcoord (w : Edge → ℝ) (v : V) := degree w v / 2 - (∑ k, w k) / 6
  15. def mean (w : Edge → ℝ) (i : H) := (left w i + right w i) / 2
  16. def halfDiff (w : Edge → ℝ) (i : H) := (left w i - right w i) / 2
  17. def projection (x : V → ℝ) (i : H) := (∑ v, sign i v * x v) / 2
  18. theorem centered (w : Edge → ℝ) : ∑ v, xcoord w v = 0 := by
  19. simp [xcoord,degree,Fin.sum_univ_succ]
  20. ring
  21. theorem halfDiff_eq (w : Edge → ℝ) : halfDiff w = projection (xcoord w) := by
  22. funext i
  23. fin_cases i <;> simp [halfDiff, projection, xcoord, degree, left, right, sign, Fin.sum_univ_succ] <;> ring
  24. /-- Linear inverse from ten means and six centered vertex coordinates. -/
  25. def recover (m : H → ℝ) (x : V → ℝ) (k : Edge) : ℝ :=
  26. (x (endpoints k).1 + x (endpoints k).2)/2 +
  27. ∑ i, m i * ((1 + 3*sign i (endpoints k).1 * sign i (endpoints k).2)/12)
  28. theorem recover_original (w : Edge → ℝ) : recover (mean w) (xcoord w) = w := by
  29. funext k
  30. fin_cases k <;> simp [recover, xcoord, degree, mean, left, right, sign, endpoints, Fin.sum_univ_succ] <;> ring
  31. /-- Sum of powers of the edge-weight readings over all twenty triples. -/
  32. def moment (w : Edge → ℝ) (k : ℕ) : ℝ := ∑ i, ((left w i)^k + (right w i)^k)
  33. theorem moment_eq (w : Edge → ℝ) (k : ℕ) : moment w k = total (mean w) (halfDiff w) k := by
  34. unfold moment total
  35. apply Finset.sum_congr rfl
  36. intro i _
  37. have hp : mean w i + halfDiff w i = left w i := by unfold mean halfDiff; ring
  38. have hn : mean w i - halfDiff w i = right w i := by unfold mean halfDiff; ring
  39. rw [hp, hn]
  40. end SixEquality