l3lab/ntp-mathlib huggingface dataset:
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatibleMaps : Submodule R (N →ₗ[R] N₂) where
  carrier := { fₗ | pₗ ≤ comap fₗ qₗ }
  zero_mem' := by
    change pₗ ≤ comap (0 : N →ₗ[R] N₂) qₗ
    rw [comap_zero]
    refine' le_top
  add_mem' {f₁ f₂} h₁ h₂ := by
    

Proof state:
R : Type u_1
R₁ : Type u_2
R₂ : Type u_3
R₃ : Type u_4
S : Type u_5
M : Type u_6
M₁ : Type u_7
M₂ : Type u_8
M₃ : Type u_9
N : Type u_10
N₂ : Type u_11
inst✝¹¹ : CommSemiring R
inst✝¹⁰ : CommSemiring R₂
inst✝⁹ : AddCommMonoid M
inst✝⁸ : AddCommMonoid M₂
inst✝⁷ : Module R M
inst✝⁶ : Module R₂ M₂
inst✝⁵ : AddCommMonoid N
inst✝⁴ : AddCommMonoid N₂
inst✝³ : Module R N
inst✝² : Module R N₂
τ₁₂ : R →+* R₂
τ₂₁ : R₂ →+* R
inst✝¹ : RingHomInvPair τ₁₂ τ₂₁
inst✝ : RingHomInvPair τ₂₁ τ₁₂
p : Submodule R M
q : Submodule R₂ M₂
pₗ : Submodule R N
qₗ : Submodule R N₂
f₁ f₂ : N →ₗ[R] N₂
h₁ : f₁ ∈ {fₗ | pₗ ≤ comap fₗ qₗ}
h₂ : f₂ ∈ {fₗ | pₗ ≤ comap fₗ qₗ}
⊢ f₁ + f₂ ∈ {fₗ | pₗ ≤ comap fₗ qₗ}

Next tactic:
apply le_trans _ (inf_comap_le_comap_add qₗ f₁ f₂)
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatibleMaps : Submodule R (N →ₗ[R] N₂) where
  carrier := { fₗ | pₗ ≤ comap fₗ qₗ }
  zero_mem' := by
    change pₗ ≤ comap (0 : N →ₗ[R] N₂) qₗ
    rw [comap_zero]
    refine' le_top
  add_mem' {f₁ f₂} h₁ h₂ := by
    apply le_trans _ (inf_comap_le_comap_add qₗ f₁ f₂)
    

Proof state:
R : Type u_1
R₁ : Type u_2
R₂ : Type u_3
R₃ : Type u_4
S : Type u_5
M : Type u_6
M₁ : Type u_7
M₂ : Type u_8
M₃ : Type u_9
N : Type u_10
N₂ : Type u_11
inst✝¹¹ : CommSemiring R
inst✝¹⁰ : CommSemiring R₂
inst✝⁹ : AddCommMonoid M
inst✝⁸ : AddCommMonoid M₂
inst✝⁷ : Module R M
inst✝⁶ : Module R₂ M₂
inst✝⁵ : AddCommMonoid N
inst✝⁴ : AddCommMonoid N₂
inst✝³ : Module R N
inst✝² : Module R N₂
τ₁₂ : R →+* R₂
τ₂₁ : R₂ →+* R
inst✝¹ : RingHomInvPair τ₁₂ τ₂₁
inst✝ : RingHomInvPair τ₂₁ τ₁₂
p : Submodule R M
q : Submodule R₂ M₂
pₗ : Submodule R N
qₗ : Submodule R N₂
f₁ f₂ : N →ₗ[R] N₂
h₁ : f₁ ∈ {fₗ | pₗ ≤ comap fₗ qₗ}
h₂ : f₂ ∈ {fₗ | pₗ ≤ comap fₗ qₗ}
⊢ pₗ ≤ comap f₁ qₗ ⊓ comap f₂ qₗ

Next tactic:
rw [le_inf_iff]
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatibleMaps : Submodule R (N →ₗ[R] N₂) where
  carrier := { fₗ | pₗ ≤ comap fₗ qₗ }
  zero_mem' := by
    change pₗ ≤ comap (0 : N →ₗ[R] N₂) qₗ
    rw [comap_zero]
    refine' le_top
  add_mem' {f₁ f₂} h₁ h₂ := by
    apply le_trans _ (inf_comap_le_comap_add qₗ f₁ f₂)
    rw [le_inf_iff]
    

