import Mathlib open Filter Finset open scoped BigOperators Topology namespace HypercubeBinomial noncomputable def binWeight (n k : ℕ) : ℝ := (n.choose k : ℝ) / 2^n noncomputable def binAvg (n : ℕ) (f : ℕ → ℝ) : ℝ := ∑ k ∈ range (n+1), binWeight n k * f k theorem binWeight_nonneg (n k : ℕ) : 0 ≤ binWeight n k := by unfold binWeight positivity theorem binWeight_eq_zero {n k : ℕ} (h : n < k) : binWeight n k = 0 := by simp [binWeight, Nat.choose_eq_zero_of_lt h] theorem binAvg_one (n : ℕ) : binAvg n (fun _ => 1) = 1 := by unfold binAvg binWeight simp only [mul_one, ← Finset.sum_div] rw [← Nat.cast_sum, Nat.sum_range_choose, Nat.cast_pow] norm_num theorem binAvg_zero (f : ℕ → ℝ) : binAvg 0 f = f 0 := by simp [binAvg, binWeight] theorem binAvg_succ (n : ℕ) (f : ℕ → ℝ) : binAvg (n+1) f = (binAvg n f + binAvg n (fun k => f (k+1))) / 2 := by have hw (k : ℕ) : binWeight (n+1) (k+1) = (binWeight n k + binWeight n (k+1)) / 2 := by simp [binWeight, Nat.choose_succ_succ, pow_succ] ring have hw0 : binWeight (n+1) 0 = binWeight n 0 / 2 := by simp [binWeight, pow_succ] ring unfold binAvg rw [Finset.sum_range_succ', hw0] simp_rw [hw, add_div, add_mul, div_mul_eq_mul_div, Finset.sum_add_distrib, ← Finset.sum_div] rw [Finset.sum_range_succ' (fun k => binWeight n k * f k)] rw [Finset.sum_range_succ (fun k => binWeight n (k+1) * f (k+1))] rw [binWeight_eq_zero (by omega : n < n+1)] ring theorem binAvg_nonneg (n : ℕ) (f : ℕ → ℝ) (h : ∀ k, 0 ≤ f k) : 0 ≤ binAvg n f := Finset.sum_nonneg (fun k _ => mul_nonneg (binWeight_nonneg n k) (h k)) theorem binAvg_sub (n : ℕ) (f g : ℕ → ℝ) : binAvg n (fun k => f k - g k) = binAvg n f - binAvg n g := by simp [binAvg, mul_sub, Finset.sum_sub_distrib] theorem abs_binAvg_le (n : ℕ) (f : ℕ → ℝ) {C : ℝ} (h : ∀ k, |f k| ≤ C) : |binAvg n f| ≤ C := by unfold binAvg calc _ ≤ ∑ k ∈ range (n+1), |binWeight n k * f k| := Finset.abs_sum_le_sum_abs .. _ ≤ ∑ k ∈ range (n+1), binWeight n k * C := by apply Finset.sum_le_sum intro k hk rw [abs_mul, abs_of_nonneg (binWeight_nonneg n k)] exact mul_le_mul_of_nonneg_left (h k) (binWeight_nonneg n k) _ = C := by rw [← Finset.sum_mul] have hw : ∑ k ∈ range (n+1), binWeight n k = 1 := by simpa [binAvg] using binAvg_one n rw [hw, one_mul] theorem binAvg_add (n : ℕ) (f g : ℕ → ℝ) : binAvg n (fun k => f k + g k) = binAvg n f + binAvg n g := by simp [binAvg, mul_add, Finset.sum_add_distrib] theorem binAvg_mul (n : ℕ) (c : ℝ) (f : ℕ → ℝ) : binAvg n (fun k => c * f k) = c * binAvg n f := by simp [binAvg, Finset.mul_sum, mul_left_comm] /-- The centered walk after `n` fair steps has second moment `n`. -/ theorem binAvg_sq_centered (n : ℕ) : binAvg n (fun k => (2*(k:ℝ) - n)^2) = n := by induction n with | zero => simp [binAvg_zero] | succ n ih => rw [binAvg_succ, ← binAvg_add, div_eq_inv_mul, ← one_div, ← binAvg_mul] have hf : (fun k : ℕ => (1/2:ℝ)*((2*(k:ℝ) - ((n+1:ℕ):ℝ))^2 + (2*((k+1:ℕ):ℝ) - ((n+1:ℕ):ℝ))^2)) = (fun k : ℕ => (2*(k:ℝ) - n)^2 + 1) := by funext k push_cast ring rw [hf, binAvg_add, ih, binAvg_one] push_cast norm_num private theorem binWeight_mul_succ (n k : ℕ) (hk : k ≤ n+1) : binWeight n k * (n+1:ℝ) = binWeight (n+1) k * (2*(n+1-(k:ℝ))) := by have h : (n.choose k : ℝ) * (n+1:ℝ) = ((n+1).choose k:ℝ) * (n+1-(k:ℝ)) := by simpa [Nat.cast_mul, Nat.cast_add, Nat.cast_sub hk] using congrArg (fun t : ℕ => (t:ℝ)) (Nat.choose_mul_succ_eq n k) unfold binWeight rw [pow_succ] field_simp linear_combination h private theorem binAvg_extension (n : ℕ) (f : ℕ → ℝ) : (n+1:ℝ) * binAvg n f = binAvg (n+1) (fun k => 2*(n+1-(k:ℝ)) * f k) := by unfold binAvg rw [Finset.mul_sum, Finset.sum_range_succ _ (n+1)] push_cast rw [show (n:ℝ) + 1 - ((n:ℝ) + 1) = 0 by ring] simp only [mul_zero, zero_mul, add_zero] apply Finset.sum_congr rfl intro k hk have hw := binWeight_mul_succ n k (by have := Finset.mem_range.mp hk; omega) calc (n+1:ℝ) * (binWeight n k * f k) = (binWeight n k * (n+1:ℝ)) * f k := by ring _ = _ := by rw [hw]; ring private theorem binAvg_shift_eq (n : ℕ) (f : ℕ → ℝ) : (n+1:ℝ) * (binAvg n (fun k => f (k+1)) - binAvg n f) = binAvg (n+1) (fun k => 2*(2*(k:ℝ)-(n+1)) * f k) := by calc _ = 2 * ((n+1:ℝ) * binAvg (n+1) f - (n+1:ℝ) * binAvg n f) := by rw [binAvg_succ] ring _ = _ := by rw [binAvg_extension, ← binAvg_mul, ← binAvg_sub, ← binAvg_mul] congr 1 funext k ring theorem binAvg_sq_le (n : ℕ) (f : ℕ → ℝ) : (binAvg n f)^2 ≤ binAvg n (fun k => (f k)^2) := by let w := binWeight n have h : (∑ k ∈ range (n+1), w k * |f k|)^2 ≤ (∑ k ∈ range (n+1), w k) * ∑ k ∈ range (n+1), w k * (f k)^2 := by apply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul · exact fun k hk => binWeight_nonneg n k · exact fun k hk => mul_nonneg (binWeight_nonneg n k) (sq_nonneg _) · intro k hk rw [mul_pow, sq_abs] nlinarith only have hnorm : ∑ k ∈ range (n+1), w k = 1 := by simpa [w, binAvg] using binAvg_one n rw [hnorm, one_mul] at h have hb : |binAvg n f| ≤ ∑ k ∈ range (n+1), w k * |f k| := by calc _ ≤ ∑ k ∈ range (n+1), |w k * f k| := Finset.abs_sum_le_sum_abs .. _ = _ := by apply Finset.sum_congr rfl intro k hk rw [abs_mul, abs_of_nonneg (binWeight_nonneg n k)] unfold binAvg at * rw [← sq_abs (∑ k ∈ range (n+1), binWeight n k * f k)] exact le_trans (pow_le_pow_left₀ (abs_nonneg _) hb 2) h /-- Shifting a function bounded by one changes its binomial average by at most `2 / sqrt (n+1)`. -/ theorem binAvg_shift_sq_le (n : ℕ) (f : ℕ → ℝ) (hf : ∀ k, |f k| ≤ 1) : (binAvg n (fun k => f (k+1)) - binAvg n f)^2 ≤ 4 / (n+1:ℝ) := by have hs := binAvg_sq_le (n+1) (fun k => 2*(2*(k:ℝ)-(n+1)) * f k) have hb : binAvg (n+1) (fun k => (2*(2*(k:ℝ)-(n+1)) * f k)^2) ≤ binAvg (n+1) (fun k => 4 * (2*(k:ℝ)-((n+1:ℕ):ℝ))^2) := by unfold binAvg apply Finset.sum_le_sum intro k hk apply mul_le_mul_of_nonneg_left _ (binWeight_nonneg _ _) have hk' : (f k)^2 ≤ 1 := by rw [← sq_abs] simpa using pow_le_pow_left₀ (abs_nonneg _) (hf k) 2 push_cast rw [mul_pow, show (2 * (2 * (k:ℝ) - ((n:ℝ) + 1)))^2 = 4 * (2 * (k:ℝ) - ((n:ℝ) + 1))^2 by ring] apply mul_le_of_le_one_right (by positivity) hk' have h := le_trans hs hb rw [binAvg_mul, binAvg_sq_centered, ← binAvg_shift_eq] at h push_cast at h rw [mul_pow] at h apply (le_div_iff₀ (by positivity : (0:ℝ) < n+1)).2 nlinarith only [h, mul_nonneg (show (0:ℝ) ≤ n by positivity) (sq_nonneg (binAvg n (fun k => f (k+1)) - binAvg n f))] theorem binAvg_shift_eventually (ε : ℝ) (hε : 0 < ε) : ∀ᶠ n : ℕ in atTop, ∀ f : ℕ → ℝ, (∀ k, |f k| ≤ 1) → |binAvg n (fun k => f (k+1)) - binAvg n f| ≤ ε := by obtain ⟨N,hN⟩ := exists_nat_gt (4 / ε^2) filter_upwards [eventually_ge_atTop N] with n hn f hf have h := binAvg_shift_sq_le n f hf have hden : 4 / (n+1:ℝ) ≤ ε^2 := by apply (div_le_iff₀ (by positivity : (0:ℝ) < n+1)).2 have h₁ : 4 < (N:ℝ) * ε^2 := (div_lt_iff₀ (by positivity : 0 < ε^2)).1 hN have h₂ : (N:ℝ) ≤ n+1 := by exact_mod_cast (by omega : N ≤ n+1) exact h₁.le.trans (by simpa [mul_comm] using mul_le_mul_of_nonneg_right h₂ (sq_nonneg ε)) have hsq := h.trans hden rw [← sq_abs (binAvg n (fun k => f (k+1)) - binAvg n f)] at hsq nlinarith only [hsq, abs_nonneg (binAvg n (fun k => f (k+1)) - binAvg n f), hε] end HypercubeBinomial namespace HypercubeTwoBlocks def line (a b c : Bool) : ℤ := if a.toNat + 2 * b.toNat + c.toNat = 1 then 1 else 0 def square (a b c d : Bool) : ℤ := if a.toNat + b.toNat + c.toNat + d.toNat = 1 then 1 else 0 def encode (a b c : Bool) : ℕ := a.toNat + 2 * b.toNat + 4 * c.toNat def potential : ℕ → ℕ → ℤ | 0, 5 => -4 | 5, 0 => 4 | 1, 2 | 4, 2 | 1, 3 | 4, 6 => -2 | 2, 1 | 2, 4 | 3, 1 | 6, 4 => 2 | _, _ => 0 def h (f : ℕ → ℕ → Bool) (i j : ℕ) : ℤ := line (f i j) (f (i+1) j) (f (i+2) j) def v (f : ℕ → ℕ → Bool) (i j : ℕ) : ℤ := line (f i j) (f i (j+1)) (f i (j+2)) def s (f : ℕ → ℕ → Bool) (i j : ℕ) : ℤ := square (f i j) (f (i+1) j) (f i (j+1)) (f (i+1) (j+1)) def rowPotential (f : ℕ → ℕ → Bool) (i j : ℕ) : ℤ := potential (encode (f i j) (f (i+1) j) (f (i+2) j)) (encode (f i (j+1)) (f (i+1) (j+1)) (f (i+2) (j+1))) def colPotential (f : ℕ → ℕ → Bool) (i j : ℕ) : ℤ := potential (encode (f i j) (f i (j+1)) (f i (j+2))) (encode (f (i+1) j) (f (i+1) (j+1)) (f (i+1) (j+2))) theorem line_bounds (a b c : Bool) : 0 ≤ line a b c ∧ line a b c ≤ 1 := by unfold line split <;> decide theorem square_bounds (a b c d : Bool) : 0 ≤ square a b c d ∧ square a b c d ≤ 1 := by unfold square split <;> decide theorem h_bounds (f : ℕ → ℕ → Bool) (i j : ℕ) : 0 ≤ h f i j ∧ h f i j ≤ 1 := line_bounds _ _ _ theorem v_bounds (f : ℕ → ℕ → Bool) (i j : ℕ) : 0 ≤ v f i j ∧ v f i j ≤ 1 := line_bounds _ _ _ theorem s_bounds (f : ℕ → ℕ → Bool) (i j : ℕ) : 0 ≤ s f i j ∧ s f i j ≤ 1 := square_bounds _ _ _ _ theorem potential_bound (a b : ℕ) : |potential a b| ≤ 4 := by unfold potential split <;> decide theorem rowPotential_bound (f : ℕ → ℕ → Bool) (i j : ℕ) : |rowPotential f i j| ≤ 4 := potential_bound _ _ theorem colPotential_bound (f : ℕ → ℕ → Bool) (i j : ℕ) : |colPotential f i j| ≤ 4 := potential_bound _ _ private theorem bool_patch : ∀ a b c d e f g h i : Bool, let lines := line a b c + 2 * line d e f + line g h i + line a d g + 2 * line b e h + line c f i let squares := square a b d e + square b c e f + square d e g h + square e f h i 3 * (lines + 2 * squares) ≤ 32 + potential (encode a b c) (encode d e f) - potential (encode d e f) (encode g h i) + potential (encode a d g) (encode b e h) - potential (encode b e h) (encode c f i) := by decide theorem patch (f : ℕ → ℕ → Bool) (i j : ℕ) : 3 * (h f i j + 2 * h f i (j+1) + h f i (j+2) + v f i j + 2 * v f (i+1) j + v f (i+2) j + 2 * (s f i j + s f (i+1) j + s f i (j+1) + s f (i+1) (j+1))) ≤ 32 + rowPotential f i j - rowPotential f i (j+1) + colPotential f i j - colPotential f (i+1) j := bool_patch (f i j) (f (i+1) j) (f (i+2) j) (f i (j+1)) (f (i+1) (j+1)) (f (i+2) (j+1)) (f i (j+2)) (f (i+1) (j+2)) (f (i+2) (j+2)) end HypercubeTwoBlocks namespace HypercubeTwoBlocks open HypercubeBinomial open Topology private theorem binAvg_const (n : ℕ) (c : ℝ) : binAvg n (fun _ => c) = c := by have hw := binAvg_one n simp only [binAvg, mul_one] at hw simp only [binAvg, ← sum_mul, hw, one_mul] private theorem binAvg_mono {n : ℕ} {f g : ℕ → ℝ} (h : ∀ i, f i ≤ g i) : binAvg n f ≤ binAvg n g := sum_le_sum fun i _ => mul_le_mul_of_nonneg_left (h i) (binWeight_nonneg n i) private noncomputable def avg (n m : ℕ) (f : ℕ → ℕ → ℝ) := binAvg n (fun i => binAvg m (f i)) private theorem average_powerset_card {α : Type*} (s : Finset α) (f : ℕ → ℝ) : (∑ t ∈ s.powerset, f t.card) / (2 : ℝ)^s.card = binAvg s.card f := by classical rw [powerset_card_biUnion, sum_biUnion (fun _ _ _ _ h => pairwise_disjoint_powersetCard s h), binAvg, sum_div] apply sum_congr rfl intro k hk rw [show (∑ t ∈ s.powersetCard k, f t.card) = ∑ _t ∈ s.powersetCard k, f k by apply sum_congr rfl intro t ht rw [(mem_powersetCard.mp ht).2]] rw [sum_const, nsmul_eq_mul, card_powersetCard, binWeight] ring /-- Bits in fixed coordinates are specified by the subsets on which they are one. -/ private noncomputable def subsetAverage (n m : ℕ) (f : ℕ → ℕ → ℝ) : ℝ := (∑ a : Finset (Fin n), ∑ b : Finset (Fin m), f a.card b.card) / (2:ℝ)^(n+m) private theorem subsetAverage_eq_avg (n m : ℕ) (f : ℕ → ℕ → ℝ) : subsetAverage n m f = avg n m f := by have hu (k : ℕ) (g : ℕ → ℝ) : (∑ t : Finset (Fin k), g t.card) / (2:ℝ)^k = binAvg k g := by simpa using average_powerset_card (univ : Finset (Fin k)) g unfold subsetAverage avg rw [pow_add, mul_comm, ← div_div, sum_div] simp_rw [hu] exact hu n (fun a => binAvg m (f a)) private theorem avg_add (n m : ℕ) (f g : ℕ → ℕ → ℝ) : avg n m (fun i j => f i j + g i j) = avg n m f + avg n m g := by simp only [avg, binAvg_add] private theorem avg_sub (n m : ℕ) (f g : ℕ → ℕ → ℝ) : avg n m (fun i j => f i j - g i j) = avg n m f - avg n m g := by simp only [avg, binAvg_sub] private theorem avg_mul (n m : ℕ) (c : ℝ) (f : ℕ → ℕ → ℝ) : avg n m (fun i j => c * f i j) = c * avg n m f := by simp only [avg, binAvg_mul] private theorem avg_expand_left (n m : ℕ) (f : ℕ → ℕ → ℝ) : avg (n+1) m f = (avg n m f + avg n m (fun i j => f (i+1) j)) / 2 := binAvg_succ _ _ private theorem avg_expand_right (n m : ℕ) (f : ℕ → ℕ → ℝ) : avg n (m+1) f = (avg n m f + avg n m (fun i j => f i (j+1))) / 2 := by unfold avg simp_rw [binAvg_succ m] simp only [div_eq_mul_inv, mul_comm _ (2 : ℝ)⁻¹, binAvg_mul, binAvg_add] private theorem avg_const (n m : ℕ) (c : ℝ) : avg n m (fun _ _ => c) = c := by simp only [avg, binAvg_const] private theorem avg_mono {n m : ℕ} {f g : ℕ → ℕ → ℝ} (h : ∀ i j, f i j ≤ g i j) : avg n m f ≤ avg n m g := binAvg_mono fun i => binAvg_mono (h i) private theorem avg_shift_left {ε : ℝ} {n m : ℕ} (shift : ∀ (g : ℕ → ℝ), (∀ x, |g x| ≤ 1) → |binAvg n (fun k => g (k+1)) - binAvg n g| ≤ ε) (f : ℕ → ℕ → ℝ) (hf : ∀ i j, |f i j| ≤ 1) : |avg n m (fun i j => f (i+1) j) - avg n m f| ≤ ε := shift (fun i => binAvg m (f i)) fun i => abs_binAvg_le _ _ (hf i) private theorem avg_shift_right {ε : ℝ} {n m : ℕ} (shift : ∀ (g : ℕ → ℝ), (∀ x, |g x| ≤ 1) → |binAvg m (fun k => g (k+1)) - binAvg m g| ≤ ε) (f : ℕ → ℕ → ℝ) (hf : ∀ i j, |f i j| ≤ 1) : |avg n m (fun i j => f i (j+1)) - avg n m f| ≤ ε := by unfold avg rw [← binAvg_sub] refine abs_le.mpr ⟨?_, ?_⟩ · simpa only [binAvg_const] using (binAvg_mono (n := n) fun i => (abs_le.mp (shift (f i) (hf i))).1) · simpa only [binAvg_const] using (binAvg_mono (n := n) fun i => (abs_le.mp (shift (f i) (hf i))).2) private theorem lower_mod (i j : ℕ) : let f (r i j : ℕ) : Bool := decide ((i+j) % 3 = r) h (f 0) i j + h (f 1) i j + h (f 2) i j = 2 ∧ v (f 0) i j + v (f 1) i j + v (f 2) i j = 2 ∧ s (f 0) i j + s (f 1) i j + s (f 2) i j = 2 := by dsimp [h, v, s, line, square] have h0 : (i+j) % 3 = 0 ∨ (i+j) % 3 = 1 ∨ (i+j) % 3 = 2 := by omega rcases h0 with h0 | h0 | h0 all_goals have a : (i + 1 + j) % 3 = ((i+j)%3 + 1)%3 := by omega have b : (i + 2 + j) % 3 = ((i+j)%3 + 2)%3 := by omega have c : (i + (j+1)) % 3 = ((i+j)%3 + 1)%3 := by omega have d : (i + (j+2)) % 3 = ((i+j)%3 + 2)%3 := by omega have e : (i + 1 + (j+1)) % 3 = ((i+j)%3 + 2)%3 := by omega simp [a, b, c, d, e, h0] abbrev Marking := ℕ → ℕ → Bool private def lines (f : Marking) (i j : ℕ) : ℤ := h f i j + 2 * h f i (j+1) + h f i (j+2) + v f i j + 2 * v f (i+1) j + v f (i+2) j private def squares (f : Marking) (i j : ℕ) : ℤ := s f i j + s f (i+1) j + s f i (j+1) + s f (i+1) (j+1) private noncomputable def lineMass (n : ℕ) (f : Marking) := avg n n (fun i j => (lines f i j : ℝ)) private noncomputable def squareMass (n : ℕ) (f : Marking) := avg n n (fun i j => (squares f i j : ℝ)) private noncomputable def correction (n : ℕ) : ℝ := 1 / (2 * (n : ℝ) + 3) /-- With two coordinate blocks of size `n + 2`, this is the fraction of coordinate faces with exactly one marked vertex. The argument `f i j` records whether the layer with weight `i` in the first block and `j` in the second is marked. The two spare fair bits per block give the coefficients `1, 2, 1` for the same-block faces, and `1, 1, 1, 1` for the mixed faces. -/ noncomputable def density (n : ℕ) (f : Marking) : ℝ := (1 - correction n) * lineMass n f / 16 + (1 + correction n) * squareMass n f / 8 /-- The fraction of faces with one marked vertex, counted by the locations of the two free coordinates. The block size is `n + 2`. The two cases with both free coordinates in one block each have `m*(m-1)/2` choices of the pair, and the case with one free coordinate per block has `m^2` choices. -/ noncomputable def faceFraction (n : ℕ) (f : Marking) : ℝ := let m := (n : ℝ) + 2 (m * (m - 1) / 2 * (subsetAverage n (n+2) (fun i j => h f i j) + subsetAverage (n+2) n (fun i j => v f i j)) + m^2 * subsetAverage (n+1) (n+1) (fun i j => s f i j)) / (m * (2*m - 1)) theorem faceFraction_eq_density (n : ℕ) (f : Marking) : faceFraction n f = density n f := by unfold faceFraction density correction lineMass squareMass lines squares push_cast simp only [subsetAverage_eq_avg, avg_expand_left, avg_expand_right, avg_add, avg_mul] simp only [Nat.add_assoc] have hm : (n : ℝ) + 2 ≠ 0 := by positivity have hr : (2 * (n : ℝ) + 3) ≠ 0 := by positivity have hr' : (2 * ((n : ℝ) + 2) - 1) ≠ 0 := by convert hr using 1; ring field_simp ring /-- The supremum runs over all marking rules. Only weights at most `n + 2` in either block contribute to the density. -/ noncomputable def best (n : ℕ) : ℝ := ⨆ f : Marking, density n f private theorem lineMass_bounds (n : ℕ) (f : Marking) : 0 ≤ lineMass n f ∧ lineMass n f ≤ 8 := by constructor · rw [← avg_const n n (0 : ℝ)] apply avg_mono intro i j exact_mod_cast (show 0 ≤ lines f i j by unfold lines linarith [(h_bounds f i j).1, (h_bounds f i (j+1)).1, (h_bounds f i (j+2)).1, (v_bounds f i j).1, (v_bounds f (i+1) j).1, (v_bounds f (i+2) j).1]) · rw [← avg_const n n (8 : ℝ)] apply avg_mono intro i j exact_mod_cast (show lines f i j ≤ 8 by unfold lines linarith [(h_bounds f i j).2, (h_bounds f i (j+1)).2, (h_bounds f i (j+2)).2, (v_bounds f i j).2, (v_bounds f (i+1) j).2, (v_bounds f (i+2) j).2]) private theorem squareMass_bounds (n : ℕ) (f : Marking) : 0 ≤ squareMass n f ∧ squareMass n f ≤ 4 := by constructor · rw [← avg_const n n (0 : ℝ)] apply avg_mono intro i j exact_mod_cast (show 0 ≤ squares f i j by unfold squares linarith [(s_bounds f i j).1, (s_bounds f (i+1) j).1, (s_bounds f i (j+1)).1, (s_bounds f (i+1) (j+1)).1]) · rw [← avg_const n n (4 : ℝ)] apply avg_mono intro i j exact_mod_cast (show squares f i j ≤ 4 by unfold squares linarith [(s_bounds f i j).2, (s_bounds f (i+1) j).2, (s_bounds f i (j+1)).2, (s_bounds f (i+1) (j+1)).2]) private theorem correction_bounds (n : ℕ) : 0 ≤ correction n ∧ correction n ≤ 1 := by unfold correction refine ⟨by positivity, (div_le_one (by positivity)).2 ?_⟩ linarith [Nat.cast_nonneg (α := ℝ) n] theorem density_le_one (n : ℕ) (f : Marking) : density n f ≤ 1 := by have hc := correction_bounds n have hl := mul_le_mul_of_nonneg_left (lineMass_bounds n f).2 (sub_nonneg.mpr hc.2) have hs := mul_le_mul_of_nonneg_left (squareMass_bounds n f).2 (show 0 ≤ 1 + correction n by linarith [hc.1]) unfold density linarith private theorem density_bdd (n : ℕ) : BddAbove (Set.range (density n)) := ⟨1, by rintro _ ⟨f, rfl⟩; exact density_le_one n f⟩ private def residue (r : ℕ) : Marking := fun i j => decide ((i+j) % 3 = r) theorem best_ge_two_thirds (n : ℕ) : (2/3 : ℝ) ≤ best n := by have hl : lineMass n (residue 0) + lineMass n (residue 1) + lineMass n (residue 2) = 16 := by unfold lineMass rw [← avg_add, ← avg_add, ← avg_const n n (16 : ℝ)] congr 1 funext i j have hh (a b : ℕ) : h (residue 0) a b + h (residue 1) a b + h (residue 2) a b = 2 := (lower_mod a b).1 have hv (a b : ℕ) : v (residue 0) a b + v (residue 1) a b + v (residue 2) a b = 2 := (lower_mod a b).2.1 exact_mod_cast (show lines (residue 0) i j + lines (residue 1) i j + lines (residue 2) i j = 16 by unfold lines linarith [hh i j, hh i (j+1), hh i (j+2), hv i j, hv (i+1) j, hv (i+2) j]) have hs : squareMass n (residue 0) + squareMass n (residue 1) + squareMass n (residue 2) = 8 := by unfold squareMass rw [← avg_add, ← avg_add, ← avg_const n n (8 : ℝ)] congr 1 funext i j have hh (a b : ℕ) : s (residue 0) a b + s (residue 1) a b + s (residue 2) a b = 2 := (lower_mod a b).2.2 exact_mod_cast (show squares (residue 0) i j + squares (residue 1) i j + squares (residue 2) i j = 8 by unfold squares linarith [hh i j, hh (i+1) j, hh i (j+1), hh (i+1) (j+1)]) have hsum : density n (residue 0) + density n (residue 1) + density n (residue 2) = 2 := by unfold density linear_combination (1 - correction n) / 16 * hl + (1 + correction n) / 8 * hs have hub (r : ℕ) : density n (residue r) ≤ best n := le_ciSup (density_bdd n) _ linarith [hub 0, hub 1, hub 2] private theorem mass_bound_of_shift (n : ℕ) (ε : ℝ) (shift : ∀ (g : ℕ → ℝ), (∀ x, |g x| ≤ 1) → |binAvg n (fun k => g (k+1)) - binAvg n g| ≤ ε) (f : Marking) : 3 * (lineMass n f + 2 * squareMass n f) ≤ 32 + 8 * ε := by let row (i j : ℕ) : ℝ := rowPotential f i j / 4 let col (i j : ℕ) : ℝ := colPotential f i j / 4 have hr (i j : ℕ) : |row i j| ≤ 1 := by have ha : |(rowPotential f i j : ℝ)| ≤ 4 := by exact_mod_cast rowPotential_bound f i j simpa only [row, abs_div, abs_of_nonneg (by positivity : (0:ℝ) ≤ 4), div_le_one (by positivity : (0:ℝ) < 4)] using ha have hc (i j : ℕ) : |col i j| ≤ 1 := by have ha : |(colPotential f i j : ℝ)| ≤ 4 := by exact_mod_cast colPotential_bound f i j simpa only [col, abs_div, abs_of_nonneg (by positivity : (0:ℝ) ≤ 4), div_le_one (by positivity : (0:ℝ) < 4)] using ha have hp (i j : ℕ) : 3 * ((lines f i j : ℝ) + 2 * (squares f i j : ℝ)) ≤ 32 + 4 * row i j - 4 * row i (j+1) + 4 * col i j - 4 * col (i+1) j := by have hi : 3 * (lines f i j + 2 * squares f i j) ≤ 32 + rowPotential f i j - rowPotential f i (j+1) + colPotential f i j - colPotential f (i+1) j := by exact patch f i j have hp' : 3 * ((lines f i j : ℝ) + 2 * (squares f i j : ℝ)) ≤ 32 + (rowPotential f i j : ℝ) - (rowPotential f i (j+1) : ℝ) + (colPotential f i j : ℝ) - (colPotential f (i+1) j : ℝ) := by exact_mod_cast hi dsimp only [row, col] linarith have ha := avg_mono (n := n) (m := n) hp simp only [avg_mul, avg_add, avg_sub, avg_const] at ha have hrow := (abs_le.mp (avg_shift_right (n := n) shift row hr)).1 have hcol := (abs_le.mp (avg_shift_left (m := n) shift col hc)).1 unfold lineMass squareMass linarith private theorem density_bound_of_shift (n : ℕ) {ε : ℝ} (shift : ∀ (g : ℕ → ℝ), (∀ x, |g x| ≤ 1) → |binAvg n (fun k => g (k+1)) - binAvg n g| ≤ ε) (f : Marking) : density n f ≤ 2/3 + ε / 6 + correction n / 2 := by have hm := mass_bound_of_shift n ε shift f have hc := (correction_bounds n).1 have hl := mul_nonneg hc (lineMass_bounds n f).1 have hs := mul_le_mul_of_nonneg_left (squareMass_bounds n f).2 hc unfold density linarith only [hm, hl, hs] /-- A quantitative bound for two coordinate blocks of size `n + 2`. -/ theorem best_finite_upper (n : ℕ) : best n ≤ 2/3 + 1 / (3 * Real.sqrt ((n:ℝ) + 1)) + 1 / (2 * (2 * (n:ℝ) + 3)) := by have hpos : 0 < Real.sqrt ((n:ℝ) + 1) := Real.sqrt_pos.2 (by positivity) have hsq : (Real.sqrt ((n:ℝ) + 1)) ^ 2 = (n:ℝ) + 1 := Real.sq_sqrt (by positivity) have hshift (f : ℕ → ℝ) (hf : ∀ x, |f x| ≤ 1) : |binAvg n (fun k => f (k+1)) - binAvg n f| ≤ 2 / Real.sqrt ((n:ℝ) + 1) := by have h := binAvg_shift_sq_le n f hf rw [← sq_abs] at h have he : (2 / Real.sqrt ((n:ℝ) + 1)) ^ 2 = 4 / ((n:ℝ) + 1) := by rw [div_pow, hsq] norm_num rw [← he] at h nlinarith [abs_nonneg (binAvg n (fun k => f (k+1)) - binAvg n f), (show 0 ≤ 2 / Real.sqrt ((n:ℝ) + 1) by positivity)] have hu : best n ≤ 2/3 + (2 / Real.sqrt ((n:ℝ) + 1)) / 6 + correction n / 2 := ciSup_le fun f => density_bound_of_shift n hshift f unfold correction at hu convert hu using 1 simp only [div_div] ring /-- The optimal fraction of faces with exactly one marked vertex converges to `2/3` for markings determined by the weights in two equal coordinate blocks. -/ theorem best_tendsto : Tendsto best atTop (𝓝 (2 / 3 : ℝ)) := by apply tendsto_order.2 constructor · intro a ha exact Filter.Eventually.of_forall fun n => ha.trans_le (best_ge_two_thirds n) · intro b hb let ε := b - 2/3 have hε : 0 < ε := sub_pos.mpr hb obtain ⟨N, hN⟩ := exists_nat_gt (1 / ε) filter_upwards [binAvg_shift_eventually ε hε, eventually_ge_atTop N] with n hshift hn have hδ : correction n ≤ ε := by unfold correction apply (div_le_iff₀ (by positivity : (0:ℝ) < 2 * (n:ℝ) + 3)).2 have h₁ := (div_lt_iff₀ hε).1 hN have h₂ : (N : ℝ) ≤ 2 * (n:ℝ) + 3 := by have hn' : (N : ℝ) ≤ n := by exact_mod_cast hn linarith [Nat.cast_nonneg (α := ℝ) n] nlinarith [mul_le_mul_of_nonneg_left h₂ hε.le] have hu : best n ≤ 2/3 + ε / 6 + correction n / 2 := ciSup_le fun f => density_bound_of_shift n hshift f dsimp [ε] at * linarith /-- The optimum of the face fraction for two equal coordinate blocks tends to `2/3` as the block size `n + 2` tends to infinity. -/ theorem optimal_face_fraction_tendsto : Tendsto (fun n : ℕ => ⨆ f : Marking, faceFraction n f) atTop (𝓝 (2 / 3 : ℝ)) := by simp only [faceFraction_eq_density] exact best_tendsto end HypercubeTwoBlocks