l3lab/ntp-mathlib huggingface dataset:
/-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even. -/
protected lemma Even.convexOn_pow {n : ℕ} (hn : Even n) : ConvexOn 𝕜 univ fun x : 𝕜 ↦ x ^ n := by
  obtain ⟨n, rfl⟩ := hn
  simp_rw [← two_mul, pow_mul]
  refine ConvexOn.pow ⟨convex_univ, fun x _ y _ a b ha hb hab ↦ sub_nonneg.1 ?_⟩
    (fun _ _ ↦ by positivity) _
  

Proof state:
case intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝¹² : LinearOrderedCommRing 𝕜
inst✝¹¹ : LinearOrderedCommRing E
inst✝¹⁰ : LinearOrderedAddCommGroup F
inst✝⁹ : Module 𝕜 E
inst✝⁸ : Module 𝕜 F
inst✝⁷ : Module E F
inst✝⁶ : IsScalarTower 𝕜 E F
inst✝⁵ : SMulCommClass 𝕜 E F
inst✝⁴ : OrderedSMul 𝕜 E
inst✝³ : OrderedSMul 𝕜 F
inst✝² : OrderedSMul E F
s : Set 𝕜
f✝ : 𝕜 → E
g✝ : 𝕜 → F
inst✝¹ : IsScalarTower 𝕜 E E
inst✝ : SMulCommClass 𝕜 E E
f g : 𝕜 → E
n : ℕ
x : 𝕜
x✝¹ : x ∈ univ
y : 𝕜
x✝ : y ∈ univ
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ 0 ≤ a • x ^ 2 + b • y ^ 2 - (a • x + b • y) ^ 2

Next tactic:
calc
    (0 : 𝕜) ≤ (a * b) * (x - y) ^ 2 := by positivity
    _ = _ := by obtain rfl := eq_sub_of_add_eq hab; simp only [smul_eq_mul]; ring
/-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even. -/
protected lemma Even.convexOn_pow {n : ℕ} (hn : Even n) : ConvexOn 𝕜 univ fun x : 𝕜 ↦ x ^ n := by
  obtain ⟨n, rfl⟩ := hn
  simp_rw [← two_mul, pow_mul]
  refine ConvexOn.pow ⟨convex_univ, fun x _ y _ a b ha hb hab ↦ sub_nonneg.1 ?_⟩
    (fun _ _ ↦ by positivity) _
  calc
    (0 : 𝕜) ≤ (a * b) * (x - y) ^ 2 := by 

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝¹² : LinearOrderedCommRing 𝕜
inst✝¹¹ : LinearOrderedCommRing E
inst✝¹⁰ : LinearOrderedAddCommGroup F
inst✝⁹ : Module 𝕜 E
inst✝⁸ : Module 𝕜 F
inst✝⁷ : Module E F
inst✝⁶ : IsScalarTower 𝕜 E F
inst✝⁵ : SMulCommClass 𝕜 E F
inst✝⁴ : OrderedSMul 𝕜 E
inst✝³ : OrderedSMul 𝕜 F
inst✝² : OrderedSMul E F
s : Set 𝕜
f✝ : 𝕜 → E
g✝ : 𝕜 → F
inst✝¹ : IsScalarTower 𝕜 E E
inst✝ : SMulCommClass 𝕜 E E
f g : 𝕜 → E
n : ℕ
x : 𝕜
x✝¹ : x ∈ univ
y : 𝕜
x✝ : y ∈ univ
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ 0 ≤ a * b * (x - y) ^ 2

