Documentation

Dynamics.Binomial

The binomial law #

Distribution.binomial n p is the law of the number of successes in n independent trials of success probability p: a distribution on {0, …, n} (Fin (n + 1)) with weight C(n, k) p^k (1 - p)^(n - k) at k. Its weights are those of Mathlib's binomial distribution ProbabilityTheory.binomial (Distribution.binomial_weight_eq), and it is the law of the number of heads of independent Bernoulli(p) coins indexed by any finite type with n elements (Distribution.independent_bernoulli_map_countFin, Distribution.independent_bernoulli_map_card), so its mean is n p (Distribution.binomial_expect_val). The number of elements with a property is countFin, an element of {0, …, n}.

Two facts used on the way are stated in general: the indicator of an event is a Bernoulli coin with the probability of the event (Distribution.map_decide_eq_bernoulli), and an independent product transported coordinatewise is the independent product of the transported coordinates (Distribution.independent_map_pi).

def Dynamics.countFin {ι : Type u_1} [Fintype ι] (P : ι → Prop) [DecidablePred P] :

The number of elements of a finite type ι with the property P, as an element of {0, …, |ι|}.

Equations
Instances For
    @[simp]
    theorem Dynamics.countFin_val {ι : Type u_1} [Fintype ι] (P : ι → Prop) [DecidablePred P] :
    noncomputable def Dynamics.Distribution.binomial (n : ℕ) (p : ℝ) (h0 : 0 ≤ p) (h1 : p ≤ 1) :

    The binomial law Bin(n, p) on {0, …, n}: weight C(n, k) p^k (1 - p)^(n - k) at k, the law of the number of successes in n independent trials of success probability p.

    Equations
    Instances For
      theorem Dynamics.Distribution.binomial_weight_eq (n : ℕ) (p : ℝ) (h0 : 0 ≤ p) (h1 : p ≤ 1) (k : Fin (n + 1)) :

      The weights of binomial n p are those of Mathlib's binomial distribution Bin(n, p) on ℕ (ProbabilityTheory.binomial, with p in the unit interval).

      theorem Dynamics.Distribution.map_decide_eq_bernoulli {α : Type u_2} [Fintype α] (p : Distribution α) (P : α → Prop) [DecidablePred P] :
      (p.map fun (a : α) => decide (P a)) = bernoulli (p.prob P) ⋯ ⋯

      The indicator of an event P is a Bernoulli coin with the probability of P.

      theorem Dynamics.Distribution.independent_map_pi {ι : Type u_1} {α : Type u_2} {β : Type u_3} [Fintype ι] [Fintype α] [Fintype β] [DecidableEq ι] (q : ι → Distribution α) (f : ι → α → β) :
      ((independent q).map fun (x : ι → α) (i : ι) => f i (x i)) = independent fun (i : ι) => (q i).map (f i)

      An independent product transported coordinatewise, by f i on coordinate i, is the independent product of the transported coordinates.

      theorem Dynamics.Distribution.card_countFin_eq {ι : Type u_1} [Fintype ι] [DecidableEq ι] (k : Fin (Fintype.card ι + 1)) :
      {ω : ι → Bool | (countFin fun (i : ι) => ω i = true) = k}.card = (Fintype.card ι).choose ↑k

      Exactly C(|ι|, k) maps ι → Bool take the value true k times.

      theorem Dynamics.Distribution.independent_bernoulli_map_countFin {ι : Type u_1} [Fintype ι] [DecidableEq ι] (p : ℝ) (h0 : 0 ≤ p) (h1 : p ≤ 1) :
      ((independent fun (x : ι) => bernoulli p h0 h1).map fun (ω : ι → Bool) => countFin fun (i : ι) => ω i = true) = binomial (Fintype.card ι) p h0 h1

      The number of heads is binomial. The number of heads of independent Bernoulli(p) coins indexed by a finite type ι has the binomial law Bin(|ι|, p).

      theorem Dynamics.Distribution.independent_bernoulli_map_card {ι : Type u_1} [Fintype ι] [DecidableEq ι] {m : ℕ} (hm : Fintype.card ι = m) (p : ℝ) (h0 : 0 ≤ p) (h1 : p ≤ 1) :
      ((independent fun (x : ι) => bernoulli p h0 h1).map fun (ω : ι → Bool) => Fin.cast ⋯ (countFin fun (i : ι) => ω i = true)) = binomial m p h0 h1

      independent_bernoulli_map_countFin for a finite type with m elements, the number of heads counted in {0, …, m}.

      theorem Dynamics.Distribution.binomial_expect_val (n : ℕ) (p : ℝ) (h0 : 0 ≤ p) (h1 : p ≤ 1) :
      ((binomial n p h0 h1).expect fun (k : Fin (n + 1)) => ↑↑k) = ↑n * p

      The mean of the binomial law: 𝔼[Bin(n, p)] = n p, the expected number of heads of n independent coins.