l3lab/ntp-mathlib huggingface dataset:
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t : Set α
inst✝ : PartialOrder β
f : α → β
s : Set α
h : Set.Finite s
hs : Set.Nonempty s
⊢ ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'

Next tactic:
induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · rfl
      · rwa [← ih c hcs (le_trans h hac)]
    · refine' ⟨b, Set.mem_insert_of_mem _ hb, fun c hc hbc => _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · exact (h hbc).elim
      · exact ih c hcs hbc
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  

Proof state:
case H0
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t : Set α
inst✝ : PartialOrder β
f : α → β
s : Set α
hs : Set.Nonempty ∅
⊢ ∃ a ∈ ∅, ∀ a' ∈ ∅, f a ≤ f a' → f a = f a'

Next tactic:
| H0 => exact absurd hs not_nonempty_empty
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => 

Proof state:
case H0
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t : Set α
inst✝ : PartialOrder β
f : α → β
s : Set α
hs : Set.Nonempty ∅
⊢ ∃ a ∈ ∅, ∀ a' ∈ ∅, f a ≤ f a' → f a = f a'

Next tactic:
exact absurd hs not_nonempty_empty
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  

Proof state:
case H1
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝ : Set.Finite s
ih : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
⊢ ∃ a_1 ∈ insert a s, ∀ a' ∈ insert a s, f a_1 ≤ f a' → f a_1 = f a'

Next tactic:
| @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · rfl
      · rwa [← ih c hcs (le_trans h hac)]
    · refine' ⟨b, Set.mem_insert_of_mem _ hb, fun c hc hbc => _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · exact (h hbc).elim
      · exact ih c hcs hbc
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    

Proof state:
case H1
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝ : Set.Finite s
ih : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
⊢ ∃ a_1 ∈ insert a s, ∀ a' ∈ insert a s, f a_1 ≤ f a' → f a_1 = f a'

Next tactic:
rcases s.eq_empty_or_nonempty with h | h
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · 

Proof state:
case H1.inl
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝ : Set.Finite s
ih : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h : s = ∅
⊢ ∃ a_1 ∈ insert a s, ∀ a' ∈ insert a s, f a_1 ≤ f a' → f a_1 = f a'

Next tactic:
use a
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      

Proof state:
case h
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝ : Set.Finite s
ih : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h : s = ∅
⊢ a ∈ insert a s ∧ ∀ a' ∈ insert a s, f a ≤ f a' → f a = f a'

Next tactic:
simp [h]
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    

Proof state:
case H1.inr
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝ : Set.Finite s
ih : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h : Set.Nonempty s
⊢ ∃ a_1 ∈ insert a s, ∀ a' ∈ insert a s, f a_1 ≤ f a' → f a_1 = f a'

Next tactic:
rcases ih h with ⟨b, hb, ih⟩
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    

Proof state:
case H1.inr.intro.intro
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝ : Set.Finite s
ih✝ : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h : Set.Nonempty s
b : α
hb : b ∈ s
ih : ∀ a' ∈ s, f b ≤ f a' → f b = f a'
⊢ ∃ a_1 ∈ insert a s, ∀ a' ∈ insert a s, f a_1 ≤ f a' → f a_1 = f a'

Next tactic:
by_cases h : f b ≤ f a
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · 

Proof state:
case pos
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝¹ : Set.Finite s
ih✝ : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h✝ : Set.Nonempty s
b : α
hb : b ∈ s
ih : ∀ a' ∈ s, f b ≤ f a' → f b = f a'
h : f b ≤ f a
⊢ ∃ a_1 ∈ insert a s, ∀ a' ∈ insert a s, f a_1 ≤ f a' → f a_1 = f a'

Next tactic:
refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
      

Proof state:
case pos
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝¹ : Set.Finite s
ih✝ : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h✝ : Set.Nonempty s
b : α
hb : b ∈ s
ih : ∀ a' ∈ s, f b ≤ f a' → f b = f a'
h : f b ≤ f a
c : α
hc : c ∈ insert a s
hac : f a ≤ f c
⊢ f c ≤ f a

Next tactic:
rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · 

