Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Sampling and untricking primes in a residue class

Definition
GreenTaoPort_Wikipedia_GreenTao_Primes_WTrickDensity

by kmehltretter82 · Nov 14, 2026 · Mathlib c5ea003 (Lean v4.30.0)

arithmetic-progressionsgreen-tao-port-8822number-theory

For natural parameters W,NW,NW,N, the sampling scale is X=W⌊N/8⌋X=W\lfloor N/8\rfloorX=W⌊N/8⌋. The selected prime set consists of the primes in (⌊X/4⌋,X](\lfloor X/4\rfloor,X](⌊X/4⌋,X] whose remainder modulo WWW is bbb.

A selected prime ppp is sent to the natural parameter

u(p)=p−bWu(p)=\frac{p-b}{W}u(p)=Wp−b​

using natural subtraction and quotient, and then to its image in Z/NZ\mathbb Z/N\mathbb ZZ/NZ. The resulting finite cyclic set is the image of the selected primes under this map. In the positive-modulus residue-class setting, p=Wu(p)+bp=Wu(p)+bp=Wu(p)+b; the definitions themselves are total at arbitrary natural parameters. This sampling scale is chosen so that later bounds place the untricked points in the short interval used by the prime weight.

Definition code
import Definitions.Def_GreenTaoPort_Wikipedia_SzemeredisTheorem_Finite_Mean
import Definitions.Def_GreenTaoPort_Wikipedia_GreenTao_Parameters
import Definitions.Def_GreenTaoPort_Wikipedia_GreenTao_Primes_Chebyshev
import Definitions.Def_GreenTaoPort_Wikipedia_GreenTao_Primes_ReducedResidues
import Definitions.Def_GreenTaoPort_Wikipedia_GreenTao_Primes_WTrick
import Lean
import Mathlib.Algebra.BigOperators.Expect
import Mathlib.Analysis.SpecialFunctions.Log.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Combinatorics.Pigeonhole
import Mathlib.Data.Fintype.Card
import Mathlib.Data.Nat.Totient
import Mathlib.Data.ZMod.Basic
import Mathlib.NumberTheory.ArithmeticFunction.Moebius
import Mathlib.NumberTheory.Chebyshev
import Mathlib.NumberTheory.Divisors
import Mathlib.NumberTheory.Primorial
import Mathlib.Tactic

set_option autoImplicit true
set_option relaxedAutoImplicit false
set_option maxSynthPendingDepth 3


/-!
# From primes in a quarter interval to a dense W-tricked prime weight

This file supplies the finite arithmetic bridge in the `W`-trick.  We take
`X = W * (N / 8)`, choose one reduced class among the primes in `(X / 4, X]`,
and send a prime `p` in that class to `(p - b) / W`.  The generous constants
in `greenTaoInterval` make this quotient lie in `[N / 64, N / 4]`.
-/

namespace Wikipedia.SzemeredisTheorem

open Finset Real Filter
open scoped BigOperators

/-- The scale at which primes are sampled before applying the `W`-trick. -/
def wTrickPrimeScale (W N : ℕ) : ℕ :=
  W * (N / 8)

/-- The primes in `(X / 4, X]`, where `X = W * (N / 8)`, which lie in the
standard residue class `b` modulo `W`. -/
def quarterIntervalResidueClass (W N b : ℕ) : Finset ℕ :=
  residueFiber (primesInQuarterInterval (wTrickPrimeScale W N)) W b



/-- The natural parameter underlying a prime in residue class `b`. -/
def untrickPrime (W b p : ℕ) : ℕ :=
  (p - b) / W

/-- The same parameter, regarded as an element of the cyclic group. -/
def untrickPrimeZMod (N W b p : ℕ) : ZMod N :=
  (untrickPrime W b p : ℕ)

















/-- The image of the selected primes inside the cyclic group. -/
def untrickedPrimeResidues (N W b : ℕ) : Finset (ZMod N) :=
  (quarterIntervalResidueClass W N b).image
    (untrickPrimeZMod N W b)













































end Wikipedia.SzemeredisTheorem


/- Materialize compiler-generated declarations promised by this bundle. -/
run_meta do
  for requiredName in #[
    `Wikipedia.SzemeredisTheorem.quarterIntervalResidueClass.eq_1,
    `Wikipedia.SzemeredisTheorem.untrickPrime.eq_1,
    `Wikipedia.SzemeredisTheorem.untrickedPrimeResidues.eq_1,
    `Wikipedia.SzemeredisTheorem.wTrickPrimeScale.eq_1
  ] do
    let actualName ← Lean.realizeGlobalConstNoOverloadCore requiredName
    unless actualName == requiredName do
      throwError "Generated companion resolved to an unexpected name"
Source
https://github.com/plby/lean-proofs/blob/8822f7ddef30fadbd92e1c6ab4ed897af356af5e/src/latest/Wikipedia/GreenTao/Primes/WTrickDensity.lean#L21-L147

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me