AFTD Auto-Formalizing Theoretical Domains

good_slopes_gap_three_primes_field_conditional

theoremverifiedoriginal

Let p and q be primes with p at least 5, q at least 2p−1, and 3(p+1)<2q. Suppose for each r in {p,q} that every set of r points over the r-element field with at least (r+1)/2 injective finite directions is a line. Then every non-extremal permutation modulo 3pq has at most 2(p−1)(q−2) good slopes.

Statement

theorem good_slopes_gap_three_primes_field_conditional (p q : ℕ)
    [Fact (Nat.Prime p)] [Fact (Nat.Prime q)] (hp : 5 ≤ p) (hsep : 2*p-1 ≤ q)
    (hsize : (p+1)*3 < 2*q) (hdirP : (∀ T : Finset (ZMod p × ZMod p), T.card = p →
      (∃ G : Finset (ZMod p), (p+1)/2 ≤ G.card ∧ ∀ a ∈ G, Set.InjOn (fun z : ZMod p × ZMod p => z.2 + a*z.1) T) →
      (∃ x : ZMod p, ∀ z ∈ T, z.1 = x) ∨ (∃ a t : ZMod p, ∀ z ∈ T, z.2 + a*z.1 = t))) (hdirQ : (∀ T : Finset (ZMod q × ZMod q), T.card = q →
      (∃ G : Finset (ZMod q), (q+1)/2 ≤ G.card ∧ ∀ a ∈ G, Set.InjOn (fun z : ZMod q × ZMod q => z.2 + a*z.1) T) →
      (∃ x : ZMod q, ∀ z ∈ T, z.1 = x) ∨ (∃ a t : ZMod q, ∀ z ∈ T, z.2 + a*z.1 = t)))
    (f : Equiv.Perm (ZMod (3*(p*q)))) (hf : ¬ is_extremal_perm (3*(p*q)) f)
    :
    (good_slopes (3*(p*q)) f).card ≤ 2*(p-1)*(q-2)
Related work
The general gap question is Question 10.2 of https://arxiv.org/abs/2611.04551; the assumed prime-field direction bound follows from Theorem 1.1 of https://arxiv.org/abs/2212.12823.
Verified
19 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 4
  • good_slopes_gap_three_primes_conditionalFor primes 5≤p and q≥2p−1 with 3(p+1)<2q, the conjectured gap for a nonextremal permutation modulo 3pq follows from the two finite-field…
  • good_slopes_unit_cover_squarefreeFor every nonzero squarefree modulus and permutation, some unit can be added to all its good slopes to make them units.
  • good_slopesGiven a natural number n with n ≠ 0 (via [NeZero n]) and a permutation f of ℤ/nℤ, good_slopes n f is the finite set (Finset) of elements m…
  • is_extremal_permGiven n with [NeZero n], a permutation f of ℤ/nℤ is extremal if the number of its good slopes (the cardinality of good_slopes n f) equals…

Read back from the Lean

Let $p$ and $q$ be prime numbers such that $5 \le p$, $2p - 1 \le q$, and $3(p + 1) < 2q$. Assume the following two direction/collinearity conditions: 1. (hdirP) For every subset $T \subseteq \mathbb{Z}/p\mathbb{Z} \times \mathbb{Z}/p\mathbb{Z}$ with $|T| = p$, if there exists a subset $G \subseteq \mathbb{Z}/p\mathbb{Z}$ with $|G| \ge (p + 1) / 2$ (integer division) such that for all $a \in G$, the map $(z_1, z_2) \mapsto z_2 + a z_1$ is injective on $T$, then $T$ is contained in a line (that is, either there exists $x \in \mathbb{Z}/p\mathbb{Z}$ such that $z_1 = x$ for all $z \in T$, or there exist $a, t \in \mathbb{Z}/p\mathbb{Z}$ such that $z_2 + a z_1 = t$ for all $z \in T$). 2. (hdirQ) For every subset $T \subseteq \mathbb{Z}/q\mathbb{Z} \times \mathbb{Z}/q\mathbb{Z}$ with $|T| = q$, if there exists a subset $G \subseteq \mathbb{Z}/q\mathbb{Z}$ with $|G| \ge (q + 1) / 2$ (integer division) such that for all $a \in G$, the map $(z_1, z_2) \mapsto z_2 + a z_1$ is injective on $T$, then $T$ is contained in a line (that is, either there exists $x \in \mathbb{Z}/q\mathbb{Z}$ such that $z_1 = x$ for all $z \in T$, or there exist $a, t \in \mathbb{Z}/q\mathbb{Z}$ such that $z_2 + a z_1 = t$ for all $z \in T$). Let $f$ be a permutation of $\mathbb{Z}/(3pq)\mathbb{Z}$. If $f$ is not extremal—that is, the number of good slopes of $f$ is not equal to $\varphi(3pq)$—then the number of good slopes of $f$ is at most $2(p - 1)(q - 2)$.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

