l3lab/ntp-mathlib huggingface dataset:
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    

Proof state:
case refine_3.refine_1
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s✝ t✝ : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
s : Finset α
hs : Shatters (memberSubfamily a 𝒜) s
t : Finset α
ht : t ⊆ s
⊢ ∃ u ∈ 𝒜, s ∩ u = t

Next tactic:
obtain ⟨u, hu, rfl⟩ := hs ht
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    obtain ⟨u, hu, rfl⟩ := hs ht
    

Proof state:
case refine_3.refine_1.intro.intro
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s✝ t : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
s : Finset α
hs : Shatters (memberSubfamily a 𝒜) s
u : Finset α
hu : u ∈ memberSubfamily a 𝒜
ht : s ∩ u ⊆ s
⊢ ∃ u_1 ∈ 𝒜, s ∩ u_1 = s ∩ u

Next tactic:
rw [mem_memberSubfamily] at hu
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    obtain ⟨u, hu, rfl⟩ := hs ht
    rw [mem_memberSubfamily] at hu
    

Proof state:
case refine_3.refine_1.intro.intro
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s✝ t : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
s : Finset α
hs : Shatters (memberSubfamily a 𝒜) s
u : Finset α
hu : insert a u ∈ 𝒜 ∧ a ∉ u
ht : s ∩ u ⊆ s
⊢ ∃ u_1 ∈ 𝒜, s ∩ u_1 = s ∩ u

Next tactic:
refine ⟨insert a u, hu.1, inter_insert_of_not_mem fun ha ↦ ?_⟩
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    obtain ⟨u, hu, rfl⟩ := hs ht
    rw [mem_memberSubfamily] at hu
    refine ⟨insert a u, hu.1, inter_insert_of_not_mem fun ha ↦ ?_⟩
    

Proof state:
case refine_3.refine_1.intro.intro
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s✝ t : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
s : Finset α
hs : Shatters (memberSubfamily a 𝒜) s
u : Finset α
hu : insert a u ∈ 𝒜 ∧ a ∉ u
ht : s ∩ u ⊆ s
ha : a ∈ s
⊢ False

Next tactic:
obtain ⟨v, hv, hsv⟩ := hs.exists_inter_eq_singleton ha
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    obtain ⟨u, hu, rfl⟩ := hs ht
    rw [mem_memberSubfamily] at hu
    refine ⟨insert a u, hu.1, inter_insert_of_not_mem fun ha ↦ ?_⟩
    obtain ⟨v, hv, hsv⟩ := hs.exists_inter_eq_singleton ha
    

Proof state:
case refine_3.refine_1.intro.intro.intro.intro
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s✝ t : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
s : Finset α
hs : Shatters (memberSubfamily a 𝒜) s
u : Finset α
hu : insert a u ∈ 𝒜 ∧ a ∉ u
ht : s ∩ u ⊆ s
ha : a ∈ s
v : Finset α
hv : v ∈ memberSubfamily a 𝒜
hsv : s ∩ v = {a}
⊢ False

Next tactic:
rw [mem_memberSubfamily] at hv
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    obtain ⟨u, hu, rfl⟩ := hs ht
    rw [mem_memberSubfamily] at hu
    refine ⟨insert a u, hu.1, inter_insert_of_not_mem fun ha ↦ ?_⟩
    obtain ⟨v, hv, hsv⟩ := hs.exists_inter_eq_singleton ha
    rw [mem_memberSubfamily] at hv
    

Proof state:
case refine_3.refine_1.intro.intro.intro.intro
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s✝ t : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
s : Finset α
hs : Shatters (memberSubfamily a 𝒜) s
u : Finset α
hu : insert a u ∈ 𝒜 ∧ a ∉ u
ht : s ∩ u ⊆ s
ha : a ∈ s
v : Finset α
hv : insert a v ∈ 𝒜 ∧ a ∉ v
hsv : s ∩ v = {a}
⊢ False

Next tactic:
rw [← singleton_subset_iff (a := a), ← hsv] at hv
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    obtain ⟨u, hu, rfl⟩ := hs ht
    rw [mem_memberSubfamily] at hu
    refine ⟨insert a u, hu.1, inter_insert_of_not_mem fun ha ↦ ?_⟩
    obtain ⟨v, hv, hsv⟩ := hs.exists_inter_eq_singleton ha
    rw [mem_memberSubfamily] at hv
    rw [← singleton_subset_iff (a := a), ← hsv] at hv
    

Proof state:
case refine_3.refine_1.intro.intro.intro.intro
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s✝ t : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
s : Finset α
hs : Shatters (memberSubfamily a 𝒜) s
u : Finset α
hu : insert a u ∈ 𝒜 ∧ a ∉ u
ht : s ∩ u ⊆ s
ha : a ∈ s
v : Finset α
hv : insert a v ∈ 𝒜 ∧ ¬s ∩ v ⊆ v
hsv : s ∩ v = {a}
⊢ False

