l3lab/ntp-mathlib huggingface dataset:
/-- Adding a point to a collinear set produces a coplanar set. -/
theorem Collinear.coplanar_insert {s : Set P} (h : Collinear k s) (p : P) :
    Coplanar k (insert p s) := by
  have : FiniteDimensional k { x // x ∈ vectorSpan k s } := h.finiteDimensional_vectorSpan
  rw [coplanar_iff_finrank_le_two]
  

Proof state:
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
s : Set P
h : Collinear k s
p : P
this : FiniteDimensional k ↥(vectorSpan k s)
⊢ finrank k ↥(vectorSpan k (insert p s)) ≤ 2

Next tactic:
exact (finrank_vectorSpan_insert_le_set k s p).trans (add_le_add_right h.finrank_le_one _)
/-- A set of points in a two-dimensional space is coplanar. -/
theorem coplanar_of_finrank_eq_two (s : Set P) (h : finrank k V = 2) : Coplanar k s := by
  

Proof state:
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
s : Set P
h : finrank k V = 2
⊢ Coplanar k s

Next tactic:
have : FiniteDimensional k V := finiteDimensional_of_finrank_eq_succ h
/-- A set of points in a two-dimensional space is coplanar. -/
theorem coplanar_of_finrank_eq_two (s : Set P) (h : finrank k V = 2) : Coplanar k s := by
  have : FiniteDimensional k V := finiteDimensional_of_finrank_eq_succ h
  

Proof state:
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
s : Set P
h : finrank k V = 2
this : FiniteDimensional k V
⊢ Coplanar k s

Next tactic:
rw [coplanar_iff_finrank_le_two, ← h]
/-- A set of points in a two-dimensional space is coplanar. -/
theorem coplanar_of_finrank_eq_two (s : Set P) (h : finrank k V = 2) : Coplanar k s := by
  have : FiniteDimensional k V := finiteDimensional_of_finrank_eq_succ h
  rw [coplanar_iff_finrank_le_two, ← h]
  

Proof state:
k : Type u_1
V : Type u_2
P : Type u_3
inst✝³ : DivisionRing k
inst✝² : AddCommGroup V
inst✝¹ : Module k V
inst✝ : AffineSpace V P
s : Set P
h : finrank k V = 2
this : FiniteDimensional k V
⊢ finrank k ↥(vectorSpan k s) ≤ finrank k V

Next tactic:
exact Submodule.finrank_le _
theorem exists_affineBasis_of_finiteDimensional [Fintype ι] [FiniteDimensional k V]
    (h : Fintype.card ι = FiniteDimensional.finrank k V + 1) : Nonempty (AffineBasis ι k P) := by
  

Proof state:
ι : Type u₁
k : Type u₂
V : Type u₃
P : Type u₄
inst✝⁵ : AddCommGroup V
inst✝⁴ : AffineSpace V P
inst✝³ : DivisionRing k
inst✝² : Module k V
inst✝¹ : Fintype ι
inst✝ : FiniteDimensional k V
h : Fintype.card ι = FiniteDimensional.finrank k V + 1
⊢ Nonempty (AffineBasis ι k P)

Next tactic:
obtain ⟨s, b, hb⟩ := AffineBasis.exists_affineBasis k V P
theorem exists_affineBasis_of_finiteDimensional [Fintype ι] [FiniteDimensional k V]
    (h : Fintype.card ι = FiniteDimensional.finrank k V + 1) : Nonempty (AffineBasis ι k P) := by
  obtain ⟨s, b, hb⟩ := AffineBasis.exists_affineBasis k V P
  

Proof state:
case intro.intro
ι : Type u₁
k : Type u₂
V : Type u₃
P : Type u₄
inst✝⁵ : AddCommGroup V
inst✝⁴ : AffineSpace V P
inst✝³ : DivisionRing k
inst✝² : Module k V
inst✝¹ : Fintype ι
inst✝ : FiniteDimensional k V
h : Fintype.card ι = FiniteDimensional.finrank k V + 1
s : Set P
b : AffineBasis (↑s) k P
hb : ⇑b = Subtype.val
⊢ Nonempty (AffineBasis ι k P)

Next tactic:
lift s to Finset P using b.finite_set
theorem exists_affineBasis_of_finiteDimensional [Fintype ι] [FiniteDimensional k V]
    (h : Fintype.card ι = FiniteDimensional.finrank k V + 1) : Nonempty (AffineBasis ι k P) := by
  obtain ⟨s, b, hb⟩ := AffineBasis.exists_affineBasis k V P
  lift s to Finset P using b.finite_set
  

Proof state:
case intro.intro.intro
ι : Type u₁
k : Type u₂
V : Type u₃
P : Type u₄
inst✝⁵ : AddCommGroup V
inst✝⁴ : AffineSpace V P
inst✝³ : DivisionRing k
inst✝² : Module k V
inst✝¹ : Fintype ι
inst✝ : FiniteDimensional k V
h : Fintype.card ι = FiniteDimensional.finrank k V + 1
s : Finset P
b : AffineBasis (↑↑s) k P
hb : ⇑b = Subtype.val
⊢ Nonempty (AffineBasis ι k P)

Next tactic:
refine' ⟨b.reindex <| Fintype.equivOfCardEq _⟩
theorem exists_affineBasis_of_finiteDimensional [Fintype ι] [FiniteDimensional k V]
    (h : Fintype.card ι = FiniteDimensional.finrank k V + 1) : Nonempty (AffineBasis ι k P) := by
  obtain ⟨s, b, hb⟩ := AffineBasis.exists_affineBasis k V P
  lift s to Finset P using b.finite_set
  refine' ⟨b.reindex <| Fintype.equivOfCardEq _⟩
  

Proof state:
case intro.intro.intro
ι : Type u₁
k : Type u₂
V : Type u₃
P : Type u₄
inst✝⁵ : AddCommGroup V
inst✝⁴ : AffineSpace V P
inst✝³ : DivisionRing k
inst✝² : Module k V
inst✝¹ : Fintype ι
inst✝ : FiniteDimensional k V
h : Fintype.card ι = FiniteDimensional.finrank k V + 1
s : Finset P
b : AffineBasis (↑↑s) k P
hb : ⇑b = Subtype.val
⊢ Fintype.card ↑↑s = Fintype.card ι

Next tactic:
rw [h, ← b.card_eq_finrank_add_one]
/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/
def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
⊢ PMF α

Next tactic:
refine' ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s _ _
/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/
def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by
  refine' ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s _ _
  · 

Proof state:
case refine'_1
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
⊢ ∑ a in s, (fun a => if a ∈ s then (↑(Finset.card s))⁻¹ else 0) a = 1

Next tactic:
simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul]
/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/
def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by
  refine' ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s _ _
  · simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul]
    

