Segmented/Multicore k-Trillion Run

Here, I built a new SoE which works on k-space, which is the fastest and most stable version I built yet. It uses parallel processing, a segmented sieve, and an optimized L3 cache strategy to get a 10x speedup over my prior SoE version which was itself 10x faster than a brute force implementation. Because the script crashed when I tried to compute a linear regression for Hardy Littlewood constant at k=10^12 (one trillion), the fix was essentially to run the regression as a second pass. This results in it being about twice as slow as it needs to be, but the data is interesting; resulting in an r-squared of 0.99964915.

1.0 – Purpose:

The primary purpose of this script is to provide a computational tool for a rigorous empirical analysis of the Twin Prime Index Conjecture by implementing a “dual sieve in k-space”. This conjecture reframes the search for twin primes into a search for a specific set of integers, k, which generate twin prime pairs of the form (6k-1, 6k+1). The script automates the discovery of these indices and, more importantly, implements a sophisticated statistical method to test the validity of the conjecture against established number theory.

The script’s methodology is designed to test a specific prediction derived from the First Hardy-Littlewood Conjecture. The standard conjecture predicts the density of twin primes p, p+2. By adapting this for primes of the form 6k±1, the theoretical density constant scales from 2C₂ to 12C₂, where C₂ is the twin prime constant (≈0.66016181584). The script’s final extrapolated value is therefore a direct empirical test of this scaled constant, K ≈ 7.921942, providing a quantitative measure of the Twin Prime Index Conjecture’s accuracy.

Aside from an accurate count of twin primes up to (6*k)+1, this is the primary result of the analysis. By fitting a linear model to the trend of the entire dataset, this method mitigates the effect of local noise and provides a statistical forecast of the true asymptotic value of twin prime-producing k values.

(This was first explored in v2.0 of the brute force sieve.)

2.0 – Theoretical Background and Methodology

2.1. The Twin Prime Index Conjecture (it’s actually a Theorem in terms of its accuracy as a restatement of the Twin Prime Conjecture)

The script is based on the theory that an integer k is the index of a twin prime pair (6k-1, 6k+1) if and only if it cannot be generated by the Diophantine formula k = |6xy + x + y| for any non-zero integers x and y.

The set of all “creatable” integers is defined as K_composite = {|6xy + x + y| : x,y ∈ ℤ \ {0}}. The set of twin prime indices is therefore the complement of this set in the positive integers, ℤ⁺ \ K_composite.

Let:f(x,y)=∣6xy+x+y∣

where 𝑥,𝑦 ∈ 𝑍∖{0} (i.e., both are non-zero integers, so may be positive or negative).

Define the set:

𝐾composite = {𝑓(𝑥,𝑦): 𝑥≠0, 𝑦≠0}

Then: A positive integer 𝑘 is the index of a twin prime pair (6𝑘−1,6𝑘+1) if and only if:

𝑘∉𝐾composite

Therefore, the Twin Prime Conjecture is true if and only if:

𝑍+∖𝐾composite is infinite

In plain language:

There are infinitely many twin primes if and only if there are infinitely many positive integers 𝑘 that cannot be written in the form ∣6𝑥𝑦+𝑥+𝑦∣ for any non-zero integers 𝑥,𝑦.

2.2. Theorem

There are infinitely many twin primes, p=6k-1,p+2=6k+1 if and only if there are infinitely positive integers k not expressible by the Diophantine equation k=|6xy+x+y| for non-zero x and y.

2.2.1. Lemma (Completeness of Composite Coverage)

Let N be a positive integer such that N ≡ ±1 (mod 6) and N is composite. Then the index k for which N = 6k ± 1 belongs to the set:

  K_composite = { |6xy + x + y| : x, y ∈ ℤ \ {0} }

This proves that the k-index filter correctly identifies all composite numbers of the form 6k ± 1.

Proof

We must show that for any composite number N ≡ ±1 (mod 6), its corresponding index k can be generated by the form |6xy + x + y| for some non-zero integers x and y. We proceed by cases based on the residue of N modulo 6.

Note: Since N ≡ ±1 (mod 6), the prime factors of N must also be congruent to ±1 (mod 6). Thus, every prime divisor of N is of the form 6m ± 1.

Case 1: N is composite and N ≡ 1 (mod 6).

Since N is composite, write N = AB, where A, B > 1. To satisfy N ≡ 1 (mod 6), either:

