|
|
|
|
Quelle GoldenRatio.lean
Sprache: Lean
|
|
/-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Alexey Soloyev, Junyan Xu, Kamila Szewczyk
-/
module
public import Mathlib.Algebra.LinearRecurrence
public import Mathlib.Data.Int.Fib.Basic
public import Mathlib.NumberTheory.Real.Irrational
public import Mathlib.Tactic.NormNum.NatFib
public import Mathlib.Tactic.NormNum.Prime
/-!
# The golden ratio and its conjugate
This file defines the golden ratio `φ := (1 + √5)/2` and its conjugate
`ψ := (1 - √5)/2`, which are the two real roots of `X² - X - 1`.
Along with various computational facts about them, we prove their
irrationality, and we link them to the Fibonacci sequence by proving
Binet's formula.
-/
@[expose] public section
noncomputable section
open Polynomial
namespace Real
/-- The golden ratio `φ := (1 + √5)/2`. -/
@[oeis A001622 "decimal expansion"]
abbrev goldenRatio : ℝ := (1 + √5) / 2
/-- The conjugate of the golden ratio `ψ := (1 - √5)/2`. -/
abbrev goldenConj : ℝ := (1 - √5) / 2
@[inherit_doc] scoped[goldenRatio] notation "φ" => Real.goldenRatio
@[inherit_doc] scoped[goldenRatio] notation "ψ" => Real.goldenConj
open scoped goldenRatio
/-- The inverse of the golden ratio is the opposite of its conjugate. -/
theorem inv_goldenRatio : φ⁻¹ = -ψ := by
grind
/-- The opposite of the golden ratio is the inverse of its conjugate. -/
theorem inv_goldenConj : ψ⁻¹ = -φ := by
rw [inv_eq_iff_eq_inv, ← neg_inv, ← neg_eq_iff_eq_neg]
exact inv_goldenRatio.symm
@[simp]
theorem goldenRatio_mul_goldenConj : φ * ψ = -1 := by
grind
@[simp]
theorem goldenConj_mul_goldenRatio : ψ * φ = -1 := by
rw [mul_comm]
exact goldenRatio_mul_goldenConj
@[simp]
theorem goldenRatio_add_goldenConj : φ + ψ = 1 := by
rw [goldenRatio, goldenConj]
ring
theorem one_sub_goldenConj : 1 - φ = ψ := by
linarith [goldenRatio_add_goldenConj]
theorem one_sub_goldenRatio : 1 - ψ = φ := by
linarith [goldenRatio_add_goldenConj]
@[simp]
theorem goldenRatio_sub_goldenConj : φ - ψ = √5 := by ring
theorem goldenRatio_pow_sub_goldenRatio_pow (n : ℕ) : φ ^ (n + 2) - φ ^ (n + 1) = φ ^ n := by
grind
@[simp 1200]
theorem goldenRatio_sq : φ ^ 2 = φ + 1 := by
grind
@[simp 1200]
theorem goldenConj_sq : ψ ^ 2 = ψ + 1 := by
grind
theorem goldenRatio_pos : 0 < φ :=
mul_pos (by apply add_pos <;> simp) <| inv_pos.2 zero_lt_two
theorem goldenRatio_ne_zero : φ ≠ 0 :=
ne_of_gt goldenRatio_pos
theorem one_lt_goldenRatio : 1 < φ := by
refine lt_of_mul_lt_mul_left ?_ (le_of_lt goldenRatio_pos)
simp [← sq, zero_lt_one]
theorem goldenRatio_lt_two : φ < 2 := by calc
(1 + √5) / 2 < (1 + 3) / 2 := by gcongr; rw [sqrt_lt'] <;> norm_num
_ = 2 := by norm_num
theorem goldenConj_neg : ψ < 0 := by
linarith [one_sub_goldenConj, one_lt_goldenRatio]
theorem goldenConj_ne_zero : ψ ≠ 0 :=
ne_of_lt goldenConj_neg
theorem neg_one_lt_goldenConj : -1 < ψ := by
rw [neg_lt, ← inv_goldenRatio]
exact inv_lt_one_of_one_lt₀ one_lt_goldenRatio
/-!
## Irrationality
-/
/-- The golden ratio is irrational. -/
theorem goldenRatio_irrational : Irrational φ := by
have := Nat.Prime.irrational_sqrt (show Nat.Prime 5 by norm_num)
have := this.ratCast_add 1
convert this.ratCast_mul (show (0.5 : ℚ) ≠ 0 by norm_num)
simp
ring
/-- The conjugate of the golden ratio is irrational. -/
theorem goldenConj_irrational : Irrational ψ := by
have := Nat.Prime.irrational_sqrt (show Nat.Prime 5 by norm_num)
have := this.ratCast_sub 1
convert this.ratCast_mul (show (0.5 : ℚ) ≠ 0 by norm_num)
simp
ring
/-!
## Links with Fibonacci sequence
-/
section Fibrec
variable {α : Type*} [CommSemiring α]
/-- The recurrence relation satisfied by the Fibonacci sequence. -/
def fibRec : LinearRecurrence α where
order := 2
coeffs := ![1, 1]
section Poly
open Polynomial
/-- The characteristic polynomial of `fibRec` is `X² - (X + 1)`. -/
theorem fibRec_charPoly_eq {β : Type*} [CommRing β] :
fibRec.charPoly = X ^ 2 - (X + (1 : β[X])) := by
rw [fibRec, LinearRecurrence.charPoly]
simp [Finset.sum_fin_eq_sum_range, Finset.sum_range_succ', ← smul_X_eq_monomial]
end Poly
/-- As expected, the Fibonacci sequence is a solution of `fibRec`. -/
theorem fib_isSol_fibRec : fibRec.IsSolution (fun x => x.fib : ℕ → α) := by
rw [fibRec]
intro n
simp only
rw [Nat.fib_add_two, add_comm]
simp [Finset.sum_fin_eq_sum_range, Finset.sum_range_succ']
/-- The geometric sequence `fun n ↦ φ^n` is a solution of `fibRec`. -/
theorem geom_goldenRatio_isSol_fibRec : fibRec.IsSolution (φ ^ ·) := by
rw [fibRec.geom_sol_iff_root_charPoly, fibRec_charPoly_eq]
simp
/-- The geometric sequence `fun n ↦ ψ^n` is a solution of `fibRec`. -/
theorem geom_goldenConj_isSol_fibRec : fibRec.IsSolution (ψ ^ ·) := by
rw [fibRec.geom_sol_iff_root_charPoly, fibRec_charPoly_eq]
simp
end Fibrec
/-- Binet's formula as a function equality. -/
theorem coe_fib_eq' :
(fun n => Nat.fib n : ℕ → ℝ) = fun n => (φ ^ n - ψ ^ n) / √5 := by
rw [fibRec.eq_iff_eqOn_range_order]
· intro i hi
norm_cast at hi
fin_cases hi <;> simp
· exact fib_isSol_fibRec
· suffices LinearRecurrence.IsSolution fibRec
((fun n ↦ (√5)⁻¹ * φ ^ n) - (fun n ↦ (√5)⁻¹ * ψ ^ n)) by
convert! this
rw [Pi.sub_apply]
ring
apply (@fibRec ℝ _).solSpace.sub_mem
· exact Submodule.smul_mem fibRec.solSpace (√5)⁻¹ geom_goldenRatio_isSol_fibRec
· exact Submodule.smul_mem fibRec.solSpace (√5)⁻¹ geom_goldenConj_isSol_fibRec
/-- **Binet's formula** as a dependent equality. -/
theorem coe_fib_eq : ∀ n, (Nat.fib n : ℝ) = (φ ^ n - ψ ^ n) / √5 := by
rw [← funext_iff, Real.coe_fib_eq']
/-- **Binet's formula** for integer values. -/
theorem coe_intFib_eq (n : ℤ) : (Int.fib n : ℝ) = (φ ^ n - ψ ^ n) / √5 := by
obtain ⟨n, (rfl | rfl)⟩ := n.eq_nat_or_neg
· exact coe_fib_eq n
· simp only [Int.fib_neg, Int.even_natCast, Int.fib_natCast, Int.cast_ite, Int.cast_neg,
Int.cast_natCast, zpow_neg, zpow_natCast, ← inv_pow, inv_goldenRatio, inv_goldenConj,
← neg_one_mul ψ, ← neg_one_mul φ, mul_pow, neg_one_pow_eq_ite]
grind [coe_fib_eq]
/-- Relationship between the Fibonacci Sequence, the golden ratio, and its conjugate's exponents. -/
theorem fib_succ_sub_goldenRatio_mul_fib (n : ℕ) : Nat.fib (n + 1) - φ * Nat.fib n = ψ ^ n := by
repeat rw [coe_fib_eq]
rw [mul_div, div_sub_div_same, mul_sub, ← pow_succ']
ring_nf
have nz : √5 ≠ 0 := by simp
rw [← (mul_inv_cancel₀ nz).symm, one_mul]
/-- Relationship between the Fibonacci Sequence, the conjugate of the golden ratio,
and its exponents. -/
lemma goldenConj_mul_fib_succ_add_fib (n : ℕ) : ψ * Nat.fib (n + 1) + Nat.fib n = ψ ^ (n + 1) := by
grind [fib_succ_sub_goldenRatio_mul_fib]
/-- Relationship between the Fibonacci Sequence, the golden ratio, and its exponents. -/
lemma goldenRatio_mul_fib_succ_add_fib (n : ℕ) : φ * Nat.fib (n + 1) + Nat.fib n = φ ^ (n + 1) := by
induction n with
| zero => simp
| succ n ih =>
calc
_ = φ * (Nat.fib n) + φ ^ 2 * (Nat.fib (n + 1)) := by
simp only [Nat.fib_add_one (Nat.succ_ne_zero n), Nat.succ_sub_succ_eq_sub,
Nat.cast_add, goldenRatio_sq, Nat.sub_zero]; ring
_ = φ * ((Nat.fib n) + φ * (Nat.fib (n + 1))) := by ring
_ = φ ^ (n + 2) := by rw [add_comm, ih]; ring
/-- Relationship between the Fibonacci Sequence, exponents of the golden ratio,
and its conjugate. -/
theorem fib_succ_sub_goldenConj_mul_fib (n : ℕ) : Nat.fib (n + 1) - ψ * Nat.fib n = φ ^ n := by
grind [goldenRatio_mul_fib_succ_add_fib]
end Real
¤ Dauer der Verarbeitung: 0.8 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|
|
|
|
|