Proof state:
case refine'_1
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
⊢ ↑(Finset.card s) * (↑(Finset.card s))⁻¹ = 1

Next tactic:
have : (s.card : ℝ≥0∞) ≠ 0 := by
      simpa only [Ne.def, Nat.cast_eq_zero, Finset.card_eq_zero] using
        Finset.nonempty_iff_ne_empty.1 hs
/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/
def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by
  refine' ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s _ _
  · simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul]
    have : (s.card : ℝ≥0∞) ≠ 0 := by
      

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
⊢ ↑(Finset.card s) ≠ 0

Next tactic:
simpa only [Ne.def, Nat.cast_eq_zero, Finset.card_eq_zero] using
        Finset.nonempty_iff_ne_empty.1 hs
/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/
def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by
  refine' ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s _ _
  · simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul]
    have : (s.card : ℝ≥0∞) ≠ 0 := by
      simpa only [Ne.def, Nat.cast_eq_zero, Finset.card_eq_zero] using
        Finset.nonempty_iff_ne_empty.1 hs
    

Proof state:
case refine'_1
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
this : ↑(Finset.card s) ≠ 0
⊢ ↑(Finset.card s) * (↑(Finset.card s))⁻¹ = 1

Next tactic:
refine' ENNReal.mul_inv_cancel this <| ENNReal.nat_ne_top s.card
/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/
def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by
  refine' ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s _ _
  · simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul]
    have : (s.card : ℝ≥0∞) ≠ 0 := by
      simpa only [Ne.def, Nat.cast_eq_zero, Finset.card_eq_zero] using
        Finset.nonempty_iff_ne_empty.1 hs
    refine' ENNReal.mul_inv_cancel this <| ENNReal.nat_ne_top s.card
  · 

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
⊢ ∀ a ∉ s, (fun a => if a ∈ s then (↑(Finset.card s))⁻¹ else 0) a = 0