Subcase 1a: A ≡ 1 (mod 6) and B ≡ 1 (mod 6).

Then A = 6x + 1, B = 6y + 1 for some x, y ∈ ℕ. Since A, B > 1, we have x, y ≠ 0. Then:

  N = (6x + 1)(6y + 1) = 36xy + 6x + 6y + 1 = 6(6xy + x + y) + 1.

Thus, N = 6k + 1 where k = 6xy + x + y > 0, so k = |6xy + x + y| ∈ K_composite.

Subcase 1b: A ≡ -1 (mod 6) and B ≡ -1 (mod 6).

Then A = 6u − 1 and B = 6v − 1 for some u, v ∈ ℕ. Let x = –u and y = –v, which are non-zero integers. Then:

  N = (6x + 1)(6y + 1) = 6(6xy + x + y) + 1.

So again, N = 6k + 1, with k = |6xy + x + y| ∈ K_composite.

Thus, in both subcases of Case 1, composite numbers N ≡ 1 (mod 6) yield indices k in K_composite.

Case 2: N is composite and N ≡ -1 (mod 6).

Write N = AB, A, B > 1, such that one of A, B ≡ 1 (mod 6), and the other ≡ -1 (mod 6). Without loss of generality, let A = 6x + 1 and B = 6y − 1, with x, y ∈ ℕ.

Then:

  N = (6x + 1)(6y − 1) = 36xy − 6x + 6y − 1 = 6(6xy − x + y) − 1.

So N = 6k − 1 with k = 6xy − x + y.

Let a = x, b = −y. Then:

  6ab + a + b = 6x(−y) + x − y = −6xy + x − y = –k.

Thus, k = |6ab + a + b|, and k ∈ K_composite.

Therefore, every composite N ≡ −1 (mod 6) has index k ∈ K_composite.

Conclusion

In all cases, whether N ≡ 1 or N ≡ –1 (mod 6), if N is composite, then its associated index k = (N – 1)/6 or (N + 1)/6 is in the set K_composite. Therefore, the filtering model using the form k = |6xy + x + y| correctly and completely identifies all indices corresponding to composite numbers of the form 6k ± 1.

2.3. Equivalence of Diophantine Approach and Sieve of Eratosthenes

The primary question is whether the brute force method which first generates all integers expressible as |6xy + x + y| and then determines the complement set (the set of twin prime indices) is equivalent to a trusted and established method like the Sieve of Eratosthenes. A direct comparison of their outputs for an analysis up to k = 1,000,000,000 confirms that they are identical in every respect.

MetricBrute-Force Method (v3.0)Sieve of Eratosthenes (SoE)Result
Integers Found17,244,40817,244,408Identical
Last Integer n999,999,975999,999,975Identical
Last Twin Prime Pair5999999849,
5999999851
5999999849,
5999999851
Identical
Point-Estimate K7.4056767.405676Identical
Extrapolated K7.7085157.708515Identical
R-Squared of Fit0.9938790.993879Identical
Table validating equivalence of Diophantine hypothesis with outputs of Sieve of Eratosthenes-based model.

The lists of uncreatable integers produced are also a perfect match, from the first [1, 2, 3, 5, 7, …] to the last […, 999999858, 999999975].

This perfect correspondence up to a very large limit provides strong empirical evidence for the initial hypothesis. It validates that the set of integers not expressible by k = |6xy + x + y| is, in fact, the set of indices that generate twin primes of the form (6k-1, 6k+1). The brute-force method serves as the essential, rigorous proof, while the Sieve method serves as its efficient implementation.

2.4. Dual Sieve in k-Space

2.4.1. k-space

To see this structure, we must shift our perspective.

  • N-Space is the familiar number line (1, 2, 3, …). Primes appear on this line with chaotic, irregular spacing. Finding patterns here is difficult.
  • K-Space is the perfectly regular sequence of indices k (1, 2, 3, …) used in the formula for twin primes, (6k-1, 6k+1).

By moving our analysis to k-space, we change the problem from finding irregularly spaced primes to a much simpler question: “Which of these perfectly regular k values have the special property of generating a prime pair?

