|
| 1 | +/- |
| 2 | +Copyright (c) 2022 Jeoff Lee. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Jeoff Lee |
| 5 | +
|
| 6 | +! This file was ported from Lean 3 source module wiedijk_100_theorems.solution_of_cubic |
| 7 | +! leanprover-community/mathlib commit 5563b1b49e86e135e8c7b556da5ad2f5ff881cad |
| 8 | +! Please do not edit these lines, except to modify the commit id |
| 9 | +! if you have ported upstream changes. |
| 10 | +-/ |
| 11 | +import Mathlib.Tactic.LinearCombination |
| 12 | +import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots |
| 13 | + |
| 14 | +/-! |
| 15 | +# The Solution of a Cubic |
| 16 | +
|
| 17 | +This file proves Theorem 37 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/). |
| 18 | +
|
| 19 | +In this file, we give the solutions to the cubic equation `a * x^3 + b * x^2 + c * x + d = 0` |
| 20 | +over a field `K` that has characteristic neither 2 nor 3, that has a third primitive root of |
| 21 | +unity, and in which certain other quantities admit square and cube roots. |
| 22 | +
|
| 23 | +This is based on the [Cardano's Formula](https://en.wikipedia.org/wiki/Cubic_equation#Cardano's_formula). |
| 24 | +
|
| 25 | +## Main statements |
| 26 | +
|
| 27 | +- `cubic_eq_zero_iff` : gives the roots of the cubic equation |
| 28 | +where the discriminant `p = 3 * a * c - b^2` is nonzero. |
| 29 | +- `cubic_eq_zero_iff_of_p_eq_zero` : gives the roots of the cubic equation |
| 30 | +where the discriminant equals zero. |
| 31 | +
|
| 32 | +## References |
| 33 | +
|
| 34 | +Originally ported from Isabelle/HOL. The |
| 35 | +[original file](https://isabelle.in.tum.de/dist/library/HOL/HOL-ex/Cubic_Quartic.html) was written by Amine Chaieb. |
| 36 | +
|
| 37 | +## Tags |
| 38 | +
|
| 39 | +polynomial, cubic, root |
| 40 | +-/ |
| 41 | + |
| 42 | + |
| 43 | +namespace Theorems100 |
| 44 | + |
| 45 | +section Field |
| 46 | + |
| 47 | +open Polynomial |
| 48 | + |
| 49 | +variable {K : Type _} [Field K] |
| 50 | + |
| 51 | +variable [Invertible (2 : K)] [Invertible (3 : K)] |
| 52 | + |
| 53 | +variable (a b c d : K) |
| 54 | + |
| 55 | +variable {ω p q r s t : K} |
| 56 | + |
| 57 | +theorem cube_root_of_unity_sum (hω : IsPrimitiveRoot ω 3) : 1 + ω + ω ^ 2 = 0 := by |
| 58 | + simpa [cyclotomic_prime, Finset.sum_range_succ] using hω.isRoot_cyclotomic (by decide) |
| 59 | +#align theorems_100.cube_root_of_unity_sum Theorems100.cube_root_of_unity_sum |
| 60 | + |
| 61 | +/-- The roots of a monic cubic whose quadratic term is zero and whose discriminant is nonzero. -/ |
| 62 | +theorem cubic_basic_eq_zero_iff (hω : IsPrimitiveRoot ω 3) (hp_nonzero : p ≠ 0) |
| 63 | + (hr : r ^ 2 = q ^ 2 + p ^ 3) (hs3 : s ^ 3 = q + r) (ht : t * s = p) (x : K) : |
| 64 | + x ^ 3 + 3 * p * x - 2 * q = 0 ↔ x = s - t ∨ x = s * ω - t * ω ^ 2 ∨ x = s * ω ^ 2 - t * ω := by |
| 65 | + have h₁ : ∀ x a₁ a₂ a₃ : K, x = a₁ ∨ x = a₂ ∨ x = a₃ ↔ (x - a₁) * (x - a₂) * (x - a₃) = 0 := by |
| 66 | + intros; simp only [mul_eq_zero, sub_eq_zero, or_assoc] |
| 67 | + rw [h₁] |
| 68 | + refine' Eq.congr _ rfl |
| 69 | + have hs_nonzero : s ≠ 0 := by |
| 70 | + contrapose! hp_nonzero with hs_nonzero |
| 71 | + linear_combination -1 * ht + t * hs_nonzero |
| 72 | + rw [← mul_left_inj' (pow_ne_zero 3 hs_nonzero)] |
| 73 | + have H := cube_root_of_unity_sum hω |
| 74 | + linear_combination |
| 75 | + hr + (-q + r + s ^ 3) * hs3 - (3 * x * s ^ 3 + (t * s) ^ 2 + t * s * p + p ^ 2) * ht + |
| 76 | + (x ^ 2 * (s - t) + x * (-ω * (s ^ 2 + t ^ 2) + s * t * (3 + ω ^ 2 - ω)) - |
| 77 | + (-(s ^ 3 - t ^ 3) * (ω - 1) + s ^ 2 * t * ω ^ 2 - s * t ^ 2 * ω ^ 2)) * s ^ 3 * H |
| 78 | +#align theorems_100.cubic_basic_eq_zero_iff Theorems100.cubic_basic_eq_zero_iff |
| 79 | + |
| 80 | +/-- Roots of a monic cubic whose discriminant is nonzero. -/ |
| 81 | +theorem cubic_monic_eq_zero_iff (hω : IsPrimitiveRoot ω 3) (hp : p = (3 * c - b ^ 2) / 9) |
| 82 | + (hp_nonzero : p ≠ 0) (hq : q = (9 * b * c - 2 * b ^ 3 - 27 * d) / 54) |
| 83 | + (hr : r ^ 2 = q ^ 2 + p ^ 3) (hs3 : s ^ 3 = q + r) (ht : t * s = p) (x : K) : |
| 84 | + x ^ 3 + b * x ^ 2 + c * x + d = 0 ↔ |
| 85 | + x = s - t - b / 3 ∨ x = s * ω - t * ω ^ 2 - b / 3 ∨ x = s * ω ^ 2 - t * ω - b / 3 := by |
| 86 | + let y := x + b / 3 |
| 87 | + have hi2 : (2 : K) ≠ 0 := nonzero_of_invertible _ |
| 88 | + have hi3 : (3 : K) ≠ 0 := nonzero_of_invertible _ |
| 89 | + have h9 : (9 : K) = 3 ^ 2 := by norm_num |
| 90 | + have h54 : (54 : K) = 2 * 3 ^ 3 := by norm_num |
| 91 | + have h₁ : x ^ 3 + b * x ^ 2 + c * x + d = y ^ 3 + 3 * p * y - 2 * q := by |
| 92 | + rw [hp, hq] |
| 93 | + field_simp [h9, h54]; ring |
| 94 | + rw [h₁, cubic_basic_eq_zero_iff hω hp_nonzero hr hs3 ht y] |
| 95 | + simp_rw [eq_sub_iff_add_eq] |
| 96 | +#align theorems_100.cubic_monic_eq_zero_iff Theorems100.cubic_monic_eq_zero_iff |
| 97 | + |
| 98 | +/-- **The Solution of Cubic**. |
| 99 | + The roots of a cubic polynomial whose discriminant is nonzero. -/ |
| 100 | +theorem cubic_eq_zero_iff (ha : a ≠ 0) (hω : IsPrimitiveRoot ω 3) |
| 101 | + (hp : p = (3 * a * c - b ^ 2) / (9 * a ^ 2)) (hp_nonzero : p ≠ 0) |
| 102 | + (hq : q = (9 * a * b * c - 2 * b ^ 3 - 27 * a ^ 2 * d) / (54 * a ^ 3)) |
| 103 | + (hr : r ^ 2 = q ^ 2 + p ^ 3) (hs3 : s ^ 3 = q + r) (ht : t * s = p) (x : K) : |
| 104 | + a * x ^ 3 + b * x ^ 2 + c * x + d = 0 ↔ |
| 105 | + x = s - t - b / (3 * a) ∨ |
| 106 | + x = s * ω - t * ω ^ 2 - b / (3 * a) ∨ x = s * ω ^ 2 - t * ω - b / (3 * a) := by |
| 107 | + have hi2 : (2 : K) ≠ 0 := nonzero_of_invertible _ |
| 108 | + have hi3 : (3 : K) ≠ 0 := nonzero_of_invertible _ |
| 109 | + have h9 : (9 : K) = 3 ^ 2 := by norm_num |
| 110 | + have h54 : (54 : K) = 2 * 3 ^ 3 := by norm_num |
| 111 | + have h₁ : a * x ^ 3 + b * x ^ 2 + c * x + d = a * (x ^ 3 + b / a * x ^ 2 + c / a * x + d / a) := |
| 112 | + by field_simp; ring |
| 113 | + have h₂ : ∀ x, a * x = 0 ↔ x = 0 := by intro x; simp [ha] |
| 114 | + have hp' : p = (3 * (c / a) - (b / a) ^ 2) / 9 := by field_simp [hp, h9]; ring_nf |
| 115 | + have hq' : q = (9 * (b / a) * (c / a) - 2 * (b / a) ^ 3 - 27 * (d / a)) / 54 := by |
| 116 | + field_simp [hq, h54]; ring_nf |
| 117 | + rw [h₁, h₂, cubic_monic_eq_zero_iff (b / a) (c / a) (d / a) hω hp' hp_nonzero hq' hr hs3 ht x] |
| 118 | + have h₄ := |
| 119 | + calc |
| 120 | + b / a / 3 = b / (a * 3) := by field_simp [ha] |
| 121 | + _ = b / (3 * a) := by rw [mul_comm] |
| 122 | + rw [h₄] |
| 123 | +#align theorems_100.cubic_eq_zero_iff Theorems100.cubic_eq_zero_iff |
| 124 | + |
| 125 | +/-- the solution of the cubic equation when p equals zero. -/ |
| 126 | +theorem cubic_eq_zero_iff_of_p_eq_zero (ha : a ≠ 0) (hω : IsPrimitiveRoot ω 3) |
| 127 | + (hpz : 3 * a * c - b ^ 2 = 0) |
| 128 | + (hq : q = (9 * a * b * c - 2 * b ^ 3 - 27 * a ^ 2 * d) / (54 * a ^ 3)) (hs3 : s ^ 3 = 2 * q) |
| 129 | + (x : K) : |
| 130 | + a * x ^ 3 + b * x ^ 2 + c * x + d = 0 ↔ |
| 131 | + x = s - b / (3 * a) ∨ x = s * ω - b / (3 * a) ∨ x = s * ω ^ 2 - b / (3 * a) := by |
| 132 | + have h₁ : ∀ x a₁ a₂ a₃ : K, x = a₁ ∨ x = a₂ ∨ x = a₃ ↔ (x - a₁) * (x - a₂) * (x - a₃) = 0 := by |
| 133 | + intros; simp only [mul_eq_zero, sub_eq_zero, or_assoc] |
| 134 | + have hi2 : (2 : K) ≠ 0 := nonzero_of_invertible _ |
| 135 | + have hi3 : (3 : K) ≠ 0 := nonzero_of_invertible _ |
| 136 | + have h54 : (54 : K) = 2 * 3 ^ 3 := by norm_num |
| 137 | + have hb2 : b ^ 2 = 3 * a * c := by rw [sub_eq_zero] at hpz ; rw [hpz] |
| 138 | + have hb3 : b ^ 3 = 3 * a * b * c := by rw [pow_succ, hb2]; ring |
| 139 | + have h₂ := |
| 140 | + calc |
| 141 | + a * x ^ 3 + b * x ^ 2 + c * x + d = |
| 142 | + a * (x + b / (3 * a)) ^ 3 + (c - b ^ 2 / (3 * a)) * x + (d - b ^ 3 * a / (3 * a) ^ 3) := |
| 143 | + by field_simp; ring |
| 144 | + _ = a * (x + b / (3 * a)) ^ 3 + (d - (9 * a * b * c - 2 * b ^ 3) * a / (3 * a) ^ 3) := by |
| 145 | + simp only [hb2, hb3]; field_simp; ring |
| 146 | + _ = a * ((x + b / (3 * a)) ^ 3 - s ^ 3) := by rw [hs3, hq]; field_simp [h54]; ring |
| 147 | + have h₃ : ∀ x, a * x = 0 ↔ x = 0 := by intro x; simp [ha] |
| 148 | + have h₄ : ∀ x : K, x ^ 3 - s ^ 3 = (x - s) * (x - s * ω) * (x - s * ω ^ 2) := by |
| 149 | + intro x |
| 150 | + calc |
| 151 | + x ^ 3 - s ^ 3 = (x - s) * (x ^ 2 + x * s + s ^ 2) := by ring |
| 152 | + _ = (x - s) * (x ^ 2 - (ω + ω ^ 2) * x * s + (1 + ω + ω ^ 2) * x * s + s ^ 2) := by ring |
| 153 | + _ = (x - s) * (x ^ 2 - (ω + ω ^ 2) * x * s + ω ^ 3 * s ^ 2) := by |
| 154 | + rw [hω.pow_eq_one, cube_root_of_unity_sum hω]; simp |
| 155 | + _ = (x - s) * (x - s * ω) * (x - s * ω ^ 2) := by ring |
| 156 | + rw [h₁, h₂, h₃, h₄ (x + b / (3 * a))] |
| 157 | + ring_nf |
| 158 | +#align theorems_100.cubic_eq_zero_iff_of_p_eq_zero Theorems100.cubic_eq_zero_iff_of_p_eq_zero |
| 159 | + |
| 160 | +end Field |
| 161 | + |
| 162 | +end Theorems100 |
0 commit comments