Next tactic:
exact fun x hx => by simp only [hx, if_false]
/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/
def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by
  refine' ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s _ _
  · simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul]
    have : (s.card : ℝ≥0∞) ≠ 0 := by
      simpa only [Ne.def, Nat.cast_eq_zero, Finset.card_eq_zero] using
        Finset.nonempty_iff_ne_empty.1 hs
    refine' ENNReal.mul_inv_cancel this <| ENNReal.nat_ne_top s.card
  · exact fun x hx => by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
x : α
hx : x ∉ s
⊢ (fun a => if a ∈ s then (↑(Finset.card s))⁻¹ else 0) x = 0

Next tactic:
simp only [hx, if_false]
theorem uniformOfFinset_apply_of_mem (ha : a ∈ s) : uniformOfFinset s hs a = (s.card : ℝ≥0∞)⁻¹ := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a : α
ha : a ∈ s
⊢ (uniformOfFinset s hs) a = (↑(Finset.card s))⁻¹

Next tactic:
simp [ha]
theorem uniformOfFinset_apply_of_not_mem (ha : a ∉ s) : uniformOfFinset s hs a = 0 := by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a : α
ha : a ∉ s
⊢ (uniformOfFinset s hs) a = 0

Next tactic:
simp [ha]
@[simp]
theorem support_uniformOfFinset : (uniformOfFinset s hs).support = s :=
  Set.ext
    (by
      

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a : α
⊢ ∀ (x : α), x ∈ support (uniformOfFinset s hs) ↔ x ∈ ↑s

Next tactic:
let ⟨a, ha⟩ := hs
@[simp]
theorem support_uniformOfFinset : (uniformOfFinset s hs).support = s :=
  Set.ext
    (by
      let ⟨a, ha⟩ := hs
      

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a✝ a : α
ha : a ∈ s
⊢ ∀ (x : α), x ∈ support (uniformOfFinset s (_ : ∃ x, x ∈ s)) ↔ x ∈ ↑s

Next tactic:
simp [mem_support_iff, Finset.ne_empty_of_mem ha]
theorem mem_support_uniformOfFinset_iff (a : α) : a ∈ (uniformOfFinset s hs).support ↔ a ∈ s := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a✝ a : α
⊢ a ∈ support (uniformOfFinset s hs) ↔ a ∈ s

Next tactic:
simp
@[simp]
theorem toOuterMeasure_uniformOfFinset_apply :
    (uniformOfFinset s hs).toOuterMeasure t = (s.filter (· ∈ t)).card / s.card :=
  calc
    (uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 :=
      toOuterMeasure_apply (uniformOfFinset s hs) t
    _ = ∑' x, if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 :=
      (tsum_congr fun x => by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a : α
t : Set α
x : α
⊢ (if x ∈ t then (uniformOfFinset s hs) x else 0) = if x ∈ s ∧ x ∈ t then (↑(Finset.card s))⁻¹ else 0

Next tactic:
simp_rw [uniformOfFinset_apply, ← ite_and, and_comm]
@[simp]
theorem toOuterMeasure_uniformOfFinset_apply :
    (uniformOfFinset s hs).toOuterMeasure t = (s.filter (· ∈ t)).card / s.card :=
  calc
    (uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 :=
      toOuterMeasure_apply (uniformOfFinset s hs) t
    _ = ∑' x, if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 :=
      (tsum_congr fun x => by simp_rw [uniformOfFinset_apply, ← ite_and, and_comm])
    _ = ∑ x in s.filter (· ∈ t), if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 :=
      (tsum_eq_sum fun x hx => if_neg fun h => hx (Finset.mem_filter.2 h))
    _ = ∑ _x in s.filter (· ∈ t), (s.card : ℝ≥0∞)⁻¹ :=
      (Finset.sum_congr rfl fun x hx => by
        

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a : α
t : Set α
x : α
hx : x ∈ Finset.filter (fun x => x ∈ t) s
⊢ (if x ∈ s ∧ x ∈ t then (↑(Finset.card s))⁻¹ else 0) = (↑(Finset.card s))⁻¹

Next tactic:
let this : x ∈ s ∧ x ∈ t := by simpa using hx
@[simp]
theorem toOuterMeasure_uniformOfFinset_apply :
    (uniformOfFinset s hs).toOuterMeasure t = (s.filter (· ∈ t)).card / s.card :=
  calc
    (uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 :=
      toOuterMeasure_apply (uniformOfFinset s hs) t
    _ = ∑' x, if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 :=
      (tsum_congr fun x => by simp_rw [uniformOfFinset_apply, ← ite_and, and_comm])
    _ = ∑ x in s.filter (· ∈ t), if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 :=
      (tsum_eq_sum fun x hx => if_neg fun h => hx (Finset.mem_filter.2 h))
    _ = ∑ _x in s.filter (· ∈ t), (s.card : ℝ≥0∞)⁻¹ :=
      (Finset.sum_congr rfl fun x hx => by
        let this : x ∈ s ∧ x ∈ t := by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a : α
t : Set α
x : α
hx : x ∈ Finset.filter (fun x => x ∈ t) s
⊢ x ∈ s ∧ x ∈ t

Next tactic:
simpa using hx
@[simp]
theorem toOuterMeasure_uniformOfFinset_apply :
    (uniformOfFinset s hs).toOuterMeasure t = (s.filter (· ∈ t)).card / s.card :=
  calc
    (uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 :=
      toOuterMeasure_apply (uniformOfFinset s hs) t
    _ = ∑' x, if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 :=
      (tsum_congr fun x => by simp_rw [uniformOfFinset_apply, ← ite_and, and_comm])
    _ = ∑ x in s.filter (· ∈ t), if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 :=
      (tsum_eq_sum fun x hx => if_neg fun h => hx (Finset.mem_filter.2 h))
    _ = ∑ _x in s.filter (· ∈ t), (s.card : ℝ≥0∞)⁻¹ :=
      (Finset.sum_congr rfl fun x hx => by
        let this : x ∈ s ∧ x ∈ t := by simpa using hx
        

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a : α
t : Set α
x : α
hx : x ∈ Finset.filter (fun x => x ∈ t) s
this : x ∈ s ∧ x ∈ t := Eq.mp Mathlib.Data.Finset.Basic._auxLemma.140 hx
⊢ (if x ∈ s ∧ x ∈ t then (↑(Finset.card s))⁻¹ else 0) = (↑(Finset.card s))⁻¹

Next tactic:
simp only [this, and_self_iff, if_true]
@[simp]
theorem toOuterMeasure_uniformOfFinset_apply :
    (uniformOfFinset s hs).toOuterMeasure t = (s.filter (· ∈ t)).card / s.card :=
  calc
    (uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 :=
      toOuterMeasure_apply (uniformOfFinset s hs) t
    _ = ∑' x, if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 :=
      (tsum_congr fun x => by simp_rw [uniformOfFinset_apply, ← ite_and, and_comm])
    _ = ∑ x in s.filter (· ∈ t), if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 :=
      (tsum_eq_sum fun x hx => if_neg fun h => hx (Finset.mem_filter.2 h))
    _ = ∑ _x in s.filter (· ∈ t), (s.card : ℝ≥0∞)⁻¹ :=
      (Finset.sum_congr rfl fun x hx => by
        let this : x ∈ s ∧ x ∈ t := by simpa using hx
        simp only [this, and_self_iff, if_true])
    _ = (s.filter (· ∈ t)).card / s.card := by
        

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Finset α
hs : Finset.Nonempty s
a : α
t : Set α
⊢ ∑ _x in Finset.filter (fun x => x ∈ t) s, (↑(Finset.card s))⁻¹ =
    ↑(Finset.card (Finset.filter (fun x => x ∈ t) s)) / ↑(Finset.card s)

Next tactic:
simp only [div_eq_mul_inv, Finset.sum_const, nsmul_eq_mul]
@[simp]
theorem uniformOfFintype_apply (a : α) : uniformOfFintype α a = (Fintype.card α : ℝ≥0∞)⁻¹ := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Fintype α
inst✝ : Nonempty α
a : α
⊢ (uniformOfFintype α) a = (↑(Fintype.card α))⁻¹

Next tactic:
simp [uniformOfFintype, Finset.mem_univ, if_true, uniformOfFinset_apply]
@[simp]
theorem uniformOfFintype_apply (a : α) : uniformOfFintype α a = (Fintype.card α : ℝ≥0∞)⁻¹ := by
  simp [uniformOfFintype, Finset.mem_univ, if_true, uniformOfFinset_apply]
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Fintype α
inst✝ : Nonempty α
a : α
⊢ Finset.card Finset.univ = Fintype.card α

Next tactic:
rfl
@[simp]
theorem support_uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] :
    (uniformOfFintype α).support = ⊤ :=
  Set.ext fun x => by 

Proof state:
α✝ : Type u_1
β : Type u_2
γ : Type u_3
inst✝³ : Fintype α✝
inst✝² : Nonempty α✝
α : Type u_4
inst✝¹ : Fintype α
inst✝ : Nonempty α
x : α
⊢ x ∈ support (uniformOfFintype α) ↔ x ∈ ⊤

Next tactic:
simp [mem_support_iff]
theorem mem_support_uniformOfFintype (a : α) : a ∈ (uniformOfFintype α).support := by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Fintype α
inst✝ : Nonempty α
a : α
⊢ a ∈ support (uniformOfFintype α)

Next tactic:
simp
theorem toOuterMeasure_uniformOfFintype_apply :
    (uniformOfFintype α).toOuterMeasure s = Fintype.card s / Fintype.card α := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Fintype α
inst✝ : Nonempty α
s : Set α
⊢ ↑(toOuterMeasure (uniformOfFintype α)) s = ↑(Fintype.card ↑s) / ↑(Fintype.card α)

Next tactic:
rw [uniformOfFintype, toOuterMeasure_uniformOfFinset_apply,Fintype.card_ofFinset]
theorem toOuterMeasure_uniformOfFintype_apply :
    (uniformOfFintype α).toOuterMeasure s = Fintype.card s / Fintype.card α := by
  rw [uniformOfFintype, toOuterMeasure_uniformOfFinset_apply,Fintype.card_ofFinset]
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝¹ : Fintype α
inst✝ : Nonempty α
s : Set α
⊢ ↑(Finset.card (Finset.filter (fun x => x ∈ s) Finset.univ)) / ↑(Finset.card Finset.univ) =
    ↑(Finset.card (Finset.filter (fun x => x ∈ s) Finset.univ)) / ↑(Fintype.card α)

Next tactic:
rfl
theorem toMeasure_uniformOfFintype_apply [MeasurableSpace α] (hs : MeasurableSet s) :
    (uniformOfFintype α).toMeasure s = Fintype.card s / Fintype.card α := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝² : Fintype α
inst✝¹ : Nonempty α
s : Set α
inst✝ : MeasurableSpace α
hs : MeasurableSet s
⊢ ↑↑(toMeasure (uniformOfFintype α)) s = ↑(Fintype.card ↑s) / ↑(Fintype.card α)

Next tactic:
simp [uniformOfFintype, hs]
theorem toMeasure_uniformOfFintype_apply [MeasurableSpace α] (hs : MeasurableSet s) :
    (uniformOfFintype α).toMeasure s = Fintype.card s / Fintype.card α := by
  simp [uniformOfFintype, hs]
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
inst✝² : Fintype α
inst✝¹ : Nonempty α
s : Set α
inst✝ : MeasurableSpace α
hs : MeasurableSet s
⊢ ↑(Finset.card (Finset.filter (fun x => x ∈ s) Finset.univ)) / ↑(Finset.card Finset.univ) =
    ↑(Finset.card (Finset.filter (fun x => x ∈ s) Finset.univ)) / ↑(Fintype.card α)

Next tactic:
rfl
/-- Given a non-empty multiset `s` we construct the `PMF` which sends `a` to the fraction of
  elements in `s` that are `a`. -/
def ofMultiset (s : Multiset α) (hs : s ≠ 0) : PMF α :=
  ⟨fun a => s.count a / (Multiset.card s),
    ENNReal.summable.hasSum_iff.2
      (calc
        (∑' b : α, (s.count b : ℝ≥0∞) / (Multiset.card s))
          = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑' b, (s.count b : ℝ≥0∞) := by
            

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Multiset α
hs : s ≠ 0
⊢ ∑' (b : α), ↑(Multiset.count b s) / ↑(Multiset.card s) = (↑(Multiset.card s))⁻¹ * ∑' (b : α), ↑(Multiset.count b s)

Next tactic:
simp_rw [ENNReal.div_eq_inv_mul, ENNReal.tsum_mul_left]
/-- Given a non-empty multiset `s` we construct the `PMF` which sends `a` to the fraction of
  elements in `s` that are `a`. -/
def ofMultiset (s : Multiset α) (hs : s ≠ 0) : PMF α :=
  ⟨fun a => s.count a / (Multiset.card s),
    ENNReal.summable.hasSum_iff.2
      (calc
        (∑' b : α, (s.count b : ℝ≥0∞) / (Multiset.card s))
          = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑' b, (s.count b : ℝ≥0∞) := by
            simp_rw [ENNReal.div_eq_inv_mul, ENNReal.tsum_mul_left]
        _ = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑ b in s.toFinset, (s.count b : ℝ≥0∞) :=
          (congr_arg (fun x => (Multiset.card s : ℝ≥0∞)⁻¹ * x)
            (tsum_eq_sum fun a ha =>
              Nat.cast_eq_zero.2 <| by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Multiset α
hs : s ≠ 0
a : α
ha : a ∉ Multiset.toFinset s
⊢ Multiset.count a s = 0

Next tactic:
rwa [Multiset.count_eq_zero, ← Multiset.mem_toFinset]
/-- Given a non-empty multiset `s` we construct the `PMF` which sends `a` to the fraction of
  elements in `s` that are `a`. -/
def ofMultiset (s : Multiset α) (hs : s ≠ 0) : PMF α :=
  ⟨fun a => s.count a / (Multiset.card s),
    ENNReal.summable.hasSum_iff.2
      (calc
        (∑' b : α, (s.count b : ℝ≥0∞) / (Multiset.card s))
          = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑' b, (s.count b : ℝ≥0∞) := by
            simp_rw [ENNReal.div_eq_inv_mul, ENNReal.tsum_mul_left]
        _ = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑ b in s.toFinset, (s.count b : ℝ≥0∞) :=
          (congr_arg (fun x => (Multiset.card s : ℝ≥0∞)⁻¹ * x)
            (tsum_eq_sum fun a ha =>
              Nat.cast_eq_zero.2 <| by rwa [Multiset.count_eq_zero, ← Multiset.mem_toFinset]))
        _ = 1 := by
          

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Multiset α
hs : s ≠ 0
⊢ (↑(Multiset.card s))⁻¹ * ∑ b in Multiset.toFinset s, ↑(Multiset.count b s) = 1

Next tactic:
rw [← Nat.cast_sum, Multiset.toFinset_sum_count_eq s,
            ENNReal.inv_mul_cancel (Nat.cast_ne_zero.2 (hs ∘ Multiset.card_eq_zero.1))
              (ENNReal.nat_ne_top _)]
@[simp]
theorem support_ofMultiset : (ofMultiset s hs).support = s.toFinset :=
  Set.ext (by 

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Multiset α
hs : s ≠ 0
⊢ ∀ (x : α), x ∈ support (ofMultiset s hs) ↔ x ∈ ↑(Multiset.toFinset s)

Next tactic:
simp [mem_support_iff, hs]
theorem mem_support_ofMultiset_iff (a : α) : a ∈ (ofMultiset s hs).support ↔ a ∈ s.toFinset := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Multiset α
hs : s ≠ 0
a : α
⊢ a ∈ support (ofMultiset s hs) ↔ a ∈ Multiset.toFinset s

Next tactic:
simp
theorem ofMultiset_apply_of_not_mem {a : α} (ha : a ∉ s) : ofMultiset s hs a = 0 := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Multiset α
hs : s ≠ 0
a : α
ha : a ∉ s
⊢ (ofMultiset s hs) a = 0

Next tactic:
simpa only [ofMultiset_apply, ENNReal.div_eq_zero_iff, Nat.cast_eq_zero, Multiset.count_eq_zero,
    ENNReal.nat_ne_top, or_false_iff] using ha
@[simp]
theorem toOuterMeasure_ofMultiset_apply :
    (ofMultiset s hs).toOuterMeasure t =
      (∑' x, (s.filter (· ∈ t)).count x : ℝ≥0∞) / (Multiset.card s) := by
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Multiset α
hs : s ≠ 0
t : Set α
⊢ ↑(toOuterMeasure (ofMultiset s hs)) t =
    (∑' (x : α), ↑(Multiset.count x (Multiset.filter (fun x => x ∈ t) s))) / ↑(Multiset.card s)

Next tactic:
simp_rw [div_eq_mul_inv, ← ENNReal.tsum_mul_right, toOuterMeasure_apply]
@[simp]
theorem toOuterMeasure_ofMultiset_apply :
    (ofMultiset s hs).toOuterMeasure t =
      (∑' x, (s.filter (· ∈ t)).count x : ℝ≥0∞) / (Multiset.card s) := by
  simp_rw [div_eq_mul_inv, ← ENNReal.tsum_mul_right, toOuterMeasure_apply]
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Multiset α
hs : s ≠ 0
t : Set α
⊢ ∑' (x : α), Set.indicator t (⇑(ofMultiset s hs)) x =
    ∑' (i : α), ↑(Multiset.count i (Multiset.filter (fun x => x ∈ t) s)) * (↑(Multiset.card s))⁻¹

Next tactic:
refine' tsum_congr fun x => _
@[simp]
theorem toOuterMeasure_ofMultiset_apply :
    (ofMultiset s hs).toOuterMeasure t =
      (∑' x, (s.filter (· ∈ t)).count x : ℝ≥0∞) / (Multiset.card s) := by
  simp_rw [div_eq_mul_inv, ← ENNReal.tsum_mul_right, toOuterMeasure_apply]
  refine' tsum_congr fun x => _
  

Proof state:
α : Type u_1
β : Type u_2
γ : Type u_3
s : Multiset α
hs : s ≠ 0
t : Set α
x : α
⊢ Set.indicator t (⇑(ofMultiset s hs)) x =
    ↑(Multiset.count x (Multiset.filter (fun x => x ∈ t) s)) * (↑(Multiset.card s))⁻¹

Next tactic:
by_cases hx : x ∈ t