Standard Euclidean continued fraction of a rational (with canonical form)
Definitionburau_std_cfThe standard Euclidean continued fraction of a rational, together with its canonical form.
For integers , is the quotient list produced by the standard (positive) Euclidean descent on the rational :
where division and remainder are the Euclidean ones on (remainder of the sign of the divisor). The recursion terminates because .
The auxiliary map puts such a list into the canonical shape of a regular continued fraction by folding a final term into the preceding term: this is the normal form in which the transformations and of continued fractions take their clean two- and three-case forms. Both objects are the integer skeleton of the Euclidean-descent section of used in the reduction of the three-strand Burau faithfulness statement to a continued-fraction identity.
import Mathlib
/-- Standard (positive) Euclidean continued fraction of the rational `b/a`: `cfStd a b = []` when
`a = 0`, and `(b/a) :: cfStd (b % a) a` otherwise. -/
noncomputable def cfStd (a b : ℤ) : List ℤ :=
if h : a = 0 then [] else b / a :: cfStd (b % a) a
termination_by a.natAbs
decreasing_by
have h1 : 0 ≤ b % a := Int.emod_nonneg b h
have h2 : b % a < |a| := Int.emod_lt_abs b h
have h3 : |b % a| < |a| := by rwa [abs_of_nonneg h1]
rw [Int.natAbs_lt_iff_sq_lt]
exact sq_lt_sq.mpr h3
/-- The recursion equation of `cfStd` at a nonzero first argument. -/
theorem cfStd_cons (a b : ℤ) (h : a ≠ 0) : cfStd a b = b / a :: cfStd (b % a) a := by
rw [cfStd.eq_def]
exact dif_neg h
/-- `cfStd` vanishes at a zero first argument. -/
theorem cfStd_zero (b : ℤ) : cfStd 0 b = [] := by
rw [cfStd.eq_def]
exact dif_pos rfl
/-- Normalisation of a continued-fraction list: a trailing `1` is absorbed into the previous term. -/
def canon : List ℤ → List ℤ
| [] => []
| [x] => [x]
| x :: y :: l =>
match canon (y :: l) with
| [] => [x]
| [z] => if z = 1 then [x + 1] else [x, z]
| z :: zs => x :: z :: zs