Counting primes in a residue class

The count follows the classical proof of Dirichlet's theorem with explicit constants. Mertens' first theorem controls \(\sum_{n\le x}\Lambda(n)/n\) to within \(3\), and the principal character inherits this up to the primes dividing \(q\).

TheoremMertens' first theorem#✓

Let \(\Lambda\) be the von Mangoldt function and \(\psi(x)=\sum_{n\le x}\Lambda(n)\). For every real \(x\ge0\), \(\psi(x)\le3x\). For every real \(x\ge1\), $\(\log x-2\le\sum_{n\le x}\frac{\Lambda(n)}{n}\le\log x+3,\qquad\text{so}\qquad \Bigl|\sum_{n\le x}\frac{\Lambda(n)}{n}-\log x\Bigr|\le3 .\)$

Proof sketch. Chebyshev's bound \(\psi(x)\le\log4\cdot x+2\sqrt x\log x\) for \(x\ge1\), with \(\log x\le2\sqrt x/e\) (from \(\log t\le t-1\) at \(t=\sqrt x/e\)) and \(4/e\le1.5\), gives \(\psi(x)\le(\log4+1.5)x\le3x\); for \(x<2\), \(\psi(x)=0\). Let \(N=\lfloor x\rfloor\ge1\). Since \(\log n=\sum_{d\mid n}\Lambda(d)\), $\(\log N!=\sum_{d\le N}\Lambda(d)\Bigl\lfloor\frac Nd\Bigr\rfloor =N\sum_{d\le N}\frac{\Lambda(d)}d-\sum_{d\le N}\Lambda(d)\Bigl\{\frac Nd\Bigr\},\)$ and the last sum lies in \([0,\psi(N)]\). With \(N\log N-N\le\log N!\le N\log N\) and \(\psi(N)\le3N\), this gives \(\log N-1\le\sum_{d\le N}\Lambda(d)/d\le\log N+3\). Finally \(\log N\le\log x\le\log N+1\), since \(x/N<2\).

noncomputable def mertensSum (x : ℝ) : ℝ := ∑ n ∈ Ioc 0 ⌊x⌋₊, Λ n / n
theorem abs_mertensSum_sub_log_le {x : ℝ} (hx : 1 ≤ x) : |mertensSum x - log x| ≤ 3
theorem log_sub_two_le_mertensSum {x : ℝ} (hx : 1 ≤ x) : log x - 2 ≤ mertensSum x
Sources
Used by 2

TheoremThe principal character#✓

Let \(q\ge1\) and let \(1\le y\le x\) be real. Then $\(\sum_{\substack{y<n\le x\\ \gcd(n,q)=1}}\frac{\Lambda(n)}{n}\ge\log\frac xy-6-\log q ;\)$ the left side is \(S_{\chi_0}(x)-S_{\chi_0}(y)\) for the principal character \(\chi_0\) modulo \(q\). Moreover, for every integer \(N\ge0\), \(\sum_{n\le N,\ \gcd(n,q)>1}\Lambda(n)/n\le\log q\).

Proof sketch. By Mertens' first theorem, \(\sum_{y<n\le x}\Lambda(n)/n\ge(\log x-2)-(\log y+3)\ge\log(x/y)-6\). The terms with \(\gcd(n,q)>1\) and \(\Lambda(n)\ne0\) are the powers \(p^k\) of the primes \(p\mid q\), and all of them together contribute at most \(\sum_{p\mid q}\sum_{k\ge1}\log p/p^k=\sum_{p\mid q}\log p/(p-1)\le\sum_{p\mid q}\log p\le\log q\).

theorem log_div_sub_le_re_twistedSum_one_sub [NeZero q] {x y : ℝ} (hy : 1 ≤ y) (hyx : y ≤ x) :
    Real.log (x / y) - 2 * 3 - Real.log q ≤
      (twistedSum (1 : DirichletCharacter ℂ q) x -
        twistedSum (1 : DirichletCharacter ℂ q) y).re
lemma twistedSum_one_eq (x : ℝ) :
    twistedSum (1 : DirichletCharacter ℂ q) x =
      ((∑ n ∈ Ioc 0 ⌊x⌋₊ with n.Coprime q, Λ n / n : ℝ) : ℂ)
theorem sum_nonunit_vonMangoldt_div_le_log {q : ℕ} (hq : q ≠ 0) (N : ℕ) :
    ∑ n ∈ Ioc 0 N with ¬ n.Coprime q, Λ n / n ≤ Real.log q
Sources
Uses 1 · Used by 1

For a nonprincipal \(\chi\), the identity \(\log n=\sum_{d\mid n}\Lambda(d)\) relates \(L(1,\chi)\sum_{n\le x}\chi(n)\Lambda(n)/n\) to the bounded sum \(\sum_{n\le x}\chi(n)\log n/n\), so the twisted sum is at most \((M^2+6q)/|L(1,\chi)|\); the lower bounds for \(|L(1,\chi)|\) of the preceding sections combine into one bound for all nonprincipal characters.

