Lean / Reader
Lean reader

WallisLimit.lean

102 lines6 declarationsno sorryimports WallisBounds WallisAverages WallisTriples

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports WallisBounds, WallisAverages, WallisTriples, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import WallisBounds
  2. import WallisAverages
  3. import WallisTriples
  4. namespace WallisEncoding
  5. open Finset WallisGap Filter
  6. open scoped Topology
  7. noncomputable section
  8. open Classical
  9. def wallis (m : ℕ) : ℝ := ∫ x in 0..Real.pi / 2, Real.sin x ^ (2 * m + 1)
  10. /-- The fixed-point rate among encodings differs from the disjoint triple rate
  11. by at most the probability of coinciding marked positions. -/
  12. theorem encoding_rate {n m : ℕ} (hm : m ≤ n) (hn : 0 < n) (w : ℝ)
  13. (hw₀ : 0 ≤ w) (hw₁ : w ≤ 1)
  14. (hr : ((univ.filter (fun t : Triple n m => DisjointTriple t ∧ MatchingRank t)).card : ℝ) =
  15. ((univ.filter (fun t : Triple n m => DisjointTriple t)).card : ℝ) * w) :
  16. |frequency (univ : Finset (MarkedCode n m)) (fun z => fixed (markedDecode z)) - w|
  17. ≤ ((univ.filter (fun t : Triple n m => ¬DisjointTriple t)).card : ℝ) /
  18. Fintype.card (Triple n m) := by
  19. have liftRat : (((univ : Finset (MarkedCode n m)).filter fun z =>
  20. DisjointTriple (triple z) ∧ MatchingRank (triple z)).card : ℝ) =
  21. (((univ : Finset (MarkedCode n m)).filter fun z => DisjointTriple (triple z)).card : ℝ) * w := by
  22. rw [mark_count_lift (fun t => DisjointTriple t ∧ MatchingRank t), mark_count_lift DisjointTriple,
  23. Nat.cast_mul, Nat.cast_mul, hr]
  24. ring
  25. have h := ratio_from_restriction (univ : Finset (MarkedCode n m))
  26. (fun z => DisjointTriple (triple z)) (fun z => fixed (markedDecode z))
  27. (fun z => MatchingRank (triple z)) (fun z _ => fixed_on_good z) w hw₀ hw₁ (by convert liftRat using 1 <;> congr)
  28. (exists_marked hm hn)
  29. have eqbad : (univ.filter (fun z : MarkedCode n m => ¬DisjointTriple (triple z))).card =
  30. (univ.filter (fun t : Triple n m => ¬DisjointTriple t)).card * Fintype.card (Equiv.Perm (Fin m)) :=
  31. mark_count_lift (fun t => ¬DisjointTriple t)
  32. have h' : |frequency (univ : Finset (MarkedCode n m)) (fun z => fixed (markedDecode z)) - w| ≤ ((univ.filter (fun z : MarkedCode n m => ¬DisjointTriple (triple z))).card : ℝ) /
  33. (Fintype.card (MarkedCode n m)) := by
  34. convert h using 1 <;> congr
  35. rw [eqbad,count_marked,Nat.cast_mul,Nat.cast_mul] at h'
  36. simpa only [mul_div_mul_right _ _ (Nat.cast_ne_zero.mpr (Fintype.card_ne_zero : Fintype.card (Equiv.Perm (Fin m)) ≠ 0) : (_ : ℝ) ≠ 0)] using h'
  37. lemma exists_target_of_sparse {n m k : ℕ} (hm : m ≤ n) (hn : 0 < n) (hk : k < n)
  38. (hs : n * (univ.filter (fun c : Code n m => ¬Separated c.1 c.2.1)).card ≤ k * Fintype.card (Code n m)) :
  39. (target n m).Nonempty := by
  40. obtain ⟨z,_⟩ := exists_marked hm hn
  41. letI : Nonempty (Code n m) := ⟨z.1⟩
  42. have hlt : (univ.filter (fun c : Code n m => ¬Separated c.1 c.2.1)).card < Fintype.card (Code n m) := by
  43. by_contra! h
  44. exact (not_lt_of_ge (hs.trans' (Nat.mul_le_mul_left n h))) (Nat.mul_lt_mul_of_pos_right hk Fintype.card_pos)
  45. have hf : ∃ c : Code n m, Separated c.1 c.2.1 := by
  46. by_contra! h
  47. simp [h] at hlt
  48. obtain ⟨c,hc⟩ := hf
  49. exact ⟨(decode c, z.2), mem_filter.2 ⟨mem_univ _,defect_of_separated c hc⟩⟩
  50. lemma exceptional_fraction {n x k t : ℕ} (hn : 0 < n) (h : n*x ≤ k*t) :
  51. (x : ℝ)/t ≤ (k : ℝ)/n := by
  52. by_cases ht : t = 0
  53. · simp [ht]; positivity
  54. have hp : (0:ℝ) < n := by exact_mod_cast hn
  55. have ht' : (0:ℝ) < t := by exact_mod_cast Nat.pos_of_ne_zero ht
  56. apply (div_le_div_iff₀ ht' hp).2
  57. exact_mod_cast (Nat.mul_comm n x ▸ h)
  58. theorem finite_bound_of_counts {m n k l : ℕ} (hm : m ≤ n) (hn : 0 < n)
  59. (hk : k < n)
  60. (hs : n * (univ.filter (fun c : Code n m => ¬Separated c.1 c.2.1)).card ≤ k * Fintype.card (Code n m))
  61. (hd : n * (univ.filter (fun t : Triple n m => ¬DisjointTriple t)).card ≤ l * Fintype.card (Triple n m))
  62. (w : ℝ) (hw₀ : 0 ≤ w) (hw₁ : w ≤ 1)
  63. (hr : ((univ.filter (fun t : Triple n m => DisjointTriple t ∧ MatchingRank t)).card : ℝ) =
  64. ((univ.filter (fun t : Triple n m => DisjointTriple t)).card : ℝ) * w) :
  65. |expected n m - w| ≤ ((k+l : ℕ) : ℝ)/n := by
  66. have h₁ := (transfer_marked hm (exists_target_of_sparse hm hn hk hs)).trans (exceptional_fraction hn hs)
  67. have h₂ := (encoding_rate hm hn w hw₀ hw₁ hr).trans (exceptional_fraction hn hd)
  68. let enc := frequency (univ : Finset (MarkedCode n m)) (fun z => fixed (markedDecode z))
  69. calc
  70. |expected n m - w| ≤ |expected n m - enc| + |enc - w| := abs_sub_le _ _ _
  71. _ ≤ (k : ℝ)/n + (l : ℝ)/n := add_le_add h₁ h₂
  72. _ = _ := by rw [← add_div,Nat.cast_add]
  73. /-- Erickson's Problem 1.6: the expectation for a uniform permutation with a
  74. longest increasing subsequence of length n-m tends to the odd Wallis integral. -/
  75. theorem erickson_problem_1_6 (m : ℕ) :
  76. Tendsto (fun n => expected n m) atTop (𝓝 (∫ x in 0..Real.pi / 2, Real.sin x ^ (2 * m + 1))) := by
  77. let k := m*m*(2*m+1)
  78. let l := m*m+2*m
  79. apply tendsto_iff_dist_tendsto_zero.2
  80. apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds
  81. (tendsto_const_div_atTop_nhds_zero_nat ((k+l : ℕ) : ℝ))
  82. (Eventually.of_forall (fun _ => dist_nonneg))
  83. filter_upwards [eventually_ge_atTop (k+m+1)] with n hn
  84. have hm : m ≤ n := by omega
  85. have hn' : 0 < n := by omega
  86. have hk : k < n := by omega
  87. have H := finite_bound_of_counts hm hn' hk (bad_separated_bound n m) (bad_triple_bound n m)
  88. (wallisValue m) (wallisValue_bounds m).1 (wallisValue_bounds m).2 (disjointTripleRankCount_real n m)
  89. exact (show dist _ _ ≤ _ from by simpa only [Real.dist_eq] using H)
  90. #print axioms erickson_problem_1_6
  91. end
  92. end WallisEncoding