Next tactic:
positivity
/-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even. -/
protected lemma Even.convexOn_pow {n : ℕ} (hn : Even n) : ConvexOn 𝕜 univ fun x : 𝕜 ↦ x ^ n := by
  obtain ⟨n, rfl⟩ := hn
  simp_rw [← two_mul, pow_mul]
  refine ConvexOn.pow ⟨convex_univ, fun x _ y _ a b ha hb hab ↦ sub_nonneg.1 ?_⟩
    (fun _ _ ↦ by positivity) _
  calc
    (0 : 𝕜) ≤ (a * b) * (x - y) ^ 2 := by positivity
    _ = _ := by 

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝¹² : LinearOrderedCommRing 𝕜
inst✝¹¹ : LinearOrderedCommRing E
inst✝¹⁰ : LinearOrderedAddCommGroup F
inst✝⁹ : Module 𝕜 E
inst✝⁸ : Module 𝕜 F
inst✝⁷ : Module E F
inst✝⁶ : IsScalarTower 𝕜 E F
inst✝⁵ : SMulCommClass 𝕜 E F
inst✝⁴ : OrderedSMul 𝕜 E
inst✝³ : OrderedSMul 𝕜 F
inst✝² : OrderedSMul E F
s : Set 𝕜
f✝ : 𝕜 → E
g✝ : 𝕜 → F
inst✝¹ : IsScalarTower 𝕜 E E
inst✝ : SMulCommClass 𝕜 E E
f g : 𝕜 → E
n : ℕ
x : 𝕜
x✝¹ : x ∈ univ
y : 𝕜
x✝ : y ∈ univ
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ a * b * (x - y) ^ 2 = a • x ^ 2 + b • y ^ 2 - (a • x + b • y) ^ 2

Next tactic:
obtain rfl := eq_sub_of_add_eq hab
/-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even. -/
protected lemma Even.convexOn_pow {n : ℕ} (hn : Even n) : ConvexOn 𝕜 univ fun x : 𝕜 ↦ x ^ n := by
  obtain ⟨n, rfl⟩ := hn
  simp_rw [← two_mul, pow_mul]
  refine ConvexOn.pow ⟨convex_univ, fun x _ y _ a b ha hb hab ↦ sub_nonneg.1 ?_⟩
    (fun _ _ ↦ by positivity) _
  calc
    (0 : 𝕜) ≤ (a * b) * (x - y) ^ 2 := by positivity
    _ = _ := by obtain rfl := eq_sub_of_add_eq hab; 

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝¹² : LinearOrderedCommRing 𝕜
inst✝¹¹ : LinearOrderedCommRing E
inst✝¹⁰ : LinearOrderedAddCommGroup F
inst✝⁹ : Module 𝕜 E
inst✝⁸ : Module 𝕜 F
inst✝⁷ : Module E F
inst✝⁶ : IsScalarTower 𝕜 E F
inst✝⁵ : SMulCommClass 𝕜 E F
inst✝⁴ : OrderedSMul 𝕜 E
inst✝³ : OrderedSMul 𝕜 F
inst✝² : OrderedSMul E F
s : Set 𝕜
f✝ : 𝕜 → E
g✝ : 𝕜 → F
inst✝¹ : IsScalarTower 𝕜 E E
inst✝ : SMulCommClass 𝕜 E E
f g : 𝕜 → E
n : ℕ
x : 𝕜
x✝¹ : x ∈ univ
y : 𝕜
x✝ : y ∈ univ
b : 𝕜
hb : 0 ≤ b
ha : 0 ≤ 1 - b
hab : 1 - b + b = 1
⊢ (1 - b) * b * (x - y) ^ 2 = (1 - b) • x ^ 2 + b • y ^ 2 - ((1 - b) • x + b • y) ^ 2