Next tactic:
exact hv.2 <| inter_subset_right _ _
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    obtain ⟨u, hu, rfl⟩ := hs ht
    rw [mem_memberSubfamily] at hu
    refine ⟨insert a u, hu.1, inter_insert_of_not_mem fun ha ↦ ?_⟩
    obtain ⟨v, hv, hsv⟩ := hs.exists_inter_eq_singleton ha
    rw [mem_memberSubfamily] at hv
    rw [← singleton_subset_iff (a := a), ← hsv] at hv
    exact hv.2 <| inter_subset_right _ _
  · 

Proof state:
case refine_3.refine_2
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s t : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
⊢ ℬ ⊆ shatterer 𝒜

Next tactic:
refine forall_image.2 fun s hs ↦ mem_shatterer.2 fun t ht ↦ ?_
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    obtain ⟨u, hu, rfl⟩ := hs ht
    rw [mem_memberSubfamily] at hu
    refine ⟨insert a u, hu.1, inter_insert_of_not_mem fun ha ↦ ?_⟩
    obtain ⟨v, hv, hsv⟩ := hs.exists_inter_eq_singleton ha
    rw [mem_memberSubfamily] at hv
    rw [← singleton_subset_iff (a := a), ← hsv] at hv
    exact hv.2 <| inter_subset_right _ _
  · refine forall_image.2 fun s hs ↦ mem_shatterer.2 fun t ht ↦ ?_
    

Proof state:
case refine_3.refine_2
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s✝ t✝ : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
s : Finset α
hs : s ∈ shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜)
t : Finset α
ht : t ⊆ insert a s
⊢ ∃ u ∈ 𝒜, insert a s ∩ u = t

Next tactic:
simp only [mem_inter, mem_shatterer] at hs
/-- Pajor's variant of the **Sauer-Shelah lemma**. -/
lemma card_le_card_shatterer (𝒜 : Finset (Finset α)) : 𝒜.card ≤ 𝒜.shatterer.card := by
  refine memberFamily_induction_on 𝒜 ?_ ?_ ?_
  · simp
  · rfl
  intros a 𝒜 ih₀ ih₁
  set ℬ : Finset (Finset α) :=
    ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).image (insert a)
  have hℬ :
    ℬ.card = ((memberSubfamily a 𝒜).shatterer ∩ (nonMemberSubfamily a 𝒜).shatterer).card
  · refine card_image_of_injOn <| insert_erase_invOn.2.injOn.mono ?_
    simp only [coe_inter, Set.subset_def, Set.mem_inter_iff, mem_coe, Set.mem_setOf_eq, and_imp,
      mem_shatterer]
    exact fun s _ ↦ aux (fun t ht ↦ (mem_filter.1 ht).2)
  rw [← card_memberSubfamily_add_card_nonMemberSubfamily a]
  refine (add_le_add ih₁ ih₀).trans ?_
  rw [← card_union_add_card_inter, ← hℬ, ← card_disjoint_union]
  swap
  · simp only [disjoint_left, mem_union, mem_shatterer, mem_image, not_exists, not_and]
    rintro _ (hs | hs) s - rfl
    · exact aux (fun t ht ↦ (mem_memberSubfamily.1 ht).2) hs <| mem_insert_self _ _
    · exact aux (fun t ht ↦ (mem_nonMemberSubfamily.1 ht).2) hs <| mem_insert_self _ _
  refine card_mono <| union_subset (union_subset ?_ <| shatterer_mono <| filter_subset _ _) ?_
  · simp only [subset_iff, mem_shatterer]
    rintro s hs t ht
    obtain ⟨u, hu, rfl⟩ := hs ht
    rw [mem_memberSubfamily] at hu
    refine ⟨insert a u, hu.1, inter_insert_of_not_mem fun ha ↦ ?_⟩
    obtain ⟨v, hv, hsv⟩ := hs.exists_inter_eq_singleton ha
    rw [mem_memberSubfamily] at hv
    rw [← singleton_subset_iff (a := a), ← hsv] at hv
    exact hv.2 <| inter_subset_right _ _
  · refine forall_image.2 fun s hs ↦ mem_shatterer.2 fun t ht ↦ ?_
    simp only [mem_inter, mem_shatterer] at hs
    

Proof state:
case refine_3.refine_2
α : Type u_1
inst✝ : DecidableEq α
𝒜✝¹ ℬ✝ : Finset (Finset α)
s✝ t✝ : Finset α
a✝ : α
n : ℕ
𝒜✝ : Finset (Finset α)
a : α
𝒜 : Finset (Finset α)
ih₀ : card (nonMemberSubfamily a 𝒜) ≤ card (shatterer (nonMemberSubfamily a 𝒜))
ih₁ : card (memberSubfamily a 𝒜) ≤ card (shatterer (memberSubfamily a 𝒜))
ℬ : Finset (Finset α) := image (insert a) (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
hℬ : card ℬ = card (shatterer (memberSubfamily a 𝒜) ∩ shatterer (nonMemberSubfamily a 𝒜))
s t : Finset α
ht : t ⊆ insert a s
hs : Shatters (memberSubfamily a 𝒜) s ∧ Shatters (nonMemberSubfamily a 𝒜) s
⊢ ∃ u ∈ 𝒜, insert a s ∩ u = t

Next tactic:
rw [subset_insert_iff] at ht