Lean / Reader
Lean readerSixEqualityCoordinates.lean
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.
import SixEqualityAlgebranoncomputable sectionnamespace SixEquality/-- Edges in lexicographic order on the vertices 0 through 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)]/-- Each row marks a triple containing vertex zero by +1 and its complement by -1.The ten rows are in lexicographic order. -/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]]/-- Sums of the three original edge weights on each chosen triangle. -/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]/-- Sums on their complementary triangles, in corresponding order. -/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]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]def xcoord (w : Edge → ℝ) (v : V) := degree w v / 2 - (∑ k, w k) / 6def mean (w : Edge → ℝ) (i : H) := (left w i + right w i) / 2def halfDiff (w : Edge → ℝ) (i : H) := (left w i - right w i) / 2def projection (x : V → ℝ) (i : H) := (∑ v, sign i v * x v) / 2theorem centered (w : Edge → ℝ) : ∑ v, xcoord w v = 0 := bysimp [xcoord,degree,Fin.sum_univ_succ]ringtheorem halfDiff_eq (w : Edge → ℝ) : halfDiff w = projection (xcoord w) := byfunext ifin_cases i <;> simp [halfDiff, projection, xcoord, degree, left, right, sign, Fin.sum_univ_succ] <;> ring/-- Linear inverse from ten means and six centered vertex coordinates. -/def recover (m : H → ℝ) (x : V → ℝ) (k : Edge) : ℝ :=(x (endpoints k).1 + x (endpoints k).2)/2 +∑ i, m i * ((1 + 3*sign i (endpoints k).1 * sign i (endpoints k).2)/12)theorem recover_original (w : Edge → ℝ) : recover (mean w) (xcoord w) = w := byfunext kfin_cases k <;> simp [recover, xcoord, degree, mean, left, right, sign, endpoints, Fin.sum_univ_succ] <;> ring/-- Sum of powers of the edge-weight readings over all twenty triples. -/def moment (w : Edge → ℝ) (k : ℕ) : ℝ := ∑ i, ((left w i)^k + (right w i)^k)theorem moment_eq (w : Edge → ℝ) (k : ℕ) : moment w k = total (mean w) (halfDiff w) k := byunfold moment totalapply Finset.sum_congr rflintro i _have hp : mean w i + halfDiff w i = left w i := by unfold mean halfDiff; ringhave hn : mean w i - halfDiff w i = right w i := by unfold mean halfDiff; ringrw [hp, hn]end SixEquality