l3lab/ntp-mathlib huggingface dataset:
theorem eq_finite_iUnion_of_finite_subset_iUnion {ι} {s : ι → Set α} {t : Set α} (tfin : t.Finite)
    (h : t ⊆ ⋃ i, s i) :
    ∃ I : Set ι,
      I.Finite ∧
        ∃ σ : { i | i ∈ I } → Set α, (∀ i, (σ i).Finite) ∧ (∀ i, σ i ⊆ s i) ∧ t = ⋃ i, σ i :=
  let ⟨I, Ifin, hI⟩ := finite_subset_iUnion tfin h
  ⟨I, Ifin, fun x => s x ∩ t, fun i => tfin.subset (inter_subset_right _ _), fun i =>
    inter_subset_left _ _, by
    ext x
    rw [mem_iUnion]
    constructor
    · intro x_in
      rcases mem_iUnion.mp (hI x_in) with ⟨i, _, ⟨hi, rfl⟩, H⟩
      

Proof state:
case h.mp.intro.intro.intro.intro
α : Type u
β : Type v
ι✝ : Sort w
γ : Type x
ι : Type u_1
s : ι → Set α
t : Set α
tfin : Set.Finite t
h : t ⊆ ⋃ i, s i
I : Set ι
Ifin : Set.Finite I
hI : t ⊆ ⋃ i ∈ I, s i
x : α
x_in : x ∈ t
i : ι
hi : i ∈ I
H : x ∈ (fun h => s i) hi
⊢ ∃ i, x ∈ (fun x => s ↑x ∩ t) i

Next tactic:
refine' ⟨⟨i, hi⟩, ⟨H, x_in⟩⟩
theorem eq_finite_iUnion_of_finite_subset_iUnion {ι} {s : ι → Set α} {t : Set α} (tfin : t.Finite)
    (h : t ⊆ ⋃ i, s i) :
    ∃ I : Set ι,
      I.Finite ∧
        ∃ σ : { i | i ∈ I } → Set α, (∀ i, (σ i).Finite) ∧ (∀ i, σ i ⊆ s i) ∧ t = ⋃ i, σ i :=
  let ⟨I, Ifin, hI⟩ := finite_subset_iUnion tfin h
  ⟨I, Ifin, fun x => s x ∩ t, fun i => tfin.subset (inter_subset_right _ _), fun i =>
    inter_subset_left _ _, by
    ext x
    rw [mem_iUnion]
    constructor
    · intro x_in
      rcases mem_iUnion.mp (hI x_in) with ⟨i, _, ⟨hi, rfl⟩, H⟩
      refine' ⟨⟨i, hi⟩, ⟨H, x_in⟩⟩
    · 

Proof state:
case h.mpr
α : Type u
β : Type v
ι✝ : Sort w
γ : Type x
ι : Type u_1
s : ι → Set α
t : Set α
tfin : Set.Finite t
h : t ⊆ ⋃ i, s i
I : Set ι
Ifin : Set.Finite I
hI : t ⊆ ⋃ i ∈ I, s i
x : α
⊢ (∃ i, x ∈ (fun x => s ↑x ∩ t) i) → x ∈ t

Next tactic:
rintro ⟨i, -, H⟩
theorem eq_finite_iUnion_of_finite_subset_iUnion {ι} {s : ι → Set α} {t : Set α} (tfin : t.Finite)
    (h : t ⊆ ⋃ i, s i) :
    ∃ I : Set ι,
      I.Finite ∧
        ∃ σ : { i | i ∈ I } → Set α, (∀ i, (σ i).Finite) ∧ (∀ i, σ i ⊆ s i) ∧ t = ⋃ i, σ i :=
  let ⟨I, Ifin, hI⟩ := finite_subset_iUnion tfin h
  ⟨I, Ifin, fun x => s x ∩ t, fun i => tfin.subset (inter_subset_right _ _), fun i =>
    inter_subset_left _ _, by
    ext x
    rw [mem_iUnion]
    constructor
    · intro x_in
      rcases mem_iUnion.mp (hI x_in) with ⟨i, _, ⟨hi, rfl⟩, H⟩
      refine' ⟨⟨i, hi⟩, ⟨H, x_in⟩⟩
    · rintro ⟨i, -, H⟩
      

