UNNS Modular Interpreter System
UNNS MODULAR INTERPRETER
A fully modular UNNS Interpreter System with pluggable Prime Spiral Renderer and Betti Number Visualizer modules that integrate seamlessly with the macro system.
Here's what makes this special:
🎯 Key Features:
1. Modular Architecture:
- PrimeSpiralModule - Standalone module for Ulam spiral visualization
- BettiNumberModule - Independent topology visualizer
- CombinedModule - Orchestrates multiple modules together
- Each module has its own
render()
,animate()
, andstopAnimation()
methods
2. Macro System Integration:
@prime_spiral(n, density) {
render: ulam_spiral;
max: n;
density: density;
color: gradient(prime_count);
}
@betti_compute(dimension, manifold) {
compute: homology_groups;
dim: dimension;
type: manifold;
visualize: true;
}
@unns_transform(expr) {
parse: algebraic;
apply: prime_spiral(42, 0.8);
overlay: betti_compute(3, torus);
}
3. Prime Spiral Features:
- Ulam Spiral Pattern - True mathematical spiral layout
- Prime Detection - Efficient primality testing up to 10,000
- Density Control - Adjustable visualization density
- Glow Effects - Visual distinction between primes and composites
- Rotation Animation - Smooth spiral rotation
4. Betti Number Visualizer:
- Multiple Manifold Types:
- Sphere (β₀=1, βₙ=1)
- Torus (Pascal's triangle pattern)
- Projective space (alternating pattern)
- Homology Group Visualization - Nested circles for each dimension
- Euler Characteristic - Automatic calculation (χ = Σ(-1)ⁱβᵢ)
- Morphism Connections - Visual links between dimensions
5. Interpreter Features:
- Macro Parser - Parses custom UNNS macro definitions
- Macro Executor - Interprets and executes parsed macros
- Module Dispatcher - Routes commands to appropriate modules
- Live Logging - Real-time execution feedback
- Parameter Extraction - Dynamic parameter handling
6. Interactive Controls:
- Sliders for real-time parameter adjustment
- Module Switcher for focusing on specific visualizations
- Animation Controls - Start/stop all animations
- Keyboard Shortcuts:
Ctrl+Enter
- Execute macrosCtrl+P
- Parse macrosCtrl+R
- Render combined
7. Computed Metrics:
- Active Macro Count - Number of parsed macros
- Prime Count - Total primes in current spiral
- Betti Sum - Σβᵢ (total homology rank)
- Euler Characteristic - Alternating sum of Betti numbers
🔧 How the Modular System Works:
- Module Registration:
JavaScript
this.modules = { primeSpiral: new PrimeSpiralModule(), bettiNumbers: new BettiNumberModule(), combined: new CombinedModule() };
- Macro Interpretation:
- Macros are parsed into structured objects
- Each macro has a name, parameters, and body
- Nested macros are supported for complex transformations
- Execution Pipeline:
- Parse → Extract Parameters → Dispatch to Module → Render → Update Metrics
- Module Communication:
- Modules can share data through the interpreter
- Combined module can orchestrate multiple modules
- Each module maintains its own state
🚀 Extension Points:
The system is designed to be easily extended with new modules:
class NewModule {
render(ctx, params) { /* rendering logic */ }
animate(ctx) { /* animation logic */ }
stopAnimation() { /* cleanup */ }
}
// Register new module
interpreter.modules.newModule = new NewModule();
This modular architecture makes it easy to add new mathematical visualizations (like Mandelbrot sets, Julia sets, cellular automata, etc.) that can all be controlled through the unified macro system!