Next tactic:
simp only [smul_eq_mul]
/-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even. -/
protected lemma Even.convexOn_pow {n : ℕ} (hn : Even n) : ConvexOn 𝕜 univ fun x : 𝕜 ↦ x ^ n := by
  obtain ⟨n, rfl⟩ := hn
  simp_rw [← two_mul, pow_mul]
  refine ConvexOn.pow ⟨convex_univ, fun x _ y _ a b ha hb hab ↦ sub_nonneg.1 ?_⟩
    (fun _ _ ↦ by positivity) _
  calc
    (0 : 𝕜) ≤ (a * b) * (x - y) ^ 2 := by positivity
    _ = _ := by obtain rfl := eq_sub_of_add_eq hab; simp only [smul_eq_mul]; 

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝¹² : LinearOrderedCommRing 𝕜
inst✝¹¹ : LinearOrderedCommRing E
inst✝¹⁰ : LinearOrderedAddCommGroup F
inst✝⁹ : Module 𝕜 E
inst✝⁸ : Module 𝕜 F
inst✝⁷ : Module E F
inst✝⁶ : IsScalarTower 𝕜 E F
inst✝⁵ : SMulCommClass 𝕜 E F
inst✝⁴ : OrderedSMul 𝕜 E
inst✝³ : OrderedSMul 𝕜 F
inst✝² : OrderedSMul E F
s : Set 𝕜
f✝ : 𝕜 → E
g✝ : 𝕜 → F
inst✝¹ : IsScalarTower 𝕜 E E
inst✝ : SMulCommClass 𝕜 E E
f g : 𝕜 → E
n : ℕ
x : 𝕜
x✝¹ : x ∈ univ
y : 𝕜
x✝ : y ∈ univ
b : 𝕜
hb : 0 ≤ b
ha : 0 ≤ 1 - b
hab : 1 - b + b = 1
⊢ (1 - b) * b * (x - y) ^ 2 = (1 - b) * x ^ 2 + b * y ^ 2 - ((1 - b) * x + b * y) ^ 2

Next tactic:
ring
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
⊢ ConvexOn 𝕜 (Ioi 0) fun x => x ^ ↑n

Next tactic:
simp_rw [zpow_ofNat]
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
⊢ ConvexOn 𝕜 (Ioi 0) fun x => x ^ n

Next tactic:
exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
⊢ ConvexOn 𝕜 (Ioi 0) fun x => x ^ -[n+1]

Next tactic:
simp_rw [zpow_negSucc, ← inv_pow]
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
⊢ ConvexOn 𝕜 (Ioi 0) fun x => x⁻¹ ^ (n + 1)

Next tactic:
refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by 

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
⊢ 0 ≤ x⁻¹

Next tactic:
positivity
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
⊢ ∀ ⦃x : 𝕜⦄,
    x ∈ Ioi 0 → ∀ ⦃y : 𝕜⦄, y ∈ Ioi 0 → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → (a • x + b • y)⁻¹ ≤ a • x⁻¹ + b • y⁻¹

Next tactic:
rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
    

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ (a • x + b • y)⁻¹ ≤ a • x⁻¹ + b • y⁻¹

Next tactic:
field_simp
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
    field_simp
    

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ 1 / (a * x + b * y) ≤ (a * y + b * x) / (x * y)

Next tactic:
rw [div_le_div_iff, ← sub_nonneg]
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
    field_simp
    rw [div_le_div_iff, ← sub_nonneg]
    

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ 0 ≤ (a * y + b * x) * (a * x + b * y) - 1 * (x * y)
case b0
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ 0 < a * x + b * y
case d0
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ 0 < x * y

Next tactic:
calc
      0 ≤ a * b * (x - y) ^ 2 := by positivity
      _ = _ := by obtain rfl := eq_sub_of_add_eq hab; ring
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
    field_simp
    rw [div_le_div_iff, ← sub_nonneg]
    calc
      0 ≤ a * b * (x - y) ^ 2 := by 

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ 0 ≤ a * b * (x - y) ^ 2

Next tactic:
positivity
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
    field_simp
    rw [div_le_div_iff, ← sub_nonneg]
    calc
      0 ≤ a * b * (x - y) ^ 2 := by positivity
      _ = _ := by 

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ a * b * (x - y) ^ 2 = (a * y + b * x) * (a * x + b * y) - 1 * (x * y)

