Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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:
|
| 8 |
-
def
|
| 9 |
"""
|
| 10 |
-
|
| 11 |
-
|
| 12 |
"""
|
| 13 |
-
# 1.
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
# 2.
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
heat = np.diff(primes, prepend=0) * (1 - persistence_factor)
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
fig.update_layout(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
return fig
|
| 28 |
|
| 29 |
-
# --- MODULE 2: MATROSKA
|
| 30 |
-
def visualize_matroska_network(shells):
|
| 31 |
"""
|
| 32 |
-
|
|
|
|
| 33 |
"""
|
| 34 |
-
|
| 35 |
-
pos = {}
|
| 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 |
-
fig
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
| 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
|
| 75 |
|
| 76 |
-
with gr.Tab("
|
|
|
|
| 77 |
with gr.Row():
|
| 78 |
-
seq_len = gr.Slider(
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
|
| 84 |
with gr.Tab("Matroska Topology"):
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|