File size: 1,970 Bytes
edae06c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

import math

class PrimePhysics:
    """
    Protocol 13: SPCW Physics Engine.
    Implements learned knowledge from Visual Artifacts (Prime Gaps & Frequency).
    """

    @staticmethod
    def calculate_gaps(primes):
        """
        Calculates Prime Gaps G_n = P_{n+1} - P_n.
        Returns a list of dictionaries.
        """
        gaps = []
        for i in range(len(primes) - 1):
            p_n = primes[i]
            p_next = primes[i+1]
            g_n = p_next - p_n
            
            # Metric: Frequency f = (P_n * pi) / G_n
            # Avoid division by zero (G_n is always >= 1 for primes > 2)
            freq = (p_n * math.pi) / g_n
            
            gaps.append({
                "p_n": p_n,
                "p_next": p_next,
                "g_n": g_n,
                "frequency": round(freq, 4)
            })
        return gaps

    @staticmethod
    def get_resonance_frequency(node_id, primes_map):
        """
        Returns the frequency 'f' for a given Prime Node.
        """
        if node_id not in primes_map:
            return 0.0 # Composite
            
        # Find index
        # This is O(N), for production use precise index map
        try:
            # Simple scan for prototype
            idx = primes_map.index(node_id)
            if idx >= len(primes_map) - 1:
                return 0.0 # Last prime has no next gap yet
                
            p_n = primes_map[idx]
            p_next = primes_map[idx+1]
            g_n = p_next - p_n
            return (p_n * math.pi) / g_n
        except ValueError:
            return 0.0

if __name__ == "__main__":
    # Test Data
    test_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
    gaps = PrimePhysics.calculate_gaps(test_primes)
    
    print(f"{'Pn':<5} | {'Pn+1':<5} | {'Gap':<3} | {'Frequency (Hz)':<15}")
    print("-" * 40)
    for g in gaps:
        print(f"{g['p_n']:<5} | {g['p_next']:<5} | {g['g_n']:<3} | {g['frequency']:<15}")