The proof, explained

The proof reduces the upper bound on good slopes to `good_slopes_gap_three_primes_conditional`, which establishes the inequality under the extra hypothesis that the good slopes admit a unit-translating shift $c \in \mathbb{Z}/(3pq)$. The prime separation hypotheses imply that $3$, $p$, and $q$ are distinct primes, making their product $3pq$ squarefree. The required unit-translating shift $c$ is then obtained directly from the general lemma `good_slopes_unit_cover_squarefree` for squarefree moduli.

  1. The primes $3$, $p$, and $q$ are pairwise coprime, and $3$ is coprime to $pq$.

    Using classical logic, the primality of $p$ and $q$ is obtained from their typeclass assumptions via `Fact.out`. The inequalities $5 \le p$ and $2p - 1 \le q$ imply by linear arithmetic that $p \ne q$, $3 \ne p$, and $3 \ne q$. By `Nat.coprime_primes`, distinct primes are coprime, so $\gcd(p, q) = 1$, $\gcd(3, p) = 1$, and $\gcd(3, q) = 1$. The coprimality of $3$ with $p$ and with $q$ implies that $3$ is coprime to the product $pq$.

    lines 14–20

    uses Fact.out, Nat.coprime_primes

      classical
      have hppr : Nat.Prime p := Fact.out
      have hqpr : Nat.Prime q := Fact.out
      have hcop : Nat.Coprime p q := (Nat.coprime_primes hppr hqpr).mpr (by omega)
      have hcop3p : Nat.Coprime 3 p := (Nat.coprime_primes (by decide) hppr).mpr (by omega)
      have hcop3q : Nat.Coprime 3 q := (Nat.coprime_primes (by decide) hqpr).mpr (by omega)
      have hcop3 : Nat.Coprime 3 (p*q) := hcop3p.mul_right hcop3q
  2. The modulus $3pq$ is squarefree.

    Since $p$ and $q$ are coprime primes, each is squarefree, so their product $pq$ is squarefree by `Nat.squarefree_mul`. Since $3$ is prime (verified by computation) and coprime to $pq$, a second application of `Nat.squarefree_mul` establishes that $3pq$ is squarefree.

    lines 21–23

    uses Nat.squarefree_mul

      have hpq : Squarefree (p*q) := (Nat.squarefree_mul hcop).mpr ⟨hppr.squarefree,hqpr.squarefree⟩
      have h3 : Nat.Prime 3 := by decide
      have hsq : Squarefree (3*(p*q)) := (Nat.squarefree_mul hcop3).mpr ⟨h3.squarefree,hpq⟩
  3. There exists an element $c \in \mathbb{Z}/(3pq)$ such that $m + c$ is a unit for every good slope $m$ of $f$.

    Because $3pq$ is squarefree, applying the lemma `good_slopes_unit_cover_squarefree` yields an element $c \in \mathbb{Z}/(3pq)$ such that $m + c$ is an invertible element for every good slope $m$ of $f$.

    line 24

    uses good_slopes_unit_cover_squarefree

      obtain ⟨c,_,hc⟩ := good_slopes_unit_cover_squarefree (3*(p*q)) hsq f
  4. The number of good slopes of $f$ is at most $2(p-1)(q-2)$.

    With the unit shift $c$ provided, all hypotheses of `good_slopes_gap_three_primes_conditional` are satisfied. Applying that theorem directly yields the bound.

    line 25

    uses good_slopes_gap_three_primes_conditional

      exact good_slopes_gap_three_primes_conditional p q hp hsep hsize hdirP hdirQ f hf ⟨c,hc⟩