Proof state:
case h.mpr.intro.intro
α : Type u
β : Type v
ι✝ : Sort w
γ : Type x
ι : Type u_1
s : ι → Set α
t : Set α
tfin : Set.Finite t
h : t ⊆ ⋃ i, s i
I : Set ι
Ifin : Set.Finite I
hI : t ⊆ ⋃ i ∈ I, s i
x : α
i : ↑{i | i ∈ I}
H : x ∈ t
⊢ x ∈ t

Next tactic:
exact H
@[elab_as_elim]
theorem Finite.induction_on {C : Set α → Prop} {s : Set α} (h : s.Finite) (H0 : C ∅)
    (H1 : ∀ {a s}, a ∉ s → Set.Finite s → C s → C (insert a s)) : C s := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
C : Set α → Prop
s : Set α
h : Set.Finite s
H0 : C ∅
H1 : ∀ {a : α} {s : Set α}, a ∉ s → Set.Finite s → C s → C (insert a s)
⊢ C s

Next tactic:
lift s to Finset α using h
@[elab_as_elim]
theorem Finite.induction_on {C : Set α → Prop} {s : Set α} (h : s.Finite) (H0 : C ∅)
    (H1 : ∀ {a s}, a ∉ s → Set.Finite s → C s → C (insert a s)) : C s := by
  lift s to Finset α using h
  

Proof state:
case intro
α : Type u
β : Type v
ι : Sort w
γ : Type x
C : Set α → Prop
H0 : C ∅
H1 : ∀ {a : α} {s : Set α}, a ∉ s → Set.Finite s → C s → C (insert a s)
s : Finset α
⊢ C ↑s

Next tactic:
induction' s using Finset.cons_induction_on with a s ha hs
@[elab_as_elim]
theorem Finite.induction_on {C : Set α → Prop} {s : Set α} (h : s.Finite) (H0 : C ∅)
    (H1 : ∀ {a s}, a ∉ s → Set.Finite s → C s → C (insert a s)) : C s := by
  lift s to Finset α using h
  induction' s using Finset.cons_induction_on with a s ha hs
  · 

Proof state:
case intro.h₁
α : Type u
β : Type v
ι : Sort w
γ : Type x
C : Set α → Prop
H0 : C ∅
H1 : ∀ {a : α} {s : Set α}, a ∉ s → Set.Finite s → C s → C (insert a s)
⊢ C ↑∅

Next tactic:
rwa [Finset.coe_empty]
@[elab_as_elim]
theorem Finite.induction_on {C : Set α → Prop} {s : Set α} (h : s.Finite) (H0 : C ∅)
    (H1 : ∀ {a s}, a ∉ s → Set.Finite s → C s → C (insert a s)) : C s := by
  lift s to Finset α using h
  induction' s using Finset.cons_induction_on with a s ha hs
  · rwa [Finset.coe_empty]
  · 

Proof state:
case intro.h₂
α : Type u
β : Type v
ι : Sort w
γ : Type x
C : Set α → Prop
H0 : C ∅
H1 : ∀ {a : α} {s : Set α}, a ∉ s → Set.Finite s → C s → C (insert a s)
a : α
s : Finset α
ha : a ∉ s
hs : C ↑s
⊢ C ↑(Finset.cons a s ha)

Next tactic:
rw [Finset.coe_cons]
@[elab_as_elim]
theorem Finite.induction_on {C : Set α → Prop} {s : Set α} (h : s.Finite) (H0 : C ∅)
    (H1 : ∀ {a s}, a ∉ s → Set.Finite s → C s → C (insert a s)) : C s := by
  lift s to Finset α using h
  induction' s using Finset.cons_induction_on with a s ha hs
  · rwa [Finset.coe_empty]
  · rw [Finset.coe_cons]
    

