l3lab/ntp-mathlib huggingface dataset:
theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
    ∃ (f : α → β), BijOn f s t := by
  obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; 

Proof state:
case intro.intro
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f✝ : α → β
inst✝ : Nonempty β
hs : Set.Finite s
h : encard s = encard t
f : α → β
hf : s ⊆ f ⁻¹' t
hinj : InjOn f s
⊢ ∃ f, BijOn f s t

Next tactic:
use f
theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
    ∃ (f : α → β), BijOn f s t := by
  obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f
  

Proof state:
case h
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f✝ : α → β
inst✝ : Nonempty β
hs : Set.Finite s
h : encard s = encard t
f : α → β
hf : s ⊆ f ⁻¹' t
hinj : InjOn f s
⊢ BijOn f s t

Next tactic:
convert hinj.bijOn_image
theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
    ∃ (f : α → β), BijOn f s t := by
  obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f
  convert hinj.bijOn_image
  

Proof state:
case h.e'_5
α : Type u_2
β : Type u_1
s✝ t✝ s : Set α
t : Set β
f✝ : α → β
inst✝ : Nonempty β
hs : Set.Finite s
h : encard s = encard t
f : α → β
hf : s ⊆ f ⁻¹' t
hinj : InjOn f s
⊢ t = f '' s

Next tactic:
rw [(hs.image f).eq_of_subset_of_encard_le' (image_subset_iff.mpr hf)
    (h.symm.trans hinj.encard_image.symm).le]
theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
  

Proof state:
α : Type u_1
s t : Set α
hs : Set.Finite s
⊢ ↑(ncard s) = encard s

Next tactic:
rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not]
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
⊢ Nat.card ↑s = ncard s

Next tactic:
obtain (h | h) := s.finite_or_infinite
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
  obtain (h | h) := s.finite_or_infinite
  · 

Proof state:
case inl
α : Type u_1
s✝ t s : Set α
h : Set.Finite s
⊢ Nat.card ↑s = ncard s

Next tactic:
have := h.fintype
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
  obtain (h | h) := s.finite_or_infinite
  · have := h.fintype
    

Proof state:
case inl
α : Type u_1
s✝ t s : Set α
h : Set.Finite s
this : Fintype ↑s
⊢ Nat.card ↑s = ncard s

Next tactic:
rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
      toFinite_toFinset, toFinset_card, ENat.toNat_coe]
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
  obtain (h | h) := s.finite_or_infinite
  · have := h.fintype
    rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
      toFinite_toFinset, toFinset_card, ENat.toNat_coe]
  

Proof state:
case inr
α : Type u_1
s✝ t s : Set α
h : Set.Infinite s
⊢ Nat.card ↑s = ncard s

Next tactic:
have := infinite_coe_iff.2 h
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
  obtain (h | h) := s.finite_or_infinite
  · have := h.fintype
    rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
      toFinite_toFinset, toFinset_card, ENat.toNat_coe]
  have := infinite_coe_iff.2 h
  

Proof state:
case inr
α : Type u_1
s✝ t s : Set α
h : Set.Infinite s
this : Infinite ↑s
⊢ Nat.card ↑s = ncard s

Next tactic:
rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top]
theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) :
    s.ncard = hs.toFinset.card := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard s = Finset.card (Finite.toFinset hs)

Next tactic:
rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
    @Finite.card_toFinset _ _ hs.fintype hs]
theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] :
    s.ncard = s.toFinset.card := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
inst✝ : Fintype ↑s
⊢ ncard s = Finset.card (toFinset s)

Next tactic:
simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
  

Proof state:
α : Type u_1
s t : Set α
k : ℕ
⊢ encard s ≤ ↑k ↔ Set.Finite s ∧ ncard s ≤ k

Next tactic:
rw [encard_le_coe_iff, and_congr_right_iff]
theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
  rw [encard_le_coe_iff, and_congr_right_iff]
  

