/- 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. -/ import FormalConjecturesUtil

Agoh-Giuga conjecture

Reference: Wikipedia

open scoped Nat/- The **Agoh-Giuga Conjecture**. References: * Wikipedia: https://en.wikipedia.org/wiki/Agoh-Giuga_conjecture * Wikipedia: https://en.wikipedia.org/wiki/Giuga_number * G. Giuga, _Su una presumibile proprieta caratteristica dei numeri primi_ * E. Bedocchi, _Note on a conjecture about prime numbers_ * D. Borwein, J. M. Borwein, P. B. Borwein, and R. Girgensohn, _Giuga’s conjecture on primality_ * V. Tipu, _A Note on Giuga’s Conjecture_ -/ namespace AgohGiuga

The Agoh-Giuga Conjecture, Agoh's formulation. An integer p ≥ 2 is prime if and only if we have p*B_{p-1} ≡ -1 [MOD p]

def AgohGiugaCongr : Prop := p 2, p.Prime (k : ), let B := bernoulli' (p - 1) p * B.num + B.den = k * p^2

The Agoh-Giuga Conjecture, Giuga's formulation. An integer p ≥ 2 is prime if and only if it satisfies the congruence ∑_{i=1}^{p-1} i^{p-1} ≡ -1 [MOD p].

def AgohGiugaSum : Prop := p 2, p.Prime p 1 + i Finset.Ioo 0 p, i^(p - 1 : )

The Agoh-Giuga Conjecture, Agoh's formulation

@[category research open, AMS 11] theorem agoh_giuga : AgohGiugaCongr := AgohGiugaCongr All goals completed! 🐙

The Agoh-Giuga Conjecture, Giuga's formulation

@[category research open, AMS 11] theorem agoh_giuga.variants.giuga : AgohGiugaSum := AgohGiugaSum All goals completed! 🐙

The two statements of the conjecture are equivalent.

@[category research solved, AMS 11] theorem agoh_giuga.variants.equivalence : AgohGiugaCongr AgohGiugaSum := AgohGiugaCongr AgohGiugaSum All goals completed! 🐙

A (weak) Giuga number is a composite number $n$ such that $$\sum_{i=1}^{n - 1}i^{\varphi(n)} \equiv -1\pmod{n}$$.

def IsWeakGiuga (n : ) : Prop := n.Composite n 1 + i Finset.Ioo 0 n, i ^ φ n

A (strong) Giuga number is a composite number $n$ such that $$\sum_{i=1}^{n - 1}i^{n - 1} \equiv -1\pmod{n}$$

def IsStrongGiuga (n : ) : Prop := n.Composite n 1 + i Finset.Ioo 0 n, i ^ (n - 1)

A composite number $n$ is weak Giuga if and only if $p \mid (\frac{n}{p} - 1)$ for all prime divisors $p$ of $n$.

@[category research solved, AMS 11, formal_proof using formal_conjectures at "https://github.com/mo271/formal-conjectures/blob/2663234a28260853790aa5752d8d4550ff0ab1ca/FormalConjectures/Wikipedia/AgohGiuga.lean#L97"] theorem isWeakGiuga_iff_prime_dvd {n : } (hn : n.Composite) : IsWeakGiuga n p n.primeFactors, p (n / p - 1) := n:hn:n.CompositeIsWeakGiuga n p n.primeFactors, p n / p - 1 All goals completed! 🐙

A composite number $n$ is weak Giuga if and only if $$ \sum_{p\mid n} \frac{1}{p} - \frac{1}{n} \in\mathbb{N}. $$

@[category research solved, AMS 11] theorem isWeakGiuga_iff_sum_primeFactors {n : } (hn : n.Composite) : IsWeakGiuga n m : , p n.primeFactors, (1 / p : ) - 1 / n = m := n:hn:n.CompositeIsWeakGiuga n m, p n.primeFactors, 1 / p - 1 / n = m All goals completed! 🐙

A composite Carmichael number is squarefree.