TheoremThe twisted sum and \(L(1,\chi)\)#✓

Let \(q\ge1\), let \(\chi\) be a nonprincipal Dirichlet character modulo \(q\), put \(M=\log q+3\), and for real \(x\) let $\(S_\chi(x)=\sum_{n\le x}\frac{\chi(n)\Lambda(n)}{n},\qquad T_\chi(x)=\sum_{n\le x}\frac{\chi(n)\log n}{n}.\)$ Then for every real \(x\ge1\), $\(|L(1,\chi)|\,|S_\chi(x)|\le|T_\chi(x)|+\frac{2q\,\psi(x)}{x}\le M^2+6q ,\)$ and hence, as \(L(1,\chi)\ne0\), \(|S_\chi(x)|\le(M^2+6q)/|L(1,\chi)|\).

Proof sketch. Write \(\log n=\sum_{d\mid n}\Lambda(d)\) and \(n=dm\), using \(\chi(dm)=\chi(d)\chi(m)\): $\(T_\chi(x)=\sum_{d\le x}\frac{\chi(d)\Lambda(d)}{d}\sum_{m\le x/d}\frac{\chi(m)}{m} =L(1,\chi)S_\chi(x)+\sum_{d\le x}\frac{\chi(d)\Lambda(d)}{d}R\Bigl(\frac xd\Bigr),\)$ where \(R(y)=\sum_{m\le y}\chi(m)/m-L(1,\chi)\) satisfies \(|R(y)|\le2q/y\) for \(y\ge1\). So \(|L(1,\chi)||S_\chi(x)|\le|T_\chi(x)|+(2q/x)\sum_{d\le x}\Lambda(d)=|T_\chi(x)|+2q\psi(x)/x\), and \(|T_\chi(x)|\le M^2\) while \(\psi(x)\le3x\).

theorem norm_LFunction_one_mul_norm_twistedSum_le_explicit {χ : DirichletCharacter ℂ q}
    (hχ : χ ≠ 1) {x : ℝ} (hx : 1 ≤ x) :
    ‖DirichletCharacter.LFunction χ 1‖ * ‖twistedSum χ x‖ ≤ (Real.log q + 3) ^ 2 + 6 * q
theorem norm_twistedSum_le {χ : DirichletCharacter ℂ q} (hχ : χ ≠ 1) {x : ℝ} (hx : 1 ≤ x) :
    ‖twistedSum χ x‖ ≤ ((Real.log q + 3) ^ 2 + 6 * q) / ‖DirichletCharacter.LFunction χ 1‖
theorem norm_LFunction_one_mul_norm_twistedSum_le {χ : DirichletCharacter ℂ q} (hχ : χ ≠ 1)
    {x : ℝ} (hx : 1 ≤ x) :
    ‖DirichletCharacter.LFunction χ 1‖ * ‖twistedSum χ x‖ ≤
      ‖logSum χ x‖ + 2 * q * ψ x / x
Uses 3 · Used by 1

TheoremA lower bound for \(|L(1,\chi)|\) at every nonprincipal character#✓

Let \(q\ge1\), put \(M=\log q+3\), and let \(\chi\) be a nonprincipal Dirichlet character modulo \(q\). Then $\(|L(1,\chi)|\ge\min\Bigl(\frac1{256\,M^7},\ \frac1{40\,q^{3/2}}\Bigr).\)$

Proof sketch. If \(\chi^2\ne\chi_0\), the lower bound at complex characters gives \(|L(1,\chi)|\ge1/(256M^7)\). If \(\chi^2=\chi_0\), the lower bound at real characters gives \(|L(1,\chi)|\ge1/(40q^{3/2})\). In both cases \(|L(1,\chi)|\) is at least the minimum.

theorem min_le_norm_LFunction_one {q : ℕ} [NeZero q] {χ : DirichletCharacter ℂ q} (hχ : χ ≠ 1) :
    min (1 / (256 * (Real.log q + 3) ^ 7)) (1 / (40 * (q * √q))) ≤
      ‖DirichletCharacter.LFunction χ 1‖
theorem effectiveLBound_le_norm_LFunction_one {q : ℕ} [NeZero q] {χ : DirichletCharacter ℂ q}
    (hχ : χ ≠ 1) : effectiveLBound q ≤ ‖DirichletCharacter.LFunction χ 1‖
Sources
Uses 2 · Used by 1

Orthogonality isolates one residue class; above \(y=q^8\), prime powers with exponent at least \(2\) add less than \(1/5\) and each prime adds at most \(\log y/y\). So the interval \((q^8,q^8e^{5qB}]\) holds twenty-two primes of the class when every twisted sum is at most \(B\).

