{
  "id": "8473",
  "ident": "NS.08473",
  "slug": "wikipedia-sixstandarddeviations--six-standard-deviations-variants-random-bound",
  "title": "Six standard deviations suffice (Spencer's theorem) · variants.random_bound",
  "status": "solved",
  "statement_status": "reviewed",
  "statement_md": "**The random colouring bound**\n\nThere is a constant $K > 0$ such that for every $n$ and every family of $n$ subsets\n$S_1, \\dots, S_n$ of $\\{1, \\dots, n\\}$, there is a colouring\n$\\chi : \\{1, \\dots, n\\} \\to \\{-1, +1\\}$ with\n$\\left|\\sum_{j \\in S_i} \\chi(j)\\right| \\le K \\sqrt{n \\log(n + 2)}$ for every $i$.\nThis follows from a Chernoff bound applied to a uniformly random colouring, and is\nthe benchmark that Spencer's theorem improves upon by removing the logarithmic\nfactor. (The shift $n + 2$ inside the logarithm is a harmless normalization keeping\nit positive for $n \\in \\{0, 1\\}$.)",
  "subjects": [
    "math.CO",
    "msc:05"
  ],
  "tags": [
    "formal_proof"
  ],
  "collection": "wikipedia",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "SixStandardDeviations.six_standard_deviations.variants.random_bound",
  "statement_lean": "theorem six_standard_deviations.variants.random_bound :\n    ∃ K : ℝ, 0 < K ∧ ∀ (n : ℕ) (S : Fin n → Finset (Fin n)),\n      ∃ χ : Fin n → ℝ, (∀ j, χ j = 1 ∨ χ j = -1) ∧\n        ∀ i, |∑ j ∈ S i, χ j| ≤ K * Real.sqrt (n * Real.log (n + 2))",
  "challenge_source": "/-\nCopyright 2026 The Formal Conjectures Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n-/\nmodule\n\npublic import FormalConjecturesUtil\n\n/-!\n# Six standard deviations suffice (Spencer's theorem)\n\nSpencer's theorem in discrepancy theory: for every $n$ and every family of $n$ subsets\n$S_1, \\dots, S_n$ of $\\{1, \\dots, n\\}$, there is a colouring\n$\\chi : \\{1, \\dots, n\\} \\to \\{-1, +1\\}$ such that\n$$\\left|\\sum_{j \\in S_i} \\chi(j)\\right| \\le 6\\sqrt{n}$$\nfor every $i$.\n\nA uniformly random colouring only achieves the bound $O(\\sqrt{n \\log n})$, so Spencer's\ntheorem (\"six standard deviations suffice\") is a genuine improvement over the basic\nprobabilistic method; its proof uses a partial-colouring argument based on the entropy\nmethod, and the bound $\\Theta(\\sqrt{n})$ is tight up to the value of the constant.\nSpencer's original argument is non-constructive; polynomial-time algorithms achieving\n$O(\\sqrt{n})$ were later found by Bansal (2010) and Lovett–Meka (2012).\n\nThe Komlós conjecture (the subject of a companion file in this directory) would\nstrengthen this theorem: applied to the incidence vectors of the sets, scaled by\n$1/\\sqrt{n}$, it would give a discrepancy bound $O(\\sqrt{n})$ for any number of sets,\nnot just $n$ of them.\n\n*References:*\n- [Wikipedia](https://en.wikipedia.org/wiki/Discrepancy_of_hypergraphs#General_hypergraphs)\n- [J. Spencer, *Six standard deviations suffice*,\n  Trans. Amer. Math. Soc. **289** (1985), 679–706](https://doi.org/10.1090/S0002-9947-1985-0784009-0)\n- [N. Bansal, *Constructive algorithms for discrepancy minimization*,\n  FOCS 2010, 3–10](https://doi.org/10.1109/FOCS.2010.7)\n- [S. Lovett and R. Meka, *Constructive discrepancy minimization by walking on the edges*,\n  SIAM J. Comput. **44** (2015), 1573–1582](https://doi.org/10.1137/130929400)\n-/\n\n@[expose] public section\n\nnamespace SixStandardDeviations\n\n/--\n**Six standard deviations suffice** (Spencer, 1985)\n\nFor every $n$ and every family of $n$ subsets $S_1, \\dots, S_n$ of $\\{1, \\dots, n\\}$,\nthere is a colouring $\\chi : \\{1, \\dots, n\\} \\to \\{-1, +1\\}$ such that\n$\\left|\\sum_{j \\in S_i} \\chi(j)\\right| \\le 6\\sqrt{n}$ for every $i$.\n-/\n@[category research solved, AMS 5]\ntheorem six_standard_deviations :\n    ∀ (n : ℕ) (S : Fin n → Finset (Fin n)),\n      ∃ χ : Fin n → ℝ, (∀ j, χ j = 1 ∨ χ j = -1) ∧\n        ∀ i, |∑ j ∈ S i, χ j| ≤ 6 * Real.sqrt n := by\n  sorry\n\nset_option linter.style.formal_proof_palomar false in\n/--\n**The random colouring bound**\n\nThere is a constant $K > 0$ such that for every $n$ and every family of $n$ subsets\n$S_1, \\dots, S_n$ of $\\{1, \\dots, n\\}$, there is a colouring\n$\\chi : \\{1, \\dots, n\\} \\to \\{-1, +1\\}$ with\n$\\left|\\sum_{j \\in S_i} \\chi(j)\\right| \\le K \\sqrt{n \\log(n + 2)}$ for every $i$.\nThis follows from a Chernoff bound applied to a uniformly random colouring, and is\nthe benchmark that Spencer's theorem improves upon by removing the logarithmic\nfactor. (The shift $n + 2$ inside the logarithm is a harmless normalization keeping\nit positive for $n \\in \\{0, 1\\}$.)\n-/\n@[category research solved, AMS 5,\n  formal_proof using lean4 at\n    \"https://github.com/Lemmy00/spencer-random-coloring-lean/blob/a691214a7263c1010fdd10560091e9f8cfce903a/SpencerRandomColoring/RandomBound.lean#L37\"]\ntheorem six_standard_deviations.variants.random_bound :\n    ∃ K : ℝ, 0 < K ∧ ∀ (n : ℕ) (S : Fin n → Finset (Fin n)),\n      ∃ χ : Fin n → ℝ, (∀ j, χ j = 1 ∨ χ j = -1) ∧\n        ∀ i, |∑ j ∈ S i, χ j| ≤ K * Real.sqrt (n * Real.log (n + 2)) := by\n  sorry\n\nset_option linter.style.formal_proof_palomar false in\n/--\n**A universal discrepancy bound**\n\nThere is a positive universal constant $K$ such that every family of $n$ subsets\nof the `n` points has a colouring with discrepancy at most $K\\sqrt{n}$ in every\nrow. This qualitative form has the optimal order of growth, but it does not assert\nthe constant $6$ in Spencer's theorem.\n-/\n@[category research solved, AMS 5,\n  formal_proof using lean4 at\n    \"https://github.com/Lemmy00/spencer-universal-bound-lean/blob/e8d83c0a99f7c1be5a04aa155164bc477d2c6df3/Spencer/UniversalBound.lean#L15\"]\ntheorem six_standard_deviations.variants.universal_bound :\n    ∃ K : ℝ, 0 < K ∧ ∀ (n : ℕ) (S : Fin n → Finset (Fin n)),\n      ∃ χ : Fin n → ℝ, (∀ j, χ j = 1 ∨ χ j = -1) ∧\n        ∀ i, |∑ j ∈ S i, χ j| ≤ K * Real.sqrt n := by\n  sorry\n\n/--\nSanity check: with no points and no sets ($n = 0$), the empty colouring works and\nthe bound $6\\sqrt{0} = 0$ holds vacuously.\n-/\n@[category test, AMS 5]\ntheorem six_standard_deviations.variants.zero_sets (S : Fin 0 → Finset (Fin 0)) :\n    ∃ χ : Fin 0 → ℝ, (∀ j, χ j = 1 ∨ χ j = -1) ∧\n      ∀ i, |∑ j ∈ S i, χ j| ≤ 6 * Real.sqrt 0 :=\n  ⟨Fin.elim0, fun j => j.elim0, fun i => i.elim0⟩\n\nend SixStandardDeviations\n",
  "statement_hash": "b7ef7e887818fa0811629b53f26c00f85d246f0bedecbe6b5e1d0fb1a59518c9",
  "toolchain": "leanprover/lean4:v4.33.1",
  "upstream_commit": "f9b3868d5ca994a7bf95039bcec05338c0c21e2f",
  "workspace": "formal-conjectures",
  "field": "math",
  "formalization": "formal",
  "verification": "lean-kernel",
  "license": "Apache-2.0",
  "attribution": "google-deepmind/formal-conjectures contributors",
  "metric_name": null,
  "metric_direction": null,
  "critiques": [],
  "public_partial_proofs": [],
  "research_threads": [],
  "instructions": "Read research_threads first: other people's public repositories and what they already tried. Write Solution.lean starting from challenge_source. Keep every definition identical, prove decl_name with exactly the same type, no sorry in its dependency closure, no new axioms, no native_decide, no metaprogramming. Submit with POST /api/v1/submissions."
}