p:hp:Nat.Prime pN:ha₁:1 < p * (p * N) ¬Nat.Prime (p * (p * N))ha₂: (b : ), 1 b (p * p * N).Coprime b p * p * N b ^ (p * p * N - 1) - 1ha₂_forall: (b : ), 1 b (p * p * N).Coprime b p * p * N b ^ (p * p * N - 1) - 1this:Fact (Nat.Prime p)¬(p.Coprime (p * N + 1) (p * N).Coprime (p * N + 1) p * (p * N) (∑ i Finset.range (p * (p * N) - 1), (p * N + 1) ^ i) * (p * N + 1 - 1)) simpa using (mul_dvd_mul_iff_right fun _ p:hp:Nat.Prime pN:ha₁:1 < p * (p * N) ¬Nat.Prime (p * (p * N))ha₂: (b : ), 1 b (p * p * N).Coprime b p * p * N b ^ (p * p * N - 1) - 1ha₂_forall: (b : ), 1 b (p * p * N).Coprime b p * p * N b ^ (p * p * N - 1) - 1this:Fact (Nat.Prime p)x✝:p * N = 0False All goals completed! 🐙).not.mpr ((ZMod.natCast_eq_zero_iff _ _).not.mp (p:hp:Nat.Prime pN:ha₁:1 < p * (p * N) ¬Nat.Prime (p * (p * N))ha₂: (b : ), 1 b (p * p * N).Coprime b p * p * N b ^ (p * p * N - 1) - 1ha₂_forall: (b : ), 1 b (p * p * N).Coprime b p * p * N b ^ (p * p * N - 1) - 1this:Fact (Nat.Prime p)¬(∑ i Finset.range (p * (p * N) - 1), (p * N + 1) ^ i) = 0 All goals completed! 🐙))

A composite number a is Carmichael if and only if it is squarefree and, for all prime p dividing a, we have p - 1 ∣ a - 1.

a:b:hb✝:1 bhab:a.Coprime bh_sqfr: (x : ), Nat.Prime x ¬x * x ah_dvd: (p : ), Nat.Prime p p a p - 1 a - 1hb:¬b ^ (a - 1) - 1 = 0p:hp:Nat.Prime phpa:p aw:h:a - 1 = (p - 1) * wha₁:1 < aha₂:¬Nat.Prime athis:a.factorization p = 1one_le_b_pow:1 b ^ (a - 1)(b ^ (a - 1) - 1) = 0 a:b:hb✝:1 bhab:a.Coprime bh_sqfr: (x : ), Nat.Prime x ¬x * x ah_dvd: (p : ), Nat.Prime p p a p - 1 a - 1hb:¬b ^ (a - 1) - 1 = 0p:hp:Nat.Prime phpa:p aw:h:a - 1 = (p - 1) * wha₁:1 < aha₂:¬Nat.Prime athis:a.factorization p = 1one_le_b_pow:1 b ^ (a - 1)b ^ (a - 1) - 1 = 0 simp_rw a:b:hb✝:1 bhab:a.Coprime bh_sqfr: (x : ), Nat.Prime x ¬x * x ah_dvd: (p : ), Nat.Prime p p a p - 1 a - 1hb:¬b ^ (a - 1) - 1 = 0p:hp:Nat.Prime phpa:p aw:h:a - 1 = (p - 1) * wha₁:1 < aha₂:¬Nat.Prime athis:a.factorization p = 1one_le_b_pow:1 b ^ (a - 1)b ^ (a - 1) - 1 = 0a:b:hb✝:1 bhab:a.Coprime bh_sqfr: (x : ), Nat.Prime x ¬x * x ah_dvd: (p : ), Nat.Prime p p a p - 1 a - 1hb:¬b ^ (a - 1) - 1 = 0p:hp:Nat.Prime phpa:p aw:h:a - 1 = (p - 1) * wha₁:1 < aha₂:¬Nat.Prime athis:a.factorization p = 1one_le_b_pow:1 b ^ (a - 1)b ^ ((p - 1) * w) - 1 = 0 a:b:hb✝:1 bhab:a.Coprime bh_sqfr: (x : ), Nat.Prime x ¬x * x ah_dvd: (p : ), Nat.Prime p p a p - 1 a - 1hb:¬b ^ (a - 1) - 1 = 0p:hp:Nat.Prime phpa:p aw:h:a - 1 = (p - 1) * wha₁:1 < aha₂:¬Nat.Prime athis:a.factorization p = 1one_le_b_pow:1 b ^ (a - 1)(b ^ (p - 1)) ^ w - 1 = 0] simp_all +decide [CharP.cast_eq_zero_iff _ p, hp.coprime_iff_not_dvd.1 (hab.of_dvd_left (a:b:hb✝:1 bhab:a.Coprime bh_sqfr: (x : ), Nat.Prime x ¬x * x ah_dvd: (p : ), Nat.Prime p p a p - 1 a - 1hb:¬b ^ (a - 1) - 1 = 0p:hp:Nat.Prime phpa:p aw:h:a - 1 = (p - 1) * wha₁:1 < aha₂:¬Nat.Prime athis:a.factorization p = 1one_le_b_pow:1 b ^ (a - 1)p a All goals completed! 🐙)), ZMod.pow_card_sub_one_eq_one] a:b:ha₁:1 < a ¬Nat.Prime ahb✝:1 bhab:a.Coprime bh_sqfr: (x : ), Nat.Prime x ¬x * x ah_dvd: (p : ), Nat.Prime p p a p - 1 a - 1hb:¬b ^ (a - 1) - 1 = 0p:hp:Nat.Prime phpa:¬p aa.factorization p (b ^ (a - 1) - 1).factorization p All goals completed! 🐙 a:b:ha₁:1 < a ¬Nat.Prime ahb✝:1 bhab:a.Coprime bh_sqfr: (x : ), Nat.Prime x ¬x * x ah_dvd: (p : ), Nat.Prime p p a p - 1 a - 1hb:¬b ^ (a - 1) - 1 = 0p:hp:¬Nat.Prime pa.factorization p (b ^ (a - 1) - 1).factorization p All goals completed! 🐙h_comp:Nat.Composite 561p:hp:Nat.Prime php_dvd:p 3 * (11 * 17)h1:561 = 3 * (11 * 17)h11_17:p 11 * 17h17:p 17this:p = 17p - 1 561 - 1 h_comp:Nat.Composite 561h1:561 = 3 * (11 * 17)hp:Nat.Prime 17hp_dvd:17 3 * (11 * 17)h11_17:17 11 * 17h17:17 1717 - 1 561 - 1; All goals completed! 🐙

