roseking's picture
Add lean source and binary files (part 19)
9eeb9c7 verified
Raw History Blame Contribute Delete
4.95 kB
13
lemma baseLaw_bin {r : ℕ} [NeZero r] (d : Fin r) :
    baseLaw (bin r d) = (r : ℝ≥0∞)⁻¹ := by
proof · 6 lines
  have hr : (0 : ℝ) < r := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne r)
  rw [baseLaw_eq_restrict, Measure.restrict_apply (show MeasurableSet (bin r d) from measurableSet_Ico),
    inter_eq_left.mpr (bin_subset_unit d)]
  rw [bin, Real.volume_Ico, bin_length]
  rw [ENNReal.ofReal_div_of_pos hr]
  simp
22
lemma labelsGivenDigit_singleton (side : Bool) (r : ℕ) (κ m a b t : ℝ)
    (d : Fin r) (l : Label) :
    labelsGivenDigit side r κ m a b t d {l} =
      digitWeight side r κ m a b t l d / ∑ k, digitWeight side r κ m a b t k d := by
proof · 3 lines
  classical
  cases l <;> simp [labelsGivenDigit, FiniteKernelMixture.normalizedKernel_apply,
    Kernel.const_apply, Pi.single_apply]
37
lemma endpointLaw_isProbabilityMeasure (side : Bool) (l : Label) :
    IsProbabilityMeasure (endpointLaw side m a b l) := by
proof · 9 lines
  have hm0 : 0 < m := by linarith
  have ha0 := width_pos hm0 ha
  have hb0 := width_pos hm0 hb
  cases l with
  | none => exact baseLaw_isProbabilityMeasure
  | some i =>
    cases side
    · exact leftLaw_isProbabilityMeasure (by linarith) ha0 ha' hb0 hb' i
    · exact rightLaw_isProbabilityMeasure (by linarith) ha0 ha' hb0 hb' i
50
lemma labelMass_sum : (∑ l, labelMass κ m a b t l) = 1 := by
proof · 16 lines
  have hm0 : 0 < m := by linarith
  have hq0 : 0 ≤ diagonalMass κ m a b t :=
    le_trans (by norm_num) (diagonalMass_bounds hκ0 hκ hm ha ha' hb hb' ht0 ht).1
  have hp0 := componentProbabilities_nonneg (a := a) (b := b) hκ0 hm0 ht0
  rw [Fintype.sum_option]
  change ENNReal.ofReal (diagonalMass κ m a b t) +
    ∑ i, ENNReal.ofReal (componentProbabilities κ m a b t i) = 1
  rw [← ENNReal.ofReal_sum_of_nonneg (fun i _ => hp0 i),
    ← ENNReal.ofReal_add hq0 (Finset.sum_nonneg (fun i _ => hp0 i))]
  have heq : diagonalMass κ m a b t + ∑ i, componentProbabilities κ m a b t i = 1 := by
    simp only [componentProbabilities, Fin.sum_univ_succ, Matrix.cons_val_zero,
      Matrix.cons_val_succ, Fin.sum_univ_zero, add_zero]
    unfold diagonalMass
    ring
  rw [heq]
  norm_num
69
lemma rawLaw_isProbabilityMeasure : IsProbabilityMeasure (rawLaw κ m a b t) := by
proof · 10 lines
  have hm0 : 0 < m := by linarith
  have ha0 := width_pos hm0 ha
  have hb0 := width_pos hm0 hb
  have : ∀ i, IsProbabilityMeasure (leftLaw (2 * m) a b i) :=
    leftLaw_isProbabilityMeasure (by linarith) ha0 ha' hb0 hb'
  have : ∀ i, IsProbabilityMeasure (rightLaw (2 * m) a b i) :=
    rightLaw_isProbabilityMeasure (by linarith) ha0 ha' hb0 hb'
  apply labelledMixture_isProbabilityMeasure
  have h := labelMass_sum hκ0 hκ hm ha ha' hb hb' ht0 ht
  simpa only [Fintype.sum_option, labelMass] using h
82
lemma digitWeight_total_ne_zero (side : Bool) (r : ℕ) [NeZero r] (d : Fin r) :
    (∑ l, digitWeight side r κ m a b t l d) ≠ 0 := by
proof · 10 lines
  have hq : 0 < diagonalMass κ m a b t := by
    have := (diagonalMass_bounds hκ0 hκ hm ha ha' hb hb' ht0 ht).1
    linarith
  have hpos : digitWeight side r κ m a b t none d ≠ 0 := by
    simp only [digitWeight, labelMass, endpointLaw, baseLaw_bin]
    exact mul_ne_zero (ENNReal.ofReal_ne_zero_iff.mpr hq)
      (ENNReal.inv_ne_zero.mpr (by simp))
  intro h
  apply hpos
  exact (Finset.sum_eq_zero_iff.mp h) none (Finset.mem_univ none)
96
lemma digitWeight_total_ne_top (side : Bool) (r : ℕ) (d : Fin r) :
    (∑ l, digitWeight side r κ m a b t l d) ≠ ∞ := by
proof · 7 lines
  have : ∀ l, IsProbabilityMeasure (endpointLaw side m a b l) :=
    endpointLaw_isProbabilityMeasure hm ha ha' hb hb' side
  apply ENNReal.sum_ne_top.mpr
  intro l _
  apply ENNReal.mul_ne_top
  · cases l <;> exact ENNReal.ofReal_ne_top
  · exact measure_ne_top _ _
107
lemma labelsGivenDigit_isMarkov (side : Bool) (r : ℕ) [NeZero r] :
    IsMarkovKernel (labelsGivenDigit side r κ m a b t) := by
proof · 3 lines
  apply FiniteKernelMixture.normalizedKernel_isMarkov
  · exact digitWeight_total_ne_zero hκ0 hκ hm ha ha' hb hb' ht0 ht side r
  · exact digitWeight_total_ne_top hm ha ha' hb hb' side r