Proof state:
R : Type u_1
R₁ : Type u_2
R₂ : Type u_3
R₃ : Type u_4
S : Type u_5
M : Type u_6
M₁ : Type u_7
M₂ : Type u_8
M₃ : Type u_9
N : Type u_10
N₂ : Type u_11
inst✝¹¹ : CommSemiring R
inst✝¹⁰ : CommSemiring R₂
inst✝⁹ : AddCommMonoid M
inst✝⁸ : AddCommMonoid M₂
inst✝⁷ : Module R M
inst✝⁶ : Module R₂ M₂
inst✝⁵ : AddCommMonoid N
inst✝⁴ : AddCommMonoid N₂
inst✝³ : Module R N
inst✝² : Module R N₂
τ₁₂ : R →+* R₂
τ₂₁ : R₂ →+* R
inst✝¹ : RingHomInvPair τ₁₂ τ₂₁
inst✝ : RingHomInvPair τ₂₁ τ₁₂
p : Submodule R M
q : Submodule R₂ M₂
pₗ : Submodule R N
qₗ : Submodule R N₂
f₁ f₂ : N →ₗ[R] N₂
h₁ : f₁ ∈ {fₗ | pₗ ≤ comap fₗ qₗ}
h₂ : f₂ ∈ {fₗ | pₗ ≤ comap fₗ qₗ}
⊢ pₗ ≤ comap f₁ qₗ ∧ pₗ ≤ comap f₂ qₗ

Next tactic:
exact ⟨h₁, h₂⟩
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatibleMaps : Submodule R (N →ₗ[R] N₂) where
  carrier := { fₗ | pₗ ≤ comap fₗ qₗ }
  zero_mem' := by
    

Proof state:
R : Type u_1
R₁ : Type u_2
R₂ : Type u_3
R₃ : Type u_4
S : Type u_5
M : Type u_6
M₁ : Type u_7
M₂ : Type u_8
M₃ : Type u_9
N : Type u_10
N₂ : Type u_11
inst✝¹¹ : CommSemiring R
inst✝¹⁰ : CommSemiring R₂
inst✝⁹ : AddCommMonoid M
inst✝⁸ : AddCommMonoid M₂
inst✝⁷ : Module R M
inst✝⁶ : Module R₂ M₂
inst✝⁵ : AddCommMonoid N
inst✝⁴ : AddCommMonoid N₂
inst✝³ : Module R N
inst✝² : Module R N₂
τ₁₂ : R →+* R₂
τ₂₁ : R₂ →+* R
inst✝¹ : RingHomInvPair τ₁₂ τ₂₁
inst✝ : RingHomInvPair τ₂₁ τ₁₂
p : Submodule R M
q : Submodule R₂ M₂
pₗ : Submodule R N
qₗ : Submodule R N₂
⊢ 0 ∈
    { carrier := {fₗ | pₗ ≤ comap fₗ qₗ},
        add_mem' :=
          (_ :
            ∀ {f₁ f₂ : N →ₗ[R] N₂},
              f₁ ∈ {fₗ | pₗ ≤ comap fₗ qₗ} → f₂ ∈ {fₗ | pₗ ≤ comap fₗ qₗ} → pₗ ≤ comap (f₁ + f₂) qₗ) }.carrier

Next tactic:
change pₗ ≤ comap (0 : N →ₗ[R] N₂) qₗ
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatibleMaps : Submodule R (N →ₗ[R] N₂) where
  carrier := { fₗ | pₗ ≤ comap fₗ qₗ }
  zero_mem' := by
    change pₗ ≤ comap (0 : N →ₗ[R] N₂) qₗ
    

Proof state:
R : Type u_1
R₁ : Type u_2
R₂ : Type u_3
R₃ : Type u_4
S : Type u_5
M : Type u_6
M₁ : Type u_7
M₂ : Type u_8
M₃ : Type u_9
N : Type u_10
N₂ : Type u_11
inst✝¹¹ : CommSemiring R
inst✝¹⁰ : CommSemiring R₂
inst✝⁹ : AddCommMonoid M
inst✝⁸ : AddCommMonoid M₂
inst✝⁷ : Module R M
inst✝⁶ : Module R₂ M₂
inst✝⁵ : AddCommMonoid N
inst✝⁴ : AddCommMonoid N₂
inst✝³ : Module R N
inst✝² : Module R N₂
τ₁₂ : R →+* R₂
τ₂₁ : R₂ →+* R
inst✝¹ : RingHomInvPair τ₁₂ τ₂₁
inst✝ : RingHomInvPair τ₂₁ τ₁₂
p : Submodule R M
q : Submodule R₂ M₂
pₗ : Submodule R N
qₗ : Submodule R N₂
⊢ pₗ ≤ comap 0 qₗ

