l3lab/ntp-mathlib huggingface dataset:
/-- **Kleitman's theorem**. An intersecting family on `n` elements contains at most `2ⁿ⁻¹` sets, and
each further intersecting family takes at most half of the sets that are in no previous family. -/
theorem Finset.card_biUnion_le_of_intersecting (s : Finset ι) (f : ι → Finset (Finset α))
    (hf : ∀ i ∈ s, (f i : Set (Finset α)).Intersecting) :
    (s.biUnion f).card ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - s.card) := by
  have : DecidableEq ι := by
    classical
    infer_instance
  obtain hs | hs := le_total (Fintype.card α) s.card
  · rw [tsub_eq_zero_of_le hs, pow_zero]
    refine' (card_le_of_subset <| biUnion_subset.2 fun i hi a ha ↦
      mem_compl.2 <| not_mem_singleton.2 <| (hf _ hi).ne_bot ha).trans_eq _
    rw [card_compl, Fintype.card_finset, card_singleton]
  induction' s using Finset.cons_induction with i s hi ih generalizing f
  · simp
  set f' : ι → Finset (Finset α) :=
    fun j ↦ if hj : j ∈ cons i s hi then (hf j hj).exists_card_eq.choose else ∅
  have hf₁ : ∀ j, j ∈ cons i s hi → f j ⊆ f' j ∧ 2 * (f' j).card =
      2 ^ Fintype.card α ∧ (f' j : Set (Finset α)).Intersecting := by
    rintro j hj
    simp_rw [dif_pos hj, ← Fintype.card_finset]
    exact Classical.choose_spec (hf j hj).exists_card_eq
  have hf₂ : ∀ j, j ∈ cons i s hi → IsUpperSet (f' j : Set (Finset α)) := by
    refine' fun j hj ↦ (hf₁ _ hj).2.2.isUpperSet' ((hf₁ _ hj).2.2.is_max_iff_card_eq.2 _)
    rw [Fintype.card_finset]
    exact (hf₁ _ hj).2.1
  refine' (card_le_of_subset <| biUnion_mono fun j hj ↦ (hf₁ _ hj).1).trans _
  nth_rw 1 [cons_eq_insert i]
  rw [biUnion_insert]
  refine' (card_mono <| @le_sup_sdiff _ _ _ <| f' i).trans ((card_union_le _ _).trans _)
  

Proof state:
case inr.cons
ι : Type u_1
α : Type u_2
inst✝² : Fintype α
inst✝¹ : DecidableEq α
inst✝ : Nonempty α
this : DecidableEq ι
i : ι
s : Finset ι
hi : i ∉ s
ih :
  ∀ (f : ι → Finset (Finset α)),
    (∀ i ∈ s, Set.Intersecting ↑(f i)) →
      card s ≤ Fintype.card α → card (Finset.biUnion s f) ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - card s)
f : ι → Finset (Finset α)
hf : ∀ i_1 ∈ cons i s hi, Set.Intersecting ↑(f i_1)
hs : card (cons i s hi) ≤ Fintype.card α
f' : ι → Finset (Finset α) :=
  fun j =>
    if hj : j ∈ cons i s hi then
      Exists.choose (_ : ∃ t, f j ⊆ t ∧ 2 * card t = Fintype.card (Finset α) ∧ Set.Intersecting ↑t)
    else ∅
