l3lab/ntp-mathlib huggingface dataset:
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
  rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
  field_simp
  apply or_congr
  · constructor <;> 

Proof state:
case h₁.mp
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
s : K
h : discrim a b c = s * s
x : K
⊢ s = 2 * a * x + b → x * (2 * a) = -b + s

Next tactic:
intro h'
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
  rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
  field_simp
  apply or_congr
  · constructor <;> 

Proof state:
case h₁.mpr
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
s : K
h : discrim a b c = s * s
x : K
⊢ x * (2 * a) = -b + s → s = 2 * a * x + b

Next tactic:
intro h'
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
  rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
  field_simp
  apply or_congr
  · constructor <;> intro h' <;> 

Proof state:
case h₁.mp
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
s : K
h : discrim a b c = s * s
x : K
h' : s = 2 * a * x + b
⊢ x * (2 * a) = -b + s

Next tactic:
linear_combination -h'
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
  rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
  field_simp
  apply or_congr
  · constructor <;> intro h' <;> 

Proof state:
case h₁.mpr
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
s : K
h : discrim a b c = s * s
x : K
h' : x * (2 * a) = -b + s
⊢ s = 2 * a * x + b

Next tactic:
linear_combination -h'
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
  rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
  field_simp
  apply or_congr
  · constructor <;> intro h' <;> linear_combination -h'
  · 

Proof state:
case h₂
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
s : K
h : discrim a b c = s * s
x : K
⊢ s = -b + -(2 * a * x) ↔ x * (2 * a) = -b - s

Next tactic:
constructor
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
  rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
  field_simp
  apply or_congr
  · constructor <;> intro h' <;> linear_combination -h'
  · constructor <;> 

Proof state:
case h₂.mp
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
s : K
h : discrim a b c = s * s
x : K
⊢ s = -b + -(2 * a * x) → x * (2 * a) = -b - s

Next tactic:
intro h'
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
  rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
  field_simp
  apply or_congr
  · constructor <;> intro h' <;> linear_combination -h'
  · constructor <;> 

Proof state:
case h₂.mpr
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
s : K
h : discrim a b c = s * s
x : K
⊢ x * (2 * a) = -b - s → s = -b + -(2 * a * x)

Next tactic:
intro h'
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
  rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
  field_simp
  apply or_congr
  · constructor <;> intro h' <;> linear_combination -h'
  · constructor <;> intro h' <;> 

Proof state:
case h₂.mp
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
s : K
h : discrim a b c = s * s
x : K
h' : s = -b + -(2 * a * x)
⊢ x * (2 * a) = -b - s

Next tactic:
linear_combination h'
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
  rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
  field_simp
  apply or_congr
  · constructor <;> intro h' <;> linear_combination -h'
  · constructor <;> intro h' <;> 

Proof state:
case h₂.mpr
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
s : K
h : discrim a b c = s * s
x : K
h' : x * (2 * a) = -b - s
⊢ s = -b + -(2 * a * x)

Next tactic:
linear_combination h'
/-- A quadratic has roots if its discriminant has square roots -/
theorem exists_quadratic_eq_zero (ha : a ≠ 0) (h : ∃ s, discrim a b c = s * s) :
    ∃ x, a * x * x + b * x + c = 0 := by
  

Proof state:
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x : K
ha : a ≠ 0
h : ∃ s, discrim a b c = s * s
⊢ ∃ x, a * x * x + b * x + c = 0

Next tactic:
rcases h with ⟨s, hs⟩
/-- A quadratic has roots if its discriminant has square roots -/
theorem exists_quadratic_eq_zero (ha : a ≠ 0) (h : ∃ s, discrim a b c = s * s) :
    ∃ x, a * x * x + b * x + c = 0 := by
  rcases h with ⟨s, hs⟩
  

Proof state:
case intro
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x : K
ha : a ≠ 0
s : K
hs : discrim a b c = s * s
⊢ ∃ x, a * x * x + b * x + c = 0

Next tactic:
use (-b + s) / (2 * a)
/-- A quadratic has roots if its discriminant has square roots -/
theorem exists_quadratic_eq_zero (ha : a ≠ 0) (h : ∃ s, discrim a b c = s * s) :
    ∃ x, a * x * x + b * x + c = 0 := by
  rcases h with ⟨s, hs⟩
  use (-b + s) / (2 * a)
  