Next tactic:
obtain rfl := eq_sub_of_add_eq hab
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
    field_simp
    rw [div_le_div_iff, ← sub_nonneg]
    calc
      0 ≤ a * b * (x - y) ^ 2 := by positivity
      _ = _ := by obtain rfl := eq_sub_of_add_eq hab; 

Proof state:
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
b : 𝕜
hb : 0 < b
ha : 0 < 1 - b
hab : 1 - b + b = 1
⊢ (1 - b) * b * (x - y) ^ 2 = ((1 - b) * y + b * x) * ((1 - b) * x + b * y) - 1 * (x * y)

Next tactic:
ring
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
    field_simp
    rw [div_le_div_iff, ← sub_nonneg]
    calc
      0 ≤ a * b * (x - y) ^ 2 := by positivity
      _ = _ := by obtain rfl := eq_sub_of_add_eq hab; ring
    

Proof state:
case b0
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ 0 < a * x + b * y
case d0
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ 0 < x * y

Next tactic:
all_goals positivity
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
    field_simp
    rw [div_le_div_iff, ← sub_nonneg]
    calc
      0 ≤ a * b * (x - y) ^ 2 := by positivity
      _ = _ := by obtain rfl := eq_sub_of_add_eq hab; ring
    all_goals 

Proof state:
case b0
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ 0 < a * x + b * y

Next tactic:
positivity
open Int in
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/
lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n
  | (n : ℕ) => by
    simp_rw [zpow_ofNat]
    exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _)
  | -[n+1] => by
    simp_rw [zpow_negSucc, ← inv_pow]
    refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _
    rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab
    field_simp
    rw [div_le_div_iff, ← sub_nonneg]
    calc
      0 ≤ a * b * (x - y) ^ 2 := by positivity
      _ = _ := by obtain rfl := eq_sub_of_add_eq hab; ring
    all_goals 

Proof state:
case d0
𝕜 : Type u_1
E : Type u_2
F : Type u_3
inst✝ : LinearOrderedField 𝕜
n : ℕ
x : 𝕜
hx : 0 < x
y : 𝕜
hy : 0 < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ 0 < x * y

