|
1 | 1 | import math |
2 | 2 |
|
3 | | -class PrimeElevationSieve: |
4 | | - """ |
5 | | - An implementation of a targeted primality search algorithm. |
6 | | - Utilizes an adaptive step function and parametric elevation (n) |
7 | | - to identify primes in the form P ≡ ±1 (mod 2kX). |
8 | | - """ |
9 | | - |
| 3 | +class PrimeSieve: |
10 | 4 | @staticmethod |
11 | | - def is_prime(m): |
12 | | - if m < 2: return False |
13 | | - if m % 2 == 0 or m % 3 == 0: return m in (2, 3) |
14 | | - for i in range(5, int(m**0.5) + 1, 6): |
15 | | - if m % i == 0 or m % (i + 2) == 0: return False |
| 5 | + def check(n): |
| 6 | + if n < 2: return False |
| 7 | + if n in (2, 3): return True |
| 8 | + if n % 2 == 0 or n % 3 == 0: return False |
| 9 | + for i in range(5, int(n**0.5) + 1, 6): |
| 10 | + if n % i == 0 or n % (i + 2) == 0: return False |
16 | 11 | return True |
17 | 12 |
|
18 | | - def hunt(self, X): |
19 | | - print(f"\n[RESEARCH LOG] Analyzing Base X = {X}") |
20 | | - print("-" * 50) |
21 | | - |
22 | | - # Define the adaptive step: s = ⌈X/20⌉ |
23 | | - s = math.ceil(X / 20) |
24 | | - n = 0 |
| 13 | + def solve(self, X): |
| 14 | + # Step Boundary: m >= ceil(X/20) |
| 15 | + m_start = math.ceil(X / 20) |
| 16 | + k = m_start |
25 | 17 |
|
26 | 18 | while True: |
27 | | - # Multiplier k = 2(s + n) |
28 | | - k = 2 * (s + n) |
29 | | - candidates = [k * X - 1, k * X + 1] |
30 | | - |
31 | | - results = [self.is_prime(p) for p in candidates] |
| 19 | + # Candidate set S = {2kX - 1, 2kX + 1} |
| 20 | + candidates = [(2 * k * X) - 1, (2 * k * X) + 1] |
| 21 | + primes = [p for p in candidates if self.check(p)] |
32 | 22 |
|
33 | | - print(f"Iteration n={n}: Testing P ≡ ±1 (mod {k*X}) -> {candidates}") |
34 | | - |
35 | | - if any(results): |
36 | | - return n, k, candidates, results |
37 | | - n += 1 |
| 23 | + if primes: |
| 24 | + # P = min(S intersect Primes) |
| 25 | + return min(primes), k |
| 26 | + k += 1 |
38 | 27 |
|
39 | 28 | def main(): |
40 | | - print("NUMERICAL ANALYSIS: ADAPTIVE PRIME GENERATION") |
41 | | - X = int(input("Enter Domain Parameter (X): ")) |
| 29 | + print("--- 📐 FORMAL PARAMETRIC ANALYSIS ---") |
| 30 | + X = int(input("Define Domain Parameter X: ")) |
42 | 31 |
|
43 | | - sieve = PrimeElevationSieve() |
44 | | - n, k, candidates, results = sieve.hunt(X) |
| 32 | + engine = PrimeSieve() |
| 33 | + P, k_star = engine.solve(X) |
45 | 34 |
|
46 | | - print("\n" + "="*50) |
47 | | - print(f"CONVERGENCE ACHIEVED AT n = {n}") |
48 | | - for val, prime_status in zip(candidates, results): |
49 | | - status = "PRIME (∈ ℙ)" if prime_status else "COMPOSITE" |
50 | | - print(f" P = {val} : {status}") |
51 | | - print("="*50) |
| 35 | + print(f"\nCONVERGENCE: P = {P} at k* = {k_star}") |
52 | 36 |
|
53 | | - print("\n[FORMAL THEORY: THE ADAPTIVE SIEVE]") |
54 | | - print("1. RESIDUE CLASSES: The formula forces P ≡ ±1 (mod 2X).") |
55 | | - print(" By Dirichlet's Theorem, there exist infinitely many primes") |
56 | | - print(" in this progression, as gcd(±1, 2X) = 1.") |
57 | | - print("\n2. COMPOSITE EXCLUSION:") |
58 | | - print(" The term 2(s+n)X creates an even base, ensuring P is odd.") |
59 | | - print(" Furthermore, P is coprime to X, effectively 'sieving out'") |
60 | | - print(" all prime factors of X from the candidate pool.") |
61 | | - print("\n3. DENSITY ADAPTATION:") |
62 | | - print(" The function s = ⌈X/20⌉ accounts for the logarithmic") |
63 | | - print(" distribution of primes π(x) ≈ x/ln(x), increasing the") |
64 | | - print(" search interval as X moves toward infinity.") |
| 37 | + print("\n" + "="*60) |
| 38 | + print("📐 FORMAL THEORY: THE ADAPTIVE SIEVE") |
| 39 | + print("-" * 60) |
| 40 | + print("• RESIDUE CLASSES: Candidates are restricted to P ≡ ±1 (mod 2X).") |
| 41 | + print(" Since gcd(±1, 2X) = 1, Dirichlet’s Theorem guarantees prime density.") |
| 42 | + print("• PARAMETRIC MINIMIZATION: P is the infimum of the set intersection.") |
| 43 | + print(" k is the minimal integer m where (2mX ± 1) ∩ ℙ is non-empty.") |
| 44 | + print("• COPRIMALITY: The mapping ensures P is coprime to X (gcd(P, X) = 1).") |
| 45 | + print("="*60) |
65 | 46 |
|
66 | 47 | if __name__ == "__main__": |
67 | 48 | main() |
68 | | - |
0 commit comments