|
|
| import sys |
| import os |
| import numpy as np |
|
|
| |
| sys.path.append(os.path.join(os.path.dirname(__file__), '../tests/tensor_lenia/lib')) |
|
|
| from hypergraph import SimpleWolframSystem |
| from operators import apply_asymmetric_laplacian, apply_laplacian |
|
|
| def run_turing_gate_experiment(steps=100): |
| print("--- EXPERIMENT 15: TURING MECHANICS (Solitonic Turing Machine) ---") |
| |
| |
| |
| |
| nodes = list(range(10)) |
| adj = {i: {(i-1)%10, (i+1)%10} for i in nodes} |
| |
| |
| class TapeGraph: |
| def get_adjacency_list(self): return adj |
| |
| graph = TapeGraph() |
| |
| |
| |
| |
| phi = {i: 0.0 for i in nodes} |
| phi[0] = 2.0 |
| |
| bit_state = {i: 0.0 for i in nodes} |
| |
| |
| |
| flow_weights = {} |
| for i in nodes: |
| flow_weights[(i, (i+1)%10)] = 0.8 |
| flow_weights[((i+1)%10, i)] = 0.2 |
| |
| dt = 0.1 |
| diffusion = 0.02 |
| advection_speed = 0.5 |
| gate_node = 5 |
| |
| with open("exp15_turing_machine.log", "w") as f: |
| f.write("--- EXPERIMENT 15: TURING MECHANICS (Solitonic Turing Machine) ---\n") |
|
|
| def log(msg): |
| print(msg) |
| with open("exp15_turing_machine.log", "a") as f: |
| f.write(msg + "\n") |
|
|
| log(f"Moving Soliton towards Gate at node {gate_node}...") |
| |
| history_gate = [] |
| |
| for t in range(steps): |
| |
| adv = apply_asymmetric_laplacian(phi, graph, flow_weights) |
| lap = apply_laplacian(phi, graph) |
| |
| new_phi = {} |
| for i in nodes: |
| change = advection_speed * adv[i] + diffusion * lap[i] |
| val = phi[i] + change * dt |
| new_phi[i] = max(0.0, min(2.0, val)) |
| phi = new_phi |
| |
| |
| p = bit_state[gate_node] |
| signal = phi[gate_node] |
| |
| |
| stabilization = 10.0 * p * (p - 0.5) * (1.0 - p) |
| |
| |
| coupling = 15.0 * signal * (1.0 - p) |
| |
| d_state = (stabilization + coupling) * dt |
| bit_state[gate_node] = max(0.0, min(1.0, p + d_state)) |
| |
| history_gate.append(bit_state[gate_node]) |
| |
| if (t+1) % 20 == 0: |
| active_node = max(phi, key=phi.get) |
| log(f" Step {t+1}: Soliton at ~{active_node}, Gate State={bit_state[gate_node]:.4f}") |
|
|
| log("\nSimulation Final Result:") |
| log(f" Final Gate State: {bit_state[gate_node]:.4f}") |
| |
| |
| import matplotlib.pyplot as plt |
| plt.figure(figsize=(10, 4)) |
| plt.plot(history_gate, label='Memory Bit State (Node 5)', color='purple', linewidth=2) |
| plt.axhline(y=0.0, color='gray', linestyle=':', label='State 0') |
| plt.axhline(y=1.0, color='gray', linestyle=':', label='State 1') |
| plt.title('Experiment 15: Solitonic Memory Writes') |
| plt.ylabel('Bit State') |
| plt.xlabel('Time Step') |
| plt.legend() |
| plt.grid(True, alpha=0.3) |
| plt.savefig('exp15_turing_machine.png') |
| log("Saved visualization to exp15_turing_machine.png") |
| |
| if bit_state[gate_node] > 0.9: |
| log("\n[!!! SUCCESS !!!] Bit Flip Detected.") |
| log("The moving soliton successfully updated the memory state of the gate.") |
| log("This proves the feasibility of a solitonic Turing Machine.") |
| else: |
| log("\n[FAIL] The gate state did not transition.") |
|
|
| if __name__ == "__main__": |
| run_turing_gate_experiment() |
|
|