hf₁ : ∀ j ∈ cons i s hi, f j ⊆ f' j ∧ 2 * card (f' j) = 2 ^ Fintype.card α ∧ Set.Intersecting ↑(f' j)
hf₂ : ∀ j ∈ cons i s hi, IsUpperSet ↑(f' j)
⊢ card (f' i) + card ((f' i ∪ Finset.biUnion s fun j => f' j) \ f' i) ≤
    2 ^ Fintype.card α - 2 ^ (Fintype.card α - card (cons i s hi))

Next tactic:
rw [union_sdiff_left, sdiff_eq_inter_compl]
/-- **Kleitman's theorem**. An intersecting family on `n` elements contains at most `2ⁿ⁻¹` sets, and
each further intersecting family takes at most half of the sets that are in no previous family. -/
theorem Finset.card_biUnion_le_of_intersecting (s : Finset ι) (f : ι → Finset (Finset α))
    (hf : ∀ i ∈ s, (f i : Set (Finset α)).Intersecting) :
    (s.biUnion f).card ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - s.card) := by
  have : DecidableEq ι := by
    classical
    infer_instance
  obtain hs | hs := le_total (Fintype.card α) s.card
  · rw [tsub_eq_zero_of_le hs, pow_zero]
    refine' (card_le_of_subset <| biUnion_subset.2 fun i hi a ha ↦
      mem_compl.2 <| not_mem_singleton.2 <| (hf _ hi).ne_bot ha).trans_eq _
    rw [card_compl, Fintype.card_finset, card_singleton]
  induction' s using Finset.cons_induction with i s hi ih generalizing f
  · simp
  set f' : ι → Finset (Finset α) :=
    fun j ↦ if hj : j ∈ cons i s hi then (hf j hj).exists_card_eq.choose else ∅
  have hf₁ : ∀ j, j ∈ cons i s hi → f j ⊆ f' j ∧ 2 * (f' j).card =
      2 ^ Fintype.card α ∧ (f' j : Set (Finset α)).Intersecting := by
    rintro j hj
    simp_rw [dif_pos hj, ← Fintype.card_finset]
    exact Classical.choose_spec (hf j hj).exists_card_eq
  have hf₂ : ∀ j, j ∈ cons i s hi → IsUpperSet (f' j : Set (Finset α)) := by
    refine' fun j hj ↦ (hf₁ _ hj).2.2.isUpperSet' ((hf₁ _ hj).2.2.is_max_iff_card_eq.2 _)
    rw [Fintype.card_finset]
    exact (hf₁ _ hj).2.1
  refine' (card_le_of_subset <| biUnion_mono fun j hj ↦ (hf₁ _ hj).1).trans _
  nth_rw 1 [cons_eq_insert i]
  rw [biUnion_insert]
  refine' (card_mono <| @le_sup_sdiff _ _ _ <| f' i).trans ((card_union_le _ _).trans _)
  rw [union_sdiff_left, sdiff_eq_inter_compl]
  

Proof state:
case inr.cons
ι : Type u_1
α : Type u_2
inst✝² : Fintype α
inst✝¹ : DecidableEq α
inst✝ : Nonempty α
this : DecidableEq ι
i : ι
s : Finset ι
hi : i ∉ s
ih :
  ∀ (f : ι → Finset (Finset α)),
    (∀ i ∈ s, Set.Intersecting ↑(f i)) →
      card s ≤ Fintype.card α → card (Finset.biUnion s f) ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - card s)
f : ι → Finset (Finset α)
hf : ∀ i_1 ∈ cons i s hi, Set.Intersecting ↑(f i_1)
hs : card (cons i s hi) ≤ Fintype.card α
f' : ι → Finset (Finset α) :=
  fun j =>
    if hj : j ∈ cons i s hi then
      Exists.choose (_ : ∃ t, f j ⊆ t ∧ 2 * card t = Fintype.card (Finset α) ∧ Set.Intersecting ↑t)
    else ∅
hf₁ : ∀ j ∈ cons i s hi, f j ⊆ f' j ∧ 2 * card (f' j) = 2 ^ Fintype.card α ∧ Set.Intersecting ↑(f' j)
hf₂ : ∀ j ∈ cons i s hi, IsUpperSet ↑(f' j)
⊢ card (f' i) + card ((Finset.biUnion s fun j => f' j) ∩ (f' i)ᶜ) ≤
    2 ^ Fintype.card α - 2 ^ (Fintype.card α - card (cons i s hi))

Next tactic:
refine' le_of_mul_le_mul_left _ (pow_pos (zero_lt_two' ℕ) <| Fintype.card α + 1)
/-- **Kleitman's theorem**. An intersecting family on `n` elements contains at most `2ⁿ⁻¹` sets, and
each further intersecting family takes at most half of the sets that are in no previous family. -/
theorem Finset.card_biUnion_le_of_intersecting (s : Finset ι) (f : ι → Finset (Finset α))
    (hf : ∀ i ∈ s, (f i : Set (Finset α)).Intersecting) :
    (s.biUnion f).card ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - s.card) := by
  have : DecidableEq ι := by
    classical
    infer_instance
  obtain hs | hs := le_total (Fintype.card α) s.card
  · rw [tsub_eq_zero_of_le hs, pow_zero]
    refine' (card_le_of_subset <| biUnion_subset.2 fun i hi a ha ↦
      mem_compl.2 <| not_mem_singleton.2 <| (hf _ hi).ne_bot ha).trans_eq _
    rw [card_compl, Fintype.card_finset, card_singleton]
  induction' s using Finset.cons_induction with i s hi ih generalizing f
  · simp
  set f' : ι → Finset (Finset α) :=
    fun j ↦ if hj : j ∈ cons i s hi then (hf j hj).exists_card_eq.choose else ∅
  have hf₁ : ∀ j, j ∈ cons i s hi → f j ⊆ f' j ∧ 2 * (f' j).card =
      2 ^ Fintype.card α ∧ (f' j : Set (Finset α)).Intersecting := by
    rintro j hj
    simp_rw [dif_pos hj, ← Fintype.card_finset]
    exact Classical.choose_spec (hf j hj).exists_card_eq
  have hf₂ : ∀ j, j ∈ cons i s hi → IsUpperSet (f' j : Set (Finset α)) := by
    refine' fun j hj ↦ (hf₁ _ hj).2.2.isUpperSet' ((hf₁ _ hj).2.2.is_max_iff_card_eq.2 _)
    rw [Fintype.card_finset]
    exact (hf₁ _ hj).2.1
  refine' (card_le_of_subset <| biUnion_mono fun j hj ↦ (hf₁ _ hj).1).trans _
  nth_rw 1 [cons_eq_insert i]
  rw [biUnion_insert]
  refine' (card_mono <| @le_sup_sdiff _ _ _ <| f' i).trans ((card_union_le _ _).trans _)
  rw [union_sdiff_left, sdiff_eq_inter_compl]
  refine' le_of_mul_le_mul_left _ (pow_pos (zero_lt_two' ℕ) <| Fintype.card α + 1)
  