Next tactic:
rw [comap_zero]
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatibleMaps : Submodule R (N →ₗ[R] N₂) where
  carrier := { fₗ | pₗ ≤ comap fₗ qₗ }
  zero_mem' := by
    change pₗ ≤ comap (0 : N →ₗ[R] N₂) qₗ
    rw [comap_zero]
    

Proof state:
R : Type u_1
R₁ : Type u_2
R₂ : Type u_3
R₃ : Type u_4
S : Type u_5
M : Type u_6
M₁ : Type u_7
M₂ : Type u_8
M₃ : Type u_9
N : Type u_10
N₂ : Type u_11
inst✝¹¹ : CommSemiring R
inst✝¹⁰ : CommSemiring R₂
inst✝⁹ : AddCommMonoid M
inst✝⁸ : AddCommMonoid M₂
inst✝⁷ : Module R M
inst✝⁶ : Module R₂ M₂
inst✝⁵ : AddCommMonoid N
inst✝⁴ : AddCommMonoid N₂
inst✝³ : Module R N
inst✝² : Module R N₂
τ₁₂ : R →+* R₂
τ₂₁ : R₂ →+* R
inst✝¹ : RingHomInvPair τ₁₂ τ₂₁
inst✝ : RingHomInvPair τ₂₁ τ₁₂
p : Submodule R M
q : Submodule R₂ M₂
pₗ : Submodule R N
qₗ : Submodule R N₂
⊢ pₗ ≤ ⊤

Next tactic:
refine' le_top
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatibleMaps : Submodule R (N →ₗ[R] N₂) where
  carrier := { fₗ | pₗ ≤ comap fₗ qₗ }
  zero_mem' := by
    change pₗ ≤ comap (0 : N →ₗ[R] N₂) qₗ
    rw [comap_zero]
    refine' le_top
  add_mem' {f₁ f₂} h₁ h₂ := by
    apply le_trans _ (inf_comap_le_comap_add qₗ f₁ f₂)
    rw [le_inf_iff]
    exact ⟨h₁, h₂⟩
  smul_mem' c fₗ h := by
    