Proof state:
α : Type u_1
s t : Set α
k : ℕ
⊢ Set.Finite s → ((∃ n₀, encard s = ↑n₀ ∧ n₀ ≤ k) ↔ ncard s ≤ k)

Next tactic:
exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe],
    fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩
theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
  rw [encard_le_coe_iff, and_congr_right_iff]
  exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by 

Proof state:
α : Type u_1
s t : Set α
k : ℕ
hfin : Set.Finite s
x✝ : ∃ n₀, encard s = ↑n₀ ∧ n₀ ≤ k
n₀ : ℕ
hn₀ : encard s = ↑n₀
hle : n₀ ≤ k
⊢ ncard s ≤ k

Next tactic:
rwa [ncard_def, hn₀, ENat.toNat_coe]
theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
  rw [encard_le_coe_iff, and_congr_right_iff]
  exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe],
    fun h ↦ ⟨s.ncard, by 

Proof state:
α : Type u_1
s t : Set α
k : ℕ
hfin : Set.Finite s
h : ncard s ≤ k
⊢ encard s = ↑(ncard s)

Next tactic:
rw [hfin.cast_ncard_eq]
theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by
  

Proof state:
α : Type u_1
s t : Set α
hs : Set.Infinite s
⊢ Set.ncard s = 0

Next tactic:
rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
theorem ncard_le_of_subset (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
    s.ncard ≤ t.ncard := by
  

Proof state:
α : Type u_1
s t : Set α
hst : s ⊆ t
ht : autoParam (Set.Finite t) _auto✝
⊢ ncard s ≤ ncard t

Next tactic:
rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
theorem ncard_le_of_subset (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
    s.ncard ≤ t.ncard := by
  rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
  

Proof state:
α : Type u_1
s t : Set α
hst : s ⊆ t
ht : autoParam (Set.Finite t) _auto✝
⊢ encard s ≤ encard t

Next tactic:
exact encard_mono hst
@[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) :
    s.ncard = 0 ↔ s = ∅ := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard s = 0 ↔ s = ∅

Next tactic:
rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero]
@[simp] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by
  

Proof state:
α : Type u_1
s✝ t : Set α
s : Finset α
⊢ ncard ↑s = Finset.card s

Next tactic:
rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset]
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
  

Proof state:
α✝ : Type ?u.168346
s t : Set α✝
α : Type u_1
⊢ ncard univ = Nat.card α

Next tactic:
cases' finite_or_infinite α with h h
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
  cases' finite_or_infinite α with h h
  · 

Proof state:
case inl
α✝ : Type ?u.168346
s t : Set α✝
α : Type u_1
h : Finite α
⊢ ncard univ = Nat.card α

Next tactic:
have hft := Fintype.ofFinite α
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
  cases' finite_or_infinite α with h h
  · have hft := Fintype.ofFinite α
    

Proof state:
case inl
α✝ : Type ?u.168346
s t : Set α✝
α : Type u_1
h : Finite α
hft : Fintype α
⊢ ncard univ = Nat.card α

Next tactic:
rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
  cases' finite_or_infinite α with h h
  · have hft := Fintype.ofFinite α
    rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
  

Proof state:
case inr
α✝ : Type ?u.168346
s t : Set α✝
α : Type u_1
h : Infinite α
⊢ ncard univ = Nat.card α

Next tactic:
rw [Nat.card_eq_zero_of_infinite, Infinite.ncard]
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
  cases' finite_or_infinite α with h h
  · have hft := Fintype.ofFinite α
    rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
  rw [Nat.card_eq_zero_of_infinite, Infinite.ncard]
  

Proof state:
case inr
α✝ : Type ?u.168346
s t : Set α✝
α : Type u_1
h : Infinite α
⊢ Set.Infinite univ