k Range: k>=10n Range: (k*6)+1No of Primes Less than or Equal to n in RangeNo of Twin Prime Pairs (6k-1,6k+1) Less than or Equal to n in Range
1061186
10060111026
1,0006,001783142
10,00060,0016,057810
100,000600,00149,0985,330
1,000,0006,000,001412,84937,915
10,000,00060,000,0013,562,115280,557
100,000,000600,000,00131,324,7042,166,300
1,000,000,0006,000,000,001279,545,36917,244,408
10,000,000,00060,000,000,0012,524,038,155140,494,396
100,000,000,000600,000,000,00123,007,501,7861,166,916,932
1,000,000,000,0006,000,000,000,001211,381,427,0399,846,842,483
Clarifying relationships of n space and k space for primes and twin primes.

2.4.2. The Dual Sieve

The model uses modular arithmetic to determine exactly which k values to eliminate.
For any given sieving prime p > 3:

  • For Sieve 1, we find k where 6k - 1 is a multiple of p.
    This means solving 6k - 1 ≡ 0 (mod p), which gives the rule:
    Eliminate all k that follow the pattern k ≡ 6⁻¹ (mod p).
  • For Sieve 2, we find k where 6k + 1 is a multiple of p.
    This means solving 6k + 1 ≡ 0 (mod p), which gives the rule:
    Eliminate all k that follow the pattern k ≡ -6⁻¹ (mod p).

The most important mathematical insight is this: for any prime p > 3, the
two solutions 6⁻¹ and -6⁻¹ are ALWAYS different. They can never be the same.

2.4.3. Technical Note – Solution for Self Sieving Anomalies

Understanding the “self-sieving error” and its solution are key to understanding why our final sieve is both fast and mathematically correct. Here is the detailed technical solution.

A. The Problem: The “Self-Sieving” Error.

The self-sieving error is a logical flaw in a naive sieve model where the sieving process incorrectly eliminates the very k indices that generate the prime numbers it uses as tools. A naive sieve operates on a simple principle: “For a sieving prime p, eliminate every k where 6k-1 or 6k+1 is a multiple of p. “This leads to an error. For example: The index k=1 generates the twin prime pair (5, 7). It should be a survivor. To check for composites, we use the sieving prime p=5.The naive sieve’s rule is: “Eliminate k if 6k-1 is a multiple of 5.”For k=1, 6(1)-1 = 5. Since 5 is a multiple of 5, the naive sieve incorrectly eliminates k=1.This results in a systematic undercount of the true number of twin prime indices.

B. The Root Cause: Confusing “Multiple” with “Composite “

The core of the error is a subtle confusion between two different mathematical concepts: A multiple of p: Any number m * p where m is an integer ≥ 1. (e.g., for p=5, the multiples are 5, 10, 15, 20…)A composite multiple of p: Any number m * p where m is an integer ≥ 2. (e.g., for p=5, the composite multiples are 10, 15, 20…)The prime p itself is a multiple of p, but it is not a composite number. The goal of the sieve is to eliminate k indices that generate composites, not primes.

C. The Technical Solution: The “Greater Than p” Principle

The definitive solution is to refine the sieving rule with one precise condition. We eliminate an index k if and only if the number it generates is a composite multiple of a sieving prime p.This leads to a simple, powerful test: a number N is a composite multiple of a prime p if and only if:N % p == 0 (It is a multiple of p)N > p (It is strictly greater than p)By applying this principle, we can derive the exact, corrected starting point for every sieving operation.

D. Implementation in Code

The “Greater Than p” principle is applied slightly differently to the two sieves (6k-1 and 6k+1) because they have different mathematical properties. Case 1: Sieve for 6k-1 Composites Rule: We eliminate k where 6k – 1 ≡ 0 (mod p).First Instance: The first k that satisfies this is k_start_1 = pow(6, -1, p).Analysis: Let’s examine the number generated by this first k: N = 6 * k_start_1 – 1. It can be mathematically proven that for any prime p > 3, this value N is always equal to p itself. Conclusion: Since the number generated is p, it is not > p. Therefore, it is not a composite. The first instance, k_start_1, must never be eliminated by this sieve.

Correct Action: We must always skip the first instance and begin the elimination process at the second instance, which is guaranteed to be a composite: k_start_1 + p.

2.4.4. The Code for the Solution (Sieve 1):

# Calculate the first instance of the rule
k_start_1 = mod_inv_6 + p

# The number generated (6*k_start_1-1) is always p itself.
# Since p is not a composite, we start at the next instance.
sieve_point_1 = k_start_1 + p 