Giuga showed that a number n is strong Giuga if and only if it is Carmichael and ∑_{p|n} 1/p - 1/n ∈ ℕ (i.e., if and only if it is Carmichael and weak Giuga). Ref: G. Giuga, Su una presumibile proprieta caratteristica dei numeri primi

@[category research solved, AMS 11] theorem isStrongGiuga_iff {a : } (ha : a.Composite) : IsStrongGiuga a IsCarmichael a n : , p a.primeFactors, (1 / p : ) - 1 / a = n := a:ha:a.CompositeIsStrongGiuga a IsCarmichael a n, p a.primeFactors, 1 / p - 1 / a = n All goals completed! 🐙

Every strong Giuga number is a Carmichael number.

@[category research solved, AMS 11] theorem agoh_giuga.variants.isStrongGiuga_implies_isCarmichael (a : ) (ha : IsStrongGiuga a) : IsCarmichael a := a:ha:IsStrongGiuga aIsCarmichael a All goals completed! 🐙

Giuga showed that a Giuga number has at least 9 prime factors. Ref: G. Giuga, Su una presumibile proprieta caratteristica dei numeri primi

@[category research solved, AMS 11] theorem agoh_giuga.variants.le_primeFactors_card_of_isStrongGiuga (a : ) (ha : IsStrongGiuga a) : 9 a.primeFactors.card := a:ha:IsStrongGiuga a9 a.primeFactors.card All goals completed! 🐙

Giuga showed that a counterexample Giuga number has at least 1000 digits. Ref: G. Giuga, Su una presumibile proprieta caratteristica dei numeri primi

@[category research solved, AMS 11] theorem agoh_giuga.variants._1000_le_digits_length_of_isStrongGiuga (a : ) (ha : IsStrongGiuga a) : 1000 (Nat.digits 10 a).length := a:ha:IsStrongGiuga a1000 (Nat.digits 10 a).length All goals completed! 🐙

Bedocchi showed that any Giuga number has at least 1700 digits. Ref: E. Bedocchi, Note on a conjecture about prime numbers

@[category research solved, AMS 11] theorem agoh_giuga.variants._1700_le_digits_length_of_isStrongGiuga (a : ) (ha : IsStrongGiuga a) : (Nat.digits 10 a).length > 1700 := a:ha:IsStrongGiuga a(Nat.digits 10 a).length > 1700 All goals completed! 🐙

Borwein, Borwein, Borwein and Girgensohn showed that any strong Giuga number has at least 13000 digits. Ref: D. Borwein, J. M. Borwein, P. B. Borwein, and R. Girgensohn, Giuga’s conjecture on primality

@[category research solved, AMS 11] theorem agoh_giuga.variants._13000_le_digits_length_of_isStrongGiuga (a : ) (ha : IsStrongGiuga a) : 13000 (Nat.digits 10 a).length := a:ha:IsStrongGiuga a13000 (Nat.digits 10 a).length All goals completed! 🐙open scoped Classical in

Let G(X) denote the number of exceptions n ≤ X to Giuga’s conjecture. Then for X larger than an absolute constant which can be made explicit, G(X) ≪ X^{1/2} log X. Ref: Vicentiu Tipu, A Note on Giuga’s Conjecture

@[category research solved, AMS 11] theorem agoh_giuga.variants.isStrongGiuga_growth (G : ) (hG : G = fun x => Finset.Icc 1 x |>.filter IsStrongGiuga |>.card) : N O, n N, G n O * (n : ).sqrt * (n : ).log := G: hG:G = fun x (Finset.filter IsStrongGiuga (Finset.Icc 1 x)).card N O, n N, (G n) O * n * Real.log n All goals completed! 🐙end AgohGiuga