Next tactic:
exact infinite_univ
@[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by
  

Proof state:
α✝ : Type ?u.169810
s t : Set α✝
α : Type u_1
⊢ ncard ∅ = 0

Next tactic:
rw [ncard_eq_zero]
theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ 0 < ncard s ↔ Set.Nonempty s

Next tactic:
rw [pos_iff_ne_zero, Ne.def, ncard_eq_zero hs, nonempty_iff_ne_empty]
theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
  

Proof state:
α : Type u_1
s t : Set α
hs : ncard s ≠ 0
⊢ Set.Nonempty s

Next tactic:
rw [nonempty_iff_ne_empty]
theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
  rw [nonempty_iff_ne_empty]; 

Proof state:
α : Type u_1
s t : Set α
hs : ncard s ≠ 0
⊢ s ≠ ∅

Next tactic:
rintro rfl
theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
  rw [nonempty_iff_ne_empty]; rintro rfl; 

Proof state:
α : Type u_1
t : Set α
hs : ncard ∅ ≠ 0
⊢ False

Next tactic:
simp at hs
@[simp] theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by
  

Proof state:
α : Type u_1
s t : Set α
a : α
⊢ ncard {a} = 1

Next tactic:
simp [ncard, ncard_eq_toFinset_card]
theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by
  

Proof state:
α : Type u_1
s✝ t : Set α
a : α
s : Set α
⊢ ncard ({a} ∩ s) ≤ 1

Next tactic:
rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one]
theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by
  rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one]
  

Proof state:
α : Type u_1
s✝ t : Set α
a : α
s : Set α
⊢ encard ({a} ∩ s) ≤ 1

Next tactic:
apply encard_singleton_inter
@[simp] theorem ncard_insert_of_not_mem (h : a ∉ s) (hs : s.Finite := by toFinite_tac) :
    (insert a s).ncard = s.ncard + 1 := by
  

Proof state:
α : Type u_1
s t : Set α
a : α
h : a ∉ s
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard (insert a s) = ncard s + 1

Next tactic:
rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one,
    hs.cast_ncard_eq, encard_insert_of_not_mem h]
theorem ncard_insert_of_mem (h : a ∈ s) : ncard (insert a s) = s.ncard := by
    

Proof state:
α : Type u_1
s t : Set α
a : α
h : a ∈ s
⊢ ncard (insert a s) = ncard s

Next tactic:
rw [insert_eq_of_mem h]
theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
  

Proof state:
α : Type u_1
s✝ t : Set α
a : α
s : Set α
⊢ ncard (insert a s) ≤ ncard s + 1

Next tactic:
obtain hs | hs := s.finite_or_infinite
theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
  obtain hs | hs := s.finite_or_infinite
  · 

Proof state:
case inl
α : Type u_1
s✝ t : Set α
a : α
s : Set α
hs : Set.Finite s
⊢ ncard (insert a s) ≤ ncard s + 1

Next tactic:
to_encard_tac
theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
  obtain hs | hs := s.finite_or_infinite
  · to_encard_tac; 

Proof state:
case inl
α : Type u_1
s✝ t : Set α
a : α
s : Set α
hs : Set.Finite s
⊢ ↑(ncard (insert a s)) ≤ ↑(ncard s) + 1

Next tactic:
rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]
theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
  obtain hs | hs := s.finite_or_infinite
  · to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; 

Proof state:
case inl
α : Type u_1
s✝ t : Set α
a : α
s : Set α
hs : Set.Finite s
⊢ encard (insert a s) ≤ encard s + 1

Next tactic:
apply encard_insert_le
theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
  obtain hs | hs := s.finite_or_infinite
  · to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le
  

Proof state:
case inr
α : Type u_1
s✝ t : Set α
a : α
s : Set α
hs : Set.Infinite s
⊢ ncard (insert a s) ≤ ncard s + 1

Next tactic:
rw [(hs.mono (subset_insert a s)).ncard]
theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
  obtain hs | hs := s.finite_or_infinite
  · to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le
  rw [(hs.mono (subset_insert a s)).ncard]
  

