/- Copyright 2025 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ module public import FormalConjecturesUtil

Infinitude of Wall–Sun–Sun primes

References:

    Wikipedia

    [EJ10] A.-S. Elsenhans and J. Jahnel, The Fibonacci sequence modulo $p^2$ – An investigation by computer for $p < 10^{14}$, arXiv:1006.0824

@[expose] public sectionopen Algebra (IsQuadraticExtension)open NumberFieldnamespace QuadraticAlgebravariable {d : } [Fact <| Squarefree d] [Fact <| d 1]

The discriminant of ℚ[√d] for d ≥ 2 squarefree congruent to 1 mod 4 is d.

@[category textbook, AMS 11, simp] lemma discr_rat_of_modEq_one (hd₄ : d 1 [ZMOD 4]) : discr (QuadraticAlgebra d 0) = d := d:inst✝¹:Fact (Squarefree d)inst✝:Fact (d 1)hd₄:d 1 [ZMOD 4]discr (QuadraticAlgebra (↑d) 0) = d All goals completed! 🐙

The discriminant of ℚ[√d] for d ≥ 2 squarefree not congruent to 1 mod 4 is 4 * d.

@[category textbook, AMS 11, simp] lemma discr_rat_of_not_modEq_one (hd₄ : ¬ d 1 [ZMOD 4]) : discr (QuadraticAlgebra d 0) = 4 * d := d:inst✝¹:Fact (Squarefree d)inst✝:Fact (d 1)hd₄:¬d 1 [ZMOD 4]discr (QuadraticAlgebra (↑d) 0) = 4 * d All goals completed! 🐙end QuadraticAlgebranamespace Algebravariable {K L : Type*} [Field K] [Field L] [Algebra K L]variable (K L) in

A quadratic algebra L over a field K is isomorphic to the explicit quadratic algebra QuadraticAlgebra K a b for some a b : K.

@[category textbook, AMS 11] lemma exists_quadraticAlgebra_of_isQuadraticExtension [IsQuadraticExtension K L] : a b, Nonempty (L ≃ₐ[K] QuadraticAlgebra K a b) := K:Type u_1L:Type u_2inst✝³:Field Kinst✝²:Field Linst✝¹:Algebra K Linst✝:IsQuadraticExtension K L a b, Nonempty (L ≃ₐ[K] QuadraticAlgebra K a b) All goals completed! 🐙

An algebra L is quadratic over a field K iff it is isomorphic to the explicit quadratic algebra QuadraticAlgebra K a b for some a b : K.

@[category textbook, AMS 11] lemma isQuadraticExtension_iff_exists_quadraticAlgebra : IsQuadraticExtension K L a b, Nonempty (L ≃ₐ[K] QuadraticAlgebra K a b) where mp _ := exists_quadraticAlgebra_of_isQuadraticExtension .. mpr := K:Type u_1L:Type u_2inst✝²:Field Kinst✝¹:Field Linst✝:Algebra K L(∃ a b, Nonempty (L ≃ₐ[K] QuadraticAlgebra K a b)) IsQuadraticExtension K L K:Type u_1L:Type u_2inst✝²:Field Kinst✝¹:Field Linst✝:Algebra K La:Kb:Ke:L ≃ₐ[K] QuadraticAlgebra K a bIsQuadraticExtension K L; All goals completed! 🐙end Algebranamespace NumberFieldvariable {K : Type*} [Field K] [NumberField K]variable (K) in

A quadratic number field K is isomorphic to the explicit quadratic field QuadraticAlgebra ℚ d 0 for some squarefree d : ℤ not equal to 1.

@[category textbook, AMS 11] lemma exists_quadraticAlgebra_of_isQuadraticExtension [IsQuadraticExtension K] : d (1 : ), Squarefree d Nonempty (K ≃+* QuadraticAlgebra d 0) := K:Type u_1inst✝²:Field Kinst✝¹:NumberField Kinst✝:IsQuadraticExtension K d, d 1 Squarefree d Nonempty (K ≃+* QuadraticAlgebra (↑d) 0) All goals completed! 🐙