Proof state:
case inr.cons
ι : Type u_1
α : Type u_2
inst✝² : Fintype α
inst✝¹ : DecidableEq α
inst✝ : Nonempty α
this : DecidableEq ι
i : ι
s : Finset ι
hi : i ∉ s
ih :
  ∀ (f : ι → Finset (Finset α)),
    (∀ i ∈ s, Set.Intersecting ↑(f i)) →
      card s ≤ Fintype.card α → card (Finset.biUnion s f) ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - card s)
f : ι → Finset (Finset α)
hf : ∀ i_1 ∈ cons i s hi, Set.Intersecting ↑(f i_1)
hs : card (cons i s hi) ≤ Fintype.card α
f' : ι → Finset (Finset α) :=
  fun j =>
    if hj : j ∈ cons i s hi then
      Exists.choose (_ : ∃ t, f j ⊆ t ∧ 2 * card t = Fintype.card (Finset α) ∧ Set.Intersecting ↑t)
    else ∅
hf₁ : ∀ j ∈ cons i s hi, f j ⊆ f' j ∧ 2 * card (f' j) = 2 ^ Fintype.card α ∧ Set.Intersecting ↑(f' j)
hf₂ : ∀ j ∈ cons i s hi, IsUpperSet ↑(f' j)
⊢ 2 ^ (Fintype.card α + 1) * (card (f' i) + card ((Finset.biUnion s fun j => f' j) ∩ (f' i)ᶜ)) ≤
    2 ^ (Fintype.card α + 1) * (2 ^ Fintype.card α - 2 ^ (Fintype.card α - card (cons i s hi)))

Next tactic:
rw [pow_succ', mul_add, mul_assoc, mul_comm _ 2, mul_assoc]
/-- **Kleitman's theorem**. An intersecting family on `n` elements contains at most `2ⁿ⁻¹` sets, and
each further intersecting family takes at most half of the sets that are in no previous family. -/
theorem Finset.card_biUnion_le_of_intersecting (s : Finset ι) (f : ι → Finset (Finset α))
    (hf : ∀ i ∈ s, (f i : Set (Finset α)).Intersecting) :
    (s.biUnion f).card ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - s.card) := by
  have : DecidableEq ι := by
    classical
    infer_instance
  obtain hs | hs := le_total (Fintype.card α) s.card
  · rw [tsub_eq_zero_of_le hs, pow_zero]
    refine' (card_le_of_subset <| biUnion_subset.2 fun i hi a ha ↦
      mem_compl.2 <| not_mem_singleton.2 <| (hf _ hi).ne_bot ha).trans_eq _
    rw [card_compl, Fintype.card_finset, card_singleton]
  induction' s using Finset.cons_induction with i s hi ih generalizing f
  · simp
  set f' : ι → Finset (Finset α) :=
    fun j ↦ if hj : j ∈ cons i s hi then (hf j hj).exists_card_eq.choose else ∅
  have hf₁ : ∀ j, j ∈ cons i s hi → f j ⊆ f' j ∧ 2 * (f' j).card =
      2 ^ Fintype.card α ∧ (f' j : Set (Finset α)).Intersecting := by
    rintro j hj
    simp_rw [dif_pos hj, ← Fintype.card_finset]
    exact Classical.choose_spec (hf j hj).exists_card_eq
  have hf₂ : ∀ j, j ∈ cons i s hi → IsUpperSet (f' j : Set (Finset α)) := by
    refine' fun j hj ↦ (hf₁ _ hj).2.2.isUpperSet' ((hf₁ _ hj).2.2.is_max_iff_card_eq.2 _)
    rw [Fintype.card_finset]
    exact (hf₁ _ hj).2.1
  refine' (card_le_of_subset <| biUnion_mono fun j hj ↦ (hf₁ _ hj).1).trans _
  nth_rw 1 [cons_eq_insert i]
  rw [biUnion_insert]
  refine' (card_mono <| @le_sup_sdiff _ _ _ <| f' i).trans ((card_union_le _ _).trans _)
  rw [union_sdiff_left, sdiff_eq_inter_compl]
  refine' le_of_mul_le_mul_left _ (pow_pos (zero_lt_two' ℕ) <| Fintype.card α + 1)
  rw [pow_succ', mul_add, mul_assoc, mul_comm _ 2, mul_assoc]
  

Proof state:
case inr.cons
ι : Type u_1
α : Type u_2
inst✝² : Fintype α
inst✝¹ : DecidableEq α
inst✝ : Nonempty α
this : DecidableEq ι
i : ι
s : Finset ι
hi : i ∉ s
ih :
  ∀ (f : ι → Finset (Finset α)),
    (∀ i ∈ s, Set.Intersecting ↑(f i)) →
      card s ≤ Fintype.card α → card (Finset.biUnion s f) ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - card s)
f : ι → Finset (Finset α)
hf : ∀ i_1 ∈ cons i s hi, Set.Intersecting ↑(f i_1)
hs : card (cons i s hi) ≤ Fintype.card α
f' : ι → Finset (Finset α) :=
  fun j =>
    if hj : j ∈ cons i s hi then
      Exists.choose (_ : ∃ t, f j ⊆ t ∧ 2 * card t = Fintype.card (Finset α) ∧ Set.Intersecting ↑t)
    else ∅
hf₁ : ∀ j ∈ cons i s hi, f j ⊆ f' j ∧ 2 * card (f' j) = 2 ^ Fintype.card α ∧ Set.Intersecting ↑(f' j)
hf₂ : ∀ j ∈ cons i s hi, IsUpperSet ↑(f' j)
⊢ 2 ^ Fintype.card α * (2 * card (f' i)) +
      2 * (2 ^ Fintype.card α * card ((Finset.biUnion s fun j => f' j) ∩ (f' i)ᶜ)) ≤
    2 * 2 ^ Fintype.card α * (2 ^ Fintype.card α - 2 ^ (Fintype.card α - card (cons i s hi)))

Next tactic:
refine' (add_le_add
      ((mul_le_mul_left <| pow_pos (zero_lt_two' ℕ) _).2
      (hf₁ _ <| mem_cons_self _ _).2.2.card_le) <|
      (mul_le_mul_left <| zero_lt_two' ℕ).2 <| IsUpperSet.card_inter_le_finset _ _).trans _
/-- **Kleitman's theorem**. An intersecting family on `n` elements contains at most `2ⁿ⁻¹` sets, and
each further intersecting family takes at most half of the sets that are in no previous family. -/
theorem Finset.card_biUnion_le_of_intersecting (s : Finset ι) (f : ι → Finset (Finset α))
    (hf : ∀ i ∈ s, (f i : Set (Finset α)).Intersecting) :
    (s.biUnion f).card ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - s.card) := by
  have : DecidableEq ι := by
    classical
    infer_instance
  obtain hs | hs := le_total (Fintype.card α) s.card
  · rw [tsub_eq_zero_of_le hs, pow_zero]
    refine' (card_le_of_subset <| biUnion_subset.2 fun i hi a ha ↦
      mem_compl.2 <| not_mem_singleton.2 <| (hf _ hi).ne_bot ha).trans_eq _
    rw [card_compl, Fintype.card_finset, card_singleton]
  induction' s using Finset.cons_induction with i s hi ih generalizing f
  · simp
  set f' : ι → Finset (Finset α) :=
    fun j ↦ if hj : j ∈ cons i s hi then (hf j hj).exists_card_eq.choose else ∅
  have hf₁ : ∀ j, j ∈ cons i s hi → f j ⊆ f' j ∧ 2 * (f' j).card =
      2 ^ Fintype.card α ∧ (f' j : Set (Finset α)).Intersecting := by
    rintro j hj
    simp_rw [dif_pos hj, ← Fintype.card_finset]
    exact Classical.choose_spec (hf j hj).exists_card_eq
  have hf₂ : ∀ j, j ∈ cons i s hi → IsUpperSet (f' j : Set (Finset α)) := by
    refine' fun j hj ↦ (hf₁ _ hj).2.2.isUpperSet' ((hf₁ _ hj).2.2.is_max_iff_card_eq.2 _)
    rw [Fintype.card_finset]
    exact (hf₁ _ hj).2.1
  refine' (card_le_of_subset <| biUnion_mono fun j hj ↦ (hf₁ _ hj).1).trans _
  nth_rw 1 [cons_eq_insert i]
  rw [biUnion_insert]
  refine' (card_mono <| @le_sup_sdiff _ _ _ <| f' i).trans ((card_union_le _ _).trans _)
  rw [union_sdiff_left, sdiff_eq_inter_compl]
  refine' le_of_mul_le_mul_left _ (pow_pos (zero_lt_two' ℕ) <| Fintype.card α + 1)
  rw [pow_succ', mul_add, mul_assoc, mul_comm _ 2, mul_assoc]
  refine' (add_le_add
      ((mul_le_mul_left <| pow_pos (zero_lt_two' ℕ) _).2
      (hf₁ _ <| mem_cons_self _ _).2.2.card_le) <|
      (mul_le_mul_left <| zero_lt_two' ℕ).2 <| IsUpperSet.card_inter_le_finset _ _).trans _
  · 

Proof state:
case inr.cons.refine'_1
ι : Type u_1
α : Type u_2
inst✝² : Fintype α
inst✝¹ : DecidableEq α
inst✝ : Nonempty α
this : DecidableEq ι
i : ι
s : Finset ι
hi : i ∉ s
ih :
  ∀ (f : ι → Finset (Finset α)),
    (∀ i ∈ s, Set.Intersecting ↑(f i)) →
      card s ≤ Fintype.card α → card (Finset.biUnion s f) ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - card s)
f : ι → Finset (Finset α)
hf : ∀ i_1 ∈ cons i s hi, Set.Intersecting ↑(f i_1)
hs : card (cons i s hi) ≤ Fintype.card α
f' : ι → Finset (Finset α) :=
  fun j =>
    if hj : j ∈ cons i s hi then
      Exists.choose (_ : ∃ t, f j ⊆ t ∧ 2 * card t = Fintype.card (Finset α) ∧ Set.Intersecting ↑t)
    else ∅
hf₁ : ∀ j ∈ cons i s hi, f j ⊆ f' j ∧ 2 * card (f' j) = 2 ^ Fintype.card α ∧ Set.Intersecting ↑(f' j)
hf₂ : ∀ j ∈ cons i s hi, IsUpperSet ↑(f' j)
⊢ IsUpperSet ↑(Finset.biUnion s fun j => f' j)

Next tactic:
rw [coe_biUnion]
/-- **Kleitman's theorem**. An intersecting family on `n` elements contains at most `2ⁿ⁻¹` sets, and
each further intersecting family takes at most half of the sets that are in no previous family. -/
theorem Finset.card_biUnion_le_of_intersecting (s : Finset ι) (f : ι → Finset (Finset α))
    (hf : ∀ i ∈ s, (f i : Set (Finset α)).Intersecting) :
    (s.biUnion f).card ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - s.card) := by
  have : DecidableEq ι := by
    classical
    infer_instance
  obtain hs | hs := le_total (Fintype.card α) s.card
  · rw [tsub_eq_zero_of_le hs, pow_zero]
    refine' (card_le_of_subset <| biUnion_subset.2 fun i hi a ha ↦
      mem_compl.2 <| not_mem_singleton.2 <| (hf _ hi).ne_bot ha).trans_eq _
    rw [card_compl, Fintype.card_finset, card_singleton]
  induction' s using Finset.cons_induction with i s hi ih generalizing f
  · simp
  set f' : ι → Finset (Finset α) :=
    fun j ↦ if hj : j ∈ cons i s hi then (hf j hj).exists_card_eq.choose else ∅
  have hf₁ : ∀ j, j ∈ cons i s hi → f j ⊆ f' j ∧ 2 * (f' j).card =
      2 ^ Fintype.card α ∧ (f' j : Set (Finset α)).Intersecting := by
    rintro j hj
    simp_rw [dif_pos hj, ← Fintype.card_finset]
    exact Classical.choose_spec (hf j hj).exists_card_eq
  have hf₂ : ∀ j, j ∈ cons i s hi → IsUpperSet (f' j : Set (Finset α)) := by
    refine' fun j hj ↦ (hf₁ _ hj).2.2.isUpperSet' ((hf₁ _ hj).2.2.is_max_iff_card_eq.2 _)
    rw [Fintype.card_finset]
    exact (hf₁ _ hj).2.1
  refine' (card_le_of_subset <| biUnion_mono fun j hj ↦ (hf₁ _ hj).1).trans _
  nth_rw 1 [cons_eq_insert i]
  rw [biUnion_insert]
  refine' (card_mono <| @le_sup_sdiff _ _ _ <| f' i).trans ((card_union_le _ _).trans _)
  rw [union_sdiff_left, sdiff_eq_inter_compl]
  refine' le_of_mul_le_mul_left _ (pow_pos (zero_lt_two' ℕ) <| Fintype.card α + 1)
  rw [pow_succ', mul_add, mul_assoc, mul_comm _ 2, mul_assoc]
  refine' (add_le_add
      ((mul_le_mul_left <| pow_pos (zero_lt_two' ℕ) _).2
      (hf₁ _ <| mem_cons_self _ _).2.2.card_le) <|
      (mul_le_mul_left <| zero_lt_two' ℕ).2 <| IsUpperSet.card_inter_le_finset _ _).trans _
  · rw [coe_biUnion]
    

Proof state:
case inr.cons.refine'_1
ι : Type u_1
α : Type u_2
inst✝² : Fintype α
inst✝¹ : DecidableEq α
inst✝ : Nonempty α
this : DecidableEq ι
i : ι
s : Finset ι
hi : i ∉ s
ih :
  ∀ (f : ι → Finset (Finset α)),
    (∀ i ∈ s, Set.Intersecting ↑(f i)) →
      card s ≤ Fintype.card α → card (Finset.biUnion s f) ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - card s)
f : ι → Finset (Finset α)
hf : ∀ i_1 ∈ cons i s hi, Set.Intersecting ↑(f i_1)
hs : card (cons i s hi) ≤ Fintype.card α
f' : ι → Finset (Finset α) :=
  fun j =>
    if hj : j ∈ cons i s hi then
      Exists.choose (_ : ∃ t, f j ⊆ t ∧ 2 * card t = Fintype.card (Finset α) ∧ Set.Intersecting ↑t)
    else ∅
hf₁ : ∀ j ∈ cons i s hi, f j ⊆ f' j ∧ 2 * card (f' j) = 2 ^ Fintype.card α ∧ Set.Intersecting ↑(f' j)
hf₂ : ∀ j ∈ cons i s hi, IsUpperSet ↑(f' j)
⊢ IsUpperSet (⋃ x ∈ ↑s, ↑(f' x))

Next tactic:
exact isUpperSet_iUnion₂ fun i hi ↦ hf₂ _ <| subset_cons _ hi
/-- **Kleitman's theorem**. An intersecting family on `n` elements contains at most `2ⁿ⁻¹` sets, and
each further intersecting family takes at most half of the sets that are in no previous family. -/
theorem Finset.card_biUnion_le_of_intersecting (s : Finset ι) (f : ι → Finset (Finset α))
    (hf : ∀ i ∈ s, (f i : Set (Finset α)).Intersecting) :
    (s.biUnion f).card ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - s.card) := by
  have : DecidableEq ι := by
    classical
    infer_instance
  obtain hs | hs := le_total (Fintype.card α) s.card
  · rw [tsub_eq_zero_of_le hs, pow_zero]
    refine' (card_le_of_subset <| biUnion_subset.2 fun i hi a ha ↦
      mem_compl.2 <| not_mem_singleton.2 <| (hf _ hi).ne_bot ha).trans_eq _
    rw [card_compl, Fintype.card_finset, card_singleton]
  induction' s using Finset.cons_induction with i s hi ih generalizing f
  · simp
  set f' : ι → Finset (Finset α) :=
    fun j ↦ if hj : j ∈ cons i s hi then (hf j hj).exists_card_eq.choose else ∅
  have hf₁ : ∀ j, j ∈ cons i s hi → f j ⊆ f' j ∧ 2 * (f' j).card =
      2 ^ Fintype.card α ∧ (f' j : Set (Finset α)).Intersecting := by
    rintro j hj
    simp_rw [dif_pos hj, ← Fintype.card_finset]
    exact Classical.choose_spec (hf j hj).exists_card_eq
  have hf₂ : ∀ j, j ∈ cons i s hi → IsUpperSet (f' j : Set (Finset α)) := by
    refine' fun j hj ↦ (hf₁ _ hj).2.2.isUpperSet' ((hf₁ _ hj).2.2.is_max_iff_card_eq.2 _)
    rw [Fintype.card_finset]
    exact (hf₁ _ hj).2.1
  refine' (card_le_of_subset <| biUnion_mono fun j hj ↦ (hf₁ _ hj).1).trans _
  nth_rw 1 [cons_eq_insert i]
  rw [biUnion_insert]
  refine' (card_mono <| @le_sup_sdiff _ _ _ <| f' i).trans ((card_union_le _ _).trans _)
  rw [union_sdiff_left, sdiff_eq_inter_compl]
  refine' le_of_mul_le_mul_left _ (pow_pos (zero_lt_two' ℕ) <| Fintype.card α + 1)
  rw [pow_succ', mul_add, mul_assoc, mul_comm _ 2, mul_assoc]
  refine' (add_le_add
      ((mul_le_mul_left <| pow_pos (zero_lt_two' ℕ) _).2
      (hf₁ _ <| mem_cons_self _ _).2.2.card_le) <|
      (mul_le_mul_left <| zero_lt_two' ℕ).2 <| IsUpperSet.card_inter_le_finset _ _).trans _
  · rw [coe_biUnion]
    exact isUpperSet_iUnion₂ fun i hi ↦ hf₂ _ <| subset_cons _ hi
  · 

Proof state:
case inr.cons.refine'_2
ι : Type u_1
α : Type u_2
inst✝² : Fintype α
inst✝¹ : DecidableEq α
inst✝ : Nonempty α
this : DecidableEq ι
i : ι
s : Finset ι
hi : i ∉ s
ih :
  ∀ (f : ι → Finset (Finset α)),
    (∀ i ∈ s, Set.Intersecting ↑(f i)) →
      card s ≤ Fintype.card α → card (Finset.biUnion s f) ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - card s)
f : ι → Finset (Finset α)
hf : ∀ i_1 ∈ cons i s hi, Set.Intersecting ↑(f i_1)
hs : card (cons i s hi) ≤ Fintype.card α
f' : ι → Finset (Finset α) :=
  fun j =>
    if hj : j ∈ cons i s hi then
      Exists.choose (_ : ∃ t, f j ⊆ t ∧ 2 * card t = Fintype.card (Finset α) ∧ Set.Intersecting ↑t)
    else ∅
hf₁ : ∀ j ∈ cons i s hi, f j ⊆ f' j ∧ 2 * card (f' j) = 2 ^ Fintype.card α ∧ Set.Intersecting ↑(f' j)
hf₂ : ∀ j ∈ cons i s hi, IsUpperSet ↑(f' j)
⊢ IsLowerSet ↑(f' i)ᶜ

Next tactic:
rw [coe_compl]
/-- **Kleitman's theorem**. An intersecting family on `n` elements contains at most `2ⁿ⁻¹` sets, and
each further intersecting family takes at most half of the sets that are in no previous family. -/
theorem Finset.card_biUnion_le_of_intersecting (s : Finset ι) (f : ι → Finset (Finset α))
    (hf : ∀ i ∈ s, (f i : Set (Finset α)).Intersecting) :
    (s.biUnion f).card ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - s.card) := by
  have : DecidableEq ι := by
    classical
    infer_instance
  obtain hs | hs := le_total (Fintype.card α) s.card
  · rw [tsub_eq_zero_of_le hs, pow_zero]
    refine' (card_le_of_subset <| biUnion_subset.2 fun i hi a ha ↦
      mem_compl.2 <| not_mem_singleton.2 <| (hf _ hi).ne_bot ha).trans_eq _
    rw [card_compl, Fintype.card_finset, card_singleton]
  induction' s using Finset.cons_induction with i s hi ih generalizing f
  · simp
  set f' : ι → Finset (Finset α) :=
    fun j ↦ if hj : j ∈ cons i s hi then (hf j hj).exists_card_eq.choose else ∅
  have hf₁ : ∀ j, j ∈ cons i s hi → f j ⊆ f' j ∧ 2 * (f' j).card =
      2 ^ Fintype.card α ∧ (f' j : Set (Finset α)).Intersecting := by
    rintro j hj
    simp_rw [dif_pos hj, ← Fintype.card_finset]
    exact Classical.choose_spec (hf j hj).exists_card_eq
  have hf₂ : ∀ j, j ∈ cons i s hi → IsUpperSet (f' j : Set (Finset α)) := by
    refine' fun j hj ↦ (hf₁ _ hj).2.2.isUpperSet' ((hf₁ _ hj).2.2.is_max_iff_card_eq.2 _)
    rw [Fintype.card_finset]
    exact (hf₁ _ hj).2.1
  refine' (card_le_of_subset <| biUnion_mono fun j hj ↦ (hf₁ _ hj).1).trans _
  nth_rw 1 [cons_eq_insert i]
  rw [biUnion_insert]
  refine' (card_mono <| @le_sup_sdiff _ _ _ <| f' i).trans ((card_union_le _ _).trans _)
  rw [union_sdiff_left, sdiff_eq_inter_compl]
  refine' le_of_mul_le_mul_left _ (pow_pos (zero_lt_two' ℕ) <| Fintype.card α + 1)
  rw [pow_succ', mul_add, mul_assoc, mul_comm _ 2, mul_assoc]
  refine' (add_le_add
      ((mul_le_mul_left <| pow_pos (zero_lt_two' ℕ) _).2
      (hf₁ _ <| mem_cons_self _ _).2.2.card_le) <|
      (mul_le_mul_left <| zero_lt_two' ℕ).2 <| IsUpperSet.card_inter_le_finset _ _).trans _
  · rw [coe_biUnion]
    exact isUpperSet_iUnion₂ fun i hi ↦ hf₂ _ <| subset_cons _ hi
  · rw [coe_compl]
    

Proof state:
case inr.cons.refine'_2
ι : Type u_1
α : Type u_2
inst✝² : Fintype α
inst✝¹ : DecidableEq α
inst✝ : Nonempty α
this : DecidableEq ι
i : ι
s : Finset ι
hi : i ∉ s
ih :
  ∀ (f : ι → Finset (Finset α)),
    (∀ i ∈ s, Set.Intersecting ↑(f i)) →
      card s ≤ Fintype.card α → card (Finset.biUnion s f) ≤ 2 ^ Fintype.card α - 2 ^ (Fintype.card α - card s)
f : ι → Finset (Finset α)
hf : ∀ i_1 ∈ cons i s hi, Set.Intersecting ↑(f i_1)
hs : card (cons i s hi) ≤ Fintype.card α
f' : ι → Finset (Finset α) :=
  fun j =>
    if hj : j ∈ cons i s hi then
      Exists.choose (_ : ∃ t, f j ⊆ t ∧ 2 * card t = Fintype.card (Finset α) ∧ Set.Intersecting ↑t)
    else ∅
hf₁ : ∀ j ∈ cons i s hi, f j ⊆ f' j ∧ 2 * card (f' j) = 2 ^ Fintype.card α ∧ Set.Intersecting ↑(f' j)
hf₂ : ∀ j ∈ cons i s hi, IsUpperSet ↑(f' j)
⊢ IsLowerSet (↑(f' i))ᶜ

Next tactic:
exact (hf₂ _ <| mem_cons_self _ _).compl
theorem submonoid_map_le_is_unit : M.map (algebraMap R S) ≤ IsUnit.submonoid S := by
  

Proof state:
R : Type u_1
inst✝⁴ : CommRing R
M : Submonoid R
S : Type u_2
inst✝³ : CommRing S
inst✝² : Algebra R S
P : Type u_3
inst✝¹ : CommRing P
inst✝ : IsLocalization M S
⊢ Submonoid.map (algebraMap R S) M ≤ IsUnit.submonoid S

Next tactic:
rintro _ ⟨a, ha, rfl⟩
theorem submonoid_map_le_is_unit : M.map (algebraMap R S) ≤ IsUnit.submonoid S := by
  rintro _ ⟨a, ha, rfl⟩
  

Proof state:
case intro.intro
R : Type u_1
inst✝⁴ : CommRing R
M : Submonoid R
S : Type u_2
inst✝³ : CommRing S
inst✝² : Algebra R S
P : Type u_3
inst✝¹ : CommRing P
inst✝ : IsLocalization M S
a : R
ha : a ∈ ↑M
⊢ (algebraMap R S) a ∈ IsUnit.submonoid S

Next tactic:
exact IsLocalization.map_units S ⟨_, ha⟩