Proof state:
case h
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x : K
ha : a ≠ 0
s : K
hs : discrim a b c = s * s
⊢ a * ((-b + s) / (2 * a)) * ((-b + s) / (2 * a)) + b * ((-b + s) / (2 * a)) + c = 0

Next tactic:
rw [quadratic_eq_zero_iff ha hs]
/-- A quadratic has roots if its discriminant has square roots -/
theorem exists_quadratic_eq_zero (ha : a ≠ 0) (h : ∃ s, discrim a b c = s * s) :
    ∃ x, a * x * x + b * x + c = 0 := by
  rcases h with ⟨s, hs⟩
  use (-b + s) / (2 * a)
  rw [quadratic_eq_zero_iff ha hs]
  

Proof state:
case h
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x : K
ha : a ≠ 0
s : K
hs : discrim a b c = s * s
⊢ (-b + s) / (2 * a) = (-b + s) / (2 * a) ∨ (-b + s) / (2 * a) = (-b - s) / (2 * a)

Next tactic:
simp
/-- Root of a quadratic when its discriminant equals zero -/
theorem quadratic_eq_zero_iff_of_discrim_eq_zero (ha : a ≠ 0) (h : discrim a b c = 0) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = -b / (2 * a) := by
  

Proof state:
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
h : discrim a b c = 0
x : K
⊢ a * x * x + b * x + c = 0 ↔ x = -b / (2 * a)

Next tactic:
have : discrim a b c = 0 * 0 := by rw [h, mul_zero]
/-- Root of a quadratic when its discriminant equals zero -/
theorem quadratic_eq_zero_iff_of_discrim_eq_zero (ha : a ≠ 0) (h : discrim a b c = 0) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = -b / (2 * a) := by
  have : discrim a b c = 0 * 0 := by 

Proof state:
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
h : discrim a b c = 0
x : K
⊢ discrim a b c = 0 * 0

Next tactic:
rw [h, mul_zero]
/-- Root of a quadratic when its discriminant equals zero -/
theorem quadratic_eq_zero_iff_of_discrim_eq_zero (ha : a ≠ 0) (h : discrim a b c = 0) (x : K) :
    a * x * x + b * x + c = 0 ↔ x = -b / (2 * a) := by
  have : discrim a b c = 0 * 0 := by rw [h, mul_zero]
  

Proof state:
K : Type u_1
inst✝¹ : Field K
inst✝ : NeZero 2
a b c x✝ : K
ha : a ≠ 0
h : discrim a b c = 0
x : K
this : discrim a b c = 0 * 0
⊢ a * x * x + b * x + c = 0 ↔ x = -b / (2 * a)

Next tactic:
rw [quadratic_eq_zero_iff ha this, add_zero, sub_zero, or_self_iff]
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  

Proof state:
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
⊢ discrim a b c ≤ 0

Next tactic:
rw [discrim, sq]
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  

Proof state:
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
⊢ b * b - 4 * a * c ≤ 0

Next tactic:
obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · 

Proof state:
case inl
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
ha : a < 0
⊢ b * b - 4 * a * c ≤ 0

Next tactic:
have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    

Proof state:
case inl
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
ha : a < 0
this : Tendsto (fun x => (a * x + b) * x + c) atTop atBot
⊢ b * b - 4 * a * c ≤ 0

Next tactic:
rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    

Proof state:
case inl.intro
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
ha : a < 0
this : Tendsto (fun x => (a * x + b) * x + c) atTop atBot
x : K
hx : (a * x + b) * x + c < 0
⊢ b * b - 4 * a * c ≤ 0

Next tactic:
exact False.elim ((h x).not_lt <| by rwa [← add_mul])
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by 

Proof state:
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
ha : a < 0
this : Tendsto (fun x => (a * x + b) * x + c) atTop atBot
x : K
hx : (a * x + b) * x + c < 0
⊢ a * x * x + b * x + c < 0

Next tactic:
rwa [← add_mul]
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by rwa [← add_mul])
  -- if a = 0
  · 

Proof state:
case inr.inl
K : Type u_1
inst✝ : LinearOrderedField K
b c : K
h : ∀ (x : K), 0 ≤ 0 * x * x + b * x + c
⊢ b * b - 4 * 0 * c ≤ 0

