import Mathlib.Tactic.Ring/-!# Round 12: the unit case as a cubic Thue–Mahler equationElements `a + b√d` are pairs `(a, b)` with `(a, b)(a', b') = (aa' + dbb', ab' + a'b)`. For `δ = e + f√d` and`γ = u + v√d`, the `√d`-coefficient of `δγ³` is the binary cubic form`F(u, v) = f u³ + 3e u²v + 3fd uv² + ed v³`, and the rational part is `e u³ + 3fd u²v + 3ed uv² + fd² v³`.-/namespace BealThueReduction/-- Multiplication in `ℤ[√d]` on pairs. -/def mul (d : ℤ) (x y : ℤ × ℤ) : ℤ × ℤ := (x.1 * y.1 + d * x.2 * y.2, x.1 * y.2 + x.2 * y.1)/-- The coordinates of `(e + f√d)(u + v√d)³`. -/theorem unit_times_cube (d e f u v : ℤ) :mul d (e, f) (mul d (u, v) (mul d (u, v) (u, v))) =(e * u ^ 3 + 3 * f * d * u ^ 2 * v + 3 * e * d * u * v ^ 2 + f * d ^ 2 * v ^ 3,f * u ^ 3 + 3 * e * u ^ 2 * v + 3 * f * d * u * v ^ 2 + e * d * v ^ 3) := bysimp only [mul, Prod.mk.injEq]constructor <;> ring/-- The cube itself (`δ = 1`): `(u + v√d)³ = (u³ + 3duv², 3u²v + dv³)`. -/theorem cube (d u v : ℤ) :mul d (u, v) (mul d (u, v) (u, v)) = (u ^ 3 + 3 * d * u * v ^ 2, 3 * u ^ 2 * v + d * v ^ 3) := bysimp only [mul, Prod.mk.injEq]constructor <;> ring/-- The norm is multiplicative on pairs: `N(xy) = N(x)N(y)` with `N(a, b) = a² - db²`. -/theorem norm_mul (d : ℤ) (x y : ℤ × ℤ) :(mul d x y).1 ^ 2 - d * (mul d x y).2 ^ 2 = (x.1 ^ 2 - d * x.2 ^ 2) * (y.1 ^ 2 - d * y.2 ^ 2) := bysimp only [mul]ringend BealThueReduction#print axioms BealThueReduction.unit_times_cube