import Std/-! Algebraic certificates for the sharp six-point fourth moment. The namesbelow apply to arbitrary commutative rings, or ordered rings as indicated.The ten chosen triples contain vertex 1; their complements give the other ten. -/namespace SixPointopen Lean.Grind Stdsection Identitiesvariable {R : Type} [CommRing R]def halfTriples (a b c d e f : R) : List R :=[a+b+c, a+b+d, a+b+e, a+b+f, a+c+d, a+c+e, a+c+f,a+d+e, a+d+f, a+e+f]def moment (p : Nat) (entries : List R) : R :=(entries.map (· ^ p)).foldr (· + ·) 0theorem second_moment (a b c d e : R) :let f := -(a + b + c + d + e)moment 2 (halfTriples a b c d e f) = 3 * moment 2 [a,b,c,d,e,f] := bysimp [moment, halfTriples]grindtheorem fourth_moment (a b c d e : R) :let f := -(a + b + c + d + e)moment 4 (halfTriples a b c d e f) =3 * ((moment 2 [a,b,c,d,e,f])^2 - moment 4 [a,b,c,d,e,f]) := bysimp [moment, halfTriples]grinddef pairGaps (entries : List R) : List R :=match entries with| [] => []| a :: rest => (rest.map (a - ·)) ++ pairGaps rest/-- For a representative triple containing a,b,c. Vertex relabelling gives every triple. -/theorem coordinate_gap (a b c d e : R) :let f := -(a + b + c + d + e)3 * moment 2 [a,b,c,d,e,f] - 2*(a+b+c)^2 =moment 2 (pairGaps [a,b,c]) + moment 2 (pairGaps [d,e,f]) := bysimp [moment, pairGaps]grindtheorem fourth_gap (a b c d e f : R) :6*moment 4 [a,b,c,d,e,f] - (moment 2 [a,b,c,d,e,f])^2 =moment 2 (pairGaps [a^2,b^2,c^2,d^2,e^2,f^2]) := bysimp [moment, pairGaps]grind/-- The equality witness has one pair of exceptional triples, and eighteenmixed triples of value +1 or -1. M is the positive square root of 44. -/theorem equality_witness (m : R) (hm : m^2 = 44) :(m+3)^2 + (m-3)^2 + 18 = 124 ∧(m+3)^4 + (m-3)^4 + 18 = 8804 := byconstructor <;> grindend Identitiessection Ordervariable {R : Type} [CommRing R] [LE R] [LT R] [LawfulOrderLT R][IsLinearOrder R] [OrderedRing R]/-- The final deduction in the paper, written without denominators. -/theorem sharp_bound (a b c d e : R)(hc : c ≤ a^2) (hd : 2*d ≤ a*b) (he : 18*e ≤ 5*b^2) :62*(c+6*d+e) ≤ 71*(a+b)^2 := byhave hs : 0 ≤ (9*a - 22*b)^2 := OrderedRing.sq_nonneggrindtheorem second_nonneg (s : List R) : 0 ≤ moment 2 s := byinduction s with| nil => simp [moment]| cons a s ih =>change 0 ≤ a^2 + moment 2 shave : 0 ≤ a^2 := OrderedRing.sq_nonneggrindtheorem fourth_le_second_sq (s : List R) : moment 4 s ≤ (moment 2 s)^2 := byinduction s with| nil => simp [moment]; grind| cons a s ih =>change a^4 + moment 4 s ≤ (a^2 + moment 2 s)^2have ht := second_nonneg shave ha : 0 ≤ a^2 := OrderedRing.sq_nonneghave := OrderedRing.mul_nonneg ha htgrinddef mixed (p : List (R × R)) : R :=(p.map (fun q => q.1^2 * q.2^2)).foldr (· + ·) 0theorem mixed_bound (p : List (R × R)) (b : R)(h : ∀ q ∈ p, 2*q.2^2 ≤ b) :2*mixed p ≤ moment 2 (p.map Prod.fst) * b := byinduction p with| nil => simp [mixed,moment]; grind| cons q s ih =>have ht := ih (fun z hz => h z (by simp [hz]))have hq := h q (by simp)have ha : 0 ≤ q.1^2 := OrderedRing.sq_nonneghave := OrderedRing.mul_nonneg ha (OrderedAdd.sub_nonneg_iff.mpr hq)change 2*(q.1^2 * q.2^2 + mixed s) ≤ (q.1^2+moment 2 (s.map Prod.fst))*bgrinddef joinPairs (p : List (R × R)) : List R :=p.flatMap (fun q => [q.1+q.2,q.1-q.2])omit [LE R] [LT R] [LawfulOrderLT R] [IsLinearOrder R] [OrderedRing R] intheorem paired_second (p : List (R × R)) :moment 2 (joinPairs p) = 2*(moment 2 (p.map Prod.fst)+moment 2 (p.map Prod.snd)) := byinduction p with| nil => simp [joinPairs, moment]; grind| cons q s ih =>change (q.1+q.2)^2 + ((q.1-q.2)^2 + moment 2 (joinPairs s)) =2*((q.1^2 + moment 2 (s.map Prod.fst))+(q.2^2 + moment 2 (s.map Prod.snd)))grindomit [LE R] [LT R] [LawfulOrderLT R] [IsLinearOrder R] [OrderedRing R] intheorem paired_fourth (p : List (R × R)) :moment 4 (joinPairs p) =2*(moment 4 (p.map Prod.fst)+6*mixed p+moment 4 (p.map Prod.snd)) := byinduction p with| nil => simp [joinPairs, moment,mixed]; grind| cons q s ih =>change (q.1+q.2)^4 + ((q.1-q.2)^4 + moment 4 (joinPairs s)) =2*((q.1^4 + moment 4 (s.map Prod.fst))+6*(q.1^2*q.2^2+mixed s)+(q.2^4+moment 4 (s.map Prod.snd)))grindprivate theorem coord (a b c d e f : R) (h : a+b+c+d+e+f=0) :2*(a+b+c)^2 ≤ 3*moment 2 [a,b,c,d,e,f] := byhave h1 := second_nonneg (pairGaps [a,b,c])have h2 := second_nonneg (pairGaps [d,e,f])have hf : f = -(a+b+c+d+e) := by grindhave eqn := coordinate_gap a b c d erw [← hf] at eqngrindtheorem max_coordinate (a b c d e f : R) (h : a+b+c+d+e+f=0) :∀ y ∈ halfTriples a b c d e f, 2*y^2 ≤ 3*moment 2 [a,b,c,d,e,f] := byhave aux (p q r s t u : R) (hs : p+q+r+s+t+u=0) := coord p q r s t u hshave h1 := aux a b c d e f (by grind)have h2 := aux a b d c e f (by grind)have h3 := aux a b e c d f (by grind)have h4 := aux a b f c d e (by grind)have h5 := aux a c d b e f (by grind)have h6 := aux a c e b d f (by grind)have h7 := aux a c f b d e (by grind)have h8 := aux a d e b c f (by grind)have h9 := aux a d f b c e (by grind)have h10 := aux a e f b c d (by grind)simp only [moment, List.map_cons, List.map_nil, List.foldr_cons, List.foldr_nil]at h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 ⊢intro y hysimp [halfTriples] at hyrcases hy with h|h|h|h|h|h|h|h|h|h <;> subst y <;> grindtheorem six_point_bound (p : List (R × R)) (a b c d e f : R)(h : a+b+c+d+e+f=0) (hl : p.map Prod.snd = halfTriples a b c d e f) :124*moment 4 (joinPairs p) ≤ 71*(moment 2 (joinPairs p))^2 := byhave hf : f = -(a+b+c+d+e) := by grindhave h2 := second_moment a b c d ehave h4 := fourth_moment a b c d edsimp only at h2 h4rw [← hf, ← hl] at h2 h4have hc := fourth_le_second_sq (p.map Prod.fst)have hd := mixed_bound p (moment 2 (p.map Prod.snd)) (byintro q hqhave mem : q.2 ∈ p.map Prod.snd := List.mem_map.mpr ⟨q,hq,rfl⟩rw [hl] at memrw [h2]exact max_coordinate a b c d e f h _ mem)have hg := fourth_gap a b c d e fhave hp := second_nonneg (pairGaps [a^2,b^2,c^2,d^2,e^2,f^2])have he : 18 * moment 4 (p.map Prod.snd) ≤ 5*(moment 2 (p.map Prod.snd))^2 := byrw [h2,h4]rw [← hg] at hpclear h2 h4 hc hd hg hf hl hgrind onlyhave bound := sharp_bound _ _ _ _ _ hc hd herw [paired_second, paired_fourth]grindend Orderstructure EdgeWeights (R : Type) whereab : Rac : Rad : Rae : Raf : Rbc : Rbd : Rbe : Rbf : Rcd : Rce : Rcf : Rde : Rdf : Ref : Rsection Edgesvariable {R : Type} [CommRing R]/-- All triples paired with their complements. The first triple contains a. -/def readings (e : EdgeWeights R) : List (R × R) :=[(e.ab+e.ac+e.bc,e.de+e.df+e.ef), (e.ab+e.ad+e.bd,e.ce+e.cf+e.ef),(e.ab+e.ae+e.be,e.cd+e.cf+e.df), (e.ab+e.af+e.bf,e.cd+e.ce+e.de),(e.ac+e.ad+e.cd,e.be+e.bf+e.ef), (e.ac+e.ae+e.ce,e.bd+e.bf+e.df),(e.ac+e.af+e.cf,e.bd+e.be+e.de), (e.ad+e.ae+e.de,e.bc+e.bf+e.cf),(e.ad+e.af+e.df,e.bc+e.be+e.ce), (e.ae+e.af+e.ef,e.bc+e.bd+e.cd)]def unpack (p : List (R × R)) : List R := p.flatMap (fun q => [q.1,q.2])def changeCoordinates (p : List (R × R)) : List (R × R) :=p.map (fun q => (3*(q.1+q.2),3*(q.1-q.2)))theorem scaled_second (p : List (R × R)) :moment 2 (joinPairs (changeCoordinates p)) = 36*moment 2 (unpack p) := byinduction p with| nil => simp [joinPairs,changeCoordinates,unpack,moment]; grind| cons q s ih =>change (3*(q.1+q.2)+3*(q.1-q.2))^2+((3*(q.1+q.2)-3*(q.1-q.2))^2+moment 2 (joinPairs (changeCoordinates s))) = 36*(q.1^2+(q.2^2+moment 2 (unpack s)))grindtheorem scaled_fourth (p : List (R × R)) :moment 4 (joinPairs (changeCoordinates p)) = 1296*moment 4 (unpack p) := byinduction p with| nil => simp [joinPairs,changeCoordinates,unpack,moment]; grind| cons q s ih =>change (3*(q.1+q.2)+3*(q.1-q.2))^4+((3*(q.1+q.2)-3*(q.1-q.2))^4+moment 4 (joinPairs (changeCoordinates s))) = 1296*(q.1^4+(q.2^4+moment 4 (unpack s)))grinddef witnessEdges (m : R) : EdgeWeights R :=let inner := 2*(m+3)let outer := 2*(m-3)let cross := -m⟨inner,inner,cross,cross,cross,inner,cross,cross,cross,cross,cross,cross,outer,outer,outer⟩theorem witness_reading (m : R) (hm : m^2 = 44) :moment 2 (unpack (readings (witnessEdges m))) = 36*124 ∧moment 4 (unpack (readings (witnessEdges m))) = 1296*8804 := bysimp [moment, unpack, readings, witnessEdges]constructor <;> grindvariable [LE R] [LT R] [LawfulOrderLT R] [IsLinearOrder R] [OrderedRing R]/-- Sharp upper bound from the fifteen arbitrary original edge weights. -/theorem edge_bound (w : EdgeWeights R) :124 * moment 4 (unpack (readings w)) ≤ 71 * (moment 2 (unpack (readings w)))^2 := bylet t := w.ab+w.ac+w.ad+w.ae+w.af+w.bc+w.bd+w.be+w.bf+w.cd+w.ce+w.cf+w.de+w.df+w.eflet a := 3*(w.ab+w.ac+w.ad+w.ae+w.af)-tlet b := 3*(w.ab+w.bc+w.bd+w.be+w.bf)-tlet c := 3*(w.ac+w.bc+w.cd+w.ce+w.cf)-tlet d := 3*(w.ad+w.bd+w.cd+w.de+w.df)-tlet e := 3*(w.ae+w.be+w.ce+w.de+w.ef)-tlet f := 3*(w.af+w.bf+w.cf+w.df+w.ef)-thave hz : a+b+c+d+e+f=0 := bydsimp [a,b,c,d,e,f,t]grind onlyhave hl : (changeCoordinates (readings w)).map Prod.snd = halfTriples a b c d e f := bysimp [changeCoordinates, readings, halfTriples, a,b,c,d,e,f,t]repeat' apply And.intro <;> grind onlyhave bound := six_point_bound _ a b c d e f hz hlrw [scaled_second,scaled_fourth] at boundclear hl hzgrind onlyend Edges#print axioms second_moment#print axioms fourth_moment#print axioms coordinate_gap#print axioms fourth_gap#print axioms equality_witness#print axioms sharp_bound#print axioms edge_bound#print axioms witness_readingend SixPoint