Next tactic:
rcases eq_or_ne b 0 with (rfl | hb)
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by rwa [← add_mul])
  -- if a = 0
  · rcases eq_or_ne b 0 with (rfl | hb)
    · 

Proof state:
case inr.inl.inl
K : Type u_1
inst✝ : LinearOrderedField K
c : K
h : ∀ (x : K), 0 ≤ 0 * x * x + 0 * x + c
⊢ 0 * 0 - 4 * 0 * c ≤ 0

Next tactic:
simp
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by rwa [← add_mul])
  -- if a = 0
  · rcases eq_or_ne b 0 with (rfl | hb)
    · simp
    · 

Proof state:
case inr.inl.inr
K : Type u_1
inst✝ : LinearOrderedField K
b c : K
h : ∀ (x : K), 0 ≤ 0 * x * x + b * x + c
hb : b ≠ 0
⊢ b * b - 4 * 0 * c ≤ 0

Next tactic:
have := h ((-c - 1) / b)
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by rwa [← add_mul])
  -- if a = 0
  · rcases eq_or_ne b 0 with (rfl | hb)
    · simp
    · have := h ((-c - 1) / b)
      

Proof state:
case inr.inl.inr
K : Type u_1
inst✝ : LinearOrderedField K
b c : K
h : ∀ (x : K), 0 ≤ 0 * x * x + b * x + c
hb : b ≠ 0
this : 0 ≤ 0 * ((-c - 1) / b) * ((-c - 1) / b) + b * ((-c - 1) / b) + c
⊢ b * b - 4 * 0 * c ≤ 0