Proof state:
case intro.h₂
α : Type u
β : Type v
ι : Sort w
γ : Type x
C : Set α → Prop
H0 : C ∅
H1 : ∀ {a : α} {s : Set α}, a ∉ s → Set.Finite s → C s → C (insert a s)
a : α
s : Finset α
ha : a ∉ s
hs : C ↑s
⊢ C (insert a ↑s)

Next tactic:
exact @H1 a s ha (Set.toFinite _) hs
/-- Analogous to `Finset.induction_on'`. -/
@[elab_as_elim]
theorem Finite.induction_on' {C : Set α → Prop} {S : Set α} (h : S.Finite) (H0 : C ∅)
    (H1 : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)) : C S := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
C : Set α → Prop
S : Set α
h : Set.Finite S
H0 : C ∅
H1 : ∀ {a : α} {s : Set α}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)
⊢ C S

Next tactic:
refine' @Set.Finite.induction_on α (fun s => s ⊆ S → C s) S h (fun _ => H0) _ Subset.rfl
/-- Analogous to `Finset.induction_on'`. -/
@[elab_as_elim]
theorem Finite.induction_on' {C : Set α → Prop} {S : Set α} (h : S.Finite) (H0 : C ∅)
    (H1 : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)) : C S := by
  refine' @Set.Finite.induction_on α (fun s => s ⊆ S → C s) S h (fun _ => H0) _ Subset.rfl
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
C : Set α → Prop
S : Set α
h : Set.Finite S
H0 : C ∅
H1 : ∀ {a : α} {s : Set α}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)
⊢ ∀ {a : α} {s : Set α}, a ∉ s → Set.Finite s → (fun s => s ⊆ S → C s) s → (fun s => s ⊆ S → C s) (insert a s)

Next tactic:
intro a s has _ hCs haS
/-- Analogous to `Finset.induction_on'`. -/
@[elab_as_elim]
theorem Finite.induction_on' {C : Set α → Prop} {S : Set α} (h : S.Finite) (H0 : C ∅)
    (H1 : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)) : C S := by
  refine' @Set.Finite.induction_on α (fun s => s ⊆ S → C s) S h (fun _ => H0) _ Subset.rfl
  intro a s has _ hCs haS
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
C : Set α → Prop
S : Set α
h : Set.Finite S
H0 : C ∅
H1 : ∀ {a : α} {s : Set α}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)
a : α
s : Set α
has : a ∉ s
a✝ : Set.Finite s
hCs : s ⊆ S → C s
haS : insert a s ⊆ S
⊢ C (insert a s)

Next tactic:
rw [insert_subset_iff] at haS
/-- Analogous to `Finset.induction_on'`. -/
@[elab_as_elim]
theorem Finite.induction_on' {C : Set α → Prop} {S : Set α} (h : S.Finite) (H0 : C ∅)
    (H1 : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)) : C S := by
  refine' @Set.Finite.induction_on α (fun s => s ⊆ S → C s) S h (fun _ => H0) _ Subset.rfl
  intro a s has _ hCs haS
  rw [insert_subset_iff] at haS
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
C : Set α → Prop
S : Set α
h : Set.Finite S
H0 : C ∅
H1 : ∀ {a : α} {s : Set α}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)
a : α
s : Set α
has : a ∉ s
a✝ : Set.Finite s
hCs : s ⊆ S → C s
haS : a ∈ S ∧ s ⊆ S
⊢ C (insert a s)

Next tactic:
exact H1 haS.1 haS.2 has (hCs haS.2)
/-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set
`t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.

(We use this later to show sequentially compact sets are totally bounded.)
-/
theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop}
    (h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ✝ : Type x
γ : Type u_1
P : γ → Set γ → Prop
h : ∀ (t : Set γ), Set.Finite t → ∃ c, P c t
⊢ ∃ u, ∀ (n : ℕ), P (u n) (u '' Iio n)

Next tactic:
haveI : Nonempty γ := (h ∅ finite_empty).nonempty
/-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set
`t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.

