|
| 1 | +/- |
| 2 | +Copyright (c) 2024 Moritz Firsching. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Moritz Firsching |
| 5 | +-/ |
| 6 | +import Mathlib.Algebra.BigOperators.Group.Finset |
| 7 | +import Mathlib.Algebra.Order.Ring.Basic |
| 8 | +import Mathlib.Algebra.Order.Star.Basic |
| 9 | +import Mathlib.Data.Nat.Prime.Defs |
| 10 | +import Mathlib.Tactic.Ring.RingNF |
| 11 | + |
| 12 | +/-! |
| 13 | +# Fermat numbers |
| 14 | +
|
| 15 | +The Fermat numbers are a sequence of natural numbers defined as `fermat n = 2^(2^n) + 1`, for all |
| 16 | +natural numbers `n`. |
| 17 | +
|
| 18 | +## Main theorems |
| 19 | +
|
| 20 | +- `coprime_fermat_fermat`: two distinct Fermat numbers are coprime. |
| 21 | +-/ |
| 22 | + |
| 23 | +open Nat Finset |
| 24 | +open scoped BigOperators |
| 25 | + |
| 26 | +/-- Fermat numbers: the `n`-th Fermat number is defined as `2^(2^n) + 1`. -/ |
| 27 | +def fermat (n : ℕ) : ℕ := 2 ^ (2 ^ n) + 1 |
| 28 | + |
| 29 | +@[simp] theorem fermat_zero : fermat 0 = 3 := rfl |
| 30 | +@[simp] theorem fermat_one : fermat 1 = 5 := rfl |
| 31 | +@[simp] theorem fermat_two : fermat 2 = 17 := rfl |
| 32 | + |
| 33 | +theorem strictMono_fermat : StrictMono fermat := by |
| 34 | + intro m n |
| 35 | + simp only [fermat, add_lt_add_iff_right, pow_lt_pow_iff_right (one_lt_two : 1 < 2), imp_self] |
| 36 | + |
| 37 | +theorem two_lt_fermat (n : ℕ) : 2 < fermat n := by |
| 38 | + cases n |
| 39 | + · simp |
| 40 | + · exact lt_of_succ_lt <| strictMono_fermat <| zero_lt_succ _ |
| 41 | + |
| 42 | +theorem odd_fermat (n : ℕ) : Odd (fermat n) := |
| 43 | + (even_pow.mpr ⟨even_two, (pow_pos two_pos n).ne'⟩).add_one |
| 44 | + |
| 45 | +theorem fermat_product (n : ℕ) : ∏ k in range n, fermat k = fermat n - 2 := by |
| 46 | + induction' n with n hn |
| 47 | + · rfl |
| 48 | + rw [prod_range_succ, hn, fermat, fermat, mul_comm, |
| 49 | + (show 2 ^ 2 ^ n + 1 - 2 = 2 ^ 2 ^ n - 1 by omega), ← sq_sub_sq] |
| 50 | + ring_nf |
| 51 | + omega |
| 52 | + |
| 53 | +theorem fermat_eq_prod_add_two (n : ℕ) : fermat n = (∏ k in range n, fermat k) + 2 := by |
| 54 | + rw [fermat_product, Nat.sub_add_cancel] |
| 55 | + exact le_of_lt <| two_lt_fermat _ |
| 56 | + |
| 57 | +/-- |
| 58 | +**Goldbach's theorem** : no two distinct Fermat numbers share a common factor greater than one. |
| 59 | +
|
| 60 | +From a letter to Euler, see page 37 in [juskevic2022]. |
| 61 | +-/ |
| 62 | +theorem coprime_fermat_fermat {k n : ℕ} (h : k ≠ n) : Coprime (fermat n) (fermat k) := by |
| 63 | + wlog hkn : k < n |
| 64 | + · simpa only [coprime_comm] using this h.symm (by omega) |
| 65 | + let m := (fermat n).gcd (fermat k) |
| 66 | + have h_n : m ∣ fermat n := (fermat n).gcd_dvd_left (fermat k) |
| 67 | + have h_m : m ∣ 2 := (Nat.dvd_add_right <| (gcd_dvd_right _ _).trans <| dvd_prod_of_mem _ |
| 68 | + <| mem_range.mpr hkn).mp <| fermat_eq_prod_add_two _ ▸ h_n |
| 69 | + refine ((dvd_prime prime_two).mp h_m).elim id (fun h_two ↦ ?_) |
| 70 | + exact ((odd_fermat _).not_two_dvd_nat (h_two ▸ h_n)).elim |
0 commit comments