Proof state:
R : Type u_1
R₁ : Type u_2
R₂ : Type u_3
R₃ : Type u_4
S : Type u_5
M : Type u_6
M₁ : Type u_7
M₂ : Type u_8
M₃ : Type u_9
N : Type u_10
N₂ : Type u_11
inst✝¹¹ : CommSemiring R
inst✝¹⁰ : CommSemiring R₂
inst✝⁹ : AddCommMonoid M
inst✝⁸ : AddCommMonoid M₂
inst✝⁷ : Module R M
inst✝⁶ : Module R₂ M₂
inst✝⁵ : AddCommMonoid N
inst✝⁴ : AddCommMonoid N₂
inst✝³ : Module R N
inst✝² : Module R N₂
τ₁₂ : R →+* R₂
τ₂₁ : R₂ →+* R
inst✝¹ : RingHomInvPair τ₁₂ τ₂₁
inst✝ : RingHomInvPair τ₂₁ τ₁₂
p : Submodule R M
q : Submodule R₂ M₂
pₗ : Submodule R N
qₗ : Submodule R N₂
c : R
fₗ : N →ₗ[R] N₂
h :
  fₗ ∈
    {
          toAddSubsemigroup :=
            { carrier := {fₗ | pₗ ≤ comap fₗ qₗ},
              add_mem' :=
                (_ :
                  ∀ {f₁ f₂ : N →ₗ[R] N₂},
                    f₁ ∈ {fₗ | pₗ ≤ comap fₗ qₗ} → f₂ ∈ {fₗ | pₗ ≤ comap fₗ qₗ} → pₗ ≤ comap (f₁ + f₂) qₗ) },
          zero_mem' := (_ : pₗ ≤ comap 0 qₗ) }.toAddSubsemigroup.carrier
⊢ c • fₗ ∈
    {
          toAddSubsemigroup :=
            { carrier := {fₗ | pₗ ≤ comap fₗ qₗ},
              add_mem' :=
                (_ :
                  ∀ {f₁ f₂ : N →ₗ[R] N₂},
                    f₁ ∈ {fₗ | pₗ ≤ comap fₗ qₗ} → f₂ ∈ {fₗ | pₗ ≤ comap fₗ qₗ} → pₗ ≤ comap (f₁ + f₂) qₗ) },
          zero_mem' := (_ : pₗ ≤ comap 0 qₗ) }.toAddSubsemigroup.carrier

Next tactic:
dsimp at h
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatibleMaps : Submodule R (N →ₗ[R] N₂) where
  carrier := { fₗ | pₗ ≤ comap fₗ qₗ }
  zero_mem' := by
    change pₗ ≤ comap (0 : N →ₗ[R] N₂) qₗ
    rw [comap_zero]
    refine' le_top
  add_mem' {f₁ f₂} h₁ h₂ := by
    apply le_trans _ (inf_comap_le_comap_add qₗ f₁ f₂)
    rw [le_inf_iff]
    exact ⟨h₁, h₂⟩
  smul_mem' c fₗ h := by
    dsimp at h
    

Proof state:
R : Type u_1
R₁ : Type u_2
R₂ : Type u_3
R₃ : Type u_4
S : Type u_5
M : Type u_6
M₁ : Type u_7
M₂ : Type u_8
M₃ : Type u_9
N : Type u_10
N₂ : Type u_11
inst✝¹¹ : CommSemiring R
inst✝¹⁰ : CommSemiring R₂
inst✝⁹ : AddCommMonoid M
inst✝⁸ : AddCommMonoid M₂
inst✝⁷ : Module R M
inst✝⁶ : Module R₂ M₂
inst✝⁵ : AddCommMonoid N
inst✝⁴ : AddCommMonoid N₂
inst✝³ : Module R N
inst✝² : Module R N₂
τ₁₂ : R →+* R₂
τ₂₁ : R₂ →+* R
inst✝¹ : RingHomInvPair τ₁₂ τ₂₁
inst✝ : RingHomInvPair τ₂₁ τ₁₂
p : Submodule R M
q : Submodule R₂ M₂
pₗ : Submodule R N
qₗ : Submodule R N₂
c : R
fₗ : N →ₗ[R] N₂
h : pₗ ≤ comap fₗ qₗ
⊢ c • fₗ ∈
    {
          toAddSubsemigroup :=
            { carrier := {fₗ | pₗ ≤ comap fₗ qₗ},
              add_mem' :=
                (_ :
                  ∀ {f₁ f₂ : N →ₗ[R] N₂},
                    f₁ ∈ {fₗ | pₗ ≤ comap fₗ qₗ} → f₂ ∈ {fₗ | pₗ ≤ comap fₗ qₗ} → pₗ ≤ comap (f₁ + f₂) qₗ) },
          zero_mem' := (_ : pₗ ≤ comap 0 qₗ) }.toAddSubsemigroup.carrier

Next tactic:
exact le_trans h (comap_le_comap_smul qₗ fₗ c)
@[simp]
theorem sort_nodup (s : Finset α) : (sort r s).Nodup :=
  (by 

Proof state:
α : Type u_1
β : Type u_2
r : α → α → Prop
inst✝³ : DecidableRel r
inst✝² : IsTrans α r
inst✝¹ : IsAntisymm α r
inst✝ : IsTotal α r
s : Finset α
⊢ Nodup ↑(sort r s)

Next tactic:
rw [sort_eq]
@[simp]
theorem sort_nodup (s : Finset α) : (sort r s).Nodup :=
  (by rw [sort_eq]; 

Proof state:
α : Type u_1
β : Type u_2
r : α → α → Prop
inst✝³ : DecidableRel r
inst✝² : IsTrans α r
inst✝¹ : IsAntisymm α r
inst✝ : IsTotal α r
s : Finset α
⊢ Nodup s.val

Next tactic:
exact s.2
open scoped List in
theorem sort_perm_toList (s : Finset α) : sort r s ~ s.toList := by
  

Proof state:
α : Type u_1
β : Type u_2
r : α → α → Prop
inst✝³ : DecidableRel r
inst✝² : IsTrans α r
inst✝¹ : IsAntisymm α r
inst✝ : IsTotal α r
s : Finset α
⊢ sort r s ~ toList s

Next tactic:
rw [← Multiset.coe_eq_coe]
open scoped List in
theorem sort_perm_toList (s : Finset α) : sort r s ~ s.toList := by
  rw [← Multiset.coe_eq_coe]
  

Proof state:
α : Type u_1
β : Type u_2
r : α → α → Prop
inst✝³ : DecidableRel r
inst✝² : IsTrans α r
inst✝¹ : IsAntisymm α r
inst✝ : IsTotal α r
s : Finset α
⊢ ↑(sort r s) = ↑(toList s)

Next tactic:
simp only [coe_toList, sort_eq]
theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe 0 h = s.min' H := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) 0 h = min' s H

Next tactic:
let l := s.sort (· ≤ ·)
theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe 0 h = s.min' H := by
  let l := s.sort (· ≤ ·)
  

Proof state:
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) 0 h = min' s H

Next tactic:
apply le_antisymm
theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe 0 h = s.min' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · 

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) 0 h ≤ min' s H

Next tactic:
have : s.min' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.min'_mem H)
theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe 0 h = s.min' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : s.min' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.min'_mem H)
    

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
this : min' s H ∈ l
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) 0 h ≤ min' s H

Next tactic:
obtain ⟨i, hi⟩ : ∃ i, l.get i = s.min' H := List.mem_iff_get.1 this
theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe 0 h = s.min' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : s.min' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.min'_mem H)
    obtain ⟨i, hi⟩ : ∃ i, l.get i = s.min' H := List.mem_iff_get.1 this
    

Proof state:
case a.intro
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
this : min' s H ∈ l
i : Fin (List.length l)
hi : List.get l i = min' s H
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) 0 h ≤ min' s H

