-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstablecyclelimit.py
132 lines (112 loc) · 4.12 KB
/
stablecyclelimit.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from decimal import Decimal, getcontext
import math
getcontext().prec = 28 # High precision for stability
#############################################
# Minimal Complex Arithmetic with Decimal
#############################################
class ComplexDecimal:
def __init__(self, real, imag=Decimal('0')):
self.real = Decimal(real)
self.imag = Decimal(imag)
def __add__(self, other):
return ComplexDecimal(self.real + other.real, self.imag + other.imag)
def __sub__(self, other):
return ComplexDecimal(self.real - other.real, self.imag - other.imag)
def __mul__(self, other):
return ComplexDecimal(
self.real * other.real - self.imag * other.imag,
self.real * other.imag + self.imag * other.real
)
def __truediv__(self, other):
denom = other.real * other.real + other.imag * other.imag
num = self * other.conjugate()
return ComplexDecimal(num.real / denom, num.imag / denom)
def conjugate(self):
return ComplexDecimal(self.real, -self.imag)
def abs(self):
return (self.real * self.real + self.imag * self.imag).sqrt()
def __repr__(self):
return f"({self.real}+{self.imag}i)"
#############################################
# Epistemic Phase Space Kernel (Q)
#############################################
class Q:
"""
Epistemic feedback kernel.
- ψ: Injects novelty (perturbation)
- π: Applies damping (momentum retention)
"""
def __init__(self, state: ComplexDecimal, ψ, π):
self.state = state
self.ψ = ψ
self.π = π
def normalize(self):
"""Normalize state to a unit cycle with slight adaptive energy loss."""
norm = self.state.abs()
if norm > 0:
self.state = ComplexDecimal(self.state.real / norm, self.state.imag / norm)
return self
def evolve(self):
"""Evolve with ψ and π, ensuring periodic attractor-like behavior."""
new_state = self.ψ(self.state) + self.π(self.state)
self.state = new_state
return self.normalize()
def __repr__(self):
return f"Q(state={self.state})"
#############################################
# ψ (Novelty) - Oscillatory Phase Perturbation
#############################################
def novel(x: ComplexDecimal) -> ComplexDecimal:
"""
Introduces an oscillatory perturbation using a rotational factor.
"""
angle = Decimal('0.1') # Small rotation factor
rot = ComplexDecimal(d_cos(angle), d_sin(angle)) # e^(iθ)
return x * rot
#############################################
# π (Momentum) - Nonlinear Damping
#############################################
def inertia(x: ComplexDecimal) -> ComplexDecimal:
"""
Applies non-linear damping to stabilize limit cycle behavior.
"""
entropy = x.abs() # Proxy for information density
scaling = Decimal('0.98') + Decimal('0.02') * entropy # Soft damping
return ComplexDecimal(x.real * scaling, x.imag * scaling)
#############################################
# Decimal-Based Trig Functions (Taylor Series)
#############################################
def d_sin(x, terms=10):
x = Decimal(x)
result = Decimal(0)
sign = Decimal(1)
x_power = x
factorial = Decimal(1)
for n in range(1, 2*terms, 2):
result += sign * x_power / factorial
sign *= -1
x_power *= x * x
factorial *= Decimal(n+1) * Decimal(n+2)
return result
def d_cos(x, terms=10):
x = Decimal(x)
result = Decimal(0)
sign = Decimal(1)
x_power = Decimal(1)
factorial = Decimal(1)
for n in range(0, 2*terms, 2):
result += sign * x_power / factorial
sign *= -1
x_power *= x * x
factorial *= Decimal(n+1) * Decimal(n+2)
return result
#############################################
# Run the System: Observe Limit Cycles
#############################################
if __name__ == "__main__":
q = Q(ComplexDecimal('1', '0'), novel, inertia)
print("Initial Q state:")
print(q)
for i in range(2000):
q.evolve()
print(f"Step {i+1}: {q}")