/-Copyright (c) 2026 Carles MarΓn. All rights reserved.Released under Apache 2.0 license as described in the file LICENSE.Authors: Carles MarΓn, Claude (AI assistant)-/module public import Mathlib.Analysis.InnerProductSpace.Basicpublic import Mathlib.Data.Finset.Powersetpublic import Mathlib.Algebra.BigOperators.Ring.Finsetpublic import Mathlib.Algebra.BigOperators.Group.Finset.Powersetpublic import Mathlib.Algebra.Order.BigOperators.Group.Finset /-!# Hlawka's inequality and its generalisation by DjokoviΔ Hlawka's inequality `βx+yβ + βy+zβ + βz+xβ β€ βxβ + βyβ + βzβ + βx+y+zβ` in a real inner productspace, and its generalisation (DjokoviΔ 1963; SmileyβSmiley 1964): for `n β₯ 3` vectors, with `d_k`the sum of the norms of all `k`-element subsums, `d_2 + β― + d_{n-1} β€ (2^(n-2) - 1) (d_1 + d_n)`.The general case is equivalent to `4F β€ 2^n (d_1 + d_n)`, where `F` sums the norms of the subsumsover all subsets; it is proved by strong induction on the number of vectors, merging two of them,`x a` and `x b`, into `x a + x b`: the subsets containing both or neither form the merged family,and each subset `T` containing exactly one of them is handled by Hlawka's inequality for`(Ξ£_T, x a, x b)`. ## Main results * `Hlawka.norm_add_add_le`: Hlawka's inequality for three vectors* `Hlawka.generalised`: d_2 + ... + d_(n-1) <= (2^(n-2) - 1)(d_1 + d_n) for n >= 3 vectors ## References * D. Ε½. DjokoviΔ, *Generalizations of Hlawka's inequality*, Glasnik Mat.-Fiz. Astronom. 18 (1963), 169β175.* D. M. Smiley and M. F. Smiley, *The polygonal inequalities*, Amer. Math. Monthly 71 (1964), 755β760.-/ @[expose] public section open Finset namespace Hlawka variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace β E] /-- **Hlawka's inequality** (`n = 3`). -/theorem norm_add_add_le (x y z : E) : βx + yβ + βy + zβ + βz + xβ β€ βxβ + βyβ + βzβ + βx + y + zβ := by have e1 := norm_add_sq_real x y have e2 := norm_add_sq_real y z have e3 := norm_add_sq_real z x have e4 := norm_add_sq_real (x + y) z rw [inner_add_left] at e4 have c1 := real_inner_comm x z have h : βxβ ^ 2 + βyβ ^ 2 + βzβ ^ 2 + βx + y + zβ ^ 2 = βx + yβ ^ 2 + βy + zβ ^ 2 + βz + xβ ^ 2 := by linarith have t1 : βx + yβ β€ βxβ + βyβ := norm_add_le x y have t2 : βy + zβ β€ βyβ + βzβ := norm_add_le y z have t3 : βz + xβ β€ βzβ + βxβ := norm_add_le z x have u1 : βx + yβ β€ βx + y + zβ + βzβ := by calc βx + yβ = β(x + y + z) - zβ := by rw [add_sub_cancel_right] _ β€ βx + y + zβ + βzβ := norm_sub_le _ _ have u2 : βy + zβ β€ βx + y + zβ + βxβ := by calc βy + zβ = β(x + y + z) - xβ := by congr 1; abel _ β€ βx + y + zβ + βxβ := norm_sub_le _ _ have u3 : βz + xβ β€ βx + y + zβ + βyβ := by calc βz + xβ = β(x + y + z) - yβ := by congr 1; abel _ β€ βx + y + zβ + βyβ := norm_sub_le _ _ have key : (βxβ + βyβ + βzβ + βx + y + zβ) * (βxβ + βyβ + βzβ + βx + y + zβ - βx + yβ - βy + zβ - βz + xβ) = (βxβ + βyβ - βx + yβ) * (βzβ - βx + yβ + βx + y + zβ) + (βyβ + βzβ - βy + zβ) * (βxβ - βy + zβ + βx + y + zβ) + (βzβ + βxβ - βz + xβ) * (βyβ - βz + xβ + βx + y + zβ) := by linear_combination h have p1 : 0 β€ (βxβ + βyβ - βx + yβ) * (βzβ - βx + yβ + βx + y + zβ) := mul_nonneg (by linarith) (by linarith) have p2 : 0 β€ (βyβ + βzβ - βy + zβ) * (βxβ - βy + zβ + βx + y + zβ) := mul_nonneg (by linarith) (by linarith) have p3 : 0 β€ (βzβ + βxβ - βz + xβ) * (βyβ - βz + xβ + βx + y + zβ) := mul_nonneg (by linarith) (by linarith) have n1 := norm_nonneg x have n2 := norm_nonneg y have n3 := norm_nonneg z have n4 := norm_nonneg (x + y + z) rcases (add_nonneg (add_nonneg (add_nonneg n1 n2) n3) n4).eq_or_lt with hs | hs Β· linarith Β· by_contra hc have hneg : (βxβ + βyβ + βzβ + βx + y + zβ - βx + yβ - βy + zβ - βz + xβ) < 0 := by linarith have := mul_neg_of_pos_of_neg hs hneg linarith /-- Pointwise step: Hlawka rewritten for merging two summands. -/private lemma pt (u v w : E) : βuβ + βw + uβ + βv + uβ + βv + (w + u)β β€ 2 * (βuβ + βv + w + uβ) + (βvβ + βwβ - βv + wβ) := by have h := norm_add_add_le u v w have e1 : βv + uβ = βu + vβ := by rw [add_comm] have e2 : βv + (w + u)β = βu + v + wβ := by congr 1; abel have e3 : βv + w + uβ = βu + v + wβ := by congr 1; abel linarith private lemma sum_powerset_four {ΞΉ : Type*} [DecidableEq ΞΉ] {a b : ΞΉ} {R : Finset ΞΉ} (ha : a β insert b R) (hb : b β R) (f : Finset ΞΉ β β) : β S β (insert a (insert b R)).powerset, f S = β T β R.powerset, (f T + f (insert b T) + f (insert a T) + f (insert a (insert b T))) := by rw [Finset.sum_powerset_insert ha, Finset.sum_powerset_insert hb f, Finset.sum_powerset_insert hb (fun t => f (insert a t))] simp only [Finset.sum_add_distrib] ring /-- Key induction: `4 Β· F β€ 2^m (dβ + dβ)` where `F` sums the norms of all subsums. -/private lemma key {ΞΉ : Type*} [DecidableEq ΞΉ] (m : β) : β (s : Finset ΞΉ) (x : ΞΉ β E), s.card = m β 4 * β S β s.powerset, ββ i β S, x iβ β€ 2 ^ m * (β i β s, βx iβ + ββ i β s, x iβ) := by induction m using Nat.strong_induction_on with | _ m ih => intro s x hs rcases m with _ | _ | k Β· have h0 : s = β := Finset.card_eq_zero.mp hs subst h0 simp Β· obtain β¨a, rflβ© := Finset.card_eq_one.mp hs rw [show ({a} : Finset ΞΉ) = insert a β from rfl, Finset.sum_powerset_insert (Finset.notMem_empty a)] simp linarith Β· obtain β¨a, ha, b, hb, habβ© := Finset.one_lt_card.mp (by omega : 1 < s.card) have hb' : b β s.erase a := Finset.mem_erase.mpr β¨hab.symm, hbβ© have hsR : insert a (insert b ((s.erase a).erase b)) = s := by rw [Finset.insert_erase hb', Finset.insert_erase ha] have haR : a β insert b ((s.erase a).erase b) := by simp [hab] have hbR : b β (s.erase a).erase b := by simp obtain β¨R, hsR', haR', hbR'β© : β R : Finset ΞΉ, insert a (insert b R) = s β§ a β insert b R β§ b β R := β¨_, hsR, haR, hbRβ© subst hsR' have haR2 : a β R := fun h => haR' (Finset.mem_insert_of_mem h) have hRc : R.card = k := by rw [Finset.card_insert_of_notMem haR', Finset.card_insert_of_notMem hbR'] at hs omega -- merged family let x' : ΞΉ β E := fun i => if i = a then x a + x b else x i have hx' : β T β R, β i β T, x' i = β i β T, x i := by intro T hT refine Finset.sum_congr rfl fun i hi => ?_ have hia : i β a := fun h => haR2 (h βΈ hT hi) simp [x', hia] have hnx' : β i β R, βx' iβ = β i β R, βx iβ := by refine Finset.sum_congr rfl fun i hi => ?_ have hia : i β a := fun h => haR2 (h βΈ hi) simp [x', hia] have IH := ih (k + 1) (by omega) (insert a R) x' (by rw [Finset.card_insert_of_notMem haR2, hRc]) have hF' : β S β (insert a R).powerset, ββ i β S, x' iβ = β T β R.powerset, (ββ i β T, x iβ + βx a + x b + β i β T, x iβ) := by rw [Finset.sum_powerset_insert haR2, β Finset.sum_add_distrib] refine Finset.sum_congr rfl fun T hT => ?_ have hTR := Finset.mem_powerset.mp hT have haT : a β T := fun h => haR2 (hTR h) rw [Finset.sum_insert haT, hx' T hTR] simp [x'] have hF : β S β (insert a (insert b R)).powerset, ββ i β S, x iβ β€ β T β R.powerset, (2 * (ββ i β T, x iβ + βx a + x b + β i β T, x iβ) + (βx aβ + βx bβ - βx a + x bβ)) := by rw [sum_powerset_four haR' hbR'] refine Finset.sum_le_sum fun T hT => ?_ have hTR := Finset.mem_powerset.mp hT have haT : a β T := fun h => haR2 (hTR h) have hbT : b β T := fun h => hbR' (hTR h) have haT' : a β insert b T := fun h => haR' (by rcases Finset.mem_insert.mp h with h | h Β· exact Finset.mem_insert.mpr (Or.inl h) Β· exact Finset.mem_insert_of_mem (hTR h)) rw [Finset.sum_insert hbT, Finset.sum_insert haT, Finset.sum_insert haT', Finset.sum_insert hbT] exact pt (β i β T, x i) (x a) (x b) have hsum : β T β R.powerset, (2 * (ββ i β T, x iβ + βx a + x b + β i β T, x iβ) + (βx aβ + βx bβ - βx a + x bβ)) = 2 * β S β (insert a R).powerset, ββ i β S, x' iβ + 2 ^ k * (βx aβ + βx bβ - βx a + x bβ) := by rw [hF', Finset.sum_add_distrib, β Finset.mul_sum, Finset.sum_const, Finset.card_powerset, hRc, nsmul_eq_mul] push_cast ring rw [Finset.sum_insert haR2, Finset.sum_insert haR2, hnx', hx' R (subset_refl R)] at IH have e1 : x' a = x a + x b := by simp [x'] rw [e1] at IH rw [Finset.sum_insert haR', Finset.sum_insert hbR', Finset.sum_insert haR', Finset.sum_insert hbR', β add_assoc (x a) (x b)] have p1 : (2 : β) ^ (k + 1 + 1) = 4 * 2 ^ k := by ring have p2 : (2 : β) ^ (k + 1) = 2 * 2 ^ k := by ring rw [p2] at IH rw [p1] have := hF.trans_eq hsum nlinarith [this, IH] private lemma sum_range_split (h : β β β) (m : β) : β k β range (m + 4), h k = h 0 + h 1 + β k β Icc 2 (m + 2), h k + h (m + 3) := by induction m with | zero => simp [Finset.sum_range_succ] | succ m ih => rw [Finset.sum_range_succ, ih, show m + 1 + 2 = (m + 2) + 1 from rfl, Finset.sum_Icc_succ_top (a := 2) (b := m + 2) (by omega)] ring /-- **Generalised Hlawka inequality (DjokoviΔ 1963; SmileyβSmiley 1964).** For `n β₯ 3` vectors of a realinner product space, write `d_k` for the sum of the norms of all `k`-element subsums. Then`d_2 + β― + d_{n-1} β€ (2^(n-2) - 1) (d_1 + d_n)`. For `n = 3` this is Hlawka's inequality`βx+yβ + βy+zβ + βz+xβ β€ βxβ + βyβ + βzβ + βx+y+zβ`. -/theorem generalised {n : β} (hn : 3 β€ n) (x : Fin n β E) : β k β Finset.Icc 2 (n - 1), β S β (Finset.univ : Finset (Fin n)).powersetCard k, ββ i β S, x iβ β€ (2 ^ (n - 2) - 1 : β) * (β i, βx iβ + ββ i, x iβ) := by obtain β¨m, rflβ© : β m, n = m + 3 := β¨n - 3, by omegaβ© have hK := key (m + 3) (Finset.univ : Finset (Fin (m + 3))) x (by simp) have hF : β S β (Finset.univ : Finset (Fin (m + 3))).powerset, ββ i β S, x iβ = β k β range (m + 4), β S β (Finset.univ : Finset (Fin (m + 3))).powersetCard k, ββ i β S, x iβ := by rw [Finset.powerset_card_biUnion, Finset.sum_biUnion ((Finset.pairwise_disjoint_powersetCard _).set_pairwise _)] simp rw [hF, sum_range_split (fun k => β S β (Finset.univ : Finset (Fin (m + 3))).powersetCard k, ββ i β S, x iβ)] at hK have h0 : β S β (Finset.univ : Finset (Fin (m + 3))).powersetCard 0, ββ i β S, x iβ = 0 := by simp have h1 : β S β (Finset.univ : Finset (Fin (m + 3))).powersetCard 1, ββ i β S, x iβ = β i, βx iβ := by rw [Finset.powersetCard_one, Finset.sum_map] simp have hn : β S β (Finset.univ : Finset (Fin (m + 3))).powersetCard (m + 3), ββ i β S, x iβ = ββ i, x iβ := by have := Finset.powersetCard_self (Finset.univ : Finset (Fin (m + 3))) rw [Finset.card_univ, Fintype.card_fin] at this rw [this] simp simp only [h0, h1, hn] at hK have e1 : m + 3 - 1 = m + 2 := rfl have e2 : m + 3 - 2 = m + 1 := rfl rw [e1, e2] have p : (2 : β) ^ (m + 3) = 4 * 2 ^ (m + 1) := by ring rw [p] at hK nlinarith [hK] end Hlawka