Proof state:
case pos.inl
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ s : Set α
h✝¹ : Set.Finite s
ih✝ : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
h✝ : Set.Nonempty s
b : α
hb : b ∈ s
ih : ∀ a' ∈ s, f b ≤ f a' → f b = f a'
c : α
his : c ∉ s
hs : Set.Nonempty (insert c s)
h : f b ≤ f c
hc : c ∈ insert c s
hac : f c ≤ f c
⊢ f c ≤ f c

Next tactic:
rfl
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · rfl
      · 

Proof state:
case pos.inr
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝¹ : Set.Finite s
ih✝ : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h✝ : Set.Nonempty s
b : α
hb : b ∈ s
ih : ∀ a' ∈ s, f b ≤ f a' → f b = f a'
h : f b ≤ f a
c : α
hc : c ∈ insert a s
hac : f a ≤ f c
hcs : c ∈ s
⊢ f c ≤ f a

Next tactic:
rwa [← ih c hcs (le_trans h hac)]
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · rfl
      · rwa [← ih c hcs (le_trans h hac)]
    · 

Proof state:
case neg
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝¹ : Set.Finite s
ih✝ : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h✝ : Set.Nonempty s
b : α
hb : b ∈ s
ih : ∀ a' ∈ s, f b ≤ f a' → f b = f a'
h : ¬f b ≤ f a
⊢ ∃ a_1 ∈ insert a s, ∀ a' ∈ insert a s, f a_1 ≤ f a' → f a_1 = f a'

Next tactic:
refine' ⟨b, Set.mem_insert_of_mem _ hb, fun c hc hbc => _⟩
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · rfl
      · rwa [← ih c hcs (le_trans h hac)]
    · refine' ⟨b, Set.mem_insert_of_mem _ hb, fun c hc hbc => _⟩
      

Proof state:
case neg
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝¹ : Set.Finite s
ih✝ : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h✝ : Set.Nonempty s
b : α
hb : b ∈ s
ih : ∀ a' ∈ s, f b ≤ f a' → f b = f a'
h : ¬f b ≤ f a
c : α
hc : c ∈ insert a s
hbc : f b ≤ f c
⊢ f b = f c

Next tactic:
rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · rfl
      · rwa [← ih c hcs (le_trans h hac)]
    · refine' ⟨b, Set.mem_insert_of_mem _ hb, fun c hc hbc => _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · 

Proof state:
case neg.inl
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ s : Set α
h✝¹ : Set.Finite s
ih✝ : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
h✝ : Set.Nonempty s
b : α
hb : b ∈ s
ih : ∀ a' ∈ s, f b ≤ f a' → f b = f a'
c : α
hbc : f b ≤ f c
his : c ∉ s
hs : Set.Nonempty (insert c s)
h : ¬f b ≤ f c
hc : c ∈ insert c s
⊢ f b = f c

Next tactic:
exact (h hbc).elim
theorem Finite.exists_maximal_wrt [PartialOrder β] (f : α → β) (s : Set α) (h : s.Finite)
    (hs : s.Nonempty) : ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a' := by
  induction s, h using Set.Finite.dinduction_on with
  | H0 => exact absurd hs not_nonempty_empty
  | @H1 a s his _ ih =>
    rcases s.eq_empty_or_nonempty with h | h
    · use a
      simp [h]
    rcases ih h with ⟨b, hb, ih⟩
    by_cases h : f b ≤ f a
    · refine' ⟨a, Set.mem_insert _ _, fun c hc hac => le_antisymm hac _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · rfl
      · rwa [← ih c hcs (le_trans h hac)]
    · refine' ⟨b, Set.mem_insert_of_mem _ hb, fun c hc hbc => _⟩
      rcases Set.mem_insert_iff.1 hc with (rfl | hcs)
      · exact (h hbc).elim
      · 

