File size: 6,089 Bytes
e63eb7f | 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | import OAI.Combinatorics.EditApproximation.Probability.ExactSampling
import Mathlib.Probability.Distributions.Geometric
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! A probability law for terminating fair-word rejection executions.
It records the failed trial count and accepted integer, identifies their
joint masses with literal finite fair-word traces, and charges all trials. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
theorem rejectionSuccessParameter_ne_zero (N R : ℕ) (hN : 0 < N) (hNR : N ≤ R) :
rejectionSuccessParameter N R hN hNR ≠ 0 := by
intro h
have heq := congrArg (fun p : unitInterval => (p : ℝ)) h
have hpos : (0 : ℝ) < (N : ℝ) / R :=
div_pos (by exact_mod_cast hN) (by exact_mod_cast hN.trans_le hNR)
change (N : ℝ) / R = 0 at heq
linarith
theorem rejectionSuccessParameter_complement (N R : ℕ) (hN : 0 < N) (hNR : N ≤ R) :
1 - (rejectionSuccessParameter N R hN hNR : ℝ) = ((R - N : ℕ) : ℝ) / R := by
change 1 - (N : ℝ) / R = _
rw [Nat.cast_sub hNR]
have hR : (R : ℝ) ≠ 0 := by exact_mod_cast (hN.trans_le hNR).ne'
field_simp [hR]
noncomputable def rejectionExecutionLaw (N R : ℕ) [NeZero N]
(hN : 0 < N) (hNR : N ≤ R) : Measure (ℕ × Fin N) :=
(geometricMeasure (rejectionSuccessParameter N R hN hNR)).prod
(PMF.uniformOfFintype (Fin N)).toMeasure
instance rejectionExecutionLaw_probability (N R : ℕ) [NeZero N]
(hN : 0 < N) (hNR : N ≤ R) :
IsProbabilityMeasure (rejectionExecutionLaw N R hN hNR) := by
unfold rejectionExecutionLaw
infer_instance
/-- The accepted value has exactly the uniform law, independently of the
number of failed trials. -/
theorem rejectionExecutionLaw_output (N R : ℕ) [NeZero N]
(hN : 0 < N) (hNR : N ≤ R) :
(rejectionExecutionLaw N R hN hNR).map Prod.snd =
(PMF.uniformOfFintype (Fin N)).toMeasure := by
simp [rejectionExecutionLaw]
/-- Each execution atom has the probability of the corresponding literal
finite first-success trace event. -/
theorem rejectionExecutionLaw_atom (N R : ℕ) [NeZero N]
(hN : 0 < N) (hNR : N ≤ R) (failures : ℕ) (accepted : Fin N) :
(rejectionExecutionLaw N R hN hNR).real {(failures, accepted)} =
((R - N : ℕ) : ℝ) ^ failures / ((R : ℝ) ^ failures * R) := by
have hu : ((PMF.uniformOfFintype (Fin N)).toMeasure).real {accepted} = (1 : ℝ) / N := by
rw [measureReal_def, PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton _)]
simp [PMF.uniformOfFintype_apply]
rw [rejectionExecutionLaw, ← Set.singleton_prod_singleton, measureReal_prod_prod,
geometricMeasure_real_singleton (rejectionSuccessParameter_ne_zero N R hN hNR), hu,
rejectionSuccessParameter_complement]
change ((((R - N : ℕ) : ℝ) / R) ^ failures * ((N : ℝ) / R)) * (1 / N) = _
rw [div_pow]
have hn : (N : ℝ) ≠ 0 := by exact_mod_cast hN.ne'
field_simp
theorem rejectionExecutionLaw_literal_trace (N R : ℕ) [NeZero N]
(hN : 0 < N) (hNR : N ≤ R) (failures : ℕ) (accepted : Fin N) :
let : NeZero R := ⟨by omega⟩
(rejectionExecutionLaw N R hN hNR).real {(failures, accepted)} =
((PMF.uniformOfFintype ((Fin failures → Fin R) × Fin R)).toMeasure).real
(firstSuccessEvent N R failures accepted) := by
let : NeZero R := ⟨by omega⟩
dsimp only
rw [rejectionExecutionLaw_atom, firstSuccessEvent_probability N R failures hN hNR accepted]
theorem rejection_trial_moment (N R : ℕ) (hN : 0 < N) (hNR : N ≤ R) :
(∫ failures : ℕ, ((failures : ℝ) + 1)
∂geometricMeasure (rejectionSuccessParameter N R hN hNR)) = (R : ℝ) / N := by
rw [integral_geometricMeasure (rejectionSuccessParameter_ne_zero N R hN hNR)]
have hterm (k : ℕ) :
((1 - (rejectionSuccessParameter N R hN hNR : ℝ)) ^ k *
(rejectionSuccessParameter N R hN hNR : ℝ)) * ((k : ℝ) + 1) =
((k : ℝ) + 1) * N * (((R - N : ℕ) : ℝ) ^ k / ((R : ℝ) ^ k * R)) := by
rw [rejectionSuccessParameter_complement]
change (((R - N : ℕ) : ℝ) / R) ^ k * ((N : ℝ) / R) * ((k : ℝ) + 1) = _
rw [div_pow]
ring
simp_rw [smul_eq_mul, hterm]
exact (rejection_first_success_expected_trials N R hN hNR).tsum_eq
theorem rejection_trials_integrable (N R : ℕ) (hN : 0 < N) (hNR : N ≤ R) :
Integrable (fun failures : ℕ => (failures : ℝ) + 1)
(geometricMeasure (rejectionSuccessParameter N R hN hNR)) := by
apply (integrable_geometricMeasure_iff (rejectionSuccessParameter_ne_zero N R hN hNR)).mpr
have hterm (k : ℕ) :
(1 - (rejectionSuccessParameter N R hN hNR : ℝ)) ^ k *
(rejectionSuccessParameter N R hN hNR : ℝ) * ‖(k : ℝ) + 1‖ =
((k : ℝ) + 1) * N * (((R - N : ℕ) : ℝ) ^ k / ((R : ℝ) ^ k * R)) := by
rw [Real.norm_of_nonneg (by positivity), rejectionSuccessParameter_complement]
change (((R - N : ℕ) : ℝ) / R) ^ k * ((N : ℝ) / R) * ((k : ℝ) + 1) = _
rw [div_pow]
ring
simpa only [hterm] using (rejection_first_success_expected_trials N R hN hNR).summable
/-- All failed trials are included in this strict factor-two bound. -/
theorem rejection_fair_word_trial_moment (N : ℕ) (hN : 0 < N) :
(∫ failures : ℕ, ((failures : ℝ) + 1)
∂geometricMeasure (rejectionSuccessParameter N (2 ^ rejectionBitCount N)
hN (rejectionWord_range N hN).1)) < 2 := by
rw [rejection_trial_moment]
apply (div_lt_iff₀ (by exact_mod_cast hN : (0 : ℝ) < N)).mpr
exact_mod_cast (rejectionWord_range N hN).2
/-- Exact expected number of consumed fair bits, including failed words. -/
theorem rejection_consumed_bits_moment (N : ℕ) (hN : 0 < N) :
(∫ failures : ℕ, (((failures : ℝ) + 1) * rejectionBitCount N)
∂geometricMeasure (rejectionSuccessParameter N (2 ^ rejectionBitCount N)
hN (rejectionWord_range N hN).1)) ≤ 2 * rejectionBitCount N := by
rw [integral_mul_const]
exact mul_le_mul_of_nonneg_right
(rejection_fair_word_trial_moment N hN).le (Nat.cast_nonneg _)
end EditApproximation
end OAI
|