l3lab/ntp-mathlib huggingface dataset:
/-- A `Set` of a subsingleton type has cardinality at most one. -/
theorem ncard_le_one_of_subsingleton [Subsingleton α] (s : Set α) : s.ncard ≤ 1 := by
  rw [ncard_eq_toFinset_card]
  

Proof state:
α : Type u_1
s✝ t : Set α
inst✝ : Subsingleton α
s : Set α
⊢ Finset.card (Finite.toFinset (_ : Set.Finite s)) ≤ 1

Next tactic:
exact Finset.card_le_one_of_subsingleton _
theorem one_lt_ncard (hs : s.Finite := by toFinite_tac) :
    1 < s.ncard ↔ ∃ a ∈ s, ∃ b ∈ s, a ≠ b := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ 1 < ncard s ↔ ∃ a ∈ s, ∃ b ∈ s, a ≠ b

Next tactic:
simp_rw [ncard_eq_toFinset_card _ hs, Finset.one_lt_card, Finite.mem_toFinset]
theorem one_lt_ncard_iff (hs : s.Finite := by toFinite_tac) :
    1 < s.ncard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b :=   by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ 1 < ncard s ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b

Next tactic:
rw [one_lt_ncard hs]
theorem one_lt_ncard_iff (hs : s.Finite := by toFinite_tac) :
    1 < s.ncard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b :=   by
  rw [one_lt_ncard hs]
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ (∃ a ∈ s, ∃ b ∈ s, a ≠ b) ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b

Next tactic:
simp only [exists_prop, exists_and_left]
theorem two_lt_ncard_iff (hs : s.Finite := by toFinite_tac) :
    2 < s.ncard ↔ ∃ a b c, a ∈ s ∧ b ∈ s ∧ c ∈ s ∧ a ≠ b ∧ a ≠ c ∧ b ≠ c := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ 2 < ncard s ↔ ∃ a b c, a ∈ s ∧ b ∈ s ∧ c ∈ s ∧ a ≠ b ∧ a ≠ c ∧ b ≠ c

Next tactic:
simp_rw [ncard_eq_toFinset_card _ hs, Finset.two_lt_card_iff, Finite.mem_toFinset]
theorem two_lt_ncard (hs : s.Finite := by toFinite_tac) :
    2 < s.ncard ↔ ∃ a ∈ s, ∃ b ∈ s, ∃ c ∈ s, a ≠ b ∧ a ≠ c ∧ b ≠ c := by
  

Proof state:
α : Type u_1
s t : Set α
hs : autoParam (Set.Finite s) _auto✝
⊢ 2 < ncard s ↔ ∃ a ∈ s, ∃ b ∈ s, ∃ c ∈ s, a ≠ b ∧ a ≠ c ∧ b ≠ c

Next tactic:
simp only [two_lt_ncard_iff hs, exists_and_left, exists_prop]
theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s ∧ b ≠ a := by
  

Proof state:
α : Type u_1
s t : Set α
hs : 1 < ncard s
a : α
⊢ ∃ b ∈ s, b ≠ a

Next tactic:
have hsf := (finite_of_ncard_ne_zero (zero_lt_one.trans hs).ne.symm)
theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s ∧ b ≠ a := by
  have hsf := (finite_of_ncard_ne_zero (zero_lt_one.trans hs).ne.symm)
  

Proof state:
α : Type u_1
s t : Set α
hs : 1 < ncard s
a : α
hsf : Set.Finite s
⊢ ∃ b ∈ s, b ≠ a

Next tactic:
rw [ncard_eq_toFinset_card _ hsf] at hs
theorem exists_ne_of_one_lt_ncard (hs : 1 < s.ncard) (a : α) : ∃ b, b ∈ s ∧ b ≠ a := by
  have hsf := (finite_of_ncard_ne_zero (zero_lt_one.trans hs).ne.symm)
  rw [ncard_eq_toFinset_card _ hsf] at hs
  