Proof state:
case neg.inr
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝ : PartialOrder β
f : α → β
s✝ : Set α
a : α
s : Set α
his : a ∉ s
h✝¹ : Set.Finite s
ih✝ : Set.Nonempty s → ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'
hs : Set.Nonempty (insert a s)
h✝ : Set.Nonempty s
b : α
hb : b ∈ s
ih : ∀ a' ∈ s, f b ≤ f a' → f b = f a'
h : ¬f b ≤ f a
c : α
hc : c ∈ insert a s
hbc : f b ≤ f c
hcs : c ∈ s
⊢ f b = f c

Next tactic:
exact ih c hcs hbc
/-- A version of `Finite.exists_maximal_wrt` with the (weaker) hypothesis that the image of `s`
  is finite rather than `s` itself. -/
theorem Finite.exists_maximal_wrt' [PartialOrder β] (f : α → β) (s : Set α) (h : (f '' s).Finite)
    (hs : s.Nonempty) : (∃ a ∈ s, ∀ (a' : α), a' ∈ s → f a ≤ f a' → f a = f a') := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t : Set α
inst✝ : PartialOrder β
f : α → β
s : Set α
h : Set.Finite (f '' s)
hs : Set.Nonempty s
⊢ ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'

Next tactic:
obtain ⟨_, ⟨a, ha, rfl⟩, hmax⟩ := Finite.exists_maximal_wrt id (f '' s) h (hs.image f)
/-- A version of `Finite.exists_maximal_wrt` with the (weaker) hypothesis that the image of `s`
  is finite rather than `s` itself. -/
theorem Finite.exists_maximal_wrt' [PartialOrder β] (f : α → β) (s : Set α) (h : (f '' s).Finite)
    (hs : s.Nonempty) : (∃ a ∈ s, ∀ (a' : α), a' ∈ s → f a ≤ f a' → f a = f a') := by
  obtain ⟨_, ⟨a, ha, rfl⟩, hmax⟩ := Finite.exists_maximal_wrt id (f '' s) h (hs.image f)
  

Proof state:
case intro.intro.intro.intro
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t : Set α
inst✝ : PartialOrder β
f : α → β
s : Set α
h : Set.Finite (f '' s)
hs : Set.Nonempty s
a : α
ha : a ∈ s
hmax : ∀ a' ∈ f '' s, id (f a) ≤ id a' → id (f a) = id a'
⊢ ∃ a ∈ s, ∀ a' ∈ s, f a ≤ f a' → f a = f a'

Next tactic:
exact ⟨a, ha, fun a' ha' hf ↦ hmax _ (mem_image_of_mem f ha') hf⟩
/-- A finite union of sets which are all bounded above is still bounded above.-/
theorem Finite.bddAbove_biUnion {I : Set β} {S : β → Set α} (H : I.Finite) :
    BddAbove (⋃ i ∈ I, S i) ↔ ∀ i ∈ I, BddAbove (S i) :=
  Finite.induction_on H (by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝ t : Set α
inst✝² : Preorder α
inst✝¹ : IsDirected α fun x x_1 => x ≤ x_1
inst✝ : Nonempty α
s : Set α
I : Set β
S : β → Set α
H : Set.Finite I
⊢ BddAbove (⋃ i ∈ ∅, S i) ↔ ∀ i ∈ ∅, BddAbove (S i)

Next tactic:
simp only [biUnion_empty, bddAbove_empty, ball_empty_iff]
/-- A finite union of sets which are all bounded above is still bounded above.-/
theorem Finite.bddAbove_biUnion {I : Set β} {S : β → Set α} (H : I.Finite) :
    BddAbove (⋃ i ∈ I, S i) ↔ ∀ i ∈ I, BddAbove (S i) :=
  Finite.induction_on H (by simp only [biUnion_empty, bddAbove_empty, ball_empty_iff])
    fun _ _ hs => by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
s✝¹ t : Set α
inst✝² : Preorder α
inst✝¹ : IsDirected α fun x x_1 => x ≤ x_1
inst✝ : Nonempty α
s : Set α
I : Set β
S : β → Set α
H : Set.Finite I
a✝ : β
s✝ : Set β
x✝¹ : a✝ ∉ s✝
x✝ : Set.Finite s✝
hs : BddAbove (⋃ i ∈ s✝, S i) ↔ ∀ i ∈ s✝, BddAbove (S i)
⊢ BddAbove (⋃ i ∈ insert a✝ s✝, S i) ↔ ∀ i ∈ insert a✝ s✝, BddAbove (S i)

Next tactic:
simp only [biUnion_insert, ball_insert_iff, bddAbove_union, hs]
lemma exists_card_eq [Infinite α] : ∀ n : ℕ, ∃ s : Finset α, s.card = n
  | 0 => ⟨∅, card_empty⟩
  | n + 1 => by
    

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : Infinite α
n : ℕ
⊢ ∃ s, card s = n + 1

Next tactic:
classical
    obtain ⟨s, rfl⟩ := exists_card_eq n
    obtain ⟨a, ha⟩ := s.exists_not_mem
    exact ⟨insert a s, card_insert_of_not_mem ha⟩
lemma exists_card_eq [Infinite α] : ∀ n : ℕ, ∃ s : Finset α, s.card = n
  | 0 => ⟨∅, card_empty⟩
  | n + 1 => by
    classical
    

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : Infinite α
n : ℕ
⊢ ∃ s, card s = n + 1

Next tactic:
obtain ⟨s, rfl⟩ := exists_card_eq n
lemma exists_card_eq [Infinite α] : ∀ n : ℕ, ∃ s : Finset α, s.card = n
  | 0 => ⟨∅, card_empty⟩
  | n + 1 => by
    classical
    obtain ⟨s, rfl⟩ := exists_card_eq n
    

Proof state:
case intro
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : Infinite α
s : Finset α
⊢ ∃ s_1, card s_1 = card s + 1

Next tactic:
obtain ⟨a, ha⟩ := s.exists_not_mem
lemma exists_card_eq [Infinite α] : ∀ n : ℕ, ∃ s : Finset α, s.card = n
  | 0 => ⟨∅, card_empty⟩
  | n + 1 => by
    classical
    obtain ⟨s, rfl⟩ := exists_card_eq n
    obtain ⟨a, ha⟩ := s.exists_not_mem
    

Proof state:
case intro.intro
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : Infinite α
s : Finset α
a : α
ha : a ∉ s
⊢ ∃ s_1, card s_1 = card s + 1

Next tactic:
exact ⟨insert a s, card_insert_of_not_mem ha⟩
/-- If a linear order does not contain any triple of elements `x < y < z`, then this type
is finite. -/
lemma Finite.of_forall_not_lt_lt (h : ∀ ⦃x y z : α⦄, x < y → y < z → False) : Finite α := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : LinearOrder α
s : Set α
h : ∀ ⦃x y z : α⦄, x < y → y < z → False
⊢ Finite α

Next tactic:
nontriviality α
/-- If a linear order does not contain any triple of elements `x < y < z`, then this type
is finite. -/
lemma Finite.of_forall_not_lt_lt (h : ∀ ⦃x y z : α⦄, x < y → y < z → False) : Finite α := by
  nontriviality α
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : LinearOrder α
s : Set α
h : ∀ ⦃x y z : α⦄, x < y → y < z → False
✝ : Nontrivial α
⊢ Finite α

Next tactic:
rcases exists_pair_ne α with ⟨x, y, hne⟩
/-- If a linear order does not contain any triple of elements `x < y < z`, then this type
is finite. -/
lemma Finite.of_forall_not_lt_lt (h : ∀ ⦃x y z : α⦄, x < y → y < z → False) : Finite α := by
  nontriviality α
  rcases exists_pair_ne α with ⟨x, y, hne⟩
  

Proof state:
case intro.intro
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : LinearOrder α
s : Set α
h : ∀ ⦃x y z : α⦄, x < y → y < z → False
✝ : Nontrivial α
x y : α
hne : x ≠ y
⊢ Finite α

Next tactic:
refine' @Finite.of_fintype α ⟨{x, y}, fun z => _⟩
/-- If a linear order does not contain any triple of elements `x < y < z`, then this type
is finite. -/
lemma Finite.of_forall_not_lt_lt (h : ∀ ⦃x y z : α⦄, x < y → y < z → False) : Finite α := by
  nontriviality α
  rcases exists_pair_ne α with ⟨x, y, hne⟩
  refine' @Finite.of_fintype α ⟨{x, y}, fun z => _⟩
  

Proof state:
case intro.intro
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : LinearOrder α
s : Set α
h : ∀ ⦃x y z : α⦄, x < y → y < z → False
✝ : Nontrivial α
x y : α
hne : x ≠ y
z : α
⊢ z ∈ {x, y}

Next tactic:
simpa [hne] using eq_or_eq_or_eq_of_forall_not_lt_lt h z x y
/-- If a set `s` does not contain any triple of elements `x < y < z`, then `s` is finite. -/
lemma Set.finite_of_forall_not_lt_lt (h : ∀ x ∈ s, ∀ y ∈ s, ∀ z ∈ s, x < y → y < z → False) :
    Set.Finite s :=
  @Set.toFinite _ s <| Finite.of_forall_not_lt_lt $ by 

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : LinearOrder α
s : Set α
h : ∀ x ∈ s, ∀ y ∈ s, ∀ z ∈ s, x < y → y < z → False
⊢ ∀ ⦃x y z : ↑s⦄, x < y → y < z → False

Next tactic:
simpa only [SetCoe.forall'] using h
lemma Set.finite_diff_iUnion_Ioo' (s : Set α) : (s \ ⋃ x : s × s, Ioo x.1 x.2).Finite := by
  

Proof state:
α : Type u
β : Type v
ι : Sort w
γ : Type x
inst✝ : LinearOrder α
s✝ s : Set α
⊢ Set.Finite (s \ ⋃ x, Ioo ↑x.1 ↑x.2)

Next tactic:
simpa only [iUnion, iSup_prod, iSup_subtype] using s.finite_diff_iUnion_Ioo
/-- The multiplication in a non-unital algebra is a bilinear map.

A weaker version of this for non-unital non-associative algebras exists as `LinearMap.mul`. -/
def _root_.NonUnitalAlgHom.lmul : A →ₙₐ[R] End R A :=
  { mul R A with
    map_mul' := by
      intro a b
      ext c
      exact mul_assoc a b c
    map_zero' := by
      

Proof state:
R : Type u_1
A : Type u_2
inst✝⁴ : CommSemiring R
inst✝³ : NonUnitalSemiring A
inst✝² : Module R A
inst✝¹ : SMulCommClass R A A
inst✝ : IsScalarTower R A A
src✝ : A →ₗ[R] A →ₗ[R] A := mul R A
⊢ MulActionHom.toFun
      { toFun := src✝.toFun,
        map_smul' :=
          (_ :
            ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = (RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }
      0 =
    0

Next tactic:
ext a
/-- The multiplication in a non-unital algebra is a bilinear map.

A weaker version of this for non-unital non-associative algebras exists as `LinearMap.mul`. -/
def _root_.NonUnitalAlgHom.lmul : A →ₙₐ[R] End R A :=
  { mul R A with
    map_mul' := by
      intro a b
      ext c
      exact mul_assoc a b c
    map_zero' := by
      ext a
      

Proof state:
case h
R : Type u_1
A : Type u_2
inst✝⁴ : CommSemiring R
inst✝³ : NonUnitalSemiring A
inst✝² : Module R A
inst✝¹ : SMulCommClass R A A
inst✝ : IsScalarTower R A A
src✝ : A →ₗ[R] A →ₗ[R] A := mul R A
a : A
⊢ (MulActionHom.toFun
        { toFun := src✝.toFun,
          map_smul' :=
            (_ :
              ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = (RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }
        0)
      a =
    0 a

Next tactic:
exact zero_mul a
theorem commute_mulLeft_right (a b : A) : Commute (mulLeft R a) (mulRight R b) := by
  

Proof state:
R : Type u_1
A : Type u_2
inst✝⁴ : CommSemiring R
inst✝³ : NonUnitalSemiring A
inst✝² : Module R A
inst✝¹ : SMulCommClass R A A
inst✝ : IsScalarTower R A A
a b : A
⊢ Commute (mulLeft R a) (mulRight R b)

Next tactic:
ext c