(We use this later to show sequentially compact sets are totally bounded.)
-/
theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop}
    (h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by
  haveI : Nonempty γ := (h ∅ finite_empty).nonempty
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ✝ : Type x
γ : Type u_1
P : γ → Set γ → Prop
h : ∀ (t : Set γ), Set.Finite t → ∃ c, P c t
this : Nonempty γ
⊢ ∃ u, ∀ (n : ℕ), P (u n) (u '' Iio n)

Next tactic:
choose! c hc using h
/-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set
`t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.

(We use this later to show sequentially compact sets are totally bounded.)
-/
theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop}
    (h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by
  haveI : Nonempty γ := (h ∅ finite_empty).nonempty
  choose! c hc using h
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ✝ : Type x
γ : Type u_1
P : γ → Set γ → Prop
this : Nonempty γ
c : Set γ → γ
hc : ∀ (t : Set γ), Set.Finite t → P (c t) t
⊢ ∃ u, ∀ (n : ℕ), P (u n) (u '' Iio n)

Next tactic:
set f : (n : ℕ) → (g : (m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k : Iio n => g k.1 k.2)
/-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set
`t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.

(We use this later to show sequentially compact sets are totally bounded.)
-/
theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop}
    (h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by
  haveI : Nonempty γ := (h ∅ finite_empty).nonempty
  choose! c hc using h
  set f : (n : ℕ) → (g : (m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k : Iio n => g k.1 k.2)
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ✝ : Type x
γ : Type u_1
P : γ → Set γ → Prop
this : Nonempty γ
c : Set γ → γ
hc : ∀ (t : Set γ), Set.Finite t → P (c t) t
f : (n : ℕ) → ((m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k => g ↑k (_ : ↑k ∈ Iio n))
⊢ ∃ u, ∀ (n : ℕ), P (u n) (u '' Iio n)

Next tactic:
set u : ℕ → γ := fun n => Nat.strongRecOn' n f
/-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set
`t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.

(We use this later to show sequentially compact sets are totally bounded.)
-/
theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop}
    (h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by
  haveI : Nonempty γ := (h ∅ finite_empty).nonempty
  choose! c hc using h
  set f : (n : ℕ) → (g : (m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k : Iio n => g k.1 k.2)
  set u : ℕ → γ := fun n => Nat.strongRecOn' n f
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ✝ : Type x
γ : Type u_1
P : γ → Set γ → Prop
this : Nonempty γ
c : Set γ → γ
hc : ∀ (t : Set γ), Set.Finite t → P (c t) t
f : (n : ℕ) → ((m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k => g ↑k (_ : ↑k ∈ Iio n))
u : ℕ → γ := fun n => Nat.strongRecOn' n f
⊢ ∃ u, ∀ (n : ℕ), P (u n) (u '' Iio n)

Next tactic:
refine' ⟨u, fun n => _⟩
/-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set
`t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.

(We use this later to show sequentially compact sets are totally bounded.)
-/
theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop}
    (h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by
  haveI : Nonempty γ := (h ∅ finite_empty).nonempty
  choose! c hc using h
  set f : (n : ℕ) → (g : (m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k : Iio n => g k.1 k.2)
  set u : ℕ → γ := fun n => Nat.strongRecOn' n f
  refine' ⟨u, fun n => _⟩
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ✝ : Type x
γ : Type u_1
P : γ → Set γ → Prop
this : Nonempty γ
c : Set γ → γ
hc : ∀ (t : Set γ), Set.Finite t → P (c t) t
f : (n : ℕ) → ((m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k => g ↑k (_ : ↑k ∈ Iio n))
u : ℕ → γ := fun n => Nat.strongRecOn' n f
n : ℕ
⊢ P (u n) (u '' Iio n)

Next tactic:
convert hc (u '' Iio n) ((finite_lt_nat _).image _)
/-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set
`t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.

(We use this later to show sequentially compact sets are totally bounded.)
-/
theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop}
    (h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by
  haveI : Nonempty γ := (h ∅ finite_empty).nonempty
  choose! c hc using h
  set f : (n : ℕ) → (g : (m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k : Iio n => g k.1 k.2)
  set u : ℕ → γ := fun n => Nat.strongRecOn' n f
  refine' ⟨u, fun n => _⟩
  convert hc (u '' Iio n) ((finite_lt_nat _).image _)
  

Proof state:
case h.e'_1
α : Type u
β : Type v
ι : Sort w
γ✝ : Type x
γ : Type u_1
P : γ → Set γ → Prop
this : Nonempty γ
c : Set γ → γ
hc : ∀ (t : Set γ), Set.Finite t → P (c t) t
f : (n : ℕ) → ((m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k => g ↑k (_ : ↑k ∈ Iio n))
u : ℕ → γ := fun n => Nat.strongRecOn' n f
n : ℕ
⊢ u n = c (u '' Iio n)

Next tactic:
rw [image_eq_range]
/-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set
`t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.

(We use this later to show sequentially compact sets are totally bounded.)
-/
theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop}
    (h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by
  haveI : Nonempty γ := (h ∅ finite_empty).nonempty
  choose! c hc using h
  set f : (n : ℕ) → (g : (m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k : Iio n => g k.1 k.2)
  set u : ℕ → γ := fun n => Nat.strongRecOn' n f
  refine' ⟨u, fun n => _⟩
  convert hc (u '' Iio n) ((finite_lt_nat _).image _)
  rw [image_eq_range]
  

Proof state:
case h.e'_1
α : Type u
β : Type v
ι : Sort w
γ✝ : Type x
γ : Type u_1
P : γ → Set γ → Prop
this : Nonempty γ
c : Set γ → γ
hc : ∀ (t : Set γ), Set.Finite t → P (c t) t
f : (n : ℕ) → ((m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k => g ↑k (_ : ↑k ∈ Iio n))
u : ℕ → γ := fun n => Nat.strongRecOn' n f
n : ℕ
⊢ u n = c (range fun x => u ↑x)

Next tactic:
exact Nat.strongRecOn'_beta
theorem empty_card' {h : Fintype.{u} (∅ : Set α)} : @Fintype.card (∅ : Set α) h = 0 :=
  by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
h : Fintype ↑∅
⊢ Fintype.card ↑∅ = 0

Next tactic:
simp
theorem card_fintypeInsertOfNotMem {a : α} (s : Set α) [Fintype s] (h : a ∉ s) :
    @Fintype.card _ (fintypeInsertOfNotMem s h) = Fintype.card s + 1 := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
a : α
s : Set α
inst✝ : Fintype ↑s
h : a ∉ s
⊢ Fintype.card ↑(insert a s) = Fintype.card ↑s + 1

Next tactic:
simp [fintypeInsertOfNotMem, Fintype.card_ofFinset]
@[simp]
theorem card_insert {a : α} (s : Set α) [Fintype s] (h : a ∉ s)
    {d : Fintype.{u} (insert a s : Set α)} : @Fintype.card _ d = Fintype.card s + 1 := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
a : α
s : Set α
inst✝ : Fintype ↑s
h : a ∉ s
d : Fintype ↑(insert a s)
⊢ Fintype.card ↑(insert a s) = Fintype.card ↑s + 1

Next tactic:
rw [← card_fintypeInsertOfNotMem s h]
@[simp]
theorem card_insert {a : α} (s : Set α) [Fintype s] (h : a ∉ s)
    {d : Fintype.{u} (insert a s : Set α)} : @Fintype.card _ d = Fintype.card s + 1 := by
  rw [← card_fintypeInsertOfNotMem s h]; 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
a : α
s : Set α
inst✝ : Fintype ↑s
h : a ∉ s
d : Fintype ↑(insert a s)
⊢ Fintype.card ↑(insert a s) = Fintype.card ↑(insert a s)

Next tactic:
congr
@[simp]
theorem card_insert {a : α} (s : Set α) [Fintype s] (h : a ∉ s)
    {d : Fintype.{u} (insert a s : Set α)} : @Fintype.card _ d = Fintype.card s + 1 := by
  rw [← card_fintypeInsertOfNotMem s h]; congr; 

Proof state:
case h.e_2.h
α : Type u
β : Type v
ι : Sort w
γ : Type x
a : α
s : Set α
inst✝ : Fintype ↑s
h : a ∉ s
d : Fintype ↑(insert a s)
⊢ d = fintypeInsertOfNotMem s h

Next tactic:
exact Subsingleton.elim _ _
theorem card_image_of_inj_on {s : Set α} [Fintype s] {f : α → β} [Fintype (f '' s)]
    (H : ∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y) : Fintype.card (f '' s) = Fintype.card s :=
  haveI := Classical.propDecidable
  calc
    Fintype.card (f '' s) = (s.toFinset.image f).card := Fintype.card_of_finset' _ (by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s : Set α
inst✝¹ : Fintype ↑s
f : α → β
inst✝ : Fintype ↑(f '' s)
H : ∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y
this : (a : Prop) → Decidable a
⊢ ∀ (x : β), x ∈ Finset.image f (toFinset s) ↔ x ∈ f '' s

Next tactic:
simp
theorem card_ne_eq [Fintype α] (a : α) [Fintype { x : α | x ≠ a }] :
    Fintype.card { x : α | x ≠ a } = Fintype.card α - 1 := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝¹ : Fintype α
a : α
inst✝ : Fintype ↑{x | x ≠ a}
⊢ Fintype.card ↑{x | x ≠ a} = Fintype.card α - 1

Next tactic:
haveI := Classical.decEq α
theorem card_ne_eq [Fintype α] (a : α) [Fintype { x : α | x ≠ a }] :
    Fintype.card { x : α | x ≠ a } = Fintype.card α - 1 := by
  haveI := Classical.decEq α
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝¹ : Fintype α
a : α
inst✝ : Fintype ↑{x | x ≠ a}
this : DecidableEq α
⊢ Fintype.card ↑{x | x ≠ a} = Fintype.card α - 1

Next tactic:
rw [← toFinset_card, toFinset_setOf, Finset.filter_ne',
    Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ]
theorem infinite_univ_iff : (@univ α).Infinite ↔ Infinite α := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s t : Set α
⊢ Set.Infinite univ ↔ Infinite α

Next tactic:
rw [Set.Infinite, finite_univ_iff, not_finite_iff_infinite]
lemma Infinite.exists_not_mem_finite (hs : s.Infinite) (ht : t.Finite) : ∃ a, a ∈ s ∧ a ∉ t := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s t : Set α
hs : Set.Infinite s
ht : Set.Finite t
⊢ ∃ a ∈ s, a ∉ t

Next tactic:
by_contra! h
lemma Infinite.exists_not_mem_finite (hs : s.Infinite) (ht : t.Finite) : ∃ a, a ∈ s ∧ a ∉ t := by
  by_contra! h; 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s t : Set α
hs : Set.Infinite s
ht : Set.Finite t
h : ∀ a ∈ s, a ∈ t
⊢ False

Next tactic:
exact hs $ ht.subset h
lemma Finite.exists_not_mem (hs : s.Finite) : ∃ a, a ∉ s := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s t : Set α
inst✝ : Infinite α
hs : Set.Finite s
⊢ ∃ a, a ∉ s

Next tactic:
by_contra! h
lemma Finite.exists_not_mem (hs : s.Finite) : ∃ a, a ∉ s := by
  by_contra! h; 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s t : Set α
inst✝ : Infinite α
hs : Set.Finite s
h : ∀ (a : α), a ∈ s
⊢ False

Next tactic:
exact infinite_univ (hs.subset fun a _ ↦ h _)
theorem Infinite.exists_subset_card_eq {s : Set α} (hs : s.Infinite) (n : ℕ) :
    ∃ t : Finset α, ↑t ⊆ s ∧ t.card = n :=
  ⟨((Finset.range n).map (hs.natEmbedding _)).map (Embedding.subtype _), by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t s : Set α
hs : Set.Infinite s
n : ℕ
⊢ ↑(Finset.map (Embedding.subtype fun x => x ∈ s) (Finset.map (natEmbedding s hs) (Finset.range n))) ⊆ s ∧
    Finset.card (Finset.map (Embedding.subtype fun x => x ∈ s) (Finset.map (natEmbedding s hs) (Finset.range n))) = n

Next tactic:
simp
theorem infinite_of_finite_compl [Infinite α] {s : Set α} (hs : sᶜ.Finite) : s.Infinite := fun h =>
  Set.infinite_univ (by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t : Set α
inst✝ : Infinite α
s : Set α
hs : Set.Finite sᶜ
h : Set.Finite s
⊢ Set.Finite univ

Next tactic:
simpa using hs.union h
theorem Finite.infinite_compl [Infinite α] {s : Set α} (hs : s.Finite) : sᶜ.Infinite := fun h =>
  Set.infinite_univ (by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t : Set α
inst✝ : Infinite α
s : Set α
hs : Set.Finite s
h : Set.Finite sᶜ
⊢ Set.Finite univ

Next tactic:
simpa using hs.union h
@[simp]
theorem infinite_union {s t : Set α} : (s ∪ t).Infinite ↔ s.Infinite ∨ t.Infinite := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t✝ s t : Set α
⊢ Set.Infinite (s ∪ t) ↔ Set.Infinite s ∨ Set.Infinite t

Next tactic:
simp only [Set.Infinite, finite_union, not_and_or]
theorem infinite_image2 (hfs : ∀ b ∈ t, InjOn (fun a => f a b) s) (hft : ∀ a ∈ s, InjOn (f a) t) :
    (image2 f s t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t✝ : Set α
f : α → β → γ
s : Set α
t : Set β
a : α
b : β
hfs : ∀ b ∈ t, InjOn (fun a => f a b) s
hft : ∀ a ∈ s, InjOn (f a) t
⊢ Set.Infinite (image2 f s t) ↔ Set.Infinite s ∧ Set.Nonempty t ∨ Set.Infinite t ∧ Set.Nonempty s

Next tactic:
refine' ⟨fun h => Set.infinite_prod.1 _, _⟩
theorem infinite_image2 (hfs : ∀ b ∈ t, InjOn (fun a => f a b) s) (hft : ∀ a ∈ s, InjOn (f a) t) :
    (image2 f s t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by
  refine' ⟨fun h => Set.infinite_prod.1 _, _⟩
  · 

Proof state:
case refine'_1
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t✝ : Set α
f : α → β → γ
s : Set α
t : Set β
a : α
b : β
hfs : ∀ b ∈ t, InjOn (fun a => f a b) s
hft : ∀ a ∈ s, InjOn (f a) t
h : Set.Infinite (image2 f s t)
⊢ Set.Infinite (s ×ˢ t)

Next tactic:
rw [← image_uncurry_prod] at h
theorem infinite_image2 (hfs : ∀ b ∈ t, InjOn (fun a => f a b) s) (hft : ∀ a ∈ s, InjOn (f a) t) :
    (image2 f s t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by
  refine' ⟨fun h => Set.infinite_prod.1 _, _⟩
  · rw [← image_uncurry_prod] at h
    

Proof state:
case refine'_1
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t✝ : Set α
f : α → β → γ
s : Set α
t : Set β
a : α
b : β
hfs : ∀ b ∈ t, InjOn (fun a => f a b) s
hft : ∀ a ∈ s, InjOn (f a) t
h : Set.Infinite (uncurry f '' s ×ˢ t)
⊢ Set.Infinite (s ×ˢ t)

Next tactic:
exact h.of_image _
theorem infinite_image2 (hfs : ∀ b ∈ t, InjOn (fun a => f a b) s) (hft : ∀ a ∈ s, InjOn (f a) t) :
    (image2 f s t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by
  refine' ⟨fun h => Set.infinite_prod.1 _, _⟩
  · rw [← image_uncurry_prod] at h
    exact h.of_image _
  · 

Proof state:
case refine'_2
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t✝ : Set α
f : α → β → γ
s : Set α
t : Set β
a : α
b : β
hfs : ∀ b ∈ t, InjOn (fun a => f a b) s
hft : ∀ a ∈ s, InjOn (f a) t
⊢ Set.Infinite s ∧ Set.Nonempty t ∨ Set.Infinite t ∧ Set.Nonempty s → Set.Infinite (image2 f s t)

Next tactic:
rintro (⟨hs, b, hb⟩ | ⟨ht, a, ha⟩)