# Perform the sieve, correctly skipping the self-sieving case.
for k in range(sieve_point_1, k_max + 1, p):
    k_space[k] = False
  Case 2: Sieve for 6k+1 CompositesRule: We eliminate k where 6k + 1 ≡ 0 (mod p).

First Instance: The first k is k_start_2 = p - pow(6, -1, p).

Analysis: Let's examine the number N = 6 * k_start_2 + 1. This value is not always equal to p.

Example p=7: k_start_2 = 1. N = 6(1)+1 = 7. 

Here N is not > p, so k=1 should not be eliminated.

Example p=5: k_start_2 = 4. N = 6(4)+1 = 25. 

Here N is > p, so 25 is a composite, and k=4 must be eliminated.

Correct Action: We must explicitly check if 6 * k_start_2 + 1 > p. 

If it is, k_start_2 generates a composite and we start sieving there. 

Otherwise, it generates p itself, and we must start at the next instance, k_start_2 + p.

2.4.5. The Code for the Solution (Sieve 2):

# Calculate the first instance of the rule
k_start_2 = p - mod_inv_6

# Explicitly check if the number generated is a composite.
if (6 * k_start_2 + 1) > p:
    # It's a composite (like k=4 for p=5 -> 25). Start here.
    sieve_point_2 = k_start_2
else:
    # It's the prime p itself (like k=1 for p=7 -> 7). Start at the next one.
    sieve_point_2 = k_start_2 + p

# Perform the sieve with the correctly determined starting point.
for k in range(sieve_point_2, k_max + 1, p):
    k_space[k] = False

This precise, case-by-case application of the “Greater Than p” principle is the complete technical solution to the self-sieving error, ensuring that the sieve is both theoretically sound and empirically perfect.

3.0 – Code Implementation

import math
import time
import numpy as np
import multiprocessing
import os

def generate_primes_up_to(limit):
    """Generates primes up to a limit using a NumPy Sieve of Eratosthenes."""
    if limit < 2: return np.array([], dtype=np.int64)
    is_prime = np.ones(limit + 1, dtype=bool); is_prime[0:2] = False
    for p in range(2, int(np.sqrt(limit)) + 1):
        if is_prime[p]: is_prime[p*p:limit+1:p] = False
    return np.where(is_prime)[0]

