File size: 3,931 Bytes
cdec422
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ExactStatisticWords
import OAI.LinearAlgebra.MatrixMultiplication.Entropy.ComplexTypeEntropy

namespace OAI

/-! Finite entropy, rate estimates and ordered asymptotic limits. -/

noncomputable section

namespace MatrixMultiplication.LeafRates

open MatrixMultiplication.Foundation Filter
open scoped BigOperators Topology

variable {A U : Type*} [Fintype A] [DecidableEq A] [Fintype U]

theorem log_card_supported (statistic : U → A) (counts b : A → ℕ)
    (hb : ∀ a, 0 < counts a → Fintype.card {u : U // statistic u = a} = b a)
    (hbpos : ∀ a, 0 < b a) :
    Real.log (Fintype.card (ExactStatisticWords.Words statistic counts) : ℝ) =
      Real.log (Nat.multinomial Finset.univ counts : ℝ) +
        ∑ a, (counts a : ℝ) * Real.log (b a : ℝ) := by
  rw [ExactStatisticWords.card_of_supported statistic counts b hb, Nat.cast_mul, Nat.cast_prod]
  have hm : (Nat.multinomial Finset.univ counts : ℝ) ≠ 0 := by
    exact_mod_cast (Nat.ne_of_gt (Nat.multinomial_pos Finset.univ counts))
  have hp : (∏ a, (b a ^ counts a : ℕ) : ℝ) ≠ 0 := by
    apply Finset.prod_ne_zero_iff.mpr
    intro a _
    exact_mod_cast (Nat.ne_of_gt (pow_pos (hbpos a) _))
  rw [Real.log_mul hm hp, Real.log_prod (s := Finset.univ)
    (f := fun a => ((b a ^ counts a : ℕ) : ℝ))
    (fun a _ => by exact_mod_cast (Nat.ne_of_gt (pow_pos (hbpos a) (counts a))))]
  simp only [Nat.cast_pow, Real.log_pow]

theorem log_card (statistic : U → A) (counts b : A → ℕ)
    (hb : ∀ a, Fintype.card {u : U // statistic u = a} = b a)
    (hbpos : ∀ a, 0 < b a) :
    Real.log (Fintype.card (ExactStatisticWords.Words statistic counts) : ℝ) =
      Real.log (Nat.multinomial Finset.univ counts : ℝ) +
        ∑ a, (counts a : ℝ) * Real.log (b a : ℝ) :=
  log_card_supported statistic counts b (fun a _ => hb a) hbpos

theorem tendsto_log_card_supported (statistic : U → A) (counts b : A → ℕ)
    (hb : ∀ a, 0 < counts a → Fintype.card {u : U // statistic u = a} = b a)
    (hbpos : ∀ a, 0 < b a) (hD : 0 < ∑ a, counts a) :
    Tendsto (fun t : ℕ =>
      Real.log (Fintype.card (ExactStatisticWords.Words statistic (fun a => t * counts a)) : ℝ) /
        ((t : ℝ) * (∑ a, counts a : ℕ))) atTop
      (𝓝 (finiteEntropy (fun a => (counts a : ℝ) / (∑ a, counts a : ℕ)) +
        ∑ a, ((counts a : ℝ) / (∑ a, counts a : ℕ)) * Real.log (b a : ℝ))) := by
  have hl := (tendsto_log_multinomial_mul counts hD).add_const
    (∑ a, ((counts a : ℝ) / (∑ a, counts a : ℕ)) * Real.log (b a : ℝ))
  apply hl.congr'
  filter_upwards [eventually_ne_atTop (0 : ℕ)] with t ht
  have hbt : ∀ a, 0 < t * counts a → Fintype.card {u : U // statistic u = a} = b a :=
    fun a ha => hb a (by nlinarith)
  rw [log_card_supported statistic (fun a => t * counts a) b hbt hbpos, add_div]
  congr 1
  rw [Finset.sum_div]
  apply Finset.sum_congr rfl
  intro a _
  have ht' : (t : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr ht
  have hD' : ((∑ a, counts a : ℕ) : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hD)
  have hDsum : (∑ a, (counts a : ℝ)) ≠ 0 := by
    simpa only [Nat.cast_sum] using hD'
  simp only [Nat.cast_mul]
  field_simp [ht', hD', hDsum]

theorem tendsto_log_card (statistic : U → A) (counts b : A → ℕ)
    (hb : ∀ a, Fintype.card {u : U // statistic u = a} = b a)
    (hbpos : ∀ a, 0 < b a) (hD : 0 < ∑ a, counts a) :
    Tendsto (fun t : ℕ =>
      Real.log (Fintype.card (ExactStatisticWords.Words statistic (fun a => t * counts a)) : ℝ) /
        ((t : ℝ) * (∑ a, counts a : ℕ))) atTop
      (𝓝 (finiteEntropy (fun a => (counts a : ℝ) / (∑ a, counts a : ℕ)) +
        ∑ a, ((counts a : ℝ) / (∑ a, counts a : ℕ)) * Real.log (b a : ℝ))) :=
  tendsto_log_card_supported statistic counts b (fun a _ => hb a) hbpos hD

end MatrixMultiplication.LeafRates

end

end OAI