Proof state:
α : Type u_1
s t : Set α
a : α
hsf : Set.Finite s
hs : 1 < Finset.card (Finite.toFinset hsf)
⊢ ∃ b ∈ s, b ≠ a

Next tactic:
simpa only [Finite.mem_toFinset] using Finset.exists_ne_of_one_lt_card hs a
theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
h : ncard s = n + 1
⊢ ∃ a t, a ∉ t ∧ insert a t = s ∧ ncard t = n

Next tactic:
classical
  have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
  rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_succ] at h
  obtain ⟨a, t, hat, hts, rfl⟩ := h
  simp only [Finset.ext_iff, Finset.mem_insert, Finite.mem_toFinset] at hts
  refine' ⟨a, t, hat, _, _⟩
  · simp only [Finset.mem_coe, ext_iff, mem_insert_iff]
    tauto
  simp
theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  classical
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
h : ncard s = n + 1
⊢ ∃ a t, a ∉ t ∧ insert a t = s ∧ ncard t = n

Next tactic:
have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  classical
  have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
h : ncard s = n + 1
hsf : Set.Finite s
⊢ ∃ a t, a ∉ t ∧ insert a t = s ∧ ncard t = n

Next tactic:
rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_succ] at h
theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  classical
  have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
  rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_succ] at h
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
hsf : Set.Finite s
h : ∃ a t, a ∉ t ∧ insert a t = Finite.toFinset hsf ∧ Finset.card t = n
⊢ ∃ a t, a ∉ t ∧ insert a t = s ∧ ncard t = n

Next tactic:
obtain ⟨a, t, hat, hts, rfl⟩ := h
theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  classical
  have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
  rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_succ] at h
  obtain ⟨a, t, hat, hts, rfl⟩ := h
  

Proof state:
case intro.intro.intro.intro
α : Type u_1
s t✝ : Set α
hsf : Set.Finite s
a : α
t : Finset α
hat : a ∉ t
hts : insert a t = Finite.toFinset hsf
⊢ ∃ a t_1, a ∉ t_1 ∧ insert a t_1 = s ∧ ncard t_1 = Finset.card t

Next tactic:
simp only [Finset.ext_iff, Finset.mem_insert, Finite.mem_toFinset] at hts
theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  classical
  have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
  rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_succ] at h
  obtain ⟨a, t, hat, hts, rfl⟩ := h
  simp only [Finset.ext_iff, Finset.mem_insert, Finite.mem_toFinset] at hts
  

Proof state:
case intro.intro.intro.intro
α : Type u_1
s t✝ : Set α
hsf : Set.Finite s
a : α
t : Finset α
hat : a ∉ t
hts : ∀ (a_1 : α), a_1 = a ∨ a_1 ∈ t ↔ a_1 ∈ s
⊢ ∃ a t_1, a ∉ t_1 ∧ insert a t_1 = s ∧ ncard t_1 = Finset.card t

Next tactic:
refine' ⟨a, t, hat, _, _⟩
theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  classical
  have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
  rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_succ] at h
  obtain ⟨a, t, hat, hts, rfl⟩ := h
  simp only [Finset.ext_iff, Finset.mem_insert, Finite.mem_toFinset] at hts
  refine' ⟨a, t, hat, _, _⟩
  · 

Proof state:
case intro.intro.intro.intro.refine'_1
α : Type u_1
s t✝ : Set α
hsf : Set.Finite s
a : α
t : Finset α
hat : a ∉ t
hts : ∀ (a_1 : α), a_1 = a ∨ a_1 ∈ t ↔ a_1 ∈ s
⊢ insert a ↑t = s

Next tactic:
simp only [Finset.mem_coe, ext_iff, mem_insert_iff]
theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  classical
  have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
  rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_succ] at h
  obtain ⟨a, t, hat, hts, rfl⟩ := h
  simp only [Finset.ext_iff, Finset.mem_insert, Finite.mem_toFinset] at hts
  refine' ⟨a, t, hat, _, _⟩
  · simp only [Finset.mem_coe, ext_iff, mem_insert_iff]
    