Next tactic:
rw [mul_div_cancel' _ hb] at this
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by rwa [← add_mul])
  -- if a = 0
  · rcases eq_or_ne b 0 with (rfl | hb)
    · simp
    · have := h ((-c - 1) / b)
      rw [mul_div_cancel' _ hb] at this
      

Proof state:
case inr.inl.inr
K : Type u_1
inst✝ : LinearOrderedField K
b c : K
h : ∀ (x : K), 0 ≤ 0 * x * x + b * x + c
hb : b ≠ 0
this : 0 ≤ 0 * ((-c - 1) / b) * ((-c - 1) / b) + (-c - 1) + c
⊢ b * b - 4 * 0 * c ≤ 0

Next tactic:
linarith
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by rwa [← add_mul])
  -- if a = 0
  · rcases eq_or_ne b 0 with (rfl | hb)
    · simp
    · have := h ((-c - 1) / b)
      rw [mul_div_cancel' _ hb] at this
      linarith
  -- if a > 0
  · 

Proof state:
case inr.inr
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
ha : 0 < a
⊢ b * b - 4 * a * c ≤ 0

Next tactic:
have ha' : 0 ≤ 4 * a := mul_nonneg zero_le_four ha.le
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by rwa [← add_mul])
  -- if a = 0
  · rcases eq_or_ne b 0 with (rfl | hb)
    · simp
    · have := h ((-c - 1) / b)
      rw [mul_div_cancel' _ hb] at this
      linarith
  -- if a > 0
  · have ha' : 0 ≤ 4 * a := mul_nonneg zero_le_four ha.le
    

Proof state:
case inr.inr
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
ha : 0 < a
ha' : 0 ≤ 4 * a
⊢ b * b - 4 * a * c ≤ 0

Next tactic:
convert neg_nonpos.2 (mul_nonneg ha' (h (-b / (2 * a)))) using 1
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by rwa [← add_mul])
  -- if a = 0
  · rcases eq_or_ne b 0 with (rfl | hb)
    · simp
    · have := h ((-c - 1) / b)
      rw [mul_div_cancel' _ hb] at this
      linarith
  -- if a > 0
  · have ha' : 0 ≤ 4 * a := mul_nonneg zero_le_four ha.le
    convert neg_nonpos.2 (mul_nonneg ha' (h (-b / (2 * a)))) using 1
    

Proof state:
case h.e'_3
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
ha : 0 < a
ha' : 0 ≤ 4 * a
⊢ b * b - 4 * a * c = -(4 * a * (a * (-b / (2 * a)) * (-b / (2 * a)) + b * (-b / (2 * a)) + c))

Next tactic:
field_simp
/-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/
theorem discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := by
  rw [discrim, sq]
  obtain ha | rfl | ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0
  -- if a < 0
  · have : Tendsto (fun x => (a * x + b) * x + c) atTop atBot :=
      tendsto_atBot_add_const_right _ c
        ((tendsto_atBot_add_const_right _ b (tendsto_id.neg_const_mul_atTop ha)).atBot_mul_atTop
          tendsto_id)
    rcases (this.eventually (eventually_lt_atBot 0)).exists with ⟨x, hx⟩
    exact False.elim ((h x).not_lt <| by rwa [← add_mul])
  -- if a = 0
  · rcases eq_or_ne b 0 with (rfl | hb)
    · simp
    · have := h ((-c - 1) / b)
      rw [mul_div_cancel' _ hb] at this
      linarith
  -- if a > 0
  · have ha' : 0 ≤ 4 * a := mul_nonneg zero_le_four ha.le
    convert neg_nonpos.2 (mul_nonneg ha' (h (-b / (2 * a)))) using 1
    field_simp
    

Proof state:
case h.e'_3
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), 0 ≤ a * x * x + b * x + c
ha : 0 < a
ha' : 0 ≤ 4 * a
⊢ (b * b - 4 * a * c) * (2 * a * (2 * a) * (2 * a)) =
    -(4 * a * (a * b * b * (2 * a) + -(b * b * (2 * a * (2 * a))) + c * (2 * a * (2 * a) * (2 * a))))

Next tactic:
ring
lemma discrim_le_zero_of_nonpos (h : ∀ x : K, a * x * x + b * x + c ≤ 0) : discrim a b c ≤ 0 :=
  discrim_neg a b c ▸ discrim_le_zero <| by 

Proof state:
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
h : ∀ (x : K), a * x * x + b * x + c ≤ 0
⊢ ∀ (x : K), 0 ≤ -a * x * x + -b * x + -c

Next tactic:
simpa only [neg_mul, ← neg_add, neg_nonneg]
/-- If a polynomial of degree 2 is always positive, then its discriminant is negative,
at least when the coefficient of the quadratic term is nonzero.
-/
theorem discrim_lt_zero (ha : a ≠ 0) (h : ∀ x : K, 0 < a * x * x + b * x + c) :
    discrim a b c < 0 := by
  

Proof state:
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
ha : a ≠ 0
h : ∀ (x : K), 0 < a * x * x + b * x + c
⊢ discrim a b c < 0

Next tactic:
have : ∀ x : K, 0 ≤ a * x * x + b * x + c := fun x => le_of_lt (h x)
/-- If a polynomial of degree 2 is always positive, then its discriminant is negative,
at least when the coefficient of the quadratic term is nonzero.
-/
theorem discrim_lt_zero (ha : a ≠ 0) (h : ∀ x : K, 0 < a * x * x + b * x + c) :
    discrim a b c < 0 := by
  have : ∀ x : K, 0 ≤ a * x * x + b * x + c := fun x => le_of_lt (h x)
  

Proof state:
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
ha : a ≠ 0
h : ∀ (x : K), 0 < a * x * x + b * x + c
this : ∀ (x : K), 0 ≤ a * x * x + b * x + c
⊢ discrim a b c < 0

Next tactic:
refine lt_of_le_of_ne (discrim_le_zero this) fun h' ↦ ?_
/-- If a polynomial of degree 2 is always positive, then its discriminant is negative,
at least when the coefficient of the quadratic term is nonzero.
-/
theorem discrim_lt_zero (ha : a ≠ 0) (h : ∀ x : K, 0 < a * x * x + b * x + c) :
    discrim a b c < 0 := by
  have : ∀ x : K, 0 ≤ a * x * x + b * x + c := fun x => le_of_lt (h x)
  refine lt_of_le_of_ne (discrim_le_zero this) fun h' ↦ ?_
  

Proof state:
K : Type u_1
inst✝ : LinearOrderedField K
a b c : K
ha : a ≠ 0
h : ∀ (x : K), 0 < a * x * x + b * x + c
this : ∀ (x : K), 0 ≤ a * x * x + b * x + c
h' : discrim a b c = 0
⊢ False

Next tactic:
have := h (-b / (2 * a))