Next tactic:
positivity
theorem ContinuousLinearMap.dslope_comp {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
    (f : E →L[𝕜] F) (g : 𝕜 → E) (a b : 𝕜) (H : a = b → DifferentiableAt 𝕜 g a) :
    dslope (f ∘ g) a b = f (dslope g a b) := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝⁴ : NontriviallyNormedField 𝕜
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace 𝕜 E
f✝ : 𝕜 → E
a✝ b✝ : 𝕜
s : Set 𝕜
F : Type u_3
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace 𝕜 F
f : E →L[𝕜] F
g : 𝕜 → E
a b : 𝕜
H : a = b → DifferentiableAt 𝕜 g a
⊢ dslope (⇑f ∘ g) a b = f (dslope g a b)

Next tactic:
rcases eq_or_ne b a with (rfl | hne)
theorem ContinuousLinearMap.dslope_comp {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
    (f : E →L[𝕜] F) (g : 𝕜 → E) (a b : 𝕜) (H : a = b → DifferentiableAt 𝕜 g a) :
    dslope (f ∘ g) a b = f (dslope g a b) := by
  rcases eq_or_ne b a with (rfl | hne)
  · 

Proof state:
case inl
𝕜 : Type u_1
E : Type u_2
inst✝⁴ : NontriviallyNormedField 𝕜
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace 𝕜 E
f✝ : 𝕜 → E
a b✝ : 𝕜
s : Set 𝕜
F : Type u_3
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace 𝕜 F
f : E →L[𝕜] F
g : 𝕜 → E
b : 𝕜
H : b = b → DifferentiableAt 𝕜 g b
⊢ dslope (⇑f ∘ g) b b = f (dslope g b b)

Next tactic:
simp only [dslope_same]
theorem ContinuousLinearMap.dslope_comp {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
    (f : E →L[𝕜] F) (g : 𝕜 → E) (a b : 𝕜) (H : a = b → DifferentiableAt 𝕜 g a) :
    dslope (f ∘ g) a b = f (dslope g a b) := by
  rcases eq_or_ne b a with (rfl | hne)
  · simp only [dslope_same]
    

Proof state:
case inl
𝕜 : Type u_1
E : Type u_2
inst✝⁴ : NontriviallyNormedField 𝕜
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace 𝕜 E
f✝ : 𝕜 → E
a b✝ : 𝕜
s : Set 𝕜
F : Type u_3
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace 𝕜 F
f : E →L[𝕜] F
g : 𝕜 → E
b : 𝕜
H : b = b → DifferentiableAt 𝕜 g b
⊢ deriv (⇑f ∘ g) b = f (deriv g b)

Next tactic:
exact (f.hasFDerivAt.comp_hasDerivAt b (H rfl).hasDerivAt).deriv
theorem ContinuousLinearMap.dslope_comp {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
    (f : E →L[𝕜] F) (g : 𝕜 → E) (a b : 𝕜) (H : a = b → DifferentiableAt 𝕜 g a) :
    dslope (f ∘ g) a b = f (dslope g a b) := by
  rcases eq_or_ne b a with (rfl | hne)
  · simp only [dslope_same]
    exact (f.hasFDerivAt.comp_hasDerivAt b (H rfl).hasDerivAt).deriv
  · 

Proof state:
case inr
𝕜 : Type u_1
E : Type u_2
inst✝⁴ : NontriviallyNormedField 𝕜
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace 𝕜 E
f✝ : 𝕜 → E
a✝ b✝ : 𝕜
s : Set 𝕜
F : Type u_3
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace 𝕜 F
f : E →L[𝕜] F
g : 𝕜 → E
a b : 𝕜
H : a = b → DifferentiableAt 𝕜 g a
hne : b ≠ a
⊢ dslope (⇑f ∘ g) a b = f (dslope g a b)

Next tactic:
simpa only [dslope_of_ne _ hne] using f.toLinearMap.slope_comp g a b
@[simp]
theorem sub_smul_dslope (f : 𝕜 → E) (a b : 𝕜) : (b - a) • dslope f a b = f b - f a := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f✝ : 𝕜 → E
a✝ b✝ : 𝕜
s : Set 𝕜
f : 𝕜 → E
a b : 𝕜
⊢ (b - a) • dslope f a b = f b - f a

Next tactic:
rcases eq_or_ne b a with (rfl | hne)
@[simp]
theorem sub_smul_dslope (f : 𝕜 → E) (a b : 𝕜) : (b - a) • dslope f a b = f b - f a := by
  rcases eq_or_ne b a with (rfl | hne) <;> 

Proof state:
case inl
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f✝ : 𝕜 → E
a b✝ : 𝕜
s : Set 𝕜
f : 𝕜 → E
b : 𝕜
⊢ (b - b) • dslope f b b = f b - f b

Next tactic:
simp [dslope_of_ne, *]
@[simp]
theorem sub_smul_dslope (f : 𝕜 → E) (a b : 𝕜) : (b - a) • dslope f a b = f b - f a := by
  rcases eq_or_ne b a with (rfl | hne) <;> 

Proof state:
case inr
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f✝ : 𝕜 → E
a✝ b✝ : 𝕜
s : Set 𝕜
f : 𝕜 → E
a b : 𝕜
hne : b ≠ a
⊢ (b - a) • dslope f a b = f b - f a

Next tactic:
simp [dslope_of_ne, *]
theorem dslope_sub_smul_of_ne (f : 𝕜 → E) (h : b ≠ a) :
    dslope (fun x => (x - a) • f x) a b = f b := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f✝ : 𝕜 → E
a b : 𝕜
s : Set 𝕜
f : 𝕜 → E
h : b ≠ a
⊢ dslope (fun x => (x - a) • f x) a b = f b

Next tactic:
rw [dslope_of_ne _ h, slope_sub_smul _ h.symm]
@[simp]
theorem continuousAt_dslope_same : ContinuousAt (dslope f a) a ↔ DifferentiableAt 𝕜 f a := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
⊢ ContinuousAt (dslope f a) a ↔ DifferentiableAt 𝕜 f a

Next tactic:
simp only [dslope, continuousAt_update_same, ← hasDerivAt_deriv_iff, hasDerivAt_iff_tendsto_slope]
theorem ContinuousWithinAt.of_dslope (h : ContinuousWithinAt (dslope f a) s b) :
    ContinuousWithinAt f s b := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : ContinuousWithinAt (dslope f a) s b
⊢ ContinuousWithinAt f s b

Next tactic:
have : ContinuousWithinAt (fun x => (x - a) • dslope f a x + f a) s b :=
    ((continuousWithinAt_id.sub continuousWithinAt_const).smul h).add continuousWithinAt_const
theorem ContinuousWithinAt.of_dslope (h : ContinuousWithinAt (dslope f a) s b) :
    ContinuousWithinAt f s b := by
  have : ContinuousWithinAt (fun x => (x - a) • dslope f a x + f a) s b :=
    ((continuousWithinAt_id.sub continuousWithinAt_const).smul h).add continuousWithinAt_const
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : ContinuousWithinAt (dslope f a) s b
this : ContinuousWithinAt (fun x => (x - a) • dslope f a x + f a) s b
⊢ ContinuousWithinAt f s b

Next tactic:
simpa only [sub_smul_dslope, sub_add_cancel] using this
theorem continuousWithinAt_dslope_of_ne (h : b ≠ a) :
    ContinuousWithinAt (dslope f a) s b ↔ ContinuousWithinAt f s b := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : b ≠ a
⊢ ContinuousWithinAt (dslope f a) s b ↔ ContinuousWithinAt f s b

Next tactic:
refine' ⟨ContinuousWithinAt.of_dslope, fun hc => _⟩
theorem continuousWithinAt_dslope_of_ne (h : b ≠ a) :
    ContinuousWithinAt (dslope f a) s b ↔ ContinuousWithinAt f s b := by
  refine' ⟨ContinuousWithinAt.of_dslope, fun hc => _⟩
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : b ≠ a
hc : ContinuousWithinAt f s b
⊢ ContinuousWithinAt (dslope f a) s b

Next tactic:
simp only [dslope, continuousWithinAt_update_of_ne h]
theorem continuousWithinAt_dslope_of_ne (h : b ≠ a) :
    ContinuousWithinAt (dslope f a) s b ↔ ContinuousWithinAt f s b := by
  refine' ⟨ContinuousWithinAt.of_dslope, fun hc => _⟩
  simp only [dslope, continuousWithinAt_update_of_ne h]
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : b ≠ a
hc : ContinuousWithinAt f s b
⊢ ContinuousWithinAt (slope f a) s b

Next tactic:
exact ((continuousWithinAt_id.sub continuousWithinAt_const).inv₀ (sub_ne_zero.2 h)).smul
    (hc.sub continuousWithinAt_const)
theorem continuousAt_dslope_of_ne (h : b ≠ a) : ContinuousAt (dslope f a) b ↔ ContinuousAt f b := by
  

Proof state:
𝕜 : Type u_1
E : Type u_2
inst✝² : NontriviallyNormedField 𝕜
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace 𝕜 E
f : 𝕜 → E
a b : 𝕜
s : Set 𝕜
h : b ≠ a
⊢ ContinuousAt (dslope f a) b ↔ ContinuousAt f b

Next tactic:
simp only [← continuousWithinAt_univ, continuousWithinAt_dslope_of_ne h]