Proof state:
case intro.intro.intro.intro.refine'_1
α : Type u_1
s t✝ : Set α
hsf : Set.Finite s
a : α
t : Finset α
hat : a ∉ t
hts : ∀ (a_1 : α), a_1 = a ∨ a_1 ∈ t ↔ a_1 ∈ s
⊢ ∀ (x : α), x = a ∨ x ∈ t ↔ x ∈ s

Next tactic:
tauto
theorem eq_insert_of_ncard_eq_succ {n : ℕ} (h : s.ncard = n + 1) :
    ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  classical
  have hsf := finite_of_ncard_pos (n.zero_lt_succ.trans_eq h.symm)
  rw [ncard_eq_toFinset_card _ hsf, Finset.card_eq_succ] at h
  obtain ⟨a, t, hat, hts, rfl⟩ := h
  simp only [Finset.ext_iff, Finset.mem_insert, Finite.mem_toFinset] at hts
  refine' ⟨a, t, hat, _, _⟩
  · simp only [Finset.mem_coe, ext_iff, mem_insert_iff]
    tauto
  

Proof state:
case intro.intro.intro.intro.refine'_2
α : Type u_1
s t✝ : Set α
hsf : Set.Finite s
a : α
t : Finset α
hat : a ∉ t
hts : ∀ (a_1 : α), a_1 = a ∨ a_1 ∈ t ↔ a_1 ∈ s
⊢ ncard ↑t = Finset.card t

Next tactic:
simp
theorem ncard_eq_succ {n : ℕ} (hs : s.Finite := by toFinite_tac) :
    s.ncard = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
hs : autoParam (Set.Finite s) _auto✝
⊢ ncard s = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ ncard t = n

Next tactic:
refine' ⟨eq_insert_of_ncard_eq_succ, _⟩
theorem ncard_eq_succ {n : ℕ} (hs : s.Finite := by toFinite_tac) :
    s.ncard = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  refine' ⟨eq_insert_of_ncard_eq_succ, _⟩
  

Proof state:
α : Type u_1
s t : Set α
n : ℕ
hs : autoParam (Set.Finite s) _auto✝
⊢ (∃ a t, a ∉ t ∧ insert a t = s ∧ ncard t = n) → ncard s = n + 1

Next tactic:
rintro ⟨a, t, hat, h, rfl⟩
theorem ncard_eq_succ {n : ℕ} (hs : s.Finite := by toFinite_tac) :
    s.ncard = n + 1 ↔ ∃ a t, a ∉ t ∧ insert a t = s ∧ t.ncard = n := by
  refine' ⟨eq_insert_of_ncard_eq_succ, _⟩
  rintro ⟨a, t, hat, h, rfl⟩
  

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

Next tactic:
rw [← h, ncard_insert_of_not_mem hat (hs.subset ((subset_insert a t).trans_eq h))]
theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
  

Proof state:
α : Type u_1
s t : Set α
⊢ ncard s = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y}

