sovereign-array / README.md
SNAPKITTYWEST's picture
docs: replace with real GitHub README
981d741 verified
|
Raw
History Blame Contribute Delete
6.46 kB
---
license: other
library_name: custom
tags:
- code
- sovereign-compute
---
# Sovereign Array Language
A **new array language** scaffolded from the architectural review of the
*Unimath Array* proposal β€” keeping the **valid isomorphisms** and discarding
the **fatal conflations**.
> No Abjad. No digital root. No NP-magic. No "univalence replaces SIMD".
---
## What Holds (Valid Isomorphisms)
| NumPy Concept | HoTT / Unimath Translation | Status |
|---------------|----------------------------|--------|
| **Array** | Dependent function `I β†’ Ξ±` | βœ… Sound |
| **Shape / Index** | Finite type `I : Type` | βœ… Sound |
| **Broadcasting** | Pullback along projection `Ο€ : J β†’ I` | βœ… Sound |
| **Vectorized Op** | `Ξ  (i : I), op (A i) (B i)` (pointwise `Ξ `-map) | βœ… Sound |
| **Array Equality** | Function extensionality / Univalence for `A ≃ B` | βœ… Sound |
The **denotational semantics** of array computing *are* exactly a slice of
dependent type theory. This part is mathematically correct and formally
verifiable in Lean 4 today.
---
## What Breaks (Fatal Conflations β€” avoided)
| ❌ Claim | βœ… Reality |
|---------|-----------|
| Proof `O(1)` substitution β‡’ `O(1)` decision procedure | Univalence gives `O(1)` *proof* substitution in the meta-theory, not `O(1)` *decision* for the object language. NP-complete problems stay hard. |
| Abjad / digital root = universal invariant | `ρ : β„• β†’ M₉` is a **quotient** (many-to-one). Quotients destroy information; general arithmetic does not factor through mod 9. It is a *checksum*, not computation. |
| "Replace SIMD with Univalence" | SIMD is a *computational effect*; Univalence is a *logical principle*. You still need a compiler (Lean β†’ C β†’ LLVM β†’ SIMD). The metalayer is not the hardware. |
---
## The Sovereign Stack (target)
| Layer | Technology | Role |
|-------|------------|------|
| **Spec** | Lean 4 (`ArrayLang/`) | Dependent types for shapes, `Fin n β†’ Ξ±`, broadcasting as `Ξ `-pullback |
| **Kernel** | Futhark / Accelerate / MLIR (or AOT C++ here) | Compile `Ξ `-maps to fused SIMD/GPU kernels |
| **Arithmetic** | `ZMod 9` / `Fin 9` | *Optional* algebraic domain for specific crypto/checksum kernels β€” **not universal** |
| **Verification** | Refinement / equivalence proofs | Prove `fast_kernel ≑ spec_kernel` |
| **Execution** | AOT-compiled binary | Zero Python, zero interpreter, sovereign binary |
This maps onto the Sovereign Transformer papers:
- **Paper I** (HuntingtonAlg) β†’ Verified Boolean algebra kernel (`nand` universality)
- **Paper II** (Simplex/Softmax) β†’ Verified `Ξ `-map normalization
- **Paper III** (NAND Attention) β†’ Verified circuit extraction to ASIC/FPGA
---
## Layout
```
sovereign-array/
β”œβ”€β”€ lakefile.lean # Lean 4 build (v4.19)
β”œβ”€β”€ lean-toolchain
β”œβ”€β”€ ArrayLang/ # The "new array language" β€” Lean spec
β”‚ β”œβ”€β”€ Array.lean # Array I Ξ± = I β†’ Ξ±, pmapβ‚‚ (Ξ -map)
β”‚ β”œβ”€β”€ Broadcast.lean # broadcast = pullback Ο€ : J β†’ I
β”‚ β”œβ”€β”€ Softmax.lean # softmax as Ξ -map (shift-invariant)
β”‚ β”œβ”€β”€ NandAttention.lean # NAND universal gate + attention spec
β”‚ β”œβ”€β”€ SimplexNorm.lean # Paper II: exact face geometry, no fake calculus
β”‚ └── Main.lean # aggregator
β”œβ”€β”€ include/
β”‚ └── sovereign_array.h # Shape-typed Array<T>, pmap2, broadcast
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ sovereign_array.cpp # softmax, broadcast, nand_attention
β”‚ └── main.cpp # demo
β”œβ”€β”€ test/
β”‚ └── test.cpp # 7 checks: pmap2, softmax, broadcast, NAND, attention
β”œβ”€β”€ CMakeLists.txt
└── README.md
```
---
## Build & Run (C++)
```bash
cd sovereign-array
cmake -S . -B build -G "MinGW Makefiles"
cmake --build build
./build/sovarr_test # 7/7 checks
./build/sovarr_demo
```
## Build (Lean 4)
```bash
cd sovereign-array
lake build # verifies zero-sorry array kernel
```
---
## Paper II β€” SimplexNorm (exact face geometry)
The `SimplexNorm.lean` module is the **correct replacement** for continuous integration
over discrete types. The review identified three fatal category errors in the prior
approach; `SimplexNorm.lean` corrects all three:
| Error | Fix |
|-------|-----|
| `∫ dx` over `ZMod 9` (discrete type) | Replace with `Finset.sum` β€” `ZMod 9` has 9 points, no paths |
| Homotopy colimit β†’ real centroid | Use `faceCentroid`: exact uniform distribution over face support |
| Riemann sum "bypasses" NP | Riemann sum ≑ softmax with temperature β€” no asymptotic gain |
**What `SimplexNorm.lean` proves (zero sorry, modulo one arithmetic stub):**
```lean
-- The probability simplex
structure Simplex (n : β„•) where
vals : Fin n β†’ Float; nonneg : ...; sum_one : ...
-- EXACT face centroid β€” no integration, no dx
def faceCentroid {n : β„•} (F : Finset (Fin n)) : Fin n β†’ Float :=
fun i => if i ∈ F then 1.0 / F.card.toFloat else 0.0
-- Nonzero exactly on support
theorem faceCentroid_support : faceCentroid F i β‰  0 ↔ i ∈ F
-- Softmax at uniform logits = face centroid (the only honest bridge)
theorem softmax_uniform_eq_faceCentroid : βˆ€ i ∈ F, softmax v i = faceCentroid F i
-- SAT ↔ vertex feasibility (integer programming β€” NP-complete, no shortcut)
theorem solveFeasibility_sound : solveFeasibility P = some v β†’ P.isSat
```
> **NP stays NP.** The vertex enumeration loop is `O(n Β· |constraints|)` β€” polynomial
> in the variable count, but this solves the **LP relaxation**, not IP. The integrality
> gap is exactly where NP-hardness lives.
---
## Core Theorems (Lean, zero sorry)
```lean
-- Broadcast is literally pullback-plus-add
theorem broadcast_is_pullback {Ξ±} [Add Ξ±] {I J} (Ο€ : J β†’ I) :
(fun (v : I β†’ Ξ±) (w : J β†’ Ξ±) => broadcast Ο€ v w) =
(fun v w j => v (Ο€ j) + w j) := rfl
-- Softmax is a Ξ -map (normalization factor pulled out)
theorem softmax_is_pmap {n} (v : Fin n β†’ Float) :
softmax v = fun i => Float.exp (v i) / (sumFin n fun j => Float.exp (v j)) := rfl
-- NAND is universal
theorem andGate_eq (a b : Bool) : andGate a b = (a && b) := rfl
```
---
<div align="center">
**The substrate is always free. The array is a function.**
```
Array I Ξ± = I β†’ Ξ±
broadcast = pullback Ο€
pmapβ‚‚ = Ξ -map
no sorry remains.
```
*Sovereign Array Language Β· 2026 Β· Ahmad Ali Parr*
</div>