Performance targets
Why Rust
The core engine is written in Rust for three reasons:
- Zero-cost abstractions: Algebraic operations map directly to hardware instructions with no runtime overhead. No garbage collection pauses, no JIT warm-up.
- Memory safety: The algebraic properties of MindPrism (closure, bounded values) are enforced by the type system. Invalid states are unrepresentable at compile time.
- Portable targets: The same codebase compiles to x86_64, ARM64, and WebAssembly — from cloud servers to Raspberry Pi to the browser.
Memory layout
Each ternary value (+1, 0, −1) is packed into 2 bits, giving 4 values per byte. A vector of dimension D = 10,000 occupies 2,500 bytes — small enough to fit in L1/L2 cache on most processors.
// Ternary packing: 4 values per byte // 00 = absent (0) // 01 = presence (+1) // 10 = negation (−1) // 11 = unused (reserved) struct TernaryVec { data: Box<[u8]>, // packed ternary values dim: usize, // logical dimension }
Batch operations use Structure-of-Arrays (SoA) layout: N vectors stored as N/8 bytes for value-position-0, then N/8 bytes for value-position-1, and so on. This gives optimal cache behavior for batch BIND and SUPERPOSE.
SIMD optimization
BIND (element-wise multiplication) maps directly to SIMD instructions:
// Pseudocode for SIMD BIND // Process 16 ternary values per cycle fn bind_simd(a: &TernaryVec, b: &TernaryVec) -> TernaryVec { for chunk in a.data.chunks_exact(4).zip(b.data.chunks_exact(4)) { // 2-bit lookup table for ternary multiply // Result written directly — no intermediate allocation } }
At D = 10,000, a single BIND requires ~2,500 byte operations — approximately 160 SIMD cycles on AVX2 (256-bit registers). This is why we achieve 10M+ operations per second.
Python bindings
PyO3 provides zero-overhead FFI between Python and the Rust core:
import mindprism as mp // Create vectors color = mp.random_vector(D=10000) red = mp.random_vector(D=10000) // Bind and query color_red = mp.bind(color, red) result = mp.bind(color_red, color) // ≈ red // Check similarity print(mp.similarity(result, red)) // 0.94+
The Python API mirrors the algebra 1:1. No hidden abstractions — every function corresponds to a single algebraic operation.
Regression guarantees
Every build runs 10 million property tests validating:
- Closure: all outputs are valid ternary vectors.
- Associativity: SUPERPOSE order independence.
- Reversibility: BIND is self-inverse.
- Bounded similarity: all similarity values in [−1, +1].
- Idempotency: GATE with identity mask returns the original.
Any PR that breaks a property test is rejected — the math must never drift.