Next tactic:
rw [← hi]
theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe 0 h = s.min' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : s.min' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.min'_mem H)
    obtain ⟨i, hi⟩ : ∃ i, l.get i = s.min' H := List.mem_iff_get.1 this
    rw [← hi]
    

Proof state:
case a.intro
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
this : min' s H ∈ l
i : Fin (List.length l)
hi : List.get l i = min' s H
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) 0 h ≤ List.get l i

Next tactic:
exact (s.sort_sorted (· ≤ ·)).rel_nthLe_of_le _ _ (Nat.zero_le i)
theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe 0 h = s.min' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : s.min' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.min'_mem H)
    obtain ⟨i, hi⟩ : ∃ i, l.get i = s.min' H := List.mem_iff_get.1 this
    rw [← hi]
    exact (s.sort_sorted (· ≤ ·)).rel_nthLe_of_le _ _ (Nat.zero_le i)
  · 

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
⊢ min' s H ≤ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) 0 h

Next tactic:
have : l.get ⟨0, h⟩ ∈ s := (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l 0 h)
theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe 0 h = s.min' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : s.min' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.min'_mem H)
    obtain ⟨i, hi⟩ : ∃ i, l.get i = s.min' H := List.mem_iff_get.1 this
    rw [← hi]
    exact (s.sort_sorted (· ≤ ·)).rel_nthLe_of_le _ _ (Nat.zero_le i)
  · have : l.get ⟨0, h⟩ ∈ s := (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l 0 h)
    

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
this : List.get l { val := 0, isLt := h } ∈ s
⊢ min' s H ≤ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) 0 h

Next tactic:
exact s.min'_le _ this
theorem sorted_zero_eq_min' {s : Finset α} {h : 0 < (s.sort (· ≤ ·)).length} :
    (s.sort (· ≤ ·)).nthLe 0 h = s.min' (card_pos.1 <| by 

Proof state:
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)
⊢ 0 < card s

Next tactic:
rwa [length_sort] at h
theorem min'_eq_sorted_zero {s : Finset α} {h : s.Nonempty} :
    s.min' h = (s.sort (· ≤ ·)).nthLe 0 (by 

Proof state:
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : Finset.Nonempty s
⊢ 0 < List.length (sort (fun x x_1 => x ≤ x_1) s)

Next tactic:
rw [length_sort]
theorem min'_eq_sorted_zero {s : Finset α} {h : s.Nonempty} :
    s.min' h = (s.sort (· ≤ ·)).nthLe 0 (by rw [length_sort]; 

Proof state:
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : Finset.Nonempty s
⊢ 0 < card s

