Spaces:
Runtime error
Runtime error
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,161 +1,251 @@
|
|
| 1 |
-
# LOGOS: SPCW (Scalar Prime Composite Wave) Protocol
|
| 2 |
-
|
| 3 |
-
A deterministic, non-linear data transport protocol that replaces sequential scanning with fractal addressing.
|
| 4 |
-
|
| 5 |
-
## The Problem
|
| 6 |
-
|
| 7 |
-
Modern transport (PCIe/Network) treats data as a linear stream ("The Cake"), creating bandwidth bottlenecks. Sequential scanning forces data to flow in memory address order, regardless of geometric significance.
|
| 8 |
-
|
| 9 |
-
## The Solution
|
| 10 |
-
|
| 11 |
-
LOGOS transmits generative instructions ("The Bake"). Using a 512-byte Atom architecture and Prime Modulo addressing, the receiver reconstructs the state fractally. Data is populated by geometric significance, not memory address order.
|
| 12 |
-
|
| 13 |
-
## Key Features
|
| 14 |
-
|
| 15 |
-
- **Fractal Address Space**: 32-bit Heat Codes mapped to Quadtree geometry
|
| 16 |
-
- **Prime Constraint**: 9973 Modulo harmonization for signal integrity
|
| 17 |
-
- **Non-Linear Reconstruction**: Data populated by geometric significance, not memory address order
|
| 18 |
-
- **Compression via Geometry**: Only transmit "active" parts of the signal
|
| 19 |
-
- **Infinite Canvas**: Supports up to 2^16 Γ 2^16 resolution (65,536 Γ 65,536 pixels)
|
| 20 |
-
|
| 21 |
-
## Repository Structure
|
| 22 |
-
|
| 23 |
-
```
|
| 24 |
-
LOGOS_SPCW_Protocol/
|
| 25 |
-
βββ README.md # This file
|
| 26 |
-
βββ logos_core.py # The Math (Fractal Decoder + Prime Modulo)
|
| 27 |
-
βββ bake_stream.py # The Encoder (Image -> SPCW)
|
| 28 |
-
βββ eat_cake.py # The Player (SPCW -> Screen)
|
| 29 |
-
βββ data/ # Sample files
|
| 30 |
-
β βββ sample.spcw # Pre-baked binary file
|
| 31 |
-
βββ requirements.txt # numpy, opencv-python
|
| 32 |
-
```
|
| 33 |
-
|
| 34 |
-
## Installation
|
| 35 |
-
|
| 36 |
-
```bash
|
| 37 |
-
pip install -r requirements.txt
|
| 38 |
-
```
|
| 39 |
-
|
| 40 |
-
## Quick Start
|
| 41 |
-
|
| 42 |
-
### 1. Bake an Image (Encode)
|
| 43 |
-
|
| 44 |
-
```bash
|
| 45 |
-
python bake_stream.py input.png output.spcw
|
| 46 |
-
python bake_stream.py input.png output.spcw --tolerance 3.0 # Stricter fidelity
|
| 47 |
-
```
|
| 48 |
-
|
| 49 |
-
The Deep Baker uses bottom-up dissolution + pruning:
|
| 50 |
-
- Dissolve to max depth (full inspection)
|
| 51 |
-
- Collapse only when four children are identical within tolerance
|
| 52 |
-
|
| 53 |
-
### 2. Eat the Cake (Decode/Playback)
|
| 54 |
-
|
| 55 |
-
```bash
|
| 56 |
-
python eat_cake.py output.spcw
|
| 57 |
-
python eat_cake.py output.spcw --output reconstructed.png
|
| 58 |
-
python eat_cake.py output.spcw --heatmap # Show order of operations
|
| 59 |
-
```
|
| 60 |
-
|
| 61 |
-
The Player reconstructs the image using fractal addressing:
|
| 62 |
-
- Each atom's Heat Code determines its spatial position
|
| 63 |
-
- Canvas state is updated non-linearly (fractal pattern)
|
| 64 |
-
- Heatmap mode visualizes reconstruction order (red=early, blue=late)
|
| 65 |
-
|
| 66 |
-
## Protocol Details
|
| 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 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
#
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LOGOS: SPCW (Scalar Prime Composite Wave) Protocol
|
| 2 |
+
|
| 3 |
+
A deterministic, non-linear data transport protocol that replaces sequential scanning with fractal addressing.
|
| 4 |
+
|
| 5 |
+
## The Problem
|
| 6 |
+
|
| 7 |
+
Modern transport (PCIe/Network) treats data as a linear stream ("The Cake"), creating bandwidth bottlenecks. Sequential scanning forces data to flow in memory address order, regardless of geometric significance.
|
| 8 |
+
|
| 9 |
+
## The Solution
|
| 10 |
+
|
| 11 |
+
LOGOS transmits generative instructions ("The Bake"). Using a 512-byte Atom architecture and Prime Modulo addressing, the receiver reconstructs the state fractally. Data is populated by geometric significance, not memory address order.
|
| 12 |
+
|
| 13 |
+
## Key Features
|
| 14 |
+
|
| 15 |
+
- **Fractal Address Space**: 32-bit Heat Codes mapped to Quadtree geometry
|
| 16 |
+
- **Prime Constraint**: 9973 Modulo harmonization for signal integrity
|
| 17 |
+
- **Non-Linear Reconstruction**: Data populated by geometric significance, not memory address order
|
| 18 |
+
- **Compression via Geometry**: Only transmit "active" parts of the signal
|
| 19 |
+
- **Infinite Canvas**: Supports up to 2^16 Γ 2^16 resolution (65,536 Γ 65,536 pixels)
|
| 20 |
+
|
| 21 |
+
## Repository Structure
|
| 22 |
+
|
| 23 |
+
```
|
| 24 |
+
LOGOS_SPCW_Protocol/
|
| 25 |
+
βββ README.md # This file
|
| 26 |
+
βββ logos_core.py # The Math (Fractal Decoder + Prime Modulo)
|
| 27 |
+
βββ bake_stream.py # The Encoder (Image -> SPCW)
|
| 28 |
+
βββ eat_cake.py # The Player (SPCW -> Screen)
|
| 29 |
+
βββ data/ # Sample files
|
| 30 |
+
β βββ sample.spcw # Pre-baked binary file
|
| 31 |
+
βββ requirements.txt # numpy, opencv-python
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
## Installation
|
| 35 |
+
|
| 36 |
+
```bash
|
| 37 |
+
pip install -r requirements.txt
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
## Quick Start
|
| 41 |
+
|
| 42 |
+
### 1. Bake an Image (Encode)
|
| 43 |
+
|
| 44 |
+
```bash
|
| 45 |
+
python bake_stream.py input.png output.spcw
|
| 46 |
+
python bake_stream.py input.png output.spcw --tolerance 3.0 # Stricter fidelity
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
The Deep Baker uses bottom-up dissolution + pruning:
|
| 50 |
+
- Dissolve to max depth (full inspection)
|
| 51 |
+
- Collapse only when four children are identical within tolerance
|
| 52 |
+
|
| 53 |
+
### 2. Eat the Cake (Decode/Playback)
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
python eat_cake.py output.spcw
|
| 57 |
+
python eat_cake.py output.spcw --output reconstructed.png
|
| 58 |
+
python eat_cake.py output.spcw --heatmap # Show order of operations
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
The Player reconstructs the image using fractal addressing:
|
| 62 |
+
- Each atom's Heat Code determines its spatial position
|
| 63 |
+
- Canvas state is updated non-linearly (fractal pattern)
|
| 64 |
+
- Heatmap mode visualizes reconstruction order (red=early, blue=late)
|
| 65 |
+
|
| 66 |
+
## Protocol Details
|
| 67 |
+
import gradio as gr
|
| 68 |
+
import numpy as np
|
| 69 |
+
import plotly.graph_objects as go
|
| 70 |
+
import sympy
|
| 71 |
+
import networkx as nx
|
| 72 |
+
|
| 73 |
+
# --- MODULE 1: SPCW LOGIC (The Primitive) ---
|
| 74 |
+
def generate_spcw_waveform(sequence_length, persistence_factor):
|
| 75 |
+
"""
|
| 76 |
+
Simulates the Scalar Prime Composite Waveform.
|
| 77 |
+
High persistence (00) = Low Heat. Change (11) = High Heat.
|
| 78 |
+
"""
|
| 79 |
+
# 1. Generate Primes (The Logic Backbone)
|
| 80 |
+
primes = list(sympy.primerange(0, sequence_length))
|
| 81 |
+
|
| 82 |
+
# 2. Simulate "Heat" based on Prime Gaps (your logic)
|
| 83 |
+
x = np.arange(len(primes))
|
| 84 |
+
# Synthetic "Heat" metric based on gap delta
|
| 85 |
+
heat = np.diff(primes, prepend=0) * (1 - persistence_factor)
|
| 86 |
+
|
| 87 |
+
# 3. Create Visualization (The "Heat Map")
|
| 88 |
+
fig = go.Figure()
|
| 89 |
+
fig.add_trace(go.Scatter(x=x, y=primes, mode='lines+markers', name='Prime Scalar'))
|
| 90 |
+
fig.add_trace(go.Bar(x=x, y=heat, name='Delta Heat (Change Energy)'))
|
| 91 |
+
|
| 92 |
+
fig.update_layout(title="SPCW Persistence & Change Matrix", template="plotly_dark")
|
| 93 |
+
return fig
|
| 94 |
+
|
| 95 |
+
# --- MODULE 2: MATROSKA TOPOLOGY (The Network) ---
|
| 96 |
+
def visualize_matroska_network(shells):
|
| 97 |
+
"""
|
| 98 |
+
Creates a concentric 'Matroska' network visualization.
|
| 99 |
+
"""
|
| 100 |
+
G = nx.Graph()
|
| 101 |
+
pos = {}
|
| 102 |
+
|
| 103 |
+
# Create concentric shells
|
| 104 |
+
for i in range(1, shells + 1):
|
| 105 |
+
radius = i * 5
|
| 106 |
+
nodes_in_layer = i * 6 # Hexagonal growth pattern
|
| 107 |
+
for j in range(nodes_in_layer):
|
| 108 |
+
node_id = f"L{i}-{j}"
|
| 109 |
+
angle = (2 * np.pi * j) / nodes_in_layer
|
| 110 |
+
pos[node_id] = (radius * np.cos(angle), radius * np.sin(angle))
|
| 111 |
+
G.add_node(node_id, layer=i)
|
| 112 |
+
|
| 113 |
+
# Connect to previous shell (The "Persistence" Link)
|
| 114 |
+
if i > 1:
|
| 115 |
+
prev_node = f"L{i-1}-{int(j/nodes_in_layer * ((i-1)*6))}"
|
| 116 |
+
G.add_edge(node_id, prev_node)
|
| 117 |
+
|
| 118 |
+
# Extract positions for Plotly
|
| 119 |
+
edge_x = []
|
| 120 |
+
edge_y = []
|
| 121 |
+
for edge in G.edges():
|
| 122 |
+
x0, y0 = pos[edge[0]]
|
| 123 |
+
x1, y1 = pos[edge[1]]
|
| 124 |
+
edge_x.extend([x0, x1, None])
|
| 125 |
+
edge_y.extend([y0, y1, None])
|
| 126 |
+
|
| 127 |
+
node_x = [pos[node][0] for node in G.nodes()]
|
| 128 |
+
node_y = [pos[node][1] for node in G.nodes()]
|
| 129 |
+
|
| 130 |
+
fig = go.Figure(data=[
|
| 131 |
+
go.Scatter(x=edge_x, y=edge_y, line=dict(width=0.5, color='#888'), hoverinfo='none', mode='lines'),
|
| 132 |
+
go.Scatter(x=node_x, y=node_y, mode='markers', marker=dict(color='cyan', size=5))
|
| 133 |
+
])
|
| 134 |
+
fig.update_layout(title="Modular Concentric Prime Matroska Network", showlegend=False, template="plotly_dark")
|
| 135 |
+
return fig
|
| 136 |
+
|
| 137 |
+
# --- THE INTERFACE ---
|
| 138 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 139 |
+
gr.Markdown("# LOGOS: Modular Concentric Prime Matroska Network")
|
| 140 |
+
gr.Markdown("Interactive architectural validation for SPCW and Nested Domains.")
|
| 141 |
+
|
| 142 |
+
with gr.Tab("SPCW Waveform"):
|
| 143 |
+
with gr.Row():
|
| 144 |
+
seq_len = gr.Slider(10, 1000, value=100, label="Sequence Length")
|
| 145 |
+
per_factor = gr.Slider(0.0, 1.0, value=0.5, label="Persistence Factor (00 State)")
|
| 146 |
+
spcw_plot = gr.Plot(label="Persistence/Change Matrix")
|
| 147 |
+
btn_spcw = gr.Button("Generate Waveform")
|
| 148 |
+
btn_spcw.click(generate_spcw_waveform, inputs=[seq_len, per_factor], outputs=spcw_plot)
|
| 149 |
+
|
| 150 |
+
with gr.Tab("Matroska Topology"):
|
| 151 |
+
shells_slider = gr.Slider(1, 10, value=3, step=1, label="Nesting Depth (Shells)")
|
| 152 |
+
matroska_plot = gr.Plot(label="Network Topology")
|
| 153 |
+
btn_net = gr.Button("Build Network")
|
| 154 |
+
btn_net.click(visualize_matroska_network, inputs=[shells_slider], outputs=matroska_plot)
|
| 155 |
+
|
| 156 |
+
demo.launch()
|
| 157 |
+
|
| 158 |
+
### Atom Structure (512 bytes)
|
| 159 |
+
|
| 160 |
+
- **Heat Code**: First 4 bytes (32 bits) - Fractal address
|
| 161 |
+
- **Wave Payload**: Remaining 508 bytes - Data/instructions
|
| 162 |
+
|
| 163 |
+
### Fractal Addressing
|
| 164 |
+
|
| 165 |
+
32-bit Heat Code decoded as 16-level quadtree descent:
|
| 166 |
+
- **Bit Structure**: Bits 31-30 (Level 1), Bits 29-28 (Level 2), ..., Bits 1-0 (Level 16)
|
| 167 |
+
- **Quadrant Mapping**: 00=Top-Left, 01=Top-Right, 10=Bottom-Left, 11=Bottom-Right
|
| 168 |
+
- **Termination**: Stops at minimum bucket size (64px) or stop sequence
|
| 169 |
+
|
| 170 |
+
### Prime Harmonization
|
| 171 |
+
|
| 172 |
+
- `residue = heat_code % 9973`
|
| 173 |
+
- `residue == 0` β META (Harmonized Wave/Structure)
|
| 174 |
+
- `residue != 0` β DELTA (Phase Hole/Heat/Correction)
|
| 175 |
+
|
| 176 |
+
## Core Functions (`logos_core.py`)
|
| 177 |
+
|
| 178 |
+
### `resolve_fractal_address(heat_code_int, canvas_width, canvas_height)`
|
| 179 |
+
|
| 180 |
+
Decodes 32-bit Heat Code to spatial ZoneRect `(x, y, width, height)` via quadtree descent.
|
| 181 |
+
|
| 182 |
+
### `prime_harmonizer(heat_code_int)`
|
| 183 |
+
|
| 184 |
+
Classifies Heat Code as META (harmonized) or DELTA (phase hole).
|
| 185 |
+
|
| 186 |
+
### `calculate_heat_code(path_bits)`
|
| 187 |
+
|
| 188 |
+
Encodes quadtree path (list of 2-bit quadrants) into 32-bit Heat Code.
|
| 189 |
+
|
| 190 |
+
### `pack_atom(heat_code, payload_data)`
|
| 191 |
+
|
| 192 |
+
Constructs 512-byte Atom: `[Heat Code (4B)] + [Payload (508B)]`.
|
| 193 |
+
|
| 194 |
+
## Use Cases
|
| 195 |
+
|
| 196 |
+
### 1. Compression via Geometry
|
| 197 |
+
|
| 198 |
+
Demonstrates that only "active" parts of a signal need transmission. Uniform regions compress to single atoms.
|
| 199 |
+
|
| 200 |
+
### 2. Non-Linear Stream Processing
|
| 201 |
+
|
| 202 |
+
Heatmap mode visually proves non-linear reconstruction. Large blocks appear first, fine details fill in laterβnot top-to-bottom scanning.
|
| 203 |
+
|
| 204 |
+
### 3. Infinite Canvas Support
|
| 205 |
+
|
| 206 |
+
Fractal addressing supports resolutions up to 65,536 Γ 65,536 without linear memory constraints.
|
| 207 |
+
|
| 208 |
+
### 4. Deterministic Transport
|
| 209 |
+
|
| 210 |
+
Same Heat Code always maps to same spatial region, enabling deterministic reconstruction across systems.
|
| 211 |
+
|
| 212 |
+
## Technical Notes
|
| 213 |
+
|
| 214 |
+
- **Minimum Bucket Size**: 64px (configurable)
|
| 215 |
+
- **Maximum Depth**: 16 levels (2^16 = 65,536 subdivisions)
|
| 216 |
+
- **Coordinate Clamping**: Final ZoneRect clamped to canvas bounds
|
| 217 |
+
- **Big Endian**: Heat Code stored as Big Endian unsigned int
|
| 218 |
+
|
| 219 |
+
## Examples
|
| 220 |
+
|
| 221 |
+
### Example 1: Encode and Decode
|
| 222 |
+
|
| 223 |
+
```bash
|
| 224 |
+
# Bake a test image (deep dissolution)
|
| 225 |
+
python bake_stream.py test_image.png test.spcw --tolerance 5.0 --max-depth 10
|
| 226 |
+
|
| 227 |
+
# Reconstruct it
|
| 228 |
+
python eat_cake.py test.spcw --output reconstructed.png
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
### Example 2: Visualize Reconstruction Order
|
| 232 |
+
|
| 233 |
+
```bash
|
| 234 |
+
# Show heatmap (proves non-linear processing)
|
| 235 |
+
python eat_cake.py test.spcw --heatmap --output heatmap.png
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
The heatmap shows red (early atoms) and blue (late atoms), proving that reconstruction is fractal, not sequential.
|
| 239 |
+
|
| 240 |
+
## Architecture Philosophy
|
| 241 |
+
|
| 242 |
+
**The Cake/Bake Axiom:**
|
| 243 |
+
- **Bake**: The input stream (Instructions + Ingredients)
|
| 244 |
+
- **Cake**: The output (reconstructed reality)
|
| 245 |
+
- **The Oven**: The reconstruction engine (fractal addressing + state updates)
|
| 246 |
+
|
| 247 |
+
LOGOS separates "what to transmit" (The Bake) from "how to reconstruct" (The Oven). The receiver doesn't need to know the original structureβit follows the fractal instructions.
|
| 248 |
+
|
| 249 |
+
## License
|
| 250 |
+
|
| 251 |
+
Reference Implementation for the LOGOS DSP Bridge protocol.
|