Next tactic:
rw [← encard_eq_two, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
  rw [← encard_eq_two, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  

Proof state:
α : Type u_1
s t : Set α
⊢ ↑(ENat.toNat (encard s)) = 2 ↔ encard s = 2

Next tactic:
refine' ⟨fun h ↦ _, fun h ↦ _⟩
theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
  rw [← encard_eq_two, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · 

Proof state:
case refine'_1
α : Type u_1
s t : Set α
h : ↑(ENat.toNat (encard s)) = 2
⊢ encard s = 2

Next tactic:
rwa [ENat.coe_toNat] at h
theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
  rw [← encard_eq_two, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · rwa [ENat.coe_toNat] at h; 

Proof state:
case refine'_1
α : Type u_1
s t : Set α
h : ↑(ENat.toNat (encard s)) = 2
⊢ encard s ≠ ⊤

Next tactic:
rintro h'
theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
  rw [← encard_eq_two, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · rwa [ENat.coe_toNat] at h; rintro h'; 

Proof state:
case refine'_1
α : Type u_1
s t : Set α
h : ↑(ENat.toNat (encard s)) = 2
h' : encard s = ⊤
⊢ False

Next tactic:
simp [h'] at h
theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
  rw [← encard_eq_two, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
  

Proof state:
case refine'_2
α : Type u_1
s t : Set α
h : encard s = 2
⊢ ↑(ENat.toNat (encard s)) = 2

Next tactic:
rw [h]
theorem ncard_eq_two : s.ncard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
  rw [← encard_eq_two, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
  rw [h]; 

Proof state:
case refine'_2
α : Type u_1
s t : Set α
h : encard s = 2
⊢ ↑(ENat.toNat 2) = 2

Next tactic:
rfl
theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
  

Proof state:
α : Type u_1
s t : Set α
⊢ ncard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z}

Next tactic:
rw [← encard_eq_three, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
  rw [← encard_eq_three, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  

Proof state:
α : Type u_1
s t : Set α
⊢ ↑(ENat.toNat (encard s)) = 3 ↔ encard s = 3

Next tactic:
refine' ⟨fun h ↦ _, fun h ↦ _⟩
theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
  rw [← encard_eq_three, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · 

Proof state:
case refine'_1
α : Type u_1
s t : Set α
h : ↑(ENat.toNat (encard s)) = 3
⊢ encard s = 3

Next tactic:
rwa [ENat.coe_toNat] at h
theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
  rw [← encard_eq_three, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · rwa [ENat.coe_toNat] at h; 

Proof state:
case refine'_1
α : Type u_1
s t : Set α
h : ↑(ENat.toNat (encard s)) = 3
⊢ encard s ≠ ⊤

Next tactic:
rintro h'
theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
  rw [← encard_eq_three, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · rwa [ENat.coe_toNat] at h; rintro h'; 

Proof state:
case refine'_1
α : Type u_1
s t : Set α
h : ↑(ENat.toNat (encard s)) = 3
h' : encard s = ⊤
⊢ False

Next tactic:
simp [h'] at h
theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
  rw [← encard_eq_three, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
  

Proof state:
case refine'_2
α : Type u_1
s t : Set α
h : encard s = 3
⊢ ↑(ENat.toNat (encard s)) = 3

Next tactic:
rw [h]
theorem ncard_eq_three : s.ncard = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
  rw [← encard_eq_three, ncard_def, ← Nat.cast_inj (R := ℕ∞), Nat.cast_ofNat]
  refine' ⟨fun h ↦ _, fun h ↦ _⟩
  · rwa [ENat.coe_toNat] at h; rintro h'; simp [h'] at h
  rw [h]; 

Proof state:
case refine'_2
α : Type u_1
s t : Set α
h : encard s = 3
⊢ ↑(ENat.toNat 3) = 3

Next tactic:
rfl
@[simp]
theorem map_units_smul {X Y : C} (r : Rˣ) (f : X ⟶ Y) : F.map (r • f) = r • F.map f := by
  

Proof state:
R : Type u_1
inst✝⁸ : Semiring R
C : Type u_2
D : Type u_3
inst✝⁷ : Category.{u_4, u_2} C
inst✝⁶ : Category.{u_5, u_3} D
inst✝⁵ : Preadditive C
inst✝⁴ : Preadditive D
inst✝³ : CategoryTheory.Linear R C
inst✝² : CategoryTheory.Linear R D
F : C ⥤ D
inst✝¹ : Additive F
inst✝ : Linear R F
X Y : C
r : Rˣ
f : X ⟶ Y
⊢ F.map (r • f) = r • F.map f

Next tactic:
apply map_smul
instance inverseLinear (e : C ≌ D) [e.functor.Additive] [e.functor.Linear R] :
  e.inverse.Linear R where
    map_smul r f := by
      

Proof state:
R : Type u_1
inst✝⁸ : Semiring R
C : Type u_2
D : Type u_3
inst✝⁷ : Category.{?u.32542, u_2} C
inst✝⁶ : Category.{?u.32546, u_3} D
inst✝⁵ : Preadditive C
inst✝⁴ : Linear R C
inst✝³ : Preadditive D
inst✝² : Linear R D
e : C ≌ D
inst✝¹ : Functor.Additive e.functor
inst✝ : Functor.Linear R e.functor
X✝ Y✝ : D
r : X✝ ⟶ Y✝
f : R
⊢ e.inverse.map (f • r) = f • e.inverse.map r

Next tactic:
apply e.functor.map_injective
instance inverseLinear (e : C ≌ D) [e.functor.Additive] [e.functor.Linear R] :
  e.inverse.Linear R where
    map_smul r f := by
      apply e.functor.map_injective
      

Proof state:
case a
R : Type u_1
inst✝⁸ : Semiring R
C : Type u_2
D : Type u_3
inst✝⁷ : Category.{?u.32542, u_2} C
inst✝⁶ : Category.{?u.32546, u_3} D
inst✝⁵ : Preadditive C
inst✝⁴ : Linear R C
inst✝³ : Preadditive D
inst✝² : Linear R D
e : C ≌ D
inst✝¹ : Functor.Additive e.functor
inst✝ : Functor.Linear R e.functor
X✝ Y✝ : D
r : X✝ ⟶ Y✝
f : R
⊢ e.functor.map (e.inverse.map (f • r)) = e.functor.map (f • e.inverse.map r)

Next tactic:
simp
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem MonovaryOn.sum_smul_sum_le_card_smul_sum (hfg : MonovaryOn f g s) :
    ((∑ i in s, f i) • ∑ i in s, g i) ≤ s.card • ∑ i in s, f i • g i := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝³ : LinearOrderedRing α
inst✝² : LinearOrderedAddCommGroup β
inst✝¹ : Module α β
inst✝ : OrderedSMul α β
s : Finset ι
σ : Perm ι
f : ι → α
g : ι → β
hfg : MonovaryOn f g ↑s
⊢ (∑ i in s, f i) • ∑ i in s, g i ≤ card s • ∑ i in s, f i • g i

Next tactic:
classical
    obtain ⟨σ, hσ, hs⟩ := s.countable_toSet.exists_cycleOn
    rw [← card_range s.card, sum_smul_sum_eq_sum_perm hσ]
    exact
      sum_le_card_nsmul _ _ _ fun n _ =>
        hfg.sum_smul_comp_perm_le_sum_smul fun x hx => hs fun h => hx <| IsFixedPt.perm_pow h _
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem MonovaryOn.sum_smul_sum_le_card_smul_sum (hfg : MonovaryOn f g s) :
    ((∑ i in s, f i) • ∑ i in s, g i) ≤ s.card • ∑ i in s, f i • g i := by
  classical
    

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝³ : LinearOrderedRing α
inst✝² : LinearOrderedAddCommGroup β
inst✝¹ : Module α β
inst✝ : OrderedSMul α β
s : Finset ι
σ : Perm ι
f : ι → α
g : ι → β
hfg : MonovaryOn f g ↑s
⊢ (∑ i in s, f i) • ∑ i in s, g i ≤ card s • ∑ i in s, f i • g i

Next tactic:
obtain ⟨σ, hσ, hs⟩ := s.countable_toSet.exists_cycleOn
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem MonovaryOn.sum_smul_sum_le_card_smul_sum (hfg : MonovaryOn f g s) :
    ((∑ i in s, f i) • ∑ i in s, g i) ≤ s.card • ∑ i in s, f i • g i := by
  classical
    obtain ⟨σ, hσ, hs⟩ := s.countable_toSet.exists_cycleOn
    

Proof state:
case intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝³ : LinearOrderedRing α
inst✝² : LinearOrderedAddCommGroup β
inst✝¹ : Module α β
inst✝ : OrderedSMul α β
s : Finset ι
σ✝ : Perm ι
f : ι → α
g : ι → β
hfg : MonovaryOn f g ↑s
σ : Perm ι
hσ : IsCycleOn σ ↑s
hs : {x | σ x ≠ x} ⊆ ↑s
⊢ (∑ i in s, f i) • ∑ i in s, g i ≤ card s • ∑ i in s, f i • g i

Next tactic:
rw [← card_range s.card, sum_smul_sum_eq_sum_perm hσ]
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem MonovaryOn.sum_smul_sum_le_card_smul_sum (hfg : MonovaryOn f g s) :
    ((∑ i in s, f i) • ∑ i in s, g i) ≤ s.card • ∑ i in s, f i • g i := by
  classical
    obtain ⟨σ, hσ, hs⟩ := s.countable_toSet.exists_cycleOn
    rw [← card_range s.card, sum_smul_sum_eq_sum_perm hσ]
    

Proof state:
case intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝³ : LinearOrderedRing α
inst✝² : LinearOrderedAddCommGroup β
inst✝¹ : Module α β
inst✝ : OrderedSMul α β
s : Finset ι
σ✝ : Perm ι
f : ι → α
g : ι → β
hfg : MonovaryOn f g ↑s
σ : Perm ι
hσ : IsCycleOn σ ↑s
hs : {x | σ x ≠ x} ⊆ ↑s
⊢ ∑ k in range (card s), ∑ i in s, f i • g ((σ ^ k) i) ≤ card (range (card s)) • ∑ i in s, f i • g i

Next tactic:
exact
      sum_le_card_nsmul _ _ _ fun n _ =>
        hfg.sum_smul_comp_perm_le_sum_smul fun x hx => hs fun h => hx <| IsFixedPt.perm_pow h _
/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the
other is antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem AntivaryOn.card_smul_sum_le_sum_smul_sum (hfg : AntivaryOn f g s) :
    (s.card • ∑ i in s, f i • g i) ≤ (∑ i in s, f i) • ∑ i in s, g i := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝³ : LinearOrderedRing α
inst✝² : LinearOrderedAddCommGroup β
inst✝¹ : Module α β
inst✝ : OrderedSMul α β
s : Finset ι
σ : Perm ι
f : ι → α
g : ι → β
hfg : AntivaryOn f g ↑s
⊢ card s • ∑ i in s, f i • g i ≤ (∑ i in s, f i) • ∑ i in s, g i

Next tactic:
refine hfg.dual_right.sum_smul_sum_le_card_smul_sum
/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the
other is antitone), the scalar product of their sum is less than the size of the set times their
scalar product. -/
theorem Antivary.card_smul_sum_le_sum_smul_sum (hfg : Antivary f g) :
    (Fintype.card ι • ∑ i, f i • g i) ≤ (∑ i, f i) • ∑ i, g i := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝⁴ : LinearOrderedRing α
inst✝³ : LinearOrderedAddCommGroup β
inst✝² : Module α β
inst✝¹ : OrderedSMul α β
s : Finset ι
σ : Perm ι
f : ι → α
g : ι → β
inst✝ : Fintype ι
hfg : Antivary f g
⊢ Fintype.card ι • ∑ i : ι, f i • g i ≤ (∑ i : ι, f i) • ∑ i : ι, g i

Next tactic:
refine (hfg.dual_right.monovaryOn _).sum_smul_sum_le_card_smul_sum
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the product of their sum is less than the size of the set times their scalar
product. -/
theorem MonovaryOn.sum_mul_sum_le_card_mul_sum (hfg : MonovaryOn f g s) :
    ((∑ i in s, f i) * ∑ i in s, g i) ≤ s.card * ∑ i in s, f i * g i := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝ : LinearOrderedRing α
s : Finset ι
σ : Perm ι
f g : ι → α
hfg : MonovaryOn f g ↑s
⊢ (∑ i in s, f i) * ∑ i in s, g i ≤ ↑(card s) * ∑ i in s, f i * g i

Next tactic:
rw [← nsmul_eq_mul]
/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both
monotone/antitone), the product of their sum is less than the size of the set times their scalar
product. -/
theorem MonovaryOn.sum_mul_sum_le_card_mul_sum (hfg : MonovaryOn f g s) :
    ((∑ i in s, f i) * ∑ i in s, g i) ≤ s.card * ∑ i in s, f i * g i := by
  rw [← nsmul_eq_mul]
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝ : LinearOrderedRing α
s : Finset ι
σ : Perm ι
f g : ι → α
hfg : MonovaryOn f g ↑s
⊢ (∑ i in s, f i) * ∑ i in s, g i ≤ card s • ∑ i in s, f i * g i

Next tactic:
exact hfg.sum_smul_sum_le_card_smul_sum
/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the
other is antitone), the product of their sum is greater than the size of the set times their scalar
product. -/
theorem AntivaryOn.card_mul_sum_le_sum_mul_sum (hfg : AntivaryOn f g s) :
    ((s.card : α) * ∑ i in s, f i * g i) ≤ (∑ i in s, f i) * ∑ i in s, g i := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝ : LinearOrderedRing α
s : Finset ι
σ : Perm ι
f g : ι → α
hfg : AntivaryOn f g ↑s
⊢ ↑(card s) * ∑ i in s, f i * g i ≤ (∑ i in s, f i) * ∑ i in s, g i

Next tactic:
rw [← nsmul_eq_mul]
/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the
other is antitone), the product of their sum is greater than the size of the set times their scalar
product. -/
theorem AntivaryOn.card_mul_sum_le_sum_mul_sum (hfg : AntivaryOn f g s) :
    ((s.card : α) * ∑ i in s, f i * g i) ≤ (∑ i in s, f i) * ∑ i in s, g i := by
  rw [← nsmul_eq_mul]
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝ : LinearOrderedRing α
s : Finset ι
σ : Perm ι
f g : ι → α
hfg : AntivaryOn f g ↑s
⊢ card s • ∑ i in s, f i * g i ≤ (∑ i in s, f i) * ∑ i in s, g i

Next tactic:
exact hfg.card_smul_sum_le_sum_smul_sum
/-- Special case of **Chebyshev's Sum Inequality** or the **Cauchy-Schwarz Inequality**: The square
of the sum is less than the size of the set times the sum of the squares. -/
theorem sq_sum_le_card_mul_sum_sq : (∑ i in s, f i) ^ 2 ≤ s.card * ∑ i in s, f i ^ 2 := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝ : LinearOrderedRing α
s : Finset ι
σ : Perm ι
f g : ι → α
⊢ (∑ i in s, f i) ^ 2 ≤ ↑(card s) * ∑ i in s, f i ^ 2

Next tactic:
simp_rw [sq]
/-- Special case of **Chebyshev's Sum Inequality** or the **Cauchy-Schwarz Inequality**: The square
of the sum is less than the size of the set times the sum of the squares. -/
theorem sq_sum_le_card_mul_sum_sq : (∑ i in s, f i) ^ 2 ≤ s.card * ∑ i in s, f i ^ 2 := by
  simp_rw [sq]
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
inst✝ : LinearOrderedRing α
s : Finset ι
σ : Perm ι
f g : ι → α
⊢ (∑ i in s, f i) * ∑ i in s, f i ≤ ↑(card s) * ∑ x in s, f x * f x

Next tactic:
exact (monovaryOn_self _ _).sum_mul_sum_le_card_mul_sum