def sieve_chunk_for_count(args):
    """Worker for Pass 1: Sieves a chunk and returns only the count and largest k."""
    k_start, k_end, sieving_primes = args
    SEGMENT_SIZE, count, largest_k = 2**24, 0, 0
    next_k_hits_1 = np.zeros_like(sieving_primes, dtype=np.int64)
    next_k_hits_2 = np.zeros_like(sieving_primes, dtype=np.int64)
    for i, p_np in enumerate(sieving_primes):
        p = int(p_np); mod_inv_6 = pow(6, -1, p)
        abs_k_start_1, abs_k_start_2 = mod_inv_6 + p, p - mod_inv_6
        if (6 * abs_k_start_2 + 1) <= p: abs_k_start_2 += p
        
        if k_start <= abs_k_start_1: next_k_hits_1[i] = abs_k_start_1
        else: offset_1 = (k_start - abs_k_start_1) % p; next_k_hits_1[i] = k_start + (p - offset_1 if offset_1 != 0 else 0)
        
        if k_start <= abs_k_start_2: next_k_hits_2[i] = abs_k_start_2
        else: offset_2 = (k_start - abs_k_start_2) % p; next_k_hits_2[i] = k_start + (p - offset_2 if offset_2 != 0 else 0)

    for k_low in range(k_start, k_end + 1, SEGMENT_SIZE):
        k_high = min(k_low + SEGMENT_SIZE - 1, k_end); segment_len = k_high - k_low + 1
        segment = np.ones(segment_len, dtype=bool)
        for i, p_np in enumerate(sieving_primes):
            p = int(p_np)
            start_idx_1 = next_k_hits_1[i] - k_low
            if start_idx_1 < segment_len: segment[start_idx_1::p] = False; next_k_hits_1[i] += p * ((segment_len - 1 - start_idx_1) // p + 1)
            start_idx_2 = next_k_hits_2[i] - k_low
            if start_idx_2 < segment_len: segment[start_idx_2::p] = False; next_k_hits_2[i] += p * ((segment_len - 1 - start_idx_2) // p + 1)
        survivors = np.where(segment)[0]
        if survivors.size > 0: count += survivors.size; largest_k = max(largest_k, k_low + survivors[-1])
    return count, largest_k

def sieve_and_analyze_chunk_stable(args):
    """
    Worker for Pass 2:
    Calculates intermediate statistics (count, means, and sum of squared deviations M2)
    for its chunk, avoiding large sums that cause precision loss.
    """
    k_start, k_end, sieving_primes, c_offset = args
    SEGMENT_SIZE = 2**24
    
    n, mean_x, mean_y, M2_x, M2_y, M2_xy = 0, 0.0, 0.0, 0.0, 0.0, 0.0
    
    next_k_hits_1 = np.zeros_like(sieving_primes, dtype=np.int64)
    next_k_hits_2 = np.zeros_like(sieving_primes, dtype=np.int64)
    for i, p_np in enumerate(sieving_primes):
        p = int(p_np); mod_inv_6 = pow(6, -1, p)
        abs_k_start_1, abs_k_start_2 = mod_inv_6 + p, p - mod_inv_6
        if (6 * abs_k_start_2 + 1) <= p: abs_k_start_2 += p
        
        if k_start <= abs_k_start_1: next_k_hits_1[i] = abs_k_start_1
        else: offset_1 = (k_start - abs_k_start_1) % p; next_k_hits_1[i] = k_start + (p - offset_1 if offset_1 != 0 else 0)
        
        if k_start <= abs_k_start_2: next_k_hits_2[i] = abs_k_start_2
        else: offset_2 = (k_start - abs_k_start_2) % p; next_k_hits_2[i] = k_start + (p - offset_2 if offset_2 != 0 else 0)
            
    current_local_count = 0
    for k_low in range(k_start, k_end + 1, SEGMENT_SIZE):
        k_high = min(k_low + SEGMENT_SIZE - 1, k_end); segment_len = k_high - k_low + 1
        segment = np.ones(segment_len, dtype=bool)
        for i, p_np in enumerate(sieving_primes):
            p = int(p_np)
            start_idx_1 = next_k_hits_1[i] - k_low
            if start_idx_1 < segment_len: segment[start_idx_1::p] = False; next_k_hits_1[i] += p * ((segment_len - 1 - start_idx_1) // p + 1)
            start_idx_2 = next_k_hits_2[i] - k_low
            if start_idx_2 < segment_len: segment[start_idx_2::p] = False; next_k_hits_2[i] += p * ((segment_len - 1 - start_idx_2) // p + 1)
        survivors = np.where(segment)[0]
        if survivors.size > 0:
            c_vals = c_offset + current_local_count + np.arange(1, survivors.size + 1)
            n_vals = k_low + survivors
            valid_mask = c_vals > 10
            if np.any(valid_mask):
                c_vals_reg, n_vals_reg = c_vals[valid_mask].astype(np.float64), n_vals[valid_mask].astype(np.float64)
                log_6n = np.log(6 * n_vals_reg); y_vals = 1 / log_6n
                z_vals = (c_vals_reg / n_vals_reg) * (log_6n ** 2)
                
                # --- Welford's online algorithm for combining stats stably ---
                for i in range(len(z_vals)):
                    n += 1; x, y = z_vals[i], y_vals[i]
                    delta_x, delta_y = x - mean_x, y - mean_y
                    mean_x += delta_x / n; mean_y += delta_y / n
                    M2_x += delta_x * (x - mean_x)
                    M2_y += delta_y * (y - mean_y)
                    M2_xy += delta_x * (y - mean_y)
            current_local_count += survivors.size
    return n, mean_x, mean_y, M2_x, M2_y, M2_xy

def main():
    while True:
        try:
            k_input = input(f"Enter the maximum value for k (or 'Q' to quit): ")
            if k_input.strip().lower() == 'q': break
            k_max = int(k_input)
            if k_max < 1: print("Please enter an integer greater than 0."); continue
        except (ValueError, RuntimeError): print("Invalid input. Please enter a valid integer."); continue

        start_time = time.perf_counter()
        sieve_limit = int(math.sqrt(6 * k_max + 1))
        sieving_primes = generate_primes_up_to(sieve_limit)
        sieving_primes = sieving_primes[sieving_primes > 3]
        num_processes = os.cpu_count() or 1
        chunk_size = (k_max + num_processes - 1) // num_processes
        tasks = [(i*chunk_size+1, min((i+1)*chunk_size, k_max), sieving_primes) for i in range(num_processes) if i*chunk_size+1 <= k_max]
        
        print(f"\nAnalyzing k-space up to k = {k_max:,} using {len(tasks)} CPU cores...")
        
        print("Pass 1/2: Counting twin prime indices...")
        with multiprocessing.Pool(processes=num_processes) as pool:
            pass1_results = pool.map(sieve_chunk_for_count, tasks)
        
        total_count = sum(res[0] for res in pass1_results)
        global_largest_k = max(res[1] for res in pass1_results) if pass1_results else 0
        
        pass1_end_time = time.perf_counter()
        
        # --- INTERMEDIATE OUTPUT AFTER PASS 1 ---
        print("\n--- [ Pass 1 Results ] ---")
        print(f"Total twin prime indices found: {total_count:,}")
        if global_largest_k > 0:
            p1, p2 = 6 * global_largest_k - 1, 6 * global_largest_k + 1
            print(f"Largest pair found: ({p1:,}, {p2:,}) from k={global_largest_k:,}")
        print(f"Time for Pass 1 (Count): {pass1_end_time - start_time:.4f} seconds")
        # --- END OF INTERMEDIATE OUTPUT ---

        print("\nPass 2/2: Performing regression analysis...")
        c_offsets = np.cumsum([0] + [res[0] for res in pass1_results[:-1]], dtype=np.int64)
        analysis_tasks = [(*task, c_offset) for task, c_offset in zip(tasks, c_offsets)]
        with multiprocessing.Pool(processes=num_processes) as pool:
            pass2_results = pool.map(sieve_and_analyze_chunk_stable, analysis_tasks)

        # --- Final combination of results from all chunks ---
        (n_A, mean_x_A, mean_y_A, M2_x_A, M2_y_A, M2_xy_A) = pass2_results[0]
        for i in range(1, len(pass2_results)):
            (n_B, mean_x_B, mean_y_B, M2_x_B, M2_y_B, M2_xy_B) = pass2_results[i]
            if n_B == 0: continue
            n_C = n_A + n_B
            delta_x, delta_y = mean_x_B - mean_x_A, mean_y_B - mean_y_A
            mean_x_C = mean_x_A + delta_x * n_B / n_C
            mean_y_C = mean_y_A + delta_y * n_B / n_C
            M2_x_C = M2_x_A + M2_x_B + (delta_x**2) * n_A * n_B / n_C
            M2_y_C = M2_y_A + M2_y_B + (delta_y**2) * n_A * n_B / n_C
            M2_xy_C = M2_xy_A + M2_xy_B + delta_x * delta_y * n_A * n_B / n_C
            n_A, mean_x_A, mean_y_A, M2_x_A, M2_y_A, M2_xy_A = n_C, mean_x_C, mean_y_C, M2_x_C, M2_y_C, M2_xy_C
        
        end_time = time.perf_counter()
        
        print("\n--- [ Final Analysis Complete ] ---")
        print(f"Total twin prime indices found: {total_count:,}") # Repeated for clarity in final summary
        
        print("\n--- Linearization Analysis ---")
        if n_A > 1 and M2_x_A != 0 and M2_y_A != 0:
            m = M2_xy_A / M2_x_A
            b = mean_y_A - m * mean_x_A
            r_squared = (M2_xy_A**2) / (M2_x_A * M2_y_A)
            extrapolated_K = -b / m if m != 0 else 0
            theoretical_K = 12 * 0.66016181584
            print(f"Regression model: 1/ln(6n) = {m:.8f} * Z(n) + {b:.8f}")
            print(f"R-squared of the fit:                     {r_squared:.8f}")
            print(f"Extrapolated Constant K (from x-intercept): {extrapolated_K:.6f}")
            print(f"Theoretical Constant K = 12 * C₂:           {theoretical_K:.6f}")
        else: print("Not enough data to perform linearization analysis.")
        
        print(f"\nTotal time to complete operation: {end_time - start_time:.4f} seconds\n" + "-"*35 + "\n")

if __name__ == "__main__":
    multiprocessing.freeze_support()
    main()

4.0 – Example Output

Enter the maximum value for k (or 'Q' to quit): 100

Analyzing k-space up to k = 100 using 25 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 26
Largest pair found: (599, 601) from k=100
Time for Pass 1 (Count): 0.2100 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 26

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.00849431 * Z(n) + 0.07877865
R-squared of the fit:                     0.11630115
Extrapolated Constant K (from x-intercept): -9.274286
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 0.4029 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 1000

Analyzing k-space up to k = 1,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 142
Largest pair found: (5,879, 5,881) from k=980
Time for Pass 1 (Count): 0.2012 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 142

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.01693043 * Z(n) + -0.04807548
R-squared of the fit:                     0.13349087
Extrapolated Constant K (from x-intercept): 2.839589
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 0.4072 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 10000

Analyzing k-space up to k = 10,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 810
Largest pair found: (59,669, 59,671) from k=9,945
Time for Pass 1 (Count): 0.2099 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 810

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.03525905 * Z(n) + -0.25389774
R-squared of the fit:                     0.64462365
Extrapolated Constant K (from x-intercept): 7.200925
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 0.4182 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 100000

Analyzing k-space up to k = 100,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 5,330
Largest pair found: (599,939, 599,941) from k=99,990
Time for Pass 1 (Count): 0.2070 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 5,330

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.03863460 * Z(n) + -0.28904800
R-squared of the fit:                     0.86921234
Extrapolated Constant K (from x-intercept): 7.481583
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 0.4129 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 1000000

Analyzing k-space up to k = 1,000,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 37,915
Largest pair found: (5,999,921, 5,999,923) from k=999,987
Time for Pass 1 (Count): 0.2077 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 37,915

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.04506211 * Z(n) + -0.35246166
R-squared of the fit:                     0.91657519
Extrapolated Constant K (from x-intercept): 7.821685
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 0.4261 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 10000000

Analyzing k-space up to k = 10,000,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 280,557
Largest pair found: (59,999,981, 59,999,983) from k=9,999,997
Time for Pass 1 (Count): 0.2262 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 280,557

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.03886293 * Z(n) + -0.29433480
R-squared of the fit:                     0.96624871
Extrapolated Constant K (from x-intercept): 7.573665
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 0.4709 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 100000000

Analyzing k-space up to k = 100,000,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 2,166,300
Largest pair found: (599,999,429, 599,999,431) from k=99,999,905
Time for Pass 1 (Count): 0.3248 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 2,166,300

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.03907215 * Z(n) + -0.29611628
R-squared of the fit:                     0.99003734
Extrapolated Constant K (from x-intercept): 7.578705
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 0.7504 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 1000000000

Analyzing k-space up to k = 1,000,000,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 17,244,408
Largest pair found: (5,999,999,849, 5,999,999,851) from k=999,999,975
Time for Pass 1 (Count): 4.1792 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 17,244,408

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.04314954 * Z(n) + -0.33261889
R-squared of the fit:                     0.99387908
Extrapolated Constant K (from x-intercept): 7.708515
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 8.6777 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 10000000000

Analyzing k-space up to k = 10,000,000,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 140,494,396
Largest pair found: (59,999,999,417, 59,999,999,419) from k=9,999,999,903
Time for Pass 1 (Count): 44.2765 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 140,494,396

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.04571128 * Z(n) + -0.35521590
R-squared of the fit:                     0.99785579
Extrapolated Constant K (from x-intercept): 7.770859
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 89.4527 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 100000000000

Analyzing k-space up to k = 100,000,000,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 1,166,916,932
Largest pair found: (599,999,999,771, 599,999,999,773) from k=99,999,999,962
Time for Pass 1 (Count): 470.6074 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 1,166,916,932

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.04742660 * Z(n) + -0.37014782
R-squared of the fit:                     0.99922866
Extrapolated Constant K (from x-intercept): 7.804646
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 953.2119 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit): 1000000000000

Analyzing k-space up to k = 1,000,000,000,000 using 28 CPU cores...
Pass 1/2: Counting twin prime indices...

--- [ Pass 1 Results ] ---
Total twin prime indices found: 9,846,842,483
Largest pair found: (5,999,999,999,627, 5,999,999,999,629) from k=999,999,999,938
Time for Pass 1 (Count): 4996.8203 seconds

Pass 2/2: Performing regression analysis...

--- [ Final Analysis Complete ] ---
Total twin prime indices found: 9,846,842,483

--- Linearization Analysis ---
Regression model: 1/ln(6n) = 0.04874601 * Z(n) + -0.38152162
R-squared of the fit:                     0.99964915
Extrapolated Constant K (from x-intercept): 7.826726
Theoretical Constant K = 12 * C₂:           7.921942

Total time to complete operation: 10295.1727 seconds
-----------------------------------

Enter the maximum value for k (or 'Q' to quit):