TheoremDetecting a residue class by characters#✓

Let \(q\ge1\) and let \(a\) be a unit modulo \(q\), with inverse \(a^{-1}\) modulo \(q\). For real \(x\) put $\(S_a(x)=\sum_{\substack{n\le x\\ n\equiv a\ (\mathrm{mod}\ q)}}\frac{\Lambda(n)}{n},\qquad S_\chi(x)=\sum_{n\le x}\frac{\chi(n)\Lambda(n)}{n}\)$ for each Dirichlet character \(\chi\) modulo \(q\). Then $\(S_a(x)=\frac1{\varphi(q)}\sum_{\chi\bmod q}\chi(a^{-1})\,S_\chi(x),\)$ the sum running over the \(\varphi(q)\) Dirichlet characters modulo \(q\), where \(\chi(a^{-1})=\chi(a)^{-1}=\overline{\chi(a)}\). Consequently, for all real \(x,y\), $\(S_a(x)-S_a(y)=\frac1{\varphi(q)}\,\mathrm{Re}\sum_{\chi\bmod q}\chi(a^{-1}) \bigl(S_\chi(x)-S_\chi(y)\bigr).\)$

Proof sketch. Exchange the sums and apply the orthogonality relation \(\sum_\chi\chi(a^{-1})\chi(n)=\varphi(q)\) if \(n\equiv a\pmod q\) and \(0\) otherwise. Subtract the identities at \(x\) and \(y\); the left side is real, so it equals the real part of the right side.

noncomputable def classSum (a : ZMod q) (x : ℝ) : ℝ :=
  ∑ n ∈ Ioc 0 ⌊x⌋₊ with ((n : ℕ) : ZMod q) = a, Λ n / n
noncomputable def twistedSum (χ : DirichletCharacter ℂ q) (x : ℝ) : ℂ :=
  ∑ n ∈ Ioc 0 ⌊x⌋₊, χ n * Λ n / n
theorem classSum_eq_sum_twistedSum (ha : IsUnit a) (x : ℝ) :
    (classSum a x : ℂ) =
      (q.totient : ℂ)⁻¹ * ∑ χ : DirichletCharacter ℂ q, χ a⁻¹ * twistedSum χ x
Sources
Used by 1

TheoremHigher prime powers contribute little#✓

For every integer \(N\ge0\), $\(\sum_{\substack{n\le N\\ n\text{ not prime}}}\frac{\Lambda(n)}{n}\le2 ,\)$ that is, the prime powers \(p^k\) with \(k\ge2\) contribute at most \(2\) to \(\sum_{n\le N}\Lambda(n)/n\). Moreover, for all integers \(Y\ge1\) and \(M\ge0\), with \(s=\lfloor\sqrt Y\rfloor\), $\(\sum_{\substack{Y<n\le M\\ n\text{ not prime}}}\frac{\Lambda(n)}{n} \le\frac{\log s+2+2\log4}{s}.\)$

Proof sketch. A sum of \(\Lambda(n)h(n)\) with \(h\ge0\) is at most the double sum of \(\log p\cdot h(p^k)\) over primes \(p\) and exponents \(k\) that cover its prime powers. The telescoping bound \(\sum_{s<n\le N}\log n/(n(n-1))\le(\log s+2)/s-(\log N+2)/N\) for \(1\le s\le N\) holds term by term. For the first bound, the sum is at most \(\sum_p\sum_{k\ge2}\log p/p^k\le\sum_p\log p/(p(p-1))\le\sum_{m\ge2}\log m/(m(m-1))\le2\), by the telescoping bound at \(s=1\). For the second, a prime \(p\le s\) contributes at most \(2\log p/Y\), since its powers above \(Y\) form a geometric series with ratio \(1/p\le1/2\) starting below \(1/Y\); these primes give at most \(2\theta(s)/Y\le2\log4\cdot s/Y\le2\log4/s\). A prime \(p>s\) contributes at most \(\log p/(p(p-1))\), and these primes give at most \(\sum_{n>s}\log n/(n(n-1))\le(\log s+2)/s\).

theorem sum_nonprime_vonMangoldt_div_le_two (N : ℕ) :
    ∑ n ∈ Ioc 0 N with ¬ n.Prime, Λ n / n ≤ 2
theorem sum_Ioc_nonprime_vonMangoldt_div_le {Y : ℕ} (hY : 1 ≤ Y) (M : ℕ) :
    ∑ n ∈ Ioc Y M with ¬ n.Prime, Λ n / n ≤
      (Real.log (Nat.sqrt Y) + 2 + 2 * Real.log 4) / Nat.sqrt Y