Next tactic:
exact card_pos.2 h
theorem sorted_last_eq_max'_aux (s : Finset α)
    (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe ((s.sort (· ≤ ·)).length - 1) h = s.max' H := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : List.length (sort (fun x x_1 => x ≤ x_1) s) - 1 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) (List.length (sort (fun x x_1 => x ≤ x_1) s) - 1) h = max' s H

Next tactic:
let l := s.sort (· ≤ ·)
theorem sorted_last_eq_max'_aux (s : Finset α)
    (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe ((s.sort (· ≤ ·)).length - 1) h = s.max' H := by
  let l := s.sort (· ≤ ·)
  

Proof state:
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : List.length (sort (fun x x_1 => x ≤ x_1) s) - 1 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) (List.length (sort (fun x x_1 => x ≤ x_1) s) - 1) h = max' s H

Next tactic:
apply le_antisymm
theorem sorted_last_eq_max'_aux (s : Finset α)
    (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe ((s.sort (· ≤ ·)).length - 1) h = s.max' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · 

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : List.length (sort (fun x x_1 => x ≤ x_1) s) - 1 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) (List.length (sort (fun x x_1 => x ≤ x_1) s) - 1) h ≤ max' s H

Next tactic:
have : l.get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ ∈ s :=
      (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _ h)
theorem sorted_last_eq_max'_aux (s : Finset α)
    (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe ((s.sort (· ≤ ·)).length - 1) h = s.max' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : l.get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ ∈ s :=
      (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _ h)
    

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : List.length (sort (fun x x_1 => x ≤ x_1) s) - 1 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
this : List.get l { val := List.length (sort (fun x x_1 => x ≤ x_1) s) - 1, isLt := h } ∈ s
⊢ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) (List.length (sort (fun x x_1 => x ≤ x_1) s) - 1) h ≤ max' s H

Next tactic:
exact s.le_max' _ this
theorem sorted_last_eq_max'_aux (s : Finset α)
    (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe ((s.sort (· ≤ ·)).length - 1) h = s.max' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : l.get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ ∈ s :=
      (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _ h)
    exact s.le_max' _ this
  · 

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : List.length (sort (fun x x_1 => x ≤ x_1) s) - 1 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
⊢ max' s H ≤ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) (List.length (sort (fun x x_1 => x ≤ x_1) s) - 1) h

Next tactic:
have : s.max' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.max'_mem H)
theorem sorted_last_eq_max'_aux (s : Finset α)
    (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe ((s.sort (· ≤ ·)).length - 1) h = s.max' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : l.get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ ∈ s :=
      (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _ h)
    exact s.le_max' _ this
  · have : s.max' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.max'_mem H)
    

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : List.length (sort (fun x x_1 => x ≤ x_1) s) - 1 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
this : max' s H ∈ l
⊢ max' s H ≤ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) (List.length (sort (fun x x_1 => x ≤ x_1) s) - 1) h

Next tactic:
obtain ⟨i, hi⟩ : ∃ i, l.get i = s.max' H := List.mem_iff_get.1 this
theorem sorted_last_eq_max'_aux (s : Finset α)
    (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe ((s.sort (· ≤ ·)).length - 1) h = s.max' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : l.get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ ∈ s :=
      (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _ h)
    exact s.le_max' _ this
  · have : s.max' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.max'_mem H)
    obtain ⟨i, hi⟩ : ∃ i, l.get i = s.max' H := List.mem_iff_get.1 this
    

Proof state:
case a.intro
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : List.length (sort (fun x x_1 => x ≤ x_1) s) - 1 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
this : max' s H ∈ l
i : Fin (List.length l)
hi : List.get l i = max' s H
⊢ max' s H ≤ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) (List.length (sort (fun x x_1 => x ≤ x_1) s) - 1) h

Next tactic:
rw [← hi]
theorem sorted_last_eq_max'_aux (s : Finset α)
    (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).nthLe ((s.sort (· ≤ ·)).length - 1) h = s.max' H := by
  let l := s.sort (· ≤ ·)
  apply le_antisymm
  · have : l.get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ ∈ s :=
      (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _ h)
    exact s.le_max' _ this
  · have : s.max' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.max'_mem H)
    obtain ⟨i, hi⟩ : ∃ i, l.get i = s.max' H := List.mem_iff_get.1 this
    rw [← hi]
    

Proof state:
case a.intro
α : Type u_1
β : Type u_2
inst✝ : LinearOrder α
s : Finset α
h : List.length (sort (fun x x_1 => x ≤ x_1) s) - 1 < List.length (sort (fun x x_1 => x ≤ x_1) s)
H : Finset.Nonempty s
l : List α := sort (fun x x_1 => x ≤ x_1) s
this : max' s H ∈ l
i : Fin (List.length l)
hi : List.get l i = max' s H
⊢ List.get l i ≤ List.nthLe (sort (fun x x_1 => x ≤ x_1) s) (List.length (sort (fun x x_1 => x ≤ x_1) s) - 1) h

Next tactic:
exact (s.sort_sorted (· ≤ ·)).rel_nthLe_of_le _ _ (Nat.le_sub_one_of_lt i.prop)