ANXLOG commited on
Commit
23f5b34
·
verified ·
1 Parent(s): f10ca76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -60
app.py CHANGED
@@ -4,87 +4,156 @@ import plotly.graph_objects as go
4
  import sympy
5
  import networkx as nx
6
 
7
- # --- MODULE 1: SPCW LOGIC (The Primitive) ---
8
- def generate_spcw_waveform(sequence_length, persistence_factor):
9
  """
10
- Simulates the Scalar Prime Composite Waveform.
11
- High persistence (00) = Low Heat. Change (11) = High Heat.
12
  """
13
- # 1. Generate Primes (The Logic Backbone)
14
- primes = list(sympy.primerange(0, sequence_length))
 
15
 
16
- # 2. Simulate "Heat" based on Prime Gaps (your logic)
17
- x = np.arange(len(primes))
18
- # Synthetic "Heat" metric based on gap delta
19
- heat = np.diff(primes, prepend=0) * (1 - persistence_factor)
20
 
21
- # 3. Create Visualization (The "Heat Map")
22
- fig = go.Figure()
23
- fig.add_trace(go.Scatter(x=x, y=primes, mode='lines+markers', name='Prime Scalar'))
24
- fig.add_trace(go.Bar(x=x, y=heat, name='Delta Heat (Change Energy)'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- fig.update_layout(title="SPCW Persistence & Change Matrix", template="plotly_dark")
 
 
 
 
 
 
 
27
  return fig
28
 
29
- # --- MODULE 2: MATROSKA TOPOLOGY (The Network) ---
30
- def visualize_matroska_network(shells):
31
  """
32
- Creates a concentric 'Matroska' network visualization.
 
33
  """
34
- G = nx.Graph()
35
- pos = {}
36
 
37
- # Create concentric shells
38
- for i in range(1, shells + 1):
39
- radius = i * 5
40
- nodes_in_layer = i * 6 # Hexagonal growth pattern
41
- for j in range(nodes_in_layer):
42
- node_id = f"L{i}-{j}"
43
- angle = (2 * np.pi * j) / nodes_in_layer
44
- pos[node_id] = (radius * np.cos(angle), radius * np.sin(angle))
45
- G.add_node(node_id, layer=i)
46
-
47
- # Connect to previous shell (The "Persistence" Link)
48
- if i > 1:
49
- prev_node = f"L{i-1}-{int(j/nodes_in_layer * ((i-1)*6))}"
50
- G.add_edge(node_id, prev_node)
51
-
52
- # Extract positions for Plotly
53
- edge_x = []
54
- edge_y = []
55
- for edge in G.edges():
56
- x0, y0 = pos[edge[0]]
57
- x1, y1 = pos[edge[1]]
58
- edge_x.extend([x0, x1, None])
59
- edge_y.extend([y0, y1, None])
60
-
61
- node_x = [pos[node][0] for node in G.nodes()]
62
- node_y = [pos[node][1] for node in G.nodes()]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
- fig = go.Figure(data=[
65
- go.Scatter(x=edge_x, y=edge_y, line=dict(width=0.5, color='#888'), hoverinfo='none', mode='lines'),
66
- go.Scatter(x=node_x, y=node_y, mode='markers', marker=dict(color='cyan', size=5))
67
- ])
68
- fig.update_layout(title="Modular Concentric Prime Matroska Network", showlegend=False, template="plotly_dark")
 
 
 
69
  return fig
70
 
71
  # --- THE INTERFACE ---
72
  with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
73
  gr.Markdown("# LOGOS: Modular Concentric Prime Matroska Network")
74
- gr.Markdown("Interactive architectural validation for SPCW and Nested Domains.")
75
 
76
- with gr.Tab("SPCW Waveform"):
 
77
  with gr.Row():
78
- seq_len = gr.Slider(10, 1000, value=100, label="Sequence Length")
79
- per_factor = gr.Slider(0.0, 1.0, value=0.5, label="Persistence Factor (00 State)")
80
- spcw_plot = gr.Plot(label="Persistence/Change Matrix")
81
- btn_spcw = gr.Button("Generate Waveform")
82
- btn_spcw.click(generate_spcw_waveform, inputs=[seq_len, per_factor], outputs=spcw_plot)
83
 
84
  with gr.Tab("Matroska Topology"):
85
- shells_slider = gr.Slider(1, 10, value=3, step=1, label="Nesting Depth (Shells)")
 
 
 
 
86
  matroska_plot = gr.Plot(label="Network Topology")
87
  btn_net = gr.Button("Build Network")
88
- btn_net.click(visualize_matroska_network, inputs=[shells_slider], outputs=matroska_plot)
89
 
90
  demo.launch()
 
4
  import sympy
5
  import networkx as nx
6
 
7
+ # --- MODULE 1: PRIME POTENTIALITY MATRIX (Mod 10 Waterfall) ---
8
+ def generate_potentiality_matrix(sequence_length, persistence_threshold):
9
  """
10
+ Visualizes the "Prime Potentiality" by aligning the integer stream to Mod 10.
11
+ This reveals the 1, 3, 7, 9 'rivers' of potentiality vs the Composite 'banks'.
12
  """
13
+ # 1. Create the Integer Stream (The Canvas)
14
+ # We use a standard integer range because Primes exists *within* this potential
15
+ integers = np.arange(sequence_length)
16
 
17
+ # 2. Mod 10 Alignment (The "Natural" Width)
18
+ width = 10
19
+ rows = int(np.ceil(sequence_length / width))
 
20
 
21
+ # Pad to fit perfect 10-column grid
22
+ padded_len = rows * width
23
+ padded_ints = np.pad(integers, (0, padded_len - len(integers)), mode='constant')
24
+
25
+ # 3. Calculate "Potentiality" (The Heat)
26
+ # We want to highlight Primes and their Residues
27
+ matrix_values = np.zeros(padded_len)
28
+
29
+ for i, val in enumerate(padded_ints):
30
+ if sympy.isprime(int(val)):
31
+ # Active Prime = High Heat (Visualized as distinct energy)
32
+ matrix_values[i] = 1.0
33
+ elif val % 2 == 0 or val % 5 == 0:
34
+ # Structurally Composite (0, 2, 4, 5, 6, 8) = Persistence/Ground
35
+ matrix_values[i] = 0.0
36
+ else:
37
+ # Composite but in a Prime Lane (e.g. 9, 21, 27) = "Potential"
38
+ matrix_values[i] = 0.3
39
+
40
+ # Reshape to Mod 10 Grid
41
+ grid = matrix_values.reshape(rows, width)
42
+
43
+ # 4. Visualization
44
+ fig = go.Figure(data=go.Heatmap(
45
+ z=grid,
46
+ x=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], # Explicit Mod 10 Columns
47
+ colorscale=[
48
+ [0.0, "#000000"], # Black: Ground State (Even/5s)
49
+ [0.3, "#2A2A5A"], # Blue: Potential (Odd Composites)
50
+ [1.0, "#00FFEA"] # Cyan: Kinetic Prime (The Signal)
51
+ ],
52
+ showscale=False,
53
+ hoverinfo='x+y+z'
54
+ ))
55
 
56
+ fig.update_layout(
57
+ title=f"Prime Potentiality Matrix (Mod 10 alignment)",
58
+ xaxis_title="Modulus 10 Residue (Last Digit)",
59
+ yaxis_title="Sequence Depth (Time)",
60
+ template="plotly_dark",
61
+ yaxis=dict(autorange="reversed"), # Stream flows down
62
+ height=800
63
+ )
64
  return fig
65
 
66
+ # --- MODULE 2: NESTED MATROSKA NETWORK (Hexagonal Shells) ---
67
+ def visualize_matroska_network(shells, show_connectors):
68
  """
69
+ Constructs the Matroska Network using Hexagonal Tiling.
70
+ Each shell represents a Prime Modulo Domain.
71
  """
72
+ fig = go.Figure()
 
73
 
74
+ # Colors for the "Heat" of each shell
75
+ colors = ["#FF0000", "#FF7F00", "#FFFF00", "#00FF00", "#0000FF", "#4B0082", "#9400D3"]
76
+
77
+ for layer in range(1, shells + 1):
78
+ # Hexagonal Geometry Logic
79
+ # A layer N in a hex grid has 6*N nodes
80
+ nodes_in_layer = 6 * layer
81
+ radius = layer * 10 # Spacing between shells
82
+
83
+ # Generating the Hexagon path for this layer
84
+ # We plot the "Wireframe" of the shell
85
+ t = np.linspace(0, 2*np.pi, 7) # 7 points to close the loop
86
+ hex_x = radius * np.cos(t)
87
+ hex_y = radius * np.sin(t)
88
+
89
+ # 1. Draw the Shell Boundary (The Domain)
90
+ fig.add_trace(go.Scatter(
91
+ x=hex_x, y=hex_y,
92
+ mode='lines',
93
+ line=dict(color=colors[(layer-1) % 7], width=2, dash='solid'),
94
+ name=f"Domain Shell {layer}"
95
+ ))
96
+
97
+ # 2. Draw the Nodes (The Data Atoms)
98
+ # Distributed along the perimeter
99
+ node_angles = np.linspace(0, 2*np.pi, nodes_in_layer, endpoint=False)
100
+ node_x = radius * np.cos(node_angles)
101
+ node_y = radius * np.sin(node_angles)
102
+
103
+ fig.add_trace(go.Scatter(
104
+ x=node_x, y=node_y,
105
+ mode='markers',
106
+ marker=dict(size=6, color=colors[(layer-1) % 7]),
107
+ showlegend=False
108
+ ))
109
+
110
+ # 3. Draw "Nested" Connectors (Inter-Domain Links)
111
+ # This visualizes the "Dissolution" flow from Outer -> Inner
112
+ if show_connectors and layer > 1:
113
+ prev_radius = (layer - 1) * 10
114
+ # Connect every X nodes to previous layer to show hierarchy
115
+ for k in range(0, nodes_in_layer, layer):
116
+ # Simple radial connection logic for demo
117
+ fig.add_trace(go.Scatter(
118
+ x=[node_x[k], (prev_radius * np.cos(node_angles[k]))],
119
+ y=[node_y[k], (prev_radius * np.sin(node_angles[k]))],
120
+ mode='lines',
121
+ line=dict(color='#333', width=1),
122
+ showlegend=False
123
+ ))
124
 
125
+ fig.update_layout(
126
+ title="Modular Concentric Prime Matroska (Nested Domains)",
127
+ showlegend=True,
128
+ template="plotly_dark",
129
+ xaxis=dict(showgrid=False, zeroline=False, visible=False),
130
+ yaxis=dict(showgrid=False, zeroline=False, visible=False),
131
+ width=800, height=800
132
+ )
133
  return fig
134
 
135
  # --- THE INTERFACE ---
136
  with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
137
  gr.Markdown("# LOGOS: Modular Concentric Prime Matroska Network")
138
+ gr.Markdown("Interactive architectural validation for **Mod 10 Potentiality** and **Nested Domains**.")
139
 
140
+ with gr.Tab("Prime Potentiality Matrix"):
141
+ gr.Markdown("Visualizing the 1, 3, 7, 9 Prime Avenues vs Composite Persistence.")
142
  with gr.Row():
143
+ seq_len = gr.Slider(100, 10000, value=2000, step=100, label="Sequence Depth")
144
+
145
+ matrix_plot = gr.Plot(label="Mod 10 Waterfall")
146
+ btn_matrix = gr.Button("Generate Matrix")
147
+ btn_matrix.click(generate_potentiality_matrix, inputs=[seq_len], outputs=matrix_plot)
148
 
149
  with gr.Tab("Matroska Topology"):
150
+ gr.Markdown("Visualizing the concentric dissolution of high-heat data into prime-stable domains.")
151
+ with gr.Row():
152
+ shells_slider = gr.Slider(1, 20, value=6, step=1, label="Domain Depth (Shells)")
153
+ show_links = gr.Checkbox(value=True, label="Show Inter-Domain Links")
154
+
155
  matroska_plot = gr.Plot(label="Network Topology")
156
  btn_net = gr.Button("Build Network")
157
+ btn_net.click(visualize_matroska_network, inputs=[shells_slider, show_links], outputs=matroska_plot)
158
 
159
  demo.launch()