theorem sum_vonMangoldt_mul_le_sum_primePow {A P K : Finset ℕ} (h : ℕ → ℝ)
    (hh : ∀ n, 0 ≤ h n) (hP : ∀ p ∈ P, p.Prime) (hK : ∀ k ∈ K, k ≠ 0)
    (hA : ∀ n ∈ A, IsPrimePow n → ∃ p ∈ P, ∃ k ∈ K, p ^ k = n) :
    ∑ n ∈ A, Λ n * h n ≤ ∑ p ∈ P, ∑ k ∈ K, Real.log p * h (p ^ k)
Sources
Used by 1

TheoremTwenty-two primes from a twisted sum bound#✓

Let \(q\ge3\) and \(B\ge1\) be such that \(\bigl|\sum_{n\le t}\chi(n)\Lambda(n)/n\bigr|\le B\) for every nonprincipal Dirichlet character \(\chi\) modulo \(q\) and every real \(t\ge1\). Let \(a\ge0\) be an integer coprime to \(q\). Then at least \(22\) primes \(p\equiv a\pmod q\) satisfy $\(q^8<p\le q^8e^{5qB}.\)$ In particular, if \(c>0\) and \(|L(1,\chi)|\ge c\) for every nonprincipal character \(\chi\) modulo \(q\), then this holds with \(B=((\log q+3)^2+6q)/c\).

Proof sketch. Let \(S_a(t)=\sum_{n\le t,\ n\equiv a}\Lambda(n)/n\), \(y=q^8\) and \(x=q^8e^{5qB}\), so \(\log(x/y)=5qB\). Detecting the class by characters, the principal character contributes at least \(\log(x/y)-6-\log q\) to \(\varphi(q)(S_a(x)-S_a(y))\), and each of the other \(\varphi(q)-1\) characters at most \(2B\) in absolute value. So $\(S_a(x)-S_a(y)\ge\frac{\log(x/y)-6-\log q-2B(\varphi(q)-1)}{\varphi(q)}\ge1,\)$ using \(\varphi(q)\le q\), \(\log q\le q-1\), \(B\ge1\) and \(q\ge3\). On the other hand, each prime \(p>y\) contributes \(\log p/p\le\log y/y\le16/6561\) (as \(y\ge3^8=6561\) and \(\log t/t\) decreases for \(t\ge3\)), and the prime powers \(p^k\) with \(k\ge2\) above \(y\) contribute at most \((\log s+2+2\log4)/s\le16/81\) with \(s=\lfloor\sqrt y\rfloor=q^4\ge81\). If at most \(21\) primes \(p\equiv a\) lay in \((y,x]\), then \(S_a(x)-S_a(y)\le21\cdot16/6561+16/81<1\). For the last claim, the twisted sum bound gives \(|S_\chi(t)|\le((\log q+3)^2+6q)/c\), which is at least \(1\) since \(c\le|L(1,\chi)|\le\log q+3\) for some nonprincipal \(\chi\) (one exists as \(q\ge3\)).

theorem twentytwo_primes_of_twisted_bound (hq : 3 ≤ q) {a : ℕ} (ha : a.Coprime q) {B : ℝ}
    (hB : 1 ≤ B)
    (hS : ∀ χ : DirichletCharacter ℂ q, χ ≠ 1 → ∀ x : ℝ, 1 ≤ x → ‖twistedSum χ x‖ ≤ B) :
    22 ≤ #{p ∈ Ioc (q ^ 8) ⌊(q : ℝ) ^ 8 * Real.exp (5 * q * B)⌋₊ |
      p.Prime ∧ p ≡ a [MOD q]}
theorem twentytwo_primes_of_LFunction_lower_bound (hq : 3 ≤ q) {a : ℕ} (ha : a.Coprime q)
    {c : ℝ} (hc : 0 < c)
    (hL : ∀ χ : DirichletCharacter ℂ q, χ ≠ 1 → c ≤ ‖DirichletCharacter.LFunction χ 1‖) :
    22 ≤ #{p ∈ Ioc (q ^ 8)
        ⌊(q : ℝ) ^ 8 * Real.exp (5 * q * (((Real.log q + 3) ^ 2 + 6 * q) / c))⌋₊ |
      p.Prime ∧ p ≡ a [MOD q]}
theorem classSum_sub_ge [NeZero q] {a : ZMod q} (ha : IsUnit a) {B : ℝ}
    (hS : ∀ χ : DirichletCharacter ℂ q, χ ≠ 1 → ∀ x : ℝ, 1 ≤ x → ‖twistedSum χ x‖ ≤ B)
    {x y : ℝ} (hy : 1 ≤ y) (hyx : y ≤ x) :
    (q.totient : ℝ)⁻¹ * (Real.log (x / y) - 2 * 3 - Real.log q - 2 * B * (q.totient - 1)) ≤
      classSum a x - classSum a y
Sources
Uses 5 · Used by 1
7 fully proved

The dependency explorer needs JavaScript and its graph data.

Download the complete graph data.