{
  "id": "7803",
  "ident": "NS.07803",
  "slug": "wikipedia-dedekindnumber",
  "title": "Dedekind Numbers",
  "status": "solved",
  "statement_status": "reviewed",
  "statement_md": "Kisielewicz (1988) proved the following arithmetic formula for the Dedekind numbers:\n$$\n  M(n) = \\sum_{k=0}^{2^{2^n}}\\prod_{j = 1}^{2 ^ n - 1}\\prod_{i = 0}^{j - 1} \\left(\n    1 - b_i^kb_j^k \\prod_{m = 0}^{\\log_2 i} (1 - b_m^i + b_m^ib_m^j)\\right),\n$$\nwhere $b_i^k$ is the $i$-th bit of $k$. However, this formula is not computationally\nefficient for large $n$.",
  "subjects": [
    "math.CO",
    "msc:05",
    "msc:06"
  ],
  "tags": [],
  "collection": "wikipedia",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "DedekindNumber.M_eq_kisielewiczFormula",
  "statement_lean": "theorem M_eq_kisielewiczFormula : M = kisielewiczFormula",
  "challenge_source": "/-\nCopyright 2025 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# Dedekind Numbers\n\nA Dedekind number `M(n)` counts the number of monotone Boolean functions on `n` variables,\nor equivalently, the number of antichains (Sperner families) in the Boolean lattice `2^[n]`.\n\nFor example,\n$$M ( 0 ) = 2 , M ( 1 ) = 3 , M ( 2 ) = 6 , and M ( 3 ) = 20 .$$\nThe first few values grew slowly:\n$$M ( 4 ) = 168 , M ( 5 ) = 7581$$,\nbut then rapidly:\n$$M ( 6 ) = 7828354 , M ( 7 ) = 2414682040998 , M ( 8 ) = 56130437228687557907788$$, and\n$$M ( 9 ) = 286386577668298411128469151667598498812366$$\n(computed in 2023).\n\nWe formalize two definitions:\n- `M n`: the number of monotone Boolean functions `(Fin n → Bool) → Bool`\n- `M' n`: the number of antichains (Sperner families) of `Finset (Fin n)`\n\nWe prove their values for small `n` and show that the two definitions agree for all `n`.\n\nThe problem is to determine the exact values of $M(n)$ for $n ≥ 10$.\nIn particular, the value of $M(10)$ is currently unknown.\n\n*References:*\n- [Wikipedia](https://en.wikipedia.org/wiki/Dedekind_number)\n- [Oeis/A372](https://oeis.org/A000372)\n\n-/\n\n@[expose] public section\n\nnamespace DedekindNumber\n\nopen Finset\n\ninstance piFinBoolDecidableLE {n : ℕ} :\n    DecidableRel (fun (a b : Fin n → Bool) => a ≤ b) :=\n  fun a b => show Decidable (a ≤ b) from by\n    rw [Pi.le_def]\n    exact Fintype.decidableForallFintype\n\n/-- $M(n)$ is the number of monotone Boolean functions on $n$ variables. -/\ndef M (n : ℕ) : ℕ :=\n  Fintype.card {f : (Fin n → Bool) → Bool // Monotone f}\n\n/-- A Sperner family (antichain) of subsets of `Fin n`: a family of sets such that\n    no member is a subset of another. -/\ndef IsSperner {n : ℕ} (A : Finset (Finset (Fin n))) : Prop :=\n  IsAntichain (fun s t => s ⊆ t) (A : Set (Finset (Fin n)))\n\ninstance isSpernerDecidable {n : ℕ} :\n    DecidablePred (fun A : Finset (Finset (Fin n)) => IsSperner A) :=\n  fun A => by\n    unfold IsSperner IsAntichain Set.Pairwise\n    simp only [Finset.mem_coe, Pi.compl_apply, compl_iff_not]\n    exact inferInstance\n\n/-- $M'(n)$ is the number of antichains (Sperner families) of subsets of `Fin n`. -/\ndef M' (n : ℕ) : ℕ :=\n  Fintype.card {A : Finset (Finset (Fin n)) // IsSperner A}\n\n/-- Values for small n -/\n@[category test, AMS 5]\ntheorem M_zero : M 0 = 2 := by native_decide\n\n@[category test, AMS 5]\ntheorem M_one : M 1 = 3 := by native_decide\n\n@[category test, AMS 5]\ntheorem M_two : M 2 = 6 := by native_decide\n\n@[category test, AMS 5]\ntheorem M_three : M 3 = 20 := by native_decide\n\n@[category test, AMS 6]\ntheorem M'_zero : M' 0 = 2 := by native_decide\n\n@[category test, AMS 6]\ntheorem M'_one : M' 1 = 3 := by native_decide\n\n@[category test, AMS 6]\ntheorem M'_two : M' 2 = 6 := by native_decide\n\n@[category test, AMS 6]\ntheorem M'_three : M' 3 = 20 := by native_decide\n\n/-  ## Equivalence of M and M'\n-/\n\n/-- The indicator function of a finset: `χ s i = true ↔ i ∈ s`. -/\ndef χ {n : ℕ} (s : Finset (Fin n)) : Fin n → Bool :=\n  fun i => decide (i ∈ s)\n\n/-- The support of a Boolean-valued function: `supp v = {i | v i = true}`. -/\ndef supp {n : ℕ} (v : Fin n → Bool) : Finset (Fin n) :=\n  univ.filter (fun i => v i = true)\n\n/-- Forward map: monotone function → Sperner family (the minimal true sets). -/\ndef toSperner {n : ℕ} (f : (Fin n → Bool) → Bool) : Finset (Finset (Fin n)) :=\n  univ.filter (fun s =>\n    f (χ s) = true ∧ ∀ t : Finset (Fin n), t ⊆ s → f (χ t) = true → s ⊆ t)\n\n/-- Backward map: Sperner family → monotone Boolean function. -/\ndef fromSperner {n : ℕ} (A : Finset (Finset (Fin n))) (v : Fin n → Bool) : Bool :=\n  decide (∃ s ∈ A, ∀ i ∈ s, v i = true)\n\n/-  ### Helper lemmas about χ and supp -/\n\n@[category API, AMS 5]\nlemma χ_supp {n : ℕ} (v : Fin n → Bool) : χ (supp v) = v := by\n  funext i; simp [χ, supp]\n\n@[category API, AMS 6]\nlemma supp_χ {n : ℕ} (s : Finset (Fin n)) : supp (χ s) = s := by\n  ext i\n  simp [χ, supp]\n\n@[category API, AMS 6]\nlemma χ_le_iff {n : ℕ} (s t : Finset (Fin n)) : χ s ≤ χ t ↔ s ⊆ t := by\n  simp [χ, Pi.le_def, Finset.subset_iff, Bool.le_iff_imp]\n\n@[category API, AMS 6]\nlemma mem_supp_iff {n : ℕ} (v : Fin n → Bool) (i : Fin n) : i ∈ supp v ↔ v i = true := by\n  simp [supp]\n\n@[category API, AMS 6]\nlemma toSperner_isSperner {n : ℕ} (f : (Fin n → Bool) → Bool) (_ : Monotone f) :\n    IsSperner (toSperner f) := by\n  intro s hs t ht hst; simp_all +decide [ Finset.ext_iff]\n  contrapose! hst; unfold toSperner at *; aesop\n\n@[category API, AMS 6]\nlemma fromSperner_monotone {n : ℕ} (A : Finset (Finset (Fin n))) (_ : IsSperner A) :\n    Monotone (fromSperner A) := by\n      intro v w hvw hfv\n      obtain ⟨s, hsA, hs⟩ : ∃ s ∈ A, s ⊆ supp v := by\n        unfold fromSperner at hfv\n        simp_all +decide [ Finset.subset_iff, mem_supp_iff ]\n      have hs_w : s ⊆ supp w := by\n        intro i hi; have := hs hi\n        simp_all +decide [ Finset.subset_iff, mem_supp_iff ]\n        exact Bool.eq_false_imp_eq_true.mp fun a ↦ hvw i (hs hi)\n      exact decide_eq_true\n        ( ⟨ s, hsA, fun i hi => by simpa using Finset.mem_filter.mp ( hs_w hi ) |>.2 ⟩ )\n\n/-- Every true set of a monotone Boolean function contains a minimal true set. -/\n@[category textbook, AMS 5 6]\nlemma exists_minimal_true_subset {n : ℕ} {f : (Fin n → Bool) → Bool} (_ : Monotone f)\n    {s : Finset (Fin n)} (hs : f (χ s) = true) :\n    ∃ t, t ⊆ s ∧ f (χ t) = true ∧ ∀ u, u ⊆ t → f (χ u) = true → t ⊆ u := by\n      obtain ⟨t, ht₁, ht₂⟩ :\n        ∃ t ∈ {t : Finset (Fin n) | t ⊆ s ∧ f (χ t) = true},\n        ∀ u ∈ {t : Finset (Fin n) | t ⊆ s ∧ f (χ t) = true}, t.card ≤ u.card := by\n        apply_rules [ Set.exists_min_image ]\n        · exact Set.finite_iff_bddAbove.mpr ⟨ s, fun t ht => ht.1 ⟩\n        · exact ⟨ s, Finset.Subset.refl _, hs ⟩\n      refine' ⟨ t, ht₁.1, ht₁.2, fun u hu hu' => _ ⟩\n      exact Classical.not_not.1 fun h =>\n        not_lt_of_ge ( ht₂ u ⟨ hu.trans ht₁.1, hu' ⟩ )\n        ( Finset.card_lt_card <| Finset.ssubset_iff_subset_ne.2 ⟨ hu, by aesop ⟩ )\n\n/-- Converting a monotone function to a Sperner family and back yields the same function. -/\n@[category textbook, AMS 5 6]\nlemma fromSperner_toSperner {n : ℕ} (f : (Fin n → Bool) → Bool) (hf : Monotone f) :\n    fromSperner (toSperner f) = f := by\n  funext v\n  by_cases h : f v <;> simp_all +decide [ fromSperner ]\n  · obtain ⟨t, ht₁, ht₂⟩ : ∃ t : Finset (Fin n),\n    t ⊆ Finset.univ.filter (fun i => v i = true) ∧\n    f (χ t) = true ∧\n    ∀ u : Finset (Fin n), u ⊆ t → f (χ u) = true → t ⊆ u := by\n      apply exists_minimal_true_subset hf;\n      convert h using 2\n      exact funext fun i => by unfold χ; aesop;\n    exact ⟨ t, Finset.mem_filter.mpr ⟨ Finset.mem_univ _, ht₂.1, ht₂.2 ⟩,\n    fun i hi => Finset.mem_filter.mp ( ht₁ hi ) |>.2 ⟩\n  · intro s hs; contrapose! h; simp_all +decide [ toSperner ]\n    refine' hf _ hs.1\n    intro i; by_cases hi : i ∈ s <;> simp_all +decide [ χ ]\n\n/-- Converting a Sperner family to a monotone function and back yields the same family. -/\n@[category textbook, AMS 5 6]\nlemma toSperner_fromSperner {n : ℕ} (A : Finset (Finset (Fin n))) (hA : IsSperner A) :\n    toSperner (fromSperner A) = A := by\n  ext s; simp [toSperner, fromSperner]\n  constructor <;> intro hs\n  all_goals generalize_proofs at *\n  · obtain ⟨ ⟨ t, ht₁, ht₂ ⟩, ht₃ ⟩ := hs\n    convert ht₁ using 1\n    exact subset_antisymm ( ht₃ t ( by unfold χ at ht₂; aesop ) t ht₁ ( by unfold χ; aesop ) )\n      ( by unfold χ at ht₂; aesop )\n  · refine' ⟨ ⟨ s, hs, _ ⟩, _ ⟩ <;> simp_all +decide [ IsSperner ]\n    · exact fun i hi => by unfold χ; aesop\n    · intro t ht x hx hx'; have := hA hx hs; simp_all +decide [ Finset.subset_iff, χ ]\n/--\n  The set of monotone Boolean functions on `n` variables is in bijection\n  with the set of Sperner families of subsets of `Fin n`.\n-/\ndef equivMonotoneSperner (n : ℕ) :\n    {f : (Fin n → Bool) → Bool // Monotone f} ≃\n    {A : Finset (Finset (Fin n)) // IsSperner A} where\n  toFun := fun ⟨f, hf⟩ => ⟨toSperner f, toSperner_isSperner f hf⟩\n  invFun := fun ⟨A, hA⟩ => ⟨fromSperner A, fromSperner_monotone A hA⟩\n  left_inv := fun ⟨f, hf⟩ => Subtype.ext (fromSperner_toSperner f hf)\n  right_inv := fun ⟨A, hA⟩ => Subtype.ext (toSperner_fromSperner A hA)\n\n@[category test, AMS 5 6]\ntheorem M_eq_M' : M  = M' := by\n  ext n\n  exact Fintype.card_congr (equivMonotoneSperner n)\n\n/-- A closed formula for the Dedekind numbers as found by Kisielewicz (1998):\n$$\n  M(n) = \\sum_{k=0}^{2^{2^n}}\\prod_{j = 1}^{2 ^ n - 1}\\prod_{i = 0}^{j - 1} \\left(\n    1 - b_i^kb_j^k \\prod_{m = 0}^{\\log_2 i} (1 - b_m^i + b_m^ib_m^j)\\right),\n$$,\nwhere $b_i^k$ is the $i$-th bit of $k$. -/\ndef kisielewiczFormula (n : ℕ) : ℕ :=\n  ∑ k ∈ Finset.range (2 ^ (2 ^ n)), ∏ j ∈ Finset.Icc 1 (2 ^ n), ∏ i ∈ Finset.range j,\n    (1 - (k.testBit i).toNat * (k.testBit j).toNat * ∏ m ∈ Finset.range (i.log2 + 1),\n      (1 - (i.testBit m).toNat + (i.testBit m).toNat * (j.testBit m).toNat))\n\n@[category test, AMS 5 6] theorem kisielewiczFormula_zero : kisielewiczFormula 0 = 2:= by decide\n@[category test, AMS 5 6] theorem kisielewiczFormula_one : kisielewiczFormula 1 = 3 := by decide\n@[category test, AMS 5 6] theorem kisielewiczFormula_two : kisielewiczFormula 2 = 6 := by decide\n@[category test, AMS 5 6] theorem kisielewiczFormula_three : kisielewiczFormula 3 = 20 := by\n  native_decide\n-- `native_decide` crashes for n = 4\n\n/-- Kisielewicz (1988) proved the following arithmetic formula for the Dedekind numbers:\n$$\n  M(n) = \\sum_{k=0}^{2^{2^n}}\\prod_{j = 1}^{2 ^ n - 1}\\prod_{i = 0}^{j - 1} \\left(\n    1 - b_i^kb_j^k \\prod_{m = 0}^{\\log_2 i} (1 - b_m^i + b_m^ib_m^j)\\right),\n$$\nwhere $b_i^k$ is the $i$-th bit of $k$. However, this formula is not computationally\nefficient for large $n$.\n-/\n@[category research solved, AMS 5 6]\ntheorem M_eq_kisielewiczFormula : M = kisielewiczFormula := by\n  sorry\n\ndef M_eq.answer : ℕ → ℕ := sorry\n\n/--\n  No closed-form expression that allows efficient computation of Dedekind numbers is\n  currently known.\n-/\n@[category research open, question value, AMS 5 6]\ntheorem M_eq : M = M_eq.answer := by\n  sorry\n\ndef Dedekind_10.answer : ℕ := sorry\n\n/--\n  In particular, the Dedekind number for `n = 10` is currently unknown.\n-/\n@[category research open, question value, AMS 5 6]\ntheorem Dedekind_10 : M 10 = Dedekind_10.answer := by sorry\n\nend DedekindNumber\n",
  "statement_hash": "9c992c34f3f08d0790edccc4cf31f3410fcc6e621a1d2b46f685f9fdb0536531",
  "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."
}