A number field K is quadratic iff it is isomorphic to the explicit quadratic field QuadraticAlgebra ℚ d 0 for some squarefree d : ℤ not equal to 1.

@[category textbook, AMS 11] lemma isQuadraticExtension_iff_exists_quadraticAlgebra : IsQuadraticExtension K d (1 : ), Squarefree d Nonempty (K ≃+* QuadraticAlgebra d 0) where mp _ := exists_quadraticAlgebra_of_isQuadraticExtension _ mpr := K:Type u_1inst✝¹:Field Kinst✝:NumberField K(∃ d, d 1 Squarefree d Nonempty (K ≃+* QuadraticAlgebra (↑d) 0)) IsQuadraticExtension K K:Type u_1inst✝¹:Field Kinst✝:NumberField Kd:hd₁:d 1hd:Squarefree de:K ≃+* QuadraticAlgebra (↑d) 0IsQuadraticExtension K; All goals completed! 🐙

An integer D is a fundamental discriminant iff it is the discriminant of the explicit quadratic field QuadraticAlgebra ℚ d 0 for some squarefree d : ℤ not equal to 1.

d:hD:Squarefree dhD₄:¬d 1 [ZMOD 4]this:Fact (d 1) d_1, (x : Fact (d_1 1)) (x_1 : Fact (Squarefree d_1)), discr (QuadraticAlgebra (↑d_1) 0) = 4 * d d:hD:Squarefree dhD₄:¬d 1 [ZMOD 4]this✝:Fact (d 1)this:Fact (Squarefree d) d_1, (x : Fact (d_1 1)) (x_1 : Fact (Squarefree d_1)), discr (QuadraticAlgebra (↑d_1) 0) = 4 * d All goals completed! 🐙 D:hD₁:D 1hD₄:D 1 [ZMOD 4]hD:Squarefree D d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = D D:hD₁:D 1hD₄:D 1 [ZMOD 4]hD:Squarefree Dthis:Fact (D 1) d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = D D:hD₁:D 1hD₄:D 1 [ZMOD 4]hD:Squarefree Dthis✝:Fact (D 1)this:Fact (Squarefree D) d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = D All goals completed! 🐙 mpr := D:(∃ d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = D) IsFundamentalDiscr D d:w✝¹:Fact (d 1)w✝:Fact (Squarefree d)IsFundamentalDiscr (discr (QuadraticAlgebra (↑d) 0)); d:w✝¹:Fact (d 1)w✝:Fact (Squarefree d)hd₄:d 1 [ZMOD 4]IsFundamentalDiscr (discr (QuadraticAlgebra (↑d) 0))d:w✝¹:Fact (d 1)w✝:Fact (Squarefree d)hd₄:¬d 1 [ZMOD 4]IsFundamentalDiscr (discr (QuadraticAlgebra (↑d) 0)) d:w✝¹:Fact (d 1)w✝:Fact (Squarefree d)hd₄:d 1 [ZMOD 4]IsFundamentalDiscr (discr (QuadraticAlgebra (↑d) 0))d:w✝¹:Fact (d 1)w✝:Fact (Squarefree d)hd₄:¬d 1 [ZMOD 4]IsFundamentalDiscr (discr (QuadraticAlgebra (↑d) 0)) All goals completed! 🐙

An integer D is a fundamental discriminant iff it is the discriminant of some number field.