Proof state:
case inr
α : Type u_1
s✝ t : Set α
a : α
s : Set α
hs : Set.Infinite s
⊢ 0 ≤ ncard s + 1

Next tactic:
exact Nat.zero_le _
theorem ncard_insert_eq_ite [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) :
    ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by
  

Proof state:
α : Type u_1
s t : Set α
a : α
inst✝ : Decidable (a ∈ s)
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard (insert a s) = if a ∈ s then ncard s else ncard s + 1

Next tactic:
by_cases h : a ∈ s
theorem ncard_insert_eq_ite [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) :
    ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by
  by_cases h : a ∈ s
  · 

Proof state:
case pos
α : Type u_1
s t : Set α
a : α
inst✝ : Decidable (a ∈ s)
hs : autoParam (Set.Finite s) _auto✝
h : a ∈ s
⊢ ncard (insert a s) = if a ∈ s then ncard s else ncard s + 1

Next tactic:
rw [ncard_insert_of_mem h, if_pos h]
theorem ncard_insert_eq_ite [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) :
    ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by
  by_cases h : a ∈ s
  · rw [ncard_insert_of_mem h, if_pos h]
  · 

Proof state:
case neg
α : Type u_1
s t : Set α
a : α
inst✝ : Decidable (a ∈ s)
hs : autoParam (Set.Finite s) _auto✝
h : a ∉ s
⊢ ncard (insert a s) = if a ∈ s then ncard s else ncard s + 1

Next tactic:
rw [ncard_insert_of_not_mem h hs, if_neg h]
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
  

Proof state:
α : Type u_1
s✝ t : Set α
a : α
s : Set α
⊢ ncard s ≤ ncard (insert a s)

Next tactic:
classical
  refine'
    s.finite_or_infinite.elim (fun h ↦ _) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _))
  rw [ncard_insert_eq_ite h]; split_ifs <;> simp
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
  classical
  

Proof state:
α : Type u_1
s✝ t : Set α
a : α
s : Set α
⊢ ncard s ≤ ncard (insert a s)

Next tactic:
refine'
    s.finite_or_infinite.elim (fun h ↦ _) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _))
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
  classical
  refine'
    s.finite_or_infinite.elim (fun h ↦ _) (fun h ↦ by (

Proof state:
α : Type u_1
s✝ t : Set α
a : α
s : Set α
h : Set.Infinite s
⊢ ncard s ≤ ncard (insert a s)

Next tactic:
rw [h.ncard]
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
  classical
  refine'
    s.finite_or_infinite.elim (fun h ↦ _) (fun h ↦ by (rw [h.ncard]; 

Proof state:
α : Type u_1
s✝ t : Set α
a : α
s : Set α
h : Set.Infinite s
⊢ 0 ≤ ncard (insert a s)

Next tactic:
exact Nat.zero_le _
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
  classical
  refine'
    s.finite_or_infinite.elim (fun h ↦ _) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _))
  

Proof state:
α : Type u_1
s✝ t : Set α
a : α
s : Set α
h : Set.Finite s
⊢ ncard s ≤ ncard (insert a s)

Next tactic:
rw [ncard_insert_eq_ite h]
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
  classical
  refine'
    s.finite_or_infinite.elim (fun h ↦ _) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _))
  rw [ncard_insert_eq_ite h]; 

Proof state:
α : Type u_1
s✝ t : Set α
a : α
s : Set α
h : Set.Finite s
⊢ ncard s ≤ if a ∈ s then ncard s else ncard s + 1

Next tactic:
split_ifs
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
  classical
  refine'
    s.finite_or_infinite.elim (fun h ↦ _) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _))
  rw [ncard_insert_eq_ite h]; split_ifs <;> 