Fact.out
Extracts the underlying proposition $P$ from a typeclass instance of `Fact P`.
Nat.coprime_primes
Two prime natural numbers are coprime if and only if they are distinct.
Nat.squarefree_mul
For coprime natural numbers $m$ and $n$, their product $mn$ is squarefree if and only if both $m$ and $n$ are squarefree.
good_slopes_unit_cover_squarefree
For any squarefree modulus $n$ and permutation $f$ of $\mathbb{Z}/n$, there exists an element $c$ such that $m + c$ is a unit for every good slope $m$ of $f$.
good_slopes_gap_three_primes_conditional
Under the prime conditions on $p$ and $q$ and the direction hypotheses, if a non-extremal permutation $f$ modulo $3pq$ admits an element $c$ such that $m + c$ is a unit for all good slopes $m$, then $f$ has at most $2(p-1)(q-2)$ good slopes.

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

set_option maxRecDepth 10000set_option maxHeartbeats 5000000theorem good_slopes_gap_three_primes_field_conditional (p q : ℕ)    [Fact (Nat.Prime p)] [Fact (Nat.Prime q)] (hp : 5 ≤ p) (hsep : 2*p-1 ≤ q)    (hsize : (p+1)*3 < 2*q) (hdirP : (∀ T : Finset (ZMod p × ZMod p), T.card = p →      (∃ G : Finset (ZMod p), (p+1)/2 ≤ G.card ∧ ∀ a ∈ G, Set.InjOn (fun z : ZMod p × ZMod p => z.2 + a*z.1) T) →      (∃ x : ZMod p, ∀ z ∈ T, z.1 = x) ∨ (∃ a t : ZMod p, ∀ z ∈ T, z.2 + a*z.1 = t))) (hdirQ : (∀ T : Finset (ZMod q × ZMod q), T.card = q →      (∃ G : Finset (ZMod q), (q+1)/2 ≤ G.card ∧ ∀ a ∈ G, Set.InjOn (fun z : ZMod q × ZMod q => z.2 + a*z.1) T) →      (∃ x : ZMod q, ∀ z ∈ T, z.1 = x) ∨ (∃ a t : ZMod q, ∀ z ∈ T, z.2 + a*z.1 = t)))    (f : Equiv.Perm (ZMod (3*(p*q)))) (hf : ¬ is_extremal_perm (3*(p*q)) f)    :    (good_slopes (3*(p*q)) f).card ≤ 2*(p-1)*(q-2) := by  classical  have hppr : Nat.Prime p := Fact.out  have hqpr : Nat.Prime q := Fact.out  have hcop : Nat.Coprime p q := (Nat.coprime_primes hppr hqpr).mpr (by omega)  have hcop3p : Nat.Coprime 3 p := (Nat.coprime_primes (by decide) hppr).mpr (by omega)  have hcop3q : Nat.Coprime 3 q := (Nat.coprime_primes (by decide) hqpr).mpr (by omega)  have hcop3 : Nat.Coprime 3 (p*q) := hcop3p.mul_right hcop3q  have hpq : Squarefree (p*q) := (Nat.squarefree_mul hcop).mpr ⟨hppr.squarefree,hqpr.squarefree⟩  have h3 : Nat.Prime 3 := by decide  have hsq : Squarefree (3*(p*q)) := (Nat.squarefree_mul hcop3).mpr ⟨h3.squarefree,hpq⟩  obtain ⟨c,_,hc⟩ := good_slopes_unit_cover_squarefree (3*(p*q)) hsq f  exact good_slopes_gap_three_primes_conditional p q hp hsep hsize hdirP hdirQ f hf ⟨c,hc⟩
See it in the graphDiscuss this resultChallenge it