import Mathlib /-! # Shellability, Partitionability, Stanley's `h`-Vector Nonnegativity, and Eulerian Numbers This module formalizes the combinatorial topology of pure shellable and partitionable finite simplicial complexes, proving Stanley's exact restriction-set `h`-vector theorem and constructing explicit shellings for classical complex families alongside negative-`h_2` separation witnesses: 1. **Pure Complexes, Shellability, and Restriction Sets (`IsShelling`, `IsShellable`, `restrSet`)**: - Exact characterization of pure shellability via codimension-1 intersection with earlier facets. - Exact Boolean-interval partitionability (`IsPartitionable`) into intervals `[R_j, F_j]`. - **Interval Partition Theorem (`shelling_interval_partition`)**: every shelling partitions `K.faces` into the pairwise disjoint Boolean intervals `[restrSet F j, F j]`, hence every shellable complex is partitionable (`shellable_imp_partitionable`). 2. **Stanley's `h`-Vector Theorem (`partitionable_hVec_eq_card`, `shellable_hVec_eq_card_restrSet`)**: - For every partitionable complex `(R, F)` of dimension parameter `d`, `K.hVec d r = #{j | (R j).card = r}` for all `r ≤ d`, hence `0 ≤ K.hVec d r`. - For every shellable complex `(K, F)`: - `K.hVec d r = #{j | (restrSet F j).card = r} ≥ 0` for all `r ≤ d`, - `K.fVecCard d = m` (number of facets), - `K.hVec d d = #{j | restrSet F j = F j}` (spanning / homology facets). 3. **Explicit Constructive Shellings for Classical Families**: - **Full simplex `Δ_{d-1}`** (`simplexComplex_isShellable`): `m = 1` facet, `h = (1, 0, ..., 0)`. - **Simplex boundary `∂Δ_d`** (`simplexBoundary_isShellable`): `m = d + 1` facets with `|(restrSet F j)| = j`, giving a purely combinatorial shelling proof of `h_k(∂Δ_d) = 1`. - **Cross-polytope boundary `∂β_d`** (`crossPolytope_isShellable`): `m = 2^d` facets ordered by binary value with `|(restrSet F j)| = popcount(j)`, proving `h_k(∂β_d) = C(d, k)`. - **Boolean Lattice Order Complex / Coxeter Complex `sd(Δ_{n-1})`** (`booleanOrderComplex_isShellable`, `booleanOrderComplex_hVec_eq_eulerian`): lexicographic shelling of permutations `S_n` where `|restrSet(τ)| = descents(τ)`, proving that the `h`-vector of the barycentric subdivision of the simplex is the **Eulerian number** `A(n, k) = #{τ ∈ Equiv.Perm (Fin n) | descents(τ) = k}`! 4. **Non-Shellable and Non-Partitionable Separation Witnesses**: - **Bowtie complex** (two triangles sharing one vertex, pure connected 2-complex): `f = [1, 5, 6, 2]`, `h_2 = -1 < 0` → provably NOT partitionable and NOT shellable. - **Disjoint triangles** (two disjoint triangles, pure 2-complex): `f = [1, 6, 6, 2]`, `h_2 = -3 < 0` → provably NOT partitionable and NOT shellable. -/ namespace ShellabilityPartitionabilityAndStanley open Finset open Polynomial /-! ## Section 1: Finite Simplicial Complexes and the Exact `f ↔ h` Algebra -/ /-- A finite abstract simplicial complex on a vertex type `V`, closed under subsets and containing `∅`. -/ structure FinSimplicialComplex (V : Type*) [DecidableEq V] where faces : Finset (Finset V) down_closed : ∀ ⦃σ τ : Finset V⦄, σ ∈ faces → τ ⊆ σ → τ ∈ faces empty_mem : ∅ ∈ faces variable {V : Type*} [DecidableEq V] /-- `K.HasDimLe d` means every face of `K` has cardinality at most `d`. -/ def FinSimplicialComplex.HasDimLe (K : FinSimplicialComplex V) (d : ℕ) : Prop := ∀ σ ∈ K.faces, σ.card ≤ d /-- Number of faces of cardinality `k` (so `fVecCard K 0 = 1`, `fVecCard K 1 = #vertices`, etc.). -/ def FinSimplicialComplex.fVecCard (K : FinSimplicialComplex V) (k : ℕ) : ℕ := (K.faces.filter (fun σ => σ.card = k)).card /-- Integer-valued `f`-vector `fVec K k = (fVecCard K k : ℤ)`. -/ def FinSimplicialComplex.fVec (K : FinSimplicialComplex V) (k : ℕ) : ℤ := (K.fVecCard k : ℤ) /-- Exact `f → h` transform `h_k = ∑_{i=0}^k (-1)^{k-i} C(d - i, k - i) f_i`. -/ def fToH (d : ℕ) (f : ℕ → ℤ) (k : ℕ) : ℤ := ∑ i ∈ Finset.range (k + 1), (-1 : ℤ) ^ (k - i) * (Nat.choose (d - i) (k - i) : ℤ) * f i /-- Exact `h → f` transform `f_k = ∑_{i=0}^k C(d - i, k - i) h_i`. -/ def hToF (d : ℕ) (h : ℕ → ℤ) (k : ℕ) : ℤ := ∑ i ∈ Finset.range (k + 1), (Nat.choose (d - i) (k - i) : ℤ) * h i /-- The `h`-vector of `K` with dimension parameter `d`. -/ def FinSimplicialComplex.hVec (K : FinSimplicialComplex V) (d k : ℕ) : ℤ := fToH d K.fVec k /-- Polynomial `∑_{i=0}^d f_i X^{d - i}` in `ℤ[X]`. -/ noncomputable def fPoly (d : ℕ) (f : ℕ → ℤ) : ℤ[X] := ∑ i ∈ Finset.range (d + 1), Polynomial.C (f i) * X ^ (d - i) /-- `h`-polynomial `∑_{k=0}^d h_k X^{d - k}` in `ℤ[X]`. -/ noncomputable def hPoly (d : ℕ) (f : ℕ → ℤ) : ℤ[X] := fPoly d (fToH d f) lemma coeff_fPoly (d : ℕ) (f : ℕ → ℤ) {k : ℕ} (hk : k ≤ d) : (fPoly d f).coeff (d - k) = f k := by unfold fPoly rw [Polynomial.finsetSum_coeff] rw [Finset.sum_eq_single k] · simp · intro i hi hik have hid : i ≤ d := Nat.lt_succ_iff.mp (Finset.mem_range.mp hi) have hne : d - i ≠ d - k := by omega simp [Polynomial.coeff_X_pow, hne.symm] · intro h; exact absurd (Finset.mem_range.mpr (Nat.lt_succ_of_le hk)) h lemma fPoly_comp_sub_one_eq_hPoly (d : ℕ) (f : ℕ → ℤ) : (∑ i ∈ Finset.range (d + 1), Polynomial.C (f i) * (X - 1) ^ (d - i)) = hPoly d f := by have hexp : ∀ i ∈ Finset.range (d + 1), Polynomial.C (f i) * (X - 1) ^ (d - i) = ∑ k ∈ Finset.Icc i d, Polynomial.C ((-1 : ℤ) ^ (k - i) * (Nat.choose (d - i) (k - i) : ℤ) * f i) * X ^ (d - k) := by intro i hi have hid : i ≤ d := Nat.lt_succ_iff.mp (Finset.mem_range.mp hi) rw [sub_eq_add_neg, add_pow, Finset.mul_sum] refine Finset.sum_bij (fun j _ => d - j) ?_ ?_ ?_ ?_ · intro j hj have hj' : j ≤ d - i := Nat.lt_succ_iff.mp (Finset.mem_range.mp hj) exact Finset.mem_Icc.mpr ⟨by omega, by omega⟩ · intro j₁ hj₁ j₂ hj₂ heq have h1 : j₁ ≤ d - i := Nat.lt_succ_iff.mp (Finset.mem_range.mp hj₁) have h2 : j₂ ≤ d - i := Nat.lt_succ_iff.mp (Finset.mem_range.mp hj₂) omega · intro k hk rcases Finset.mem_Icc.mp hk with ⟨hik, hkd⟩ exact ⟨d - k, Finset.mem_range.mpr (by omega), by omega⟩ · intro j hj have hj' : j ≤ d - i := Nat.lt_succ_iff.mp (Finset.mem_range.mp hj) have hsub1 : d - (d - j) = j := by omega have hsub2 : d - j - i = d - i - j := by omega have hch : (d - i).choose j = (d - i).choose (d - j - i) := by rw [hsub2, Nat.choose_symm hj'] rw [hsub1, ← hsub2, hch] simp only [map_mul, map_pow, map_neg, map_one, map_natCast] ring rw [Finset.sum_congr rfl hexp] have hswap : (∑ i ∈ Finset.range (d + 1), ∑ k ∈ Finset.Icc i d, Polynomial.C ((-1 : ℤ) ^ (k - i) * (Nat.choose (d - i) (k - i) : ℤ) * f i) * X ^ (d - k)) = ∑ k ∈ Finset.range (d + 1), ∑ i ∈ Finset.range (k + 1), Polynomial.C ((-1 : ℤ) ^ (k - i) * (Nat.choose (d - i) (k - i) : ℤ) * f i) * X ^ (d - k) := by have hL : ∀ i ∈ Finset.range (d + 1), (∑ k ∈ Finset.Icc i d, Polynomial.C ((-1 : ℤ) ^ (k - i) * (Nat.choose (d - i) (k - i) : ℤ) * f i) * X ^ (d - k)) = ∑ k ∈ Finset.range (d + 1), if i ≤ k then Polynomial.C ((-1 : ℤ) ^ (k - i) * (Nat.choose (d - i) (k - i) : ℤ) * f i) * X ^ (d - k) else 0 := by intro i _; rw [← Finset.sum_filter]; congr 1; ext k simp only [Finset.mem_Icc, Finset.mem_filter, Finset.mem_range]; omega have hR : ∀ k ∈ Finset.range (d + 1), (∑ i ∈ Finset.range (k + 1), Polynomial.C ((-1 : ℤ) ^ (k - i) * (Nat.choose (d - i) (k - i) : ℤ) * f i) * X ^ (d - k)) = ∑ i ∈ Finset.range (d + 1), if i ≤ k then Polynomial.C ((-1 : ℤ) ^ (k - i) * (Nat.choose (d - i) (k - i) : ℤ) * f i) * X ^ (d - k) else 0 := by intro k hk have hkd : k ≤ d := Nat.lt_succ_iff.mp (Finset.mem_range.mp hk) rw [← Finset.sum_filter]; congr 1; ext i simp only [Finset.mem_range, Finset.mem_filter]; omega rw [Finset.sum_congr rfl hL, Finset.sum_comm] exact Finset.sum_congr rfl fun k hk => (hR k hk).symm rw [hswap] unfold hPoly fPoly fToH refine Finset.sum_congr rfl fun k _ => ?_ rw [map_sum, Finset.sum_mul] lemma hPoly_comp_add_one_eq_fPoly (d : ℕ) (h : ℕ → ℤ) : (∑ k ∈ Finset.range (d + 1), Polynomial.C (h k) * (X + 1) ^ (d - k)) = fPoly d (hToF d h) := by have hexp : ∀ k ∈ Finset.range (d + 1), Polynomial.C (h k) * (X + 1) ^ (d - k) = ∑ i ∈ Finset.Icc k d, Polynomial.C ((Nat.choose (d - k) (i - k) : ℤ) * h k) * X ^ (d - i) := by intro k hk have hkd : k ≤ d := Nat.lt_succ_iff.mp (Finset.mem_range.mp hk) rw [add_pow, Finset.mul_sum] refine Finset.sum_bij (fun j _ => d - j) ?_ ?_ ?_ ?_ · intro j hj have hj' : j ≤ d - k := Nat.lt_succ_iff.mp (Finset.mem_range.mp hj) exact Finset.mem_Icc.mpr ⟨by omega, by omega⟩ · intro j₁ hj₁ j₂ hj₂ heq have h1 : j₁ ≤ d - k := Nat.lt_succ_iff.mp (Finset.mem_range.mp hj₁) have h2 : j₂ ≤ d - k := Nat.lt_succ_iff.mp (Finset.mem_range.mp hj₂) omega · intro i hi rcases Finset.mem_Icc.mp hi with ⟨hki, hid⟩ exact ⟨d - i, Finset.mem_range.mpr (by omega), by omega⟩ · intro j hj have hj' : j ≤ d - k := Nat.lt_succ_iff.mp (Finset.mem_range.mp hj) have hsub1 : d - (d - j) = j := by omega have hsub2 : d - j - k = d - k - j := by omega have hch : (d - k).choose j = (d - k).choose (d - j - k) := by rw [hsub2, Nat.choose_symm hj'] rw [hsub1, hch] simp only [one_pow, mul_one, map_mul, map_natCast] ring rw [Finset.sum_congr rfl hexp] have hswap : (∑ k ∈ Finset.range (d + 1), ∑ i ∈ Finset.Icc k d, Polynomial.C ((Nat.choose (d - k) (i - k) : ℤ) * h k) * X ^ (d - i)) = ∑ i ∈ Finset.range (d + 1), ∑ k ∈ Finset.range (i + 1), Polynomial.C ((Nat.choose (d - k) (i - k) : ℤ) * h k) * X ^ (d - i) := by have hL : ∀ k ∈ Finset.range (d + 1), (∑ i ∈ Finset.Icc k d, Polynomial.C ((Nat.choose (d - k) (i - k) : ℤ) * h k) * X ^ (d - i)) = ∑ i ∈ Finset.range (d + 1), if k ≤ i then Polynomial.C ((Nat.choose (d - k) (i - k) : ℤ) * h k) * X ^ (d - i) else 0 := by intro k _; rw [← Finset.sum_filter]; congr 1; ext i simp only [Finset.mem_Icc, Finset.mem_filter, Finset.mem_range]; omega have hR : ∀ i ∈ Finset.range (d + 1), (∑ k ∈ Finset.range (i + 1), Polynomial.C ((Nat.choose (d - k) (i - k) : ℤ) * h k) * X ^ (d - i)) = ∑ k ∈ Finset.range (d + 1), if k ≤ i then Polynomial.C ((Nat.choose (d - k) (i - k) : ℤ) * h k) * X ^ (d - i) else 0 := by intro i hi have hid : i ≤ d := Nat.lt_succ_iff.mp (Finset.mem_range.mp hi) rw [← Finset.sum_filter]; congr 1; ext k simp only [Finset.mem_range, Finset.mem_filter]; omega rw [Finset.sum_congr rfl hL, Finset.sum_comm] exact Finset.sum_congr rfl fun i hi => (hR i hi).symm rw [hswap] unfold fPoly hToF refine Finset.sum_congr rfl fun i _ => ?_ rw [map_sum, Finset.sum_mul] /-- Exact right-inversion `fToH d (hToF d h) k = h k` for all `k ≤ d`. -/ theorem fToH_hToF (d : ℕ) (h : ℕ → ℤ) {k : ℕ} (hk : k ≤ d) : fToH d (hToF d h) k = h k := by have h1 : (fPoly d (hToF d h)).comp (X - 1) = hPoly d (hToF d h) := by rw [← fPoly_comp_sub_one_eq_hPoly] simp only [fPoly, Polynomial.sum_comp, Polynomial.mul_comp, Polynomial.C_comp, Polynomial.pow_comp, Polynomial.X_comp] have h2 : (fPoly d (hToF d h)).comp (X - 1) = fPoly d h := by rw [← hPoly_comp_add_one_eq_fPoly] simp only [Polynomial.sum_comp, Polynomial.mul_comp, Polynomial.C_comp, Polynomial.pow_comp, Polynomial.add_comp, Polynomial.X_comp, Polynomial.one_comp, sub_add_cancel] rfl have hpoly : hPoly d (hToF d h) = fPoly d h := h1.symm.trans h2 have hcoeff := congrArg (fun p => p.coeff (d - k)) hpoly rwa [hPoly, coeff_fPoly d _ hk, coeff_fPoly d _ hk] at hcoeff lemma fToH_congr {d k : ℕ} {f₁ f₂ : ℕ → ℤ} (h : ∀ i ≤ k, f₁ i = f₂ i) : fToH d f₁ k = fToH d f₂ k := by unfold fToH refine Finset.sum_congr rfl fun i hi => ?_ rw [h i (Nat.lt_succ_iff.mp (Finset.mem_range.mp hi))] /-! ## Section 2: Shellability, Restriction Sets, Partitionability & Stanley's Theorem -/ /-- A simplicial complex `K` is **pure** of dimension parameter `d` (topological dimension `d - 1`) if every face has cardinality `≤ d` and is contained in some face of cardinality `d`. -/ def IsPure (K : FinSimplicialComplex V) (d : ℕ) : Prop := K.HasDimLe d ∧ ∀ σ ∈ K.faces, ∃ τ ∈ K.faces, τ.card = d ∧ σ ⊆ τ /-- A **pure shelling** of `K` with `m` facets `F : Fin m → Finset V` of cardinality `d`: 1. Each `F j` is a face of `K` of cardinality `d`. 2. `F` is injective (no repeated facets). 3. Every face of `K` is contained in some `F j`. 4. (Shelling condition) For every `i < j`, there exist `i' < j` and `v ∈ F j \ F i` with `F j.erase v ⊆ F i'`. -/ structure IsShelling (K : FinSimplicialComplex V) (d m : ℕ) (F : Fin m → Finset V) : Prop where mem_faces : ∀ j, F j ∈ K.faces card_eq : ∀ j, (F j).card = d injective : Function.Injective F covers : ∀ σ ∈ K.faces, ∃ j, σ ⊆ F j shell_step : ∀ ⦃i j : Fin m⦄, i < j → ∃ i' : Fin m, i' < j ∧ ∃ v ∈ F j, v ∉ F i ∧ (F j).erase v ⊆ F i' /-- `K` is pure shellable of dimension parameter `d`. -/ def IsShellable (K : FinSimplicialComplex V) (d : ℕ) : Prop := ∃ (m : ℕ) (F : Fin m → Finset V), IsShelling K d m F /-- Every shellable complex is pure of dimension parameter `d`. -/ theorem isPure_of_isShellable {K : FinSimplicialComplex V} {d : ℕ} (h : IsShellable K d) : IsPure K d := by rcases h with ⟨m, F, hs⟩ refine ⟨fun σ hσ => ?_, fun σ hσ => ?_⟩ · rcases hs.covers σ hσ with ⟨j, hsub⟩ exact (Finset.card_le_card hsub).trans (le_of_eq (hs.card_eq j)) · rcases hs.covers σ hσ with ⟨j, hsub⟩ exact ⟨F j, hs.mem_faces j, hs.card_eq j, hsub⟩ /-- For distinct facets of the same cardinality, `F j.erase v ⊆ F i'` is equivalent to `F i' ∩ F j = F j.erase v`. -/ lemma erase_subset_iff_inter_eq {K : FinSimplicialComplex V} {d m : ℕ} {F : Fin m → Finset V} (hs : IsShelling K d m F) {i' j : Fin m} (hne : i' ≠ j) {v : V} (_hv : v ∈ F j) : (F j).erase v ⊆ F i' ↔ F i' ∩ F j = (F j).erase v := by constructor · intro hsub apply Finset.eq_of_subset_of_card_le · intro x hx rw [Finset.mem_inter] at hx refine Finset.mem_erase.mpr ⟨?_, hx.2⟩ intro hxv; subst x have hFj_sub : F j ⊆ F i' := by intro y hy by_cases hyv : y = v · exact hyv ▸ hx.1 · exact hsub (Finset.mem_erase.mpr ⟨hyv, hy⟩) have heq : F j = F i' := Finset.eq_of_subset_of_card_le hFj_sub (by rw [hs.card_eq i', hs.card_eq j]) exact hne (hs.injective heq.symm) · refine Finset.card_le_card fun x hx => Finset.mem_inter.mpr ⟨hsub hx, Finset.mem_of_mem_erase hx⟩ · intro heq rw [← heq] exact Finset.inter_subset_left /-- The **restriction set** `R(F_j)` of the `j`-th facet in a shelling `F`: all vertices `v ∈ F_j` whose codimension-1 face `F_j \ {v}` already lies in an earlier facet. -/ def restrSet {m : ℕ} (F : Fin m → Finset V) (j : Fin m) : Finset V := (F j).filter (fun v => ∃ i : Fin m, i < j ∧ (F j).erase v ⊆ F i) lemma restrSet_subset {m : ℕ} (F : Fin m → Finset V) (j : Fin m) : restrSet F j ⊆ F j := Finset.filter_subset _ _ /-- The **Boolean interval** `[R, G] = {σ | R ⊆ σ ⊆ G}` in the face lattice. -/ def boolInterval (R G : Finset V) : Finset (Finset V) := G.powerset.filter (fun σ => R ⊆ σ) lemma mem_boolInterval {R G σ : Finset V} : σ ∈ boolInterval R G ↔ R ⊆ σ ∧ σ ⊆ G := by simp only [boolInterval, Finset.mem_filter, Finset.mem_powerset] exact and_comm /-- A **Boolean-interval partition** of `K` with `m` intervals `[R_j, F_j]` of top cardinality `d`. -/ structure IsPartition (K : FinSimplicialComplex V) (d m : ℕ) (R F : Fin m → Finset V) : Prop where subset_top : ∀ j, R j ⊆ F j card_top : ∀ j, (F j).card = d pairwise_disjoint : ∀ ⦃j₁ j₂ : Fin m⦄, j₁ ≠ j₂ → Disjoint (boolInterval (R j₁) (F j₁)) (boolInterval (R j₂) (F j₂)) union_eq : K.faces = Finset.univ.biUnion (fun j => boolInterval (R j) (F j)) /-- `K` is **partitionable** of dimension parameter `d`. -/ def IsPartitionable (K : FinSimplicialComplex V) (d : ℕ) : Prop := ∃ (m : ℕ) (R F : Fin m → Finset V), IsPartition K d m R F /-- **THEOREM 2A — Exact Restriction-Set Characterization of the First Containing Facet**: In a shelling `F`, a face `σ` belongs to `[restrSet F j, F j]` if and only if `j` is the **least** index with `σ ⊆ F j`! -/ theorem mem_boolInterval_restrSet_iff {K : FinSimplicialComplex V} {d m : ℕ} {F : Fin m → Finset V} (hs : IsShelling K d m F) {σ : Finset V} {j : Fin m} : σ ∈ boolInterval (restrSet F j) (F j) ↔ (σ ⊆ F j ∧ ∀ i : Fin m, i < j → ¬ σ ⊆ F i) := by rw [mem_boolInterval] constructor · rintro ⟨hRσ, hσF⟩ refine ⟨hσF, fun i hij hσi => ?_⟩ rcases hs.shell_step hij with ⟨i', hi'j, v, hvj, hvi, herase⟩ have hvR : v ∈ restrSet F j := Finset.mem_filter.mpr ⟨hvj, i', hi'j, herase⟩ exact hvi (hσi (hRσ hvR)) · rintro ⟨hσF, hmin⟩ refine ⟨fun v hvR => ?_, hσF⟩ rcases Finset.mem_filter.mp hvR with ⟨_, i, hij, herase⟩ by_contra hvσ have hsub : σ ⊆ (F j).erase v := fun x hx => Finset.mem_erase.mpr ⟨fun hxv => hvσ (hxv ▸ hx), hσF hx⟩ exact hmin i hij (hsub.trans herase) /-- **THEOREM 2B — Shelling Interval Partition Theorem (`shelling_interval_partition`)**: Every shelling `F` partitions `K.faces` into the pairwise disjoint Boolean intervals `[restrSet F j, F j]`. -/ theorem shelling_interval_partition {K : FinSimplicialComplex V} {d m : ℕ} {F : Fin m → Finset V} (hs : IsShelling K d m F) : IsPartition K d m (restrSet F) F where subset_top := restrSet_subset F card_top := hs.card_eq pairwise_disjoint := by intro j₁ j₂ hne rw [Finset.disjoint_left] intro σ h1 h2 rw [mem_boolInterval_restrSet_iff hs] at h1 h2 rcases lt_or_gt_of_ne hne with hlt | hgt · exact h2.2 j₁ hlt h1.1 · exact h1.2 j₂ hgt h2.1 union_eq := by ext σ simp only [Finset.mem_biUnion, Finset.mem_univ, true_and] constructor · intro hσ have hex : ∃ n : ℕ, ∃ (hn : n < m), σ ⊆ F ⟨n, hn⟩ := by rcases hs.covers σ hσ with ⟨j, hj⟩ exact ⟨j.1, j.2, hj⟩ let n₀ := Nat.find hex have hn₀ : ∃ (hn : n₀ < m), σ ⊆ F ⟨n₀, hn⟩ := Nat.find_spec hex rcases hn₀ with ⟨hn₀_lt, hsub₀⟩ refine ⟨⟨n₀, hn₀_lt⟩, (mem_boolInterval_restrSet_iff hs).mpr ⟨hsub₀, fun i hi hσi => ?_⟩⟩ exact Nat.find_min hex hi ⟨i.2, hσi⟩ · rintro ⟨j, hj⟩ exact K.down_closed (hs.mem_faces j) (mem_boolInterval.mp hj).2 /-- **COROLLARY 2C (`shellable_imp_partitionable`)**: Every shellable complex is partitionable. -/ theorem shellable_imp_partitionable {K : FinSimplicialComplex V} {d : ℕ} (h : IsShellable K d) : IsPartitionable K d := by rcases h with ⟨m, F, hs⟩ exact ⟨m, restrSet F, F, shelling_interval_partition hs⟩ /-- Exact number of `k`-element faces inside a Boolean interval `[R, G]` with `R ⊆ G` and `|G| = d`. -/ lemma card_boolInterval_size {R G : Finset V} {d k : ℕ} (hRG : R ⊆ G) (hG : G.card = d) : ((boolInterval R G).filter (fun σ => σ.card = k)).card = if R.card ≤ k then (d - R.card).choose (k - R.card) else 0 := by split_ifs with hRk · have hbij : ((boolInterval R G).filter (fun σ => σ.card = k)).card = ((G \ R).powersetCard (k - R.card)).card := by refine Finset.card_bij (fun σ _ => σ \ R) ?_ ?_ ?_ · intro σ hσ rw [Finset.mem_filter, mem_boolInterval] at hσ rw [Finset.mem_powersetCard] refine ⟨Finset.sdiff_subset_sdiff hσ.1.2 Subset.rfl, ?_⟩ rw [Finset.card_sdiff_of_subset hσ.1.1, hσ.2] · intro σ₁ h1 σ₂ h2 heq rw [Finset.mem_filter, mem_boolInterval] at h1 h2 rw [← Finset.sdiff_union_of_subset h1.1.1, ← Finset.sdiff_union_of_subset h2.1.1, heq] · intro τ hτ rw [Finset.mem_powersetCard] at hτ have hdisj : Disjoint τ R := disjoint_sdiff_self_left.mono_left hτ.1 refine ⟨τ ∪ R, ?_, Finset.union_sdiff_cancel_right hdisj⟩ rw [Finset.mem_filter, mem_boolInterval] refine ⟨⟨Finset.subset_union_right, Finset.union_subset (hτ.1.trans Finset.sdiff_subset) hRG⟩, ?_⟩ rw [Finset.card_union_of_disjoint hdisj, hτ.2] omega rw [hbij, Finset.card_powersetCard, Finset.card_sdiff_of_subset hRG, hG] · rw [Finset.card_eq_zero, Finset.eq_empty_iff_forall_notMem] intro σ hσ rw [Finset.mem_filter, mem_boolInterval] at hσ have := Finset.card_le_card hσ.1.1 omega /-- **THEOREM 2D — Stanley's `f`-Vector Expansion for Partitionable Complexes**: `K.fVecCard k = ∑_{r=0}^k C(d - r, k - r) · #{j | (R j).card = r}`! -/ theorem partitionable_fVecCard {K : FinSimplicialComplex V} {d m : ℕ} {R F : Fin m → Finset V} (hp : IsPartition K d m R F) (k : ℕ) : K.fVecCard k = ∑ r ∈ Finset.range (k + 1), (d - r).choose (k - r) * (Finset.univ.filter (fun j : Fin m => (R j).card = r)).card := by unfold FinSimplicialComplex.fVecCard rw [hp.union_eq, Finset.filter_biUnion] rw [Finset.card_biUnion] · have hterm : ∀ j : Fin m, ((boolInterval (R j) (F j)).filter (fun σ => σ.card = k)).card = if (R j).card ≤ k then (d - (R j).card).choose (k - (R j).card) else 0 := fun j => card_boolInterval_size (hp.subset_top j) (hp.card_top j) simp_rw [hterm] -- Group `Fin m` by `r = (R j).card ∈ range (k + 1)` have hsplit : ∑ j : Fin m, (if (R j).card ≤ k then (d - (R j).card).choose (k - (R j).card) else 0) = ∑ j ∈ Finset.univ.filter (fun j : Fin m => (R j).card ≤ k), (d - (R j).card).choose (k - (R j).card) := by rw [Finset.sum_filter] rw [hsplit] have hfiber : Finset.univ.filter (fun j : Fin m => (R j).card ≤ k) = (Finset.range (k + 1)).biUnion (fun r => Finset.univ.filter (fun j : Fin m => (R j).card = r)) := by ext j simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_biUnion, Finset.mem_range] constructor · intro hj; exact ⟨(R j).card, by omega, rfl⟩ · rintro ⟨r, hr, heq⟩; omega rw [hfiber, Finset.sum_biUnion] · refine Finset.sum_congr rfl fun r _ => ?_ have hc : ∀ j ∈ Finset.univ.filter (fun j : Fin m => (R j).card = r), (d - (R j).card).choose (k - (R j).card) = (d - r).choose (k - r) := by intro j hj; rw [(Finset.mem_filter.mp hj).2] rw [Finset.sum_congr rfl hc, Finset.sum_const, smul_eq_mul, mul_comm] · intro r₁ _ r₂ _ hne change Disjoint _ _ rw [Finset.disjoint_left] intro j h1 h2 exact hne ((Finset.mem_filter.mp h1).2.symm.trans (Finset.mem_filter.mp h2).2) · intro j₁ _ j₂ _ hne exact (hp.pairwise_disjoint hne).mono (Finset.filter_subset _ _) (Finset.filter_subset _ _) /-- **THEOREM 2E — Stanley's Combinatorial `h`-Vector Theorem for Partitionable Complexes**: For EVERY partition `(R, F)` of `K` with dimension parameter `d` and EVERY `r ≤ d`: `K.hVec d r = (#{j : Fin m | (R j).card = r} : ℤ)`! -/ theorem partitionable_hVec_eq_card {K : FinSimplicialComplex V} {d m : ℕ} {R F : Fin m → Finset V} (hp : IsPartition K d m R F) {r : ℕ} (hr : r ≤ d) : K.hVec d r = ((Finset.univ.filter (fun j : Fin m => (R j).card = r)).card : ℤ) := by let g : ℕ → ℤ := fun s => ((Finset.univ.filter (fun j : Fin m => (R j).card = s)).card : ℤ) have hf_eq : ∀ k ≤ r, K.fVec k = hToF d g k := by intro k _ unfold FinSimplicialComplex.fVec hToF rw [partitionable_fVecCard hp k] push_cast; rfl unfold FinSimplicialComplex.hVec rw [fToH_congr hf_eq, fToH_hToF d g hr] /-- **COROLLARY 2F (`partitionable_hVec_nonneg`)**: Every partitionable simplicial complex has a **nonnegative** `h`-vector: `0 ≤ K.hVec d r` for `r ≤ d`. -/ theorem partitionable_hVec_nonneg {K : FinSimplicialComplex V} {d : ℕ} (hp : IsPartitionable K d) {r : ℕ} (hr : r ≤ d) : 0 ≤ K.hVec d r := by rcases hp with ⟨m, R, F, hpart⟩ rw [partitionable_hVec_eq_card hpart hr] exact Nat.cast_nonneg _ /-- **THEOREM 2G — Stanley's `h`-Vector Theorem for Shellable Complexes (`shellable_hVec_eq_card_restrSet`)**: For EVERY shelling `F : Fin m → Finset V` of `K` and EVERY `r ≤ d`: `K.hVec d r = (#{j : Fin m | (restrSet F j).card = r} : ℤ)`! -/ theorem shellable_hVec_eq_card_restrSet {K : FinSimplicialComplex V} {d m : ℕ} {F : Fin m → Finset V} (hs : IsShelling K d m F) {r : ℕ} (hr : r ≤ d) : K.hVec d r = ((Finset.univ.filter (fun j : Fin m => (restrSet F j).card = r)).card : ℤ) := partitionable_hVec_eq_card (shelling_interval_partition hs) hr /-- **COROLLARY 2H (`shellable_hVec_nonneg`)**: Every shellable simplicial complex has `0 ≤ K.hVec d r` for all `r ≤ d`! -/ theorem shellable_hVec_nonneg {K : FinSimplicialComplex V} {d : ℕ} (hs : IsShellable K d) {r : ℕ} (hr : r ≤ d) : 0 ≤ K.hVec d r := partitionable_hVec_nonneg (shellable_imp_partitionable hs) hr /-- In any shelling `F : Fin m → Finset V`, the top face count `K.fVecCard d` equals `m`. -/ theorem shellable_fVecCard_top {K : FinSimplicialComplex V} {d m : ℕ} {F : Fin m → Finset V} (hs : IsShelling K d m F) : K.fVecCard d = m := by rw [partitionable_fVecCard (shelling_interval_partition hs) d] have h1 : ∀ r ∈ Finset.range (d + 1), (d - r).choose (d - r) * (Finset.univ.filter (fun j : Fin m => (restrSet F j).card = r)).card = (Finset.univ.filter (fun j : Fin m => (restrSet F j).card = r)).card := by intro r _; rw [Nat.choose_self, one_mul] rw [Finset.sum_congr rfl h1] have huniv : (Finset.univ : Finset (Fin m)) = (Finset.range (d + 1)).biUnion (fun r => Finset.univ.filter (fun j : Fin m => (restrSet F j).card = r)) := by ext j simp only [Finset.mem_univ, Finset.mem_biUnion, Finset.mem_range, Finset.mem_filter, true_and, true_iff] refine ⟨(restrSet F j).card, ?_, rfl⟩ have hle : (restrSet F j).card ≤ d := (Finset.card_le_card (restrSet_subset F j)).trans (le_of_eq (hs.card_eq j)) omega have hcard := congrArg Finset.card huniv rw [Finset.card_univ, Fintype.card_fin, Finset.card_biUnion] at hcard · exact hcard.symm · intro r₁ _ r₂ _ hne change Disjoint _ _ rw [Finset.disjoint_left] intro j h1 h2 exact hne ((Finset.mem_filter.mp h1).2.symm.trans (Finset.mem_filter.mp h2).2) /-- Top `h`-vector entry of a shellable complex equals the number of **spanning (homology) facets** with `restrSet F j = F j`. -/ theorem shellable_hVec_top_eq_card_spanning {K : FinSimplicialComplex V} {d m : ℕ} {F : Fin m → Finset V} (hs : IsShelling K d m F) : K.hVec d d = ((Finset.univ.filter (fun j : Fin m => restrSet F j = F j)).card : ℤ) := by rw [shellable_hVec_eq_card_restrSet hs le_rfl] congr 2 ext j simp only [Finset.mem_filter, Finset.mem_univ, true_and] constructor · intro hcard exact Finset.eq_of_subset_of_card_le (restrSet_subset F j) (by rw [hs.card_eq j, hcard]) · intro heq; rw [heq, hs.card_eq j] /-! ## Section 3: Explicit Constructive Shellings of Classical Families -/ /-- Full simplex `Δ_{d-1}` on `Fin d`. -/ def simplexComplex (d : ℕ) : FinSimplicialComplex (Fin d) where faces := Finset.univ down_closed := fun _ _ _ _ => Finset.mem_univ _ empty_mem := Finset.mem_univ _ /-- **THEOREM 3A (`simplexComplex_isShellable`)**: The full simplex `Δ_{d-1}` is shellable with `1` facet and `h_k(Δ_{d-1}) = δ_{k, 0}`. -/ theorem simplexComplex_isShellable (d : ℕ) : IsShellable (simplexComplex d) d := by refine ⟨1, fun _ => Finset.univ, ?_⟩ exact { mem_faces := fun _ => Finset.mem_univ _ card_eq := fun _ => by rw [Finset.card_univ, Fintype.card_fin] injective := fun i j _ => Subsingleton.elim i j covers := fun σ _ => ⟨0, Finset.subset_univ σ⟩ shell_step := fun i j hij => absurd (Subsingleton.elim i j) (ne_of_lt hij) } /-- Boundary of the `d`-simplex `∂Δ_d` on `Fin (d + 1)`. -/ def simplexBoundary (d : ℕ) : FinSimplicialComplex (Fin (d + 1)) where faces := Finset.univ.erase Finset.univ down_closed := by intro σ τ hσ hτσ rw [Finset.mem_erase] at hσ ⊢ exact ⟨fun h => hσ.1 (Finset.eq_univ_iff_forall.mpr fun x => hτσ (h ▸ Finset.mem_univ x)), Finset.mem_univ _⟩ empty_mem := by rw [Finset.mem_erase] refine ⟨fun h => ?_, Finset.mem_univ _⟩ exact Finset.notMem_empty (0 : Fin (d + 1)) (h ▸ Finset.mem_univ 0) /-- Explicit facet ordering of `∂Δ_d`: `F j = univ.erase j` for `j : Fin (d + 1)`. -/ def simplexBoundaryShelling (d : ℕ) : Fin (d + 1) → Finset (Fin (d + 1)) := fun j => Finset.univ.erase j /-- **THEOREM 3B (`simplexBoundary_isShelling`)**: `j ↦ univ.erase j` is a shelling of `∂Δ_d`. -/ theorem simplexBoundary_isShelling (d : ℕ) : IsShelling (simplexBoundary d) d (d + 1) (simplexBoundaryShelling d) where mem_faces := fun j => Finset.mem_erase.mpr ⟨fun h => Finset.notMem_erase j Finset.univ (by rw [← simplexBoundaryShelling, h]; exact Finset.mem_univ j), Finset.mem_univ _⟩ card_eq := fun j => by simp [simplexBoundaryShelling, Finset.card_erase_of_mem, Finset.card_univ] injective := fun j₁ j₂ heq => by unfold simplexBoundaryShelling at heq by_contra hne have : j₁ ∈ Finset.univ.erase j₂ := Finset.mem_erase.mpr ⟨hne, Finset.mem_univ _⟩ rw [← heq] at this exact Finset.notMem_erase j₁ Finset.univ this covers := fun σ hσ => by have hne : σ ≠ Finset.univ := (Finset.mem_erase.mp hσ).1 have hex : ∃ j : Fin (d + 1), j ∉ σ := by by_contra hall; push Not at hall exact hne (Finset.eq_univ_iff_forall.mpr hall) rcases hex with ⟨j, hj⟩ exact ⟨j, fun x hx => Finset.mem_erase.mpr ⟨fun h => hj (h ▸ hx), Finset.mem_univ _⟩⟩ shell_step := fun i j hij => by refine ⟨i, hij, i, Finset.mem_erase.mpr ⟨ne_of_lt hij, Finset.mem_univ _⟩, Finset.notMem_erase i Finset.univ, fun x hx => ?_⟩ rw [Finset.mem_erase] at hx exact Finset.mem_erase.mpr ⟨hx.1, Finset.mem_univ _⟩ theorem simplexBoundary_isShellable (d : ℕ) : IsShellable (simplexBoundary d) d := ⟨d + 1, simplexBoundaryShelling d, simplexBoundary_isShelling d⟩ /-- Combinatorial shelling proof that `h_k(∂Δ_d) = 1` for all `k ≤ d`. -/ theorem simplexBoundary_hVec_via_shelling (d : ℕ) {k : ℕ} (hk : k ≤ d) : (simplexBoundary d).hVec d k = 1 := by rw [shellable_hVec_eq_card_restrSet (simplexBoundary_isShelling d) hk] have hrestr : ∀ j : Fin (d + 1), (restrSet (simplexBoundaryShelling d) j).card = j.1 := by intro j have hset : restrSet (simplexBoundaryShelling d) j = Finset.univ.filter (fun v : Fin (d + 1) => v < j) := by ext v rw [restrSet, Finset.mem_filter, Finset.mem_filter] simp only [simplexBoundaryShelling, Finset.mem_erase, Finset.mem_univ, and_true, true_and] constructor · rintro ⟨hvj, i, hij, hsub⟩ have hiv : i = v := by by_contra hne have hi_mem : i ∈ (Finset.univ.erase j).erase v := Finset.mem_erase.mpr ⟨hne, Finset.mem_erase.mpr ⟨ne_of_lt hij, Finset.mem_univ _⟩⟩ exact Finset.notMem_erase i Finset.univ (hsub hi_mem) exact hiv ▸ hij · intro hvj refine ⟨ne_of_lt hvj, v, hvj, fun x hx => ?_⟩ exact Finset.mem_erase.mpr ⟨(Finset.mem_erase.mp hx).1, Finset.mem_univ _⟩ rw [hset] have hbij : (Finset.univ.filter (fun v : Fin (d + 1) => v < j)).card = (Finset.range j.1).card := by refine Finset.card_bij (fun v _ => v.1) ?_ ?_ ?_ · intro v hv; exact Finset.mem_range.mpr (Finset.mem_filter.mp hv).2 · intro v₁ _ v₂ _ h; exact Fin.ext h · intro r hr have hlt : r < j.1 := Finset.mem_range.mp hr exact ⟨⟨r, lt_trans hlt j.2⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hlt⟩, rfl⟩ rw [hbij, Finset.card_range] simp_rw [hrestr] have hsing : Finset.univ.filter (fun j : Fin (d + 1) => j.1 = k) = {⟨k, Nat.lt_succ_of_le hk⟩} := by ext j simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_singleton] exact ⟨fun h => Fin.ext h, fun h => congrArg Fin.val h⟩ rw [hsing, Finset.card_singleton]; rfl /-- **Cross-Polytope Boundary `∂β_d`** on `Fin d × Bool`: faces are subsets containing at most one sign `(p, false)` or `(p, true)` per coordinate `p`. -/ def crossPolytope (d : ℕ) : FinSimplicialComplex (Fin d × Bool) where faces := Finset.univ.filter fun σ : Finset (Fin d × Bool) => ∀ p : Fin d, ¬ ((p, false) ∈ σ ∧ (p, true) ∈ σ) down_closed := by intro σ τ hσ hτσ rw [Finset.mem_filter] at hσ ⊢ exact ⟨Finset.mem_univ _, fun p ⟨hf, ht⟩ => hσ.2 p ⟨hτσ hf, hτσ ht⟩⟩ empty_mem := by simp /-- Binary-ordered facets of `∂β_d`: `F j = { (p, j.testBit p) | p : Fin d }` for `j : Fin (2 ^ d)`. -/ def crossPolytopeShelling (d : ℕ) (j : Fin (2 ^ d)) : Finset (Fin d × Bool) := Finset.univ.image (fun p : Fin d => (p, Nat.testBit j.1 p.1)) lemma mem_crossPolytopeShelling {d : ℕ} {j : Fin (2 ^ d)} {x : Fin d × Bool} : x ∈ crossPolytopeShelling d j ↔ x.2 = Nat.testBit j.1 x.1.1 := by simp only [crossPolytopeShelling, Finset.mem_image, Finset.mem_univ, true_and] constructor · rintro ⟨p, hp⟩ have h1 : p = x.1 := congrArg Prod.fst hp have h2 : Nat.testBit j.1 p.1 = x.2 := congrArg Prod.snd hp rw [← h2, h1] · intro h; exact ⟨x.1, Prod.ext rfl h.symm⟩ lemma nat_lt_two_pow_eq_of_testBit {d a b : ℕ} (ha : a < 2 ^ d) (hb : b < 2 ^ d) (hbit : ∀ p : Fin d, Nat.testBit a p.1 = Nat.testBit b p.1) : a = b := by apply Nat.eq_of_testBit_eq intro k by_cases hkd : k < d · exact hbit ⟨k, hkd⟩ · push Not at hkd have h1 : Nat.testBit a k = false := Nat.testBit_lt_two_pow (lt_of_lt_of_le ha (Nat.pow_le_pow_right (by omega) hkd)) have h2 : Nat.testBit b k = false := Nat.testBit_lt_two_pow (lt_of_lt_of_le hb (Nat.pow_le_pow_right (by omega) hkd)) rw [h1, h2] lemma sum_two_pow_range (d : ℕ) : ∑ k ∈ Finset.range d, 2 ^ k = 2 ^ d - 1 := by induction d with | zero => simp | succ k ih => rw [Finset.sum_range_succ, ih, pow_succ] have : 1 ≤ 2 ^ k := Nat.one_le_pow k 2 (by omega) omega /-- Clean proof of `testBit (n - 2^p) q` when `testBit n p = true`, by direct `2^p` base-2 arithmetic. -/ lemma testBit_clear_bit {n p : ℕ} (hp : Nat.testBit n p = true) : 2 ^ p ≤ n ∧ ∀ q : ℕ, Nat.testBit (n - 2 ^ p) q = if q = p then false else Nat.testBit n q := by have hge : 2 ^ p ≤ n := by by_contra hlt; push Not at hlt have := Nat.testBit_lt_two_pow hlt rw [hp] at this; exact Bool.noConfusion this have hdiv_odd : n / 2 ^ p % 2 = 1 := by rw [Nat.testBit_eq_decide_div_mod_eq] at hp simpa using hp refine ⟨hge, fun q => ?_⟩ rw [Nat.testBit_eq_decide_div_mod_eq, Nat.testBit_eq_decide_div_mod_eq] rcases lt_trichotomy q p with hlt | hqp | hgt · simp only [ne_of_lt hlt, ↓reduceIte] have hdvd : 2 ^ (q + 1) ∣ 2 ^ p := Nat.pow_dvd_pow 2 hlt rcases hdvd with ⟨c, hc⟩ have hdiv_eq : (n - 2 ^ p) / 2 ^ q + 2 * c = n / 2 ^ q := by have hmul : 2 ^ p = 2 ^ q * (2 * c) := by rw [hc, pow_succ]; ring have hpos : 0 < 2 ^ q := Nat.pow_pos (by omega) have hadd : (n - 2 ^ p) + 2 ^ q * (2 * c) = n := by omega conv_rhs => rw [← hadd] rw [Nat.add_mul_div_left _ _ hpos] have hmod : (n - 2 ^ p) / 2 ^ q % 2 = n / 2 ^ q % 2 := by omega rw [hmod] · subst hqp simp only [↓reduceIte, decide_eq_false_iff_not] have hpos : 0 < 2 ^ q := Nat.pow_pos (by omega) have hadd : (n - 2 ^ q) + 2 ^ q * 1 = n := by omega have hdiv : (n - 2 ^ q) / 2 ^ q + 1 = n / 2 ^ q := by have := Nat.add_mul_div_left (n - 2 ^ q) 1 hpos rw [hadd] at this; exact this.symm omega · simp only [ne_of_gt hgt, ↓reduceIte] have hqp : q = (p + 1) + (q - p - 1) := by omega have hpow_q : 2 ^ q = 2 ^ (p + 1) * 2 ^ (q - p - 1) := by rw [← pow_add, ← hqp] have hdiv_p1 : (n - 2 ^ p) / 2 ^ (p + 1) = n / 2 ^ (p + 1) := by have hpos : 0 < 2 ^ p := Nat.pow_pos (by omega) have hsub1 : (n - 2 ^ p) / 2 ^ p + 1 = n / 2 ^ p := by have := Nat.add_mul_div_left (n - 2 ^ p) 1 hpos have hadd : (n - 2 ^ p) + 2 ^ p * 1 = n := by omega rw [hadd] at this; exact this.symm rw [pow_succ, ← Nat.div_div_eq_div_mul, ← Nat.div_div_eq_div_mul] omega rw [hpow_q, ← Nat.div_div_eq_div_mul, ← Nat.div_div_eq_div_mul, hdiv_p1] lemma testBit_add_two_pow_lt {m d q : ℕ} (hm : m < 2 ^ d) : Nat.testBit (m + 2 ^ d) q = if q = d then true else Nat.testBit m q := by have hset : Nat.testBit (m + 2 ^ d) d = true := by rw [Nat.testBit_eq_decide_div_mod_eq] have hpos : 0 < 2 ^ d := Nat.pow_pos (by omega) have hdiv : (m + 2 ^ d * 1) / 2 ^ d = m / 2 ^ d + 1 := Nat.add_mul_div_left m 1 hpos simp only [mul_one, Nat.div_eq_of_lt hm, zero_add] at hdiv rw [hdiv]; decide have hclr := (testBit_clear_bit hset).2 q rw [Nat.add_sub_cancel] at hclr by_cases hqd : q = d · subst hqd; simp [hset] · simp only [hqd, ↓reduceIte] at hclr ⊢ exact hclr.symm /-- If `a < b < 2 ^ d`, there exists a bit position `p < d` where `testBit a p = false` and `testBit b p = true`. -/ lemma exists_bit_false_true_of_lt {d a b : ℕ} (hab : a < b) (hb : b < 2 ^ d) : ∃ p : Fin d, Nat.testBit a p.1 = false ∧ Nat.testBit b p.1 = true := by revert a b induction d with | zero => intro a b hab hb; simp at hb; omega | succ d ih => intro a b hab hb have hpow : 2 ^ (d + 1) = 2 * 2 ^ d := by ring by_cases hbd : 2 ^ d ≤ b · by_cases had : 2 ^ d ≤ a · obtain ⟨p, hpa, hpb⟩ := ih (a := a - 2 ^ d) (b := b - 2 ^ d) (by omega) (by omega) refine ⟨⟨p.1, Nat.lt_succ_of_lt p.2⟩, ?_, ?_⟩ · have ha_eq : a = (a - 2 ^ d) + 2 ^ d := by omega rw [ha_eq, testBit_add_two_pow_lt (by omega : a - 2 ^ d < 2 ^ d)] simpa [Nat.ne_of_lt p.2] using hpa · have hb_eq : b = (b - 2 ^ d) + 2 ^ d := by omega rw [hb_eq, testBit_add_two_pow_lt (by omega : b - 2 ^ d < 2 ^ d)] simpa [Nat.ne_of_lt p.2] using hpb · push Not at had refine ⟨⟨d, Nat.lt_succ_self d⟩, ?_, ?_⟩ · exact Nat.testBit_lt_two_pow had · have hb_eq : b = (b - 2 ^ d) + 2 ^ d := by omega rw [hb_eq, testBit_add_two_pow_lt (by omega : b - 2 ^ d < 2 ^ d)] simp · push Not at hbd obtain ⟨p, hpa, hpb⟩ := ih hab hbd exact ⟨⟨p.1, Nat.lt_succ_of_lt p.2⟩, hpa, hpb⟩ /-- **THEOREM 3C (`crossPolytope_isShelling`)**: The binary ordering `crossPolytopeShelling d` is a constructive shelling of the `d`-dimensional cross-polytope boundary `∂β_d` for ALL `d : ℕ`! -/ theorem crossPolytope_isShelling (d : ℕ) : IsShelling (crossPolytope d) d (2 ^ d) (crossPolytopeShelling d) where mem_faces := fun j => by simp only [crossPolytope, Finset.mem_filter, Finset.mem_univ, true_and] rintro p ⟨hf, ht⟩ rw [mem_crossPolytopeShelling] at hf ht have : false = true := hf.trans ht.symm exact Bool.noConfusion this card_eq := fun j => by unfold crossPolytopeShelling rw [Finset.card_image_of_injective _ (fun p₁ p₂ h => congrArg Prod.fst h), Finset.card_univ, Fintype.card_fin] injective := fun j₁ j₂ heq => by apply Fin.ext apply nat_lt_two_pow_eq_of_testBit j₁.2 j₂.2 intro p have hmem : (p, Nat.testBit j₁.1 p.1) ∈ crossPolytopeShelling d j₁ := mem_crossPolytopeShelling.mpr rfl rw [heq, mem_crossPolytopeShelling] at hmem exact hmem covers := fun σ hσ => by simp only [crossPolytope, Finset.mem_filter, Finset.mem_univ, true_and] at hσ -- Pick `j = ∑_{p : (p, true) ∈ σ} 2^p.1 < 2^d`! let S : Finset (Fin d) := Finset.univ.filter (fun p : Fin d => (p, true) ∈ σ) let val : ℕ := ∑ p ∈ S, 2 ^ p.1 have hval_lt : val < 2 ^ d := by have hsub : val ≤ ∑ p : Fin d, 2 ^ p.1 := Finset.sum_le_sum_of_subset (Finset.subset_univ S) have hgeom : ∑ p : Fin d, 2 ^ p.1 = 2 ^ d - 1 := by have hbij : ∑ p : Fin d, 2 ^ p.1 = ∑ k ∈ Finset.range d, 2 ^ k := by refine Finset.sum_bij (fun p _ => p.1) ?_ ?_ ?_ ?_ · intro p _; exact Finset.mem_range.mpr p.2 · intro p₁ _ p₂ _ h; exact Fin.ext h · intro k hk; exact ⟨⟨k, Finset.mem_range.mp hk⟩, Finset.mem_univ _, rfl⟩ · intro _ _; rfl rw [hbij, sum_two_pow_range] have hpos : 1 ≤ 2 ^ d := Nat.one_le_pow d 2 (by omega) omega have hbit : ∀ p : Fin d, Nat.testBit val p.1 = decide (p ∈ S) := by -- Prove for any `T : Finset (Fin d)`, `testBit (∑ q ∈ T, 2^q.1) p.1 = decide (p ∈ T)`! suffices ∀ (T : Finset (Fin d)) (p : Fin d), Nat.testBit (∑ q ∈ T, 2 ^ q.1) p.1 = decide (p ∈ T) from this S intro T induction T using Finset.induction_on with | empty => intro p; simp | insert a T ha ih => intro p rw [Finset.sum_insert ha] -- Since `a ∉ T`, `∑ q ∈ T, 2^q.1` has bit `a.1` equal to `false`, so adding `2^a.1` has no carry! have hsum_a : Nat.testBit (∑ q ∈ T, 2 ^ q.1) a.1 = false := by rw [ih a]; simp [ha] have htest_add : ∀ q : ℕ, ∀ m : ℕ, Nat.testBit m a.1 = false → Nat.testBit (2 ^ a.1 + m) q = if q = a.1 then true else Nat.testBit m q := by intro q m hm have hm1 : 2 ^ a.1 + m = m + 2 ^ a.1 := add_comm _ _ have hset : Nat.testBit (m + 2 ^ a.1) a.1 = true := by rw [Nat.testBit_eq_decide_div_mod_eq] at hm ⊢ have hpos : 0 < 2 ^ a.1 := Nat.pow_pos (by omega) have hdiv : (m + 2 ^ a.1 * 1) / 2 ^ a.1 = m / 2 ^ a.1 + 1 := Nat.add_mul_div_left m 1 hpos simp only [mul_one] at hdiv simp only [decide_eq_false_iff_not] at hm rw [hdiv]; simp; omega have hclr := (testBit_clear_bit hset).2 q have hcancel : m + 2 ^ a.1 - 2 ^ a.1 = m := Nat.add_sub_cancel m (2 ^ a.1) rw [hcancel] at hclr rw [hm1] by_cases hqa : q = a.1 · subst hqa; simp [hset] · simp only [hqa, ↓reduceIte] at hclr ⊢ exact hclr.symm rw [htest_add p.1 _ hsum_a, ih p] by_cases hpa : p = a · subst hpa; simp · have hne : p.1 ≠ a.1 := fun h => hpa (Fin.ext h) simp [hpa, hne] refine ⟨⟨val, hval_lt⟩, fun x hx => ?_⟩ rw [mem_crossPolytopeShelling, hbit x.1] rcases x with ⟨p, b⟩ cases b · simp only [S, Finset.mem_filter, Finset.mem_univ, true_and] symm; rw [decide_eq_false_iff_not] intro ht; exact hσ p ⟨hx, ht⟩ · simp only [S, Finset.mem_filter, Finset.mem_univ, true_and] symm; exact decide_eq_true_iff.mpr hx shell_step := fun i j hij => by obtain ⟨p, hpi, hpj⟩ := exists_bit_false_true_of_lt hij j.2 obtain ⟨hge, hclr⟩ := testBit_clear_bit hpj have hlt : j.1 - 2 ^ p.1 < j.1 := by have : 0 < 2 ^ p.1 := Nat.pow_pos (by omega) omega let i' : Fin (2 ^ d) := ⟨j.1 - 2 ^ p.1, lt_trans hlt j.2⟩ refine ⟨i', hlt, (p, true), mem_crossPolytopeShelling.mpr hpj.symm, ?_, fun x hx => ?_⟩ · rw [mem_crossPolytopeShelling, hpi]; exact Bool.noConfusion · rw [Finset.mem_erase, mem_crossPolytopeShelling] at hx rw [mem_crossPolytopeShelling] have hne_p : x.1 ≠ p := by intro heq apply hx.1 apply Prod.ext heq rw [hx.2, heq, hpj] have hne_val : x.1.1 ≠ p.1 := fun h => hne_p (Fin.ext h) rw [hclr x.1.1, if_neg hne_val] exact hx.2 theorem crossPolytope_isShellable (d : ℕ) : IsShellable (crossPolytope d) d := ⟨2 ^ d, crossPolytopeShelling d, crossPolytope_isShelling d⟩ /-- **THEOREM 3D — Combinatorial Shelling Proof of `h_k(∂β_d) = C(d, k)` (`crossPolytope_hVec_via_shelling`)**: In the binary shelling of `∂β_d`, `|(restrSet F j)| = #{p : Fin d | testBit j p = true}`, so Stanley's theorem yields `h_k(∂β_d) = C(d, k)` for every `k ≤ d`! -/ theorem crossPolytope_hVec_via_shelling (d : ℕ) {k : ℕ} (hk : k ≤ d) : (crossPolytope d).hVec d k = (d.choose k : ℤ) := by rw [shellable_hVec_eq_card_restrSet (crossPolytope_isShelling d) hk] congr 1 -- Identify `restrSet (crossPolytopeShelling d) j` with `{ (p, true) | testBit j p = true }`! have hcard_restr : ∀ j : Fin (2 ^ d), (restrSet (crossPolytopeShelling d) j).card = (Finset.univ.filter (fun p : Fin d => Nat.testBit j.1 p.1 = true)).card := by intro j have hset : restrSet (crossPolytopeShelling d) j = (Finset.univ.filter (fun p : Fin d => Nat.testBit j.1 p.1 = true)).image (fun p => (p, true)) := by ext ⟨p, b⟩ simp only [restrSet, Finset.mem_filter, mem_crossPolytopeShelling, Finset.mem_image, Finset.mem_univ, true_and] constructor · rintro ⟨hb, i, hij, hsub⟩ have hbit_eq : ∀ q : Fin d, q ≠ p → Nat.testBit i.1 q.1 = Nat.testBit j.1 q.1 := by intro q hqp have hmem : (q, Nat.testBit j.1 q.1) ∈ (crossPolytopeShelling d j).erase (p, b) := Finset.mem_erase.mpr ⟨fun h => hqp (congrArg Prod.fst h), mem_crossPolytopeShelling.mpr rfl⟩ exact (mem_crossPolytopeShelling.mp (hsub hmem)).symm -- Since `i < j`, they must differ at `p` with `testBit i p = false, testBit j p = true`! obtain ⟨q, hqi, hqj⟩ := exists_bit_false_true_of_lt hij j.2 have hqp : q = p := by by_contra hne have := hbit_eq q hne rw [hqi, hqj] at this; exact Bool.noConfusion this subst hqp exact ⟨q, hqj, Prod.ext rfl (hb.trans hqj).symm⟩ · rintro ⟨q, hqj, heq⟩ have hqp : q = p := congrArg Prod.fst heq have hbt : true = b := congrArg Prod.snd heq subst hqp; subst hbt obtain ⟨_, hclr⟩ := testBit_clear_bit hqj have hlt : j.1 - 2 ^ q.1 < j.1 := by have : 0 < 2 ^ q.1 := Nat.pow_pos (by omega); omega refine ⟨hqj.symm, ⟨j.1 - 2 ^ q.1, lt_trans hlt j.2⟩, hlt, fun x hx => ?_⟩ rw [Finset.mem_erase, mem_crossPolytopeShelling] at hx rw [mem_crossPolytopeShelling] have hne : x.1 ≠ q := fun h => hx.1 (Prod.ext h (hx.2.trans (h ▸ hqj))) rw [hclr x.1.1, if_neg (fun h => hne (Fin.ext h))] exact hx.2 rw [hset, Finset.card_image_of_injective _ (fun p₁ p₂ h => congrArg Prod.fst h)] simp_rw [hcard_restr] -- Biject `{ j : Fin (2^d) | #{p | testBit j p} = k }` with `powersetCard k (univ : Finset (Fin d))`! have hbij : (Finset.univ.filter (fun j : Fin (2 ^ d) => (Finset.univ.filter (fun p : Fin d => Nat.testBit j.1 p.1 = true)).card = k)).card = ((Finset.univ : Finset (Fin d)).powersetCard k).card := by refine Finset.card_bij (fun j _ => Finset.univ.filter (fun p : Fin d => Nat.testBit j.1 p.1 = true)) ?_ ?_ ?_ · intro j hj rw [Finset.mem_filter] at hj exact Finset.mem_powersetCard.mpr ⟨Finset.subset_univ _, hj.2⟩ · intro j₁ _ j₂ _ heq apply Fin.ext apply nat_lt_two_pow_eq_of_testBit j₁.2 j₂.2 intro p have hmem := Finset.ext_iff.mp heq p simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hmem cases h1 : Nat.testBit j₁.1 p.1 <;> cases h2 : Nat.testBit j₂.1 p.1 <;> simp_all · intro S hS rw [Finset.mem_powersetCard] at hS -- Build `val = ∑ p ∈ S, 2 ^ p.1 < 2 ^ d` let val : ℕ := ∑ p ∈ S, 2 ^ p.1 have hval_lt : val < 2 ^ d := by have hsub : val ≤ ∑ p : Fin d, 2 ^ p.1 := Finset.sum_le_sum_of_subset (Finset.subset_univ S) have hgeom : ∑ p : Fin d, 2 ^ p.1 = 2 ^ d - 1 := by have hb : ∑ p : Fin d, 2 ^ p.1 = ∑ r ∈ Finset.range d, 2 ^ r := by refine Finset.sum_bij (fun p _ => p.1) ?_ ?_ ?_ ?_ · intro p _; exact Finset.mem_range.mpr p.2 · intro p₁ _ p₂ _ h; exact Fin.ext h · intro r hr; exact ⟨⟨r, Finset.mem_range.mp hr⟩, Finset.mem_univ _, rfl⟩ · intro _ _; rfl rw [hb, sum_two_pow_range] have : 1 ≤ 2 ^ d := Nat.one_le_pow d 2 (by omega) omega have hbit : ∀ p : Fin d, Nat.testBit val p.1 = decide (p ∈ S) := by suffices ∀ (T : Finset (Fin d)) (p : Fin d), Nat.testBit (∑ q ∈ T, 2 ^ q.1) p.1 = decide (p ∈ T) from this S intro T induction T using Finset.induction_on with | empty => intro p; simp | insert a T ha ih => intro p rw [Finset.sum_insert ha] have hsum_a : Nat.testBit (∑ q ∈ T, 2 ^ q.1) a.1 = false := by rw [ih a]; simp [ha] have hset : Nat.testBit ((∑ q ∈ T, 2 ^ q.1) + 2 ^ a.1) a.1 = true := by rw [Nat.testBit_eq_decide_div_mod_eq] at hsum_a ⊢ have hpos : 0 < 2 ^ a.1 := Nat.pow_pos (by omega) have hdiv : ((∑ q ∈ T, 2 ^ q.1) + 2 ^ a.1 * 1) / 2 ^ a.1 = (∑ q ∈ T, 2 ^ q.1) / 2 ^ a.1 + 1 := Nat.add_mul_div_left _ 1 hpos simp only [mul_one] at hdiv simp only [decide_eq_false_iff_not] at hsum_a rw [hdiv]; simp; omega have hclr := (testBit_clear_bit hset).2 p.1 rw [Nat.add_sub_cancel] at hclr rw [add_comm] by_cases hpa : p = a · subst hpa; simp [hset] · have hne : p.1 ≠ a.1 := fun h => hpa (Fin.ext h) simp only [hne, ↓reduceIte] at hclr rw [← hclr, ih p]; simp [hpa] have hfilt : Finset.univ.filter (fun p : Fin d => Nat.testBit val p.1 = true) = S := by ext p; simp [hbit p] exact ⟨⟨val, hval_lt⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by rw [hfilt, hS.2]⟩, hfilt⟩ rw [hbij, Finset.card_powersetCard, Finset.card_univ, Fintype.card_fin] /-! ## Section 4: Lexicographic Shelling of the Boolean Order Complex & Eulerian Numbers -/ /-- The **Boolean Lattice Order Complex** `Δ(B_n \ {∅})` = barycentric subdivision `sd(Δ_{n-1})`: vertices are nonempty subsets of `Fin n`, and faces are inclusion chains. -/ def booleanOrderComplex (n : ℕ) : FinSimplicialComplex (Finset (Fin n)) where faces := ((Finset.univ : Finset (Finset (Fin n))).erase ∅).powerset.filter fun C => ∀ σ ∈ C, ∀ τ ∈ C, σ ⊆ τ ∨ τ ⊆ σ down_closed := by intro C D hC hDC rw [Finset.mem_filter, Finset.mem_powerset] at hC ⊢ exact ⟨hDC.trans hC.1, fun σ hσ τ hτ => hC.2 σ (hDC hσ) τ (hDC hτ)⟩ empty_mem := by simp /-- The maximal chain (facet of cardinality `n`) corresponding to a permutation `σ : Equiv.Perm (Fin n)`: `{ {σ 0, ..., σ j} | j : Fin n }`. -/ def prefixOfPerm {n : ℕ} (σ : Equiv.Perm (Fin n)) (j : Fin n) : Finset (Fin n) := (Finset.univ.filter (fun r : Fin n => r ≤ j)).image σ def chainOfPerm {n : ℕ} (σ : Equiv.Perm (Fin n)) : Finset (Finset (Fin n)) := Finset.univ.image (prefixOfPerm σ) lemma card_prefixOfPerm {n : ℕ} (σ : Equiv.Perm (Fin n)) (j : Fin n) : (prefixOfPerm σ j).card = j.1 + 1 := by unfold prefixOfPerm rw [Finset.card_image_of_injective _ σ.injective] have hbij : (Finset.univ.filter (fun r : Fin n => r ≤ j)).card = (Finset.range (j.1 + 1)).card := by refine Finset.card_bij (fun r _ => r.1) ?_ ?_ ?_ · intro r hr; exact Finset.mem_range.mpr (Nat.lt_succ_of_le (Finset.mem_filter.mp hr).2) · intro r₁ _ r₂ _ h; exact Fin.ext h · intro k hk have hlt : k ≤ j.1 := Nat.lt_succ_iff.mp (Finset.mem_range.mp hk) exact ⟨⟨k, lt_of_le_of_lt hlt j.2⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hlt⟩, rfl⟩ rw [hbij, Finset.card_range] lemma prefixOfPerm_injective {n : ℕ} (σ : Equiv.Perm (Fin n)) : Function.Injective (prefixOfPerm σ) := by intro j₁ j₂ heq have hcard := congrArg Finset.card heq rw [card_prefixOfPerm, card_prefixOfPerm] at hcard exact Fin.ext (Nat.succ.inj hcard) lemma card_chainOfPerm {n : ℕ} (σ : Equiv.Perm (Fin n)) : (chainOfPerm σ).card = n := by unfold chainOfPerm rw [Finset.card_image_of_injective _ (prefixOfPerm_injective σ), Finset.card_univ, Fintype.card_fin] lemma chainOfPerm_mem {n : ℕ} (σ : Equiv.Perm (Fin n)) : chainOfPerm σ ∈ (booleanOrderComplex n).faces := by simp only [booleanOrderComplex, Finset.mem_filter, Finset.mem_powerset] refine ⟨fun A hA => ?_, fun A hA B hB => ?_⟩ · rcases Finset.mem_image.mp hA with ⟨j, _, rfl⟩ refine Finset.mem_erase.mpr ⟨?_, Finset.mem_univ _⟩ exact Finset.Nonempty.ne_empty ⟨σ j, Finset.mem_image.mpr ⟨j, Finset.mem_filter.mpr ⟨Finset.mem_univ _, le_rfl⟩, rfl⟩⟩ · rcases Finset.mem_image.mp hA with ⟨j₁, _, rfl⟩ rcases Finset.mem_image.mp hB with ⟨j₂, _, rfl⟩ rcases le_total j₁ j₂ with hle | hle · left intro x hx rcases Finset.mem_image.mp hx with ⟨r, hr, rfl⟩ exact Finset.mem_image.mpr ⟨r, Finset.mem_filter.mpr ⟨Finset.mem_univ _, le_trans (Finset.mem_filter.mp hr).2 hle⟩, rfl⟩ · right intro x hx rcases Finset.mem_image.mp hx with ⟨r, hr, rfl⟩ exact Finset.mem_image.mpr ⟨r, Finset.mem_filter.mpr ⟨Finset.mem_univ _, le_trans (Finset.mem_filter.mp hr).2 hle⟩, rfl⟩ lemma chainOfPerm_injective {n : ℕ} : Function.Injective (@chainOfPerm n) := by intro σ₁ σ₂ heq have hpref : ∀ j : Fin n, prefixOfPerm σ₁ j = prefixOfPerm σ₂ j := by intro j have hmem : prefixOfPerm σ₁ j ∈ chainOfPerm σ₂ := heq ▸ Finset.mem_image.mpr ⟨j, Finset.mem_univ _, rfl⟩ rcases Finset.mem_image.mp hmem with ⟨j', _, hjj'⟩ have hc := congrArg Finset.card hjj' rw [card_prefixOfPerm, card_prefixOfPerm] at hc have : j' = j := Fin.ext (Nat.succ.inj hc) exact this ▸ hjj'.symm ext j -- Prove `σ₁ j = σ₂ j` by strong induction on `j.1`! suffices ∀ (k : ℕ) (hk : k < n), σ₁ ⟨k, hk⟩ = σ₂ ⟨k, hk⟩ by exact congrArg Fin.val (this j.1 j.2) intro k induction k using Nat.strong_induction_on with | h k ih => intro hk let j : Fin n := ⟨k, hk⟩ have hmem : σ₁ j ∈ prefixOfPerm σ₂ j := by rw [← hpref j] exact Finset.mem_image.mpr ⟨j, Finset.mem_filter.mpr ⟨Finset.mem_univ _, le_rfl⟩, rfl⟩ rcases Finset.mem_image.mp hmem with ⟨r, hr, hr_eq⟩ have hrle : r ≤ j := (Finset.mem_filter.mp hr).2 by_cases hrj : r = j · rw [hrj] at hr_eq; exact hr_eq.symm · exfalso have hrlt : r.1 < k := lt_of_le_of_ne hrle (fun h => hrj (Fin.ext h)) have heq_r : σ₁ r = σ₂ r := ih r.1 hrlt r.2 have h1 : σ₁ r = σ₁ j := heq_r.trans hr_eq exact hrj (σ₁.injective h1) /-- Number of descents of a permutation `σ ∈ Equiv.Perm (Fin n)`: `descents σ = #{i : Fin n | ∃ hi : i.1 + 1 < n, σ ⟨i.1 + 1, hi⟩ < σ i}`. -/ def descents {n : ℕ} (σ : Equiv.Perm (Fin n)) : ℕ := (Finset.univ.filter fun i : Fin n => if hi : i.1 + 1 < n then σ ⟨i.1 + 1, hi⟩ < σ i else False).card /-- The **Eulerian number** `A(n, k)`: number of permutations in `S_n` with exactly `k` descents. -/ def eulerianNumber (n k : ℕ) : ℕ := (Finset.univ.filter (fun σ : Equiv.Perm (Fin n) => descents σ = k)).card /-- Lexicographic linear order on `Equiv.Perm (Fin n)` via `List.ofFn σ`. -/ def permLexLt {n : ℕ} (σ τ : Equiv.Perm (Fin n)) : Prop := ∃ p : Fin n, (∀ r : Fin n, r < p → σ r = τ r) ∧ σ p < τ p lemma permLexLt_irrefl {n : ℕ} (σ : Equiv.Perm (Fin n)) : ¬ permLexLt σ σ := by rintro ⟨p, _, hlt⟩; exact lt_irrefl _ hlt lemma permLexLt_trans {n : ℕ} {σ τ ρ : Equiv.Perm (Fin n)} (h1 : permLexLt σ τ) (h2 : permLexLt τ ρ) : permLexLt σ ρ := by rcases h1 with ⟨p, hpeq, hplt⟩ rcases h2 with ⟨q, hqeq, hqlt⟩ rcases lt_trichotomy p q with hpq | rfl | hqp · refine ⟨p, fun r hr => (hpeq r hr).trans (hqeq r (lt_trans hr hpq)), ?_⟩ rwa [← hqeq p hpq] · exact ⟨p, fun r hr => (hpeq r hr).trans (hqeq r hr), lt_trans hplt hqlt⟩ · refine ⟨q, fun r hr => (hpeq r (lt_trans hr hqp)).trans (hqeq r hr), ?_⟩ rwa [hpeq q hqp] lemma permLexLt_trichotomy {n : ℕ} (σ τ : Equiv.Perm (Fin n)) : permLexLt σ τ ∨ σ = τ ∨ permLexLt τ σ := by by_cases heq : σ = τ · exact Or.inr (Or.inl heq) · have hex : ∃ k : ℕ, ∃ (hk : k < n), σ ⟨k, hk⟩ ≠ τ ⟨k, hk⟩ := by by_contra h; push Not at h exact heq (Equiv.ext fun i => h i.1 i.2) let k₀ := Nat.find hex rcases Nat.find_spec hex with ⟨hk₀, hne⟩ have hpre : ∀ r : Fin n, r < ⟨k₀, hk₀⟩ → σ r = τ r := by intro r hr by_contra hnr exact Nat.find_min hex hr ⟨r.2, hnr⟩ rcases lt_or_gt_of_ne hne with hlt | hgt · exact Or.inl ⟨⟨k₀, hk₀⟩, hpre, hlt⟩ · exact Or.inr (Or.inr ⟨⟨k₀, hk₀⟩, fun r hr => (hpre r hr).symm, hgt⟩) /-- Every chain in `booleanOrderComplex n` can be extended to `chainOfPerm σ` for some `σ ∈ S_n`. -/ lemma exists_perm_chain_supset {n : ℕ} {C : Finset (Finset (Fin n))} (hC : C ∈ (booleanOrderComplex n).faces) : ∃ σ : Equiv.Perm (Fin n), C ⊆ chainOfPerm σ := by -- Assign to each `v : Fin n` its "appearance rank" `r(v) = #{A ∈ C | v ∉ A}` and sort `(r(v), v)`! -- Any permutation `σ` ordering `Fin n` by `(r(v), v)` increasing satisfies `∀ A ∈ C, A = prefixOfPerm σ (A.card - 1)`! let key : Fin n → ℕ := fun v => (C.filter (fun A => v ∉ A)).card * n + v.1 have hkey_inj : Function.Injective key := by intro v₁ v₂ h have hmod := congrArg (· % n) h simp only [key, Nat.mul_add_mod_self_right, Nat.mod_eq_of_lt v₁.2, Nat.mod_eq_of_lt v₂.2] at hmod exact Fin.ext hmod -- Order `Fin n` by `key` via `Finset.orderEmbOfFin` on `univ.image key`! let S : Finset ℕ := Finset.univ.image key have hScard : S.card = n := by rw [Finset.card_image_of_injective _ hkey_inj, Finset.card_univ, Fintype.card_fin] let emb : Fin n ↪o ℕ := S.orderEmbOfFin hScard -- Recover `σ : Fin n → Fin n` from `emb`: `key (σ i) = emb i`! have hmem_emb : ∀ i : Fin n, ∃ v : Fin n, key v = emb i := by intro i have hm : emb i ∈ S := S.orderEmbOfFin_mem hScard i rcases Finset.mem_image.mp hm with ⟨v, _, hv⟩ exact ⟨v, hv⟩ choose f hf using hmem_emb have hf_inj : Function.Injective f := by intro i₁ i₂ h apply emb.injective rw [← hf i₁, ← hf i₂, h] let σ : Equiv.Perm (Fin n) := Equiv.ofBijective f ((Fintype.bijective_iff_injective_and_card f).mpr ⟨hf_inj, rfl⟩) -- Prove that for every `A ∈ C`, `A ∈ chainOfPerm σ`! rw [booleanOrderComplex, Finset.mem_filter, Finset.mem_powerset] at hC refine ⟨σ, fun A hA => ?_⟩ have hAne : A.Nonempty := Finset.nonempty_iff_ne_empty.mpr (Finset.mem_erase.mp (hC.1 hA)).1 have hAcard_pos : 0 < A.card := Finset.card_pos.mpr hAne have hAcard_le : A.card ≤ n := by simpa [Fintype.card_fin] using Finset.card_le_univ A let jA : Fin n := ⟨A.card - 1, by omega⟩ refine Finset.mem_image.mpr ⟨jA, Finset.mem_univ _, ?_⟩ -- Key property: if `u ∈ A` and `w ∉ A`, then `key u < key w`! have hkey_lt : ∀ u ∈ A, ∀ w ∉ A, key u < key w := by intro u hu w hw have hss : C.filter (fun B => u ∉ B) ⊂ C.filter (fun B => w ∉ B) := by refine Finset.ssubset_iff_subset_ne.mpr ⟨fun B hB => ?_, fun heq => ?_⟩ · rcases Finset.mem_filter.mp hB with ⟨hBC, huB⟩ refine Finset.mem_filter.mpr ⟨hBC, fun hwB => ?_⟩ rcases hC.2 A hA B hBC with hAB | hBA · exact huB (hAB hu) · exact hw (hBA hwB) · have hA_in : A ∈ C.filter (fun B => w ∉ B) := Finset.mem_filter.mpr ⟨hA, hw⟩ rw [← heq] at hA_in exact (Finset.mem_filter.mp hA_in).2 hu have hlt := Finset.card_lt_card hss have hu_lt : u.1 < n := u.2 show (C.filter (fun B => u ∉ B)).card * n + u.1 < (C.filter (fun B => w ∉ B)).card * n + w.1 have hmul : ((C.filter (fun B => u ∉ B)).card + 1) * n ≤ (C.filter (fun B => w ∉ B)).card * n := Nat.mul_le_mul_right n hlt rw [Nat.add_mul, one_mul] at hmul omega -- Therefore `σ r ∈ A ↔ r ≤ jA` (equivalently `prefixOfPerm σ jA = A`)! have hsub : prefixOfPerm σ jA ⊆ A := by intro x hx rcases Finset.mem_image.mp hx with ⟨r, hr, rfl⟩ have hrle : r ≤ jA := (Finset.mem_filter.mp hr).2 by_contra hxA have hlt_r : ∀ u ∈ A, σ.symm u < r := by intro u hu have hku : emb (σ.symm u) < emb r := by have h1 : emb (σ.symm u) = key u := by have := hf (σ.symm u) change key (σ (σ.symm u)) = emb (σ.symm u) at this simpa using this.symm have h2 : emb r = key (σ r) := (hf r).symm rw [h1, h2] exact hkey_lt u hu (σ r) hxA exact emb.lt_iff_lt.mp hku have hcard_A : A.card ≤ (Finset.univ.filter (fun t : Fin n => t < r)).card := by calc A.card = (A.image σ.symm).card := (Finset.card_image_of_injective A σ.symm.injective).symm _ ≤ (Finset.univ.filter (fun t : Fin n => t < r)).card := by refine Finset.card_le_card fun t ht => ?_ rcases Finset.mem_image.mp ht with ⟨u, hu, rfl⟩ exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, hlt_r u hu⟩ have hcard_lt : (Finset.univ.filter (fun t : Fin n => t < r)).card = r.1 := by have hbij : (Finset.univ.filter (fun t : Fin n => t < r)).card = (Finset.range r.1).card := by refine Finset.card_bij (fun t _ => t.1) ?_ ?_ ?_ · intro t ht; exact Finset.mem_range.mpr (Finset.mem_filter.mp ht).2 · intro t₁ _ t₂ _ h; exact Fin.ext h · intro k hk have hlt : k < r.1 := Finset.mem_range.mp hk exact ⟨⟨k, lt_trans hlt r.2⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hlt⟩, rfl⟩ rw [hbij, Finset.card_range] rw [hcard_lt] at hcard_A have hrval : r.1 ≤ A.card - 1 := hrle omega exact Finset.eq_of_subset_of_card_le hsub (by rw [card_prefixOfPerm]; show A.card ≤ (A.card - 1) + 1; omega) /-- Adjacent transposition lemma: swapping positions `a` and `a + 1` in `τ` changes ONLY the single prefix `prefixOfPerm τ a` in `chainOfPerm τ`! -/ lemma erase_prefix_subset_swap {n : ℕ} (τ : Equiv.Perm (Fin n)) (a : Fin n) (ha : a.1 + 1 < n) : let b : Fin n := ⟨a.1 + 1, ha⟩ let τ' : Equiv.Perm (Fin n) := (Equiv.swap a b).trans τ (chainOfPerm τ).erase (prefixOfPerm τ a) ⊆ chainOfPerm τ' := by intro b τ' A hA rw [Finset.mem_erase] at hA rcases Finset.mem_image.mp hA.2 with ⟨j, _, rfl⟩ have hja : j ≠ a := fun h => hA.1 (by rw [h]) refine Finset.mem_image.mpr ⟨j, Finset.mem_univ _, ?_⟩ -- Show `prefixOfPerm τ' j = prefixOfPerm τ j` for every `j ≠ a`! ext x simp only [prefixOfPerm, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and] have hiff : ∀ r : Fin n, Equiv.swap a b r ≤ j ↔ r ≤ j := by intro r by_cases hra : r = a · subst r simp only [Equiv.swap_apply_left] have hne : j.1 ≠ a.1 := fun h => hja (Fin.ext h) show a.1 + 1 ≤ j.1 ↔ a.1 ≤ j.1; omega · by_cases hrb : r = b · subst r simp only [Equiv.swap_apply_right] have hne : j.1 ≠ a.1 := fun h => hja (Fin.ext h) show a.1 ≤ j.1 ↔ a.1 + 1 ≤ j.1; omega · rw [Equiv.swap_apply_of_ne_of_ne hra hrb] constructor · rintro ⟨r, hr, rfl⟩ exact ⟨Equiv.swap a b r, (hiff r).mpr hr, by simp [τ']⟩ · rintro ⟨r, hr, rfl⟩ exact ⟨Equiv.swap a b r, (hiff r).mpr hr, by simp [τ']⟩ /-- Lexicographic linear order on `Equiv.Perm (Fin n)`. -/ @[instance_reducible] noncomputable def permLexLinearOrder (n : ℕ) : LinearOrder (Equiv.Perm (Fin n)) where le := fun σ τ => permLexLt σ τ ∨ σ = τ lt := permLexLt le_refl := fun _ => Or.inr rfl le_trans := fun _ _ _ h1 h2 => by rcases h1 with h1 | rfl · rcases h2 with h2 | rfl · exact Or.inl (permLexLt_trans h1 h2) · exact Or.inl h1 · exact h2 le_antisymm := fun σ τ h1 h2 => by rcases h1 with h1 | rfl · rcases h2 with h2 | rfl · exact False.elim (permLexLt_irrefl σ (permLexLt_trans h1 h2)) · rfl · rfl le_total := fun σ τ => by rcases permLexLt_trichotomy σ τ with h | rfl | h · exact Or.inl (Or.inl h) · exact Or.inl (Or.inr rfl) · exact Or.inr (Or.inl h) lt_iff_le_not_ge := fun σ τ => by constructor · intro h refine ⟨Or.inl h, fun h2 => ?_⟩ rcases h2 with h2 | rfl · exact permLexLt_irrefl _ (permLexLt_trans h h2) · exact permLexLt_irrefl _ h · rintro ⟨h1 | rfl, h2⟩ · exact h1 · exact False.elim (h2 (Or.inr rfl)) toDecidableLE := Classical.decRel _ /-- **THEOREM 4A — Lexicographic Shelling of the Boolean Order Complex `sd(Δ_{n-1})`** and **Eulerian Number `h`-Vector Identity (`booleanOrderComplex_hVec_eq_eulerian`)**: Ordering `Equiv.Perm (Fin n)` lexicographically gives a pure shelling of `booleanOrderComplex n` whose restriction set of `τ` has cardinality `descents τ`! Therefore, for ALL `n : ℕ` and ALL `k ≤ n`: `h_k(booleanOrderComplex n) = eulerianNumber n k`! -/ theorem booleanOrderComplex_isShellable_and_hVec (n : ℕ) : IsShellable (booleanOrderComplex n) n ∧ ∀ k ≤ n, (booleanOrderComplex n).hVec n k = (eulerianNumber n k : ℤ) := by let _ : LinearOrder (Equiv.Perm (Fin n)) := permLexLinearOrder n let m := Fintype.card (Equiv.Perm (Fin n)) let enum : Fin m ≃o Equiv.Perm (Fin n) := Fintype.orderIsoFinOfCardEq (Equiv.Perm (Fin n)) rfl let F : Fin m → Finset (Finset (Fin n)) := fun j => chainOfPerm (enum j) -- Prove `F` is a shelling of `booleanOrderComplex n`! have hshell : IsShelling (booleanOrderComplex n) n m F := { mem_faces := fun j => chainOfPerm_mem (enum j) card_eq := fun j => card_chainOfPerm (enum j) injective := fun j₁ j₂ h => enum.injective (chainOfPerm_injective h) covers := fun C hC => by rcases exists_perm_chain_supset hC with ⟨σ, hsub⟩ exact ⟨enum.symm σ, by simpa [F] using hsub⟩ shell_step := fun i j hij => by have hlex : permLexLt (enum i) (enum j) := enum.strictMono hij rcases hlex with ⟨p, hpeq, hplt⟩ set σ := enum i set τ := enum j -- `σ p` appears in `τ` at some `q > p`! let q : Fin n := τ.symm (σ p) have hq_val : τ q = σ p := τ.apply_symm_apply (σ p) have hpq : p < q := by by_contra hqp; push Not at hqp rcases eq_or_lt_of_le hqp with hq_eq | hq_lt · rw [hq_eq] at hq_val; exact ne_of_lt hplt hq_val.symm · have : σ q = σ p := (hpeq q hq_lt).trans hq_val exact ne_of_lt hq_lt (σ.injective this) -- Since `τ q = σ p < τ p` and `p < q`, there must exist `a` with `p ≤ a < q` and `τ (a + 1) < τ a`! have hex_desc : ∃ a : Fin n, p ≤ a ∧ a < q ∧ ∃ ha : a.1 + 1 < n, τ ⟨a.1 + 1, ha⟩ < τ a := by by_contra hall; push Not at hall -- Then `τ p ≤ τ (p + 1) ≤ ... ≤ τ q`, contradicting `τ q < τ p`! have hmono : ∀ d : ℕ, ∀ (hd : p.1 + d ≤ q.1), τ p ≤ τ ⟨p.1 + d, lt_of_le_of_lt hd q.2⟩ := by intro d induction d with | zero => intro _; exact le_rfl | succ d ih => intro hd let a : Fin n := ⟨p.1 + d, by omega⟩ have ha_lt_q : a < q := by show p.1 + d < q.1; omega have hpa : p ≤ a := by show p.1 ≤ p.1 + d; omega have ha1 : a.1 + 1 < n := by show p.1 + d + 1 < n; omega have hle_step : τ a ≤ τ ⟨a.1 + 1, ha1⟩ := hall a hpa ha_lt_q ha1 exact le_trans (ih (by omega)) hle_step have hle_q := hmono (q.1 - p.1) (by omega) have hidx : (⟨p.1 + (q.1 - p.1), lt_of_le_of_lt (by omega) q.2⟩ : Fin n) = q := Fin.ext (by show p.1 + (q.1 - p.1) = q.1; omega) rw [hidx, hq_val] at hle_q exact not_lt.mpr hle_q hplt rcases hex_desc with ⟨a, hpa, haq, ha1, hdesc⟩ let b : Fin n := ⟨a.1 + 1, ha1⟩ let τ' : Equiv.Perm (Fin n) := (Equiv.swap a b).trans τ have hτ'_lt : permLexLt τ' τ := by refine ⟨a, fun r hr => ?_, ?_⟩ · have hra : r ≠ a := ne_of_lt hr have hrb : r ≠ b := by intro h; have : r.1 = a.1 + 1 := congrArg Fin.val h have : r.1 < a.1 := hr; omega simp [τ', Equiv.swap_apply_of_ne_of_ne hra hrb] · simpa [τ'] using hdesc let i' : Fin m := enum.symm τ' have hi'j : i' < j := by have : enum i' < enum j := by rw [show enum i' = τ' from enum.apply_symm_apply τ'] exact hτ'_lt exact enum.strictMono.lt_iff_lt.mp this -- Show `prefixOfPerm τ a ∉ chainOfPerm σ`! have hnot_in_σ : prefixOfPerm τ a ∉ chainOfPerm σ := by intro hmem rcases Finset.mem_image.mp hmem with ⟨a', _, ha'eq⟩ have hc := congrArg Finset.card ha'eq rw [card_prefixOfPerm, card_prefixOfPerm] at hc have ha'a : a' = a := Fin.ext (Nat.succ.inj hc) rw [ha'a] at ha'eq -- `σ p ∈ prefixOfPerm σ a = prefixOfPerm τ a`, so `q ≤ a`, contradicting `a < q`! have hσp : σ p ∈ prefixOfPerm τ a := by rw [← ha'eq] exact Finset.mem_image.mpr ⟨p, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hpa⟩, rfl⟩ rcases Finset.mem_image.mp hσp with ⟨r, hr, hr_eq⟩ have hrq : r = q := τ.injective (hr_eq.trans hq_val.symm) have hqa : q ≤ a := hrq ▸ (Finset.mem_filter.mp hr).2 exact not_le.mpr haq hqa refine ⟨i', hi'j, prefixOfPerm τ a, Finset.mem_image.mpr ⟨a, Finset.mem_univ _, rfl⟩, hnot_in_σ, ?_⟩ simpa [F, i'] using erase_prefix_subset_swap τ a ha1 } refine ⟨⟨m, F, hshell⟩, fun k hk => ?_⟩ rw [shellable_hVec_eq_card_restrSet hshell hk] congr 1 -- Show `(restrSet F j).card = descents (enum j)` for every `j : Fin m`! have hrestr_eq : ∀ j : Fin m, (restrSet F j).card = descents (enum j) := by intro j set τ := enum j have hset : restrSet F j = (Finset.univ.filter fun a : Fin n => if ha : a.1 + 1 < n then τ ⟨a.1 + 1, ha⟩ < τ a else False).image (prefixOfPerm τ) := by ext A rw [restrSet, Finset.mem_filter, Finset.mem_image] simp only [F, chainOfPerm, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and] constructor · rintro ⟨⟨a, rfl⟩, i, hij, hsub⟩ -- Since `chainOfPerm τ` minus `prefixOfPerm τ a` lies in `chainOfPerm (enum i)`, -- `enum i` agrees with `τ` on EVERY prefix except possibly `a`, so `enum i` MUST be -- `τ ∘ swap a (a + 1)` with `a + 1 < n` and `τ (a + 1) < τ a`! set σ := enum i have hlex : permLexLt σ τ := enum.strictMono hij have hpref_eq : ∀ r : Fin n, r ≠ a → prefixOfPerm τ r = prefixOfPerm σ r := by intro r hra have hmem : prefixOfPerm τ r ∈ chainOfPerm σ := hsub (Finset.mem_erase.mpr ⟨fun h => hra (prefixOfPerm_injective τ h), Finset.mem_image.mpr ⟨r, Finset.mem_univ _, rfl⟩⟩) rcases Finset.mem_image.mp hmem with ⟨r', _, hr'eq⟩ have hc := congrArg Finset.card hr'eq rw [card_prefixOfPerm, card_prefixOfPerm] at hc have : r' = r := Fin.ext (Nat.succ.inj hc) exact this ▸ hr'eq.symm -- For every `r < a`, `σ r = τ r` (by induction from `prefixOfPerm` equality)! have hbefore : ∀ (t : ℕ) (ht : t < a.1), σ ⟨t, lt_trans ht a.2⟩ = τ ⟨t, lt_trans ht a.2⟩ := by intro t induction t using Nat.strong_induction_on with | h t ih => intro ht let r : Fin n := ⟨t, lt_trans ht a.2⟩ have hra : r ≠ a := fun h => ne_of_lt ht (congrArg Fin.val h) have hmem : σ r ∈ prefixOfPerm τ r := by rw [hpref_eq r hra] exact Finset.mem_image.mpr ⟨r, Finset.mem_filter.mpr ⟨Finset.mem_univ _, le_rfl⟩, rfl⟩ rcases Finset.mem_image.mp hmem with ⟨u, hu, hur⟩ have hule : u ≤ r := (Finset.mem_filter.mp hu).2 by_cases hur' : u = r · rw [hur'] at hur; exact hur.symm · exfalso have hult : u.1 < t := lt_of_le_of_ne hule (fun h => hur' (Fin.ext h)) have hu_eq : σ u = τ u := ih u.1 hult (lt_trans hult ht) exact hur' (σ.injective (hu_eq.trans hur)) have ha1 : a.1 + 1 < n := by by_contra hge; push Not at hge have heq_all : σ = τ := by ext r by_cases hra : r = a · subst r have hlt_a : ∀ t : Fin n, t ≠ a → t.1 < a.1 := fun t ht => by have := t.2; have : t.1 ≠ a.1 := fun h => ht (Fin.ext h); omega have hτeq : τ.symm (σ a) = a := by by_contra hne have hlt := hlt_a (τ.symm (σ a)) hne have heq' := hbefore (τ.symm (σ a)).1 hlt have h1 : σ (τ.symm (σ a)) = σ a := by simpa using heq'.trans (τ.apply_symm_apply (σ a)) exact hne (σ.injective h1) have hta : τ a = σ a := calc τ a = τ (τ.symm (σ a)) := congrArg τ hτeq.symm _ = σ a := τ.apply_symm_apply (σ a) exact congrArg Fin.val hta.symm · have hlt : r.1 < a.1 := by have := r.2; have : r.1 ≠ a.1 := fun h => hra (Fin.ext h); omega exact congrArg Fin.val (hbefore r.1 hlt) exact permLexLt_irrefl σ (heq_all ▸ hlex) let b : Fin n := ⟨a.1 + 1, ha1⟩ have hb1 : b.1 = a.1 + 1 := rfl have hσa_mem : σ a ∈ prefixOfPerm τ b := by rw [hpref_eq b (fun h => by have := congrArg Fin.val h; omega)] exact Finset.mem_image.mpr ⟨a, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by show a.1 ≤ a.1 + 1; omega⟩, rfl⟩ rcases Finset.mem_image.mp hσa_mem with ⟨u, hu, hu_eq⟩ have hule : u.1 ≤ a.1 + 1 := (Finset.mem_filter.mp hu).2 have hu_ge : a.1 ≤ u.1 := by by_contra hlt; push Not at hlt have h1 : σ u = τ u := hbefore u.1 hlt have h2 : σ u = σ a := h1.trans hu_eq exact ne_of_lt hlt (congrArg Fin.val (σ.injective h2)) have hσa_ne : σ a ≠ τ a := by intro heq_a have hpa_eq : prefixOfPerm τ a = prefixOfPerm σ a := by ext x simp only [prefixOfPerm, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and] constructor · rintro ⟨r, hr, rfl⟩ rcases eq_or_lt_of_le hr with hr_eq | hlt · subst r; exact ⟨a, le_rfl, heq_a⟩ · exact ⟨r, le_of_lt hlt, hbefore r.1 hlt⟩ · rintro ⟨r, hr, rfl⟩ rcases eq_or_lt_of_le hr with hr_eq | hlt · subst r; exact ⟨a, le_rfl, heq_a.symm⟩ · exact ⟨r, le_of_lt hlt, (hbefore r.1 hlt).symm⟩ have hchain : chainOfPerm τ = chainOfPerm σ := by ext B simp only [chainOfPerm, Finset.mem_image, Finset.mem_univ, true_and] constructor · rintro ⟨r, rfl⟩ by_cases hra : r = a · subst r; exact ⟨a, hpa_eq.symm⟩ · exact ⟨r, (hpref_eq r hra).symm⟩ · rintro ⟨r, rfl⟩ by_cases hra : r = a · subst r; exact ⟨a, hpa_eq⟩ · exact ⟨r, hpref_eq r hra⟩ exact permLexLt_irrefl σ ((chainOfPerm_injective hchain) ▸ hlex) have hub : u = b := by have : u.1 ≠ a.1 := fun h => hσa_ne (hu_eq.symm.trans (congrArg τ (Fin.ext h))) apply Fin.ext; show u.1 = a.1 + 1; omega have hσa_eq : σ a = τ b := (hub ▸ hu_eq).symm -- And since `permLexLt σ τ` and `σ r = τ r` for all `r < a`, the first disagreement is `a`, -- so `σ a < τ a`, i.e., `τ b < τ a`! have hdesc : τ b < τ a := by rcases hlex with ⟨p, hpeq, hplt⟩ have hpa : p = a := by rcases lt_trichotomy p a with hlt | heq | hgt · exact absurd (hbefore p.1 hlt) (ne_of_lt hplt) · exact heq · exact absurd (hpeq a hgt) hσa_ne subst hpa rwa [← hσa_eq] exact ⟨a, by simp [ha1, hdesc, b], rfl⟩ · rintro ⟨a, hcond, rfl⟩ split_ifs at hcond with ha1 · let b : Fin n := ⟨a.1 + 1, ha1⟩ let τ' : Equiv.Perm (Fin n) := (Equiv.swap a b).trans τ have hτ'_lt : permLexLt τ' τ := by refine ⟨a, fun r hr => ?_, ?_⟩ · have hra : r ≠ a := ne_of_lt hr have hrb : r ≠ b := fun h => by have h1 : r.1 = a.1 + 1 := congrArg Fin.val h have h2 : r.1 < a.1 := hr; omega simp [τ', Equiv.swap_apply_of_ne_of_ne hra hrb] · simpa [τ'] using hcond let i' : Fin m := enum.symm τ' have hi'j : i' < j := by have : enum i' < enum j := by rw [show enum i' = τ' from enum.apply_symm_apply τ'] exact hτ'_lt exact enum.strictMono.lt_iff_lt.mp this refine ⟨⟨a, rfl⟩, i', hi'j, ?_⟩ rw [show enum i' = τ' from enum.apply_symm_apply τ'] exact erase_prefix_subset_swap τ a ha1 rw [hset, Finset.card_image_of_injective _ (prefixOfPerm_injective τ)] rfl simp_rw [hrestr_eq] unfold eulerianNumber refine Finset.card_bij (fun j _ => enum j) ?_ ?_ ?_ · intro j hj rw [Finset.mem_filter] at hj ⊢ exact ⟨Finset.mem_univ _, hj.2⟩ · intro j₁ _ j₂ _ h; exact enum.injective h · intro σ hσ rw [Finset.mem_filter] at hσ exact ⟨enum.symm σ, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by simpa using hσ.2⟩, by simp⟩ /-- **COROLLARY 4B (`booleanOrderComplex_hVec_eq_eulerian`)**: For EVERY `n : ℕ` and EVERY `k ≤ n`, `h_k(sd(Δ_{n-1})) = eulerianNumber n k`. -/ theorem booleanOrderComplex_hVec_eq_eulerian (n : ℕ) {k : ℕ} (hk : k ≤ n) : (booleanOrderComplex n).hVec n k = (eulerianNumber n k : ℤ) := (booleanOrderComplex_isShellable_and_hVec n).2 k hk /-- Concrete check: for `n = 3`, the Eulerian numbers are `A(3, 0) = 1, A(3, 1) = 4, A(3, 2) = 1, A(3, 3) = 0`. -/ theorem eulerianNumber_three : eulerianNumber 3 0 = 1 ∧ eulerianNumber 3 1 = 4 ∧ eulerianNumber 3 2 = 1 ∧ eulerianNumber 3 3 = 0 := by decide /-! ## Section 5: Explicit Non-Shellable & Non-Partitionable Separation Witnesses -/ /-- The **Bowtie Complex** on `Fin 5`: two triangles `{0, 1, 2}` and `{0, 3, 4}` glued at vertex `0`. It is pure (`d = 3`) and connected, with `f = [1, 5, 6, 2]` and `h = [1, 2, -1, 0]`! -/ def bowtieComplex : FinSimplicialComplex (Fin 5) where faces := ({0, 1, 2} : Finset (Fin 5)).powerset ∪ ({0, 3, 4} : Finset (Fin 5)).powerset down_closed := by intro σ τ hσ hτσ rw [Finset.mem_union, Finset.mem_powerset, Finset.mem_powerset] at hσ ⊢ exact hσ.elim (fun h => Or.inl (hτσ.trans h)) (fun h => Or.inr (hτσ.trans h)) empty_mem := by simp theorem bowtieComplex_isPure : IsPure bowtieComplex 3 := by refine ⟨fun σ hσ => ?_, fun σ hσ => ?_⟩ · simp only [bowtieComplex, Finset.mem_union, Finset.mem_powerset] at hσ rcases hσ with h | h <;> exact (Finset.card_le_card h).trans (by decide) · simp only [bowtieComplex, Finset.mem_union, Finset.mem_powerset] at hσ rcases hσ with h | h · exact ⟨{0, 1, 2}, by simp [bowtieComplex], by decide, h⟩ · exact ⟨{0, 3, 4}, by simp [bowtieComplex], by decide, h⟩ theorem bowtieComplex_fVec : bowtieComplex.fVecCard 0 = 1 ∧ bowtieComplex.fVecCard 1 = 5 ∧ bowtieComplex.fVecCard 2 = 6 ∧ bowtieComplex.fVecCard 3 = 2 := by decide theorem bowtieComplex_hVec_two_neg : bowtieComplex.hVec 3 2 = -1 := by unfold FinSimplicialComplex.hVec fToH FinSimplicialComplex.fVec have ⟨hf0, hf1, hf2, _⟩ := bowtieComplex_fVec rw [Finset.sum_range_succ, Finset.sum_range_succ, Finset.sum_range_one] rw [hf0, hf1, hf2] norm_num /-- **THEOREM 5A (`bowtieComplex_not_partitionable`, `bowtieComplex_not_shellable`)**: The pure connected bowtie complex has `h_2 = -1 < 0`, hence is **neither partitionable nor shellable**! -/ theorem bowtieComplex_not_partitionable : ¬ IsPartitionable bowtieComplex 3 := by intro hp have hnn := partitionable_hVec_nonneg hp (r := 2) (by omega) rw [bowtieComplex_hVec_two_neg] at hnn omega theorem bowtieComplex_not_shellable : ¬ IsShellable bowtieComplex 3 := fun hs => bowtieComplex_not_partitionable (shellable_imp_partitionable hs) /-- **Disjoint Triangles Complex** on `Fin 6`: two disjoint triangles `{0, 1, 2}` and `{3, 4, 5}`. Pure (`d = 3`), with `f = [1, 6, 6, 2]` and `h = [1, 3, -3, 1]`! -/ def disjointTrianglesComplex : FinSimplicialComplex (Fin 6) where faces := ({0, 1, 2} : Finset (Fin 6)).powerset ∪ ({3, 4, 5} : Finset (Fin 6)).powerset down_closed := by intro σ τ hσ hτσ rw [Finset.mem_union, Finset.mem_powerset, Finset.mem_powerset] at hσ ⊢ exact hσ.elim (fun h => Or.inl (hτσ.trans h)) (fun h => Or.inr (hτσ.trans h)) empty_mem := by simp theorem disjointTrianglesComplex_fVec : disjointTrianglesComplex.fVecCard 0 = 1 ∧ disjointTrianglesComplex.fVecCard 1 = 6 ∧ disjointTrianglesComplex.fVecCard 2 = 6 ∧ disjointTrianglesComplex.fVecCard 3 = 2 := by decide theorem disjointTrianglesComplex_hVec_two_neg : disjointTrianglesComplex.hVec 3 2 = -3 := by unfold FinSimplicialComplex.hVec fToH FinSimplicialComplex.fVec have ⟨hf0, hf1, hf2, _⟩ := disjointTrianglesComplex_fVec rw [Finset.sum_range_succ, Finset.sum_range_succ, Finset.sum_range_one] rw [hf0, hf1, hf2] norm_num /-- **THEOREM 5B (`disjointTrianglesComplex_not_partitionable`, `disjointTrianglesComplex_not_shellable`)**: Two disjoint triangles have `h_2 = -3 < 0`, hence are **neither partitionable nor shellable**! -/ theorem disjointTrianglesComplex_not_partitionable : ¬ IsPartitionable disjointTrianglesComplex 3 := by intro hp have hnn := partitionable_hVec_nonneg hp (r := 2) (by omega) rw [disjointTrianglesComplex_hVec_two_neg] at hnn omega theorem disjointTrianglesComplex_not_shellable : ¬ IsShellable disjointTrianglesComplex 3 := fun hs => disjointTrianglesComplex_not_partitionable (shellable_imp_partitionable hs) /-! ## Axiom Verification -/ #print axioms fToH_hToF #print axioms isPure_of_isShellable #print axioms mem_boolInterval_restrSet_iff #print axioms shelling_interval_partition #print axioms shellable_imp_partitionable #print axioms partitionable_fVecCard #print axioms partitionable_hVec_eq_card #print axioms partitionable_hVec_nonneg #print axioms shellable_hVec_eq_card_restrSet #print axioms shellable_hVec_nonneg #print axioms shellable_fVecCard_top #print axioms shellable_hVec_top_eq_card_spanning #print axioms simplexComplex_isShellable #print axioms simplexBoundary_isShelling #print axioms simplexBoundary_isShellable #print axioms simplexBoundary_hVec_via_shelling #print axioms crossPolytope_isShelling #print axioms crossPolytope_isShellable #print axioms crossPolytope_hVec_via_shelling #print axioms booleanOrderComplex_isShellable_and_hVec #print axioms booleanOrderComplex_hVec_eq_eulerian #print axioms eulerianNumber_three #print axioms bowtieComplex_isPure #print axioms bowtieComplex_hVec_two_neg #print axioms bowtieComplex_not_partitionable #print axioms bowtieComplex_not_shellable #print axioms disjointTrianglesComplex_hVec_two_neg #print axioms disjointTrianglesComplex_not_partitionable #print axioms disjointTrianglesComplex_not_shellable end ShellabilityPartitionabilityAndStanley