Zulip Chat Archive
Stream: general
Topic: discussion: Structure in Prime Gaps - Formalized (SPGF)
Kajani Kaunda (Aug 14 2024 at 20:14):
Announcement: Structure in Prime Gaps - Formalized (SPGF).
Let us Lean together.
I am excited to announce a collaboration project to formalize the results presented in the paper "Structure in Prime Gaps", which can be found at "Structure in Prime Gaps".
Your support and ownership will play a crucial role in helping achieve this goal. In appreciation, all contributors will be acknowledged on the project's GitHub-based website, repository, and any paper that may be published on the formalization.
Formalization has already begun with the definitions and the first Lemma. As someone new to Lean, I am actively learning through every resource available — books, videos, tools — and I’m grateful for any advice or help! I hope that Lean and the community are up to the task and will make this project a success.
Hopefully, ZULIP will be able to facilitate discussions, updates, and interactions related to the project through some channel or conversation.
For more details, updates, and to follow the progress, please visit the project website:
- Project Website: kkaunda.github.io/spgf
- GitHub Repository: GitHub Link
I would be glad to answer any questions to the best of my knowledge and ability.
I am deeply grateful to the community for their helpfulness and selflessness. Thank you for being a part of this exciting journey! Together, let us Lean towards mathematical precision!
Mario Carneiro (Aug 14 2024 at 20:31):
For some context, the paper is a preprint from the author which, in particular, claims to prove the Twin Prime Conjecture, so I definitely agree that formalization is a good next step.
Kajani Kaunda (Aug 14 2024 at 20:38):
Mario Carneiro said:
For some context, the paper is a preprint from the author which, in particular, claims to prove the Twin Prime Conjecture, so I definitely agree that formalization is a good next step.
I agree. A good next step indeed!
Notification Bot (Aug 14 2024 at 20:45):
2 messages were moved here from #announce > Structure in Prime Gaps - Formalized (SPGF) by Eric Wieser.
Notification Bot (Aug 14 2024 at 20:45):
2 messages were moved from this topic to #general > discussion: Structure in Prime Gaps - Formalized (SPGF) by Eric Wieser.
Edward van de Meent (Aug 14 2024 at 20:46):
how far along is the developement of a blueprint?
Kajani Kaunda (Aug 14 2024 at 20:50):
Edward van de Meent said:
how far along is the developement of a blueprint?
I would need some help on that! I have never done it before although I did have a look as @Patrick Massot great software ... But honestly I do not know where to start and would much rather someone more knowledgable do it!
Mario Carneiro (Aug 14 2024 at 20:51):
See #general > Tutorial: Getting Started with Blueprint-Driven Projects
Kajani Kaunda (Aug 14 2024 at 20:52):
Mario Carneiro said:
See #general > Tutorial: Getting Started with Blueprint-Driven Projects
Thank you. I will check that out!
Jeremy Tan (Aug 14 2024 at 21:10):
I feel compelled to voice my objection to formalising until the wider mathematical community has taken a look at the preprint.
I remember a tradition on the Mathematics Stack Exchange of (sometimes relentlessly) downvoting anything related to the twin prime conjecture, Goldbach conjecture and similar things
Edward van de Meent (Aug 14 2024 at 21:11):
this isn't stack exchange though
Jeremy Tan (Aug 14 2024 at 21:23):
If the authors were really confident in their result they would have put out Lean code already. The paper itself would be Lean with (traditional human)-readable explanation secondary, like Knuth's literate programming and indeed the Carleson project
Edward van de Meent (Aug 14 2024 at 21:24):
so your complaint is "there's no lean code yet"?
Edward van de Meent (Aug 14 2024 at 21:24):
as a reason as to why we shouldn't write lean code for this?
Edward van de Meent (Aug 14 2024 at 21:25):
that sounds backwards to me
Jeremy Tan (Aug 14 2024 at 21:25):
No, actually, my complaint is "no peer review yet, unlike FLT"
Jeremy Tan (Aug 14 2024 at 21:27):
Beware of mathematical cranks. I certainly don't want the final word to be that Kanuda et al. is yet another one of those
Mario Carneiro (Aug 14 2024 at 21:30):
Obviously this is a very crank-laden area, but ideally we should be able to use formalization as a way to separate the good work from bad, especially if the authors themselves are involved in doing the formalization
Mario Carneiro (Aug 14 2024 at 21:32):
It's up to the author whether they want to solicit mathematical review as well (I think they should, but I wouldn't be surprised if no one gives them the time of day) and formalization is a way to break the impasse
Jeremy Tan (Aug 14 2024 at 21:32):
The paper itself looks very cranky to me
Mario Carneiro (Aug 14 2024 at 21:33):
Be that as it may, it is not a reason to discourage people using this as a reason to learn how to use an ITP
Mario Carneiro (Aug 14 2024 at 21:34):
it's a bit warped to expect the author to already know how to use lean and have already formalized the result
Eric Wieser (Aug 14 2024 at 21:35):
I think probably the issue is the boundary between: "please help me use lean and the blueprint software", which I expect the community will happily do; and "please join me on this formalization project", which is probably a harder sell given the skepticism present here (and all the other exciting projects happening with more mathematical backing)
Ruben Van de Velde (Aug 14 2024 at 22:19):
In any case I don't think it's helpful to act so aggressively towards people coming here in good faith, even if you're convinced their results won't hold up
Notification Bot (Aug 15 2024 at 00:05):
2 messages were moved here from #announce > Structure in Prime Gaps - Formalized (SPGF) by Kim Morrison.
Kim Morrison (Aug 15 2024 at 00:06):
I moved the original message from #announce to here. After some discussion, we'd prefer the projects announced there already have at least one of:
- a blueprint
- a nontrivial Lean repo
- an existing group of collaborators
For projects like this one that are at a more preliminary stage, beginning discussions in #general or #new members suffices.
Kajani Kaunda (Aug 15 2024 at 06:42):
Kim Morrison said:
I moved the original message from #announce to here. After some discussion, we'd prefer the projects announced there already have at least one of:
- a blueprint
- a nontrivial Lean repo
- an existing group of collaborators
For projects like this one that are at a more preliminary stage, beginning discussions in #general or #new members suffices.
Thank you for the advice, Kim, it is much appreciated. Will work on these...
Pietro Monticone (Aug 15 2024 at 15:30):
Now the blueprint workflow compiles correctly (here is the project website). Previously it failed since the project GitHub page was't properly deployed from GitHub Actions.
Pietro Monticone (Aug 15 2024 at 16:14):
I have also just fixed the documentation website. Hope it helped.
Pietro Monticone (Aug 15 2024 at 16:22):
This should provide sufficient information to begin drafting the blueprint, outlining outstanding tasks, etc.
Unfortunately, I am unable to allocate time to yet another formalisation project at the moment. However, please feel free to reach out here with any questions, issues, or requests for clarification regarding how to get started, and I will do my best to assist you without too much delay.
Kajani Kaunda (Aug 15 2024 at 16:31):
Pietro Monticone said:
Now the blueprint workflow compiles correctly (here is the project website). Previously it failed since the project GitHub page was't properly deployed from GitHub Actions.
Thank you Pietro for you untiring help. It is very much appreciated.
Gareth Ma (Aug 15 2024 at 18:50):
Hi Kajani, I have a question about your proof. If I understand your Lemma 4.4 correctly, (specialising , meaning for , since that's the case we care about) you prove that there is are infinitely many prime arrays with , by showing that there are infinitely many pairs of integers such that , each of which gives rise to a distinct table (by construction from Lemma 4.3). However, it seems the proof does not prove that is a prime array. In other words, the "corners" of the table belongs might not be differences of two primes (this is needed by construction, Section 3.3). For example, for , the corners of the table (by Lemma 4.3) would be . Since is an element of your table , there must exist two primes such that . However, this is impossible for parity reasons. Am I missing something, or can you elaborate on that?
Gareth Ma (Aug 15 2024 at 18:50):
(Somewhat unrelated?) Welcome to Lean, as mentioned above I'm sure many are willing to help you learn Lean, for this project or not :D
Kajani Kaunda (Aug 16 2024 at 08:19):
Gareth Ma said:
Hi Kajani, I have a question about your proof. If I understand your Lemma 4.4 correctly, (specialising , meaning for , since that's the case we care about) you prove that there is are infinitely many prime arrays with , by showing that there are infinitely many pairs of integers such that , each of which gives rise to a distinct table (by construction from Lemma 4.3). However, it seems the proof does not prove that is a prime array. In other words, the "corners" of the table belongs might not be differences of two primes (this is needed by construction, Section 3.3). For example, for , the corners of the table (by Lemma 4.3) would be . Since is an element of your table , there must exist two primes such that . However, this is impossible for parity reasons. Am I missing something, or can you elaborate on that?
Hello Gareth,
Thank you for your question. I am composing a proper answer in a minute ...
Kajani Kaunda (Aug 16 2024 at 08:20):
I just wanted to acknowledge your question first.
Kajani Kaunda (Aug 16 2024 at 08:22):
Gareth Ma said:
(Somewhat unrelated?) Welcome to Lean, as mentioned above I'm sure many are willing to help you learn Lean, for this project or not :D
Thank you for welcoming me to Lean, I am grateful. I have a lot to learn about Lean and Mathematics!
Kajani Kaunda (Aug 16 2024 at 09:53):
Gareth Ma said:
Hi Kajani, I have a question about your proof. If I understand your Lemma 4.4 correctly, (specialising , meaning for , since that's the case we care about) you prove that there is are infinitely many prime arrays with , by showing that there are infinitely many pairs of integers such that , each of which gives rise to a distinct table (by construction from Lemma 4.3). However, it seems the proof does not prove that is a prime array. In other words, the "corners" of the table belongs might not be differences of two primes (this is needed by construction, Section 3.3). For example, for , the corners of the table (by Lemma 4.3) would be . Since is an element of your table , there must exist two primes such that . However, this is impossible for parity reasons. Am I missing something, or can you elaborate on that?
I hope my formatting of the message is correct!
Let's start with your specializing by setting .
So we have:
step 1:
5 = 6n - 1, where n = x + y.
step 2:
Maybe let us re-phrase/address the following,
"... by showing that there are infinitely many pairs of integers such that , each of which gives rise to a distinct table (by construction from Lemma 4.3)."
For , the first pair of integers in the first Prime Array would be;
(3, ) = (3, 5).
The second pair of integers in the first Prime Array would be;
So our sentence should perhaps read as follows,
"... by showing that there are infinitely many pairs of integers such that , each of which gives rise to a distinct table (by construction from Lemma 4.3)."
So here x and y are not one of the infinite pairs of integers but rather, we are using them to algebraically construct the pairs themselves.
For EXAMPLE in our case where = 5:
5 = = 6n - 1 = 6(x + y) - 1.
= (6x + 6y - 1) - 3 = 6x + 6y - 4.
= 6x + 12y - 8.
= 6x.
= 6x + 6y - 4.
Indeed your quite right, is an element of table , and there must exist two primes such that . In this example you have given, = 19 and = 3.
But for this particular Prime Array, where , the second pair of integers would be;
Now sticking to our case where , then we have n = x + y = 1.
So let us see what the tuple (the 'corners' of the Prime Array) of the first Prime Array will give us. To do that let us see what the values of , , and would be:
= ( - 3) = 2.
= ( - 3) = = 2.
= 0. See the Cayley table .
= ( + ) - = (2 + 2) - 0 = 4. See the Cayley table and Lemma 4.1.
This gives us = .
Now let us check what pairs of integers (primes) this gives us.
The first pair is constant,
(3, ) = (3, ( + 3)) = (3, 5).
The second pair is,
I hope I have not missed something myself, if I have please point it out and hopefully we will fix it!... I hope this helps.
Kajani Kaunda (Aug 16 2024 at 13:00):
Hello,
I have updated the project web page with some info. Some links, like the one to the Blueprint(Web) do not have content. But that will come soon, working on it! WIP ...
Kajani Kaunda (Aug 16 2024 at 14:40):
There has been an update to the website, which now includes images that offer a visual and intuitive explanation of the analysis. I believe these will be helpful in enhancing understanding. Thanks to @Pietro Monticone for making this possible!
Kajani Kaunda (Aug 18 2024 at 10:26):
Hello,
I am working on formalizing Lemma 4.2 which is a known result and is required in the subsequent Lemmas. Lemma 4.2 says:
All primes p > 3 can be expressed in the form 6n ± 1.
Here, it is implied that n > 0. Feel free to take on the challenge, it will be much appreciated! Will let you know if I have success myself ...
Kajani Kaunda (Aug 18 2024 at 12:08):
Hello @Gareth Ma ,
Hope you're well. Are you happy with the explanation given regarding your question? :smile:
Gareth Ma (Aug 18 2024 at 12:08):
I misread (and somehow thought there's no primes with gap 16..), good luck on your formalisation
Kajani Kaunda (Aug 18 2024 at 12:20):
Gareth Ma said:
I misread (and somehow thought there's no primes with gap 16..), good luck on your formalisation
Thank you for your kind words Gareth. have a good day.
Eric Wieser (Aug 18 2024 at 18:13):
@Kajani Kaunda, I think that lemma would be a very good one for you try to prove as a lean exercise; both because it is indeed true, and because you wrote out a detailed proof in your paper. If you make some progress and get stuck, you can post a #mwe to #new members to ask for help!
Kajani Kaunda (Aug 18 2024 at 18:18):
Eric Wieser said:
Kajani Kaunda, I think that lemma would be a very good one for you try to prove as a lean exercise; both because it is indeed true, and because you wrote out a detailed proof in your paper. If you make some progress and get stuck, you can post a #mwe to #new members to ask for help!
Thank you so much for the advice. I will certainly do that. I appreciate your encouragement. It is very likely that I will ask for help soon because I have had so many failed attempts! :smile:
Kajani Kaunda (Nov 17 2024 at 10:28):
Kajani Kaunda said:
Announcement: Structure in Prime Gaps - Formalized (SPGF).
Let us Lean together.
I am excited to announce a collaboration project to formalize the results presented in the paper "Structure in Prime Gaps", which can be found at "Structure in Prime Gaps".
Your support and ownership will play a crucial role in helping achieve this goal. In appreciation, all contributors will be acknowledged on the project's GitHub-based website, repository, and any paper that may be published on the formalization.
Formalization has already begun with the definitions and the first Lemma. As someone new to Lean, I am actively learning through every resource available — books, videos, tools — and I’m grateful for any advice or help! I hope that Lean and the community are up to the task and will make this project a success.
Hopefully, ZULIP will be able to facilitate discussions, updates, and interactions related to the project through some channel or conversation.
For more details, updates, and to follow the progress, please visit the project website:
- Project Website: kkaunda.github.io/spgf
- GitHub Repository: GitHub Link
I would be glad to answer any questions to the best of my knowledge and ability.
I am deeply grateful to the community for their helpfulness and selflessness. Thank you for being a part of this exciting journey! Together, let us Lean towards mathematical precision!
Hello good people.
I am happy to say that with a lot of help from the community, I have formalized this result, trivial yes, but important, nevertheless. Thank you.
Result: All primes greater than 3 can be expressed in the form 6n ± 1.
Please let me know if there is anything lacking in the formalization of this result. I know it's not elegant! ...
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.List.Basic
import Mathlib.Tactic.Linarith
import Mathlib.Data.Int.Defs
import Mathlib.Tactic.Basic
import Mathlib.Tactic
import Mathlib.Data.Finset.Basic
open List Nat
lemma lemma_k_0 (p : Nat) (n : Nat) (h1 : p = 6 * n) (h2 : p > 3) (h3 : 2 ∣ p) : ¬Nat.Prime p := by
match n with
| 0 =>
exfalso
omega
| 1 =>
rw [h1]
decide
| n + 2 =>
rw [h1]
apply Nat.not_prime_mul
· decide
· omega
lemma lemma_k (p : ℕ) : ∃ k n, p = 6 * n + k ∧ k ∈ (Finset.range 6 : Finset ℕ) := by
let n := p / 6
let k := p % 6
use k, n
have div_mod := Nat.div_add_mod p 6
symm at div_mod
have k_in_range : k ∈ (Finset.range 6 : Finset ℕ) := Finset.mem_range.mpr (Nat.mod_lt p (Nat.succ_pos 5))
exact ⟨div_mod, k_in_range⟩
lemma lemma_k_2 (p n : ℕ) (h : p = 6 * n + 2) (hgt3 : p > 3) : 2 ∣ p ∧ ¬ Nat.Prime p := by
have h_div2 : 2 ∣ p := by
use 3 * n + 1
rw [h]
ring
have h_prod : p = 2 * (3 * n + 1) := by
rw [h]
ring
apply And.intro h_div2
rw [h_prod]
apply Nat.not_prime_mul
· decide
·
have h_ne_one : 3 * n + 1 ≠ 1 := by
intro h_eq_one
have h_p_eq_2 : p = 2 * 1 := by rw [h_prod, h_eq_one]
rw [h_p_eq_2] at hgt3
exact Nat.lt_irrefl 2 (by linarith)
exact h_ne_one
lemma lemma_k_3 (p n : ℕ) (h : p = 6 * n + 3) (hgt3 : p > 3) : 3 ∣ p ∧ ¬ Nat.Prime p := by
have h_div3 : 3 ∣ p := by
use 2 * n + 1
rw [h]
ring
have h_prod : p = 3 * (2 * n + 1) := by
rw [h]
ring
apply And.intro h_div3
rw [h_prod]
apply Nat.not_prime_mul
· decide
·
have h_ne_one : 2 * n + 1 ≠ 1 := by
intro h_eq_one
have h_p_eq_3 : p = 3 * 1 := by rw [h_prod, h_eq_one]
rw [h_p_eq_3] at hgt3
exact Nat.lt_irrefl 3 (by linarith)
exact h_ne_one
lemma lemma_k_4 (p n : ℕ) (h : p = 6 * n + 4) (hgt3 : p > 3) : 2 ∣ p ∧ ¬ Nat.Prime p := by
have h_div2 : 2 ∣ p := by
use 3 * n + 1 + 1
rw [h]
ring
have h_prod : p = 2 * (3 * n + 1 + 1) := by
rw [h]
ring
apply And.intro h_div2
rw [h_prod]
apply Nat.not_prime_mul
· decide
·
have h_ne_one : 3 * n + 1 + 1 ≠ 1 := by
intro h_eq_one
have h_p_eq_2 : p = 2 * 1 := by rw [h_prod, h_eq_one]
rw [h_p_eq_2] at hgt3
exact Nat.lt_irrefl 2 (by linarith)
exact h_ne_one
theorem prime_form_6n_plus_1_or_6n_minus_1 (p : ℕ) (hprime : Nat.Prime p) (hgt3 : p > 3) :
∃ n, (p = 6 * n + 1 ∨ p = 6 * n - 1) := by
obtain ⟨k, n, hp, hk⟩ := lemma_k p
have hl : 0 ≤ k := Nat.zero_le k
have hu : k < 6 := Finset.mem_range.mp hk
interval_cases k using hl, hu
{
have hdiv2 : 2 ∣ p := by use 3 * n; rw [hp]; ring
have h_not_prime := lemma_k_0 p n hp hgt3 hdiv2
exact h_not_prime.elim hprime
}
{
use n
left
exact hp
}
{
have := lemma_k_2 p n hp hgt3
exact (this.2).elim hprime
}
{
have := lemma_k_3 p n hp hgt3
exact (this.2).elim hprime
}
{
have := lemma_k_4 p n hp hgt3
exact (this.2).elim hprime
}
{
use n + 1
right
rw [hp]
simp [Nat.mul_succ, Nat.add_sub_cancel]
}
Eric Wieser (Nov 17 2024 at 21:49):
Nice job on getting through that! Here's a shorter version, which leans a little more into automation:
Kajani Kaunda (Nov 19 2024 at 17:49):
Eric Wieser said:
Nice job on getting through that! Here's a shorter version, which leans a little more into automation:
Wow, you code is much more elegant - and short! Thank you so much, I am assuming I have permission to use it, yes?
Eric Wieser (Nov 19 2024 at 18:31):
Yes, feel free to use it without any attribution
Frederick Pu (Nov 19 2024 at 19:33):
hey can i take some lemmas?
Kajani Kaunda (Nov 19 2024 at 19:35):
Frederick Pu said:
hey can i take some lemmas?
Of course! That would be great! let me update you on what I am working on now...
Kajani Kaunda (Nov 19 2024 at 19:41):
Hello,
Here is the code so far!
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.List.Basic
import Mathlib.Tactic.Linarith
import Mathlib.Data.Int.Defs
import Mathlib.Tactic.Basic
import Mathlib.Data.Finset.Basic
open List Nat
-- DEFINITION 1: Cayley table for a finite portion.
def cayley_table (n : ℕ) : List (List ℤ) :=
let primes := (List.range n).filter Nat.Prime |>.map (λ p => ↑p)
let inverses := primes.map (λ p => -p)
let first_row := 0 :: primes
let table := inverses.map (λ inv => inv :: (primes.map (λ p => p + inv)))
first_row :: table
-- DEFINITION 2: Sub-array extraction.
def sub_array (n v w : ℕ) : Option (List (List ℤ)) :=
let table := cayley_table n -- Directly construct the Cayley table
let fixed_r := 2 -- Fixed starting row index
let fixed_c := 3 -- Fixed starting column index
if v < 2 ∨ w < 2 ∨ fixed_r + v > table.length ∨ fixed_c + w > (table.head?.getD []).length then
none -- Invalid dimensions
else
some ((table.drop fixed_r).take v |>.map (λ row => (row.drop fixed_c).take w))
-- DEFINITION 3: Beta structure definition.
structure Beta where
A : ℤ
B : ℤ
L : ℤ
E : ℤ
deriving Repr
-- REFINED FUNCTION: Create a Beta structure from a sub-array.
def beta (sub : Option (List (List ℤ))) : Option Beta :=
match sub with
| none => none -- No Beta structure possible
| some subArray =>
-- Extract elements from the sub-array to form the Beta structure
let A := subArray.head?.bind (λ row => row.head?) -- First element of the first row
let B := subArray.head?.bind (λ row => row.getLast?) -- Last element of the first row
let L := subArray.getLast?.bind (λ row => row.head?) -- First element of the last row
let E := subArray.getLast?.bind (λ row => row.getLast?) -- Last element of the last row
match (A, B, L, E) with
| (some a, some b, some l, some e) => some ⟨a, b, l, e⟩
| _ => none -- Sub-array does not have required dimensions
-- EXAMPLE: Create a Beta structure from a valid sub-array.
def β_example : Option Beta :=
let sub := sub_array 30 3 3 -- Extract a 3x3 sub-array from the Cayley table
beta sub -- Generate the Beta structure
#eval β_example -- Visualize the Beta structure
#eval β_example.map (λ β => β.A)
theorem prime_form_6n_plus_1_or_6n_minus_1 (p : ℕ) (hprime : Nat.Prime p) (hp : 3 < p) :
∃ n, (p = 6 * n + 1 ∨ p = 6 * n - 1) := by
suffices p % 6 = 1 ∨ p % 6 = 5 by
obtain hp | hp := this
· use p / 6
left
omega
· use (p / 6 + 1)
right
omega
have : p % 6 < 6 := Nat.mod_lt _ (by norm_num)
have : p ≠ 2 := by linarith
have : p ≠ 3 := by linarith
have : p ≠ 6 := by rintro rfl; norm_num at hprime
interval_cases hr : p % 6 <;> first | omega | (exfalso; revert hr)
· rw [← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 3) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
-- Lemma 4.3 (in the book) For every prime p ≥ 5, there exists a Beta structure such that A + 3 = p.
theorem exists_beta (p : ℕ) (hp : Nat.Prime p) (h : p ≥ 5) :
∃ β : Beta, β.A + 3 = p := by sory
Frederick Pu (Nov 19 2024 at 19:45):
so do you want me to do lemma 4.3 or does that lemma depend on a lot of other stuff
Kajani Kaunda (Nov 19 2024 at 19:47):
I am hoping the dependent stuff is already done. That is the definitions of 1. the Cayley table. 2. the Sub array derived from the Cayley table. 3. the Beta structure.
Frederick Pu (Nov 19 2024 at 19:48):
why is it p_{alpha} in the paper ?
Kajani Kaunda (Nov 19 2024 at 19:49):
Oh, just a label for a prime.
Frederick Pu (Nov 19 2024 at 19:50):
Kajani Kaunda (Nov 19 2024 at 19:50):
it could just be p.
Frederick Pu (Nov 19 2024 at 19:50):
those dont seem like the same lemma to me
Kajani Kaunda (Nov 19 2024 at 19:51):
Yes. Lemma 4.3 looked to complex for lean (and me!) So I was trying to break it down...
Kajani Kaunda (Nov 19 2024 at 19:52):
step 1. prove that for every prime p >= 5 there exists a Beta structure where A + 3 = p.
Kajani Kaunda (Nov 19 2024 at 19:53):
Once that part is done , then the rest would be easier. One could build onto the Theorem, e.g. add stuff to it like " and L = 6x" for instance.
Frederick Pu (Nov 19 2024 at 19:54):
probably dont call it lemma 4.3 then
Frederick Pu (Nov 19 2024 at 19:54):
call it like prime_eq_exists_beta_structure_add_three
Kajani Kaunda (Nov 19 2024 at 19:54):
Frederick Pu said:
probably dont call it lemma 4.3 then
Yes. Thats a good point.
Frederick Pu (Nov 19 2024 at 19:55):
generally use informative names for the more obscure lemmas
Kajani Kaunda (Nov 19 2024 at 19:55):
In the paper
Frederick Pu said:
generally use informative names for the more obscure lemmas
Good point. I will do that!
Frederick Pu (Nov 19 2024 at 19:55):
this right?
image.png
Kajani Kaunda (Nov 19 2024 at 19:56):
In the paper, Lemma 4.3 uses mostly a combinatorical
Frederick Pu said:
this right?
image.png
Yes.
Kajani Kaunda (Nov 19 2024 at 19:58):
In the paper, lemma 4.3 most uses a combinatorial method. But there is an algebraic method that is shorter.
Kajani Kaunda (Nov 19 2024 at 19:58):
...and better I suppose.
Kajani Kaunda (Nov 19 2024 at 19:59):
I will write it up and post it.
Frederick Pu (Nov 19 2024 at 20:01):
i dont know if it's my lean version, but the file only works when i import Mathlib.Tactic since intervalcases isnt in Mathlib.Tactic.Basic
Kajani Kaunda (Nov 19 2024 at 20:03):
Frederick Pu said:
i dont know if it's my lean version, but the file only works when i import Mathlib.Tactic since intervalcases isnt in Mathlib.Tactic.Basic
try testing it in the Lean 4 playground ...
Kajani Kaunda (Nov 19 2024 at 20:04):
Kajani Kaunda (Nov 19 2024 at 20:09):
for every prime p ≥ 5 there exists a Beta structure such that;
for β.A + 3 ∈ {6n − 1|n ∈ N1};
β.A = 6x + 6y − 4
β.B = 6x + 12y − 8
β.L = 6x
β.E = 6x + 6y − 4
for β.A + 3 ∈ {6n + 1|n ∈ N1};
β.A = 6x + 6y − 2
β.B = 6x + 12y − 4
β.L = 6x
β.E = 6x + 6y − 2
where n ∈ N1, x < n, y > 0, n = x + y:=
NOTES:
- The Beta structure is defined such that β.A and β.B is always on the third row of the Cayley table.
- (β.A + 3) = p is implied since all elements of the first row of the Cayley table are prime.
Kajani Kaunda (Nov 19 2024 at 20:10):
A more straightforward goal of the paper version of Lemma 4.3
Kajani Kaunda (Nov 19 2024 at 20:14):
I am writing up the algebraic version of the proof. Wil post it once I am done...
Frederick Pu (Nov 19 2024 at 20:21):
you might need to change how you define the beta structure then since rn a beta structure is jut 4 integers
Kajani Kaunda (Nov 19 2024 at 20:25):
Frederick Pu said:
you might need to change how you define the beta structure then since rn a beta structure is jut 4 integers
Oh. So here the Beta structure is supposed to hold the vertices of a sub array defined in the Cayley table. So that is why it is a 4-tuple.
Kajani Kaunda (Nov 19 2024 at 20:26):
The other elements of the sub array are not that important ...
Kajani Kaunda (Nov 19 2024 at 22:51):
Hello again good people.
@Frederick Pu, here are the notes I promised. I hope they prove useful.
Lemma/Goal:
for every prime p ≥ 5 there exists a Beta structure such that;
for β.A + 3 ∈ {6n − 1|n ∈ N1};
β.A = 6x + 6y − 4
β.B = 6x + 12y − 8
β.L = 6x
β.E = 6x + 6y − 4
for β.A + 3 ∈ {6n + 1|n ∈ N1};
β.A = 6x + 6y − 2
β.B = 6x + 12y − 4
β.L = 6x
β.E = 6x + 6y − 2
where n ∈ N1, x < n, y > 0, n = x + y :=
NOTES:
- The Beta structure is defined such that β.A and β.B are always on the third row of the Cayley table.
- (β.A + 3) = p is implied since all elements of the first row of the Cayley table are prime.
-
By construction of the Cayley table, the Sub Array & the Beta structure, β.L and β.E are
always gaps between two primes. -
Since (β.A + 3) is prime then (β.A + 3) = 6(x + y) ± 1 = 6x + 6y ± 1 = 6x + (6y ± 1).
- Notice that y > 0 therefore (6y ± 1) is prime infinitely often.
- Now again, since β.L and β.E are gaps between primes, then we can define β.L as:
β.L = (β.A + 3) - (6y ± 1)
β.L = (6x + (6y ± 1)) - (6y ± 1)
β.L = 6x
- And:
β.A = (β.A + 3) - 3
β.A = β.A
or
Now since (β.A + 3) is prime then we have
(β.A) = (6x + 6y - 1) - 3
(β.A) = 6x + 6y - 4
or
(β.A) = (6x + 6y + 1) - 3
(β.A) = 6x + 6y - 2
- So going for the low hanging fruit, we have deduced β.A and β.L.
-
Now we are claiming that β.A and β.E are gaps between two pairs of unique primes
and that β.A = β.E.
So, in the spirit of Lean, we can show that this is algebraically possible, no matter how trivial it may be. So, we have this little sketch analysis:
let p and r be prime numbers. let e be an even number such that (p + e) and (r + e) are prime. then (p - r) = (p + e) - (e + r).
In our particular case
p = β.A + 3 p + e = β.B + 3 r = 3 r + e = 6y ± 1
Why isr + e = 6y ± 1
? This is because:-
(β.A + 3) - (6y ± 1) = 6x
Remember, β.L is a gap between two primes and (β.A + 3) is prime and (6y ± 1) is prime i.o. -
But (β.A + 3) - 3 = 6x + 6y - 4 or 6x + 6y - 2
- Therefore, we need to again subtract (6y - 4) or (6y - 2) from (6x + 6y - 4) or (6x + 6y - 2) to get 6x.
- Therefore
-
r + e = 6y - 1
3 + e = 6y - 1
e = 6y - 1 - 3
e = 6y - 4
5. Now earlier we saw that (p - r) = (p + e) - (e + r).
Assuming (β.A + 3) is in the form 6n - 1 (we can perform similar analysis for when (β.A + 3) is in the form 6n + 1), this gives us the following:
(p - r) = (p + e) - (e + r)
(p - r) = (β.B + 3) - (e + 3)
(β.A + 3) - (3) = (β.B + 3) - (e + 3)
(6x + 6y - 1) - (3) =(β.B + 3) - (e + 3)
(6x + 6y - 1 - 3) = (β.B + 3) - (e + 3)
(6x + 6y - 1 - 3) = (β.B + 3) - ((6y - 4) + 3)
(6x + 6y - 1 - 3) = (β.B + 3) - (6y - 4 + 3)
(6x + 6y - 1 - 3) = β.B + 3 - 6y + 4 - 3
6x + 6y - 4 = β.B - 6y + 4
6x + 6y - 8 = β.B - 6y
6x + 12y - 8 = β.B
Substituting β.B back we get;
6x + 6y - 4 = β.B - 6y + 4
6x + 6y - 4 = (6x + 12y - 8) - (6y + 4)
6x + 6y - 4 = 6x + 12y - 8 - 6y - 4
6x + 6y - 4 = 6x + 6y - 4
Therefore (β.A) = (β.E) is existentially valid.
Notice that (β.L) and (β.E) are both on the same row, therefore they have the same subtrahend - (6y - 1). We also see that (β.B + 3) = (6x + 12y - 5) and so we have; (6x + 12y - 5) - (6y - 1) = (6x + 6y - 4) = (β.E).
6. Now we have worked out (β.A), (β.L) and (β.E). And finally, (β.B) is just:
(β.B + 3) - 3
(6x + 12y - 5) - 3 = 6x + 12y - 8.
This pen & paper algebraic proof should resolve all the goals of the original 'lemma 4.3'. Also, as earlier advised by Frederick Pu, we can give the Lean version of the lemma a more appropriate descriptive name. Thanks @Frederick Pu for that useful advice.
I thought this algebraic proof would be somewhat easier to implement in Lean than the combinatorial one used in the paper. I hope I have not missed anything, typo's, logic errors, etc. Please let me know if I have and also if anything needs more clarification or discussion. I hope this helps.
Okay, now for the Herculean (at least for me!) task of turning this algebraic analysis into Lean code!
This lemma (tentatively called "exists_beta") is implied from existing definitions, but it is still giving me a headache... :hurt:
theorem exists_beta (p : ℕ) (hp : Nat.Prime p) (h : p ≥ 5) : ∃ β : Beta, β.A + 3 = p := by sorry
Again, thank you all for your time and kind assistance. It is much appreciated!
Eric Wieser (Nov 19 2024 at 23:06):
exists_beta
is trivial, which means you surely stated it wrongly:
theorem exists_beta (p : ℕ) (hp : Nat.Prime p) (h : p ≥ 5) :
∃ β : Beta, β.A + 3 = p := by
use {A := p - 3, B := 0, L := 0, E := 0}
norm_num
Kajani Kaunda (Nov 19 2024 at 23:08):
Eric Wieser said:
exists_beta
is trivial, which means you surely stated it wrongly:theorem exists_beta (p : ℕ) (hp : Nat.Prime p) (h : p ≥ 5) : ∃ β : Beta, β.A + 3 = p := by use {A := p - 3, B := 0, L := 0, E := 0} norm_num
Nice code. Let me have a look ...
Kajani Kaunda (Nov 19 2024 at 23:24):
It certainly proves the existence of the structure Beta. This is good I can work with this. Now, all that needs to be done is to incrementally modify the lemma so that it eventually also proves that not only does the structure Beta exist but that it can be constructed for all primes p ≥ 5 - or more precisely, for all primes p ≥ 5, there exists a Beta structure such that β.A + 3 = p.
Kajani Kaunda (Nov 19 2024 at 23:38):
So, yes Frederick. You are absolutely correct in saying that we need to be more precise in stating the lemma. For example, the first two are equivalent and compile without error. But the last one fails:
theorem exists_beta (p : ℕ) (hp : Nat.Prime p) (h : p ≥ 5) :
∃ β : Beta, β.A + 3 = p := by
use {A := p - 3, B := 0, L := 0, E := 0}
norm_num
theorem exists_beta' (p : ℕ) :
∃ β : Beta, β.A + 3 = p := by
use {A := p - 3, B := 0, L := 0, E := 0}
norm_num
theorem exists_beta'' (p : ℕ) (hp : Nat.Prime p) (h : p ≥ 5) :
∃ β : Beta, (β.A + 3 = p) ∧ (p ≥ 5) := by
use {A := p - 3, B := 0, L := 0, E := 0}
norm_num
Eric Wieser (Nov 19 2024 at 23:40):
"fails" is a very strong word for "is an incomplete proof"
Eric Wieser (Nov 19 2024 at 23:40):
I think fundamentally your Beta
definition is wrong; it says "Beta is a tuple of any four integers, with no constraints whatsoever on what values they hold". Of course you can pick one of those integers to be p - 3
.
Kajani Kaunda (Nov 19 2024 at 23:41):
Eric Wieser said:
"fails" is a very strong word for "is an incomplete proof"
Well spoken!
Eric Wieser (Nov 19 2024 at 23:43):
I'd recommend following some tutorials on how structure work before proceeding further; https://leanprover-community.github.io/mathematics_in_lean/C06_Structures.html has some examples that might be helpful
Kajani Kaunda (Nov 20 2024 at 00:00):
Eric Wieser said:
I think fundamentally your
Beta
definition is wrong; it says "Beta is a tuple of any four integers, with no constraints whatsoever on what values they hold". Of course you can pick one of those integers to bep - 3
.
I agree. I have some constraints defined on sub_array
but they must be enforced or defined on the structure Beta as well. Otherwise using the structure Beta without reference tosub_array
is in-complete! Maybe I must find a way to couple the two. I will certainly read up on the notes you suggested before going any further ...! Thank you Eric.
Kajani Kaunda (Nov 24 2024 at 09:16):
Hello good people.
After heeding valuable community advice, (Eric, Frederick, et al.), here is an update. I am currently working on Theorem exists_valid_subarray_and_beta
. Your help, critique and contributions are always welcome, and I will keep you updated on any progress or changes.
import Mathlib
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.List.Basic
import Mathlib.Tactic.Linarith
import Mathlib.Data.Int.Defs
import Mathlib.Tactic.Basic
import Mathlib.Data.Finset.Basic
open List Nat
-- Define a finite portion of a Cayley table.
def cayley_table (n : ℕ) : List (List ℤ) :=
let primes := (List.range n).filter Nat.Prime |>.map (λ p => ↑p)
let inverses := primes.map (λ p => -p)
let first_row := 0 :: primes
let table := inverses.map (λ inv => inv :: (primes.map (λ p => p + inv)))
first_row :: table
-- Example of using the cayley_table with a finite portion
-- def T : List (List ℤ) := cayley_table 30
-- #eval T
-- Function to create a valid sub array
-- from a valid cayley table.
def sub_array (n start_c end_c end_r : ℕ) : Option (List (List ℤ)) :=
let table := cayley_table n
let fixed_r := 2
if start_c < 3 ∨ end_c < start_c ∨ end_r < fixed_r + 2 ∨ end_r > table.length ∨ end_c > (table.head?.getD []).length then
none
else
some ((table.drop fixed_r).take (end_r - fixed_r + 1)
|>.map (λ row => (row.drop start_c).take (end_c - start_c + 1)))
-- Example of using the sub array extraction function.
-- def sub := sub_array 30 3 6 5
-- #eval sub
-- Defne Beta structure, dependent on sub-array validity.
-- Use with the beta_from_sub_array function.
structure Beta where
A : ℤ
B : ℤ
L : ℤ
E : ℤ
isValid : Bool
-- isValid Flag to indicate validity,
-- set by creation function only
deriving Repr
-- Function to safely create a Beta structure
-- from a sub-array.
def beta_from_sub_array (sub : Option (List (List ℤ))) : Option Beta :=
match sub with
| none => none -- Sub-array invalid, no Beta structure
| some subArray =>
-- Extract elements to form the Beta structure
let A := subArray.head?.bind (λ row => row.head?)
let B := subArray.head?.bind (λ row => row.getLast?)
let L := subArray.getLast?.bind (λ row => row.head?)
let E := subArray.getLast?.bind (λ row => row.getLast?)
match (A, B, L, E) with
| (some a, some b, some l, some e) =>
-- Enforce constraints:
if (a < b ∧ a > l ∧ b > l ∧ b > e ∧ l < e ∧ a = e) then some ⟨a, b, l, e, true⟩ -- Valid Beta structure
else
none -- Fail constraints
| _ => none -- Sub-array lacks required elements
-- Theorem to prove that all primes > 3 can be expressed
-- in the form 6n ± 1.
theorem prime_form_6n_plus_1_or_6n_minus_1 (p : ℕ) (hprime : Nat.Prime p) (hp : 3 < p) :
∃ n, (p = 6 * n + 1 ∨ p = 6 * n - 1) := by
suffices p % 6 = 1 ∨ p % 6 = 5 by
obtain hp | hp := this
· use p / 6
left
omega
· use (p / 6 + 1)
right
omega
have : p % 6 < 6 := Nat.mod_lt _ (by norm_num)
have : p ≠ 2 := by linarith
have : p ≠ 3 := by linarith
have : p ≠ 6 := by rintro rfl; norm_num at hprime
interval_cases hr : p % 6 <;> first | omega | (exfalso; revert hr)
· rw [← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 3) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
-- #########################################################
-- Theorem to prove the existence of a sub array of a Cayley
-- table with specific constraints and properties.
theorem exists_valid_subarray_and_beta (p : ℕ) (hprime : Nat.Prime p) (hmin : 5 ≤ p) : ∃ (n start_c end_c end_r : ℕ)
(TT : List (List ℤ)) (β : Beta), TT = sub_array n start_c end_c end_r ∧ β = beta_from_sub_array TT ∧ β.A + 3 = p ∧
((p = 6 * x + 6 * y - 1) ∨ (p = 6 * x + 6 * y + 1)) ∧
(
((p = 6 * x + 6 * y - 1)∧(β.A = 6 * x + 6 * y - 4)∧(β.B = 6 * x + 12 * y - 8)∧(β.L = 6 * x)∧(β.E = 6 * x + 6 * y - 4))
∨
((p = 6 * x + 6 * y + 1)∧(β.A = 6 * x + 6 * y - 2)∧(β.B = 6 * x + 12 * y - 4)∧(β.L = 6 * x)∧(β.E = 6 * x + 6 * y - 2))
)
:= sorry
Eric Wieser (Nov 24 2024 at 10:08):
Instead of
structure Beta where
A : ℤ
B : ℤ
L : ℤ
E : ℤ
isValid : Bool
I recommend writing
structure Beta where
A : ℤ
B : ℤ
L : ℤ
E : ℤ
isValid : A < B ∧ A > L ∧ B > L ∧ B > E ∧ L < E ∧ A = E
which then records what validity actually means
Kajani Kaunda (Nov 24 2024 at 12:00):
Eric Wieser said:
Instead of
structure Beta where A : ℤ B : ℤ L : ℤ E : ℤ isValid : Bool
I recommend writing
structure Beta where A : ℤ B : ℤ L : ℤ E : ℤ isValid : A < B ∧ A > L ∧ B > L ∧ B > E ∧ L < E ∧ A = E
which then records what validity actually means
Oh!, okay, noted!
Kajani Kaunda (Nov 24 2024 at 17:49):
Hello,
The following is the updated code. Thanks to @Eric Wieser.
Benefits of the Change
- Strong Data Integrity:
By embedding the validation into the structure, it is impossible to create aBeta
instance without proving that it satisfies the required constraints. This eliminates the risk of invalid instances being constructed. There are many other benefits ...
import Mathlib
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.List.Basic
import Mathlib.Tactic.Linarith
import Mathlib.Data.Int.Defs
import Mathlib.Tactic.Basic
import Mathlib.Data.Finset.Basic
open List Nat
-- Define a finite portion of a Cayley table.
def cayley_table (n : ℕ) : List (List ℤ) :=
let primes := (List.range n).filter Nat.Prime |>.map (λ p => ↑p)
let inverses := primes.map (λ p => -p)
let first_row := 0 :: primes
let table := inverses.map (λ inv => inv :: (primes.map (λ p => p + inv)))
first_row :: table
-- Function to create a valid sub-array from a Cayley table.
def sub_array (n start_c end_c end_r : ℕ) : Option (List (List ℤ)) :=
let table := cayley_table n
let fixed_r := 2
if start_c < 3 ∨ end_c < start_c ∨ end_r < fixed_r + 2 ∨ end_r > table.length ∨ end_c > (table.head?.getD []).length then
none
else
some ((table.drop fixed_r).take (end_r - fixed_r + 1)
|>.map (λ row => (row.drop start_c).take (end_c - start_c + 1)))
-- Define Beta structure with explicit validity constraints.
structure Beta where
A : ℤ
B : ℤ
L : ℤ
E : ℤ
isValid : A < B ∧ A > L ∧ B > L ∧ B > E ∧ L < E ∧ A = E
deriving Repr
-- Function to create a Beta structure from a sub-array.
def beta_from_sub_array (sub : Option (List (List ℤ))) : Option Beta :=
match sub with
| none => none
| some subArray =>
let A := subArray.head?.bind (λ row => row.head?)
let B := subArray.head?.bind (λ row => row.getLast?)
let L := subArray.getLast?.bind (λ row => row.head?)
let E := subArray.getLast?.bind (λ row => row.getLast?)
match (A, B, L, E) with
| (some a, some b, some l, some e) =>
-- Check if the constraints hold
if h : a < b ∧ a > l ∧ b > l ∧ b > e ∧ l < e ∧ a = e then
some { A := a, B := b, L := l, E := e, isValid := h } -- Pass the proof `h`
else
none
| _ => none
-- Theorem to prove that all primes > 3 can be expressed
-- in the form 6n ± 1.
theorem prime_form_6n_plus_1_or_6n_minus_1 (p : ℕ) (hprime : Nat.Prime p) (hp : 3 < p) :
∃ n, (p = 6 * n + 1 ∨ p = 6 * n - 1) := by
suffices p % 6 = 1 ∨ p % 6 = 5 by
obtain hp | hp := this
· use p / 6
left
omega
· use (p / 6 + 1)
right
omega
have : p % 6 < 6 := Nat.mod_lt _ (by norm_num)
have : p ≠ 2 := by linarith
have : p ≠ 3 := by linarith
have : p ≠ 6 := by rintro rfl; norm_num at hprime
interval_cases hr : p % 6 <;> first | omega | (exfalso; revert hr)
· rw [← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 3) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
theorem exists_valid_subarray_and_beta' (p : ℕ) (hprime : Nat.Prime p) (hmin : 5 ≤ p) :
∃ (n start_c end_c end_r : ℕ) (TT : List (List ℤ)) (β : Beta),
TT = sub_array n start_c end_c end_r ∧
β = beta_from_sub_array TT ∧
β.A + 3 = p ∧
((p = 6 * x + 6 * y - 1) ∨ (p = 6 * x + 6 * y + 1)) ∧
(
((p = 6 * x + 6 * y - 1)∧(β.A = 6 * x + 6 * y - 4)∧(β.B = 6 * x + 12 * y - 8)∧(β.L = 6 * x)∧(β.E = 6 * x + 6 * y - 4))
∨
((p = 6 * x + 6 * y + 1)∧(β.A = 6 * x + 6 * y - 2)∧(β.B = 6 * x + 12 * y - 4)∧(β.L = 6 * x)∧(β.E = 6 * x + 6 * y - 2))
)
:= by
sorry
Kajani Kaunda (Nov 25 2024 at 08:29):
I have changed the hypothesis in Theorem exists_valid_subarray_and_beta
from (hmin : 5 ≤ p)
to (hmin : 3 < p)
in order to be consistent with the expression of the same hypothesis in Theorem prime_form_6n_plus_1_or_6n_minus_1
. I also thought it may make life easier down the line ...
Matt Diamond (Nov 25 2024 at 21:48):
@Kajani Kaunda In your paper you talk a lot about these arrays () in the Cayley Table, but it seems like you're mostly concerned with the four corners of the array (which you reference as , , , and ). Do the other values in the array actually matter? When you say an array "occurs infinitely often", are you talking about the specific values in the entire array or just the relationships between the corners?
Matt Diamond (Nov 25 2024 at 21:56):
I'm also wondering if there's a specific reason you're working with finite multi-dimensional lists. For example, you could define the entire Cayley Table as a two argument function like so:
import Mathlib
instance : Infinite {p | Nat.Prime p} :=
Nat.infinite_setOf_prime.to_subtype
noncomputable
def prime := Nat.Subtype.orderIsoOfNat {p | Nat.Prime p}
noncomputable
def cayley (row col : ℕ) : ℤ := prime col - prime row
Matt Diamond (Nov 25 2024 at 21:58):
that way you have a simple function prime
where prime n
allows you to refer to the nth prime number
Kajani Kaunda (Nov 25 2024 at 21:58):
Matt Diamond said:
Kajani Kaunda In your paper you talk a lot about these arrays () in the Cayley Table, but it seems like you're mostly concerned with the four corners of the array (which you reference as , , , and ). Do the other values in the array actually matter? When you say an array "occurs infinitely often", are you talking about the specific values in the entire array or just the relationships between the corners?
Hello Matt,
Thank you for the questions.
- The short answer is that in as far as the objective is concerned, no, the other values do not matter. Some deeper analysis may prove otherwise but analyzing just the "corners" is enough.
- Great question. Just the relationships between the corners.
Ruben Van de Velde (Nov 25 2024 at 22:03):
Btw, there's also Nat.nth Nat.Prime
Matt Diamond (Nov 25 2024 at 22:07):
@Ruben Van de Velde yep, that's another good option... only downside there is that you have to pass in the Set.Infinite
assumption every time you want a proof that the mapping has nice properties, whereas the OrderIso has it bundled... but not the worst thing in the world
Edit: Also you could just write a few lemmas proving all the properties up-front, so yeah, not much of a downside
Kajani Kaunda (Nov 25 2024 at 22:08):
Matt Diamond said:
I'm also wondering if there's a specific reason you're working with finite multi-dimensional lists. For example, you could define the entire Cayley Table as a two argument function like so:
import Mathlib instance : Infinite {p | Nat.Prime p} := Nat.infinite_setOf_prime.to_subtype noncomputable def prime := Nat.Subtype.orderIsoOfNat {p | Nat.Prime p} noncomputable def cayley (row col : ℕ) : ℤ := prime col - prime row
That is very noteworthy. Well, it turns out that a Cayley table being a mathematically correct structure has the added advantage of allowing us to assert certain facts which help us in our analysis. Specifically, the fact that all elements in the first row of the Cayley table are prime comes in handy in some proof especially in Lemma 4.5 I think. But if the same thing can be achieved much more easily using other definitions, then that would be a very good alternative indeed.
Kajani Kaunda (Nov 25 2024 at 22:10):
Matt Diamond said:
Ruben Van de Velde yep, that's another good option... only downside there is that you have to pass in the
Infinite
assumption every time you want a proof that the mapping has nice properties, whereas the OrderIso has it bundled... but not the worst thing in the world
My Lean is very very lean! I am far from an expert I am afraid! So I do appreciate all this great input.
Kajani Kaunda (Nov 29 2024 at 20:21):
Hello,
I am stuck on how to say things in Lean! Any help would be greatly appreciated. The theorem statement itself is okay though. This is Lemma 4.3 in the paper.
theorem exists_valid_subarray_and_beta (p : ℕ) (hprime : Nat.Prime p) (hmin : 3 < p) :
∃ (β : Beta),
(
(∃ x y : ℤ,
n = x + y ∧
x < n ∧
y > 0 ∧
↑p = 6 * (x + y) - 1 ∧
β.A = 6 * x + 6 * y - 4 ∧
β.B = 6 * x + 12 * y - 8 ∧
β.L = 6 * x ∧
β.E = 6 * x + 6 * y - 4
) ∨
(∃ x y : ℤ,
n = x + y ∧
x < n ∧
y > 0 ∧
↑p = 6 * (x + y) + 1 ∧
β.A = 6 * x + 6 * y - 2 ∧
β.B = 6 * x + 12 * y - 4 ∧
β.L = 6 * x ∧
β.E = 6 * x + 6 * y - 2
)
) := by
-- Use `prime_form_6n_plus_1_or_6n_minus_1`
-- to derive cases for p
obtain ⟨n, h⟩ := prime_form_6n_plus_1_or_6n_minus_1 p hprime hmin
cases h with
| inl h6n_minus_1 =>
-- Case: p = 6n - 1
let p := 23
let x := 2
let y := 2
let sub := sub_array 71 9 11 5 -- Example parameters
match beta_from_sub_array sub with
| none =>
exfalso
sorry
| some β =>
have valid_A : β.A = 6 * x + 6 * y - 4 := by sorry
have valid_B : β.B = 6 * x + 12 * y - 8 := by sorry
have valid_L : β.L = 6 * x := by sorry
have valid_E : β.E = 6 * x + 6 * y - 4 := by sorry
use β
left
use x, y
simp [h6n_minus_1, valid_A, valid_B, valid_L, valid_E]
sorry
| inr h6n_plus_1 =>
-- Case: p = 6n + 1
let p := 19
let x := 2
let y := 1
let sub := sub_array 71 8 9 4 -- Example parameters
match beta_from_sub_array sub with
| none =>
exfalso
sorry
| some β =>
have valid_A : β.A = 6 * x + 6 * y - 2 := by sorry
have valid_B : β.B = 6 * x + 12 * y - 4 := by sorry
have valid_L : β.L = 6 * x := by sorry
have valid_E : β.E = 6 * x + 6 * y - 2 := by sorry
use β
right
use x, y
simp [h6n_plus_1, valid_A, valid_B, valid_L, valid_E]
sorry
Kajani Kaunda (Dec 03 2024 at 20:25):
Hello friends,
Here is a quick update and a roadmap for the way forward. I will present the current state of the code base, with an update on GitHub to follow. I have included the formalization of Lemma 4.1, beta_field_sum_from_cayley
, which is an important result for certain combinatorial proofs.
Progress is being made and the project will surely complete. There may be changes as more efficient code comes to light. The good news is so far Lean is happy and if Lean is happy, we are all happy!
Thank you.
ROAD MAP
import Mathlib
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.List.Basic
import Mathlib.Tactic.Linarith
import Mathlib.Data.Int.Defs
import Mathlib.Tactic.Basic
import Mathlib.Data.Finset.Basic
import Mathlib.Tactic.ModCases
open List Nat
-- Define a finite portion of a Cayley table.
def cayley_table (n : ℕ) : List (List ℤ) :=
let primes := (List.range n).filter Nat.Prime |>.map (λ p => ↑p)
let inverses := primes.map (λ p => -p)
let first_row := 0 :: primes
let table := inverses.map (λ inv => inv :: (primes.map (λ p => p + inv)))
first_row :: table
-- Function to create a valid sub-array from a Cayley table.
def sub_array (n start_c end_c end_r : ℕ) : Option (List (List ℤ)) :=
let table := cayley_table n
let fixed_r := 2
if start_c < 3 ∨ end_c < start_c ∨ end_r < fixed_r + 2 ∨ end_r > table.length ∨ end_c > (table.head?.getD []).length then
none
else
some ((table.drop fixed_r).take (end_r - fixed_r + 1)
|>.map (λ row => (row.drop start_c).take (end_c - start_c + 1)))
-- Define Beta structure.
structure Beta where
A : ℤ
B : ℤ
L : ℤ
E : ℤ
isValid : A < B ∧ A > L ∧ B > L ∧ B > E ∧ L < E ∧ A = E
deriving Repr
def beta_from_sub_array (sub : Option (List (List ℤ))) : Option Beta :=
match sub with
| none => none
| some subArray =>
let A := subArray.head?.bind (λ row => row.head?)
let B := subArray.head?.bind (λ row => row.getLast?)
let L := subArray.getLast?.bind (λ row => row.head?)
let E := subArray.getLast?.bind (λ row => row.getLast?)
match (A, B, L, E) with
| (some a, some b, some l, some e) =>
if h : a < b ∧ a > l ∧ b > l ∧ b > e ∧ l < e ∧ a = e then
some { A := a, B := b, L := l, E := e, isValid := h }
else none
| _ => none
-- lemma 4.1
-- an important result especially for a combinatorial proof
lemma beta_field_sum_from_cayley (β : Beta) (m n c k : ℤ)
(hA : β.A = m + n)
(hB : β.B = m + (n + k))
(hL : β.L = (m + c) + n)
(hE : β.E = (m + c) + (n + k)) :
β.B + β.L = β.A + β.E := by
-- Substitute the relationships for β.A, β.B, β.L, and β.E.
rw [hA, hB, hL, hE]
-- Simplify the resulting equation.
linarith
-- lemma 4.2
-- Theorem to prove that all primes > 3 can be expressed
-- in the form 6n ± 1.
theorem prime_form_6n_plus_1_or_6n_minus_1 (p : ℕ) (hprime : Nat.Prime p) (hp : 3 < p) :
∃ n, (p = 6 * n + 1 ∨ p = 6 * n - 1) := by
suffices p % 6 = 1 ∨ p % 6 = 5 by
obtain hp | hp := this
· use p / 6
left
omega
· use (p / 6 + 1)
right
omega
have : p % 6 < 6 := Nat.mod_lt _ (by norm_num)
have : p ≠ 2 := by linarith
have : p ≠ 3 := by linarith
have : p ≠ 6 := by rintro rfl; norm_num at hprime
interval_cases hr : p % 6 <;> first | omega | (exfalso; revert hr)
· rw [← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 3) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
-- lemma 4.3
theorem exists_valid_subarray_and_beta (p : ℕ) (hprime : Nat.Prime p) (hmin : 3 < p) :
∃ (β : Beta),
(
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) - 1 ∧
β.A = 6 * x + 6 * y - 4 ∧
β.B = 6 * x + 12 * y - 8 ∧
β.L = 6 * x ∧
β.E = 6 * x + 6 * y - 4
) ∨
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) + 1 ∧
β.A = 6 * x + 6 * y - 2 ∧
β.B = 6 * x + 12 * y - 4 ∧
β.L = 6 * x ∧
β.E = 6 * x + 6 * y - 2
)
)
:= by sorry
-- lemma 4.4
theorem infinitely_many_beta_structures (p : ℕ) (hprime : Nat.Prime p) (hmin : 3 < p) :
∃ β : Beta, ∀ n : ℕ,
∃ βn : Beta,
(
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) - 1 ∧
βn.A = 6 * x + 6 * y - 4 ∧
βn.B = 6 * x + 12 * y - 8 ∧
βn.L = 6 * x ∧
βn.E = 6 * x + 6 * y - 4
) ∨
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) + 1 ∧
βn.A = 6 * x + 6 * y - 2 ∧
βn.B = 6 * x + 12 * y - 4 ∧
βn.L = 6 * x ∧
βn.E = 6 * x + 6 * y - 2
)
) := by sorry
-- lemma 4.5
theorem infinitely_many_primes_B_and_Q (p : ℕ) (hprime : Nat.Prime p) (hmin : 3 < p) :
∃ β : Beta, ∀ n : ℕ,
∃ βn : Beta,
(
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) - 1 ∧
βn.A = 6 * x + 6 * y - 4 ∧
βn.B = 6 * x + 12 * y - 8 ∧
βn.L = 6 * x ∧
βn.E = 6 * x + 6 * y - 4 ∧
Nat.Prime ((βn.B + 3).toNat) ∧
Nat.Prime (((βn.B + 3) - βn.E).toNat)
) ∨
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) + 1 ∧
βn.A = 6 * x + 6 * y - 2 ∧
βn.B = 6 * x + 12 * y - 4 ∧
βn.L = 6 * x ∧
βn.E = 6 * x + 6 * y - 2 ∧
Nat.Prime ((βn.B + 3).toNat) ∧
Nat.Prime (((βn.B + 3) - βn.E).toNat)
)
) := by sorry
-- theorem 1
theorem infinitely_many_prime_pairs (α n m : ℕ) (p : ℕ)
(hprime_p : Nat.Prime p) (hα : α ≥ 3) (hn : n ≥ 3) (hm : m ≥ 1) :
∃ (pn pn_plus_m : ℕ), Nat.Prime pn ∧ Nat.Prime pn_plus_m ∧ pn_plus_m - pn = p - 3 := by sorry
-- theorem 2
-- There exist infinitely many pairs of primes with a gap of 2.
-- We get this result when we set p = 5 in theorem infinitely_many_prime_pairs.
--
theorem twin_prime_conjecture (n m : ℕ) :
∃ (pn pn_plus_m : ℕ), Nat.Prime pn ∧ Nat.Prime pn_plus_m ∧ pn_plus_m - pn = 2 := by sorry
Eric Wieser (Dec 03 2024 at 20:31):
Your infinitely_many_beta_structures
statement doesn't ever mention β
or n
, so is surely stated incorrectly.
Kajani Kaunda (Dec 03 2024 at 20:33):
Eric Wieser said:
Your
infinitely_many_beta_structures
statement doesn't ever mentionβ
orn
, so is surely stated incorrectly.
Oh, let me check that. Thanks...
Kajani Kaunda (Dec 03 2024 at 20:48):
I think this is a better re-statement:
The original statement of infinitely_many_beta_structures
was misleading and unclear because it redundantly mentioned β and did not properly connect n to the infinite sequence of structures. The fixed version explicitly states that for each n∈N, there exists a corresponding βn-structure satisfying the necessary conditions.
This updated statement aligns better with mathematical expectations and avoids logical confusion.
Thank you Eric!
Let me know if there are more things to fix!
theorem infinitely_many_beta_structures (p : ℕ) (hprime : Nat.Prime p) (hmin : 3 < p) :
∀ n : ℕ, ∃ βn : Beta,
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) - 1 ∧
βn.A = 6 * x + 6 * y - 4 ∧
βn.B = 6 * x + 12 * y - 8 ∧
βn.L = 6 * x ∧
βn.E = 6 * x + 6 * y - 4
) ∨
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) + 1 ∧
βn.A = 6 * x + 6 * y - 2 ∧
βn.B = 6 * x + 12 * y - 4 ∧
βn.L = 6 * x ∧
βn.E = 6 * x + 6 * y - 2
) :=
by sorry
Eric Wieser (Dec 03 2024 at 21:07):
Unless your condition mentions n
, that statement is the same as saying "there exists at least one Beta
structure"
Kajani Kaunda (Dec 03 2024 at 21:09):
Eric Wieser said:
Unless your condition mentions
n
, that statement is the same as saying "there exists at least oneBeta
structure"
Ok! let me re-check... I need to fix infinitely_many_primes_B_and_Q too ...
Thanks again!
Eric Wieser (Dec 03 2024 at 21:09):
To reduce this to something without any relevance to your project;∀ n : ℕ, ∃ m : ℕ, m.Prime
does not say there are infinitely many primes m
Kajani Kaunda (Dec 03 2024 at 21:12):
Eric Wieser said:
To reduce this to something without any relevance to your project;
∀ n : ℕ, ∃ m : ℕ, m.Prime
does not say there are infinitely many primesm
mmm, I need to be more careful...
Kajani Kaunda (Dec 03 2024 at 21:24):
Since we simply want to prove the existence of infinitely many Beta structures for a given prime p > 3. So we can state the theorem like this:
theorem infinitely_many_beta_structures (p : ℕ) (hprime : Nat.Prime p) (hmin : 3 < p) :
∃ β : Beta,
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) - 1 ∧
β.A = 6 * x + 6 * y - 4 ∧
β.B = 6 * x + 12 * y - 8 ∧
β.L = 6 * x ∧
β.E = 6 * x + 6 * y - 4
) ∨
(∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
↑p = 6 * (x + y) + 1 ∧
β.A = 6 * x + 6 * y - 2 ∧
β.B = 6 * x + 12 * y - 4 ∧
β.L = 6 * x ∧
β.E = 6 * x + 6 * y - 2
)
The "infinity" comes from the fact that there are infinitely many valid x,y - pairs satisfying the given conditions, and we don’t need n to explicitly index them. Does that make sence?
Eric Wieser (Dec 03 2024 at 21:26):
No, that argument doesn't work (though your new statement is a cleaner-but-still-equally-wrong version of the old one). I encourage you to think about much simpler "infinitely many" statements to get some intuition.
Kajani Kaunda (Dec 03 2024 at 21:27):
Eric Wieser said:
No, that argument doesn't work. I encourage you to think about much simpler "infinitely many" statements to get some intuition.
Ok. Will do that ...!
Kajani Kaunda (Dec 03 2024 at 21:29):
I need to get a handle on how Lean handles infinity, infinitely many and things like that ...
Kajani Kaunda (Dec 05 2024 at 09:58):
I have been reading up on how the concept of "infinitely many" can be handled in Lean 4. I think I'm on the right track, so here is what I think might work, but I am open to further guidance:
Use of Set.Infinite
The expression Set.Infinite {β : Beta | ...}
correctly encapsulates the mathematical intention of asserting the existence of infinite entities. This means that with the given conditions, there can be infinitely many distinct Beta structures.
@Eric Wieser, what do you think?
-- lemma 4.4
theorem infinitely_many_betas_for_prime (p : ℕ) (hprime : Nat.Prime p) (hmin : 3 < p) :
Set.Infinite {β : Beta |
∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
(
(↑p = 6 * (x + y) - 1 ∧
β.A = 6 * x + 6 * y - 4 ∧ β.B = 6 * x + 12 * y - 8 ∧ β.L = 6 * x ∧ β.E = 6 * x + 6 * y - 4
) ∨
(↑p = 6 * (x + y) + 1 ∧
β.A = 6 * x + 6 * y - 2 ∧ β.B = 6 * x + 12 * y - 4 ∧ β.L = 6 * x ∧ β.E = 6 * x + 6 * y - 2
)
)
} := by sorry
Eric Wieser (Dec 05 2024 at 10:10):
Yes, that looks like a correct spelling of infiniteness
Michael Rothgang (Dec 05 2024 at 10:24):
Perhaps elaborating on the previous issue: you need to show there are infinitely many distinct beta-structures/prime pairs (not just the same one infinitely often). Set.Infinite should do this.
Kajani Kaunda (Dec 05 2024 at 10:27):
Eric Wieser said:
Yes, that looks like a correct smoking of infiniteness
Thank you so much for the guidance @Eric Wieser , @Michael Rothgang ! It is very much appreciated. Now for the harder task of implementing a Lean 4 proof... which is basically hinged on showing that we can have infinitely many values of x and y with each pair resulting into a unique Beta structure.
Eric Wieser (Dec 05 2024 at 11:14):
My initial impression is that the statement we just discussed (4.4) is either mathematically trivial or false, but is either way a good lean exercise
Eric Wieser (Dec 05 2024 at 11:15):
But I didn't think it will help at all with 4.5
Kajani Kaunda (Dec 05 2024 at 11:17):
Eric Wieser said:
But I didn't think it will help at all with 4.5
I am always curious and eager to learn, how so? Or perhaps can 4.4 and 4.5 be combined into one statement?
Kajani Kaunda (Dec 05 2024 at 11:20):
4.4 tries to prove that there are infinitely many Beta structures .. and 4.5 tries to prove that ((B+3) - E) and (B + 3) are prime in infinitely many of those Beta structures.
Kajani Kaunda (Dec 05 2024 at 11:23):
I would very much like help on the proof of 4.4 (infinitely_many_betas_for_prime) and 4.5 though. To be honest that would not be trivial for me to do in Lean 4!
Kajani Kaunda (Dec 05 2024 at 11:25):
I am new to Lean ... :blush:
Kajani Kaunda (Dec 05 2024 at 13:42):
I was thinking about your comment on whether statement 4.4 would help with 4.5. You do have a point, and I am inclined to agree with you in the sense that we could have one statement to prove both results instead of two, as follows:
theorem infinitely_many_betas_with_prime_properties (p : ℕ) (hprime : Nat.Prime p) (hmin : 3 < p) :
Set.Infinite {β : Beta |
∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
(
(↑p = 6 * (x + y) - 1 ∧
β.A = 6 * x + 6 * y - 4 ∧ β.B = 6 * x + 12 * y - 8 ∧ β.L = 6 * x ∧ β.E = 6 * x + 6 * y - 4 ∧
Nat.Prime (β.B + 3).toNat ∧ Nat.Prime ((β.B + 3) - β.E).toNat
) ∨
(↑p = 6 * (x + y) + 1 ∧
β.A = 6 * x + 6 * y - 2 ∧ β.B = 6 * x + 12 * y - 4 ∧ β.L = 6 * x ∧ β.E = 6 * x + 6 * y - 2 ∧
Nat.Prime (β.B + 3).toNat ∧ Nat.Prime ((β.B + 3) - β.E).toNat
)
)
} := by sorry
That way we achieve the following:
Efficiency: By proving additional properties within the same theorem, we avoid the need to establish the same foundational results in a separate proof, which can save time and effort.
Clarity: Including these properties directly in the statement makes it clear that we are interested in a specific subset of Beta structures that not only exist infinitely but also satisfy additional prime conditions.
Logical Cohesion: If the properties of B and E are inherently linked to the structures we are studying, it makes sense to encapsulate them together in one theorem.
The downside of course is the additional complexity of the Lean code - at least for me!
Do you think this is a better approach?
Kajani Kaunda (Dec 12 2024 at 12:05):
@Eric Wieser, I just watched your video on Defining Structures. I enjoyed it very much, thank you!
Kajani Kaunda (Dec 15 2024 at 20:57):
Hello,
A little update.
We have put a pin on theorem infinitely_many_betas_with_prime_properties. Trying a different proof strategy (thanks to some inspiration after watching a lecture video on defining Structures by @Eric Wieser):
We let the Beta structure help a little more with the heavy lifting. The idea is that by constructing (creating an instance of) the Beta structure, we implicitly prove its existence with the rest of the claims to be subsequently proved.
Creating an instance of the Beta structure is working fine. Run code to see/check. We now have a valid instance of Beta created from a valid sub array that was in turn created from a valid Cayley table.
Now I need help on the following three Lemma's. They "feel" so easy but alas I am still on my Lean 4 training wheels! As always, I am grateful to all of you for your help:
-- Lemma 1: For any valid subarray, (β.A + 3) is always prime by definition
lemma beta_A_plus_3_prime (β : Beta) : Nat.Prime (β.A + 3).toNat := by sorry
-- Lemma 2: For any valid subarray, (β.B + 3) is always prime by definition
lemma beta_B_plus_3_prime (β : Beta) : Nat.Prime (β.B + 3).toNat := by sorry
-- Lemma 3: For any valid subarray, (β.B + 3) - β.E is always prime by definition
lemma beta_B_plus_3_minus_E_prime (β : Beta) : Nat.Prime ((β.B + 3) - β.E).toNat := by sorry
Proof explanation on the claim that: (A + 3), (B + 3), (B + 3) - E are prime.
-
Top-Left Vertice: By definition, the top-left vertex of a "valid" subarray is always on the third row of the Cayley table.
-
Top-Right Vertice: Similarly, the top-right vertex of the subarray is always on the third row of the Cayley table by definition.
-
Primes from the Third Row: Adding 3 to any element in the third row of the Cayley table results in a prime number. This follows directly from the construction of the Cayley table and subarray.
-
Non-First Row/Column Elements: Any element in the Cayley table (or subarray) that is not on the first row or first column of the Cayley table is, by definition, the difference between two prime numbers.
-
Bottom-Right Element:
- In a valid subarray, the element at the bottom-right position is a difference between two prime numbers by definition.
- Let the element at the bottom-right of the subarray be β.E, and let the element at the top-right be β.B.
- Since β.B is on the third row of the Cayley table, (β.B + 3) is prime by definition.
- Moreover, (β.B + 3) is in the same column as β.E. Therefore, the difference ((β.B + 3) - β.E) is prime by definition.
Code Base
import Mathlib
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.List.Basic
import Mathlib.Tactic.Linarith
import Mathlib.Data.Int.Defs
import Mathlib.Tactic.Basic
import Mathlib.Data.Finset.Basic
import Mathlib.Tactic.ModCases
import Mathlib.Data.Set.Basic
import Mathlib.Tactic.NormNum
import Mathlib.Algebra.ModEq
import Mathlib.Order.Filter.Basic
import Mathlib.Topology.Filter
import Init.Data.Option.Basic
open List Nat
-- Define a finite portion of a Cayley table.
def cayley_table (n : ℕ) : List (List ℤ) :=
let primes := (List.range n).filter Nat.Prime |>.map (λ p => ↑p)
let inverses := primes.map (λ p => -p)
let first_row := 0 :: primes
let table := inverses.map (λ inv => inv :: (primes.map (λ p => p + inv)))
first_row :: table
#eval "valid cayley table"
def cayleytable := cayley_table 71
#eval cayleytable
-- Function to create a valid sub-array from a Cayley table.
def sub_array (n start_c end_c end_r : ℕ) : Option (List (List ℤ)) :=
let table := cayley_table n
let fixed_r := 2
if start_c < 3 ∨ end_c < start_c ∨ end_r < fixed_r + 2 ∨ end_r > table.length ∨ end_c > (table.head?.getD []).length then
none
else
some ((table.drop fixed_r).take (end_r - fixed_r + 1)
|>.map (λ row => (row.drop start_c).take (end_c - start_c + 1)))
#eval "valid sub array of a valid cayley table"
def sub := sub_array 71 9 11 5
#eval sub
-- Define Beta structure.
structure Beta where
X : ℤ
Y : ℤ
P : ℕ
A : ℤ := 6 * X + 6 * Y -
(if P = 6 * (X + Y) - 1 then 4
else if P = 6 * (X + Y) + 1 then 2
else 0)
B : ℤ := 6 * X + 12 * Y -
(if P = 6 * (X + Y) - 1 then 8
else if P = 6 * (X + Y) + 1 then 4
else 0)
L : ℤ := 6 * X
E : ℤ := A -- Since A = E by definition
isValid :
(A < B ∧ A > L ∧ B > L ∧ B > E ∧ L < E ∧ A = E ∧ X < X + Y ∧ Y > 0)
deriving Repr
def beta_from_sub_array (sub : Option (List (List ℤ))) (x y : ℤ) : Option Beta :=
match sub with
| none => none
| some subArray =>
let A := subArray.head?.bind (λ row => row.head?) -- Top-left vertex
let B := subArray.head?.bind (λ row => row.getLast?) -- Top-right vertex
let L := subArray.getLast?.bind (λ row => row.head?) -- Bottom-left vertex
let E := subArray.getLast?.bind (λ row => row.getLast?) -- Bottom-right vertex
match (A, B, L, E) with
| (some a, some b, some l, some e) =>
let P := Int.toNat (a + 3) -- Dynamically derive P
if h : (a < b ∧ a > l ∧ b > l ∧ b > e ∧ l < e ∧ a = e ∧ x < x + y ∧ y > 0)
then
some { X := x, Y := y, P := P, A := a, B := b, L := l, E := e, isValid := h}
else none
| _ => none
#eval "beta of cayley table sub array"
def beta_of_cayley_table_sub_array := beta_from_sub_array sub 2 2
#eval beta_of_cayley_table_sub_array
-- START section debug: this section has sorries!
-- Attempting to prove that A+3, B+3 and (B+3)-E are prime.
-- This claim is true by construction of the Cayley table
-- and its "valid" sub arrays.
-- Need some help here...
-- Lemma 1: For any valid subarray, (β.A + 3) is always prime by definition
lemma beta_A_plus_3_prime (β : Beta) : Nat.Prime (β.A + 3).toNat := by sorry
-- Lemma 2: For any valid subarray, (β.B + 3) is always prime by definition
lemma beta_B_plus_3_prime (β : Beta) : Nat.Prime (β.B + 3).toNat := by sorry
-- Lemma 3: For any valid subarray, (β.B + 3) - β.E is always prime by definition
lemma beta_B_plus_3_minus_E_prime (β : Beta) : Nat.Prime ((β.B + 3) - β.E).toNat := by sorry
-- END section debug:
-- lemma 4.1
-- an important result especially for a combinatorial proof
lemma beta_field_sum_from_cayley (β : Beta) (m n c k : ℤ)
(hA : β.A = m + n)
(hB : β.B = m + (n + k))
(hL : β.L = (m + c) + n)
(hE : β.E = (m + c) + (n + k)) :
β.B + β.L = β.A + β.E := by
-- Substitute the relationships for β.A, β.B, β.L, and β.E.
rw [hA, hB, hL, hE]
-- Simplify the resulting equation.
linarith
-- lemma 4.2
-- Theorem to prove that all primes > 3 can be expressed
-- in the form 6n ± 1.
theorem prime_form_6n_plus_1_or_6n_minus_1 (p : ℕ) (hprime : Nat.Prime p) (hp : 3 < p) :
∃ n, (p = 6 * n + 1 ∨ p = 6 * n - 1) := by
suffices p % 6 = 1 ∨ p % 6 = 5 by
obtain hp | hp := this
· use p / 6
left
omega
· use (p / 6 + 1)
right
omega
have : p % 6 < 6 := Nat.mod_lt _ (by norm_num)
have : p ≠ 2 := by linarith
have : p ≠ 3 := by linarith
have : p ≠ 6 := by rintro rfl; norm_num at hprime
interval_cases hr : p % 6 <;> first | omega | (exfalso; revert hr)
· rw [← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 3) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
-- Lemma 4.3, 4.4, and 4.5.
theorem infinitely_many_betas_with_prime_properties (p : ℕ) (hprime : Nat.Prime p) (hmin : 3 < p) :
Set.Infinite {β : Beta |
∃ x y : ℤ,
x < x + y ∧
y > 0 ∧
(
(↑p = 6 * (x + y) - 1 ∧
β.A = 6 * x + 6 * y - 4 ∧ β.B = 6 * x + 12 * y - 8 ∧ β.L = 6 * x ∧ β.E = 6 * x + 6 * y - 4 ∧
Nat.Prime (β.B + 3).toNat ∧ Nat.Prime ((β.B + 3) - β.E).toNat
) ∨
(↑p = 6 * (x + y) + 1 ∧
β.A = 6 * x + 6 * y - 2 ∧ β.B = 6 * x + 12 * y - 4 ∧ β.L = 6 * x ∧ β.E = 6 * x + 6 * y - 2 ∧
Nat.Prime (β.B + 3).toNat ∧ Nat.Prime ((β.B + 3) - β.E).toNat
)
)
} :=
by sorry
-- We have put a pin on this theorem, infinitely_many_betas_with_prime_properties. Trying a different
-- proof strategy: We let the Beta structure help a little more with the heavy
-- lifting. The idea is that by constructing it, we
-- implicitly prove its existence with the rest of
-- the properties to be subsequently proved...
Frederick Pu (Dec 15 2024 at 21:01):
do yu have teh informal proof for this lemma?
Kajani Kaunda (Dec 15 2024 at 21:06):
Frederick Pu said:
do yu have teh informal proof for this lemma?
Yes.
Kajani Kaunda (Dec 15 2024 at 21:08):
It basically follows from the construction of the Cayley table and the "valid" sub arrays. I have included the notes on that in the writeup above. Please let me know if you need more clarification.
Frederick Pu (Dec 15 2024 at 21:12):
it might be helpful if you sketch the proof in lean and we can try to fill in the sorries
Kajani Kaunda (Dec 15 2024 at 21:13):
Frederick Pu said:
it might be helpful if you sketch the proof in lean and we can try to fill in the sorries
That is noted. I will try to do just that!
Eric Wieser (Dec 15 2024 at 21:39):
You should also be a little careful of E := A
in structures; this does not mean "always set E to A", but rather "set E to A if not specified". If you want the former, then you actually want abbrev Beta.E (b : Beta) := b.A
.
Thankfully your isValid
means it doesn't matter for A and E, but maybe you do care for X and Y
Kajani Kaunda (Dec 16 2024 at 07:27):
Eric Wieser said:
You should also be a little careful of
E := A
in structures; this does not mean "always set E to A", but rather "set E to A if not specified". If you want the former, then you actually wantabbrev Beta.E (b : Beta) := b.A
.Thankfully your
isValid
means it doesn't matter for A and E, but maybe you do care for X and Y
Thank you, Eric, for that crucial technical clarification regarding E := A
in structures. I understand now that this approach only sets E
to A
if not explicitly specified, rather than enforcing that E
is always equal to A
.
To ensure the intended behavior and avoid potential issues, I’ve updated the structure definition to explicitly compute E
independently, even though it mirrors the computation of A
. This ensures that E
is treated as a fully independent field and avoids the ambiguity of default values. Here is the revised version:
structure Beta where
X : ℤ
Y : ℤ
P : ℕ
A : ℤ := 6 * X + 6 * Y -
(if P = 6 * (X + Y) - 1 then 4
else if P = 6 * (X + Y) + 1 then 2
else 0)
B : ℤ := 6 * X + 12 * Y -
(if P = 6 * (X + Y) - 1 then 8
else if P = 6 * (X + Y) + 1 then 4
else 0)
L : ℤ := 6 * X
E : ℤ := 6 * X + 6 * Y -
(if P = 6 * (X + Y) - 1 then 4
else if P = 6 * (X + Y) + 1 then 2
else 0)
isValid :
(A < B ∧ A > L ∧ B > L ∧ B > E ∧ L < E ∧ A = E ∧ X < X + Y ∧ Y > 0)
deriving Repr
This approach should address the concern you raised and maintain clarity in the structure's logic.
Eric Wieser (Dec 16 2024 at 07:30):
I'm not sure you fully understood my comment there; all of the :=
s are suspect there, E := A
was just the simplest one
Eric Wieser (Dec 16 2024 at 07:31):
(apologies if this is a false accusation, but the last clause of your last sentence feels slightly ChatGPT-y!)
Kajani Kaunda (Dec 16 2024 at 08:43):
Eric Wieser said:
I'm not sure you fully understood my comment there; all of the
:=
s are suspect there,E := A
was just the simplest one
No apologies needed, Eric! Your comments are all in order and much appreciated. English is not my first language so I often like checking my grammar! I also use ChatGPT as a Lean learning tool. I am trying to learn Lean as fast as I can using anything I can get my hands on, Books, Videos, the internet, ChatGPT, etc. So, in trying to understand the syntax you provided, "abbrev", etc, I asked ChatGPT which said "abbrev" would essentially render Beta.E as an Alias of Beta.A. But my intention is to have Beta.E as a separate field in its own right but with the same value as Beta.A. Then again, I am afraid ChatGPT can be wrong say on the Alias issue as an example. But assuming ChatGPT was right this time around, I thought I should simply define Beta.E in the same way I defined Beta.A. I hope this clarifies things! :smile:
Kajani Kaunda (Dec 16 2024 at 08:55):
On the ":="'s being suspect, well, I am assuming you are alluding to their theoretical truth considering that the code compiles and displays valid Beta values for A, B, L and E. So, the short answer is you can rest assured that the ":=" assignments are theoretically correct!
Ruben Van de Velde (Dec 16 2024 at 08:58):
No, the point is that you can create instances of Beta
where A
, B
, ... have any value whatsoever, not just the value you assign there
Kajani Kaunda (Dec 16 2024 at 08:59):
Oh I see...
Kajani Kaunda (Dec 16 2024 at 09:02):
I understand that. So that is why I was trying differentiate between a "Beta structure" and a "valid Beta structure". My apologies, I may not have articulated that clearly...
Kajani Kaunda (Dec 16 2024 at 09:03):
So in our case a "valid" Beta structure would be one that has been derived from a "valid" sub array of a valid Cayley table.
Kajani Kaunda (Dec 16 2024 at 09:06):
So I tried to couple the Beta structure to the function beta_from_sub_array in order to guarantee the creation of a "valid" Beta structure.
Kajani Kaunda (Dec 16 2024 at 09:07):
So, yes, Eric and Ruben, your very correct in pointing that out.
Kajani Kaunda (Dec 16 2024 at 09:10):
If the Beta structure were to be used independently, one could create an instance of it with values of A, etc that are not quite correct ... thank you for pointing that out. And once again my apologies ...
Kajani Kaunda (Dec 16 2024 at 09:10):
I hope that clarifies things!
Kajani Kaunda (Dec 16 2024 at 09:22):
Earlier, @Frederick Pu suggested that I post my work on the three Lemma's and then ask for help where I get stuck. So I will try to do. But thanks to your guidance, Eric, Ruben, Frederick et. al, I am confident that I will be doing that from a solid Lean 4 foundation. Again, I am grateful for your patience, help and input.
Jz Pan (Dec 16 2024 at 13:02):
Maybe you mean:
structure Beta where
X : ℤ
Y : ℤ
P : ℕ
A : ℤ
B : ℤ
L : ℤ
E : ℤ
hA : A = 6 * X + 6 * Y -
(if P = 6 * (X + Y) - 1 then 4
else if P = 6 * (X + Y) + 1 then 2
else 0)
hB : B = 6 * X + 12 * Y -
(if P = 6 * (X + Y) - 1 then 8
else if P = 6 * (X + Y) + 1 then 4
else 0)
hL : L = 6 * X
hE : E = 6 * X + 6 * Y -
(if P = 6 * (X + Y) - 1 then 4
else if P = 6 * (X + Y) + 1 then 2
else 0)
isValid :
(A < B ∧ A > L ∧ B > L ∧ B > E ∧ L < E ∧ A = E ∧ X < X + Y ∧ Y > 0)
deriving Repr
Kajani Kaunda (Dec 16 2024 at 13:04):
Jz Pan said:
Maybe you mean:
structure Beta where X : ℤ Y : ℤ P : ℕ A : ℤ B : ℤ L : ℤ E : ℤ hA : A = 6 * X + 6 * Y - (if P = 6 * (X + Y) - 1 then 4 else if P = 6 * (X + Y) + 1 then 2 else 0) hB : B = 6 * X + 12 * Y - (if P = 6 * (X + Y) - 1 then 8 else if P = 6 * (X + Y) + 1 then 4 else 0) hL : L = 6 * X hE : E = 6 * X + 6 * Y - (if P = 6 * (X + Y) - 1 then 4 else if P = 6 * (X + Y) + 1 then 2 else 0) isValid : (A < B ∧ A > L ∧ B > L ∧ B > E ∧ L < E ∧ A = E ∧ X < X + Y ∧ Y > 0) deriving Repr
Oh!
Eric Wieser (Dec 16 2024 at 13:05):
But this is a bit like defining a vector as
structure Vector where
X : Real
Y : Real
norm : Real
hnorm : norm = sqrt (X^2 + Y^2)
instead of
structure Vector where
X : Real
Y : Real
def Vector.norm (v : Vector) : Real :=
sqrt (v.X^2 + v.Y^2)
Eric Wieser (Dec 16 2024 at 13:05):
The second is a much more sensible interface
Kajani Kaunda (Dec 16 2024 at 13:09):
I will take what ever you say is the best way to represent this Beta structure. But perhaps I should share an image and a few notes on what inspires this Beta structure...
Kajani Kaunda (Dec 16 2024 at 13:12):
Kajani Kaunda (Dec 16 2024 at 13:17):
- The "boxes" are correct sub arrays in the Cayley table.
- The boxes with the colored vertices are the "valid" sub arrays.
- the colored vertices themselves are A, B, L and E: GREEN, ORANGE, YELLOW and BLUE
Kajani Kaunda (Dec 16 2024 at 13:18):
Example: in the first "valid" Beta structure in the diagram, L = 6 * X = 6 * 2 = 12.
Kajani Kaunda (Dec 16 2024 at 13:20):
Its a fascinating Cayley table. So what we want to do is to represent it - in Lean 4 and prove further properties related to it. Specifically the vertices of the sub arrays.
Kajani Kaunda (Dec 16 2024 at 13:22):
So now we can visually see why it's claimed that (A + 3), (B + 3) and (B + 3) - E) are prime. I hope these notes help.
Eric Wieser (Dec 16 2024 at 13:30):
I would assume you want to be storing the positions of the edges of the rectangles, not the values at those positions
Kajani Kaunda (Dec 16 2024 at 13:32):
Eric Wieser said:
I would assume you want to be storing the positions of the edges of the rectangles, not the values at those positions
Well, we would be more interested in the values.
Eric Wieser (Dec 16 2024 at 13:33):
Well, if you don't store the positions you lose the information that the grid was giving you in your table
Kajani Kaunda (Dec 16 2024 at 13:33):
For instance in the first small rectangle we would have (A, B, L, E) = (20,28,12,20)
Eric Wieser (Dec 16 2024 at 13:34):
What forces that to be a rectangle?
Kajani Kaunda (Dec 16 2024 at 13:35):
Eric Wieser said:
What forces that to be a rectangle?
Well, I would put it down to the distribution of primes ...
Kajani Kaunda (Dec 16 2024 at 13:37):
It turns out that the elements in the Cayley table are also immutable - they define gaps between primes. Its quite fascinating...!
Kajani Kaunda (Dec 16 2024 at 13:38):
That was a good question Eric...I liked it.
Kajani Kaunda (Dec 16 2024 at 13:39):
While we are on the subject, one may wonnder why or where the X and Y come from. ...
Kajani Kaunda (Dec 16 2024 at 13:40):
They allow us to algebraically define A, B, L and E.
Eric Wieser (Dec 16 2024 at 13:41):
Kajani Kaunda said:
It turns out that the elements in the Cayley table are also immutable - they define gaps between primes. Its quite fascinating...!
It is far from fascinating that table of numbers generated by subtracting two primes contains the gaps between primes.
Kajani Kaunda (Dec 16 2024 at 13:42):
The elements in the first row of the Cayley table are prime. So we can express them as 6k ± 1 or 6(x + y) ± 1. In case anyone might be wondering.
Kajani Kaunda (Dec 16 2024 at 13:53):
Eric Wieser said:
Kajani Kaunda said:
It turns out that the elements in the Cayley table are also immutable - they define gaps between primes. Its quite fascinating...!
It is far from fascinating that table of numbers generated by subtracting two primes contains the gaps between primes.
I agree. I had also wondered how a trivially constructed table could be fascinating. Until, I saw the immutable patterns it revealed. I then wondered if one could Mathematically describe them. Then I found out that one could, that for the first time one could algebraically define these gaps.
But now, what we can do is determine if Lean 4 can vouch for such a construction and it's implications. If Lean says no then I will most likely concur.
Kajani Kaunda (Dec 16 2024 at 13:54):
To that end, I am privileged and grateful to learn Lean from you all while pursuing this venture.
Kajani Kaunda (Dec 16 2024 at 13:56):
That said I have no doubts that this can be formalized in Lean. Meanwhile, has anyone attempted proving that A + 3 or B + 3 or B + 3 - E are prime in Lean?
Matt Diamond (Dec 17 2024 at 04:24):
Kajani Kaunda said:
That said I have no doubts that this can be formalized in Lean. Meanwhile, has anyone attempted proving that A + 3 or B + 3 or B + 3 - E are prime in Lean?
I'm going to sleep but here's something I threw together with my own implementation of the cayley table:
import Mathlib
def primes_set := { n | Nat.Prime n }
instance : Infinite primes_set := Nat.infinite_setOf_prime.to_subtype
instance : DecidablePred (fun n => n ∈ primes_set) := fun n => Nat.decidablePrime n
def primes (n : ℕ) : ℕ := if (n = 0) then 0 else Nat.Subtype.ofNat primes_set (n - 1)
lemma primes_zero : primes 0 = 0 := rfl
lemma primes_prime {n : ℕ} (hn : n > 0) : Nat.Prime (primes n) :=
by
unfold primes
rw [if_neg hn.ne']
exact Subtype.mem _
def cayley_table (row col : ℕ) : ℤ := primes col - primes row
structure Beta where
left_col : ℕ
width : ℕ
height : ℕ
left_col_pos : 0 < left_col
def Beta.A (β : Beta) := cayley_table 2 β.left_col
def Beta.B (β : Beta) := cayley_table 2 (β.left_col + β.width)
def Beta.L (β : Beta) := cayley_table (2 + β.height) (β.left_col)
def Beta.E (β : Beta) := cayley_table (2 + β.height) (β.left_col + β.width)
lemma primes_two_eq_three : primes 2 = 3 := by native_decide
lemma Beta.B_def (β : Beta) : β.B = cayley_table 2 (β.left_col + β.width) := rfl
lemma Beta.E_def (β : Beta) : β.E = cayley_table (2 + β.height) (β.left_col + β.width) := rfl
lemma third_row_lemma {col} (hn : 0 < col) : Nat.Prime (cayley_table 2 col + 3).natAbs :=
by
unfold cayley_table
simp [primes_two_eq_three, primes_prime hn]
example (β : Beta) : Nat.Prime (β.A + 3).natAbs := third_row_lemma β.left_col_pos
example (β : Beta) : Nat.Prime (β.B + 3).natAbs := third_row_lemma (β.left_col_pos.trans_le (Nat.le_add_right _ _))
example (β : Beta) : Nat.Prime (β.B + 3 - β.E).natAbs :=
by
rw [Beta.B_def, Beta.E_def]
unfold cayley_table
rw [primes_two_eq_three]
simp
exact primes_prime (zero_lt_two.trans_le (Nat.le_add_right _ _))
Matt Diamond (Dec 17 2024 at 04:28):
Also you had a lot of stuff in your Beta definition but I thought it was just supposed to be a rectangle in the Cayley Table so I defined it as simply as possible... apologies if I left out all the structure
Kajani Kaunda (Dec 17 2024 at 17:54):
Matt Diamond said:
Also you had a lot of stuff in your Beta definition but I thought it was just supposed to be a rectangle in the Cayley Table so I defined it as simply as possible... apologies if I left out all the structure
Thank you so much for the help. Apologies I did not see it the code soon enough. Let me have a look at it now ...
Kajani Kaunda (Dec 17 2024 at 18:59):
@Matt Diamond . I was looking at your code. Your three examples are exactly what I was looking for. The ones that prove that (A + 3), (B + 3) and (B + 3) - E are prime.
Kajani Kaunda (Dec 17 2024 at 19:02):
Now what I need to do is to express A, B, L and E in terms of X and Y. So that I can prove that infinitely often, we can have these sub arrays.
Kajani Kaunda (Dec 17 2024 at 19:07):
The idea is that as X and Y change, X + Y remains constant but B and L change, resulting in unique instances of sub arrays for every change. Hence the property of occurring infinitely often.
Matt Diamond (Dec 17 2024 at 19:10):
Isn't it obvious that these sub arrays occur infinitely often? We can just add 1 to Beta.left_col
and get a new set of coordinates
Matt Diamond (Dec 17 2024 at 19:11):
or do you need them to occur infinitely often with some kind of restriction on their coordinates?
Kajani Kaunda (Dec 17 2024 at 19:13):
Matt Diamond said:
or do you need them to occur infinitely often with some kind of restriction on their coordinates?
Well, it turns out that A, B, L and E are only valid when these specific assignments are made... nothing else is valid. Primes!
Kajani Kaunda (Dec 17 2024 at 19:14):
So A, B, L E is very much about the values of the elements in the vertices of the sub arrays
Kajani Kaunda (Dec 17 2024 at 19:14):
rather than the positions.
Matt Diamond (Dec 17 2024 at 19:14):
which specific assignments are you referring to? is the idea that you want to find values of A, B, L, and E where those values are themselves prime?
Kajani Kaunda (Dec 17 2024 at 19:15):
These is an image I posted earlier, do you see it?
Kajani Kaunda (Dec 17 2024 at 19:17):
GREEN = A; ORANGE = B; YELLOW = L; BLUE = E;
A : ℤ := 6 * X + 6 * Y -
(if P = 6 * (X + Y) - 1 then 4
else if P = 6 * (X + Y) + 1 then 2
else 0)
B : ℤ := 6 * X + 12 * Y -
(if P = 6 * (X + Y) - 1 then 8
else if P = 6 * (X + Y) + 1 then 4
else 0)
L : ℤ := 6 * X
E : ℤ := 6 * X + 6 * Y -
(if P = 6 * (X + Y) - 1 then 4
else if P = 6 * (X + Y) + 1 then 2
else 0)
Matt Diamond (Dec 17 2024 at 19:19):
are those equations valid for all A, B, L, E squares or only specific ones?
Kajani Kaunda (Dec 17 2024 at 19:19):
only specific ones.
Kajani Kaunda (Dec 17 2024 at 19:20):
the rectangles with colored vertices are the valid sub arrays.
Kajani Kaunda (Dec 17 2024 at 19:20):
so in the first one notice that: A = 20, B = 28, L = 12 E = 20
Kajani Kaunda (Dec 17 2024 at 19:22):
so there are infinitely many rectangles where those equations are valid ...
Kajani Kaunda (Dec 17 2024 at 19:22):
...and X and Y allows us to show that without needing to calculate specific numeric values.
Matt Diamond (Dec 17 2024 at 19:24):
oh, I see, thanks for clarifying
perhaps it would be useful to create a Prop or a Prop-valued class called LawfulBeta
which adds these constraints to a given Cayley subarray... I can try to write that up later today
Matt Diamond (Dec 17 2024 at 19:25):
where does P
come from?
Kajani Kaunda (Dec 17 2024 at 19:25):
Matt Diamond said:
oh, I see, thanks for clarifying
perhaps it would be useful to create a Prop or a Prop-valued class called
LawfulBeta
which adds these constraints to a given Cayley subarray... I can try to write that up later today
Ah, that would be so kind of you.
Kajani Kaunda (Dec 17 2024 at 19:26):
Matt Diamond said:
where does
P
come from?
Notice that in the image, the element in GREEN is 20. and 20 + 3 = 23. and P = 23.
Kajani Kaunda (Dec 17 2024 at 19:27):
So one constraint is that P > 3. eg For all prime P > 3 ...such sub arrays are possible.
Matt Diamond (Dec 17 2024 at 19:29):
oh I see... so P
is the prime at the top of the column, and A
is always 2 rows below it, so therefore, P = A + 3?
Kajani Kaunda (Dec 17 2024 at 19:29):
Matt Diamond said:
oh I see... so
P
is the prime at the top of the column, andA
is always 2 rows below it, so therefore, P = A + 3?
Yes! the first row of a valid sub is always on the third row of the Cayley table.
Matt Diamond (Dec 17 2024 at 19:30):
Cool... I can definitely do something with that, I'll keep you updated
Kajani Kaunda (Dec 17 2024 at 19:31):
Matt Diamond said:
Cool... I can definitely do something with that, I'll keep you updated
Thank you!!!
Kajani Kaunda (Dec 20 2024 at 10:07):
Hello,
An update on the code base, courtesy of @Matt Diamond - many thanks!
import Mathlib
def primes_set := { n | Nat.Prime n }
instance : Infinite primes_set := Nat.infinite_setOf_prime.to_subtype
instance : DecidablePred (fun n => n ∈ primes_set) := fun n => Nat.decidablePrime n
def primes (n : ℕ) : ℕ := if (n = 0) then 0 else Nat.Subtype.ofNat primes_set (n - 1)
lemma primes_zero : primes 0 = 0 := rfl
def primes_inv_exists (n : ℕ) (n_prime : Nat.Prime n) : ∃ i, primes i = n :=
by
have := Nat.Subtype.ofNat_surjective (s := primes_set)
obtain ⟨a, ha⟩ := this ⟨n, n_prime⟩
use a + 1
simp [primes, ha]
def primes_inv (n : ℕ) (n_prime : Nat.Prime n) : ℕ := Nat.find (primes_inv_exists n n_prime)
def primes_inv_def (n : ℕ) (n_prime : Nat.Prime n) : primes (primes_inv n n_prime) = n :=
Nat.find_spec (primes_inv_exists n n_prime)
lemma primes_inv_pos (n : ℕ) (n_prime : Nat.Prime n) : 0 < primes_inv n n_prime :=
by
rw [zero_lt_iff]
intro h
replace h := congrArg primes h
rw [primes_inv_def, primes_zero] at h
exact n_prime.ne_zero h
lemma primes_prime {n : ℕ} (hn : n > 0) : Nat.Prime (primes n) :=
by
unfold primes
rw [if_neg hn.ne']
exact Subtype.mem _
def cayley_table (row col : ℕ) : ℤ := primes col - primes row
lemma primes_two_eq_three : primes 2 = 3 := by native_decide
structure Beta where
P : ℕ
width : ℕ
height : ℕ
three_lt_P : 3 < P := by decide
prime_P : Nat.Prime P := by decide
def Beta.primeIndex (β : Beta) := primes_inv β.P β.prime_P
def Beta.A (β : Beta) := cayley_table 2 β.primeIndex
def Beta.B (β : Beta) := cayley_table 2 (β.primeIndex + β.width)
def Beta.L (β : Beta) := cayley_table (2 + β.height) (β.primeIndex)
def Beta.E (β : Beta) := cayley_table (2 + β.height) (β.primeIndex + β.width)
lemma Beta.primeIndexPos (β : Beta) : 0 < β.primeIndex := primes_inv_pos _ _
lemma Beta.B_def (β : Beta) : β.B = cayley_table 2 (β.primeIndex + β.width) := rfl
lemma Beta.E_def (β : Beta) : β.E = cayley_table (2 + β.height) (β.primeIndex + β.width) := rfl
lemma third_row_lemma {col} (hn : 0 < col) : Nat.Prime (cayley_table 2 col + 3).natAbs :=
by
unfold cayley_table
simp [primes_two_eq_three, primes_prime hn]
example (β : Beta) : Nat.Prime (β.A + 3).natAbs := third_row_lemma β.primeIndexPos
example (β : Beta) : Nat.Prime (β.B + 3).natAbs := third_row_lemma (β.primeIndexPos.trans_le (Nat.le_add_right _ _))
example (β : Beta) : Nat.Prime (β.B + 3 - β.E).natAbs :=
by
rw [Beta.B_def, Beta.E_def]
unfold cayley_table
rw [primes_two_eq_three]
simp
exact primes_prime (zero_lt_two.trans_le (Nat.le_add_right _ _))
-- A + E = B + L
example (β : Beta) : β.A + β.E = β.B + β.L :=
by
unfold Beta.A Beta.B Beta.L Beta.E cayley_table
ring
def Beta.isPrimeArrayWith (β : Beta) (X Y : ℕ) : Prop :=
β.A = 6 * X + 6 * Y - (
if β.P = 6 * (X + Y) - 1 then 4
else if β.P = 6 * (X + Y) + 1 then 2
else 0
) ∧
β.B = 6 * X + 12 * Y - (
if β.P = 6 * (X + Y) - 1 then 8
else if β.P = 6 * (X + Y) + 1 then 4
else 0
) ∧
β.L = 6 * X ∧
β.E = β.A
instance (β : Beta) (X Y : ℕ) : Decidable (β.isPrimeArrayWith X Y) := instDecidableAnd
def Beta.isPrimeArray (β : Beta) : Prop :=
∃ X Y, β.isPrimeArrayWith X Y
def PrimeArray : Type := { β : Beta // β.isPrimeArray }
def x : Beta := {
P := 23
width := 2
height := 3
}
#eval (x.A, x.B, x.L, x.E) -- (20, 28, 12, 20)
#eval x.isPrimeArrayWith 2 2 -- true
theorem Infinite_PrimeArray : Infinite PrimeArray := sorry
Kajani Kaunda (Dec 20 2024 at 10:15):
Hello,
A proof explanation for the theorem Infinite_PrimeArray
I thought was okay. Check it when you have a moment.
- According to the construction of the cayley table,
(B + 3)
is prime. - According to the construction of the cayley table, there are infinitely many primes
(B + 3)
. - When
P = 6(X + Y) - 1
then(B + 3) = (6X + 6Y - 1) + (6Y - 1) - 3
. -
We note that
P = (6X + 6Y - 1)
and that this implies:
For someP > 3
there are infinitely many primes(6Y - 1)
such that((6X + 6Y - 1) + (6Y - 1) - 3)
is prime. -
We know
(6Y - 1)
is prime because(B + 3) - E
is prime and(B + 3) - E = (6Y - 1)
. -
We know there are infinitely many
(6Y - 1)
because(6y - 1)
is part of the definition of(B + 3)
and by
the definition of the cayley table, there are infinitely many(B + 3)
as noted earlier in point 2. -
But
(B + 3)
can be defined exactly in terms ofX
andY
which in turn are intrinsically tied to the
definitions ofA
,B
,L
andE
- the foundational constructs of aPrimeArray
. -
Therefore
PrimeArray
s are infinite.
Note: the same analysis from points 3-8 can be made for when P = 6(X + Y) - 1
.
With a lot of help from the community I managed to come up with a proof for the well known result that:
All primes > 3 can be expressed in the form 6k ± 1
.
@Eric Wieser, many thanks to you, then offered a shorter more elegant proof which I adopted in the previous code base. I am saying this just so we remember that we already have a nice formalization of this result if needed.
Converting the above proof into Lean 4 is a challenge for me but I will give it a try...
Kajani Kaunda (Dec 20 2024 at 10:22):
I would not be surprised if a more concise proof was offered! I have quickly come to learn that the creativity of the community is boundless! Thank you.
Frederick Pu (Dec 21 2024 at 18:52):
not that isPrimeArray is a set since it maps from beta to a proposition. So you can rephrase the theorem as
theorem infinite_primearray : Set.Infinite Beta.isPrimeArray := sorry
and get rid of the PrimeArray type.
Kajani Kaunda (Dec 23 2024 at 11:08):
def x : Beta := {
P := 23
width := 2
height := 3
}
#eval x.isPrimeArrayWith 2 2 -- true
The above code works well. It constructs and verifies that x
is a valid PrimeArray
. So, I thought I could use it in an existential proof. Then I got stuck. How do I proceed?
lemma PrimeArray_exists : ∃ β : Beta, β.isPrimeArray :=
by
let x : Beta := {
P := 23,
width := 2,
height := 3
}
use x
sorry
I figured I got x, and that now all I have to do is to implement the following:
#eval x.isPrimeArrayWith 2 2
But how?
Eric Wieser (Dec 23 2024 at 11:16):
In general you can't use the result of #eval
as a proof
Eric Wieser (Dec 23 2024 at 11:17):
But in this case decide
should work
Kajani Kaunda (Dec 23 2024 at 11:17):
Eric Wieser said:
But in this case
decide
should work
Great, let me give it a try. thank you.
Kajani Kaunda (Dec 23 2024 at 11:59):
import Mathlib
def primes_set := { n | Nat.Prime n }
instance : Infinite primes_set := Nat.infinite_setOf_prime.to_subtype
instance : DecidablePred (fun n => n ∈ primes_set) := fun n => Nat.decidablePrime n
def primes (n : ℕ) : ℕ := if (n = 0) then 0 else Nat.Subtype.ofNat primes_set (n - 1)
lemma primes_zero : primes 0 = 0 := rfl
def primes_inv_exists (n : ℕ) (n_prime : Nat.Prime n) : ∃ i, primes i = n :=
by
have := Nat.Subtype.ofNat_surjective (s := primes_set)
obtain ⟨a, ha⟩ := this ⟨n, n_prime⟩
use a + 1
simp [primes, ha]
def primes_inv (n : ℕ) (n_prime : Nat.Prime n) : ℕ := Nat.find (primes_inv_exists n n_prime)
def primes_inv_def (n : ℕ) (n_prime : Nat.Prime n) : primes (primes_inv n n_prime) = n :=
Nat.find_spec (primes_inv_exists n n_prime)
lemma primes_inv_pos (n : ℕ) (n_prime : Nat.Prime n) : 0 < primes_inv n n_prime :=
by
rw [zero_lt_iff]
intro h
replace h := congrArg primes h
rw [primes_inv_def, primes_zero] at h
exact n_prime.ne_zero h
lemma primes_prime {n : ℕ} (hn : n > 0) : Nat.Prime (primes n) :=
by
unfold primes
rw [if_neg hn.ne']
exact Subtype.mem _
def cayley_table (row col : ℕ) : ℤ := primes col - primes row
lemma primes_two_eq_three : primes 2 = 3 := by native_decide
structure Beta where
P : ℕ
width : ℕ
height : ℕ
three_lt_P : 3 < P := by decide
prime_P : Nat.Prime P := by decide
def Beta.primeIndex (β : Beta) := primes_inv β.P β.prime_P
def Beta.A (β : Beta) := cayley_table 2 β.primeIndex
def Beta.B (β : Beta) := cayley_table 2 (β.primeIndex + β.width)
def Beta.L (β : Beta) := cayley_table (2 + β.height) (β.primeIndex)
def Beta.E (β : Beta) := cayley_table (2 + β.height) (β.primeIndex + β.width)
lemma Beta.primeIndexPos (β : Beta) : 0 < β.primeIndex := primes_inv_pos _ _
lemma Beta.B_def (β : Beta) : β.B = cayley_table 2 (β.primeIndex + β.width) := rfl
lemma Beta.E_def (β : Beta) : β.E = cayley_table (2 + β.height) (β.primeIndex + β.width) := rfl
lemma third_row_lemma {col} (hn : 0 < col) : Nat.Prime (cayley_table 2 col + 3).natAbs :=
by
unfold cayley_table
simp [primes_two_eq_three, primes_prime hn]
example (β : Beta) : Nat.Prime (β.A + 3).natAbs := third_row_lemma β.primeIndexPos
example (β : Beta) : Nat.Prime (β.B + 3).natAbs := third_row_lemma (β.primeIndexPos.trans_le (Nat.le_add_right _ _))
example (β : Beta) : Nat.Prime (β.B + 3 - β.E).natAbs :=
by
rw [Beta.B_def, Beta.E_def]
unfold cayley_table
rw [primes_two_eq_three]
simp
exact primes_prime (zero_lt_two.trans_le (Nat.le_add_right _ _))
-- A + E = B + L
example (β : Beta) : β.A + β.E = β.B + β.L :=
by
unfold Beta.A Beta.B Beta.L Beta.E cayley_table
ring
lemma ex1 (β : Beta) : β.A + β.E = β.B + β.L :=
by
unfold Beta.A Beta.B Beta.L Beta.E cayley_table
ring
def Beta.isPrimeArrayWith (β : Beta) (X Y : ℕ) : Prop :=
β.A = 6 * X + 6 * Y - (
if β.P = 6 * (X + Y) - 1 then 4
else if β.P = 6 * (X + Y) + 1 then 2
else 0
) ∧
β.B = 6 * X + 12 * Y - (
if β.P = 6 * (X + Y) - 1 then 8
else if β.P = 6 * (X + Y) + 1 then 4
else 0
) ∧
β.L = 6 * X ∧
β.E = β.A
instance (β : Beta) (X Y : ℕ) : Decidable (β.isPrimeArrayWith X Y) := instDecidableAnd
def Beta.isPrimeArray (β : Beta) : Prop :=
∃ X Y, β.isPrimeArrayWith X Y
def PrimeArray : Type := { β : Beta // β.isPrimeArray }
def x : Beta := {
P := 23
width := 2
height := 3
}
#eval x.isPrimeArrayWith 2 2 -- true
----------------------------
-- Now we can proceed with the existential proof
lemma PrimeArray_exists : ∃ β : Beta, β.isPrimeArray :=
by
let x : Beta := {
P := 23,
width := 2,
height := 3
}
use x
use 2
use 2
decide
----------------------------
theorem Infinite_PrimeArray' : Infinite PrimeArray := sorry
theorem infinite_primearray : Set.Infinite Beta.isPrimeArray := sorry
There is this instance that has been defined:
instance (β : Beta) (X Y : ℕ) : Decidable (β.isPrimeArrayWith X Y) := instDecidableAnd
I am not sure if I got the syntax right, but I am getting this error:
tactic 'decide' failed for proposition
{ P := 23, width := 2, height := 3, three_lt_P := ⋯, prime_P := ⋯ }.isPrimeArrayWith 2 2
since its 'Decidable' instance
instDecidableIsPrimeArrayWith { P := 23, width := 2, height := 3, three_lt_P := ⋯, prime_P := ⋯ } 2 2
did not reduce to 'isTrue' or 'isFalse'.
After unfolding the instances 'decidable_of_decidable_of_iff', 'decidable_of_iff', 'decidable_of_iff'', 'instDecidableAnd',
Kevin Buzzard (Dec 23 2024 at 12:17):
The full error:
After unfolding the instances 'decidable_of_decidable_of_iff', 'decidable_of_iff', 'decidable_of_iff'', 'instDecidableAnd', 'instDecidableEqBool', 'instDecidableEqNat', 'instDecidableIsPrimeArrayWith', 'instDecidableNot', 'instDecidablePredNatMemSetPrimes_set', 'Bool.decEq', 'Classical.propDecidable', 'Int.decEq', 'Int.instDecidableEq', 'Nat.decEq', 'Nat.decLe', 'Nat.decLt', 'Nat.decidableBallLT', 'Nat.decidableLoHi', 'Nat.decidablePrime', 'Nat.decidable_dvd' and 'Subtype.decidableLT', reduction got stuck at the 'Decidable' instance
match { P := 23, width := 2, height := 3, three_lt_P := ⋯, prime_P := ⋯ }.A,
6 * ↑2 + 6 * ↑2 -
if { P := 23, width := 2, height := 3, three_lt_P := ⋯, prime_P := ⋯ }.P = 6 * (2 + 2) - 1 then 4
else if { P := 23, width := 2, height := 3, three_lt_P := ⋯, prime_P := ⋯ }.P = 6 * (2 + 2) + 1 then 2 else 0 with
| Int.ofNat a, Int.ofNat b =>
match decEq a b with
| isTrue h => isTrue ⋯
| isFalse h => isFalse ⋯
| Int.ofNat a, Int.negSucc a_1 => isFalse ⋯
| Int.negSucc a, Int.ofNat a_1 => isFalse ⋯
| Int.negSucc a, Int.negSucc b =>
match decEq a b with
| isTrue h => isTrue ⋯
| isFalse h => isFalse ⋯
Eric Wieser (Dec 23 2024 at 12:19):
The issue is that your primes
doesn't kernel-reduce
Eric Wieser (Dec 23 2024 at 12:19):
For now you can use native_decide
, though you'll want to eliminate it eventually
Kajani Kaunda (Dec 23 2024 at 12:26):
Thank you so much. It worked!
Kajani Kaunda (Dec 23 2024 at 12:27):
Now I can move on to hopefully the last theorem:
theorem infinite_primearray : Set.Infinite Beta.isPrimeArray := sorry
Kajani Kaunda (Dec 25 2024 at 20:30):
1. Proving the Infinitude of PrimeArrays: A Theoretical Foundation for the Lean Code
Our goal is to establish that there are infinitely many PrimeArrays. The following is a theoretical basis for coding the corresponding Lean theorem Infinite_Primearray
. The argument relies on established results, particularly Dirichlet's theorem on primes in arithmetic progressions.
2. Pre-requisites for a PrimeArray
The following conditions must be satisfied for a structure to qualify as a PrimeArray:
- Prime (P > 3): A prime number greater than 3 is chosen.
-
Equations for (A, B, L, E): These equations define the relationships between the components:
-
A = 6X + 6Y - 4, if P = 6(X + Y) - 1,
A = 6X + 6Y - 2, if P = 6(X + Y) + 1
-
B = 6X + 12Y - 8, if P = 6(X + Y) - 1,
B = 6X + 12Y - 4, if P = 6(X + Y) + 1
-
L = 6X
E = A
-
-
(B + 3) is Prime: The structure is valid only if (B + 3) is also prime.
Remark: This third pre-requisite has the effect of a statement that says: "The structure is a valid PrimeArray only if it has been derived from a valid Cayley table".
3. Construction of the Formula for (B + 3)
Using the equation for (B)
, we derive (B + 3)
:
B + 3 = 6X + 12Y - k + 3
,
where (k)
depends on (P)
:
(k = 8) if ( P = 6(X + Y) - 1)
, resulting in(B + 3 = 6X + 12Y - 5)
.(k = 4) if (P = 6(X + Y) + 1)
, resulting in(B + 3 = 6X + 12Y - 1)
.
This can be expressed as:
B + 3 = 6Z + 1
,
where (Z)
is determined by (X)
and (Y)
:
(Z = X + 2Y - 1) if (P = 6(X + Y) - 1)
,(Z = X + 2Y) if (P = 6(X + Y) + 1)
.
4. Application of Dirichlet’s Theorem to (B + 3)
The derived formula (B + 3 = 6Z + 1)
represents an arithmetic progression with initial term (a = 1)
and common difference (d = 6)
.
- By Dirichlet’s theorem, since
(gcd(a, d) = 1)
, the sequence(6Z + 1)
contains infinitely many primes.
5. Implications of Dirichlet’s Theorem
From the application of Dirichlet’s theorem, we derive the following conclusions:
- Infinitely Many Primes
(B + 3)
: For any prime(P > 3)
, the value(B + 3)
is prime infinitely often. - Infinitely Many Values of
(Z)
: Since(Z)
is defined in terms of(X)
and(Y)
, infinitely many primes(B + 3)
correspond to infinitely many valid(Z)
values. - Infinitely Many Pairs
(X, Y)
: For each valid(Z)
, there exists a pair(X, Y)
that satisfies the equations for(A, B, L, E)
and ensures that(B + 3)
is prime.
6. Conclusion
The above analysis demonstrates that for any prime (P > 3)
, there are infinitely many pairs (X, Y)
that satisfy the equations for (A, B, L, E)
, ensuring (B + 3)
is prime. Thus, the structure forms a valid PrimeArray infinitely often.
We just need to have lemmas/theorems for the three points in section [5] above which would establish the three PrimeArray pre-requisites and achieve our goal.
Remark
This construction ensures that the PrimeArrays are derived from valid Cayley tables. As a result:
(A - L = B - L = 6Y ± 1)
,(6Y ± 1)
is prime by construction.
Having a solid theoretical or technical foundation is, of course, essential for any work, which is why I often write such notes to guide me as I code. That said, if I found myself hopelessly struggling with simpler goals, tackling the introduction of Dirichlet's theorem feels like a truly Herculean task! But I still have to put in the effort to learn Lean.
I just wanted to share these notes. Please let me know if there is any clarification required or things to fix. As always thank you for your help.
Kajani Kaunda (Dec 26 2024 at 11:45):
Update
Again, with a lot of help, I have the following code - an example of how one can use Dirichlet's Theorem on primes in Arithmetic Progressions. I now want to re-purpose it for our use case.
If there are any errors or areas of improvement, please let me know...
import Mathlib
-- Define a sequence of the form 6k + 1
structure ArithmeticProgression where
d : Nat -- Common difference (step)
a : Nat -- Initial term
property : Nat.gcd d a = 1
-- Example: Sequence 6k + 1
noncomputable def seq6k1 : ArithmeticProgression := {
d := 6,
a := 1,
property := by simp [Nat.gcd_comm, Nat.gcd_mul_left, Nat.gcd_one_right] }
-- State Dirichlet's theorem for arithmetic progressions
axiom Dirichlet (d a : Nat) (h : Nat.gcd d a = 1) :
Set.Infinite { n | Nat.Prime n ∧ ∃ k : Nat, n = a + d * k }
-- Use Dirichlet's theorem to show primes are infinite in 6k + 1
lemma primes_in_6k1_infinite :
Set.Infinite { p | Nat.Prime p ∧ ∃ k : Nat, p = seq6k1.a + seq6k1.d * k } :=
Dirichlet seq6k1.d seq6k1.a seq6k1.property
Kevin Buzzard (Dec 26 2024 at 12:05):
Probably your axiom is wrong (didn't check but a=1 and d=0 looks suspicious). You don't need Dirichlet to prove this, there are tricks for 1 mod 6 and more generally for 1 mod d>0 which I think we have in mathlib
Johan Commelin (Dec 26 2024 at 12:10):
We also have Dirichlet in mathlib...
Michael Stoll (Dec 26 2024 at 14:01):
See Nat.setOf_prime_and_eq_mod_infinite and Nat.forall_exists_prime_gt_and_eq_mod.
Kajani Kaunda (Dec 26 2024 at 15:47):
I am thrilled with the above input from all of you, thank you.
@Kevin Buzzard , it is great to know that there are other ways to do this!
@Johan Commelin , also good to know that Dirichlet is formalized in Mathlib!
@Michael Stoll , I will check out these tactics now!
So, what is the consensus on the easiest way to go about this?
Meanwhile, I did the following this afternoon - will have to re-check it though as per Kevin's note:
import Mathlib
-- Dirichlet's Theorem ...
-- Define a sequence of the form 6k + 1
structure ArithmeticProgression where
d : Nat -- Common difference (step)
a : Nat -- Initial term
property : Nat.gcd d a = 1
-- Example: Sequence 6k + 1
noncomputable def seq6k1 : ArithmeticProgression := {
d := 6,
a := 1,
property := by simp [Nat.gcd_comm, Nat.gcd_mul_left, Nat.gcd_one_right] }
-- State Dirichlet's theorem for arithmetic progressions
axiom Dirichlet (d a : Nat) (h : Nat.gcd d a = 1) :
Set.Infinite { n | Nat.Prime n ∧ ∃ k : Nat, n = a + d * k
}
-- Use Dirichlet's theorem to show primes are infinite in 6k + 1
lemma primes_in_6k1_infinite :
Set.Infinite { p | Nat.Prime p ∧ ∃ k : Nat, p = seq6k1.a + seq6k1.d * k } :=
Dirichlet seq6k1.d seq6k1.a seq6k1.property
-- Define B + 3 for when P = 6 * Z - 1 and P = 6 * Z + 1
def B_with_minus_1 (X Y : ℕ) : ℕ := X + 2 * Y - 1
def B_with_plus_1 (X Y : ℕ) : ℕ := X + 2 * Y
lemma primes_in_B_minus_1_infinite :
Set.Infinite { p | Nat.Prime p ∧ ∃ B_with_minus_1 : Nat, p = seq6k1.a + seq6k1.d * B_with_minus_1 } :=
Dirichlet seq6k1.d seq6k1.a seq6k1.property
lemma primes_in_B_plus_1_infinite :
Set.Infinite { p | Nat.Prime p ∧ ∃ B_with_plus_1 : Nat, p = seq6k1.a + seq6k1.d * B_with_plus_1 } :=
Dirichlet seq6k1.d seq6k1.a seq6k1.property
Frederick Pu (Dec 26 2024 at 16:28):
u dont need to make it an axiom tho, you can just prove it using Nat.setOf_prime_and_eq_mod_infinite like @Michael Stoll said
Kajani Kaunda (Dec 26 2024 at 16:46):
Frederick Pu said:
u dont need to make it an axiom tho, you can just prove it using Nat.setOf_prime_and_eq_mod_infinite like Michael Stoll said
Oh!, yes! This is all good news! Thank you so much.
Kajani Kaunda (Dec 26 2024 at 16:48):
I guess doing it this way is easier and preferable, then we will not need to use Dirichlet just like Kevin said ...
Frederick Pu (Dec 26 2024 at 16:48):
yeah but every axiom you introduce is a potential liability in your proof
Kajani Kaunda (Dec 26 2024 at 16:49):
Frederick Pu said:
yeah but every axiom you introduce is a potential liability in your proof
Ok, we must avoid those as much as possible. All the more reason not to use axioms!
Kajani Kaunda (Dec 26 2024 at 16:53):
Oh, just reading... So Nat.setOf_prime_and_eq_mod_infinite, is a formulation of Dirichlet! Cool. So we can use it and avoid axioms!
Frederick Pu (Dec 26 2024 at 16:55):
yes it's almost syntactically the exact same as the version of direchlet you're using
Kajani Kaunda (Dec 26 2024 at 16:55):
ok...
Kajani Kaunda (Dec 26 2024 at 16:55):
Kevin mentioned other tricks ..
Kajani Kaunda (Dec 26 2024 at 16:57):
@Frederick Pu would you know the alternative methods Kevin mentioned?
Kajani Kaunda (Dec 26 2024 at 17:00):
meanwhile, let me try re-writting these two lemmas on B + 3 using Nat.setOf_prime_and_eq_mod_infinite ... and get rid of the axiom.
Frederick Pu (Dec 26 2024 at 17:05):
he might be talking about using bezout's lemma or something
Kajani Kaunda (Dec 26 2024 at 17:07):
Frederick Pu said:
he might be talking about using bezout's lemma or something
Ah, an interesting lemma indeed ... Ok.
Kajani Kaunda (Dec 27 2024 at 12:14):
Update
Keeping it simple. The goal remains to show that PrimeArrays occur infinitely often by demonstrating that a constructed structure satisfying the following conditions is necessarily a PrimeArray and occurs infinitely often:
- Infinitely Many Primes
(B + 3)
: For any prime(P > 3)
, the value(B + 3)
is prime infinitely often. - Infinitely Many Values of
(Z)
: Since(Z)
is defined in terms of(X)
and(Y)
, infinitely many primes(B + 3)
correspond to infinitely many valid(Z)
values such that for each valid(Z)
, there exists a pair(X, Y)
that satisfies the equations for(A, B, L, E)
.
The Plan
-
Check the Form of
(B + 3)
:- Demonstrate that
(B + 3)
falls into the forms(6k + 1)
or(6k - 1)
modulo 6. -
This is guaranteed from the formulas for
(A)
,(B)
,(L)
, and(E)
.When
P
is in the form6k - 1
;
B = 6X + 12Y - 8
B + 3 = 6X + 12Y - 5
B + 3 = 6X + 12Y - 6 + 1
B + 3 = 6(X + 2Y - 1) + 1
When P is in the form
6k + 1
;
B = 6X + 12Y - 4
B + 3 = 6X + 12Y - 1
B + 3 = 6(X + 2Y) - 1
- Demonstrate that
-
Show
(B + 3) > 3
:- Ensure that
(B + 3)
satisfies the condition for the existing theorem to apply. - Since
(A + 3) < (B + 3)
and(A + 3) = P
(with(P > 3)
), it follows that(B + 3) > 3
.
- Ensure that
-
Leverage the Infinite Primality of
(6k + 1)
or(6k - 1)
:- Use or adapt
prime_form_6n_plus_1_or_6n_minus_1
to confirm that numbers of these forms (greater than 3) are prime infinitely often.
- Use or adapt
We already have the following elegant formalization, thanks to @Eric Wieser
theorem prime_form_6n_plus_1_or_6n_minus_1 (p : ℕ) (hprime : Nat.Prime p) (hp : 3 < p) :
∃ n, (p = 6 * n + 1 ∨ p = 6 * n - 1) := by
suffices p % 6 = 1 ∨ p % 6 = 5 by
obtain hp | hp := this
· use p / 6
left
omega
· use (p / 6 + 1)
right
omega
have : p % 6 < 6 := Nat.mod_lt _ (by norm_num)
have : p ≠ 2 := by linarith
have : p ≠ 3 := by linarith
have : p ≠ 6 := by rintro rfl; norm_num at hprime
interval_cases hr : p % 6 <;> first | omega | (exfalso; revert hr)
· rw [← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 3) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
I think this is a simpler approach.
Kajani Kaunda (Dec 27 2024 at 12:22):
Okay, let me now try to implement this in Lean...
Kajani Kaunda (Dec 29 2024 at 21:14):
These notes compliment previous notes. Please comment if any clarifications are needed, it would be very helpful
Theoretical Foundation for Proving Infinitely Many PrimeArrays
Overview:
The goal is to establish an injective mapping between unique values of (B + 3)
(proven to occur infinitely often as primes) and unique Beta structures satisfying the predicate isPrimeArray
. This proves that the existence of infinitely many (B + 3)
implies the existence of infinitely many PrimeArray structures.
Argument Refinement:
-
Infinite Primes in the Form
(B + 3)
:(B + 3)
is derived from the Beta structure through the formulas forA, B, L, E
.- Using the known result that all primes > 3 are in the form
6Z ± 1
, and since(B + 3) > 3
and satisfies this form, it follows that(B + 3)
occurs infinitely often as primes.
-
Dependency on
(X, Y)
:- Each
(B + 3)
is uniquely determined by(X, Y)
, which are variables in the formulas defining(A, B, L, E)
within the Beta structure.
- Each
-
Uniqueness of
(A, B, L, E)
:- The formulas for
(A, B, L, E)
are derived uniquely from(X, Y)
and the prime(P)
associated with the Beta structure.
- The formulas for
-
Link to
(B + 3)
:- Each unique set of values
(A, B, L, E)
corresponds to a unique(B + 3)
. Thus, every unique(B + 3)
implies a unique Beta structure satisfyingisPrimeArray
.
- Each unique set of values
-
Injective Mapping:
- The mapping from
(B + 3)
to Beta structures is injective. Hence, the infinitude of primes(B + 3)
implies the infinitude of Beta structures.
- The mapping from
-
PrimeArray Definition:
- A PrimeArray is a Beta structure that satisfies
isPrimeArray
. Hence, the existence of infinitely many Beta structures implies infinitely many PrimeArray structures.
Next Steps:
Formalization in Lean - Theorems and Lemmas:
- A PrimeArray is a Beta structure that satisfies
- Lemma 1: Prove that
(B + 3)
occurs infinitely often as prime numbers. - Lemma 2: Define and prove the injective mapping between
(B + 3)
and Beta structures satisfyingisPrimeArray
. - Theorem: Demonstrate that the infinite occurrence of
(B + 3)
directly implies the infinitude of PrimeArray structures leveraging Lemma 2.
Kajani Kaunda (Jan 24 2025 at 13:47):
Today is my birthday.
Kajani Kaunda (Jan 24 2025 at 13:48):
I have an update.
Kajani Kaunda (Jan 30 2025 at 08:51):
Kajani Kaunda said:
Today is my birthday.
Thank you for the Cake!, it's much appreciated! :heart:
Kajani Kaunda (Jan 30 2025 at 08:54):
I am also grateful to you all for everything as I learn Lean. An awesome community!
Update.
Kajani Kaunda (Jan 30 2025 at 08:54):
Structure in prime gaps - formalized.
Abstract
These notes serve as a foundation for formalizing key results from the paper Structure in Prime Gaps using Lean 4. The primary results to be formalized are:
-
Existence of Infinitely Many Prime Pairs
There exist infinitely many pairs of primes (, ) such that - = - 3, where n, α ≥ 3, m ≥ 1, and is the prime. -
Special Case
The result when = 5 is also considered as an implied corollary.
These results highlight a novel approach to understanding the structure within prime gaps and provide a framework for their formal verification in Lean 4.
Acknowledgments section
Many thanks to the incredible Zulip Lean Community for their invaluable help, generosity, time, and Lean code in making this a true community effort.
Introduction section
The purpose of these notes is to provide a constructive proof of the results we aim to formalize, tailored to be well-suited for implementation in Lean 4.
Fortunately, the proof primarily relies on elementary algebraic analysis, avoiding the need for advanced mathematical techniques.
To achieve this, we present an equivalent statement that leads to the same conclusions as those in the original paper:
For every prime = 6x + 6y ± 1, there exist infinitely many integers y > 0 such that 6x + 6y ± 1, 6y ± 1, and (6x + 6y ± 1) + (6y ± 1) - 3 are simultaneously prime, where x < x + y.
We prove this by treating y as an infinitely recurring quantity. Using a Cayley table of a commutative partial groupoid of primes and their additive inverses, we construct integers A, B, L, and E for infinitely many y, such that:
- (A + 3),
- (B + 3),
- (B + 3) - E
are simultaneously prime.
It is worth noting that the algebraic analysis presented here provides an existential proof, independent of numeric constraints that might otherwise limit its application to successive values of y.
As this effort is part of a public initiative, it is my hope that the community finds this approach both agreeable and a practical solution for formalizing the stated results.
Remark: the integers A, B, L, E are actually vertices of a sub array in our Cayley table.
Preliminary definitions & results section
Definition 1.
Cayley_definition: We define a Cayley table based on a Commutative Partial Groupoid of primes and their additive inverses.
This definition has already been formalized in Lean 4.
Cayley table T extract of a commutative partial groupoid
+ 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
-2 0 1 3 5 9 11 15 17 21 27 29 35 39 41 45 51 57 59 65 69
-3 -1 0 2 4 8 10 14 16 20 26 28 34 38 40 44 50 56 58 64 68
-5 -3 -2 0 2 6 8 12 14 18 24 26 32 36 38 42 48 54 56 62 66
-7 -5 -4 -2 0 4 6 10 12 16 22 24 30 34 36 40 46 52 54 60 64
-11 -9 -8 -6 -4 0 2 6 8 12 18 20 26 30 32 36 42 48 50 56 60
-13 -11 -10 -8 -6 -2 0 4 6 10 16 18 24 28 30 34 40 46 48 54 58
-17 -15 -14 -12 -10 -6 -4 0 2 6 12 14 20 24 26 30 36 42 44 50 54
-19 -17 -16 -14 -12 -8 -6 -2 0 4 10 12 18 22 24 28 34 40 42 48 52
-23 -21 -20 -18 -16 -12 -10 -6 -4 0 6 8 14 18 20 24 30 36 38 44 48
-29 -27 -26 -24 -22 -18 -16 -12 -10 -6 0 2 8 12 14 18 24 30 32 38 42
-31 -29 -28 -26 -24 -20 -18 -14 -12 -8 -2 0 6 10 12 16 22 28 30 36 40
-37 -35 -34 -32 -30 -26 -24 -20 -18 -14 -8 -6 0 4 6 10 16 22 24 30 34
-41 -39 -38 -36 -34 -30 -28 -24 -22 -18 -12 -10 -4 0 2 6 12 18 20 26 30
-43 -41 -40 -38 -36 -32 -30 -26 -24 -20 -14 -12 -6 -2 0 4 10 16 18 24 28
-47 -45 -44 -42 -40 -36 -34 -30 -28 -24 -18 -16 -10 -6 -4 0 6 12 14 20 24
-53 -51 -50 -48 -46 -42 -40 -36 -34 -30 -24 -22 -16 -12 -10 -6 0 6 8 14 18
-59 -57 -56 -54 -52 -48 -46 -42 -40 -36 -30 -28 -22 -18 -16 -12 -6 0 2 8 12
Definition 2.
Able_relationships: a result defining the relationships between the vertices (A, B, L, E) of a sub array of the cayley table:
A + E = B + L.
This result has already been formalized in Lean 4.
Result 1.
prime_form_6n_plus_1_or_6n_minus_1: All primes > 3 can be expressed in the form (6k ± 1).
This result has already been formalized in Lean 4.
Kajani Kaunda (Jan 30 2025 at 08:55):
Analysis notes section
Generally, it is important and helpful that any formalization effort be based on and preceded by logical justifications. The analysis notes in this section provide that.
Start analysis
-
Let be an integer.
This is given as a hypothesis. -
> 3.
This is given as a hypothesis. -
Let be prime.
This is given as a hypothesis. -
Let y > 0.
With y ∈ ℕ as defined in the theorem statement. -
Let k > 0.
We use k as a fixed constant such that 6k ± 1 = . -
Let x + y = k.
-
Let x < k.
The value of k remains constant for infinitely many values of y. -
Let = (6 * k - 1) ∨ = (6 * k + 1).
This is proven by prime_form_6n_plus_1_or_6n_minus_1.
This also allows us to work with the forms: = 6x + 6y ± 1. -
Define a sub array Subarray_1 of a Cayley table with the vertices, ((A + 3), (B + 3), l, e), such that;
(A + 3) = .
(B + 3) = a prime on the first row of the Cayley table.
l = (A + 3) - (A + 3).
e = (B + 3) + l - (A + 3).
Note that the construction of our Cayley table rendersl
ande
as differences between two primes. This coupled with the result able_relationships allows us to formulate the equations forl
ande
asl = (A + 3) - (A + 3)
ande = (B + 3) + l - (A + 3)
.
- If = 6x + 6y - 1 then
- Construct A:
- Let A = - 3.
- Construct E:
-
Let
(A + 3) - 3 = (6x + 6y - 1) - 3
A = 6x + 6y - 4 -
By able_relationships,
Let e = ((B + 3) + l - (A + 3))
e = ((B + 3) + 0 - (A + 3))
e = ((B + 3) - (6x + 6y - 1))
e = (B + 3 - 6x - 6y + 1)
e = (B + 4 - 6x - 6y) -
Re-arranging the terms of the last equation we get;
e = B + 4 - 6x - 6y
6x + 6y - 4 = B - e
B - e = 6x + 6y - 4 -
Let E = 6x + 6y - 4
- Show that A = E:
-
Let B - e = E
But A = 6x + 6y - 4
Therefore;
A = E
and also B - e = A. -
Construct B:
-
Show that B - A = B - E
This is true because A = E and B - e = E and B - e = A. -
Show that B - E = A - L
By able_relationships and L necessarily exists by construction of the Cayley table. -
Show that ((A + 3) - L) = prime.
This is true because (A + 3) is prime andL
is a difference between primes, by Cayley table. -
Show that the sub-expression of (A + 3), "(6y - 1)", is prime infinitely often.
Because of prime_form_6n_plus_1_or_6n_minus_1.
Remark:
Notice that for infinitely many values of y such that (6y - 1) is prime, remains constant because x + y = k.
Whenever the value of y increases, x decreases correspondingly so that the equation x + y = k is satisfied always.
Notice also that by choosing the sub-expression (6y - 1) of , we imply that the value of y in the prime number (6y - 1)
is the same as the value of y used in the definition of where = 6x + 6y - 1. -
Show that therefore since ((A + 3) - L) is prime then it can be represented by the form: (6y - 1).
In other words, since ((A + 3) - L) is prime then there will always be a y such that ((A + 3) - L) = (6y - 1). -
Let A + 3 - L = 6y - 1
A + 3 - L - 3 = 6y - 1 - 3
A - L = 6y - 4
But A - L = B - E = B - A = e. Therefore e = 6y - 4 -
Show that (B + 3) - (A + 3) = e - 0.
Again, by able_relationships.
Therefore (A + 3) + e = (B + 3)
Therefore (A + 3) + (6y - 4) = (B + 3)
(6x + 6y - 1) + (6y - 4) = (B + 3)
6x + 6y - 1 + 6y - 4 = B + 3
6x + 12y - 5 = B + 3
6x + 12y - 8 = B
B = 6x + 12y - 8
Remark:
Notice that given a sub array in a Cayley table with the vertices (A, B, L, E), (B + 3) is prime. If it were not then that would introduce contradictions in the definition and construction of the Cayley table. -
Construct L:
-
L = A + E - B.
By able_relationships. Therefore,
L = (6x + 6y - 4) + (6x + 6y - 4) - (6x + 12y - 8)
L = 6x + 6y - 4 + 6x + 6y - 4 - 6x - 12y + 8
L = 6x
and of course notice that (A + 3) and (6y - 1) are prime and that;
L = (A + 3) - (6y - 1)
L = (6x + (6y - 1)) - (6y - 1)
L = 6x + 6y - 1 - 6y + 1
L = 6x -
Show that for some given prime = (6x + 6y - 1) > 3 we can construct, infinitely often, a sub array of the Cayley table
with the vertices (A, B, L, E) such that (A + 3), (B + 3) and (((B + 3) - E) or ((A + 3) - L)) are simultaneously prime.
This is due to the fact that we can repeat this analysis for infinitely many values of y.
- else If = 6x + 6y - 1 then
-
Let
(A + 3) - 3 = (6x + 6y + 1) - 3
A = 6x + 6y - 2 -
By able_relationships,
Let e = ((B + 3) + l - (A + 3))
e = ((B + 3) + 0 - (A + 3))
e = ((B + 3) - (6x + 6y + 1))
e = (B + 3 - 6x - 6y - 1)
e = (B + 2 - 6x - 6y) -
Re-arranging the terms of the last equation we get;
e = B + 2 - 6x - 6y
6x + 6y - 2 = B - e
B - e = 6x + 6y - 2 -
Let E = 6x + 6y - 2
- Show that A = E:
-
Let B - e = E
But A = 6x + 6y - 2
Therefore;
A = E
and also B - e = A. -
Construct B:
-
Show that B - A = B - E
Because A = E and B - e = E and B - e = A. -
Show that B - E = A - L
By able_relationships and L exists by construction of the Cayley table. -
Show that ((A + 3) - L) = prime.
Because (A + 3) is prime and L is a difference between primes, by Cayley table. -
Show that the sub-expression of (A + 3), "(6y + 1)", is prime infinitely often.
Because of prime_form_6n_plus_1_or_6n_minus_1.
Remark:
Notice that for infinitely many values of y such that (6y + 1) is prime, remains constant because x + y = k.
Whenever the value of y increases, x decreases correspondingly so that the equation x + y = k is satisfied always.
Notice also that by choosing the sub-expression (6y + 1) of , we imply that the value of y in the prime number (6y + 1)
is the same as the value of y used in the definition of where = 6x + 6y + 1. -
Show that therefore since ((A + 3) - L) is prime then it can be represented by the form: (6y + 1).
In other words, since ((A + 3) - L) is prime then there will always be a y such that ((A + 3) - L) = (6y + 1). -
Let A + 3 - L = 6y + 1
A + 3 - L - 3 = 6y + 1 - 3
A - L = 6y - 2
But A - L = B - E = B - A = e. Therefore e = 6y - 2 -
Show that (B + 3) - (A + 3) = e - 0.
Again, by able_relationships.
Therefore (A + 3) + e = (B + 3)
Therefore (A + 3) + (6y - 2) = (B + 3)
(6x + 6y + 1) + (6y - 2) = (B + 3)
6x + 6y + 1 + 6y - 2 = B + 3
6x + 12y - 1 = B + 3
6x + 12y - 4 = B
B = 6x + 12y - 4
Remark:
Notice that given a sub array in a Cayley table with the vertices (A, B, L, E), (B + 3) is prime. If it were not then that would introduce contradictions in the definition and construction of the Cayley table. -
Construct L:
-
L = A + E - B.
By able_relationships. Therefore,
L = (6x + 6y - 2) + (6x + 6y - 2) - (6x + 12y - 4)
L = 6x + 6y - 2 + 6x + 6y - 2 - 6x - 12y + 4
L = 6x
and of course notice that (A + 3) and (6y + 1) are prime and that;
L = (A + 3) - (6y + 1)
L = (6x + (6y + 1)) - (6y + 1)
L = 6x + 6y + 1 - 6y - 1
L = 6x -
Show that for some given prime = (6x + 6y + 1) > 3 we can construct, infinitely often, a sub array of the Cayley table
with the vertices (A, B, L, E) such that (A + 3), (B + 3) and (((B + 3) - E) or ((A + 3) - L)) are simultaneously prime.
This is due to the fact that we can repeat this analysis for infinitely many values of y.
Kajani Kaunda (Jan 30 2025 at 08:55):
Lean 4 code section
In light of the analysis provided, we have the following Lean 4 code being developed:
There are likely to be many changes to it though!
Lean 4 formalization: infinitely_many_y_exist_for_primes
import Mathlib
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Order.Filter.AtTopBot
import Mathlib.Topology.Algebra.FilterBasis
import Mathlib.Order.Filter.Basic
import Mathlib.Tactic
--
theorem prime_form_6n_plus_1_or_6n_minus_1 (p : ℕ) (hprime : Nat.Prime p) (hp : 3 < p) :
∃ n, (p = 6 * n + 1 ∨ p = 6 * n - 1) := by
suffices p % 6 = 1 ∨ p % 6 = 5 by
obtain hp | hp := this
· use p / 6
left
omega
· use (p / 6 + 1)
right
omega
have : p % 6 < 6 := Nat.mod_lt _ (by norm_num)
have : p ≠ 2 := by linarith
have : p ≠ 3 := by linarith
have : p ≠ 6 := by rintro rfl; norm_num at hprime
interval_cases hr : p % 6 <;> first | omega | (exfalso; revert hr)
· rw [← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 3) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
· refine ne_of_apply_ne (· % 2) ?_
dsimp
rw [Nat.mod_mod_of_dvd _ (by norm_num), ← Nat.dvd_iff_mod_eq_zero, Nat.dvd_prime hprime]
aesop
--
def primes_set := { n | Nat.Prime n }
instance : Infinite primes_set := Nat.infinite_setOf_prime.to_subtype
instance : DecidablePred (fun n => n ∈ primes_set) := fun n => Nat.decidablePrime n
def primes (n : ℕ) : ℕ := if (n = 0) then 0 else Nat.Subtype.ofNat primes_set (n - 1)
lemma primes_zero : primes 0 = 0 := rfl
def primes_inv_exists (n : ℕ) (n_prime : Nat.Prime n) : ∃ i, primes i = n :=
by
have := Nat.Subtype.ofNat_surjective (s := primes_set)
obtain ⟨a, ha⟩ := this ⟨n, n_prime⟩
use a + 1
simp [primes, ha]
def primes_inv (n : ℕ) (n_prime : Nat.Prime n) : ℕ := Nat.find (primes_inv_exists n n_prime)
def primes_inv_def (n : ℕ) (n_prime : Nat.Prime n) : primes (primes_inv n n_prime) = n :=
Nat.find_spec (primes_inv_exists n n_prime)
lemma primes_inv_pos (n : ℕ) (n_prime : Nat.Prime n) : 0 < primes_inv n n_prime :=
by
rw [zero_lt_iff]
intro h
replace h := congrArg primes h
rw [primes_inv_def, primes_zero] at h
exact n_prime.ne_zero h
lemma primes_prime {n : ℕ} (hn : n > 0) : Nat.Prime (primes n) :=
by
unfold primes
rw [if_neg hn.ne']
exact Subtype.mem _
def cayley_table (row col : ℕ) : ℤ := primes col - primes row
lemma primes_two_eq_three : primes 2 = 3 := by native_decide
structure Beta where
P : ℕ
width : ℕ
height : ℕ
three_lt_P : 3 < P := by decide
prime_P : Nat.Prime P := by decide
def Beta.primeIndex (β : Beta) := primes_inv β.P β.prime_P
def Beta.A (β : Beta) := cayley_table 2 β.primeIndex
def Beta.B (β : Beta) := cayley_table 2 (β.primeIndex + β.width)
def Beta.L (β : Beta) := cayley_table (2 + β.height) (β.primeIndex)
def Beta.E (β : Beta) := cayley_table (2 + β.height) (β.primeIndex + β.width)
lemma Beta.primeIndexPos (β : Beta) : 0 < β.primeIndex := primes_inv_pos _ _
lemma Beta.B_def (β : Beta) : β.B = cayley_table 2 (β.primeIndex + β.width) := rfl
lemma Beta.E_def (β : Beta) : β.E = cayley_table (2 + β.height) (β.primeIndex + β.width) := rfl
lemma third_row_lemma {col} (hn : 0 < col) : Nat.Prime (cayley_table 2 col + 3).natAbs :=
by
unfold cayley_table
simp [primes_two_eq_three, primes_prime hn]
lemma A_plus_three_is_prime (β : Beta) : Nat.Prime (β.A + 3).natAbs := third_row_lemma β.primeIndexPos
lemma B_plus_three_is_prime (β : Beta) : Nat.Prime (β.B + 3).natAbs := third_row_lemma (β.primeIndexPos.trans_le (Nat.le_add_right _ _))
lemma B_plus_three_minus_E (β : Beta) : Nat.Prime (β.B + 3 - β.E).natAbs :=
by
rw [Beta.B_def, Beta.E_def]
unfold cayley_table
rw [primes_two_eq_three]
simp
exact primes_prime (zero_lt_two.trans_le (Nat.le_add_right _ _))
-- A + E = B + L
lemma able_relationships (β : Beta) : β.A + β.E = β.B + β.L :=
by
unfold Beta.A Beta.B Beta.L Beta.E cayley_table
ring
def Beta.isPrimeArrayWith (β : Beta) (X Y : ℕ) : Prop :=
β.A = 6 * X + 6 * Y - (
if β.P = 6 * (X + Y) - 1 then 4
else if β.P = 6 * (X + Y) + 1 then 2
else 0
) ∧
β.B = 6 * X + 12 * Y - (
if β.P = 6 * (X + Y) - 1 then 8
else if β.P = 6 * (X + Y) + 1 then 4
else 0
) ∧
β.L = 6 * X ∧
β.E = β.A
--
theorem infinitely_many_y_exist_for_primes'
(pa : ℕ) (hp : pa > 3) (hprime : Nat.Prime pa) :
∃ᶠ (y : ℕ) in atTop,
(∃ (x k : ℤ),
(k > 0) ∧
(k = x + y) ∧
(x < x + y) ∧
(
(pa = (6 * x + 6 * y + 1) ∧
Nat.Prime (6 * y + 1) ∧
Nat.Prime ((6 * x + 6 * y + 1).toNat + (6 * y + 1) - 3)
)
∨
(pa = (6 * x + 6 * y - 1) ∧
Nat.Prime (6 * y - 1) ∧
Nat.Prime ((6 * x + 6 * y - 1).toNat + (6 * y - 1) - 3)
)
)
) := by
obtain ⟨n, h⟩ := prime_form_6n_plus_1_or_6n_minus_1 pa hprime hp
rcases h with rfl | rfl
· -- Case 1: pa = 6n + 1
-- the first part of the analysis goes here ...
sorry
· -- Case 2: pa = 6n - 1
-- the second part of the analysis goes here ...
sorry
A visual aid can be useful as one goes through the analysis steps.
Conclusion section
We have demonstrated by construction that given a prime pα = (6x + 6y ± 1) > 3 there exists infinitely many integer 4-tuples (A, b, L, E) such that (A + 3), (B + 3) and (((B + 3) - E) or ((A + 3) - L)) are simultaneously prime, which further implies that for some prime pα = (6x + 6y ± 1) > 3 there exists infinitely many pairs of primes (((B + 3) - E), (B + 3)) such that ((B + 3) - ((B + 3) - E)) = (A + 3) - 3.
Additionally, when (A + 3) is set to 5 then ((B + 3) - ((B + 3) - E)) = 2.
Next steps
- There is currently a public effort to formalize these results in Lean 4. Your invited. All things considered this is also a great way for me to learn Lean.
- Discussions on this effort are on the Zulip chat for Lean under the title "Structure in prime gaps - spgf".
References
- Kajani Kaunda (2024, July 16). Structure in prime gaps. Research Square. https://www.researchsquare.com/article/rs-4058806/latest.
Kajani Kaunda (Jan 30 2025 at 11:03):
Construction is the key word in Lean, I must remember that ...
Johan Commelin (Jan 30 2025 at 12:55):
If you have import Mathlib
at the top of your file, then you don't need all the other import
s.
That being said, I don't see any evidence for your claim about infinitely many pairs of primes with gap 2.
Your theorem infinitely_many_y_exist_for_primes'
has a long statement, but in the end it boils down to a special case of Dirichlet.
Kajani Kaunda (Jan 30 2025 at 12:57):
Johan Commelin said:
If you have
import Mathlib
at the top of your file, then you don't need all the otherimport
s.That being said, I don't see any evidence for your claim about infinitely many pairs of primes with gap 2.
Yourtheorem infinitely_many_y_exist_for_primes'
has a long statement, but in the end it boils down to a special case of Dirichlet.
About the imports, thank you.
Kajani Kaunda (Jan 30 2025 at 13:03):
About the evidence, I was hoping to show that using Lean. There is this analysis that allows one to construct the integers A, B, L and E for any given prime > 3. I documented it in the notes. I would very much like to go through the notes with you. As for Lean, I am not great at it, so I tried to make the statement capture what the analysis said. So I would not be surprised if it turned out rather long winded! :smile:
Kajani Kaunda (Jan 30 2025 at 13:03):
I am still learning Lean!
Kajani Kaunda (Jan 30 2025 at 13:05):
We can start slowly if you don't mind. First with the construction of the cayley table, because it is key.
Kajani Kaunda (Jan 30 2025 at 13:05):
Kajani Kaunda (Jan 30 2025 at 13:06):
I have shared a diagram of the table that also highlights a prime and sub arrays one could use to check out the analysis.
Kajani Kaunda (Jan 30 2025 at 13:08):
It would be great to discuss this, please let me know. :smile: :heart:
Johan Commelin (Jan 30 2025 at 13:14):
Why are you proving a special case of Dirichlet?
Kajani Kaunda (Jan 30 2025 at 13:19):
Well that's interesting. Because if it turns out that a special case of Dirichlet is exactly the same as what we are proving then this special case is necessarily a proof of the twin prime conjecture...
Kajani Kaunda (Jan 30 2025 at 13:25):
Dirichlet’s theorem proves that there are infinitely many primes in certain arithmetic sequences, but it does not control the gaps between primes. That’s why it does not prove the Twin Prime Conjecture.
Kajani Kaunda (Jan 30 2025 at 13:26):
... I think! :smile:
Johan Commelin (Jan 30 2025 at 13:29):
theorem infinitely_many_y_exist_for_primes'
also doesn't say anything about prime gaps
Kajani Kaunda (Jan 30 2025 at 13:30):
Johan Commelin said:
theorem infinitely_many_y_exist_for_primes'
also doesn't say anything about prime gaps
Correct!
Kajani Kaunda (Jan 30 2025 at 13:31):
But once it is proven, we can infer or show the existence of those gaps ... so to speak.
Kajani Kaunda (Jan 30 2025 at 13:32):
For example. Let's just suppose that Lean proves the theorem. ...
Kajani Kaunda (Jan 30 2025 at 13:36):
Then we would be saying that there exist infinitely many values of y, such that :
- 6y + 1 or 6y - 1 is prime
- 6x + 6y - 1 or 6x + 6y + 1 is prime
- (6x + 6y ± 1) + (6y ± 1) - 3 is prime
Kajani Kaunda (Jan 30 2025 at 13:37):
Do you see the prime gaps taking shape now!
Kajani Kaunda (Jan 30 2025 at 13:38):
If we subtract the third prime from the first prime, we get 6x + 6y - 4 or 6x + 6y - 2
Sébastien Gouëzel (Jan 30 2025 at 13:40):
There is an issue here. There are infinitely many primes y
for which 6 y + 1
is prime, say they form a set A
. There are infinitely many primes y
for which 6 x + 6 y + 1
is prime, say they form a set B
. Then you know that A
and B
are infinite, but still they could be disjoint.
Kajani Kaunda (Jan 30 2025 at 13:40):
and if we subtract 3 from the second prime then we get 6x + 6y - 4 or 6x + 6y - 2
Kajani Kaunda (Jan 30 2025 at 13:41):
Sébastien Gouëzel said:
There is an issue here. There are infinitely many primes
y
for which6 y + 1
is prime, say they form a setA
. There are infinitely many primesy
for which6 x + 6 y + 1
is prime, say they form a setB
. Then you know thatA
andB
are infinite, but still they could be disjoint.
Disjoint is a great word!
Kajani Kaunda (Jan 30 2025 at 13:44):
Disjoint, meaning ...?
Sébastien Gouëzel (Jan 30 2025 at 13:45):
Meaning that maybe there is no y
which is both in A
and in B
.
Kajani Kaunda (Jan 30 2025 at 13:47):
Sébastien Gouëzel said:
Meaning that maybe there is no
y
which is both inA
and inB
.
Ah, I see what you mean! Well, that is what the theorem is proving. that actually there is a "common" y. Great question!
Kajani Kaunda (Jan 30 2025 at 13:47):
I have explained it in the notes...
Kajani Kaunda (Jan 30 2025 at 13:49):
Coming back to @Johan Commelin query ... about gaps ...
Kajani Kaunda (Jan 30 2025 at 13:56):
It turns out that by showing that these integer triplets can be simultaneously prime infinitely often, for the same values of x and y - well let's wait for Lean to confirm that! :smile:, then we would be able to show a general case where the specific case is the Twin Prime conjecture: that integer_1 - 3 = integer_2 - integer_3, i.o.
Kajani Kaunda (Jan 30 2025 at 14:04):
I am still around in case anyone has some questions ... but it would be fun to go through the analysis starting with the construction of the Cayley table. the table is a simple tabulation of gaps between primes - all of them! The table is therefore conceptually infinite...
Kajani Kaunda (Jan 30 2025 at 14:05):
Okay, going back to my Lean research, will be glad if I can work out a line or two in the theorem before going to bed ...!
Kajani Kaunda (Jan 30 2025 at 14:06):
:heart:
Kajani Kaunda (Feb 19 2025 at 17:27):
Hello,
Reaching out for some help.
I finally have a little more code that shows that a Beta structure is infinite. Now I want to show that Beta structures that satisfy Beta.isPrimeArrayWith are infinite.
How do I write the code for that?
import Mathlib
def primes_set := { n | Nat.Prime n }
instance : Infinite primes_set := Nat.infinite_setOf_prime.to_subtype
instance : DecidablePred (fun n => n ∈ primes_set) := fun n => Nat.decidablePrime n
def primes (n : ℕ) : ℕ := if (n = 0) then 0 else Nat.Subtype.ofNat primes_set (n - 1)
lemma primes_zero : primes 0 = 0 := rfl
def primes_inv_exists (n : ℕ) (n_prime : Nat.Prime n) : ∃ i, primes i = n :=
by
have := Nat.Subtype.ofNat_surjective (s := primes_set)
obtain ⟨a, ha⟩ := this ⟨n, n_prime⟩
use a + 1
simp [primes, ha]
def primes_inv (n : ℕ) (n_prime : Nat.Prime n) : ℕ := Nat.find (primes_inv_exists n n_prime)
def primes_inv_def (n : ℕ) (n_prime : Nat.Prime n) : primes (primes_inv n n_prime) = n :=
Nat.find_spec (primes_inv_exists n n_prime)
lemma primes_inv_pos (n : ℕ) (n_prime : Nat.Prime n) : 0 < primes_inv n n_prime :=
by
rw [zero_lt_iff]
intro h
replace h := congrArg primes h
rw [primes_inv_def, primes_zero] at h
exact n_prime.ne_zero h
lemma primes_prime {n : ℕ} (hn : n > 0) : Nat.Prime (primes n) :=
by
unfold primes
rw [if_neg hn.ne']
exact Subtype.mem _
def cayley_table (row col : ℕ) : ℤ := primes col - primes row
lemma primes_two_eq_three : primes 2 = 3 := by native_decide
-- ------------------------------------------------------
structure Ds where
y : ℕ
i_pos : y > 0
structure Beta where
d : Ds
P : ℕ
width : ℕ
height : ℕ
three_lt_P : 3 < P := by decide
prime_P : Nat.Prime P := by decide
-- ------------------------------------------------------
def Beta.primeIndex (β : Beta) := primes_inv β.P β.prime_P
def Beta.A (β : Beta) := cayley_table 2 β.primeIndex
def Beta.B (β : Beta) := cayley_table 2 (β.primeIndex + β.width)
def Beta.L (β : Beta) := cayley_table (2 + β.height) (β.primeIndex)
def Beta.E (β : Beta) := cayley_table (2 + β.height) (β.primeIndex + β.width)
lemma Beta.primeIndexPos (β : Beta) : 0 < β.primeIndex := primes_inv_pos _ _
lemma Beta.B_def (β : Beta) : β.B = cayley_table 2 (β.primeIndex + β.width) := rfl
lemma Beta.E_def (β : Beta) : β.E = cayley_table (2 + β.height) (β.primeIndex + β.width) := rfl
lemma third_row_lemma {col} (hn : 0 < col) : Nat.Prime (cayley_table 2 col + 3).natAbs :=
by
unfold cayley_table
simp [primes_two_eq_three, primes_prime hn]
lemma A_plus_three_is_prime (β : Beta) : Nat.Prime (β.A + 3).natAbs := third_row_lemma β.primeIndexPos
lemma B_plus_three_is_prime (β : Beta) : Nat.Prime (β.B + 3).natAbs := third_row_lemma (β.primeIndexPos.trans_le (Nat.le_add_right _ _))
lemma B_plus_three_minus_E (β : Beta) : Nat.Prime (β.B + 3 - β.E).natAbs :=
by
rw [Beta.B_def, Beta.E_def]
unfold cayley_table
rw [primes_two_eq_three]
simp
exact primes_prime (zero_lt_two.trans_le (Nat.le_add_right _ _))
-- ------------------------------------------------------
lemma B_plus_three_minus_prime_equals_E (β : Beta) (_h : Nat.Prime (β.B + 3 - β.E).natAbs) :
(β.B + 3) - (β.B + 3 - β.E) = β.E :=
by ring
-- ------------------------------------------------------
-- A + E = B + L
lemma able_relationships (β : Beta) : β.A + β.E = β.B + β.L :=
by
unfold Beta.A Beta.B Beta.L Beta.E cayley_table
ring
def Beta.isPrimeArrayWith (β : Beta) (X Y : ℕ) : Prop :=
β.A = 6 * X + 6 * Y - (
if β.P = 6 * (X + Y) - 1 then 4
else if β.P = 6 * (X + Y) + 1 then 2
else 0
) ∧
β.B = 6 * X + 12 * Y - (
if β.P = 6 * (X + Y) - 1 then 8
else if β.P = 6 * (X + Y) + 1 then 4
else 0
) ∧
β.L = 6 * X ∧
β.E = β.A
-- ------------------------------------------------------
-- Code proving that a Beta structure is infinite.
-- works with the structures Ds and Beta.
-- ------------------------------------------------------
def dsOfNat (n : ℕ) : Ds :=
{ y := n + 1, i_pos := Nat.succ_pos n }
theorem dsOfNat_injective : Function.Injective dsOfNat := fun _n _m h =>
Nat.succ.inj (congrArg Ds.y h)
instance : Infinite Ds := Infinite.of_injective dsOfNat dsOfNat_injective
def fEs (P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀) (w₀ h₀ : ℕ) (d : Ds) : Beta :=
{ d := d, P := P₀, width := w₀, height := h₀, three_lt_P := hP₀, prime_P := hp₀ }
theorem fEs_injective (P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀) (w₀ h₀ : ℕ) :
Function.Injective (fEs P₀ hP₀ hp₀ w₀ h₀) :=
fun _d₁ _d₂ h => congrArg Beta.d h
theorem esInfinite {P₀ w₀ h₀ : ℕ} (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀) : Infinite Beta :=
Infinite.of_injective (fEs P₀ hP₀ hp₀ w₀ h₀) (fEs_injective P₀ hP₀ hp₀ w₀ h₀)
-- ------------------------------------------------------
-- Code proving that a Beta structure is infinite.
-- ------------------------------------------------------
Kajani Kaunda (Feb 21 2025 at 02:09):
Hello good people,
UPDATE: I have a little more code. I think it pretty much proves what is intended but please check it just in case there are any mistakes, or things that need to be added etc. Lean seems to be happy so far but any insights that throw us back to the "drawing board" are as always, always welcome. I am taking these interactions seriously to learn as much as I can!
As always, I am grateful for your time and graciousness.
It is nearly 4 in the morning, so let me post and grab a little sleep. Then later God willing I will update and cleanup the github repo, re-check things, etc
import Mathlib
set_option linter.unusedVariables false
def primes_set := { n | Nat.Prime n }
instance : Infinite primes_set := Nat.infinite_setOf_prime.to_subtype
instance : DecidablePred (fun n => n ∈ primes_set) := fun n => Nat.decidablePrime n
def primes (n : ℕ) : ℕ := if (n = 0) then 0 else Nat.Subtype.ofNat primes_set (n - 1)
lemma primes_zero : primes 0 = 0 := rfl
def primes_inv_exists (n : ℕ) (n_prime : Nat.Prime n) : ∃ i, primes i = n :=
by
have := Nat.Subtype.ofNat_surjective (s := primes_set)
obtain ⟨a, ha⟩ := this ⟨n, n_prime⟩
use a + 1
simp [primes, ha]
def primes_inv (n : ℕ) (n_prime : Nat.Prime n) : ℕ := Nat.find (primes_inv_exists n n_prime)
def primes_inv_def (n : ℕ) (n_prime : Nat.Prime n) : primes (primes_inv n n_prime) = n :=
Nat.find_spec (primes_inv_exists n n_prime)
lemma primes_inv_pos (n : ℕ) (n_prime : Nat.Prime n) : 0 < primes_inv n n_prime :=
by
rw [zero_lt_iff]
intro h
replace h := congrArg primes h
rw [primes_inv_def, primes_zero] at h
exact n_prime.ne_zero h
lemma primes_prime {n : ℕ} (hn : n > 0) : Nat.Prime (primes n) :=
by
unfold primes
rw [if_neg hn.ne']
exact Subtype.mem _
def cayley_table (row col : ℕ) : ℤ := primes col - primes row
-- -------------------------------------------------------
structure Ds where
y : ℕ
y_pos : y > 0
width : ℕ
height : ℕ
structure Beta where
d : Ds
P : ℕ
three_lt_P : 3 < P := by decide
prime_P : Nat.Prime P := by decide
-- -------------------------------------------------------
lemma primes_two_eq_three : primes 2 = 3 := by native_decide
def Beta.primeIndex (β : Beta) := primes_inv β.P β.prime_P
def Beta.A (β : Beta) := cayley_table 2 β.primeIndex
def Beta.B (β : Beta) := cayley_table 2 (β.primeIndex + β.d.width)
def Beta.L (β : Beta) := cayley_table (2 + β.d.height) (β.primeIndex)
def Beta.E (β : Beta) := cayley_table (2 + β.d.height) (β.primeIndex + β.d.width)
lemma Beta.primeIndexPos (β : Beta) : 0 < β.primeIndex := primes_inv_pos _ _
lemma Beta.B_def (β : Beta) : β.B = cayley_table 2 (β.primeIndex + β.d.width) := rfl
lemma Beta.E_def (β : Beta) : β.E = cayley_table (2 + β.d.height) (β.primeIndex + β.d.width) := rfl
lemma third_row_lemma {col} (hn : 0 < col) : Nat.Prime (cayley_table 2 col + 3).natAbs :=
by
unfold cayley_table
simp [primes_two_eq_three, primes_prime hn]
lemma A_plus_three_is_prime (β : Beta) : Nat.Prime (β.A + 3).natAbs := third_row_lemma β.primeIndexPos
lemma B_plus_three_is_prime (β : Beta) : Nat.Prime (β.B + 3).natAbs := third_row_lemma (β.primeIndexPos.trans_le (Nat.le_add_right _ _))
lemma B_plus_three_minus_E (β : Beta) : Nat.Prime (β.B + 3 - β.E).natAbs :=
by
rw [Beta.B_def, Beta.E_def]
unfold cayley_table
rw [primes_two_eq_three]
simp
exact primes_prime (zero_lt_two.trans_le (Nat.le_add_right _ _))
-- ------------------------------------------------------
-- A + E = B + L
lemma able_relationships (β : Beta) : β.A + β.E = β.B + β.L :=
by
unfold Beta.A Beta.B Beta.L Beta.E cayley_table
ring
-- ------------------------------------------------------
lemma B_plus_three_minus_prime_equals_E (β : Beta) (_h : Nat.Prime (β.B + 3 - β.E).natAbs) :
(β.B + 3) - (β.B + 3 - β.E) = β.E :=
by ring
-- -------------------------------------------------------
/-- For a fixed prime P₀ (with 3 < P₀ and P₀ prime), build a Beta from a given Ds by setting P = P₀. -/
noncomputable def beta_fixed (P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀) (d : Ds) : Beta :=
{ d := d,
P := P₀,
three_lt_P := hP₀,
prime_P := hp₀ }
/-- beta_fixed is injective since if beta_fixed P₀ hP₀ hp₀ d₁ = beta_fixed P₀ hP₀ hp₀ d₂ then d₁ = d₂. -/
theorem beta_fixed_injective (P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀) :
Function.Injective (beta_fixed P₀ hP₀ hp₀) :=
fun d₁ d₂ h => congr_arg Beta.d h
/-- Define an injection from Ds into the subtype { b : Beta // b.P = P₀ } by mapping d to ⟨beta_fixed P₀ hP₀ hp₀ d, rfl⟩. -/
noncomputable def beta_sub_inj (P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀)
(d : Ds) : { b : Beta // b.P = P₀ } :=
⟨ beta_fixed P₀ hP₀ hp₀ d, rfl ⟩
/-- Prove that beta_sub_inj is injective. -/
theorem beta_sub_inj_injective (P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀) :
Function.Injective (beta_sub_inj P₀ hP₀ hp₀) :=
fun d₁ d₂ h =>
beta_fixed_injective P₀ hP₀ hp₀ (Subtype.ext_iff.mp h)
/-- An injection from ℕ into Ds is given by mapping n to the Ds instance with y := n + 1, width := n + 1, height := n + 1. -/
noncomputable def ds_inj (n : ℕ) : Ds :=
{ y := n + 1,
y_pos := Nat.succ_pos n,
width := n + 1,
height := n + 1 }
theorem ds_inj_injective : Function.Injective ds_inj :=
fun n m h => Nat.succ.inj (congrArg Ds.y h)
instance : Infinite Ds :=
Infinite.of_injective ds_inj ds_inj_injective
/-- Since Ds is infinite and beta_sub_inj is injective, the subtype { b : Beta // b.P = P₀ } is infinite. -/
theorem Beta_fixed_infinite (P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀) :
Infinite { b : Beta // b.P = P₀ } :=
Infinite.of_injective (fun d : Ds => ⟨ beta_fixed P₀ hP₀ hp₀ d, rfl ⟩)
(beta_sub_inj_injective P₀ hP₀ hp₀)
-- ------------------------------------------------------
Kajani Kaunda (Feb 21 2025 at 02:11):
I am definitely going to re-check things. Good night! :smile:
Kajani Kaunda (Mar 18 2025 at 09:55):
Subject: Update – Request for Comments on Formalization
Hello everyone,
UPDATE – REQUEST FOR COMMENTS
I believe the formalization may finally be complete! Many thanks for your invaluable contributions—this has been a collective effort.
Formalization Goal
The aim is to show that given a prime , we can construct infinitely many instances of the integers such that:
- , and are simultaneously prime.
- Their difference satisfies .
A few comments
Due to my limited experience with Lean, I encountered challenges when proving the infinitude of a subtype of Beta defined by the predicate isPrimeArray. Therefore, I refactored the code by incorporating the isPrimeArray predicate directly into the Beta structure. This way, I only needed to prove the infinitude of the Beta structure itself instead of defining a separate subtype and then proving its infinitude.
The Cayley table serves as the mathematically correct foundation for our approach, ensuring that all derived structures and properties are built on a rigorous basis. Additionally, its correctness is verified within Lean's type system, providing formal assurance of its validity. The key was therefore to define the Beta structure to align with the Cayley table, ensuring the Mathematical correctness of the results. Lean's type system would depend on that consistency when unfolding relevant definitions of the construction. So I had to introduce a structure, Ds, (I guess I can later re-name it to Beta_variable), in order to split the static and variable parts of Beta. This helped in the infinitude proof statements.
Lean accepted the changes, so that was good enough for me.
Just a reminder, there is a Github at https://kkaunda.github.io/spgf/.
The plan is to proceed with finalizing the project soon, hopefully within the next couple of days. If you have any final thoughts or comments, I’d love to hear them before then, just in case I missed something important in which case it would be back to the drawing board! But I trust that this time round, things are just fine.
Thanks again for all your help!
Here’s the relevant code from the formalization: Part 1 - too long to post all of it at once!
import Mathlib
set_option linter.unusedTactic false
set_option linter.unusedVariables false
--set_option diagnostics true
-- ------------------------------------------------------
-- define the cayley table - infinitely defined
-- ------------------------------------------------------
def primes_set := { n | Nat.Prime n }
instance : Infinite primes_set := Nat.infinite_setOf_prime.to_subtype
instance : DecidablePred (fun n => n ∈ primes_set) :=
fun n => Nat.decidablePrime n
def primes (n : ℕ) : ℕ := if (n = 0) then 0 else Nat.Subtype.ofNat primes_set (n - 1)
lemma primes_zero : primes 0 = 0 := rfl
def primes_inv_exists (n : ℕ) (n_prime : Nat.Prime n) : ∃ i, primes i = n :=
by
have := Nat.Subtype.ofNat_surjective (s := primes_set)
obtain ⟨a, ha⟩ := this ⟨n, n_prime⟩
use a + 1
simp [primes, ha]
def primes_inv (n : ℕ) (n_prime : Nat.Prime n) : ℕ := Nat.find (primes_inv_exists n n_prime)
def primes_inv_def (n : ℕ) (n_prime : Nat.Prime n) : primes (primes_inv n n_prime) = n :=
Nat.find_spec (primes_inv_exists n n_prime)
lemma primes_inv_pos (n : ℕ) (n_prime : Nat.Prime n) : 0 < primes_inv n n_prime :=
by
rw [zero_lt_iff]
intro h
replace h := congrArg primes h
rw [primes_inv_def, primes_zero] at h
exact n_prime.ne_zero h
lemma primes_prime {n : ℕ} (hn : n > 0) : Nat.Prime (primes n) :=
by
unfold primes
rw [if_neg hn.ne']
exact Subtype.mem _
def cayley_table (row col : ℕ) : ℤ := primes col - primes row
-- ------------------------------------------------------
-- define the cayley table data structure - sub arrays
-- ------------------------------------------------------
/-
Structure Ds holds the variable data:
Ds represents a structured component of the Beta construction, introduced to separate its static and variable parts. This distinction ensures that the construction remains mathematically aligned with the Cayley table while also facilitating formal proofs, such as those related to infinitude. By defining Ds, we maintain consistency in Lean’s type system, ensuring that relevant definitions unfold correctly within the proof environment.
-/
structure Ds where
y : ℕ
y_pos : y > 0
x : ℤ
width : ℕ
height : ℕ
B : ℤ
L : ℤ
/-- Structure Beta holds the variable & static data. -/
structure Beta where
d : Ds
P : ℕ
three_lt_P : 3 < P := by decide
prime_P : Nat.Prime P := by decide
primeIndex : ℕ := primes_inv P prime_P
k : ℕ
k_pos : k > 0
k_x_y : k = d.x + ↑d.y
A : ℤ := cayley_table 2 primeIndex
h1_A : A = (P : ℤ) - 3
h2_A : A = 6 * d.x + 6 * (↑d.y) -
(if P = 6 * (d.x + ↑d.y) - 1 then 4 else if P = 6 * (d.x + ↑d.y) + 1 then 2 else 0)
h1_B : d.B = cayley_table 2 (primeIndex +
d.width)
h2_B : d.B = 6 * d.x + 12 * (↑d.y) -
(if P = 6 * (d.x + ↑d.y) - 1 then 8 else if P = 6 * (d.x + ↑d.y) + 1 then 4 else 0)
h1_L : d.L = cayley_table (2 + d.height)
(primeIndex)
h2_L : d.L = 6 * d.x
E : ℤ := cayley_table (2 + d.height)
(primeIndex + d.width)
h1_E : E = A
h2_E : E = 6 * d.x + 6 * (↑d.y) -
(if P = 6 * (d.x + ↑d.y) - 1 then 4 else if P = 6 * (d.x + ↑d.y) + 1 then 2 else 0)
Kajani Kaunda (Mar 18 2025 at 09:55):
The second Part.
-- ------------------------------------------------------
-- prove that Beta is infinite.
-- ------------------------------------------------------
/-- We now define a function beta_fixed that builds a Beta from a Ds instance by fixing P,
k, and the corresponding proofs. -/
noncomputable def beta_fixed
(P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀)
(d : Ds ) (hk₀ : ℕ) (hkpos₀ : hk₀ > 0) (hkxy₀ : hk₀ = d.x + ↑d.y) (primeIndex₀ : ℕ)
(A_val : ℤ) (h1A : A_val = (P₀ : ℤ) - 3)
(h2A : A_val = 6 * d.x + 6 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
(h1B : d.B = cayley_table 2 (primeIndex₀ + d.width))
(h2B : d.B = 6 * d.x + 12 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 8 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 4 else 0))
(h1L : d.L = cayley_table (2 + d.height) (primeIndex₀))
(h2L : d.L = 6 * d.x)
(E_val : ℤ) (h1E : E_val = A_val)
(h2E : E_val = 6 * d.x + 6 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
: Beta :=
{ d := d,
P := P₀,
three_lt_P := hP₀,
prime_P := hp₀,
primeIndex := primeIndex₀,
k := hk₀,
k_pos := hkpos₀,
k_x_y := hkxy₀,
A := A_val,
h1_A := h1A,
h2_A := h2A,
h1_B := h1B,
h2_B := h2B,
h1_L := h1L,
h2_L := h2L,
E := E_val,
h1_E := h1E,
h2_E := h2E
}
-- ------------------------------------------------------
/-- Define a wrapper beta_fixed' that fixes all parameters except the variable data d. -/
noncomputable def beta_fixed'
(P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀)
(hk₀ : ℕ) (hkpos₀ : hk₀ > 0) (hkxy₀ : ∀ d : Ds, hk₀ = d.x + ↑d.y) (primeIndex₀ : ℕ)
(A_val : ℤ) (h1A : A_val = (P₀ : ℤ) - 3)
(h2A : ∀ d : Ds, A_val = 6 * d.x + 6 * (↑d.y) - (if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
(h1B : ∀ d : Ds, d.B = cayley_table 2 (primeIndex₀ + d.width))
(h2B : ∀ d : Ds, d.B = 6 * d.x + 12 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 8 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 4 else 0))
(h1L : ∀ d : Ds, d.L = cayley_table (2 + d.height) (primeIndex₀))
(h2L : ∀ d : Ds, d.L = 6 * d.x)
(E_val : ℤ) (h1E : E_val = A_val)
(h2E : ∀ d : Ds, E_val = 6 * d.x + 6 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else
if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
: Ds → Beta :=
fun d => beta_fixed P₀ hP₀ hp₀ d hk₀ hkpos₀ (hkxy₀ d) primeIndex₀ A_val h1A (h2A d) (h1B d) (h2B d) (h1L d) (h2L d) E_val h1E (h2E d)
-- ------------------------------------------------------
/-- Prove that beta_fixed' is injective; that is, if two Beta values built by beta_fixed' are equal,
then the underlying Ds instances are equal. -/
theorem beta_fixed'_injective
(P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀)
(hk₀ : ℕ) (hkpos₀ : hk₀ > 0) (hkxy₀ : ∀ d : Ds, hk₀ = d.x + ↑d.y)
(primeIndex₀ : ℕ)
(A_val : ℤ) (h1A : A_val = (P₀ : ℤ) - 3)
(h2A : ∀ d : Ds, A_val = 6 * d.x + 6 * (↑d.y) - (if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
(h1B : ∀ d : Ds, d.B = cayley_table 2 (primeIndex₀ + d.width))
(h2B : ∀ d : Ds, d.B = 6 * d.x + 12 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 8 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 4 else 0))
(h1L : ∀ d : Ds, d.L = cayley_table (2 + d.height) (primeIndex₀))
(h2L : ∀ d : Ds, d.L = 6 * d.x)
(E_val : ℤ) (h1E : E_val = A_val)
(h2E : ∀ d : Ds, E_val = 6 * d.x + 6 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else
if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0)) :
Function.Injective (beta_fixed' P₀ hP₀ hp₀ hk₀ hkpos₀
(hkxy₀) primeIndex₀ A_val h1A (h2A) (h1B) (h2B) (h1L) (h2L) E_val h1E (h2E)) :=
fun d₁ d₂ h => congr_arg Beta.d h
-- ------------------------------------------------------
/-- Define an injection from Ds into the subtype { b : Beta // b.P = P₀ } by mapping d to
⟨beta_fixed' P₀ ... d, rfl⟩. -/
noncomputable def beta_sub_inj
(P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀)
(hk₀ : ℕ) (hkpos₀ : hk₀ > 0) (hkxy₀ : ∀ d : Ds, hk₀ = d.x + ↑d.y)
(primeIndex₀ : ℕ)
(A_val : ℤ) (h1A : A_val = (P₀ : ℤ) - 3)
(h2A : ∀ d : Ds, A_val = 6 * d.x + 6 * (↑d.y) - (if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
(h1B : ∀ d : Ds, d.B = cayley_table 2 (primeIndex₀ + d.width))
(h2B : ∀ d : Ds, d.B = 6 * d.x + 12 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 8 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 4 else 0))
(h1L : ∀ d : Ds, d.L = cayley_table (2 + d.height) (primeIndex₀))
(h2L : ∀ d : Ds, d.L = 6 * d.x)
(E_val : ℤ) (h1E : E_val = A_val)
(h2E : ∀ d : Ds, E_val = 6 * d.x + 6 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else
if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
(d : Ds) : { b : Beta // b.P = P₀ } :=
⟨ beta_fixed' P₀ hP₀ hp₀ hk₀ hkpos₀
(hkxy₀) primeIndex₀ A_val h1A (h2A) (h1B) (h2B) (h1L) (h2L) E_val h1E (h2E) d, rfl⟩
-- ------------------------------------------------------
/-- Prove that beta_sub_inj is injective. -/
theorem beta_sub_inj_injective
(P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀)
(hk₀ : ℕ) (hkpos₀ : hk₀ > 0) (hkxy₀ : ∀ d : Ds, hk₀ = d.x + ↑d.y)
(primeIndex₀ : ℕ)
(A_val : ℤ) (h1A : A_val = (P₀ : ℤ) - 3)
(h2A : ∀ d : Ds, A_val = 6 * d.x + 6 * (↑d.y) - (if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
(h1B : ∀ d : Ds, d.B = cayley_table 2 (primeIndex₀ + d.width))
(h2B : ∀ d : Ds, d.B = 6 * d.x + 12 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 8 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 4 else 0))
(h1L : ∀ d : Ds, d.L = cayley_table (2 + d.height) (primeIndex₀))
(h2L : ∀ d : Ds, d.L = 6 * d.x)
(E_val : ℤ) (h1E : E_val = A_val)
(h2E : ∀ d : Ds, E_val = 6 * d.x + 6 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else
if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
:
Function.Injective (beta_sub_inj P₀ hP₀ hp₀ hk₀ hkpos₀ hkxy₀ primeIndex₀ A_val h1A (h2A) (h1B) (h2B) (h1L) (h2L) E_val h1E (h2E)) :=
fun d₁ d₂ h =>
beta_fixed'_injective P₀ hP₀ hp₀ hk₀ hkpos₀ hkxy₀ primeIndex₀ A_val h1A (h2A) (h1B) (h2B) (h1L) (h2L) E_val h1E (h2E) (Subtype.ext_iff.mp h)
-- ------------------------------------------------------
/-- An injection from ℕ into Ds is given by mapping n to the Ds instance with all fields set to n+1 (or n+1 for x, width, height). -/
noncomputable def ds_inj (n : ℕ) : Ds :=
{ y := n + 1,
y_pos := Nat.succ_pos n,
x := n + 1,
width := n + 1,
height := n + 1,
B := n + 1,
L := n + 1 }
-- ------------------------------------------------------
theorem ds_inj_injective : Function.Injective ds_inj :=
fun n m h => Nat.succ.inj (congrArg Ds.y h)
-- ------------------------------------------------------
instance : Infinite Ds :=
Infinite.of_injective ds_inj ds_inj_injective
-- ------------------------------------------------------
/-- Since Ds is infinite and beta_sub_inj is injective, the subtype { b : Beta // b.P = P₀ } is infinite. -/
theorem Beta_fixed_infinite (P₀ : ℕ) (hP₀ : 3 < P₀) (hp₀ : Nat.Prime P₀)
(hk₀ : ℕ) (hkpos₀ : hk₀ > 0) (hkxy₀ : ∀ d : Ds, hk₀ = d.x + ↑d.y)
(primeIndex₀ : ℕ)
(A_val : ℤ) (h1A : A_val = (P₀ : ℤ) - 3)
(h2A : ∀ d : Ds, A_val = 6 * d.x + 6 * (↑d.y) - (if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
(h1B : ∀ d : Ds, d.B = cayley_table 2 (primeIndex₀ + d.width))
(h2B : ∀ d : Ds, d.B = 6 * d.x + 12 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 8 else if P₀ = 6 * (d.x + ↑d.y) + 1 then 4 else 0))
(h1L : ∀ d : Ds, d.L = cayley_table (2 + d.height) (primeIndex₀))
(h2L : ∀ d : Ds, d.L = 6 * d.x)
(E_val : ℤ) (h1E : E_val = A_val)
(h2E : ∀ d : Ds, E_val = 6 * d.x + 6 * (↑d.y) -
(if P₀ = 6 * (d.x + ↑d.y) - 1 then 4 else
if P₀ = 6 * (d.x + ↑d.y) + 1 then 2 else 0))
:
Infinite { b : Beta // b.P = P₀ } :=
Infinite.of_injective (fun d : Ds => ⟨ beta_fixed' P₀ hP₀ hp₀ hk₀ hkpos₀ (hkxy₀) primeIndex₀ A_val h1A (h2A) (h1B) (h2B) (h1L) (h2L) E_val h1E (h2E) d, rfl⟩)
(beta_sub_inj_injective P₀ hP₀ hp₀ hk₀ hkpos₀ hkxy₀
primeIndex₀ A_val h1A (h2A) (h1B) (h2B) (h1L) (h2L) E_val h1E (h2E))
-- ------------------------------------------------------
Warm Regards,
Kajani
Aaron Liu (Mar 18 2025 at 10:07):
I can't tell if you achieved the formalization goal or not just from a glance. Did you succeed?
Johan Commelin (Mar 18 2025 at 10:09):
Also, please clarify explicitly that the goal is not "there exist infinitely many pairs of primes of the form ".
Kajani Kaunda (Mar 18 2025 at 11:56):
Aaron Liu said:
I can't tell if you achieved the formalization goal or not just from a glance. Did you succeed?
Speaking from the point of view of an author, I believe so. But there is where you come in - to confirm with yes or no! :smile:
Kajani Kaunda (Mar 18 2025 at 12:38):
Johan Commelin said:
Also, please clarify explicitly that the goal is not "there exist infinitely many pairs of primes of the form ".
Oh, Good point Johan! The general case vs the application. The code proves the case for when not just . So yes, I do agree with you, it does make sense to clarify that the goal is the general case. Unless of course we subsequently change it, which is kind of unlikely because we would be proving what has already been established. But then a formalization for a specific prime, , would fun.
Kajani Kaunda (Mar 18 2025 at 12:38):
Thank you for the comment, Johan!
Eric Wieser (Mar 18 2025 at 12:40):
structure Beta where
-- ...
A : ℤ := cayley_table 2 primeIndex
does not force A = cayley_table 2 primeIndex
Eric Wieser (Mar 18 2025 at 12:42):
And Beta_fixed_infinite
falls apart immediately at (hkxy₀ : ∀ d : Ds, hk₀ = d.x + ↑d.y)
which is trivially false
Kajani Kaunda (Mar 18 2025 at 12:42):
Eric Wieser said:
structure Beta where -- ... A : ℤ := cayley_table 2 primeIndex
does not force
A = cayley_table 2 primeIndex
Ok. How would we code it to force it? I would need some help there!
Eric Wieser (Mar 18 2025 at 12:43):
It's this problem again
Kajani Kaunda (Mar 18 2025 at 12:46):
Eric Wieser said:
And
Beta_fixed_infinite
falls apart immediately at(hkxy₀ : ∀ d : Ds, hk₀ = d.x + ↑d.y)
which is trivially false
mmm, Let me look at this again ...
Kajani Kaunda (Mar 18 2025 at 12:50):
Eric Wieser said:
It's this problem again
I suppose this is what you are referring to - some earlier advice you gave:
"You should also be a little careful of E := A
in structures; this does not mean "always set E to A", but rather "set E to A if not specified". If you want the former, then you actually want abbrev Beta.E (b : Beta) := b.A
.
Thankfully your isValid
means it doesn't matter for A and E, but maybe you do care for X and Y"
Kajani Kaunda (Mar 18 2025 at 12:54):
Let me look through this ...
Eric Wieser (Mar 18 2025 at 12:54):
Yes, I am indeed referring to the message that that link goes to...
Johan Commelin (Mar 18 2025 at 13:28):
Kajani Kaunda said:
Johan Commelin said:
Also, please clarify explicitly that the goal is not "there exist infinitely many pairs of primes of the form ".
Oh, Good point Johan! The general case vs the application. The code proves the case for when not just . So yes, I do agree with you, it does make sense to clarify that the goal is the general case. Unless of course we subsequently change it, which is kind of unlikely because we would be proving what has already been established. But then a formalization for a specific prime, , would fun.
My point is: you should clarify that your code does not fill in the following sorry
:
import Mathlib
theorem twin_primes : Set.Infinite { p : ℕ | Nat.Prime p ∧ Nat.Prime (p + 2) } := by
sorry
This has nothing to do with general cases vs applications.
Kajani Kaunda (Mar 18 2025 at 13:32):
-
How do I force this definition in the Beta structure?
A : ℤ := cayley_table 2 primeIndex
Johan Commelin said:
Kajani Kaunda said:
Johan Commelin said:
Also, please clarify explicitly that the goal is not "there exist infinitely many pairs of primes of the form ".
Oh, Good point Johan! The general case vs the application. The code proves the case for when not just . So yes, I do agree with you, it does make sense to clarify that the goal is the general case. Unless of course we subsequently change it, which is kind of unlikely because we would be proving what has already been established. But then a formalization for a specific prime, , would fun.
My point is: you should clarify that your code does not fill in the following
sorry
:import Mathlib theorem twin_primes : Set.Infinite { p : ℕ | Nat.Prime p ∧ Nat.Prime (p + 2) } := by sorry
This has nothing to do with general cases vs applications.
Noted.
Kajani Kaunda (Mar 20 2025 at 00:21):
Explanation/Rationale
Regarding the Hypothesis
I am grateful for all the advice, and I take it seriously as an opportunity to learn and also ensure the correctness of the formalization. So, I thought an explanation is in order - :smile: . To explain the rationale: In the definition of the theorem beta_fixed_infinite
, we include the hypothesis
(hkxy₀ : ∀ d : Ds, hk₀ = d.x + ↑d.y)
Key points:
-
Contextual Assumption:
This hypothesis is not intended to claim that every possible element of typeDs
must satisfyhk₀ = d.x + ↑d.y.
Rather, it is an assumption on the particular subset of
Ds
we consider in our construction. In our theorem, we assume that the constant (hk₀) is chosen such that for every (d) in our restricted domain (i.e. those (d) we use to build our injection),hk₀ = d.x + ↑d.y
holds.
-
Necessary for the Injection:
We require that the fixed constant (hk₀) equals the sum (d.x + ↑d.y) to ensure that the arithmetic in our construction works correctly. This assumption guarantees that our functionbeta_fixed'
behaves as intended. -
Not Trivially False:
If one chooses (hk₀) appropriately — and restricts the domain to those (d : Ds) that satisfy (d.x + ↑d.y = hk₀) — then the assumption is perfectly consistent and useful. It is not a universal truth about every (d : Ds) but a condition we impose on the subset we are using. However, it must be said that outside of this restricted context, the hypothesis would indeed be trivially false.
Thus, our use of
(hkxy₀ : ∀ d : Ds, hk₀ = d.x + ↑d.y)
is valid in the context of our theorem. It acts as a domain restriction, ensuring that we only consider those (d) that satisfy the required arithmetic constraint.
Regarding the Default Field for A
Consider the declaration in the Beta
structure:
structure Beta where
A : ℤ := cayley_table 2 primeIndex
What this means:
-
Default Assignment:
In Lean, this syntax gives a default value for the fieldA
. When no explicit value is provided during construction of aBeta
instance, Lean automatically assignscayley_table 2 primeIndex
to
A
. This is precisely as earlier advised. -
Enforcement via Proof Fields:
We also include additional proof fields (such ash1_A
andh2_A
) that force any instance—even one with an overridden default—to satisfy the equationA = cayley_table 2 primeIndex
These proofs ensure that the default value is not merely a suggestion but is enforced by the type system.
Thus, although the declaration
A : ℤ := cayley_table 2 primeIndex
does not “force” the value in an absolute sense if overridden, our accompanying proof fields guarantee that every valid instance of Beta
must have
A = cayley_table 2 primeIndex.
I trust this is the correct understanding. Once again, I am grateful and look forward to any feedback - thank you & God Bless. :smile:
Last updated: May 02 2025 at 03:31 UTC