D:(∃ d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = D) K x, (x_1 : NumberField K), IsQuadraticExtension K discr K = D D:(∃ d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = D) K x, (x_1 : NumberField K), IsQuadraticExtension K discr K = DD:(∃ K x, (x_1 : NumberField K), IsQuadraticExtension K discr K = D) d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = D D:(∃ d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = D) K x, (x_1 : NumberField K), IsQuadraticExtension K discr K = D d:w✝¹:Fact (d 1)w✝:Fact (Squarefree d) K x, (x_1 : NumberField K), IsQuadraticExtension K discr K = discr (QuadraticAlgebra (↑d) 0) All goals completed! 🐙 D:(∃ K x, (x_1 : NumberField K), IsQuadraticExtension K discr K = D) d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = D K:Typew✝¹:Field Kw✝:NumberField Kleft✝:IsQuadraticExtension K d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = discr K K:Typew✝¹:Field Kw✝:NumberField Kleft✝:IsQuadraticExtension Kd:hd₁:d 1hd:Squarefree de:K ≃+* QuadraticAlgebra (↑d) 0 d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = discr K K:Typew✝¹:Field Kw✝:NumberField Kleft✝:IsQuadraticExtension Kd:hd₁:d 1hd:Squarefree de:K ≃+* QuadraticAlgebra (↑d) 0this:Fact (d 1) d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = discr K K:Typew✝¹:Field Kw✝:NumberField Kleft✝:IsQuadraticExtension Kd:hd₁:d 1hd:Squarefree de:K ≃+* QuadraticAlgebra (↑d) 0this✝:Fact (d 1)this:Fact (Squarefree d) d, (x : Fact (d 1)) (x_1 : Fact (Squarefree d)), discr (QuadraticAlgebra (↑d) 0) = discr K All goals completed! 🐙end NumberFieldnamespace WallSunSunopen scoped NumberTheorySymbols

A prime $p$ is a Wall–Sun–Sun prime if and only if $L_p \equiv 1 \pmod{p^2}$, where $L_p$ is the $p$-th Lucas number. It is conjectured that there is at least one Wall–Sun–Sun prime.

@[category research open, AMS 11] theorem exists_isWallSunSunPrime : p, IsWallSunSunPrime p := p, IsWallSunSunPrime p All goals completed! 🐙

A prime $p$ is a Wall–Sun–Sun prime if and only if $L_p \equiv 1 \pmod{p^2}$, where $L_p$ is the $p$-th Lucas number. It is conjectured that there are infinitely many Wall-Sun-Sun primes.

@[category research open, AMS 11] theorem infinite_isWallSunSunPrime : {p : | IsWallSunSunPrime p}.Infinite := {p | IsWallSunSunPrime p}.Infinite All goals completed! 🐙@[category API, AMS 11] private lemma exists_parameters {D : } {p : } (hmod : (4 : ) D D 1 [ZMOD 4]) (hodd : Odd p) : a b : , a ^ 2 - 4 * b = D (p : ) ^ 2 a := D:p:hmod:4 D D 1 [ZMOD 4]hodd:Odd p a b, a ^ 2 - 4 * b = D p ^ 2 a D:p:hodd:Odd phfour:4 D a b, a ^ 2 - 4 * b = D p ^ 2 aD:p:hodd:Odd phone:D 1 [ZMOD 4] a b, a ^ 2 - 4 * b = D p ^ 2 a D:p:hodd:Odd phfour:4 D a b, a ^ 2 - 4 * b = D p ^ 2 a p:hodd:Odd pd: a b, a ^ 2 - 4 * b = 4 * d p ^ 2 a refine 2 * (p : ) ^ 2, (p : ) ^ 4 - d, p:hodd:Odd pd:(2 * p ^ 2) ^ 2 - 4 * (p ^ 4 - d) = 4 * d All goals completed! 🐙, ?_ All goals completed! 🐙 D:p:hodd:Odd phone:D 1 [ZMOD 4] a b, a ^ 2 - 4 * b = D p ^ 2 a D:hone:D 1 [ZMOD 4]k: a b, a ^ 2 - 4 * b = D (2 * k + 1) ^ 2 a D:hone:D 1 [ZMOD 4]k:c:hc:1 - D = 4 * c a b, a ^ 2 - 4 * b = D (2 * k + 1) ^ 2 a D:hone:D 1 [ZMOD 4]k:c:hc:1 - D = 4 * c((2 * k + 1) ^ 2) ^ 2 - 4 * (4 * k ^ 4 + 8 * k ^ 3 + 6 * k ^ 2 + 2 * k + c) = D D:hone:D 1 [ZMOD 4]k:c:hc:1 - D = 4 * c((2 * k + 1) ^ 2) ^ 2 - 4 * (4 * k ^ 4 + 8 * k ^ 3 + 6 * k ^ 2 + 2 * k + c) = D All goals completed! 🐙

