Theorem: Finset.surj_on_of_inj_on_of_card_le
File: Mathlib/Data/Finset/Card.lean

tactic: classical
  intro b hb
  have h : (s.attach.image fun a : { a // a ∈ s } => f a a.prop).card = s.card :=
    @card_attach _ s ▸
      card_image_of_injective _ fun ⟨a₁, ha₁⟩ ⟨a₂, ha₂⟩ h => Subtype.eq <| hinj _ _ _ _ h
  have h' : image (fun a : { a // a ∈ s } => f a a.prop) s.attach = t :=
    eq_of_subset_of_card_le
      (fun b h =>
        let ⟨a, _, ha₂⟩ := mem_image.1 h
        ha₂ ▸ hf _ _)
      (by simp [hst, h])
  rw [← h'] at hb
  obtain ⟨a, _, ha₂⟩ := mem_image.1 hb
  exact ⟨a, a.2, ha₂.symm⟩
state_before: α : Type u_2
β : Type u_1
s t✝ : Finset α
f✝ : α → β
n : ℕ
t : Finset β
f : (a : α) → a ∈ s → β
hf : ∀ (a : α) (ha : a ∈ s), f a ha ∈ t
hinj : ∀ (a₁ a₂ : α) (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s), f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂
hst : card t ≤ card s
⊢ ∀ (b : β), b ∈ t → ∃ a ha, b = f a ha

tactic: intro b hb
state_before: α : Type u_2
β : Type u_1
s t✝ : Finset α
f✝ : α → β
n : ℕ
t : Finset β
f : (a : α) → a ∈ s → β
hf : ∀ (a : α) (ha : a ∈ s), f a ha ∈ t
hinj : ∀ (a₁ a₂ : α) (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s), f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂
hst : card t ≤ card s
⊢ ∀ (b : β), b ∈ t → ∃ a ha, b = f a ha

tactic: have h : (s.attach.image fun a : { a // a ∈ s } => f a a.prop).card = s.card :=
  @card_attach _ s ▸
    card_image_of_injective _ fun ⟨a₁, ha₁⟩ ⟨a₂, ha₂⟩ h => Subtype.eq <| hinj _ _ _ _ h
state_before: α : Type u_2
β : Type u_1
s t✝ : Finset α
f✝ : α → β
n : ℕ
t : Finset β
f : (a : α) → a ∈ s → β
hf : ∀ (a : α) (ha : a ∈ s), f a ha ∈ t
hinj : ∀ (a₁ a₂ : α) (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s), f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂
hst : card t ≤ card s
b : β
hb : b ∈ t
⊢ ∃ a ha, b = f a ha

tactic: have h' : image (fun a : { a // a ∈ s } => f a a.prop) s.attach = t :=
  eq_of_subset_of_card_le
    (fun b h =>
      let ⟨a, _, ha₂⟩ := mem_image.1 h
      ha₂ ▸ hf _ _)
    (by simp [hst, h])
state_before: α : Type u_2
β : Type u_1
s t✝ : Finset α
f✝ : α → β
n : ℕ
t : Finset β
f : (a : α) → a ∈ s → β
hf : ∀ (a : α) (ha : a ∈ s), f a ha ∈ t
hinj : ∀ (a₁ a₂ : α) (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s), f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂
hst : card t ≤ card s
b : β
hb : b ∈ t
h : card (image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s)) = card s
⊢ ∃ a ha, b = f a ha

tactic: rw [← h'] at hb
state_before: α : Type u_2
β : Type u_1
s t✝ : Finset α
f✝ : α → β
n : ℕ
t : Finset β
f : (a : α) → a ∈ s → β
hf : ∀ (a : α) (ha : a ∈ s), f a ha ∈ t
hinj : ∀ (a₁ a₂ : α) (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s), f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂
hst : card t ≤ card s
b : β
hb : b ∈ t
h : card (image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s)) = card s
h' : image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s) = t
⊢ ∃ a ha, b = f a ha

tactic: obtain ⟨a, _, ha₂⟩ := mem_image.1 hb
state_before: α : Type u_2
β : Type u_1
s t✝ : Finset α
f✝ : α → β
n : ℕ
t : Finset β
f : (a : α) → a ∈ s → β
hf : ∀ (a : α) (ha : a ∈ s), f a ha ∈ t
hinj : ∀ (a₁ a₂ : α) (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s), f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂
hst : card t ≤ card s
b : β
hb : b ∈ image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s)
h : card (image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s)) = card s
h' : image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s) = t
⊢ ∃ a ha, b = f a ha

tactic: exact ⟨a, a.2, ha₂.symm⟩
state_before: case intro.intro
α : Type u_2
β : Type u_1
s t✝ : Finset α
f✝ : α → β
n : ℕ
t : Finset β
f : (a : α) → a ∈ s → β
hf : ∀ (a : α) (ha : a ∈ s), f a ha ∈ t
hinj : ∀ (a₁ a₂ : α) (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s), f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂
hst : card t ≤ card s
b : β
hb : b ∈ image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s)
h : card (image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s)) = card s
h' : image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s) = t
a : { a // a ∈ s }
left✝ : a ∈ attach s
ha₂ : f ↑a (_ : ↑a ∈ s) = b
⊢ ∃ a ha, b = f a ha

tactic: simp [hst, h]
state_before: α : Type u_2
β : Type u_1
s t✝ : Finset α
f✝ : α → β
n : ℕ
t : Finset β
f : (a : α) → a ∈ s → β
hf : ∀ (a : α) (ha : a ∈ s), f a ha ∈ t
hinj : ∀ (a₁ a₂ : α) (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s), f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂
hst : card t ≤ card s
b : β
hb : b ∈ t
h : card (image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s)) = card s
⊢ card t ≤ card (image (fun a => f ↑a (_ : ↑a ∈ s)) (attach s))