(Note: If you want a blueprint for the Hardy Littlewood tool, use this link to version 3.0. This version measures sequential k based on modular restrictions. It spends the extra computation otherwise used for density calculation and linear regression on checking how many “pairs of pairs” are possible.)
This document details the purpose, theory, and implementation of the “Constellation Hunter,” a high-performance Python script for analyzing the structure of twin prime indices. This final version incorporates key findings from runs up to a limit of one billion, demonstrating how abstract theory is confirmed by concrete data.
1. Purpose and Philosophy:
Previous analyzers on n01r.com focused on a single goal: calculating the density of twin prime indices to test the Hardy-Littlewood conjecture. While successful, this condenses a rich dataset into one number.
The “Constellation Hunter” adopts a different philosophy. It adapts the core theorem (k \ |6xy+x+y| are precisely the indices “k” of twin primes 6k-1, 6k+1) as a new tool that successfully reveals a variety of structural patterns within the sequence of twin prime indices (k).
Instead of asking “how dense are the indices?”, it asks “how are the indices arranged?”.
This approach has proven highly effective at testing new hypotheses and discovering the non-random laws governing prime distributions.
2. Background and Theory:
The tool’s analytical power comes from arithmetic constraints on k, which our results have now empirically verified.
For (6k-1, 6k+1) to be a twin prime pair, it must avoid divisibility by small primes. This creates “forbidden” values for k.
- Restriction mod 5: Forbids k ending in 1, 4, 6, or 9.
- Restriction mod 7: Forbids k congruent to 1 or 6 mod 7.
Our tool’s ability to find any indices at all is a direct confirmation that these arithmetic gaps exist.
A pair of consecutive integers (k, k+1) that are both twin prime indices generates a prime quadruple (p, p+2, p+6, p+8). The modular rules predict that for this to happen, the starting k must end in 2 or 7 (with the single exception of k=1).
Vindication from the Data: Across every run, from k=10 to k=1,000,000,000, the “Validation” section of our output has perfectly confirmed this theory. Every single one of the 119,474 prime quadruples found up to k=1B was accounted for by this simple rule, providing a stunning link between abstract modular arithmetic and the concrete structure of the primes.
3. Key Findings from the Data
The series of runs from k=10 to k=1,000,000,000 tells a classic story: as we increase the scale, chaotic-looking statistics converge into clear, undeniable laws.
At small limits, the transitions between the last digits of adjacent k’s seem random. However, the data at k=100M and k=1B shows a stable, non-uniform pattern. For example, a k ending in 8 is consistently more likely to be followed by a k ending in 0 than another one ending in 8. This reveals a subtle, predictable “flow” in the sequence.
This is the most significant result. The frequency of finding pairs (k, k+d) is not random or uniform. Each difference d has a unique “fingerprint.”
- Chaos to Order: At k=100, the counts are erratic. By k=1,000,000,000, the ratios between the counts have stabilized.
- The Ratios: The data from k=1B shows the law clearly:
- The count for d=1 (quadruples) is 119,474.
- The count for d=2 is 318,378 (~2.66x the d=1 rate).
- The count for d=5 is 478,473 (~4.00x the d=1 rate).
- The count for d=6 is 137,134 (~1.15x the d=1 rate).
These stable, non-integer ratios are direct empirical evidence of the Hardy-Littlewood k-tuple conjecture, which predicts these complex frequencies. Our tool has successfully detected the fundamental “probabilities” governing prime patterns.
4. Prerequisites
Before running the script, ensure you have Python 3.6 or newer installed. The following libraries are required:
- NumPy: For its highly efficient boolean arrays.
- Pandas: For displaying the structured ‘Transition Matrix’.
Install these packages using pip:codeBash
pip install numpy pandas
5. Scope and Limitations
It is crucial to note that this tool is designed to find and analyze pairs of indices. It can find (k, k+1) or (k, k+2), but it does not search for triples like (k, k+1, k+2). Such a search would require a different logic and remains a fascinating avenue for future investigation.
Implementation:
"""
Twin Prime Index Analyzer 4.0: The Constellation Hunter
This script provides a high-performance, interactive tool for exploratory analysis
of the twin prime indices 'k', which generate twin primes of the form (6k-1, 6k+1).
Its primary purpose is to move beyond simple density calculations and uncover the
rich, non-random structures and patterns in the arrangement of these indices.
Features:
1. **High-Performance Engine**: Uses a fast Sieve of Eratosthenes to directly
generate the twin prime indices up to a user-specified limit.
2. **Interactive Loop**: Prompts the user for a 'k' limit and allows for
multiple analyses without restarting the script.
3. **Transition Matrix**: Analyzes the sequence of indices to count the
frequency of transitions between the last digits of adjacent indices.
4. **Constellation Counter**: Searches the entire set of indices to count the
number of pairs (k, k+d) for various fixed differences 'd'.
5. **Segmented Timing**: Reports the execution time for each major analysis
phase to profile performance.
"""
from typing import List, Dict
import numpy as np
import time
import pandas as pd
def find_k_by_prime_sieve(k_limit: int) -> List[int]:
"""
Finds twin prime indices 'k' using a fast prime-first sieve.
Args:
k_limit: The maximum twin prime index to search for.
Returns:
A sorted list of all twin prime indices up to k_limit.
"""
if not isinstance(k_limit, int) or k_limit < 1:
raise ValueError("k_limit must be an integer greater than 0.")
n_max = 6 * k_limit + 2
is_prime = np.ones(n_max, dtype=bool)
is_prime[0:2] = False
for i in range(2, int(np.sqrt(n_max)) + 1):
if is_prime[i]:
is_prime[i*i::i] = False
k_indices = []
for p_start in range(5, 6 * k_limit, 6):
if is_prime[p_start] and is_prime[p_start + 2]:
k = (p_start + 1) // 6
k_indices.append(k)
return k_indices
def analyze_adjacent_k_by_last_digit(k_indices: List[int]) -> pd.DataFrame:
"""
Counts the transitions between the last digits of adjacent k's in the sequence.
Args:
k_indices: The sorted list of twin prime indices.
Returns:
A pandas DataFrame showing transition counts between last digits.
"""
digits = [0, 2, 3, 5, 7, 8]
transition_counts = pd.DataFrame(0, index=digits, columns=digits, dtype=int)
if len(k_indices) < 2:
return transition_counts
for i in range(len(k_indices) - 1):
from_digit = k_indices[i] % 10
to_digit = k_indices[i+1] % 10
if from_digit in digits and to_digit in digits:
transition_counts.loc[from_digit, to_digit] += 1
return transition_counts
def find_fixed_difference_constellations(k_indices: List[int], max_diff: int) -> Dict[int, int]:
"""
Counts pairs of indices (k, k+d) that are both twin prime indices.
Args:
k_indices: The list of twin prime indices.
max_diff: The maximum difference 'd' to check.
Returns:
A dictionary mapping each difference d to the count of (k, k+d) pairs.
"""
k_set = set(k_indices)
constellation_counts = {}
for d in range(1, max_diff + 1):
count = sum(1 for k in k_set if (k + d) in k_set)
constellation_counts[d] = count
return constellation_counts
def main():
""" Main function to run the interactive analysis loop. """
while True:
try:
k_input = input("Please enter the maximum k to analyze (or 'Q' to quit): ")
if k_input.strip().lower() == 'q':
break
K_LIMIT = int(k_input)
if K_LIMIT <= 0:
print("Error: Please enter an integer greater than 0.")
continue
except ValueError:
print("Error: Invalid input. Please enter a valid integer.")
continue
except (RuntimeError, EOFError):
print("\nNon-interactive mode detected. Exiting.")
break
print(f"\n--- Constellation Hunter Analysis up to k = {K_LIMIT:,} ---")
run_total_time = 0.0
# --- Phase 1: Engine ---
start_time = time.time()
k_indices = find_k_by_prime_sieve(K_LIMIT)
end_time = time.time()
phase_time = end_time - start_time
run_total_time += phase_time
print(f"\nEngine finished in {phase_time:.4f} seconds.")
print(f"Found {len(k_indices):,} twin prime indices up to {K_LIMIT:,}.")
if not k_indices:
print("No twin prime indices found for this limit.")
else:
# --- Phase 2: Last Digit Transitions ---
print("\n--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---")
start_time = time.time()
transition_df = analyze_adjacent_k_by_last_digit(k_indices)
end_time = time.time()
phase_time = end_time - start_time
run_total_time += phase_time
print("This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,")
print("based on their last digits. Read as (row, column).")
print(transition_df)
print(f"(Analysis 1 finished in {phase_time:.4f} seconds)")
# --- Phase 3: Fixed-Difference Constellations & Validation ---
print("\n--- Analysis 2: Fixed-Difference k-Constellations ---")
start_time = time.time()
MAX_DIFFERENCE_TO_CHECK = 12
constellation_counts = find_fixed_difference_constellations(k_indices, MAX_DIFFERENCE_TO_CHECK)
print(f"This table shows the total number of pairs (k, k+d) found in the set of indices.")
print("-" * 30)
print(f"{'Difference (d)':<15} | {'Count'}")
print("-" * 30)
for d, count in constellation_counts.items():
print(f"{d:<15} | {count:,}")
print("-" * 30)
k_set_for_validation = set(k_indices)
quad_k_pairs = [(k, k + 1) for k in k_set_for_validation if (k + 1) in k_set_for_validation]
n2_3_quads = sum(1 for k, _ in quad_k_pairs if k % 10 == 2)
n7_8_quads = sum(1 for k, _ in quad_k_pairs if k % 10 == 7)
accounted_for = n2_3_quads + n7_8_quads
print("\nValidation of Prime Quadruple last digits (for d=1):")
print(f"Total k-pairs with d=1 (quadruples): {len(quad_k_pairs):,}")
print(f"Started by k ending in 2 (n2->n3): {n2_3_quads:,}")
print(f"Started by k ending in 7 (n7->n8): {n7_8_quads:,}")
if 1 in k_set_for_validation and 2 in k_set_for_validation:
accounted_for +=1
print(f"Exception pair (k=1, k=2): 1")
print(f"Total accounted for: {accounted_for:,}")
end_time = time.time()
phase_time = end_time - start_time
run_total_time += phase_time
print(f"(Analysis 2 finished in {phase_time:.4f} seconds)")
print(f"\n--- Total time for this run: {run_total_time:.4f} seconds ---")
while True:
try:
another_run = input("\nRun another analysis? (Y/N): ").strip().lower()
if another_run in ['y', 'n']:
break
else:
print("Invalid input. Please enter 'Y' or 'N'.")
except (RuntimeError, EOFError):
another_run = 'n'
break
if another_run == 'n':
break
print("\nExiting Constellation Hunter. Goodbye!")
if __name__ == "__main__":
main()
Example Outputs (used by inference in the documentation):
Please enter the maximum k to analyze (or 'Q' to quit): 10
--- Constellation Hunter Analysis up to k = 10 ---
Engine finished in 0.0000 seconds.
Found 6 twin prime indices up to 10.
--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---
This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,
based on their last digits. Read as (row, column).
0 2 3 5 7 8
0 0 0 0 0 0 0
2 0 0 1 0 0 0
3 0 0 0 1 0 0
5 0 0 0 0 1 0
7 1 0 0 0 0 0
8 0 0 0 0 0 0
(Analysis 1 finished in 0.0145 seconds)
--- Analysis 2: Fixed-Difference k-Constellations ---
This table shows the total number of pairs (k, k+d) found in the set of indices.
------------------------------
Difference (d) | Count
------------------------------
1 | 2
2 | 3
3 | 2
4 | 2
5 | 2
6 | 1
7 | 1
8 | 1
9 | 1
10 | 0
11 | 0
12 | 0
------------------------------
Validation of Prime Quadruple last digits (for d=1):
Total k-pairs with d=1 (quadruples): 2
Started by k ending in 2 (n2->n3): 1
Started by k ending in 7 (n7->n8): 0
Exception pair (k=1, k=2): 1
Total accounted for: 2
(Analysis 2 finished in 0.0000 seconds)
--- Total time for this run: 0.0145 seconds ---
Run another analysis? (Y/N): y
Please enter the maximum k to analyze (or 'Q' to quit): 100
--- Constellation Hunter Analysis up to k = 100 ---
Engine finished in 0.0000 seconds.
Found 26 twin prime indices up to 100.
--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---
This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,
based on their last digits. Read as (row, column).
0 2 3 5 7 8
0 0 3 0 1 0 0
2 0 0 2 0 2 1
3 0 0 0 2 0 1
5 2 0 0 0 2 0
7 1 1 0 1 1 1
8 2 0 1 0 0 0
(Analysis 1 finished in 0.0000 seconds)
--- Analysis 2: Fixed-Difference k-Constellations ---
This table shows the total number of pairs (k, k+d) found in the set of indices.
------------------------------
Difference (d) | Count
------------------------------
1 | 4
2 | 9
3 | 3
4 | 2
5 | 11
6 | 5
7 | 11
8 | 7
9 | 4
10 | 5
11 | 4
12 | 5
------------------------------
Validation of Prime Quadruple last digits (for d=1):
Total k-pairs with d=1 (quadruples): 4
Started by k ending in 2 (n2->n3): 2
Started by k ending in 7 (n7->n8): 1
Exception pair (k=1, k=2): 1
Total accounted for: 4
(Analysis 2 finished in 0.0000 seconds)
--- Total time for this run: 0.0000 seconds ---
Run another analysis? (Y/N): 1000
Invalid input. Please enter 'Y' or 'N'.
Run another analysis? (Y/N): y
Please enter the maximum k to analyze (or 'Q' to quit): 1000
--- Constellation Hunter Analysis up to k = 1,000 ---
Engine finished in 0.0000 seconds.
Found 142 twin prime indices up to 1,000.
--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---
This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,
based on their last digits. Read as (row, column).
0 2 3 5 7 8
0 2 9 3 4 1 3
2 1 1 8 6 3 4
3 1 1 1 6 8 5
5 5 2 2 1 12 1
7 8 4 3 4 2 7
8 6 5 5 2 2 2
(Analysis 1 finished in 0.0112 seconds)
--- Analysis 2: Fixed-Difference k-Constellations ---
This table shows the total number of pairs (k, k+d) found in the set of indices.
------------------------------
Difference (d) | Count
------------------------------
1 | 11
2 | 28
3 | 18
4 | 13
5 | 36
6 | 11
7 | 29
8 | 17
9 | 15
10 | 23
11 | 13
12 | 23
------------------------------
Validation of Prime Quadruple last digits (for d=1):
Total k-pairs with d=1 (quadruples): 11
Started by k ending in 2 (n2->n3): 5
Started by k ending in 7 (n7->n8): 5
Exception pair (k=1, k=2): 1
Total accounted for: 11
(Analysis 2 finished in 0.0000 seconds)
--- Total time for this run: 0.0112 seconds ---
Run another analysis? (Y/N): y
Please enter the maximum k to analyze (or 'Q' to quit): 10000
--- Constellation Hunter Analysis up to k = 10,000 ---
Engine finished in 0.0000 seconds.
Found 810 twin prime indices up to 10,000.
--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---
This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,
based on their last digits. Read as (row, column).
0 2 3 5 7 8
0 13 36 21 21 18 19
2 17 11 25 33 27 28
3 17 18 17 22 31 22
5 26 17 25 12 36 19
7 22 31 18 20 13 34
8 33 27 21 28 13 17
(Analysis 1 finished in 0.0318 seconds)
--- Analysis 2: Fixed-Difference k-Constellations ---
This table shows the total number of pairs (k, k+d) found in the set of indices.
------------------------------
Difference (d) | Count
------------------------------
1 | 27
2 | 72
3 | 55
4 | 42
5 | 113
6 | 33
7 | 96
8 | 59
9 | 40
10 | 95
11 | 43
12 | 78
------------------------------
Validation of Prime Quadruple last digits (for d=1):
Total k-pairs with d=1 (quadruples): 27
Started by k ending in 2 (n2->n3): 11
Started by k ending in 7 (n7->n8): 15
Exception pair (k=1, k=2): 1
Total accounted for: 27
(Analysis 2 finished in 0.0000 seconds)
--- Total time for this run: 0.0318 seconds ---
Run another analysis? (Y/N): y
Please enter the maximum k to analyze (or 'Q' to quit): 100000
--- Constellation Hunter Analysis up to k = 100,000 ---
Engine finished in 0.0029 seconds.
Found 5,330 twin prime indices up to 100,000.
--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---
This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,
based on their last digits. Read as (row, column).
0 2 3 5 7 8
0 92 198 141 143 152 136
2 114 110 174 172 168 172
3 147 128 101 161 166 144
5 150 144 125 120 189 162
7 158 164 157 120 92 202
8 202 165 149 174 126 110
(Analysis 1 finished in 0.2153 seconds)
--- Analysis 2: Fixed-Difference k-Constellations ---
This table shows the total number of pairs (k, k+d) found in the set of indices.
------------------------------
Difference (d) | Count
------------------------------
1 | 117
2 | 312
3 | 235
4 | 157
5 | 464
6 | 133
7 | 437
8 | 236
9 | 196
10 | 372
11 | 176
12 | 338
------------------------------
Validation of Prime Quadruple last digits (for d=1):
Total k-pairs with d=1 (quadruples): 117
Started by k ending in 2 (n2->n3): 58
Started by k ending in 7 (n7->n8): 58
Exception pair (k=1, k=2): 1
Total accounted for: 117
(Analysis 2 finished in 0.0000 seconds)
--- Total time for this run: 0.2183 seconds ---
Run another analysis? (Y/N): y
Please enter the maximum k to analyze (or 'Q' to quit): 1000000
--- Constellation Hunter Analysis up to k = 1,000,000 ---
Engine finished in 0.0535 seconds.
Found 37,915 twin prime indices up to 1,000,000.
--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---
This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,
based on their last digits. Read as (row, column).
0 2 3 5 7 8
0 792 1221 1120 1100 1085 975
2 930 854 1230 1146 1068 1104
3 1144 932 834 1201 1123 1045
5 1060 1099 922 812 1264 1115
7 1117 1087 1086 908 833 1326
8 1250 1138 1087 1105 985 815
(Analysis 1 finished in 1.5504 seconds)
--- Analysis 2: Fixed-Difference k-Constellations ---
This table shows the total number of pairs (k, k+d) found in the set of indices.
------------------------------
Difference (d) | Count
------------------------------
1 | 606
2 | 1,545
3 | 1,143
4 | 781
5 | 2,268
6 | 698
7 | 2,242
8 | 1,213
9 | 901
10 | 1,894
11 | 844
12 | 1,662
------------------------------
Validation of Prime Quadruple last digits (for d=1):
Total k-pairs with d=1 (quadruples): 606
Started by k ending in 2 (n2->n3): 289
Started by k ending in 7 (n7->n8): 316
Exception pair (k=1, k=2): 1
Total accounted for: 606
(Analysis 2 finished in 0.0230 seconds)
--- Total time for this run: 1.6269 seconds ---
Run another analysis? (Y/N): y
Please enter the maximum k to analyze (or 'Q' to quit): 10000000
--- Constellation Hunter Analysis up to k = 10,000,000 ---
Engine finished in 0.5532 seconds.
Found 280,557 twin prime indices up to 10,000,000.
--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---
This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,
based on their last digits. Read as (row, column).
0 2 3 5 7 8
0 6258 8835 8292 8007 8049 7141
2 7143 6454 9073 8220 8001 7950
3 8264 7297 6390 8784 8385 7845
5 7925 8128 7379 6452 8721 8126
7 8290 7872 8015 7090 6390 9131
8 8702 8254 7816 8178 7243 6455
(Analysis 1 finished in 10.3608 seconds)
--- Analysis 2: Fixed-Difference k-Constellations ---
This table shows the total number of pairs (k, k+d) found in the set of indices.
------------------------------
Difference (d) | Count
------------------------------
1 | 3,258
2 | 8,474
3 | 6,327
4 | 4,091
5 | 12,700
6 | 3,706
7 | 12,074
8 | 6,741
9 | 4,666
10 | 10,419
11 | 4,652
12 | 8,840
------------------------------
Validation of Prime Quadruple last digits (for d=1):
Total k-pairs with d=1 (quadruples): 3,258
Started by k ending in 2 (n2->n3): 1,614
Started by k ending in 7 (n7->n8): 1,643
Exception pair (k=1, k=2): 1
Total accounted for: 3,258
(Analysis 2 finished in 0.1429 seconds)
--- Total time for this run: 11.0570 seconds ---
Run another analysis? (Y/N): y
Please enter the maximum k to analyze (or 'Q' to quit): 100000000
--- Constellation Hunter Analysis up to k = 100,000,000 ---
Engine finished in 6.7692 seconds.
Found 2,166,300 twin prime indices up to 100,000,000.
--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---
This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,
based on their last digits. Read as (row, column).
0 2 3 5 7 8
0 51464 65593 63222 61126 62751 56771
2 56650 50835 67915 62778 61185 61313
3 62796 57871 51323 65981 62705 60700
5 61261 62334 56919 51953 65576 63061
7 63125 60980 61511 56442 51130 67955
8 65631 63062 60486 62825 57796 51272
(Analysis 1 finished in 79.2446 seconds)
--- Analysis 2: Fixed-Difference k-Constellations ---
This table shows the total number of pairs (k, k+d) found in the set of indices.
------------------------------
Difference (d) | Count
------------------------------
1 | 18,839
2 | 50,411
3 | 37,682
4 | 24,316
5 | 76,089
6 | 21,775
7 | 72,036
8 | 39,870
9 | 28,056
10 | 61,038
11 | 26,451
12 | 52,333
------------------------------
Validation of Prime Quadruple last digits (for d=1):
Total k-pairs with d=1 (quadruples): 18,839
Started by k ending in 2 (n2->n3): 9,372
Started by k ending in 7 (n7->n8): 9,466
Exception pair (k=1, k=2): 1
Total accounted for: 18,839
(Analysis 2 finished in 1.3980 seconds)
--- Total time for this run: 87.4119 seconds ---
Run another analysis? (Y/N):y
Please enter the maximum k to analyze (or 'Q' to quit): 1000000000
--- Constellation Hunter Analysis up to k = 1,000,000,000 ---
Engine finished in 104.0177 seconds.
Found 17,244,408 twin prime indices up to 1,000,000,000.
--- Analysis 1: Transitions Between Last Digits of Adjacent k's ---
This table shows the count of adjacent pairs (k_i, k_{i+1}) in the sequence,
based on their last digits. Read as (row, column).
0 2 3 5 7 8
0 422586 514341 499059 484149 497022 457969
2 459686 418629 530296 497804 481537 486496
3 497272 464961 420195 515341 496109 482325
5 483759 496717 458721 422486 513680 498694
7 498604 482300 485838 457729 418897 528266
8 513219 497499 482094 496549 464389 419188
(Analysis 1 finished in 632.0556 seconds)
--- Analysis 2: Fixed-Difference k-Constellations ---
This table shows the total number of pairs (k, k+d) found in the set of indices.
------------------------------
Difference (d) | Count
------------------------------
1 | 119,474
2 | 318,378
3 | 239,081
4 | 152,097
5 | 478,473
6 | 137,134
7 | 455,798
8 | 251,919
9 | 177,846
10 | 386,915
11 | 165,366
12 | 328,790
------------------------------
Validation of Prime Quadruple last digits (for d=1):
Total k-pairs with d=1 (quadruples): 119,474
Started by k ending in 2 (n2->n3): 59,826
Started by k ending in 7 (n7->n8): 59,647
Exception pair (k=1, k=2): 1
Total accounted for: 119,474
(Analysis 2 finished in 9.8151 seconds)
--- Total time for this run: 745.8884 seconds ---
Run another analysis? (Y/N):