An earlier formulation of infinite_isWallSunSunPrime_of_disc_eq, which chose the Lucas parameters $(a, b)$ separately for every prime $p$, was degenerate: it is provable.

D:hD:IsFundamentalDiscr DhDzero:D 0hmod:4 D D 1 [ZMOD 4]B: := max D.natAbs 2hinf:({p | Nat.Prime p} \ Set.Iic B).Infinitep:hp:Nat.Prime phpB:B < phpD:D.natAbs < php2:2 < phodd:Odd phpd:¬p Dp {p | a b, a ^ 2 - 4 * b = D IsLucasWieferichPrime a b p} D:hD:IsFundamentalDiscr DhDzero:D 0hmod:4 D D 1 [ZMOD 4]B: := max D.natAbs 2hinf:({p | Nat.Prime p} \ Set.Iic B).Infinitep:hp:Nat.Prime phpB:B < phpD:D.natAbs < php2:2 < phodd:Odd phpd:¬p Da:b:hab:a ^ 2 - 4 * b = Dha:p ^ 2 ap {p | a b, a ^ 2 - 4 * b = D IsLucasWieferichPrime a b p} All goals completed! 🐙

Let $K$ be a real quadratic field of discriminant $D$ and let $\varepsilon$ be a fundamental unit of $K$. Following [EJ10, Remark 2.2.8], an odd prime $p \nmid D$ is a Wall–Sun–Sun prime for $K$ if, in $\mathcal{O}_K$, $\varepsilon^{p-1} \equiv 1 \pmod{p^2}$ when $\left(\tfrac{D}{p}\right) = 1$, and $\varepsilon^{2p+2} \equiv 1 \pmod{p^2}$ when $\left(\tfrac{D}{p}\right) = -1$. Both exponents are even, so the condition does not depend on the choice of $\varepsilon$, and it is equivalent to asking the same congruence for every unit of $K$. For $K = \mathbb{Q}(\sqrt{5})$ and $\varepsilon = \frac{1 + \sqrt{5}}{2}$ these are the classical Wall–Sun–Sun primes other than $2$ and $5$ [EJ10, Proposition 2.2.6].

It is conjectured that for every fundamental discriminant $D \neq 1$ there are infinitely many Wall–Sun–Sun primes with discriminant $D$ (Wikipedia; [EJ10, §4.1] gives the heuristic for $\mathbb{Q}(\sqrt{5})$). It is stated here for $D > 0$ only. Wikipedia's sentence also covers $D < 0$, but [EJ10] gives the definition above only for real quadratic fields, and its literal extension to imaginary quadratic fields is degenerate: there every unit is a root of unity of order dividing $4$ or $6$, and that order divides the relevant exponent $p - 1$ or $2p + 2$ for every odd prime $p \nmid D$.

@[category research open, AMS 11] theorem infinite_isWallSunSunPrime_of_disc_eq {K : Type*} [Field K] [NumberField K] [IsQuadraticExtension K] [IsTotallyReal K] {D : } (hD : discr K = D) : {p : | p.Prime Odd p ¬ (p : ) D ε : (𝓞 K)ˣ, (p : 𝓞 K) ^ 2 (ε : 𝓞 K) ^ (if J(D | p) = 1 then p - 1 else 2 * p + 2) - 1}.Infinite := K:Type u_1inst✝³:Field Kinst✝²:NumberField Kinst✝¹:IsQuadraticExtension Kinst✝:IsTotallyReal KD:hD:discr K = D{p | Nat.Prime p Odd p ¬p D (ε : (𝓞 K)ˣ), p ^ 2 (ε ^ if J(D | p) = 1 then p - 1 else 2 * p + 2) - 1}.Infinite All goals completed! 🐙end WallSunSun