Proof state:
case pos
α : Type u_1
s✝ t : Set α
a : α
s : Set α
h : Set.Finite s
h✝ : a ∈ s
⊢ ncard s ≤ ncard s

Next tactic:
simp
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
  classical
  refine'
    s.finite_or_infinite.elim (fun h ↦ _) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _))
  rw [ncard_insert_eq_ite h]; split_ifs <;> 

Proof state:
case neg
α : Type u_1
s✝ t : Set α
a : α
s : Set α
h : Set.Finite s
h✝ : a ∉ s
⊢ ncard s ≤ ncard s + 1

Next tactic:
simp
@[simp] theorem ncard_pair (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
  

Proof state:
α : Type u_1
s t : Set α
a b : α
h : a ≠ b
⊢ ncard {a, b} = 2

Next tactic:
rw [ncard_insert_of_not_mem, ncard_singleton]
@[simp] theorem ncard_pair (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
  rw [ncard_insert_of_not_mem, ncard_singleton]; 

Proof state:
α : Type u_1
s t : Set α
a b : α
h : a ≠ b
⊢ a ∉ {b}

Next tactic:
simpa
@[simp] theorem ncard_diff_singleton_add_one (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
    (s \ {a}).ncard + 1 = s.ncard := by
  

Proof state:
α : Type u_1
s t : Set α
a : α
h : a ∈ s
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard (s \ {a}) + 1 = ncard s

Next tactic:
to_encard_tac
@[simp] theorem ncard_diff_singleton_add_one (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
    (s \ {a}).ncard + 1 = s.ncard := by
  to_encard_tac; 

Proof state:
α : Type u_1
s t : Set α
a : α
h : a ∈ s
hs : autoParam (Set.Finite s) _auto✝
⊢ ↑(ncard (s \ {a})) + 1 = ↑(ncard s)

Next tactic:
rw [hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq,
    encard_diff_singleton_add_one h]
theorem ncard_diff_singleton_lt_of_mem (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
    (s \ {a}).ncard < s.ncard := by
  

Proof state:
α : Type u_1
s t : Set α
a : α
h : a ∈ s
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard (s \ {a}) < ncard s

Next tactic:
rw [← ncard_diff_singleton_add_one h hs]
theorem ncard_diff_singleton_lt_of_mem (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
    (s \ {a}).ncard < s.ncard := by
  rw [← ncard_diff_singleton_add_one h hs]; 

Proof state:
α : Type u_1
s t : Set α
a : α
h : a ∈ s
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard (s \ {a}) < ncard (s \ {a}) + 1

Next tactic:
apply lt_add_one
theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
a : α
⊢ ncard (s \ {a}) ≤ ncard s

Next tactic:
obtain hs | hs := s.finite_or_infinite
theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
  obtain hs | hs := s.finite_or_infinite
  · 

Proof state:
case inl
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Finite s
⊢ ncard (s \ {a}) ≤ ncard s

Next tactic:
apply ncard_le_of_subset (diff_subset _ _) hs
theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
  obtain hs | hs := s.finite_or_infinite
  · apply ncard_le_of_subset (diff_subset _ _) hs
  

Proof state:
case inr
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Infinite s
⊢ ncard (s \ {a}) ≤ ncard s

Next tactic:
convert @zero_le ℕ _ _
theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
  obtain hs | hs := s.finite_or_infinite
  · apply ncard_le_of_subset (diff_subset _ _) hs
  convert @zero_le ℕ _ _
  

Proof state:
case h.e'_3
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Infinite s
⊢ ncard (s \ {a}) = 0

Next tactic:
exact (hs.diff (by simp : Set.Finite {a})).ncard
theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
  obtain hs | hs := s.finite_or_infinite
  · apply ncard_le_of_subset (diff_subset _ _) hs
  convert @zero_le ℕ _ _
  exact (hs.diff (by 

Proof state:
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Infinite s
⊢ Set.Finite {a}

Next tactic:
simp
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
  

Proof state:
α : Type u_1
s✝ t s : Set α
a : α
⊢ ncard s - 1 ≤ ncard (s \ {a})

Next tactic:
cases' s.finite_or_infinite with hs hs
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
  cases' s.finite_or_infinite with hs hs
  · 

Proof state:
case inl
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Finite s
⊢ ncard s - 1 ≤ ncard (s \ {a})

Next tactic:
by_cases h : a ∈ s
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
  cases' s.finite_or_infinite with hs hs
  · by_cases h : a ∈ s
    · 

Proof state:
case pos
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Finite s
h : a ∈ s
⊢ ncard s - 1 ≤ ncard (s \ {a})

Next tactic:
rw [ncard_diff_singleton_of_mem h hs]
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
  cases' s.finite_or_infinite with hs hs
  · by_cases h : a ∈ s
    · rw [ncard_diff_singleton_of_mem h hs]
    

Proof state:
case neg
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Finite s
h : a ∉ s
⊢ ncard s - 1 ≤ ncard (s \ {a})

Next tactic:
rw [diff_singleton_eq_self h]
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
  cases' s.finite_or_infinite with hs hs
  · by_cases h : a ∈ s
    · rw [ncard_diff_singleton_of_mem h hs]
    rw [diff_singleton_eq_self h]
    

Proof state:
case neg
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Finite s
h : a ∉ s
⊢ ncard s - 1 ≤ ncard s

Next tactic:
apply Nat.pred_le
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
  cases' s.finite_or_infinite with hs hs
  · by_cases h : a ∈ s
    · rw [ncard_diff_singleton_of_mem h hs]
    rw [diff_singleton_eq_self h]
    apply Nat.pred_le
  

Proof state:
case inr
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Infinite s
⊢ ncard s - 1 ≤ ncard (s \ {a})

Next tactic:
convert Nat.zero_le _
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
  cases' s.finite_or_infinite with hs hs
  · by_cases h : a ∈ s
    · rw [ncard_diff_singleton_of_mem h hs]
    rw [diff_singleton_eq_self h]
    apply Nat.pred_le
  convert Nat.zero_le _
  

Proof state:
case h.e'_3
α : Type u_1
s✝ t s : Set α
a : α
hs : Set.Infinite s
⊢ ncard s - 1 = 0

Next tactic:
rw [hs.ncard]
theorem ncard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard = s.ncard := by
  

Proof state:
α : Type u_1
s t : Set α
a b : α
ha : a ∉ s
hb : b ∈ s
⊢ ncard (insert a s \ {b}) = ncard s

Next tactic:
rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib,
    @diff_singleton_eq_self _ b {a} fun h ↦ ha (by rwa [← mem_singleton_iff.mp h])]
theorem ncard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard = s.ncard := by
  rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib,
    @diff_singleton_eq_self _ b {a} fun h ↦ ha (by 

Proof state:
α : Type u_1
s t : Set α
a b : α
ha : a ∉ s
hb : b ∈ s
h : b ∈ {a}
⊢ a ∈ s

Next tactic:
rwa [← mem_singleton_iff.mp h]
theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by
  

Proof state:
α : Type u_2
s t : Set α
α✝ : Type u_1
f : α → α✝
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard (f '' s) ≤ ncard s

Next tactic:
to_encard_tac
theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by
  to_encard_tac; 

Proof state:
α : Type u_2
s t : Set α
α✝ : Type u_1
f : α → α✝
hs : autoParam (Set.Finite s) _auto✝
⊢ ↑(ncard (f '' s)) ≤ ↑(ncard s)

Next tactic:
rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]
theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by
  to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; 

Proof state:
α : Type u_2
s t : Set α
α✝ : Type u_1
f : α → α✝
hs : autoParam (Set.Finite s) _auto✝
⊢ encard (f '' s) ≤ encard s

Next tactic:
apply encard_image_le